The Gnome Chemistry Utils  0.15.1
gcp/document.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * GChemPaint library
5  * document.h
6  *
7  * Copyright (C) 2001-2012 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCHEMPAINT_DOCUMENT_H
26 #define GCHEMPAINT_DOCUMENT_H
27 
28 #include "operation.h"
29 #include <gcu/document.h>
30 #include <gcu/macros.h>
31 #include <gcugtk/printable.h>
32 #include <gcu/residue.h>
33 #include <gcugtk/printable.h>
34 #include <list>
35 #include <map>
36 #include <set>
37 #include <string>
38 #include <libxml/tree.h>
39 #include <gtk/gtk.h>
40 
42 namespace OpenBabel
43 {
44  class OBMol;
45 }
46 
47 namespace gcp {
48 
64 
65 class View;
66 class Application;
67 class Window;
68 class Theme;
69 class Residue;
70 class Atom;
71 class Bond;
72 class Fragment;
73 class Molecule;
74 
79 {
80  //Constructor and destructor
81 public:
90  Document (Application *App, bool StandAlone, Window *window = NULL);
94  virtual ~Document ();
95 
96  //Interface
97 public:
101  void Clear ();
105  GtkWidget* GetWidget ();
109  View* GetView () {return m_pView;}
113  void Save () const;
120  virtual bool Load (xmlNodePtr node);
124  const char* GetTitle () const;
130  void SetLabel (const gchar* label);
134  const gchar* GetLabel () const;
141  void SetFileName (std::string const &filename, const gchar *mime_type);
145  const gchar* GetFileName () const {return m_filename;}
153  void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const;
159  void AddObject (Object* pObject);
165  void AddAtom (Atom* pAtom);
171  void AddFragment (Fragment* pFragment);
178  void AddBond (Bond* pBond);
184  void ParseXMLTree (xmlDocPtr xml);
189  void LoadObjects (xmlNodePtr node);
195  xmlDocPtr BuildXMLTree () const;
199  void Update ();
205  void Remove (Object* object);
211  void Remove (const char* Id);
215  void OnProperties ();
219  void OnUndo ();
223  void OnRedo ();
227  const GDate* GetCreationDate () {return &CreationDate;}
231  const GDate* GetRevisionDate () {return &RevisionDate;}
235  const gchar* GetAuthor () {return m_author;}
239  const gchar* GetMail () {return m_mail;}
245  void SetAuthor (const gchar* author);
251  void SetMail (const gchar* mail);
257  void FinishOperation ();
261  void AbortOperation ();
265  void PopOperation ();
272  void PushOperation (Operation* operation, bool undo = true);
277  void SetActive ();
287  Operation* GetCurrentOperation () {return m_pCurOp;}
294  void PasteData (xmlNodePtr node);
298  bool CanUndo () {return m_UndoList.size() > 0;}
304  void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
308  bool GetEditable () {return m_bWriteable;}
312  gcp::Application* GetApplication () {return m_pApp;}
322  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
328  void SetReadOnly (bool ro);
332  bool GetReadOnly () {return m_bReadOnly;}
339  virtual double GetYAlign ();
347  GtkWindow *GetGtkWindow ();
354  void SetTheme (Theme *theme);
363  bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
369  void SetDirty (bool isDirty = true);
374  void OnThemeNamesChanged ();
380  double GetMedianBondLength ();
390  bool SetProperty (unsigned property, char const *value);
391 
400  std::string GetProperty (unsigned property) const;
401 
407  void SetLoading (bool loading) {m_bIsLoading = loading;}
415  void SaveResidue (Residue const *r, xmlNodePtr node);
425  gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
434  gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule);
435 
442  std::set <std::string> &GetNewObjects () {return m_NewObjects;}
443 
444 private:
445  void RemoveAtom (Atom* pAtom);
446  void RemoveBond (Bond* pBond);
447  void RemoveFragment (Fragment* pFragment);
448 
449  //Implementation
450 private:
451  View * m_pView;
452  gchar* m_filename;
453  gchar *m_label;
454  gchar *m_author, *m_mail;
455  bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
456  std::string m_FileType;
457  bool m_bWriteable;
458  GDate CreationDate, RevisionDate;
459  std::list<Operation*> m_UndoList, m_RedoList;
460  Operation* m_pCurOp;
461  Application* m_pApp;
462  Window *m_Window;
463  unsigned long m_OpID; // last operation ID
464  unsigned m_LastStackSize; // undo list size when last saved
465  std::set<Residue const *> m_SavedResidues;
466  std::map<std::string, gcu::SymbolResidue> m_Residues;
467  std::set <std::string> m_NewObjects;
468 
469 /* Theme is not really a read only property, but we provide a special Set
470 method */
486 GCU_PROP (double, BondLength)
501 GCU_PROP (double, BondAngle)
513 GCU_PROP (double, ArrowLength)
525 GCU_PROP (gchar*, TextFontFamily)
537 GCU_PROP (PangoStyle, TextFontStyle)
549 GCU_PROP (PangoWeight, TextFontWeight)
561 GCU_PROP (PangoVariant, TextFontVariant)
573 GCU_PROP (PangoStretch, TextFontStretch)
585 GCU_PROP (gint, TextFontSize)
589 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
601 GCU_PROP (bool, AllowClipboard)
610 GCU_RO_PROP (unsigned, SoftwareVersion)
622 GCU_PROP (std::string, BracketsFontFamily)
634 GCU_PROP (int, BracketsFontSize)
635 
648 GCU_PROP (bool, UseAtomColors)
649 };
650 
651 } // namespace gcp
652 
653 #endif // GCHEMPAINT_DOCUMENT_H
void AddAtom(Atom *pAtom)
themes class.
Definition: theme.h:67
void AddObject(Object *pObject)
void SetDirty(bool isDirty=true)
void SetLabel(const gchar *label)
const gchar * GetLabel() const
gcu::SignalId OnChangedSignal
#define GCU_RO_PROP(type, member)
Definition: macros.h:142
void OnProperties()
void ExportImage(std::string const &filename, const char *type, int resolution=-1)
gcu::SignalId OnDeleteSignal
void AddFragment(Fragment *pFragment)
void SetEditable(bool editable)
Definition: gcp/document.h:304
Operation * GetNewOperation(OperationType type)
gcu::SignalId OnThemeChangedSignal
const gchar * GetFileName() const
Definition: gcp/document.h:145
View * GetView()
Definition: gcp/document.h:109
void OnThemeNamesChanged()
void PasteData(xmlNodePtr node)
OperationType
Definition: operation.h:41
a GChemPaint specific Residue class.
Definition: gcp/residue.h:44
Operation * GetCurrentOperation()
Definition: gcp/document.h:287
void Remove(Object *object)
const GDate * GetRevisionDate()
Definition: gcp/document.h:231
gcu::Window * GetWindow()
virtual ~Document()
void FinishOperation()
Atoms groups.
Definition: fragment.h:109
void SetFileName(std::string const &filename, const gchar *mime_type)
bool GetEditable()
Definition: gcp/document.h:308
GtkWindow * GetGtkWindow()
const gchar * GetAuthor()
Definition: gcp/document.h:235
void DoPrint(GtkPrintOperation *print, GtkPrintContext *context, int page) const
const gchar * GetMail()
Definition: gcp/document.h:239
bool GetReadOnly()
Definition: gcp/document.h:332
void SaveResidue(Residue const *r, xmlNodePtr node)
void Save() const
virtual double GetYAlign()
void SetLoading(bool loading)
Definition: gcp/document.h:407
bool SetProperty(unsigned property, char const *value)
virtual bool Load(xmlNodePtr node)
unsigned SignalId
Definition: object.h:151
void AddBond(Bond *pBond)
void PopOperation()
void SetTheme(Theme *theme)
void SetAuthor(const gchar *author)
void LoadObjects(xmlNodePtr node)
Document(Application *App, bool StandAlone, Window *window=NULL)
std::string GetProperty(unsigned property) const
gcu::Residue * CreateResidue(char const *name, char const *symbol, gcu::Molecule *molecule)
const GDate * GetCreationDate()
Definition: gcp/document.h:227
gcp::Application * GetApplication()
Definition: gcp/document.h:312
gcu::Residue const * GetResidue(char const *symbol, bool *ambiguous=NULL)
#define GCU_PROP(type, member)
Definition: macros.h:51
void PushOperation(Operation *operation, bool undo=true)
const char * GetTitle() const
void AbortOperation()
std::set< std::string > & GetNewObjects()
Definition: gcp/document.h:442
void SetReadOnly(bool ro)
void SetActive()
double GetMedianBondLength()
xmlDocPtr BuildXMLTree() const
GChemPaint application base class.
bool OnSignal(gcu::SignalId Signal, gcu::Object *Child)
void SetMail(const gchar *mail)
void ParseXMLTree(xmlDocPtr xml)
GtkWidget * GetWidget()