Ejemplo n.º 1
0
        internal bool RunCommands(string inputCommands)
        {
            inputCommands = inputCommands.Replace("\r\n", "\n");
            char[]   delimiter = new char[] { '\n' };
            string[] commands  = inputCommands.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);

            if (null == commands || (commands.Length == 0))
            {
                return(false);
            }

            foreach (string command in commands)
            {
                if (null == command)
                {
                    continue;
                }

                string trimmed = command.Trim();
                if (string.IsNullOrEmpty(trimmed))
                {
                    continue;
                }

                GraphCommand graphCommand = GraphCommand.FromString(trimmed);
                if (!RerouteToHandler(graphCommand))
                {
                    return(false);
                }
            }

            return(true);
        }
        private bool HandleUndoOperation(GraphCommand command)
        {
            DeltaNodes deltaNodes = new DeltaNodes();

            // Start tracking variables being undefined in this process.
            {
                RuntimeStates runtimeStates = this.GetRuntimeStates();
                runtimeStates.BeginDefinitionMonitor();
                this.undoRedoRecorder.Undo(deltaNodes);

                Dictionary <uint, List <string> > undefinedVariables = null;
                runtimeStates.EndDefinitionMonitor(out undefinedVariables);
                deltaNodes.AppendUndefinedVariables(undefinedVariables);
            }

            this.ValidateNodesSyntax(this.nodeCollection.Values.ToList <IVisualNode>());
            this.ValidateDefinedAndReferencedVariables();
            if (false == deltaNodes.IsEmpty)
            {
                this.SynchronizeToLiveRunner(deltaNodes);
            }

            this.UpdateDirtyNodes();
            this.edgeController.UpdateDirtyEdges(deltaNodes.ModifiedNodes);
            selectionBox.UpdateSelectionBox(GetSelectedNodes());
            return(true);
        }
        public bool DoTogglePreview(uint bubbleId)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.TogglePreview);

            command.AppendArgument(bubbleId);
            return(RerouteToHandler(command));
        }
        private bool HandleSelectComponent(GraphCommand command)
        {
            uint         compId    = (uint)command.GetArgument(0);
            ModifierKeys modifiers = ((ModifierKeys)command.GetArgument(1));

            IVisualNode selectedNode = null;

            nodeCollection.TryGetValue(compId, out selectedNode);

            if (selectedNode != null)
            {
                VisualNode node = (VisualNode)selectedNode;

                if (modifiers.HasFlag(ModifierKeys.Control))//toggle
                {
                    node.Selected = !node.Selected;
                }
                else
                {
                    node.Selected = true;
                }
            }
            else
            {
                edgeController.SelectComponent(compId, modifiers);
            }

            this.selectionBox.UpdateSelectionBox(GetSelectedNodes());
            return(true);
        }
        public bool DoSaveGraph(string filePath)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.SaveGraph);

            command.AppendArgument(filePath);
            return(RerouteToHandler(command));
        }
        public bool DoImportScript(string scriptPath)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.ImportScript);

            command.AppendArgument(scriptPath);
            return(RerouteToHandler(command));
        }
        private bool HandleSetReplicationGuideText(GraphCommand command)
        {
            uint   nodeId           = (uint)command.GetArgument(0);
            int    replicationIndex = (int)command.GetArgument(1);
            string text             = ((string)command.GetArgument(2));

            VisualNode node = GetVisualNode(nodeId);

            if (node.VisualType != NodeType.Function)
            {
                throw new InvalidOperationException("Node must be FunctionNode");
            }

            DeltaNodes  deltaNodes = new DeltaNodes();
            IVisualNode iNode      = this.GetVisualNode(nodeId);

            deltaNodes.AppendToModifiedNodes(iNode);

            FunctionNode fNode = node as FunctionNode;

            undoRedoRecorder.BeginGroup();
            undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
            undoRedoRecorder.EndGroup();
            fNode.SetReplicationText(replicationIndex, text);
            //if(!fNode.SetReplicationText(replicationIndex,text))
            //    undoRedoRecorder.PopRecordFromUndoStorage();
            node.DisableEdit();
            node.Dirty = true;
            node.Compose();
            this.SynchronizeToLiveRunner(deltaNodes);
            return(true);
        }
        private bool HandleCreateCodeBlockNode(GraphCommand command)
        {
            double mouseX  = ((double)command.GetArgument(0));
            double mouseY  = ((double)command.GetArgument(1));
            string content = command.GetArgument(2) as string;

            CodeBlockNode node      = new CodeBlockNode(this, content);
            object        parameter = null;

            int    intResult  = 0;
            bool   boolResult = false;
            double dblResult  = 0;

            if (Int32.TryParse(content, out intResult))
            {
                parameter = intResult;
            }
            else if (Double.TryParse(content, out dblResult))
            {
                parameter = dblResult;
            }
            else if (Boolean.TryParse(content, out boolResult))
            {
                parameter = boolResult;
            }
            else
            {
                parameter = content; // String type.
            }
            this.CreateNodeInternal(node, mouseX, mouseY);
            return(true);
        }
        public bool DoCreateSubRadialMenu(int selectedItemId)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.CreateSubRadialMenu);

            command.AppendArgument(selectedItemId);
            return(RerouteToHandler(command));
        }
        private bool HandleImportScript(GraphCommand command)
        {
            string scriptPath = (string)command.GetArgument(0);

            if (string.IsNullOrEmpty(scriptPath))
            {
                return(false);
            }

            // check if the file is already imported
            if (this.GetImportedScripts().Exists((string file) => scriptPath.Equals(file, StringComparison.InvariantCultureIgnoreCase)))
            {
                CoreComponent.Instance.AddFeedbackMessage(ResourceNames.Error, UiStrings.DuplicateFailure.Replace("fileName", System.IO.Path.GetFileName(scriptPath)));
                return(false);
            }

            if (CoreComponent.Instance.ImportAssembly(scriptPath, this.FilePath, false))
            {
                List <string> scripts = this.GetImportedScripts();
                if (!scripts.Exists((string file) => scriptPath.Equals(file, StringComparison.InvariantCultureIgnoreCase)))
                {
                    scripts.Add(scriptPath);
                }
            }

            return(true);
        }
        public bool DoRemoveReplicationGuide(uint nodeId)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.RemoveReplicationGuide);

            command.AppendArgument(nodeId);
            return(RerouteToHandler(command));
        }
        public bool DoEndHighFrequencyUpdate(string text)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.EndHighFrequencyUpdate);

            command.AppendArgument(text);
            return(RerouteToHandler(command));
        }
        private bool HandleBeginHighFrequencyUpdate(GraphCommand command)
        {
            uint     nodeId   = (uint)command.GetArgument(0);
            NodePart nodePart = ((NodePart)command.GetArgument(1));

            nodeSelectedForHighFrequencyUpdate = GetVisualNode(nodeId);
            if (null == nodeSelectedForHighFrequencyUpdate)
            {
                return(false);
            }

            // @TODO(Ben): The caller would have to specify NodePart in
            // the near future, but for now we are making some assumption.
            //
            switch (nodeSelectedForHighFrequencyUpdate.VisualType)
            {
            case NodeType.Driver:
                nodePart = NodePart.Text;
                break;

            default:
                throw new InvalidOperationException("Not available for other node type (097D3A07D806)");
            }

            nodeSelectedForHighFrequencyUpdate.EnableEdit(nodePart, -1);
            return(true);
        }
        private bool HandleCreateSubRadialMenu(GraphCommand command)
        {
            int selectedItemId = (int)command.GetArgument(0);

            this.itemsProvider.PopulateOverloads(selectedItemId);
            return(true);
        }
        public bool DoCreateRadialMenu(NodePart nodePart, uint nodeId)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.CreateRadialMenu);

            command.AppendArgument(nodePart);
            command.AppendArgument(nodeId);
            return(RerouteToHandler(command));
        }
        public bool DoEditReplicationGuide(uint compId, int replicationIndex)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.EditReplicationGuide);

            command.AppendArgument(compId);
            command.AppendArgument(replicationIndex);
            return(RerouteToHandler(command));
        }
        public bool DoSelectComponent(uint compId, ModifierKeys modifiers)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.SelectComponent);

            command.AppendArgument(compId);
            command.AppendArgument(modifiers);
            return(RerouteToHandler(command));
        }
        public bool DoBeginHighFrequencyUpdate(uint nodeId, NodePart nodePart)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.BeginHighFrequencyUpdate);

            command.AppendArgument(nodeId);
            command.AppendArgument(nodePart);
            return(RerouteToHandler(command));
        }
        public bool DoBeginNodeEdit(uint compId, NodePart nodePart)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.BeginNodeEdit);

            command.AppendArgument(compId);
            command.AppendArgument(nodePart);
            return(RerouteToHandler(command));
        }
        public bool DoCreateDriverNode(double mouseX, double mouseY)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.CreateDriverNode);

            command.AppendArgument(mouseX);
            command.AppendArgument(mouseY);
            return(RerouteToHandler(command));
        }
        private bool HandleCreateRadialMenu(GraphCommand command)
        {
            NodePart part   = ((NodePart)command.GetArgument(0));
            uint     nodeId = (uint)command.GetArgument(1);

            this.itemsProvider = new MenuItemsProvider(this, part, nodeId);
            return(true);
        }
        private bool HandleEndHighFrequencyUpdate(GraphCommand command)
        {
            string text = command.GetArgument(0) as string;

            UpdateNodeTextHighFrequency(text);
            nodeSelectedForHighFrequencyUpdate = null;
            return(true);
        }
        public bool DoCreateCodeBlockNode(double mouseX, double mouseY, string content)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.CreateCodeBlockNode);

            command.AppendArgument(mouseX);
            command.AppendArgument(mouseY);
            command.AppendArgument(content);
            return(RerouteToHandler(command));
        }
        public bool DoEndNodeEdit(uint compId, string text, bool updateFlag)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.EndNodeEdit);

            command.AppendArgument(compId);
            command.AppendArgument(text);
            command.AppendArgument(updateFlag);
            return(RerouteToHandler(command));
        }
        public bool DoSetReplicationGuideText(uint nodeId, int replicationIndex, string text)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.SetReplicationGuide);

            command.AppendArgument(nodeId);
            command.AppendArgument(replicationIndex);
            command.AppendArgument(text);
            return(RerouteToHandler(command));
        }
        private bool HandleEditReplicationGuide(GraphCommand command)
        {
            uint       nodeId           = (uint)command.GetArgument(0);
            int        replicationIndex = (int)command.GetArgument(1);
            VisualNode node             = this.GetVisualNode(nodeId);

            node.EnableEdit(NodePart.ReplicationGuide, replicationIndex);
            return(true);
        }
