Example #1
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);
        }
        public void CanCreateGroupIfANodeIsAlreadyInAGroup()
        {
            //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());

            //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));

        }
        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);
        }
Example #4
0
        public void Freeze_ANode_Test()
        {           
            var model = CurrentDynamoModel;
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            model.CurrentWorkspace.AddAndRegisterNode(addNode, false);

            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 1);
            Assert.AreEqual(addNode.IsFrozen, false);

            addNode.IsFrozen = true;          
            Assert.AreEqual(addNode.IsFrozen, true);
        }
        public void Node_InFreeze_ExecuteState_Test()
        {
            var model = ViewModel.Model;
            //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,
                DynamoModel.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID, 0, PortType.Input,
                DynamoModel.MakeConnectionCommand.Mode.End));

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

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

            //Now Freeze the NumberNode1.
            numberNode1.IsFrozen = true;
           
            //Get the ViewModel of the number node and check the Freeze property.
            var numberNodevm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode1);
            Assert.IsNotNull(numberNodevm);
            Assert.AreEqual(numberNodevm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNodevm.CanToggleFrozen, true);

            //Get the ViewModel of add node and check the Freeze property. This node is a child node of numbernode1.
            //so this node should be in Frozen and Executing state.
            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);
            Assert.IsNotNull(addNodeVm);
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);
        }
Example #6
0
        public void CanAddOneNodeToClipboard()
        {
            int numNodes = 1;

            // 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.AddAndRegisterNode(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);
        }
Example #7
0
        public void WorkspaceModelHasCorrectDependencies()
        {
            var addNode    = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            var ws         = this.CurrentDynamoModel.CustomNodeManager.CreateCustomNode("someNode", "someCategory", "");
            var csid       = (ws as CustomNodeWorkspaceModel).CustomNodeId;
            var customNode = this.CurrentDynamoModel.CustomNodeManager.CreateCustomNodeInstance(csid);

            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Dependencies.ToList().Count());

            CurrentDynamoModel.AddNodeToCurrentWorkspace(customNode, false);
            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Dependencies.ToList().Count());
            //assert that we still only record one dep even though custom node is in graph twice.
            CurrentDynamoModel.AddNodeToCurrentWorkspace(customNode, false);
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Dependencies.ToList().Count());

            //assert that guid we have stored is is the custom nodes functionID
            Assert.AreEqual(customNode.FunctionUuid, CurrentDynamoModel.CurrentWorkspace.Dependencies.First());
        }
        public void TestBasicAttributes()
        {
            var sumNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"))
            {
                X = 400, Y = 100
            };

            //Assert initial values
            Assert.AreEqual(400, sumNode.X);
            Assert.AreEqual(100, sumNode.Y);
            Assert.AreEqual("+", sumNode.Name);
            Assert.AreEqual(LacingStrategy.Auto, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            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.Name = "TestNode";
            sumNode.UpdateValue(new UpdateValueParams("ArgumentLacing", "CrossProduct"));
            sumNode.UpdateValue(new UpdateValueParams("IsVisible", "false"));
            sumNode.State = ElementState.Active;

            //Assert New Changes
            Assert.AreEqual(250, sumNode.X);
            Assert.AreEqual(0, sumNode.Y);
            Assert.AreEqual("TestNode", sumNode.Name);
            Assert.AreEqual(LacingStrategy.CrossProduct, sumNode.ArgumentLacing);
            Assert.AreEqual(false, sumNode.IsVisible);
            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.Name);
            Assert.AreEqual(LacingStrategy.Auto, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            Assert.AreEqual(ElementState.Dead, sumNode.State);
        }
Example #9
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.Auto, 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.Auto, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            Assert.AreEqual(true, sumNode.IsUpstreamVisible);
            Assert.AreEqual(ElementState.Dead, sumNode.State);
        }
Example #10
0
        public void TooglePresetVisibilityWithUndoRedo()
        {
            //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.ExecuteCommand(new DynamoModel.AddPresetCommand("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);

            //undo the preset creation
            ViewModel.CurrentSpace.UndoRecorder.Undo();

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

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

            //redo the preset creation
            ViewModel.CurrentSpace.UndoRecorder.Redo();

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

            //Check the Preset option visibility.
            Assert.AreEqual(true, ViewModel.EnablePresetOptions);
        }
Example #11
0
        public void UndoAModelDeleteShouldGetTheModelInThatGroup()
        {
            //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);

            var modelToDelete = new List <ModelBase> {
                addNode
            };

            //Delete the model
            model.DeleteModelInternal(modelToDelete);

            //Check for the model count now
            Assert.AreEqual(1, annotation.SelectedModels.Count());

            //Undo the operation
            model.CurrentWorkspace.Undo();

            //Check for the model count now
            Assert.AreEqual(2, annotation.SelectedModels.Count());
        }
Example #12
0
        public void ParentNode_Freeze_Test()
        {
            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);

            //Check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //Freeeze the numbernode1 and compute the Freeze state of other nodes.           
            numberNode1.IsFrozen = true;          

            //change the value of number node1.
            numberNode1.Value = "3.0";

            // the number node must be frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
             
            //the add node must be frozen and can execute state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //Since the nodes are frozen, the value  of add node should not change.            
            AssertPreviewValue(addNode.GUID.ToString(), 3);
        }
Example #13
0
        public void UndoDeletingTheGroupShouldBringTheGroupAndModelsBack()
        {
            //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());

            //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();

            //Selecting the Group should select the models within that group
            var vm = ViewModel.CurrentSpaceViewModel.Annotations.FirstOrDefault();

            Assert.IsNotNull(vm);
            vm.Select();
            Assert.AreEqual(annotation.Nodes.Count(), annotation.Nodes.Count(x => x.IsSelected));

            //Execute the delete command - This should delete the entire group and models
            ViewModel.DeleteCommand.Execute(null);
            Assert.AreEqual(null, ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault());

            //Undo the operation
            ViewModel.CurrentSpace.Undo();
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Annotations.Count());

            annotation = ViewModel.Model.CurrentWorkspace.Annotations.FirstOrDefault();
            Assert.IsNotNull(annotation);
            Assert.AreEqual(1, annotation.Nodes.Count());
        }
