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 "iface_pointset.h"
45 
46 #include "config.h"
47 
48 /**
49  * SECTION:iface_pointset
50  * @short_description: Defines a common interface for objects with
51  * points inside a box that can be translated or expanded.
52  * @See_also: #VisuData, #VisuSurface, #VisuScalarField
53  * @Title: VisuPointset
54  *
55  * <para></para>
56  */
57 
58 enum {
59   PROP_0,
60   PROP_USE_TRANS,
61   PROP_TRANS,
62   PROP_RED_TRANS,
63   PROP_MODULO,
64   N_PROPS
65 };
66 static GParamSpec *properties[N_PROPS];
67 
68 /* enum */
69 /*   { */
70 /*     NB_SIGNAL */
71 /*   }; */
72 
73 /* /\* Internal variables. *\/ */
74 /* static guint _signals[NB_SIGNAL] = { 0 }; */
75 
76 /* Pointset interface. */
G_DEFINE_INTERFACE(VisuPointset,visu_pointset,VISU_TYPE_BOXED)77 G_DEFINE_INTERFACE(VisuPointset, visu_pointset, VISU_TYPE_BOXED)
78 
79 static void visu_pointset_default_init(VisuPointsetInterface *iface)
80 {
81   /**
82    * VisuPointset::use-translation:
83    *
84    * Wether translations are applied or not.
85    *
86    * Since: 3.8
87    */
88   properties[PROP_USE_TRANS] =
89     g_param_spec_boolean("use-translation", "Use translation",
90                          "Use translations along all axis", FALSE, G_PARAM_READWRITE);
91   g_object_interface_install_property(iface, properties[PROP_USE_TRANS]);
92 
93   /**
94    * VisuPointset::translation:
95    *
96    * The translation applied on [x,y,z] axis.
97    *
98    * Since: 3.8
99    */
100   properties[PROP_TRANS] =
101     g_param_spec_boxed("translation", "Translations along all axis",
102                        "Translations along all axis", TOOL_TYPE_VECTOR, G_PARAM_READWRITE);
103   g_object_interface_install_property(iface, properties[PROP_TRANS]);
104 
105   /**
106    * VisuPointset::reduced-translation:
107    *
108    * The translation applied on the box axis, normalised by box lengths.
109    *
110    * Since: 3.8
111    */
112   properties[PROP_RED_TRANS] =
113     g_param_spec_boxed("reduced-translation", "Translations along box axis",
114                        "Translations along box axis", TOOL_TYPE_VECTOR, G_PARAM_READWRITE);
115   g_object_interface_install_property(iface, properties[PROP_RED_TRANS]);
116 
117   /**
118    * VisuPointset::in-the-box:
119    *
120    * The status of the position of all nodes.
121    *
122    * Since: 3.8
123    */
124   properties[PROP_MODULO] =
125     g_param_spec_boolean("in-the-box", "Constrain nodes in the box",
126                          "All nodes are constrained in the box", FALSE, G_PARAM_READWRITE);
127   g_object_interface_install_property(iface, properties[PROP_MODULO]);
128 }
129 
130 /**
131  * visu_pointset_getTranslation:
132  * @self: a #VisuPointset object.
133  * @trans: (array fixed-size=3) (out): a location to store the
134  * translation values.
135  *
136  * Retrieves the translations of @self.
137  *
138  * Since: 3.8
139  **/
visu_pointset_getTranslation(VisuPointset * self,float trans[3])140 void visu_pointset_getTranslation(VisuPointset *self, float trans[3])
141 {
142   g_return_if_fail(VISU_IS_POINTSET(self));
143 
144   VISU_POINTSET_GET_INTERFACE(self)->get_translation(self, trans);
145 }
146 /**
147  * visu_pointset_setTranslation:
148  * @self: a #VisuPointset object.
149  * @trans: (array fixed-size=3): the translations.
150  * @withModulo: a boolean.
151  *
152  * Apply the given translation values to @self. If @withModulo is
153  * given, all points inside the pointset will be shifted inside the
154  * periodic cell.
155  *
156  * Since: 3.8
157  *
158  * Returns: FALSE @pointset was already pointset with the #VisuBox of @box.
159  **/
visu_pointset_setTranslation(VisuPointset * self,float trans[3],gboolean withModulo)160 gboolean visu_pointset_setTranslation(VisuPointset *self, float trans[3], gboolean withModulo)
161 {
162   g_return_val_if_fail(VISU_IS_POINTSET(self), FALSE);
163 
164   return VISU_POINTSET_GET_INTERFACE(self)->set_translation(self, trans, withModulo);
165 }
166 /**
167  * visu_pointset_setTranslationActive:
168  * @self: a #VisuPointset object.
169  * @status: a boolean.
170  *
171  * Set the if the translations are applied or not to @self.
172  *
173  * Since: 3.8
174  *
175  * Returns: TRUE if status is changed.
176  **/
visu_pointset_setTranslationActive(VisuPointset * self,gboolean status)177 gboolean visu_pointset_setTranslationActive(VisuPointset *self, gboolean status)
178 {
179   g_return_val_if_fail(VISU_IS_POINTSET(self), FALSE);
180 
181   return VISU_POINTSET_GET_INTERFACE(self)->set_translationActive(self, status);
182 }
183 /**
184  * visu_pointset_shift:
185  * @self: a #VisuPointset object.
186  * @delta: (array fixed-size=3): a translation.
187  * @withModulo: a boolean.
188  *
189  * Shift the translation by @delta.
190  *
191  * Since: 3.8
192  *
193  * Returns: TRUE if translation is changed.
194  **/
visu_pointset_shift(VisuPointset * self,const gfloat delta[3],gboolean withModulo)195 gboolean visu_pointset_shift(VisuPointset *self, const gfloat delta[3],
196                              gboolean withModulo)
197 {
198   gfloat trans[3];
199 
200   visu_pointset_getTranslation(self, trans);
201   trans[0] += delta[0];
202   trans[1] += delta[1];
203   trans[2] += delta[2];
204   return visu_pointset_setTranslation(self, trans, withModulo);
205 }
206 
207 /**
208  * visu_pointset_setInTheBox:
209  * @self: a #VisuPointset object.
210  * @status: a boolean.
211  *
212  * Update all node positions inside @self to be constrained inside the
213  * box (@status is TRUE), or release all previous position shift to
214  * original position without constrain (@status is FALSE).
215  *
216  * Since: 3.8
217  *
218  * Returns: TRUE, if any node has changed position.
219  **/
visu_pointset_setInTheBox(VisuPointset * self,gboolean status)220 gboolean visu_pointset_setInTheBox(VisuPointset *self, gboolean status)
221 {
222   g_return_val_if_fail(VISU_IS_POINTSET(self), FALSE);
223 
224   return VISU_POINTSET_GET_INTERFACE(self)->set_inTheBox(self, status);
225 }
226 
227 /**
228  * visu_pointset_setTranslationPeriodic:
229  * @self: a #VisuPointset object ;
230  * @trans: (in) (array fixed-size=3): an array of floating point
231  * values.
232  * @withModulo: a boolean.
233  *
234  * This sets the translations of the specified #VisuPointset only in
235  * periodic boundary conditions. Points are also constrainted inside
236  * the box in the periodic directions if @withModulo is TRUE.
237  *
238  * Returns: TRUE if any translations have been changed.
239  */
visu_pointset_setTranslationPeriodic(VisuPointset * self,float trans[3],gboolean withModulo)240 gboolean visu_pointset_setTranslationPeriodic(VisuPointset* self, float trans[3],
241                                               gboolean withModulo)
242 {
243   VisuBoxBoundaries bc;
244   float xyz_[3];
245 
246   g_return_val_if_fail(VISU_IS_POINTSET(self), FALSE);
247 
248   visu_pointset_getTranslation(self, xyz_);
249   bc = visu_box_getBoundary(visu_boxed_getBox(VISU_BOXED(self)));
250   if (bc & TOOL_XYZ_MASK_X)
251     xyz_[0] = trans[0];
252   if (bc & TOOL_XYZ_MASK_Y)
253     xyz_[1] = trans[1];
254   if (bc & TOOL_XYZ_MASK_Z)
255     xyz_[2] = trans[2];
256 
257   return visu_pointset_setTranslation(self, xyz_, withModulo);
258 }
259 /**
260  * visu_pointset_setBoxTranslation:
261  * @self: a #VisuPointset object ;
262  * @boxTrans: (in) (array fixed-size=3): an array of floating point
263  * values.
264  * @withModulo: a boolean.
265  *
266  * This sets the translations of the specified #VisuPointset only along
267  * periodic axis. The translation @boxTrans gives normalized values
268  * along all box axis. Points are also constrainted inside
269  * the box in the periodic directions if @withModulo is TRUE.
270  *
271  * Since: 3.8
272  *
273  * Returns: TRUE if any translations have been changed.
274  **/
visu_pointset_setBoxTranslation(VisuPointset * self,float boxTrans[3],gboolean withModulo)275 gboolean visu_pointset_setBoxTranslation(VisuPointset* self, float boxTrans[3],
276                                          gboolean withModulo)
277 {
278   VisuBox *box;
279   gfloat trans[3], orig[3];
280   float zeros[3] = {0.f, 0.f, 0.f};
281 
282   box = visu_boxed_getBox(VISU_BOXED(self));
283   visu_box_convertBoxCoordinatestoXYZ(box, orig, zeros);
284   visu_box_convertBoxCoordinatestoXYZ(box, trans, boxTrans);
285   trans[0] -= orig[0];
286   trans[1] -= orig[1];
287   trans[2] -= orig[2];
288   return visu_pointset_setTranslationPeriodic(self, trans, withModulo);
289 }
290 /**
291  * visu_pointset_getTranslationPeriodicStatus:
292  * @self: a #VisuPointset object.
293  *
294  * Tests if any of the translation in the periodic boundary
295  * conditions are not null.
296  *
297  * Since: 3.8
298  *
299  * Returns: TRUE if any of the translation in the periodic boundary
300  * conditions are not null.
301  **/
visu_pointset_getTranslationPeriodicStatus(VisuPointset * self)302 gboolean visu_pointset_getTranslationPeriodicStatus(VisuPointset *self)
303 {
304   VisuBoxBoundaries bc;
305   float xyz_[3];
306 
307   g_return_val_if_fail(VISU_IS_POINTSET(self), FALSE);
308 
309   visu_pointset_getTranslation(self, xyz_);
310   bc = visu_box_getBoundary(visu_boxed_getBox(VISU_BOXED(self)));
311   return ((bc & TOOL_XYZ_MASK_X) && xyz_[0] != 0.f) ||
312     ((bc & TOOL_XYZ_MASK_Y) && xyz_[1] != 0.f) ||
313     ((bc & TOOL_XYZ_MASK_Z) && xyz_[2] != 0.f);
314 }
315 /**
316  * visu_pointset_applyTranslation:
317  * @self: a #VisuPointset object.
318  *
319  * Apply all the translation (node and box) on each node coordinates
320  * and reset both translations to zero.
321  *
322  * Since: 3.8
323  **/
visu_pointset_applyTranslation(VisuPointset * self)324 void visu_pointset_applyTranslation(VisuPointset *self)
325 {
326   g_return_if_fail(VISU_IS_POINTSET(self));
327 
328   VISU_POINTSET_GET_INTERFACE(self)->apply_translation(self);
329 }
330