Ejemplo n.º 27
0
 public void TestToStringForEnum()
 {
     GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation);
     command.AppendArgument(NodeType.Function);
     command.AppendArgument("Math.Sin");
     command.AppendArgument(12.34);
     command.AppendArgument(56.78);
     Assert.AreEqual("UndoOperation|e:DesignScriptStudio.Graph.Core.NodeType,Function|s:Math.Sin|d:12.34|d:56.78", command.ToString());
 }
        private bool HandleCreateDriverNode(GraphCommand command)
        {
            double mouseX = ((double)command.GetArgument(0));
            double mouseY = ((double)command.GetArgument(1));

            DriverNode node = new DriverNode(this, Configurations.DriverInitialTextValue);

            this.CreateNodeInternal(node, mouseX, mouseY);
            return(true);
        }
        private bool HandleCreateRenderNode(GraphCommand command)
        {
            double mouseX = ((double)command.GetArgument(0));
            double mouseY = ((double)command.GetArgument(1));

            RenderNode node = new RenderNode(this, 0);

            this.CreateNodeInternal(node, mouseX, mouseY);
            return(true);
        }
        private bool HandleSaveGraph(GraphCommand command)
        {
            string filePath = command.GetArgument(0) as string;

            this.filePath = filePath;
            this.UpdateImportedLibrary();
            this.SaveFileInternal(filePath);
            this.FireFilePathSavedNotification();

            return(true);
        }
        public bool DoSelectMenuItem(int menuItemId, double x, double y, uint nodeId, NodePart nodePart)
        {
            GraphCommand command = new GraphCommand(GraphCommand.Name.SelectMenuItem);

            command.AppendArgument(menuItemId);
            command.AppendArgument(x);
            command.AppendArgument(y);
            command.AppendArgument(nodeId);
            command.AppendArgument(nodePart);
            return(RerouteToHandler(command));
        }