Example #14
0
        public void CheckIfModelExistsInSomeGroup_True_ShouldNotCreateNewAnnotation()
        {
            //Add a Node
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Nodes.Count(), 1);

            //Add a Note
            Guid id      = Guid.NewGuid();
            var  addNote = CurrentDynamoModel.CurrentWorkspace.AddNote(false, 200, 200, "This is a test note", id);

            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Notes.Count(), 1);

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

            //Create the group around selected node and note
            Guid groupId = Guid.NewGuid();

            CurrentDynamoModel.CurrentWorkspace.AddAnnotation("This is a test group", groupId);
            Assert.AreEqual(CurrentDynamoModel.CurrentWorkspace.Annotations.Count(), 1);

            //Tries to create new annotation with the same selection
            var result = CurrentDynamoModel.CurrentWorkspace.AddAnnotation("This is a test group", Guid.NewGuid());

            Assert.IsNull(result);

            //Adds additional node
            var extraNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(extraNode);
            Assert.AreEqual(2, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            //Adds new node to selection
            DynamoSelection.Instance.Selection.Add(extraNode);

            //Tries to create new annotation with selected nodes.
            result = CurrentDynamoModel.CurrentWorkspace.AddAnnotation("This is a test group", Guid.NewGuid());
            Assert.IsNull(result);
        }
Example #15
0
        public void CanAdd100NodesToClipboard()
        {
            var model = ViewModel.Model;

            int numNodes = 100;

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

                model.AddToSelection(ViewModel.Model.CurrentWorkspace.Nodes[i]);
                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }

            model.Copy();
            Assert.AreEqual(numNodes, ViewModel.Model.ClipBoard.Count);
        }
        public void Node_InFreeze_NotExecuteState_Test()
        {
            //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());

            //Freeze the node
            addNode.IsFrozen = true;

            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);
            Assert.IsNotNull(addNodeVm);
            
            //Check the Freeze property. Assuming only one node is selected
            //this property is fetched from Nodeviewmodel. Context Menu on Workspace,
            //Context menu on Node and Edit Menu toolbar refers to the same location.
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, true);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, true);
        }
Example #17
0
        public void CanSaveAsFileWithNodesInIt()
        {
            int numNodes = 100;

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

            string fn   = "ruthlessTurtles.dyn";
            string path = Path.Combine(TempFolder, fn);

            CurrentDynamoModel.CurrentWorkspace.Save(path);

            var tempFldrInfo = new DirectoryInfo(TempFolder);

            Assert.AreEqual(1, tempFldrInfo.GetFiles().Length);
            Assert.AreEqual(fn, tempFldrInfo.GetFiles()[0].Name);
        }
Example #18
0
        public void Freeze_Test_On_WatchNode()
        {
            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));

            //add  a watch node
            var watchNode = new Watch();

            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));

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

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

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //check the watch node value
            AssertPreviewValue(watchNode.GUID.ToString(), 3);
        }
Example #19
0
        public void TestDraggedNode()
        {
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"))
            {
                X = 16, Y = 32
            };

            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            NodeModel locatable = ViewModel.Model.CurrentWorkspace.Nodes.First();

            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);
        }
Example #20
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);
        }
Example #21
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.AddAndRegisterNode(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);
            }
        }
        public void NodeManipulatorUnselectedNodeTest()
        {
            RaiseLoadedEvent(this.View);

            var pntNode = new DSFunction(Model.LibraryServices.GetFunctionDescriptor("Autodesk.DesignScript.Geometry.Point.ByCoordinates"));

            Model.ExecuteCommand(new DynamoModel.CreateNodeCommand(pntNode, 0, 0, true, false));

            pntNode.IsSelected = false;

            var dme         = View.viewExtensionManager.ViewExtensions.OfType <DynamoManipulationExtension>().FirstOrDefault();
            var manipulator = new MousePointManipulator(pntNode, dme);

            Assert.IsNotNull(manipulator);

            var manipulatorType = typeof(MousePointManipulator);
            var method          = manipulatorType.GetMethod("UpdatePosition", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            Assert.IsNotNull(method);

            method.Invoke(manipulator, new object[] { });
        }
Example #23
0
        public void TestCopyPasteGroups()
        {
            //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);

            //Add the group  selection
            DynamoSelection.Instance.Selection.Add(annotation);

            //Copy the group
            model.Copy();

            //paste the group
            model.Paste();

            //there should be 2 groups in the workspace
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 2);
        }
        public void ChangingIsExpandedMarksGraphAsModified()
        {
            // Arrange
            //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());

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

            //Create a Group around that node
            ViewModel.AddAnnotationCommand.Execute(null);
            var annotationViewModel = ViewModel.CurrentSpaceViewModel.Annotations.FirstOrDefault();

            // Act
            // Set workspace changes to false
            ViewModel.CurrentSpaceViewModel.HasUnsavedChanges = false;

            // Change annotationViewModel IsExpandedState
            annotationViewModel.IsExpanded = !annotationViewModel.IsExpanded;
            var workspaceStateAfterChangingIsExpandedFirst = ViewModel.CurrentSpaceViewModel.HasUnsavedChanges;

            // Set workspace changes to false
            ViewModel.CurrentSpaceViewModel.HasUnsavedChanges = false;

            // Change annotationViewModel IsExpandedState
            annotationViewModel.IsExpanded = !annotationViewModel.IsExpanded;
            var workspaceStateAfterChangingIsExpandedSecond = ViewModel.CurrentSpaceViewModel.HasUnsavedChanges;

            // Assert
            Assert.IsTrue(workspaceStateAfterChangingIsExpandedFirst);
            Assert.IsTrue(workspaceStateAfterChangingIsExpandedSecond);
            Assert.IsTrue(ViewModel.CurrentSpaceViewModel.HasUnsavedChanges);
        }
        public void Node_InFreeze_NotExecuteState_Test()
        {
            //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());

            //Freeze the node
            addNode.IsFrozen = true;

            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);

            Assert.IsNotNull(addNodeVm);

            //Check the Freeze property. Assuming only one node is selected
            //this property is fetched from Nodeviewmodel. Context Menu on Workspace,
            //Context menu on Node and Edit Menu toolbar refers to the same location.
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, true);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, true);
        }
        public void CreateGroupAroundNodes()
        {
            //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());

            //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);           
        }
        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);
        }
Example #28
0
        public void Freeze_Test_On_WatchNode()
        {
            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));

            //add  a watch node
            var watchNode = new Watch();
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));

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

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

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);
        
            //check the watch node value
            AssertPreviewValue(watchNode.GUID.ToString(), 3);
        }
Example #29
0
        public void NestedGroupTestForNodes()
        {
            //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());

            //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();

            var secondNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));

            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(secondNode, false);

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

            //Select the nodes again - add node is in a group and secondnode is not in a group
            DynamoSelection.Instance.Selection.Add(addNode);
            DynamoSelection.Instance.Selection.Add(secondNode);

            //Check whether group can be created
            Assert.AreEqual(false, ViewModel.CanAddAnnotation(null));
        }
