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 #ifndef GCU_OBJECT_H
00026 #define GCU_OBJECT_H
00027
00028 #include "matrix2d.h"
00029 #include <glib.h>
00030 #include <libxml/parser.h>
00031 #include <map>
00032 #include <set>
00033 #include <list>
00034 #include <string>
00035 #include <stdexcept>
00036 #include <gtk/gtk.h>
00037 #include <libgnomeprint/gnome-print.h>
00038
00039 #define square(x) ((x)*(x))
00040
00041 using namespace std;
00042
00043 namespace gcu
00044 {
00045
00070 enum GcuTypeId
00071 {
00072 NoType,
00073 AtomType,
00074 FragmentType,
00075 BondType,
00076 MoleculeType,
00077 ChainType,
00078 CycleType,
00079 ReactantType,
00080 ReactionArrowType,
00081 ReactionOperatorType,
00082 ReactionType,
00083 MesomeryType,
00084 MesomeryArrowType,
00085 DocumentType,
00086 TextType,
00087 OtherType
00088 };
00089
00094 typedef unsigned TypeId;
00095
00096 class Object;
00097
00106 typedef bool (*BuildMenuCb) (Object *target, GtkUIManager *UIManager, Object *object, double x, double y);
00107
00120 enum RuleId
00121 {
00122 RuleMayContain,
00123 RuleMustContain,
00124 RuleMayBeIn,
00125 RuleMustBeIn
00126 };
00127
00132 typedef unsigned SignalId;
00133
00134 class Document;
00135
00139 class Object
00140 {
00141 public:
00145 Object (TypeId Id = OtherType);
00149 virtual ~Object ();
00150
00155 TypeId GetType () {return m_Type;}
00161 void SetId (gchar const *Id);
00165 const gchar* GetId () {return m_Id;}
00172 void AddChild (Object* object);
00179 Object* GetMolecule ();
00186 Object* GetReaction ();
00194 Object* GetGroup ();
00201 Document* GetDocument ();
00211 Object* GetParentOfType (TypeId Id);
00218 Object* GetChild (const gchar* Id);
00225 Object* GetFirstChild (map<string, Object*>::iterator& i);
00232 Object* GetNextChild (map<string, Object*>::iterator& i);
00239 Object* GetDescendant (const gchar* Id);
00243 Object* GetParent () {return m_Parent;}
00250 void SetParent (Object* Parent);
00259 virtual xmlNodePtr Save (xmlDocPtr xml);
00276 virtual bool Load (xmlNodePtr node);
00285 virtual void Move (double x, double y, double z = 0.);
00296 virtual void Transform2D (Matrix2D& m, double x, double y);
00305 bool SaveChildren (xmlDocPtr xml, xmlNodePtr node);
00311 void SaveId (xmlNodePtr node);
00322 xmlNodePtr GetNodeByProp (xmlNodePtr node, char const *Property, char const *Id);
00332 xmlNodePtr GetNextNodeByProp (xmlNodePtr node, char const *Property, char const *Id);
00342 xmlNodePtr GetNodeByName (xmlNodePtr node, char const *Name);
00351 xmlNodePtr GetNextNodeByName (xmlNodePtr node, char const *Name);
00358 virtual void Add (GtkWidget* w);
00364 virtual void Print (GnomePrintContext *pc);
00371 virtual void Update (GtkWidget* w);
00379 virtual void SetSelected (GtkWidget* w, int state);
00383 bool HasChildren () {return m_Children.size () != 0;}
00384
00388 unsigned GetChildrenNumber () {return m_Children.size ();}
00389
00398 virtual Object* GetAtomAt (double x, double y, double z = 0.);
00399
00406 virtual bool Build (list<Object*>& Children) throw (invalid_argument);
00407
00413 virtual double GetYAlign ();
00414
00428 virtual bool BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y);
00429
00436 void EmitSignal (SignalId Signal);
00437
00447 virtual bool OnSignal (SignalId Signal, Object *Child);
00448
00456 void Lock (bool state = true);
00457
00464 bool IsLocked () {return m_Locked > 0;}
00465
00473 Object* GetFirstLink (set<Object*>::iterator& i);
00474
00481 Object* GetNextLink (set<Object*>::iterator& i);
00482
00488 void Unlink (Object *object);
00489
00496 virtual void OnUnlink (Object *object);
00497
00503 void GetPossibleAncestorTypes (set<TypeId>& types);
00504
00514 static TypeId AddType (string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00515
00526 static Object* CreateObject (const string& TypeName, Object* parent = NULL);
00527
00533 static TypeId GetTypeId (const string& Name);
00534
00540 static string GetTypeName (TypeId Id);
00541
00548 static void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00549
00557 static void AddRule (TypeId type1, RuleId rule, TypeId type2);
00558
00566 static void AddRule (const string& type1, RuleId rule, const string& type2);
00567
00574 static const set<TypeId>& GetRules (TypeId type, RuleId rule);
00575
00582 static const set<TypeId>& GetRules (const string& type, RuleId rule);
00583
00591 static void SetCreationLabel (TypeId Id, string Label);
00592
00598 static const string& GetCreationLabel (TypeId Id);
00599
00605 static const string& GetCreationLabel (const string& TypeName);
00606
00610 static SignalId CreateNewSignalId ();
00611
00612 private:
00613 Object* RealGetDescendant (const gchar* Id);
00614
00615 private:
00616 gchar* m_Id;
00617 TypeId m_Type;
00618 Object *m_Parent;
00619 map<string, Object*> m_Children;
00620 set<Object*> m_Links;
00621
00622 private:
00626 int m_Locked;
00627 };
00628
00629 }
00630 #endif //GCU_OBJECT_H