Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

object.h

00001 // -*- C++ -*- 00002 00003 /* 00004 * Gnome Chemistry Utils 00005 * object.h 00006 * 00007 * Copyright (C) 2002-2004 00008 * 00009 * Developed by Jean Bréfort <jean.brefort@normalesup.rg> 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Lesser General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2.1 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the 00023 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00024 * Boston, MA 02111-1307, USA. 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 00406 virtual bool BuildContextualMenu (GtkUIManager *UIManager); 00407 00414 void EmitSignal (SignalId Signal); 00415 00425 virtual bool OnSignal (SignalId Signal, Object *Child); 00426 00434 Object* GetFirstLink (set<Object*>::iterator& i); 00435 00442 Object* GetNextLink (set<Object*>::iterator& i); 00443 00449 void Unlink (Object *object); 00450 00457 virtual void OnUnlink (Object *object); 00458 00464 void GetPossibleAncestorTypes (set<TypeId>& types); 00465 00475 static TypeId AddType (string TypeName, Object*(*CreateFunc)(), TypeId id = OtherType); 00476 00487 static Object* CreateObject (const string& TypeName, Object* parent = NULL); 00488 00494 static TypeId GetTypeId (const string& Name); 00495 00501 static string GetTypeName (TypeId Id); 00502 00510 static void AddRule (TypeId type1, RuleId rule, TypeId type2); 00511 00519 static void AddRule (const string& type1, RuleId rule, const string& type2); 00520 00527 static const set<TypeId>& GetRules (TypeId type, RuleId rule); 00528 00535 static const set<TypeId>& GetRules (const string& type, RuleId rule); 00536 00544 static void SetCreationLabel (TypeId Id, string Label); 00545 00551 static const string& GetCreationLabel (TypeId Id); 00552 00558 static const string& GetCreationLabel (const string& TypeName); 00559 00563 static SignalId CreateNewSignalId (); 00564 00565 private: 00566 Object* RealGetDescendant (const gchar* Id); 00567 00568 private: 00569 gchar* m_Id; 00570 TypeId m_Type; 00571 Object *m_Parent; 00572 map<string, Object*> m_Children; //string is Id of object, so each object must have an Id 00573 set<Object*> m_Links; //objects linked to this but outside of the hierarchy 00574 }; 00575 00576 } 00577 #endif //GCU_OBJECT_H

Generated on Tue Sep 21 14:59:35 2004 for The Gnome Chemistry Utils by doxygen 1.3.8