public dynPort(int index, PortType portType, dynNodeUI owner, string name) { InitializeComponent(); Index = index; this.MouseEnter += delegate { foreach (var c in connectors) c.Highlight(); }; this.MouseLeave += delegate { foreach (var c in connectors) c.Unhighlight(); }; IsConnected = false; PortType = portType; Owner = owner; PortName = name; portGrid.DataContext = this; portNameTb.DataContext = this; toolTipText.DataContext = this; ellipse1Dot.DataContext = this; ellipse1.DataContext = Owner; portGrid.Loaded += new RoutedEventHandler(portGrid_Loaded); }
public dynNode() { InPortData = new List<PortData>(); OutPortData = new List<PortData>(); NodeUI = new dynNodeUI(this); }
public dynConnector(dynNodeUI start, dynNodeUI end, int startIndex, int endIndex, int portType) : this(start, end, startIndex, endIndex, portType, true) { }
public dynConnector(dynNodeUI start, dynNodeUI end, int startIndex, int endIndex, int portType, bool visible) { //don't try to create a connector with a bad start, //end, or if we're trying to connector the same //port to itself. if (start == null || end == null || start == end) { throw new Exception("Attempting to create connector with invalid start or end nodes."); } pStart = start.OutPorts[startIndex]; dynPort endPort = null; if (portType == 0) endPort = end.InPorts[endIndex]; //connect the two ports //get start point pStart.Connect(this); BrushConverter bc = new BrushConverter(); strokeBrush = (Brush)bc.ConvertFrom("#313131"); #region bezier creation connector = new Path(); connector.Stroke = strokeBrush; connector.StrokeThickness = STROKE_THICKNESS; connector.Opacity = STROKE_OPACITY; connector.DataContext = this; Binding strokeBinding = new Binding("StrokeBrush"); connector.SetBinding(Path.StrokeProperty, strokeBinding); 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; dynSettings.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; dynSettings.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; endDot.IsHitTestVisible = false; endDot.MouseDown +=new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown); Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE / 2); Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE / 2); dynSettings.Workbench.Children.Add(endDot); endDot.Opacity = STROKE_OPACITY; endDot.IsHitTestVisible = false; endDot.MouseDown += new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown); 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); Canvas.SetZIndex(this, 1); this.Connect(endPort); ConnectorType = dynSettings.Bench.ConnectorType; }
void SetState(dynNodeUI el, ElementState state) { el.State = state; }
private static void DeleteNode(dynNodeUI node) { foreach (var port in node.OutPorts) { for (int j = port.Connectors.Count - 1; j >= 0; j--) { port.Connectors[j].Kill(); } } foreach (dynPort p in node.InPorts) { for (int j = p.Connectors.Count - 1; j >= 0; j--) { p.Connectors[j].Kill(); } } dynSettings.Workbench.Selection.Remove(node); dynSettings.Controller.Nodes.Remove(node.NodeLogic); dynSettings.Workbench.Children.Remove(node); }