The Gnome Chemistry Utils  0.12.13
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-2008 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 2 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 <gcu/printable.h>
32 #include <gcu/residue.h>
33 #include <list>
34 #include <map>
35 #include <set>
36 #include <string>
37 #include <libxml/tree.h>
38 #include <gtk/gtk.h>
39 
41 namespace OpenBabel
42 {
43  class OBMol;
44 }
45 
46 namespace gcp {
47 
63 
64 class View;
65 class Application;
66 class Window;
67 class Theme;
68 class Residue;
69 class Atom;
70 class Bond;
71 class Fragment;
72 class Molecule;
73 
77 class Document: public gcu::Document, public gcu::Printable
78 {
79  //Constructor and destructor
80 public:
89  Document (Application *App, bool StandAlone, Window *window = NULL);
93  virtual ~Document ();
94 
95  //Interface
96 public:
100  void Clear ();
104  GtkWidget* GetWidget ();
108  View* GetView () {return m_pView;}
114  bool ImportOB (OpenBabel::OBMol& Mol);
118  void ExportOB () const;
122  void Save () const;
129  virtual bool Load (xmlNodePtr node);
133  const gchar* GetTitle () const;
139  void SetTitle (const gchar* title);
145  void SetLabel (const gchar* label);
149  const gchar* GetLabel () const;
156  void SetFileName (std::string const &filename, const gchar *mime_type);
160  const gchar* GetFileName () const {return m_filename;}
168  void DoPrint (GtkPrintOperation *print, GtkPrintContext *context, int page) const;
174  void AddObject (Object* pObject);
180  void AddAtom (Atom* pAtom);
186  void AddFragment (Fragment* pFragment);
193  void AddBond (Bond* pBond);
199  void ParseXMLTree (xmlDocPtr xml);
204  void LoadObjects (xmlNodePtr node);
210  xmlDocPtr BuildXMLTree () const;
214  void Update ();
220  void Remove (Object* object);
226  void Remove (const char* Id);
230  void OnProperties ();
234  void OnUndo ();
238  void OnRedo ();
242  const GDate* GetCreationDate () {return &CreationDate;}
246  const GDate* GetRevisionDate () {return &RevisionDate;}
250  const gchar* GetAuthor () {return m_author;}
254  const gchar* GetMail () {return m_mail;}
258  const gchar* GetComment () {return m_comment;}
264  void SetAuthor (const gchar* author);
270  void SetMail (const gchar* mail);
276  void SetComment (const gchar* comment);
282  void FinishOperation ();
286  void AbortOperation ();
290  void PopOperation ();
297  void PushOperation (Operation* operation, bool undo = true);
302  void SetActive ();
312  Operation* GetCurrentOperation () {return m_pCurOp;}
318  void AddData (xmlNodePtr node);
322  bool CanUndo () {return m_UndoList.size() > 0;}
328  void SetEditable (bool editable) {m_bWriteable = editable; m_bUndoRedo = true;}
332  bool GetEditable () {return m_bWriteable;}
336  gcp::Application* GetApplication () {return m_pApp;}
346  void ExportImage (std::string const &filename, const char* type, int resolution = -1);
352  void SetReadOnly (bool ro);
356  bool GetReadOnly () {return m_bReadOnly;}
363  virtual double GetYAlign ();
367  Window *GetWindow () {return m_Window;}
371  GtkWindow *GetGtkWindow ();
378  void SetTheme (Theme *theme);
387  bool OnSignal (gcu::SignalId Signal, gcu::Object *Child);
393  void SetDirty (bool isDirty = true);
398  void OnThemeNamesChanged ();
404  double GetMedianBondLength ();
414  bool SetProperty (unsigned property, char const *value);
415 
424  std::string GetProperty (unsigned property) const;
425 
431  void SetLoading (bool loading) {m_bIsLoading = loading;}
439  void SaveResidue (Residue const *r, xmlNodePtr node);
449  gcu::Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
459  gcu::Residue *CreateResidue (char const *name, char const *symbol, gcu::Molecule *molecule);
460 
461 private:
462  void BuildBondList (std::list<Bond*>& BondList, gcu::Object const *obj) const;
463  void BuildAtomTable (std::map<std::string, unsigned>& AtomTable, gcu::Object const *obj, unsigned& index) const;
464  void RemoveAtom (Atom* pAtom);
465  void RemoveBond (Bond* pBond);
466  void RemoveFragment (Fragment* pFragment);
467 
468  //Implementation
469 private:
470  View * m_pView;
471  gchar* m_filename;
472  gchar *m_title;
473  gchar *m_label;
474  gchar *m_comment, *m_author, *m_mail;
475  bool m_bIsLoading, m_bUndoRedo, m_bReadOnly;
476  std::string m_FileType;
477  bool m_bWriteable;
478  GDate CreationDate, RevisionDate;
479  std::list<Operation*> m_UndoList, m_RedoList;
480  Operation* m_pCurOp;
481  Application* m_pApp;
482  Window *m_Window;
483  unsigned long m_OpID; // last operation ID
484  unsigned m_LastStackSize; // undo list size when last saved
485  std::set<Residue const *> m_SavedResidues;
486  std::map<std::string, gcu::SymbolResidue> m_Residues;
487 
488 /* Theme is not really a read only property, but we provide a special Set
489 method */
505 GCU_PROP (double, BondLength)
520 GCU_PROP (double, BondAngle)
532 GCU_PROP (double, ArrowLength)
544 GCU_PROP (gchar*, TextFontFamily)
556 GCU_PROP (PangoStyle, TextFontStyle)
568 GCU_PROP (PangoWeight, TextFontWeight)
580 GCU_PROP (PangoVariant, TextFontVariant)
592 GCU_PROP (PangoStretch, TextFontStretch)
604 GCU_PROP (gint, TextFontSize)
608 GCU_RO_PROP (PangoAttrList*, PangoAttrList)
620 GCU_PROP (bool, AllowClipboard)
629 GCU_RO_PROP (unsigned, SoftwareVersion)
630 };
631 
632 } // namespace gcp
633 
634 #endif // GCHEMPAINT_DOCUMENT_H