1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2012-2016 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
23 #include <stdlib.h> // for malloc
24 #include <string.h> // for NULL, strdup
25 #include <sys/types.h> // for uint
26 #include "hkl-factory-private.h" // for __start_xautodata_factories, etc
27 #include "hkl-geometry-private.h" // for _HklGeometry, etc
28 #include "hkl-parameter-private.h"
29 #include "hkl-pseudoaxis-private.h" // for _HklEngine, HklEngineInfo
30 #include "hkl-sample-private.h" // for _HklSampleReflection, etc
31 #include "hkl.h" // for HklGeometry, HklEngine, etc
32 #include "hkl/ccan/autodata/autodata.h" // for autodata_get
33 #include "hkl/ccan/darray/darray.h" // for darray_foreach, darray_size
34 #include "hkl/ccan/list/list.h" // for list_for_each, list_head
41 * hkl_quaternion_to_matrix_binding: (rename-to hkl_quaternion_to_matrix)
42 * @self: the #HklQuaternion use to compute the #HklMatrix
44 * Returns: (transfer full): the @HklQuaternion@ as a @HklMatrix@.
46 HklMatrix
*hkl_quaternion_to_matrix_binding(const HklQuaternion
*self
)
48 HklMatrix
*m
= hkl_matrix_new();
50 hkl_quaternion_to_matrix(self
, m
);
63 * return all the Hkl factories objects as a dictionnary
65 * Returns: (element-type utf8 Hkl.Factory) (transfer container):
67 GHashTable
*hkl_factories(void)
69 GHashTable
*table
= NULL
;
71 HklFactory
**factories
;
73 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
74 factories
= autodata_get(factories
, &n
);
76 g_hash_table_insert(table
,
77 (gpointer
)hkl_factory_name_get(factories
[i
]),
89 * hkl_geometry_axis_names_get_binding: (rename-to hkl_geometry_axis_names_get)
91 * @length: (out caller-allocates): the length of the returned array
93 * get all the axes of the given geometry.
95 * Returns: (array length=length) (transfer none): array of the axes names.
97 const char **hkl_geometry_axis_names_get_binding(const HklGeometry
*self
,
100 const darray_string
*axes
= hkl_geometry_axis_names_get(self
);
102 *length
= darray_size(*axes
);
104 return &darray_item(*axes
, 0);
108 * hkl_geometry_axis_values_get_binding: (rename-to hkl_geometry_axis_values_get)
109 * @self: the this ptr
110 * @len: (out caller-allocates): the length of the returned array
111 * @unit_type: the unit type (default or user) of the returned value
113 * Return value: (array length=len) (transfer container): list of axes values,
114 * free the list with free when done.
116 double *hkl_geometry_axis_values_get_binding(const HklGeometry
*self
, guint
*len
,
117 HklUnitEnum unit_type
)
123 if(!self
|| !len
|| darray_size(self
->axes
) == 0)
126 *len
= darray_size(self
->axes
);
127 values
= malloc(darray_size(self
->axes
) * sizeof(*values
));
129 darray_foreach(axis
, self
->axes
){
130 values
[i
++] = hkl_parameter_value_get(*axis
, unit_type
);
137 * hkl_geometry_sample_rotation_get_binding: (rename-to hkl_geometry_sample_rotation_get)
138 * @self: the self @HklGeometry@
139 * @sample: the rotated sample.
141 * return the rotation part of the given sample in the laboratory basis.
143 * Returns: (transfer full): the rotation express as a quaternion.
145 HklQuaternion
*hkl_geometry_sample_rotation_get_binding(const HklGeometry
*self
,
146 const HklSample
*sample
)
148 HklQuaternion q
= hkl_geometry_sample_rotation_get(self
, sample
);
150 return hkl_quaternion_dup(&q
);
154 * hkl_geometry_detector_rotation_get_binding: (rename-to hkl_geometry_detector_rotation_get)
155 * @self: the self @HklGeometry@
157 * return the rotation part of the given detector in the laboratory
160 * Returns: (transfer full): the rotation express as a quaternion.
162 HklQuaternion
*hkl_geometry_detector_rotation_get_binding(const HklGeometry
*self
,
163 const HklDetector
*detector
)
165 HklQuaternion q
= hkl_geometry_detector_rotation_get(self
, detector
);
167 return hkl_quaternion_dup(&q
);
170 /*******************/
171 /* HklGeometryList */
172 /*******************/
175 * hkl_geometry_list_items:
176 * @self: the #HklGeometryList
178 * Return value: (element-type HklGeometryListItem) (transfer container): list of items,
179 * free the list with g_slist_free when done.
181 GSList
* hkl_geometry_list_items(HklGeometryList
*self
)
184 HklGeometryListItem
*item
;
186 list_for_each(&self
->items
, item
, list
)
187 list
= g_slist_append(list
, item
);
197 * hkl_engine_modes_names_get_binding: (rename-to hkl_engine_modes_names_get)
198 * @self: the this ptr
199 * @length: (out caller-allocates): return the length of the returned array.
201 * Return value: (array length=length) (transfer none): All the modes supported by the #HklEngine
203 const char **hkl_engine_modes_names_get_binding(const HklEngine
*self
, size_t *length
)
205 *length
= darray_size(self
->mode_names
);
206 return &darray_item(self
->mode_names
, 0);
210 * hkl_engine_pseudo_axis_names_get_binding: (rename-to hkl_engine_pseudo_axis_names_get)
211 * @self: the this ptr
212 * @length: (out caller-allocates): return the length of the returned array.
214 * Return value: (array length=length) (transfer none): All the pseudo_axes names of the #HklEngine
217 const char **hkl_engine_pseudo_axis_names_get_binding(HklEngine
*self
, size_t *length
)
219 *length
= darray_size(self
->pseudo_axis_names
);
220 return &darray_item(self
->pseudo_axis_names
, 0);
224 * hkl_engine_parameters_names_get_binding: (rename-to hkl_engine_parameters_names_get)
225 * @self: the this ptr
226 * @length: (out caller-allocates): return the length of the returned array.
228 * Return value: (array length=length) (transfer none): All the parameters of #HklEngine.
230 const char **hkl_engine_parameters_names_get_binding(const HklEngine
*self
, size_t *length
)
232 *length
= darray_size(self
->mode
->parameters_names
);
233 return &darray_item(self
->mode
->parameters_names
, 0);
237 * hkl_engine_axis_names_get_binding: (rename-to hkl_engine_axis_names_get)
238 * @self: the this ptr
239 * @mode: the #HklEngineAxesNamesGet
240 * @length: (out caller-allocates): return the length of the returned array.
242 * Return value: (array length=length) (transfer none): axes of the #HklEngine for the given mode.
244 const char **hkl_engine_axis_names_get_binding(const HklEngine
*self
,
245 HklEngineAxisNamesGet mode
,
248 const darray_string
*axes
= hkl_engine_axis_names_get(self
, mode
);
250 *length
= darray_size(*axes
);
252 return &darray_item(*axes
, 0);
256 * hkl_engine_parameters_values_get_binding: (rename-to hkl_engine_parameters_values_get)
257 * @self: the this ptr
258 * @len: (out caller-allocates): the length of the returned array
259 * @unit_type: the unit type (default or user) of the returned value
261 * Return value: (array length=len) (transfer container): list of parameters values,
262 * free the list with free when done.
264 double *hkl_engine_parameters_values_get_binding(const HklEngine
*self
, guint
*len
,
265 HklUnitEnum unit_type
)
269 HklParameter
**parameter
;
271 if(!self
|| !len
|| !self
->mode
|| darray_size(self
->mode
->parameters
) == 0)
274 *len
= darray_size(self
->mode
->parameters
);
275 values
= malloc(*len
* sizeof(*values
));
277 darray_foreach(parameter
, self
->mode
->parameters
){
278 values
[i
++] = hkl_parameter_value_get(*parameter
, unit_type
);
285 * hkl_engine_pseudo_axis_values_get_binding: (rename-to hkl_engine_pseudo_axis_values_get)
286 * @self: the this ptr
287 * @len: (out caller-allocates): the length of the returned array
288 * @unit_type: the unit type (default or user) of the returned value
290 * Return value: (array length=len) (transfer container): list of pseudo axes values,
291 * free the list with free when done.
293 double *hkl_engine_pseudo_axis_values_get_binding(const HklEngine
*self
, guint
*len
,
294 HklUnitEnum unit_type
)
300 if(!self
|| !len
|| darray_size(self
->pseudo_axes
) == 0)
303 *len
= darray_size(self
->pseudo_axes
);
304 values
= malloc(darray_size(self
->pseudo_axes
) * sizeof(*values
));
306 darray_foreach(axis
, self
->pseudo_axes
){
307 values
[i
++] = hkl_parameter_value_get(*axis
, unit_type
);
314 * hkl_engine_list_engines_get_as_gslist: (rename-to hkl_engine_list_engines_get)
315 * @self: the this ptr
317 * Return value: (element-type HklEngine) (transfer container): list of engines,
318 * free the list with g_slist_free when done.
320 GSList
* hkl_engine_list_engines_get_as_gslist(HklEngineList
*self
)
325 darray_foreach(engine
, *self
){
326 list
= g_slist_append(list
, *engine
);
337 * hkl_sample_reflections_get:
338 * @self: the this ptr
340 * Return value: (element-type HklSampleReflection) (transfer container): list of reflections,
341 * free the list with g_slist_free when done.
343 GSList
*hkl_sample_reflections_get(const HklSample
*self
)
346 HklSampleReflection
*reflection
;
348 list_for_each(&self
->reflections
, reflection
, list
){
349 list
= g_slist_append(list
, reflection
);
356 * hkl_sample_add_reflection_binding: (rename-to hkl_sample_add_reflection)
357 * @self: the this ptr
358 * @geometry: the geometry of the HklSampleReflection
359 * @detector: the detector of the HklSampleReflection
360 * @h: the h coordinate
361 * @k: the k coordinate
362 * @l: the l coordinate
363 * @error: return location for a GError, or NULL
365 * Return value: (transfer none): the newly created HklSampleReflection
367 HklSampleReflection
*hkl_sample_add_reflection_binding(HklSample
*self
,
368 const HklGeometry
*geometry
,
369 const HklDetector
*detector
,
370 double h
, double k
, double l
,
373 HklSampleReflection
*reflection
;
375 hkl_error (error
== NULL
|| *error
== NULL
);
377 reflection
= hkl_sample_reflection_new(geometry
, detector
,
380 g_assert (error
== NULL
|| *error
!= NULL
);
383 g_assert (error
== NULL
|| *error
== NULL
);
385 hkl_sample_add_reflection(self
, reflection
);