Пример #1
0
        /// <summary>
        ///     Creates and initializes a NodeModel from its Xml representation.
        /// </summary>
        /// <param name="elNode">XmlElement for a NodeModel.</param>
        /// <param name="context">The serialization context for initialization.</param>
        /// <param name="nodeFactory">A NodeFactory, to be used to create the node.</param>
        /// <returns></returns>
        public static CSharpCommonGraph.Node LoadNodeFromXml(
            XmlElement elNode)
        {
            var commonGraphNode = new CSharpCommonGraph.Node();

            commonGraphNode.InstanceGuid = elNode.GetAttribute("guid");

            //case 1 the node is a zero touch node
            if (elNode.GetAttribute("type") == "Dynamo.Nodes.DSFunction")
            {
                commonGraphNode.Type = elNode.GetAttribute("nickname");
            }
            else
            {
                //TODO handle other cases... like custom nodes and builtins?
                commonGraphNode.Type = elNode.GetAttribute("nickname");
            }

            var helper = new Dynamo.Utilities.XmlElementHelper(elNode);

            var x = helper.ReadDouble("x", 0.0);
            var y = helper.ReadDouble("y", 0.0);


            commonGraphNode.MetaData.Inspect = elNode.OuterXml.ToString();
            commonGraphNode.Position.X       = x;
            commonGraphNode.Position.Y       = y;
            //commonGraphNode.Ports = CreatPortsFromNode(commonGraphNode.InstanceGuid, edges);
            return(commonGraphNode);
        }
Пример #2
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static CSharpCommonGraph.Edge LoadConnectorsAndAddPortsFromXml(XmlElement connEl, IDictionary <string, CSharpCommonGraph.Node> nodes)
        {
            var helper = new Dynamo.Utilities.XmlElementHelper(connEl);

            var guid       = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart  = helper.ReadGuid("start");
            var guidEnd    = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex   = helper.ReadInteger("end_index");


            //find the elements to connect
            CSharpCommonGraph.Node start;
            if (nodes.TryGetValue(guidStart.ToString(), out start))
            {
                var startport = new CSharpCommonGraph.Port();
                startport.InstanceGuid     = start.InstanceGuid.ToString() + "_OUT" + startIndex.ToString();
                startport.MetaData.Inspect = "start";
                startport.Name             = "a cool port";
                //if we have not seen this port id before add the port, we dont want to duplicate ports
                if (start.Ports.All(x => x.InstanceGuid != startport.InstanceGuid))
                {
                    start.Ports.Add(startport);
                }


                CSharpCommonGraph.Node end;
                if (nodes.TryGetValue(guidEnd.ToString(), out end))
                {
                    var endport = new CSharpCommonGraph.Port();
                    endport.InstanceGuid     = end.InstanceGuid.ToString() + "_IN" + endIndex.ToString();
                    endport.MetaData.Inspect = "end";
                    endport.Name             = "a cool port";
                    if (end.Ports.All(x => x.InstanceGuid != endport.InstanceGuid))
                    {
                        end.Ports.Add(endport);
                    }

                    var edge = new CSharpCommonGraph.Edge();
                    edge.SrcGuid      = startport.InstanceGuid;
                    edge.DestGuid     = endport.InstanceGuid;
                    edge.InstanceGuid = guid.ToString();
                    return(edge);
                }
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static CSharpCommonGraph.Edge LoadConnectorsAndAddPortsFromXml(XmlElement connEl,IDictionary<string, CSharpCommonGraph.Node> nodes)
        {
            var helper = new Dynamo.Utilities.XmlElementHelper(connEl);

            var guid = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart = helper.ReadGuid("start");
            var guidEnd = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex = helper.ReadInteger("end_index");

             //find the elements to connect
            CSharpCommonGraph.Node start;
            if (nodes.TryGetValue(guidStart.ToString(), out start))
            {
                var startport = new CSharpCommonGraph.Port();
                startport.InstanceGuid = start.InstanceGuid.ToString()+"_OUT"+ startIndex.ToString();
                startport.MetaData.Inspect = "start";
                startport.Name = "a cool port";
                //if we have not seen this port id before add the port, we dont want to duplicate ports
                if (start.Ports.All(x=>x.InstanceGuid != startport.InstanceGuid))
                {
                      start.Ports.Add(startport);
                }

                CSharpCommonGraph.Node end;
                if (nodes.TryGetValue(guidEnd.ToString(), out end))
                {

                    var endport = new CSharpCommonGraph.Port();
                    endport.InstanceGuid = end.InstanceGuid.ToString() + "_IN" + endIndex.ToString();
                    endport.MetaData.Inspect = "end";
                    endport.Name = "a cool port";
                    if (end.Ports.All(x => x.InstanceGuid != endport.InstanceGuid))
                    {
                        end.Ports.Add(endport);
                    }

                    var edge = new CSharpCommonGraph.Edge();
                    edge.SrcGuid = startport.InstanceGuid;
                    edge.DestGuid = endport.InstanceGuid;
                    edge.InstanceGuid = guid.ToString();
                    return edge;
                }
            }

            return null;
        }
Пример #4
0
        /// <summary>
        ///     Creates and initializes a NodeModel from its Xml representation.
        /// </summary>
        /// <param name="elNode">XmlElement for a NodeModel.</param>
        /// <param name="context">The serialization context for initialization.</param>
        /// <param name="nodeFactory">A NodeFactory, to be used to create the node.</param>
        /// <returns></returns>
        public static CSharpCommonGraph.Node LoadNodeFromXml(
            XmlElement elNode)
        {
            var commonGraphNode = new CSharpCommonGraph.Node();
            commonGraphNode.InstanceGuid = elNode.GetAttribute("guid");

            //case 1 the node is a zero touch node
            if (elNode.GetAttribute("type") == "Dynamo.Nodes.DSFunction")
            {
                commonGraphNode.Type = elNode.GetAttribute("nickname");
            }
            else
            {
                //TODO handle other cases... like custom nodes and builtins?
                commonGraphNode.Type = elNode.GetAttribute("nickname");
            }

             var helper = new Dynamo.Utilities.XmlElementHelper(elNode);

            var x = helper.ReadDouble("x",0.0);
            var y = helper.ReadDouble("y",0.0);

            commonGraphNode.MetaData.Inspect = elNode.OuterXml.ToString();
            commonGraphNode.Position.X = x;
            commonGraphNode.Position.Y = y;
            //commonGraphNode.Ports = CreatPortsFromNode(commonGraphNode.InstanceGuid, edges);
            return commonGraphNode;
        }