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
00071 enum
00072 {
00073 NoType,
00074 AtomType,
00075 FragmentType,
00076 BondType,
00077 MoleculeType,
00078 ChainType,
00079 CycleType,
00080 ReactantType,
00081 ReactionArrowType,
00082 ReactionOperatorType,
00083 ReactionType,
00084 MesomeryType,
00085 MesomeryArrowType,
00086 DocumentType,
00087 TextType,
00088 OtherType
00089 };
00090
00091 typedef unsigned TypeId;
00092
00105 enum RuleId
00106 {
00107 RuleMayContain,
00108 RuleMustContain,
00109 RuleMayBeIn,
00110 RuleMustBeIn
00111 };
00112
00113 class Document;
00114
00118 class Object
00119 {
00120 public:
00124 Object(TypeId Id = OtherType);
00128 virtual ~Object();
00129
00134 TypeId GetType() {return m_Type;}
00140 void SetId(gchar* Id);
00144 const gchar* GetId() {return m_Id;}
00151 void AddChild(Object* object);
00158 Object* GetMolecule();
00165 Object* GetReaction();
00173 Object* GetGroup();
00180 Document* GetDocument();
00190 Object* GetParentOfType(TypeId Id);
00197 Object* GetChild(const gchar* Id);
00204 Object* GetFirstChild(map<string, Object*>::iterator& i);
00211 Object* GetNextChild(map<string, Object*>::iterator& i);
00218 Object* GetDescendant(const gchar* Id);
00222 Object* GetParent() {return m_Parent;}
00229 void SetParent(Object* Parent);
00238 virtual xmlNodePtr Save(xmlDocPtr xml);
00255 virtual bool Load(xmlNodePtr node);
00264 virtual void Move(double x, double y, double z = 0.);
00275 virtual void Transform2D(Matrix2D& m, double x, double y);
00284 bool SaveChildren(xmlDocPtr xml, xmlNodePtr node);
00290 void SaveId(xmlNodePtr node);
00301 xmlNodePtr GetNodeByProp(xmlNodePtr node, char* Property, char* Id);
00311 xmlNodePtr GetNextNodeByProp(xmlNodePtr node, char* Property, char* Id);
00321 xmlNodePtr GetNodeByName(xmlNodePtr node, char* Name);
00330 xmlNodePtr GetNextNodeByName(xmlNodePtr node, char* Name);
00338 void ShowContextualMenu(unsigned button, unsigned time);
00345 virtual void Add(GtkWidget* w);
00351 virtual void Print(GnomePrintContext *pc);
00358 virtual void Update(GtkWidget* w);
00366 virtual void SetSelected(GtkWidget* w, int state);
00370 bool HasChildren() {return m_Children.size() != 0;}
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
00402 void GetPossibleAncestorTypes (set<TypeId>& types);
00403
00413 static TypeId AddType(string TypeName, Object*(*CreateFunc)(), TypeId id = OtherType);
00414
00425 static Object* CreateObject(const string& TypeName, Object* parent = NULL);
00426
00432 static TypeId GetTypeId (const string& Name);
00433
00439 static string GetTypeName (TypeId Id);
00440
00448 static void AddRule (TypeId type1, RuleId rule, TypeId type2);
00449
00457 static void AddRule (const string& type1, RuleId rule, const string& type2);
00458
00465 static const set<TypeId>& GetRules (TypeId type, RuleId rule);
00466
00473 static const set<TypeId>& GetRules (const string& type, RuleId rule);
00474
00482 static void SetCreationLabel (TypeId Id, string Label);
00483
00489 static const string& GetCreationLabel (TypeId Id);
00490
00496 static const string& GetCreationLabel (const string& TypeName);
00497
00498 protected:
00504 virtual void BuildContextualMenu();
00505
00506 private:
00507 gchar* m_Id;
00508 TypeId m_Type;
00509 Object *m_Parent;
00510 map<string, Object*> m_Children;
00511 GtkMenu* m_Menu;
00512 };
00513
00514 }
00515 #endif //GCU_OBJECT_H