The Gnome Chemistry Utils 0.12.9
|
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 <gcu/residue.h> 00033 #include <list> 00034 #include <map> 00035 #include <set> 00036 #include <string> 00037 #include <libxml/tree.h> 00038 #include <gtk/gtk.h> 00039 00041 namespace OpenBabel 00042 { 00043 class OBMol; 00044 } 00045 00046 namespace gcp { 00047 00052 extern gcu::SignalId OnChangedSignal; 00057 extern gcu::SignalId OnDeleteSignal; 00062 extern gcu::SignalId OnThemeChangedSignal; 00063 00064 class View; 00065 class Application; 00066 class Window; 00067 class Theme; 00068 class Residue; 00069 class Atom; 00070 class Bond; 00071 class Fragment; 00072 class Molecule; 00073 00077 class Document: public gcu::Document, public gcu::Printable 00078 { 00079 //Constructor and destructor 00080 public: 00089 Document (Application *App, bool StandAlone, Window *window = NULL); 00093 virtual ~Document (); 00094 00095 //Interface 00096 public: 00100 void Clear (); 00104 GtkWidget* GetWidget (); 00108 View* GetView () {return m_pView;} 00114 bool ImportOB (OpenBabel::OBMol& Mol); 00118 void ExportOB () const; 00122 void Save () const; 00129 virtual bool Load (xmlNodePtr node); 00133 const gchar* GetTitle () const; 00139 void SetTitle (const gchar* title); 00145 void SetLabel (const gchar* label); 00149 const gchar* GetLabel () const; 00156 void SetFileName (std::string const &filename, const gchar *mime_type); 00160 const gchar* GetFileName () const {return m_filename;} 00168 void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const; 00174 void AddObject (Object* pObject); 00180 void AddAtom (Atom* pAtom); 00186 void AddFragment (Fragment* pFragment); 00193 void AddBond (Bond* pBond); 00199 void ParseXMLTree (xmlDocPtr xml); 00204 void LoadObjects (xmlNodePtr node); 00210 xmlDocPtr BuildXMLTree () const; 00214 void Update (); 00220 void Remove (Object* object); 00226 void Remove (const char* Id); 00230 void OnProperties (); 00234 void OnUndo (); 00238 void OnRedo (); 00242 const GDate* GetCreationDate () {return &CreationDate;} 00246 const GDate* GetRevisionDate () {return &RevisionDate;} 00250 const gchar* GetAuthor () {return m_author;} 00254 const gchar* GetMail () {return m_mail;} 00258 const gchar* GetComment () {return m_comment;} 00264 void SetAuthor (const gchar* author); 00270 void SetMail (const gchar* mail); 00276 void SetComment (const gchar* comment); 00282 void FinishOperation (); 00286 void AbortOperation (); 00290 void PopOperation (); 00297 void PushOperation (Operation* operation, bool undo = true); 00302 void SetActive (); 00308 Operation* GetNewOperation (OperationType type); 00312 Operation* GetCurrentOperation () {return m_pCurOp;} 00318 void AddData (xmlNodePtr node); 00322 bool CanUndo () {return m_UndoList.size() > 0;} 00328 void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;} 00332 bool GetEditable () {return m_bWriteable;} 00336 gcp::Application* GetApplication () {return m_pApp;} 00346 void ExportImage (std::string const &filename, const char* type, int resolution = -1); 00352 void SetReadOnly (bool ro); 00356 bool GetReadOnly () {return m_bReadOnly;} 00363 virtual double GetYAlign (); 00367 Window *GetWindow () {return m_Window;} 00371 GtkWindow *GetGtkWindow (); 00378 void SetTheme (Theme *theme); 00387 bool OnSignal (gcu::SignalId Signal, gcu::Object *Child); 00393 void SetDirty (bool isDirty = true); 00398 void OnThemeNamesChanged (); 00404 double GetMedianBondLength (); 00414 bool SetProperty (unsigned property, char const *value); 00415 00424 std::string GetProperty (unsigned property) const; 00425 00431 void SetLoading (bool loading) {m_bIsLoading = loading;} 00439 void SaveResidue (Residue const *r, xmlNodePtr node); 00449 gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL); 00459 gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule); 00460 00461 private: 00462 void BuildBondList (std::list<Bond*>& BondList, gcu::Object const *obj) const; 00463 void BuildAtomTable (std::map<std::string, unsigned>& AtomTable, gcu::Object const *obj, unsigned& index) const; 00464 void RemoveAtom (Atom* pAtom); 00465 void RemoveBond (Bond* pBond); 00466 void RemoveFragment (Fragment* pFragment); 00467 00468 //Implementation 00469 private: 00470 View * m_pView; 00471 gchar* m_filename; 00472 gchar *m_title; 00473 gchar *m_label; 00474 gchar *m_comment, *m_author, *m_mail; 00475 bool m_bIsLoading, m_bUndoRedo, m_bReadOnly; 00476 std::string m_FileType; 00477 bool m_bWriteable; 00478 GDate CreationDate, RevisionDate; 00479 std::list<Operation*> m_UndoList, m_RedoList; 00480 Operation* m_pCurOp; 00481 Application* m_pApp; 00482 Window *m_Window; 00483 unsigned long m_OpID; // last operation ID 00484 unsigned m_LastStackSize; // undo list size when last saved 00485 std::set<Residue const *> m_SavedResidues; 00486 std::map<std::string, gcu::SymbolResidue> m_Residues; 00487 00488 /* Theme is not really a read only property, but we provide a special Set 00489 method */ 00493 GCU_RO_PROP (Theme*, Theme) 00505 GCU_PROP (double, BondLength) 00520 GCU_PROP (double, BondAngle) 00532 GCU_PROP (double, ArrowLength) 00544 GCU_PROP (gchar*, TextFontFamily) 00556 GCU_PROP (PangoStyle, TextFontStyle) 00568 GCU_PROP (PangoWeight, TextFontWeight) 00580 GCU_PROP (PangoVariant, TextFontVariant) 00592 GCU_PROP (PangoStretch, TextFontStretch) 00604 GCU_PROP (gint, TextFontSize) 00608 GCU_RO_PROP (PangoAttrList*, PangoAttrList) 00620 GCU_PROP (bool, AllowClipboard) 00629 GCU_RO_PROP (unsigned, SoftwareVersion) 00630 }; 00631 00632 } // namespace gcp 00633 00634 #endif // GCHEMPAINT_DOCUMENT_H