コード例 #1
0
        public void TestConnections()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel();

            nodeA.Outputs.Add(nodeAOutput);

            NodeInputViewModel  nodeBInput  = new NodeInputViewModel();
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel();
            NodeViewModel       nodeB       = new NodeViewModel
            {
                CanBeRemovedByUser = false,
                IsSelected         = true
            };

            nodeB.Inputs.Add(nodeBInput);
            nodeB.Outputs.Add(nodeBOutput);

            NodeInputViewModel nodeCInput = new NodeInputViewModel
            {
                MaxConnections = 2
            };
            NodeViewModel nodeC = new NodeViewModel
            {
                IsSelected = true
            };

            nodeC.Inputs.Add(nodeCInput);

            NodeViewModel nodeD = new NodeViewModel
            {
                IsSelected = true
            };

            NetworkViewModel network = new NetworkViewModel();

            network.Nodes.AddRange(new[] { nodeA, nodeB, nodeC, nodeD });

            Assert.IsTrue(nodeBInput.Connections.Count == 0);

            var conAB = network.ConnectionFactory(nodeBInput, nodeAOutput);
            var conBC = network.ConnectionFactory(nodeCInput, nodeBOutput);

            network.Connections.Add(conAB);
            network.Connections.Add(conBC);

            Assert.IsTrue(Enumerable.SequenceEqual(nodeBInput.Connections.Items, new[] { conAB }));

            network.Connections.Remove(conAB);

            Assert.IsTrue(nodeBInput.Connections.Count == 0);

            var conAC = network.ConnectionFactory(nodeCInput, nodeAOutput);

            network.Connections.Add(conAC);

            Assert.IsTrue(Enumerable.SequenceEqual(nodeCInput.Connections.Items, new[] { conBC, conAC }));
        }
コード例 #2
0
 protected virtual void BindEndpointProperties(NodeOutputViewModel output, NodeInputViewModel input)
 {
     input.WhenAnyValue(vm => vm.Name).BindTo(output, vm => vm.Name);
     output.WhenAnyValue(vm => vm.Name).BindTo(input, vm => vm.Name);
     input.WhenAnyValue(vm => vm.SortIndex).BindTo(output, vm => vm.SortIndex);
     output.WhenAnyValue(vm => vm.SortIndex).BindTo(input, vm => vm.SortIndex);
     input.WhenAnyValue(vm => vm.Icon).BindTo(output, vm => vm.Icon);
     output.WhenAnyValue(vm => vm.Icon).BindTo(input, vm => vm.Icon);
 }
コード例 #3
0
        public override NodeOutputViewModel AddNewGroupNodeOutput(NodeInputViewModel candidateInput)
        {
            NodeOutputViewModel output = CreateCompatibleOutput((dynamic)candidateInput);

            GroupNode.Outputs.Add(output);
            // Append to bottom of list
            output.SortIndex = GroupNode.Outputs.Items.Select(o => o.SortIndex).DefaultIfEmpty(-1).Max() + 1;
            return(output);
        }
コード例 #4
0
        public void TestConnections()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel
            {
                Outputs = { nodeAOutput }
            };

            NodeInputViewModel nodeBInput = new NodeInputViewModel();
            NodeViewModel      nodeB      = new NodeViewModel
            {
                Inputs = { nodeBInput }
            };

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                Inputs = { nodeCInput }
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC }
            };

            Assert.AreEqual(0, nodeAOutput.Connections.Count);

            var conAB = network.ConnectionFactory(nodeBInput, nodeAOutput);

            network.Connections.Add(conAB);

            Assert.IsTrue(nodeAOutput.Connections.SequenceEqual(new[]
            {
                conAB
            }));

            var conAC = network.ConnectionFactory(nodeCInput, nodeAOutput);

            network.Connections.Add(conAC);

            Assert.IsTrue(nodeAOutput.Connections.SequenceEqual(new []
            {
                conAB, conAC
            }));

            network.Connections.Remove(conAB);

            Assert.IsTrue(nodeAOutput.Connections.SequenceEqual(new[]
            {
                conAC
            }));

            network.Connections.Remove(conAC);

            Assert.AreEqual(0, nodeAOutput.Connections.Count);
        }
