The Gnome Chemistry Utils  0.14.15
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;}
110  View const*GetView () const {return m_pView;}
114  void Save () const;
121  virtual bool Load (xmlNodePtr node);
125  const gchar* GetTitle () const;
131  void SetTitle (const gchar* title);
137  void SetLabel (const gchar* label);
141  const gchar* GetLabel () const;
148  void SetFileName (std::string const &filename, const gchar *mime_type);
152  const gchar* GetFileName () const {return m_filename;}
160  void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const;
166  void AddObject (Object* pObject);
172  void AddAtom (Atom* pAtom);
178  void AddFragment (Fragment* pFragment);
185  void AddBond (Bond* pBond);
191  void ParseXMLTree (xmlDocPtr xml);
196  void LoadObjects (xmlNodePtr node);
202  xmlDocPtr BuildXMLTree () const;
206  void Update ();
212  void Remove (Object* object);
218  void Remove (const char* Id);
222  void OnProperties ();
226  void OnUndo ();
230  void OnRedo ();
234  const GDate* GetCreationDate () {return &CreationDate;}
238  const GDate* GetRevisionDate () {return &RevisionDate;}
242  const gchar* GetAuthor () {return m_author;}
246  const gchar* GetMail () {return m_mail;}
250  const gchar* GetComment () {return m_comment;}
256  void SetAuthor (const gchar* author);
262  void SetMail (const gchar* mail);
268  void SetComment (const gchar* comment);
274  void FinishOperation ();
278  void AbortOperation ();
282  void PopOperation ();
289  void PushOperation (Operation* operation, bool undo = true);
294  void SetActive ();
300  Operation* GetNewOperation (OperationType type);
304  Operation* GetCurrentOperation () {return m_pCurOp;}
311  void PasteData (xmlNodePtr node);
315  bool CanUndo () {return m_UndoList.size() > 0;}
321  void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
325  bool GetEditable () {return m_bWriteable;}
329  gcp::Application* GetApplication () {return m_pApp;}
339  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
345  void SetReadOnly (bool ro);
349  bool GetReadOnly () {return m_bReadOnly;}
356  virtual double GetYAlign ();
360  gcu::Window *GetWindow ();
364  GtkWindow *GetGtkWindow ();
371  void SetTheme (Theme *theme);
380  bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
386  void SetDirty (bool isDirty = true);
391  void OnThemeNamesChanged ();
397  double GetMedianBondLength ();
407  bool SetProperty (unsigned property, char const *value);
408 
417  std::string GetProperty (unsigned property) const;
418 
424  void SetLoading (bool loading) {m_bIsLoading = loading;}
432  void SaveResidue (Residue const *r, xmlNodePtr node);
442  gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
451  gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule);
452 
459  std::set <std::string> &GetNewObjects () {return m_NewObjects;}
460 
461 private:
462  void RemoveAtom (Atom* pAtom);
463  void RemoveBond (Bond* pBond);
464  void RemoveFragment (Fragment* pFragment);
465 
466  //Implementation
467 private:
468  View * m_pView;
469  gchar* m_filename;
470  gchar *m_title;
471  gchar *m_label;
472  gchar *m_comment, *m_author, *m_mail;
473  bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
474  std::string m_FileType;
475  bool m_bWriteable;
476  GDate CreationDate, RevisionDate;
477  std::list<Operation*> m_UndoList, m_RedoList;
478  Operation* m_pCurOp;
479  Application* m_pApp;
480  Window *m_Window;
481  unsigned long m_OpID; // last operation ID
482  unsigned m_LastStackSize; // undo list size when last saved
483  std::set<Residue const *> m_SavedResidues;
484  std::map<std::string, gcu::SymbolResidue> m_Residues;
485  std::set <std::string> m_NewObjects;
486 
487 /* Theme is not really a read only property, but we provide a special Set
488 method */
504 GCU_PROP (double, BondLength)
519 GCU_PROP (double, BondAngle)
531 GCU_PROP (double, ArrowLength)
543 GCU_PROP (gchar*, TextFontFamily)
555 GCU_PROP (PangoStyle, TextFontStyle)
567 GCU_PROP (PangoWeight, TextFontWeight)
579 GCU_PROP (PangoVariant, TextFontVariant)
591 GCU_PROP (PangoStretch, TextFontStretch)
603 GCU_PROP (gint, TextFontSize)
607 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
619 GCU_PROP (bool, AllowClipboard)
628 GCU_RO_PROP (unsigned, SoftwareVersion)
640 GCU_PROP (std::string, BracketsFontFamily)
652 GCU_PROP (int, BracketsFontSize)
653 
666 GCU_PROP (bool, UseAtomColors)
667 };
668 
669 } // namespace gcp
670 
671 #endif // GCHEMPAINT_DOCUMENT_H
themes class.
Definition: theme.h:67
GChemPaint specific C++ classes.
gcu::SignalId OnChangedSignal
#define GCU_RO_PROP(type, member)
Definition: macros.h:117
gcu::SignalId OnDeleteSignal
void SetEditable(bool editable)
Definition: gcp/document.h:321
gcu::SignalId OnThemeChangedSignal
View * GetView()
Definition: gcp/document.h:109
OperationType
Definition: operation.h:41
a GChemPaint specific Residue class.
Definition: gcp/residue.h:44
Operation * GetCurrentOperation()
Definition: gcp/document.h:304
const GDate * GetRevisionDate()
Definition: gcp/document.h:238
Atoms groups.
Definition: fragment.h:109
bool GetEditable()
Definition: gcp/document.h:325
const gchar * GetAuthor()
Definition: gcp/document.h:242
const gchar * GetFileName() const
Definition: gcp/document.h:152
const gchar * GetMail()
Definition: gcp/document.h:246
bool GetReadOnly()
Definition: gcp/document.h:349
void SetLoading(bool loading)
Definition: gcp/document.h:424
unsigned SignalId
Definition: object.h:151
const gchar * GetComment()
Definition: gcp/document.h:250
const GDate * GetCreationDate()
Definition: gcp/document.h:234
gcp::Application * GetApplication()
Definition: gcp/document.h:329
#define GCU_PROP(type, member)
Definition: macros.h:50
std::set< std::string > & GetNewObjects()
Definition: gcp/document.h:459
GChemPaint application base class.