Пример #1
0
        static void CreateItemizedNode(State state, VSGraphModel graphModel, ref IPortModel outputPortModel)
        {
            ItemizeOptions currentItemizeOptions = state.Preferences.CurrentItemizeOptions;

            // automatically itemize, i.e. duplicate variables as they get connected
            if (!outputPortModel.Connected || currentItemizeOptions == ItemizeOptions.Nothing)
            {
                return;
            }

            INodeModel nodeToConnect = outputPortModel.NodeModel;

            bool itemizeContant = currentItemizeOptions.HasFlag(ItemizeOptions.Constants) &&
                                  nodeToConnect is ConstantNodeModel;
            bool itemizeVariable = currentItemizeOptions.HasFlag(ItemizeOptions.Variables) &&
                                   (nodeToConnect is VariableNodeModel || nodeToConnect is ThisNodeModel);
            bool itemizeSystemConstant = currentItemizeOptions.HasFlag(ItemizeOptions.SystemConstants) &&
                                         nodeToConnect is SystemConstantNodeModel;

            if (itemizeContant || itemizeVariable || itemizeSystemConstant)
            {
                Vector2 offset = Vector2.up * k_NodeOffset;
                nodeToConnect   = graphModel.DuplicateUnstackedNode(outputPortModel.NodeModel, new Dictionary <INodeModel, NodeModel>(), offset);
                outputPortModel = nodeToConnect.OutputsById[outputPortModel.UniqueId];
            }
        }
Пример #2
0
        static void CreateItemizedNode(State state, VSGraphModel graphModel, ref IPortModel outputPortModel)
        {
            ItemizeOptions currentItemizeOptions = state.Preferences.CurrentItemizeOptions;

            // automatically itemize, i.e. duplicate variables as they get connected
            if (outputPortModel.Connected && currentItemizeOptions != ItemizeOptions.Nothing)
            {
                var nodeToConnect = outputPortModel.NodeModel;
                var offset        = Vector2.up * k_NodeOffset;

                if (currentItemizeOptions.HasFlag(ItemizeOptions.Constants) &&
                    nodeToConnect is ConstantNodeModel constantModel)
                {
                    string newName = string.IsNullOrEmpty(constantModel.Title)
                        ? "Temporary"
                        : constantModel.Title + "Copy";
                    nodeToConnect = graphModel.CreateConstantNode(
                        newName,
                        constantModel.Type.GenerateTypeHandle(graphModel.Stencil),
                        constantModel.Position + offset
                        );
                    ((ConstantNodeModel)nodeToConnect).ObjectValue = constantModel.ObjectValue;
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.Variables) &&
                         nodeToConnect is VariableNodeModel variableModel)
                {
                    nodeToConnect = graphModel.CreateVariableNode(variableModel.DeclarationModel,
                                                                  variableModel.Position + offset);
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.Variables) &&
                         nodeToConnect is ThisNodeModel thisModel)
                {
                    nodeToConnect = graphModel.CreateNode <ThisNodeModel>("this", thisModel.Position + offset);
                }
                else if (currentItemizeOptions.HasFlag(ItemizeOptions.SystemConstants) &&
                         nodeToConnect is SystemConstantNodeModel sysConstModel)
                {
                    Action <SystemConstantNodeModel> preDefineSetup = m =>
                    {
                        m.ReturnType    = sysConstModel.ReturnType;
                        m.DeclaringType = sysConstModel.DeclaringType;
                        m.Identifier    = sysConstModel.Identifier;
                    };
                    nodeToConnect = graphModel.CreateNode(sysConstModel.Title, sysConstModel.Position + offset, SpawnFlags.Default, preDefineSetup);
                }

                outputPortModel = nodeToConnect.OutputsById[outputPortModel.UniqueId];
            }
        }
Пример #3
0
        public void Test_CreateEdgeAction_Itemize(TestingMode testingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
        {
            // save initial itemize options
            VSPreferences  pref           = ((TestState)m_Store.GetState()).Preferences;
            ItemizeOptions initialOptions = pref.CurrentItemizeOptions;

            try
            {
                // create int node
                IHasMainOutputPort node0 = makeNode(GraphModel);

                // create Addition node
                BinaryOperatorNodeModel opNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.Add, Vector2.zero);

                // enable Itemize depending on the test case
                var itemizeOptions = ItemizeOptions.Nothing;
                pref.CurrentItemizeOptions = (itemizeTest == ItemizeTestType.Enabled) ? options : itemizeOptions;

                // connect int to first input
                m_Store.Dispatch(new CreateEdgeAction(opNode.InputPortA, node0.OutputPort));
                m_Store.Update();

                // test how the node reacts to getting connected a second time
                TestPrereqActionPostreq(testingMode,
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetNodeCount(), Is.EqualTo(2));
                    Assert.That(GetEdgeCount(), Is.EqualTo(1));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(input1, Is.Not.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);
                    return(new CreateEdgeAction(input1, node0.OutputPort));
                },
                                        () =>
                {
                    RefreshReference(ref node0);
                    RefreshReference(ref opNode);
                    var binOp            = GraphModel.GetAllNodes().OfType <BinaryOperatorNodeModel>().First();
                    IPortModel input0    = binOp.InputPortA;
                    IPortModel input1    = binOp.InputPortB;
                    IPortModel binOutput = binOp.OutputPort;
                    Assert.That(GetEdgeCount(), Is.EqualTo(2));
                    Assert.That(input0, Is.ConnectedTo(node0.OutputPort));
                    Assert.That(binOutput.Connected, Is.False);

                    if (itemizeTest == ItemizeTestType.Enabled)
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(3));
                        IHasMainOutputPort newNode = GetNode(2) as IHasMainOutputPort;
                        Assert.NotNull(newNode);
                        Assert.That(newNode, Is.TypeOf(node0.GetType()));
                        IPortModel output1 = newNode.OutputPort;
                        Assert.That(input1, Is.ConnectedTo(output1));
                    }
                    else
                    {
                        Assert.That(GetNodeCount(), Is.EqualTo(2));
                    }
                });
            }
            finally
            {
                // restore itemize options
                pref.CurrentItemizeOptions = initialOptions;
            }
        }
Пример #4
0
 static object[] MakeItemizeTestCase(TestingMode testingMode, ItemizeOptions options, ItemizeTestType itemizeTest, Func <VSGraphModel, IHasMainOutputPort> makeNode)
 {
     return(new object[] { testingMode, options, itemizeTest, makeNode });
 }