コード例 #5
0
        public void TestCutLine()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel();

            nodeA.Outputs.Add(nodeAOutput);

            NodeInputViewModel  nodeBInput  = new NodeInputViewModel();
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel();
            NodeViewModel       nodeB       = new NodeViewModel
            {
                CanBeRemovedByUser = false,
                IsSelected         = true
            };

            nodeB.Inputs.Add(nodeBInput);
            nodeB.Outputs.Add(nodeBOutput);

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                IsSelected = true
            };

            nodeC.Inputs.Add(nodeCInput);

            NodeViewModel nodeD = new NodeViewModel
            {
                IsSelected = true
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC, nodeD }
            };

            var conAB = network.ConnectionFactory(nodeBInput, nodeAOutput);
            var conBC = network.ConnectionFactory(nodeCInput, nodeBOutput);

            network.Connections.Add(conAB);
            network.Connections.Add(conBC);

            network.StartCut();
            network.CutLine.IntersectingConnections.Add(conAB);
            network.FinishCut();

            Assert.IsTrue(network.Connections.Items.SequenceEqual(new [] { conBC }));
            Assert.IsFalse(network.CutLine.IsVisible);
        }
コード例 #6
0
        public void TestValidateAfterConnectionsAllUpdated()
        {
            NodeInputViewModel  input1  = new NodeInputViewModel();
            NodeOutputViewModel output1 = new NodeOutputViewModel();
            NodeViewModel       node1   = new NodeViewModel
            {
                Inputs  = { input1 },
                Outputs = { output1 }
            };

            NodeInputViewModel  input2  = new NodeInputViewModel();
            NodeOutputViewModel output2 = new NodeOutputViewModel();
            NodeViewModel       node2   = new NodeViewModel
            {
                Inputs  = { input2 },
                Outputs = { output2 }
            };

            NetworkViewModel network = new NetworkViewModel();

            network.Validator = n =>
            {
                if (GraphAlgorithms.FindLoops(network).Any())
                {
                    return(new NetworkValidationResult(false, false, null));
                }
                return(new NetworkValidationResult(true, true, null));
            };

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var conn1 = network.ConnectionFactory(input1, output2);

            network.Connections.Add(conn1);

            Assert.IsTrue(network.LatestValidation.IsValid);

            var conn2 = network.ConnectionFactory(input2, output1);

            network.Connections.Add(conn2);

            Assert.IsFalse(network.LatestValidation.IsValid);

            network.Connections.Remove(conn1);

            Assert.IsTrue(network.LatestValidation.IsValid);
        }
コード例 #7
0
ファイル: CutNodeViewModel.cs プロジェクト: LordNed/Winditor
        public void AddPropertiesToNode()
        {
            System.Windows.Point prop_offset = new System.Windows.Point(Position.X - 200, Position.Y + 70);

            for (int i = 0; i < Cut.Properties.Count; i++)
            {
                Substance s = Cut.Properties[i];

                // If we have enough node inputs already, just grab the one corresponding to this property;
                // Otherwise, add a new input to the input view model.
                NodeInputViewModel prop_input = new NodeInputViewModel();
                if (Inputs.Count > i + 1)
                {
                    prop_input = Inputs.Items.ElementAt(i + 1);
                }
                else
                {
                    Inputs.Edit(x => x.Add(prop_input));
                }

                if (Cut.Properties[i] == null)
                {
                    continue;
                }

                prop_input.Connections.Connect()
                .Subscribe(change => {
                    OnPropertyInputChanged(change);
                });

                // Create a node for the property
                SubstanceNodeViewModel temp_node = new SubstanceNodeViewModel(s);
                temp_node.Position = prop_offset;

                Parent.Nodes.Edit(x => x.Add(temp_node));

                prop_offset.Y = (temp_node.Position.Y + temp_node.Size.Height + 125);

                // Connect the property node to the cut node.
                ConnectionViewModel first_to_begin = new ConnectionViewModel(
                    Parent,
                    prop_input,
                    temp_node.Outputs.Items.First());
                Parent.Connections.Edit(x => x.Add(first_to_begin));
            }

            m_EnableConnectionUpdates = true;
        }
コード例 #8
0
        public void TestInputParent()
        {
            NodeInputViewModel input = new NodeInputViewModel();

            Assert.AreEqual(null, input.Parent);

            NodeViewModel node = new NodeViewModel
            {
                Inputs = { input }
            };

            Assert.AreEqual(node, input.Parent);

            node.Inputs.Remove(input);
            Assert.AreEqual(null, input.Parent);
        }
