Example #1
0
 public dynConnector(dynNode start, dynNode end, int startIndex, int endIndex, int portType)
     : this(start, end, startIndex, endIndex, portType, true)
 {
 }
Example #2
0
 void SetState(dynNode el, ElementState state)
 {
     el.State = state;
 }
Example #3
0
        public dynConnector(dynNode start, dynNode end, int startIndex, int endIndex, int portType, bool visible)
        {
            //this.workBench = settings.WorkBench;

             //if (start != null && end != null && start != end)
             //{
             //in the start element, find the out port at the startIndex
             pStart = start.OutPort;

             dynPort endPort = null;

             if (portType == 0)
            endPort = end.InPorts[endIndex];
             else if (portType == 1)
            endPort = end.StatePorts[endIndex];

             //connect the two ports
             //get start point

             pStart.Connect(this);

             BrushConverter bc = new BrushConverter();
             Brush strokeBrush = (Brush)bc.ConvertFrom("#313131");

             #region bezier creation
             connector = new Path();
             connector.Stroke = strokeBrush;
             connector.StrokeThickness = STROKE_THICKNESS;
             connector.Opacity = STROKE_OPACITY;

             DoubleCollection dashArray = new DoubleCollection();
             dashArray.Add(5); dashArray.Add(2);
             connector.StrokeDashArray = dashArray;

             PathGeometry connectorGeometry = new PathGeometry();
             connectorPoints = new PathFigure();
             connectorCurve = new BezierSegment();

             connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
             connectorCurve.Point1 = connectorPoints.StartPoint;
             connectorCurve.Point2 = connectorPoints.StartPoint;
             connectorCurve.Point3 = connectorPoints.StartPoint;

             connectorPoints.Segments.Add(connectorCurve);
             connectorGeometry.Figures.Add(connectorPoints);
             connector.Data = connectorGeometry;
             dynElementSettings.SharedInstance.Workbench.Children.Add(connector);
             #endregion

             #region polyline creation
             plineConnector = new Path();
             plineConnector.Stroke = strokeBrush;
             plineConnector.StrokeThickness = STROKE_THICKNESS;
             plineConnector.Opacity = STROKE_OPACITY;
             plineConnector.StrokeDashArray = dashArray;

             PathGeometry plineGeometry = new PathGeometry();
             //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx
             plineFigure = new PathFigure();
             plineFigure.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
             Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint,
                connectorPoints.StartPoint,
                connectorPoints.StartPoint};
             pline = new PolyLineSegment(polyLinePointArray, true);
             pline.Points = new PointCollection(polyLinePointArray);
             plineFigure.Segments.Add(pline);
             plineGeometry.Figures.Add(plineFigure);
             plineConnector.Data = plineGeometry;
             dynElementSettings.SharedInstance.Workbench.Children.Add(plineConnector);
             #endregion

             endDot = new Ellipse();
             endDot.Height = 6;
             endDot.Width = 6;
             endDot.Fill = Brushes.Black;
             endDot.StrokeThickness = 2;
             endDot.Stroke = Brushes.Black;
             Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE/2);
             Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE/2);
             dynElementSettings.SharedInstance.Workbench.Children.Add(endDot);
             endDot.Opacity = STROKE_OPACITY;

             this.Visible = visible;

             connector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
             connector.MouseLeave += delegate { Unhighlight(); };
             plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
             plineConnector.MouseLeave += delegate { Unhighlight(); };

             isDrawing = true;

             //set this to not draggable
             Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
             Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

             //set the z order to the front
             Canvas.SetZIndex(this, 300);

             this.Connect(endPort);

             this.ConnectorType = dynElementSettings.SharedInstance.Bench.ConnectorType;
             dynElementSettings.SharedInstance.Bench.settings_curves.Checked += new RoutedEventHandler(settings_curves_Checked);
             dynElementSettings.SharedInstance.Bench.settings_plines.Checked += new RoutedEventHandler(settings_plines_Checked);
        }