Ejemplo n.º 32
0
 public void TestToStringForUnsigned()
 {
     GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation);
     command.AppendArgument("Math.Sin");
     command.AppendArgument(12.34);
     command.AppendArgument((uint)5678);
     Assert.AreEqual("UndoOperation|s:Math.Sin|d:12.34|u:0x0000162e", command.ToString());
 }
Ejemplo n.º 33
0
 public void TestToStringWithLineBreak()
 {
     GraphCommand command = new GraphCommand(GraphCommand.Name.EndNodeEdit);
     command.AppendArgument((uint)0x10000001);
     command.AppendArgument("a=3;\nb=4;");
     command.AppendArgument(true);
     Assert.AreEqual("EndNodeEdit|u:0x10000001|s:a=3;\\nb=4;|b:True", command.ToString());
 }
Ejemplo n.º 34
0
 public void TestToStringWithArguments()
 {
     GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation);
     command.AppendArgument(1234);
     command.AppendArgument(56.78);
     command.AppendArgument(true);
     command.AppendArgument("DesignScript Rocks!");
     Assert.AreEqual("UndoOperation|i:1234|d:56.78|b:True|s:DesignScript Rocks!", command.ToString());
 }
Ejemplo n.º 35
0
 public void TestToStringNoArgument()
 {
     GraphCommand command = new GraphCommand(GraphCommand.Name.UndoOperation);
     Assert.AreEqual("UndoOperation", command.ToString());
 }
