public void SwitchingToCustomWorkspaceWithSelectionShouldNotAllowGeometricOperations()
        {
            var model = ViewModel.Model; // The current DynamoModel instance.

            // Step 0: Create a new node in Home workspace.
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            model.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 1);

            // Step 1: Select the newly node, geometry operation should be enabled.
            DynamoSelection.Instance.Selection.Add(addNode);
            Assert.AreEqual(true, ViewModel.CurrentSpaceViewModel.HasSelection);
            Assert.AreEqual(true, ViewModel.CurrentSpaceViewModel.IsGeometryOperationEnabled);

            // Step 2: Open a Custom workspace.
            var customNodePath = Path.Combine(TestDirectory, @"core\CustomNodes\NoInput.dyf");
            ViewModel.OpenCommand.Execute(customNodePath);
            var customWorkspace = model.Workspaces.FirstOrDefault(x => x is CustomNodeWorkspaceModel);
            Assert.IsNotNull(customWorkspace);

            // Step 3: Switch over from home workspace to custom workspace.
            Assert.IsTrue(ViewModel.CurrentSpaceViewModel.Model is HomeWorkspaceModel);
            ViewModel.CurrentWorkspaceIndex = 1;
            Assert.IsTrue(ViewModel.CurrentSpaceViewModel.Model is CustomNodeWorkspaceModel);

            // Step 4: Verify that the geometry operations are 
            // disabled despite the fact that there is still selection.
            Assert.AreEqual(true, ViewModel.CurrentSpaceViewModel.HasSelection);
            Assert.AreEqual(false, ViewModel.CurrentSpaceViewModel.IsGeometryOperationEnabled);
        }
Ejemplo n.º 2
0
        public void CleanWorkbenchClearsUndoStack()
        {
            var dynamoModel = ViewModel.Model;
            Assert.IsNotNull(dynamoModel.CurrentWorkspace);

            var workspace = dynamoModel.CurrentWorkspace;
            Assert.AreEqual(false, workspace.CanUndo);
            Assert.AreEqual(false, workspace.CanRedo);
            Assert.AreEqual(0, workspace.Nodes.Count); // An empty workspace

            var addNode = new DSFunction(dynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            var createNodeCommand = new DynamoModel.CreateNodeCommand(
                addNode, 0, 0, false, false);

            // Create a new node in the empty workspace.
            ViewModel.ExecuteCommand(createNodeCommand);
            Assert.AreEqual(1, workspace.Nodes.Count);

            Assert.AreEqual(true, workspace.CanUndo);
            Assert.AreEqual(false, workspace.CanRedo);
            dynamoModel.CurrentWorkspace.Clear(); // Clearing current workspace.

            // Undo stack should be cleared.
            Assert.AreEqual(false, workspace.CanUndo);
            Assert.AreEqual(false, workspace.CanRedo);
        }
Ejemplo n.º 3
0
        public void CanCreatePreset()
        {
            //Create a Node
            var numberNode = new DoubleInput();
            numberNode.Value = "1";
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(numberNode, false);

            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());
          
            DynamoSelection.Instance.Selection.Add(numberNode);

            //Check for input nodes
            Assert.AreEqual(true, ViewModel.GetSelectedInputNodes().Any());

            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);

            DynamoSelection.Instance.ClearSelection();

            DynamoSelection.Instance.Selection.Add(addNode);

            Assert.AreEqual(false, ViewModel.GetSelectedInputNodes().Any());

            DynamoSelection.Instance.Selection.Add(numberNode);

            //Check for input nodes
            Assert.AreEqual(true, ViewModel.GetSelectedInputNodes().Any());

        }
Ejemplo n.º 4
0
        public void CanCreateGroupIfANodeIsAlreadyInAGroup()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddNode(addNode, false);

            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

            //Select the note for group
            DynamoSelection.Instance.Selection.Add(addNode);

            //Create a Group around that node
            ViewModel.AddAnnotationCommand.Execute(null);
            var annotation = ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault();

            //Check if the group is created
            Assert.IsNotNull(annotation);

            //Clear the selection
            DynamoSelection.Instance.ClearSelection();

            //Select the node again
            DynamoSelection.Instance.Selection.Add(addNode);

            //Check whether group can be created
            Assert.AreEqual(false,ViewModel.CanAddAnnotation(null));

        }
