The Gnome Chemistry Utils  0.14.0
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 
134  void NotifyDirty (Object* pObject) {m_DirtyObjects.insert (pObject);}
139  virtual void Save () const {;}
150  virtual Residue *CreateResidue (char const *name, char const *symbol, Molecule *molecule);
160  virtual Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
166  virtual GtkWindow *GetGtkWindow () {return NULL;}
167 
181  bool SetTarget (char const *id, Object **target, Object *parent, Object *owner = NULL, Action action = ActionException) throw (std::runtime_error);
182 
187  virtual bool Loaded () throw (LoaderError);
191  std::string Name ();
192 
199  void ObjectLoaded (Object *obj);
200 
204  std::set < Object * > GetNewObjects () {return m_NewObjects;}
205 
210  virtual Window *GetWindow () {return NULL;}
211 
212 private:
213 
223  char* GetNewId (char const *id, bool Cache = true);
224 
225 private:
226  std::map <std::string, std::string> m_TranslationTable;//used when Ids translations are necessary (on pasting...)
227  std::map <std::string, std::list <PendingTarget> > m_PendingTable;//used to set pointers to objects when loading does not occur in the ideal order
228  std::set<Object*> m_NewObjects;
229 
230 protected:
234  std::string m_Title;
235 
239  std::set<Object*> m_DirtyObjects;
240 
255 GCU_PROT_PROP (bool, Empty);
267 GCU_PROP (double, Scale);
268 };
269 
270 
271 }
272 #endif //GCU_DOCUMENT_H