Example #1
0
 private void MainWindow_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (mode == Mode.DragNode)
     {
         Point p = e.GetPosition(this.MasterCanvas);
         curNode.X = p.X - nodeOffsetX;
         curNode.Y = p.Y - nodeOffsetY;
         curNode   = null;
         mode      = Mode.None;
     }
     else if (mode == Mode.LinkConnectors)
     {
         Point p = e.GetPosition(this.MasterCanvas);
         this.linkPts[2].X          = p.X + 10;
         this.linkPts[2].Y          = p.Y;
         this.linkPts[3].X          = p.X;
         this.linkPts[3].Y          = p.Y;
         this.linkFigure.StartPoint = this.linkPts[0];
         this.linkSegment.Point1    = this.linkPts[1];
         this.linkSegment.Point2    = this.linkPts[2];
         this.linkSegment.Point3    = this.linkPts[3];
         this.linkSegment.IsStroked = true;
         this.linkPath.Visibility   = Visibility.Hidden;
         DispConnector connector = InConnector(p);
         if (connector != null)
         {
             curConnector.ConnectTo(connector);
             curConnector.Parent.Layout(curConnector.Parent.X, curConnector.Parent.Y);
             connector.Parent.Layout(connector.Parent.X, connector.Parent.Y);
         }
         mode = Mode.None;
     }
 }
Example #2
0
 void UpdateConnectionLink(DispConnector owner, Line inputLine, Canvas inputCanvas, Line outputLine, Canvas outputCanvas)
 {
     this.pts[0] = inputCanvas.TranslatePoint(new System.Windows.Point(inputLine.X1, inputLine.Y1), VisualNode.MasterCanvas);
     this.pts[1] = inputCanvas.TranslatePoint(new System.Windows.Point(inputLine.X1 - 50.0, inputLine.Y2), VisualNode.MasterCanvas);
     this.pts[2] = outputCanvas.TranslatePoint(new System.Windows.Point(outputLine.X1 + 50.0, outputLine.Y1), VisualNode.MasterCanvas);
     this.pts[3] = outputCanvas.TranslatePoint(new System.Windows.Point(outputLine.X1, outputLine.Y2), VisualNode.MasterCanvas);
     owner.UpdateConnection();
 }
Example #3
0
        public void ConnectTo(DispConnector connector)
        {
            DispConnector inputConnector  = (IsInput) ? this : connector;
            DispConnector outputConnector = (IsInput) ? connector : this;

            if (inputConnector == outputConnector)
            {
                return;
            }
            if (inputConnector.Connections.Count == 0 || inputConnector.Connections[0] != outputConnector)
            {
                inputConnector.Connections.Clear();
                inputConnector.Connections.Add(outputConnector);
                outputConnector.Connections.Add(inputConnector);
            }
        }
Example #4
0
        private void MainWindow_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Point p = e.GetPosition(this.MasterCanvas);

            if (mode == Mode.None)
            {
                // Check if point is in node
                foreach (var dispNode in dispGraph.dispNodes)
                {
                    if (dispNode.PointInObject(p.X, p.Y))
                    {
                        curNode     = dispNode;
                        nodeOffsetX = p.X - dispNode.X;
                        nodeOffsetY = p.Y - dispNode.Y;
                        mode        = Mode.DragNode;
                        UpdateProperties(curNode);
                        break;
                    }
                    else
                    {
                        UpdateProperties(null);
                        // Check if in connector ring
                        curConnector = InConnectorList(p, dispNode.inputs);
                        if (curConnector == null)
                        {
                            curConnector = InConnectorList(p, dispNode.outputs);
                        }
                        if (curConnector != null)
                        {
                            curNode                  = curConnector.Parent;
                            mode                     = Mode.LinkConnectors;
                            this.linkPts[0].X        = p.X;
                            this.linkPts[0].Y        = p.Y;
                            this.linkPts[1].X        = p.X - 10.0;
                            this.linkPts[1].Y        = p.Y;
                            this.linkPts[2].X        = p.X - 10.0;
                            this.linkPts[2].Y        = p.Y;
                            this.linkPts[3].X        = p.X - 10.0;
                            this.linkPts[3].Y        = p.Y;
                            this.linkPath.Visibility = Visibility.Visible;
                            break;
                        }
                    }
                }
            }
        }
Example #5
0
 private DispConnector InConnector(Point p)
 {
     foreach (var dispNode in dispGraph.dispNodes)
     {
         DispConnector connector = InConnectorList(p, dispNode.inputs);
         if (connector != null)
         {
             return(connector);
         }
         connector = InConnectorList(p, dispNode.outputs);
         if (connector != null)
         {
             return(connector);
         }
     }
     return(null);
 }