コード例 #9
0
        public ValueNodeGroupIOBinding(NodeViewModel groupNode, NodeViewModel entranceNode, NodeViewModel exitNode)
            : base(groupNode, entranceNode, exitNode)
        {
            // For each input on the group node, create an output in the subnet
            groupNode.Inputs.Connect()
            .Filter(input => input.PortPosition == PortPosition.Left)
            .Transform(i =>
            {
                // Dynamic is applied here so that late binding is used to find the most specific
                // CreateCompatibleOutput variant for this specific input.
                NodeOutputViewModel result = CreateCompatibleOutput((dynamic)i);
                BindOutputToInput((dynamic)result, (dynamic)i);
                return(result);
            }).PopulateInto(entranceNode.Outputs);
            groupNode.Inputs.Connect()
            .Filter(input => input.PortPosition == PortPosition.Right)
            .Transform(i =>
            {
                NodeOutputViewModel result = CreateCompatibleOutput((dynamic)i);
                BindOutputToInput((dynamic)result, (dynamic)i);
                return(result);
            }).PopulateInto(exitNode.Outputs);
            groupNode.Inputs.Connect().OnItemRemoved(input =>
                                                     _outputInputMapping.Remove(
                                                         _outputInputMapping.First(kvp => kvp.Value == input)
                                                         )
                                                     );

            // For each output on the group node, create an input in the subnet
            groupNode.Outputs.Connect()
            .Filter(input => input.PortPosition == PortPosition.Right)
            .Transform(o =>
            {
                NodeInputViewModel result = CreateCompatibleInput((dynamic)o);
                BindOutputToInput((dynamic)o, (dynamic)result);
                return(result);
            }).PopulateInto(exitNode.Inputs);
            groupNode.Outputs.Connect()
            .Filter(input => input.PortPosition == PortPosition.Left)
            .Transform(o =>
            {
                NodeInputViewModel result = CreateCompatibleInput((dynamic)o);
                BindOutputToInput((dynamic)o, (dynamic)result);
                return(result);
            }).PopulateInto(entranceNode.Inputs);
            groupNode.Outputs.Connect().OnItemRemoved(output => _outputInputMapping.Remove(output));
        }
コード例 #10
0
ファイル: MainWindow.xaml.cs プロジェクト: SDellaoui/Nodio
        public MainWindow()
        {
            InitializeComponent();

            //Create a new viewmodel for the NetworkView
            var network = new NetworkViewModel();

            //Create the node for the first node, set its name and add it to the network.
            var node1 = new NodeViewModel();

            node1.Name = "Node 1";
            network.Nodes.Add(node1);

            //Create the viewmodel for the input on the first node, set its name and add it to the node.
            var node1Input = new NodeInputViewModel();

            node1Input.Name = "Node 1 input";
            node1.Inputs.Add(node1Input);

            //Create the second node viewmodel, set its name, add it to the network and add an output in a similar fashion.
            var node2 = new NodeViewModel();

            node2.Name = "Node 2";
            network.Nodes.Add(node2);

            var node2Output = new NodeOutputViewModel();

            node2Output.Name = "Node 2 output";
            node2.Outputs.Add(node2Output);

            //Create a third test node

            var node3 = new NodeViewModel();

            node3.Name = "Test ";
            network.Nodes.Add(node3);

            var node3Input = new ValueNodeInputViewModel <string>();

            node3Input.Name = "Test String";
            node3.Inputs.Add(node3Input);

            //Assign the viewmodel to the view.
            networkView.ViewModel = network;
        }
コード例 #11
0
        public void TestNestedObserving()
        {
            //Setup
            var scheduler = new TestScheduler();

            NodeInputViewModel  input1  = new NodeInputViewModel();
            NodeOutputViewModel output1 = new NodeOutputViewModel();
            NodeViewModel       node1   = new NodeViewModel
            {
                Inputs  = { input1 },
                Outputs = { output1 }
            };

            NodeInputViewModel  input2  = new NodeInputViewModel();
            NodeOutputViewModel output2 = new NodeOutputViewModel();
            NodeViewModel       node2   = new NodeViewModel
            {
                Inputs  = { input2 },
                Outputs = { output2 }
            };

            NetworkViewModel network = new NetworkViewModel();

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var conn1 = network.ConnectionFactory(input1, output2);

            network.Connections.Add(conn1);

            var obs = network.ConnectionsUpdated;


            //Define actions
            scheduler.Schedule(TimeSpan.FromTicks(10), () => network.Connections.Remove(conn1));
            var actual = scheduler.Start(() => obs, created: 0, subscribed: 0, disposed: 100); // But subscribe to it here

            //Assert
            var expected = new[]
            {
                ReactiveTest.OnNext(10, Unit.Default)
            };

            ReactiveAssert.AreElementsEqual(expected, actual.Messages);
        }
