/// <summary> /// Copy attributes from one cgraph object to another. /// Throw argument exception if self and destination are not of the same type. /// Also copies attributes that haven't been introduced in the destination object, /// unless introduce_new_attrs is false. /// Return code indicates success or failure. /// </summary> public int CopyAttributesTo(CGraphThing destination, bool introduce_new_attrs = true) { if (!((this is Node && destination is Node) || (this is Edge && destination is Edge) || (this is Graph && destination is Graph))) { throw new ArgumentException("Argument must be of the same type as self."); } // Copying the attributes doesn't work if they have not been introduced in the graph // Moreover, the copying may just stop at some point if copying of a single attribute fails if (introduce_new_attrs && MyRootGraph._ptr != destination.MyRootGraph._ptr) { CloneAttributeDeclarations(MyRootGraph._ptr, destination.MyRootGraph._ptr); } // agcopyattr returns non-zero number on failure. // Problems have been observed while copying between edges (of the same graph) // Hypothesis: are the pointers different in this case? // Hypothesis 2: does it have something to do with the comment "Do not copy key attribute for edges, // as this must be distinct." in the graphviz source code? // Returncode 1 has been observed while copying rootgraphs, while the number of attributes was 0 Debug.Assert(_ptr != destination._ptr); int success = Agcopyattr(_ptr, destination._ptr); // We implement a workaround for copying between edges if (success != 0) { // Fail for unknown failing cases if (GetType() != typeof(Edge) && GetAttributes().Count != 0) { Debug.Fail("Copying attributes failed"); } // We work around this doing the following: var attrs = GetAttributes(); foreach (var key in attrs.Keys) { destination.SetAttribute(key, attrs[key]); } } return(0); }
/// <summary> /// Delete the given thing from the graph. /// Is this is a root graph, and thing is a node, its edges are delete too. /// </summary> public void Delete(CGraphThing thing) { int return_code = Agdelete(_ptr, thing._ptr); Debug.Assert(return_code == 0); }
public bool Contains(CGraphThing thing) { return(Agcontains(_ptr, thing._ptr) != 0); }