static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);

                    IVariableModel newVariable = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }
                }
            }

            return(previousState);
        }
Exemple #2
0
        static State CreateVariableNodes(State previousState, CreateVariableNodesAction action)
        {
            if (action.VariablesToCreate.Count > 0)
            {
                if (action.ConnectAfterCreation != null)
                {
                    // Delete previous connections
                    if (action.EdgeModelsToDelete.Any())
                    {
                        ((VSGraphModel)previousState.CurrentGraphModel).DeleteEdges(action.EdgeModelsToDelete);
                    }
                }

                bool needToGroup = action.GroupModel != null;
                List <INodeModel> nodesToGroup = needToGroup ? new List <INodeModel>(action.VariablesToCreate.Count) : null;

                foreach (Tuple <IVariableDeclarationModel, Vector2> tuple in action.VariablesToCreate)
                {
                    VSGraphModel   vsGraphModel = ((VSGraphModel)previousState.CurrentGraphModel);
                    IVariableModel newVariable  = vsGraphModel.CreateVariableNode(tuple.Item1, tuple.Item2);

                    if (action.ConnectAfterCreation != null)
                    {
                        var newEdge = ((VSGraphModel)previousState.CurrentGraphModel).CreateEdge(action.ConnectAfterCreation, newVariable.OutputPort);
                        if (action.AutoAlign)
                        {
                            vsGraphModel.LastChanges.ModelsToAutoAlign.Add(newEdge);
                        }
                    }

                    if (needToGroup)
                    {
                        nodesToGroup.Add(newVariable);
                    }
                }

                if (needToGroup)
                {
                    GroupNodeModel.Ungroup(nodesToGroup);

                    ((GroupNodeModel)action.GroupModel).AddNodes(nodesToGroup);
                }
            }

            return(previousState);
        }