Exemple #1
0
        public void DrawPoint(Point point, Brush color)
        {
            NodeSocket nc = new NodeSocket(null, typeof(int));

            nc.SetColorStroke(color);

            MainPanel.Children.Add(nc);
            nc.Loaded += (a, b) =>
            {
                var margin = nc.Margin;
                margin.Left        = point.X - nc.ActualWidth / 2;
                margin.Top         = point.Y - nc.ActualHeight / 2;
                nc.Margin          = margin;
                nc.RenderTransform = new ScaleTransform(0.5, 0.5, nc.ActualWidth / 2, nc.ActualHeight / 2);
            };
        }
Exemple #2
0
        //Закрепление соединения между NodeConnector
        private void NodeConnector_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!NConnDrag)
            {
                return;
            }

            var nc = sender as NodeSocket;

            nc.SetBaseColor();
            initNode.SetColorStroke(Brushes.Black);
            if (nc.SocketType == initNode.SocketType)
            {
                MessageBox.Show("Same node type");
                Window_MouseLeftButtonDown(sender, e);
                return;
            }
            if (nc.ParentNode == initNode.ParentNode)
            {
                MessageBox.Show("Infinite cycle");
                Window_MouseLeftButtonDown(sender, e);
                return;
            }
            if (nc.ConnectedCurves.Select(x => x.GetInitSocket()).Contains(initNode))
            {
                return;
            }
            if (nc.SocketType == NodeSocket.SocketTypes.Input && nc.ConnectedCurves.Count > 0)
            {
                MessageBox.Show("There are existing connections left");
                Window_MouseLeftButtonDown(sender, e);
                return;
            }
            if (initNode.SocketType == NodeSocket.SocketTypes.Input && initNode.ConnectedCurves.Count > 0)
            {
                MessageBox.Show("There are existing connections left");
                Window_MouseLeftButtonDown(sender, e);
                return;
            }
            //if (initNode.DataType != nc.DataType) return;
            Vector start = (Vector)initNode.GetCenter(MainPanel);
            Vector end   = (Vector)nc.GetCenter(MainPanel);

            var path = CreatePath(start, end, nc.SocketType == NodeSocket.SocketTypes.Input ? NodeSocket.SocketTypes.Output : NodeSocket.SocketTypes.Input);

            MainPanel.Children.Remove(Drawed);
            Drawed = null;
            MainPanel.Children.Add(path);
            nc.ConnectedCurves.Add(path);
            initNode.ConnectedCurves.Add(path);

            path.SetSockets(initNode, nc);

            (path.ContextMenu.Items[0] as MenuItem).Click += (x, y) =>
            {
                MainPanel.Children.Remove(path);
                path.GetInitSocket().ConnectedCurves.Remove(path);
                path.GetEndSocket().ConnectedCurves.Remove(path);
                UpdateProcess(nc.ParentNode);
            };
            UpdateProcess(nc.ParentNode);
            NConnDrag = false;
            //MessageBox.Show(MainGrid.Children.OfType<Path>().Count().ToString());
        }