The Gnome Chemistry Utils  0.14.0
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 gchar* GetTitle () const;
130  void SetTitle (const gchar* title);
136  void SetLabel (const gchar* label);
140  const gchar* GetLabel () const;
147  void SetFileName (std::string const &filename, const gchar *mime_type);
151  const gchar* GetFileName () const {return m_filename;}
159  void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const;
165  void AddObject (Object* pObject);
171  void AddAtom (Atom* pAtom);
177  void AddFragment (Fragment* pFragment);
184  void AddBond (Bond* pBond);
190  void ParseXMLTree (xmlDocPtr xml);
195  void LoadObjects (xmlNodePtr node);
201  xmlDocPtr BuildXMLTree () const;
205  void Update ();
211  void Remove (Object* object);
217  void Remove (const char* Id);
221  void OnProperties ();
225  void OnUndo ();
229  void OnRedo ();
233  const GDate* GetCreationDate () {return &CreationDate;}
237  const GDate* GetRevisionDate () {return &RevisionDate;}
241  const gchar* GetAuthor () {return m_author;}
245  const gchar* GetMail () {return m_mail;}
249  const gchar* GetComment () {return m_comment;}
255  void SetAuthor (const gchar* author);
261  void SetMail (const gchar* mail);
267  void SetComment (const gchar* comment);
273  void FinishOperation ();
277  void AbortOperation ();
281  void PopOperation ();
288  void PushOperation (Operation* operation, bool undo = true);
293  void SetActive ();
303  Operation* GetCurrentOperation () {return m_pCurOp;}
310  void PasteData (xmlNodePtr node);
314  bool CanUndo () {return m_UndoList.size() > 0;}
320  void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
324  bool GetEditable () {return m_bWriteable;}
328  gcp::Application* GetApplication () {return m_pApp;}
338  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
344  void SetReadOnly (bool ro);
348  bool GetReadOnly () {return m_bReadOnly;}
355  virtual double GetYAlign ();
363  GtkWindow *GetGtkWindow ();
370  void SetTheme (Theme *theme);
379  bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
385  void SetDirty (bool isDirty = true);
390  void OnThemeNamesChanged ();
396  double GetMedianBondLength ();
406  bool SetProperty (unsigned property, char const *value);
407 
416  std::string GetProperty (unsigned property) const;
417 
423  void SetLoading (bool loading) {m_bIsLoading = loading;}
431  void SaveResidue (Residue const *r, xmlNodePtr node);
441  gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
450  gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule);
451 
458  std::set <std::string> &GetNewObjects () {return m_NewObjects;}
459 
460 private:
461  void RemoveAtom (Atom* pAtom);
462  void RemoveBond (Bond* pBond);
463  void RemoveFragment (Fragment* pFragment);
464 
465  //Implementation
466 private:
467  View * m_pView;
468  gchar* m_filename;
469  gchar *m_title;
470  gchar *m_label;
471  gchar *m_comment, *m_author, *m_mail;
472  bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
473  std::string m_FileType;
474  bool m_bWriteable;
475  GDate CreationDate, RevisionDate;
476  std::list<Operation*> m_UndoList, m_RedoList;
477  Operation* m_pCurOp;
478  Application* m_pApp;
479  Window *m_Window;
480  unsigned long m_OpID; // last operation ID
481  unsigned m_LastStackSize; // undo list size when last saved
482  std::set<Residue const *> m_SavedResidues;
483  std::map<std::string, gcu::SymbolResidue> m_Residues;
484  std::set <std::string> m_NewObjects;
485 
486 /* Theme is not really a read only property, but we provide a special Set
487 method */
503 GCU_PROP (double, BondLength)
518 GCU_PROP (double, BondAngle)
530 GCU_PROP (double, ArrowLength)
542 GCU_PROP (gchar*, TextFontFamily)
554 GCU_PROP (PangoStyle, TextFontStyle)
566 GCU_PROP (PangoWeight, TextFontWeight)
578 GCU_PROP (PangoVariant, TextFontVariant)
590 GCU_PROP (PangoStretch, TextFontStretch)
602 GCU_PROP (gint, TextFontSize)
606 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
618 GCU_PROP (bool, AllowClipboard)
627 GCU_RO_PROP (unsigned, SoftwareVersion)
639 GCU_PROP (std::string, BracketsFontFamily)
651 GCU_PROP (int, BracketsFontSize)
652 
665 GCU_PROP (bool, UseAtomColors)
666 };
667 
668 } // namespace gcp
669 
670 #endif // GCHEMPAINT_DOCUMENT_H