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 Object* GetFirstLink (set<Object*>::iterator& i);
00436
00443 Object* GetNextLink (set<Object*>::iterator& i);
00444
00450 void Unlink (Object *object);
00451
00458 virtual void OnUnlink (Object *object);
00459
00465 void GetPossibleAncestorTypes (set<TypeId>& types);
00466
00476 static TypeId AddType (string TypeName, Object*(*CreateFunc)(), TypeId id = OtherType);
00477
00488 static Object* CreateObject (const string& TypeName, Object* parent = NULL);
00489
00495 static TypeId GetTypeId (const string& Name);
00496
00502 static string GetTypeName (TypeId Id);
00503
00511 static void AddRule (TypeId type1, RuleId rule, TypeId type2);
00512
00520 static void AddRule (const string& type1, RuleId rule, const string& type2);
00521
00528 static const set<TypeId>& GetRules (TypeId type, RuleId rule);
00529
00536 static const set<TypeId>& GetRules (const string& type, RuleId rule);
00537
00545 static void SetCreationLabel (TypeId Id, string Label);
00546
00552 static const string& GetCreationLabel (TypeId Id);
00553
00559 static const string& GetCreationLabel (const string& TypeName);
00560
00564 static SignalId CreateNewSignalId ();
00565
00566 private:
00567 Object* RealGetDescendant (const gchar* Id);
00568
00569 private:
00570 gchar* m_Id;
00571 TypeId m_Type;
00572 Object *m_Parent;
00573 map<string, Object*> m_Children;
00574 set<Object*> m_Links;
00575
00576 protected:
00580 bool m_IsLoading;
00581 };
00582
00583 }
00584 #endif