Ejemplo n.º 5
0
        public void DescriptionTest()
        {
            var assembly = System.Reflection.Assembly.UnsafeLoadFrom("FFITarget.dll");
            var testClass = assembly.GetType("FFITarget.DummyZeroTouchClass");

            MethodInfo methodWithDesc = testClass.GetMethod("FunctionWithDescription");
            MethodInfo methodWithoutDesc = testClass.GetMethod("FunctionWithoutDescription");

            NodeDescriptionAttribute atr = new NodeDescriptionAttribute("");
            IEnumerable<TypedParameter> arguments;
            FunctionDescriptor fucDescriptor;

            // 1 case. Method with description.
            var attributes = methodWithDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false);
            Assert.IsNotNull(attributes);
            Assert.Greater(attributes.Length, 0);
            atr = attributes[0] as NodeDescriptionAttribute;
            arguments = methodWithDesc.GetParameters().Select(
                arg =>
                {
                    var type = new ProtoCore.Type();
                    type.Name = arg.ParameterType.ToString();
                    return new TypedParameter(arg.Name, type);
                });

            fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams
            {
                FunctionName = methodWithDesc.Name,
                Summary = atr.ElementDescription,
                Parameters = arguments
            });

            NodeModel node = new DSFunction(fucDescriptor);
            Assert.AreEqual(atr.ElementDescription + "\n\n" + fucDescriptor.Signature, node.Description);

            // 2 case. Method without description.
            atr = new NodeDescriptionAttribute("");
            attributes = methodWithoutDesc.GetCustomAttributes(typeof(NodeDescriptionAttribute), false);
            Assert.IsNotNull(attributes);
            Assert.AreEqual(attributes.Length, 0);
            arguments = methodWithoutDesc.GetParameters().Select(
                arg =>
                {
                    var type = new ProtoCore.Type();
                    type.Name = arg.ParameterType.ToString();
                    return new TypedParameter(arg.Name, type);
                });

            fucDescriptor = new FunctionDescriptor(new FunctionDescriptorParams
            {
                FunctionName = methodWithDesc.Name,
                Summary = atr.ElementDescription,
                Parameters = arguments
            });

            node = new DSFunction(fucDescriptor);
            Assert.AreEqual(fucDescriptor.Signature, node.Description);
        }
Ejemplo n.º 6
0
        public void CanAddToSelectionCommand()
        {
            int numNodes = 100;

            // create 100 nodes, and select them as you go
            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);

                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

                CurrentDynamoModel.AddToSelection(addNode);
                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }
        }
Ejemplo n.º 7
0
        private List<NodeModel> SetupNumberNodesAndPresets()
        {
            var model = CurrentDynamoModel;
            //create some numbers
            var numberNode1 = new DoubleInput();
            numberNode1.Value = "1";
            var numberNode2 = new DoubleInput();
            numberNode2.Value = "2";
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(numberNode1,0,0,true,false));
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(numberNode2, 0, 0, true, false));
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(addNode, 0, 0, true, false));

            //connect them up
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(numberNode1.GUID,0,PortType.Output,DynCmd.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID,0,PortType.Input,DynCmd.MakeConnectionCommand.Mode.End));

            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(numberNode2.GUID,0,PortType.Output,DynCmd.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID,1,PortType.Input,DynCmd.MakeConnectionCommand.Mode.End));

            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3);
            Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2);

            DynamoSelection.Instance.ClearSelection();
            //create the first state with the numbers selected
            DynamoSelection.Instance.Selection.Add(numberNode1);
            DynamoSelection.Instance.Selection.Add(numberNode2);
            var ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
            //create the preset from 2 nodes
            model.ExecuteCommand(new DynamoModel.AddPresetCommand("state1", "3", ids));

            //change values
            numberNode1.Value = "2";
            numberNode2.Value = "3";

            DynamoSelection.Instance.ClearSelection();
            DynamoSelection.Instance.Selection.Add(numberNode1);
            DynamoSelection.Instance.Selection.Add(numberNode2);
            ids = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();

            model.ExecuteCommand(new DynamoModel.AddPresetCommand("state2", "5", ids));

            return new List<NodeModel>() { numberNode1, numberNode2,addNode };
        }
