private void Port_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                switch (HostCanvas.SplineMode)
                {
                case SplineModes.Nothing:
                    HostCanvas.TempStartPort = this;
                    HostCanvas.SplineMode    = SplineModes.Second;
                    break;

                case SplineModes.Second:
                    if (
                        (
                            (
                                HostCanvas.TempStartPort.DataType.IsCastableTo(DataType) &&
                                HostCanvas.TypeSensitive && PortType == PortTypes.Output
                                ||
                                DataType.IsCastableTo(HostCanvas.TempStartPort.DataType) &&
                                HostCanvas.TypeSensitive && PortType == PortTypes.Input
                            )                           // data types matching
                            ||
                            (!HostCanvas.TypeSensitive) // data types must not match
                        ) &&
                        PortType != HostCanvas.TempStartPort.PortType
                        // is not same port type --> input to output or output to input
                        && !Equals(ParentNode, HostCanvas.TempStartPort.ParentNode))     // is not same node
                    {
                        Connector connector;

                        if (PortType == PortTypes.Output)
                        {
                            if (HostCanvas.TempStartPort.ConnectedConnectors.Count > 0)
                            {
                                if (!HostCanvas.TempStartPort.MultipleConnectionsAllowed)
                                {
                                    foreach (var tempConnector in HostCanvas.TempStartPort.ConnectedConnectors)
                                    {
                                        tempConnector.RemoveFromCanvas();
                                    }

                                    HostCanvas.TempStartPort.ConnectedConnectors.Clear();
                                }
                            }

                            connector = new Connector(HostCanvas, this, HostCanvas.TempStartPort);
                        }
                        else
                        {
                            if (ConnectedConnectors.Count > 0)
                            {
                                if (!MultipleConnectionsAllowed)
                                {
                                    foreach (var tempConnector in ConnectedConnectors)
                                    {
                                        tempConnector.RemoveFromCanvas();
                                    }

                                    ConnectedConnectors.Clear();
                                }
                            }

                            connector = new Connector(HostCanvas, HostCanvas.TempStartPort, this);
                        }

                        HostCanvas.ConnectorCollection.Add(connector);
                    }


                    HostCanvas.SplineMode = SplineModes.Nothing;
                    HostCanvas.ClearTempLine();
                    break;
                }
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                foreach (var connector in ConnectedConnectors)
                {
                    connector.RemoveFromCanvas();
                }
                ConnectedConnectors.Clear();
            }
            // e.Handled = true;
        }
