protected IEnumerator CreateConnectedNodes(Vector2 firstNodePos, Vector2 secondNodePos, Vector2 thirdNodePos, Vector2 fourthNodePos, bool isVerticalPort)
        {
            var orientation = isVerticalPort ? PortOrientation.Vertical : PortOrientation.Horizontal;

            FirstNodeModel  = CreateNode("Node1", firstNodePos, 0, 0, 0, 1, orientation);
            SecondNodeModel = CreateNode("Node2", secondNodePos, 0, 0, 0, 1, orientation);
            ThirdNodeModel  = CreateNode("Node3", thirdNodePos, 0, 0, 1, 1, orientation);
            FourthNodeModel = CreateNode("Node4", fourthNodePos, 0, 0, 1, 0, orientation);

            MarkGraphViewStateDirty();
            yield return(null);

            IPortModel outputPortFirstNode  = FirstNodeModel.OutputsByDisplayOrder[0];
            IPortModel outputPortSecondNode = SecondNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortFirstNode);
            Assert.IsNotNull(outputPortSecondNode);

            IPortModel intputPortThirdNode = ThirdNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortThirdNode = ThirdNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(intputPortThirdNode);
            Assert.IsNotNull(outputPortThirdNode);

            IPortModel inputPortFourthNode = FourthNodeModel.InputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFourthNode);

            // Connect the ports together
            var actions = ConnectPorts(outputPortFirstNode, intputPortThirdNode);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, intputPortThirdNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortThirdNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            // Get the UI nodes
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            Assert.IsNotNull(m_FirstNode);
            Assert.IsNotNull(m_SecondNode);
            Assert.IsNotNull(m_ThirdNode);
            Assert.IsNotNull(m_FourthNode);
        }
        IEnumerator AlignElements(AutoAlignmentHelper.AlignmentReference reference)
        {
            m_AlignmentHelper.SendAlignCommand(reference);
            yield return(null);

            // Get the UI elements
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            m_Placemat   = PlacematModel.GetUI <Placemat>(graphView);
            m_StickyNote = StickyNoteModel.GetUI <StickyNote>(graphView);
        }