コード例 #12
0
        public void TestDeleteNodeShouldRemoveConnections()
        {
            NodeInputViewModel  input1  = new NodeInputViewModel();
            NodeOutputViewModel output1 = new NodeOutputViewModel();
            NodeViewModel       node1   = new NodeViewModel
            {
                Inputs  = { input1 },
                Outputs = { output1 }
            };

            NodeInputViewModel  input2  = new NodeInputViewModel();
            NodeOutputViewModel output2 = new NodeOutputViewModel();
            NodeViewModel       node2   = new NodeViewModel
            {
                Inputs  = { input2 },
                Outputs = { output2 }
            };

            NetworkViewModel network = new NetworkViewModel();

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var conn1 = network.ConnectionFactory(input1, output2);
            var conn2 = network.ConnectionFactory(input2, output1);

            network.Connections.Add(conn1);
            network.Connections.Add(conn2);

            Assert.IsTrue(network.Connections.Contains(conn1));
            Assert.IsTrue(network.Connections.Contains(conn2));
            network.Nodes.Remove(node1);
            Assert.IsFalse(network.Connections.Contains(conn1));
            Assert.IsFalse(network.Connections.Contains(conn2));

            network.Nodes.AddRange(new [] { node1, node2 });
            network.Connections.AddRange(new[] { conn1, conn2 });

            Assert.IsTrue(network.Connections.Contains(conn1));
            Assert.IsTrue(network.Connections.Contains(conn2));
            network.Nodes.Clear();
            Assert.IsFalse(network.Connections.Contains(conn1));
            Assert.IsFalse(network.Connections.Contains(conn2));
        }
コード例 #13
0
        public void TestDeleteSelectedNodes()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel();

            nodeA.Outputs.Add(nodeAOutput);

            NodeInputViewModel  nodeBInput  = new NodeInputViewModel();
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel();
            NodeViewModel       nodeB       = new NodeViewModel
            {
                CanBeRemovedByUser = false,
                IsSelected         = true,
            };

            nodeB.Inputs.Add(nodeBInput);
            nodeB.Outputs.Add(nodeBOutput);

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                IsSelected = true
            };

            nodeC.Inputs.Add(nodeCInput);

            NodeViewModel nodeD = new NodeViewModel
            {
                IsSelected = true
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC, nodeD }
            };

            network.Connections.Add(network.ConnectionFactory(nodeBInput, nodeAOutput));
            network.Connections.Add(network.ConnectionFactory(nodeCInput, nodeBOutput));

            Observable.Return(Unit.Default).InvokeCommand(network.DeleteSelectedNodes);

            Assert.AreEqual(1, network.Connections.Count);
            Assert.IsTrue(network.Nodes.SequenceEqual(new [] { nodeA, nodeB }));
        }
コード例 #14
0
        public NodeViewModel CreateNode()
        {
            NodeInputViewModel input = new NodeInputViewModel
            {
                Name = "A"
            };

            NodeOutputViewModel output = new NodeOutputViewModel
            {
                Name = "B"
            };

            NodeViewModel node = new NodeViewModel();

            node.Inputs.Add(input);
            node.Outputs.Add(output);

            return(node);
        }
コード例 #15
0
        public void TestRectangleSelection()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel();

            nodeA.Outputs.Add(nodeAOutput);

            NodeInputViewModel  nodeBInput  = new NodeInputViewModel();
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel();
            NodeViewModel       nodeB       = new NodeViewModel
            {
                CanBeRemovedByUser = false,
                IsSelected         = true
            };

            nodeB.Inputs.Add(nodeBInput);
            nodeB.Outputs.Add(nodeBOutput);

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                IsSelected = true
            };

            nodeC.Inputs.Add(nodeCInput);

            NodeViewModel nodeD = new NodeViewModel
            {
                IsSelected = true
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC, nodeD }
            };

            network.StartRectangleSelection();
            network.SelectionRectangle.IntersectingNodes.Add(nodeA);
            network.SelectionRectangle.IntersectingNodes.Add(nodeD);
            network.FinishRectangleSelection();

            Assert.IsTrue(network.SelectedNodes.SequenceEqual(new[] { nodeA, nodeD }));
        }
