# gcu::Object Class Reference

`#include <gcu/object.h>`

Inheritance diagram for gcu::Object:

List of all members.

## Public Member Functions

| Object (TypeId Id=OtherType)
virtual | ~Object ()
TypeId | GetType ()
void | SetId (gchar *Id)
const gchar * | GetId ()
void | AddChild (Object *object)
Object * | GetMolecule ()
Object * | GetReaction ()
Object * | GetGroup ()
Document * | GetDocument ()
Object * | GetParentOfType (TypeId Id)
Object * | GetChild (const gchar *Id)
Object * | GetFirstChild (map< string, Object * >::iterator &i)
Object * | GetNextChild (map< string, Object * >::iterator &i)
Object * | GetDescendant (const gchar *Id)
Object * | GetParent ()
void | SetParent (Object *Parent)
virtual xmlNodePtr | Save (xmlDocPtr xml)
virtual bool | Load (xmlNodePtr node)
virtual void | Move (double x, double y, double z=0.)
virtual void | Transform2D (Matrix2D &m, double x, double y)
bool | SaveChildren (xmlDocPtr xml, xmlNodePtr node)
void | SaveId (xmlNodePtr node)
xmlNodePtr | GetNodeByProp (xmlNodePtr node, char *Property, char *Id)
xmlNodePtr | GetNextNodeByProp (xmlNodePtr node, char *Property, char *Id)
xmlNodePtr | GetNodeByName (xmlNodePtr node, char *Name)
xmlNodePtr | GetNextNodeByName (xmlNodePtr node, char *Name)
virtual void | Add (GtkWidget *w)
virtual void | Print (GnomePrintContext *pc)
virtual void | Update (GtkWidget *w)
virtual void | SetSelected (GtkWidget *w, int state)
bool | HasChildren ()
unsigned | GetChildrenNumber ()
virtual Object * | GetAtomAt (double x, double y, double z=0.)
virtual bool | Build (list< Object * > &Children) throw (invalid_argument)
virtual double | GetYAlign ()
virtual bool | BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y)
void | EmitSignal (SignalId Signal)
virtual bool | OnSignal (SignalId Signal, Object *Child)
void | Lock (bool state=true)
bool | IsLocked ()
Object * | GetFirstLink (set< Object * >::iterator &i)
Object * | GetNextLink (set< Object * >::iterator &i)
void | Unlink (Object *object)
virtual void | OnUnlink (Object *object)
void | GetPossibleAncestorTypes (set< TypeId > &types)

## Static Public Member Functions

static TypeId | AddType (string TypeName, Object *(*CreateFunc)(), TypeId id=OtherType)
static Object * | CreateObject (const string &TypeName, Object *parent=NULL)
static TypeId | GetTypeId (const string &Name)
static string | GetTypeName (TypeId Id)
static void | AddRule (TypeId type1, RuleId rule, TypeId type2)
static void | AddRule (const string &type1, RuleId rule, const string &type2)
static const set< TypeId > & | GetRules (TypeId type, RuleId rule)
static const set< TypeId > & | GetRules (const string &type, RuleId rule)
static void | SetCreationLabel (TypeId Id, string Label)
static const string & | GetCreationLabel (TypeId Id)
static const string & | GetCreationLabel (const string &TypeName)
static SignalId | CreateNewSignalId ()

## Detailed Description

This is the base class for most other objects in the gcu namespace.

Definition at line 127 of file object.h.

## Constructor & Destructor Documentation

gcu::Object::Object | ( | TypeId | Id = `OtherType` | ) |

Used to create an object of type Id. Shold only be called from the constructor of a derived class.

virtual gcu::Object::~Object | ( |  | ) | `[virtual]`

The standard destructor of Object instances. Automatically called when the object is destroyed.

## Member Function Documentation

TypeId gcu::Object::GetType | ( |  | ) | `[inline]`

Returns:
  the type of the object. If the type is at least equal to OtherType, it is a dynamically created type returned by the Object::AddType method.

Definition at line 143 of file object.h.

void gcu::Object::SetId | ( | gchar * | Id | ) |

Parameters:

  | Id,: | the id of the Object instance.

Every object must have an Id, since searches in the document tree uses it.

const gchar* gcu::Object::GetId | ( |  | ) | `[inline]`

Returns:
  the Id of the Object instance.

Definition at line 153 of file object.h.

