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-2014 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 <glib.h> // for g_set_error, GError etc
27 #include "hkl-error-private.h" // for hkl_error_clear, _HklError
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.h" // for HklGeometry, HklEngine, etc
34 #include "hkl/ccan/autodata/autodata.h" // for autodata_get
35 #include "hkl/ccan/darray/darray.h" // for darray_foreach, darray_size
36 #include "hkl/ccan/list/list.h" // for list_for_each, list_head
45 * return all the Hkl factories objects as a dictionnary
47 * Returns: (element-type utf8 Hkl.Factory) (transfer container):
49 GHashTable
*hkl_factories(void)
51 GHashTable
*table
= NULL
;
54 HklFactory
**factories
;
56 table
= g_hash_table_new(g_str_hash
, g_str_equal
);
57 factories
= autodata_get(factories
, &n
);
59 g_hash_table_insert(table
,
60 (gpointer
)hkl_factory_name(factories
[i
]),
75 * Returns: (element-type HklParameter) (transfer container): list of HklParameter,
76 * free the list with g_slist_free when done.
78 GSList
*hkl_geometry_axes(HklGeometry
*self
)
83 darray_foreach(axis
, self
->axes
){
84 list
= g_slist_append(list
, *axis
);
92 * hkl_geometry_get_axes_values_unit:
94 * @len: (out caller-allocates): the length of the returned array
96 * Return value: (array length=len) (transfer container): list of axes values,
97 * free the list with free when done.
99 double *hkl_geometry_get_axes_values_unit(const HklGeometry
*self
, guint
*len
)
105 if(!self
|| !len
|| darray_size(self
->axes
) == 0)
108 *len
= darray_size(self
->axes
);
109 values
= malloc(darray_size(self
->axes
) * sizeof(*values
));
111 darray_foreach(axis
, self
->axes
){
112 values
[i
++] = hkl_parameter_value_unit_get(*axis
);
119 * hkl_geometry_set_axes_values_unit:
120 * @self: the this ptr
121 * @values: (array length=len): the values to set.
122 * @len: the length of the values array.
124 void hkl_geometry_set_axes_values_unit(HklGeometry
*self
, double *values
, unsigned int len
)
129 if (!self
|| !values
|| len
!= darray_size(self
->axes
))
132 darray_foreach(axis
, self
->axes
){
133 hkl_parameter_value_unit_set(*axis
,
138 hkl_geometry_update(self
);
141 /*******************/
142 /* HklGeometryList */
143 /*******************/
146 * hkl_geometry_list_items:
147 * @self: the #HklGeometryList
149 * Return value: (element-type HklGeometryListItem) (transfer container): list of items,
150 * free the list with g_slist_free when done.
152 GSList
* hkl_geometry_list_items(HklGeometryList
*self
)
155 HklGeometryListItem
*item
;
157 list_for_each(&self
->items
, item
, list
)
158 list
= g_slist_append(list
, item
);
163 /***********************/
164 /* HklGeometryListItem */
165 /***********************/
168 * hkl_geometry_list_item_geometry:
169 * @self: the this ptr
171 * Return value: The geometry contain inside the HklGeometryListItem
173 const HklGeometry
*hkl_geometry_list_item_geometry(const HklGeometryListItem
*self
)
175 return hkl_geometry_list_item_geometry_get(self
);
182 #define HKL_ENGINE_ERROR hkl_engine_error_quark ()
184 GQuark
hkl_engine_error_quark (void)
186 return g_quark_from_static_string ("hkl-pseudo-axis-engine-error-quark");
190 HKL_ENGINE_ERROR_SET
/* can not set the pseudo axis engine */
195 * hkl_engine_modes_get_binding:
196 * @self: the this ptr
197 * @length: (out caller-allocates): return the length of the returned array.
199 * Rename to: hkl_engine_modes_get
201 * Return value: (array length=length) (transfer none): All the modes supported by the #HklEngine
203 const char **hkl_engine_modes_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_parameters_names_get_binding:
211 * @self: the this ptr
212 * @length: (out caller-allocates): return the length of the returned array.
214 * Rename to: hkl_engine_parameters_names_get
216 * Return value: (array length=length) (transfer none): All the parameters of #HklEngine.
218 const char **hkl_engine_parameters_names_get_binding(const HklEngine
*self
, size_t *length
)
220 *length
= darray_size(self
->mode
->parameters_names
);
221 return &darray_item(self
->mode
->parameters_names
, 0);
225 * hkl_engine_pseudo_axes_values_get_binding:
226 * @self: the this ptr
227 * @len: (out caller-allocates): the length of the returned array
229 * Rename to: hkl_engine_pseudo_axes_values_get
231 * Return value: (array length=len) (transfer container): list of pseudo axes values,
232 * free the list with free when done.
234 double *hkl_engine_pseudo_axes_values_get_binding(const HklEngine
*self
, guint
*len
)
240 if(!self
|| !len
|| darray_size(self
->pseudo_axes
) == 0)
243 *len
= darray_size(self
->pseudo_axes
);
244 values
= malloc(darray_size(self
->pseudo_axes
) * sizeof(*values
));
246 darray_foreach(axis
, self
->pseudo_axes
){
247 values
[i
++] = hkl_parameter_value_unit_get(*axis
);
254 * hkl_engine_set_values_unit:
255 * @self: the this ptr
256 * @values: (array length=len): the values to set
257 * @len: the len of the values array
258 * @error: return location of a GError or NULL
260 * compute the #HklGeometry angles for this #HklEngine
262 * Return value: TRUE on success or FALSE if an error occurred
264 gboolean
hkl_engine_set_values_unit(HklEngine
*self
,
265 double values
[], unsigned int len
,
268 HklParameter
**pseudo_axis
;
270 HklError
*err
= NULL
;
272 g_return_val_if_fail(error
== NULL
||*error
== NULL
, FALSE
);
274 if(len
!= self
->info
->n_pseudo_axes
)
277 darray_foreach(pseudo_axis
, self
->pseudo_axes
){
278 if(!hkl_parameter_value_unit_set(*pseudo_axis
, values
[i
++], &err
)){
279 g_assert(&err
== NULL
|| err
!= NULL
);
283 HKL_ENGINE_ERROR_SET
,
284 strdup(err
->message
));
286 hkl_error_clear(&err
);
292 if(!hkl_engine_set(self
, &err
)){
293 g_assert(&err
== NULL
|| err
!= NULL
);
297 HKL_ENGINE_ERROR_SET
,
298 strdup(err
->message
));
300 hkl_error_clear(&err
);
304 g_assert(error
!= NULL
||*error
!= NULL
);
310 * hkl_engine_list_engines_get_as_gslist:
311 * @self: the this ptr
313 * Return value: (element-type HklEngine) (transfer container): list of engines,
314 * free the list with g_slist_free when done.
316 * Rename to: hkl_engine_list_engines_get
318 GSList
* hkl_engine_list_engines_get_as_gslist(HklEngineList
*self
)
323 darray_foreach(engine
, *self
){
324 list
= g_slist_append(list
, *engine
);
335 * hkl_sample_reflections_get:
336 * @self: the this ptr
338 * Return value: (element-type HklSampleReflection) (transfer container): list of reflecions,
339 * free the list with g_slist_free when done.
341 const GSList
*hkl_sample_reflections_get(const HklSample
*self
)
344 HklSampleReflection
*reflection
;
346 list_for_each(&self
->reflections
, reflection
, list
){
347 list
= g_slist_append(list
, reflection
);
354 * hkl_sample_add_reflection_binding:
355 * @self: the this ptr
356 * @geometry: the geometry of the HklSampleReflection
357 * @detector: the detector of the HklSampleReflection
358 * @h: the h coordinate
359 * @k: the k coordinate
360 * @l: the l coordinate
362 * Return value: (element-type HklEngine) (transfer container): list of engines,
363 * free the list with g_slist_free when done.
365 * Rename to: hkl_sample_add_reflection
367 HklSampleReflection
*hkl_sample_add_reflection_binding(HklSample
*self
,
368 const HklGeometry
*geometry
,
369 const HklDetector
*detector
,
370 double h
, double k
, double l
)
372 HklSampleReflection
*reflection
;
374 reflection
= hkl_sample_reflection_new(geometry
, detector
, h
, k
, l
);
375 hkl_sample_add_reflection(self
, reflection
);