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-2013 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 hkl_factory_name(factories
[i
]),
67 /********************/
68 /* HklParameterList */
69 /********************/
71 #define HKL_PARAMETER_LIST_ERROR hkl_parameter_list_error_quark ()
73 GQuark
hkl_parameter_list_error_quark (void)
75 return g_quark_from_static_string ("hkl-parameter-list-error-quark");
79 HKL_PARAMETER_LIST_ERROR_VALUES_SET
/* can not set the parameter list values */
80 } HklParameterListError
;
83 * hkl_parameter_list_values_unit_set_binding:
85 * @values: (array length=len): the values to set
86 * @len: the length of the values
87 * @error: error set if something goes wrong
89 * set the parameter list with the given values
91 * Rename to: hkl_parameter_list_values_unit_set
93 * Return value: true if succeed or false otherwise
95 gboolean
hkl_parameter_list_values_unit_set_binding(HklParameterList
*self
,
96 double values
[], uint len
,
101 g_return_val_if_fail(error
== NULL
||*error
== NULL
, FALSE
);
103 if(!hkl_parameter_list_values_unit_set(self
,
105 g_assert(&err
== NULL
|| err
!= NULL
);
108 HKL_PARAMETER_LIST_ERROR
,
109 HKL_PARAMETER_LIST_ERROR_VALUES_SET
,
110 strdup(err
->message
));
112 hkl_error_clear(&err
);
120 * hkl_parameter_list_parameters:
121 * @self: the this ptr
123 * Return value: (element-type HklParameter) (transfer container): list of parameters
124 * free the list with g_slist_free when done.
126 GSList
* hkl_parameter_list_parameters(HklParameterList
*self
)
129 HklParameter
**parameter
;
131 darray_foreach(parameter
, *self
){
132 list
= g_slist_append(list
, *parameter
);
144 * @self: the this ptr
146 * Returns: (element-type HklParameter) (transfer container): list of HklParameter,
147 * free the list with g_slist_free when done.
149 GSList
*hkl_geometry_axes(HklGeometry
*self
)
154 darray_foreach(axis
, self
->axes
){
155 list
= g_slist_append(list
, *axis
);
163 * hkl_geometry_get_axes_values_unit:
164 * @self: the this ptr
165 * @len: (out caller-allocates): the length of the returned array
167 * Return value: (array length=len) (transfer container): list of axes values,
168 * free the list with free when done.
170 double *hkl_geometry_get_axes_values_unit(const HklGeometry
*self
, guint
*len
)
176 if(!self
|| !len
|| darray_size(self
->axes
) == 0)
179 *len
= darray_size(self
->axes
);
180 values
= malloc(darray_size(self
->axes
) * sizeof(*values
));
182 darray_foreach(axis
, self
->axes
){
183 values
[i
++] = hkl_parameter_value_unit_get(*axis
);
190 * hkl_geometry_set_axes_values_unit:
191 * @self: the this ptr
192 * @values: (array length=len): the values to set.
193 * @len: the length of the values array.
195 void hkl_geometry_set_axes_values_unit(HklGeometry
*self
, double *values
, unsigned int len
)
200 if (!self
|| !values
|| len
!= darray_size(self
->axes
))
203 darray_foreach(axis
, self
->axes
){
204 hkl_parameter_value_unit_set(*axis
,
209 hkl_geometry_update(self
);
212 /*******************/
213 /* HklGeometryList */
214 /*******************/
217 * hkl_geometry_list_items:
218 * @self: the #HklGeometryList
220 * Return value: (element-type HklGeometryListItem) (transfer container): list of items,
221 * free the list with g_slist_free when done.
223 GSList
* hkl_geometry_list_items(HklGeometryList
*self
)
226 HklGeometryListItem
**item
;
228 darray_foreach(item
, self
->items
){
229 list
= g_slist_append(list
, *item
);
235 /***********************/
236 /* HklGeometryListItem */
237 /***********************/
240 * hkl_geometry_list_item_geometry:
241 * @self: the this ptr
243 * Return value: The geometry contain inside the HklGeometryListItem
245 const HklGeometry
*hkl_geometry_list_item_geometry(const HklGeometryListItem
*self
)
247 return hkl_geometry_list_item_geometry_get(self
);
254 #define HKL_ENGINE_ERROR hkl_engine_error_quark ()
256 GQuark
hkl_engine_error_quark (void)
258 return g_quark_from_static_string ("hkl-pseudo-axis-engine-error-quark");
262 HKL_ENGINE_ERROR_SET
/* can not set the pseudo axis engine */
267 * hkl_engine_modes_get_as_gslist:
268 * @self: the this ptr
270 * Return value: (element-type HklMode) (transfer container): list of mode,
271 * free the list with g_slist_free when done.
273 * Rename to: hkl_engine_modes_get
275 GSList
* hkl_engine_modes_get_as_gslist(HklEngine
*self
)
280 darray_foreach(mode
, self
->modes
){
281 list
= g_slist_append(list
, *mode
);
288 * hkl_engine_set_values_unit:
289 * @self: the this ptr
290 * @values: (array length=len): the values to set
291 * @len: the len of the values array
292 * @error: return location of a GError or NULL
294 * compute the #HklGeometry angles for this #HklEngine
296 * Return value: TRUE on success or FALSE if an error occurred
298 gboolean
hkl_engine_set_values_unit(HklEngine
*self
,
299 double values
[], unsigned int len
,
302 HklParameter
*parameter
;
304 HklError
*err
= NULL
;
306 g_return_val_if_fail(error
== NULL
||*error
== NULL
, FALSE
);
308 if(len
!= self
->info
->n_pseudo_axes
)
311 if(!hkl_parameter_list_values_unit_set(&self
->pseudo_axes
,
313 g_assert(&err
== NULL
|| err
!= NULL
);
317 HKL_ENGINE_ERROR_SET
,
318 strdup(err
->message
));
320 hkl_error_clear(&err
);
325 if(!hkl_engine_set(self
, &err
)){
326 g_assert(&err
== NULL
|| err
!= NULL
);
330 HKL_ENGINE_ERROR_SET
,
331 strdup(err
->message
));
333 hkl_error_clear(&err
);
337 g_assert(error
!= NULL
||*error
!= NULL
);
343 * hkl_engine_list_engines_as_gslist:
344 * @self: the this ptr
346 * Return value: (element-type HklEngine) (transfer container): list of engines,
347 * free the list with g_slist_free when done.
349 * Rename to: hkl_engine_list_engines
351 GSList
* hkl_engine_list_engines_as_gslist(HklEngineList
*self
)
356 darray_foreach(engine
, *self
){
357 list
= g_slist_append(list
, *engine
);
368 * hkl_sample_reflections_get:
369 * @self: the this ptr
371 * Return value: (element-type HklSampleReflection) (transfer container): list of reflecions,
372 * free the list with g_slist_free when done.
374 const GSList
*hkl_sample_reflections_get(const HklSample
*self
)
377 HklSampleReflection
*reflection
;
379 list_for_each(&self
->reflections
, reflection
, list
){
380 list
= g_slist_append(list
, reflection
);
387 * hkl_sample_add_reflection_binding:
388 * @self: the this ptr
389 * @geometry: the geometry of the HklSampleReflection
390 * @detector: the detector of the HklSampleReflection
391 * @h: the h coordinate
392 * @k: the k coordinate
393 * @l: the l coordinate
395 * Return value: (element-type HklEngine) (transfer container): list of engines,
396 * free the list with g_slist_free when done.
398 * Rename to: hkl_sample_add_reflection
400 HklSampleReflection
*hkl_sample_add_reflection_binding(HklSample
*self
,
401 const HklGeometry
*geometry
,
402 const HklDetector
*detector
,
403 double h
, double k
, double l
)
405 HklSampleReflection
*reflection
;
407 reflection
= hkl_sample_reflection_new(geometry
, detector
, h
, k
, l
);
408 hkl_sample_add_reflection(self
, reflection
);