Ejemplo n.º 36
0
        private void PreProcessCommand(GraphCommand.Name commandName)
        {
            if (commandName == GraphCommand.Name.SaveGraph)
                this.IsModified = true;

            undoStoragePreProcessCommandPosition = undoRedoRecorder.GetUndoPosition();

            //case GraphCommand.Name.SaveGraph:
            //    this.IsModified = false;
            //    break;

            //case GraphCommand.Name.UndoOperation:
            //case GraphCommand.Name.RedoOperation:
            //    // Undo/redo does nothing for modified state.
            //    break;

            //default:
            //    this.IsModified = true;
            //    break;
        }
Ejemplo n.º 37
0
        internal static GraphCommand FromString(string content)
        {
            if (String.IsNullOrEmpty(content))
                throw new ArgumentException("Invalid argument", "content");

            content = content.Trim();
            if (String.IsNullOrEmpty(content))
                throw new ArgumentException("Invalid argument", "content");

            char[] delimiter = new char[] { textDelimiter };
            string[] inputs = content.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            if (null == inputs || (inputs.Length <= 0))
                return null;

            Type enumType = typeof(GraphCommand.Name);
            object commandName = Enum.Parse(enumType, inputs[0]);
            GraphCommand command = new GraphCommand((Name)commandName);

            int inputIndex = 0;
            foreach (string input in inputs)
            {
                // Skip past the command name.
                if (inputIndex++ < 1)
                    continue;

                if (String.IsNullOrEmpty(input))
                    throw new ArgumentException("Invalid argument", "content");
                if ((input.Length < 2) || (input[1] != ':'))
                    throw new ArgumentException("Invalid argument", "content");

                int intValue = 0;
                bool boolValue = false;
                double doubleValue = 0.0;

                string value = input.Substring(2); // Skip past the "x:" portion.

                switch (input[0])
                {
                    case 'b':
                        if (!Boolean.TryParse(value, out boolValue))
                            throw new InvalidCastException("Invalid 'bool' value");
                        command.AppendArgument(boolValue);
                        break;
                    case 'd':
                        if (!Double.TryParse(value, out doubleValue))
                            throw new InvalidCastException("Invalid 'double' value");
                        command.AppendArgument(doubleValue);
                        break;
                    case 'e':
                        int commaIndex = value.IndexOf(',');
                        if (-1 == commaIndex)
                            throw new ArgumentException("Invalid argument", "content");

                        string fullTypeName = value.Substring(0, commaIndex);
                        string enumValue = value.Substring(commaIndex + 1); // Skip ','.
                        System.Type type = GraphCommand.GetEnumType(fullTypeName);
                        command.AppendArgument(Enum.Parse(type, enumValue));
                        break;
                    case 'i':
                        if (!Int32.TryParse(value, out intValue))
                            throw new InvalidCastException("Invalid 'int' value");
                        command.AppendArgument(intValue);
                        break;
                    case 's':
                        string transformed = value.Replace("\\n", "\n");
                        command.AppendArgument(transformed);
                        break;
                    case 'u':
                        if (value.StartsWith("0x") || value.StartsWith("0X"))
                            value = value.Substring(2);

                        uint unsignedValue = UInt32.Parse(value, NumberStyles.HexNumber);
                        command.AppendArgument(unsignedValue);
                        break;
                }
            }

            return command;
        }