Example #30
0
        public void UngroupAllTheModelsShouldDeleteTheGroup()
        {
            //Add a Node
            var model   = CurrentDynamoModel;
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

            model.CurrentWorkspace.AddNode(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);

            var modelsToUngroup = new List <ModelBase>();

            modelsToUngroup.Add(addNote);
            modelsToUngroup.Add(addNode);

            //Delete the models
            model.UngroupModel(modelsToUngroup);

            //Group should be deleted
            Assert.AreEqual(null, model.CurrentWorkspace.Annotations.FirstOrDefault());
        }
        public void SelectModelImplTest()
        {
            //Arrange
            string openPath = Path.Combine(TestDirectory, @"core\DetailedPreviewMargin_Test.dyn");

            RunModel(openPath);

            //This will add a new DSFunction node to the current workspace
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);

            //Select the node created (DSFunction)
            DynamoSelection.Instance.Selection.Add(addNode);
            var ids           = DynamoSelection.Instance.Selection.OfType <NodeModel>().Select(x => x.GUID).ToList();
            var selectCommand = new DynamoModel.SelectModelCommand(ids, ModifierKeys.Shift);

            //Act
            CurrentDynamoModel.ExecuteCommand(selectCommand);

            //Assert
            Assert.Greater(ids.Count, 0); //At least one guid was found
            Assert.IsNotNull(selectCommand);
        }
Example #32
0
        public void CanCopydAndPasteNodeWithRightOffset()
        {
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));

            addNode.Height  = 2;
            addNode.Width   = 2;
            addNode.CenterX = 3;
            addNode.CenterY = 2;

            CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            Assert.AreEqual(1, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

            CurrentDynamoModel.AddToSelection(addNode);
            Assert.AreEqual(1, DynamoSelection.Instance.Selection.Count);

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

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

            Assert.AreEqual(22, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(1).X);
            Assert.AreEqual(21, CurrentDynamoModel.CurrentWorkspace.Nodes.ElementAt(1).Y);
        }
        public void CanUngroupNodeFromAGroup()
        {
            //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();

            var secondNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));

            ViewModel.Model.CurrentWorkspace.AddNode(secondNode, false);

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

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

            //Check whether group can be created
            Assert.AreEqual(true, ViewModel.CanUngroupModel(null));
        }
        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);
        }
