/// <summary>
        /// Default command handler.
        /// </summary>
        /// <param name="graphToolState">The state.</param>
        /// <param name="command">The command.</param>
        public static void DefaultCommandHandler(GraphToolState graphToolState, ItemizeNodeCommand command)
        {
            bool undoPushed = false;

            using (var graphUpdater = graphToolState.GraphViewState.UpdateScope)
            {
                var graphModel = graphToolState.GraphViewState.GraphModel;
                foreach (var model in command.Models.Where(m => m is IVariableNodeModel || m is IConstantNodeModel))
                {
                    var edges = graphModel.GetEdgesConnections(model.OutputPort).ToList();

                    for (var i = 1; i < edges.Count; i++)
                    {
                        if (!undoPushed)
                        {
                            undoPushed = true;
                            graphToolState.PushUndo(command);
                        }

                        var newModel = (ISingleOutputPortNodeModel)graphModel.DuplicateNode(model, i * 50 * Vector2.up);
                        graphUpdater.MarkNew(newModel);
                        var edge          = edges[i];
                        var newEdge       = graphModel.CreateEdge(edge.ToPort, newModel.OutputPort);
                        var deletedModels = graphModel.DeleteEdge(edge);
                        graphUpdater.MarkNew(newEdge);
                        graphUpdater.MarkDeleted(deletedModels);
                    }
                }
            }
        }
예제 #2
0
        public static void DefaultHandler(GraphToolState state, RemovePortCommand command)
        {
            state.PushUndo(command);

            using (var graphUpdater = state.GraphViewState.UpdateScope)
            {
                foreach (var nodeModel in command.Models)
                {
                    nodeModel.RemoveIngredientPort();
                    graphUpdater.MarkChanged(nodeModel);
                }
            }
        }
예제 #3
0
        public static void DefaultHandler(GraphToolState state, SetTemperatureCommand command)
        {
            state.PushUndo(command);

            using (var graphUpdater = state.GraphViewState.UpdateScope)
            {
                foreach (var nodeModel in command.Models)
                {
                    nodeModel.Temperature = command.Value;
                    graphUpdater.MarkChanged(nodeModel);
                }
            }
        }
예제 #4
0
        public static void DefaultCommandHandler(GraphToolState graphToolState, SetNumberOfInputPortCommand command)
        {
            if (!command.Models.Any())
            {
                return;
            }

            graphToolState.PushUndo(command);

            using (var graphUpdater = graphToolState.GraphViewState.UpdateScope)
            {
                foreach (var nodeModel in command.Models)
                {
                    nodeModel.InputPortCount = command.Value;
                    nodeModel.DefineNode();
                }
                graphUpdater.MarkChanged(command.Models);
            }
        }
