1 /*   EXTRAITS DE LA LICENCE
2 	Copyright CEA, contributeurs : Luc BILLARD et Damien
3 	CALISTE, laboratoire L_Sim, (2001-2005)
4 
5 	Adresse mèl :
6 	BILLARD, non joignable par mèl ;
7 	CALISTE, damien P caliste AT cea P fr.
8 
9 	Ce logiciel est un programme informatique servant à visualiser des
10 	structures atomiques dans un rendu pseudo-3D.
11 
12 	Ce logiciel est régi par la licence CeCILL soumise au droit français et
13 	respectant les principes de diffusion des logiciels libres. Vous pouvez
14 	utiliser, modifier et/ou redistribuer ce programme sous les conditions
15 	de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
16 	sur le site "http://www.cecill.info".
17 
18 	Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
19 	pris connaissance de la licence CeCILL, et que vous en avez accepté les
20 	termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
21 */
22 
23 /*   LICENCE SUM UP
24 	Copyright CEA, contributors : Luc BILLARD et Damien
25 	CALISTE, laboratoire L_Sim, (2001-2005)
26 
27 	E-mail address:
28 	BILLARD, not reachable any more ;
29 	CALISTE, damien P caliste AT cea P fr.
30 
31 	This software is a computer program whose purpose is to visualize atomic
32 	configurations in 3D.
33 
34 	This software is governed by the CeCILL  license under French law and
35 	abiding by the rules of distribution of free software.  You can  use,
36 	modify and/ or redistribute the software under the terms of the CeCILL
37 	license as circulated by CEA, CNRS and INRIA at the following URL
38 	"http://www.cecill.info".
39 
40 	The fact that you are presently reading this means that you have had
41 	knowledge of the CeCILL license and that you accept its terms. You can
42 	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
43 */
44 #include "axes.h"
45 
46 #include <GL/gl.h>
47 #include <GL/glu.h>
48 
49 #include <math.h>
50 #include <string.h>
51 
52 #include <opengl.h>
53 #include <openGLFunctions/text.h>
54 #include <visu_tools.h>
55 #include <visu_configFile.h>
56 #include <openGLFunctions/objectList.h>
57 #include <coreTools/toolColor.h>
58 
59 #undef near
60 #undef far
61 
62 /**
63  * SECTION:axes
64  * @short_description: Defines methods to draw axes.
65  *
66  * <para>The axes are the X, Y and Z lines drawn on the bottom right of the
67  * screen defining a given orthogonal basis set in which the box is
68  * projected.</para>
69  * <para>The axis may be different, depending on the rendering method
70  * currently used. For instance, when the spin is used, a projection
71  * of the colour scheme is added to the simple lines of the basis
72  * set. Besides that, axes are defined by their width (see
73  * visu_gl_ext_lined_setWidth()) and their colour (see
74  * visu_gl_ext_lined_setRGBA()).</para>
75  */
76 
77 /* Parameters & resources*/
78 /* This is a boolean to control is the axes is render or not. */
79 #define FLAG_RESOURCE_AXES_USED   "axes_are_on"
80 #define DESC_RESOURCE_AXES_USED   "Control if the axes are drawn ; boolean (0 or 1)"
81 static gboolean RESOURCE_AXES_USED_DEFAULT = FALSE;
82 /* A resource to control the color used to render the lines of the axes. */
83 #define FLAG_RESOURCE_AXES_COLOR   "axes_color"
84 #define DESC_RESOURCE_AXES_COLOR   "Define the color of the axes ; three floating point values (0. <= v <= 1.)"
85 static float rgbDefault[4] = {1.0, 0.5, 0.1, 1.};
86 /* A resource to control the width to render the lines of the axes. */
87 #define FLAG_RESOURCE_AXES_LINE   "axes_line_width"
88 #define DESC_RESOURCE_AXES_LINE   "Define the width of the lines of the axes ; one floating point values (1. <= v <= 10.)"
89 static float LINE_WIDTH_DEFAULT = 1.f;
90 /* A resource to control the stipple to render the lines of the axes. */
91 #define FLAG_RESOURCE_AXES_STIPPLE   "axes_line_stipple"
92 #define DESC_RESOURCE_AXES_STIPPLE   "Dot scheme detail for the lines of the axes ; 0 < integer < 2^16"
93 static guint16 LINE_STIPPLE_DEFAULT = 65535;
94 /* A resource to control the position to render the axes. */
95 #define FLAG_RESOURCE_AXES_POSITION   "axes_position"
96 #define DESC_RESOURCE_AXES_POSITION   "Position of the representation of the axes ; two floating point values (0. <= v <= 1.)"
97 static float POSITION_DEFAULT[2] = {1.f, 1.f};
98 
99 #define FLAG_RESOURCE_AXES_LABEL_X    "axes_label_x"
100 #define FLAG_RESOURCE_AXES_LABEL_Y    "axes_label_y"
101 #define FLAG_RESOURCE_AXES_LABEL_Z    "axes_label_z"
102 #define DESC_RESOURCE_AXES_LABEL      "Label to be drawn beside each axis ; string"
103 static gchar *LABEL_DEFAULT[3] = {NULL, NULL, NULL};
104 
105 #define FLAG_RESOURCE_AXES_FACTOR   "axes_size"
106 #define DESC_RESOURCE_AXES_FACTOR   "Portion of the screen used to draw the axis ; one floating point value (0. <= v <= 1.)"
107 static float SIZE_DEFAULT = .16f;
108 
109 /* Export function that is called by visu_module to write the
110    values of resources to a file. */
111 static void exportResources(GString *data, VisuData *dataObj);
112 
113 struct _VisuGlExtAxesPrivate
114 {
115   gboolean dispose_has_run;
116 
117   /* Basis definition. */
118   double matrix[3][3];
119   VisuBox *box;
120   gulong box_signal;
121 
122   /* Rendenring parameters. */
123   float xpos, ypos;
124   float lgFact;
125   float rgb[4];
126   float lineWidth;
127   guint16 lineStipple;
128   gchar *lbl[3];
129   gboolean displayOrientation;
130   float orientation[3];
131 
132   /* Signals for the current view. */
133   VisuGlView *view;
134   gulong widthHeight_signal, persp_signal, refLength_signal, color_signal;
135 };
136 
137 enum
138   {
139     PROP_0,
140     XPOS_PROP,
141     YPOS_PROP,
142     SIZE_PROP,
143     COLOR_PROP,
144     WIDTH_PROP,
145     STIPPLE_PROP,
146     VIEW_PROP,
147     BOX_PROP,
148     LBLX_PROP,
149     LBLY_PROP,
150     LBLZ_PROP,
151     USE_ORIENTATION_PROP,
152     CONE_THETA_PROP,
153     CONE_PHI_PROP,
154     CONE_OMEGA_PROP,
155     N_PROP
156   };
157 static GParamSpec *properties[N_PROP];
158 
159 static VisuGlExtAxes* defaultAxes;
160 
161 static void visu_gl_ext_lined_interface_init(VisuGlExtLinedInterface *iface);
162 static void visu_gl_ext_axes_finalize(GObject* obj);
163 static void visu_gl_ext_axes_dispose(GObject* obj);
164 static void visu_gl_ext_axes_get_property(GObject* obj, guint property_id,
165                                           GValue *value, GParamSpec *pspec);
166 static void visu_gl_ext_axes_set_property(GObject* obj, guint property_id,
167                                           const GValue *value, GParamSpec *pspec);
168 static void visu_gl_ext_axes_rebuild(VisuGlExt *ext);
169 static void visu_gl_ext_axes_draw(VisuGlExt *ext);
170 static gboolean visu_gl_ext_axes_setGlView(VisuGlExt *axes, VisuGlView *view);
171 static void _setBox(VisuGlExtAxes *axes, VisuBox *box);
172 
173 static gboolean _setRGB(VisuGlExtLined *axes, float rgb[4], int mask);
174 static gboolean _setLineWidth(VisuGlExtLined *axes, float width);
175 static gboolean _setLineStipple(VisuGlExtLined *axes, guint16 stipple);
176 static float*   _getRGB(const VisuGlExtLined *axes);
177 static float    _getLineWidth(const VisuGlExtLined *axes);
178 static guint16  _getLineStipple(const VisuGlExtLined *axes);
179 
180 /* Local callbacks */
181 static void onAxesParametersChange(VisuGlExtAxes *axes);
182 static void onBoxChange(VisuBox *box, float extens, gpointer data);
183 static void onEntryUsed(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
184 static void onEntryColor(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
185 static void onEntryWidth(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
186 static void onEntryStipple(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
187 static void onEntryPosition(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
188 static void onEntryLabel(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
189 static void onEntryFactor(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj);
190 
G_DEFINE_TYPE_WITH_CODE(VisuGlExtAxes,visu_gl_ext_axes,VISU_TYPE_GL_EXT,G_ADD_PRIVATE (VisuGlExtAxes)G_IMPLEMENT_INTERFACE (VISU_TYPE_GL_EXT_LINED,visu_gl_ext_lined_interface_init))191 G_DEFINE_TYPE_WITH_CODE(VisuGlExtAxes, visu_gl_ext_axes, VISU_TYPE_GL_EXT,
192                         G_ADD_PRIVATE(VisuGlExtAxes)
193                         G_IMPLEMENT_INTERFACE(VISU_TYPE_GL_EXT_LINED,
194                                               visu_gl_ext_lined_interface_init))
195 
196 static void visu_gl_ext_lined_interface_init(VisuGlExtLinedInterface *iface)
197 {
198   iface->get_width   = _getLineWidth;
199   iface->set_width   = _setLineWidth;
200   iface->get_stipple = _getLineStipple;
201   iface->set_stipple = _setLineStipple;
202   iface->get_rgba    = _getRGB;
203   iface->set_rgba    = _setRGB;
204 }
visu_gl_ext_axes_class_init(VisuGlExtAxesClass * klass)205 static void visu_gl_ext_axes_class_init(VisuGlExtAxesClass *klass)
206 {
207   float rgColor[2] = {0.f, 1.f};
208   float rgWidth[2] = {0.f, 10.f};
209   float rgFactor[2] = {0.f, 1.f};
210   VisuConfigFileEntry *resourceEntry;
211 
212   DBG_fprintf(stderr, "Extension Axes: creating the class of the object.\n");
213   /* DBG_fprintf(stderr, "                - adding new signals ;\n"); */
214   LABEL_DEFAULT[TOOL_XYZ_X] = g_strdup("x");
215   LABEL_DEFAULT[TOOL_XYZ_Y] = g_strdup("y");
216   LABEL_DEFAULT[TOOL_XYZ_Z] = g_strdup("z");
217 
218   DBG_fprintf(stderr, "                - adding new resources ;\n");
219   resourceEntry = visu_config_file_addBooleanEntry(VISU_CONFIG_FILE_RESOURCE,
220                                                    FLAG_RESOURCE_AXES_USED,
221                                                    DESC_RESOURCE_AXES_USED,
222                                                    &RESOURCE_AXES_USED_DEFAULT, FALSE);
223   resourceEntry = visu_config_file_addFloatArrayEntry(VISU_CONFIG_FILE_RESOURCE,
224                                                       FLAG_RESOURCE_AXES_COLOR,
225                                                       DESC_RESOURCE_AXES_COLOR,
226                                                       3, rgbDefault, rgColor, FALSE);
227   resourceEntry = visu_config_file_addFloatArrayEntry(VISU_CONFIG_FILE_RESOURCE,
228                                                       FLAG_RESOURCE_AXES_LINE,
229                                                       DESC_RESOURCE_AXES_LINE,
230                                                       1, &LINE_WIDTH_DEFAULT, rgWidth, FALSE);
231   resourceEntry = visu_config_file_addStippleArrayEntry(VISU_CONFIG_FILE_RESOURCE,
232                                                         FLAG_RESOURCE_AXES_STIPPLE,
233                                                         DESC_RESOURCE_AXES_STIPPLE,
234                                                         1, &LINE_STIPPLE_DEFAULT);
235   visu_config_file_entry_setVersion(resourceEntry, 3.4f);
236   resourceEntry = visu_config_file_addFloatArrayEntry(VISU_CONFIG_FILE_RESOURCE,
237                                                       FLAG_RESOURCE_AXES_POSITION,
238                                                       DESC_RESOURCE_AXES_POSITION,
239                                                       2, POSITION_DEFAULT, rgColor, FALSE);
240   visu_config_file_entry_setVersion(resourceEntry, 3.7f);
241   resourceEntry = visu_config_file_addStringEntry(VISU_CONFIG_FILE_RESOURCE,
242                                                   FLAG_RESOURCE_AXES_LABEL_X,
243                                                   DESC_RESOURCE_AXES_LABEL,
244                                                   LABEL_DEFAULT + TOOL_XYZ_X);
245   visu_config_file_entry_setVersion(resourceEntry, 3.8f);
246   resourceEntry = visu_config_file_addStringEntry(VISU_CONFIG_FILE_RESOURCE,
247                                                   FLAG_RESOURCE_AXES_LABEL_Y,
248                                                   DESC_RESOURCE_AXES_LABEL,
249                                                   LABEL_DEFAULT + TOOL_XYZ_Y);
250   visu_config_file_entry_setVersion(resourceEntry, 3.8f);
251   resourceEntry = visu_config_file_addStringEntry(VISU_CONFIG_FILE_RESOURCE,
252                                                   FLAG_RESOURCE_AXES_LABEL_Z,
253                                                   DESC_RESOURCE_AXES_LABEL,
254                                                   LABEL_DEFAULT + TOOL_XYZ_Z);
255   visu_config_file_entry_setVersion(resourceEntry, 3.8f);
256   resourceEntry = visu_config_file_addFloatArrayEntry(VISU_CONFIG_FILE_RESOURCE,
257                                                       FLAG_RESOURCE_AXES_FACTOR,
258                                                       DESC_RESOURCE_AXES_FACTOR,
259                                                       1, &SIZE_DEFAULT, rgFactor, FALSE);
260   visu_config_file_entry_setVersion(resourceEntry, 3.8f);
261   visu_config_file_addExportFunction(VISU_CONFIG_FILE_RESOURCE, exportResources);
262 
263   defaultAxes = (VisuGlExtAxes*)0;
264 
265   /* Connect the overloading methods. */
266   G_OBJECT_CLASS(klass)->dispose  = visu_gl_ext_axes_dispose;
267   G_OBJECT_CLASS(klass)->finalize = visu_gl_ext_axes_finalize;
268   G_OBJECT_CLASS(klass)->set_property = visu_gl_ext_axes_set_property;
269   G_OBJECT_CLASS(klass)->get_property = visu_gl_ext_axes_get_property;
270   VISU_GL_EXT_CLASS(klass)->rebuild = visu_gl_ext_axes_rebuild;
271   VISU_GL_EXT_CLASS(klass)->draw = visu_gl_ext_axes_draw;
272   VISU_GL_EXT_CLASS(klass)->setGlView = visu_gl_ext_axes_setGlView;
273 
274   /**
275    * VisuGlExtAxes::x-pos:
276    *
277    * Store the position along x of the axes.
278    *
279    * Since: 3.8
280    */
281   properties[XPOS_PROP] = g_param_spec_float("x-pos", "x position",
282                                              "position along x axis",
283                                              0., 1., POSITION_DEFAULT[0],
284                                              G_PARAM_READWRITE);
285   g_object_class_install_property(G_OBJECT_CLASS(klass), XPOS_PROP,
286 				  properties[XPOS_PROP]);
287   /**
288    * VisuGlExtAxes::y-pos:
289    *
290    * Store the position along y of the axes.
291    *
292    * Since: 3.8
293    */
294   properties[YPOS_PROP] = g_param_spec_float("y-pos", "y position",
295                                              "position along y axis",
296                                              0., 1., POSITION_DEFAULT[1],
297                                              G_PARAM_READWRITE);
298   g_object_class_install_property(G_OBJECT_CLASS(klass), YPOS_PROP,
299 				  properties[YPOS_PROP]);
300   /**
301    * VisuGlExtAxes::size:
302    *
303    * Store the portion of screen the axis occupy.
304    *
305    * Since: 3.8
306    */
307   properties[SIZE_PROP] = g_param_spec_float("size", "Size",
308                                                "portion of the screen for the axis",
309                                                0., 1., .16f, G_PARAM_READWRITE);
310   g_object_class_install_property(G_OBJECT_CLASS(klass), SIZE_PROP,
311 				  properties[SIZE_PROP]);
312   g_object_class_override_property(G_OBJECT_CLASS(klass), COLOR_PROP, "color");
313   g_object_class_override_property(G_OBJECT_CLASS(klass), WIDTH_PROP, "width");
314   g_object_class_override_property(G_OBJECT_CLASS(klass), STIPPLE_PROP, "stipple");
315   /**
316    * VisuGlExtAxes::view:
317    *
318    * Store the view where the axes are rendered.
319    *
320    * Since: 3.8
321    */
322   properties[VIEW_PROP] = g_param_spec_object("view", "OpenGl View",
323                                               "rendering view for the axes",
324                                               VISU_TYPE_GL_VIEW, G_PARAM_READWRITE);
325   g_object_class_install_property(G_OBJECT_CLASS(klass), VIEW_PROP,
326 				  properties[VIEW_PROP]);
327   /**
328    * VisuGlExtAxes::basis:
329    *
330    * Store the #VisuBoxed object that defines the axes. If %NULL, a
331    * cartesian basis-set is assumed.
332    *
333    * Since: 3.8
334    */
335   properties[BOX_PROP] = g_param_spec_object("basis", "basis-set",
336                                              "provides the basis-set to draw the axes",
337                                              VISU_TYPE_BOX, G_PARAM_READWRITE);
338   g_object_class_install_property(G_OBJECT_CLASS(klass), BOX_PROP,
339 				  properties[BOX_PROP]);
340   /**
341    * VisuGlExtAxes::x-label:
342    *
343    * Store the label for x axis.
344    *
345    * Since: 3.8
346    */
347   properties[LBLX_PROP] = g_param_spec_string("x-label", "X label", "label for the x axis",
348                                              "x", G_PARAM_READWRITE);
349   g_object_class_install_property(G_OBJECT_CLASS(klass), LBLX_PROP,
350 				  properties[LBLX_PROP]);
351   /**
352    * VisuGlExtAxes::y-label:
353    *
354    * Store the label for y axis.
355    *
356    * Since: 3.8
357    */
358   properties[LBLY_PROP] = g_param_spec_string("y-label", "Y label", "label for the y axis",
359                                              "y", G_PARAM_READWRITE);
360   g_object_class_install_property(G_OBJECT_CLASS(klass), LBLY_PROP,
361 				  properties[LBLY_PROP]);
362   /**
363    * VisuGlExtAxes::z-label:
364    *
365    * Store the label for z axis.
366    *
367    * Since: 3.8
368    */
369   properties[LBLZ_PROP] = g_param_spec_string("z-label", "Z label", "label for the z axis",
370                                              "z", G_PARAM_READWRITE);
371   g_object_class_install_property(G_OBJECT_CLASS(klass), LBLZ_PROP,
372 				  properties[LBLZ_PROP]);
373   /**
374    * VisuGlExtAxes::display-orienation:
375    *
376    * If TRUE, it draws a coloured cone to display orientation information.
377    *
378    * Since: 3.8
379    */
380   properties[USE_ORIENTATION_PROP] = g_param_spec_boolean("display-orientation",
381                                                           "Display orientation",
382                                                           "display orientation information",
383                                                           FALSE, G_PARAM_READWRITE);
384   g_object_class_install_property(G_OBJECT_CLASS(klass), USE_ORIENTATION_PROP,
385 				  properties[USE_ORIENTATION_PROP]);
386   /**
387    * VisuGlExtAxes::orientation-theta:
388    *
389    * Store the theta angle used to defined the coloured cone position
390    * when axis are used to display a coloured orientation.
391    *
392    * Since: 3.8
393    */
394   properties[CONE_THETA_PROP] = g_param_spec_float("orientation-theta",
395                                                    "Theta angle in degrees",
396                                                    "theta defining top",
397                                                    0., 180., 0.f, G_PARAM_READWRITE);
398   g_object_class_install_property(G_OBJECT_CLASS(klass), CONE_THETA_PROP,
399 				  properties[CONE_THETA_PROP]);
400   /**
401    * VisuGlExtAxes::orientation-phi:
402    *
403    * Store the phi angle used to defined the coloured cone position
404    * when axis are used to display a coloured orientation.
405    *
406    * Since: 3.8
407    */
408   properties[CONE_PHI_PROP] = g_param_spec_float("orientation-phi",
409                                                    "Phi angle in degrees",
410                                                    "phi defining top",
411                                                    0., 360., 0.f, G_PARAM_READWRITE);
412   g_object_class_install_property(G_OBJECT_CLASS(klass), CONE_PHI_PROP,
413 				  properties[CONE_PHI_PROP]);
414   /**
415    * VisuGlExtAxes::orientation-omega:
416    *
417    * Store the omega angle used to defined the coloured cone position
418    * when axis are used to display a coloured orientation.
419    *
420    * Since: 3.8
421    */
422   properties[CONE_OMEGA_PROP] = g_param_spec_float("orientation-omega",
423                                                    "Omega angle in degrees",
424                                                    "omega defining top",
425                                                    0., 360., 0.f, G_PARAM_READWRITE);
426   g_object_class_install_property(G_OBJECT_CLASS(klass), CONE_OMEGA_PROP,
427 				  properties[CONE_OMEGA_PROP]);
428 }
429 
visu_gl_ext_axes_init(VisuGlExtAxes * obj)430 static void visu_gl_ext_axes_init(VisuGlExtAxes *obj)
431 {
432   DBG_fprintf(stderr, "Extension Axes: initializing a new object (%p).\n",
433 	      (gpointer)obj);
434 
435   obj->priv = visu_gl_ext_axes_get_instance_private(obj);
436   obj->priv->dispose_has_run = FALSE;
437 
438   /* Private data. */
439   obj->priv->rgb[0]      = rgbDefault[0];
440   obj->priv->rgb[1]      = rgbDefault[1];
441   obj->priv->rgb[2]      = rgbDefault[2];
442   obj->priv->rgb[3]      = 1.f;
443   obj->priv->lgFact      = SIZE_DEFAULT;
444   obj->priv->lineWidth   = LINE_WIDTH_DEFAULT;
445   obj->priv->lineStipple = LINE_STIPPLE_DEFAULT;
446   obj->priv->xpos        = POSITION_DEFAULT[0];
447   obj->priv->ypos        = POSITION_DEFAULT[1];
448   obj->priv->view               = (VisuGlView*)0;
449   obj->priv->widthHeight_signal = 0;
450   obj->priv->persp_signal     = 0;
451   obj->priv->refLength_signal   = 0;
452   obj->priv->color_signal       = 0;
453   obj->priv->matrix[0][0] = 1.;
454   obj->priv->matrix[0][1] = 0.;
455   obj->priv->matrix[0][2] = 0.;
456   obj->priv->matrix[1][0] = 0.;
457   obj->priv->matrix[1][1] = 1.;
458   obj->priv->matrix[1][2] = 0.;
459   obj->priv->matrix[2][0] = 0.;
460   obj->priv->matrix[2][1] = 0.;
461   obj->priv->matrix[2][2] = 1.;
462   obj->priv->box          = (VisuBox*)0;
463   obj->priv->box_signal   = 0;
464   obj->priv->lbl[0]       = g_strdup(LABEL_DEFAULT[TOOL_XYZ_X]);
465   obj->priv->lbl[1]       = g_strdup(LABEL_DEFAULT[TOOL_XYZ_Y]);
466   obj->priv->lbl[2]       = g_strdup(LABEL_DEFAULT[TOOL_XYZ_Z]);
467   obj->priv->displayOrientation = FALSE;
468   obj->priv->orientation[0] = 0.f;
469   obj->priv->orientation[1] = 0.f;
470   obj->priv->orientation[2] = 0.f;
471 
472   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_USED,
473                           G_CALLBACK(onEntryUsed), (gpointer)obj, G_CONNECT_SWAPPED);
474   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_COLOR,
475                           G_CALLBACK(onEntryColor), (gpointer)obj, G_CONNECT_SWAPPED);
476   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_LINE,
477                           G_CALLBACK(onEntryWidth), (gpointer)obj, G_CONNECT_SWAPPED);
478   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_STIPPLE,
479                           G_CALLBACK(onEntryStipple), (gpointer)obj, G_CONNECT_SWAPPED);
480   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_POSITION,
481                           G_CALLBACK(onEntryPosition), (gpointer)obj, G_CONNECT_SWAPPED);
482   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_LABEL_X,
483                           G_CALLBACK(onEntryLabel), (gpointer)obj, G_CONNECT_SWAPPED);
484   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_LABEL_Y,
485                           G_CALLBACK(onEntryLabel), (gpointer)obj, G_CONNECT_SWAPPED);
486   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_LABEL_Z,
487                           G_CALLBACK(onEntryLabel), (gpointer)obj, G_CONNECT_SWAPPED);
488 
489   g_signal_connect_object(VISU_CONFIG_FILE_RESOURCE, "parsed::" FLAG_RESOURCE_AXES_FACTOR,
490                           G_CALLBACK(onEntryFactor), (gpointer)obj, G_CONNECT_SWAPPED);
491 
492   if (!defaultAxes)
493     defaultAxes = obj;
494 }
495 
496 /* This method can be called several times.
497    It should unref all of its reference to
498    GObjects. */
visu_gl_ext_axes_dispose(GObject * obj)499 static void visu_gl_ext_axes_dispose(GObject* obj)
500 {
501   VisuGlExtAxes *axes;
502 
503   DBG_fprintf(stderr, "Extension Axes: dispose object %p.\n", (gpointer)obj);
504 
505   axes = VISU_GL_EXT_AXES(obj);
506   if (axes->priv->dispose_has_run)
507     return;
508   axes->priv->dispose_has_run = TRUE;
509 
510   /* Disconnect signals. */
511   visu_gl_ext_axes_setGlView(VISU_GL_EXT(axes), (VisuGlView*)0);
512   _setBox(axes, (VisuBox*)0);
513 
514   /* Chain up to the parent class */
515   G_OBJECT_CLASS(visu_gl_ext_axes_parent_class)->dispose(obj);
516 }
517 /* This method is called once only. */
visu_gl_ext_axes_finalize(GObject * obj)518 static void visu_gl_ext_axes_finalize(GObject* obj)
519 {
520   VisuGlExtAxes *axes;
521 
522   g_return_if_fail(obj);
523 
524   DBG_fprintf(stderr, "Extension Axes: finalize object %p.\n", (gpointer)obj);
525 
526   axes = VISU_GL_EXT_AXES(obj);
527 
528   /* Free privs elements. */
529   if (axes->priv)
530     {
531       DBG_fprintf(stderr, "Extension Axes: free private axes.\n");
532       g_free(axes->priv->lbl[0]);
533       g_free(axes->priv->lbl[1]);
534       g_free(axes->priv->lbl[2]);
535     }
536   /* The free is called by g_type_free_instance... */
537 /*   g_free(axes); */
538 
539   /* Chain up to the parent class */
540   DBG_fprintf(stderr, "Extension Axes: chain to parent.\n");
541   G_OBJECT_CLASS(visu_gl_ext_axes_parent_class)->finalize(obj);
542   DBG_fprintf(stderr, "Extension Axes: freeing ... OK.\n");
543 }
visu_gl_ext_axes_get_property(GObject * obj,guint property_id,GValue * value,GParamSpec * pspec)544 static void visu_gl_ext_axes_get_property(GObject* obj, guint property_id,
545                                           GValue *value, GParamSpec *pspec)
546 {
547   VisuGlExtAxes *self = VISU_GL_EXT_AXES(obj);
548 
549   DBG_fprintf(stderr, "Extension Axes: get property '%s' -> ",
550 	      g_param_spec_get_name(pspec));
551   switch (property_id)
552     {
553     case SIZE_PROP:
554       g_value_set_float(value, self->priv->lgFact);
555       DBG_fprintf(stderr, "%g.\n", self->priv->lgFact);
556       break;
557     case XPOS_PROP:
558       g_value_set_float(value, self->priv->xpos);
559       DBG_fprintf(stderr, "%g.\n", self->priv->xpos);
560       break;
561     case YPOS_PROP:
562       g_value_set_float(value, self->priv->ypos);
563       DBG_fprintf(stderr, "%g.\n", self->priv->ypos);
564       break;
565     case COLOR_PROP:
566       g_value_take_boxed(value, tool_color_new(self->priv->rgb));
567       DBG_fprintf(stderr, "%gx%gx%g.\n", self->priv->rgb[0], self->priv->rgb[1], self->priv->rgb[2]);
568       break;
569     case WIDTH_PROP:
570       g_value_set_float(value, self->priv->lineWidth);
571       DBG_fprintf(stderr, "%g.\n", self->priv->lineWidth);
572       break;
573     case STIPPLE_PROP:
574       g_value_set_uint(value, (guint)self->priv->lineStipple);
575       DBG_fprintf(stderr, "%d.\n", (guint)self->priv->lineStipple);
576       break;
577     case VIEW_PROP:
578       g_value_set_object(value, self->priv->view);
579       DBG_fprintf(stderr, "%p.\n", (gpointer)self->priv->view);
580       break;
581     case BOX_PROP:
582       g_value_set_object(value, self->priv->box);
583       DBG_fprintf(stderr, "%p.\n", g_value_get_object(value));
584       break;
585     case LBLX_PROP:
586       g_value_set_static_string(value, self->priv->lbl[0]);
587       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[0]);
588       break;
589     case LBLY_PROP:
590       g_value_set_static_string(value, self->priv->lbl[1]);
591       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[1]);
592       break;
593     case LBLZ_PROP:
594       g_value_set_static_string(value, self->priv->lbl[2]);
595       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[2]);
596       break;
597     case USE_ORIENTATION_PROP:
598       g_value_set_boolean(value, self->priv->displayOrientation);
599       DBG_fprintf(stderr, "%d.\n", self->priv->displayOrientation);
600       break;
601     case CONE_THETA_PROP:
602       g_value_set_float(value, self->priv->orientation[0]);
603       DBG_fprintf(stderr, "%g.\n", self->priv->orientation[0]);
604       break;
605     case CONE_PHI_PROP:
606       g_value_set_float(value, self->priv->orientation[1]);
607       DBG_fprintf(stderr, "%g.\n", self->priv->orientation[1]);
608       break;
609     case CONE_OMEGA_PROP:
610       g_value_set_float(value, self->priv->orientation[2]);
611       DBG_fprintf(stderr, "%g.\n", self->priv->orientation[2]);
612       break;
613     default:
614       /* We don't have any other property... */
615       G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
616       break;
617     }
618 }
visu_gl_ext_axes_set_property(GObject * obj,guint property_id,const GValue * value,GParamSpec * pspec)619 static void visu_gl_ext_axes_set_property(GObject* obj, guint property_id,
620                                           const GValue *value, GParamSpec *pspec)
621 {
622   ToolColor *color;
623   VisuGlExtAxes *self = VISU_GL_EXT_AXES(obj);
624   float orientation[3];
625 
626   DBG_fprintf(stderr, "Extension Axes: set property '%s' -> ",
627 	      g_param_spec_get_name(pspec));
628   switch (property_id)
629     {
630     case SIZE_PROP:
631       visu_gl_ext_axes_setLengthFactor(self, g_value_get_float(value));
632       DBG_fprintf(stderr, "%g.\n", self->priv->lgFact);
633       break;
634     case XPOS_PROP:
635       visu_gl_ext_axes_setPosition(self, g_value_get_float(value), self->priv->ypos);
636       DBG_fprintf(stderr, "%g.\n", self->priv->xpos);
637       break;
638     case YPOS_PROP:
639       visu_gl_ext_axes_setPosition(self, self->priv->xpos, g_value_get_float(value));
640       DBG_fprintf(stderr, "%g.\n", self->priv->ypos);
641       break;
642     case COLOR_PROP:
643       color = (ToolColor*)g_value_get_boxed(value);
644       _setRGB((VisuGlExtLined*)self, color->rgba, TOOL_COLOR_MASK_RGBA);
645       DBG_fprintf(stderr, "%gx%gx%g.\n", self->priv->rgb[0], self->priv->rgb[1], self->priv->rgb[2]);
646       break;
647     case WIDTH_PROP:
648       _setLineWidth((VisuGlExtLined*)self, g_value_get_float(value));
649       DBG_fprintf(stderr, "%g.\n", self->priv->lineWidth);
650       break;
651     case STIPPLE_PROP:
652       _setLineStipple((VisuGlExtLined*)self, (guint16)g_value_get_uint(value));
653       DBG_fprintf(stderr, "%d.\n", (guint)self->priv->lineStipple);
654       break;
655     case VIEW_PROP:
656       visu_gl_ext_axes_setGlView(VISU_GL_EXT(self),
657                                  VISU_GL_VIEW(g_value_get_object(value)));
658       DBG_fprintf(stderr, "%p.\n", (gpointer)self->priv->view);
659       break;
660     case BOX_PROP:
661       DBG_fprintf(stderr, "%p.\n", (gpointer)g_value_get_object(value));
662       visu_gl_ext_axes_setBasisFromBox(self, VISU_BOX(g_value_get_object(value)));
663       break;
664     case LBLX_PROP:
665       visu_gl_ext_axes_setLabel(self, g_value_get_string(value), TOOL_XYZ_X);
666       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[0]);
667       break;
668     case LBLY_PROP:
669       visu_gl_ext_axes_setLabel(self, g_value_get_string(value), TOOL_XYZ_Y);
670       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[1]);
671       break;
672     case LBLZ_PROP:
673       visu_gl_ext_axes_setLabel(self, g_value_get_string(value), TOOL_XYZ_Z);
674       DBG_fprintf(stderr, "'%s'.\n", self->priv->lbl[2]);
675       break;
676     case USE_ORIENTATION_PROP:
677       visu_gl_ext_axes_useOrientation(self, g_value_get_boolean(value));
678       DBG_fprintf(stderr, "%d.\n", self->priv->displayOrientation);
679       break;
680     case CONE_THETA_PROP:
681       orientation[0] = g_value_get_float(value);
682       visu_gl_ext_axes_setOrientationTop(self, orientation, VISU_GL_CAMERA_THETA);
683       DBG_fprintf(stderr, "%g.\n", self->priv->orientation[0]);
684       break;
685     case CONE_PHI_PROP:
686       orientation[1] = g_value_get_float(value);
687       visu_gl_ext_axes_setOrientationTop(self, orientation, VISU_GL_CAMERA_PHI);
688       DBG_fprintf(stderr, "%g.\n", self->priv->orientation[1]);
689       break;
690     case CONE_OMEGA_PROP:
691       DBG_fprintf(stderr, "%g.\n", g_value_get_float(value));
692       orientation[2] = g_value_get_float(value);
693       visu_gl_ext_axes_setOrientationTop(self, orientation, VISU_GL_CAMERA_OMEGA);
694       break;
695     default:
696       /* We don't have any other property... */
697       G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
698       break;
699     }
700 }
_setBox(VisuGlExtAxes * axes,VisuBox * box)701 static void _setBox(VisuGlExtAxes *axes, VisuBox *box)
702 {
703   if (axes->priv->box == box)
704     return;
705 
706   if (axes->priv->box)
707     {
708       g_signal_handler_disconnect(G_OBJECT(axes->priv->box), axes->priv->box_signal);
709       g_object_unref(axes->priv->box);
710     }
711   if (box)
712     {
713       g_object_ref(box);
714       axes->priv->box_signal =
715         g_signal_connect(G_OBJECT(box), "SizeChanged",
716                          G_CALLBACK(onBoxChange), (gpointer)axes);
717     }
718   else
719     axes->priv->box_signal = 0;
720   axes->priv->box = box;
721   g_object_notify_by_pspec(G_OBJECT(axes), properties[BOX_PROP]);
722 }
723 
724 /**
725  * visu_gl_ext_axes_new:
726  * @name: (allow-none): the name to give to the extension (default is #VISU_GL_EXT_AXES_ID).
727  *
728  * Creates a new #VisuGlExt to draw axes.
729  *
730  * Since: 3.7
731  *
732  * Returns: a pointer to the #VisuGlExt it created or
733  * NULL otherwise.
734  */
visu_gl_ext_axes_new(const gchar * name)735 VisuGlExtAxes* visu_gl_ext_axes_new(const gchar *name)
736 {
737   char *name_ = VISU_GL_EXT_AXES_ID;
738   char *description = _("Draw {x,y,z} axes.");
739   VisuGlExt *extensionAxes;
740 
741   DBG_fprintf(stderr,"Extension Axes: new object.\n");
742 
743   extensionAxes = VISU_GL_EXT(g_object_new(VISU_TYPE_GL_EXT_AXES,
744                                               "name", (name)?name:name_, "label", _(name),
745                                               "description", description, "nGlObj", 1,
746                                               "priority", VISU_GL_EXT_PRIORITY_LAST,
747                                               "saveState", TRUE, NULL));
748 
749   return VISU_GL_EXT_AXES(extensionAxes);
750 }
751 
_setRGB(VisuGlExtLined * axes,float rgb[4],int mask)752 static gboolean _setRGB(VisuGlExtLined *axes, float rgb[4], int mask)
753 {
754   VisuGlExtAxesPrivate *self;
755   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
756 
757   self = VISU_GL_EXT_AXES(axes)->priv;
758 
759   if (mask & TOOL_COLOR_MASK_R)
760     self->rgb[0] = rgb[0];
761   if (mask & TOOL_COLOR_MASK_G)
762     self->rgb[1] = rgb[1];
763   if (mask & TOOL_COLOR_MASK_B)
764     self->rgb[2] = rgb[2];
765 
766   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
767   return TRUE;
768 }
_setLineWidth(VisuGlExtLined * axes,float width)769 static gboolean _setLineWidth(VisuGlExtLined *axes, float width)
770 {
771   VisuGlExtAxesPrivate *self;
772   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
773   self = VISU_GL_EXT_AXES(axes)->priv;
774 
775   self->lineWidth = width;
776   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
777   return TRUE;
778 }
_setLineStipple(VisuGlExtLined * axes,guint16 stipple)779 static gboolean _setLineStipple(VisuGlExtLined *axes, guint16 stipple)
780 {
781   VisuGlExtAxesPrivate *self;
782   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
783   self = VISU_GL_EXT_AXES(axes)->priv;
784 
785   self->lineStipple = stipple;
786   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
787   return TRUE;
788 }
_setBasis(VisuGlExtAxes * axes,double matrix[3][3])789 static void _setBasis(VisuGlExtAxes *axes, double matrix[3][3])
790 {
791   double sum2;
792 
793   DBG_fprintf(stderr, "Extension Axes: %8g %8g %8g\n"
794               "                %8g %8g %8g\n"
795 	      "                %8g %8g %8g\n",
796 	      matrix[0][0], matrix[0][1], matrix[0][2],
797 	      matrix[1][0], matrix[1][1], matrix[1][2],
798 	      matrix[2][0], matrix[2][1], matrix[2][2]);
799   /* We normalise it and copy it. */
800   sum2 = 1. / sqrt(matrix[0][0] * matrix[0][0] +
801                    matrix[1][0] * matrix[1][0] +
802                    matrix[2][0] * matrix[2][0]);
803   axes->priv->matrix[0][0] = matrix[0][0] * sum2;
804   axes->priv->matrix[0][1] = matrix[1][0] * sum2;
805   axes->priv->matrix[0][2] = matrix[2][0] * sum2;
806   sum2 = 1. / sqrt(matrix[0][1] * matrix[0][1] +
807                    matrix[1][1] * matrix[1][1] +
808                    matrix[2][1] * matrix[2][1]);
809   axes->priv->matrix[1][0] = matrix[0][1] * sum2;
810   axes->priv->matrix[1][1] = matrix[1][1] * sum2;
811   axes->priv->matrix[1][2] = matrix[2][1] * sum2;
812   sum2 = 1. / sqrt(matrix[0][2] * matrix[0][2] +
813                    matrix[1][2] * matrix[1][2] +
814                    matrix[2][2] * matrix[2][2]);
815   axes->priv->matrix[2][0] = matrix[0][2] * sum2;
816   axes->priv->matrix[2][1] = matrix[1][2] * sum2;
817   axes->priv->matrix[2][2] = matrix[2][2] * sum2;
818 
819   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
820 }
821 /**
822  * visu_gl_ext_axes_setBasis:
823  * @axes: the #VisuGlExtAxes object to modify.
824  * @matrix: the definition of the three basis axis.
825  *
826  * The @axes can represent an arbitrary basis-set, provided by
827  * @matrix. @matrix[{0,1,2}] represents the {x,y,z} axis vector in a
828  * cartesian basis-set. See visu_gl_ext_axes_setBasisFromBox() if the
829  * basis-set should follow the one of a given #VisuBox.
830  *
831  * Since: 3.7
832  *
833  * Returns: TRUE if the basis is actually changed.
834  **/
visu_gl_ext_axes_setBasis(VisuGlExtAxes * axes,double matrix[3][3])835 gboolean visu_gl_ext_axes_setBasis(VisuGlExtAxes *axes, double matrix[3][3])
836 {
837   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
838 
839   _setBox(axes, (VisuBox*)0);
840   _setBasis(axes, matrix);
841 
842   return visu_gl_ext_getActive(VISU_GL_EXT(axes));
843 }
844 /**
845  * visu_gl_ext_axes_setBasisFromBox:
846  * @axes: the #VisuGlExtAxes object to modify.
847  * @box: (allow-none): the #VisuBox to use as basis-set.
848  *
849  * The @axes can follow the basis-set defined by @box. If NULL is
850  * passed, then the orthorombic default basis-set is used.
851  *
852  * Since: 3.7
853  *
854  * Returns: TRUE if the basis is actually changed.
855  **/
visu_gl_ext_axes_setBasisFromBox(VisuGlExtAxes * axes,VisuBox * box)856 gboolean visu_gl_ext_axes_setBasisFromBox(VisuGlExtAxes *axes, VisuBox *box)
857 {
858   double m[3][3];
859 
860   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
861 
862   if (box)
863     visu_box_getCellMatrix(box, m);
864   else
865     {
866       memset(m, '\0', sizeof(double) * 9);
867       m[0][0] = 1.;
868       m[1][1] = 1.;
869       m[2][2] = 1.;
870     }
871   _setBox(axes, box);
872   _setBasis(axes, m);
873 
874   return visu_gl_ext_getActive(VISU_GL_EXT(axes));
875 }
876 /**
877  * visu_gl_ext_axes_setLabel:
878  * @axes: a #VisuGlExtAxes object.
879  * @lbl: a string.
880  * @dir: an axis direction.
881  *
882  * Set the label @lbl for the given axis @dir.
883  *
884  * Since: 3.8
885  *
886  * Returns: TRUE if the label is modified.
887  **/
visu_gl_ext_axes_setLabel(VisuGlExtAxes * axes,const gchar * lbl,ToolXyzDir dir)888 gboolean visu_gl_ext_axes_setLabel(VisuGlExtAxes *axes, const gchar *lbl, ToolXyzDir dir)
889 {
890   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes) && lbl, FALSE);
891 
892   if (!strcmp(axes->priv->lbl[dir], lbl))
893     return FALSE;
894 
895   g_free(axes->priv->lbl[dir]);
896   axes->priv->lbl[dir] = g_strdup(lbl);
897   g_object_notify_by_pspec(G_OBJECT(axes), properties[LBLX_PROP + dir]);
898   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
899   return TRUE;
900 }
901 /**
902  * visu_gl_ext_axes_setPosition:
903  * @axes: the #VisuGlExtAxes object to modify.
904  * @xpos: the reduced x position (1 to the right).
905  * @ypos: the reduced y position (1 to the bottom).
906  *
907  * Change the position of the axes representation.
908  *
909  * Since: 3.7
910  *
911  * Returns: TRUE if the position is actually changed.
912  **/
visu_gl_ext_axes_setPosition(VisuGlExtAxes * axes,float xpos,float ypos)913 gboolean visu_gl_ext_axes_setPosition(VisuGlExtAxes *axes, float xpos, float ypos)
914 {
915   gboolean changed;
916 
917   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
918 
919   xpos = CLAMP(xpos, 0.f, 1.f);
920   ypos = CLAMP(ypos, 0.f, 1.f);
921   changed = FALSE;
922 
923   g_object_freeze_notify(G_OBJECT(axes));
924   if (xpos != axes->priv->xpos)
925     {
926       axes->priv->xpos = xpos;
927       g_object_notify_by_pspec(G_OBJECT(axes), properties[XPOS_PROP]);
928       changed = TRUE;
929     }
930   if (ypos != axes->priv->ypos)
931     {
932       axes->priv->ypos = ypos;
933       g_object_notify_by_pspec(G_OBJECT(axes), properties[YPOS_PROP]);
934       changed = TRUE;
935     }
936   if (changed)
937     visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
938   g_object_thaw_notify(G_OBJECT(axes));
939 
940   return changed;
941 }
942 /**
943  * visu_gl_ext_axes_useOrientation:
944  * @axes: a #VisuGlExtAxes object.
945  * @use: a boolean.
946  *
947  * If TRUE, @axes also draws a coloured cone to display orientation information.
948  *
949  * Since: 3.8
950  *
951  * Returns: TRUE if value is actually changed.
952  **/
visu_gl_ext_axes_useOrientation(VisuGlExtAxes * axes,gboolean use)953 gboolean visu_gl_ext_axes_useOrientation(VisuGlExtAxes *axes, gboolean use)
954 {
955   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
956 
957   if (axes->priv->displayOrientation == use)
958     return FALSE;
959 
960   axes->priv->displayOrientation = use;
961   g_object_notify_by_pspec(G_OBJECT(axes), properties[USE_ORIENTATION_PROP]);
962   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
963   return TRUE;
964 }
965 /**
966  * visu_gl_ext_axes_setOrientationTop:
967  * @axes: a #VisuGlExtAxes object.
968  * @top: (array fixed-size=3): a camera orientation.
969  * @dir: flags used to specify which angles to set.
970  *
971  * Define the camera orientation of the top orientation when @axes are
972  * used to display orientation information.
973  *
974  * Since: 3.8
975  *
976  * Returns: TRUE if value is actually changed.
977  **/
visu_gl_ext_axes_setOrientationTop(VisuGlExtAxes * axes,const gfloat top[3],int dir)978 gboolean visu_gl_ext_axes_setOrientationTop(VisuGlExtAxes *axes,
979                                             const gfloat top[3], int dir)
980 {
981   gboolean changed;
982 
983   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
984 
985   changed = FALSE;
986 
987   g_object_freeze_notify(G_OBJECT(axes));
988   if ((dir & VISU_GL_CAMERA_THETA) &&
989       (CLAMP(top[0], 0.f, 180.) != axes->priv->orientation[0]))
990     {
991       axes->priv->orientation[0] = CLAMP(top[0], 0.f, 180.);
992       g_object_notify_by_pspec(G_OBJECT(axes), properties[CONE_THETA_PROP]);
993       changed = TRUE;
994     }
995   if ((dir & VISU_GL_CAMERA_PHI) &&
996       (CLAMP(top[1], 0.f, 360.) != axes->priv->orientation[1]))
997     {
998       axes->priv->orientation[1] = CLAMP(top[1], 0.f, 360.);
999       g_object_notify_by_pspec(G_OBJECT(axes), properties[CONE_PHI_PROP]);
1000       changed = TRUE;
1001     }
1002   if ((dir & VISU_GL_CAMERA_OMEGA) &&
1003       (CLAMP(top[2], 0.f, 360.) != axes->priv->orientation[2]))
1004     {
1005       axes->priv->orientation[2] = CLAMP(top[2], 0.f, 360.);
1006       g_object_notify_by_pspec(G_OBJECT(axes), properties[CONE_OMEGA_PROP]);
1007       changed = TRUE;
1008     }
1009   if (changed && axes->priv->displayOrientation)
1010     visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
1011   g_object_thaw_notify(G_OBJECT(axes));
1012 
1013   return changed;
1014 }
visu_gl_ext_axes_setGlView(VisuGlExt * axes,VisuGlView * view)1015 static gboolean visu_gl_ext_axes_setGlView(VisuGlExt *axes, VisuGlView *view)
1016 {
1017   VisuGlExtAxesPrivate *priv = ((VisuGlExtAxes*)axes)->priv;
1018 
1019   /* No change to be done. */
1020   if (view == priv->view)
1021     return FALSE;
1022 
1023   if (priv->view)
1024     {
1025       g_signal_handler_disconnect(G_OBJECT(priv->view), priv->persp_signal);
1026       g_signal_handler_disconnect(G_OBJECT(priv->view), priv->refLength_signal);
1027       g_signal_handler_disconnect(G_OBJECT(priv->view), priv->widthHeight_signal);
1028       g_object_unref(priv->view);
1029       priv->persp_signal     = 0;
1030       priv->refLength_signal   = 0;
1031       priv->widthHeight_signal = 0;
1032       priv->color_signal       = 0;
1033     }
1034   if (view)
1035     {
1036       g_object_ref(view);
1037       priv->persp_signal =
1038         g_signal_connect_swapped(G_OBJECT(view), "notify::perspective",
1039                                  G_CALLBACK(onAxesParametersChange), (gpointer)axes);
1040       priv->refLength_signal =
1041         g_signal_connect_swapped(G_OBJECT(view), "RefLengthChanged",
1042                                  G_CALLBACK(onAxesParametersChange), (gpointer)axes);
1043       priv->widthHeight_signal =
1044         g_signal_connect_swapped(G_OBJECT(view), "WidthHeightChanged",
1045                                  G_CALLBACK(onAxesParametersChange), (gpointer)axes);
1046     }
1047   priv->view = view;
1048   g_object_notify_by_pspec(G_OBJECT(axes), properties[VIEW_PROP]);
1049 
1050   return TRUE;
1051 }
1052 
1053 /* Get methods. */
_getRGB(const VisuGlExtLined * axes)1054 static float* _getRGB(const VisuGlExtLined *axes)
1055 {
1056   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), rgbDefault);
1057 
1058   return ((VisuGlExtAxes*)axes)->priv->rgb;
1059 }
_getLineWidth(const VisuGlExtLined * axes)1060 static float _getLineWidth(const VisuGlExtLined *axes)
1061 {
1062   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), LINE_WIDTH_DEFAULT);
1063 
1064   return ((VisuGlExtAxes*)axes)->priv->lineWidth;
1065 }
_getLineStipple(const VisuGlExtLined * axes)1066 static guint16 _getLineStipple(const VisuGlExtLined *axes)
1067 {
1068   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), LINE_STIPPLE_DEFAULT);
1069 
1070   return ((VisuGlExtAxes*)axes)->priv->lineStipple;
1071 }
1072 /**
1073  * visu_gl_ext_axes_getPosition:
1074  * @axes: the #VisuGlExtAxes object to inquire.
1075  * @xpos: (out) (allow-none): a location to store the x position.
1076  * @ypos: (out) (allow-none): a location to store the y position.
1077  *
1078  * Inquire the position of the representation of tha axes.
1079  *
1080  * Since: 3.7
1081  **/
visu_gl_ext_axes_getPosition(VisuGlExtAxes * axes,float * xpos,float * ypos)1082 void visu_gl_ext_axes_getPosition(VisuGlExtAxes *axes, float *xpos, float *ypos)
1083 {
1084   g_return_if_fail(VISU_IS_GL_EXT_AXES(axes));
1085 
1086   if (xpos)
1087     *xpos = axes->priv->xpos;
1088   if (ypos)
1089     *ypos = axes->priv->ypos;
1090 }
1091 /**
1092  * visu_gl_ext_axes_setLengthFactor:
1093  * @axes: a #VisuGlExtAxes object.
1094  * @factor: a floating point value between 0. and 10.
1095  *
1096  * Change the scaling factor to draw the axis.
1097  *
1098  * Since: 3.8
1099  *
1100  * Returns: TRUE if value is indeed changed.
1101  **/
visu_gl_ext_axes_setLengthFactor(VisuGlExtAxes * axes,float factor)1102 gboolean visu_gl_ext_axes_setLengthFactor(VisuGlExtAxes *axes, float factor)
1103 {
1104   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), FALSE);
1105 
1106   if (axes->priv->lgFact == factor)
1107     return FALSE;
1108   axes->priv->lgFact = factor;
1109 
1110   g_object_notify_by_pspec(G_OBJECT(axes), properties[SIZE_PROP]);
1111   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
1112 
1113   return TRUE;
1114 }
1115 /**
1116  * visu_gl_ext_axes_getLengthFactor:
1117  * @axes: a #VisuGlExtAxes object.
1118  *
1119  * Retrieve the scaling factor used to draw axis.
1120  *
1121  * Since: 3.8
1122  *
1123  * Returns: the scaling factor.
1124  **/
visu_gl_ext_axes_getLengthFactor(VisuGlExtAxes * axes)1125 float visu_gl_ext_axes_getLengthFactor(VisuGlExtAxes *axes)
1126 {
1127   g_return_val_if_fail(VISU_IS_GL_EXT_AXES(axes), 1.f);
1128 
1129   return axes->priv->lgFact;
1130 }
1131 
1132 /****************/
1133 /* Private part */
1134 /****************/
visu_gl_ext_axes_rebuild(VisuGlExt * ext)1135 static void visu_gl_ext_axes_rebuild(VisuGlExt *ext)
1136 {
1137   visu_gl_text_rebuildFontList();
1138   visu_gl_ext_axes_draw(ext);
1139 }
onAxesParametersChange(VisuGlExtAxes * axes)1140 static void onAxesParametersChange(VisuGlExtAxes *axes)
1141 {
1142   DBG_fprintf(stderr, "Extension Axes: caught change on view.\n");
1143   visu_gl_ext_setDirty(VISU_GL_EXT(axes), TRUE);
1144 }
onBoxChange(VisuBox * box,float extens _U_,gpointer data)1145 static void onBoxChange(VisuBox *box, float extens _U_, gpointer data)
1146 {
1147   VisuGlExtAxes *axes = VISU_GL_EXT_AXES(data);
1148   double m[3][3];
1149 
1150   /* We copy the definition of the box. */
1151   visu_box_getCellMatrix(box, m);
1152   _setBasis(axes, m);
1153 }
onEntryUsed(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1154 static void onEntryUsed(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1155 {
1156   visu_gl_ext_setActive(VISU_GL_EXT(axes), RESOURCE_AXES_USED_DEFAULT);
1157 }
onEntryColor(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1158 static void onEntryColor(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1159 {
1160   visu_gl_ext_lined_setRGBA(VISU_GL_EXT_LINED(axes), rgbDefault, TOOL_COLOR_MASK_RGBA);
1161 }
onEntryWidth(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1162 static void onEntryWidth(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1163 {
1164   visu_gl_ext_lined_setWidth(VISU_GL_EXT_LINED(axes), LINE_WIDTH_DEFAULT);
1165 }
onEntryStipple(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1166 static void onEntryStipple(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1167 {
1168   visu_gl_ext_lined_setStipple(VISU_GL_EXT_LINED(axes), LINE_STIPPLE_DEFAULT);
1169 }
onEntryPosition(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1170 static void onEntryPosition(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1171 {
1172   visu_gl_ext_axes_setPosition(axes, POSITION_DEFAULT[0], POSITION_DEFAULT[1]);
1173 }
onEntryLabel(VisuGlExtAxes * axes,VisuConfigFileEntry * entry,VisuConfigFile * obj _U_)1174 static void onEntryLabel(VisuGlExtAxes *axes, VisuConfigFileEntry *entry, VisuConfigFile *obj _U_)
1175 {
1176   if (!strcmp(visu_config_file_entry_getKey(entry), FLAG_RESOURCE_AXES_LABEL_X))
1177     g_object_set(G_OBJECT(axes), "x-label", LABEL_DEFAULT[TOOL_XYZ_X], NULL);
1178   else if (!strcmp(visu_config_file_entry_getKey(entry), FLAG_RESOURCE_AXES_LABEL_Y))
1179     g_object_set(G_OBJECT(axes), "y-label", LABEL_DEFAULT[TOOL_XYZ_Y], NULL);
1180   else if (!strcmp(visu_config_file_entry_getKey(entry), FLAG_RESOURCE_AXES_LABEL_Z))
1181     g_object_set(G_OBJECT(axes), "z-label", LABEL_DEFAULT[TOOL_XYZ_Z], NULL);
1182 }
onEntryFactor(VisuGlExtAxes * axes,VisuConfigFileEntry * entry _U_,VisuConfigFile * obj _U_)1183 static void onEntryFactor(VisuGlExtAxes *axes, VisuConfigFileEntry *entry _U_, VisuConfigFile *obj _U_)
1184 {
1185   visu_gl_ext_axes_setLengthFactor(axes, SIZE_DEFAULT);
1186 }
1187 
drawAxes(float length,double matrix[3][3],GLsizei w,GLsizei h,float width,float rgb[3],const char * legend,gboolean long_axes,gchar * lbl[3])1188 static void drawAxes(float length, double matrix[3][3], GLsizei w, GLsizei h, float width,
1189 		     float rgb[3], const char *legend, gboolean long_axes, gchar *lbl[3])
1190 {
1191   double orig[3][3];
1192 
1193   if (long_axes)
1194     {
1195       orig[0][0] = -matrix[0][0];
1196       orig[0][1] = -matrix[0][1];
1197       orig[0][2] = -matrix[0][2];
1198       orig[1][0] = -matrix[1][0];
1199       orig[1][1] = -matrix[1][1];
1200       orig[1][2] = -matrix[1][2];
1201       orig[2][0] = -matrix[2][0];
1202       orig[2][1] = -matrix[2][1];
1203       orig[2][2] = -matrix[2][2];
1204     }
1205   else
1206     memset(orig, '\0',  sizeof(double) * 9);
1207 
1208   glLineWidth(width);
1209   glColor3fv(rgb);
1210   glPushMatrix();
1211   glScalef(length, length, length);
1212   glBegin(GL_LINES);
1213   glVertex3dv(orig[0]); glVertex3dv(matrix[0]);
1214   glVertex3dv(orig[1]); glVertex3dv(matrix[1]);
1215   glVertex3dv(orig[2]); glVertex3dv(matrix[2]);
1216   glEnd();
1217 
1218   glRasterPos3dv(matrix[0]); visu_gl_text_drawChars(lbl[0], VISU_GL_TEXT_NORMAL);
1219   glRasterPos3dv(matrix[1]); visu_gl_text_drawChars(lbl[1], VISU_GL_TEXT_NORMAL);
1220   glRasterPos3dv(matrix[2]); visu_gl_text_drawChars(lbl[2], VISU_GL_TEXT_NORMAL);
1221 
1222   glPopMatrix();
1223 
1224   if(legend != NULL)
1225     {
1226       glMatrixMode (GL_PROJECTION);
1227       glPushMatrix();
1228       glLoadIdentity ();
1229       gluOrtho2D (0, MIN(w,h), 0, MIN(h,w));
1230       glMatrixMode (GL_MODELVIEW);
1231       glPushMatrix();
1232       glLoadIdentity ();
1233       glRasterPos3f(20., 5., 0.9); visu_gl_text_drawChars(legend, VISU_GL_TEXT_NORMAL);
1234       glPopMatrix();
1235       glMatrixMode(GL_PROJECTION);
1236       glPopMatrix();
1237       glMatrixMode(GL_MODELVIEW);
1238     }
1239 }
1240 
1241 /**
1242  * draw_coloured_cone:
1243  * @r: the radius of the cone
1244  * @h: the semi-height of the cone
1245  * @n: the precision used to draw the sphere
1246  *
1247  * Draws a coloured double cone at the given position.
1248  */
draw_coloured_cone(double r,double h,int n,float phi_prime_zero)1249 static void draw_coloured_cone(double r, double h, int n, float phi_prime_zero)
1250 {
1251   float hsv[3], rgb[3];
1252   int i,j;
1253   double theta1,theta2,theta3;
1254   float e_x, e_y, e_z, p_x, p_y, p_z;
1255 
1256   g_return_if_fail(r >= 0 && n >= 0);
1257 
1258   if (n < 4 || r <= 0)
1259     {
1260       glBegin(GL_POINTS);
1261       glVertex3f(0,0,0);
1262       glEnd();
1263       return;
1264     }
1265 
1266   glFrontFace(GL_CW);
1267 
1268   glPushMatrix();
1269   glRotatef(phi_prime_zero, 0, 0, 1);
1270 
1271   glRotatef(-90, 1, 0, 0);
1272 
1273   hsv[1] = 0;
1274   hsv[2] = 1;
1275 
1276   for (j=0;j<n/2;j++)
1277     {
1278       theta1 = j * 2 * G_PI / n - G_PI_2;
1279       theta2 = (j + 1) * 2 * G_PI / n - G_PI_2;
1280 
1281       glBegin(GL_QUAD_STRIP);
1282       for (i=0;i<=n;i++)
1283 	{
1284 	  theta3 = i * 2 * G_PI / n;
1285 
1286 	  hsv[0] = /*1-*/(float)i/(float)n;
1287 
1288 	  hsv[1] = 2*(float)(1+j)/(float)(n/2);
1289 	  if(hsv[1] > 1) hsv[1] = 1;
1290 
1291 	  hsv[2] = 2-2*(float)(1+j)/(float)(n/2);
1292 	  if(hsv[2] > 1) hsv[2] = 1;
1293 
1294 	  e_x = /*cos(theta2) **/hsv[1]*hsv[2]* cos(theta3);
1295 	  e_y = sin(theta2);
1296 	  e_z = /*cos(theta2) **/hsv[1]*hsv[2]* sin(theta3);
1297 	  p_x = r * e_x;
1298 	  p_y = /*r * e_y*/h*(hsv[1] - hsv[2]);
1299 	  p_z = r * e_z;
1300 
1301 	  tool_color_convertHSVtoRGB(rgb, hsv);
1302 	  glColor3f(rgb[0], rgb[1], rgb[2]);
1303 	  glNormal3f(e_x,e_y,e_z);
1304 	  glVertex3f(p_x,p_y,p_z);
1305 
1306 	  hsv[0] = /*1-*/(float)i/(float)n;
1307 
1308 	  hsv[1] = 2*(float)j/(float)(n/2);
1309 	  if(hsv[1] > 1) hsv[1] = 1;
1310 
1311 	  hsv[2] = 2-2*(float)j/(float)(n/2);
1312 	  if(hsv[2] > 1) hsv[2] = 1;
1313 
1314 	  e_x = /*cos(theta1) **/hsv[1]*hsv[2]* cos(theta3);
1315        	  e_y = sin(theta1);
1316 	  e_z = /*cos(theta1) **/hsv[1]*hsv[2]* sin(theta3);
1317 	  p_x = r * e_x;
1318 	  p_y = /*r * e_y*/h*(hsv[1] - hsv[2]);
1319 	  p_z = r * e_z;
1320 
1321 	  tool_color_convertHSVtoRGB(rgb, hsv);
1322 	  glColor3f(rgb[0], rgb[1], rgb[2]);
1323 	  glNormal3f(e_x,e_y,e_z);
1324 	  glVertex3f(p_x,p_y,p_z);
1325 
1326 	}
1327       glEnd();
1328     }
1329   glPopMatrix();
1330   glFrontFace(GL_CCW);
1331 
1332 }
1333 
1334 /* void drawConeCircle(/\*XYZ c,*\/ double r, int n)  */
1335 /* { */
1336 /*   /\*  XYZ e,p;*\/ */
1337 /*   GLboolean antialiasing_was_on; */
1338 /*   GLUquadric* trash = gluNewQuadric(); */
1339 /*   int i; */
1340 /*   double theta, height = 1; */
1341 
1342 /* /\*   glEnable (GL_POLYGON_SMOOTH); *\/ */
1343 /* /\*   glDisable (GL_DEPTH_TEST); *\/ */
1344 
1345 /*   antialiasing_was_on = enableGlFeature(GL_LINE_SMOOTH); */
1346 /*   glPushMatrix(); */
1347 /*   glRotatef(90, 1, 0, 0); */
1348 /*   glTranslatef(0, 0, -height/2); */
1349 /*   glLineWidth(lineWidth); */
1350 /*   glColor3f(0, 0, 0);  */
1351 /*   gluQuadricOrientation(trash, GLU_INSIDE); */
1352 /*   gluCylinder(trash, 0.95*r, 0.95*r, height, n, 1); */
1353 /* /\*   glBegin(GL_LINE_LOOP); *\/ */
1354 /* /\*   for (i=0;i<=n;i++)  *\/ */
1355 /* /\*     { *\/ */
1356 /* /\*       theta = i * TWOPI / n; *\/ */
1357 /* /\*       e.x = cos(theta); *\/ */
1358 /* /\*       e.z = sin(theta); *\/ */
1359 /* /\*       p.x = 0.8*(c.x +  r * e.x); *\/ */
1360 /* /\*       p.z = 0.8*(c.z +  r * e.z); *\/ */
1361 /* /\*       glVertex3f(p.x, -0.6, p.z); *\/ */
1362 /* /\*       glVertex3f(p.x, 0.6, p.z); *\/ */
1363 /* /\*     } *\/ */
1364 /* /\*   glEnd(); *\/ */
1365 /*   glPopMatrix(); */
1366 /*   restoreGlFeature(GL_LINE_SMOOTH, antialiasing_was_on); */
1367 /* /\*   glEnable (GL_DEPTH_TEST); *\/ */
1368 /* /\*   glDisable(GL_POLYGON_SMOOTH); *\/ */
1369 
1370 /* } */
1371 
1372 /**
1373  * visu_gl_ext_axes_draw:
1374  * @axes: the #VisuBox object to build axes for.
1375  *
1376  * This method creates a compiled list that draws axes.
1377  */
visu_gl_ext_axes_draw(VisuGlExt * ext)1378 static void visu_gl_ext_axes_draw(VisuGlExt *ext)
1379 {
1380   float length;
1381   GLsizei w, h;
1382   GLint xx, yy;
1383   double mini, maxi, near, far;
1384   float length0;
1385   VisuGlExtAxes *axes;
1386 
1387   g_return_if_fail(VISU_IS_GL_EXT_AXES(ext));
1388   axes = VISU_GL_EXT_AXES(ext);
1389 
1390   DBG_fprintf(stderr, "Extension Axes: call to axes draw (%p).\n",
1391               (gpointer)axes->priv->view);
1392   /* Nothing to draw; */
1393   if (!axes->priv->view)
1394     return;
1395 
1396   DBG_fprintf(stderr, "Extension axes: creating axes in (%dx%d).\n",
1397 	      axes->priv->view->window.width, axes->priv->view->window.height);
1398 
1399   length0 = visu_gl_camera_getRefLength(&axes->priv->view->camera, (ToolUnits*)0);
1400   DBG_fprintf(stderr, " | refLength = %g\n", length0);
1401   DBG_fprintf(stderr, " | window = %dx%d\n",
1402               axes->priv->view->window.width, axes->priv->view->window.height);
1403   w = axes->priv->lgFact * MIN(axes->priv->view->window.width,
1404                                axes->priv->view->window.height);
1405   h = w;
1406   xx = (axes->priv->view->window.width - w) * axes->priv->xpos;
1407   yy = (axes->priv->view->window.height - h) * (1.f - axes->priv->ypos);
1408   mini = -0.5f * length0 *
1409     (axes->priv->view->camera.d_red - 1.f) / axes->priv->view->camera.d_red;
1410   maxi = -mini;
1411   near = far = axes->priv->view->camera.d_red * length0;
1412   near -= length0;
1413   far  += length0;
1414   DBG_fprintf(stderr, " | near/far = %g %g\n", near, far);
1415 
1416   visu_gl_text_initFontList();
1417 
1418   glDeleteLists(visu_gl_ext_getGlList(ext), 1);
1419   visu_gl_ext_startDrawing(ext);
1420 
1421   /* Désactivation de la lumière et du brouillard et activation du culling. */
1422   glEnable(GL_CULL_FACE);
1423   glDisable(GL_LIGHTING);
1424   glDisable(GL_FOG);
1425 
1426   if (axes->priv->lineStipple != 65535)
1427     {
1428       glEnable(GL_LINE_STIPPLE);
1429       glLineStipple(1, axes->priv->lineStipple);
1430     }
1431 
1432   glMatrixMode(GL_PROJECTION);
1433   glPushMatrix();
1434   glLoadIdentity();
1435   DBG_fprintf(stderr, "Extension axes: frustum is %fx%f %fx%f %fx%f.\n",
1436 	      mini, maxi, mini, maxi, near, far);
1437   glFrustum(mini, maxi, mini, maxi, near, far);
1438   glMatrixMode(GL_MODELVIEW);
1439   glPopMatrix();
1440 
1441   DBG_fprintf(stderr, "Extension Axes: new view port at %dx%d, size %dx%d.\n",
1442               xx, yy, w, h);
1443   glViewport(xx, yy, w, h);
1444 
1445   length = 0.33 * length0;
1446   if (axes->priv->displayOrientation)
1447     {
1448       /* Resetting the depth buffer. */
1449       glClear(GL_DEPTH_BUFFER_BIT);
1450       glEnable(GL_DEPTH_TEST);
1451 
1452       /* Draw the first color cone */
1453       glPushMatrix();
1454       glRotatef(axes->priv->orientation[1], 0, 0, 1);
1455       glRotatef(axes->priv->orientation[0], 0, 1, 0);
1456       draw_coloured_cone(length, 1.2*length, 16, axes->priv->orientation[2]);
1457       glPopMatrix();
1458 
1459       drawAxes(1.5*length, axes->priv->matrix, w, h, axes->priv->lineWidth,
1460                axes->priv->rgb, _("front"), TRUE, axes->priv->lbl);
1461 
1462       glViewport(xx, yy+h, w, h);
1463 
1464       /* Enabling front culling and drawing the second color cone */
1465       glPushMatrix();
1466       glRotatef(axes->priv->orientation[1], 0, 0, 1);
1467       glRotatef(axes->priv->orientation[0], 0, 1, 0);
1468       glCullFace(GL_FRONT);
1469       draw_coloured_cone(length, 1.2*length, 16, axes->priv->orientation[2]);
1470       glCullFace(GL_BACK);
1471       glPopMatrix();
1472 
1473       drawAxes(1.5*length, axes->priv->matrix, w, h, axes->priv->lineWidth,
1474                axes->priv->rgb, _("back"), TRUE, axes->priv->lbl);
1475     }
1476   else
1477     {
1478       glDisable(GL_DEPTH_TEST);
1479       drawAxes(length, axes->priv->matrix, w, h, axes->priv->lineWidth,
1480                axes->priv->rgb, NULL, FALSE, axes->priv->lbl);
1481       glEnable(GL_DEPTH_TEST);
1482     }
1483   glPushMatrix();
1484   glMatrixMode(GL_PROJECTION);
1485   glPopMatrix();
1486   glMatrixMode(GL_MODELVIEW);
1487   /* Back to the main viewport. */
1488   glViewport(0, 0, axes->priv->view->window.width, axes->priv->view->window.height);
1489 
1490   visu_gl_ext_completeDrawing(ext);
1491 }
1492 
1493 /*************************/
1494 /* Parameters & resources*/
1495 /*************************/
1496 /* Export function that is called by visu_module to write the
1497    values of resources to a file. */
exportResources(GString * data,VisuData * dataObj _U_)1498 static void exportResources(GString *data, VisuData *dataObj _U_)
1499 {
1500   if (!defaultAxes)
1501     return;
1502 
1503   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_USED);
1504   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_USED, NULL,
1505                                "%d", visu_gl_ext_getActive(VISU_GL_EXT(defaultAxes)));
1506 
1507   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_COLOR);
1508   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_COLOR, NULL,
1509                                "%4.3f %4.3f %4.3f", defaultAxes->priv->rgb[0],
1510                                defaultAxes->priv->rgb[1], defaultAxes->priv->rgb[2]);
1511 
1512   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_LINE);
1513   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_LINE, NULL,
1514                                "%4.0f", defaultAxes->priv->lineWidth);
1515 
1516   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_STIPPLE);
1517   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_STIPPLE, NULL,
1518                                "%d", defaultAxes->priv->lineStipple);
1519 
1520   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_POSITION);
1521   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_POSITION, NULL,
1522                                "%4.3f %4.3f", defaultAxes->priv->xpos,
1523                                defaultAxes->priv->ypos);
1524 
1525   visu_config_file_exportComment(data, DESC_RESOURCE_AXES_LABEL);
1526   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_LABEL_X, NULL,
1527                                "%s", defaultAxes->priv->lbl[TOOL_XYZ_X]);
1528   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_LABEL_Y, NULL,
1529                                "%s", defaultAxes->priv->lbl[TOOL_XYZ_Y]);
1530   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_LABEL_Z, NULL,
1531                                "%s", defaultAxes->priv->lbl[TOOL_XYZ_Z]);
1532 
1533   visu_config_file_exportEntry(data, FLAG_RESOURCE_AXES_FACTOR, NULL,
1534                                "%4.3f", defaultAxes->priv->lgFact);
1535 
1536   visu_config_file_exportComment(data, "");
1537 }
1538