Example #35
0
        public NodeModel CreateNodeFromXml(XmlElement nodeElement, SaveContext context, ElementResolver resolver)
        {
            string assembly = "";
            string function;
            var    nickname = nodeElement.Attributes["nickname"].Value;

            FunctionDescriptor descriptor;

            Trace.Assert(nodeElement.Attributes != null, "nodeElement.Attributes != null");

            if (nodeElement.Attributes["assembly"] == null)
            {
                assembly = DetermineAssemblyName(nodeElement);
                function = nickname.Replace(".get", ".");
            }
            else
            {
                string xmlSignature = nodeElement.Attributes["function"].Value;

                string hintedSigniture =
                    libraryServices.FunctionSignatureFromFunctionSignatureHint(xmlSignature);

                if (hintedSigniture != null)
                {
                    nodeElement.Attributes["nickname"].Value =
                        libraryServices.NicknameFromFunctionSignatureHint(xmlSignature);
                    function = hintedSigniture;

                    // if the node needs additional parameters, add them here
                    libraryServices.AddAdditionalAttributesToNode(xmlSignature, nodeElement);
                    libraryServices.AddAdditionalElementsToNode(xmlSignature, nodeElement);
                }
                else
                {
                    function = xmlSignature;
                }

                var xmlAttribute = nodeElement.Attributes["assembly"];
                if (xmlAttribute != null)
                {
                    assembly = Uri.UnescapeDataString(xmlAttribute.Value);
                }
            }

            if (context == SaveContext.File && !string.IsNullOrEmpty(assembly))
            {
                var document = nodeElement.OwnerDocument;
                var docPath  = Nodes.Utilities.GetDocumentXmlPath(document);
                assembly = Nodes.Utilities.MakeAbsolutePath(docPath, assembly);

                if (libraryServices.IsLibraryLoaded(assembly))
                {
                    descriptor = libraryServices.GetFunctionDescriptor(assembly, function);
                }
                else
                {
                    // If the desired assembly is not loaded already. Check if it belongs to BuiltInFunctionGroup.
                    if (libraryServices.IsFunctionBuiltIn(assembly, nickname))
                    {
                        descriptor = libraryServices.GetFunctionDescriptor(function);
                    }
                    else
                    {
                        // If neither of these, Dynamo need to import the library.
                        try
                        {
                            libraryServices.ImportLibrary(assembly);
                            descriptor = libraryServices.GetFunctionDescriptor(assembly, function);
                        }
                        catch (LibraryLoadFailedException)
                        {
                            descriptor = libraryServices.GetFunctionDescriptor(function);
                        }
                    }
                }
            }
            else
            {
                descriptor = libraryServices.GetFunctionDescriptor(function);
            }

            if (null == descriptor)
            {
                var inputcount = DetermineFunctionInputCount(nodeElement);

                return(new DummyNode(
                           inputcount,
                           1,
                           nickname,
                           nodeElement,
                           assembly,
                           DummyNode.Nature.Unresolved));
            }

            DSFunctionBase result;

            if (descriptor.IsVarArg)
            {
                result = new DSVarArgFunction(descriptor);

                var akas = typeof(DSVarArgFunction).GetCustomAttribute <AlsoKnownAsAttribute>().Values;
                if (nodeElement.Name != typeof(DSVarArgFunction).FullName &&
                    akas.All(aka => aka != nodeElement.Name))
                {
                    VariableInputNodeController.SerializeInputCount(
                        nodeElement,
                        descriptor.Parameters.Count());
                }
            }
            else
            {
                result = new DSFunction(descriptor);
            }

            result.Deserialize(nodeElement, context);

            // In case of input parameters mismatch, use default arguments for parameters that have one
            if (!descriptor.MangledName.EndsWith(function))
            {
                string[] oldSignature = function.Split('@');
                string[] inputTypes = oldSignature.Length > 1 ? oldSignature[1].Split(',') : new string[] {};
                int      i = 0, j = 0;
                foreach (var param in descriptor.InputParameters)
                {
                    if (i >= inputTypes.Length || param.Item2 != inputTypes[i])
                    {
                        result.InPorts[j].UsingDefaultValue = result.InPorts[j].DefaultValue != null;
                    }
                    else
                    {
                        i++;
                    }
                    j++;
                }
            }

            return(result);
        }
 internal PointOnCurveManipulator(DSFunction node, DynamoManipulationExtension manipulatorContext)
     : base(node, manipulatorContext)
 {
 }
        public void Undo_Freeze_Test()
        {
            var model = ViewModel.Model;
            //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,
                DynamoModel.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID, 0, PortType.Input,
                DynamoModel.MakeConnectionCommand.Mode.End));

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

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

            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);
            Assert.IsNotNull(addNodeVm);

            var numberNode1Vm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode1);
            Assert.IsNotNull(numberNode1Vm);

            var numberNode2Vm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode2);
            Assert.IsNotNull(numberNode2Vm);

            //freeze number node1.            
            numberNode1Vm.ToggleIsFrozenCommand.Execute(null);

            Assert.AreEqual(numberNode1Vm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNode1Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            //freeze number node2
            numberNode2Vm.ToggleIsFrozenCommand.Execute(null);

            Assert.AreEqual(numberNode2Vm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNode2Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            ViewModel.CurrentSpace.Undo();

            //numbernode2 unfreeze
            Assert.AreEqual(numberNode2Vm.IsFrozenExplicitly, false);
            Assert.AreEqual(numberNode2Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            ViewModel.CurrentSpace.Undo();

            //numbernode1 unfreeze
            Assert.AreEqual(numberNode1Vm.IsFrozenExplicitly, false);
            Assert.AreEqual(numberNode1Vm.CanToggleFrozen, true);

            //add node is in normal state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, true);

        }
        public void UndoDeleteAllTheModelsShouldBringTheModelsAndGroupBack()
        {
            //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);

            var modelsToDelete = new List<ModelBase> { addNote, addNode };

            //Delete the models
            model.DeleteModelInternal(modelsToDelete);

            //Group should be deleted
            Assert.AreEqual(null, model.CurrentWorkspace.Annotations.FirstOrDefault());

            //Undo the operation
            model.CurrentWorkspace.Undo();

            //Check for the annotation count 
            Assert.AreEqual(1, model.CurrentWorkspace.Annotations.Count());
           
            //Check for the model count 
            annotation = model.CurrentWorkspace.Annotations.FirstOrDefault();
            Assert.NotNull(annotation);
            Assert.AreEqual(2, annotation.SelectedModels.Count());
        }
Example #39
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            NodeModel node = null;

            var obj  = JObject.Load(reader);
            var type = Type.GetType(obj["$type"].Value <string>());

            //if we can't find this type - try to look in our load from assemblies,
            //but only during testing - this is required during testing because some dlls are loaded
            //using Assembly.LoadFrom using the assemblyHelper - which loads dlls into loadFrom context -
            //dlls loaded with LoadFrom context cannot be found using Type.GetType() - this should
            //not be an issue during normal dynamo use but if it is we can enable this code.
            if (type == null && this.isTestMode == true)
            {
                List <Assembly> resultList;

                var typeName = obj["$type"].Value <string>().Split(',').FirstOrDefault();
                //this assemblyName does not usually contain version information...
                var assemblyName = obj["$type"].Value <string>().Split(',').Skip(1).FirstOrDefault().Trim();
                if (assemblyName != null)
                {
                    if (this.loadedAssemblies.TryGetValue(assemblyName, out resultList))
                    {
                        var matchingTypes = resultList.Select(x => x.GetType(typeName)).ToList();
                        type = matchingTypes.FirstOrDefault();
                    }
                }
            }

            // If the id is not a guid, makes a guid based on the id of the node
            var guid = GuidUtility.tryParseOrCreateGuid(obj["Id"].Value <string>());

            var replication = obj["Replication"].Value <string>();

            var inPorts  = obj["Inputs"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();
            var outPorts = obj["Outputs"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();

            var    resolver         = (IdReferenceResolver)serializer.ReferenceResolver;
            string assemblyLocation = objectType.Assembly.Location;

            bool remapPorts = true;

            if (type == null)
            {
                node = CreateDummyNode(obj, assemblyLocation, inPorts, outPorts);
            }
            else if (type == typeof(Function))
            {
                var functionId = Guid.Parse(obj["FunctionSignature"].Value <string>());

                CustomNodeDefinition def  = null;
                CustomNodeInfo       info = null;
                bool     isUnresolved     = !manager.TryGetCustomNodeData(functionId, null, false, out def, out info);
                Function function         = manager.CreateCustomNodeInstance(functionId, null, false, def, info);
                node = function;

                if (isUnresolved)
                {
                    function.UpdatePortsForUnresolved(inPorts, outPorts);
                }
            }
            else if (type == typeof(CodeBlockNodeModel))
            {
                var code = obj["Code"].Value <string>();
                node = new CodeBlockNodeModel(code, guid, 0.0, 0.0, libraryServices, ElementResolver);
            }
            else if (typeof(DSFunctionBase).IsAssignableFrom(type))
            {
                var mangledName = obj["FunctionSignature"].Value <string>();

                var functionDescriptor = libraryServices.GetFunctionDescriptor(mangledName);
                if (functionDescriptor == null)
                {
                    node = CreateDummyNode(obj, assemblyLocation, inPorts, outPorts);
                }
                else
                {
                    if (type == typeof(DSVarArgFunction))
                    {
                        node = new DSVarArgFunction(functionDescriptor);
                        // The node syncs with the function definition.
                        // Then we need to make the inport count correct
                        var varg = (DSVarArgFunction)node;
                        varg.VarInputController.SetNumInputs(inPorts.Count());
                    }
                    else if (type == typeof(DSFunction))
                    {
                        node = new DSFunction(functionDescriptor);
                    }
                }
            }
            else if (type == typeof(DSVarArgFunction))
            {
                var functionId = Guid.Parse(obj["FunctionSignature"].Value <string>());
                node = manager.CreateCustomNodeInstance(functionId);
            }
            else if (type.ToString() == "CoreNodeModels.Formula")
            {
                node = (NodeModel)obj.ToObject(type);
            }
            else
            {
                node = (NodeModel)obj.ToObject(type);

                // We don't need to remap ports for any nodes with json constructors which pass ports
                remapPorts = false;
            }

            if (remapPorts)
            {
                RemapPorts(node, inPorts, outPorts, resolver);
            }

            // Cannot set Lacing directly as property is protected
            node.UpdateValue(new UpdateValueParams("ArgumentLacing", replication));
            node.GUID = guid;

            // Add references to the node and the ports to the reference resolver,
            // so that they are available for entities which are deserialized later.
            serializer.ReferenceResolver.AddReference(serializer.Context, node.GUID.ToString(), node);

            foreach (var p in node.InPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }

            foreach (var p in node.OutPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }

            return(node);
        }
Example #40
0
        public void Node_AttachedTThatHasParents_ShouldNotUnfreeze_UntilAllParentsUnfreeze_Test()
        {
            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));

            //add  a watch node
            var watchNode = new Watch() { X = 100, Y = 300 };
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));

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

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

            //check the value.
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //now freeze both the number nodes.
            numberNode1.IsFrozen = true;
          
            numberNode2.IsFrozen = true;
           
            //Number nodes in frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
            
            Assert.AreEqual(numberNode2.IsFrozen, true);
           
            //change the value of number nodes
            numberNode1.Value = "3.0";
            numberNode2.Value = "3.0";

            //add node in frozen and can execute state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //addnode should not change the value.
            AssertPreviewValue(addNode.GUID.ToString(), 3);
            Assert.AreEqual(Convert.ToInt32(watchNode.CachedValue),3);

            //unfreeze one of the number node          
            numberNode1.IsFrozen = false;
           
            //Number nodes in frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, false);
            
            Assert.AreEqual(numberNode2.IsFrozen, true);
            
            //add node should still be in frozen and can execute state
            Assert.AreEqual(addNode.IsFrozen, true);
                      
            //now unfreeze the other node.
            numberNode2.IsFrozen = false;
            
            Assert.AreEqual(numberNode2.IsFrozen, false);
           
            //now the add node should not be in frozen state
            Assert.AreEqual(addNode.IsFrozen, false);
            
            //addnode should change the value now.
            AssertPreviewValue(addNode.GUID.ToString(), 6);
            AssertPreviewValue(watchNode.GUID.ToString(), 6);
        }
