Exemplo n.º 1
0
        /// <summary>
        /// SERIALIZATION: Creates a NodeGraphView from a Serialized XML Copy
        /// </summary>
        /// <param name="p_XmlTreeNode">the parent XmlTreeNode used in serialization</param>
        /// <param name="p_Panel">the panel that will contain this NodeGraphView</param>
        public NodeGraphView(XmlTreeNode p_XmlTreeNode, NodeGraphPanel p_Panel)
        {
            System.Globalization.CultureInfo v_IntlCultureInfo = new System.Globalization.CultureInfo("en-us");
            this.m_oPanel = p_Panel;
            this.ViewX    = int.Parse(p_XmlTreeNode.m_attributes["ViewX"]);
            this.ViewY    = int.Parse(p_XmlTreeNode.m_attributes["ViewY"]);
            this.ViewZoom = float.Parse(p_XmlTreeNode.m_attributes["ViewZoom"], v_IntlCultureInfo);


            this.m_NodeCollection = new List <NodeGraphNode>();

            XmlTreeNode v_NodesXml = p_XmlTreeNode.GetFirstChild("NodeGraphNodeCollection");

            foreach (XmlTreeNode i_ChildNode in v_NodesXml.m_childNodes)
            {
                this.m_NodeCollection.Add(NodeGraphNode.DeserializeFromXML(i_ChildNode, this));
            }


            this.m_Links = new List <NodeGraphLink>();

            XmlTreeNode v_LinksXml = p_XmlTreeNode.GetFirstChild("NodeGraphLinkCollection");

            foreach (XmlTreeNode i_ChildLink in v_LinksXml.m_childNodes)
            {
                this.m_Links.Add(NodeGraphLink.DeserializeFromXML(i_ChildLink, this));
            }

            this.m_SelectedItems = new List <NodeGraphNode>();
        }
Exemplo n.º 2
0
        /// <summary>
        /// CLIPBOARD: If contains a NodeGraphClipboard.xml, deserializes and add nodes to current view.
        /// </summary>
        public void PasteSelectionFromClipBoard()
        {
            if (Clipboard.ContainsFileDropList())
            {
                if (Clipboard.GetFileDropList().Contains(Path.GetTempPath() + "NodeGraphClipboard.xml"))
                {
                    XmlTree     v_Contents     = XmlTree.FromFile(Path.GetTempPath() + "NodeGraphClipboard.xml");
                    XmlTreeNode v_ContentsRoot = v_Contents.m_rootNode;
                    XmlTreeNode v_NodesRoot    = v_ContentsRoot.GetFirstChild("Nodes");
                    XmlTreeNode v_LinksRoot    = v_ContentsRoot.GetFirstChild("Links");

                    int PreviousNodeCount = this.m_NodeCollection.Count;

                    NodeGraphNode v_CurrentNode;

                    foreach (XmlTreeNode i_Node in v_NodesRoot.m_childNodes)
                    {
                        v_CurrentNode    = NodeGraphNode.DeserializeFromXML(i_Node, this);
                        v_CurrentNode.X += 10;
                        v_CurrentNode.Y += 10;
                        v_CurrentNode.UpdateHitRectangle();
                        this.NodeCollection.Add(v_CurrentNode);
                    }


                    int v_InId, v_InConnectorIdx, v_OutId, v_OutConnectorIdx;

                    foreach (XmlTreeNode i_Link in v_LinksRoot.m_childNodes)
                    {
                        v_InId            = int.Parse(i_Link.m_attributes["InputNodeId"]);
                        v_InConnectorIdx  = int.Parse(i_Link.m_attributes["InputNodeConnectorIdx"]);
                        v_OutId           = int.Parse(i_Link.m_attributes["OutputNodeId"]);
                        v_OutConnectorIdx = int.Parse(i_Link.m_attributes["OutputNodeConnectorIdx"]);


                        // Relinking
                        this.m_Links.Add(new NodeGraphLink(
                                             // P_INPUT
                                             this.m_NodeCollection[PreviousNodeCount + v_InId].Connectors[v_InConnectorIdx],
                                             // P_OUTPUT
                                             this.m_NodeCollection[PreviousNodeCount + v_OutId].Connectors[v_OutConnectorIdx],
                                             // CONNECTOR TYPE
                                             this.m_NodeCollection[PreviousNodeCount + v_InId].Connectors[v_InConnectorIdx].DataType
                                             ));
                    }
                }
                ParentPanel.Refresh();
            }
        }