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 #ifndef GCHEMPAINT_DOCUMENT_H
00026 #define GCHEMPAINT_DOCUMENT_H
00027
00028 #include <list>
00029 #include <map>
00030 #include <set>
00031 #include <string>
00032 #include <libxml/tree.h>
00033 #include <gtk/gtk.h>
00034 #include <libgnomeprint/gnome-print.h>
00035 #include <gcu/document.h>
00036 #include <gcu/macros.h>
00037 #include "atom.h"
00038 #include "fragment.h"
00039 #include "bond.h"
00040 #include "molecule.h"
00041 #include "operation.h"
00042
00043 namespace OpenBabel
00044 {
00045 class OBMol;
00046 }
00047
00048 using namespace OpenBabel;
00049 using namespace std;
00050
00051 namespace gcp {
00052
00053 extern SignalId OnChangedSignal;
00054 extern SignalId OnDeleteSignal;
00055 extern SignalId OnThemeChangedSignal;
00056
00057 class View;
00058 class Application;
00059 class Window;
00060 class Theme;
00061
00062 class Document: public gcu::Document
00063 {
00064
00065 public:
00066 Document (Application *App, bool StandAlone, Window *window = NULL);
00067 virtual ~Document ();
00068
00069
00070 public:
00071 void Clear ();
00072 GtkWidget* GetWidget ();
00073 View* GetView () {return m_pView;}
00074 void BuildBondList (list<Bond*>& BondList, Object* obj);
00075 bool ImportOB (OBMol& Mol);
00076 void ExportOB ();
00077 void BuildAtomTable (map<string, unsigned>& AtomTable, Object* obj, unsigned& index);
00078 void Save ();
00079 virtual bool Load (xmlNodePtr);
00080 const gchar* GetTitle ();
00081 void SetTitle (const gchar* title);
00082 void SetLabel (const gchar* label);
00083 const gchar* GetLabel ();
00084 void SetFileName (string const &, const gchar *mime_type);
00085 const gchar* GetFileName () {return m_filename;}
00086 void Print (GnomePrintContext *pc, gdouble width, gdouble height);
00087 void AddObject (Object* pObject);
00088 void AddAtom (Atom* pAtom);
00089 void AddFragment (Fragment* pFragment);
00090 void AddBond (Bond* pBond);
00091 void ParseXMLTree (xmlDocPtr xml);
00092 void LoadObjects (xmlNodePtr node);
00093 xmlDocPtr BuildXMLTree ();
00094 void NotifyDirty (Bond* pBond) {m_DirtyObjects.insert (pBond);}
00095 void Update ();
00096 void Remove (Object*);
00097 void Remove (const char* Id);
00098 void OnProperties ();
00099 void OnUndo ();
00100 void OnRedo ();
00101 const GDate* GetCreationDate () {return &CreationDate;}
00102 const GDate* GetRevisionDate () {return &RevisionDate;}
00103 const gchar* GetAuthor () {return m_author;}
00104 const gchar* GetMail () {return m_mail;}
00105 const gchar* GetComment () {return m_comment;}
00106 void SetAuthor (const gchar* author);
00107 void SetMail (const gchar* mail);
00108 void SetComment (const gchar* comment);
00109 void FinishOperation ();
00110 void AbortOperation ();
00111 void PopOperation ();
00112 void PushOperation (Operation* operation, bool undo = true);
00113 void SetActive ();
00114 Operation* GetNewOperation (OperationType type);
00115 Operation* GetCurrentOperation () {return m_pCurOp;}
00116 void AddData (xmlNodePtr node);
00117 bool CanUndo () {return m_UndoList.size() > 0;}
00118 void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
00119 bool GetEditable () {return m_bWriteable;}
00120 gcp::Application* GetApplication () {return m_pApp;}
00121 void ExportImage (string const &filename, const char* type, int resolution = -1);
00122 void SetReadOnly (bool ro);
00123 bool GetReadOnly () {return m_bReadOnly;}
00124 virtual double GetYAlign ();
00125 Window *GetWindow () {return m_Window;}
00126 void SetTheme (Theme *theme);
00127 bool OnSignal (SignalId Signal, Object *Child);
00128 void SetDirty (bool isDirty = true);
00129 void OnThemeNamesChanged ();
00130 double GetMedianBondLength ();
00131
00132 private:
00133 void RemoveAtom (Atom* pAtom);
00134 void RemoveBond (Bond* pBond);
00135 void RemoveFragment (Fragment* pFragment);
00136
00137
00138 private:
00139 View * m_pView;
00140 gchar* m_filename;
00141 gchar *m_title;
00142 gchar *m_label;
00143 gchar *m_comment, *m_author, *m_mail;
00144 set<Object*> m_DirtyObjects;
00145 bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
00146 string m_FileType;
00147 bool m_bWriteable;
00148 GDate CreationDate, RevisionDate;
00149 list<Operation*> m_UndoList, m_RedoList;
00150 Operation* m_pCurOp;
00151 Application* m_pApp;
00152 Window *m_Window;
00153 unsigned long m_OpID;
00154 unsigned m_LastStackSize;
00155
00156
00157
00158 GCU_RO_PROP (Theme*, Theme)
00159 GCU_PROP (double, BondLength)
00160 GCU_PROP (double, BondAngle)
00161 GCU_PROP (double, ArrowLength)
00162 GCU_PROP (gchar*, TextFontFamily)
00163 GCU_PROP (PangoStyle, TextFontStyle)
00164 GCU_PROP (PangoWeight, TextFontWeight)
00165 GCU_PROP (PangoVariant, TextFontVariant)
00166 GCU_PROP (PangoStretch, TextFontStretch)
00167 GCU_PROP (gint, TextFontSize)
00168 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
00169 GCU_PROP (bool, AllowClipboard)
00170 };
00171
00172 extern list<Document*> Docs;
00173 extern bool bCloseAll;
00174
00175 }
00176
00177 #endif // GCHEMPAINT_DOCUMENT_H