Esempio n. 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;
     }
 }
Esempio n. 2
0
 public void SelectNode(DispNode node)
 {
     if (curSelection != null)
     {
         curSelection.Selected = false;
     }
     curSelection = node;
     if (curSelection != null)
     {
         curSelection.Selected = true;
     }
 }
Esempio n. 3
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;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 private void UpdateProperties(DispNode node)
 {
     this.dispGraph.SelectNode(node);
     PropertyGrid.Children.Clear();
     PropertyGrid.RowDefinitions.Clear();
     if (node != null && node.properties != null)
     {
         int row = 0;
         foreach (var item in node.properties)
         {
             PropertyGrid.RowDefinitions.Add(new RowDefinition());
             Label l = new Label();
             l.Content = item.Key;
             l.SetValue(Grid.RowProperty, row);
             l.SetValue(Grid.ColumnProperty, 0);
             PropertyGrid.Children.Add(l);
             TextBox tb = new TextBox();
             tb.Text = item.Value.ToString();
             tb.SetValue(Grid.RowProperty, row++);
             tb.SetValue(Grid.ColumnProperty, 1);
             PropertyGrid.Children.Add(tb);
         }
     }
 }
Esempio n. 5
0
 public static void Connect(DispNode n1, string name1, DispNode n2, string name2)
 {
     n1.FindConnector(name1).Connections.Add(n2.FindConnector(name2));
     n2.FindConnector(name2).Connections.Add(n1.FindConnector(name1));
 }
Esempio n. 6
0
        public DispConnector(DispNode parent, string name, Canvas parentCanvas, bool isInput) : base(parentCanvas)
        {
            this.Parent      = parent;
            this.Connections = new List <DispConnector>();
            this.Name        = name;
            this.IsInput     = isInput;

            this.Width  = 140.0;
            this.Height = 15.0;

            // Draw connector line
            this.line = new Line();
            this.ParentCanvas.Children.Add(this.line);
            this.line.SetValue(Canvas.ZIndexProperty, 4);
            this.line.Stroke          = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            this.line.StrokeThickness = 3.0;

            // Draw connector circle
            this.ellipse = new Ellipse();
            this.ellipse.SetValue(Canvas.ZIndexProperty, 4);
            this.ParentCanvas.Children.Add(ellipse);
            this.ellipse.Fill            = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            this.ellipse.Width           = 10.0;
            this.ellipse.Height          = 10.0;
            this.ellipse.Stroke          = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            this.ellipse.StrokeThickness = 2.0;

            // Add name of input node
            this.tb = new TextBlock();
            this.tb.SetValue(Canvas.ZIndexProperty, 4);
            this.ParentCanvas.Children.Add(tb);
            this.tb.Text = name;

            // line delimiting input nodes
            this.separator = new Line();
            this.separator.SetValue(Canvas.ZIndexProperty, 4);
            this.ParentCanvas.Children.Add(this.separator);
            this.separator.Stroke          = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            this.separator.StrokeThickness = 1.0;

            if (isInput)
            {
                this.link = new Path();
                this.link.SetValue(Canvas.ZIndexProperty, 5);
                this.link.Stroke          = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                this.link.Opacity         = 0.7;
                this.link.StrokeThickness = 4.0;
                var geom   = new PathGeometry();
                var figure = new PathFigure();
                this.pts[0]       = new System.Windows.Point(-20.0, 0.0);
                this.pts[1]       = new System.Windows.Point(-30.0, 0.0);
                this.pts[2]       = new System.Windows.Point(-30.0, 10.0);
                this.pts[3]       = new System.Windows.Point(-20.0, 10.0);
                figure.StartPoint = this.pts[0];
                var segment = new BezierSegment(this.pts[1], this.pts[2], this.pts[3], true);
                figure.Segments.Add(segment);
                geom.Figures.Add(figure);
                this.link.Data = geom;
                VisualNode.MasterCanvas.Children.Add(this.link);
            }

            Layout(0.0, 0.0);
        }