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 GtkWidget* GetWidget ();
00072 View* GetView () {return m_pView;}
00073 void BuildBondList (list<Bond*>& BondList, Object* obj);
00074 bool ImportOB (OBMol& Mol);
00075 void ExportOB ();
00076 void BuildAtomTable (map<string, unsigned>& AtomTable, Object* obj, unsigned& index);
00077 void Save ();
00078 virtual bool Load (xmlNodePtr);
00079 const gchar* GetTitle ();
00080 void SetTitle (const gchar* title);
00081 void SetLabel (const gchar* label);
00082 const gchar* GetLabel ();
00083 void SetFileName (string const &, const gchar *mime_type);
00084 const gchar* GetFileName () {return m_filename;}
00085 void Print (GnomePrintContext *pc, gdouble width, gdouble height);
00086 void AddObject (Object* pObject);
00087 void AddAtom (Atom* pAtom);
00088 void AddFragment (Fragment* pFragment);
00089 void AddBond (Bond* pBond);
00090 void ParseXMLTree (xmlDocPtr xml);
00091 void LoadObjects (xmlNodePtr node);
00092 xmlDocPtr BuildXMLTree ();
00093 void NotifyDirty (Bond* pBond) {m_DirtyObjects.insert (pBond);}
00094 void Update ();
00095 void Remove (Object*);
00096 void Remove (const char* Id);
00097 void OnProperties ();
00098 void OnUndo ();
00099 void OnRedo ();
00100 const GDate* GetCreationDate () {return &CreationDate;}
00101 const GDate* GetRevisionDate () {return &RevisionDate;}
00102 const gchar* GetAuthor () {return m_author;}
00103 const gchar* GetMail () {return m_mail;}
00104 const gchar* GetComment () {return m_comment;}
00105 void SetAuthor (const gchar* author);
00106 void SetMail (const gchar* mail);
00107 void SetComment (const gchar* comment);
00108 void FinishOperation ();
00109 void AbortOperation ();
00110 void PopOperation ();
00111 void PushOperation (Operation* operation, bool undo = true);
00112 void SetActive ();
00113 Operation* GetNewOperation (OperationType type);
00114 Operation* GetCurrentOperation () {return m_pCurOp;}
00115 void AddData (xmlNodePtr node);
00116 bool CanUndo () {return m_UndoList.size() > 0;}
00117 void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
00118 bool GetEditable () {return m_bWriteable;}
00119 gcp::Application* GetApplication () {return m_pApp;}
00120 void ExportImage (string const &filename, const char* type, int resolution = -1);
00121 void SetReadOnly (bool ro);
00122 bool GetReadOnly () {return m_bReadOnly;}
00123 virtual double GetYAlign ();
00124 Window *GetWindow () {return m_Window;}
00125 void SetTheme (Theme *theme);
00126 bool OnSignal (SignalId Signal, Object *Child);
00127 void SetDirty (bool isDirty = true);
00128 void OnThemeNamesChanged ();
00129 double GetMedianBondLength ();
00130
00131 private:
00132 void RemoveAtom (Atom* pAtom);
00133 void RemoveBond (Bond* pBond);
00134 void RemoveFragment (Fragment* pFragment);
00135
00136
00137 private:
00138 View * m_pView;
00139 gchar* m_filename;
00140 gchar *m_title;
00141 gchar *m_label;
00142 gchar *m_comment, *m_author, *m_mail;
00143 set<Object*> m_DirtyObjects;
00144 bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
00145 string m_FileType;
00146 bool m_bWriteable;
00147 GDate CreationDate, RevisionDate;
00148 list<Operation*> m_UndoList, m_RedoList;
00149 Operation* m_pCurOp;
00150 Application* m_pApp;
00151 Window *m_Window;
00152 unsigned long m_OpID;
00153 unsigned m_LastStackSize;
00154
00155
00156
00157 GCU_RO_PROP (Theme*, Theme)
00158 GCU_PROP (double, BondLength)
00159 GCU_PROP (double, BondAngle)
00160 GCU_PROP (double, ArrowLength)
00161 GCU_PROP (gchar*, TextFontFamily)
00162 GCU_PROP (PangoStyle, TextFontStyle)
00163 GCU_PROP (PangoWeight, TextFontWeight)
00164 GCU_PROP (PangoVariant, TextFontVariant)
00165 GCU_PROP (PangoStretch, TextFontStretch)
00166 GCU_PROP (gint, TextFontSize)
00167 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
00168 };
00169
00170 extern list<Document*> Docs;
00171 extern bool bCloseAll;
00172
00173 }
00174
00175 #endif // GCHEMPAINT_DOCUMENT_H