コード例 #16
0
        public void TestConnectionsUpdatedAfterPreexistingConnectionRemoved()
        {
            //Setup
            var scheduler = new TestScheduler();

            NodeInputViewModel  input1  = new NodeInputViewModel();
            NodeOutputViewModel output1 = new NodeOutputViewModel();
            NodeViewModel       node1   = new NodeViewModel();

            node1.Inputs.Add(input1);
            node1.Outputs.Add(output1);

            NodeInputViewModel  input2  = new NodeInputViewModel();
            NodeOutputViewModel output2 = new NodeOutputViewModel();
            NodeViewModel       node2   = new NodeViewModel();

            node2.Inputs.Add(input2);
            node2.Outputs.Add(output2);

            NetworkViewModel network = new NetworkViewModel();

            var observable = network.ConnectionsUpdated; // Create observable before nodes/connections are added

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var conn1 = network.ConnectionFactory(input1, output2);

            network.Connections.Add(conn1);


            //Define actions
            scheduler.Schedule(TimeSpan.FromTicks(10), () => network.Connections.Remove(conn1));
            var actual = scheduler.Start(() => observable, created: 0, subscribed: 0, disposed: 100); // But subscribe to it here

            //Assert
            var expected = new[]
            {
                ReactiveTest.OnNext(10, Unit.Default)
            };

            ReactiveAssert.AreElementsEqual(expected, actual.Messages);
        }
コード例 #17
0
        public NodeViewModel CreateNode()
        {
            NodeInputViewModel input = new NodeInputViewModel
            {
                Name = "A"
            };

            NodeOutputViewModel output = new NodeOutputViewModel
            {
                Name = "B"
            };

            NodeViewModel node = new NodeViewModel
            {
                Inputs  = { input },
                Outputs = { output }
            };

            return(node);
        }
コード例 #18
0
ファイル: CutNodeViewModel.cs プロジェクト: LordNed/Winditor
        public CutNodeViewModel(Cut cut)
        {
            Cut = cut;
            cut.NodeViewModel = this;

            // Create exec input node
            NodeInputViewModel exec_input = new NodeInputViewModel()
            {
                Port = new ExecPortViewModel()
                {
                    PortType = PortType.Execution
                }, MaxConnections = 1
            };

            Inputs.Edit(x => x.Add(exec_input));

            exec_input.Connections.Connect()
            .Subscribe(change => {
                OnExecInputChanged(change);
            });

            // Create exec output node
            NodeOutputViewModel exec_output = new NodeOutputViewModel()
            {
                Port = new ExecPortViewModel()
                {
                    PortType = PortType.Execution
                }, MaxConnections = 1
            };

            Outputs.Edit(x => x.Add(exec_output));

            exec_output.Connections.Connect()
            .Subscribe(change => {
                OnExecOutputChanged(change);
            });

            PropertyChanged += CutNodeViewModel_PropertyChanged;
        }
コード例 #19
0
        public BlockingCutNodeViewModel(Cut cut)
        {
            Cut  = cut;
            Name = "Blocking Actions";
            BlockingCutEditor = new BlockingCutEditorViewModel(cut);

            // Create exec input node
            NodeInputViewModel exec_input = new NodeInputViewModel()
            {
                Port = new ExecPortViewModel()
                {
                    PortType = PortType.Execution
                }, MaxConnections = 1
            };

            Inputs.Edit(x => x.Add(exec_input));

            exec_input.Connections.Connect()
            .Subscribe(change => {
                OnExecInputChanged(change);
            });

            // Create exec output node
            NodeOutputViewModel exec_output = new NodeOutputViewModel()
            {
                Port = new ExecPortViewModel()
                {
                    PortType = PortType.Execution
                }, MaxConnections = 1, Editor = BlockingCutEditor
            };

            Outputs.Edit(x => x.Add(exec_output));

            exec_output.Connections.Connect()
            .Subscribe(change => {
                OnExecOutputChanged(change);
            });
        }
コード例 #20
0
        public void TestNodeCollapse()
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel
            {
                Outputs = { nodeAOutput }
            };

            NodeInputViewModel  nodeBInput   = new NodeInputViewModel();
            NodeInputViewModel  nodeBInput2  = new NodeInputViewModel();
            NodeOutputViewModel nodeBOutput  = new NodeOutputViewModel();
            NodeOutputViewModel nodeBOutput2 = new NodeOutputViewModel();
            NodeViewModel       nodeB        = new NodeViewModel
            {
                Inputs  = { nodeBInput, nodeBInput2 },
                Outputs = { nodeBOutput, nodeBOutput2 }
            };

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                Inputs = { nodeCInput }
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC }
            };

            network.Connections.Add(network.ConnectionFactory(nodeBInput, nodeAOutput));
            network.Connections.Add(network.ConnectionFactory(nodeCInput, nodeBOutput));

            nodeB.IsCollapsed = true;

            Assert.IsTrue(nodeB.VisibleInputs.SequenceEqual(new [] { nodeBInput }));
            Assert.IsTrue(nodeB.VisibleOutputs.SequenceEqual(new[] { nodeBOutput }));
        }