Example #41
0
        public void TestDraggedNode()
        {
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+")) { X = 16, Y = 32 };
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);
            NodeModel locatable = ViewModel.Model.CurrentWorkspace.Nodes.First();

            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);
        }
Example #42
0
        public void AddPresetShouldSetDirtyFlag()

        {
            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("+"));

            //Check for Dirty flag
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, false);

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

            //Check for Dirty flag
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true);

            //Set the dirty flag to false. Mocking the save.
            model.CurrentWorkspace.HasUnsavedChanges = false;
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, false);

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

            //Check for Dirty flag - After the connection the dirty flag should be set.
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true);

            //Set the dirty flag to false. Mocking the save.
            model.CurrentWorkspace.HasUnsavedChanges = false;
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, false);

            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(1, model.CurrentWorkspace.Presets.Count());

            //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);

            //Check for Dirty flag - After the Preset the dirty flag should be set.
            Assert.AreEqual(model.CurrentWorkspace.HasUnsavedChanges, true);
        }
        public void TestCopyPasteGroup_IfItsNodeDeletedAfterCopying()
        {
            //Add a Node
            var ws = CurrentDynamoModel.CurrentWorkspace;
            var addNode = new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("+"));
            ws.AddAndRegisterNode(addNode);
            Assert.AreEqual(ws.Nodes.Count(), 1);

            //Add a Note 
            var addNote = ws.AddNote(false, 200, 200, "This is a test note", Guid.NewGuid());
            Assert.AreEqual(ws.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
            var groupId = Guid.NewGuid();
            var annotation = ws.AddAnnotation("This is a test group", groupId);
            Assert.AreEqual(ws.Annotations.Count(), 1);
            Assert.AreNotEqual(0, annotation.Width);

            //Add the group  selection
            DynamoSelection.Instance.Selection.Add(annotation);

            //Copy the group
            CurrentDynamoModel.Copy();

            var modelToDelete = new List<ModelBase> { addNode };

            //Delete the node
            CurrentDynamoModel.DeleteModelInternal(modelToDelete);

            // only the note should remain
            Assert.AreEqual(1, annotation.SelectedModels.Count());

            //paste the group
            CurrentDynamoModel.Paste();

            //there should be 2 groups in the workspace
            Assert.AreEqual(ws.Annotations.Count(), 2);
            var pastedGroup = ws.Annotations.First(g => g != annotation);

            // group has been copied with 1 node and 1 note
            Assert.AreEqual(2, pastedGroup.SelectedModels.Count());
        }
Example #44
0
        public void RedoAddModelToAGroup()
        {
            //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);

            //Create Another node
            //Add a Node
            var secondNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

            model.CurrentWorkspace.AddAndRegisterNode(secondNode, false);
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 2);

            DynamoSelection.Instance.ClearSelection();

            //Select the group and newly created node
            DynamoSelection.Instance.Selection.Add(annotation);
            DynamoSelection.Instance.Selection.Add(secondNode);

            var modelsToAdd = new List <ModelBase>();

            modelsToAdd.Add(secondNode);

            //Add the model to group
            model.AddToGroup(modelsToAdd);

            //Group should have the new node added
            Assert.AreEqual(3, annotation.SelectedModels.Count());

            DynamoSelection.Instance.ClearSelection();

            //Add a new note
            id = Guid.NewGuid();
            var secondNote = model.CurrentWorkspace.AddNote(false, 200, 200, "This is a test note", id);

            Assert.AreEqual(model.CurrentWorkspace.Notes.Count(), 2);

            //Select the group and newly created note
            DynamoSelection.Instance.Selection.Add(annotation);
            DynamoSelection.Instance.Selection.Add(secondNote);

            modelsToAdd.Clear();
            modelsToAdd.Add(secondNote);

            //Add the model to group
            model.AddToGroup(modelsToAdd);

            //Group should have the new note added
            Assert.AreEqual(4, annotation.SelectedModels.Count());

            //Undo the operation
            model.CurrentWorkspace.Undo();

            //Notes should not be a part of the group
            Assert.AreEqual(3, annotation.SelectedModels.Count());

            //Redo the operation - notes should be within that group
            model.CurrentWorkspace.Redo();
            Assert.AreEqual(4, annotation.SelectedModels.Count());
        }
        public void UndoRedoCopyPasteGroups()
        {
            //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);

            //Add the group  selection
            DynamoSelection.Instance.Selection.Add(annotation);

            //Copy the group
            model.Copy();

            //paste the group
            model.Paste();

            //there should be 2 groups in the workspace
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 2);

            //Undo the paste
            model.CurrentWorkspace.Undo();

            //there should be 1 groups in the workspace
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 1);

            //Redo the Undo
            model.CurrentWorkspace.Redo();

            //there should be 2 groups in the workspace
            Assert.AreEqual(model.CurrentWorkspace.Annotations.Count(), 2);
        }
        public void Undo_Freeze_Test()
        {
            var model = ViewModel.Model;
            //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,
                                                                       DynamoModel.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID, 0, PortType.Input,
                                                                       DynamoModel.MakeConnectionCommand.Mode.End));

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

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

            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);

            Assert.IsNotNull(addNodeVm);

            var numberNode1Vm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode1);

            Assert.IsNotNull(numberNode1Vm);

            var numberNode2Vm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode2);

            Assert.IsNotNull(numberNode2Vm);

            //freeze number node1.
            numberNode1Vm.ToggleIsFrozenCommand.Execute(null);

            Assert.AreEqual(numberNode1Vm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNode1Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            //freeze number node2
            numberNode2Vm.ToggleIsFrozenCommand.Execute(null);

            Assert.AreEqual(numberNode2Vm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNode2Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            ViewModel.CurrentSpace.Undo();

            //numbernode2 unfreeze
            Assert.AreEqual(numberNode2Vm.IsFrozenExplicitly, false);
            Assert.AreEqual(numberNode2Vm.CanToggleFrozen, true);

            //add node is in frozen executing state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);

            ViewModel.CurrentSpace.Undo();

            //numbernode1 unfreeze
            Assert.AreEqual(numberNode1Vm.IsFrozenExplicitly, false);
            Assert.AreEqual(numberNode1Vm.CanToggleFrozen, true);

            //add node is in normal state
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, false);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, true);
        }