Example #3
0
        IEnumerator SpaceElements(PortOrientation orientation)
        {
            m_AutoSpacingHelper.SendSpacingCommand(orientation);
            yield return(null);

            // Get the UI elements
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            m_Placemat   = PlacematModel.GetUI <Placemat>(graphView);
            m_StickyNote = StickyNoteModel.GetUI <StickyNote>(graphView);
        }
        public IEnumerator NodeIsItsOwnParent()
        {
            // Config   +---------+
            //          |+-------+|                    +-------+
            //          +o Node2 o+-+                +-o Node5 |
            //           +-------+  |   +-------+    | +-------+
            // +-------+ +-------+  +-+-o Node4 o-+--+
            // | Node1 o-o Node3 o--+   +-------+
            // +-------+ +-------+

            Vector2 firstNodePos  = new Vector2(0, 400);
            Vector2 secondNodePos = new Vector2(200, 0);
            Vector2 thirdNodePos  = new Vector2(200, 400);
            Vector2 fourthNodePos = new Vector2(400, 200);
            Vector2 fifthNodePos  = new Vector2(600, 10);

            FirstNodeModel  = CreateNode("Node1", firstNodePos, 0, 0, 0, 1);
            SecondNodeModel = CreateNode("Node2", secondNodePos, 0, 0, 1, 1);
            ThirdNodeModel  = CreateNode("Node3", thirdNodePos, 0, 0, 1, 1);
            FourthNodeModel = CreateNode("Node4", fourthNodePos, 0, 0, 1, 1);
            var fifthNodeModel = CreateNode("Node5", fifthNodePos, 0, 0, 1);

            MarkGraphViewStateDirty();
            yield return(null);

            IPortModel outputPortFirstNode = FirstNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortFirstNode);

            IPortModel inputPortSecondNode  = SecondNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortSecondNode = SecondNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortSecondNode);
            Assert.IsNotNull(outputPortSecondNode);

            IPortModel inputPortThirdNode  = ThirdNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortThirdNode = ThirdNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortThirdNode);
            Assert.IsNotNull(outputPortThirdNode);

            IPortModel inputPortFourthNode  = FourthNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortFourthNode = FourthNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFourthNode);
            Assert.IsNotNull(outputPortFourthNode);

            IPortModel inputPortFifthNode = fifthNodeModel.InputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFifthNode);

            // Connect the ports together
            var actions = ConnectPorts(outputPortFirstNode, inputPortThirdNode);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            // Connect to itself
            actions = ConnectPorts(outputPortSecondNode, inputPortSecondNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortThirdNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortFourthNode, inputPortFifthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Assert.AreEqual(5, GraphModel.EdgeModels.Count, "Not all edges were created.");

            // Get the UI nodes
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            var fifthNode = fifthNodeModel.GetUI <Node>(graphView);

            Assert.IsNotNull(m_FirstNode);
            Assert.IsNotNull(m_SecondNode);
            Assert.IsNotNull(m_ThirdNode);
            Assert.IsNotNull(m_FourthNode);
            Assert.IsNotNull(fifthNode);

            SelectConnectedNodes();
            yield return(null);

            // Select node 5
            Vector2 selectionPosNode5 = graphView.ContentViewContainer.LocalToWorld(fifthNode.layout.position) + k_SelectionOffset;

            actions = SelectElement(selectionPosNode5);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            float expectedDistanceBetweenSecondThird = m_ThirdNode.layout.yMin - m_SecondNode.layout.yMax;
            float expectedTop = GraphViewStaticBridge.RoundToPixelGrid(0f);

            actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Top);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            fifthNode = fifthNodeModel.GetUI <Node>(graphView);
            Assert.IsNotNull(fifthNode);

            // Nodes 2, 3 are part of the same group: they move together
            Assert.AreEqual(expectedTop, m_SecondNode.layout.yMin);
            Assert.AreNotEqual(expectedTop, m_ThirdNode.layout.yMin);
            Assert.AreEqual(expectedDistanceBetweenSecondThird, m_ThirdNode.layout.yMin - m_SecondNode.layout.yMax);

            // Nodes 1, 4 and 5 move individually
            Assert.AreEqual(expectedTop, m_FirstNode.layout.yMin);
            Assert.AreEqual(expectedTop, m_FourthNode.layout.yMin);
            Assert.AreEqual(expectedTop, fifthNode.layout.yMin);

            var nodeDependencies = m_AlignmentHelper.NodeDependencies;

            // There should be 3 parents
            Assert.AreEqual(3, nodeDependencies.Keys.Count);

            // Node 2 should not be considered a parent even if it is its own parent
            Assert.False(nodeDependencies.ContainsKey(SecondNodeModel));

            // Node 3 should be parent to Node 1
            Assert.True(nodeDependencies.ContainsKey(ThirdNodeModel));
            Assert.AreEqual(1, nodeDependencies[ThirdNodeModel].Count);
            Assert.True(nodeDependencies[ThirdNodeModel].Contains(FirstNodeModel));

            // Node 4 should be parent to Nodes 2,3
            Assert.True(nodeDependencies.ContainsKey(FourthNodeModel));
            Assert.AreEqual(2, nodeDependencies[FourthNodeModel].Count);
            Assert.True(nodeDependencies[FourthNodeModel].Contains(SecondNodeModel));
            Assert.True(nodeDependencies[FourthNodeModel].Contains(ThirdNodeModel));

            // Node 5 should be parent to Node 4
            Assert.True(nodeDependencies.ContainsKey(fifthNodeModel));
            Assert.AreEqual(1, nodeDependencies[fifthNodeModel].Count);
            Assert.True(nodeDependencies[fifthNodeModel].Contains(FourthNodeModel));
        }
        public IEnumerator GetNodeDependencies()
        {
            // Config
            //           +-------+                      +-------+
            //           | Node2 o--+---------------+---o Node5 |
            //           +-------+  |   +-------+   |   +-------+
            // +-------+ +-------+  +---o Node4 o---+
            // | Node1 o-o Node3 o--+   +-------+
            // +-------+ +-------+

            Vector2 firstNodePos  = new Vector2(0, 400);
            Vector2 secondNodePos = new Vector2(200, 10);
            Vector2 thirdNodePos  = new Vector2(200, 400);
            Vector2 fourthNodePos = new Vector2(400, 200);
            Vector2 fifthNodePos  = new Vector2(600, 0);

            FirstNodeModel  = CreateNode("Node1", firstNodePos, 0, 0, 0, 1);
            SecondNodeModel = CreateNode("Node2", secondNodePos, 0, 0, 0, 1);
            ThirdNodeModel  = CreateNode("Node3", thirdNodePos, 0, 0, 1, 1);
            FourthNodeModel = CreateNode("Node4", fourthNodePos, 0, 0, 1, 1);
            var fifthNodeModel = CreateNode("Node5", fifthNodePos, 0, 0, 1);

            MarkGraphViewStateDirty();
            yield return(null);

            IPortModel outputPortFirstNode = FirstNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortFirstNode);

            IPortModel outputPortSecondNode = SecondNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortSecondNode);

            IPortModel inputPortThirdNode  = ThirdNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortThirdNode = ThirdNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortThirdNode);
            Assert.IsNotNull(outputPortThirdNode);

            IPortModel inputPortFourthNode  = FourthNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortFourthNode = FourthNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFourthNode);
            Assert.IsNotNull(outputPortFourthNode);

            IPortModel inputPortFifthNode = fifthNodeModel.InputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFifthNode);

            // Connect the ports together
            var actions = ConnectPorts(outputPortFirstNode, inputPortThirdNode);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortThirdNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, inputPortFifthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortFourthNode, inputPortFifthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Assert.AreEqual(5, GraphModel.EdgeModels.Count, "Not all edges were created.");

            // Get the UI nodes
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            var fifthNode = fifthNodeModel.GetUI <Node>(graphView);

            Assert.IsNotNull(m_FirstNode);
            Assert.IsNotNull(m_SecondNode);
            Assert.IsNotNull(m_ThirdNode);
            Assert.IsNotNull(m_FourthNode);
            Assert.IsNotNull(fifthNode);

            SelectConnectedNodes();
            yield return(null);

            // Select node 5
            Vector2 selectionPosNode5 = graphView.ContentViewContainer.LocalToWorld(fifthNode.layout.position) + k_SelectionOffset;

            actions = SelectElement(selectionPosNode5);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Top);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            fifthNode = fifthNodeModel.GetUI <Node>(graphView);
            Assert.IsNotNull(fifthNode);

            var nodeDependencies = m_AlignmentHelper.NodeDependencies;

            // There should be two parents
            Assert.AreEqual(2, nodeDependencies.Keys.Count);

            // Node 3 should be parent to Node 1
            Assert.True(nodeDependencies.ContainsKey(ThirdNodeModel));
            Assert.AreEqual(1, nodeDependencies[ThirdNodeModel].Count);
            Assert.True(nodeDependencies[ThirdNodeModel].Contains(FirstNodeModel));
        }
        public IEnumerator AlignComplexConnectedNodes()
        {
            // Config
            //           +-------+                      +-------+
            //           | Node2 o--+---------------+---o Node5 |
            //           +-------+  |   +-------+   |   +-------+
            // +-------+ +-------+  +---o Node4 o---+
            // | Node1 o-o Node3 o--+   +-------+
            // +-------+ +-------+

            Vector2 firstNodePos  = new Vector2(0, 400);
            Vector2 secondNodePos = new Vector2(200, 10);
            Vector2 thirdNodePos  = new Vector2(200, 400);
            Vector2 fourthNodePos = new Vector2(400, 200);
            Vector2 fifthNodePos  = new Vector2(600, 0);

            FirstNodeModel  = CreateNode("Node1", firstNodePos, 0, 0, 0, 1);
            SecondNodeModel = CreateNode("Node2", secondNodePos, 0, 0, 0, 1);
            ThirdNodeModel  = CreateNode("Node3", thirdNodePos, 0, 0, 1, 1);
            FourthNodeModel = CreateNode("Node4", fourthNodePos, 0, 0, 1, 1);
            var fifthNodeModel = CreateNode("Node5", fifthNodePos, 0, 0, 1);

            MarkGraphViewStateDirty();
            yield return(null);

            IPortModel outputPortFirstNode = FirstNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortFirstNode);

            IPortModel outputPortSecondNode = SecondNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(outputPortSecondNode);

            IPortModel inputPortThirdNode  = ThirdNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortThirdNode = ThirdNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortThirdNode);
            Assert.IsNotNull(outputPortThirdNode);

            IPortModel inputPortFourthNode  = FourthNodeModel.InputsByDisplayOrder[0];
            IPortModel outputPortFourthNode = FourthNodeModel.OutputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFourthNode);
            Assert.IsNotNull(outputPortFourthNode);

            IPortModel inputPortFifthNode = fifthNodeModel.InputsByDisplayOrder[0];

            Assert.IsNotNull(inputPortFifthNode);

            // Connect the ports together
            var actions = ConnectPorts(outputPortFirstNode, inputPortThirdNode);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortThirdNode, inputPortFourthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortSecondNode, inputPortFifthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = ConnectPorts(outputPortFourthNode, inputPortFifthNode);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Assert.AreEqual(5, GraphModel.EdgeModels.Count, "Not all edges were created.");

            // Get the UI nodes
            m_FirstNode  = FirstNodeModel.GetUI <Node>(graphView);
            m_SecondNode = SecondNodeModel.GetUI <Node>(graphView);
            m_ThirdNode  = ThirdNodeModel.GetUI <Node>(graphView);
            m_FourthNode = FourthNodeModel.GetUI <Node>(graphView);
            var fifthNode = fifthNodeModel.GetUI <Node>(graphView);

            Assert.IsNotNull(m_FirstNode);
            Assert.IsNotNull(m_SecondNode);
            Assert.IsNotNull(m_ThirdNode);
            Assert.IsNotNull(m_FourthNode);
            Assert.IsNotNull(fifthNode);

            SelectConnectedNodes();
            yield return(null);

            // Select node 5
            Vector2 selectionPosNode5 = graphView.ContentViewContainer.LocalToWorld(fifthNode.layout.position) + k_SelectionOffset;

            actions = SelectElement(selectionPosNode5);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            float expectedDistanceBetweenSecondThird  = m_ThirdNode.layout.yMin - m_SecondNode.layout.yMax;
            float expectedDistanceBetweenSecondFourth = m_FourthNode.layout.yMin - m_SecondNode.layout.yMax;
            float expectedTop = GraphViewStaticBridge.RoundToPixelGrid(0f);

            actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Top);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            fifthNode = fifthNodeModel.GetUI <Node>(graphView);
            Assert.IsNotNull(fifthNode);

            // Nodes 2, 3 and 4 are part of the same group: they move together
            Assert.AreEqual(expectedTop, m_SecondNode.layout.yMin);
            Assert.AreNotEqual(expectedTop, m_ThirdNode.layout.yMin);
            Assert.AreNotEqual(expectedTop, m_FourthNode.layout.yMin);
            Assert.AreEqual(expectedDistanceBetweenSecondThird, m_ThirdNode.layout.yMin - m_SecondNode.layout.yMax);
            Assert.AreEqual(expectedDistanceBetweenSecondFourth, m_FourthNode.layout.yMin - m_SecondNode.layout.yMax);

            // Node 1 and node 5 move individually
            Assert.AreEqual(expectedTop, m_FirstNode.layout.yMin);
            Assert.AreEqual(expectedTop, fifthNode.layout.yMin);
        }