<html> <head> <title>Developer's Guide: The class HierarchyNode </title> </head> <body bgcolor=white text=black link=blue vlink=navy alink=red> <TABLE WIDTH="100%"> <TR> <TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH> <TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH> <TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH> </TR> <TR> <TD ALIGN="left"><A HREF="devguide-12.html">The class Bounded </A></TD> <TD ALIGN="center"><A HREF="devguide-9.html">The Document and Graphics Classes</A></TD> <TD ALIGN="right"><A HREF="devguide-14.html">The class Protocols</A></TD> </TR> </TABLE> <HR NOSHADE> <H2><FONT face="Helvetica,Arial"><A NAME="N1"></A>The class <A NAME="N2"></A><tt>HierarchyNode</tt> </font></H2> <P>In Sketch, a document consists of a hierarchy of objects. Each object has at most one parent and belongs to at most one document. That is, an object may not belong to any compound object or document, but if it belongs to one, it cannot be part of two compound objects or two documents.</P> <P>An object in this hierarchy knows which parent and document it belongs to.</P> <P>The class <tt>HierarchyNode</tt> provides the standard interface for managing this hierarchy and the references to the parent and the document for child objects. The default behavior for parents is defined by the class <A HREF="devguide-17.html#N2"><tt>Compound</tt></A>.</P> <P>No object derived from this class should override the methods defined here except as documented.</P> <H3><FONT face="Helvetica,Arial"><A NAME="N3"></A>Instance Variables</font></H3> <P><tt>HierarchyNode</tt> uses the following instance variables:</P> <P> <DL> <DT><B><CODE>parent</CODE></B><DD> <P>The parent of the object. Since the parent also has a reference to its child this introduces a circular reference. Therefore we must make sure that these references are deleted when the document is destroyed. The <A HREF="#N6"><tt>Destroy</tt></A> method takes care of this.</P> <P>If the object is not currently the child of a compound object this variable should be <CODE>None</CODE>.</P> <DT><B><CODE>document</CODE></B><DD> <P>The document the object belongs to. If the object has just been created and is not yet inserted into the document, or when the object is stored in the application's clipboard, this variable is <CODE>None</CODE>.</P> </DL> </P> <P>In general, if <CODE>parent</CODE> is not <CODE>None</CODE>, <CODE>document</CODE> should be the same as <CODE>parent.document</CODE>.</P> <H3><FONT face="Helvetica,Arial"><A NAME="N4"></A>Methods</font></H3> <P>Methods defined in <tt>HierarchyNode</tt> (incomplete):</P> <P> <DL> <DT><B><A NAME="N5"></A><tt>__init__</tt></B><DD> <P>A <tt>HierarchyNode</tt>'s <tt>__init__</tt> method (and that of all derived classes) must accept an optional keyword argument called <CODE>duplicate</CODE> with the default value <CODE>None</CODE> and it must be callable with just that argument. This is used by the standard <A HREF="#N9"><tt>Duplicate</tt></A> method.</P> <DT><B><A NAME="N6"></A><tt>Destroy()</tt></B><DD> <P>Called by the parent when the document is destroyed. This method should delete any circular references. A Compound object should call the <tt>Destroy</tt> method of each of its children.</P> <P>The default implementation just sets <CODE>parent</CODE> to <CODE>None</CODE>. Derived classes should extend this method if necessary.</P> <DT><B><A NAME="N7"></A><tt>SetParent(<i>parent</i>)</tt></B><DD> <P>Set self's instance variable <CODE>parent</CODE> to <i>parent</i>.</P> <DT><B><A NAME="N8"></A><tt>SetDocument(<i>document</i>)</tt></B><DD> <P>Set self's instance variable <CODE>document</CODE> to <i>document</i>.</P> <DT><B><A NAME="N9"></A><tt>Duplicate()</tt></B><DD> <P>Return a duplicate of self. The default implementation just returns <CODE>self.__class__(duplicate = self)</CODE>. Therefore, the class's constructor must be callable with a single keyword argument <CODE>duplicate</CODE>.</P> </DL> </P> <HR NOSHADE> <TABLE WIDTH="100%"> <TR> <TD ALIGN="left"><A HREF="devguide-12.html">The class Bounded </A></TD> <TD ALIGN="center"><A HREF="devguide-9.html">The Document and Graphics Classes</A></TD> <TD ALIGN="right"><A HREF="devguide-14.html">The class Protocols</A></TD> </TR> <TR> <TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH> <TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH> <TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH> </TR> </TABLE> </body> </html>