Ejemplo n.º 8
0
        public void TestBasicAttributes()
        {
            var sumNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+")) { X = 400, Y = 100 };

            //Assert inital values
            Assert.AreEqual(400, sumNode.X);
            Assert.AreEqual(100, sumNode.Y);
            Assert.AreEqual("+", sumNode.NickName);
            Assert.AreEqual(LacingStrategy.Shortest, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            Assert.AreEqual(true, sumNode.IsUpstreamVisible);
            Assert.AreEqual(ElementState.Dead, sumNode.State);

            //Serialize node and then change values
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement serializedEl = sumNode.Serialize(xmlDoc, SaveContext.Undo);
            sumNode.X = 250;
            sumNode.Y = 0;
            sumNode.NickName = "TestNode";
            sumNode.UpdateValue(new UpdateValueParams("ArgumentLacing", "CrossProduct"));
            sumNode.UpdateValue(new UpdateValueParams("IsVisible", "false"));
            sumNode.UpdateValue(new UpdateValueParams("IsUpstreamVisible", "false"));
            sumNode.State = ElementState.Active;

            //Assert New Changes
            Assert.AreEqual(250, sumNode.X);
            Assert.AreEqual(0, sumNode.Y);
            Assert.AreEqual("TestNode", sumNode.NickName);
            Assert.AreEqual(LacingStrategy.CrossProduct, sumNode.ArgumentLacing);
            Assert.AreEqual(false, sumNode.IsVisible);
            Assert.AreEqual(false, sumNode.IsUpstreamVisible);
            Assert.AreEqual(ElementState.Active, sumNode.State);

            //Deserialize and Assert Old values
            sumNode.Deserialize(serializedEl, SaveContext.Undo);
            Assert.AreEqual(400, sumNode.X);
            Assert.AreEqual(100, sumNode.Y);
            Assert.AreEqual("+", sumNode.NickName);
            Assert.AreEqual(LacingStrategy.Shortest, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            Assert.AreEqual(true, sumNode.IsUpstreamVisible);
            Assert.AreEqual(ElementState.Dead, sumNode.State);
        }
Ejemplo n.º 9
0
        public void CreateGroupAroundNodes()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddNode(addNode, false);
           
            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

            //Select the note for group
            DynamoSelection.Instance.Selection.Add(addNode);

            //Create a Group around that node
            ViewModel.AddAnnotationCommand.Execute(null);
            var annotation = ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault();
            Assert.IsNotNull(annotation);

            //verify whether group is not empty
            Assert.AreNotEqual(0, annotation.Y);
            Assert.AreNotEqual(0, annotation.X);
            Assert.AreNotEqual(0, annotation.Width);
            Assert.AreNotEqual(0, annotation.Height);           
        }
Ejemplo n.º 10
0
        public void CanAddAnnotation()
        {
            //Add a Node
            var model = CurrentDynamoModel;
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            model.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 1);

            //Add a Note 
            Guid id = Guid.NewGuid();
            var addNote = model.CurrentWorkspace.AddNote(false, 200, 200, "This is a test note", id);
            Assert.AreEqual(model.CurrentWorkspace.Notes.Count(), 1);

            //Select the node and notes
            DynamoSelection.Instance.Selection.Add(addNode);
            DynamoSelection.Instance.Selection.Add(addNote);

            //create the group around selected nodes and notes
            Guid groupid = Guid.NewGuid();
            var annotation = model.CurrentWorkspace.AddAnnotation("This is a test group", groupid);
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 1);
            Assert.AreNotEqual(0, annotation.Width);
        }