Example #47
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            NodeModel node = null;

            var obj  = JObject.Load(reader);
            var type = Type.GetType(obj["$type"].Value <string>());

            // If we can't find this type - try to look in our load from assemblies,
            // but only during testing - this is required during testing because some dlls are loaded
            // using Assembly.LoadFrom using the assemblyHelper - which loads dlls into loadFrom context -
            // dlls loaded with LoadFrom context cannot be found using Type.GetType() - this should
            // not be an issue during normal dynamo use but if it is we can enable this code.
            if (type == null && this.isTestMode == true)
            {
                List <Assembly> resultList;

                var typeName = obj["$type"].Value <string>().Split(',').FirstOrDefault();
                // This assemblyName does not usually contain version information...
                var assemblyName = obj["$type"].Value <string>().Split(',').Skip(1).FirstOrDefault().Trim();
                if (assemblyName != null)
                {
                    if (this.loadedAssemblies.TryGetValue(assemblyName, out resultList))
                    {
                        var matchingTypes = resultList.Select(x => x.GetType(typeName)).ToList();
                        type = matchingTypes.FirstOrDefault();
                    }
                }
            }

            // Check for and attempt to resolve an unknown type before proceeding
            if (type == null)
            {
                // Attempt to resolve the type using `AlsoKnownAs`
                var  unresolvedName = obj["$type"].Value <string>().Split(',').FirstOrDefault();
                Type newType;
                nodeFactory.ResolveType(unresolvedName, out newType);

                // If resolved update the type
                if (newType != null)
                {
                    type = newType;
                }
            }

            // If the id is not a guid, makes a guid based on the id of the node
            var guid = GuidUtility.tryParseOrCreateGuid(obj["Id"].Value <string>());

            var replication = obj["Replication"].Value <string>();

            var inPorts  = obj["Inputs"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();
            var outPorts = obj["Outputs"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();

            var    resolver         = (IdReferenceResolver)serializer.ReferenceResolver;
            string assemblyLocation = objectType.Assembly.Location;

            bool remapPorts = true;

            // If type is still null at this point return a dummy node
            if (type == null)
            {
                node = CreateDummyNode(obj, assemblyLocation, inPorts, outPorts);
            }
            // Attempt to create a valid node using the type
            else if (type == typeof(Function))
            {
                var functionId = Guid.Parse(obj["FunctionSignature"].Value <string>());

                CustomNodeDefinition def  = null;
                CustomNodeInfo       info = null;
                bool     isUnresolved     = !manager.TryGetCustomNodeData(functionId, null, false, out def, out info);
                Function function         = manager.CreateCustomNodeInstance(functionId, null, false, def, info);
                node = function;

                if (isUnresolved)
                {
                    function.UpdatePortsForUnresolved(inPorts, outPorts);
                }
            }

            else if (type == typeof(CodeBlockNodeModel))
            {
                var code = obj["Code"].Value <string>();
                CodeBlockNodeModel codeBlockNode = new CodeBlockNodeModel(code, guid, 0.0, 0.0, libraryServices, ElementResolver);
                node = codeBlockNode;

                // If the code block node is in an error state read the extra port data
                // and initialize the input and output ports
                if (node.IsInErrorState)
                {
                    List <string> inPortNames = new List <string>();
                    var           inputs      = obj["Inputs"];
                    foreach (var input in inputs)
                    {
                        inPortNames.Add(input["Name"].ToString());
                    }

                    // NOTE: This could be done in a simpler way, but is being implemented
                    //       in this manner to allow for possible future port line number
                    //       information being available in the file
                    List <int> outPortLineIndexes = new List <int>();
                    var        outputs            = obj["Outputs"];
                    int        outputLineIndex    = 0;
                    foreach (var output in outputs)
                    {
                        outPortLineIndexes.Add(outputLineIndex++);
                    }

                    codeBlockNode.SetErrorStatePortData(inPortNames, outPortLineIndexes);
                }
            }
            else if (typeof(DSFunctionBase).IsAssignableFrom(type))
            {
                var    mangledName        = obj["FunctionSignature"].Value <string>();
                var    priorNames         = libraryServices.GetPriorNames();
                var    functionDescriptor = libraryServices.GetFunctionDescriptor(mangledName);
                string newName;

                // Update the function descriptor if a newer migrated version of the node exists
                if (priorNames.TryGetValue(mangledName, out newName))
                {
                    functionDescriptor = libraryServices.GetFunctionDescriptor(newName);
                }

                // Use the functionDescriptor to try and restore the proper node if possible
                if (functionDescriptor == null)
                {
                    node = CreateDummyNode(obj, assemblyLocation, inPorts, outPorts);
                }
                else
                {
                    if (type == typeof(DSVarArgFunction))
                    {
                        node = new DSVarArgFunction(functionDescriptor);
                        // The node syncs with the function definition.
                        // Then we need to make the inport count correct
                        var varg = (DSVarArgFunction)node;
                        varg.VarInputController.SetNumInputs(inPorts.Count());
                    }
                    else if (type == typeof(DSFunction))
                    {
                        node = new DSFunction(functionDescriptor);
                    }
                }
            }
            else if (type == typeof(DSVarArgFunction))
            {
                var functionId = Guid.Parse(obj["FunctionSignature"].Value <string>());
                node = manager.CreateCustomNodeInstance(functionId);
            }
            else if (type.ToString() == "CoreNodeModels.Formula")
            {
                node = (NodeModel)obj.ToObject(type);
            }
            else
            {
                node = (NodeModel)obj.ToObject(type);

                // if node is an customNode input symbol - assign the element resolver.
                if (node is Nodes.CustomNodes.Symbol)
                {
                    (node as Nodes.CustomNodes.Symbol).ElementResolver = ElementResolver;
                }
                // We don't need to remap ports for any nodes with json constructors which pass ports
                remapPorts = false;
            }

            if (remapPorts)
            {
                RemapPorts(node, inPorts, outPorts, resolver, manager.AsLogger());
            }


            // Cannot set Lacing directly as property is protected
            node.UpdateValue(new UpdateValueParams("ArgumentLacing", replication));
            node.GUID = guid;

            // Add references to the node and the ports to the reference resolver,
            // so that they are available for entities which are deserialized later.
            serializer.ReferenceResolver.AddReference(serializer.Context, node.GUID.ToString(), node);

            foreach (var p in node.InPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }

            foreach (var p in node.OutPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }

            return(node);
        }
Example #48
0
        public void Unfreeze_ParentNode_MakesATemporaryStateNode_SwitchBackToPreviousState_Test()
        {
            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));

            //add  a watch node
            var watchNode = new Watch() {X = 100, Y = 300};
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));
            
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID, 0, PortType.Output, DynCmd.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(watchNode.GUID, 0, PortType.Input, DynCmd.MakeConnectionCommand.Mode.End));

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

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //freeze add node
            addNode.IsFrozen = true;
           
            // the add node must be frozen and not executing state
            Assert.AreEqual(addNode.IsFrozen, true);
           
            //freeze number node.
            numberNode1.IsFrozen = true;
            
            // the number node must be frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
            
            //change the value on number node 1
            numberNode1.Value = "3.0";

            // the add node must be frozen and in a temporary state
            Assert.AreEqual(addNode.IsFrozen, true);
           
            //check the value on add node.
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //now unfreeze number node.
            numberNode1.IsFrozen = false;
           
            //now number node is not frozen
            Assert.AreEqual(numberNode1.IsFrozen, false);

            //this causes the add node to switch back from temporary state
            //to frozen and not executing state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //check the value on add node. Add node is not executed in the run,
            // becuase the frozen nodes are removed from AST. So the value of add node
            // should be 0. But the cached value should be 3, which is from the previous execution.
            AssertPreviewValue(addNode.GUID.ToString(), 0);
            Assert.IsNotNull(addNode.CachedValue.Data);
            Assert.AreEqual(Convert.ToInt32(addNode.CachedValue.Data),3);
            Assert.AreEqual(Convert.ToInt32(watchNode.CachedValue), 3);
        }
        public void UndoUngroupAllTheModelShouldGetTheGroupWithModels()
        {
            //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);

            var modelsToUngroup = new List<ModelBase> { addNote, addNode };

            //Delete the models
            model.UngroupModel(modelsToUngroup);

            //Group should be deleted
            Assert.AreEqual(null, model.CurrentWorkspace.Annotations.FirstOrDefault());
    
            //Undo the Group Deletion
            model.CurrentWorkspace.Undo();

            //This should get the group back
            Assert.AreEqual(1, model.CurrentWorkspace.Annotations.Count());

            //Undo again should get the first model into the group
            model.CurrentWorkspace.Undo();
            annotation = model.CurrentWorkspace.Annotations.FirstOrDefault();
            Assert.NotNull(annotation);
            Assert.AreEqual(2, annotation.SelectedModels.Count());
        }
