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
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;
00573 set<Object*> m_Links;
00574 };
00575
00576 }
00577
#endif //GCU_OBJECT_H