Example #1
0
        /// <summary>
        /// Copy the node to another root graph.
        /// Copies the attributes as well, as far as the attributes have been
        /// introduced in the destination graph.
        /// </summary>
        public Node CopyToOtherRoot(RootGraph destination)
        {
            Node result = destination.GetOrAddNode(GetName());

            _ = CopyAttributesTo(result);
            return(result);
        }
Example #2
0
        public static RootGraph FromDotString(string graph)
        {
            IntPtr ptr    = Imagmemread(graph);
            var    result = new RootGraph(ptr);

            result.UpdateMemoryPressure();
            return(result);
        }
Example #3
0
 /// <summary>
 /// Introduces an attribute for nodes in the given graph by giving a default value.
 /// A given default can be overwritten by calling this method again.
 /// </summary>
 public static void IntroduceAttribute(RootGraph root, string name, string deflt)
 {
     if (deflt == null)
     {
         throw new ArgumentNullException(nameof(deflt));
     }
     Agattr(root._ptr, 1, name, deflt);
 }
Example #4
0
        /// <summary>
        /// Create a deepcopy of the graph as a new root graph.
        /// All nodes, edges and subgraphs contained in self are copied.
        ///
        /// No side effects to self.
        /// </summary>
        /// <returns></returns>
        public RootGraph Clone(string resultname)
        {
            RootGraph result = RootGraph.CreateNew(resultname, GetGraphType());

            CopyAttributesTo(result);
            CloneInto(result);
            result.UpdateMemoryPressure();
            return(result);
        }
 /// <summary>
 /// Argument root may be null.
 /// In that case, it is assumed this is a RootGraph, and MyRootGraph is set to `this`.
 /// </summary>
 internal CGraphThing(IntPtr ptr, RootGraph root) : base(ptr)
 {
     if (root == null)
     {
         MyRootGraph = (RootGraph)this;
     }
     else
     {
         MyRootGraph = root;
     }
 }
 /// <summary>
 /// rootgraph must not be null
 /// </summary>
 internal SubGraph(IntPtr ptr, RootGraph rootgraph) : base(ptr, rootgraph)
 {
 }
Example #7
0
 /// <summary>
 /// rootgraph must not be null
 /// </summary>
 internal Node(IntPtr ptr, RootGraph rootgraph) : base(ptr, rootgraph)
 {
 }
Example #8
0
 public static void IntroduceAttributeHtml(RootGraph root, string name, string deflt)
 {
     _ = deflt ?? throw new ArgumentNullException(nameof(deflt));
     AgattrHtml(root._ptr, 2, name, deflt);
 }
Example #9
0
        public void CloneInto(RootGraph target)
        {
            // Copy all nodes and edges
            foreach (var node in Nodes())
            {
                string nodename = node.GetName();
                Node   newnode  = target.GetOrAddNode(nodename);

                foreach (var edge in node.EdgesOut(this))
                {
                    Node head = edge.Head();
                    Debug.Assert(Contains(head));
                    Node tail = edge.Tail();
                    Debug.Assert(node.Equals(tail));
                    string headname = head.GetName();
                    Node   newhead  = target.GetOrAddNode(headname);
                    string tailname = tail.GetName();
                    Node   newtail  = target.GetNode(tailname);

                    string edgename = edge.GetName();
                    Edge   newedge  = target.GetOrAddEdge(newtail, newhead, edgename);
                    edge.CopyAttributesTo(newedge);
                }
                node.CopyAttributesTo(newnode);
            }

            // Copy all subgraphs
            foreach (var subgraph in Descendants())
            {
                string subgraphname = subgraph.GetName();
                Graph  parent       = subgraph.Parent();
                Graph  newparent;
                if (parent.Equals(this))
                {
                    newparent = target;
                }
                else
                {
                    string parentname = parent.GetName();
                    newparent = target.GetDescendantByName(parentname);
                    Debug.Assert(newparent != null);
                }
                SubGraph newsubgraph = newparent.GetOrAddSubgraph(subgraphname);
                subgraph.CopyAttributesTo(newsubgraph);

                // Add the (already created) nodes and edges to newly created subgraph
                foreach (var node in subgraph.Nodes())
                {
                    string nodename = node.GetName();
                    Node   newnode  = target.GetNode(nodename);
                    Debug.Assert(newnode != null);
                    newsubgraph.AddExisting(newnode);

                    foreach (var edge in node.EdgesOut(subgraph))
                    {
                        Node head = edge.Head();
                        Node tail = edge.Tail();
                        Debug.Assert(node.Equals(tail));

                        string headname = head.GetName();
                        Node   newhead  = target.GetNode(headname);
                        string tailname = tail.GetName();
                        Node   newtail  = target.GetNode(tailname);

                        string edgename = edge.GetName();
                        Edge   newedge  = target.GetEdge(newtail, newhead, edgename);
                        newsubgraph.AddExisting(newedge);
                    }
                    node.CopyAttributesTo(newnode);
                }
            }
        }