gcp/document.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * document.h 
00006  *
00007  * Copyright (C) 2001-2007 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
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         //Constructor and destructor
00062 public:
00063         Document (Application *App, bool StandAlone, Window *window = NULL);
00064         virtual ~Document ();
00065         
00066         //Interface
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         //Implementation
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; // last operation ID
00151         unsigned m_LastStackSize; // undo list size when last saved
00152 
00153 /* Theme is not really a read only property, but we provide a special Set
00154 method */
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 }       //      namespace gcp
00173 
00174 #endif // GCHEMPAINT_DOCUMENT_H

Generated on Thu Dec 20 11:20:45 2007 for The Gnome Chemistry Utils by  doxygen 1.5.4