コード例 #1
0
        public void TestLoadingSavedFile07()
        {
            // Create a save file at temp path contain 4 nodes and 3 edges
            // Load the file on a new graph controller instance
            // Check and add another node
            // Overwritten the same file
            // Load the file again in a new graph controller instance
            // Check the number of node
            // Delete temp path
            //
            try
            {
                string commands = @"
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    CreateCodeBlockNode|d:10341.0|d:10228.0|s:
                    BeginNodeEdit|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,Text
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,NorthWest|i:-1|e:System.Windows.Input.ModifierKeys,None
                    EndNodeEdit|u:0x10000001|s:200|b:True
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    CreateIdentifierNode|d:10534.0|d:10264.0
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                    BeginDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:10376.0|d:10242.0
                    EndDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000002|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:10537.0|d:10278.0
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000002|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    CreateCodeBlockNode|d:10352.0|d:10329.0|s:
                    BeginNodeEdit|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,Text
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,NorthWest|i:-1|e:System.Windows.Input.ModifierKeys,None
                    EndNodeEdit|u:0x10000003|s:100|b:True
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0xffffffff|e:DesignScriptStudio.Graph.Core.NodePart,None|i:-1|e:System.Windows.Input.ModifierKeys,None
                    CreateFunctionNode|d:10526.0|d:10354.0|s:|s:+|s:double,double
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                    BeginDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:10379.0|d:10240.0
                    EndDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000004|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:10526.0|d:10365.0
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000004|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                    MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                    BeginDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:10387.0|d:10342.0
                    EndDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000004|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:1|e:System.Windows.Input.ModifierKeys,None|d:10529.0|d:10385.0
                    MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000004|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:1|e:System.Windows.Input.ModifierKeys,None";

                GraphController graphController01 = new GraphController(null);
                bool result = graphController01.RunCommands(commands);
                Assert.AreEqual(true, result);

                string filePath = Path.GetTempPath() + "test.bin";
                graphController01.DoSaveGraph(filePath);
                GraphController graphController02 = new GraphController(null, filePath);

                Assert.AreEqual(4, graphController02.GetVisualNodes().Count);
                IVisualNode node01 = graphController02.GetVisualNodes()[0];
                Assert.AreEqual(NodeType.CodeBlock, node01.VisualType);
                IVisualNode node02 = graphController02.GetVisualNodes()[1];
                Assert.AreEqual(NodeType.Identifier, node02.VisualType);
                IVisualNode node03 = graphController02.GetVisualNodes()[2];
                Assert.AreEqual(NodeType.CodeBlock, node03.VisualType);
                IVisualNode node04 = graphController02.GetVisualNodes()[3];
                Assert.AreEqual(NodeType.Function, node04.VisualType);
                IVisualEdge edge01 = graphController02.GetVisualEdge(0x60000001);
                Assert.IsNotNull(edge01);
                IVisualEdge edge02 = graphController02.GetVisualEdge(0x60000002);
                Assert.IsNotNull(edge02);
                IVisualEdge edge03 = graphController02.GetVisualEdge(0x60000003);
                Assert.IsNotNull(edge03);

                IVisualNode node05 = new CodeBlockNode(graphController02, "a = 1;");
                graphController02.DoSaveGraph(filePath);
                GraphController graphController03 = new GraphController(null, filePath);
                Assert.AreEqual(5, graphController03.GetVisualNodes().Count);
            }
            finally
            {
                string filePath = Path.GetTempPath() + "test.bin";
                File.Delete(filePath);
            }
        }
コード例 #2
0
        public void TestHandleSaveGraphAndLoadGraph()
        {
            try
            {
                GraphController graphController1 = new GraphController(null);
                IVisualNode node1 = new CodeBlockNode(graphController1, "Double Click and Type");
                IVisualNode node2 = new DriverNode(graphController1, Configurations.DriverInitialTextValue);
                IVisualNode node3 = new FunctionNode(graphController1, "", "-", "double,double");
                IVisualNode node4 = new IdentifierNode(graphController1, "c");

                string filePath = Path.GetTempPath() + "test.bin";
                graphController1.DoSaveGraph(filePath);
                GraphController graphController2 = new GraphController(null, filePath);

                Assert.AreEqual(4, graphController2.GetVisualNodes().Count);
            }
            finally
            {
                File.Delete(Path.GetTempPath() + "test.bin");
            }
        }
