The Gnome Chemistry Utils  0.13.7
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-2012 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 3 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 
00211         AtomList* GetAtomList () {return &AtomDef;}
00212 
00216         CleavageList *GetCleavageList () {return &Cleavages;}
00217 
00221         LineList* GetLineList () {return &LineDef;}
00222 
00234         void GetCell (Lattice *lattice, double *a, double *b, double *c, double *alpha, double *beta, double *gamma);
00235 
00247         void SetCell (Lattice lattice, double a, double b, double c, double alpha, double beta, double gamma);
00248 
00259         void GetSize (double* xmin, double* xmax, double* ymin, double* ymax, double* zmin, double* zmax);
00260 
00271         void SetSize (double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
00272 
00276         void CheckAtoms ();
00277 
00281         void CheckCleavages ();
00282 
00286         void CheckLines ();
00287 
00298         void Define (unsigned nPage = 0);
00299 
00305         void AddView(View* pView);
00306 
00313         bool RemoveView(View* pView);
00314 
00319         void RemoveAllViews ();
00320 
00324         View *GetActiveView () {return m_pActiveView;}
00325 
00329         std::list <gcr::View *> *GetViews () {return &m_Views;}
00330 
00334         void RenameViews ();
00335 
00342         bool VerifySaved();
00343 
00349         void SetWidget (GtkWidget* widget) {m_widget = widget;}
00350 
00354         const gchar* GetFileName () {return m_filename;}
00355 
00361         void SetActiveView (View *pView) {m_pActiveView = pView;}
00362 
00370         void SaveAsImage (const std::string &filename, char const *type, std::map<std::string, std::string>& options);
00371 
00377         void SetFileName (const std::string &filename);
00378 
00384         void SetTitle (char const *title);
00385         void SetTitle (std::string& title);
00386 
00390         char const *GetTitle () {return m_Title.c_str ();}
00391 
00397         void SetAuthor (char const *author);
00398 
00404         void SetMail (char const *mail);
00405 
00412         void SetComment (char const *comment);
00413 
00419         void SetLabel (char const *label);
00420 
00424         GDate *GetCreationDate () {return &m_CreationDate;}
00425 
00429         GDate *GetRevisionDate () {return &m_RevisionDate;}
00430 
00434         char const *GetLabel () {return m_Label? m_Label: m_DefaultLabel.c_str ();}
00435 
00441         void OnExportVRML (const std::string &FileName) const;
00442 
00446         void Save () const;
00447 
00448 protected:
00452         void Init ();
00458         virtual bool LoadNewView (xmlNodePtr node);
00459 
00460 private:
00461         void Duplicate (Atom& Atom);
00462         void Duplicate (Line& Line);
00463         void Error(int num) const;
00464 
00465 protected:
00469         Lattice m_lattice;
00473         gdouble m_a;
00477         gdouble m_b;
00481         gdouble m_c;
00485         gdouble m_alpha;
00489         gdouble m_beta;
00493         gdouble m_gamma;
00497         gdouble m_xmin;
00501         gdouble m_ymin;
00505         gdouble m_zmin;
00509         gdouble m_xmax;
00513         gdouble m_ymax;
00517         gdouble m_zmax;
00521         AtomList AtomDef;
00525         AtomList Atoms;
00529         LineList LineDef;
00533         LineList Lines;
00537         CleavageList Cleavages;
00541         std::list <View *> m_Views;
00542 
00546         GDate m_CreationDate;
00547 
00551         GDate m_RevisionDate;
00552 
00553 private:
00554         gchar *m_filename;
00555         bool m_bClosing;
00556         GtkWidget* m_widget;
00557         View *m_pActiveView;
00558         std::string m_DefaultLabel;
00559         char *m_Label;
00560 
00564 GCU_RO_PROP (std::string, NameCommon)
00568 GCU_RO_PROP (std::string, NameSystematic)
00572 GCU_RO_PROP (std::string, NameMineral)
00576 GCU_RO_PROP (std::string, NameStructure)
00587 GCU_PROP (gcu::SpaceGroup const *, SpaceGroup)
00600 GCU_PROP (bool, AutoSpaceGroup)
00601 
00614 GCU_PROP (bool, FixedSize);
00615 
00627 GCU_PROP (bool, ReadOnly)
00628 
00635 GCU_PROT_POINTER_PROP (char, Author)
00636 
00643 GCU_PROT_POINTER_PROP (char, Mail)
00644 
00651 GCU_PROT_POINTER_PROP (char, Comment)
00652 };
00653 
00657 extern gchar const *LatticeName[];
00658 
00659 } // namespace gcr
00660 
00661 #endif // GCR_DOCUMENT_H