00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GCU_OBJECT_H
00028 #define GCU_OBJECT_H
00029
00030 #include "matrix2d.h"
00031 #include <glib.h>
00032 #include <libxml/parser.h>
00033 #include <map>
00034 #include <set>
00035 #include <list>
00036 #include <string>
00037 #include <stdexcept>
00038 #include <gtk/gtk.h>
00039 #include <libgnomeprint/gnome-print.h>
00040
00041 #define square(x) ((x)*(x))
00042
00043 using namespace std;
00044
00045 namespace gcu
00046 {
00047
00072 enum
00073 {
00074 NoType,
00075 AtomType,
00076 FragmentType,
00077 BondType,
00078 MoleculeType,
00079 ChainType,
00080 CycleType,
00081 ReactantType,
00082 ReactionArrowType,
00083 ReactionOperatorType,
00084 ReactionType,
00085 MesomeryType,
00086 MesomeryArrowType,
00087 DocumentType,
00088 TextType,
00089 OtherType
00090 };
00091
00092 typedef unsigned TypeId;
00093
00106 enum RuleId
00107 {
00108 RuleMayContain,
00109 RuleMustContain,
00110 RuleMayBeIn,
00111 RuleMustBeIn
00112 };
00113
00114 typedef unsigned SignalId;
00115
00116 class Document;
00117
00121 class Object
00122 {
00123 public:
00127 Object (TypeId Id = OtherType);
00131 virtual ~Object ();
00132
00137 TypeId GetType () {return m_Type;}
00143 void SetId (gchar* Id);
00147 const gchar* GetId () {return m_Id;}
00154 void AddChild (Object* object);
00161 Object* GetMolecule ();
00168 Object* GetReaction ();
00176 Object* GetGroup ();
00183 Document* GetDocument ();
00193 Object* GetParentOfType (TypeId Id);
00200 Object* GetChild (const gchar* Id);
00207 Object* GetFirstChild (map<string, Object*>::iterator& i);
00214 Object* GetNextChild (map<string, Object*>::iterator& i);
00221 Object* GetDescendant (const gchar* Id);
00225 Object* GetParent () {return m_Parent;}
00232 void SetParent (Object* Parent);
00241 virtual xmlNodePtr Save (xmlDocPtr xml);
00258 virtual bool Load (xmlNodePtr node);
00267 virtual void Move (double x, double y, double z = 0.);
00278 virtual void Transform2D (Matrix2D& m, double x, double y);
00287 bool SaveChildren (xmlDocPtr xml, xmlNodePtr node);
00293 void SaveId (xmlNodePtr node);
00304 xmlNodePtr GetNodeByProp (xmlNodePtr node, char* Property, char* Id);
00314 xmlNodePtr GetNextNodeByProp (xmlNodePtr node, char* Property, char* Id);
00324 xmlNodePtr GetNodeByName (xmlNodePtr node, char* Name);
00333 xmlNodePtr GetNextNodeByName (xmlNodePtr node, char* Name);
00340 virtual void Add (GtkWidget* w);
00346 virtual void Print (GnomePrintContext *pc);
00353 virtual void Update (GtkWidget* w);
00361 virtual void SetSelected (GtkWidget* w, int state);
00365 bool HasChildren () {return m_Children.size () != 0;}
00366
00370 unsigned GetChildrenNumber () {return m_Children.size ();}
00371
00380 virtual Object* GetAtomAt (double x, double y, double z = 0.);
00381
00388 virtual bool Build (list<Object*>& Children) throw (invalid_argument);
00389
00395 virtual double GetYAlign ();
00396
00407 virtual bool BuildContextualMenu (GtkUIManager *UIManager, Object *object);
00408
00415 void EmitSignal (SignalId Signal);
00416
00426 virtual bool OnSignal (SignalId Signal, Object *Child);
00427
00435 void Lock (bool state = true);
00436
00445
00454
00462
00469
00477
00484
00495
00507
00514
00521
00530
00539
00547
00555
00564
00571
00578
00583
00599