コード例 #3
0
ファイル: VisualNode.cs プロジェクト: samuto/designscript
        public static IVisualNode Create(IGraphController graphController, IStorage storage)
        {
            if (graphController == null || storage == null)
                throw new ArgumentNullException("graphcontroller, storage");

            storage.Seek(12, SeekOrigin.Current); //Skip NodeSignature
            NodeType type = (NodeType)storage.ReadInteger(FieldCode.NodeType);
            storage.Seek(-24, SeekOrigin.Current); //Shift cursor back to the start point of reading NodeSignature
            VisualNode node = null;
            switch (type)
            {
                case NodeType.CodeBlock:
                    node = new CodeBlockNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Condensed:
                    node = new CondensedNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Driver:
                    node = new DriverNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Function:
                    node = new FunctionNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Identifier:
                    node = new IdentifierNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Property:
                    node = new PropertyNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Render:
                    node = new RenderNode(graphController);
                    node.Deserialize(storage);
                    break;
                default:
                    throw new ArgumentException("Invalid 'nodeType'");
            }

            return node;
        }
コード例 #4
0
        public void TestSerializeNullException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = null;
            IVisualNode node = new CodeBlockNode(graphController, "Double Click and Type");

            Assert.Throws<ArgumentNullException>(() =>
            {
                node.Serialize(storage);
            });
        }
コード例 #5
0
        public void TestSerializeDeserialize()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();

            IVisualNode node1 = new CodeBlockNode(graphController, "Double Click and Type");
            IVisualNode node2 = new CodeBlockNode(graphController, "Double Click and Type");

            node1.Serialize(storage);
            storage.Seek(0, SeekOrigin.Begin);
            node2.Deserialize(storage);

            Assert.AreEqual(NodeType.CodeBlock, node2.VisualType);
            Assert.AreEqual(node1.NodeId, node2.NodeId);
            Assert.AreEqual(true, ((CodeBlockNode)node2).Dirty);
            Assert.AreEqual(((CodeBlockNode)node1).Text, ((CodeBlockNode)node2).Text);
            Assert.AreEqual(((CodeBlockNode)node1).Caption, ((CodeBlockNode)node2).Caption);
            Assert.AreEqual(node1.X, node2.X);
            Assert.AreEqual(node1.Y, node2.Y);
        }
コード例 #6
0
        public void TestDeserilaizeOperationException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();
            IVisualNode node = new CodeBlockNode(graphController, "Double Click and Type");

            ulong signature = Utilities.MakeEightCC('T', 'E', 'S', 'T', ' ', ' ', ' ', ' ');
            storage.WriteUnsignedInteger(signature, 21);
            storage.Seek(0, SeekOrigin.Begin);

            bool result = node.Deserialize(storage);
            Assert.AreEqual(result, false);
        }
コード例 #7
0
        public void TestConstructorFromSnapshotNode()
        {
            IGraphController graphController = new GraphController(null);
            uint id = 0x10000001;
            string content = "a = b;\nc = d;";
            GraphToDSCompiler.SnapshotNode snapshotNode = new GraphToDSCompiler.SnapshotNode(id, GraphToDSCompiler.SnapshotNodeType.CodeBlock, content);
            CodeBlockNode node = new CodeBlockNode(graphController, snapshotNode);

            Assert.IsNotNull(node);
            Assert.AreEqual(id, node.NodeId);
            Assert.AreEqual(content, node.Text);

            uint[] outputSlots = node.GetOutputSlots();
            uint[] inputSlots = node.GetInputSlots();
            Assert.AreEqual(2, outputSlots.Length);
            Assert.AreEqual(2, inputSlots.Length);
        }