gcp/document.h
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 "operation.h"
00029 #include <gcu/document.h>
00030 #include <gcu/macros.h>
00031 #include <gcu/printable.h>
00032 #include <list>
00033 #include <map>
00034 #include <set>
00035 #include <string>
00036 #include <libxml/tree.h>
00037 #include <gtk/gtk.h>
00038
00039 namespace OpenBabel
00040 {
00041 class OBMol;
00042 }
00043
00044 namespace gcp {
00045
00046 extern gcu::SignalId OnChangedSignal;
00047 extern gcu::SignalId OnDeleteSignal;
00048 extern gcu::SignalId OnThemeChangedSignal;
00049
00050 class View;
00051 class Application;
00052 class Window;
00053 class Theme;
00054 class Residue;
00055 class Atom;
00056 class Bond;
00057 class Fragment;
00058 class Molecule;
00059
00060 class Document: public gcu::Document, public gcu::Printable
00061 {
00062
00063 public:
00064 Document (Application *App, bool StandAlone, Window *window = NULL);
00065 virtual ~Document ();
00066
00067
00068 public:
00069 void Clear ();
00070 GtkWidget* GetWidget ();
00071 View* GetView () {return m_pView;}
00072 void BuildBondList (std::list<Bond*>& BondList, gcu::Object const *obj) const;
00073 bool ImportOB (OpenBabel::OBMol& Mol);
00074 void ExportOB () const;
00075 void BuildAtomTable (std::map<std::string, unsigned>& AtomTable, gcu::Object const *obj, unsigned& index) const;
00076 void Save () const;
00077 virtual bool Load (xmlNodePtr);
00078 const gchar* GetTitle () const;
00079 void SetTitle (const gchar* title);
00080 void SetLabel (const gchar* label);
00081 const gchar* GetLabel () const;
00082 void SetFileName (std::string const &, const gchar *mime_type);
00083 const gchar* GetFileName () {return m_filename;}
00084 void DoPrint (GtkPrintOperation *print, GtkPrintContext *context) const;
00085 void AddObject (Object* pObject);
00086 void AddAtom (Atom* pAtom);
00087 void AddFragment (Fragment* pFragment);
00088 void AddBond (Bond* pBond);
00089 void ParseXMLTree (xmlDocPtr xml);
00090 void LoadObjects (xmlNodePtr node);
00091 xmlDocPtr BuildXMLTree () const;
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 GtkWindow *GetGtkWindow ();
00124 void SetTheme (Theme *theme);
00125 bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
00126 void SetDirty (bool isDirty = true);
00127 void OnThemeNamesChanged ();
00128 double GetMedianBondLength ();
00129 bool SetProperty (unsigned property, char const *value);
00130 void SaveResidue (Residue const *r, xmlNodePtr node);
00131 void SetLoading (bool loading) {m_bIsLoading = loading;}
00132
00133 private:
00134 void RemoveAtom (Atom* pAtom);
00135 void RemoveBond (Bond* pBond);
00136 void RemoveFragment (Fragment* pFragment);
00137
00138
00139 private:
00140 View * m_pView;
00141 gchar* m_filename;
00142 gchar *m_title;
00143 gchar *m_label;
00144 gchar *m_comment, *m_author, *m_mail;
00145 bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
00146 std::string m_FileType;
00147 bool m_bWriteable;
00148 GDate CreationDate, RevisionDate;
00149 std::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 std::set<Residue const *> m_SavedResidues;
00156
00157
00158
00159 GCU_RO_PROP (Theme*, Theme)
00160 GCU_PROP (double, BondLength)
00161 GCU_PROP (double, BondAngle)
00162 GCU_PROP (double, ArrowLength)
00163 GCU_PROP (gchar*, TextFontFamily)
00164 GCU_PROP (PangoStyle, TextFontStyle)
00165 GCU_PROP (PangoWeight, TextFontWeight)
00166 GCU_PROP (PangoVariant, TextFontVariant)
00167 GCU_PROP (PangoStretch, TextFontStretch)
00168 GCU_PROP (gint, TextFontSize)
00169 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
00170 GCU_PROP (bool, AllowClipboard)
00171 };
00172
00173 extern std::list<Document*> Docs;
00174 extern bool bCloseAll;
00175
00176 }
00177
00178 #endif // GCHEMPAINT_DOCUMENT_H