remove the pseudo_axes_parameter treeview (useless)
[hkl.git] / gui / hkl-gui.c
blob589abde6cd3ebcc48857e2682a69df0d81570cbb
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) 2003-2010 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 "hkl-gui.h"
24 #include <glib.h>
25 #include <glib-object.h>
26 #include <gtk/gtk.h>
27 #include "hkl.h"
28 #include "hkl-gui-pseudoaxes.h"
29 #include <gdk/gdk.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <float.h>
33 #include <math.h>
34 #include <stdio.h>
36 #define HKL_GUI_TYPE_WINDOW (hkl_gui_window_get_type ())
37 #define HKL_GUI_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HKL_GUI_TYPE_WINDOW, HklGuiWindow))
38 #define HKL_GUI_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HKL_GUI_TYPE_WINDOW, HklGuiWindowClass))
39 #define HKL_GUI_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HKL_GUI_TYPE_WINDOW))
40 #define HKL_GUI_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HKL_GUI_TYPE_WINDOW))
41 #define HKL_GUI_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HKL_GUI_TYPE_WINDOW, HklGuiWindowClass))
43 #define EMBED_BREAKPOINT asm volatile ("int3;")
45 G_DEFINE_TYPE (HklGuiWindow, hkl_gui_window, G_TYPE_OBJECT);
47 typedef enum {
48 REFLECTION_COL_INDEX = 0,
49 REFLECTION_COL_H,
50 REFLECTION_COL_K,
51 REFLECTION_COL_L,
52 REFLECTION_COL_FLAG,
53 REFLECTION_COL_REFLECTION,
54 REFLECTION_COL_N_COLUMNS
55 } ReflectionCol;
57 typedef enum {
58 AXIS_COL_AXIS = 0,
59 AXIS_COL_NAME,
60 AXIS_COL_READ,
61 AXIS_COL_WRITE,
62 AXIS_COL_MIN,
63 AXIS_COL_MAX,
64 AXIS_COL_N_COLUMNS
65 } AxisCol;
67 typedef enum {
68 PSEUDO_AXIS_COL_PARAMETER = 0,
69 PSEUDO_AXIS_COL_ENGINE,
70 PSEUDO_AXIS_COL_NAME,
71 PSEUDO_AXIS_COL_READ,
72 PSEUDO_AXIS_COL_WRITE,
73 PSEUDO_AXIS_COL_N_COLUMNS
74 } PseudoAxisCol;
76 typedef enum {
77 PARAMETER_COL_PARAMETER = 0,
78 PARAMETER_COL_NAME,
79 PARAMETER_COL_VALUE,
80 PARAMETER_COL_N_COLUMNS
81 } ParameterCol;
83 typedef enum {
84 SAMPLE_COL_SAMPLE = 0,
85 SAMPLE_COL_NAME,
86 SAMPLE_COL_A,
87 SAMPLE_COL_B,
88 SAMPLE_COL_C,
89 SAMPLE_COL_ALPHA,
90 SAMPLE_COL_BETA,
91 SAMPLE_COL_GAMMA,
92 SAMPLE_COL_N_COLUMNS
93 } SampleCol;
95 typedef enum {
96 SOLUTION_COL_INDEX = 0,
97 SOLUTION_COL_N_COLUMNS
98 } SolutionCol;
100 typedef enum {
101 DIFFRACTOMETER_COL_NAME = 0,
102 DIFFRACTOMETER_COL_FACTORY,
103 DIFFRACTOMETER_COL_DIFFRACTOMETER,
104 DIFFRACTOMETER_COL_N_COLUMNS
105 } DiffractometerCol;
107 /******************/
108 /* Diffractometer */
109 /******************/
111 struct diffractometer_t {
112 HklGeometry *geometry;
113 HklDetector *detector;
114 HklEngineList *engines;
118 static struct diffractometer_t *
119 create_diffractometer(HklFactory *factory)
121 struct diffractometer_t *self;
123 self = malloc(sizeof(*self));
125 self->geometry = hkl_factory_create_new_geometry (factory);
126 self->engines = hkl_factory_create_new_engine_list (factory);
127 self->detector = hkl_detector_factory_new (HKL_DETECTOR_TYPE_0D);
128 hkl_detector_idx_set (self->detector, 1);
130 return self;
133 static void
134 delete_diffractometer(struct diffractometer_t *self)
136 hkl_geometry_free(self->geometry);
137 hkl_engine_list_free(self->engines);
138 hkl_detector_free(self->detector);
142 static void
143 dump_diffractometer(struct diffractometer_t *self)
145 /* hkl_geometry_fprintf(stderr, self->geometry); */
146 /* hkl_engine_list_fprintf(stderr, self->engines); */
147 /* hkl_detector_fprintf(stderr, self->detector); */
150 static void
151 diffractometer_get_pseudo(struct diffractometer_t *self)
153 hkl_engine_list_get(self->engines);
156 static void
157 diffractometer_engine_list_init(struct diffractometer_t *self,
158 HklSample *sample)
160 g_return_if_fail(self != NULL);
161 g_return_if_fail(sample != NULL);
163 hkl_engine_list_init(self->engines,
164 self->geometry,
165 self->detector,
166 sample);
167 diffractometer_get_pseudo(self);
170 /****************/
171 /* HklGuiWindow */
172 /****************/
174 struct _HklGuiWindowPrivate {
175 GtkBuilder* builder;
176 GtkLabel* _label_UB11;
177 GtkLabel* _label_UB12;
178 GtkLabel* _label_UB13;
179 GtkLabel* _label_UB21;
180 GtkLabel* _label_UB22;
181 GtkLabel* _label_UB23;
182 GtkLabel* _label_UB31;
183 GtkLabel* _label_UB32;
184 GtkLabel* _label_UB33;
185 GtkButton* _button2;
186 GtkSpinButton* _spinbutton_a;
187 GtkSpinButton* _spinbutton_b;
188 GtkSpinButton* _spinbutton_c;
189 GtkSpinButton* _spinbutton_alpha;
190 GtkSpinButton* _spinbutton_beta;
191 GtkSpinButton* _spinbutton_gamma;
192 GtkSpinButton* _spinbutton_a_min;
193 GtkSpinButton* _spinbutton_b_min;
194 GtkSpinButton* _spinbutton_c_min;
195 GtkSpinButton* _spinbutton_alpha_min;
196 GtkSpinButton* _spinbutton_beta_min;
197 GtkSpinButton* _spinbutton_gamma_min;
198 GtkSpinButton* _spinbutton_a_max;
199 GtkSpinButton* _spinbutton_b_max;
200 GtkSpinButton* _spinbutton_c_max;
201 GtkSpinButton* _spinbutton_alpha_max;
202 GtkSpinButton* _spinbutton_beta_max;
203 GtkSpinButton* _spinbutton_gamma_max;
204 GtkSpinButton* _spinbutton_lambda;
205 GtkSpinButton* _spinbutton_a_star;
206 GtkSpinButton* _spinbutton_b_star;
207 GtkSpinButton* _spinbutton_c_star;
208 GtkSpinButton* _spinbutton_alpha_star;
209 GtkSpinButton* _spinbutton_beta_star;
210 GtkSpinButton* _spinbutton_gamma_star;
211 GtkSpinButton* _spinbutton_ux;
212 GtkSpinButton* _spinbutton_uy;
213 GtkSpinButton* _spinbutton_uz;
214 GtkSpinButton* _spinbutton_U11;
215 GtkSpinButton* _spinbutton_U12;
216 GtkSpinButton* _spinbutton_U13;
217 GtkSpinButton* _spinbutton_U21;
218 GtkSpinButton* _spinbutton_U22;
219 GtkSpinButton* _spinbutton_U23;
220 GtkSpinButton* _spinbutton_U31;
221 GtkSpinButton* _spinbutton_U32;
222 GtkSpinButton* _spinbutton_U33;
223 GtkCheckButton* _checkbutton_a;
224 GtkCheckButton* _checkbutton_b;
225 GtkCheckButton* _checkbutton_c;
226 GtkCheckButton* _checkbutton_alpha;
227 GtkCheckButton* _checkbutton_beta;
228 GtkCheckButton* _checkbutton_gamma;
229 GtkCheckButton* _checkbutton_ux;
230 GtkCheckButton* _checkbutton_uy;
231 GtkCheckButton* _checkbutton_uz;
232 GtkTreeView* _treeview_reflections;
233 GtkTreeView* _treeview_crystals;
234 GtkTreeView* _treeview_axes;
235 GtkTreeView* _treeview_pseudo_axes;
236 GtkTreeView* _treeview_solutions;
237 GtkToolButton* _toolbutton_add_reflection;
238 GtkToolButton* _toolbutton_goto_reflection;
239 GtkToolButton* _toolbutton_del_reflection;
240 GtkToolButton* _toolbutton_setUB;
241 GtkToolButton* _toolbutton_computeUB;
242 GtkToolButton* _toolbutton_add_crystal;
243 GtkToolButton* _toolbutton_copy_crystal;
244 GtkToolButton* _toolbutton_del_crystal;
245 GtkToolButton* _toolbutton_affiner;
246 GtkStatusbar* _statusbar;
247 GtkImageMenuItem* _menuitem5;
248 GtkVBox* _box_info_bar; /* fake for the infor bar */
249 GtkVBox* _vbox7;
250 GtkVBox* _vbox2;
251 GtkDialog* _dialog1;
252 GtkButton* _button1;
253 GtkComboBox* _combobox1;
254 GtkListStore* _liststore_diffractometer;
255 GtkListStore* _liststore_axis;
256 GtkListStore* _liststore_pseudo_axes;
257 GtkListStore* _liststore_solutions;
258 GtkListStore* _liststore_reflections;
259 GtkListStore* _liststore_crystals;
261 GtkInfoBar *info_bar;
262 GtkLabel *info_message;
264 darray(HklGuiEngine *) pseudo_frames;
266 struct diffractometer_t *diffractometer; /* unowned */
267 HklSample *sample; /* unowned */
268 HklLattice *reciprocal;
271 #define HKL_GUI_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), HKL_GUI_TYPE_WINDOW, HklGuiWindowPrivate))
273 static gboolean
274 finalize_liststore_diffractometer(GtkTreeModel *model,
275 GtkTreePath *path,
276 GtkTreeIter *iter,
277 gpointer data)
279 struct diffractometer_t *diffractometer;
281 gtk_tree_model_get(model, iter,
282 DIFFRACTOMETER_COL_DIFFRACTOMETER, &diffractometer,
283 -1);
284 delete_diffractometer(diffractometer);
285 return FALSE;
288 static gboolean
289 finalize_liststore_samples(GtkTreeModel *model,
290 GtkTreePath *path,
291 GtkTreeIter *iter,
292 gpointer data)
294 HklSample *sample = NULL;
296 gtk_tree_model_get(model, iter,
297 SAMPLE_COL_SAMPLE, &sample,
298 -1);
299 hkl_sample_free(sample);
300 return FALSE;
303 static void
304 finalize (GObject* object)
306 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(object);
308 g_object_unref(priv->builder);
310 darray_free(priv->pseudo_frames);
312 gtk_tree_model_foreach(GTK_TREE_MODEL(priv->_liststore_diffractometer),
313 finalize_liststore_diffractometer,
314 NULL);
316 gtk_tree_model_foreach(GTK_TREE_MODEL(priv->_liststore_crystals),
317 finalize_liststore_samples,
318 NULL);
320 G_OBJECT_CLASS (hkl_gui_window_parent_class)->finalize (object);
323 HklGuiWindow* hkl_gui_window_new (void)
325 return g_object_new (HKL_GUI_TYPE_WINDOW, NULL);
329 #define get_object(builder, type, priv, name) priv->_ ## name = type(gtk_builder_get_object(builder, #name))
331 static void
332 hkl_gui_window_get_widgets_and_objects_from_ui (HklGuiWindow* self)
334 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
335 GtkBuilder* builder;
337 g_return_if_fail (self != NULL);
339 priv->builder = builder = gtk_builder_new ();
340 gtk_builder_add_from_file (builder, "ghkl.ui", NULL);
342 get_object(builder, GTK_LIST_STORE, priv, liststore_diffractometer);
343 get_object(builder, GTK_LIST_STORE, priv, liststore_axis);
344 get_object(builder, GTK_LIST_STORE, priv, liststore_pseudo_axes);
345 get_object(builder, GTK_LIST_STORE, priv, liststore_reflections);
346 get_object(builder, GTK_LIST_STORE, priv, liststore_crystals);
348 get_object(builder, GTK_LABEL, priv, label_UB11);
349 get_object(builder, GTK_LABEL, priv, label_UB12);
350 get_object(builder, GTK_LABEL, priv, label_UB13);
351 get_object(builder, GTK_LABEL, priv, label_UB21);
352 get_object(builder, GTK_LABEL, priv, label_UB22);
353 get_object(builder, GTK_LABEL, priv, label_UB23);
354 get_object(builder, GTK_LABEL, priv, label_UB31);
355 get_object(builder, GTK_LABEL, priv, label_UB32);
356 get_object(builder, GTK_LABEL, priv, label_UB33);
358 get_object(builder, GTK_BUTTON, priv, button2);
360 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_a);
361 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_a_min);
362 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_a_max);
363 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_a_star);
365 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_b);
366 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_b_min);
367 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_b_max);
368 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_b_star);
370 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_c);
371 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_c_min);
372 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_c_max);
373 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_c_star);
375 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_alpha);
376 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_alpha_min);
377 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_alpha_max);
378 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_alpha_star);
380 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_beta);
381 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_beta_min);
382 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_beta_max);
383 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_beta_star);
385 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_gamma);
386 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_gamma_min);
387 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_gamma_max);
388 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_gamma_star);
390 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_lambda);
392 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_ux);
393 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_uy);
394 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_uz);
396 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U11);
397 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U12);
398 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U13);
399 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U21);
400 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U22);
401 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U23);
402 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U31);
403 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U32);
404 get_object(builder, GTK_SPIN_BUTTON, priv, spinbutton_U33);
407 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_a);
408 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_b);
409 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_c);
410 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_alpha);
411 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_beta);
412 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_gamma);
413 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_ux);
414 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_uy);
415 get_object(builder, GTK_CHECK_BUTTON, priv, checkbutton_uz);
418 get_object(builder, GTK_TREE_VIEW, priv, treeview_reflections);
419 get_object(builder, GTK_TREE_VIEW, priv, treeview_crystals);
420 get_object(builder, GTK_TREE_VIEW, priv, treeview_axes);
421 get_object(builder, GTK_TREE_VIEW, priv, treeview_pseudo_axes);
422 get_object(builder, GTK_TREE_VIEW, priv, treeview_solutions);
424 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_add_reflection);
425 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_goto_reflection);
426 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_del_reflection);
427 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_setUB);
428 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_computeUB);
429 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_add_crystal);
430 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_copy_crystal);
431 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_del_crystal);
432 get_object(builder, GTK_TOOL_BUTTON, priv, toolbutton_affiner);
434 get_object(builder, GTK_STATUSBAR, priv, statusbar);
436 get_object(builder, GTK_IMAGE_MENU_ITEM, priv, menuitem5);
438 get_object(builder, GTK_VBOX, priv, vbox7);
439 get_object(builder, GTK_VBOX, priv, vbox2);
440 get_object(builder, GTK_VBOX, priv, box_info_bar);
442 get_object(builder, GTK_DIALOG, priv, dialog1);
444 get_object(builder, GTK_COMBO_BOX, priv, combobox1);
446 gtk_builder_connect_signals (builder, self);
449 static void
450 update_pseudo_axes_frames (HklGuiWindow* self)
452 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
453 HklGuiEngine **engine;
455 g_return_if_fail (self != NULL);
457 darray_foreach(engine, priv->pseudo_frames){
458 hkl_gui_engine_update(*engine);
462 static void
463 raise_error(HklGuiWindow *self, HklError **error)
465 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
467 g_return_if_fail (self != NULL);
468 g_return_if_fail (error != NULL);
470 /* show an error message */
471 gtk_label_set_text (GTK_LABEL (priv->info_message),
472 hkl_error_message_get(*error));
473 gtk_info_bar_set_message_type (priv->info_bar,
474 GTK_MESSAGE_ERROR);
475 gtk_widget_show (GTK_WIDGET(priv->info_bar));
477 hkl_error_clear(error);
480 static void
481 clear_error(HklGuiWindow *self, HklError **error)
483 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
485 g_return_if_fail (self != NULL);
487 gtk_widget_hide(GTK_WIDGET(priv->info_bar));
490 static gboolean
491 _update_axis (GtkTreeModel *model, GtkTreePath *path,
492 GtkTreeIter *iter, gpointer data)
494 HklParameter *parameter;
495 gdouble value, min, max;
497 gtk_tree_model_get (model, iter,
498 AXIS_COL_AXIS, &parameter,
499 -1);
501 hkl_parameter_min_max_unit_get(parameter, &min, &max);
502 value = hkl_parameter_value_unit_get(parameter);
504 gtk_list_store_set(GTK_LIST_STORE(model), iter,
505 AXIS_COL_READ, value,
506 AXIS_COL_WRITE, value,
507 AXIS_COL_MIN, min,
508 AXIS_COL_MAX, max,
509 -1);
510 return FALSE;
513 static void
514 update_axes (HklGuiWindow* self)
516 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
518 g_return_if_fail (self != NULL);
520 gtk_tree_model_foreach(GTK_TREE_MODEL(priv->_liststore_axis),
521 _update_axis,
522 self);
525 static gboolean
526 _update_pseudo_axes (GtkTreeModel *model, GtkTreePath *path,
527 GtkTreeIter *iter, gpointer data)
529 HklParameter *parameter;
530 gdouble value, min, max;
532 gtk_tree_model_get (model, iter,
533 PSEUDO_AXIS_COL_PARAMETER, &parameter,
534 -1);
536 hkl_parameter_min_max_unit_get(parameter, &min, &max);
537 value = hkl_parameter_value_unit_get(parameter);
539 gtk_list_store_set(GTK_LIST_STORE(model), iter,
540 PSEUDO_AXIS_COL_READ, value,
541 PSEUDO_AXIS_COL_WRITE, value,
542 -1);
543 return FALSE;
546 static void
547 update_pseudo_axes (HklGuiWindow* self)
549 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
551 g_return_if_fail (self != NULL);
553 gtk_tree_model_foreach(GTK_TREE_MODEL(priv->_liststore_pseudo_axes),
554 _update_pseudo_axes,
555 self);
558 static void
559 update_solutions (HklGuiWindow* self)
561 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
562 const HklGeometryList *geometries;
563 const darray_item *items;
564 GtkTreeIter iter = {0};
566 g_return_if_fail (self != NULL);
568 geometries = hkl_engine_list_geometries(priv->diffractometer->engines);
570 gtk_list_store_clear(priv->_liststore_solutions);
571 items = hkl_geometry_list_items_get(geometries);
572 if (darray_size(*items)){
573 gint n_values = gtk_tree_model_get_n_columns (GTK_TREE_MODEL(priv->_liststore_solutions));
574 GValue *values = g_new0(GValue, n_values);
575 gint *columns = g_new0(gint, n_values);
576 gint i;
578 /* prepare the GValue before using them */
579 g_value_init(&values[0], G_TYPE_INT);
580 for(i=1; i<n_values; ++i)
581 g_value_init(&values[i], G_TYPE_DOUBLE);
583 for(i=0; i<darray_size(*items);++i){
584 gint column = 0;
585 const HklGeometry *geometry;
586 HklParameter **parameter;
587 const darray_parameter *parameters;
589 geometry = hkl_geometry_list_item_geometry_get(darray_item(*items, i));
590 parameters = hkl_geometry_axes_get(geometry);
592 g_value_set_int(&values[column], i);
593 columns[0] = column;
595 darray_foreach(parameter, *parameters){
596 double value = hkl_parameter_value_unit_get(*parameter);
598 column = column + 1;
599 g_value_set_double(&values[column], value);
600 columns[column] = column;
602 gtk_list_store_insert_with_valuesv(priv->_liststore_solutions,
603 &iter, i,
604 columns, values, n_values);
606 g_free(columns);
607 g_free(values);
611 static void
612 update_source (HklGuiWindow* self)
614 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
616 g_return_if_fail (self != NULL);
618 gtk_spin_button_set_value (priv->_spinbutton_lambda,
619 hkl_geometry_wavelength_get(priv->diffractometer->geometry));
622 static void
623 update_reflections (HklGuiWindow *self)
625 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
627 gtk_list_store_clear (priv->_liststore_reflections);
629 if(priv->sample){
630 HklSampleReflection* reflection = NULL;
631 guint index = 0;
633 reflection = hkl_sample_first_reflection_get(priv->sample);
634 while(reflection){
635 GtkTreeIter iter = {0};
636 gdouble h, k, l;
637 gboolean flag;
639 hkl_sample_reflection_hkl_get(reflection, &h, &k, &l);
640 flag = hkl_sample_reflection_flag_get(reflection);
642 gtk_list_store_append (priv->_liststore_reflections, &iter);
644 gtk_list_store_set (priv->_liststore_reflections,
645 &iter,
646 REFLECTION_COL_INDEX, index++,
647 REFLECTION_COL_H, h,
648 REFLECTION_COL_K, k,
649 REFLECTION_COL_L, l,
650 REFLECTION_COL_FLAG, flag,
651 REFLECTION_COL_REFLECTION, reflection,
652 -1);
653 reflection = hkl_sample_next_reflection_get(priv->sample,
654 reflection);
659 static gboolean
660 hkl_engine_to_axes(HklGuiWindow *self, HklEngine *engine)
662 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
663 HklError *error = NULL;
664 gboolean res = TRUE;
666 g_return_val_if_fail (self != NULL, FALSE);
667 g_return_val_if_fail (engine != NULL, FALSE);
669 if(hkl_engine_set(engine, &error)){
670 clear_error(self, &error);
671 hkl_engine_list_select_solution(priv->diffractometer->engines, 0);
672 hkl_engine_list_get(priv->diffractometer->engines);
674 update_axes (self);
675 update_pseudo_axes (self);
676 update_pseudo_axes_frames (self);
677 }else{
678 raise_error(self, &error);
679 dump_diffractometer(priv->diffractometer);
680 res = FALSE;
682 update_solutions (self);
683 return res;
686 static void
687 pseudo_axes_frame_changed_cb (HklGuiEngine *gui_engine, HklGuiWindow *self)
689 HklEngine *engine;
691 g_return_if_fail (self != NULL);
693 g_object_get(G_OBJECT(gui_engine),
694 "engine", &engine,
695 NULL);
697 hkl_engine_to_axes(self, engine);
700 static void
701 set_up_pseudo_axes_frames (HklGuiWindow* self)
703 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
704 HklGuiEngine **pseudo;
705 GtkVBox* vbox2;
706 HklEngine **engine;
707 darray_engine *engines;
709 g_return_if_fail (self != NULL);
711 darray_foreach (pseudo, priv->pseudo_frames){
712 gtk_container_remove(GTK_CONTAINER(priv->_vbox2),
713 GTK_WIDGET (hkl_gui_engine_get_frame (*pseudo)));
714 g_object_unref(*pseudo);
716 darray_size (priv->pseudo_frames) = 0;
718 engines = hkl_engine_list_engines (priv->diffractometer->engines);
719 darray_foreach (engine, *engines){
720 HklGuiEngine *pseudo;
722 pseudo = hkl_gui_engine_new (*engine);
723 darray_append(priv->pseudo_frames, pseudo);
724 gtk_container_add (GTK_CONTAINER (priv->_vbox2),
725 GTK_WIDGET (hkl_gui_engine_get_frame(pseudo)));
727 g_signal_connect_object (pseudo,
728 "changed",
729 G_CALLBACK(pseudo_axes_frame_changed_cb),
730 self, 0);
733 gtk_widget_show_all (GTK_WIDGET (priv->_vbox2));
737 static void
738 set_up_diffractometer_model (HklGuiWindow* self)
740 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
741 unsigned int i, n;
742 HklFactory **factories;
744 g_return_if_fail (self != NULL);
746 factories = hkl_factory_get_all(&n);
747 for(i=0; i<n; ++i){
748 GtkTreeIter iter = {0};
750 gtk_list_store_append (priv->_liststore_diffractometer, &iter);
751 gtk_list_store_set (priv->_liststore_diffractometer,
752 &iter,
753 DIFFRACTOMETER_COL_NAME, hkl_factory_name(factories[i]),
754 DIFFRACTOMETER_COL_FACTORY, factories[i],
755 DIFFRACTOMETER_COL_DIFFRACTOMETER, NULL,
756 -1);
760 static void
761 set_up_tree_view_axes (HklGuiWindow* self)
763 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
764 HklParameter **parameter;
765 const darray_parameter *parameters;
766 GtkCellRenderer* renderer = NULL;
767 GtkTreeViewColumn* column = NULL;
768 GList* columns;
770 g_return_if_fail (self != NULL);
772 gtk_list_store_clear (priv->_liststore_axis);
774 parameters = hkl_geometry_axes_get(priv->diffractometer->geometry);
775 darray_foreach (parameter, *parameters){
776 GtkTreeIter iter = {0};
778 gtk_list_store_append (priv->_liststore_axis, &iter);
779 gtk_list_store_set (priv->_liststore_axis, &iter,
780 AXIS_COL_AXIS, *parameter,
781 AXIS_COL_NAME, hkl_parameter_name_get(*parameter),
782 -1);
785 update_axes (self);
788 static void
789 set_up_tree_view_pseudo_axes (HklGuiWindow* self)
791 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
792 HklParameter **parameter;
793 const darray_parameter *parameters;
794 HklEngine **engine;
795 const darray_engine *engines;
797 GtkCellRendererText* renderer = NULL;
798 GtkTreeViewColumn* column = NULL;
799 GList* columns;
801 g_return_if_fail (self != NULL);
803 gtk_list_store_clear(priv->_liststore_pseudo_axes);
805 engines = hkl_engine_list_engines(priv->diffractometer->engines);
806 darray_foreach(engine, *engines){
807 parameters = hkl_engine_pseudo_axes(*engine);
808 darray_foreach(parameter, *parameters){
809 GtkTreeIter iter = {0};
811 gtk_list_store_append (priv->_liststore_pseudo_axes, &iter);
812 gtk_list_store_set (priv->_liststore_pseudo_axes, &iter,
813 PSEUDO_AXIS_COL_PARAMETER, *parameter,
814 PSEUDO_AXIS_COL_ENGINE, *engine,
815 PSEUDO_AXIS_COL_NAME, hkl_parameter_name_get(*parameter),
816 -1);
820 update_pseudo_axes (self);
823 static void
824 _delete_column(gpointer data,
825 gpointer user_data)
827 gtk_tree_view_remove_column (GTK_TREE_VIEW(user_data),
828 GTK_TREE_VIEW_COLUMN(data));
831 static void
832 set_up_tree_view_solutions (HklGuiWindow* self)
834 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
835 const darray_parameter *parameters;
836 int i;
837 GtkCellRenderer* renderer = NULL;
838 GtkTreeViewColumn* column = NULL;
839 GList* columns;
840 GType* types;
841 gint n_columns;
843 g_return_if_fail (self != NULL);
845 parameters = hkl_geometry_axes_get(priv->diffractometer->geometry);
847 n_columns = SOLUTION_COL_N_COLUMNS + darray_size(*parameters);
849 /* prepare types for the liststore */
850 types = g_new0 (GType, n_columns);
852 /* first remove all the columns */
853 columns = gtk_tree_view_get_columns (priv->_treeview_solutions);
854 g_list_foreach(columns, _delete_column, priv->_treeview_solutions);
855 g_list_free(columns);
857 /* now add the index column */
858 renderer = gtk_cell_renderer_text_new ();
859 column = gtk_tree_view_column_new_with_attributes ("index",
860 renderer, "text",
861 SOLUTION_COL_INDEX, NULL);
863 gtk_tree_view_append_column (priv->_treeview_solutions, column);
864 types[0] = G_TYPE_INT;
866 /* add the axes column */
867 for(i=1; i<n_columns; ++i){
868 HklParameter *parameter;
870 parameter = darray_item(*parameters, i - SOLUTION_COL_N_COLUMNS);
871 renderer = gtk_cell_renderer_text_new ();
872 column = gtk_tree_view_column_new_with_attributes (hkl_parameter_name_get(parameter),
873 renderer, "text",
874 i, NULL);
876 gtk_tree_view_append_column (priv->_treeview_solutions, column);
877 types[i] = G_TYPE_DOUBLE;
880 if (priv->_liststore_solutions)
881 g_object_unref(priv->_liststore_solutions);
882 priv->_liststore_solutions = gtk_list_store_newv (n_columns, types);
883 g_free (types);
885 gtk_tree_view_set_model (priv->_treeview_solutions,
886 GTK_TREE_MODEL(priv->_liststore_solutions));
888 update_solutions (self);
891 void
892 set_up_info_bar(HklGuiWindow *self)
894 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
895 GtkWidget *content_area;
897 g_return_if_fail (self != NULL);
899 /* set up info bar until we can use glade for this purpose or
900 * switch to gtk3 */
901 if (priv->info_bar)
902 return;
904 priv->info_bar = GTK_INFO_BAR(gtk_info_bar_new ());
905 gtk_widget_set_no_show_all (GTK_WIDGET(priv->info_bar), TRUE);
907 priv->info_message = GTK_LABEL(gtk_label_new (""));
908 gtk_widget_show (GTK_WIDGET(priv->info_message));
910 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->info_bar));
911 gtk_container_add (GTK_CONTAINER (content_area),
912 GTK_WIDGET(priv->info_message));
913 gtk_info_bar_add_button (priv->info_bar,
914 GTK_STOCK_OK, GTK_RESPONSE_OK);
915 g_signal_connect (priv->info_bar, "response",
916 G_CALLBACK (gtk_widget_hide), NULL);
918 gtk_box_pack_start(GTK_BOX(priv->_box_info_bar),
919 GTK_WIDGET(priv->info_bar),
920 TRUE, TRUE, 0);
923 void
924 hkl_gui_window_combobox1_changed_cb(GtkComboBox *combobox, gpointer *user_data)
926 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
927 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
928 HklFactory *factory;
929 struct diffractometer_t *dif = NULL;
931 GtkTreeIter iter = {0};
933 if(gtk_combo_box_get_active_iter (combobox, &iter)){
934 gtk_tree_model_get(GTK_TREE_MODEL(priv->_liststore_diffractometer),
935 &iter,
936 DIFFRACTOMETER_COL_FACTORY, &factory,
937 DIFFRACTOMETER_COL_DIFFRACTOMETER, &dif,
938 -1);
940 if (!dif){
941 dif = create_diffractometer(factory);
942 gtk_list_store_set(priv->_liststore_diffractometer,
943 &iter,
944 DIFFRACTOMETER_COL_DIFFRACTOMETER, dif,
945 -1);
947 printf("toto\n");
949 priv->diffractometer = dif;
950 /* TODO check if this is the right place for this */
951 hkl_engine_list_init(dif->engines, dif->geometry, dif->detector, priv->sample);
953 set_up_pseudo_axes_frames(self);
954 set_up_tree_view_axes(self);
955 set_up_tree_view_pseudo_axes(self);
957 /* FIXME create the right solution Model Column */
958 /* this._solutionModelColumns = 0; */
959 set_up_tree_view_solutions(self);
960 set_up_info_bar(self);
961 #if HKL3D
962 set_up_3D(self);
963 #endif
967 /* axis read cb */
968 void
969 hkl_gui_window_cellrendererspin1_edited_cb(GtkCellRendererText *renderer,
970 gchar *path,
971 gchar *new_text,
972 gpointer user_data)
974 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
975 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
976 GtkTreeIter iter = {0};
977 gdouble value = 0.0;
978 HklParameter* parameter = NULL;
980 g_return_if_fail (renderer != NULL);
981 g_return_if_fail (path != NULL);
982 g_return_if_fail (new_text != NULL);
983 g_return_if_fail (user_data != NULL);
985 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_axis),
986 &iter,
987 path);
988 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_axis), &iter,
989 AXIS_COL_AXIS, &parameter,
990 -1);
992 value = atof(new_text); /* TODO need to check for the right conversion */
993 hkl_parameter_value_unit_set (parameter, value, NULL);
994 hkl_geometry_axis_set(priv->diffractometer->geometry,
995 parameter);
997 hkl_engine_list_get(priv->diffractometer->engines);
999 /* ok so set the model with the new value */
1000 gtk_list_store_set (priv->_liststore_axis, &iter,
1001 AXIS_COL_READ, value,
1002 AXIS_COL_WRITE, value,
1003 -1);
1005 update_pseudo_axes (self);
1006 update_pseudo_axes_frames (self);
1010 /* axis min cb */
1011 void
1012 hkl_gui_window_cellrendererspin3_edited_cb(GtkCellRendererText *renderer,
1013 gchar *path,
1014 gchar *new_text,
1015 gpointer user_data)
1017 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1018 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1019 GtkTreeIter iter = {0};
1020 gdouble value = 0.0;
1021 HklParameter* parameter = NULL;
1022 gdouble shit, max;
1024 g_return_if_fail (renderer != NULL);
1025 g_return_if_fail (path != NULL);
1026 g_return_if_fail (new_text != NULL);
1027 g_return_if_fail (user_data != NULL);
1029 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_axis),
1030 &iter,
1031 path);
1032 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_axis), &iter,
1033 AXIS_COL_AXIS, &parameter,
1034 -1);
1036 value = atof(new_text); /* TODO need to check for the right conversion */
1037 hkl_parameter_min_max_unit_get (parameter, &shit, &max);
1038 hkl_parameter_min_max_unit_set (parameter, value, max);
1040 gtk_list_store_set (priv->_liststore_axis, &iter,
1041 AXIS_COL_MIN, value,
1042 -1);
1044 update_pseudo_axes (self);
1048 /* axis max cb */
1049 void
1050 hkl_gui_window_cellrendererspin4_edited_cb(GtkCellRendererText *renderer,
1051 gchar *path,
1052 gchar *new_text,
1053 gpointer user_data)
1055 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1056 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1057 GtkTreeIter iter = {0};
1058 gdouble value = 0.0;
1059 HklParameter* parameter = NULL;
1060 gdouble shit, min;
1062 g_return_if_fail (renderer != NULL);
1063 g_return_if_fail (path != NULL);
1064 g_return_if_fail (new_text != NULL);
1065 g_return_if_fail (user_data != NULL);
1067 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_axis),
1068 &iter,
1069 path);
1070 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_axis), &iter,
1071 AXIS_COL_AXIS, &parameter,
1072 -1);
1074 value = atof(new_text); /* TODO need to check for the right conversion */
1075 hkl_parameter_min_max_unit_get (parameter, &min, &shit);
1076 hkl_parameter_min_max_unit_set (parameter, min, value);
1078 gtk_list_store_set (priv->_liststore_axis, &iter,
1079 AXIS_COL_MAX, value,
1080 -1);
1082 update_pseudo_axes (self);
1086 /* pseudo axis write */
1087 void
1088 hkl_gui_window_cellrenderertext5_edited_cb(GtkCellRendererText *renderer,
1089 gchar *path,
1090 gchar *new_text,
1091 gpointer user_data)
1093 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1094 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1095 GtkTreeIter iter = {0};
1096 gdouble value = 0.0;
1097 gdouble old_value;
1098 HklParameter* parameter = NULL;
1099 HklEngine *engine = NULL;
1100 HklError *error = NULL;
1102 g_return_if_fail (renderer != NULL);
1103 g_return_if_fail (path != NULL);
1104 g_return_if_fail (new_text != NULL);
1105 g_return_if_fail (user_data != NULL);
1107 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_pseudo_axes),
1108 &iter,
1109 path);
1110 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_pseudo_axes), &iter,
1111 PSEUDO_AXIS_COL_PARAMETER, &parameter,
1112 PSEUDO_AXIS_COL_ENGINE, &engine,
1113 -1);
1115 value = atof(new_text); /* TODO need to check for the right conversion */
1116 old_value = hkl_parameter_value_unit_get(parameter);
1118 g_assert(error != NULL || error == NULL);
1119 hkl_parameter_value_unit_set (parameter, value, &error);
1120 if(error != NULL){
1121 raise_error(self, &error);
1124 if (hkl_engine_to_axes(self, engine)){
1125 gtk_list_store_set (priv->_liststore_pseudo_axes,
1126 &iter,
1127 PSEUDO_AXIS_COL_WRITE, value,
1128 -1);
1129 }else{
1130 hkl_parameter_value_unit_set(parameter, old_value, NULL);
1135 void
1136 hkl_gui_window_treeview_solutions_cursor_changed_cb (GtkTreeView *tree_view,
1137 gpointer user_data)
1139 HklGuiWindow* self = HKL_GUI_WINDOW(user_data);
1140 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1142 GtkTreePath* path = NULL;
1143 GtkTreeViewColumn* focus_column = NULL;
1144 GtkTreeIter iter = {0};
1145 gsize index = 0UL;
1147 g_return_if_fail (tree_view != NULL);
1148 g_return_if_fail (user_data != NULL);
1150 gtk_tree_view_get_cursor (tree_view, &path, &focus_column);
1151 gtk_tree_model_get_iter (GTK_TREE_MODEL(priv->_liststore_solutions), &iter, path);
1152 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_solutions), &iter,
1153 SOLUTION_COL_INDEX, &index,
1154 -1);
1156 hkl_engine_list_select_solution (priv->diffractometer->engines, index);
1157 hkl_engine_list_get (priv->diffractometer->engines);
1159 update_axes (self);
1160 update_pseudo_axes (self);
1161 update_pseudo_axes_frames (self);
1163 gtk_tree_path_free (path);
1166 /* reflection h */
1167 void
1168 hkl_gui_window_cellrenderertext7_edited_cb(GtkCellRendererText* _sender, const gchar* path,
1169 const gchar* new_text, gpointer self)
1171 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1173 g_return_if_fail (self != NULL);
1174 g_return_if_fail (path != NULL);
1175 g_return_if_fail (new_text != NULL);
1177 if (priv->sample){
1178 gdouble h = 0.0;
1179 gdouble k = 0.0;
1180 gdouble l = 0.0;
1181 HklSampleReflection* reflection = NULL;
1182 GtkTreeIter iter = {0};
1184 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_reflections),
1185 &iter, path);
1186 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1187 &iter,
1188 REFLECTION_COL_REFLECTION, &reflection,
1189 -1);
1191 hkl_sample_reflection_hkl_get (reflection, &h, &k, &l);
1192 h = atof(new_text);
1193 hkl_sample_reflection_hkl_set (reflection, h, k, l);
1194 gtk_list_store_set (priv->_liststore_reflections,
1195 &iter,
1196 REFLECTION_COL_H, h,
1197 -1);
1201 /* reflection k */
1202 void
1203 hkl_gui_window_cellrenderertext8_edited_cb (GtkCellRendererText* _sender, const gchar* path,
1204 const gchar* new_text, gpointer self)
1206 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1208 g_return_if_fail (self != NULL);
1209 g_return_if_fail (path != NULL);
1210 g_return_if_fail (new_text != NULL);
1212 if (priv->sample){
1213 gdouble h = 0.0;
1214 gdouble k = 0.0;
1215 gdouble l = 0.0;
1216 HklSampleReflection* reflection = NULL;
1217 GtkTreeIter iter = {0};
1219 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_reflections),
1220 &iter, path);
1221 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1222 &iter,
1223 REFLECTION_COL_REFLECTION, &reflection,
1224 -1);
1226 hkl_sample_reflection_hkl_get (reflection, &h, &k, &l);
1227 k = atof(new_text);
1228 hkl_sample_reflection_hkl_set (reflection, h, k, l);
1229 gtk_list_store_set (priv->_liststore_reflections,
1230 &iter,
1231 REFLECTION_COL_K, k,
1232 -1);
1236 /* reflection l */
1237 void
1238 hkl_gui_window_cellrenderertext9_edited_cb (GtkCellRendererText* _sender, const gchar* path,
1239 const gchar* new_text, gpointer self)
1241 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1243 g_return_if_fail (self != NULL);
1244 g_return_if_fail (path != NULL);
1245 g_return_if_fail (new_text != NULL);
1247 if (priv->sample){
1248 gdouble h = 0.0;
1249 gdouble k = 0.0;
1250 gdouble l = 0.0;
1251 HklSampleReflection* reflection = NULL;
1252 GtkTreeIter iter = {0};
1254 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_reflections),
1255 &iter, path);
1256 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1257 &iter,
1258 REFLECTION_COL_REFLECTION, &reflection,
1259 -1);
1261 hkl_sample_reflection_hkl_get (reflection, &h, &k, &l);
1262 l = atof(new_text);
1263 hkl_sample_reflection_hkl_set (reflection, h, k, l);
1264 gtk_list_store_set (priv->_liststore_reflections,
1265 &iter,
1266 REFLECTION_COL_L, l,
1267 -1);
1271 /* reflection flag */
1272 void
1273 hkl_gui_window_cellrenderertoggle1_toggled_cb (GtkCellRendererToggle* renderer, const gchar* path,
1274 gpointer self)
1276 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1278 g_return_if_fail (self != NULL);
1279 g_return_if_fail (path != NULL);
1281 if (priv->sample){
1282 gboolean flag;
1283 HklSampleReflection* reflection = NULL;
1284 GtkTreeIter iter = {0};
1286 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(priv->_liststore_reflections),
1287 &iter, path);
1288 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1289 &iter,
1290 REFLECTION_COL_REFLECTION, &reflection,
1291 -1);
1293 flag = gtk_cell_renderer_toggle_get_active(renderer);
1294 hkl_sample_reflection_flag_set (reflection, flag);
1295 gtk_list_store_set (priv->_liststore_reflections,
1296 &iter,
1297 REFLECTION_COL_FLAG, flag,
1298 -1);
1302 gboolean
1303 hkl_gui_window_treeview_reflections_key_press_event_cb (GtkWidget* _sender, GdkEventKey* event,
1304 gpointer self)
1306 return TRUE;
1309 void
1310 hkl_gui_window_toolbutton_add_reflection_clicked_cb(GtkToolButton* _sender,
1311 gpointer self)
1313 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1315 if (priv->diffractometer == NULL){
1316 gtk_statusbar_push (priv->_statusbar, 0,
1317 "Please select a diffractometer before adding reflections");
1318 return;
1321 if (priv->sample) {
1322 HklSampleReflection *reflection = NULL;
1323 GtkTreeIter iter = {0};
1324 gboolean flag;
1325 gint n_rows;
1327 reflection = hkl_sample_reflection_new(priv->diffractometer->geometry,
1328 priv->diffractometer->detector,
1329 0, 0, 0);
1330 hkl_sample_add_reflection(priv->sample, reflection);
1331 flag = hkl_sample_reflection_flag_get(reflection);
1333 n_rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(priv->_liststore_reflections),
1334 NULL);
1335 gtk_list_store_insert_with_values (priv->_liststore_reflections,
1336 &iter, -1,
1337 REFLECTION_COL_INDEX, n_rows,
1338 REFLECTION_COL_H, 0.,
1339 REFLECTION_COL_K, 0.,
1340 REFLECTION_COL_L, 0.,
1341 REFLECTION_COL_FLAG, flag,
1342 REFLECTION_COL_REFLECTION, reflection,
1343 -1);
1347 void
1348 hkl_gui_window_toolbutton_goto_reflection_clicked_cb (GtkToolButton* _sender, gpointer user_data)
1350 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1351 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1353 g_return_if_fail (self != NULL);
1355 if (priv->sample) {
1356 GtkTreeSelection* selection = NULL;
1357 guint nb_rows = 0U;
1359 selection = gtk_tree_view_get_selection (priv->_treeview_reflections);
1360 nb_rows = gtk_tree_selection_count_selected_rows (selection);
1362 if (nb_rows == 1) {
1363 HklSampleReflection *reflection;
1364 GtkTreeIter iter = {0};
1365 GtkTreeModel* model = NULL;
1366 GtkTreePath *treepath;
1367 GList* list;
1369 model = GTK_TREE_MODEL(priv->_liststore_reflections);
1371 list = gtk_tree_selection_get_selected_rows (selection,
1372 &model);
1374 treepath = g_list_nth_data(list, 0);
1376 gtk_tree_model_get_iter (GTK_TREE_MODEL(priv->_liststore_reflections),
1377 &iter, treepath);
1379 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1380 &iter,
1381 REFLECTION_COL_REFLECTION, &reflection,
1382 -1);
1384 hkl_geometry_set (priv->diffractometer->geometry,
1385 hkl_sample_reflection_geometry_get(reflection));
1387 update_source (self);
1389 update_axes (self);
1391 update_pseudo_axes (self);
1393 g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
1394 } else
1395 if (nb_rows > 1)
1396 gtk_statusbar_push (priv->_statusbar, 0,
1397 "Please select only one reflection.");
1398 else
1399 gtk_statusbar_push (priv->_statusbar, 0,
1400 "Please select at least one reflection.");
1404 static void
1405 _del_reflection(gpointer data, gpointer user_data)
1407 HklSampleReflection *reflection;
1408 GtkTreeIter iter = {0};
1409 GtkTreePath *treepath = data;
1410 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1412 gtk_tree_model_get_iter (GTK_TREE_MODEL(priv->_liststore_reflections),
1413 &iter, treepath);
1415 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_reflections),
1416 &iter,
1417 REFLECTION_COL_REFLECTION, &reflection,
1418 -1);
1419 hkl_sample_del_reflection(priv->sample, reflection);
1422 void
1423 hkl_gui_window_toolbutton_del_reflection_clicked_cb (GtkToolButton* _sender, gpointer user_data)
1425 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1426 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1427 HklSample* sample = NULL;
1429 g_return_if_fail (self != NULL);
1431 if (priv->sample) {
1432 GtkTreeSelection* selection = NULL;
1433 guint nb_rows = 0U;
1435 selection = gtk_tree_view_get_selection (priv->_treeview_reflections);
1436 nb_rows = gtk_tree_selection_count_selected_rows (selection);
1437 if (nb_rows > 0) {
1438 GtkTreeModel* model = NULL;
1439 GList* list;
1440 guint* indexes;
1441 gint i;
1442 GtkMessageDialog* dialog;
1444 model = GTK_TREE_MODEL(priv->_liststore_reflections);
1445 list = gtk_tree_selection_get_selected_rows (selection, &model);
1448 dialog = GTK_MESSAGE_DIALOG(
1449 gtk_message_dialog_new (NULL,
1450 GTK_DIALOG_DESTROY_WITH_PARENT,
1451 GTK_MESSAGE_WARNING,
1452 GTK_BUTTONS_YES_NO,
1453 "Are you sure that you want to delete reflections"));
1455 switch (gtk_dialog_run (GTK_DIALOG(dialog))) {
1456 case GTK_RESPONSE_YES:
1458 g_list_foreach(list, _del_reflection, self);
1459 update_reflections (self);
1460 break;
1462 default:
1463 break;
1465 gtk_widget_destroy (GTK_WIDGET(dialog));
1466 g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
1467 } else {
1468 gtk_statusbar_push (priv->_statusbar, 0,
1469 "Please select at least one reflection.");
1474 /* crystal name */
1475 void
1476 hkl_gui_window_cellrenderertext10_edited_cb(GtkCellRendererText* _sender, const gchar* path,
1477 const gchar* new_text, gpointer user_data)
1479 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1481 GtkTreeModel* model = NULL;
1482 GtkTreeIter iter = {0};
1483 HklSample* sample = NULL;
1484 gchar* name = NULL;
1486 g_return_if_fail (user_data != NULL);
1487 g_return_if_fail (path != NULL);
1488 g_return_if_fail (new_text != NULL);
1490 model = GTK_TREE_MODEL(priv->_liststore_crystals);
1492 gtk_tree_model_get_iter_from_string (model, &iter, path);
1494 gtk_tree_model_get (model, &iter,
1495 SAMPLE_COL_SAMPLE, &sample,
1496 -1);
1498 hkl_sample_name_set (sample, new_text);
1500 gtk_list_store_set(priv->_liststore_crystals, &iter,
1501 SAMPLE_COL_NAME, new_text,
1502 -1);
1505 #define set_lattice(lattice, parameter) do{ \
1506 const HklParameter *p; \
1507 gdouble min, max, value; \
1508 gboolean fit; \
1509 p = hkl_lattice_## parameter ##_get((lattice)); \
1510 value = hkl_parameter_value_unit_get(p); \
1511 hkl_parameter_min_max_unit_get(p, &min, &max); \
1512 fit = hkl_parameter_fit_get(p); \
1513 gtk_spin_button_set_value(priv->_spinbutton_## parameter, value); \
1514 gtk_spin_button_set_value(priv->_spinbutton_## parameter ##_min, min); \
1515 gtk_spin_button_set_value(priv->_spinbutton_## parameter ##_max, max); \
1516 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->_checkbutton_ ## parameter), fit); \
1517 }while(0)
1519 static void
1520 update_lattice (HklGuiWindow* self)
1522 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1524 g_return_if_fail (self != NULL);
1526 if (priv->sample != NULL) {
1527 const HklLattice *lattice;
1528 lattice = hkl_sample_lattice_get(priv->sample);
1529 set_lattice(lattice, a);
1530 set_lattice(lattice, b);
1531 set_lattice(lattice, c);
1532 set_lattice(lattice, alpha);
1533 set_lattice(lattice, beta);
1534 set_lattice(lattice, gamma);
1538 #define set_reciprocal_lattice(lattice, parameter) do{ \
1539 const HklParameter *p; \
1540 gdouble value; \
1541 p = hkl_lattice_## parameter ##_get((lattice)); \
1542 value = hkl_parameter_value_unit_get(p); \
1543 gtk_spin_button_set_value(priv->_spinbutton_## parameter ##_star, value); \
1544 }while(0)
1546 static void
1547 update_reciprocal_lattice (HklGuiWindow* self)
1549 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1551 g_return_if_fail (self != NULL);
1553 if (priv->sample != NULL) {
1554 hkl_lattice_reciprocal (hkl_sample_lattice_get(priv->sample),
1555 priv->reciprocal);
1557 set_reciprocal_lattice(priv->reciprocal, a);
1558 set_reciprocal_lattice(priv->reciprocal, b);
1559 set_reciprocal_lattice(priv->reciprocal, c);
1560 set_reciprocal_lattice(priv->reciprocal, alpha);
1561 set_reciprocal_lattice(priv->reciprocal, beta);
1562 set_reciprocal_lattice(priv->reciprocal, gamma);
1566 #define set_ux_uy_uz(sample, parameter) do { \
1567 const HklParameter *p; \
1568 p = hkl_sample_## parameter ##_get((sample)); \
1569 gboolean fit = hkl_parameter_fit_get(p); \
1570 gtk_spin_button_set_value(priv->_spinbutton_## parameter, \
1571 hkl_parameter_value_unit_get(p)); \
1572 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->_checkbutton_## parameter), fit); \
1573 }while(0)
1575 static void
1576 update_ux_uy_uz (HklGuiWindow* self)
1578 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1580 g_return_if_fail (self != NULL);
1582 if (priv->sample != NULL) {
1583 set_ux_uy_uz(priv->sample, ux);
1584 set_ux_uy_uz(priv->sample, uy);
1585 set_ux_uy_uz(priv->sample, uz);
1589 static void
1590 update_UB (HklGuiWindow* self)
1592 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1594 g_return_if_fail (self != NULL);
1596 if (priv->sample != NULL) {
1597 const HklMatrix *UB = hkl_sample_UB_get (priv->sample);
1598 gchar *text = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
1600 gtk_label_set_text(priv->_label_UB11,
1601 g_ascii_dtostr(text,
1602 G_ASCII_DTOSTR_BUF_SIZE,
1603 hkl_matrix_get(UB, 0, 0)));
1604 gtk_label_set_text(priv->_label_UB12,
1605 g_ascii_dtostr(text,
1606 G_ASCII_DTOSTR_BUF_SIZE,
1607 hkl_matrix_get(UB, 0, 1)));
1608 gtk_label_set_text(priv->_label_UB13,
1609 g_ascii_dtostr(text,
1610 G_ASCII_DTOSTR_BUF_SIZE,
1611 hkl_matrix_get(UB, 0, 2)));
1612 gtk_label_set_text(priv->_label_UB21,
1613 g_ascii_dtostr(text,
1614 G_ASCII_DTOSTR_BUF_SIZE,
1615 hkl_matrix_get(UB, 1, 0)));
1616 gtk_label_set_text(priv->_label_UB22,
1617 g_ascii_dtostr(text,
1618 G_ASCII_DTOSTR_BUF_SIZE,
1619 hkl_matrix_get(UB, 1, 1)));
1620 gtk_label_set_text(priv->_label_UB23,
1621 g_ascii_dtostr(text,
1622 G_ASCII_DTOSTR_BUF_SIZE,
1623 hkl_matrix_get(UB, 1, 2)));
1624 gtk_label_set_text(priv->_label_UB31,
1625 g_ascii_dtostr(text,
1626 G_ASCII_DTOSTR_BUF_SIZE,
1627 hkl_matrix_get(UB, 2, 0)));
1628 gtk_label_set_text(priv->_label_UB32,
1629 g_ascii_dtostr(text,
1630 G_ASCII_DTOSTR_BUF_SIZE,
1631 hkl_matrix_get(UB, 2, 1)));
1632 gtk_label_set_text(priv->_label_UB33,
1633 g_ascii_dtostr(text,
1634 G_ASCII_DTOSTR_BUF_SIZE,
1635 hkl_matrix_get(UB, 2, 2)));
1636 g_free(text);
1640 void
1641 hkl_gui_window_treeview_crystals_cursor_changed_cb (GtkTreeView* _sender, gpointer user_data)
1643 GtkTreePath* path = NULL;
1644 GtkTreeViewColumn* column = NULL;
1645 GtkTreeIter iter = {0};
1647 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1648 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1649 HklSample *sample;
1651 g_return_if_fail (user_data != NULL);
1653 gtk_tree_view_get_cursor (priv->_treeview_crystals, &path, &column);
1654 if(path){
1655 if (gtk_tree_model_get_iter (GTK_TREE_MODEL(priv->_liststore_crystals),
1656 &iter, path) == TRUE){
1657 gtk_tree_model_get (GTK_TREE_MODEL(priv->_liststore_crystals),
1658 &iter,
1659 SAMPLE_COL_SAMPLE, &sample,
1660 -1);
1662 if(sample){
1663 priv->sample = sample;
1664 diffractometer_engine_list_init(priv->diffractometer,
1665 priv->sample);
1666 update_reflections(self);
1667 update_lattice(self);
1668 update_reciprocal_lattice (self);
1669 update_ux_uy_uz (self);
1670 update_UB (self);
1671 update_pseudo_axes (self);
1672 update_pseudo_axes_frames (self);
1675 gtk_tree_path_free (path);
1681 static GtkTreeIter
1682 _add_sample(HklGuiWindow *self, HklSample *sample)
1684 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1685 GtkTreeIter iter = {0};
1686 const HklLattice *lattice;
1687 gdouble a, b, c, alpha, beta, gamma;
1689 g_return_val_if_fail (self != NULL, iter);
1691 lattice = hkl_sample_lattice_get(sample);
1692 a = hkl_parameter_value_unit_get(hkl_lattice_a_get(lattice));
1693 b = hkl_parameter_value_unit_get(hkl_lattice_b_get(lattice));
1694 c = hkl_parameter_value_unit_get(hkl_lattice_c_get(lattice));
1695 alpha = hkl_parameter_value_unit_get(hkl_lattice_alpha_get(lattice));
1696 beta = hkl_parameter_value_unit_get(hkl_lattice_beta_get(lattice));
1697 gamma = hkl_parameter_value_unit_get(hkl_lattice_gamma_get(lattice));
1699 gtk_list_store_insert_with_values(priv->_liststore_crystals,
1700 &iter, -1,
1701 SAMPLE_COL_SAMPLE, sample,
1702 SAMPLE_COL_NAME, hkl_sample_name_get(sample),
1703 SAMPLE_COL_A, a,
1704 SAMPLE_COL_B, b,
1705 SAMPLE_COL_C, c,
1706 SAMPLE_COL_ALPHA, alpha,
1707 SAMPLE_COL_BETA, beta,
1708 SAMPLE_COL_GAMMA, gamma,
1709 -1);
1710 return iter;
1713 static void
1714 set_up_tree_view_crystals (HklGuiWindow* self)
1716 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1717 GtkTreeIter iter = {0};
1718 GtkTreePath *path = NULL;
1720 g_return_if_fail (self != NULL);
1722 iter = _add_sample(self, priv->sample);
1724 path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->_liststore_crystals),
1725 &iter);
1727 gtk_tree_view_set_cursor(priv->_treeview_crystals, path, NULL, FALSE);
1729 gtk_tree_path_free(path);
1732 static void
1733 _add_sample_and_edit_name(HklGuiWindow *self, HklSample *sample)
1735 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1736 GtkTreeIter iter = {0};
1737 GtkTreePath* path = NULL;
1738 GtkTreeViewColumn* column = NULL;
1740 iter = _add_sample(self, sample);
1742 path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->_liststore_crystals),
1743 &iter);
1744 column = gtk_tree_view_get_column (priv->_treeview_crystals, 0);
1745 gtk_tree_view_set_cursor (priv->_treeview_crystals, path, column, TRUE);
1747 gtk_tree_path_free(path);
1750 void
1751 hkl_gui_window_toolbutton_add_crystal_clicked_cb (GtkToolButton* _sender, gpointer user_data)
1753 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1754 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1755 HklSample *sample;
1757 g_return_if_fail (user_data != NULL);
1759 sample = hkl_sample_new ("new");
1760 if(sample)
1761 _add_sample_and_edit_name(self, sample);
1764 void
1765 hkl_gui_window_toolbutton_copy_crystal_clicked_cb (GtkToolButton* _sender, gpointer user_data)
1767 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1768 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1769 HklSample *copy = NULL;
1771 g_return_if_fail (self != NULL);
1773 if(priv->sample) {
1774 copy = hkl_sample_new_copy(priv->sample);
1775 if (copy)
1776 _add_sample_and_edit_name(self, copy);
1777 }else
1778 gtk_statusbar_push (priv->_statusbar, (guint) 0, "Please select a crystal to copy.");
1781 void
1782 hkl_gui_window_toolbutton_del_crystal_clicked_cb (GtkToolButton* _sender, gpointer user_data)
1784 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1785 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1787 g_return_if_fail (user_data != NULL);
1789 if (priv->sample != NULL) {
1790 guint n_rows;
1792 n_rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(priv->_liststore_crystals),
1793 NULL );
1794 if (n_rows == 1)
1795 return;
1796 else {
1797 GtkTreeIter iter = {0};
1798 GtkTreePath *path = NULL;
1799 GtkTreeViewColumn *column = NULL;
1801 gtk_tree_view_get_cursor(priv->_treeview_crystals,
1802 &path, &column);
1803 if (path){
1804 if (gtk_tree_model_get_iter (GTK_TREE_MODEL(priv->_liststore_crystals),
1805 &iter, path) == TRUE) {
1806 gtk_tree_path_free(path);
1808 hkl_sample_free(priv->sample);
1809 if (gtk_list_store_remove(priv->_liststore_crystals,
1810 &iter) == TRUE){
1811 path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->_liststore_crystals),
1812 &iter);
1813 gtk_tree_view_set_cursor(priv->_treeview_crystals,
1814 path, NULL, FALSE);
1822 #define get_lattice_parameter(lattice, parameter) do{ \
1823 HklParameter *p = hkl_parameter_new_copy(hkl_lattice_## parameter ##_get(lattice)); \
1824 hkl_parameter_min_max_unit_set(p, \
1825 gtk_spin_button_get_value(priv->_spinbutton_## parameter ##_min), \
1826 gtk_spin_button_get_value(priv->_spinbutton_## parameter ##_max)); \
1827 hkl_parameter_fit_set(p, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->_checkbutton_## parameter))); \
1828 hkl_lattice_## parameter ##_set(lattice, p); \
1829 hkl_parameter_free(p); \
1830 } while(0)
1832 #define get_ux_uy_uz(sample, parameter) do { \
1833 HklParameter *p; \
1834 p = hkl_parameter_new_copy(hkl_sample_## parameter ##_get(sample)); \
1835 hkl_parameter_value_unit_set(p, \
1836 gtk_spin_button_get_value (priv->_spinbutton_## parameter), \
1837 NULL); \
1838 hkl_parameter_fit_set(p, \
1839 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->_checkbutton_## parameter))); \
1840 hkl_sample_## parameter ##_set(sample, p); \
1841 hkl_parameter_free(p); \
1842 }while(0)
1845 static gboolean
1846 _update_crystal_model(GtkTreeModel *model,
1847 GtkTreePath *path,
1848 GtkTreeIter *iter,
1849 gpointer data)
1851 HklGuiWindow *self = HKL_GUI_WINDOW(data);
1852 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(data);
1853 HklSample *sample = NULL;
1855 gtk_tree_model_get(model, iter,
1856 SAMPLE_COL_SAMPLE, &sample,
1857 -1);
1858 if(priv->sample == sample){
1859 const HklLattice *lattice;
1860 gdouble a, b, c, alpha, beta, gamma;
1862 lattice = hkl_sample_lattice_get(sample);
1863 a = hkl_parameter_value_unit_get(hkl_lattice_a_get(lattice));
1864 b = hkl_parameter_value_unit_get(hkl_lattice_b_get(lattice));
1865 c = hkl_parameter_value_unit_get(hkl_lattice_c_get(lattice));
1866 alpha = hkl_parameter_value_unit_get(hkl_lattice_alpha_get(lattice));
1867 beta = hkl_parameter_value_unit_get(hkl_lattice_beta_get(lattice));
1868 gamma = hkl_parameter_value_unit_get(hkl_lattice_gamma_get(lattice));
1870 gtk_list_store_set(priv->_liststore_crystals,
1871 iter,
1872 SAMPLE_COL_NAME, hkl_sample_name_get(sample),
1873 SAMPLE_COL_A, a,
1874 SAMPLE_COL_B, b,
1875 SAMPLE_COL_C, c,
1876 SAMPLE_COL_ALPHA, alpha,
1877 SAMPLE_COL_BETA, beta,
1878 SAMPLE_COL_GAMMA, gamma,
1879 -1);
1880 diffractometer_get_pseudo(priv->diffractometer);
1882 return TRUE;
1884 return FALSE;
1887 static void
1888 update_crystal_model(HklGuiWindow *self)
1890 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
1892 gtk_tree_model_foreach(GTK_TREE_MODEL(priv->_liststore_crystals),
1893 _update_crystal_model,
1894 self);
1897 /* apply crystal parameters */
1898 void
1899 hkl_gui_window_button2_clicked_cb (GtkButton* _sender, gpointer user_data)
1901 HklGuiWindow *self = HKL_GUI_WINDOW(user_data);
1902 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(user_data);
1904 g_return_if_fail (self != NULL);
1906 if (priv->sample != NULL) {
1907 gdouble a, b, c, alpha, beta, gamma;
1908 gdouble ux, uy, uz;
1909 HklLattice *lattice;
1910 HklParameter *p;
1912 fprintf(stderr, "%s\n", __func__);
1913 /* lattice parameters */
1914 a = gtk_spin_button_get_value (priv->_spinbutton_a);
1915 b = gtk_spin_button_get_value (priv->_spinbutton_b);
1916 c = gtk_spin_button_get_value (priv->_spinbutton_c);
1917 alpha = gtk_spin_button_get_value (priv->_spinbutton_alpha);
1918 beta = gtk_spin_button_get_value (priv->_spinbutton_beta);
1919 gamma = gtk_spin_button_get_value (priv->_spinbutton_gamma);
1921 lattice = hkl_lattice_new(a, b, c,
1922 alpha * HKL_DEGTORAD,
1923 beta * HKL_DEGTORAD,
1924 gamma * HKL_DEGTORAD);
1926 get_lattice_parameter(lattice, a);
1927 get_lattice_parameter(lattice, b);
1928 get_lattice_parameter(lattice, c);
1929 get_lattice_parameter(lattice, alpha);
1930 get_lattice_parameter(lattice, beta);
1931 get_lattice_parameter(lattice, gamma);
1933 hkl_sample_lattice_set(priv->sample, lattice);
1935 hkl_lattice_free(lattice);
1937 /* UB */
1938 get_ux_uy_uz(priv->sample, ux);
1939 get_ux_uy_uz(priv->sample, uy);
1940 get_ux_uy_uz(priv->sample, uz);
1942 update_crystal_model (self);
1943 update_reciprocal_lattice (self);
1944 update_UB (self);
1945 update_pseudo_axes (self);
1946 update_pseudo_axes_frames (self);
1955 static void _hkl_gui_window_on_spinbutton_lambda_value_changed_gtk_spin_button_value_changed (GtkSpinButton* _sender, gpointer self) {
1957 hkl_gui_window_on_spinbutton_lambda_value_changed (self);
1962 static void _hkl_gui_window_on_spinbutton_uxuyuz_value_changed_gtk_spin_button_value_changed (GtkSpinButton* _sender, gpointer self) {
1964 hkl_gui_window_on_spinbutton_uxuyuz_value_changed (self);
1969 static void _hkl_gui_window_on_checkbutton_a_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
1971 hkl_gui_window_on_checkbutton_a_toggled (self);
1976 static void _hkl_gui_window_on_checkbutton_b_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
1978 hkl_gui_window_on_checkbutton_b_toggled (self);
1983 static void _hkl_gui_window_on_checkbutton_c_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
1985 hkl_gui_window_on_checkbutton_c_toggled (self);
1990 static void _hkl_gui_window_on_checkbutton_alpha_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
1992 hkl_gui_window_on_checkbutton_alpha_toggled (self);
1997 static void _hkl_gui_window_on_checkbutton_beta_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
1999 hkl_gui_window_on_checkbutton_beta_toggled (self);
2004 static void _hkl_gui_window_on_checkbutton_gamma_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
2006 hkl_gui_window_on_checkbutton_gamma_toggled (self);
2011 static void _hkl_gui_window_on_checkbutton_Ux_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
2013 hkl_gui_window_on_checkbutton_Ux_toggled (self);
2018 static void _hkl_gui_window_on_checkbutton_Uy_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
2020 hkl_gui_window_on_checkbutton_Uy_toggled (self);
2025 static void _hkl_gui_window_on_checkbutton_Uz_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender, gpointer self) {
2027 hkl_gui_window_on_checkbutton_Uz_toggled (self);
2032 static void _hkl_gui_window_on_tree_view_pseudo_axes_cursor_changed_gtk_tree_view_cursor_changed (GtkTreeView* _sender, gpointer self) {
2034 hkl_gui_window_on_tree_view_pseudo_axes_cursor_changed (self);
2039 static gboolean _hkl_gui_window_on_tree_view_crystals_key_press_event_gtk_widget_key_press_event (GtkWidget* _sender, GdkEventKey* event, gpointer self) {
2040 gboolean result;
2041 result = hkl_gui_window_on_tree_view_crystals_key_press_event (event, self);
2043 return result;
2050 static void _hkl_gui_window_on_toolbutton_setUB_clicked_gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
2052 hkl_gui_window_on_toolbutton_setUB_clicked (self);
2057 static void _hkl_gui_window_on_toolbutton_computeUB_clicked_gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
2059 hkl_gui_window_on_toolbutton_computeUB_clicked (self);
2064 static void _hkl_gui_window_on_toolbutton_affiner_clicked_gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
2066 hkl_gui_window_on_toolbutton_affiner_clicked (self);
2071 static void _hkl_gui_window_on_menuitem5_activate_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
2073 hkl_gui_window_on_menuitem5_activate (self);
2078 static void _hkl_gui_window_on_button1_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
2080 hkl_gui_window_on_button1_clicked (self);
2085 static void _hkl_gui_window_on_combobox1_changed_gtk_combo_box_changed (GtkComboBox* _sender, gpointer self) {
2087 hkl_gui_window_on_combobox1_changed (self);
2090 static void _hkl_gui_window_on_cell_tree_view_pseudo_axes_is_initialized_toggled_gtk_cell_renderer_toggle_toggled (GtkCellRendererToggle* _sender, const gchar* path, gpointer self) {
2092 hkl_gui_window_on_cell_tree_view_pseudo_axes_is_initialized_toggled (path, self);
2099 static void _hkl_gui_window_on_tree_view1_cursor_changed_gtk_tree_view_cursor_changed (GtkTreeView* _sender, gpointer self) {
2101 hkl_gui_window_on_tree_view1_cursor_changed (self);
2111 static void hkl_gui_window_set_up_3D (HklGuiWindow* self) {
2112 HklGeometry* _tmp0_;
2113 HklGeometryConfig* _tmp1_;
2114 HklGeometryType _tmp2_;
2115 GtkVBox* _tmp7_;
2116 HklGui3DFrame* _tmp8_;
2117 GtkFrame* _tmp9_ = NULL;
2118 GtkFrame* _tmp10_;
2119 GtkVBox* _tmp11_;
2121 g_return_if_fail (self != NULL);
2123 _tmp0_ = priv->geometry;
2125 _tmp1_ = _tmp0_->config;
2127 _tmp2_ = (*_tmp1_).type;
2129 switch (_tmp2_) {
2131 case HKL_GEOMETRY_TYPE_KAPPA6C:
2134 HklGeometry* _tmp3_;
2135 HklGui3DFrame* _tmp4_;
2137 _tmp3_ = priv->geometry;
2139 _tmp4_ = hkl_gui_3d_frame_new ("../data/diffabs.yaml", _tmp3_);
2141 _g_object_unref0 (priv->Frame3D);
2143 priv->Frame3D = _tmp4_;
2145 break;
2149 case HKL_GEOMETRY_TYPE_KAPPA4C_VERTICAL:
2152 HklGeometry* _tmp5_;
2153 HklGui3DFrame* _tmp6_;
2155 _tmp5_ = priv->geometry;
2157 _tmp6_ = hkl_gui_3d_frame_new ("../data/cristal4C.yaml", _tmp5_);
2159 _g_object_unref0 (priv->Frame3D);
2161 priv->Frame3D = _tmp6_;
2163 break;
2166 default:
2168 break;
2172 _tmp7_ = priv->_vbox7;
2174 _tmp8_ = priv->Frame3D;
2176 _tmp9_ = hkl_gui_3d_frame_frame (_tmp8_);
2178 _tmp10_ = _tmp9_;
2180 gtk_box_pack_start ((GtkBox*) _tmp7_, (GtkWidget*) _tmp10_, TRUE, TRUE, (guint) 0);
2182 _g_object_unref0 (_tmp10_);
2184 _tmp11_ = priv->_vbox7;
2186 gtk_widget_show_all ((GtkWidget*) _tmp11_);
2194 static void hkl_gui_window_on_spinbutton_lambda_value_changed (HklGuiWindow* self) {
2195 HklGeometry* _tmp0_;
2196 GtkSpinButton* _tmp1_;
2197 gdouble _tmp2_ = 0.0;
2199 g_return_if_fail (self != NULL);
2201 _tmp0_ = priv->geometry;
2203 _tmp1_ = priv->_spinbutton_lambda;
2205 _tmp2_ = gtk_spin_button_get_value (_tmp1_);
2207 _tmp0_->source.wave_length = _tmp2_;
2209 hkl_gui_window_update_pseudo_axes (self);
2211 hkl_gui_window_update_pseudo_axes_frames (self);
2216 static void hkl_gui_window_on_spinbutton_uxuyuz_value_changed (HklGuiWindow* self) {
2218 g_return_if_fail (self != NULL);
2225 static void hkl_gui_window_on_checkbutton_a_toggled (HklGuiWindow* self) {
2226 HklSampleList* _tmp0_;
2227 HklSample* _tmp1_;
2228 HklSample* sample;
2229 HklSample* _tmp2_;
2231 g_return_if_fail (self != NULL);
2233 _tmp0_ = priv->samples;
2235 _tmp1_ = _tmp0_->current;
2237 sample = _tmp1_;
2239 _tmp2_ = sample;
2241 if (_tmp2_ != NULL) {
2243 HklSample* _tmp3_;
2244 HklLattice* _tmp4_;
2245 HklParameter* _tmp5_;
2246 GtkCheckButton* _tmp6_;
2247 gboolean _tmp7_ = FALSE;
2249 _tmp3_ = sample;
2251 _tmp4_ = _tmp3_->lattice;
2253 _tmp5_ = _tmp4_->a;
2255 _tmp6_ = priv->_checkbutton_a;
2257 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2259 (*_tmp5_).fit = _tmp7_;
2265 static void hkl_gui_window_on_checkbutton_b_toggled (HklGuiWindow* self) {
2266 HklSampleList* _tmp0_;
2267 HklSample* _tmp1_;
2268 HklSample* sample;
2269 HklSample* _tmp2_;
2271 g_return_if_fail (self != NULL);
2273 _tmp0_ = priv->samples;
2275 _tmp1_ = _tmp0_->current;
2277 sample = _tmp1_;
2279 _tmp2_ = sample;
2281 if (_tmp2_ != NULL) {
2283 HklSample* _tmp3_;
2284 HklLattice* _tmp4_;
2285 HklParameter* _tmp5_;
2286 GtkCheckButton* _tmp6_;
2287 gboolean _tmp7_ = FALSE;
2289 _tmp3_ = sample;
2291 _tmp4_ = _tmp3_->lattice;
2293 _tmp5_ = _tmp4_->b;
2295 _tmp6_ = priv->_checkbutton_b;
2297 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2299 (*_tmp5_).fit = _tmp7_;
2305 static void hkl_gui_window_on_checkbutton_c_toggled (HklGuiWindow* self) {
2306 HklSampleList* _tmp0_;
2307 HklSample* _tmp1_;
2308 HklSample* sample;
2309 HklSample* _tmp2_;
2311 g_return_if_fail (self != NULL);
2313 _tmp0_ = priv->samples;
2315 _tmp1_ = _tmp0_->current;
2317 sample = _tmp1_;
2319 _tmp2_ = sample;
2321 if (_tmp2_ != NULL) {
2323 HklSample* _tmp3_;
2324 HklLattice* _tmp4_;
2325 HklParameter* _tmp5_;
2326 GtkCheckButton* _tmp6_;
2327 gboolean _tmp7_ = FALSE;
2329 _tmp3_ = sample;
2331 _tmp4_ = _tmp3_->lattice;
2333 _tmp5_ = _tmp4_->c;
2335 _tmp6_ = priv->_checkbutton_c;
2337 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2339 (*_tmp5_).fit = _tmp7_;
2345 static void hkl_gui_window_on_checkbutton_alpha_toggled (HklGuiWindow* self) {
2346 HklSampleList* _tmp0_;
2347 HklSample* _tmp1_;
2348 HklSample* sample;
2349 HklSample* _tmp2_;
2351 g_return_if_fail (self != NULL);
2353 _tmp0_ = priv->samples;
2355 _tmp1_ = _tmp0_->current;
2357 sample = _tmp1_;
2359 _tmp2_ = sample;
2361 if (_tmp2_ != NULL) {
2363 HklSample* _tmp3_;
2364 HklLattice* _tmp4_;
2365 HklParameter* _tmp5_;
2366 GtkCheckButton* _tmp6_;
2367 gboolean _tmp7_ = FALSE;
2369 _tmp3_ = sample;
2371 _tmp4_ = _tmp3_->lattice;
2373 _tmp5_ = _tmp4_->alpha;
2375 _tmp6_ = priv->_checkbutton_alpha;
2377 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2379 (*_tmp5_).fit = _tmp7_;
2385 static void hkl_gui_window_on_checkbutton_beta_toggled (HklGuiWindow* self) {
2386 HklSampleList* _tmp0_;
2387 HklSample* _tmp1_;
2388 HklSample* sample;
2389 HklSample* _tmp2_;
2391 g_return_if_fail (self != NULL);
2393 _tmp0_ = priv->samples;
2395 _tmp1_ = _tmp0_->current;
2397 sample = _tmp1_;
2399 _tmp2_ = sample;
2401 if (_tmp2_ != NULL) {
2403 HklSample* _tmp3_;
2404 HklLattice* _tmp4_;
2405 HklParameter* _tmp5_;
2406 GtkCheckButton* _tmp6_;
2407 gboolean _tmp7_ = FALSE;
2409 _tmp3_ = sample;
2411 _tmp4_ = _tmp3_->lattice;
2413 _tmp5_ = _tmp4_->beta;
2415 _tmp6_ = priv->_checkbutton_beta;
2417 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2419 (*_tmp5_).fit = _tmp7_;
2425 static void hkl_gui_window_on_checkbutton_gamma_toggled (HklGuiWindow* self) {
2426 HklSampleList* _tmp0_;
2427 HklSample* _tmp1_;
2428 HklSample* sample;
2429 HklSample* _tmp2_;
2431 g_return_if_fail (self != NULL);
2433 _tmp0_ = priv->samples;
2435 _tmp1_ = _tmp0_->current;
2437 sample = _tmp1_;
2439 _tmp2_ = sample;
2441 if (_tmp2_ != NULL) {
2443 HklSample* _tmp3_;
2444 HklLattice* _tmp4_;
2445 HklParameter* _tmp5_;
2446 GtkCheckButton* _tmp6_;
2447 gboolean _tmp7_ = FALSE;
2449 _tmp3_ = sample;
2451 _tmp4_ = _tmp3_->lattice;
2453 _tmp5_ = _tmp4_->gamma;
2455 _tmp6_ = priv->_checkbutton_gamma;
2457 _tmp7_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp6_);
2459 (*_tmp5_).fit = _tmp7_;
2465 static void hkl_gui_window_on_checkbutton_Ux_toggled (HklGuiWindow* self) {
2466 HklSampleList* _tmp0_;
2467 HklSample* _tmp1_;
2468 HklSample* sample;
2469 HklSample* _tmp2_;
2471 g_return_if_fail (self != NULL);
2473 _tmp0_ = priv->samples;
2475 _tmp1_ = _tmp0_->current;
2477 sample = _tmp1_;
2479 _tmp2_ = sample;
2481 if (_tmp2_ != NULL) {
2483 HklSample* _tmp3_;
2484 HklParameter* _tmp4_;
2485 GtkCheckButton* _tmp5_;
2486 gboolean _tmp6_ = FALSE;
2488 _tmp3_ = sample;
2490 _tmp4_ = _tmp3_->ux;
2492 _tmp5_ = priv->_checkbutton_Ux;
2494 _tmp6_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp5_);
2496 (*_tmp4_).fit = _tmp6_;
2502 static void hkl_gui_window_on_checkbutton_Uy_toggled (HklGuiWindow* self) {
2503 HklSampleList* _tmp0_;
2504 HklSample* _tmp1_;
2505 HklSample* sample;
2506 HklSample* _tmp2_;
2508 g_return_if_fail (self != NULL);
2510 _tmp0_ = priv->samples;
2512 _tmp1_ = _tmp0_->current;
2514 sample = _tmp1_;
2516 _tmp2_ = sample;
2518 if (_tmp2_ != NULL) {
2520 HklSample* _tmp3_;
2521 HklParameter* _tmp4_;
2522 GtkCheckButton* _tmp5_;
2523 gboolean _tmp6_ = FALSE;
2525 _tmp3_ = sample;
2527 _tmp4_ = _tmp3_->uy;
2529 _tmp5_ = priv->_checkbutton_Uy;
2531 _tmp6_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp5_);
2533 (*_tmp4_).fit = _tmp6_;
2539 static void hkl_gui_window_on_checkbutton_Uz_toggled (HklGuiWindow* self) {
2540 HklSampleList* _tmp0_;
2541 HklSample* _tmp1_;
2542 HklSample* sample;
2543 HklSample* _tmp2_;
2545 g_return_if_fail (self != NULL);
2547 _tmp0_ = priv->samples;
2549 _tmp1_ = _tmp0_->current;
2551 sample = _tmp1_;
2553 _tmp2_ = sample;
2555 if (_tmp2_ != NULL) {
2557 HklSample* _tmp3_;
2558 HklParameter* _tmp4_;
2559 GtkCheckButton* _tmp5_;
2560 gboolean _tmp6_ = FALSE;
2562 _tmp3_ = sample;
2564 _tmp4_ = _tmp3_->uz;
2566 _tmp5_ = priv->_checkbutton_Uz;
2568 _tmp6_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp5_);
2570 (*_tmp4_).fit = _tmp6_;
2575 static void hkl_gui_window_on_cell_tree_view_pseudo_axes_is_initialized_toggled (const gchar* path, HklGuiWindow* self) {
2576 GtkTreeModel* model = NULL;
2577 GtkTreeIter iter = {0};
2578 HklPseudoAxis* pseudoAxis = NULL;
2579 gboolean old_flag = FALSE;
2580 GtkTreeView* _tmp0_;
2581 GtkTreeModel* _tmp1_ = NULL;
2582 GtkTreeModel* _tmp2_;
2583 GtkTreeModel* _tmp3_;
2584 const gchar* _tmp4_;
2585 GtkTreeIter _tmp5_ = {0};
2586 GtkTreeModel* _tmp6_;
2587 GtkTreeIter _tmp7_;
2588 gboolean _tmp8_;
2590 g_return_if_fail (self != NULL);
2592 g_return_if_fail (path != NULL);
2594 _tmp0_ = priv->_treeview_pseudo_axes;
2596 _tmp1_ = gtk_tree_view_get_model (_tmp0_);
2598 _tmp2_ = _g_object_ref0 (_tmp1_);
2600 _g_object_unref0 (model);
2602 model = _tmp2_;
2604 _tmp3_ = model;
2606 _tmp4_ = path;
2608 gtk_tree_model_get_iter_from_string (_tmp3_, &_tmp5_, _tmp4_);
2610 iter = _tmp5_;
2612 _tmp6_ = model;
2614 _tmp7_ = iter;
2616 gtk_tree_model_get (_tmp6_, &_tmp7_, PSEUDO_AXIS_COL_PSEUDOAXIS, &pseudoAxis, PSEUDO_AXIS_COL_INITIALIZED, &old_flag, -1);
2618 _tmp8_ = old_flag;
2620 if (!_tmp8_) {
2622 HklPseudoAxis* _tmp9_;
2623 HklPseudoAxisEngine* _tmp10_;
2624 gboolean _tmp11_ = FALSE;
2626 _tmp9_ = pseudoAxis;
2628 _tmp10_ = _tmp9_->engine;
2630 _tmp11_ = hkl_pseudo_axis_engine_initialize (_tmp10_, NULL);
2632 if (_tmp11_) {
2634 hkl_gui_window_update_pseudo_axes (self);
2639 _g_object_unref0 (model);
2643 static void hkl_gui_window_on_toolbutton_setUB_clicked (HklGuiWindow* self) {
2644 HklSampleList* _tmp0_;
2645 HklSample* _tmp1_;
2647 g_return_if_fail (self != NULL);
2649 _tmp0_ = priv->samples;
2651 _tmp1_ = _tmp0_->current;
2653 if (_tmp1_ != NULL) {
2655 HklMatrix UB = {0};
2656 HklSampleList* _tmp2_;
2657 HklSample* _tmp3_;
2658 HklMatrix _tmp4_ = {0};
2659 HklMatrix _tmp5_;
2660 gdouble** _tmp6_;
2661 gint _tmp6__length1;
2662 gdouble* _tmp7_;
2663 gint _tmp7__length1;
2664 GtkSpinButton* _tmp8_;
2665 gdouble _tmp9_ = 0.0;
2666 gdouble _tmp10_;
2667 HklMatrix _tmp11_;
2668 gdouble** _tmp12_;
2669 gint _tmp12__length1;
2670 gdouble* _tmp13_;
2671 gint _tmp13__length1;
2672 GtkSpinButton* _tmp14_;
2673 gdouble _tmp15_ = 0.0;
2674 gdouble _tmp16_;
2675 HklMatrix _tmp17_;
2676 gdouble** _tmp18_;
2677 gint _tmp18__length1;
2678 gdouble* _tmp19_;
2679 gint _tmp19__length1;
2680 GtkSpinButton* _tmp20_;
2681 gdouble _tmp21_ = 0.0;
2682 gdouble _tmp22_;
2683 HklMatrix _tmp23_;
2684 gdouble** _tmp24_;
2685 gint _tmp24__length1;
2686 gdouble* _tmp25_;
2687 gint _tmp25__length1;
2688 GtkSpinButton* _tmp26_;
2689 gdouble _tmp27_ = 0.0;
2690 gdouble _tmp28_;
2691 HklMatrix _tmp29_;
2692 gdouble** _tmp30_;
2693 gint _tmp30__length1;
2694 gdouble* _tmp31_;
2695 gint _tmp31__length1;
2696 GtkSpinButton* _tmp32_;
2697 gdouble _tmp33_ = 0.0;
2698 gdouble _tmp34_;
2699 HklMatrix _tmp35_;
2700 gdouble** _tmp36_;
2701 gint _tmp36__length1;
2702 gdouble* _tmp37_;
2703 gint _tmp37__length1;
2704 GtkSpinButton* _tmp38_;
2705 gdouble _tmp39_ = 0.0;
2706 gdouble _tmp40_;
2707 HklMatrix _tmp41_;
2708 gdouble** _tmp42_;
2709 gint _tmp42__length1;
2710 gdouble* _tmp43_;
2711 gint _tmp43__length1;
2712 GtkSpinButton* _tmp44_;
2713 gdouble _tmp45_ = 0.0;
2714 gdouble _tmp46_;
2715 HklMatrix _tmp47_;
2716 gdouble** _tmp48_;
2717 gint _tmp48__length1;
2718 gdouble* _tmp49_;
2719 gint _tmp49__length1;
2720 GtkSpinButton* _tmp50_;
2721 gdouble _tmp51_ = 0.0;
2722 gdouble _tmp52_;
2723 HklMatrix _tmp53_;
2724 gdouble** _tmp54_;
2725 gint _tmp54__length1;
2726 gdouble* _tmp55_;
2727 gint _tmp55__length1;
2728 GtkSpinButton* _tmp56_;
2729 gdouble _tmp57_ = 0.0;
2730 gdouble _tmp58_;
2731 HklSampleList* _tmp59_;
2732 HklSample* _tmp60_;
2733 HklSampleList* _tmp61_;
2734 HklSample* _tmp62_;
2735 FILE* _tmp63_;
2736 HklSampleList* _tmp64_;
2737 HklSample* _tmp65_;
2739 _tmp2_ = priv->samples;
2741 _tmp3_ = _tmp2_->current;
2743 hkl_sample_get_UB (_tmp3_, &_tmp4_);
2745 (&UB);
2747 UB = _tmp4_;
2749 _tmp5_ = UB;
2751 _tmp6_ = _tmp5_.data;
2753 _tmp6__length1 = -1;
2755 _tmp7_ = _tmp6_[0];
2757 _tmp7__length1 = -1;
2759 _tmp8_ = priv->_spinbutton_U11;
2761 _tmp9_ = gtk_spin_button_get_value (_tmp8_);
2763 _tmp7_[0] = _tmp9_;
2765 _tmp10_ = _tmp7_[0];
2767 _tmp11_ = UB;
2769 _tmp12_ = _tmp11_.data;
2771 _tmp12__length1 = -1;
2773 _tmp13_ = _tmp12_[0];
2775 _tmp13__length1 = -1;
2777 _tmp14_ = priv->_spinbutton_U12;
2779 _tmp15_ = gtk_spin_button_get_value (_tmp14_);
2781 _tmp13_[1] = _tmp15_;
2783 _tmp16_ = _tmp13_[1];
2785 _tmp17_ = UB;
2787 _tmp18_ = _tmp17_.data;
2789 _tmp18__length1 = -1;
2791 _tmp19_ = _tmp18_[0];
2793 _tmp19__length1 = -1;
2795 _tmp20_ = priv->_spinbutton_U13;
2797 _tmp21_ = gtk_spin_button_get_value (_tmp20_);
2799 _tmp19_[2] = _tmp21_;
2801 _tmp22_ = _tmp19_[2];
2803 _tmp23_ = UB;
2805 _tmp24_ = _tmp23_.data;
2807 _tmp24__length1 = -1;
2809 _tmp25_ = _tmp24_[1];
2811 _tmp25__length1 = -1;
2813 _tmp26_ = priv->_spinbutton_U21;
2815 _tmp27_ = gtk_spin_button_get_value (_tmp26_);
2817 _tmp25_[0] = _tmp27_;
2819 _tmp28_ = _tmp25_[0];
2821 _tmp29_ = UB;
2823 _tmp30_ = _tmp29_.data;
2825 _tmp30__length1 = -1;
2827 _tmp31_ = _tmp30_[1];
2829 _tmp31__length1 = -1;
2831 _tmp32_ = priv->_spinbutton_U22;
2833 _tmp33_ = gtk_spin_button_get_value (_tmp32_);
2835 _tmp31_[1] = _tmp33_;
2837 _tmp34_ = _tmp31_[1];
2839 _tmp35_ = UB;
2841 _tmp36_ = _tmp35_.data;
2843 _tmp36__length1 = -1;
2845 _tmp37_ = _tmp36_[1];
2847 _tmp37__length1 = -1;
2849 _tmp38_ = priv->_spinbutton_U23;
2851 _tmp39_ = gtk_spin_button_get_value (_tmp38_);
2853 _tmp37_[2] = _tmp39_;
2855 _tmp40_ = _tmp37_[2];
2857 _tmp41_ = UB;
2859 _tmp42_ = _tmp41_.data;
2861 _tmp42__length1 = -1;
2863 _tmp43_ = _tmp42_[2];
2865 _tmp43__length1 = -1;
2867 _tmp44_ = priv->_spinbutton_U31;
2869 _tmp45_ = gtk_spin_button_get_value (_tmp44_);
2871 _tmp43_[0] = _tmp45_;
2873 _tmp46_ = _tmp43_[0];
2875 _tmp47_ = UB;
2877 _tmp48_ = _tmp47_.data;
2879 _tmp48__length1 = -1;
2881 _tmp49_ = _tmp48_[2];
2883 _tmp49__length1 = -1;
2885 _tmp50_ = priv->_spinbutton_U32;
2887 _tmp51_ = gtk_spin_button_get_value (_tmp50_);
2889 _tmp49_[1] = _tmp51_;
2891 _tmp52_ = _tmp49_[1];
2893 _tmp53_ = UB;
2895 _tmp54_ = _tmp53_.data;
2897 _tmp54__length1 = -1;
2899 _tmp55_ = _tmp54_[2];
2901 _tmp55__length1 = -1;
2903 _tmp56_ = priv->_spinbutton_U33;
2905 _tmp57_ = gtk_spin_button_get_value (_tmp56_);
2907 _tmp55_[2] = _tmp57_;
2909 _tmp58_ = _tmp55_[2];
2911 _tmp59_ = priv->samples;
2913 _tmp60_ = _tmp59_->current;
2915 hkl_sample_set_UB (_tmp60_, &UB);
2917 _tmp61_ = priv->samples;
2919 _tmp62_ = _tmp61_->current;
2921 _tmp63_ = stdout;
2923 hkl_sample_fprintf (_tmp63_, _tmp62_);
2925 hkl_gui_window_update_lattice (self);
2927 hkl_gui_window_update_lattice_parameters (self);
2929 hkl_gui_window_update_reciprocal_lattice (self);
2931 _tmp64_ = priv->samples;
2933 _tmp65_ = _tmp64_->current;
2935 hkl_gui_window_update_crystal_model (self, _tmp65_);
2937 hkl_gui_window_update_UB (self);
2939 hkl_gui_window_update_UxUyUz (self);
2941 hkl_gui_window_update_pseudo_axes (self);
2943 hkl_gui_window_update_pseudo_axes_frames (self);
2945 (&UB);
2951 static void hkl_gui_window_on_toolbutton_computeUB_clicked (HklGuiWindow* self) {
2952 HklSampleList* _tmp0_;
2953 HklSample* _tmp1_;
2954 HklSample* sample;
2955 HklSample* _tmp2_;
2957 g_return_if_fail (self != NULL);
2959 _tmp0_ = priv->samples;
2961 _tmp1_ = _tmp0_->current;
2963 sample = _tmp1_;
2965 _tmp2_ = sample;
2967 if (_tmp2_ != NULL) {
2969 HklSample* _tmp3_;
2971 _tmp3_ = sample;
2973 hkl_sample_compute_UB_busing_levy (_tmp3_, (gsize) 0, (gsize) 1);
2975 hkl_gui_window_update_UB (self);
2977 hkl_gui_window_update_UxUyUz (self);
2979 hkl_gui_window_update_pseudo_axes (self);
2981 hkl_gui_window_update_pseudo_axes_frames (self);
2987 static void hkl_gui_window_on_toolbutton_affiner_clicked (HklGuiWindow* self) {
2988 HklSampleList* _tmp0_;
2989 HklSample* _tmp1_;
2990 HklSample* sample;
2991 HklSample* _tmp2_;
2992 HklSample* _tmp4_;
2994 g_return_if_fail (self != NULL);
2996 _tmp0_ = priv->samples;
2998 _tmp1_ = _tmp0_->current;
3000 sample = _tmp1_;
3002 _tmp2_ = sample;
3004 if (_tmp2_ != NULL) {
3006 HklSample* _tmp3_;
3008 _tmp3_ = sample;
3010 hkl_sample_affine (_tmp3_);
3014 _tmp4_ = sample;
3016 hkl_gui_window_update_crystal_model (self, _tmp4_);
3018 hkl_gui_window_update_lattice (self);
3020 hkl_gui_window_update_reciprocal_lattice (self);
3022 hkl_gui_window_update_UB (self);
3024 hkl_gui_window_update_UxUyUz (self);
3031 static gboolean hkl_gui_window_on_tree_view_crystals_key_press_event (GdkEventKey* event, HklGuiWindow* self) {
3032 gboolean result = FALSE;
3034 g_return_val_if_fail (self != NULL, FALSE);
3036 g_return_val_if_fail (event != NULL, FALSE);
3038 result = TRUE;
3040 return result;
3045 static void hkl_gui_window_on_menuitem5_activate (HklGuiWindow* self) {
3046 GtkDialog* _tmp0_;
3048 g_return_if_fail (self != NULL);
3050 _tmp0_ = priv->_dialog1;
3052 gtk_widget_show ((GtkWidget*) _tmp0_);
3057 void hkl_gui_window_on_button1_clicked (HklGuiWindow* self) {
3058 GtkDialog* _tmp0_;
3060 g_return_if_fail (self != NULL);
3062 _tmp0_ = priv->_dialog1;
3064 gtk_widget_hide ((GtkWidget*) _tmp0_);
3070 static void
3071 hkl_gui_window_class_init (HklGuiWindowClass *class)
3073 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
3075 g_type_class_add_private (class, sizeof (HklGuiWindowPrivate));
3077 /* virtual method */
3078 gobject_class->finalize = finalize;
3082 static void hkl_gui_window_init (HklGuiWindow * self)
3084 HklGuiWindowPrivate *priv = HKL_GUI_WINDOW_GET_PRIVATE(self);
3086 priv->diffractometer = NULL;
3088 darray_init(priv->pseudo_frames);
3090 priv->sample = hkl_sample_new ("test");
3091 priv->reciprocal = hkl_lattice_new_default ();
3093 hkl_gui_window_get_widgets_and_objects_from_ui (self);
3095 set_up_diffractometer_model (self);
3097 set_up_tree_view_crystals (self);
3100 int main (int argc, char ** argv)
3102 gtk_init (&argc, &argv);
3104 hkl_gui_window_new ();
3106 gtk_main ();
3108 return 0;