Ejemplo n.º 11
0
        public void UndoAnnotationText()
        {
            //Add a Node
            var model = CurrentDynamoModel;
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            model.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 1);

            //Add a Note 
            Guid id = Guid.NewGuid();
            var addNote = model.CurrentWorkspace.AddNote(false, 200, 200, "This is a test note", id);
            Assert.AreEqual(model.CurrentWorkspace.Notes.Count(), 1);

            //Select the node and notes
            DynamoSelection.Instance.Selection.Add(addNode);
            DynamoSelection.Instance.Selection.Add(addNote);

            //create the group around selected nodes and notes
            Guid groupid = Guid.NewGuid();
            var annotation = model.CurrentWorkspace.AddAnnotation("This is a test group", groupid);
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 1);
            Assert.AreNotEqual(0, annotation.Width);

            //Update the Annotation Text
            model.ExecuteCommand(
                    new DynCmd.UpdateModelValueCommand(
                        Guid.Empty, annotation.GUID, "TextBlockText",
                        "This is a unit test"));
            Assert.AreEqual("This is a unit test", annotation.AnnotationText);

            //Undo Annotation text
            model.CurrentWorkspace.Undo();
            
            //Title should be changed now.
            Assert.AreEqual("This is a test group", annotation.AnnotationText);
        }
Ejemplo n.º 12
0
        public void TogglePresetOptionVisibility()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);

            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

            //Check the Preset option visibility.
            Assert.AreEqual(false, ViewModel.EnablePresetOptions);

            DynamoSelection.Instance.Selection.Add(addNode);

            var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
            //create the preset from 2 nodes
            ViewModel.Model.CurrentWorkspace.AddPreset(
                "state1",
                "a state with 2 numbers", IDS);
            //assert that the preset has been created
            Assert.AreEqual(ViewModel.Model.CurrentWorkspace.Presets.Count(), 1);
            Assert.AreEqual(ViewModel.Model.CurrentWorkspace.Presets.First().Nodes.Count(), 1);

            //Check the Preset option visibility.
            Assert.AreEqual(true, ViewModel.EnablePresetOptions);

            //Delete the preset
            //delete state
            var state = ViewModel.Model.CurrentWorkspace.Presets.First();
            ViewModel.Model.CurrentWorkspace.RemovePreset(state);

            Assert.AreEqual(ViewModel.Model.CurrentWorkspace.Presets.Count(), 0);

            //Check the Preset option visibility.
            Assert.AreEqual(false, ViewModel.EnablePresetOptions);
        }
Ejemplo n.º 13
0
        public void CanAdd100NodesToClipboardAndPaste3Times()
        {
            int numNodes = 100;

            // create 100 nodes, and select them as you go
            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

                CurrentDynamoModel.AddToSelection(CurrentDynamoModel.CurrentWorkspace.Nodes.Last());

                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }

            CurrentDynamoModel.Copy();

            Assert.AreEqual(numNodes, CurrentDynamoModel.ClipBoard.Count);

            int numPastes = 3;
            for (int i = 1; i <= numPastes; i++)
            {
                CurrentDynamoModel.Paste();
                Assert.AreEqual(numNodes, CurrentDynamoModel.ClipBoard.Count);
                Assert.AreEqual(numNodes * (i + 1), CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
            }
        }
Ejemplo n.º 14
0
        public void CanClearWorkspaceWithNodes()
        {
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
            CurrentDynamoModel.CurrentWorkspace.AddNode(new DoubleInput(), false);
            CurrentDynamoModel.CurrentWorkspace.AddNode(new DoubleInput(), false);
            Assert.AreEqual(3, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            CurrentDynamoModel.ClearCurrentWorkspace();
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
        }
Ejemplo n.º 15
0
 public void TestDefaultArgumentTooltip()
 {
     var node =
         new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("Autodesk.DesignScript.Geometry.Point.ByCoordinates@double,double"));
     CurrentDynamoModel.ExecuteCommand(new Dynamo.Models.DynamoModel.CreateNodeCommand(node, 0, 0, true, false));
     Assert.IsTrue(node.InPorts[0].ToolTipContent.Equals("double\nDefault value : 0"));
     node.InPorts[0].UsingDefaultValue = false;
     Assert.IsTrue(node.InPorts[0].ToolTipContent.Equals("double\nDefault value : 0 (disabled)"));
 }
