The Gnome Chemistry Utils  0.15.1
gcu/document.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcu/document.h
6  *
7  * Copyright (C) 2004-2011 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 
26 #ifndef GCU_DOCUMENT_H
27 #define GCU_DOCUMENT_H
28 
29 #include <gcu/object.h>
30 #include <gcu/dialog-owner.h>
31 #include <gcu/macros.h>
32 #include <gcu/loader-error.h>
33 #include <string>
34 #include <set>
35 
37 namespace gcu
38 {
39 
40 class Application;
41 class Dialog;
42 class Molecule;
43 class Residue;
44 class Window;
45 
49 typedef enum {
56 } Action;
57 
61 class Document: public Object, virtual public DialogOwner
62 {
63 friend class Application;
64 friend class Object;
65 friend class Dialog;
66 
67 private:
68 class PendingTarget
69 {
70 public:
71  Object *parent;
72  Object *owner;
73  Object **target;
74  Action action;
75 };
76 
77 public:
83  Document (Application *App = NULL);
87  virtual ~Document ();
88 
89 public:
90 
98  std::string& GetTranslatedId (const char* id);
99 
106  void EraseTranslationId (const char* Id) {m_TranslationTable.erase (Id);}
107 
113  void EmptyTranslationTable() {m_TranslationTable.clear();}
114 
118  virtual void SetTitle (std::string& title) {m_Title = title;}
122  virtual void SetTitle (char const *title) {m_Title = title;}
126  std::string &GetTitle () {return m_Title;}
127  std::string const &GetTitle () const {return m_Title;}
128 
132  virtual void SetComment (std::string& comment) {m_Comment = comment;}
136  virtual void SetComment (char const *comment) {m_Comment = comment;}
140  std::string &GetComment () {return m_Comment;}
141  std::string const &GetComment () const {return m_Comment;}
142 
149  void NotifyDirty (Object* pObject) {m_DirtyObjects.insert (pObject);}
154  virtual void Save () const {;}
165  virtual Residue *CreateResidue (char const *name, char const *symbol, Molecule *molecule);
175  virtual Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
181  virtual GtkWindow *GetGtkWindow () {return NULL;}
182 
196  bool SetTarget (char const *id, Object **target, Object *parent, Object *owner = NULL, Action action = ActionException) throw (std::runtime_error);
197 
202  virtual bool Loaded () throw (LoaderError);
206  std::string Name ();
207 
214  void ObjectLoaded (Object *obj);
215 
219  std::set < Object * > GetNewObjects () {return m_NewObjects;}
220 
225  virtual Window *GetWindow () {return NULL;}
226 
227 private:
228 
238  char* GetNewId (char const *id, bool Cache = true);
239 
240 private:
241  std::map <std::string, std::string> m_TranslationTable;//used when Ids translations are necessary (on pasting...)
242  std::map <std::string, std::list <PendingTarget> > m_PendingTable;//used to set pointers to objects when loading does not occur in the ideal order
243  std::set<Object*> m_NewObjects;
244 
245 protected:
249  std::string m_Title;
250 
254  std::string m_Comment;
255 
259  std::set<Object*> m_DirtyObjects;
260 
275 GCU_PROT_PROP (bool, Empty);
287 GCU_PROP (double, Scale);
288 };
289 
290 
291 }
292 #endif //GCU_DOCUMENT_H
void NotifyDirty(Object *pObject)
Definition: gcu/document.h:149
void EmptyTranslationTable()
Definition: gcu/document.h:113
virtual Residue * CreateResidue(char const *name, char const *symbol, Molecule *molecule)
std::string m_Comment
Definition: gcu/document.h:254
std::string Name()
virtual void Save() const
Definition: gcu/document.h:154
virtual void SetComment(char const *comment)
Definition: gcu/document.h:136
virtual void SetTitle(std::string &title)
Definition: gcu/document.h:118
virtual void SetComment(std::string &comment)
Definition: gcu/document.h:132
std::string m_Title
Definition: gcu/document.h:249
virtual bool Loaded()
void EraseTranslationId(const char *Id)
Definition: gcu/document.h:106
virtual void SetTitle(char const *title)
Definition: gcu/document.h:122
std::set< Object * > GetNewObjects()
Definition: gcu/document.h:219
void ObjectLoaded(Object *obj)
virtual Residue const * GetResidue(char const *symbol, bool *ambiguous=NULL)
std::string & GetTranslatedId(const char *id)
#define GCU_PROT_PROP(type, member)
Definition: macros.h:199
virtual Window * GetWindow()
Definition: gcu/document.h:225
std::set< Object * > m_DirtyObjects
Definition: gcu/document.h:259
#define GCU_PROT_POINTER_PROP(type, member)
Definition: macros.h:220
std::string & GetComment()
Definition: gcu/document.h:140
bool SetTarget(char const *id, Object **target, Object *parent, Object *owner=NULL, Action action=ActionException)
#define GCU_PROP(type, member)
Definition: macros.h:51
std::string & GetTitle()
Definition: gcu/document.h:126
Document(Application *App=NULL)
virtual GtkWindow * GetGtkWindow()
Definition: gcu/document.h:181
virtual ~Document()