1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcu/chem3ddoc.h
6  *
7  * Copyright (C) 2006-2012 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 #ifndef GCU_CHEM3D_DOCUMENT_H
26 #define GCU_CHEM3D_DOCUMENT_H
27 
28 #include <gcu/macros.h>
29 #include <gcu/gldocument.h>
30 #include <gcu/molecule.h>
31 
32 /*!\file*/
33 namespace gcu {
34 
35 /*! \enum Display3DMode
36  3D display mode.
37  Possible values are:
38 	 - BALL_AND_STICK: use ball and stick representation; atoms are represented by spheres with a radius equal to 20% of
39 	 their van der Waals radius and bonds are displayed as cylinders Multiple bonds are displayed as multiple cylinders.
40 	 - SPACEFILL: use space filling representation; atoms are represented by spheres with a radius equal
41 	 their van der Waals radius; bonds are not displayed.
42 	 - CYLINDERS: only bonds are represented as cylinders, atoms just end the cylinders.
43 	 - WIREFRAME: bonds are represented as narrow lines, atoms just end the lines.
44 */
45 typedef enum
46 {
47 	BALL_AND_STICK,
48 	SPACEFILL,
49 	CYLINDERS,
50 	WIREFRAME
51 } Display3DMode;
52 
53 class Application;
54 class Matrix;
55 
56 /*!
57 \class Chem3dDoc gcu/chem3ddoc.h
58 
59 Document base class for a molecule.
60 */
61 class Chem3dDoc: public GLDocument
62 {
63 public:
64 /*!
65 Default constructor
66 */
67 	Chem3dDoc ();
68 /*!
69 @param App the application.
70 @param View: an optional already existing GLView instance.
71 */
72 	Chem3dDoc (Application *App, GLView *View);
73 /*!
74 Default destructor
75 */
76 	virtual ~Chem3dDoc ();
77 
78 /*!
79 @param m the Matrix giving the current model orientation
80 
81 Displays the molecule using OpenGL.
82 */
83 	void Draw (Matrix const &m) const;
84 
85 /*!
86 @return true if the molecule have no atom, false otherwise.
87 */
IsEmpty()88 	bool IsEmpty () {return !m_Mol || m_Mol->GetAtomsNumber () == 0;}
89 
90 /*!
91 @param uri the uri of the molecule file.
92 @param mime_type the mime type of the molecule file.
93 
94 Loads a molecule from the provided uri.
95 */
96 	void Load (char const *uri, char const *mime_type);
97 
98 /*!
99 @param data the inline data.
100 @param mime_type the mime type of the data.
101 @param size the size of the data. If nul, the size will be evaluated from
102 the string length.
103 
104 Loads a molecule from the provided data.
105 */
106 	ContentType LoadData (char const *data, char const *mime_type, size_t size = 0);
107 
108 /*!
109 @param filename the name of the vrml file to which the data should be written.
110 
111 Exports the embedded molecule as a vrml scene.
112 */
113 	void OnExportVRML (std::string const &filename);
114 
115 /*!
116 Clears the document.
117 */
118 	void Clear ();
119 
120 /*!
121 	 Pure virtual method used to create a view. Must be overriden in derived classes.
122 
123 @return the newly created view.
124 */
125 	virtual GLView *CreateView () = 0;
126 
127 /*!
128 @param name the name of the display mode.
129 
130 Converts a string to an actual display mode. Supported names are: "ball&stick",
131 "spacefill", "cylinders", and "wireframe".
132 @return the display mode or BALL_AND_STICK on error.
133 
134 */
135 	static Display3DMode Display3DModeFromString (char const *name);
136 
137 /*!
138 @param mode a display mode.
139 
140 @return a string representation of the display mode.
141 */
142 	static char const *Display3DModeAsString (Display3DMode mode);
143 
144 /*!
145 @param property the property id as defined in objprops.h
146 @param value the property value as a string
147 
148 Used when loading to set properties to the document
149 @return true if the property could be set, or if the property is not relevant, false otherwise.
150 */
151 	bool SetProperty (unsigned property, char const *value);
152 
153 /*!\fn SetDisplay3D(Display3DMode mode)
154 @param mode: the new mode.
155 
156 Sets the display mode to one of the available Display3DMode values.
157 */
158 /*!\fn GetDisplay3D()
159 @return the current mode.
160 */
161 GCU_PROP_EX (Display3DMode, Display3D)
162 /*!\fn GetMol()
163 @return the molecule dispayed inside the document.
164 */
165 GCU_RO_PROP (Molecule *, Mol)
166 
167 private:
168 	/* cell parameters to support molecule loaded from a crystal structure */
169 	gdouble m_a, m_b, m_c, m_alpha, m_beta, m_gamma;
170 };
171 
172 }	// namespace gcu
173 
174 #endif	//	GCU_CHEM3D_DOCUMENT_H
175