Ejemplo n.º 38
0
        private void PostProcessCommand(GraphCommand.Name commandName)
        {
            // The auto-saving timer expires in a given interval, and then it
            // performs auto-saving for recovery later. Once saved, the timer
            // is stopped, until user performs an action that alters the graph
            // content (which is through graph commands channeling through the
            // "RerouteToHandler" method). When the graph is modified, the
            // timer then restarts here and wait for the interval to expire.
            //
            if (null != autoSaveTimer && (false == autoSaveTimer.IsEnabled))
            {
                autoSaveTimer.Stop(); // Just to be 100% sure.
                autoSaveTimer.Start(); // Restart timer.
            }

            long undoStoragePosition = undoRedoRecorder.GetUndoPosition();

            switch (commandName)
            {
                case GraphCommand.Name.UndoOperation:
                case GraphCommand.Name.RedoOperation:
                    break;
                case GraphCommand.Name.SaveGraph:
                    undoStorageSavedPosition = undoStoragePosition;
                    break;
                default:
                    // for the case of action -> save -> undo ->action
                    // then the saved state will never be recovered from undoStorage
                    //
                    if (undoStoragePreProcessCommandPosition > undoStoragePosition // the command actually does some actions
                        && undoStorageSavedPosition >= undoStoragePosition)        // which makes the saved state unreachable
                        undoStorageSavedPosition = 0;
                    break;
            }

            if (undoStorageSavedPosition == undoStoragePosition)
                this.IsModified = false;
            else
                this.IsModified = true;

            undoStoragePreProcessCommandPosition = -1;
        }
