当前位置: 首页>>代码示例>>C#>>正文


C# Nodes.DSFunction类代码示例

本文整理汇总了C#中Dynamo.Nodes.DSFunction的典型用法代码示例。如果您正苦于以下问题:C# DSFunction类的具体用法?C# DSFunction怎么用?C# DSFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DSFunction类属于Dynamo.Nodes命名空间,在下文中一共展示了DSFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SwitchingToCustomWorkspaceWithSelectionShouldNotAllowGeometricOperations

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

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

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

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

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

            // Step 4: Verify that the geometry operations are 
            // disabled despite the fact that there is still selection.
            Assert.AreEqual(true, ViewModel.CurrentSpaceViewModel.HasSelection);
            Assert.AreEqual(false, ViewModel.CurrentSpaceViewModel.IsGeometryOperationEnabled);
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:30,代码来源:WorkspaceGeneralOperations.cs

示例2: CleanWorkbenchClearsUndoStack

        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);
        }
开发者ID:ke-yu,项目名称:Dynamo,代码行数:26,代码来源:WorkspaceSaving.cs

示例3: CanCreatePreset

        public void CanCreatePreset()
        {
            //Create a Node
            var numberNode = new DoubleInput();
            numberNode.Value = "1";
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(numberNode, false);

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

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

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

            DynamoSelection.Instance.ClearSelection();

            DynamoSelection.Instance.Selection.Add(addNode);

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

            DynamoSelection.Instance.Selection.Add(numberNode);

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

        }
开发者ID:jimb000,项目名称:Dynamo,代码行数:30,代码来源:PresetViewModelTest.cs

示例4: CanCreateGroupIfANodeIsAlreadyInAGroup

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

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

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

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

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

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

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

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

        }
开发者ID:qingemeng,项目名称:Dynamo,代码行数:29,代码来源:AnnotationViewModelTests.cs

示例5: DescriptionTest

        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);
        }
开发者ID:rafatahmed,项目名称:Dynamo,代码行数:58,代码来源:TestZeroTouchClass.cs

示例6: CanAddToSelectionCommand

        public void CanAddToSelectionCommand()
        {
            int numNodes = 100;

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

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

                CurrentDynamoModel.AddToSelection(addNode);
                Assert.AreEqual(i + 1, DynamoSelection.Instance.Selection.Count);
            }
        }
开发者ID:qingemeng,项目名称:Dynamo,代码行数:16,代码来源:CoreTests.cs

示例7: SetupNumberNodesAndPresets

        private List<NodeModel> SetupNumberNodesAndPresets()
        {
            var model = CurrentDynamoModel;
            //create some numbers
            var numberNode1 = new DoubleInput();
            numberNode1.Value = "1";
            var numberNode2 = new DoubleInput();
            numberNode2.Value = "2";
            var addNode = new DSFunction(model.LibraryServices.GetFunctionDescriptor("+"));

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

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

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

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

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

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

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

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

            return new List<NodeModel>() { numberNode1, numberNode2,addNode };
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:45,代码来源:PresetsTests.cs

示例8: TestBasicAttributes

        public void TestBasicAttributes()
        {
            var sumNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+")) { X = 400, Y = 100 };

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

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

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

            //Deserialize and Assert Old values
            sumNode.Deserialize(serializedEl, SaveContext.Undo);
            Assert.AreEqual(400, sumNode.X);
            Assert.AreEqual(100, sumNode.Y);
            Assert.AreEqual("+", sumNode.NickName);
            Assert.AreEqual(LacingStrategy.Shortest, sumNode.ArgumentLacing);
            Assert.AreEqual(true, sumNode.IsVisible);
            Assert.AreEqual(true, sumNode.IsUpstreamVisible);
            Assert.AreEqual(ElementState.Dead, sumNode.State);
        }
开发者ID:rafatahmed,项目名称:Dynamo,代码行数:43,代码来源:SerializationTests.cs

示例9: CreateGroupAroundNodes

        public void CreateGroupAroundNodes()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddNode(addNode, false);
           
            //verify the node was created
            Assert.AreEqual(1, ViewModel.Model.CurrentWorkspace.Nodes.Count());

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

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

            //verify whether group is not empty
            Assert.AreNotEqual(0, annotation.Y);
            Assert.AreNotEqual(0, annotation.X);
            Assert.AreNotEqual(0, annotation.Width);
            Assert.AreNotEqual(0, annotation.Height);           
        }
开发者ID:qingemeng,项目名称:Dynamo,代码行数:23,代码来源:AnnotationViewModelTests.cs

示例10: CanAddAnnotation

        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);
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:23,代码来源:AnnotationModelTest.cs

示例11: UndoAnnotationText

        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);
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:36,代码来源:AnnotationModelTest.cs

示例12: TogglePresetOptionVisibility

        public void TogglePresetOptionVisibility()
        {
            //Create a Node
            var addNode = new DSFunction(ViewModel.Model.LibraryServices.GetFunctionDescriptor("+"));
            ViewModel.Model.CurrentWorkspace.AddAndRegisterNode(addNode, false);

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

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

            DynamoSelection.Instance.Selection.Add(addNode);

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

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

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

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

            //Check the Preset option visibility.
            Assert.AreEqual(false, ViewModel.EnablePresetOptions);
        }
开发者ID:jimb000,项目名称:Dynamo,代码行数:36,代码来源:PresetViewModelTest.cs

示例13: CanAdd100NodesToClipboardAndPaste3Times

        public void CanAdd100NodesToClipboardAndPaste3Times()
        {
            int numNodes = 100;

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

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

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

            CurrentDynamoModel.Copy();

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

            int numPastes = 3;
            for (int i = 1; i <= numPastes; i++)
            {
                CurrentDynamoModel.Paste();
                Assert.AreEqual(numNodes, CurrentDynamoModel.ClipBoard.Count);
                Assert.AreEqual(numNodes * (i + 1), CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
            }
        }
开发者ID:qingemeng,项目名称:Dynamo,代码行数:28,代码来源:CoreTests.cs

示例14: CanClearWorkspaceWithNodes

        public void CanClearWorkspaceWithNodes()
        {
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());

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

            CurrentDynamoModel.ClearCurrentWorkspace();
            Assert.AreEqual(0, CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
        }
开发者ID:qingemeng,项目名称:Dynamo,代码行数:13,代码来源:CoreTests.cs

示例15: TestDefaultArgumentTooltip

 public void TestDefaultArgumentTooltip()
 {
     var node =
         new DSFunction(CurrentDynamoModel.LibraryServices.GetFunctionDescriptor("[email protected],double"));
     CurrentDynamoModel.ExecuteCommand(new Dynamo.Models.DynamoModel.CreateNodeCommand(node, 0, 0, true, false));
     Assert.IsTrue(node.InPorts[0].ToolTipContent.Equals("double\nDefault value : 0"));
     node.InPorts[0].UsingDefaultValue = false;
     Assert.IsTrue(node.InPorts[0].ToolTipContent.Equals("double\nDefault value : 0 (disabled)"));
 }
开发者ID:RevitLution,项目名称:Dynamo,代码行数:9,代码来源:DSEvaluationModelTest.cs


注:本文中的Dynamo.Nodes.DSFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。