Ejemplo n.º 16
0
        public void TestCrossSelectingGroups()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddNode(addNode, false);

            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

            //Select the node for group
            DynamoSelection.Instance.Selection.Add(addNode);

            //Create a Group around that node
            ViewModel.AddAnnotationCommand.Execute(null);
            var annotation = ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault();

            //Check if the group is created
            Assert.IsNotNull(annotation);

            //Clear the selection
            DynamoSelection.Instance.ClearSelection();

            //Get the Rect for the group
            var rect = annotation.Rect;
            ViewModel.CurrentSpaceViewModel.SelectInRegion(rect,true);

            //Check whether group is selected
            Assert.AreEqual(true, annotation.IsSelected);

            //Check whether the model is selected
            Assert.AreEqual(true,addNode.IsSelected);
        }
Ejemplo n.º 17
0
        public void SelectionDoesNotChangeWhenAddingAlreadySelectedNode()
        {
            int numNodes = 100;

            // create 100 nodes, and select them as you go
            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

                CurrentDynamoModel.AddToSelection(CurrentDynamoModel.CurrentWorkspace.Nodes.Last());
                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }

            // the number selected stays the same
            for (int i = 0; i < numNodes; i++)
            {
                CurrentDynamoModel.AddToSelection(CurrentDynamoModel.CurrentWorkspace.Nodes.Last());
                Assert.AreEqual(numNodes, DynamoSelection.Instance.Selection.Count);
            }
        }
Ejemplo n.º 18
0
        public void CannotSavePopulatedWorkspaceIfSaveIsCalledWithoutSettingPath()
        {
            int numNodes = 100;

            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
            }

            CurrentDynamoModel.CurrentWorkspace.Save(CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore);

            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.FileName, string.Empty);
        }
Ejemplo n.º 19
0
        public void CanAddAndRestoreState()
        {
            var model = CurrentDynamoModel;
            //create some numbers
            var numberNode1 = new DoubleInput();
            numberNode1.Value = "1";
            var numberNode2 = new DoubleInput();
            numberNode2.Value = "2";
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

            //add the nodes
            model.CurrentWorkspace.AddNode(numberNode1, false);
            model.CurrentWorkspace.AddNode(numberNode2, false);
            model.CurrentWorkspace.AddNode(addNode, false);

           //connect them up
           ConnectorModel.Make(numberNode1,addNode, 0, 0);
           ConnectorModel.Make(numberNode2,addNode, 0, 1);

           Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3);
           Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2);

            //create the first state with the numbers selected
           DynamoSelection.Instance.Selection.Add(numberNode1);
           DynamoSelection.Instance.Selection.Add(numberNode2);
           var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
           //create the preset from 2 nodes
           model.CurrentWorkspace.AddPreset(
               "state1",
               "3", IDS);

            //change values
           numberNode1.Value = "2";
           numberNode2.Value = "3";

           DynamoSelection.Instance.ClearSelection();
           DynamoSelection.Instance.Selection.Add(numberNode1);
           DynamoSelection.Instance.Selection.Add(numberNode2);
           IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();

           model.CurrentWorkspace.AddPreset(
           "state2",
           "5", IDS);

            //now restore state to state 1
           model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where(
               x => x.Name == "state1").First());

           RunCurrentModel();
           Thread.Sleep(250);
              //assert that the value of the add node is 3
           Assert.AreEqual(addNode.CachedValue.Data, 3);

           //now restore state to state 2
           model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where(
               x => x.Name == "state2").First());

           RunCurrentModel();
           Thread.Sleep(250);
           //assert that the value of the add node is 5
           Assert.AreEqual(addNode.CachedValue.Data, 5);

        }
