Наследование: INotifyPropertyChanged
Пример #1
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;
            }
        }
        private void Port_MouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (ParentNode.HostCanvas.SplineMode)
            {
                case SplineModes.Nothing:
                    ParentNode.HostCanvas.TempStartPort = this;
                    ParentNode.HostCanvas.SplineMode = SplineModes.Second;
                    break;
                case SplineModes.Second:
                    if (
                        (
                            (
                                ParentNode.HostCanvas.TempStartPort.DataType.IsCastableTo(DataType) &&
                                ParentNode.HostCanvas.TypeSensitive && PortType == PortTypes.Output
                                ||
                                DataType.IsCastableTo(ParentNode.HostCanvas.TempStartPort.DataType) &&
                                ParentNode.HostCanvas.TypeSensitive && PortType == PortTypes.Input
                                ) // data types matching
                            ||
                            (!ParentNode.HostCanvas.TypeSensitive) // data types must not match
                            )
                        && PortType != ParentNode.HostCanvas.TempStartPort.PortType
                            // is not same port type --> input to output or output to input
                        && !Equals(ParentNode, ParentNode.HostCanvas.TempStartPort.ParentNode)) // is not same node
                    {
                        Connector connector;

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

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

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

                        ParentNode.HostCanvas.ConnectorCollection.Add(connector);
                    }


                    ParentNode.HostCanvas.SplineMode = SplineModes.Nothing;
                    ParentNode.HostCanvas.ClearTempLine();
                    break;
            }

            e.Handled = true;
        }