void gcu::Object::AddChild | ( | Object * | object | ) |

Parameters:

  | object*,: | the Object instance to add as a child.

Each Object instance maintains a list of its children. If object has already a parent, it will be removed from its parent children list. The new parent Object must have a Document ancestor to ensure that Ids are unique.

Object* gcu::Object::GetMolecule | ( |  | ) |

Used to get the Molecule in the Object instances ancestors.

Returns:
  the first Object of type MoleculeType encountered when exploring the Objects tree or NULL if none is found.

Object* gcu::Object::GetReaction | ( |  | ) |

Used to get the Reaction in the Object instances ancestors.

Returns:
  the first Object of type ReactionType encountered when exploring the Objects tree or NULL if none is found.

Object* gcu::Object::GetGroup | ( |  | ) |

Used to get the highest ancestor just before the document in the Object instances ancestors.

Returns:
  the last Object of type ReactionType encountered before the document when exploring the Objects tree or NULL if the object's parent is the document itself.

Document* gcu::Object::GetDocument | ( |  | ) |

Used to get the Document in the Object instances ancestors.

Returns:
  the first Object of type DocumentType encountered when exploring the Objects tree (only one should be found) or NULL if none is found.

Object* gcu::Object::GetParentOfType | ( | TypeId | Id | ) |

Parameters:

  | Id,: | the type of the ancestor searched.

Used to get the first ancestor of type Id in the Object instances ancestors. GetDocument, GetMolecule and GetReaction are special cases of this method.

Returns:
  the first Object of type Id encountered when exploring the Objects tree (only one should be found) or NULL if none is found.

Object* gcu::Object::GetChild | ( | const gchar * | Id | ) |

Parameters:

  | Id,: | the Id of the child searched.

To search the Object in lower shells of the tree, use the Object::GetDescendant method.

Returns:
  the Object instance of type Id if found in the children list or NULL if not found.

Object* gcu::Object::GetFirstChild | ( | map< string, Object * >::iterator & | i | ) |

Parameters:

  | i,: | a C++ std::map iterator.

Use this function to retrieve the first child of the object and initialize the iterator.

Returns:
  the first child of the object or NULL.

Object* gcu::Object::GetNextChild | ( | map< string, Object * >::iterator & | i | ) |

Parameters:

  | i,: | a C++ std::map iterator initialized by Object::GetFirstChild.

Use this method to iterate through the list of the Object children.

Returns:
  the next child of the object or NULL.

Object* gcu::Object::GetDescendant | ( | const gchar * | Id | ) |

Parameters:

  | Id,: | the Id of the descendant searched.

This method searches the Object in its children and if not found calls the GetDescendant method for its children.

Returns:
  the Object instance of type Id if found in the decendants or NULL if not found.

Object* gcu::Object::GetParent | ( |  | ) | `[inline]`

Returns:
  the parent of the Object.

Definition at line 231 of file object.h.

void gcu::Object::SetParent | ( | Object * | Parent | ) |

Parameters:

  | Parent,: | the new parent of the Object or NULL.

When Parent is not NULL, this is equivalent to

     Parent->AddChild(this);

Otherwise, it removes the Object from the Document tree.

virtual xmlNodePtr gcu::Object::Save | ( | xmlDocPtr | xml | ) | `[virtual]`

Parameters:

  | xml,: | the xmlDoc used to save the document.

Used to save the Object to the xmlDoc. Each serializable Object should implement this virtual method.

Returns:
  the xmlNode containing the serialized object. The name of the node should be the name of the corresponding type used as first parameter to the Object::AddType method. The default method just saves the id and children.

Reimplemented in gcu::Atom, and gcu::Bond.

virtual bool gcu::Object::Load | ( | xmlNodePtr | node | ) | `[virtual]`

Parameters:

  | node,: | a pointer to the xmlNode containing the serialized object.

Used to load an Object in memory. The Object must already exist.

Example:

            std::string str = (const char*)node->name;
            Object* pObject = Object::CreateObject(str, this);
            if (pObject) {
                    if (!pObject->Load(node)) delete Object;
            } else
                    cerr << "Warning: unknown object: " << str << endl;

Returns:
  true on succes, false otherwise.

Reimplemented in gcu::Atom, and gcu::Bond.

