The Gnome Chemistry Utils 0.13.3
gcu/document.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /* 
00004  * Gnome Chemistry Utils
00005  * gcu/document.h 
00006  *
00007  * Copyright (C) 2004-2011 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or 
00010  * modify it under the terms of the GNU General Public License as 
00011  * published by the Free Software Foundation; either version 2 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 
00026 #ifndef GCU_DOCUMENT_H
00027 #define GCU_DOCUMENT_H
00028 
00029 #include <gcu/object.h>
00030 #include <gcu/dialog-owner.h>
00031 #include <gcu/macros.h>
00032 #include <gcu/loader-error.h>
00033 #include <string>
00034 #include <set>
00035 
00037 namespace gcu
00038 {
00039 
00040 class Application;
00041 class Dialog;
00042 class Molecule;
00043 class Residue;
00044 
00045 typedef enum {
00046         ActionException,
00047         ActionDelete,
00048         ActionIgnore
00049 } Action;               
00050 
00051 class PendingTarget
00052 {
00053 public:
00054         Object *parent;
00055         Object *owner;
00056         Object **target;
00057         Action action;
00058 };
00059 
00063 class Document: public Object, virtual public DialogOwner
00064 {
00065 friend class Application;
00066 friend class Object;
00067 friend class Dialog;
00068 public:
00074         Document (Application *App = NULL);
00078         virtual ~Document ();
00079 
00080 public:
00081 
00089         std::string& GetTranslatedId (const char* id) {return m_TranslationTable[id];}
00090 
00097         void EraseTranslationId (const char* Id) {m_TranslationTable.erase (Id);}
00098 
00104         void EmptyTranslationTable() {m_TranslationTable.clear();}
00105 
00109         virtual void SetTitle (std::string& title) {m_Title = title;}
00113         virtual void SetTitle (char const *title) {m_Title = title;}
00117         std::string &GetTitle () {return m_Title;}
00118 
00125         void NotifyDirty (Object* pObject) {m_DirtyObjects.insert (pObject);}
00130         virtual void Save () const {;}
00141         virtual Residue *CreateResidue (char const *name, char const *symbol, Molecule *molecule);
00151         virtual Residue const *GetResidue (char const *symbol, bool *ambiguous = NULL);
00157         virtual GtkWindow *GetGtkWindow () {return NULL;}
00158 
00171         bool SetTarget (char const *id, Object **target, Object *parent, Object *owner = NULL, Action action = ActionException) throw (std::runtime_error);
00172 
00177         virtual bool Loaded () throw (LoaderError);
00181         std::string Name ();
00182 
00183         void ObjectLoaded (Object *obj);
00184         std::set < Object * > GetNewObjects () {return m_NewObjects;}
00185 
00186 private:
00187 
00197         char* GetNewId (char const *id, bool Cache = true);
00198 
00199 private:
00200         std::map <std::string, std::string> m_TranslationTable;//used when Ids translations are necessary (on pasting...)
00201         std::map <std::string, std::list <PendingTarget> > m_PendingTable;//used to set pointers to objects when loading does not occur in the ideal order
00202         std::set<Object*> m_NewObjects;
00203 
00204 protected:
00208         std::string m_Title;
00209 
00213         std::set<Object*> m_DirtyObjects;
00214 
00222 GCU_PROT_POINTER_PROP (Application, App)
00229 GCU_PROT_PROP (bool, Empty);
00241 GCU_PROP (double, Scale);
00242 };
00243 
00244 
00245 }
00246 #endif  //GCU_DOCUMENT_H