Пример #3
0
        internal void DeserializeNetwork(string filePath)
        {
            var tempNodeCollection = new List<Node>();

            NewFile();

            // Create an reader
            using (var reader = new XmlTextReader(filePath))
            {
                reader.MoveToContent();

                var enumString = reader.GetAttribute("GraphFlowDirection");

                if (enumString != null)
                {
                    ImportFlowDirection =
                        (GraphFlowDirections) Enum.Parse(typeof (GraphFlowDirections), enumString, true);
                }


                reader.ReadToDescendant("Nodes");

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:

                            if (reader.Name != null)
                            {
                                var type = Type.GetType(reader.Name);

                                if (type == null)
                                {
                                    try // try to find type in entry assembly
                                    {
                                        var assembly = Assembly.GetEntryAssembly();
                                        type = assembly.GetTypes().FirstOrDefault(t => t.FullName == reader.Name);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }

                                    try // try to find type in ExternalNodeTypes
                                    {
                                        type = ExternalNodeTypes.ToArray()
                                            .FirstOrDefault(t => t.FullName == reader.Name);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }
                                }


                                if (type != null)
                                {
                                    if (type.IsSubclassOf(typeof (Node)))
                                    {
                                        var node = (Node) Activator.CreateInstance(type, this);
                                        node.DeserializeNetwork(reader);

                                        tempNodeCollection.Add(node);
                                    }
                                    else if (type == typeof (Connector))
                                    {
                                        Node startNode = null;
                                        Node endNode = null;

                                        var value = reader.GetAttribute("StartNode");
                                        if (value != null)
                                        {
                                            startNode =
                                                NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));
                                        }

                                        value = reader.GetAttribute("EndNode");
                                        if (value != null)
                                            endNode = NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));

                                        value = reader.GetAttribute("StartIndex");
                                        var startIndex = Convert.ToInt32(value);

                                        value = reader.GetAttribute("EndIndex");
                                        var endIndex = Convert.ToInt32(value);


                                        if (startNode != null && endNode != null)
                                        {
                                            var startPort = startNode.OutputPorts[startIndex];
                                            var endPort = endNode.InputPorts[endIndex];

                                            if (startPort != null && endPort != null)
                                            {
                                                var connector = new Connector(this, startPort, endPort);
                                                ConnectorCollection.Add(connector);
                                            }
                                        }
                                    }
                                }
                            }

                            break;
                        case XmlNodeType.Text:

                            break;
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:

                            break;
                        case XmlNodeType.Comment:

                            break;
                        case XmlNodeType.EndElement:

                            break;
                    }
                }
            }


            foreach (var node in tempNodeCollection)
            {
                node.Show();
            }
        }
        internal void DeserializeNetwork(string filePath)
        {
            NewFile();

            // Create an reader
            using (var reader = new XmlTextReader(filePath))
            {
                reader.MoveToContent();

                var enumString = reader.GetAttribute("GraphFlowDirection");

                if (enumString != null)
                {
                    ImportFlowDirection =
                        (GraphFlowDirections)Enum.Parse(typeof(GraphFlowDirections), enumString, true);
                }

                reader.ReadToDescendant("Nodes");

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:

                        if (reader.Name != null)
                        {
                            var type = Type.GetType(reader.Name);

                            if (type == null)
                            {
                                try     // try to find type in entry assembly
                                {
                                    var assembly = Assembly.GetEntryAssembly();
                                    type = assembly.GetTypes().First(t => t.FullName == reader.Name);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }

                                try     // try to find type in ExternalNodeTypes
                                {
                                    type = ExternalNodeTypes.ToArray().First(t => t.FullName == reader.Name);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }
                            }


                            if (type != null)
                            {
                                if (type.IsSubclassOf(typeof(Node)))
                                {
                                    var node = (Node)Activator.CreateInstance(type, this);
                                    node.DeserializeNetwork(reader);
                                    NodeCollection.Add(node);
                                }
                                else if (type == typeof(Connector))
                                {
                                    Node startNode = null;
                                    Node endNode   = null;

                                    var value = reader.GetAttribute("StartNode");
                                    if (value != null)
                                    {
                                        startNode =
                                            NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));
                                    }

                                    value = reader.GetAttribute("EndNode");
                                    if (value != null)
                                    {
                                        endNode = NodeCollection.FirstOrDefault(node => node.Guid == new Guid(value));
                                    }

                                    value = reader.GetAttribute("StartIndex");
                                    var startIndex = Convert.ToInt32(value);

                                    value = reader.GetAttribute("EndIndex");
                                    var endIndex = Convert.ToInt32(value);


                                    if (startNode != null && endNode != null)
                                    {
                                        var startPort = startNode.OutputPorts[startIndex];
                                        var endPort   = endNode.InputPorts[endIndex];

                                        if (startPort != null && endPort != null)
                                        {
                                            var connector = new Connector(this, startPort, endPort);
                                            ConnectorCollection.Add(connector);
                                        }
                                    }
                                }
                            }
                        }

                        break;

                    case XmlNodeType.Text:

                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:

                        break;

                    case XmlNodeType.Comment:

                        break;

                    case XmlNodeType.EndElement:

                        break;
                    }
                }
            }
        }
        /*
         * 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:

                // Do not Delete if there is an ScriptingNode in the selection -> Delete Key is used several times inside ...
                foreach (var node in SelectedNodes)
                {
                    if (node.GetType().ToString() == "TUM.CMS.VPL.Scripting.Nodes.ScriptingNode")
                    {
                        return;
                    }
                    node.Delete();
                }


                SelectedNodes.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))
                {
                    // Do not copy if there is an ScriptingNode in the selection
                    if (SelectedNodes.Any(node => node.GetType().ToString() == "TUM.CMS.VPL.Scripting.Nodes.ScriptingNode"))
                    {
                        return;
                    }

                    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);

                    SelectedNodes.Clear();

                    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);

                        NodeCollection.Add(newNode);

                        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.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;
            }
        }
Пример #6
0
        private void Port_MouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (ParentNode.HostCanvas.SplineMode)
            {
            case SplineModes.Nothing:
                ParentNode.HostCanvas.TempStartPort = this;
                ParentNode.HostCanvas.SplineMode    = SplineModes.Second;
                break;

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

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

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

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

                                ConnectedConnectors.Clear();
                            }
                        }

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

                    ParentNode.HostCanvas.ConnectorCollection.Add(connector);
                }


                ParentNode.HostCanvas.SplineMode = SplineModes.Nothing;
                ParentNode.HostCanvas.ClearTempLine();
                break;
            }

            e.Handled = true;
        }
Пример #7
0
        private void Port_MouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (hostCanvas.SplineMode)
            {
                case SplineModes.Nothing:

                    if (PortType== PortTypes.Input && !MultipleConnectionsAllowed && ConnectedConnectors.Count > 0)
                    {
                        Connector conn = ConnectedConnectors[0];
                        conn.Delete();
                        hostCanvas.TempStartPort = conn.StartPort;
                    }
                    else
                    {
                        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);
                        }


                        connector.SynchroniseAfterZoom();
                        hostCanvas.ConnectorCollection.Add(connector);
                    }


                    hostCanvas.SplineMode = SplineModes.Nothing;
                    hostCanvas.ClearTempLine();
                    break;
            }

            e.Handled = true;
        }
Пример #8
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:

                    // Do not Delete if there is an ScriptingNode in the selection -> Delete Key is used several times inside ... 
                    foreach (var node in SelectedNodes)
                    {
                        if (node.GetType().ToString() == "TUM.CMS.VPL.Scripting.Nodes.ScriptingNode")
                            return;
                        node.Delete();
                    }
                        

                    SelectedNodes.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))
                    {
                        // Do not copy if there is an ScriptingNode in the selection
                        if (SelectedNodes.Any(node => node.GetType().ToString() == "TUM.CMS.VPL.Scripting.Nodes.ScriptingNode"))
                        {
                            return;
                        }

                        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);

                        SelectedNodes.Clear();

                        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);

                            NodeCollection.Add(newNode);

                            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.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;
            }
        }