The Gnome Chemistry Utils 0.13.3
|
00001 // -*- C++ -*- 00002 00003 /* 00004 * GChemPaint library 00005 * document.h 00006 * 00007 * Copyright (C) 2001-2011 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 <gcugtk/printable.h> 00032 #include <gcu/residue.h> 00033 #include <gcugtk/printable.h> 00034 #include <list> 00035 #include <map> 00036 #include <set> 00037 #include <string> 00038 #include <libxml/tree.h> 00039 #include <gtk/gtk.h> 00040 00042 namespace OpenBabel 00043 { 00044 class OBMol; 00045 } 00046 00047 namespace gcp { 00048 00053 extern gcu::SignalId OnChangedSignal; 00058 extern gcu::SignalId OnDeleteSignal; 00063 extern gcu::SignalId OnThemeChangedSignal; 00064 00065 class View; 00066 class Application; 00067 class Window; 00068 class Theme; 00069 class Residue; 00070 class Atom; 00071 class Bond; 00072 class Fragment; 00073 class Molecule; 00074 00078 class Document: public gcu::Document, public gcugtk::Printable 00079 { 00080 //Constructor and destructor 00081 public: 00090 Document (Application *App, bool StandAlone, Window *window = NULL); 00094 virtual ~Document (); 00095 00096 //Interface 00097 public: 00101 void Clear (); 00105 GtkWidget* GetWidget (); 00109 View* GetView () {return m_pView;} 00113 void Save () const; 00120 virtual bool Load (xmlNodePtr node); 00124 const gchar* GetTitle () const; 00130 void SetTitle (const gchar* title); 00136 void SetLabel (const gchar* label); 00140 const gchar* GetLabel () const; 00147 void SetFileName (std::string const &filename, const gchar *mime_type); 00151 const gchar* GetFileName () const {return m_filename;} 00159 void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const; 00165 void AddObject (Object* pObject); 00171 void AddAtom (Atom* pAtom); 00177 void AddFragment (Fragment* pFragment); 00184 void AddBond (Bond* pBond); 00190 void ParseXMLTree (xmlDocPtr xml); 00195 void LoadObjects (xmlNodePtr node); 00201 xmlDocPtr BuildXMLTree () const; 00205 void Update (); 00211 void Remove (Object* object); 00217 void Remove (const char* Id); 00221 void OnProperties (); 00225 void OnUndo (); 00229 void OnRedo (); 00233 const GDate* GetCreationDate () {return &CreationDate;} 00237 const GDate* GetRevisionDate () {return &RevisionDate;} 00241 const gchar* GetAuthor () {return m_author;} 00245 const gchar* GetMail () {return m_mail;} 00249 const gchar* GetComment () {return m_comment;} 00255 void SetAuthor (const gchar* author); 00261 void SetMail (const gchar* mail); 00267 void SetComment (const gchar* comment); 00273 void FinishOperation (); 00277 void AbortOperation (); 00281 void PopOperation (); 00288 void PushOperation (Operation* operation, bool undo = true); 00293 void SetActive (); 00299 Operation* GetNewOperation (OperationType type); 00303 Operation* GetCurrentOperation () {return m_pCurOp;} 00310 void PasteData (xmlNodePtr node); 00314 bool CanUndo () {return m_UndoList.size() > 0;} 00320 void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;} 00324 bool GetEditable () {return m_bWriteable;} 00328 gcp::Application* GetApplication () {return m_pApp;} 00338 void ExportImage (std::string const &filename, const char* type, int resolution = -1); 00344 void SetReadOnly (bool ro); 00348 bool GetReadOnly () {return m_bReadOnly;} 00355 virtual double GetYAlign (); 00359 Window *GetWindow () {return m_Window;} 00363 GtkWindow *GetGtkWindow (); 00370 void SetTheme (Theme *theme); 00379 bool OnSignal (gcu::SignalId Signal, gcu::Object *Child); 00385 void SetDirty (bool isDirty = true); 00390 void OnThemeNamesChanged (); 00396 double GetMedianBondLength (); 00406 bool SetProperty (unsigned property, char const *value); 00407 00416 std::string GetProperty (unsigned property) const; 00417 00423 void SetLoading (bool loading) {m_bIsLoading = loading;} 00431 void SaveResidue (Residue const *r, xmlNodePtr node); 00441 gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL); 00451 gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule); 00452 00453 std::set <std::string> &GetNewObjects () {return m_NewObjects;} 00454 00455 private: 00456 void RemoveAtom (Atom* pAtom); 00457 void RemoveBond (Bond* pBond); 00458 void RemoveFragment (Fragment* pFragment); 00459 00460 //Implementation 00461 private: 00462 View * m_pView; 00463 gchar* m_filename; 00464 gchar *m_title; 00465 gchar *m_label; 00466 gchar *m_comment, *m_author, *m_mail; 00467 bool m_bIsLoading, m_bUndoRedo, m_bReadOnly; 00468 std::string m_FileType; 00469 bool m_bWriteable; 00470 GDate CreationDate, RevisionDate; 00471 std::list<Operation*> m_UndoList, m_RedoList; 00472 Operation* m_pCurOp; 00473 Application* m_pApp; 00474 Window *m_Window; 00475 unsigned long m_OpID; // last operation ID 00476 unsigned m_LastStackSize; // undo list size when last saved 00477 std::set<Residue const *> m_SavedResidues; 00478 std::map<std::string, gcu::SymbolResidue> m_Residues; 00479 std::set <std::string> m_NewObjects; 00480 00481 /* Theme is not really a read only property, but we provide a special Set 00482 method */ 00486 GCU_RO_PROP (Theme*, Theme) 00498 GCU_PROP (double, BondLength) 00513 GCU_PROP (double, BondAngle) 00525 GCU_PROP (double, ArrowLength) 00537 GCU_PROP (gchar*, TextFontFamily) 00549 GCU_PROP (PangoStyle, TextFontStyle) 00561 GCU_PROP (PangoWeight, TextFontWeight) 00573 GCU_PROP (PangoVariant, TextFontVariant) 00585 GCU_PROP (PangoStretch, TextFontStretch) 00597 GCU_PROP (gint, TextFontSize) 00601 GCU_RO_PROP (PangoAttrList*, PangoAttrList) 00613 GCU_PROP (bool, AllowClipboard) 00622 GCU_RO_PROP (unsigned, SoftwareVersion) 00634 GCU_PROP (std::string, BracketsFontFamily) 00646 GCU_PROP (int, BracketsFontSize) 00647 GCU_PROP (bool, UseAtomColors) 00648 }; 00649 00650 } // namespace gcp 00651 00652 #endif // GCHEMPAINT_DOCUMENT_H