gcp/document.h

00001 // -*- C++ -*-
00002 
00003 /* 
00004  * GChemPaint library
00005  * document.h 
00006  *
00007  * Copyright (C) 2001-2008 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 "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         //Constructor and destructor
00063 public:
00064         Document (Application *App, bool StandAlone, Window *window = NULL);
00065         virtual ~Document ();
00066         
00067         //Interface
00068 public:
00069         void Clear ();
00070         GtkWidget* GetWidget ();
00071         View* GetView () {return m_pView;}
00072         void BuildBondList (std::list<Bond*>& BondList, Object* obj);
00073         bool ImportOB (OpenBabel::OBMol& Mol);
00074         void ExportOB ();
00075         void BuildAtomTable (std::map<std::string, unsigned>& AtomTable, Object* obj, unsigned& index);
00076         void Save ();
00077         virtual bool Load (xmlNodePtr);
00078         const gchar* GetTitle ();
00079         void SetTitle (const gchar* title);
00080         void SetLabel (const gchar* label);
00081         const gchar* GetLabel ();
00082         void SetFileName (std::string const &, const gchar *mime_type);
00083         const gchar* GetFileName () {return m_filename;}
00084         void DoPrint (GtkPrintOperation *print, GtkPrintContext *context);
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 ();
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         //Implementation
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; // last operation ID
00154         unsigned m_LastStackSize; // undo list size when last saved
00155         std::set<Residue const *> m_SavedResidues;
00156 
00157 /* Theme is not really a read only property, but we provide a special Set
00158 method */
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 }       //      namespace gcp
00177 
00178 #endif // GCHEMPAINT_DOCUMENT_H

Generated on Tue Mar 18 16:06:03 2008 for The Gnome Chemistry Utils by  doxygen 1.5.5