1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcr/line.h
6  *
7  * Copyright (C) 2002-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 GCR_LINE_H
26 #define GCR_LINE_H
27 
28 #include <gtk/gtk.h>
29 #include <libxml/parser.h>
30 #include <list>
31 
32 /*!\file*/
33 namespace gcr {
34 
35 /*!\enum LineType gcr/line.h
36 The type of a Line instance. Possible values are:
37 - edges: all the cell edges.
38 - diagonals: the lines joining opposite vertices of a cell.
39 - medians: the lines joining the centers of opposite faces of a cell.
40 - normal: a line with defined ends, repeated in each displayes cell.
41 - unique: a line with defined ends, not repeated.
42 */
43 enum LineType
44 {
45 	edges = 0,
46 	diagonals,
47 	medians,
48 	normal,
49 	unique
50 };
51 
52 /*!\class Line gcr/line.h
53 Describes lines represented as cylinders in the view. Thes cylinders are not capped.
54 */
55 class Line
56 {
57 public:
58 /*!
59 The default constructor of Line.
60 */
61 	Line ();
62 /*!
63 The destructior of CrystaLine
64 */
65 	virtual ~Line ();
66 
67 public :
68 /*!
69 @param Type: the type (LineType) of the new line.
70 @param X1: the x coordinate of the first end of the new line.
71 @param Y1: the y coordinate of the first end of the new line.
72 @param Z1: the z coordinate of the first end of the new line.
73 @param X2: the x coordinate of the second end of the new line.
74 @param Y2: the y coordinate of the second end of the new line.
75 @param Z2: the z coordinate of the second end of the new line.
76 @param r: the radius of the cylinder which will represent the new line.
77 @param red: the red component of the cylinder which will represent the new line.
78 @param green: the green component of the cylinder which will represent the new line.
79 @param blue: the blue component of the cylinder which will represent the new line.
80 @param alpha: the alpha component of the cylinder which will represent the new line.
81 
82 Constructs a new line from its characterisitics.
83 */
84 	Line (LineType Type, double X1, double Y1, double Z1, double X2, double Y2, double Z2, double r, float red, float green, float blue, float alpha);
85 /*!
86 @param clLine: the line to duplicate.
87 
88 Creates a new line with the same characteristics as clLine.
89 */
90 	Line (Line& clLine);
91 /*!
92 @param clLine: the line to copy.
93 
94 Copies a line.
95 @return the copied line.
96 */
97 	Line& operator= (Line& clLine);
98 
99 /*!
100 @return the x coordinate of the first end of the line.
101 */
X1(void)102 	double &X1 (void) {return m_dx;}
103 /*!
104 @return the y coordinate of the first end of the line.
105 */
Y1(void)106 	double &Y1 (void) {return m_dy;}
107 /*!
108 @return the z coordinate of the first end of the line.
109 */
Z1(void)110 	double &Z1 (void) {return m_dz;}
111 /*!
112 @return the x coordinate of the second end of the line.
113 */
X2(void)114 	double &X2 (void) {return m_dx2;}
115 /*!
116 @return the y coordinate of the second end of the line.
117 */
Y2(void)118 	double &Y2 (void) {return m_dy2;}
119 /*!
120 @return the z coordinate of the second end of the line.
121 */
Z2(void)122 	double &Z2 (void) {return m_dz2;}
123 /*!
124 @return the greatest x coordinate of the line.
125 */
126 	double Xmax ();
127 /*!
128 @return the greatest y coordinate of the line.
129 */
130 	double Ymax ();
131 /*!
132 @return the greatest z coordinate of the line.
133 */
134 	double Zmax ();
135 /*!
136 @return the lowest x coordinate of the line.
137 */
138 	double Xmin ();
139 /*!
140 @return the lowest y coordinate of the line.
141 */
142 	double Ymin ();
143 /*!
144 @return the lowest z coordinate of the line.
145 */
146 	double Zmin ();
147 /*!
148 @return the length of the line.
149 */
Long()150 	double Long () {return m_dl;}
151 /*!
152 @return the type of the line (see LineType).
153 */
Type()154 	LineType &Type () {return m_nType;}
155 /*!
156 @param x: the new x coordinate of the first end of the new line.
157 @param y: the new y coordinate of the first end of the new line.
158 @param z: the new z coordinate of the first end of the new line.
159 @param x1: the new x coordinate of the second end of the new line.
160 @param y1: the new y coordinate of the second end of the new line.
161 @param z1: the new z coordinate of the second end of the new line.
162 
163 Moves a line to a new position.
164 */
165 	void SetPosition (double x, double y, double z, double x1, double y1, double z1);
166 /*!
167 @param red: the red component of the new color of the line.
168 @param green: the green component of the new color of the line.
169 @param blue: the blue component of the new color of the line.
170 @param alpha: the alpha component of the new color of the line.
171 
172 Changes the color used to display the line.
173 */
174 	void SetColor (float red, float green, float blue, float alpha);
175 /*!
176 @param rgba: the new color of the line.
177 
178 Changes the color used to display the line.
179 */
180 	void SetColor (GdkRGBA rgba);
181 /*!
182 @param red: a pointer to the location to which the red component of the color of the line will be copied.
183 @param green: a pointer to the location to which the green component of the new color of the line will be copied.
184 @param blue: a pointer to the location to which the blue component of the new color of the line will be copied.
185 @param alpha: a pointer to the location to which the alpha component of the new color of the line will be copied.
186 
187 Gets the components of the color used to display the line.
188 */
189 	void GetColor (double *red, double *green, double *blue, double *alpha);
190 /*!
191 @param rgba: a pointer to the location to which the new color of the line will be copied.
192 
193 Gets the color used to display the line.
194 */
195 	void GetColor (GdkRGBA &rgba);
196 /*!
197 @param r: the new radius of the cylinder representing the line.
198 
199 Changes the radius of the cylinder used to represent the line.
200 */
201 	void SetRadius (double r);
202 /*!
203 @return the radius of the cylinder used to represent the line.
204 */
GetRadius()205 	double GetRadius () {return m_dr;};
206 /*!
207 @param clLine: a Line instance.
208 @return true if the two lines have the same type and the same position.
209 */
210 	bool operator== (Line& clLine);
211 /*!
212 @param x: the x component of the transation vector.
213 @param y: the y component of the transation vector.
214 @param z: the z component of the transation vector.
215 
216 Used to move a line.
217 */
218 	virtual void Move (double x, double y, double z);
219 /*!
220 @param h: the h Miller index of a plane.
221 @param k: the k Miller index of a plane.
222 @param l: the l Miller index of a plane.
223 
224 @return the product hx+ky+lz where x, y and z are the coordinates of one of the ends the line.
225 The end giving the largest value is retained for the calculus.
226 This makes sense only if coordinates are related to the net and are not the cartesian coordinates.
227 This method should not be called after NetToCartesian().
228 */
229 	double ScalProd (int h, int k, int l);
230 /*!
231 Method used to cleave a line. The inverse operation does not exist since the whole crystal must be recalculated
232 after a change in the definition.
233 */
Cleave()234 	void Cleave () {m_nCleave++;}
235 /*!
236 @param a: the a parameter of the unit cell.
237 @param b: the b parameter of the unit cell.
238 @param c: the c parameter of the unit cell.
239 @param alpha: the alpha angle of the unit cell.
240 @param beta: the beta angle of the unit cell.
241 @param gamma: the gamma angle of the unit cell.
242 
243 Converts the coordinates of the line from net related ones to cartesian. Initially, lines are defined by their
244 position relative to the unit cell and the coordinates must be transformed to the cartesian ones before
245 displaying the line.
246 */
247 	void NetToCartesian (double a, double b, double c, double alpha, double beta, double gamma);
248 /*!
249 @param x: the x coordinate of the center.
250 @param y: the y coordinate of the center.
251 @param z: the z coordinate of the center.
252 @param bFixed: tells if cleaved lines are taken into account.
253 
254 This helper method is called when searching for the size of the crystal. When some cleavages are defined,
255 the procedure cn take into account lines cleaved to get the same position in the view for the cleaved crystal
256 than for the whole crystal. If bFixed is true, all lines are taken into account.
257 
258 @return the largest distance of the line to the center of the view or 0 if bFixed is false and the line cleaved.
259 */
260 	double Distance (double x, double y, double z, bool bFixed);
261 /*!
262 @return true if the line is cleaved by at least one cleavage or false if the line is not cleaved at all.
263 */
IsCleaved()264 	bool IsCleaved () {return m_nCleave != 0;}
265 /*!
266 @param x: the x component of the vector of the rotation axis.
267 @param y: the y component of the vector of the rotation axis.
268 @param z: the z component of the vector of the rotation axis.
269 @param th: the angle of the rotation.
270 
271 This helper method is used to get the orientation of the line relative to the z axis. It is used when exporting to the
272 VRML format.
273 */
274 	void GetRotation (double& x, double& y, double& z, double& th);
275 /*!
276 @param xml: the xmlDoc used to save the document.
277 
278 Saves the line.
279 @return the xmlnode containing the description of the line.
280 */
281 	virtual xmlNodePtr Save (xmlDocPtr xml) const;
282 /*!
283 @param node: a pointer to the xmlNode containing the serialized line.
284 
285 Loads a line from the XML document.
286 */
287 	virtual bool Load (xmlNodePtr node);
288 
289 protected :
290 /*!
291 The blue component of the color of the cylinder representing the line.
292 */
293 	float m_fBlue;
294 /*!
295 The red component of the color of the cylinder representing the line.
296 */
297 	float m_fRed;
298 /*!
299 The green component of the color of the cylinder representing the line.
300 */
301 	float m_fGreen;
302 /*!
303 The alpha component of the color of the cylinder representing the line.
304 */
305 	float m_fAlpha;
306 /*!
307 The x coordinate of the first end of the line.
308 */
309 	double m_dx;
310 /*!
311 The y coordinate of the first end of the line.
312 */
313 	double m_dy;
314 /*!
315 The z coordinate of the first end of the line.
316 */
317 	double m_dz;
318 /*!
319 The x coordinate of the second end of the line.
320 */
321 	double m_dx2;
322 /*!
323 The x coordinate of the second end of the line.
324 */
325 	double m_dy2;
326 /*!
327 The x coordinate of the second end of the line.
328 */
329 	double m_dz2;
330 /*!
331 The radius of the cylinder representing the line.
332 */
333 	double m_dr;
334 /*!
335 When cleavages (see Cleavage class documentation) are defined, the line might be cleaved. m_nCleave is
336 the number of Cleavage instances which remove the line. If this member is not 0, the line will
337 not be displayed.
338 */
339 	int m_nCleave; //0 if not cleaved
340 /*!
341 The type of the Line instance. Possible values are:
342 - edges: all the cell edges.
343 - diagonals: the lines joining opposite vertices of a cell.
344 - medians: the lines joining the centers of opposite faces of a cell.
345 - normal: a line with defined ends, repeated in each displayes cell.
346 - unique: a line with defined ends, not repeated.
347 */
348 	LineType m_nType;
349 
350 private:
351 	double m_dl;
352 	double m_dxrot;
353 	double m_dyrot;
354 	double m_darot;//rotation axis coordinates (z = 0) and angle
355 };
356 
357 /*!
358 a list of pointers to Line instances derived from std::list.
359 */
360 typedef std::list<Line*> LineList;
361 
362 /*!
363 an array of the line types names used for serialization.
364 */
365 extern char const *LineTypeName[];
366 
367 }	//	namespace gcr
368 
369 #endif // GCR_BOND_H
370