virtual void gcu::Object::Move | ( | double | x,
|  | double | y,
|  | double | z = `0.` |
| ) |  |  | `[virtual]`

Parameters:

  | x,: | the x component of the transation vector.
  | y,: | the y component of the transation vector.
  | z,: | the z component of the transation vector.

Used to move an object. This virtual method should most often be overrided by Object derived classes for which it makes sense. The base Object class has no coordinates and the default method only loads its id and children.

Reimplemented in gcu::Atom, and gcu::Bond.

virtual void gcu::Object::Transform2D | ( | Matrix2D & | m,
|  | double | x,
|  | double | y |
| ) |  |  | `[virtual]`

Parameters:

  | m,: | the 2D Matrix of the transformation.
  | x,: | the x component of the center of the transformation.
  | y,: | the y component of the center of the transformation.

Used to move and/or transform an object. This virtual method must be overrided by Object derived classes for which it makes sense. The base Object class has no coordinates and the default method calls the corresponding method for every child.

Reimplemented in gcu::Atom, and gcu::Bond.

bool gcu::Object::SaveChildren | ( | xmlDocPtr | xml,
|  | xmlNodePtr | node |
| ) |  |  |

Parameters:

  | xml,: | the xmlDoc used to save the document.
  | node,: | the node representing the Object.

This method calls Object::Save fo each child of the Object instance and add the xmlNode returned to the children of node. It might be called from the Save method of objects having serializable children.

Returns:
  true on succes, false otherwise.

void gcu::Object::SaveId | ( | xmlNodePtr | node | ) |

Parameters:

  | node,: | the node representing the Object.

This helper method saves the Id of the node as a property of the xmlNode.

xmlNodePtr gcu::Object::GetNodeByProp | ( | xmlNodePtr | node,
|  | char * | Property,
|  | char * | Id |
| ) |  |  |

Parameters:

  | node,: | the node where the search is to be done.
  | Property,: | the name of the property used in the search.
  | Id,: | the value to match to the property.

Helper method used in conjunction with Object::GetNextNodeByProp to search xmlNode instances having a property Property whose value is Id in the children of node.

Returns:
  the node corresponding to the first match. This value is to be passed to Object::GetNextNodeByProp to iterate in the list

xmlNodePtr gcu::Object::GetNextNodeByProp | ( | xmlNodePtr | node,
|  | char * | Property,
|  | char * | Id |
| ) |  |  |

Parameters:

  | node,: | the xmlNodePtr returned by Object::GetNodeByProp or the last call to Object::GetNextNodeByProp.
  | Property,: | the name of the property used in the search.
  | Id,: | the value to match to the property.

Helper method used to iterate through a list of xmlNodePtr searching for a special value of a property. Generally, the iteration is initialized by a call to Object::GetNodeByProp.

Returns:
  the next matching node.

xmlNodePtr gcu::Object::GetNodeByName | ( | xmlNodePtr | node,
|  | char * | Name |
| ) |  |  |

Parameters:

  | node,: | the node where the search is to be done.
  | Name,: | the name of the xmlNode searched.

Helper method used in conjunction with Object::GetNextNodeByProp to search xmlNode instances of name Name in the children of node.

Returns:
  the node corresponding to the first match. This value is to be passed to Object::GetNextNodeByName to iterate in the list.

xmlNodePtr gcu::Object::GetNextNodeByName | ( | xmlNodePtr | node,
|  | char * | Name |
| ) |  |  |

Parameters:

  | node,: | the xmlNodePtr returned by Object::GetNodeByName or the last call to Object::GetNextNodeByName.
  | Name,: | the name of the xmlNode searched.

Helper method used to iterate through a list of xmlNodePtr searching for nodes whose name is Name. Generally, the iteration is initialized by a call to Object::GetNodeByName.

Returns:
  the next matching node.

virtual void gcu::Object::Add | ( | GtkWidget * | w | ) | `[virtual]`

Parameters:

  | w,: | the GtkWidget inside which the Object will be displayed.

Used to add a representation of the Object in the widget. This method might be overrided for displayable Object classes unless the application uses another mechanism.

virtual void gcu::Object::Print | ( | GnomePrintContext * | pc | ) | `[virtual]`

Parameters:

  | pc,: | the GnomePrintContext to which the document is printed.

This method might be used to print a document from an application using the Gnome Chemistry Utils.

virtual void gcu::Object::Update | ( | GtkWidget * | w | ) | `[virtual]`