예제 #5
0
        public static void DefaultHandler(GraphToolState state, AddPortCommand command)
        {
            if (!command.Models.Any() || command.m_PortDirection == PortDirection.None)
            {
                return;
            }

            state.PushUndo(command);

            using (var updater = state.GraphViewState.UpdateScope)
            {
                foreach (var nodeModel in command.Models)
                {
                    nodeModel.AddPort(command.m_PortOrientation, command.m_PortDirection);
                }

                updater.MarkChanged(command.Models);
            }
        }
        /// <summary>
        /// Default command handler.
        /// </summary>
        /// <param name="graphToolState">The state.</param>
        /// <param name="command">The command.</param>
        public static void DefaultCommandHandler(GraphToolState graphToolState, LockConstantNodeCommand command)
        {
            if (!command.Models.Any())
            {
                return;
            }

            graphToolState.PushUndo(command);

            using (var graphUpdater = graphToolState.GraphViewState.UpdateScope)
            {
                foreach (var constantNodeModel in command.Models)
                {
                    constantNodeModel.IsLocked = command.Value;
                }

                graphUpdater.MarkChanged(command.Models);
            }
        }
        /// <summary>
        /// Default command handler.
        /// </summary>
        /// <param name="graphToolState">The state.</param>
        /// <param name="command">The command.</param>
        public static void DefaultCommandHandler(GraphToolState graphToolState, ChangeVariableDeclarationCommand command)
        {
            if (!command.Models.Any())
            {
                return;
            }

            graphToolState.PushUndo(command);

            using (var graphUpdater = graphToolState.GraphViewState.UpdateScope)
            {
                foreach (var model in command.Models)
                {
                    model.DeclarationModel = command.Variable;

                    var references = graphToolState.GraphViewState.GraphModel.FindReferencesInGraph <IVariableNodeModel>(command.Variable);
                    graphUpdater.MarkChanged(references);
                }

                graphUpdater.MarkChanged(command.Models);
            }
        }
        /// <summary>
        /// Default command handler.
        /// </summary>
        /// <param name="graphToolState">The state to modify.</param>
        /// <param name="command">The command to apply to the state.</param>
        public static void DefaultCommandHandler(GraphToolState graphToolState, ConvertConstantNodesAndVariableNodesCommand command)
        {
            if ((command.ConstantNodeModels?.Count ?? 0) == 0 && (command.VariableNodeModels?.Count ?? 0) == 0)
            {
                return;
            }

            graphToolState.PushUndo(command);

            using (var graphUpdater = graphToolState.GraphViewState.UpdateScope)
                using (var selectionUpdater = graphToolState.SelectionState.UpdateScope)
                {
                    var graphModel = graphToolState.GraphViewState.GraphModel;

                    foreach (var constantModel in command.ConstantNodeModels ?? Enumerable.Empty <IConstantNodeModel>())
                    {
                        var declarationModel = graphModel.CreateGraphVariableDeclaration(
                            constantModel.Type.GenerateTypeHandle(),
                            constantModel.Type.FriendlyName().CodifyStringInternal(), ModifierFlags.None, true,
                            constantModel.Value.CloneConstant());
                        graphUpdater.MarkNew(declarationModel);

                        var variableModel = graphModel.CreateVariableNode(declarationModel, constantModel.Position);
                        if (variableModel != null)
                        {
                            graphUpdater.MarkNew(variableModel);
                            selectionUpdater.SelectElement(variableModel, true);

                            variableModel.State = constantModel.State;
                            if (constantModel.HasUserColor)
                            {
                                variableModel.Color = constantModel.Color;
                            }
                            foreach (var edge in graphModel.GetEdgesConnections(constantModel.OutputPort).ToList())
                            {
                                var newEdge       = graphModel.CreateEdge(edge.ToPort, variableModel.OutputPort);
                                var deletedModels = graphModel.DeleteEdge(edge);

                                graphUpdater.MarkNew(newEdge);
                                graphUpdater.MarkDeleted(deletedModels);
                                selectionUpdater.SelectElements(deletedModels, false);
                            }
                        }

                        var deletedElements = graphModel.DeleteNode(constantModel, deleteConnections: false);
                        graphUpdater.MarkDeleted(deletedElements);
                        selectionUpdater.SelectElements(deletedElements, false);
                    }

                    foreach (var variableModel in command.VariableNodeModels ?? Enumerable.Empty <IVariableNodeModel>())
                    {
                        if (graphModel.Stencil.GetConstantNodeValueType(variableModel.GetDataType()) == null)
                        {
                            continue;
                        }
                        var constantModel = graphModel.CreateConstantNode(variableModel.GetDataType(), variableModel.Title, variableModel.Position);
                        constantModel.ObjectValue = variableModel.VariableDeclarationModel?.InitializationModel?.ObjectValue;
                        constantModel.State       = variableModel.State;
                        if (variableModel.HasUserColor)
                        {
                            constantModel.Color = variableModel.Color;
                        }
                        graphUpdater.MarkNew(constantModel);
                        selectionUpdater.SelectElement(constantModel, true);

                        var edgeModels = graphModel.GetEdgesConnections(variableModel.OutputPort).ToList();
                        foreach (var edge in edgeModels)
                        {
                            var newEdge       = graphModel.CreateEdge(edge.ToPort, constantModel.OutputPort);
                            var deletedModels = graphModel.DeleteEdge(edge);
                            graphUpdater.MarkNew(newEdge);
                            graphUpdater.MarkDeleted(deletedModels);
                            selectionUpdater.SelectElements(deletedModels, false);
                        }

                        var deletedElements = graphModel.DeleteNode(variableModel, deleteConnections: false);
                        graphUpdater.MarkDeleted(deletedElements);
                        selectionUpdater.SelectElements(deletedElements, false);
                    }
                }
        }