コード例 #21
0
        public void TestDeleteInputShouldRemoveConnections()
        {
            NodeOutputViewModel output = new NodeOutputViewModel();
            NodeViewModel       node1  = new NodeViewModel();

            node1.Outputs.Add(output);

            NodeInputViewModel input = new NodeInputViewModel();
            NodeViewModel      node2 = new NodeViewModel();

            node2.Inputs.Add(input);

            NetworkViewModel network = new NetworkViewModel();

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            var conn = network.ConnectionFactory(input, output);

            network.Connections.Add(conn);

            Assert.IsTrue(input.Connections.Items.Contains(conn));
            Assert.IsTrue(network.Connections.Items.Contains(conn));
            node2.Inputs.Remove(input);
            Assert.IsFalse(input.Connections.Items.Contains(conn));
            Assert.IsFalse(network.Connections.Items.Contains(conn));

            node2.Inputs.Add(input);
            network.Connections.Add(conn);

            Assert.IsTrue(input.Connections.Items.Contains(conn));
            Assert.IsTrue(network.Connections.Items.Contains(conn));
            node2.Inputs.Clear();
            Assert.IsFalse(input.Connections.Items.Contains(conn));
            Assert.IsFalse(network.Connections.Items.Contains(conn));
        }
コード例 #22
0
ファイル: CutNodeViewModel.cs プロジェクト: LordNed/Winditor
        private void AddProperty(Substance Sub, System.Windows.Point Position)
        {
            SubstanceNodeViewModel sub_view = new SubstanceNodeViewModel(Sub);

            sub_view.Position = Position;

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Parent.Nodes.Edit(x => x.Add(sub_view));

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                sub_view.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }
コード例 #23
0
 /// <summary>
 /// Create and add a new input to the group node, along with a corresponding output in the subnet (e.g. on the entrance node).
 /// </summary>
 /// <param name="candidateInput">Input viewmodel that should match the new output that is added to the subnet.</param>
 public abstract NodeOutputViewModel AddNewSubnetInlet(NodeInputViewModel candidateInput);
コード例 #24
0
ファイル: CutNodeViewModel.cs プロジェクト: LordNed/Winditor
        public void CopySettingsFromCamera(WCamera Camera, bool IsStart)
        {
            string EyeName    = IsStart ? "StartEye" : "Eye";
            string CenterName = IsStart ? "StartCenter" : "Center";
            string FovyName   = IsStart ? "StartFovy" : "Fovy";

            List <NodeInputViewModel> ViewModelList = Inputs.Items.ToList();

            ViewModelList.RemoveAt(0); // First input is always the execution input, so skip it because it doesn't matter for properties.

            NodeInputViewModel     EyeNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == EyeName.ToLower());
            SubstanceNodeViewModel EyeNode      = EyeNodeInput != null?EyeNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            NodeInputViewModel     CenterNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == CenterName.ToLower());
            SubstanceNodeViewModel CenterNode      = CenterNodeInput != null?CenterNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            NodeInputViewModel     FovyNodeInput = ViewModelList.Find(x => x.Connections.Items.First().Output.Parent.Name.ToLower() == FovyName.ToLower());
            SubstanceNodeViewModel FovyNode      = FovyNodeInput != null?FovyNodeInput.Connections.Items.First().Output.Parent as SubstanceNodeViewModel : null;

            System.Windows.Point Offset = new System.Windows.Point(Position.X - 375, Position.Y + 50);

            // EyeNode was already attached to this cut
            if (EyeNode != null)
            {
                Substance <ObservableCollection <BindingVector3> > EyeSub = EyeNode.Substance as Substance <ObservableCollection <BindingVector3> >;
                EyeSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(Camera.Transform.Position)
                };
            }
            // EyeNode needs to be added
            else
            {
                Substance <ObservableCollection <BindingVector3> > EyeSub = new Substance <ObservableCollection <BindingVector3> >(EyeName, SubstanceType.Vec3);
                EyeSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(Camera.Transform.Position)
                };

                AddProperty(EyeSub, Offset);
            }

            Offset.Y += 125;

            // CenterNode was already attached to this cut
            if (CenterNode != null)
            {
                Substance <ObservableCollection <BindingVector3> > CenterSub = CenterNode.Substance as Substance <ObservableCollection <BindingVector3> >;
                Vector3 CenterPos = Camera.Transform.Position + (Camera.Transform.Forward * -1000.0f);
                CenterSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(CenterPos)
                };
            }
            // CenterNode needs to be added
            else
            {
                Substance <ObservableCollection <BindingVector3> > CenterSub = new Substance <ObservableCollection <BindingVector3> >(CenterName, SubstanceType.Vec3);
                Vector3 CenterPos = Camera.Transform.Position + (Camera.Transform.Forward * -1000.0f);
                CenterSub.Data = new ObservableCollection <BindingVector3>()
                {
                    new BindingVector3(CenterPos)
                };

                AddProperty(CenterSub, Offset);
            }

            Offset.Y += 125;

            // FovyNode was already attached to this cut
            if (FovyNode != null)
            {
                Substance <ObservableCollection <PrimitiveBinding <float> > > FovySub = FovyNode.Substance as Substance <ObservableCollection <PrimitiveBinding <float> > >;
                FovySub.Data = new ObservableCollection <PrimitiveBinding <float> >()
                {
                    new PrimitiveBinding <float>(Camera.FieldOfView)
                };
            }
            // FovyNode needs to be added
            else
            {
                Substance <ObservableCollection <PrimitiveBinding <float> > > FovySub = new Substance <ObservableCollection <PrimitiveBinding <float> > >(FovyName, SubstanceType.Float);
                FovySub.Data = new ObservableCollection <PrimitiveBinding <float> >()
                {
                    new PrimitiveBinding <float>(Camera.FieldOfView)
                };

                AddProperty(FovySub, Offset);
            }
        }
