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-2019, 2022, 2023 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.h" // for HklGeometry, HklEngine, etc
27 #include "hkl-binding-private.h"
28 #include "hkl-factory-private.h" // for __start_xautodata_factories, etc
29 #include "hkl-geometry-private.h" // for _HklGeometry, etc
30 #include "hkl-parameter-private.h"
31 #include "hkl-pseudoaxis-private.h" // for _HklEngine, HklEngineInfo
32 #include "hkl-sample-private.h" // for _HklSampleReflection, etc
33 #include "hkl/ccan/autodata/autodata.h" // for autodata_get
34 #include "hkl/ccan/darray/darray.h" // for darray_foreach, darray_size
35 #include "hkl/ccan/list/list.h" // for list_for_each, list_head
42 * hkl_quaternion_to_matrix_binding: (rename-to hkl_quaternion_to_matrix)
43 * @self: the #HklQuaternion use to compute the #HklMatrix
45 * Returns: (transfer full): the @HklQuaternion@ as a @HklMatrix@.
47 HklMatrix
*hkl_quaternion_to_matrix_binding(const HklQuaternion
*self
)
49 HklMatrix
*m
= hkl_matrix_new();
51 hkl_quaternion_to_matrix(self
, m
);
64 * return all the Hkl factories objects as a dictionnary
66 * Returns: (element-type utf8 Hkl.Factory) (transfer container):
68 GHashTable
*hkl_factories(void)
70 GHashTable
*table
= NULL
;
72 HklFactory
**factories
;
74 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
75 factories
= autodata_get(factories
, &n
);
77 g_hash_table_insert(table
,
78 (gpointer
)hkl_factory_name_get(factories
[i
]),
90 * hkl_geometry_axis_names_get_binding: (rename-to hkl_geometry_axis_names_get)
92 * @length: (out caller-allocates): the length of the returned array
94 * get all the axes of the given geometry.
96 * Returns: (array length=length) (transfer none): array of the axes names.
98 const char **hkl_geometry_axis_names_get_binding(const HklGeometry
*self
,
101 const darray_string
*axes
= hkl_geometry_axis_names_get(self
);
103 *length
= darray_size(*axes
);
105 return &darray_item(*axes
, 0);
109 * hkl_geometry_axis_values_get_binding: (rename-to hkl_geometry_axis_values_get)
110 * @self: the this ptr
111 * @len: (out caller-allocates): the length of the returned array
112 * @unit_type: the unit type (default or user) of the returned value
114 * Return value: (array length=len) (transfer container): list of axes values,
115 * free the list with free when done.
117 double *hkl_geometry_axis_values_get_binding(const HklGeometry
*self
, guint
*len
,
118 HklUnitEnum unit_type
)
124 if(darray_size(self
->axes
) == 0)
127 *len
= darray_size(self
->axes
);
128 values
= g_new(double, darray_size(self
->axes
));
130 darray_foreach(axis
, self
->axes
){
131 values
[i
++] = hkl_parameter_value_get(*axis
, unit_type
);
138 * hkl_geometry_sample_rotation_get_binding: (rename-to hkl_geometry_sample_rotation_get)
139 * @self: the self @HklGeometry@
140 * @sample: the rotated sample.
142 * return the rotation part of the given sample in the laboratory basis.
144 * Returns: (transfer full): the rotation express as a quaternion.
146 HklQuaternion
*hkl_geometry_sample_rotation_get_binding(const HklGeometry
*self
,
147 const HklSample
*sample
)
149 HklQuaternion q
= hkl_geometry_sample_rotation_get(self
, sample
);
151 return hkl_quaternion_dup(&q
);
155 * hkl_geometry_detector_rotation_get_binding: (rename-to hkl_geometry_detector_rotation_get)
156 * @self: the self #HklGeometry
158 * return the rotation part of the given detector in the laboratory
161 * Returns: (transfer full): the rotation express as a quaternion.
163 HklQuaternion
*hkl_geometry_detector_rotation_get_binding(const HklGeometry
*self
,
164 const HklDetector
*detector
)
166 HklQuaternion q
= hkl_geometry_detector_rotation_get(self
, detector
);
168 return hkl_quaternion_dup(&q
);
172 * hkl_geometry_ki_get_binding: (rename-to hkl_geometry_ki_get)
173 * @self: the self #HklGeometry
175 * return the ki vector in the laboratory
178 * Returns: (transfer full): the ki vector.
180 HklVector
*hkl_geometry_ki_get_binding(const HklGeometry
*self
)
182 HklVector v
= hkl_geometry_ki_get(self
);
184 return hkl_vector_dup(&v
);
188 * hkl_geometry_ki_abc_get_binding: (rename-to hkl_geometry_ki_abc_get)
189 * @self: the self #HklGeometry
190 * @sample: the sample to project into #HklSample.
192 * return the ki vector in the sample lattice recipocal.
195 * Returns: (transfer full): the ki vector.
197 HklVector
*hkl_geometry_ki_abc_get_binding(const HklGeometry
*self
,
198 const HklSample
*sample
)
200 HklVector v
= hkl_geometry_ki_abc_get(self
, sample
);
202 return hkl_vector_dup(&v
);
206 * hkl_geometry_kf_get_binding: (rename-to hkl_geometry_kf_get)
207 * @self: the self #HklGeometry
208 * @detector: the self #HklDetector
210 * return the kf vector in the laboratory
213 * Returns: (transfer full): the kf vector.
215 HklVector
*hkl_geometry_kf_get_binding(const HklGeometry
*self
,
216 const HklDetector
*detector
)
218 HklVector v
= hkl_geometry_kf_get(self
, detector
);
220 return hkl_vector_dup(&v
);
224 * hkl_geometry_kf_abc_get_binding: (rename-to hkl_geometry_kf_abc_get)
225 * @self: the self #HklGeometry
226 * @detector: the self #HklDetector
227 * @sample: the sample to project into #HklSample.
229 * return the kf vector in the laboratory
232 * Returns: (transfer full): the kf vector.
234 HklVector
*hkl_geometry_kf_abc_get_binding(const HklGeometry
*self
,
235 const HklDetector
*detector
,
236 const HklSample
*sample
)
238 HklVector v
= hkl_geometry_kf_abc_get(self
, detector
, sample
);
240 return hkl_vector_dup(&v
);
243 /*******************/
244 /* HklGeometryList */
245 /*******************/
248 * hkl_geometry_list_items:
249 * @self: the #HklGeometryList
251 * Return value: (element-type HklGeometryListItem) (transfer container): list of items,
252 * free the list with g_slist_free when done.
254 GSList
* hkl_geometry_list_items(HklGeometryList
*self
)
257 HklGeometryListItem
*item
;
259 list_for_each(&self
->items
, item
, list
)
260 list
= g_slist_append(list
, item
);
270 * hkl_engine_modes_names_get_binding: (rename-to hkl_engine_modes_names_get)
271 * @self: the this ptr
272 * @length: (out caller-allocates): return the length of the returned array.
274 * Return value: (array length=length) (transfer none): All the modes supported by the #HklEngine
276 const char **hkl_engine_modes_names_get_binding(const HklEngine
*self
, size_t *length
)
278 *length
= darray_size(self
->mode_names
);
279 return &darray_item(self
->mode_names
, 0);
283 * hkl_engine_pseudo_axis_names_get_binding: (rename-to hkl_engine_pseudo_axis_names_get)
284 * @self: the this ptr
285 * @length: (out caller-allocates): return the length of the returned array.
287 * Return value: (array length=length) (transfer none): All the pseudo_axes names of the #HklEngine
290 const char **hkl_engine_pseudo_axis_names_get_binding(HklEngine
*self
, size_t *length
)
292 *length
= darray_size(self
->pseudo_axis_names
);
293 return &darray_item(self
->pseudo_axis_names
, 0);
297 * hkl_engine_parameters_names_get_binding: (rename-to hkl_engine_parameters_names_get)
298 * @self: the this ptr
299 * @length: (out caller-allocates): return the length of the returned array.
301 * Return value: (array length=length) (transfer none): All the parameters of #HklEngine.
303 const char **hkl_engine_parameters_names_get_binding(const HklEngine
*self
, size_t *length
)
305 *length
= darray_size(self
->mode
->parameters_names
);
306 return &darray_item(self
->mode
->parameters_names
, 0);
310 * hkl_engine_axis_names_get_binding: (rename-to hkl_engine_axis_names_get)
311 * @self: the this ptr
312 * @mode: the #HklEngineAxesNamesGet
313 * @length: (out caller-allocates): return the length of the returned array.
315 * Return value: (array length=length) (transfer none): axes of the #HklEngine for the given mode.
317 const char **hkl_engine_axis_names_get_binding(const HklEngine
*self
,
318 HklEngineAxisNamesGet mode
,
321 const darray_string
*axes
= hkl_engine_axis_names_get(self
, mode
);
323 *length
= darray_size(*axes
);
325 return &darray_item(*axes
, 0);
329 * hkl_engine_parameters_values_get_binding: (rename-to hkl_engine_parameters_values_get)
330 * @self: the this ptr
331 * @len: (out caller-allocates): the length of the returned array
332 * @unit_type: the unit type (default or user) of the returned value
334 * Return value: (array length=len) (transfer container): list of parameters values,
335 * free the list with free when done.
337 double *hkl_engine_parameters_values_get_binding(const HklEngine
*self
, guint
*len
,
338 HklUnitEnum unit_type
)
342 HklParameter
**parameter
;
344 if(!self
->mode
|| darray_size(self
->mode
->parameters
) == 0)
347 *len
= darray_size(self
->mode
->parameters
);
348 values
= g_new(double, *len
);
350 darray_foreach(parameter
, self
->mode
->parameters
){
351 values
[i
++] = hkl_parameter_value_get(*parameter
, unit_type
);
358 * hkl_engine_pseudo_axis_values_get_binding: (rename-to hkl_engine_pseudo_axis_values_get)
359 * @self: the this ptr
360 * @len: (out caller-allocates): the length of the returned array
361 * @unit_type: the unit type (default or user) of the returned value
363 * Return value: (array length=len) (transfer container): list of pseudo axes values,
364 * free the list with free when done.
366 double *hkl_engine_pseudo_axis_values_get_binding(const HklEngine
*self
, guint
*len
,
367 HklUnitEnum unit_type
)
373 if(!self
|| !len
|| darray_size(self
->pseudo_axes
) == 0)
376 *len
= darray_size(self
->pseudo_axes
);
377 values
= g_new(double, *len
);
379 darray_foreach(axis
, self
->pseudo_axes
){
380 values
[i
++] = hkl_parameter_value_get(*axis
, unit_type
);
387 * hkl_engine_list_engines_get_as_gslist: (rename-to hkl_engine_list_engines_get)
388 * @self: the this ptr
390 * Return value: (element-type HklEngine) (transfer container): list of engines,
391 * free the list with g_slist_free when done.
393 GSList
* hkl_engine_list_engines_get_as_gslist(HklEngineList
*self
)
398 darray_foreach(engine
, *self
){
399 list
= g_slist_append(list
, *engine
);
410 * hkl_engine_list_parameters_names_get_binding: (rename-to hkl_engine_list_parameters_names_get)
411 * @self: the this ptr
412 * @length: (out caller-allocates): return the length of the returned array.
414 * Return value: (array length=length) (transfer none): All the modes supported by the #HklEngineList
416 const char **hkl_engine_list_parameters_names_get_binding(const HklEngineList
*self
, size_t *length
)
418 *length
= darray_size(self
->parameters_names
);
419 return &darray_item(self
->parameters_names
, 0);
423 * hkl_engine_list_parameters_values_get_binding: (rename-to hkl_engine_list_parameters_values_get)
424 * @self: the this ptr
425 * @len: (out caller-allocates): the length of the returned array
426 * @unit_type: the unit type (default or user) of the returned value
428 * Return value: (array length=len) (transfer container): list of parameters values,
429 * free the list with free when done.
431 double *hkl_engine_list_parameters_values_get_binding(const HklEngineList
*self
, guint
*len
,
432 HklUnitEnum unit_type
)
436 HklParameter
**parameter
;
438 if(darray_size(self
->parameters
) == 0)
441 *len
= darray_size(self
->parameters
);
442 values
= g_new(double, *len
);
444 darray_foreach(parameter
, self
->parameters
){
445 values
[i
++] = hkl_parameter_value_get(*parameter
, unit_type
);
456 * hkl_sample_reflections_get:
457 * @self: the this ptr
459 * Return value: (element-type HklSampleReflection) (transfer container): list of reflections,
460 * free the list with g_slist_free when done.
462 GSList
*hkl_sample_reflections_get(const HklSample
*self
)
465 HklSampleReflection
*reflection
;
467 list_for_each(&self
->reflections
, reflection
, list
){
468 list
= g_slist_append(list
, reflection
);
475 * hkl_sample_add_reflection_binding: (rename-to hkl_sample_add_reflection)
476 * @self: the this ptr
477 * @geometry: the geometry of the HklSampleReflection
478 * @detector: the detector of the HklSampleReflection
479 * @h: the h coordinate
480 * @k: the k coordinate
481 * @l: the l coordinate
482 * @error: return location for a GError, or NULL
484 * Return value: (transfer none): the newly created HklSampleReflection
486 HklSampleReflection
*hkl_sample_add_reflection_binding(HklSample
*self
,
487 const HklGeometry
*geometry
,
488 const HklDetector
*detector
,
489 double h
, double k
, double l
,
492 HklSampleReflection
*reflection
;
494 hkl_error (error
== NULL
|| *error
== NULL
);
496 reflection
= hkl_sample_reflection_new(geometry
, detector
,
499 hkl_assert (error
== NULL
|| *error
!= NULL
);
502 hkl_assert (error
== NULL
|| *error
== NULL
);
504 hkl_sample_add_reflection(self
, reflection
);