Ejemplo n.º 20
0
        public void CanRestoreStateAndNodesDoNotMove()
        {
            var model = CurrentDynamoModel;
            //create some numbers
            var numberNode1 = new DoubleInput();
           
            numberNode1.Value = "1";
            var numberNode2 = new DoubleInput();
            numberNode2.Value = "2";
            
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
             
            //add the nodes
            model.CurrentWorkspace.AddNode(numberNode1, false);
            model.CurrentWorkspace.AddNode(numberNode2, false);
            model.CurrentWorkspace.AddNode(addNode, false);
            //connect them up
            ConnectorModel.Make(numberNode1, addNode, 0, 0);
            ConnectorModel.Make(numberNode2, addNode, 0, 1);

            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3);
            Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2);

            //create the first state with the numbers selected
            DynamoSelection.Instance.Selection.Add(numberNode1);
            DynamoSelection.Instance.Selection.Add(numberNode2);
            var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
            //create the preset from 2 nodes
            model.CurrentWorkspace.AddPreset(
                 "state1",
                 "3", IDS);

            Assert.AreEqual(numberNode1.X, 0);
            Assert.AreEqual(numberNode1.Y, 0);
            Assert.AreEqual(numberNode2.X, 0);
            Assert.AreEqual(numberNode2.Y, 0);

            // move the nodes
            numberNode1.X = 10;
            numberNode1.Y = 10;

            numberNode2.X = 20;
            numberNode2.Y = 20;
            //set the state back before 
            model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where(
                   x => x.Name == "state1").First());
            Assert.AreEqual(numberNode1.X, 10);
            Assert.AreEqual(numberNode1.Y, 10);
            Assert.AreEqual(numberNode2.X, 20);
            Assert.AreEqual(numberNode2.Y, 20);
        }
Ejemplo n.º 21
0
        public void CanCreateStatesAndSave()
          {
              var model = CurrentDynamoModel;
              //create some numbers
              var numberNode1 = new DoubleInput();
              numberNode1.Value = "1";
              var numberNode2 = new DoubleInput();
              numberNode2.Value = "2";
              var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            
              //add the nodes
              model.CurrentWorkspace.AddNode(numberNode1, false);
              model.CurrentWorkspace.AddNode(numberNode2, false);
              model.CurrentWorkspace.AddNode(addNode, false);

              //connect them up
              ConnectorModel.Make(numberNode1, addNode, 0, 0);
              ConnectorModel.Make(numberNode2, addNode, 0, 1);

              Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3);
              Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2);

              //create the first state with the numbers selected
              DynamoSelection.Instance.Selection.Add(numberNode1);
              DynamoSelection.Instance.Selection.Add(numberNode2);
              var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
              //create the preset from 2 nodes
              model.CurrentWorkspace.AddPreset(
                  "state1",
                  "3", IDS);

              //change values
              numberNode1.Value = "2";
              numberNode2.Value = "3";

              DynamoSelection.Instance.ClearSelection();
              DynamoSelection.Instance.Selection.Add(numberNode1);
              DynamoSelection.Instance.Selection.Add(numberNode2);
              IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();

              model.CurrentWorkspace.AddPreset(
              "state2",
              "5", IDS);

              //save these states
              var newPath = GetNewFileNameOnTempPath("dyn");
              var res = model.CurrentWorkspace.SaveAs(newPath, model.EngineController.LiveRunnerRuntimeCore);

              Assert.IsTrue(res);
              Assert.IsTrue(File.Exists(newPath));
         

          }
Ejemplo n.º 22
0
        public void CanRestoreStateInGraphThatIsMissingNodes()
        {
            var model = CurrentDynamoModel;
            //create some numbers
            var numberNode1 = new DoubleInput();
            numberNode1.Value = "1";
            var numberNode2 = new DoubleInput();
            numberNode2.Value = "2";
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

            //add the nodes
            model.CurrentWorkspace.AddNode(numberNode1, false);
            model.CurrentWorkspace.AddNode(numberNode2, false);
            model.CurrentWorkspace.AddNode(addNode, false);

            //connect them up
            ConnectorModel.Make(numberNode1, addNode, 0, 0);
            ConnectorModel.Make(numberNode2, addNode, 0, 1);

            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 3);
            Assert.AreEqual(model.CurrentWorkspace.Connectors.Count(), 2);

            //create the first state with the numbers selected
            DynamoSelection.Instance.Selection.Add(numberNode1);
            DynamoSelection.Instance.Selection.Add(numberNode2);
            var IDS = DynamoSelection.Instance.Selection.OfType<NodeModel>().Select(x => x.GUID).ToList();
            //create the preset from 2 nodes
            model.CurrentWorkspace.AddPreset(
                "state1",
                "3", IDS);

            //change values
            numberNode1.Value = "2";
            numberNode2.Value = "3";

           //now delete numberNode1;
            model.CurrentWorkspace.RemoveNode(numberNode1);


            //now restore state to state 1
            Assert.DoesNotThrow(() =>
            {
                model.CurrentWorkspace.ApplyPreset(model.CurrentWorkspace.Presets.Where(
                    x => x.Name == "state1").First());
            });

            //now check that numbernode2 has been set to correct value in state 1
            Assert.AreEqual(numberNode2.Value, "2");
            //check that node 1 has actually been deleted
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 2);
        }
