remove unsafe hkl_geometry_axes_get method
[hkl.git] / gui / hkl-gui-callbacks.cpp
blobcbf018fcf38eccda5912827cd70151f838e86158
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-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 "hkl-gui.h"
24 #include "hkl.h"
26 void HKLWindow::on_treeView_pseudoAxes_cursor_changed(void)
28 LOG;
30 Gtk::TreeModel::Path path;
31 Gtk::TreeViewColumn * column;
32 _TreeView_pseudoAxes->get_cursor(path, column);
33 Gtk::ListStore::Row row = *(_pseudoAxeModel->get_iter(path));
34 HklParameter *parameter = row[_pseudoAxeModelColumns.parameter];
35 _TreeView_pseudoAxes_parameters->set_model(_mapPseudoAxeParameterModel[parameter]);
38 void HKLWindow::on_treeViewCrystals_cursor_changed(void)
40 LOG;
42 Gtk::TreeModel::Path path;
43 Gtk::TreeViewColumn * column;
44 _treeViewCrystals->get_cursor(path, column);
45 Gtk::TreeModel::iterator iter = _crystalModel->get_iter(path);
46 Gtk::ListStore::Row row = *(iter);
48 Glib::ustring name = row[_crystalModelColumns.name];
49 _sample = _samples[name];
50 hkl_engine_list_init(_engines, _geometry, _detector, _sample);
51 _treeViewReflections->set_model(_mapReflectionModel[name]);
52 this->updateLattice();
53 this->updateLatticeParameters();
54 this->updateReciprocalLattice();
55 this->updateUxUyUz();
56 this->updateUB();
57 this->updatePseudoAxes();
58 this->updatePseudoAxesFrames();
61 void HKLWindow::on_spinbutton_a_value_changed(void)
63 LOG;
64 // TODO change the cell background color if not synchro
67 void HKLWindow::on_spinbutton_b_value_changed(void)
69 LOG;
70 // TODO change the cell background color if not synchro
73 void HKLWindow::on_spinbutton_c_value_changed(void)
75 LOG;
76 // TODO change the cell background color if not synchro
79 void HKLWindow::on_spinbutton_alpha_value_changed(void)
81 LOG;
82 // TODO change the cell background color if not synchro
85 void HKLWindow::on_spinbutton_beta_value_changed(void)
87 LOG;
88 // TODO change the cell background color if not synchro
91 void HKLWindow::on_spinbutton_gamma_value_changed(void)
93 LOG;
94 // TODO change the cell background color if not synchro
97 void HKLWindow::on_spinbutton_a_min_value_changed(void)
99 LOG;
100 // TODO change the cell background color if not synchro
103 void HKLWindow::on_spinbutton_b_min_value_changed(void)
105 LOG;
106 // TODO change the cell background color if not synchro
109 void HKLWindow::on_spinbutton_c_min_value_changed(void)
111 LOG;
112 // TODO change the cell background color if not synchro
115 void HKLWindow::on_spinbutton_alpha_min_value_changed(void)
117 LOG;
118 // TODO change the cell background color if not synchro
121 void HKLWindow::on_spinbutton_beta_min_value_changed(void)
123 LOG;
124 // TODO change the cell background color if not synchro
127 void HKLWindow::on_spinbutton_gamma_min_value_changed(void)
129 LOG;
130 // TODO change the cell background color if not synchro
133 void HKLWindow::on_spinbutton_a_max_value_changed(void)
135 LOG;
136 // TODO change the cell background color if not synchro
139 void HKLWindow::on_spinbutton_b_max_value_changed(void)
141 LOG;
142 // TODO change the cell background color if not synchro
145 void HKLWindow::on_spinbutton_c_max_value_changed(void)
147 LOG;
148 // TODO change the cell background color if not synchro
151 void HKLWindow::on_spinbutton_alpha_max_value_changed(void)
153 LOG;
154 // TODO change the cell background color if not synchro
157 void HKLWindow::on_spinbutton_beta_max_value_changed(void)
159 LOG;
160 // TODO change the cell background color if not synchro
163 void HKLWindow::on_spinbutton_gamma_max_value_changed(void)
165 LOG;
166 // TODO change the cell background color if not synchro
169 void HKLWindow::on_spinbutton_lambda_value_changed(void)
171 LOG;
173 if(_geometry){
174 hkl_geometry_wavelength_set(this->_geometry,
175 _spinbutton_lambda->get_value());
176 this->updatePseudoAxes();
177 this->updatePseudoAxesFrames();
181 void HKLWindow::on_spinbutton_uxuyuz_value_changed(void)
183 LOG;
184 // TODO change the cell background color if not synchro
187 void HKLWindow::on_button2_clicked(void)
189 LOG;
191 if(_sample){
192 HklMatrix *U;
193 HklParameter *parameter;
194 HklLattice *lattice;
196 lattice = hkl_lattice_new(_spinbutton_a->get_value(),
197 _spinbutton_b->get_value(),
198 _spinbutton_c->get_value(),
199 _spinbutton_alpha->get_value() * HKL_DEGTORAD,
200 _spinbutton_beta->get_value() * HKL_DEGTORAD,
201 _spinbutton_gamma->get_value() * HKL_DEGTORAD);
203 /* set min/max a */
204 parameter = hkl_parameter_new_copy(hkl_lattice_a_get(lattice));
205 hkl_parameter_min_max_unit_set(parameter,
206 _spinbutton_a_min->get_value(),
207 _spinbutton_a_max->get_value());
208 hkl_lattice_a_set(lattice, parameter);
209 hkl_parameter_free(parameter);
211 /* set min/max b */
212 parameter = hkl_parameter_new_copy(hkl_lattice_b_get(lattice));
213 hkl_parameter_min_max_unit_set(parameter,
214 _spinbutton_b_min->get_value(),
215 _spinbutton_b_max->get_value());
216 hkl_lattice_b_set(lattice, parameter);
217 hkl_parameter_free(parameter);
219 parameter = hkl_parameter_new_copy(hkl_lattice_c_get(lattice));
220 hkl_parameter_min_max_unit_set(parameter,
221 _spinbutton_c_min->get_value(),
222 _spinbutton_c_max->get_value());
223 hkl_lattice_c_set(lattice, parameter);
224 hkl_parameter_free(parameter);
226 parameter = hkl_parameter_new_copy(hkl_lattice_alpha_get(lattice));
227 hkl_parameter_min_max_unit_set(parameter,
228 _spinbutton_alpha_min->get_value(),
229 _spinbutton_alpha_max->get_value());
230 hkl_lattice_alpha_set(lattice, parameter);
231 hkl_parameter_free(parameter);
233 parameter = hkl_parameter_new_copy(hkl_lattice_beta_get(lattice));
234 hkl_parameter_min_max_unit_set(parameter,
235 _spinbutton_beta_min->get_value(),
236 _spinbutton_beta_max->get_value());
237 hkl_lattice_beta_set(lattice, parameter);
238 hkl_parameter_free(parameter);
240 parameter = hkl_parameter_new_copy(hkl_lattice_gamma_get(lattice));
241 hkl_parameter_min_max_unit_set(parameter,
242 _spinbutton_gamma_min->get_value(),
243 _spinbutton_gamma_max->get_value());
244 hkl_lattice_gamma_set(lattice, parameter);
245 hkl_parameter_free(parameter);
248 hkl_sample_lattice_set(_sample, lattice);
249 U = hkl_matrix_new_euler(_spinbutton_ux->get_value() * HKL_DEGTORAD,
250 _spinbutton_uy->get_value() * HKL_DEGTORAD,
251 _spinbutton_uz->get_value() * HKL_DEGTORAD);
252 hkl_sample_U_set(_sample, U);
253 hkl_matrix_free(U);
254 hkl_lattice_free(lattice);
256 this->updateCrystalModel(_sample);
257 this->updateReciprocalLattice();
258 this->updateUB();
259 this->updatePseudoAxes();
260 this->updatePseudoAxesFrames();
264 #define ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(p, sample) \
265 void HKLWindow::on_checkbutton_##p##_toggled(void) \
267 LOG; \
268 if(_sample){ \
269 HklLattice *lattice = hkl_lattice_new_copy(hkl_sample_lattice_get((sample))); \
270 HklParameter *parameter = hkl_parameter_new_copy(hkl_lattice_##p##_get(lattice)); \
271 hkl_parameter_fit_set(parameter, _checkbutton_##p->get_active()); \
272 hkl_lattice_##p##_set(lattice, parameter); \
273 hkl_sample_lattice_set((sample), lattice); \
274 hkl_parameter_free(parameter); \
275 hkl_lattice_free(lattice); \
279 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(a, _sample);
280 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(b, _sample);
281 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(c, _sample);
282 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(alpha, _sample);
283 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(beta, _sample);
284 ON_CHECKBUTTON_LATTICE_PARAMETER_TOGGLE(gamma, _sample);
286 #define ON_CHECKBUTTON_UXUYUZ_TOGGLED(p, sample) \
287 void HKLWindow::on_checkbutton_##p##_toggled(void) \
289 LOG; \
290 if(_sample){ \
291 HklParameter *parameter = hkl_parameter_new_copy(hkl_sample_##p##_get((sample))); \
292 hkl_parameter_fit_set(parameter, _checkbutton_##p->get_active()); \
293 hkl_sample_##p##_set(sample, parameter); \
294 hkl_parameter_free(parameter); \
298 ON_CHECKBUTTON_UXUYUZ_TOGGLED(ux, _sample)
299 ON_CHECKBUTTON_UXUYUZ_TOGGLED(uy, _sample)
300 ON_CHECKBUTTON_UXUYUZ_TOGGLED(uz, _sample)
302 void HKLWindow::on_cell_TreeView_axes_read_edited(Glib::ustring const & spath,
303 Glib::ustring const & newText)
305 LOG;
307 Gtk::TreePath path(spath);
308 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_axes->get_model();
309 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
310 Gtk::ListStore::Row row = *(iter);
311 HklParameter *axis = row[_axeModelColumns.axis];
312 double value;
314 sscanf(newText.c_str(), "%lf", &value);
315 hkl_parameter_value_unit_set(axis, value, NULL);
316 hkl_geometry_axis_set(this->_geometry, axis);
318 row[_axeModelColumns.read] = value;
319 this->updatePseudoAxes();
320 this->updatePseudoAxesFrames();
322 #ifdef HKL3D
323 if(_Scene){
324 _Scene->is_colliding();
325 _Scene->invalidate();
327 #endif
330 void HKLWindow::on_cell_TreeView_axes_write_edited(Glib::ustring const & spath,
331 Glib::ustring const & newText)
333 LOG;
335 Gtk::TreePath path(spath);
336 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_axes->get_model();
337 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
338 Gtk::ListStore::Row row = *(iter);
340 HklParameter *axis = row[_axeModelColumns.axis];
341 double value;
342 sscanf(newText.c_str(), "%lf", &value);
343 hkl_parameter_value_unit_set(axis, value, NULL);
344 hkl_geometry_axis_set(this->_geometry, axis);
346 row[_axeModelColumns.write] = value;
347 this->updatePseudoAxes();
348 this->updatePseudoAxesFrames();
350 #ifdef HKL3D
351 if(_Scene){
352 _Scene->is_colliding();
353 _Scene->invalidate();
355 #endif
358 void HKLWindow::on_cell_TreeView_axes_min_edited(Glib::ustring const & spath,
359 Glib::ustring const & newText)
361 LOG;
363 Gtk::TreePath path(spath);
364 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_axes->get_model();
365 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
366 Gtk::ListStore::Row row = *(iter);
367 HklParameter *axis = row[_axeModelColumns.axis];
369 double shit;
370 double max;
371 double value;
373 sscanf(newText.c_str(), "%lf", &value);
375 hkl_parameter_min_max_unit_get(axis, &shit, &max);
376 hkl_parameter_min_max_unit_set(axis, value, max);
377 hkl_geometry_axis_set(this->_geometry, axis);
379 row[_axeModelColumns.min] = value;
380 this->updatePseudoAxes();
383 void HKLWindow::on_cell_TreeView_axes_max_edited(Glib::ustring const & spath,
384 Glib::ustring const & newText)
386 LOG;
388 Gtk::TreePath path(spath);
389 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_axes->get_model();
390 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
391 Gtk::ListStore::Row row = *(iter);
392 HklParameter *axis = row[_axeModelColumns.axis];
394 double min, shit;
395 double value;
397 sscanf(newText.c_str(), "%lf", &value);
399 hkl_parameter_min_max_unit_get(axis, &min, &shit);
400 hkl_parameter_min_max_unit_set(axis, min, value);
401 hkl_geometry_axis_set(this->_geometry, axis);
403 row[_axeModelColumns.max] = value;
404 this->updatePseudoAxes();
407 // PseudoAxes
408 void HKLWindow::on_cell_TreeView_pseudoAxes_write_edited(Glib::ustring const & spath,
409 Glib::ustring const & newText)
411 LOG;
413 double value;
414 HklParameter *parameter;
415 HklEngine *engine;
416 int res;
418 Gtk::TreePath path(spath);
419 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_pseudoAxes->get_model();
420 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
421 Gtk::ListStore::Row row = *(iter);
423 parameter = row[_pseudoAxeModelColumns.parameter];
424 engine = row[_pseudoAxeModelColumns.engine];
425 sscanf(newText.c_str(), "%lf", &value);
427 if(hkl_parameter_value_unit_set(parameter, value, NULL))
428 if(hkl_engine_set(engine, NULL)){
429 hkl_engine_list_select_solution(this->_engines, 0);
431 row[_pseudoAxeModelColumns.write] = value;
432 this->updateAxes();
433 this->updatePseudoAxes();
434 this->updatePseudoAxesFrames();
435 this->updateSolutions();
437 #ifdef HKL3D
438 if(_Scene){
439 _Scene->is_colliding();
440 _Scene->invalidate();
442 #endif
446 //PseudoAxes Parameters
447 void HKLWindow::on_cell_TreeView_pseudoAxes_parameters_value_edited(Glib::ustring const & spath,
448 Glib::ustring const & newText)
450 LOG;
452 double value;
453 HklParameter *parameter;
455 Gtk::TreePath path(spath);
456 Glib::RefPtr<Gtk::TreeModel> listStore = _TreeView_pseudoAxes_parameters->get_model();
457 Gtk::ListStore::Row row = *(listStore->get_iter(path));
458 sscanf(newText.c_str(), "%lf", &value);
460 parameter = row[_parameterModelColumns.parameter];
461 /* TODO error check */
462 hkl_parameter_value_unit_set(parameter, value, NULL);
464 row[_parameterModelColumns.value] = value;
465 this->updatePseudoAxes();
466 this->update_pseudoAxes_parameters();
469 void HKLWindow::on_cell_TreeView_crystals_name_edited(Glib::ustring const & spath,
470 Glib::ustring const & newText)
472 LOG;
474 Gtk::TreePath path(spath);
475 Glib::RefPtr<Gtk::TreeModel> listStore = _treeViewCrystals->get_model();
476 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
477 Gtk::ListStore::Row row = *(iter);
478 Glib::ustring name = row[_crystalModelColumns.name];
479 std::map<std::string, HklSample *>::iterator it = _samples.find(name);
480 if (it != _samples.end()){
481 HklSample *sample = it->second;
483 hkl_sample_name_set(sample, newText.c_str());
484 _samples.erase(it);
485 _samples.insert(std::pair<std::string, HklSample *>(hkl_sample_name_get(sample),
486 sample));
488 this-> updateTreeViewCrystals();
492 void HKLWindow::on_cell_TreeView_reflections_h_edited(Glib::ustring const & spath,
493 Glib::ustring const & newText)
495 LOG;
497 Gtk::TreePath path(spath);
498 Glib::RefPtr<Gtk::TreeModel> listStore = _treeViewReflections->get_model();
499 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
500 Gtk::ListStore::Row row = *(iter);
502 if(_sample){
503 double h;
504 double k;
505 double l;
506 HklSampleReflection *reflection;
508 reflection = row[_reflectionModelColumns.reflection];
510 hkl_sample_reflection_hkl_get(reflection, &h, &k, &l);
511 sscanf(newText.c_str(), "%lf", &h);
512 hkl_sample_reflection_hkl_set(reflection, h, k, l);
513 row[_reflectionModelColumns.h] = h;
515 row[_reflectionModelColumns.flag] = hkl_sample_reflection_flag_get(reflection);
517 this->updateCrystalModel(_sample);
521 void HKLWindow::on_cell_TreeView_reflections_k_edited(Glib::ustring const & spath,
522 Glib::ustring const & newText)
524 LOG;
526 Gtk::TreePath path(spath);
527 Glib::RefPtr<Gtk::TreeModel> listStore = _treeViewReflections->get_model();
528 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
529 Gtk::ListStore::Row row = *(iter);
531 if(_sample){
532 double h;
533 double k;
534 double l;
535 HklSampleReflection *reflection;
538 reflection = row[_reflectionModelColumns.reflection];
540 hkl_sample_reflection_hkl_get(reflection, &h, &k, &l);
541 sscanf(newText.c_str(), "%lf", &k);
542 hkl_sample_reflection_hkl_set(reflection, h, k, l);
543 row[_reflectionModelColumns.k] = k;
545 row[_reflectionModelColumns.flag] = hkl_sample_reflection_flag_get(reflection);
546 this->updateCrystalModel(_sample);
550 void HKLWindow::on_cell_TreeView_reflections_l_edited(Glib::ustring const & spath,
551 Glib::ustring const & newText)
553 LOG;
555 Gtk::TreePath path(spath);
556 Glib::RefPtr<Gtk::TreeModel> listStore = _treeViewReflections->get_model();
557 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
558 Gtk::ListStore::Row row = *(iter);
560 if(_sample){
561 double h;
562 double k;
563 double l;
564 HklSampleReflection *reflection;
566 reflection = row[_reflectionModelColumns.reflection];
568 hkl_sample_reflection_hkl_get(reflection, &h, &k, &l);
569 sscanf(newText.c_str(), "%lf", &l);
570 hkl_sample_reflection_hkl_set(reflection, h, k, l);
571 row[_reflectionModelColumns.l] = l;
573 row[_reflectionModelColumns.flag] = hkl_sample_reflection_flag_get(reflection);
575 this->updateCrystalModel(_sample);
579 void HKLWindow::on_cell_TreeView_reflections_flag_toggled(Glib::ustring const & spath)
581 LOG;
583 Gtk::TreePath path(spath);
584 Glib::RefPtr<Gtk::TreeModel> listStore = _treeViewReflections->get_model();
585 Gtk::TreeModel::iterator iter = listStore->get_iter(path);
586 Gtk::ListStore::Row row = *(iter);
588 if(_sample){
589 int flag;
590 HklSampleReflection *reflection;
592 reflection = row[_reflectionModelColumns.reflection];
593 flag = !hkl_sample_reflection_flag_get(reflection);
594 hkl_sample_reflection_flag_set(reflection, flag);
595 row[_reflectionModelColumns.flag] = flag;
599 void HKLWindow::on_toolbutton_add_reflection_clicked(void)
601 LOG;
603 if(_sample){
604 HklSampleReflection *reflection;
605 double h = 0;
606 double k = 0;
607 double l = 0;
609 reflection = hkl_sample_reflection_new(_geometry, _detector, h, k, l);
610 hkl_sample_add_reflection(_sample, reflection);
612 this->updateReflections(_sample,
613 _mapReflectionModel[hkl_sample_name_get(_sample)]);
617 void HKLWindow::on_toolbutton_goto_reflection_clicked(void)
619 LOG;
621 if(_sample){
622 Glib::RefPtr<Gtk::TreeSelection> selection = _treeViewReflections->get_selection();
623 unsigned int nb_rows = selection->count_selected_rows();
624 if (nb_rows == 1){
625 Gtk::TreeSelection::ListHandle_Path list_path = selection->get_selected_rows();
626 Gtk::TreePath path = *(list_path.begin());
627 Glib::RefPtr<Gtk::ListStore> liststore = _mapReflectionModel[hkl_sample_name_get(_sample)];
628 Gtk::ListStore::Row row = *(liststore->get_iter(path));
629 HklSampleReflection *reflection = row[_reflectionModelColumns.reflection];
631 hkl_geometry_set(this->_geometry,
632 hkl_sample_reflection_geometry_get(reflection));
634 this->updateSource();
635 this->updateAxes();
636 this->updatePseudoAxes();
637 #ifdef HKL3D
638 if(_Scene){
639 _Scene->is_colliding();
640 _Scene->invalidate();
642 #endif
643 }else{
644 if (nb_rows)
645 _statusBar->push("Please select only one reflection.");
646 else
647 _statusBar->push("Please select one reflection.");
652 void HKLWindow::on_toolbutton_del_reflection_clicked(void)
654 LOG;
656 if(_sample){
657 Glib::RefPtr<Gtk::TreeSelection> selection = _treeViewReflections->get_selection();
658 unsigned int nb_rows = selection->count_selected_rows();
659 if (nb_rows){
660 Gtk::TreeSelection::ListHandle_Path list = selection->get_selected_rows();
661 Gtk::TreeSelection::ListHandle_Path::iterator iter = list.begin();
662 Gtk::TreeSelection::ListHandle_Path::iterator last = list.end();
663 Glib::RefPtr<Gtk::ListStore> liststore = _mapReflectionModel[hkl_sample_name_get(_sample)];
664 // fill indexes with the reflections index
665 std::vector<HklSampleReflection *> to_delete;
666 while(iter != last){
667 Gtk::ListStore::Row row = *(liststore->get_iter(*iter));
668 to_delete.push_back(row[_reflectionModelColumns.reflection]);
669 ++iter;
671 std::ostringstream os;
672 os << "Are you sure you want to delete reflections :";
673 for(unsigned int i=0; i< to_delete.size();i++){
674 double h, k, l;
676 hkl_sample_reflection_hkl_get(to_delete[i], &h, &k, &l);
677 os << " "
678 << " h: " << h
679 << " k: " << k
680 << " l: " << l;
683 _message = new Gtk::MessageDialog("", false,
684 Gtk::MESSAGE_WARNING,
685 Gtk::BUTTONS_YES_NO);
686 _message->set_message(os.str());
687 _message->show();
688 int respons = _message->run();
689 switch (respons){
690 case Gtk::RESPONSE_YES:
691 for(unsigned int i=0;i<to_delete.size();i++){
692 hkl_sample_del_reflection(_sample,
693 to_delete[i]);
695 this->updateReflections(_sample, liststore);
696 break;
698 delete _message;
699 }else
700 _statusBar->push("Please select at least one reflection.");
703 void HKLWindow::on_toolbutton_setUB_clicked(void)
705 LOG;
707 if(_sample){
708 HklMatrix *UB = hkl_matrix_new_full(
709 _spinbutton_U11->get_value(),
710 _spinbutton_U12->get_value(),
711 _spinbutton_U13->get_value(),
712 _spinbutton_U21->get_value(),
713 _spinbutton_U22->get_value(),
714 _spinbutton_U23->get_value(),
715 _spinbutton_U31->get_value(),
716 _spinbutton_U32->get_value(),
717 _spinbutton_U33->get_value());
719 hkl_sample_UB_set(_sample, UB);
720 hkl_matrix_free(UB);
722 this->updateLattice();
723 this->updateLatticeParameters();
724 this->updateReciprocalLattice();
725 this->updateCrystalModel(_sample);
726 this->updateUB();
727 this->updateUxUyUz();
728 this->updatePseudoAxes();
729 this->updatePseudoAxesFrames();
733 void HKLWindow::on_toolbutton_computeUB_clicked(void)
735 LOG;
737 if(_sample){
738 const HklSampleReflection *r1 = hkl_sample_first_reflection_get(_sample);
739 const HklSampleReflection *r2 = hkl_sample_next_reflection_get(_sample,
740 const_cast<HklSampleReflection*>(r1));
742 hkl_sample_compute_UB_busing_levy(_sample, r1, r2);
743 this->updateUB();
744 this->updateUxUyUz();
745 this->updatePseudoAxes();
746 this->updatePseudoAxesFrames();
750 void HKLWindow::on_toolbutton_add_crystal_clicked(void)
752 LOG;
754 _sample = hkl_sample_new("new_sample");
755 if(_sample){
756 _samples.insert(std::pair<std::string, HklSample *>(hkl_sample_name_get(_sample),
757 _sample));
758 this->updateTreeViewCrystals();
760 // activate for edition the name of the new crystal
761 Gtk::TreeModel::Path path;
762 Gtk::TreeView::Column * column;
763 _treeViewCrystals->get_cursor(path, column);
764 column = _treeViewCrystals->get_column(0);
765 _treeViewCrystals->set_cursor(path, *column, true);
769 void HKLWindow::on_toolbutton_copy_crystal_clicked(void)
771 LOG;
773 Glib::ustring name;
774 Glib::ustring newname;
775 HklSample *old_sample = _sample;
776 HklSample *sample;
777 if(!old_sample){
778 _statusBar->push("Please select a crystal to copy.");
779 return;
782 sample = hkl_sample_new_copy(_sample);
783 hkl_sample_name_set(sample, "copy");
784 _samples.insert(std::pair<std::string, HklSample *>(hkl_sample_name_get(sample),
785 sample));
786 _sample = sample;
787 this->updateTreeViewCrystals();
789 // activate for edition the name of the new crystal
790 Gtk::TreeModel::Path path;
791 Gtk::TreeView::Column * column;
792 _treeViewCrystals->get_cursor(path, column);
793 column = _treeViewCrystals->get_column(0);
794 _treeViewCrystals->set_cursor(path, *column, true);
797 void HKLWindow::on_toolbutton_del_crystal_clicked(void)
799 LOG;
801 _samples.erase(_samples.find(hkl_sample_name_get(_sample)));
802 this->updateTreeViewCrystals();
805 void HKLWindow::on_toolbutton_affiner_clicked(void)
807 LOG;
809 Glib::ustring name;
810 Glib::ustring method;
811 if(_sample)
812 hkl_sample_affine(_sample);
814 this->updateCrystalModel(_sample);
815 this->updateLattice();
816 this->updateReciprocalLattice();
817 this->updateUB();
818 this->updateUxUyUz();
821 bool HKLWindow::on_treeViewReflections_key_press_event(GdkEventKey * event)
823 LOG;
825 switch (event->keyval)
827 case GDK_Insert:
828 case GDK_KP_Insert:
829 on_toolbutton_add_reflection_clicked();
830 break;
831 case GDK_Delete:
832 case GDK_KP_Delete:
833 on_toolbutton_del_reflection_clicked();
834 break;
836 return true;
839 bool HKLWindow::on_treeViewCrystals_key_press_event(GdkEventKey * event)
841 LOG;
843 switch (event->keyval)
845 case GDK_Insert:
846 case GDK_KP_Insert:
847 on_toolbutton_add_crystal_clicked();
848 break;
849 case GDK_Delete:
850 case GDK_KP_Delete:
851 on_toolbutton_del_crystal_clicked();
852 break;
854 return true;
857 void HKLWindow::on_treeview1_cursor_changed(void)
859 LOG;
861 Gtk::TreeModel::Path path;
862 Gtk::TreeViewColumn * column;
863 _treeview1->get_cursor(path, column);
864 Gtk::TreeModel::iterator iter = _solutionModel->get_iter(path);
865 Gtk::ListStore::Row row = *(iter);
866 const HklGeometryListItem *item = row[_solutionModelColumns->item];
868 const HklGeometry *geometry = hkl_geometry_list_item_geometry_get(item);
869 hkl_engine_list_geometry_set(this->_engines, geometry);
871 this->updateAxes();
872 this->updatePseudoAxes();
873 this->updatePseudoAxesFrames();
874 #ifdef HKL3D
875 if(_Scene){
876 _Scene->is_colliding();
877 _Scene->invalidate();
879 #endif
882 void HKLWindow::on_pseudoAxesFrame_changed(void)
884 LOG;
886 this->updateAxes();
887 this->updatePseudoAxes();
888 this->updatePseudoAxesFrames();
889 this->updateSolutions();
892 void HKLWindow::on_menuitem5_activate(void)
894 LOG;
896 _dialog1->show();
899 void HKLWindow::on_button1_clicked(void)
901 LOG;
903 _dialog1->hide();
906 void HKLWindow::on_combobox1_changed(void)
908 LOG;
910 size_t idx = _combobox1->get_active_row_number();
911 unsigned int n;
912 HklFactory **factories;
914 factories = hkl_factory_get_all(&n);
915 this->_factory = factories[idx];
917 if(_geometry)
918 hkl_geometry_free(_geometry);
919 _geometry = hkl_factory_create_new_geometry(this->_factory);
921 if(_engines)
922 hkl_engine_list_free(_engines);
923 _engines = hkl_factory_create_new_engine_list(this->_factory);
924 hkl_engine_list_init(_engines, _geometry, _detector, _sample);
926 this->set_up_pseudo_axes_frames();
927 this->set_up_TreeView_axes();
928 this->set_up_TreeView_pseudoAxes_parameters();
929 this->set_up_TreeView_pseudoAxes();
931 _solutionModelColumns = 0;
932 this->set_up_TreeView_treeview1();
933 #ifdef HKL3D
934 this->set_up_3D();
935 #endif