Example #1
0
        public void DeleteEdgeModels()
        {
            VSGraphModel graphModel = (VSGraphModel)m_CurrentState?.CurrentGraphModel;

            if (graphModel != null)
            {
                foreach (var edgeModel1 in m_EdgesToDelete)
                {
                    var edgeModel = (EdgeModel)edgeModel1;
                    graphModel.DeleteEdge(edgeModel);
                }
            }
        }
        static State SplitStack(State previousState, SplitStackAction action)
        {
            VSGraphModel graphModel = (VSGraphModel)previousState.CurrentGraphModel;

            Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Move stacked nodes");

            if (action.SplitIndex > 0 && action.SplitIndex < action.StackModel.NodeModels.Count())
            {
                // Get the list of nodes to move to another stack.
                var nodeModels = action.StackModel.NodeModels.Skip(action.SplitIndex).ToList();
                if (nodeModels.Any())
                {
                    // Get old stack (stack A)
                    var stackA = action.StackModel;

                    // Create new stack (stack B).
                    var stackB = graphModel.CreateStack(((NodeModel)stackA).Title + "_split", stackA.Position + Vector2.up * 300);

                    // Move the list of nodes to this new stack.
                    stackB.MoveStackedNodes(nodeModels, 0);

                    // if the stack had a condition node or anything providing the actual port models, we need to move
                    // the nodes BEFORE fetching the port models, as stack.portModels will actually return the condition
                    // port models
                    var stackAOutputPortModel = stackA.OutputPorts.First();
                    var stackBInputPortModel  = stackB.InputPorts.First();
                    var stackBOutputPortModel = stackB.OutputPorts.First();

                    // Connect the edges that were connected to the old stack to the new one.
                    var previousEdgeConnections = graphModel.GetEdgesConnections(stackAOutputPortModel).ToList();
                    foreach (var edge in previousEdgeConnections)
                    {
                        graphModel.CreateEdge(edge.InputPortModel, stackBOutputPortModel);
                        graphModel.DeleteEdge(edge);
                    }

                    // Connect the new stack with the old one.
                    IEdgeModel newEdge = graphModel.CreateEdge(stackBInputPortModel, stackAOutputPortModel);

                    graphModel.LastChanges.ChangedElements.Add(stackA);
                    graphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                }
            }

            return(previousState);
        }