コード例 #25
0
ファイル: CutNodeViewModel.cs プロジェクト: LordNed/Winditor
        private void OnRequestCreatePropertyNode(Tuple <string, string, SubstanceType> args)
        {
            Substance new_sub = null;

            switch (args.Item3)
            {
            case SubstanceType.Float:
                float FloatDefault = 0.0f;
                float.TryParse(args.Item2, out FloatDefault);

                new_sub = new Substance <ObservableCollection <PrimitiveBinding <float> > >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <PrimitiveBinding <float> >()
                    {
                        new PrimitiveBinding <float>(FloatDefault)
                    }
                };
                break;

            case SubstanceType.Int:
                int IntDefault = 0;
                int.TryParse(args.Item2, out IntDefault);

                new_sub = new Substance <ObservableCollection <PrimitiveBinding <int> > >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <PrimitiveBinding <int> >()
                    {
                        new PrimitiveBinding <int>(IntDefault)
                    }
                };
                break;

            case SubstanceType.String:
                new_sub = new Substance <PrimitiveBinding <string> >(args.Item1, args.Item3)
                {
                    Data = new PrimitiveBinding <string>(args.Item2)
                };
                break;

            case SubstanceType.Vec3:
                new_sub = new Substance <ObservableCollection <BindingVector3> >(args.Item1, args.Item3)
                {
                    Data = new ObservableCollection <BindingVector3>()
                    {
                        new BindingVector3(new OpenTK.Vector3(0, 0, 0))
                    }
                };
                break;
            }

            SubstanceNodeViewModel temp_node = new SubstanceNodeViewModel(new_sub);

            temp_node.Position = Position;

            Parent.Nodes.Edit(x => x.Add(temp_node));

            NodeInputViewModel new_prop_input = new NodeInputViewModel();

            new_prop_input.Connections.Connect()
            .Subscribe(change => {
                OnPropertyInputChanged(change);
            });

            Inputs.Edit(x => x.Add(new_prop_input));

            ConnectionViewModel new_prop_connection = new ConnectionViewModel(
                Parent,
                new_prop_input,
                temp_node.Outputs.Items.First());

            Parent.Connections.Edit(x => x.Add(new_prop_connection));
        }
コード例 #26
0
 /// <summary>
 /// Create and add a new output to the group node, along with a corresponding input in the subnet (e.g. on the exit node).
 /// </summary>
 /// <param name="candidateInput">Input viewmodel that should match the new output on the group node.</param>
 public abstract NodeOutputViewModel AddNewGroupNodeOutput(NodeInputViewModel candidateInput);
コード例 #27
0
        public void TestPortParent()
        {
            NodeInputViewModel input = new NodeInputViewModel();

            Assert.AreEqual(input, input.Port.Parent);
        }
コード例 #28
0
 public CodeGenConnectionViewModel(NetworkViewModel parent, NodeInputViewModel input, NodeOutputViewModel output) : base(parent, input, output)
 {
 }