Example #50
0
 internal PointOnCurveManipulator(DSFunction node, DynamoManipulationExtension manipulatorContext)
     : base(node, manipulatorContext)
 {
 }
Example #51
0
        public void UnFreeze_ParentNode_UnfreezesChildNodes_Test()
        {
            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));

            //add  a watch node
            var watchNode = new Watch();
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));

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

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

            BeginRun();

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //Add the number node to selection and call Freeze state on the workspace.
            //this should freeze the number node.
            numberNode1.IsFrozen = true;
            
            // the number node must be frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
            
            //the add node must be frozen and can execute state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //check the watch node value
            AssertPreviewValue(watchNode.GUID.ToString(), 3);

            //now the number node1 is frozen. change the value.
            numberNode1.Value = "3.0";

            //check the value of add node. it should not change.
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //unfreeze the input node
            numberNode1.IsFrozen = false;
            
            Assert.AreEqual(numberNode1.IsFrozen, false);

            //Now the add node should be in unfreeze state
            Assert.AreEqual(addNode.IsFrozen, false);

            //Now the add node should get the value
            AssertPreviewValue(addNode.GUID.ToString(), 5);

            //check the watch node value
            AssertPreviewValue(watchNode.GUID.ToString(), 5);
        }
        public void RedoAddModelToAGroup()
        {
            //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);

            //Create Another node
            //Add a Node            
            var secondNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));
            model.CurrentWorkspace.AddAndRegisterNode(secondNode, false);
            Assert.AreEqual(model.CurrentWorkspace.Nodes.Count(), 2);

            DynamoSelection.Instance.ClearSelection();

            //Select the group and newly created node
            DynamoSelection.Instance.Selection.Add(annotation);
            DynamoSelection.Instance.Selection.Add(secondNode);

            var modelsToAdd = new List<ModelBase>();
            modelsToAdd.Add(secondNode);

            //Add the model to group
            model.AddToGroup(modelsToAdd);

            //Group should have the new node added 
            Assert.AreEqual(3, annotation.SelectedModels.Count());

            DynamoSelection.Instance.ClearSelection();

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

            //Select the group and newly created note
            DynamoSelection.Instance.Selection.Add(annotation);
            DynamoSelection.Instance.Selection.Add(secondNote);

            modelsToAdd.Clear();
            modelsToAdd.Add(secondNote);

            //Add the model to group
            model.AddToGroup(modelsToAdd);

            //Group should have the new note added 
            Assert.AreEqual(4, annotation.SelectedModels.Count());

            //Undo the operation
            model.CurrentWorkspace.Undo();

            //Notes should not be a part of the group
            Assert.AreEqual(3, annotation.SelectedModels.Count());

            //Redo the operation - notes should be within that group
            model.CurrentWorkspace.Redo();
            Assert.AreEqual(4, annotation.SelectedModels.Count());
        }