Esempio n. 2
0
        protected Node(VplControl hostCanvas) : base(hostCanvas)
        {
            Guid = Guid.NewGuid();

            id = Interlocked.Increment(ref id);
            id = Interlocked.Increment(ref id);
            Id = id;

            InputPorts      = new List <Port>();
            OutputPorts     = new List <Port>();
            ControlElements = new List <UIElement>();

            IsHitTestVisible = true;
            HasError         = false;


            SpaceCanvas = new Canvas();
            Children.Add(ContentGrid = new Grid {
                ShowGridLines = false, Background = Brushes.Transparent
            });


            if (hostCanvas.GraphFlowDirection == GraphFlowDirections.Horizontal)
            {
                // ----------------------------------------------------------------------------------------------------------------------
                // Content Panels
                // ----------------------------------------------------------------------------------------------------------------------
                InputPortPanel = new StackPanel
                {
                    VerticalAlignment = VerticalAlignment.Center
                };

                SetColumn(InputPortPanel, 0);
                SetRow(InputPortPanel, 1);
                ContentGrid.Children.Add(InputPortPanel);

                OutputPortPanel = new StackPanel
                {
                    VerticalAlignment = VerticalAlignment.Center
                };
                SetColumn(OutputPortPanel, 2);
                SetRow(OutputPortPanel, 1);
                ContentGrid.Children.Add(OutputPortPanel);
            }
            else
            {
                // ----------------------------------------------------------------------------------------------------------------------
                // Content Panels
                // ----------------------------------------------------------------------------------------------------------------------
                InputPortPanel = new DockPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                SetRow(InputPortPanel, 0);
                SetColumn(InputPortPanel, 1);
                ContentGrid.Children.Add(InputPortPanel);

                OutputPortPanel = new DockPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                SetColumn(OutputPortPanel, 1);
                SetRow(OutputPortPanel, 2);
                ContentGrid.Children.Add(OutputPortPanel);
            }

            // ----------------------------------------------------------------------------------------------------------------------
            // Content grid row and column definitions
            // ----------------------------------------------------------------------------------------------------------------------
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            // Input
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            // Content
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            // Output

            ContentGrid.RowDefinitions.Insert(0, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Header
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Content
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Footer
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Risize area

            ContentGrid.SizeChanged      += ContentGridOnSizeChanged;
            ContentGrid.VerticalAlignment = VerticalAlignment.Center;

            // ----------------------------------------------------------------------------------------------------------------------
            // Main content grid
            // ----------------------------------------------------------------------------------------------------------------------
            MainContentGrid = new Grid
            {
                ShowGridLines = false,
                Style         = FindResource("MainContentGridStyle") as Style
            };


            SetColumn(MainContentGrid, 1);
            SetRow(MainContentGrid, 1);
            ContentGrid.Children.Add(MainContentGrid);

            // ----------------------------------------------------------------------------------------------------------------------
            // Event delagates
            // ----------------------------------------------------------------------------------------------------------------------
            Border.MouseDown += Node_MouseDown;

            Loaded  += Node_Loaded;
            KeyUp   += Node_KeyUp;
            KeyDown += Node_KeyDown;

            // ----------------------------------------------------------------------------------------------------------------------
            // Comments
            // ----------------------------------------------------------------------------------------------------------------------
            TopComment = new Comment(this)
            {
                Text =
                    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
                Background = HostCanvas.FindResource("CommentBackgroundBrushError") as Brush,
                ExpandSide = CommentExpandSides.Top
            };


            BottomComment = new Comment(this)
            {
                Text =
                    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
                Background = HostCanvas.FindResource("CommentBackgroundBrush") as Brush,
                ExpandSide = CommentExpandSides.Bottom
            };

            TopComment.Visibility    = Visibility.Collapsed;
            BottomComment.Visibility = Visibility.Collapsed;

            ShowHelpOnMouseOver = false;

            if (QuestButton != null)
            {
                if (QuestButton != null)
                {
                    QuestButton.Click += QuestButton_Click;
                }
            }

            SetZIndex(this, Id);
            SetZIndex(Border, Id);


            if (HitTestBorder != null)
            {
                SetZIndex(HitTestBorder, Id);
            }
            if (BinButton != null)
            {
                SetZIndex(BinButton, Id);
            }
            if (ResizeButton != null)
            {
                SetZIndex(ResizeButton, Id);
            }
            if (QuestButton != null)
            {
                SetZIndex(QuestButton, Id);
            }
            if (CaptionLabel != null)
            {
                SetZIndex(CaptionLabel, Id);
            }
            if (AutoCheckBox != null)
            {
                SetZIndex(AutoCheckBox, Id);
            }

            SetZIndex(TopComment, Id);
            SetZIndex(BottomComment, Id);

            if (GetType() == typeof(SelectionNode))
            {
                return;
            }
            HostCanvas.NodeCollection.Add(this);
        }
Esempio n. 3
0
        protected Node(VplControl hostCanvas) : base(hostCanvas)
        {
            Guid = Guid.NewGuid();

            id = Interlocked.Increment(ref id);
            id = Interlocked.Increment(ref id);
            Id = id;

            InputPorts      = new List <Port>();
            OutputPorts     = new List <Port>();
            ControlElements = new List <UIElement>();

            IsHitTestVisible = true;
            HasError         = false;

            SpaceCanvas = new Canvas();

            //Adding a title to nodes. A new subgrid holds the title an the node panel
            //TODO : Clean up

            // ----------------------------------------------------------------------------------------------------------------------
            // Container Panel
            // ----------------------------------------------------------------------------------------------------------------------

            Grid container = new Grid {
                ShowGridLines = false, Background = Brushes.Transparent
            };

            container.RowDefinitions.Insert(0, new RowDefinition());
            container.RowDefinitions.Insert(1, new RowDefinition());

            Children.Add(container);

            NodeTitle = new Grid {
                ShowGridLines = false, Background = Brushes.Transparent
            };

            Title(container, new Label {
                Content    = this.GetType().Name,
                Foreground = Brushes.White,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontSize = 13,
                Padding  = new Thickness(0)
            });

            container.Children.Add(ContentGrid = new Grid {
                ShowGridLines = false, Background = Brushes.Transparent
            });
            SetColumn(ContentGrid, 0);
            SetRow(ContentGrid, 1);


            if (hostCanvas.GraphFlowDirection == GraphFlowDirections.Horizontal)
            {
                // ----------------------------------------------------------------------------------------------------------------------
                // Content Panels
                // ----------------------------------------------------------------------------------------------------------------------
                InputPortPanel = new StackPanel
                {
                    VerticalAlignment = VerticalAlignment.Center
                };

                SetColumn(InputPortPanel, 0);
                SetRow(InputPortPanel, 1);
                ContentGrid.Children.Add(InputPortPanel);

                OutputPortPanel = new StackPanel
                {
                    VerticalAlignment = VerticalAlignment.Center
                };
                SetColumn(OutputPortPanel, 2);
                SetRow(OutputPortPanel, 1);
                ContentGrid.Children.Add(OutputPortPanel);
            }
            else
            {
                // ----------------------------------------------------------------------------------------------------------------------
                // Content Panels
                // ----------------------------------------------------------------------------------------------------------------------
                InputPortPanel = new DockPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                SetRow(InputPortPanel, 0);
                SetColumn(InputPortPanel, 1);
                ContentGrid.Children.Add(InputPortPanel);

                OutputPortPanel = new DockPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Center
                };

                SetColumn(OutputPortPanel, 1);
                SetRow(OutputPortPanel, 2);
                ContentGrid.Children.Add(OutputPortPanel);
            }

            // ----------------------------------------------------------------------------------------------------------------------
            // Content grid row and column definitions
            // ----------------------------------------------------------------------------------------------------------------------
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            // Input
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            // Content
            ContentGrid.ColumnDefinitions.Insert(0,
                                                 new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            // Output

            ContentGrid.RowDefinitions.Insert(0, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Header
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Content
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Footer
            ContentGrid.RowDefinitions.Insert(1, new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            // Risize area

            ContentGrid.SizeChanged      += ContentGridOnSizeChanged;
            ContentGrid.VerticalAlignment = VerticalAlignment.Center;

            // ----------------------------------------------------------------------------------------------------------------------
            // Main content grid
            // ----------------------------------------------------------------------------------------------------------------------
            MainContentGrid = new Grid
            {
                ShowGridLines = false,
                Style         = FindResource("MainContentGridStyle") as Style
            };


            SetColumn(MainContentGrid, 1);
            SetRow(MainContentGrid, 1);
            ContentGrid.Children.Add(MainContentGrid);

            // ----------------------------------------------------------------------------------------------------------------------
            // Event delagates
            // ----------------------------------------------------------------------------------------------------------------------
            Border.MouseDown += Node_MouseDown;

            Loaded  += Node_Loaded;
            KeyUp   += Node_KeyUp;
            KeyDown += Node_KeyDown;

            // ----------------------------------------------------------------------------------------------------------------------
            // Comments
            // ----------------------------------------------------------------------------------------------------------------------
            TopComment = new Comment(this)
            {
                Text       = "",
                Background = HostCanvas.FindResource("CommentBackgroundBrushError") as Brush,
                ExpandSide = CommentExpandSides.Top
            };


            BottomComment = new Comment(this)
            {
                Text       = "",
                Background = HostCanvas.FindResource("CommentBackgroundBrush") as Brush,
                ExpandSide = CommentExpandSides.Bottom
            };

            TopComment.Visibility    = Visibility.Collapsed;
            BottomComment.Visibility = Visibility.Collapsed;

            ShowHelpOnMouseOver = false;

            if (QuestButton != null)
            {
                if (QuestButton != null)
                {
                    QuestButton.Click += QuestButton_Click;
                }
            }

            SetZIndex(this, Id);
            SetZIndex(Border, Id);


            if (HitTestBorder != null)
            {
                SetZIndex(HitTestBorder, Id);
            }
            if (BinButton != null)
            {
                SetZIndex(BinButton, Id);
            }
            if (ResizeButton != null)
            {
                SetZIndex(ResizeButton, Id);
            }
            if (QuestButton != null)
            {
                SetZIndex(QuestButton, Id);
            }
            if (CaptionLabel != null)
            {
                SetZIndex(CaptionLabel, Id);
            }
            if (AutoCheckBox != null)
            {
                SetZIndex(AutoCheckBox, Id);
            }

            SetZIndex(TopComment, Id);
            SetZIndex(BottomComment, Id);

            if (GetType() == typeof(SelectionNode))
            {
                return;
            }
            HostCanvas.NodeCollection.Add(this);
        }