Ejemplo n.º 39
0
        private bool RerouteToHandler(GraphCommand command)
        {
            try
            {
                if (null != visualHost && (false != visualHost.IsInRecordingMode))
                    recordedCommands.Add(command.ToString());

                bool callResult = false;
                currentCommand = command.CommandName;
                this.PreProcessCommand(command.CommandName);

                switch (command.CommandName)
                {
                    case GraphCommand.Name.CreateCodeBlockNode:
                        callResult = HandleCreateCodeBlockNode(command);
                        break;
                    case GraphCommand.Name.CreateDriverNode:
                        callResult = HandleCreateDriverNode(command);
                        break;
                    case GraphCommand.Name.CreateFunctionNode:
                        callResult = HandleCreateFunctionNode(command);
                        break;
                    case GraphCommand.Name.CreateIdentifierNode:
                        callResult = HandleCreateIdentifierNode(command);
                        break;
                    case GraphCommand.Name.CreateRenderNode:
                        callResult = HandleCreateRenderNode(command);
                        break;
                    case GraphCommand.Name.CreatePropertyNode:
                        callResult = HandleCreatePropertyNode(command);
                        break;
                    case GraphCommand.Name.SaveGraph:
                        callResult = HandleSaveGraph(command);
                        break;
                    case GraphCommand.Name.MouseDown:
                        callResult = HandleMouseDown(command);
                        break;
                    case GraphCommand.Name.MouseUp:
                        callResult = HandleMouseUp(command);
                        break;
                    case GraphCommand.Name.BeginDrag:
                        callResult = HandleBeginDrag(command);
                        break;
                    case GraphCommand.Name.EndDrag:
                        callResult = HandleEndDrag(command);
                        break;
                    case GraphCommand.Name.BeginNodeEdit:
                        callResult = HandleBeginNodeEdit(command);
                        break;
                    case GraphCommand.Name.EndNodeEdit:
                        callResult = HandleEndNodeEdit(command);
                        break;
                    case GraphCommand.Name.BeginHighFrequencyUpdate:
                        callResult = HandleBeginHighFrequencyUpdate(command);
                        break;
                    case GraphCommand.Name.EndHighFrequencyUpdate:
                        callResult = HandleEndHighFrequencyUpdate(command);
                        break;
                    case GraphCommand.Name.DeleteComponents:
                        callResult = HandleDeleteComponents(command);
                        break;
                    case GraphCommand.Name.SelectComponent:
                        callResult = HandleSelectComponent(command);
                        break;
                    case GraphCommand.Name.ClearSelection:
                        callResult = HandleClearSelection(command);
                        break;
                    case GraphCommand.Name.UndoOperation:
                        callResult = HandleUndoOperation(command);
                        break;
                    case GraphCommand.Name.RedoOperation:
                        callResult = HandleRedoOperation(command);
                        break;
                    case GraphCommand.Name.EditReplicationGuide:
                        callResult = HandleEditReplicationGuide(command);
                        break;
                    case GraphCommand.Name.SetReplicationGuide:
                        callResult = HandleSetReplicationGuideText(command);
                        break;
                    case GraphCommand.Name.SelectMenuItem:
                        callResult = HandleSelectedMenuItem(command);
                        break;
                    case GraphCommand.Name.CreateRadialMenu:
                        callResult = HandleCreateRadialMenu(command);
                        break;
                    case GraphCommand.Name.CreateSubRadialMenu:
                        callResult = HandleCreateSubRadialMenu(command);
                        break;
                    case GraphCommand.Name.ImportScript:
                        callResult = HandleImportScript(command);
                        break;
                    case GraphCommand.Name.ConvertSelectionToCode:
                        callResult = HandleConvertSelectionToCode();
                        break;
                    case GraphCommand.Name.TogglePreview:
                        callResult = HandleTogglePreview(command);
                        break;
                }

                this.PostProcessCommand(this.currentCommand);
                currentCommand = GraphCommand.Name.None;
                return callResult;
            }
            catch (Exception exception)
            {
                if (null != visualHost && (false != visualHost.IsInRecordingMode))
                {
                    string filePath = this.DumpUiStatesToExternalFile(exception);
                    if (System.IO.File.Exists(filePath))
                        System.Diagnostics.Process.Start(filePath);

                    string xmlFilePath = this.DumpVmStatesToExternalFile();
                    if (System.IO.File.Exists(xmlFilePath))
                        System.Diagnostics.Process.Start(xmlFilePath);
                }
                throw exception; // Rethrow to external handler.
            }

            throw new InvalidOperationException("Unhandled command in 'RerouteToHandler'");
        }