The Gnome Chemistry Utils  0.13.6
gcr/document.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /*
00004  * Gnome Chemisty Utils
00005  * gcr/document.h
00006  *
00007  * Copyright (C) 2002-2010 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 #ifndef GCR_DOCUMENT_H
00026 #define GCR_DOCUMENT_H
00027 
00028 #include <libxml/tree.h>
00029 #include <glib.h>
00030 #include "atom.h"
00031 #include "bond.h"
00032 #include "line.h"
00033 #include "cleavage.h"
00034 #include <gcu/chemistry.h>
00035 #include <gcu/macros.h>
00036 #include <gcu/gldocument.h>
00037 
00038 namespace gcu {
00039 class Application;
00040 class Matrix;
00041 class SpaceGroup;
00042 }
00043 
00045 namespace gcr {
00046 
00047 class View;
00048 
00068 enum Lattice {
00069         cubic=0,
00070         body_centered_cubic,
00071         face_centered_cubic,
00072         hexagonal,
00073         tetragonal,
00074         body_centered_tetragonal,
00075         orthorhombic,
00076         base_centered_orthorhombic,
00077         body_centered_orthorhombic,
00078         face_centered_orthorhombic,
00079         rhombohedral,
00080         monoclinic,
00081         base_centered_monoclinic,
00082         triclinic
00083 };
00084 
00088 class Document: public gcu::GLDocument
00089 {
00090 public:
00094         Document (gcu::Application *App);
00098         virtual ~Document ();
00099 
00100         bool Load (const std::string &filename);
00101 
00112         void ParseXMLTree (xmlNode* xml);
00117         void Update ();
00118 
00119         void UpdateAllViews ();
00120 
00124         View* GetView ();
00125 
00131         void Draw (gcu::Matrix const &m) const;
00132 
00139         virtual View* CreateNewView ();
00146         virtual Atom* CreateNewAtom ();
00153         virtual Line* CreateNewLine ();
00159         virtual Cleavage* CreateNewCleavage ();
00164         xmlDocPtr BuildXMLTree () const;
00170         virtual const char* GetProgramId () const;
00171 
00179         bool SetProperty (unsigned property, char const *value);
00180 
00187         std::string GetProperty (unsigned property) const;
00188 
00193         bool Loaded () throw (gcu::LoaderError);
00197         void AddChild (Object* object);
00202         gcu::SpaceGroup const *FindSpaceGroup ();
00206         void Reinit ();
00207         AtomList* GetAtomList () {return &AtomDef;}
00208         CleavageList *GetCleavageList () {return &Cleavages;}
00209         LineList* GetLineList () {return &LineDef;}
00210         void GetCell (Lattice *lattice, double *a, double *b, double *c, double *alpha, double *beta, double *gamma);
00211         void SetCell (Lattice lattice, double a, double b, double c, double alpha, double beta, double gamma);
00212         void GetSize (double* xmin, double* xmax, double* ymin, double* ymax, double* zmin, double* zmax);
00213         void SetSize (double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
00214         void CheckAtoms ();
00215         void CheckCleavages ();
00216         void CheckLines ();
00217         void Define (unsigned nPage = 0);
00218         void AddView(View* pView);
00219         bool RemoveView(View* pView);
00220         void RemoveAllViews ();
00221         View *GetActiveView () {return m_pActiveView;}
00222         std::list <gcr::View *> *GetViews () {return &m_Views;}
00223         void RenameViews ();
00224         bool VerifySaved();
00225         void SetWidget (GtkWidget* widget) {m_widget = widget;}
00226         const gchar* GetFileName () {return m_filename;}
00227         void SetActiveView (View *pView) {m_pActiveView = pView;}
00228         void SaveAsImage (const std::string &filename, char const *type, std::map<std::string, std::string>& options);
00229         void SetFileName (const std::string &filename);
00230         void SetTitle (char const *title);
00231         void SetTitle (std::string& title);
00232         char const *GetTitle () {return m_Title.c_str ();}
00233         void SetAuthor (char const *author);
00234         void SetMail (char const *mail);
00235         void SetComment (char const *comment);
00236         void SetLabel (char const *label);
00237         GDate *GetCreationDate () {return &m_CreationDate;}
00238         GDate *GetRevisionDate () {return &m_RevisionDate;}
00239         char const *GetLabel () {return m_Label? m_Label: m_DefaultLabel.c_str ();}
00240         void OnExportVRML (const std::string &FileName) const;
00241         void Save () const;
00242 
00243 protected:
00247         void Init ();
00253         virtual bool LoadNewView (xmlNodePtr node);
00254 
00255 private:
00256         void Duplicate (Atom& Atom);
00257         void Duplicate (Line& Line);
00258         void Error(int num) const;
00259 
00260 protected:
00264         Lattice m_lattice;
00268         gdouble m_a;
00272         gdouble m_b;
00276         gdouble m_c;
00280         gdouble m_alpha;
00284         gdouble m_beta;
00288         gdouble m_gamma;
00292         gdouble m_xmin;
00296         gdouble m_ymin;
00300         gdouble m_zmin;
00304         gdouble m_xmax;
00308         gdouble m_ymax;
00312         gdouble m_zmax;
00316         AtomList AtomDef;
00320         AtomList Atoms;
00324         LineList LineDef;
00328         LineList Lines;
00332         CleavageList Cleavages;
00336         std::list <View *> m_Views;
00337 
00338         GDate m_CreationDate, m_RevisionDate;
00339 
00340 private:
00341         gchar *m_filename;
00342         bool m_bClosing;
00343         GtkWidget* m_widget;
00344         View *m_pActiveView;
00345         std::string m_DefaultLabel;
00346         char *m_Label;
00347 
00351 GCU_RO_PROP (std::string, NameCommon)
00355 GCU_RO_PROP (std::string, NameSystematic)
00359 GCU_RO_PROP (std::string, NameMineral)
00363 GCU_RO_PROP (std::string, NameStructure)
00374 GCU_PROP (gcu::SpaceGroup const *, SpaceGroup)
00387 GCU_PROP (bool, AutoSpaceGroup)
00388 
00392 GCU_PROP (bool, FixedSize);
00393 
00394 GCU_PROP (bool, ReadOnly)
00395 GCU_PROT_POINTER_PROP (char, Author)
00396 GCU_PROT_POINTER_PROP (char, Mail)
00397 GCU_PROT_POINTER_PROP (char, Comment)
00398 };
00399 
00403 extern gchar const *LatticeName[];
00404 
00405 } // namespace gcr
00406 
00407 #endif // GCR_DOCUMENT_H