Parameters:

  | w,: | the GtkWidget inside which the Object is displayed.

Used to update the representation of the Object in the widget. This method might be overrided for displayable Object classes unless the application uses another mechanism.

virtual void gcu::Object::SetSelected | ( | GtkWidget * | w,
|  | int | state |
| ) |  |  | `[virtual]`

Parameters:

  | w,: | the GtkWidget inside which the Object is displayed.
  | state,: | the selection state of the Object.

Used to set the selection state of the Object inside the widget. The values of state are application dependant and have no default value.

bool gcu::Object::HasChildren | ( |  | ) | `[inline]`

Returns:
  true if the Object has at least a child an false if it has none.

Definition at line 371 of file object.h.

unsigned gcu::Object::GetChildrenNumber | ( |  | ) | `[inline]`

Returns:
  the children number of the Object.

Definition at line 376 of file object.h.

virtual Object* gcu::Object::GetAtomAt | ( | double | x,
|  | double | y,
|  | double | z = `0.` |
| ) |  |  | `[virtual]`

Parameters:

  | x,: | the x coordinate
  | y,: | the y coordinate
  | z,: | the z coordinate

Returns:
  a pointer to a child of type Atomtype at or near position defined by the coordinates passed as parameters. Default implementation returns NULL.

virtual bool gcu::Object::Build | ( | list< Object * > & | Children | ) | throw (invalid_argument)`[virtual]`

Parameters:

  | Children,: | the list of objects used as children to build the object

This method is called to build a parent object from its children. The object must already exist.

Returns:
  true in case of success and false if failed.

virtual double gcu::Object::GetYAlign | ( |  | ) | `[virtual]`

Used to retreive the y coordinate for alignment. The default implementation returns 0.0 and every derived class for which alignment has a meaning should implement this method.

Returns:
  y coordinate used for objects alignment.

virtual bool gcu::Object::BuildContextualMenu | ( | GtkUIManager * | UIManager,
|  | Object * | object,
|  | double | x,
|  | double | y |
| ) |  |  | `[virtual]`

Parameters:

  | UIManager,: | the GtkUIanager to populate.
  | object,: | the Object on which occured the mouse click.
  | x,: | x coordinate of the mouse click.
  | y,: | y coordinate of the mouse click.

This method is called to build a contextual menu for the object. It is called by Object::ShowContextualMenu, so it should not be necessary to call it directly. It should be overrided by derived classes when a contextual menu is needed. Typically, each class adds a submenu and calls the same method for its parent. Default implementation just calls the parent's method.

Returns:
  true if something is added to the UIManager, false otherwise.

void gcu::Object::EmitSignal | ( | SignalId | Signal | ) |

Parameters:

  | Signal,: | the appropriate SignalId

Sends a signal to the object parent. The signal may be propagated to the ancestors (see Object::OnSignal ()).

virtual bool gcu::Object::OnSignal | ( | SignalId | Signal,
|  | Object * | Child |
| ) |  |  | `[virtual]`

Parameters:

  | Signal,: | the appropriate SignalId
  | Child,: | the child which emitted the signal or NULL

This function is called by the framework when a signal has been emitted for the object. It should not be called by a program; call Object::EmitSignal instead.

Returns:
  true if the signal should be propagated to the parent, false otherwise.

void gcu::Object::Lock | ( | bool | state = `true` | ) |

Parameters:

  | state,: | whether to block signals or not

Blocks signals if State is true and unblocs if state is false.

Since 0.4.2

bool gcu::Object::IsLocked | ( |  | ) | `[inline]`

Returns:
  true if signals are locked, false otherwise

Since 0.4.2

Definition at line 451 of file object.h.

Object* gcu::Object::GetFirstLink | ( | set< Object * >::iterator & | i | ) |

Parameters:

  | i,: | a C++ std::set<Object*> iterator.

Use this function to retrieve the first object linked to the object and initialize the iterator. Links can be used when the relation between the objects is not a parent to child one.

Returns:
  the first object linked to the object or NULL.

Object* gcu::Object::GetNextLink | ( | set< Object * >::iterator & | i | ) |

Parameters:

  | i,: | a C++ std::set<Object*> iterator initialized by Object::GetFirstLink.

Use this method to iterate through the list of Object instances linked to the object.

Returns:
  the next object linked to the object or NULL.