Ejemplo n.º 23
0
        public void CanCopydAndPaste2NodesWithRightOffset()
        {
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            addNode.Height = 2;
            addNode.Width = 2;
            addNode.CenterX = 3;
            addNode.CenterY = 2;

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            CurrentDynamoModel.AddToSelection(addNode);

            addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            addNode.Height = 2;
            addNode.Width = 2;
            addNode.CenterX = 6;
            addNode.CenterY = 8;

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            CurrentDynamoModel.AddToSelection(addNode);

            CurrentDynamoModel.Copy();
            Assert.AreEqual(2, CurrentDynamoModel.ClipBoard.Count);

            CurrentDynamoModel.Paste();
            Assert.AreEqual(4, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            Assert.AreEqual(17, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(2).X);
            Assert.AreEqual(17, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(2).Y);

            Assert.AreEqual(20, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(3).X);
            Assert.AreEqual(23, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(3).Y);
        }
Ejemplo n.º 24
0
 public void CanAddANodeByName()
 {
     var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
     CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
     Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 1);
 }
Ejemplo n.º 25
0
        public void CanSaveAsFileWithNodesInIt()
        {
            int numNodes = 100;

            for (int i = 0; i < numNodes; i++)
            {
                var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
                CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
                Assert.AreEqual(i + 1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
            }

            string fn = "ruthlessTurtles.dyn";
            string path = Path.Combine(TempFolder, fn);
            CurrentDynamoModel.CurrentWorkspace.SaveAs(
                path,
                CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore);

            var tempFldrInfo = new DirectoryInfo(TempFolder);
            Assert.AreEqual(1, tempFldrInfo.GetFiles().Length);
            Assert.AreEqual(fn, tempFldrInfo.GetFiles()[0].Name);
        }
Ejemplo n.º 26
0
        public void HomeWorkspaceHasUnsavedChangesPropertyIsSetOnSaveAs()
        {
            // open file
            // make change
            // saveAs
            // SavedProperty is true, filePath set, file exists

            // get empty workspace
            var dynamoModel = ViewModel.Model;
            Assert.IsNotNull(dynamoModel.CurrentWorkspace);
            Assert.IsAssignableFrom(typeof(HomeWorkspaceModel), dynamoModel.CurrentWorkspace);

            // make change
            var node = new DSFunction(dynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            dynamoModel.CurrentWorkspace.AddNode(node, false);
            Assert.IsTrue(ViewModel.Model.CurrentWorkspace.HasUnsavedChanges);
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count);

            // save
            var newPath = GetNewFileNameOnTempPath("dyn");
            ViewModel.Model.CurrentWorkspace.SaveAs(newPath, ViewModel.Model.EngineController.LiveRunnerRuntimeCore);

            // check expected
            Assert.IsFalse(ViewModel.Model.CurrentWorkspace.HasUnsavedChanges);

        }
Ejemplo n.º 27
0
        public void CanSumTwoNumbers()
        {
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            CurrentDynamoModel.CurrentWorkspace.AddNode(addNode, false);
            CurrentDynamoModel.CurrentWorkspace.AddNode(new CodeBlockNodeModel("2", 100.0, 100.0, CurrentDynamoModel.LibraryServices), false);
            CurrentDynamoModel.CurrentWorkspace.AddNode(new CodeBlockNodeModel("2", 100.0, 100.0, CurrentDynamoModel.LibraryServices), false);
            CurrentDynamoModel.CurrentWorkspace.AddNode(new Watch { X = 100, Y = 300 }, false);

            ConnectorModel.Make(CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(1), CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(0), 0, 0);
            ConnectorModel.Make(CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(2), CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(0), 0, 1);
            ConnectorModel.Make(CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(0), CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(3), 0, 0);

            BeginRun();

            Thread.Sleep(250);

            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(3) is Watch, true);

            var w = (Watch)CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(3);
            Assert.AreEqual(4.0, w.CachedValue);
        }
