Пример #1
0
 public void TestCreateCodeBlockNodeFrom00()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         MigrationManager.CreateCodeBlockNodeFrom(null);
     });
 }
Пример #2
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode       = data.MigratedNodes.ElementAt(0);
            XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);

            // Create CBN based on the input/output port count
            string codeText = ""; int num = 1;

            foreach (XmlElement childNode in oldNode.ChildNodes)
            {
                if (childNode.Name == "Output")
                {
                    codeText += "element.GetParameterValueByName(param" + num++ + ");";
                    if (num > 1)
                    {
                        codeText += "\n";
                    }
                }
            }

            // To avoid empty CBN
            if (codeText == "")
            {
                codeText = "element;";
            }

            codeBlockNode.SetAttribute("CodeText", codeText);
            codeBlockNode.SetAttribute("nickname", "Get Parameters");

            migrationData.AppendNode(codeBlockNode);
            return(migrationData);
        }
Пример #3
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            if ((data.FindFirstConnector(new PortId(oldNodeId, 1, PortType.OUTPUT)) != null) ||
                (data.FindFirstConnector(new PortId(oldNodeId, 2, PortType.OUTPUT)) != null))
            {
                // If the second or third output port is utilized, migrate to CBN
                XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);
                codeBlockNode.SetAttribute("CodeText",
                                           "p = Plane.ByBestFitThroughPoints(XYZs);\n" +
                                           "p.Normal.AsPoint();\n" +
                                           "p.Origin;");
                codeBlockNode.SetAttribute("nickname", "Best Fit Plane");
                migrationData.AppendNode(codeBlockNode);
            }
            else
            {
                // When only the first output port is utilized, migrate directly
                var newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);
                MigrationManager.SetFunctionSignature(newNode, "ProtoGeometry.dll",
                                                      "Plane.ByBestFitThroughPoints", "Plane.ByBestFitThroughPoints");
                migrationData.AppendNode(newNode);
            }

            return(migrationData);
        }
Пример #4
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            if (data.FindFirstConnector(new PortId(oldNodeId, 1, PortType.Output)) != null)
            {
                // If the second output port is utilized, migrate to CBN
                XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);
                codeBlockNode.SetAttribute("CodeText",
                                           "Line.ByBestFitThroughPoints(XYZs)\n" +
                                           ".Direction.Normalized().AsPoint();\n" +
                                           "Point.ByCoordinates(Math.Average(XYZs.X),\n" +
                                           "Math.Average(XYZs.Y), Math.Average(XYZs.Z));");
                codeBlockNode.SetAttribute("nickname", "Best Fit Line");
                migrationData.AppendNode(codeBlockNode);
            }
            else
            {
                // When only the first output port is utilized, migrate to a chain of nodes

                var newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);
                MigrationManager.SetFunctionSignature(newNode, "ProtoGeometry.dll",
                                                      "Vector.AsPoint", "Vector.AsPoint");

                var lineNode = MigrationManager.CreateFunctionNode(
                    data.Document, oldNode, 0, "ProtoGeometry.dll",
                    "Line.ByBestFitThroughPoints",
                    "Line.ByBestFitThroughPoints@Point[]");
                string lineNodeId = MigrationManager.GetGuidFromXmlElement(lineNode);

                var directionNode = MigrationManager.CreateFunctionNode(
                    data.Document, oldNode, 1, "ProtoGeometry.dll",
                    "Line.Direction", "Line.Direction");

                var normalizedNode = MigrationManager.CreateFunctionNode(
                    data.Document, oldNode, 2, "ProtoGeometry.dll",
                    "Vector.Normalized", "Vector.Normalized");

                migrationData.AppendNode(newNode);
                migrationData.AppendNode(lineNode);
                migrationData.AppendNode(directionNode);
                migrationData.AppendNode(normalizedNode);

                // Update connectors
                PortId     oldInPort0  = new PortId(oldNodeId, 0, PortType.Input);
                PortId     lineInPort0 = new PortId(lineNodeId, 0, PortType.Input);
                XmlElement connector0  = data.FindFirstConnector(oldInPort0);

                data.ReconnectToPort(connector0, lineInPort0);
                data.CreateConnector(lineNode, 0, directionNode, 0);
                data.CreateConnector(directionNode, 0, normalizedNode, 0);
                data.CreateConnector(normalizedNode, 0, newNode, 0);
            }

            return(migrationData);
        }