void gcu::Object::Unlink | ( | Object * | object | ) |

Parameters:

  | object,: | the object to unlink.

Unlinks object and calls Object::OnUnlink.

virtual void gcu::Object::OnUnlink | ( | Object * | object | ) | `[virtual]`

Parameters:

  | object,: | the object just unlinked by Object::Unlink.

Virtual method called when an object hs been unlinked. Programs should not call it directly, but should call Object::OnUnlink instead.

void gcu::Object::GetPossibleAncestorTypes | ( | set< TypeId > & | types | ) |

Parameters:

  | types,: | the list of TypeId values to fill

Fills types with all valid ancestor types for the object as defined by rules created with AddRule

static TypeId gcu::Object::AddType | ( | string | TypeName,
|  | Object *(*)() | CreateFunc,
|  | TypeId | id = `OtherType` |
| ) |  |  | `[static]`

Parameters:

  | TypeName,: | the name of the new type.
  | CreateFunc,: | a pointer to a function returning a pointer to a new object of the new type.
  | id,: | the Id of the type to create if a standard one or OtherType for a new type. In this last case, this parameter can be omitted.

This method is used to register a new type derived from Object.

Returns:
  the Id of the new type.

static Object* gcu::Object::CreateObject | ( | const string & | TypeName,
|  | Object * | parent = `NULL` |
| ) |  |  | `[static]`

Parameters:

  | TypeName,: | the name of the new type.
  | parent,: | the parent of the newly created object or NULL. if NULL, the parameter can be omitted.

Used to create an object of type name TypeName. The Object::AddType method must have been called with the same TypeName parameter. if parent is given and not NULL, the new Object will be a child of parent. It will also be given a default Id.

Returns:
  a pointer to the newly created Object or NULL if the Object could not be created.

static TypeId gcu::Object::GetTypeId | ( | const string & | Name | ) | `[static]`

Parameters:

  | Name,: | the name of the Object derived class

Returns:
  the TypeId corresponding to Name

static string gcu::Object::GetTypeName | ( | TypeId | Id | ) | `[static]`

Parameters:

  | Id,: | the TypeId of the Object derived class

Returns:
  the name of the type.

static void gcu::Object::AddRule | ( | TypeId | type1,
|  | RuleId | rule,
|  | TypeId | type2 |
| ) |  |  | `[static]`

Parameters:

  | type1,: | the TypeId of the first class in the rule
  | rule,: | the new rule value
  | type2,: | the TypeId of the second class in the rule

Adds a rule.

static void gcu::Object::AddRule | ( | const string & | type1,
|  | RuleId | rule,
|  | const string & | type2 |
| ) |  |  | `[static]`

Parameters:

  | type1,: | the name of the first class in the rule
  | rule,: | the new rule value
  | type2,: | the name of the second class in the rule

Adds a rule.

static const set<TypeId>& gcu::Object::GetRules | ( | TypeId | type,
|  | RuleId | rule |
| ) |  |  | `[static]`

Parameters:

  | type,: | the TypeId of a class
  | rule,: | a RuleId value

Returns:
  the set of rules correponding to the RuleId value for this class.

static const set<TypeId>& gcu::Object::GetRules | ( | const string & | type,
|  | RuleId | rule |
| ) |  |  | `[static]`

Parameters:

  | type,: | the name of a class
  | rule,: | a RuleId value

Returns:
  the set of rules correponding to the RuleId value for this class.

static void gcu::Object::SetCreationLabel | ( | TypeId | Id,
|  | string | Label |
| ) |  |  | `[static]`

Parameters:

  | Id,: | the TypeId of a class
  | Label,: | the string to display in a contextual menu

Used to give a label for contextual menus used when the creation of an instance of the class seems possible.

static const string& gcu::Object::GetCreationLabel | ( | TypeId | Id | ) | `[static]`

Parameters:

  | Id,: | the TypeId of a class

Returns:
  the string defined by SetCreationLabel.

static const string& gcu::Object::GetCreationLabel | ( | const string & | TypeName | ) | `[static]`

Parameters:

  | TypeName,: | the name of a class

Returns:
  the string defined by SetCreationLabel.

static SignalId gcu::Object::CreateNewSignalId | ( |  | ) | `[static]`

Returns:
  a new SignalId.

The documentation for this class was generated from the following file:

- object.h