Example #53
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            NodeModel node = null;

            var obj  = JObject.Load(reader);
            var type = Type.GetType(obj["$type"].Value <string>());

            var guid        = Guid.Parse(obj["Uuid"].Value <string>());
            var displayName = obj["DisplayName"].Value <string>();
            //var x = obj["X"].Value<double>();
            //var y = obj["Y"].Value<double>();

            var inPorts  = obj["InputPorts"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();
            var outPorts = obj["OutputPorts"].ToArray().Select(t => t.ToObject <PortModel>()).ToArray();

            var resolver = (IdReferenceResolver)serializer.ReferenceResolver;

            if (type == typeof(Function))
            {
                var functionId = Guid.Parse(obj["FunctionUuid"].Value <string>());
                node = manager.CreateCustomNodeInstance(functionId);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if (type == typeof(CodeBlockNodeModel))
            {
                var code = obj["Code"].Value <string>();
                node = new CodeBlockNodeModel(code, guid, 0.0, 0.0, libraryServices, ElementResolver);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if (typeof(DSFunctionBase).IsAssignableFrom(type))
            {
                var mangledName = obj["FunctionName"].Value <string>();

                var description = libraryServices.GetFunctionDescriptor(mangledName);

                if (type == typeof(DSVarArgFunction))
                {
                    node = new DSVarArgFunction(description);
                    // The node syncs with the function definition.
                    // Then we need to make the inport count correct
                    var varg = (DSVarArgFunction)node;
                    varg.VarInputController.SetNumInputs(inPorts.Count());
                }
                else if (type == typeof(DSFunction))
                {
                    node = new DSFunction(description);
                }
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if (type == typeof(DSVarArgFunction))
            {
                var functionId = Guid.Parse(obj["FunctionUuid"].Value <string>());
                node = manager.CreateCustomNodeInstance(functionId);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else if (type == typeof(Formula))
            {
                node = (Formula)obj.ToObject(type);
                RemapPorts(node, inPorts, outPorts, resolver);
            }
            else
            {
                node = (NodeModel)obj.ToObject(type);
            }

            node.GUID     = guid;
            node.NickName = displayName;
            //node.X = x;
            //node.Y = y;

            // Add references to the node and the ports to the reference resolver,
            // so that they are available for entities which are deserialized later.
            serializer.ReferenceResolver.AddReference(serializer.Context, node.GUID.ToString(), node);

            foreach (var p in node.InPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }
            foreach (var p in node.OutPorts)
            {
                serializer.ReferenceResolver.AddReference(serializer.Context, p.GUID.ToString(), p);
            }
            return(node);
        }
Example #54
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.AddAndRegisterNode(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);
        }
Example #55
0
        public void Undo_Freeze_OnParentNode_Test()
        {
            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));
            
            //add  a watch node
            var watchNode = new Watch() { X = 100, Y = 300 };
            model.ExecuteCommand(new DynamoModel.CreateNodeCommand(watchNode, 0, 0, true, false));

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

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

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //Record for undo.
            model.ExecuteCommand(
                    new DynCmd.UpdateModelValueCommand(
                        Guid.Empty, numberNode1.GUID, "IsFrozen",
                         numberNode1.IsFrozen.ToString()));

            numberNode1.IsFrozen = true;
           
            //Number nodes in frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
           
            //add node in frozen and can execute state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);
            Assert.AreEqual(Convert.ToInt32(watchNode.CachedValue), 3);

            //undo the freeze on numbernode1
            model.CurrentWorkspace.Undo();
          
            //Now change the value on number node1
            numberNode1.Value = "3.0";

            //now the first number node unfreeze mode.
            Assert.AreEqual(numberNode1.IsFrozen, false);
           
            //add node in normal state
            Assert.AreEqual(addNode.IsFrozen, false);
           
            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 5);
            AssertPreviewValue(watchNode.GUID.ToString(), 5);
        }        
        public void Node_InTemporaryFreeze_State()
        {
            var model = ViewModel.Model;
            //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,
                DynamoModel.MakeConnectionCommand.Mode.Begin));
            model.ExecuteCommand(new DynamoModel.MakeConnectionCommand(addNode.GUID, 0, PortType.Input,
                DynamoModel.MakeConnectionCommand.Mode.End));

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

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

            //Now Freeze the add node. This node has two input nodes. Note that
            //input nodes are not frozen.
            addNode.IsFrozen = true;
           
            //Get the ViewModel of add node and check the Freeze property.
            //This node should be in Frozen and not Executing state.
            var addNodeVm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == addNode);
            Assert.IsNotNull(addNodeVm);
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, true);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, true);

            //Now freeze NumberNode1.
            numberNode1.IsFrozen = true;
           
            //Get the ViewModel of add node and check the Freeze property.
            //This node should be in Frozen and not Executing state.
            var numberNode1Vm = ViewModel.CurrentSpaceViewModel.Nodes.First(x => x.NodeLogic == numberNode1);
            Assert.IsNotNull(numberNode1Vm);
            Assert.AreEqual(numberNode1Vm.IsFrozenExplicitly, true);
            Assert.AreEqual(numberNode1Vm.CanToggleFrozen, true);

            //Now check the add node. Freeze property will be unchecked and disabled.
            Assert.AreEqual(addNodeVm.IsFrozenExplicitly, true);
            Assert.AreEqual(addNodeVm.CanToggleFrozen, false);
        }
        public void ChangeTheBackgroundForAGroup()
        {
            //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);

            //Check the default color - it should be green
            Assert.AreEqual(annotation.GroupBackground, annotation.Background);

            //change the color
            annotation.Background = "#ff7bac";

            //Check the  color - it should be ff7bac
            Assert.AreEqual("#ff7bac", annotation.Background);
        }
Example #58
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.AddAndRegisterNode(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);

        }
Example #59
0
        public void Unfreeze_ParentNode_MakesATemporaryStateNode_SwitchBackToPreviousState_Test()
        {
            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);

            //check the value
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //freeze add node
            addNode.IsFrozen = true;
           
            // the add node must be frozen and not executing state
            Assert.AreEqual(addNode.IsFrozen, true);
           
            //freeze number node.
            numberNode1.IsFrozen = true;
            
            // the number node must be frozen and not executing state
            Assert.AreEqual(numberNode1.IsFrozen, true);
            
            //change the value on number node 1
            numberNode1.Value = "3.0";

            // the add node must be frozen and in a temporary state
            Assert.AreEqual(addNode.IsFrozen, true);
           
            //check the value on add node.
            AssertPreviewValue(addNode.GUID.ToString(), 3);

            //now unfreeze number node.
            numberNode1.IsFrozen = false;
           
            //now number node is not frozen
            Assert.AreEqual(numberNode1.IsFrozen, false);

            //this causes the add node to switch back from temporary state
            //to frozen and not executing state
            Assert.AreEqual(addNode.IsFrozen, true);
            
            //check the value on add node. 
            AssertPreviewValue(addNode.GUID.ToString(), 5);
        }
        public void UndoAModelDeleteShouldGetTheModelInThatGroup()
        {
            //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);

            var modelToDelete = new List<ModelBase> { addNode };

            //Delete the model
            model.DeleteModelInternal(modelToDelete);

            //Check for the model count now
            Assert.AreEqual(1, annotation.SelectedModels.Count());

            //Undo the operation
            model.CurrentWorkspace.Undo();

            //Check for the model count now
            Assert.AreEqual(2, annotation.SelectedModels.Count());

        }