Пример #5
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            var    migratedData = new NodeMigrationData(data.Document);
            var    oldNode      = data.MigratedNodes.ElementAt(0);
            string oldNodeId    = MigrationManager.GetGuidFromXmlElement(oldNode);

            var codeBlockNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);

            codeBlockNode.SetAttribute("CodeText",
                                       "p=Plane.ByOriginNormal(origin,axis.AsVector());\n" +
                                       "cs=CoordinateSystem.ByPlane(p);\n" +
                                       "Cylinder.ByRadiusHeight(cs,r,h);");
            migratedData.AppendNode(codeBlockNode);

            //create and reconnect the connecters
            var        oldInPort0 = new PortId(oldNodeId, 0, PortType.INPUT);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);

            var        oldInPort1 = new PortId(oldNodeId, 1, PortType.INPUT);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);

            var        oldInPort2 = new PortId(oldNodeId, 2, PortType.INPUT);
            XmlElement connector2 = data.FindFirstConnector(oldInPort2);

            var        oldInPort3 = new PortId(oldNodeId, 3, PortType.INPUT);
            XmlElement connector3 = data.FindFirstConnector(oldInPort3);

            var oldOutPort0      = new PortId(oldNodeId, 0, PortType.OUTPUT);
            var oldOutConnectors = data.FindConnectors(oldOutPort0);

            var newInPort0  = new PortId(oldNodeId, 0, PortType.INPUT);
            var newInPort1  = new PortId(oldNodeId, 1, PortType.INPUT);
            var newInPort2  = new PortId(oldNodeId, 2, PortType.INPUT);
            var newInPort3  = new PortId(oldNodeId, 3, PortType.INPUT);
            var newOutPort2 = new PortId(oldNodeId, 2, PortType.OUTPUT);

            data.ReconnectToPort(connector0, newInPort1);
            data.ReconnectToPort(connector1, newInPort0);
            data.ReconnectToPort(connector2, newInPort2);
            data.ReconnectToPort(connector3, newInPort3);

            if (oldOutConnectors.Any())
            {
                foreach (var connector in oldOutConnectors)
                {
                    //connect anything that previously was connected to output port 0
                    //to output port 2
                    data.ReconnectToPort(connector, newOutPort2);
                }
            }

            return(migratedData);
        }
Пример #6
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);

            codeBlockNode.SetAttribute("CodeText", "{{0,0},{1,1}};");
            codeBlockNode.SetAttribute("nickname", "Get Surface Domain");

            migrationData.AppendNode(codeBlockNode);
            return(migrationData);
        }
Пример #7
0
        public static NodeMigrationData Migrate_Range(NodeMigrationData data)
        {
            var migrationData = new NodeMigrationData(data.Document);
            var oldNode       = data.MigratedNodes.ElementAt(0);
            var valEls        = oldNode.GetElementsByTagName("System.Double"); // The Value node
            var val           = valEls[0].Attributes["value"].Value;

            double result = 0.0;

            if (double.TryParse(val, out result))
            {
                return(data);
            }

            var newNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);

            newNode.Attributes["CodeText"].Value = val + ";";
            migrationData.AppendNode(newNode);
            return(migrationData);
        }
Пример #8
0
        public void TestCreateCodeBlockNodeFrom01()
        {
            XmlElement srcElement = xmlDocument.CreateElement("Element");

            srcElement.SetAttribute("isVisible", "true");
            srcElement.SetAttribute("lacing", "Longest");

            XmlElement dstElement = MigrationManager.CreateCodeBlockNodeFrom(srcElement);

            Assert.IsNotNull(dstElement);
            Assert.IsNotNull(dstElement.Attributes);

            XmlAttributeCollection attribs = dstElement.Attributes;

            Assert.AreEqual(6, attribs.Count);
            Assert.AreEqual("true", attribs["isVisible"].Value);
            Assert.AreEqual("Disabled", attribs["lacing"].Value);
            Assert.AreEqual("Dynamo.Graph.Nodes.CodeBlockNodeModel", attribs["type"].Value);
            Assert.AreEqual(string.Empty, attribs["CodeText"].Value);
            Assert.AreEqual("false", attribs["ShouldFocus"].Value);
            Assert.AreEqual("Code Block", attribs["nickname"].Value);
        }