gcp/document.h

Go to the documentation of this file.
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 () {return m_filename;}
00167         void DoPrint (GtkPrintOperation *print, GtkPrintContext *context) const;
00173         void AddObject (Object* pObject);
00179         void AddAtom (Atom* pAtom);
00185         void AddFragment (Fragment* pFragment);
00192         void AddBond (Bond* pBond);
00198         void ParseXMLTree (xmlDocPtr xml);
00203         void LoadObjects (xmlNodePtr node);
00209         xmlDocPtr BuildXMLTree () const;
00213         void Update ();
00219         void Remove (Object* object);
00225         void Remove (const char* Id);
00229         void OnProperties ();
00233         void OnUndo ();
00237         void OnRedo ();
00241         const GDate* GetCreationDate () {return &CreationDate;}
00245         const GDate* GetRevisionDate () {return &RevisionDate;}
00249         const gchar* GetAuthor () {return m_author;}
00253         const gchar* GetMail () {return m_mail;}
00257         const gchar* GetComment () {return m_comment;}
00263         void SetAuthor (const gchar* author);
00269         void SetMail (const gchar* mail);
00275         void SetComment (const gchar* comment);
00281         void FinishOperation ();
00285         void AbortOperation ();
00289         void PopOperation ();
00296         void PushOperation (Operation* operation, bool undo = true);
00301         void SetActive ();
00307         Operation* GetNewOperation (OperationType type);
00311         Operation* GetCurrentOperation () {return m_pCurOp;}
00317         void AddData (xmlNodePtr node);
00321         bool CanUndo () {return m_UndoList.size() > 0;}
00327         void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
00331         bool GetEditable () {return m_bWriteable;}
00335         gcp::Application* GetApplication () {return m_pApp;}
00345         void ExportImage (std::string const &filename, const char* type, int resolution = -1);
00351         void SetReadOnly (bool ro);
00355         bool GetReadOnly () {return m_bReadOnly;}
00362         virtual double GetYAlign ();
00366         Window *GetWindow () {return m_Window;}
00370         GtkWindow *GetGtkWindow ();
00377         void SetTheme (Theme *theme);
00386         bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
00392         void SetDirty (bool isDirty = true);
00397         void OnThemeNamesChanged ();
00403         double GetMedianBondLength ();
00413         bool SetProperty (unsigned property, char const *value);
00419         void SetLoading (bool loading) {m_bIsLoading = loading;}
00427         void SaveResidue (Residue const *r, xmlNodePtr node);
00437         gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
00447         gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule);
00448 
00449 private:
00450         void BuildBondList (std::list<Bond*>& BondList, gcu::Object const *obj) const;
00451         void BuildAtomTable (std::map<std::string, unsigned>& AtomTable, gcu::Object const *obj, unsigned& index) const;
00452         void RemoveAtom (Atom* pAtom);
00453         void RemoveBond (Bond* pBond);
00454         void RemoveFragment (Fragment* pFragment);
00455 
00456         //Implementation
00457 private:
00458         View * m_pView;
00459         gchar* m_filename;
00460         gchar *m_title;
00461         gchar *m_label;
00462         gchar *m_comment, *m_author, *m_mail;
00463         bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
00464         std::string m_FileType;
00465         bool m_bWriteable;
00466         GDate CreationDate, RevisionDate;
00467         std::list<Operation*> m_UndoList, m_RedoList;
00468         Operation* m_pCurOp;
00469         Application* m_pApp;
00470         Window *m_Window;
00471         unsigned long m_OpID; // last operation ID
00472         unsigned m_LastStackSize; // undo list size when last saved
00473         std::set<Residue const *> m_SavedResidues;
00474         std::map<std::string, gcu::SymbolResidue> m_Residues;
00475 
00476 /* Theme is not really a read only property, but we provide a special Set
00477 method */
00481 GCU_RO_PROP (Theme*, Theme)
00493 GCU_PROP (double, BondLength)
00508 GCU_PROP (double, BondAngle)
00520 GCU_PROP (double, ArrowLength)
00532 GCU_PROP (gchar*, TextFontFamily)
00544 GCU_PROP (PangoStyle, TextFontStyle)
00556 GCU_PROP (PangoWeight, TextFontWeight)
00568 GCU_PROP (PangoVariant, TextFontVariant)
00580 GCU_PROP (PangoStretch, TextFontStretch)
00592 GCU_PROP (gint, TextFontSize)
00596 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
00608 GCU_PROP (bool, AllowClipboard)
00609 };
00610 
00611 }       //      namespace gcp
00612 
00613 #endif // GCHEMPAINT_DOCUMENT_H

Generated on Sat Nov 14 11:46:35 2009 for The Gnome Chemistry Utils by  doxygen 1.6.1