Ejemplo n.º 28
0
        public void CustomNodeWorkspaceHasUnsavedChangesPropertyIsSetOnSaveAs()
        {
            // open file
            // make change
            // saveAs
            // SavedProperty is true, filePath set, file exists

            var dynamoModel = ViewModel.Model;
            var nodeName = "Cool node";
            var catName = "Custom Nodes";

            var def = dynamoModel.CustomNodeManager.CreateCustomNode(nodeName, catName, "");
            Assert.IsFalse(def.HasUnsavedChanges);

            var node = new DSFunction(dynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            def.AddNode(node, false);
            Assert.IsTrue(def.HasUnsavedChanges);
            Assert.AreEqual(1, def.Nodes.Count );
            
            var newPath = GetNewFileNameOnTempPath("dyf");
            def.SaveAs(newPath, ViewModel.Model.EngineController.LiveRunnerRuntimeCore);

            Assert.IsFalse(def.HasUnsavedChanges);
        }
Ejemplo n.º 29
0
        internal static NodeModel CreateNodeInstance(string name)
        {
            NodeModel result;

            if (dynSettings.Controller.BuiltInFunctions.ContainsKey(name))
            {
                var method = dynSettings.Controller.BuiltInFunctions[name];
                result = new DSFunction(method as ProcedureNode);
            }
            else if (dynSettings.Controller.BuiltInTypesByName.ContainsKey(name))
            {
                TypeLoadData tld = dynSettings.Controller.BuiltInTypesByName[name];

                ObjectHandle obj = Activator.CreateInstanceFrom(tld.Assembly.Location, tld.Type.FullName);
                var newEl = (NodeModel)obj.Unwrap();
                newEl.DisableInteraction();
                result = newEl;
            }
            else if (dynSettings.Controller.BuiltInTypesByNickname.ContainsKey(name))
            {
                TypeLoadData tld = dynSettings.Controller.BuiltInTypesByNickname[name];
                try
                {

                    ObjectHandle obj = Activator.CreateInstanceFrom(tld.Assembly.Location, tld.Type.FullName);
                    var newEl = (NodeModel)obj.Unwrap();
                    newEl.DisableInteraction();
                    result = newEl;
                }
                catch (Exception ex)
                {
                    DynamoLogger.Instance.Log("Failed to load built-in type");
                    DynamoLogger.Instance.Log(ex);
                    result = null;
                }
            }
            else
            {
                Function func;

                if (dynSettings.Controller.CustomNodeManager.GetNodeInstance(Guid.Parse(name), out func))
                {
                    result = func;
                }
                else
                {
                    DynamoLogger.Instance.Log("Failed to find FunctionDefinition.");
                    return null;
                }
            }

            return result;
        }
Ejemplo n.º 30
0
        public void TestDraggedNode()
        {
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+")) { X = 16, Y = 32 };
            ViewModel.Model.CurrentWorkspace.AddNode(addNode, false);
            NodeModel locatable = ViewModel.Model.CurrentWorkspace.Nodes[0];

            var startPoint = new Point2D(8, 64);
            var dn = new WorkspaceViewModel.DraggedNode(locatable, startPoint);

            // Initial node position.
            Assert.AreEqual(16, locatable.X);
            Assert.AreEqual(32, locatable.Y);

            // Move the mouse cursor to move node.
            dn.Update(new Point2D(-16, 72));
            Assert.AreEqual(-8, locatable.X);
            Assert.AreEqual(40, locatable.Y);
        }