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