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
00443 bool IsLocked () {return m_Locked > 0;}
00444
00452 Object* GetFirstLink (set<Object*>::iterator& i);
00453
00460 Object* GetNextLink (set<Object*>::iterator& i);
00461
00467 void Unlink (Object *object);
00468
00475 virtual void OnUnlink (Object *object);
00476
00482 void GetPossibleAncestorTypes (set<TypeId>& types);
00483
00493 static TypeId AddType (string TypeName, Object*(*CreateFunc)(), TypeId id = OtherType);
00494
00505 static Object* CreateObject (const string& TypeName, Object* parent = NULL);
00506
00512 static TypeId GetTypeId (const string& Name);
00513
00519 static string GetTypeName (TypeId Id);
00520
00528 static void AddRule (TypeId type1, RuleId rule, TypeId type2);
00529
00537 static void AddRule (const string& type1, RuleId rule, const string& type2);
00538
00545 static const set<TypeId>& GetRules (TypeId type, RuleId rule);
00546
00553 static const set<TypeId>& GetRules (const string& type, RuleId rule);
00554
00562 static void SetCreationLabel (TypeId Id, string Label);
00563
00569 static const string& GetCreationLabel (TypeId Id);
00570
00576 static const string& GetCreationLabel (const string& TypeName);
00577
00581 static SignalId CreateNewSignalId ();
00582
00583 private:
00584 Object* RealGetDescendant (const gchar* Id);
00585
00586 private:
00587 gchar* m_Id;
00588 TypeId m_Type;
00589 Object *m_Parent;
00590 map<string, Object*> m_Children;
00591 set<Object*> m_Links;
00592
00593 private:
00597 int m_Locked;
00598 };
00599
00600 }
00601 #endif //GCU_OBJECT_H