コード例 #29
0
        private void UpdateNetwork()
        {
            network.Nodes.Clear();
            network.Connections.Clear();

            var stateMachineToDraw = parsed.cStateMachines.ElementAt(Index);

            var states1 = stateMachineToDraw.states.ToDictionary(state => state, state => new NodeViewModel()
            {
                Name = state.Raw.GetParam <string>("name")
            });

            foreach (var state in states1)
            {
                network.Nodes.Add(state.Value);
            }

            var anyStateNode = new NodeViewModel()
            {
                Name = "Any State"
            };

            network.Nodes.Add(anyStateNode);

            if (stateMachineToDraw.wildcardTransitions != null)
            {
                foreach (var trans in stateMachineToDraw.wildcardTransitions)
                {
                    var targetStateNode = states1[trans.targetState];

                    var output = new NodeOutputViewModel();

                    var input = new NodeInputViewModel();

                    anyStateNode.Outputs.Add(output);

                    targetStateNode.Inputs.Add(input);

                    var connection = new ConnectionViewModel(network, input, output);

                    network.Connections.Add(connection);
                }
            }

            foreach (var state in states1)
            {
                var originNode = state.Value;

                if (state.Key.transitions != null)
                {
                    foreach (var trans in state.Key.transitions)
                    {
                        var targetStateNode = states1[trans.targetState];

                        var output = new NodeOutputViewModel();

                        var input = new NodeInputViewModel();

                        originNode.Outputs.Add(output);

                        targetStateNode.Inputs.Add(input);

                        var connection = new ConnectionViewModel(network, input, output);

                        network.Connections.Add(connection);
                    }
                }
            }
        }
コード例 #30
0
        public void TestNodeCollapse(EndpointVisibility visibility, bool nonCollapsedNonConnectedVisible, bool nonCollapsedConnectedVisible, bool collapsedNonConnectedVisible, bool collapsedConnectedVisible)
        {
            NodeOutputViewModel nodeAOutput = new NodeOutputViewModel();
            NodeViewModel       nodeA       = new NodeViewModel
            {
                Outputs = { nodeAOutput }
            };

            NodeInputViewModel nodeBInput = new NodeInputViewModel {
                Visibility = visibility
            };
            NodeInputViewModel nodeBInput2 = new NodeInputViewModel {
                Visibility = visibility
            };
            NodeOutputViewModel nodeBOutput = new NodeOutputViewModel {
                Visibility = visibility
            };
            NodeOutputViewModel nodeBOutput2 = new NodeOutputViewModel {
                Visibility = visibility
            };
            NodeViewModel nodeB = new NodeViewModel
            {
                Inputs  = { nodeBInput, nodeBInput2 },
                Outputs = { nodeBOutput, nodeBOutput2 }
            };

            NodeInputViewModel nodeCInput = new NodeInputViewModel();
            NodeViewModel      nodeC      = new NodeViewModel
            {
                Inputs = { nodeCInput }
            };

            NetworkViewModel network = new NetworkViewModel
            {
                Nodes = { nodeA, nodeB, nodeC }
            };

            network.Connections.Add(network.ConnectionFactory(nodeBInput, nodeAOutput));
            network.Connections.Add(network.ConnectionFactory(nodeCInput, nodeBOutput));

            var expectedInputSeq  = Enumerable.Empty <Endpoint>();
            var expectedOutputSeq = Enumerable.Empty <Endpoint>();

            if (nonCollapsedConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput });
            }
            if (nonCollapsedNonConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput2 });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput2 });
            }

            Assert.IsTrue(nodeB.VisibleInputs.SequenceEqual(expectedInputSeq));
            Assert.IsTrue(nodeB.VisibleOutputs.SequenceEqual(expectedOutputSeq));

            nodeB.IsCollapsed = true;

            expectedInputSeq  = Enumerable.Empty <Endpoint>();
            expectedOutputSeq = Enumerable.Empty <Endpoint>();

            if (collapsedConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput });
            }
            if (collapsedNonConnectedVisible)
            {
                expectedInputSeq  = expectedInputSeq.Concat(new[] { nodeBInput2 });
                expectedOutputSeq = expectedOutputSeq.Concat(new[] { nodeBOutput2 });
            }

            Assert.IsTrue(nodeB.VisibleInputs.SequenceEqual(expectedInputSeq));
            Assert.IsTrue(nodeB.VisibleOutputs.SequenceEqual(expectedOutputSeq));
        }