예제 #1
0
        private void UnselectAllElements()
        {
            foreach (var node in SelectedNodes)
            {
                node.IsSelected = false;
            }

            foreach (var conn in ConnectorCollection)
            {
                conn.IsSelected = false;
            }

            SelectedNodes.Clear();
            SelectedConnectors.Clear();
            SelectedUiElements.Clear();
        }
예제 #2
0
        /*
         * public void DoDynamicAnimation(object sender, MouseButtonEventArgs args)
         * {
         *  for (var i = 0; i < 36; ++i)
         *  {
         *      // var e = new Button { Width = 50, Height = 16, Content="Test" };
         *
         *      //var e = new Ellipse { Width = 16, Height = 16, Fill = SystemColors.HighlightBrush };
         *      //var e = new Ellipse { Width = 6, Height = 6, Fill=Brushes.HotPink };
         *
         *      var e = new SliderNode(this) {Left = Mouse.GetPosition(this).X, Top = Mouse.GetPosition(this).Y};
         *
         *      // var e = new TextBlock { Text = "Test" };
         *      // var e = new Slider { Width = 100 };
         *
         *      // var e = new ProgressBar { Width = 100 , Height =10, Value=i };
         *
         *      // var e = =new DataGrid{Width=100, Height=100};
         *      // var e = new TextBox { Text = "Hallo" };
         *      // var e = new Label { Content = "Halllo" };
         *      // var e = new RadioButton { Content="dfsdf" };
         *
         *      //Canvas.SetLeft(e, Mouse.GetPosition(this).X);
         *      //Canvas.SetTop(e, Mouse.GetPosition(this).Y);
         *
         *      var tg = new TransformGroup();
         *      var translation = new TranslateTransform(30, 0);
         *      var translationName = "myTranslation" + translation.GetHashCode();
         *      RegisterName(translationName, translation);
         *      tg.Children.Add(translation);
         *      tg.Children.Add(new RotateTransform(i*10));
         *      e.RenderTransform = tg;
         *
         *      NodeCollection.Add(e);
         *      Children.Add(e);
         *
         *      var anim = new DoubleAnimation(3, 250, new Duration(new TimeSpan(0, 0, 0, 2, 0)))
         *      {
         *          EasingFunction = new PowerEase {EasingMode = EasingMode.EaseOut}
         *      };
         *
         *      var s = new Storyboard();
         *      Storyboard.SetTargetName(s, translationName);
         *      Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.YProperty));
         *      var storyboardName = "s" + s.GetHashCode();
         *      Resources.Add(storyboardName, s);
         *
         *      s.Children.Add(anim);
         *
         *      s.Completed +=
         *          (sndr, evtArgs) =>
         *          {
         *              //panel.Children.Remove(e);
         *              Resources.Remove(storyboardName);
         *              UnregisterName(translationName);
         *          };
         *      s.Begin();
         *  }
         * }
         */


        public void VplControl_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Delete:

                foreach (var node in SelectedNodes)
                {
                    node.Delete();
                }

                foreach (var conn in SelectedConnectors)
                {
                    conn.Delete();
                }

                SelectedNodes.Clear();
                SelectedConnectors.Clear();
                break;

            case Key.C:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    tempCollection = new TrulyObservableCollection <Node>();


                    foreach (var node in SelectedNodes)
                    {
                        tempCollection.Add(node);
                    }
                }
            }
            break;

            case Key.V:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    if (tempCollection == null)
                    {
                        return;
                    }
                    if (tempCollection.Count == 0)
                    {
                        return;
                    }

                    var bBox = Node.GetBoundingBoxOfNodes(tempCollection.ToList());

                    var copyPoint  = new Point(bBox.Left + bBox.Size.Width / 2, bBox.Top + bBox.Size.Height / 2);
                    var pastePoint = Mouse.GetPosition(this);

                    var delta = Point.Subtract(pastePoint, copyPoint);

                    UnselectAllElements();

                    var alreadyClonedConnectors = new List <Connector>();
                    var copyConnections         = new List <CopyConnection>();

                    // copy nodes from clipboard to canvas
                    foreach (var node in tempCollection)
                    {
                        var newNode = node.Clone();

                        newNode.Left += delta.X;
                        newNode.Top  += delta.Y;

                        newNode.Left = Convert.ToInt32(newNode.Left);
                        newNode.Top  = Convert.ToInt32(newNode.Top);

                        newNode.Show();

                        copyConnections.Add(new CopyConnection {
                                NewNode = newNode, OldNode = node
                            });
                    }

                    foreach (var cc in copyConnections)
                    {
                        var counter = 0;

                        foreach (var conn in cc.OldNode.InputPorts)
                        {
                            foreach (var connector in conn.ConnectedConnectors)
                            {
                                if (!alreadyClonedConnectors.Contains(connector))
                                {
                                    Connector newConnector = null;

                                    // start and end node are contained in selection
                                    if (tempCollection.Contains(connector.StartPort.ParentNode))
                                    {
                                        var cc2 =
                                            copyConnections.FirstOrDefault(
                                                i => Equals(i.OldNode, connector.StartPort.ParentNode));

                                        if (cc2 != null)
                                        {
                                            newConnector = new Connector(this, cc2.NewNode.OutputPorts[0],
                                                                         cc.NewNode.InputPorts[counter]);
                                        }
                                    }
                                    // only end node is contained in selection
                                    else
                                    {
                                        newConnector = new Connector(this, connector.StartPort,
                                                                     cc.NewNode.InputPorts[counter]);
                                    }

                                    if (newConnector != null)
                                    {
                                        alreadyClonedConnectors.Add(connector);
                                        ConnectorCollection.Add(newConnector);
                                    }
                                }
                            }
                            counter++;
                        }
                    }
                }
            }
            break;

            case Key.G:
            {
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    GroupNodes();
                }
            }
            break;

            case Key.S:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    SaveFile();
                }
            }
            break;

            case Key.T:
            {
                Console.WriteLine("T");
                foreach (var node in NodeCollection)
                {
                    Console.WriteLine(node.ActualWidth);
                    Console.WriteLine(node.ActualHeight);
                }
            }
            break;

            case Key.O:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    OpenFile();
                }
            }
            break;

            case Key.A:
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    SelectedNodes.Clear();

                    foreach (var node in NodeCollection)
                    {
                        node.IsSelected = true;
                        SelectedNodes.Add(node);
                    }
                }
            }
            break;

            case Key.Escape:
            {
                UnselectAllElements();
                mouseMode = MouseMode.Nothing;
            }
            break;

            case Key.LeftCtrl:
                if (!Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    ShowElementsAfterTransformation();
                }
                break;

            case Key.RightCtrl:
                if (!Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    ShowElementsAfterTransformation();
                }
                break;
            }
        }