Beispiel #1
0
        public Connection(WorkflowCanvas canvas, RenderNode startPoint, RenderNode endPoint, ConnectingLine line)
        {
            this.Canvas = canvas;
            Line        = line;
            if (startPoint.Node.GetConnectionType() == INodeConnectionType.OUTPUT &&
                endPoint.Node.GetConnectionType() == INodeConnectionType.INPUT)
            {
                Input  = (BaseInputNode)endPoint.Node;
                Output = (BaseOutputNode)startPoint.Node;

                Start = startPoint;
                End   = endPoint;
            }
            else if (startPoint.Node.GetConnectionType() == INodeConnectionType.INPUT &&
                     endPoint.Node.GetConnectionType() == INodeConnectionType.OUTPUT)
            {
                Input  = (BaseInputNode)startPoint.Node;
                Output = (BaseOutputNode)endPoint.Node;
                Start  = endPoint;
                End    = startPoint;
            }

            contextMenu = new ContextMenu();
            MenuItem item = new MenuItem();

            item.Header = "Disconnect";
            contextMenu.Items.Add(item);

            item.Click += delegate
            {
                Disconnect();
            };
        }
Beispiel #2
0
        /// <summary>
        /// Finishes a temporary connection started by <see cref="StartConnection"/>.
        /// This will solidify a connection and add it to the active connections
        /// list to prevent redrawing of static lines.
        /// </summary>
        /// <param name="node">The node.</param>
        public void FinishConnection(RenderNode node)
        {
            ConnectingLine connectingLine = new ConnectingLine(TempLine.Line.Stroke);

            connectingLine.Line.StrokeThickness = node.Visual.Width / LINE_THICKNESS_FRACTION;

            Connection connection = new Connection(this, StartNode, node, connectingLine);

            if (connection.IsValid())
            {
                bool success = connection.Connect();
                if (success)
                {
                    RedrawLine(connection);

                    Connections.Add(connection);
                    Children.Add(connection.Line.Line);
                    Children.Add(connection.Line.Arrowhead);
                    connection.Start.Parent.OnModuleMove += OnConnectedModuleMove;
                    connection.End.Parent.OnModuleMove   += OnConnectedModuleMove;
                }
            }
            // else let it fall out of scope to be garbage collected
            StartNode = null;
            TempLine.SetVisibility(Visibility.Collapsed);
        }