1 /*This file is a part of luscus project*/
2 /*Licensed under the Academic Free License version 3.0*/
3 #include<stdlib.h>
4 #include<string.h>
5 #include<gtk/gtk.h>
6 #ifdef GTK_GLEXT
7 #include<gtk/gtkgl.h>
8 #endif
9 //#include<gdk-pixbuf/gdk-pixbuf.h>
10 #include<gdk/gdkkeysyms.h>
11 #include"luscus.h"
12 #include"gv.h"
13 #include"gv_functions.h"
14 #include"gv_gtk.h"
15
16 /*int showing_symbols = 0;
17 int showing_indices = 0;
18 int showing_numeration = 0;
19 int showing_names = 0;
20 int showing_mulliken = 0;
21 int showing_loprop = 0;*/
22
23 int rot_axis_order = 2;
24 int n_input_types;
25 int elem_selected = 1;
26 int control_pressed;
27 INPUT_FORMAT *input_filetypes;
28 /*INPUT_DATA Input_Data;*/
29 GtkWidget *element_dialog;
30 GtkWidget *atom_prop_label;
31 GtkWidget *atom_prop_color_button;
32 GtkWidget *atom_prop_atom_size_spin;
33 GtkWidget *atom_prop_bond_size_spin;
34 GtkWidget *atom_prop_atom_valency_spin;
35
36 ELEM_DATA *e;
37 ELEM_DATA *tmp_elem;
38
39 gint calc_timer;
40 char calc_alive = 0;
41
42 double angle_values[] =
43 {
44 60., 90., 109.45, 120., 180.
45 };
46
luscus_check_writable_pic_files(GdkPixbufFormat * data,GSList ** list)47 void luscus_check_writable_pic_files(GdkPixbufFormat *data, GSList **list)
48 {
49 if (gdk_pixbuf_format_is_writable(data))
50 *list = g_slist_prepend (*list, data);
51 }
52
53
luscus_toggle_movement_mode(GtkWidget * combo,gpointer data)54 void luscus_toggle_movement_mode(GtkWidget *combo, gpointer data)
55 {
56 luscus_gtk_pop_message_from_statusbar2();
57 if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) == 1)
58 {
59 move_camera=1;
60 luscus_gtk_push_message_to_statusbar2("moving camera");
61 }
62 else
63 {
64 move_camera=0;
65 luscus_gtk_push_message_to_statusbar2("moving molecule");
66 }
67 }
68
luscus_gtk_move_up(GtkWidget * button,gpointer data)69 void luscus_gtk_move_up(GtkWidget *button, gpointer data)
70 {
71 Do_key_ud(1, 0);
72 redraw();
73 }
74
luscus_gtk_move_down(GtkWidget * button,gpointer data)75 void luscus_gtk_move_down(GtkWidget *button, gpointer data)
76 {
77 Do_key_ud(0, 0);
78 redraw();
79 }
80
luscus_gtk_move_forw(GtkWidget * button,gpointer data)81 void luscus_gtk_move_forw(GtkWidget *button, gpointer data)
82 {
83 Do_key_lr(1, 0);
84 redraw();
85 }
86
luscus_gtk_move_back(GtkWidget * button,gpointer data)87 void luscus_gtk_move_back(GtkWidget *button, gpointer data)
88 {
89 Do_key_lr(0, 0);
90 redraw();
91 }
92
luscus_gtk_center(GtkWidget * button,gpointer data)93 void luscus_gtk_center(GtkWidget *button, gpointer data)
94 {
95 Do_center();
96 /* set_origin_molecule();*/
97 redraw();
98 }
99
luscus_gtk_zoom(GtkWidget * button,gint in_out)100 void luscus_gtk_zoom(GtkWidget *button, gint in_out)
101 {
102 change_scale(in_out);
103 redraw();
104 }
105
callback_geo_forw(GtkWidget * button,gpointer data)106 void callback_geo_forw(GtkWidget *button, gpointer data)
107 {
108 if (!m) return;
109 if (igeo == n_geometries-1) return;
110 igeo++;
111 if (igeo >= n_geometries) igeo = n_geometries - 1;
112 get_new_section();
113 luscus_gtk_update_geo_info();
114 set_current_graph_data();
115 set_scale();
116 rerender_3d();
117 redraw();
118 }
119
callback_geo_back(GtkWidget * button,gpointer data)120 void callback_geo_back(GtkWidget *button, gpointer data)
121 {
122 if (!m) return;
123 if (igeo == 0) return;
124 igeo--;
125 if (igeo <= 0) igeo = 0;
126 get_new_section();
127 luscus_gtk_update_geo_info();
128 set_current_graph_data();
129 set_scale();
130 rerender_3d();
131 redraw();
132 }
133
callback_geo_first(GtkWidget * button,gpointer data)134 void callback_geo_first(GtkWidget *button, gpointer data)
135 {
136 if (!m) return;
137 if (igeo == 0) return;
138 igeo = 0;
139 get_new_section();
140 luscus_gtk_update_geo_info();
141 set_current_graph_data();
142 rerender_3d();
143 redraw();
144 }
145
callback_geo_last(GtkWidget * button,gpointer data)146 void callback_geo_last(GtkWidget *button, gpointer data)
147 {
148 if (!m) return;
149 if (igeo == n_geometries) return;
150 igeo = n_geometries - 1;
151 get_new_section();
152 luscus_gtk_update_geo_info();
153 set_current_graph_data();
154 rerender_3d();
155 redraw();
156 }
157
158 #ifdef GTK3
callback_adj_geometry(GtkAdjustment * adj,gpointer data)159 void callback_adj_geometry(GtkAdjustment *adj, gpointer data)
160 #endif
161 #ifdef GTK2
162 void callback_adj_geometry(GtkObject *adj, gpointer data)
163 #endif
164 {
165 if (!m) return;
166 igeo = (int) gtk_adjustment_get_value(GTK_ADJUSTMENT(adj));
167 if (igeo >= n_geometries-1) igeo = n_geometries-1;
168 get_new_section();
169 luscus_gtk_update_geo_info();
170 set_current_graph_data();
171 rerender_3d();
172 redraw();
173 }
174
callback_geo_play(GtkWidget * button,gpointer data)175 void callback_geo_play(GtkWidget *button, gpointer data)
176 {
177 if (Input_Data.animate)
178 {
179 geo_play_button_play(1);
180 Input_Data.animate = FALSE;
181 }
182 else
183 {
184 geo_play_button_play(0);
185 Input_Data.animate = TRUE;
186 luscus_gtk_start_animation(0);
187 }
188 redraw();
189 }
190
191 /*grid*/
192
luscus_gtk_change_transparency_level(GtkWidget * adjustment,gpointer data)193 void luscus_gtk_change_transparency_level(GtkWidget* adjustment, gpointer data)
194 {
195 Input_Data.electrostatic_poten_color[0][3] =
196 Input_Data.electrostatic_poten_color[1][3] =
197 Input_Data.neg_pos_color[0][3] = Input_Data.neg_pos_color[1][3] =
198 gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
199 rerender_3d();
200 redraw();
201 }
202
luscus_gtk_change_isosurface_level(GtkWidget * adjustment,gpointer data)203 void luscus_gtk_change_isosurface_level(GtkWidget* adjustment, gpointer data)
204 {
205 Input_Data.lev = gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
206 make_surfaces();
207 rerender_3d();
208 redraw();
209 }
210
luscus_gtk_show_all_orbitals(GtkWidget * toggle,gpointer data)211 void luscus_gtk_show_all_orbitals(GtkWidget* toggle, gpointer data)
212 {
213 luscus_gtk_show_multiorb_window();
214 }
215
luscus_gtk_show_electrostatic_potential(GtkWidget * button,gpointer data)216 void luscus_gtk_show_electrostatic_potential(GtkWidget* button, gpointer data)
217 {
218 if (Input_Data.show_epot) Input_Data.show_epot = 0;
219 else Input_Data.show_epot = 1;
220 rerender_3d();
221 redraw();
222 }
223
224 /*vibrations*/
225
luscus_gtk_change_vibration_speed(GtkWidget * adjustment,gpointer data)226 void luscus_gtk_change_vibration_speed(GtkWidget *adjustment, gpointer data)
227 {
228 Input_Data.frequency_speed = gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
229 redraw();
230 }
231
luscus_gtk_change_vibration_amplitude(GtkWidget * adjustment,gpointer data)232 void luscus_gtk_change_vibration_amplitude(GtkWidget *adjustment, gpointer data)
233 {
234 Input_Data.frequency_amplitude = gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment));
235 redraw();
236 }
237
238 /*fragments*/
239
luscus_gtk_add_fragment(GtkWidget * button,gpointer data)240 void luscus_gtk_add_fragment(GtkWidget *button, gpointer data)
241 {
242 if (m->n_selected == 2) change_bond_type(SINGLE_BOND);
243 else do_key_insert();
244 printf("INSERTING FRAGMENT\n");
245 rerender_3d();
246 redraw();
247 }
248
luscus_gtk_remove_fragment(GtkWidget * widget,gpointer data)249 void luscus_gtk_remove_fragment(GtkWidget* widget, gpointer data)
250 {
251 if (m->n_selected == 2) change_bond_type(NO_BOND);
252 else delete_coord(0);
253 rerender_3d();
254 redraw();
255 }
256
luscus_gtk_change_bond_callback(GtkWidget * combo_bond,gpointer data)257 void luscus_gtk_change_bond_callback(GtkWidget *combo_bond, gpointer data)
258 {
259 change_bond_type(gtk_combo_box_get_active(GTK_COMBO_BOX(combo_bond)));
260 rerender_3d();
261 redraw();
262 }
263
luscus_gtk_change_angle_callback(GtkWidget * combo_angle,gpointer data)264 void luscus_gtk_change_angle_callback(GtkWidget *combo_angle, gpointer data)
265 {
266 int iang;
267 iang = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_angle));
268 luscus_gtk_move_coord(angle_values[iang]);
269 rerender_3d();
270 redraw();
271 }
272
callback_change_atom(GtkWidget * widget,gpointer data)273 void callback_change_atom(GtkWidget* widget, gpointer data)
274 {
275 /*PERIODIC SYSTEM*/
276 GtkWidget *vbox, *hbox;
277 GtkWidget *persys; /*GtkTable with buttons arreanged in form of periodic system*/
278 GtkWidget *expander;
279
280 GtkWidget *label;
281 #ifdef GTK2
282 GtkObject *adj_atom_size, *adj_bond_size, *adj_valency;
283 #else
284 GtkAdjustment *adj_atom_size, *adj_bond_size, *adj_valency;
285 #endif
286 GdkColor color;
287 gint response;
288
289 GtkWidget *custom_atom_color_button;
290 GtkWidget *custom_atom_valency_spin;
291 GtkWidget *custom_atom_size_spin;
292 GtkWidget *custom_bond_size_spin;
293
294 printf("CHANGE ATOM\n");
295
296 element_dialog = gtk_dialog_new_with_buttons("Choose element", GTK_WINDOW(gtk_widget_get_toplevel(widget)),
297 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
298 GTK_STOCK_CLOSE, GTK_RESPONSE_REJECT,
299 NULL);
300
301 /*periodic system*/
302 persys = luscus_gtk_make_periodic_system();
303 vbox = gtk_dialog_get_content_area(GTK_DIALOG(element_dialog));
304 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(element_dialog))), persys, FALSE, FALSE, 0);
305 /*custom data change*/
306 expander = gtk_expander_new("custom data");
307
308 #ifdef GTK2
309 hbox = gtk_hbox_new(FALSE, 0);
310 #endif
311 #ifdef GTK3
312 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
313 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
314 #endif
315 gtk_container_add(GTK_CONTAINER(expander), hbox);
316
317 color.red = (guint16) (m->elem[m->selected[0]].color[0] * (gfloat) G_MAXUINT16);
318 color.green = (guint16) (m->elem[m->selected[0]].color[1] * (gfloat) G_MAXUINT16);
319 color.blue = (guint16) (m->elem[m->selected[0]].color[2] * (gfloat) G_MAXUINT16);
320
321 custom_atom_color_button = gtk_color_button_new_with_color(&color);
322 gtk_box_pack_start(GTK_BOX(hbox), custom_atom_color_button, FALSE, FALSE, 0);
323 g_signal_connect(G_OBJECT(custom_atom_color_button), "color-set", G_CALLBACK(custom_atom_color_changed_callback), NULL);
324 gtk_widget_show(custom_atom_color_button);
325 /* -atom size- */
326 label = gtk_label_new("Van der Waals radius:");
327 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
328 gtk_widget_show(label);
329
330 adj_atom_size = gtk_adjustment_new(0.0, 0.F, 3.F, 0.01F, 0.1F, 0.F);
331 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_atom_size), m->elem[m->selected[0]].vdw_rad);
332
333 #ifdef GTK2
334 custom_atom_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_atom_size), 0.01, 2);
335 #else
336 custom_atom_size_spin = gtk_spin_button_new(adj_atom_size, 0.01, 2);
337 #endif
338 g_signal_connect(G_OBJECT(custom_atom_size_spin), "value-changed", G_CALLBACK(custom_atom_size_changed_callback), NULL);
339 gtk_box_pack_start(GTK_BOX(hbox), custom_atom_size_spin, FALSE, FALSE, 3);
340 gtk_widget_show(custom_atom_size_spin);
341
342 /* -bond size- */
343 label = gtk_label_new("bond size:");
344 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
345 gtk_widget_show(label);
346
347 adj_bond_size = gtk_adjustment_new(0.0, 0.F, 3.F, 0.01F, 0.1F, 0.F);
348 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond_size), m->elem[m->selected[0]].bond_rad);
349
350 #ifdef GTK2
351 custom_bond_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_bond_size), 0.01, 2);
352 #else
353 custom_bond_size_spin = gtk_spin_button_new(adj_bond_size, 0.01, 2);
354 #endif
355 g_signal_connect(G_OBJECT(custom_bond_size_spin), "value-changed", G_CALLBACK(custom_bond_size_changed_callback), NULL);
356
357 gtk_box_pack_start(GTK_BOX(hbox), custom_bond_size_spin, FALSE, FALSE, 0);
358 gtk_widget_show(custom_bond_size_spin);
359
360 label = gtk_label_new("valency:");
361 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
362 gtk_widget_show(label);
363
364 /* -valency- */
365
366 adj_valency = gtk_adjustment_new(0.0, 0.F, 30.F, 1.0F, 1.0F, 0.F);
367 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_valency), m->elem[m->selected[0]].valency);
368
369 #ifdef GTK2
370 custom_atom_valency_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_valency), 0.01, 2);
371 #else
372 custom_atom_valency_spin = gtk_spin_button_new(adj_valency, 0.01, 2);
373 #endif
374 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(custom_atom_valency_spin), 0);
375 g_signal_connect(G_OBJECT(custom_atom_valency_spin), "value-changed", G_CALLBACK(custom_valency_changed_callback), NULL);
376
377 gtk_box_pack_start(GTK_BOX(hbox), custom_atom_valency_spin, FALSE, FALSE, 0);
378 gtk_widget_show(custom_atom_valency_spin);
379
380 gtk_widget_show(hbox);
381 gtk_widget_show(expander);
382 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(element_dialog))), expander, FALSE, FALSE, 0);
383
384 response = gtk_dialog_run(GTK_DIALOG(element_dialog));
385 if (GTK_IS_WIDGET(element_dialog)) gtk_widget_destroy(element_dialog);
386 rerender_3d();
387 redraw();
388 }
389
luscus_gtk_make_periodic_system(void)390 GtkWidget *luscus_gtk_make_periodic_system(void)
391 {
392 GtkWidget *table;
393 GtkWidget *button;
394 gint i;
395
396 gint maxx = 0, maxy = 0;
397
398 for (i = 1; i < number_of_elements; i++)
399 {
400 if (e[i].periodic_pos_x > maxx) maxx = e[i].periodic_pos_x;
401 if (e[i].periodic_pos_y > maxy) maxy = e[i].periodic_pos_y;
402 }
403
404 table = gtk_table_new(maxy+1, maxx+1, TRUE);
405
406 for(i = 1; i < number_of_elements; i++)
407 {
408 button = gtk_button_new_with_label(e[i].name);
409 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_select_element), GINT_TO_POINTER(i));
410 gtk_table_attach(GTK_TABLE(table), button, e[i].periodic_pos_x, e[i].periodic_pos_x+1, e[i].periodic_pos_y, e[i].periodic_pos_y+1, GTK_FILL, GTK_FILL, 0, 0);
411 gtk_widget_show(button);
412 }
413 gtk_widget_show(table);
414
415 return table;
416 }
417
luscus_gtk_select_element(GtkWidget * button,gint iatom)418 gboolean luscus_gtk_select_element(GtkWidget *button, gint iatom)
419 {
420 int i;
421 for(i = 0; i < 3; i++)
422 m->elem[m->selected[0]].color[i] = e[iatom].color[i];
423 m->elem[m->selected[0]].vdw_rad = e[iatom].vdw_rad;
424 m->elem[m->selected[0]].bond_rad = e[iatom].bond_rad;
425 m->elem[m->selected[0]].valency = e[iatom].valency;
426 free(m->elem[m->selected[0]].name);
427 m->elem[m->selected[0]].name = strdup(e[iatom].name);
428 change_atom_parameters_in_list(m->selected[0]);
429 append_backup();
430 gtk_widget_destroy(element_dialog);
431 return FALSE;
432 }
433
custom_atom_color_changed_callback(GtkWidget * col_button,gpointer data)434 void custom_atom_color_changed_callback(GtkWidget *col_button, gpointer data)
435 {
436 GdkColor color;
437
438 gtk_color_button_get_color(GTK_COLOR_BUTTON(col_button), &color);
439
440 if (m->selected[0] < 0) return;
441
442 m->elem[m->selected[0]].color[0] = (double) color.red / (double) G_MAXUINT16;
443 m->elem[m->selected[0]].color[1] = (double) color.green / (double) G_MAXUINT16;
444 m->elem[m->selected[0]].color[2] = (double) color.blue / (double) G_MAXUINT16;
445 m->ishow ^= HAS_COLOUR;
446 }
447
custom_atom_size_changed_callback(GtkWidget * spin,gpointer data)448 void custom_atom_size_changed_callback(GtkWidget *spin, gpointer data)
449 {
450 if (m->selected[0] < 0) return;
451 m->elem[m->selected[0]].vdw_rad = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
452 }
453
custom_bond_size_changed_callback(GtkWidget * spin,gpointer data)454 void custom_bond_size_changed_callback(GtkWidget *spin, gpointer data)
455 {
456 if (m->selected[0] < 0) return;
457 m->elem[m->selected[0]].bond_rad = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
458 }
459
custom_valency_changed_callback(GtkWidget * spin,gpointer data)460 void custom_valency_changed_callback(GtkWidget *spin, gpointer data)
461 {
462 if (m->selected[0] < 0) return;
463 m->elem[m->selected[0]].valency = (int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
464 }
465
luscus_gtk_disable_keys(GtkWidget * widget,GdkEvent * event,gpointer data)466 gboolean luscus_gtk_disable_keys(GtkWidget *widget, GdkEvent *event, gpointer data)
467 {
468 accept_keys = 0;
469 return FALSE;
470 }
471
luscus_gtk_enable_keys(GtkWidget * widget,GdkEvent * event,gpointer user_data)472 gboolean luscus_gtk_enable_keys(GtkWidget *widget, GdkEvent *event, gpointer user_data)
473 {
474 accept_keys = 1;
475 return FALSE;
476 }
477
478 /*this function is replaced with three functions (below) ->0.3.6*/
479 /*void luscus_gtk_change_bond_angle_tors_value(GtkWidget* adj, gpointer data)
480 {
481 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(adj));
482 luscus_gtk_move_coord(value);
483 redraw();
484 }*/
485
luscus_gtk_change_bond_value(GtkWidget * adj,gpointer data)486 void luscus_gtk_change_bond_value(GtkWidget* adj, gpointer data)
487 {
488 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(adj));
489 luscus_gtk_move_bond(value);
490 rerender_3d();
491 redraw();
492 }
493
luscus_gtk_change_angle_value(GtkWidget * adj,gpointer data)494 void luscus_gtk_change_angle_value(GtkWidget* adj, gpointer data)
495 {
496 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(adj));
497 luscus_gtk_move_angle(value);
498 rerender_3d();
499 redraw();
500 }
501
luscus_gtk_change_tors_value(GtkWidget * adj,gpointer data)502 void luscus_gtk_change_tors_value(GtkWidget* adj, gpointer data)
503 {
504 gdouble value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(adj));
505 luscus_gtk_move_torsion(value);
506 rerender_3d();
507 redraw();
508 }
509
luscus_gtk_change_xyz_coordinate(GtkWidget * spin,gpointer data)510 void luscus_gtk_change_xyz_coordinate(GtkWidget* spin, gpointer data)
511 {
512 int icoord=GPOINTER_TO_INT(data);
513 double value;
514
515 if (m->n_selected < 1 || m->n_selected > 4) return;
516 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
517 accumulate_motion(m->xyz[m->selected[0]][icoord] - value);
518 m->xyz[m->selected[0]][icoord] = value;
519 rerender_3d();
520
521 redraw();
522 change_watched_data();
523 if (Input_Data.automatic_rebonding) rebond();
524 change_atom_parameters_in_list(m->selected[0]);
525 }
526
luscus_gtk_add_dummy_atoms(GtkWidget * widget,gpointer data)527 void luscus_gtk_add_dummy_atoms(GtkWidget* widget, gpointer data)
528 {
529 add_atoms(1);
530 rerender_3d();
531 redraw();
532 }
533
luscus_gtk_remove_dummy_atoms(GtkWidget * widget,gpointer data)534 void luscus_gtk_remove_dummy_atoms(GtkWidget* widget, gpointer data)
535 {
536 delete_dummy_atoms();
537 rerender_3d();
538 redraw();
539 }
540
luscus_gtk_remove_selection(GtkWidget * widget,gpointer data)541 void luscus_gtk_remove_selection(GtkWidget* widget, gpointer data)
542 {
543 unselect_all();
544 redraw();
545 }
546
luscus_gtk_unmark(GtkWidget * widget,gpointer data)547 void luscus_gtk_unmark(GtkWidget* widget, gpointer data)
548 {
549 unmark_all();
550 rerender_3d();
551 redraw();
552 }
553
luscus_gtk_sort_mark(GtkWidget * widget,gpointer data)554 void luscus_gtk_sort_mark(GtkWidget* widget, gpointer data)
555 {
556 renumber_marked();
557 rerender_3d();
558 redraw();
559 }
560
luscus_gtk_mark_H_atoms(GtkWidget * widget,gpointer data)561 void luscus_gtk_mark_H_atoms(GtkWidget* widget, gpointer data)
562 {
563 mark_H();
564 rerender_3d();
565 redraw();
566 }
567
luscus_gtk_mark_reverse(GtkWidget * widget,gpointer data)568 void luscus_gtk_mark_reverse(GtkWidget* widget, gpointer data)
569 {
570 reverse_marked();
571 rerender_3d();
572 redraw();
573 }
574
luscus_gtk_mark_element(GtkWidget * widget,gpointer data)575 void luscus_gtk_mark_element(GtkWidget* widget, gpointer data)
576 {
577 mark_element_as_selected();
578 rerender_3d();
579 redraw();
580 }
581
luscus_gtk_mark_neighbor(GtkWidget * widget,gpointer data)582 void luscus_gtk_mark_neighbor(GtkWidget* widget, gpointer data)
583 {
584 mark_neighbor();
585 rerender_3d();
586 redraw();
587 }
588
luscus_gtk_watch_value(GtkWidget * widget,gpointer data)589 void luscus_gtk_watch_value(GtkWidget* widget, gpointer data)
590 {
591 add_watched_coord();
592 luscus_gtk_update_upon_select_or_mark();
593 }
594
luscus_gtk_unwatch_values(GtkWidget * widget,gpointer data)595 void luscus_gtk_unwatch_values(GtkWidget* widget, gpointer data)
596 {
597 remove_watched_coords();
598 luscus_gtk_update_upon_select_or_mark();
599 }
600
luscus_gtk_select_fragment(GtkWidget * adjustment,gpointer data)601 void luscus_gtk_select_fragment(GtkWidget *adjustment, gpointer data)
602 {
603 add_fragment(GPOINTER_TO_INT(data));
604 rerender_3d();
605 redraw();
606 }
607
608 #ifndef HAS_MSYM
luscus_gtk_alpply_symmetry(GtkWidget * button,gpointer data)609 void luscus_gtk_alpply_symmetry(GtkWidget* button, gpointer data)
610 {
611 luscus_gtk_set_vec_rot(0);
612 do_symmetry();
613 rerender_3d();
614 redraw();
615 }
616 #endif
617
luscus_gtk_apply_translation(GtkWidget * button,gpointer data)618 void luscus_gtk_apply_translation(GtkWidget* button, gpointer data)
619 {
620 luscus_gtk_set_vec_rot(0);
621 do_symmetry();
622 rerender_3d();
623 redraw();
624 }
625
change_translation_magnitude(GtkWidget * sb,gpointer data)626 void change_translation_magnitude(GtkWidget *sb, gpointer data)
627 {
628 Input_Data.symmetry_translation = gtk_spin_button_get_value(GTK_SPIN_BUTTON(sb));
629 }
630
luscus_gtk_alpply_rot_symmetry(GtkWidget * button,gpointer data)631 void luscus_gtk_alpply_rot_symmetry(GtkWidget* button, gpointer data)
632 {
633 luscus_gtk_set_vec_rot(rot_axis_order);
634 do_symmetry();
635 rerender_3d();
636 redraw();
637 }
638
change_rotation_axis_order(GtkWidget * sb,gpointer data)639 void change_rotation_axis_order(GtkWidget *sb, gpointer data)
640 {
641 rot_axis_order = (int) gtk_spin_button_get_value(GTK_SPIN_BUTTON(sb));
642 }
643
644 #ifndef HAS_MSYM
645
luscus_gtk_force_symmetry(GtkWidget * button,gpointer data)646 void luscus_gtk_force_symmetry(GtkWidget* button, gpointer data)
647 {
648 Input_Data.force_symmetry = 1;
649 do_symmetry();
650 rerender_3d();
651 redraw();
652 }
653 #endif
654
luscus_add_arrow(GtkWidget * button,gpointer data)655 void luscus_add_arrow(GtkWidget* button, gpointer data)
656 {
657 if (m->n_selected != 2) return;
658 add_vector(m, m->xyz[m->selected[0]], m->xyz[m->selected[1]]);
659 rerender_3d();
660 redraw();
661 append_backup();
662 }
663
luscus_add_sphere(GtkWidget * button,gpointer data)664 void luscus_add_sphere(GtkWidget* button, gpointer data)
665 {
666 if (m->n_selected == 0) return;
667 else if (m->n_selected == 1) add_sphere(m, m->xyz[m->selected[0]], 2.0);
668 else if (m->n_selected == 2) add_sphere(m, m->xyz[m->selected[0]], rr_dist(m->xyz[m->selected[0]], m->xyz[m->selected[1]]));
669 else return;
670 rerender_3d();
671 redraw();
672 append_backup();
673 }
674
luscus_add_plain(GtkWidget * button,gpointer data)675 void luscus_add_plain(GtkWidget *button, gpointer data)
676 {
677 if (m->n_selected != 3) return;
678 add_surface(m, m->xyz[m->selected[0]], m->xyz[m->selected[1]], m->xyz[m->selected[2]]);
679 rerender_3d();
680 redraw();
681 append_backup();
682 }
683
luscus_add_triangle(GtkWidget * button,gpointer data)684 void luscus_add_triangle(GtkWidget *button, gpointer data)
685 {
686 if (m->n_selected != 3) return;
687 add_triangle(m, m->xyz[m->selected[0]], m->xyz[m->selected[1]], m->xyz[m->selected[2]]);
688 rerender_3d();
689 redraw();
690 append_backup();
691 }
692
luscus_add_cell(GtkWidget * button,gpointer data)693 void luscus_add_cell(GtkWidget *button, gpointer data)
694 {
695 if (m->n_selected != 4) return;
696 add_cell(m, m->xyz[m->selected[0]], m->xyz[m->selected[1]], m->xyz[m->selected[2]], m->xyz[m->selected[3]]);
697 rerender_3d();
698 redraw();
699 append_backup();
700 }
701
luscus_insert_textbox(GtkWidget * button,gpointer data)702 void luscus_insert_textbox(GtkWidget *button, gpointer data)
703 {
704 if (!textbox_state) /*this way shit won't happen if user clicks "insert text" twice*/
705 {
706 allocate_textbox(m);
707 m->textboxes[m->ntextboxes-1].coord_x = 0;
708 m->textboxes[m->ntextboxes-1].coord_y = 0;
709
710 m->textboxes[m->ntextboxes-1].color[0] = 0.f;
711 m->textboxes[m->ntextboxes-1].color[1] = 0.f;
712 m->textboxes[m->ntextboxes-1].color[2] = 0.f;
713 m->textboxes[m->ntextboxes-1].color[3] = 1.0;
714
715 m->textboxes[m->ntextboxes-1].font = g_strdup(Input_Data.font);
716 m->textboxes[m->ntextboxes-1].message = NULL;
717 m->textboxes[m->ntextboxes-1].pixtext.width = 0;
718 m->textboxes[m->ntextboxes-1].pixtext.height = 0;
719 m->textboxes[m->ntextboxes-1].pixtext.pixels = NULL;
720
721 textbox_state = 1;
722 luscus_set_cursor_text();
723 }
724 }
725
luscus_clear_drawings(GtkWidget * button,gpointer data)726 void luscus_clear_drawings(GtkWidget *button, gpointer data)
727 {
728 deallocate_vectors(m);
729 deallocate_triangles(m);
730 deallocate_spheres(m);
731 deallocate_surfaces(m);
732 deallocate_cells(m);
733 deallocate_textboxes(m);
734 luscus_gtk_update_upon_select_or_mark();
735 luscus_gtk_update_3Dobject_info();
736 rerender_3d();
737 redraw();
738 append_backup();
739 }
740
luscus_gtk_modify_3Dobject(GtkWidget * button,GTK_3D_DESC * desc)741 void luscus_gtk_modify_3Dobject(GtkWidget *button, GTK_3D_DESC* desc)
742 {
743 int i;
744 GtkWidget *dialog;
745 GtkWidget *vbox, *hbox;
746 GtkWidget *label;
747 GtkWidget *color_button;
748 /* GtkWidget *hscale;*/
749 GtkWidget *spin_button;
750 GtkWidget *separator;
751 GtkWidget *entry_00, *entry_01, *entry_02;
752 GtkWidget *entry_10, *entry_11, *entry_12;
753 GtkWidget *entry_20, *entry_21, *entry_22;
754 GtkWidget *entry_30, *entry_31, *entry_32;
755 gint response;
756 gchar title[20];
757 gchar buffer[30];
758 GdkColor color;
759 #ifdef GTK2
760 GtkObject *adj_transparency;
761 #endif
762 #ifdef GTK3
763 GtkAdjustment *adj_transparency;
764 #endif
765 double new_value;
766 GtkWidget *font_button;
767 gint width, height;
768 GtkWidget *button_1;
769
770 set_go_selected(desc->i3dtype, desc->inum);
771 rerender_3d();
772 redraw();
773
774 if (desc->i3dtype == SPHERE)
775 {
776 g_snprintf(title, 20, "sphere #%d", desc->inum+1);
777 color.red = (guint16) (m->sphere_color[desc->inum][0] * (gfloat) G_MAXUINT16);
778 color.green = (guint16) (m->sphere_color[desc->inum][1] * (gfloat) G_MAXUINT16);
779 color.blue = (guint16) (m->sphere_color[desc->inum][2] * (gfloat) G_MAXUINT16);
780 adj_transparency = gtk_adjustment_new(m->sphere_color[desc->inum][3], 0.0, 1.0, 0.01, 0.1, 0.0);
781 }
782 else if (desc->i3dtype == VECTOR)
783 {
784 g_snprintf(title, 20, "vector #%d", desc->inum+1);
785 color.red = (guint16) (m->vector_color[desc->inum][0] * (gfloat) G_MAXUINT16);
786 color.green = (guint16) (m->vector_color[desc->inum][1] * (gfloat) G_MAXUINT16);
787 color.blue = (guint16) (m->vector_color[desc->inum][2] * (gfloat) G_MAXUINT16);
788 adj_transparency = gtk_adjustment_new(m->vector_color[desc->inum][3], 0.0, 1.0, 0.01, 0.1, 0.0);
789 }
790 else if (desc->i3dtype == TRIANGLE)
791 {
792 g_snprintf(title, 20, "triangle #%d", desc->inum+1);
793 color.red = (guint16) (m->triangle_color[desc->inum][0] * (gfloat) G_MAXUINT16);
794 color.green = (guint16) (m->triangle_color[desc->inum][1] * (gfloat) G_MAXUINT16);
795 color.blue = (guint16) (m->triangle_color[desc->inum][2] * (gfloat) G_MAXUINT16);
796 adj_transparency = gtk_adjustment_new(m->triangle_color[desc->inum][3], 0.0, 1.0, 0.01, 0.1, 0.0);
797 }
798 else if (desc->i3dtype == SURFACE)
799 {
800 g_snprintf(title, 20, "surface #%d", desc->inum+1);
801 color.red = (guint16) (m->surf_color[desc->inum][0] * (gfloat) G_MAXUINT16);
802 color.green = (guint16) (m->surf_color[desc->inum][1] * (gfloat) G_MAXUINT16);
803 color.blue = (guint16) (m->surf_color[desc->inum][2] * (gfloat) G_MAXUINT16);
804 adj_transparency = gtk_adjustment_new(m->surf_color[desc->inum][3], 0.0, 1.0, 0.01, 0.1, 0.0);
805 }
806 else if (desc->i3dtype == CELL)
807 {
808 g_snprintf(title, 20, "cell #%d", desc->inum+1);
809 color.red = (guint16) (m->cell_color[desc->inum][0] * (gfloat) G_MAXUINT16);
810 color.green = (guint16) (m->cell_color[desc->inum][1] * (gfloat) G_MAXUINT16);
811 color.blue = (guint16) (m->cell_color[desc->inum][2] * (gfloat) G_MAXUINT16);
812 adj_transparency = gtk_adjustment_new(m->cell_color[desc->inum][3], 0.0, 1.0, 0.01, 0.1, 0.0);
813 }
814 else if (desc->i3dtype == TEXTBOX)
815 {
816 g_snprintf(title, 20, "textbox #%d", desc->inum+1);
817 color.red = (guint16) (m->textboxes[desc->inum].color[0] * (gfloat) G_MAXUINT16);
818 color.green = (guint16) (m->textboxes[desc->inum].color[1] * (gfloat) G_MAXUINT16);
819 color.blue = (guint16) (m->textboxes[desc->inum].color[2] * (gfloat) G_MAXUINT16);
820
821 }
822
823 dialog = gtk_dialog_new_with_buttons (title, NONE, GTK_DIALOG_MODAL,
824 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
825 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
826 GTK_STOCK_DELETE, GTK_RESPONSE_YES, NULL);
827
828 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
829
830 if (desc->i3dtype != TEXTBOX)
831 {
832 #ifdef GTK2
833 hbox = gtk_hbox_new(FALSE, 0);
834 #endif
835 #ifdef GTK3
836 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
837 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
838 #endif
839 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
840
841 label = gtk_label_new("color");
842 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
843 gtk_widget_show(label);
844
845 color_button = gtk_color_button_new_with_color(&color);
846 gtk_box_pack_start(GTK_BOX(hbox), color_button, TRUE, TRUE, 0);
847 /*g_signal_connect*/
848 gtk_widget_show(color_button);
849
850 #ifdef GTK2
851 separator = gtk_vseparator_new();
852 #endif
853 #ifdef GTK3
854 separator = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
855 #endif
856 gtk_box_pack_start(GTK_BOX(hbox), separator, TRUE, TRUE, 0);
857 gtk_widget_show(separator);
858
859 label = gtk_label_new("transparency");
860 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
861 gtk_widget_show(label);
862
863 spin_button = gtk_spin_button_new(GTK_ADJUSTMENT(adj_transparency), 0.01, 2);
864 gtk_box_pack_start(GTK_BOX(hbox), spin_button, TRUE, TRUE, 0);
865 gtk_widget_show(spin_button);
866
867 gtk_widget_show(hbox);
868 }
869
870 if (desc->i3dtype == SPHERE)
871 {
872 #ifdef GTK2
873 hbox = gtk_hbox_new(FALSE, 0);
874 #endif
875 #ifdef GTK3
876 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
877 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
878 #endif
879 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
880
881 label = gtk_label_new("center");
882 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
883 gtk_widget_show(label);
884
885 g_snprintf(buffer, 30, "%15.8f", m->sphere_center[desc->inum][0]);
886 entry_00 = gtk_entry_new();
887 gtk_box_pack_start(GTK_BOX(hbox), entry_00, TRUE, TRUE, 0);
888 gtk_entry_set_text(GTK_ENTRY(entry_00), buffer);
889 gtk_widget_show(entry_00);
890
891 g_snprintf(buffer, 30, "%15.8f", m->sphere_center[desc->inum][1]);
892 entry_01 = gtk_entry_new();
893 gtk_box_pack_start(GTK_BOX(hbox), entry_01, TRUE, TRUE, 0);
894 gtk_entry_set_text(GTK_ENTRY(entry_01), buffer);
895 gtk_widget_show(entry_01);
896
897 g_snprintf(buffer, 30, "%15.8f", m->sphere_center[desc->inum][2]);
898 entry_02 = gtk_entry_new();
899 gtk_box_pack_start(GTK_BOX(hbox), entry_02, TRUE, TRUE, 0);
900 gtk_entry_set_text(GTK_ENTRY(entry_02), buffer);
901 gtk_widget_show(entry_02);
902
903 gtk_widget_show(hbox);
904
905 #ifdef GTK2
906 hbox = gtk_hbox_new(FALSE, 0);
907 #endif
908 #ifdef GTK3
909 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
910 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
911 #endif
912 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
913
914 label = gtk_label_new("radius");
915 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
916 gtk_widget_show(label);
917
918 g_snprintf(buffer, 30, "%15.8f", m->sphere_radius[desc->inum]);
919 entry_10 = gtk_entry_new();
920 gtk_box_pack_start(GTK_BOX(hbox), entry_10, TRUE, TRUE, 0);
921 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
922 gtk_widget_show(entry_10);
923
924 gtk_widget_show(hbox);
925 }
926 else if (desc->i3dtype == VECTOR)
927 {
928 #ifdef GTK2
929 hbox = gtk_hbox_new(FALSE, 0);
930 #endif
931 #ifdef GTK3
932 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
933 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
934 #endif
935 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
936
937 label = gtk_label_new("base");
938 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
939 gtk_widget_show(label);
940
941 g_snprintf(buffer, 30, "%15.8f", m->vector1[desc->inum][0]);
942 entry_00 = gtk_entry_new();
943 gtk_box_pack_start(GTK_BOX(hbox), entry_00, TRUE, TRUE, 0);
944 gtk_entry_set_text(GTK_ENTRY(entry_00), buffer);
945 gtk_widget_show(entry_00);
946
947 g_snprintf(buffer, 30, "%15.8f", m->vector1[desc->inum][1]);
948 entry_01 = gtk_entry_new();
949 gtk_box_pack_start(GTK_BOX(hbox), entry_01, TRUE, TRUE, 0);
950 gtk_entry_set_text(GTK_ENTRY(entry_01), buffer);
951 gtk_widget_show(entry_01);
952
953 g_snprintf(buffer, 30, "%15.8f", m->vector1[desc->inum][2]);
954 entry_02 = gtk_entry_new();
955 gtk_box_pack_start(GTK_BOX(hbox), entry_02, TRUE, TRUE, 0);
956 gtk_entry_set_text(GTK_ENTRY(entry_02), buffer);
957 gtk_widget_show(entry_02);
958
959 gtk_widget_show(hbox);
960
961 #ifdef GTK2
962 hbox = gtk_hbox_new(FALSE, 0);
963 #endif
964 #ifdef GTK3
965 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
966 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
967 #endif
968 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
969
970 label = gtk_label_new("tip");
971 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
972 gtk_widget_show(label);
973
974 g_snprintf(buffer, 30, "%15.8f", m->vector2[desc->inum][0]);
975 entry_10 = gtk_entry_new();
976 gtk_box_pack_start(GTK_BOX(hbox), entry_10, TRUE, TRUE, 0);
977 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
978 gtk_widget_show(entry_10);
979
980 g_snprintf(buffer, 30, "%15.8f", m->vector2[desc->inum][1]);
981 entry_11 = gtk_entry_new();
982 gtk_box_pack_start(GTK_BOX(hbox), entry_11, TRUE, TRUE, 0);
983 gtk_entry_set_text(GTK_ENTRY(entry_11), buffer);
984 gtk_widget_show(entry_11);
985
986 g_snprintf(buffer, 30, "%15.8f", m->vector2[desc->inum][2]);
987 entry_12 = gtk_entry_new();
988 gtk_box_pack_start(GTK_BOX(hbox), entry_12, TRUE, TRUE, 0);
989 gtk_entry_set_text(GTK_ENTRY(entry_12), buffer);
990 gtk_widget_show(entry_12);
991
992 gtk_widget_show(hbox);
993
994 #ifdef GTK2
995 hbox = gtk_hbox_new(FALSE, 0);
996 #endif
997 #ifdef GTK3
998 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
999 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1000 #endif
1001 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1002
1003 label = gtk_label_new("radius");
1004 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1005 gtk_widget_show(label);
1006
1007 g_snprintf(buffer, 30, "%15.8f", m->radius[desc->inum]);
1008 entry_20 = gtk_entry_new();
1009 gtk_box_pack_start(GTK_BOX(hbox), entry_20, TRUE, TRUE, 0);
1010 gtk_entry_set_text(GTK_ENTRY(entry_20), buffer);
1011 gtk_widget_show(entry_20);
1012
1013 label = gtk_label_new("sharpness");
1014 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1015 gtk_widget_show(label);
1016
1017 g_snprintf(buffer, 30, "%15.8f", m->sharpness[desc->inum]);
1018 entry_21 = gtk_entry_new();
1019 gtk_box_pack_start(GTK_BOX(hbox), entry_21, TRUE, TRUE, 0);
1020 gtk_entry_set_text(GTK_ENTRY(entry_21), buffer);
1021 gtk_widget_show(entry_21);
1022
1023 gtk_widget_show(hbox);
1024 }
1025 else if (desc->i3dtype == TRIANGLE)
1026 {
1027 #ifdef GTK2
1028 hbox = gtk_hbox_new(FALSE, 0);
1029 #endif
1030 #ifdef GTK3
1031 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1032 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1033 #endif
1034 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1035
1036 label = gtk_label_new("vertex 1");
1037 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1038 gtk_widget_show(label);
1039
1040 g_snprintf(buffer, 30, "%15.8f", m->triangle1[desc->inum][0]);
1041 entry_00 = gtk_entry_new();
1042 gtk_box_pack_start(GTK_BOX(hbox), entry_00, TRUE, TRUE, 0);
1043 gtk_entry_set_text(GTK_ENTRY(entry_00), buffer);
1044 gtk_widget_show(entry_00);
1045
1046 g_snprintf(buffer, 30, "%15.8f", m->triangle1[desc->inum][1]);
1047 entry_01 = gtk_entry_new();
1048 gtk_box_pack_start(GTK_BOX(hbox), entry_01, TRUE, TRUE, 0);
1049 gtk_entry_set_text(GTK_ENTRY(entry_01), buffer);
1050 gtk_widget_show(entry_01);
1051
1052 g_snprintf(buffer, 30, "%15.8f", m->triangle1[desc->inum][2]);
1053 entry_02 = gtk_entry_new();
1054 gtk_box_pack_start(GTK_BOX(hbox), entry_02, TRUE, TRUE, 0);
1055 gtk_entry_set_text(GTK_ENTRY(entry_02), buffer);
1056 gtk_widget_show(entry_02);
1057
1058 gtk_widget_show(hbox);
1059
1060 #ifdef GTK2
1061 hbox = gtk_hbox_new(FALSE, 0);
1062 #endif
1063 #ifdef GTK3
1064 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1065 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1066 #endif
1067 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1068
1069 label = gtk_label_new("vertex 2");
1070 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1071 gtk_widget_show(label);
1072
1073 g_snprintf(buffer, 30, "%15.8f", m->triangle2[desc->inum][0]);
1074 entry_10 = gtk_entry_new();
1075 gtk_box_pack_start(GTK_BOX(hbox), entry_10, TRUE, TRUE, 0);
1076 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
1077 gtk_widget_show(entry_10);
1078
1079 g_snprintf(buffer, 30, "%15.8f", m->triangle2[desc->inum][1]);
1080 entry_11 = gtk_entry_new();
1081 gtk_box_pack_start(GTK_BOX(hbox), entry_11, TRUE, TRUE, 0);
1082 gtk_entry_set_text(GTK_ENTRY(entry_11), buffer);
1083 gtk_widget_show(entry_11);
1084
1085 g_snprintf(buffer, 30, "%15.8f", m->triangle2[desc->inum][2]);
1086 entry_12 = gtk_entry_new();
1087 gtk_box_pack_start(GTK_BOX(hbox), entry_12, TRUE, TRUE, 0);
1088 gtk_entry_set_text(GTK_ENTRY(entry_12), buffer);
1089 gtk_widget_show(entry_12);
1090
1091 gtk_widget_show(hbox);
1092
1093 #ifdef GTK2
1094 hbox = gtk_hbox_new(FALSE, 0);
1095 #endif
1096 #ifdef GTK3
1097 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1098 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1099 #endif
1100 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1101
1102 label = gtk_label_new("vertex 3");
1103 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1104 gtk_widget_show(label);
1105
1106 g_snprintf(buffer, 30, "%15.8f", m->triangle3[desc->inum][0]);
1107 entry_20 = gtk_entry_new();
1108 gtk_box_pack_start(GTK_BOX(hbox), entry_20, TRUE, TRUE, 0);
1109 gtk_entry_set_text(GTK_ENTRY(entry_20), buffer);
1110 gtk_widget_show(entry_20);
1111
1112 g_snprintf(buffer, 30, "%15.8f", m->triangle3[desc->inum][1]);
1113 entry_21 = gtk_entry_new();
1114 gtk_box_pack_start(GTK_BOX(hbox), entry_21, TRUE, TRUE, 0);
1115 gtk_entry_set_text(GTK_ENTRY(entry_21), buffer);
1116 gtk_widget_show(entry_21);
1117
1118 g_snprintf(buffer, 30, "%15.8f", m->triangle3[desc->inum][2]);
1119 entry_22 = gtk_entry_new();
1120 gtk_box_pack_start(GTK_BOX(hbox), entry_22, TRUE, TRUE, 0);
1121 gtk_entry_set_text(GTK_ENTRY(entry_22), buffer);
1122 gtk_widget_show(entry_22);
1123
1124 gtk_widget_show(hbox);
1125 }
1126 else if (desc->i3dtype == SURFACE)
1127 {
1128 #ifdef GTK2
1129 hbox = gtk_hbox_new(FALSE, 0);
1130 #endif
1131 #ifdef GTK3
1132 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1133 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1134 #endif
1135 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1136
1137 label = gtk_label_new("point 1");
1138 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1139 gtk_widget_show(label);
1140
1141 g_snprintf(buffer, 30, "%15.8f", m->surf1[desc->inum][0]);
1142 entry_00 = gtk_entry_new();
1143 gtk_box_pack_start(GTK_BOX(hbox), entry_00, TRUE, TRUE, 0);
1144 gtk_entry_set_text(GTK_ENTRY(entry_00), buffer);
1145 gtk_widget_show(entry_00);
1146
1147 g_snprintf(buffer, 30, "%15.8f", m->surf1[desc->inum][1]);
1148 entry_01 = gtk_entry_new();
1149 gtk_box_pack_start(GTK_BOX(hbox), entry_01, TRUE, TRUE, 0);
1150 gtk_entry_set_text(GTK_ENTRY(entry_01), buffer);
1151 gtk_widget_show(entry_01);
1152
1153 g_snprintf(buffer, 30, "%15.8f", m->surf1[desc->inum][2]);
1154 entry_02 = gtk_entry_new();
1155 gtk_box_pack_start(GTK_BOX(hbox), entry_02, TRUE, TRUE, 0);
1156 gtk_entry_set_text(GTK_ENTRY(entry_02), buffer);
1157 gtk_widget_show(entry_02);
1158
1159 gtk_widget_show(hbox);
1160
1161 #ifdef GTK2
1162 hbox = gtk_hbox_new(FALSE, 0);
1163 #endif
1164 #ifdef GTK3
1165 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1166 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1167 #endif
1168 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1169
1170 label = gtk_label_new("point 2");
1171 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1172 gtk_widget_show(label);
1173
1174 g_snprintf(buffer, 30, "%15.8f", m->surf2[desc->inum][0]);
1175 entry_10 = gtk_entry_new();
1176 gtk_box_pack_start(GTK_BOX(hbox), entry_10, TRUE, TRUE, 0);
1177 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
1178 gtk_widget_show(entry_10);
1179
1180 g_snprintf(buffer, 30, "%15.8f", m->surf2[desc->inum][1]);
1181 entry_11 = gtk_entry_new();
1182 gtk_box_pack_start(GTK_BOX(hbox), entry_11, TRUE, TRUE, 0);
1183 gtk_entry_set_text(GTK_ENTRY(entry_11), buffer);
1184 gtk_widget_show(entry_11);
1185
1186 g_snprintf(buffer, 30, "%15.8f", m->surf2[desc->inum][2]);
1187 entry_12 = gtk_entry_new();
1188 gtk_box_pack_start(GTK_BOX(hbox), entry_12, TRUE, TRUE, 0);
1189 gtk_entry_set_text(GTK_ENTRY(entry_12), buffer);
1190 gtk_widget_show(entry_12);
1191
1192 gtk_widget_show(hbox);
1193
1194 #ifdef GTK2
1195 hbox = gtk_hbox_new(FALSE, 0);
1196 #endif
1197 #ifdef GTK3
1198 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1199 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1200 #endif
1201 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1202
1203 label = gtk_label_new("point 3");
1204 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1205 gtk_widget_show(label);
1206
1207 g_snprintf(buffer, 30, "%15.8f", m->surf3[desc->inum][0]);
1208 entry_20 = gtk_entry_new();
1209 gtk_box_pack_start(GTK_BOX(hbox), entry_20, TRUE, TRUE, 0);
1210 gtk_entry_set_text(GTK_ENTRY(entry_20), buffer);
1211 gtk_widget_show(entry_20);
1212
1213 g_snprintf(buffer, 30, "%15.8f", m->surf3[desc->inum][1]);
1214 entry_21 = gtk_entry_new();
1215 gtk_box_pack_start(GTK_BOX(hbox), entry_21, TRUE, TRUE, 0);
1216 gtk_entry_set_text(GTK_ENTRY(entry_21), buffer);
1217 gtk_widget_show(entry_21);
1218
1219 g_snprintf(buffer, 30, "%15.8f", m->surf3[desc->inum][2]);
1220 entry_22 = gtk_entry_new();
1221 gtk_box_pack_start(GTK_BOX(hbox), entry_22, TRUE, TRUE, 0);
1222 gtk_entry_set_text(GTK_ENTRY(entry_22), buffer);
1223 gtk_widget_show(entry_22);
1224
1225 gtk_widget_show(hbox);
1226 }
1227 else if (desc->i3dtype == CELL)
1228 {
1229 #ifdef GTK2
1230 hbox = gtk_hbox_new(FALSE, 0);
1231 #endif
1232 #ifdef GTK3
1233 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1234 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1235 #endif
1236 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1237
1238 label = gtk_label_new("vertex 1");
1239 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1240 gtk_widget_show(label);
1241
1242 g_snprintf(buffer, 30, "%15.8f", m->cell1[desc->inum][0]);
1243 entry_00 = gtk_entry_new();
1244 gtk_box_pack_start(GTK_BOX(hbox), entry_00, TRUE, TRUE, 0);
1245 gtk_entry_set_text(GTK_ENTRY(entry_00), buffer);
1246 gtk_widget_show(entry_00);
1247
1248 g_snprintf(buffer, 30, "%15.8f", m->cell1[desc->inum][1]);
1249 entry_01 = gtk_entry_new();
1250 gtk_box_pack_start(GTK_BOX(hbox), entry_01, TRUE, TRUE, 0);
1251 gtk_entry_set_text(GTK_ENTRY(entry_01), buffer);
1252 gtk_widget_show(entry_01);
1253
1254 g_snprintf(buffer, 30, "%15.8f", m->cell1[desc->inum][2]);
1255 entry_02 = gtk_entry_new();
1256 gtk_box_pack_start(GTK_BOX(hbox), entry_02, TRUE, TRUE, 0);
1257 gtk_entry_set_text(GTK_ENTRY(entry_02), buffer);
1258 gtk_widget_show(entry_02);
1259
1260 gtk_widget_show(hbox);
1261
1262 #ifdef GTK2
1263 hbox = gtk_hbox_new(FALSE, 0);
1264 #endif
1265 #ifdef GTK3
1266 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1267 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1268 #endif
1269 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1270
1271 label = gtk_label_new("vertex 2");
1272 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1273 gtk_widget_show(label);
1274
1275 g_snprintf(buffer, 30, "%15.8f", m->cell2[desc->inum][0]);
1276 entry_10 = gtk_entry_new();
1277 gtk_box_pack_start(GTK_BOX(hbox), entry_10, TRUE, TRUE, 0);
1278 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
1279 gtk_widget_show(entry_10);
1280
1281 g_snprintf(buffer, 30, "%15.8f", m->cell2[desc->inum][1]);
1282 entry_11 = gtk_entry_new();
1283 gtk_box_pack_start(GTK_BOX(hbox), entry_11, TRUE, TRUE, 0);
1284 gtk_entry_set_text(GTK_ENTRY(entry_11), buffer);
1285 gtk_widget_show(entry_11);
1286
1287 g_snprintf(buffer, 30, "%15.8f", m->cell2[desc->inum][2]);
1288 entry_12 = gtk_entry_new();
1289 gtk_box_pack_start(GTK_BOX(hbox), entry_12, TRUE, TRUE, 0);
1290 gtk_entry_set_text(GTK_ENTRY(entry_12), buffer);
1291 gtk_widget_show(entry_12);
1292
1293 gtk_widget_show(hbox);
1294
1295 #ifdef GTK2
1296 hbox = gtk_hbox_new(FALSE, 0);
1297 #endif
1298 #ifdef GTK3
1299 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1300 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1301 #endif
1302 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1303
1304 label = gtk_label_new("vertex 3");
1305 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1306 gtk_widget_show(label);
1307
1308 g_snprintf(buffer, 30, "%15.8f", m->cell3[desc->inum][0]);
1309 entry_20 = gtk_entry_new();
1310 gtk_box_pack_start(GTK_BOX(hbox), entry_20, TRUE, TRUE, 0);
1311 gtk_entry_set_text(GTK_ENTRY(entry_20), buffer);
1312 gtk_widget_show(entry_20);
1313
1314 g_snprintf(buffer, 30, "%15.8f", m->cell3[desc->inum][1]);
1315 entry_21 = gtk_entry_new();
1316 gtk_box_pack_start(GTK_BOX(hbox), entry_21, TRUE, TRUE, 0);
1317 gtk_entry_set_text(GTK_ENTRY(entry_21), buffer);
1318 gtk_widget_show(entry_21);
1319
1320 g_snprintf(buffer, 30, "%15.8f", m->cell3[desc->inum][2]);
1321 entry_22 = gtk_entry_new();
1322 gtk_box_pack_start(GTK_BOX(hbox), entry_22, TRUE, TRUE, 0);
1323 gtk_entry_set_text(GTK_ENTRY(entry_22), buffer);
1324 gtk_widget_show(entry_22);
1325
1326 gtk_widget_show(hbox);
1327
1328 #ifdef GTK2
1329 hbox = gtk_hbox_new(FALSE, 0);
1330 #endif
1331 #ifdef GTK3
1332 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1333 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1334 #endif
1335 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1336
1337 label = gtk_label_new("vertex 4");
1338 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1339 gtk_widget_show(label);
1340
1341 g_snprintf(buffer, 30, "%15.8f", m->cell4[desc->inum][0]);
1342 entry_30 = gtk_entry_new();
1343 gtk_box_pack_start(GTK_BOX(hbox), entry_30, TRUE, TRUE, 0);
1344 gtk_entry_set_text(GTK_ENTRY(entry_30), buffer);
1345 gtk_widget_show(entry_30);
1346
1347 g_snprintf(buffer, 30, "%15.8f", m->cell4[desc->inum][1]);
1348 entry_31 = gtk_entry_new();
1349 gtk_box_pack_start(GTK_BOX(hbox), entry_31, TRUE, TRUE, 0);
1350 gtk_entry_set_text(GTK_ENTRY(entry_31), buffer);
1351 gtk_widget_show(entry_31);
1352
1353 g_snprintf(buffer, 30, "%15.8f", m->cell4[desc->inum][2]);
1354 entry_32 = gtk_entry_new();
1355 gtk_box_pack_start(GTK_BOX(hbox), entry_32, TRUE, TRUE, 0);
1356 gtk_entry_set_text(GTK_ENTRY(entry_32), buffer);
1357 gtk_widget_show(entry_32);
1358
1359 gtk_widget_show(hbox);
1360 }
1361 else if (desc->i3dtype == TEXTBOX)
1362 {
1363 #ifdef GTK2
1364 hbox = gtk_hbox_new(FALSE, 0);
1365 #endif
1366 #ifdef GTK3
1367 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1368 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1369 #endif
1370 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1371
1372 label = gtk_label_new("text:");
1373 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1374 gtk_widget_show(label);
1375
1376 entry_00 = gtk_entry_new();
1377 gtk_entry_set_text(GTK_ENTRY(entry_00), m->textboxes[desc->inum].message);
1378 gtk_box_pack_start(GTK_BOX(hbox), entry_00, FALSE, FALSE, 0);
1379 gtk_widget_show(entry_00);
1380 gtk_widget_show(hbox);
1381
1382 #ifdef GTK2
1383 hbox = gtk_hbox_new(FALSE, 0);
1384 #endif
1385 #ifdef GTK3
1386 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1387 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1388 #endif
1389 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1390
1391 label = gtk_label_new("font:");
1392 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1393 gtk_widget_show(label);
1394
1395 font_button = gtk_font_button_new_with_font(m->textboxes[desc->inum].font);
1396 gtk_box_pack_start(GTK_BOX(hbox), font_button, FALSE, FALSE, 0);
1397 gtk_widget_show(font_button);
1398 gtk_widget_show(hbox);
1399
1400 #ifdef GTK2
1401 hbox = gtk_hbox_new(FALSE, 0);
1402 #endif
1403 #ifdef GTK3
1404 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1405 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1406 #endif
1407 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1408
1409 label = gtk_label_new("color:");
1410 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1411 gtk_widget_show(label);
1412
1413 color_button = gtk_color_button_new();
1414 gtk_color_button_set_color(GTK_COLOR_BUTTON(color_button), &color);
1415 gtk_box_pack_start(GTK_BOX(hbox), color_button, FALSE, FALSE, 0);
1416 gtk_widget_show(color_button);
1417 gtk_widget_show(hbox);
1418
1419 #ifdef GTK2
1420 hbox = gtk_hbox_new(FALSE, 0);
1421 #endif
1422 #ifdef GTK3
1423 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1424 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1425 #endif
1426 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
1427
1428 label = gtk_label_new("coordinates:");
1429 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1430 gtk_widget_show(label);
1431
1432 entry_10 = gtk_entry_new();
1433 g_snprintf(buffer, 20, "%d", m->textboxes[desc->inum].coord_x);
1434 gtk_entry_set_text(GTK_ENTRY(entry_10), buffer);
1435 gtk_box_pack_start(GTK_BOX(hbox), entry_10, FALSE, FALSE, 0);
1436 gtk_widget_show(entry_10);
1437
1438 entry_11 = gtk_entry_new();
1439 g_snprintf(buffer, 20, "%d", m->textboxes[desc->inum].coord_y);
1440 gtk_entry_set_text(GTK_ENTRY(entry_11), buffer);
1441 gtk_box_pack_start(GTK_BOX(hbox), entry_11, FALSE, FALSE, 0);
1442 gtk_widget_show(entry_11);
1443 gtk_widget_show(hbox);
1444
1445 button_1 = gtk_button_new_with_label("click on the display for new position");
1446 gtk_box_pack_start(GTK_BOX(vbox), button_1, FALSE, FALSE, 0);
1447 g_signal_connect(G_OBJECT(button_1), "clicked", G_CALLBACK(luscus_move_textbox_by_click), (gpointer) desc);
1448 g_signal_connect_swapped(G_OBJECT(button_1), "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) dialog);
1449
1450 gtk_widget_show(button_1);
1451 }
1452
1453 response = gtk_dialog_run(GTK_DIALOG(dialog));
1454 if (response == GTK_RESPONSE_ACCEPT)
1455 {
1456 gtk_color_button_get_color(GTK_COLOR_BUTTON(color_button), &color);
1457 if (desc->i3dtype != TEXTBOX)
1458 new_value = gtk_adjustment_get_value(GTK_ADJUSTMENT(adj_transparency));
1459 if (desc->i3dtype == SPHERE)
1460 {
1461 m->sphere_color[desc->inum][0] = (float) color.red / (float) G_MAXUINT16;
1462 m->sphere_color[desc->inum][1] = (float) color.green / (float) G_MAXUINT16;
1463 m->sphere_color[desc->inum][2] = (float) color.blue / (float) G_MAXUINT16;
1464 m->sphere_color[desc->inum][3] = new_value;
1465 m->sphere_center[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1466 m->sphere_center[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_01)));
1467 m->sphere_center[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_02)));
1468 m->sphere_radius[desc->inum] = atof(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1469 }
1470 else if (desc->i3dtype == VECTOR)
1471 {
1472 m->vector_color[desc->inum][0] = (float) color.red / (float) G_MAXUINT16;
1473 m->vector_color[desc->inum][1] = (float) color.green / (float) G_MAXUINT16;
1474 m->vector_color[desc->inum][2] = (float) color.blue / (float) G_MAXUINT16;
1475 m->vector_color[desc->inum][3] = new_value;
1476
1477 m->vector1[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1478 m->vector1[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_01)));
1479 m->vector1[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_02)));
1480 m->vector2[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1481 m->vector2[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_11)));
1482 m->vector2[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_12)));
1483 m->radius[desc->inum] = atof(gtk_entry_get_text(GTK_ENTRY(entry_20)));
1484 m->sharpness[desc->inum] = atof(gtk_entry_get_text(GTK_ENTRY(entry_21)));
1485 }
1486 else if (desc->i3dtype == TRIANGLE)
1487 {
1488 m->triangle_color[desc->inum][0] = (float) color.red / (float) G_MAXUINT16;
1489 m->triangle_color[desc->inum][1] = (float) color.green / (float) G_MAXUINT16;
1490 m->triangle_color[desc->inum][2] = (float) color.blue / (float) G_MAXUINT16;
1491 m->triangle_color[desc->inum][3] = new_value;
1492
1493 m->triangle1[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1494 m->triangle1[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_01)));
1495 m->triangle1[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_02)));
1496 m->triangle2[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1497 m->triangle2[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_11)));
1498 m->triangle2[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_12)));
1499 m->triangle3[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_20)));
1500 m->triangle3[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_21)));
1501 m->triangle3[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_22)));
1502 }
1503 else if (desc->i3dtype == SURFACE)
1504 {
1505 m->surf_color[desc->inum][0] = (float) color.red / (float) G_MAXUINT16;
1506 m->surf_color[desc->inum][1] = (float) color.green / (float) G_MAXUINT16;
1507 m->surf_color[desc->inum][2] = (float) color.blue / (float) G_MAXUINT16;
1508 m->surf_color[desc->inum][3] = new_value;
1509
1510 m->surf1[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1511 m->surf1[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_01)));
1512 m->surf1[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_02)));
1513 m->surf2[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1514 m->surf2[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_11)));
1515 m->surf2[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_12)));
1516 m->surf3[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_20)));
1517 m->surf3[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_21)));
1518 m->surf3[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_22)));
1519 }
1520 else if (desc->i3dtype == CELL)
1521 {
1522 m->cell_color[desc->inum][0] = (float) color.red / (float) G_MAXUINT16;
1523 m->cell_color[desc->inum][1] = (float) color.green / (float) G_MAXUINT16;
1524 m->cell_color[desc->inum][2] = (float) color.blue / (float) G_MAXUINT16;
1525 m->cell_color[desc->inum][3] = new_value;
1526
1527 m->cell1[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1528 m->cell1[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_01)));
1529 m->cell1[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_02)));
1530 m->cell2[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1531 m->cell2[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_11)));
1532 m->cell2[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_12)));
1533 m->cell3[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_20)));
1534 m->cell3[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_21)));
1535 m->cell3[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_22)));
1536 m->cell4[desc->inum][0] = atof(gtk_entry_get_text(GTK_ENTRY(entry_30)));
1537 m->cell4[desc->inum][1] = atof(gtk_entry_get_text(GTK_ENTRY(entry_31)));
1538 m->cell4[desc->inum][2] = atof(gtk_entry_get_text(GTK_ENTRY(entry_32)));
1539 }
1540 else if (desc->i3dtype == TEXTBOX)
1541 {
1542 gv_gtk_get_screen_size(&width, &height);
1543
1544 m->textboxes[desc->inum].coord_x = atoi(gtk_entry_get_text(GTK_ENTRY(entry_10)));
1545 if (m->textboxes[desc->inum].coord_x > width) m->textboxes[desc->inum].coord_x = width;
1546 m->textboxes[desc->inum].coord_y = atoi(gtk_entry_get_text(GTK_ENTRY(entry_11)));
1547 if (m->textboxes[desc->inum].coord_y > height) m->textboxes[desc->inum].coord_y = height;
1548
1549 m->textboxes[desc->inum].color[0] = (float) color.red/G_MAXUINT16;
1550 m->textboxes[desc->inum].color[1] = (float) color.green/G_MAXUINT16;
1551 m->textboxes[desc->inum].color[2] = (float) color.blue/G_MAXUINT16;
1552 m->textboxes[desc->inum].color[3] = 1.0;
1553
1554 if (m->textboxes[desc->inum].font) free(m->textboxes[desc->inum].font);
1555 m->textboxes[desc->inum].font = g_strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font_button)));
1556 if (m->textboxes[desc->inum].message) free(m->textboxes[desc->inum].message);
1557 m->textboxes[desc->inum].message = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_00)));
1558 draw_pixdata_textbox(desc->inum);
1559 }
1560 }
1561 else if (response == GTK_RESPONSE_YES)
1562 {
1563 if (desc->i3dtype == SPHERE)
1564 {
1565 for(i = desc->inum; i < m->nsphere-1; i++)
1566 {
1567 m->sphere_center[i][0] = m->sphere_center[i+1][0];
1568 m->sphere_center[i][1] = m->sphere_center[i+1][1];
1569 m->sphere_center[i][2] = m->sphere_center[i+1][2];
1570 m->sphere_radius[i] = m->sphere_radius[i+1];
1571 m->sphere_color[i][0] = m->sphere_color[i+1][0];
1572 m->sphere_color[i][1] = m->sphere_color[i+1][1];
1573 m->sphere_color[i][2] = m->sphere_color[i+1][2];
1574 m->sphere_color[i][3] = m->sphere_color[i+1][3];
1575 }
1576 m->nsphere--;
1577 m->sphere_center = (XYZ*) realloc(m->sphere_center, sizeof(XYZ) * m->nsphere);
1578 m->sphere_radius = (double*) realloc(m->sphere_radius, sizeof(double) * m->nsphere);
1579 m->sphere_color = (color_t*) realloc(m->sphere_color, sizeof(color_t) * m->nsphere);
1580 }
1581 else if (desc->i3dtype == VECTOR)
1582 {
1583 for(i = desc->inum; i < m->nvector-1; i++)
1584 {
1585 m->vector1[i][0] = m->vector1[i+1][0];
1586 m->vector1[i][1] = m->vector1[i+1][1];
1587 m->vector1[i][2] = m->vector1[i+1][2];
1588 m->vector2[i][0] = m->vector2[i+1][0];
1589 m->vector2[i][1] = m->vector2[i+1][1];
1590 m->vector2[i][2] = m->vector2[i+1][2];
1591 m->radius[i] = m->radius[i+1];
1592 m->sharpness[i] = m->sharpness[i+1];
1593 m->vector_color[i][0] = m->vector_color[i+1][0];
1594 m->vector_color[i][1] = m->vector_color[i+1][1];
1595 m->vector_color[i][2] = m->vector_color[i+1][2];
1596 m->vector_color[i][3] = m->vector_color[i+1][3];
1597 }
1598 m->nvector--;
1599 m->vector1 = (XYZ*) realloc(m->vector1, sizeof(XYZ) * m->nvector);
1600 m->vector2 = (XYZ*) realloc(m->vector2, sizeof(XYZ) * m->nvector);
1601 m->radius = (double*) realloc(m->radius, sizeof(double) * m->nvector);
1602 m->sharpness = (double*) realloc(m->sharpness, sizeof(double) * m->nvector);
1603 m->vector_color = (color_t*) realloc(m->vector_color, sizeof(color_t) * m->nvector);
1604 }
1605 else if (desc->i3dtype == TRIANGLE)
1606 {
1607 for(i = desc->inum; i < m->ntriangle-1; i++)
1608 {
1609 m->triangle1[i][0] = m->triangle1[i+1][0];
1610 m->triangle1[i][1] = m->triangle1[i+1][1];
1611 m->triangle1[i][2] = m->triangle1[i+1][2];
1612 m->triangle2[i][0] = m->triangle2[i+1][0];
1613 m->triangle2[i][1] = m->triangle2[i+1][1];
1614 m->triangle2[i][2] = m->triangle2[i+1][2];
1615 m->triangle3[i][0] = m->triangle3[i+1][0];
1616 m->triangle3[i][1] = m->triangle3[i+1][1];
1617 m->triangle3[i][2] = m->triangle3[i+1][2];
1618 m->triangle_color[i][0] = m->triangle_color[i+1][0];
1619 m->triangle_color[i][1] = m->triangle_color[i+1][1];
1620 m->triangle_color[i][2] = m->triangle_color[i+1][2];
1621 m->triangle_color[i][3] = m->triangle_color[i+1][3];
1622 }
1623 m->ntriangle--;
1624 m->triangle1 = (XYZ*) realloc(m->triangle1, sizeof(XYZ) * m->ntriangle);
1625 m->triangle2 = (XYZ*) realloc(m->triangle2, sizeof(XYZ) * m->ntriangle);
1626 m->triangle3 = (XYZ*) realloc(m->triangle3, sizeof(XYZ) * m->ntriangle);
1627 m->triangle_color = (color_t*) realloc(m->triangle_color, sizeof(color_t) * m->ntriangle);
1628 }
1629 else if (desc->i3dtype == SURFACE)
1630 {
1631 for(i = desc->inum; i < m->nsurf-1; i++)
1632 {
1633 m->surf1[i][0] = m->surf1[i+1][0];
1634 m->surf1[i][1] = m->surf1[i+1][1];
1635 m->surf1[i][2] = m->surf1[i+1][2];
1636 m->surf2[i][0] = m->surf2[i+1][0];
1637 m->surf2[i][1] = m->surf2[i+1][1];
1638 m->surf2[i][2] = m->surf2[i+1][2];
1639 m->surf3[i][0] = m->surf3[i+1][0];
1640 m->surf3[i][1] = m->surf3[i+1][1];
1641 m->surf3[i][2] = m->surf3[i+1][2];
1642 m->surf_color[i][0] = m->surf_color[i+1][0];
1643 m->surf_color[i][1] = m->surf_color[i+1][1];
1644 m->surf_color[i][2] = m->surf_color[i+1][2];
1645 m->surf_color[i][3] = m->surf_color[i+1][3];
1646 }
1647 m->nsurf--;
1648 m->surf1 = (XYZ*) realloc(m->surf1, sizeof(XYZ) * m->nsurf);
1649 m->surf2 = (XYZ*) realloc(m->surf2, sizeof(XYZ) * m->nsurf);
1650 m->surf3 = (XYZ*) realloc(m->surf3, sizeof(XYZ) * m->nsurf);
1651 m->surf_color = (color_t*) realloc(m->surf_color, sizeof(color_t) * m->nsurf);
1652 }
1653 else if (desc->i3dtype == CELL)
1654 {
1655 for(i = desc->inum; i < m->ncells-1; i++)
1656 {
1657 m->cell1[i][0] = m->cell1[i+1][0];
1658 m->cell1[i][1] = m->cell1[i+1][1];
1659 m->cell1[i][2] = m->cell1[i+1][2];
1660 m->cell2[i][0] = m->cell2[i+1][0];
1661 m->cell2[i][1] = m->cell2[i+1][1];
1662 m->cell2[i][2] = m->cell2[i+1][2];
1663 m->cell3[i][0] = m->cell3[i+1][0];
1664 m->cell3[i][1] = m->cell3[i+1][1];
1665 m->cell3[i][2] = m->cell3[i+1][2];
1666 m->cell4[i][0] = m->cell4[i+1][0];
1667 m->cell4[i][1] = m->cell4[i+1][1];
1668 m->cell4[i][2] = m->cell4[i+1][2];
1669 m->cell_color[i][0] = m->cell_color[i+1][0];
1670 m->cell_color[i][1] = m->cell_color[i+1][1];
1671 m->cell_color[i][2] = m->cell_color[i+1][2];
1672 m->cell_color[i][3] = m->cell_color[i+1][3];
1673 }
1674 m->ncells--;
1675 m->cell1 = (XYZ*) realloc(m->cell1, sizeof(XYZ) * m->ncells);
1676 m->cell2 = (XYZ*) realloc(m->cell2, sizeof(XYZ) * m->ncells);
1677 m->cell3 = (XYZ*) realloc(m->cell3, sizeof(XYZ) * m->ncells);
1678 m->cell4 = (XYZ*) realloc(m->cell4, sizeof(XYZ) * m->ncells);
1679 m->cell_color = (color_t*) realloc(m->cell_color, sizeof(color_t) * m->ncells);
1680 }
1681 else if (desc->i3dtype == TEXTBOX)
1682 {
1683 delete_ith_textbox(m, desc->inum);
1684 }
1685 }
1686 if (GTK_IS_WIDGET(dialog)) gtk_widget_destroy(dialog);
1687
1688 unset_go_selected();
1689 rerender_3d();
1690
1691 if (response != GTK_RESPONSE_REJECT)
1692 {
1693 luscus_gtk_update_3Dobject_info();
1694 }
1695
1696 redraw();
1697 append_backup();
1698 }
1699
luscus_move_textbox_by_click(GtkWidget * button,GTK_3D_DESC * desc)1700 void luscus_move_textbox_by_click(GtkWidget* button, GTK_3D_DESC* desc)
1701 {
1702 luscus_set_textbox_number(desc->inum);
1703 textbox_state = 3;
1704 }
1705
1706 /*menubar functions*/
1707
callback_open_file(GtkWidget * widget,gpointer data)1708 void callback_open_file(GtkWidget *widget, gpointer data)
1709 {
1710 int i;
1711 gchar *tmp;
1712 GtkWidget *dialog;
1713 GtkFileFilter *ffilter;
1714 char *filename;
1715 char *file_description;
1716
1717 dialog = gtk_file_chooser_dialog_new("open file", NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
1718 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1719 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1720 NULL);
1721 if (get_current_directory())
1722 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), get_current_directory());
1723 else
1724 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "./");
1725
1726 /*filter for all files*/
1727 ffilter = gtk_file_filter_new();
1728 gtk_file_filter_set_name(ffilter, "all files");
1729 gtk_file_filter_add_pattern(ffilter, "*");
1730 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1731
1732 /*filter for native luscus format*/
1733 ffilter = gtk_file_filter_new();
1734 tmp = g_strconcat("*.", input_filetypes[0].extension, NULL);
1735 gtk_file_filter_set_name(ffilter, input_filetypes[0].description);
1736 gtk_file_filter_add_pattern(ffilter, tmp);
1737 g_free(tmp);
1738 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1739
1740 for(i = 0; i < n_input_types; i++)
1741 if (input_filetypes[i].forward)
1742 {
1743 ffilter = gtk_file_filter_new();
1744 tmp = g_strconcat("*.", input_filetypes[i].extension, NULL);
1745 gtk_file_filter_set_name(ffilter, input_filetypes[i].description);
1746 gtk_file_filter_add_pattern(ffilter, tmp);
1747 g_free(tmp);
1748 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1749 }
1750
1751 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1752 {
1753 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1754 ffilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
1755 file_description = (char*) gtk_file_filter_get_name(GTK_FILE_FILTER(ffilter));
1756
1757 deallocate_vib_buttons();
1758
1759 /**/
1760
1761 if (strcmp(file_description, "all files") == 0) open_file(filename, NULL);
1762 else open_file(filename, file_description);
1763 g_free(filename);
1764 }
1765
1766 gtk_widget_destroy(dialog);
1767 set_scale();
1768 rerender_3d();
1769 redraw();
1770 }
1771
callback_save_file(GtkWidget * widget,gpointer data)1772 void callback_save_file(GtkWidget *widget, gpointer data)
1773 {
1774 gint i;
1775 gint mode;
1776 GtkWidget *dialog;
1777 gchar *filename;
1778 GtkFileFilter *ffilter;
1779
1780 gchar *filetype;
1781 gchar *msg;
1782 mode = GPOINTER_TO_INT(data);
1783
1784 filename = g_strdup(get_input_filename());
1785 if (filename == NULL) mode = 1;
1786
1787 if (mode == 0)
1788 {
1789 luscus_gtk_do_save_file(filename, get_filetype(filename));
1790 /* filename = ...*/
1791 /*close input*/
1792 /*luscus_gtk_do_save_file*/
1793 }
1794 else
1795 {
1796 dialog = gtk_file_chooser_dialog_new("Save file", NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
1797 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1798 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1799 NULL);
1800
1801 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
1802 set_save_file_filename(dialog, mode);
1803
1804 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1805 {
1806 ffilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
1807 filetype = (gchar*) gtk_file_filter_get_name(ffilter);
1808
1809 for (i = 0; i < n_input_types; i++)
1810 if (g_strcmp0(filetype, input_filetypes[i].description) == 0) break;
1811
1812 g_free(filename);
1813 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1814 luscus_gtk_do_save_file(filename, i);
1815 }
1816
1817 gtk_widget_destroy(dialog);
1818 }
1819
1820 msg = g_strdup_printf("File saved to: %s", filename);
1821 luscus_gtk_pop_message_from_statusbar2();
1822 luscus_gtk_push_message_to_statusbar2(msg);
1823 g_free(msg);
1824 g_free(filename);
1825 }
1826
set_save_file_filename(GtkWidget * dialog,gint mode)1827 void set_save_file_filename(GtkWidget *dialog, gint mode)
1828 {
1829 gint i;
1830 gchar *fname, *tmp;
1831 GtkFileFilter *ffilter;
1832
1833 /*filter for all files*/
1834 ffilter = gtk_file_filter_new();
1835 gtk_file_filter_set_name(ffilter, "all files");
1836 gtk_file_filter_add_pattern(ffilter, "*");
1837 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1838
1839 /*filter for luscus file*/
1840 ffilter = gtk_file_filter_new();
1841 tmp = g_strconcat("*.", input_filetypes[0].extension, NULL);
1842 gtk_file_filter_set_name(ffilter, input_filetypes[0].description);
1843 gtk_file_filter_add_pattern(ffilter, tmp);
1844 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1845 g_free(tmp);
1846
1847 /*filters for other files*/
1848 for(i = 0; i < n_input_types; i++)
1849 if (input_filetypes[i].backward)
1850 {
1851 ffilter = gtk_file_filter_new();
1852 tmp = g_strconcat("*.", input_filetypes[i].extension, NULL);
1853 gtk_file_filter_set_name(ffilter, input_filetypes[i].description);
1854 gtk_file_filter_add_pattern(ffilter, tmp);
1855 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), ffilter);
1856 g_free(tmp);
1857 }
1858
1859 fname = nextfname();
1860
1861 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), "./");
1862 if (fname == NULL) gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), "newfile");
1863 else gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), fname);
1864
1865 free(fname);
1866 }
1867
callback_close_file(GtkWidget * widget,gpointer data)1868 void callback_close_file(GtkWidget* widget, gpointer data)
1869 {
1870 close_file();
1871 deallocate_vib_buttons();
1872 rerender_3d();
1873 redraw();
1874 luscus_gtk_update_3Dobject_info();
1875 }
1876
callback_do_undo(GtkWidget * widget,gpointer data)1877 void callback_do_undo(GtkWidget *widget, gpointer data)
1878 {
1879 luscus_gtk_pop_message_from_statusbar2();
1880 get_backup();
1881 /* set_scale();*/
1882 rerender_3d();
1883 redraw();
1884 luscus_gtk_update_3Dobject_info();
1885 }
1886
callback_make_editable(GtkWidget * widget,gpointer data)1887 void callback_make_editable(GtkWidget *widget, gpointer data)
1888 {
1889 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
1890 {
1891 m->editable = 1;
1892 luscus_gtk_enable_editing();
1893 }
1894 else
1895 {
1896 m->editable = 0;
1897 luscus_gtk_diseable_editing();
1898 }
1899
1900
1901 }
1902
callback_change_background(GtkWidget * widget,gpointer data)1903 void callback_change_background(GtkWidget *widget, gpointer data)
1904 {
1905 GtkWidget *dialog;
1906 GtkWidget *colorsel;
1907 GdkColor *background_color;
1908
1909 background_color = (GdkColor*) g_malloc(sizeof(GdkColor));
1910 /*convert color_t to the GdkColor*/
1911 color_t_2_GdkColor(background_color, Input_Data.background_color);
1912
1913 dialog = gtk_color_selection_dialog_new("Background color");
1914 /* colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);*/
1915 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
1916 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), background_color);
1917
1918 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
1919 {
1920 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), background_color);
1921 GdkColor_2_color_t(background_color, Input_Data.background_color);
1922 }
1923 gtk_widget_destroy (dialog);
1924 redraw();
1925
1926 g_free(background_color);
1927 }
1928
1929 /* conversion of color_t in OpenGL format to the GTK format (GdkColor) */
color_t_2_GdkColor(GdkColor * out_color,color_t in_color)1930 void color_t_2_GdkColor(GdkColor *out_color, color_t in_color)
1931 {
1932 out_color->red = (guint16) G_MAXUINT16 * ((double) in_color[0]);
1933 out_color->green = (guint16) G_MAXUINT16 * ((double) in_color[1]);
1934 out_color->blue = (guint16) G_MAXUINT16 * ((double) in_color[2]);
1935 out_color->pixel = (guint32) G_MAXUINT32 * ((double) in_color[3]);
1936 }
1937 /* conversion of the GTK format (GdkColor) to the color_t OpenGL[4] */
1938
GdkColor_2_color_t(GdkColor * in_color,color_t out_color)1939 void GdkColor_2_color_t(GdkColor *in_color, color_t out_color)
1940 {
1941 out_color[0] = (double) in_color->red / (double) G_MAXUINT16;
1942 out_color[1] = (double) in_color->green / (double) G_MAXUINT16;
1943 out_color[2] = (double) in_color->blue / (double) G_MAXUINT16;
1944 out_color[3] = (double) in_color->pixel / (double) G_MAXUINT32;
1945 }
1946
callback_change_label(GtkWidget * widget,gpointer data)1947 void callback_change_label(GtkWidget *widget, gpointer data)
1948 {
1949 GtkWidget *dialog;
1950 GtkWidget *colorsel;
1951 GdkColor *label_color;
1952
1953 label_color = (GdkColor*) g_malloc(sizeof(GdkColor));
1954 color_t_2_GdkColor(label_color, Input_Data.label_color);
1955
1956 dialog = gtk_color_selection_dialog_new("Label color");
1957 /* colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);*/
1958 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
1959 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), label_color);
1960
1961 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
1962 {
1963 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), label_color);
1964 GdkColor_2_color_t(label_color, Input_Data.label_color);
1965 }
1966 gtk_widget_destroy (dialog);
1967 redraw();
1968
1969 g_free(label_color);
1970 }
1971
callback_change_pos_orbital(GtkWidget * widget,gpointer data)1972 void callback_change_pos_orbital(GtkWidget *widget, gpointer data)
1973 {
1974 GtkWidget *dialog;
1975 /*GtkColorSelection*/ GtkWidget *colorsel;
1976 GdkColor *orbital_color;
1977
1978 orbital_color = (GdkColor*) g_malloc(sizeof(GdkColor));
1979 color_t_2_GdkColor(orbital_color, Input_Data.neg_pos_color[0]);
1980
1981 dialog = gtk_color_selection_dialog_new("Orbital color");
1982 /* colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);*/
1983 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
1984 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), orbital_color);
1985
1986 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
1987 {
1988 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), orbital_color);
1989 GdkColor_2_color_t(orbital_color, Input_Data.neg_pos_color[0]);
1990 }
1991 gtk_widget_destroy(dialog);
1992 rerender_3d();
1993 redraw();
1994
1995 g_free(orbital_color);
1996 }
1997
callback_change_neg_orbital(GtkWidget * widget,gpointer data)1998 void callback_change_neg_orbital(GtkWidget *widget, gpointer data)
1999 {
2000 GtkWidget *dialog;
2001 /*GtkColorSelection*/ GtkWidget *colorsel;
2002 GdkColor *orbital_color;
2003
2004 orbital_color = (GdkColor*) g_malloc(sizeof(GdkColor));
2005 color_t_2_GdkColor(orbital_color, Input_Data.neg_pos_color[1]);
2006
2007 dialog = gtk_color_selection_dialog_new("Orbital color");
2008 /* colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);*/
2009 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
2010 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), orbital_color);
2011
2012 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2013 {
2014 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), orbital_color);
2015 GdkColor_2_color_t(orbital_color, Input_Data.neg_pos_color[1]);
2016 }
2017 gtk_widget_destroy(dialog);
2018 rerender_3d();
2019 redraw();
2020
2021 g_free(orbital_color);
2022 }
2023
callback_change_pos_epot(GtkWidget * widget,gpointer data)2024 void callback_change_pos_epot(GtkWidget *widget, gpointer data)
2025 {
2026 GtkWidget *dialog;
2027 GtkWidget *colorsel;
2028 GdkColor *epot_color;
2029
2030 epot_color = (GdkColor*) g_malloc(sizeof(GdkColor));
2031 color_t_2_GdkColor(epot_color, Input_Data.electrostatic_poten_color[0]);
2032
2033 dialog = gtk_color_selection_dialog_new("Electrostatic potential color");
2034 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
2035 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), epot_color);
2036
2037 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2038 {
2039 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), epot_color);
2040 GdkColor_2_color_t(epot_color, Input_Data.electrostatic_poten_color[0]);
2041 }
2042 gtk_widget_destroy(dialog);
2043 rerender_3d();
2044 redraw();
2045
2046 g_free(epot_color);
2047 }
2048
callback_change_neg_epot(GtkWidget * widget,gpointer data)2049 void callback_change_neg_epot(GtkWidget *widget, gpointer data)
2050 {
2051 GtkWidget *dialog;
2052 GtkWidget *colorsel;
2053 GdkColor *epot_color;
2054
2055 epot_color = (GdkColor*) g_malloc(sizeof(GdkColor));
2056 color_t_2_GdkColor(epot_color, Input_Data.electrostatic_poten_color[1]);
2057
2058 dialog = gtk_color_selection_dialog_new("Electrostatic potential color");
2059 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
2060 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), epot_color);
2061
2062 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2063 {
2064 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), epot_color);
2065 GdkColor_2_color_t(epot_color, Input_Data.electrostatic_poten_color[1]);
2066 }
2067 gtk_widget_destroy(dialog);
2068 rerender_3d();
2069 redraw();
2070
2071 g_free(epot_color);
2072 }
2073
callback_change_plain(GtkWidget * widget,gpointer data)2074 void callback_change_plain(GtkWidget *widget, gpointer data)
2075 {
2076 GtkWidget *dialog;
2077 /*GtkColorSelection*/ GtkWidget *colorsel;
2078 GdkColor *plain_color;
2079
2080 plain_color = (GdkColor*) g_malloc(sizeof(GdkColor));
2081 color_t_2_GdkColor(plain_color, Input_Data.extracolor);
2082
2083 dialog = gtk_color_selection_dialog_new("Plain color");
2084 /* colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);*/
2085 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog));
2086 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), plain_color);
2087
2088 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2089 {
2090 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), plain_color);
2091 GdkColor_2_color_t(plain_color, Input_Data.extracolor);
2092 }
2093 gtk_widget_destroy (dialog);
2094 rerender_3d();
2095 redraw();
2096
2097 g_free(plain_color);
2098 }
2099
callback_change_font(GtkWidget * widget,gpointer data)2100 void callback_change_font(GtkWidget *widget, gpointer data)
2101 {
2102 GtkWidget *dialog;
2103
2104 #ifdef GTK2
2105 dialog = gtk_font_selection_dialog_new("Select font");
2106 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), Input_Data.font);
2107 #endif
2108 #ifdef GTK3
2109 dialog = gtk_font_chooser_dialog_new("Select font", NULL);
2110 gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), Input_Data.font);
2111 #endif
2112
2113 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2114 {
2115 #ifdef GTK2
2116 g_strlcpy(Input_Data.font, gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog)), 100);
2117 #endif
2118 #ifdef GTK3
2119 g_strlcpy(Input_Data.font, gtk_font_chooser_get_preview_text(GTK_FONT_CHOOSER(dialog)), 100);
2120 #endif
2121 draw_all_pixdata();
2122 }
2123
2124 gtk_widget_destroy(dialog);
2125 }
2126
callback_adjust_atom_properties(GtkWidget * widget,gpointer data)2127 void callback_adjust_atom_properties(GtkWidget *widget, gpointer data)
2128 {
2129 GtkWidget *dialog;
2130 GtkWidget *hbox;
2131 GtkWidget *label;
2132 GtkWidget *persys;
2133 GtkWidget *separator;
2134 GdkColor color;
2135 gint response;
2136 gint i, j;
2137
2138
2139 #ifdef GTK2
2140 GtkObject *adj_atom_size, *adj_bond_size, *adj_valency;
2141 #endif
2142 #ifdef GTK3
2143 GtkAdjustment *adj_atom_size, *adj_bond_size, *adj_valency;
2144 #endif
2145
2146 dialog = gtk_dialog_new_with_buttons("Atom properties", GTK_WINDOW(gtk_widget_get_toplevel(widget)),
2147 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
2148 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
2149 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
2150 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2151 NULL);
2152
2153 tmp_elem = (ELEM_DATA*) g_malloc(sizeof(ELEM_DATA) * number_of_elements);
2154
2155 /*copy data to the newly allocated array; Direct data changing will be on temporary array; this way, user can change properties on more than one atom*/
2156 for(i = 0; i < number_of_elements; i++)
2157 {
2158 tmp_elem[i].name = g_strdup(e[i].name);
2159 for(j = 0; j < 4; j++)
2160 tmp_elem[i].color[j] = e[i].color[j];
2161 tmp_elem[i].vdw_rad = e[i].vdw_rad;
2162 tmp_elem[i].bond_rad = e[i].bond_rad;
2163 tmp_elem[i].valency = e[i].valency;
2164 tmp_elem[i].periodic_pos_x = e[i].periodic_pos_x;
2165 tmp_elem[i].periodic_pos_y = e[i].periodic_pos_y;
2166 }
2167
2168 persys = luscus_gtk_make_periodic_system1(tmp_elem);
2169
2170 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), persys, TRUE, TRUE, 0);
2171
2172 #ifdef GTK2
2173 separator = gtk_vseparator_new();
2174 #endif
2175 #ifdef GTK3
2176 separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
2177 #endif
2178 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), separator, TRUE, TRUE, 0);
2179 gtk_widget_show(separator);
2180
2181 #ifdef GTK2
2182 hbox = gtk_hbox_new(FALSE, 0);
2183 #endif
2184 #ifdef GTK3
2185 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2186 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
2187 #endif
2188
2189 atom_prop_label = gtk_label_new(tmp_elem[elem_selected].name);
2190 gtk_box_pack_start(GTK_BOX(hbox), atom_prop_label, FALSE, FALSE, 0);
2191 gtk_widget_show(atom_prop_label);
2192
2193 color_t_2_GdkColor(&color, tmp_elem[elem_selected].color);
2194 atom_prop_color_button = gtk_color_button_new();
2195 gtk_color_button_set_color(GTK_COLOR_BUTTON(atom_prop_color_button), &color);
2196 gtk_box_pack_start(GTK_BOX(hbox), atom_prop_color_button, FALSE, FALSE, 5);
2197 gtk_widget_show(atom_prop_color_button);
2198
2199 label = gtk_label_new("Van der Waals radius:");
2200 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
2201 gtk_widget_show(label);
2202
2203 adj_atom_size = gtk_adjustment_new(0.0, 0.F, 3.F, 0.01F, 0.1F, 0.F);
2204 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_atom_size), tmp_elem[elem_selected].vdw_rad);
2205
2206 #ifdef GTK2
2207 atom_prop_atom_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_atom_size), 0.01, 2);
2208 #endif
2209 #ifdef GTK3
2210 atom_prop_atom_size_spin = gtk_spin_button_new(adj_atom_size, 0.01, 2);
2211 #endif
2212 g_signal_connect(G_OBJECT(atom_prop_atom_size_spin), "value-changed", G_CALLBACK(atom_prop_atom_size_spin_callback), NULL);
2213 gtk_box_pack_start(GTK_BOX(hbox), atom_prop_atom_size_spin, FALSE, FALSE, 0);
2214 gtk_widget_show(atom_prop_atom_size_spin);
2215
2216 label = gtk_label_new("bonding radius:");
2217 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
2218 gtk_widget_show(label);
2219
2220 adj_bond_size = gtk_adjustment_new(0.0, 0.F, 3.F, 0.01F, 0.1F, 0.F);
2221 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond_size), tmp_elem[elem_selected].bond_rad);
2222
2223 #ifdef GTK2
2224 atom_prop_bond_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_bond_size), 0.01, 2);
2225 #endif
2226 #ifdef GTK3
2227 atom_prop_bond_size_spin = gtk_spin_button_new(adj_bond_size, 0.01, 2);
2228 #endif
2229 g_signal_connect(G_OBJECT(atom_prop_bond_size_spin), "value-changed", G_CALLBACK(atom_prop_bond_size_spin_callback), NULL);
2230 gtk_box_pack_start(GTK_BOX(hbox), atom_prop_bond_size_spin, FALSE, FALSE, 0);
2231 gtk_widget_show(atom_prop_bond_size_spin);
2232
2233 label = gtk_label_new("valency:");
2234 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
2235 gtk_widget_show(label);
2236
2237 adj_valency = gtk_adjustment_new(0.0, 0.F, 30.F, 1.0F, 1.0F, 0.F);
2238 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_valency), tmp_elem[elem_selected].valency);
2239
2240 #ifdef GTK2
2241 atom_prop_atom_valency_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj_valency), 0.01, 2);
2242 #endif
2243 #ifdef GTK3
2244 atom_prop_atom_valency_spin = gtk_spin_button_new(adj_valency, 0.01, 2);
2245 #endif
2246 g_signal_connect(G_OBJECT(atom_prop_atom_valency_spin), "value-changed", G_CALLBACK(atom_prop_atom_valency_spin_callback), NULL);
2247 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(atom_prop_atom_valency_spin), 0);
2248 gtk_box_pack_start(GTK_BOX(hbox), atom_prop_atom_valency_spin, FALSE, FALSE, 0);
2249 gtk_widget_show(atom_prop_atom_valency_spin);
2250
2251 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), hbox, TRUE, TRUE, 0);
2252 gtk_widget_show(hbox);
2253
2254 #ifdef GTK2
2255 separator = gtk_hseparator_new();
2256 #endif
2257 #ifdef GTK3
2258 separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
2259 #endif
2260 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), separator, TRUE, TRUE, 0);
2261 gtk_widget_show(separator);
2262
2263 response = gtk_dialog_run(GTK_DIALOG(dialog));
2264
2265 if (response == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_APPLY)
2266 {
2267 gtk_color_button_get_color(GTK_COLOR_BUTTON(atom_prop_color_button), &color);
2268 GdkColor_2_color_t(&color, e[elem_selected].color);
2269 e[elem_selected].vdw_rad = tmp_elem[elem_selected].vdw_rad;
2270 e[elem_selected].bond_rad = tmp_elem[elem_selected].bond_rad;
2271 e[elem_selected].valency = tmp_elem[elem_selected].valency;
2272
2273 /*copy data to the newly allocated array; Direct data changing will be on temporary array; this way, user can change properties on more than one atom*/
2274 /* for(i = 0; i < number_of_elements; i++)
2275 {
2276 for(j = 0; j < 4; j++)
2277 e[i].color[j] = tmp_elem[i].color[j];
2278 e[i].vdw_rad = tmp_elem[i].vdw_rad;
2279 e[i].bond_rad = tmp_elem[i].bond_rad;
2280 e[i].valency = tmp_elem[i].valency;
2281 }*/
2282 for (i = 0; i < m->natom; i++)
2283 {
2284 for (j = 0; j < number_of_elements && g_strcmp0(e[j].name, m->elem[i].name) != 0; j++); /*searching for correct element*/
2285 m->elem[i].color[0] = e[j].color[0];
2286 m->elem[i].color[1] = e[j].color[1];
2287 m->elem[i].color[2] = e[j].color[2];
2288 m->elem[i].color[3] = e[j].color[3];
2289 m->elem[i].vdw_rad = e[j].vdw_rad;
2290 m->elem[i].bond_rad = e[j].bond_rad;
2291 m->elem[i].valency = e[j].valency;
2292 }
2293
2294 if (response == GTK_RESPONSE_ACCEPT) save_atom_data();
2295 }
2296 if (GTK_IS_WIDGET(dialog)) gtk_widget_destroy(dialog);
2297
2298 /*free temporary storage*/
2299
2300 for(i = 0; i < number_of_elements; i++) g_free(tmp_elem[i].name);
2301 g_free(tmp_elem);
2302 rerender_3d();
2303 redraw();
2304 }
2305
luscus_gtk_make_periodic_system1(ELEM_DATA * tmp_e)2306 GtkWidget *luscus_gtk_make_periodic_system1(ELEM_DATA* tmp_e)
2307 {
2308 GtkWidget *table;
2309 GtkWidget *button;
2310 gint i;
2311 gint maxr = 0, maxc = 0;
2312
2313 for(i = 1; i < number_of_elements; i++)
2314 {
2315 if (e[i].periodic_pos_x > maxc) maxc = e[i].periodic_pos_x;
2316 if (e[i].periodic_pos_y > maxr) maxr = e[i].periodic_pos_y;
2317 }
2318
2319 table = gtk_table_new(maxr + 1, maxc + 1, TRUE);
2320
2321 for(i = 1; i < number_of_elements; i++)
2322 {
2323 button = gtk_button_new_with_label(e[i].name);
2324 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_atom_prop_select_element), (gpointer) GINT_TO_POINTER(i));
2325 gtk_table_attach(GTK_TABLE(table), button, e[i].periodic_pos_x, e[i].periodic_pos_x+1, e[i].periodic_pos_y, e[i].periodic_pos_y+1, GTK_FILL, GTK_FILL, 0, 0);
2326 gtk_widget_show(button);
2327 }
2328 gtk_widget_show(table);
2329
2330 return table;
2331 }
2332
callback_change_automatic_bonding(GtkWidget * widget,gpointer data)2333 void callback_change_automatic_bonding(GtkWidget *widget, gpointer data)
2334 {
2335 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
2336 {
2337 Input_Data.automatic_rebonding = 1;
2338 rebond();
2339 rerender_3d();
2340 redraw();
2341 }
2342 else
2343 Input_Data.automatic_rebonding = 0;
2344 }
2345
luscus_gtk_atom_prop_select_element(GtkWidget * widget,gpointer data)2346 void luscus_gtk_atom_prop_select_element(GtkWidget *widget, gpointer data)
2347 {
2348 gint iatom = GPOINTER_TO_INT(data);
2349 GdkColor color;
2350 elem_selected = iatom; /*atoms are numbered according to the numeration in the atoms.c -> H is #1*/
2351
2352 color_t_2_GdkColor(&color, tmp_elem[iatom].color);
2353
2354 gtk_label_set_label(GTK_LABEL(atom_prop_label), tmp_elem[iatom].name);
2355 gtk_color_button_set_color(GTK_COLOR_BUTTON(atom_prop_color_button), &color);
2356 gtk_spin_button_set_value(GTK_SPIN_BUTTON(atom_prop_atom_size_spin), tmp_elem[iatom].vdw_rad);
2357 gtk_spin_button_set_value(GTK_SPIN_BUTTON(atom_prop_bond_size_spin), tmp_elem[iatom].bond_rad);
2358 gtk_spin_button_set_value(GTK_SPIN_BUTTON(atom_prop_atom_valency_spin), tmp_elem[iatom].valency);
2359
2360 }
2361
atom_prop_atom_size_spin_callback(GtkWidget * spin,gpointer data)2362 void atom_prop_atom_size_spin_callback(GtkWidget *spin, gpointer data)
2363 {
2364 tmp_elem[elem_selected].vdw_rad = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
2365 }
2366
atom_prop_bond_size_spin_callback(GtkWidget * spin,gpointer data)2367 void atom_prop_bond_size_spin_callback(GtkWidget *spin, gpointer data)
2368 {
2369 tmp_elem[elem_selected].bond_rad = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
2370 }
2371
atom_prop_atom_valency_spin_callback(GtkWidget * spin,gpointer data)2372 void atom_prop_atom_valency_spin_callback(GtkWidget *spin, gpointer data)
2373 {
2374 tmp_elem[elem_selected].valency = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
2375 }
2376
callback_save_settings(GtkWidget * widget,gpointer data)2377 void callback_save_settings(GtkWidget *widget, gpointer data)
2378 {
2379 save_settings_data();
2380 }
2381
callback_move_light(GtkWidget * checkmenu,gpointer data)2382 void callback_move_light(GtkWidget *checkmenu, gpointer data)
2383 {
2384 luscus_gtk_move_light_state();
2385 }
2386
callback_create_viewpoint(GtkWidget * widget,gpointer data)2387 void callback_create_viewpoint(GtkWidget *widget, gpointer data)
2388 {
2389 ViewPoint(0);
2390 }
2391
callback_restore_viewpoint(GtkWidget * widget,gpointer data)2392 void callback_restore_viewpoint(GtkWidget *widget, gpointer data)
2393 {
2394 ViewPoint(1);
2395 }
2396
callback_grayscale(GtkWidget * checkmenu,gpointer data)2397 void callback_grayscale(GtkWidget *checkmenu, gpointer data)
2398 {
2399 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkmenu))) Input_Data.bw = 1;
2400 else Input_Data.bw = 0;
2401 rerender_3d();
2402 redraw();
2403 }
2404
callback_animate(GtkWidget * menuitem,gpointer data)2405 void callback_animate(GtkWidget *menuitem, gpointer data)
2406 {
2407 if (Input_Data.animate)
2408 {
2409 Input_Data.animate = FALSE;
2410 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_SMALL_TOOLBAR));
2411 gtk_menu_item_set_label(GTK_MENU_ITEM(menuitem), "Animate");
2412 }
2413 else
2414 {
2415 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), gtk_image_new_from_stock(GTK_STOCK_MEDIA_STOP, GTK_ICON_SIZE_SMALL_TOOLBAR));
2416 gtk_menu_item_set_label(GTK_MENU_ITEM(menuitem), "Stop animation");
2417 Input_Data.animate = TRUE;
2418 luscus_gtk_start_animation(0);
2419 }
2420 redraw();
2421 }
2422
luscus_gtk_start_animation(int i)2423 void luscus_gtk_start_animation(int i)
2424 {
2425 g_timeout_add((guint) (1000.0 * Input_Data.snapshot_delay), luscus_start_animation1, NULL);
2426 }
2427
luscus_start_animation1(gpointer data)2428 gboolean luscus_start_animation1(gpointer data)
2429 {
2430 animate(0);
2431 if (Input_Data.animate) return TRUE;
2432 else return FALSE;
2433 }
2434
luscus_gtk_show_atoms(GtkWidget * menu_item,gpointer data)2435 void luscus_gtk_show_atoms(GtkWidget* menu_item, gpointer data)
2436 {
2437 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item))) Input_Data.hide_atoms = 0;
2438 else Input_Data.hide_atoms = 1;
2439 rerender_3d();
2440 redraw();
2441 }
2442
luscus_gtk_show_bonds(GtkWidget * menu_item,gpointer data)2443 void luscus_gtk_show_bonds(GtkWidget* menu_item, gpointer data)
2444 {
2445 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item))) Input_Data.hide_bonds = 0;
2446 else Input_Data.hide_bonds = 1;
2447 rerender_3d();
2448 redraw();
2449 }
2450
luscus_gtk_show_axes(GtkWidget * menu_item,gpointer data)2451 void luscus_gtk_show_axes(GtkWidget* menu_item, gpointer data)
2452 {
2453 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item))) Input_Data.show_axis = 1;
2454 else Input_Data.show_axis = 0;
2455 rerender_3d();
2456 redraw();
2457 }
2458
luscus_gtk_callback_show_dot_line(GtkWidget * menu_item,gpointer data)2459 void luscus_gtk_callback_show_dot_line(GtkWidget* menu_item, gpointer data)
2460 {
2461 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item))) Input_Data.style_atoms = 1;
2462 else Input_Data.style_atoms = 0;
2463 rerender_3d();
2464 redraw();
2465 }
2466
luscus_gtk_show_labels(GtkWidget * widget,gpointer data)2467 void luscus_gtk_show_labels(GtkWidget* widget, gpointer data)
2468 {
2469 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 0;
2470 else Input_Data.label_atoms &= ~(1 << 0);
2471 redraw();
2472 }
2473
luscus_gtk_show_indices(GtkWidget * widget,gpointer data)2474 void luscus_gtk_show_indices(GtkWidget* widget, gpointer data)
2475 {
2476 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 1;
2477 else Input_Data.label_atoms &= ~(1 << 1);
2478 redraw();
2479 }
2480
luscus_gtk_show_numeration(GtkWidget * widget,gpointer data)2481 void luscus_gtk_show_numeration(GtkWidget* widget, gpointer data)
2482 {
2483 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 2;
2484 else Input_Data.label_atoms &= ~(1 << 2);
2485 redraw();
2486 }
2487
luscus_gtk_show_symbols(GtkWidget * widget,gpointer data)2488 void luscus_gtk_show_symbols(GtkWidget* widget, gpointer data)
2489 {
2490 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 3;
2491 else Input_Data.label_atoms &= ~(1 << 3);
2492 redraw();
2493 }
2494
luscus_gtk_show_names(GtkWidget * widget,gpointer data)2495 void luscus_gtk_show_names(GtkWidget* widget, gpointer data)
2496 {
2497 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 4;
2498 else Input_Data.label_atoms &= ~(1 << 4);
2499 redraw();
2500 }
2501
luscus_gtk_show_mulliken(GtkWidget * widget,gpointer data)2502 void luscus_gtk_show_mulliken(GtkWidget* widget, gpointer data)
2503 {
2504 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 5;
2505 else Input_Data.label_atoms &= ~(1 << 5);
2506 redraw();
2507 }
2508
luscus_gtk_show_loprop(GtkWidget * widget,gpointer data)2509 void luscus_gtk_show_loprop(GtkWidget* widget, gpointer data)
2510 {
2511 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) Input_Data.label_atoms |= 1 << 6;
2512 else Input_Data.label_atoms &= ~(1 << 6);
2513 redraw();
2514 }
2515
do_screenshot(int out)2516 void do_screenshot(int out)
2517 {
2518 gchar *newfilename = NULL;
2519 int ifile = 0;
2520
2521 /* newfilename = nextfname();*/
2522 do
2523 {
2524 printf("G_FREE(newfilename)0\n"); fflush(stdout);
2525 g_free(newfilename);
2526 if (out == 0) newfilename = g_strdup_printf("new_file_%.3d.tga", ifile);
2527 else if (out == 1) newfilename = g_strdup_printf("new_file_%.3d.eps", ifile);
2528 else if (out == 2) newfilename = g_strdup_printf("new_file_%.3d.eps", ifile);
2529 else if (out == 3) newfilename = g_strdup_printf("new_file_%.3d.pov", ifile);
2530 ifile++;
2531 } while(get_file_exist(newfilename) && ifile < 1000);
2532
2533 luscus_gtk_push_message_to_statusbar2("screenshot done");
2534
2535 if (out == 0) /*luscus_save_builtin_graphic_format(newfilename, "tga", Input_Data.init_screen_size, Input_Data.init_screen_size);*/ tgaSave(newfilename, Input_Data.init_screen_size, Input_Data.init_screen_size);
2536 else if (out == 1) initPS(0, newfilename);
2537 else if (out == 2) initPS(1, newfilename);
2538 else if (out == 3) initPovray(newfilename);
2539
2540 printf("G_FREE(newfilename)1\n"); fflush(stdout);
2541 g_free(newfilename);
2542 }
2543
callback_screenshot(GtkWidget * widget,gpointer data)2544 void callback_screenshot(GtkWidget *widget, gpointer data)
2545 {
2546 GtkWidget *dialog;
2547 GtkWidget *combo;
2548 GtkWidget *hbox, *vbox, *ihbox;
2549 GtkWidget *label;
2550 GtkWidget *spin_button;
2551 #ifdef GTK_GLEXT
2552 #ifdef GTK2
2553 GtkObject *adj_w, *adj_h;
2554 #elif GTK3
2555 GtkAdjustment *adj_w, *adj_h;
2556 #endif
2557 #else
2558 GdkWindow *wind;
2559 GdkPixbuf *pixbuf;
2560 GtkAllocation allocation;
2561 #endif
2562 gint result;
2563 gchar *filename;
2564 gint num_file_saved;
2565 gint width, height;
2566
2567 /* ----- check writable formats ----- */
2568
2569 GSList *formats = gdk_pixbuf_get_formats();
2570 GSList *writable_formats = NULL;
2571 GSList *lwritable_formats = NULL;
2572 GdkPixbufFormat *gpixformtmp;
2573
2574 g_slist_foreach(formats, (GFunc) luscus_check_writable_pic_files, &writable_formats);
2575 g_slist_free(formats);
2576
2577 lwritable_formats = writable_formats;
2578
2579 /*-----------------------------------*/
2580
2581 /* ----- check screen size ----- */
2582
2583 gv_gtk_get_screen_size(&width, &height);
2584
2585 /* ----------------------------- */
2586
2587 /*adj_w, *adj_h;*/
2588 #ifdef GTK_GLEXT
2589 adj_w = gtk_adjustment_new((gdouble) width, 600.0, 4000.0, 1.0, 10.0, 0.0);
2590 adj_h = gtk_adjustment_new((gdouble) height, 600.0, 4000.0, 1.0, 10.0, 0.0);
2591 #else
2592 /*GET PIXBUF BEFORE THE DIALOG IS INITIATED*/
2593 wind = gtk_widget_get_window(drawingarea);
2594 gtk_widget_get_allocation(drawingarea, &allocation);
2595 width = allocation.width;
2596 height = allocation.height;
2597 #ifdef GTK2
2598 pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(wind), NULL, 0, 0, 0, 0, width, height);
2599 #endif
2600 #ifdef GTK3
2601 pixbuf = gdk_pixbuf_get_from_window(wind, 0, 0, width, height);
2602 #endif
2603 #endif
2604
2605 dialog = gtk_file_chooser_dialog_new("Save screenshot image", NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
2606 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
2607
2608 /* luscus_set_filename(NULL, dialog);*/
2609 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), FALSE);
2610
2611 #ifdef GTK2
2612 hbox = gtk_hbox_new(FALSE, 0);
2613 #endif
2614 #ifdef GTK3
2615 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2616 gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
2617 #endif
2618
2619 #ifdef GTK_GLEXT
2620 #ifdef GTK2
2621 vbox = gtk_vbox_new(FALSE, 0);
2622 #endif
2623 #ifdef GTK3
2624 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2625 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE);
2626 #endif
2627 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
2628
2629 #ifdef GTK2
2630 ihbox = gtk_hbox_new(FALSE, 0);
2631 #endif
2632 #ifdef GTK3
2633 ihbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2634 gtk_box_set_homogeneous(GTK_BOX(ihbox), FALSE);
2635 #endif
2636 gtk_box_pack_start(GTK_BOX(vbox), ihbox, FALSE, FALSE, 0);
2637
2638 label = gtk_label_new("Width:");
2639 gtk_box_pack_start(GTK_BOX(ihbox), label, FALSE, FALSE, 0);
2640 gtk_widget_show(label);
2641
2642 #ifdef GTK2
2643 spin_button = gtk_spin_button_new(GTK_ADJUSTMENT(adj_w), 1.0, 0);
2644 #elif GTK3
2645 spin_button = gtk_spin_button_new(adj_w, 1.0, 0);
2646 #endif
2647 gtk_box_pack_start(GTK_BOX(ihbox), spin_button, FALSE, FALSE, 0);
2648 gtk_widget_show(spin_button);
2649
2650 gtk_widget_show(ihbox);
2651
2652
2653 #ifdef GTK2
2654 ihbox = gtk_hbox_new(FALSE, 0);
2655 #endif
2656 #ifdef GTK3
2657 ihbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2658 gtk_box_set_homogeneous(GTK_BOX(ihbox), FALSE);
2659 #endif
2660
2661 gtk_box_pack_start(GTK_BOX(vbox), ihbox, FALSE, FALSE, 0);
2662
2663 label = gtk_label_new("Height:");
2664 gtk_box_pack_start(GTK_BOX(ihbox), label, FALSE, FALSE, 0);
2665 gtk_widget_show(label);
2666
2667 #ifdef GTK2
2668 spin_button = gtk_spin_button_new(GTK_ADJUSTMENT(adj_h), 1.0, 0);
2669 #elif GTK3
2670 spin_button = gtk_spin_button_new(adj_h, 1.0, 0);
2671 #endif
2672 gtk_box_pack_start(GTK_BOX(ihbox), spin_button, FALSE, FALSE, 0);
2673 gtk_widget_show(spin_button);
2674
2675
2676 label = gtk_label_new("pixels");
2677 gtk_box_pack_start(GTK_BOX(ihbox), label, FALSE, FALSE, 0);
2678 gtk_widget_show(label);
2679
2680 gtk_widget_show(ihbox);
2681
2682 gtk_widget_show(vbox);
2683 #endif
2684
2685 #ifdef GTK_OLD
2686 combo = gtk_combo_box_new_text();
2687 #else
2688 combo = gtk_combo_box_text_new_with_entry();
2689 #endif
2690 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0);
2691
2692 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), FALSE);
2693 gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), hbox);
2694 gtk_widget_show(hbox);
2695 gtk_widget_show(combo);
2696 #ifdef GTK_OLD
2697 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "TarGA (*.tga)");
2698 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "postscript (*.eps)");
2699 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "postscript level 2 (*.eps)");
2700 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "povray (*.pov)");
2701 while(lwritable_formats)
2702 {
2703 gpixformtmp = lwritable_formats->data;
2704 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), gdk_pixbuf_format_get_description(gpixformtmp));
2705 lwritable_formats = lwritable_formats->next;
2706 }
2707 #else
2708 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "TarGA (*.tga)");
2709 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "postscript (*.eps)");
2710 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "postscript level 2 (*.eps)");
2711 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "povray (*.pov)");
2712 while(lwritable_formats)
2713 {
2714 gpixformtmp = lwritable_formats->data;
2715 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), gdk_pixbuf_format_get_description(gpixformtmp));
2716 lwritable_formats = lwritable_formats->next;
2717 }
2718 #endif
2719
2720 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
2721
2722 /* gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fname);*/
2723
2724 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "./");
2725 /* luscus_set_filename(combo, dialog);*/
2726 /* g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(luscus_set_filename), (gpointer) dialog);*/
2727 /*-----------------ERROR CALLING LUSCUS_SET_FILENAME-----------SEGMENTATION FAULT!!!-------------*/
2728
2729 result = gtk_dialog_run(GTK_DIALOG(dialog));
2730
2731 if(result == GTK_RESPONSE_ACCEPT)
2732 {
2733
2734 #ifdef GTK_GLEXT
2735 width = (gint) gtk_adjustment_get_value(GTK_ADJUSTMENT(adj_w));
2736 height = (gint) gtk_adjustment_get_value(GTK_ADJUSTMENT(adj_h));
2737 #endif
2738
2739 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
2740 #ifdef EBUG
2741 printf("filename = |%s|\n", filename); fflush(stdout);
2742 #endif
2743 num_file_saved = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
2744
2745 if (num_file_saved > 3)
2746 {
2747 lwritable_formats = writable_formats;
2748 while(lwritable_formats)
2749 {
2750 gpixformtmp = lwritable_formats->data;
2751 /*gtk_combo_box_get_active_text has been deprecated since version 2.24 ... see manual...*/
2752 #ifdef GTK2
2753 #ifdef GTK_OLD
2754 if (g_strcmp0(gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)), gdk_pixbuf_format_get_description(gpixformtmp)) == 0)
2755 #else
2756 if (g_strcmp0(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo)), gdk_pixbuf_format_get_description(gpixformtmp)) == 0)
2757 #endif
2758 #endif
2759 #ifdef GTK3
2760 if (g_strcmp0(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo)), gdk_pixbuf_format_get_description(gpixformtmp)) == 0)
2761 #endif
2762 {
2763 gtk_widget_destroy(dialog);
2764 dialog = NULL;
2765 #ifdef GTK_GLEXT
2766 luscus_save_builtin_graphic_format(filename, gdk_pixbuf_format_get_name(gpixformtmp), width, height);
2767 #else
2768 luscus_save_builtin_graphic_format(filename, gdk_pixbuf_format_get_name(gpixformtmp), pixbuf, width, height);
2769 #endif
2770 break;
2771 }
2772 lwritable_formats = lwritable_formats->next;
2773 }
2774
2775 /*pronadji dodatne formate file-ova!*/
2776
2777 }
2778 else
2779 {
2780 switch(num_file_saved)
2781 {
2782 case SCSHOT_TGA:
2783 gtk_widget_destroy(dialog);
2784 dialog = NULL;
2785 #ifdef GTK_GLEXT
2786 luscus_save_builtin_graphic_format(filename, "tga", width, height);/*tgaSave(filename);*/ break;
2787 #else
2788 luscus_save_builtin_graphic_format(filename, "tga", pixbuf, width, height); break;
2789 #endif
2790 case SCSHOT_PS: initPS(0, filename); break;
2791 case SCSHOT_PS2: initPS(1, filename); break;
2792 case SCSHOT_POV: initPovray(filename); break;
2793 #ifdef GTK_GLEXT
2794 luscus_save_builtin_graphic_format(filename, "tga", width, height);/*tgaSave(filename);*/ break;
2795 #else
2796 luscus_save_builtin_graphic_format(filename, "tga", pixbuf, width, height); break;
2797 #endif
2798 }
2799 }
2800 g_free(filename);
2801 }
2802 g_slist_free(writable_formats);
2803 #ifndef GTK_GLEXT
2804 g_object_unref(G_OBJECT(pixbuf));
2805 #endif
2806 if (dialog && GTK_IS_WIDGET(dialog)) gtk_widget_destroy(dialog);
2807 }
2808
luscus_set_filename(GtkWidget * combo,GtkWidget * dialog)2809 void luscus_set_filename(GtkWidget *combo, GtkWidget *dialog)
2810 {
2811 gchar *fname = NULL;
2812 int ifile = 0;
2813 gint num_file_saved; /*i-th screenshot file format*/
2814
2815 GSList *formats = gdk_pixbuf_get_formats();
2816 GSList *writable_formats = NULL;
2817 GSList *lwritable_formats = NULL;
2818 GdkPixbufFormat *gpixformtmp;
2819
2820 num_file_saved = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
2821
2822 /* newfilename = nextfname();*/
2823 do
2824 {
2825 printf("_FREE(FNAME)\n"); fflush(stdout);
2826 g_free(fname);
2827 fname = g_strdup_printf("new_file_%.3d", ifile);
2828 printf("num_file_saved = %d\n", num_file_saved); fflush(stdout);
2829
2830 if(num_file_saved > 3)
2831 {
2832
2833 /* find out extension here! */
2834
2835 g_slist_foreach(formats, (GFunc) luscus_check_writable_pic_files, &writable_formats);
2836 /* g_slist_free(formats);*/
2837
2838 lwritable_formats = writable_formats;
2839
2840 while(lwritable_formats)
2841 {
2842 gpixformtmp = lwritable_formats->data;
2843 /*gtk_combo_box_get_active_text has been deprecated since version 2.24 ... see manual...*/
2844 #ifdef GTK_OLD
2845 if (g_strcmp0(gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)), gdk_pixbuf_format_get_description(gpixformtmp)) == 0)
2846 #else
2847 if (g_strcmp0(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo)), gdk_pixbuf_format_get_description(gpixformtmp)) == 0)
2848 #endif
2849 {
2850 fname = g_strconcat(fname, ".", gdk_pixbuf_format_get_name(gpixformtmp), NULL);
2851 break;
2852 }
2853 lwritable_formats = lwritable_formats->next;
2854 }
2855
2856 g_slist_free(writable_formats);
2857 }
2858 else
2859 {
2860 switch(num_file_saved)
2861 {
2862 case SCSHOT_TGA:
2863 fname = g_strconcat(fname, ".tga", NULL);
2864 break;
2865 case SCSHOT_PS:
2866 fname = g_strconcat(fname, ".eps", NULL);
2867 break;
2868 case SCSHOT_PS2:
2869 fname = g_strconcat(fname, ".eps", NULL);
2870 break;
2871 case SCSHOT_POV:
2872 fname = g_strconcat(fname, ".pov", NULL);
2873 break;
2874 default:
2875 fname = g_strconcat(fname, ".tga", NULL);
2876 }
2877 }
2878 printf("checking file |%s|\n", fname); fflush(stdout);
2879
2880 ifile++;
2881 } while(get_file_exist(fname) && ifile < 1000);
2882
2883 g_slist_free(formats);
2884
2885 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fname);
2886 printf("last fname = |%s|\n", fname); fflush(stdout);
2887 }
2888
luscus_gtk_goto_freq(GtkWidget * widget,gpointer data)2889 void luscus_gtk_goto_freq(GtkWidget *widget, gpointer data)
2890 {
2891 gint tvib = GPOINTER_TO_INT(data);
2892 ivib = tvib;
2893 set_current_graph_data();
2894 redraw();
2895 }
2896
set_calculation(gchar ** gargv,gchar * calc_filename,gchar * path)2897 void set_calculation(gchar** gargv, gchar *calc_filename, gchar *path)
2898 {
2899 GError *gerror = NULL;
2900 GPid gpid;
2901 gboolean ret;
2902 #ifdef EBUG
2903 printf("EXECUTING CALCULATION\n");
2904 {
2905 int i = 0;
2906 while(gargv[i]) printf("argument #%d = |%s|\n", i, gargv[i++]);
2907 }
2908 #endif
2909
2910 ret = g_spawn_async(path, gargv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &gpid, &gerror);
2911
2912 if (!ret)
2913 {
2914 make_warning(gerror->message);
2915 return;
2916 }
2917 else calc_alive = 1;
2918
2919 /*6. close current file*/
2920 close_file();
2921
2922 /*7. open file under calculation*/
2923 open_file(calc_filename, NULL);
2924
2925 calc_timer = g_timeout_add(1000, (GSourceFunc) luscus_check_if_calc_runs, (gpointer) calc_filename); /*watch the file every second*/
2926 g_child_watch_add(gpid, (GChildWatchFunc) luscus_calculation_over, NULL);
2927
2928 luscus_gtk_pop_message_from_statusbar2();
2929 luscus_gtk_push_message_to_statusbar2("Calculation started...");
2930 }
2931
luscus_check_if_calc_runs(char * calc_filename)2932 gboolean luscus_check_if_calc_runs(char *calc_filename)
2933 {
2934 #ifdef EBUG
2935 printf("DEBUG: checking calculation! file: |%s|\n", calc_filename); fflush(stdout);
2936 #endif
2937 check_if_file_changed();
2938 if (calc_alive)
2939 {
2940 luscus_gtk_pop_message_from_statusbar2();
2941 luscus_gtk_push_message_to_statusbar2("Calculation running...");
2942 return TRUE; /*continue the timer*/
2943 }
2944 else
2945 {
2946 g_free(calc_filename);
2947 luscus_gtk_pop_message_from_statusbar2();
2948 luscus_gtk_push_message_to_statusbar2("Calculation completed");
2949 return FALSE; /*break the timer*/
2950 }
2951 }
2952
luscus_calculation_over(GPid gpid,gint status,gpointer data)2953 void luscus_calculation_over(GPid gpid, gint status, gpointer data)
2954 {
2955 #ifdef EBUG
2956 printf("DEBUG: calculation DONE!\n");fflush(stdout);
2957 #endif
2958 calc_alive = 0;
2959 g_spawn_close_pid(gpid);
2960 }
2961
luscus_gtk_key_press(GtkWidget * da,GdkEventKey * event,gpointer data)2962 gboolean luscus_gtk_key_press(GtkWidget *da, GdkEventKey *event, gpointer data)
2963 {
2964 gint i;
2965 gint x, y;
2966 GdkModifierType mask;
2967
2968 if (textbox_state == 1) return TRUE;
2969 if (textbox_state == 2)
2970 {
2971 switch(event->keyval)
2972 {
2973 #ifdef GTK_OLD
2974 case GDK_BackSpace:
2975 #else
2976 case GDK_KEY_BackSpace:
2977 #endif
2978 textbox_delete_last_char(m);
2979 draw_pixdata_textbox(m->ntextboxes-1);
2980 break;
2981
2982 #ifdef GTK_OLD
2983 case GDK_Escape:
2984 #else
2985 case GDK_KEY_Escape:
2986 #endif
2987 delete_last_textbox(m);
2988
2989 #ifdef GTK_OLD
2990 case 10:
2991 case GDK_KP_Enter:
2992 case GDK_ISO_Enter:
2993 case GDK_3270_Enter:
2994 case GDK_RockerEnter:
2995 case GDK_Return:
2996 #else
2997 case 10:
2998 case GDK_KEY_KP_Enter:
2999 case GDK_KEY_ISO_Enter:
3000 case GDK_KEY_3270_Enter:
3001 case GDK_KEY_RockerEnter:
3002 case GDK_KEY_Return:
3003 #endif
3004 textbox_state = 0;
3005 luscus_set_cursor_default();
3006 luscus_gtk_update_3Dobject_info();
3007 append_backup();
3008 break;
3009 #ifdef GTK_OLD /*fix characters from numerical keyboard 2014.01.30*/
3010 case GDK_KP_0:
3011 #else
3012 case GDK_KEY_KP_0:
3013 #endif
3014 textbox_delete_insert_char(m, '0');
3015 break;
3016 #ifdef GTK_OLD
3017 case GDK_KP_1:
3018 #else
3019 case GDK_KEY_KP_1:
3020 #endif
3021 textbox_delete_insert_char(m, '1');
3022 break;
3023 #ifdef GTK_OLD
3024 case GDK_KP_2:
3025 #else
3026 case GDK_KEY_KP_2:
3027 #endif
3028 textbox_delete_insert_char(m, '2');
3029 break;
3030 #ifdef GTK_OLD
3031 case GDK_KP_3:
3032 #else
3033 case GDK_KEY_KP_3:
3034 #endif
3035 textbox_delete_insert_char(m, '3');
3036 break;
3037 #ifdef GTK_OLD
3038 case GDK_KP_4:
3039 #else
3040 case GDK_KEY_KP_4:
3041 #endif
3042 textbox_delete_insert_char(m, '4');
3043 break;
3044 #ifdef GTK_OLD
3045 case GDK_KP_5:
3046 #else
3047 case GDK_KEY_KP_5:
3048 #endif
3049 textbox_delete_insert_char(m, '5');
3050 break;
3051 #ifdef GTK_OLD
3052 case GDK_KP_6:
3053 #else
3054 case GDK_KEY_KP_6:
3055 #endif
3056 textbox_delete_insert_char(m, '6');
3057 break;
3058 #ifdef GTK_OLD
3059 case GDK_KP_7:
3060 #else
3061 case GDK_KEY_KP_7:
3062 #endif
3063 textbox_delete_insert_char(m, '7');
3064 break;
3065 #ifdef GTK_OLD
3066 case GDK_KP_8:
3067 #else
3068 case GDK_KEY_KP_8:
3069 #endif
3070 textbox_delete_insert_char(m, '8');
3071 break;
3072 #ifdef GTK_OLD
3073 case GDK_KP_9:
3074 #else
3075 case GDK_KEY_KP_9:
3076 #endif
3077 textbox_delete_insert_char(m, '9');
3078 break;
3079 #ifdef GTK_OLD
3080 case GDK_KP_Add:
3081 #else
3082 case GDK_KEY_KP_Add:
3083 #endif
3084 textbox_delete_insert_char(m, '+');
3085 break;
3086 #ifdef GTK_OLD
3087 case GDK_KP_Subtract:
3088 #else
3089 case GDK_KEY_KP_Subtract:
3090 #endif
3091 textbox_delete_insert_char(m, '-');
3092 break;
3093 #ifdef GTK_OLD
3094 case GDK_KP_Divide:
3095 #else
3096 case GDK_KEY_KP_Divide:
3097 #endif
3098 textbox_delete_insert_char(m, '/');
3099 break;
3100 #ifdef GTK_OLD
3101 case GDK_KP_Multiply:
3102 #else
3103 case GDK_KEY_KP_Multiply:
3104 #endif
3105 textbox_delete_insert_char(m, '*');
3106 break;
3107 #ifdef GTK_OLD
3108 case GDK_KP_Decimal:
3109 #else
3110 case GDK_KEY_KP_Decimal:
3111 #endif
3112 textbox_delete_insert_char(m, '.');
3113 break;
3114 default:
3115 if (event->keyval > 31 && event->keyval < 127)
3116 textbox_delete_insert_char(m, event->keyval);
3117 }
3118 draw_pixdata_textbox(m->ntextboxes-1);
3119 redraw();
3120 return TRUE;
3121 }
3122
3123 #ifdef GTK_OLD
3124 if (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R)
3125 #else
3126 if (event->keyval == GDK_KEY_Control_L || event->keyval == GDK_KEY_Control_R)
3127 #endif
3128 {
3129 control_pressed = 1;
3130 return TRUE;
3131 }
3132 if (control_pressed)
3133 {
3134 if (event->keyval == 'o') callback_open_file(NULL, NULL);
3135 else if (event->keyval == 'q') Kill_Gui();
3136 else if (event->keyval == 'h') luscus_gtk_callback_help(NULL, NULL);
3137 return TRUE;
3138 }
3139
3140 if (!accept_keys) return FALSE;
3141 #ifdef GTK2
3142 gdk_window_get_pointer(event->window, &x, &y, &mask);
3143 #endif
3144 #ifdef GTK3
3145 mask=event->state;
3146 /* gdk_window_get_device_position(event->window, gtk_get_current_event_device(), &x, &y, &mask);*/
3147 #endif
3148
3149 #ifdef GTK_OLD
3150 if (m->natom+m->nsphere+m->nvector+m->ntriangle+m->nsurf+m->ncells == 0 && (event->keyval != GDK_F1 && event->keyval != GDK_F9)) return TRUE;
3151 #else
3152 if (m->natom+m->nsphere+m->nvector+m->ntriangle+m->nsurf+m->ncells == 0 && (event->keyval != GDK_KEY_F1 && event->keyval != GDK_KEY_F9))
3153 return TRUE;
3154 #endif
3155
3156 switch(event->keyval)
3157 {
3158 #ifdef GTK_OLD
3159 case GDK_F1:
3160 #else
3161 case GDK_KEY_F1:
3162 #endif
3163 luscus_gtk_callback_help(NULL, NULL);
3164 break;
3165 #ifdef GTK_OLD
3166 case GDK_F2:
3167 #else
3168 case GDK_KEY_F2:
3169 #endif
3170 callback_save_file(NULL, GINT_TO_POINTER(1));
3171 break;
3172
3173 #ifdef GTK_OLD
3174 case GDK_F3:
3175 #else
3176 case GDK_KEY_F3:
3177 #endif
3178 if (m->ngrids) luscus_gtk_show_multiorb_window();
3179 break;
3180
3181 #ifdef GTK_OLD
3182 case GDK_F5:
3183 #else
3184 case GDK_KEY_F5:
3185 #endif
3186 if (mask & GDK_SHIFT_MASK)
3187 do_screenshot(1);
3188 else
3189 do_screenshot(0);
3190 /* callback_screenshot(NULL, NULL);*/
3191 break;
3192
3193 #ifdef GTK_OLD
3194 case GDK_F6:
3195 #else
3196 case GDK_KEY_F6:
3197 #endif
3198 if (mask & GDK_SHIFT_MASK)
3199 remove_watched_coords();
3200 else
3201 add_watched_coord();
3202 break;
3203
3204 #ifdef GTK_OLD
3205 case GDK_F7:
3206 #else
3207 case GDK_KEY_F7:
3208 #endif
3209 mark_neighbor();
3210 rerender_3d();
3211 break;
3212
3213 #ifdef GTK_OLD
3214 case GDK_F8:
3215 #else
3216 case GDK_KEY_F8:
3217 #endif
3218 if(m->editable)
3219 {
3220 if (mask & GDK_SHIFT_MASK)
3221 luscus_gtk_set_vec_rot(2);
3222 else
3223 luscus_gtk_set_vec_rot(0);
3224 do_symmetry();
3225 }
3226 break;
3227
3228 #ifdef GTK_OLD
3229 case GDK_F9:
3230 #else
3231 case GDK_KEY_F9:
3232 #endif
3233 if (mask & GDK_SHIFT_MASK) callback_change_background(NULL, NULL);
3234 else save_settings_data();
3235 break;
3236
3237 #ifdef GTK_OLD
3238 case GDK_F10:
3239 #else
3240 case GDK_KEY_F10:
3241 #endif
3242 callback_save_file(NULL, 0);
3243 exit(0);
3244 break;
3245
3246 #ifdef GTK_OLD
3247 case GDK_Right:
3248 #else
3249 case GDK_KEY_Right:
3250 #endif
3251 /* if(m->editable)
3252 {*/
3253 if (mask & GDK_SHIFT_MASK) Do_key_lr(1, 1);
3254 else Do_key_lr(1, 0);
3255 /* }*/
3256 break;
3257
3258 #ifdef GTK_OLD
3259 case GDK_Left:
3260 #else
3261 case GDK_KEY_Left:
3262 #endif
3263 /* if(m->editable)
3264 {*/
3265 if (mask & GDK_SHIFT_MASK) Do_key_lr(0, 1);
3266 else Do_key_lr(0, 0);
3267 /* }*/
3268 break;
3269 #ifdef GTK_OLD
3270 case GDK_Up:
3271 #else
3272 case GDK_KEY_Up:
3273 #endif
3274 /* if(m->editable)
3275 {*/
3276 if (mask & GDK_SHIFT_MASK) Do_key_ud(1, 1);
3277 else Do_key_ud(1, 0);
3278 /* }*/
3279 break;
3280 #ifdef GTK_OLD
3281 case GDK_Down:
3282 #else
3283 case GDK_KEY_Down:
3284 #endif
3285 /* if(m->editable)
3286 {*/
3287 if (mask & GDK_SHIFT_MASK) Do_key_ud(0, 1);
3288 else Do_key_ud(0, 0);
3289 /* }*/
3290 break;
3291 #ifdef GTK_OLD
3292 case GDK_Page_Up:
3293 #else
3294 case GDK_KEY_Page_Up:
3295 #endif
3296 if(m->editable)
3297 {
3298 if (mask & GDK_SHIFT_MASK) do_key_page(1, 1);
3299 else do_key_page(1, 0);
3300 }
3301 break;
3302 #ifdef GTK_OLD
3303 case GDK_Page_Down:
3304 #else
3305 case GDK_KEY_Page_Down:
3306 #endif
3307 if(m->editable)
3308 {
3309 if (mask & GDK_SHIFT_MASK) do_key_page(0, 1);
3310 else do_key_page(0, 0);
3311 }
3312 break;
3313
3314 #ifdef GTK_OLD
3315 case GDK_F12:
3316 case GDK_Insert:
3317 #else
3318 case GDK_KEY_F12:
3319 case GDK_KEY_Insert:
3320 #endif
3321 if (m->editable)
3322 {
3323 if (m->n_selected == 0) add_fragment(get_last_fragment());
3324 else if (m->n_selected == 1)
3325 {
3326 if (mask & GDK_SHIFT_MASK) add_atoms(1);
3327 else /*add_atoms(0); */ add_fragment(get_last_fragment());
3328 }
3329 else if (m->n_selected == 2)
3330 {
3331 if (mask & GDK_SHIFT_MASK) add_atoms(1);
3332 else
3333 {
3334 i = find_bond(m, m->selected[0], m->selected[1]);
3335 if (i == -1) change_bond_type(1);
3336 else change_bond_type((m->bond[i].bond_type+1)%7);
3337 }
3338 }
3339 rerender_3d();
3340 }
3341 break;
3342
3343 #ifdef GTK_OLD
3344 case GDK_Home:
3345 #else
3346 case GDK_KEY_Home:
3347 #endif
3348 if (m->editable) set_origin_molecule();
3349 break;
3350
3351 #ifdef GTK_OLD
3352 case GDK_End:
3353 #else
3354 case GDK_KEY_End:
3355 #endif
3356 if (m->editable)
3357 {
3358 add_atoms(1);
3359 rerender_3d();
3360 }
3361 break;
3362
3363 #ifdef GTK_OLD
3364 case GDK_BackSpace:
3365 #else
3366 case GDK_KEY_BackSpace:
3367 #endif
3368 if (m->editable)
3369 {
3370 get_backup();
3371 rerender_3d();
3372 }
3373 break;
3374
3375 #ifdef GTK_OLD
3376 case GDK_Escape:
3377 #else
3378 case GDK_KEY_Escape:
3379 #endif
3380 remove_watched_coords();
3381
3382 if (m->editable)
3383 {
3384 deallocate_vectors(m);
3385 deallocate_triangles(m);
3386 deallocate_spheres(m);
3387 deallocate_surfaces(m);
3388 deallocate_cells(m);
3389 luscus_gtk_update_upon_select_or_mark();
3390 luscus_gtk_update_3Dobject_info();
3391 rerender_3d();
3392 }
3393 break;
3394
3395 #ifdef GTK_OLD
3396 case GDK_Delete:
3397 #else
3398 case GDK_KEY_Delete:
3399 #endif
3400
3401 if (m->editable)
3402 {
3403 if (m->n_selected == 1 || m->n_marked)
3404 delete_coord(0);
3405 /* delete_atom(m->selected[0]);*/
3406 else if (m->n_selected == 2)
3407 {
3408 i = find_bond(m, m->selected[0], m->selected[1]);
3409 printf("I = %d\n", i); fflush(stdout);
3410 if (i >= 0)
3411 if (m->bond[i].bond_type > 0)
3412 change_bond_type(m->bond[i].bond_type-1);
3413 } /*delete_grid should be included*/
3414 rerender_3d();
3415 }
3416 break;
3417
3418 case 't':
3419 if (mask & GDK_MOD1_MASK)
3420 Input_Data.electrostatic_poten_color[0][3] =
3421 Input_Data.electrostatic_poten_color[1][3] =
3422 Input_Data.neg_pos_color[0][3] = Input_Data.neg_pos_color[1][3] =
3423 Input_Data.extracolor[3] = 1.0;
3424 else
3425 {
3426 Input_Data.electrostatic_poten_color[0][3] += 0.1;
3427 Input_Data.electrostatic_poten_color[1][3] += 0.1;
3428 Input_Data.neg_pos_color[0][3] += 0.1;
3429 Input_Data.neg_pos_color[1][3] += 0.1;
3430 Input_Data.extracolor[3] += 0.1;
3431 }
3432
3433 if (Input_Data.extracolor[3] > 1.0)
3434 {
3435 Input_Data.electrostatic_poten_color[0][3] =
3436 Input_Data.electrostatic_poten_color[1][3] =
3437 Input_Data.neg_pos_color[0][3] = Input_Data.neg_pos_color[1][3] =
3438 Input_Data.extracolor[3] = 1.0;
3439 }
3440 rerender_3d();
3441 break;
3442
3443 case 'T':
3444 Input_Data.electrostatic_poten_color[0][3] -= 0.1;
3445 Input_Data.electrostatic_poten_color[1][3] -= 0.1;
3446 Input_Data.neg_pos_color[0][3] -= 0.1;
3447 Input_Data.neg_pos_color[1][3] -= 0.1;
3448 Input_Data.extracolor[3] -= 0.1;
3449
3450 if (Input_Data.extracolor[3] < 0.0)
3451 {
3452 Input_Data.electrostatic_poten_color[0][3] = 0.0;
3453 Input_Data.electrostatic_poten_color[1][3] = 0.0;
3454 Input_Data.neg_pos_color[0][3] = 0.0;
3455 Input_Data.neg_pos_color[1][3] = 0.0;
3456 Input_Data.extracolor[3] = 0.0;
3457 }
3458 rerender_3d();
3459 break;
3460
3461 case 'W':
3462 Input_Data.atomshape++;
3463 if(Input_Data.atomshape >3) Input_Data.atomshape=0;
3464 break;
3465
3466 case 'r':
3467 case 'g':
3468 case 'b':
3469 case 'U':
3470 case 'G':
3471 case 'B':
3472
3473 callback_change_background(NULL, NULL);
3474 break;
3475 case 'c':
3476 if (m->ishow & HAS_MULLIKEN)
3477 Input_Data.label_atoms &~ (1 << 5);
3478 else if (m->ishow & HAS_LOPROP)
3479 Input_Data.label_atoms &~ (1 << 6);
3480 break;
3481 case 'l':
3482 luscus_gtk_move_light_state();
3483 break;
3484 case 'm':
3485 Input_Data.animate=!Input_Data.animate;
3486 luscus_gtk_start_animation(0);
3487 break;
3488 case 'w':
3489 if (control_pressed) callback_close_file(NULL, NULL);
3490 else if(m->n_selected==1 && m->editable) add_fragment(0);
3491 else Input_Data.bw=!Input_Data.bw;
3492 rerender_3d();
3493 break;
3494 case 'x':
3495 callback_maximize(NULL, NULL);
3496 break;
3497 case 'p':
3498 do_screenshot(3);
3499 break;
3500 case 'P':
3501 do_screenshot(2);
3502 break;
3503 case 'A':
3504 if (m->nvibr)
3505 Input_Data.frequency_amplitude += 0.1;
3506 else
3507 {
3508 Input_Data.ntexture++;
3509 if(Input_Data.ntexture > 5 ) Input_Data.ntexture=0;
3510 }
3511 break;
3512 case 'I':
3513 if (m->editable)
3514 {
3515 do_key_insert();
3516 rerender_3d();
3517 }
3518 break;
3519 case 'a':
3520 if (m->nvibr) Input_Data.frequency_amplitude -= 0.1;
3521 else if (m->ngrids) change_orbital_type(ORBITAL_TYPE_2);
3522 else
3523 {
3524 mark_H();
3525 rerender_3d();
3526 }
3527 break;
3528 case 'f':
3529 if (m->ngrids) change_orbital_type(ORBITAL_TYPE_F);
3530 break;
3531 case 'i':
3532 if (m->ngrids) change_orbital_type(ORBITAL_TYPE_I);
3533 break;
3534 #ifdef GTK_OLD
3535 case GDK_KP_1:
3536 #else
3537 case GDK_KEY_KP_1:
3538 #endif
3539 case '1':
3540 if (m->ngrids) change_orbital_type(ORBITAL_TYPE_1);
3541 break;
3542 #ifdef GTK_OLD
3543 case GDK_KP_2:
3544 #else
3545 case GDK_KEY_KP_2:
3546 #endif
3547 case '2':
3548 if (m->ngrids) change_orbital_type(ORBITAL_TYPE_2);
3549 break;
3550 #ifdef GTK_OLD
3551 case GDK_KP_3:
3552 #else
3553 case GDK_KEY_KP_3:
3554 #endif
3555 case '3':
3556 if (m->n_selected == 3 && m->editable)
3557 {
3558 add_triangle_selected();
3559 luscus_gtk_update_upon_select_or_mark();
3560 luscus_gtk_update_3Dobject_info();
3561 rerender_3d();
3562 }
3563 else if (m->ngrids) change_orbital_type(ORBITAL_TYPE_3);
3564 break;
3565
3566 #ifdef GTK_OLD
3567 case GDK_KP_4:
3568 #else
3569 case GDK_KEY_KP_4:
3570 #endif
3571 case '4':
3572 if (m->n_selected == 3 && m->editable)
3573 {
3574 add_surface_selected();
3575 luscus_gtk_update_upon_select_or_mark();
3576 luscus_gtk_update_3Dobject_info();
3577 rerender_3d();
3578 }
3579 break;
3580
3581 #ifdef GTK_OLD
3582 case GDK_KP_6:
3583 #else
3584 case GDK_KEY_KP_6:
3585 #endif
3586 case '6':
3587 if (m->n_selected == 4 && m->editable)
3588 {
3589 add_cell_selected();
3590 luscus_gtk_update_upon_select_or_mark();
3591 luscus_gtk_update_3Dobject_info();
3592 rerender_3d();
3593 }
3594 break;
3595
3596 case 's':
3597 if (control_pressed) callback_save_file(NULL, (gpointer) 0);
3598 else if (m->ngrids) change_orbital_type(ORBITAL_TYPE_S);
3599 break;
3600
3601 case 'd':
3602 if (m->ngrids) change_orbital_type(ORBITAL_TYPE_D);
3603 break;
3604
3605 #ifdef GTK_OLD
3606 case GDK_plus:
3607 case GDK_KP_Add:
3608 #else
3609 case GDK_KEY_plus:
3610 case GDK_KEY_KP_Add:
3611 #endif
3612 printf("+\n");
3613 if (m->nvibr) Input_Data.frequency_speed += 0.1;
3614 else if (m->ngrids)
3615 {
3616 Input_Data.lev += 0.01;
3617 make_surfaces();
3618 rerender_3d();
3619 redraw();
3620 }
3621 else if (m->editable)
3622 {
3623 luscus_gtk_move_coord_step(1);
3624 rerender_3d();
3625 redraw();
3626 }
3627 break;
3628
3629 #ifdef GTK_OLD
3630 case GDK_minus:
3631 case GDK_KP_Subtract:
3632 #else
3633 case GDK_KEY_minus:
3634 case GDK_KEY_KP_Subtract:
3635 #endif
3636 printf("-\n");
3637 if (m->nvibr) Input_Data.frequency_speed -= 0.1;
3638 else if (m->ngrids)
3639 {
3640 Input_Data.lev -= 0.01;
3641 make_surfaces();
3642 rerender_3d();
3643 redraw();
3644 }
3645 else if (m->editable)
3646 {
3647 luscus_gtk_move_coord_step(-1);
3648 rerender_3d();
3649 redraw();
3650 }
3651 break;
3652 case 'q':
3653 if(get_number_of_slices() > 4) set_number_of_slices(get_number_of_slices() - 1);
3654 if(get_number_of_stacks() > 4) set_number_of_stacks(get_number_of_stacks() - 1);
3655 rerender_3d();
3656 break;
3657 case 'Q':
3658 if(get_number_of_slices() < 30) set_number_of_slices(get_number_of_slices() + 1);
3659 if(get_number_of_stacks() < 30) set_number_of_stacks(get_number_of_stacks() + 1);
3660 rerender_3d();
3661 break;
3662 case 'Z':
3663 change_scale(1);
3664 break;
3665 case 'z':
3666 change_scale(-1);
3667 break;
3668 case '*':
3669 reverse_marked();
3670 rerender_3d();
3671 break;
3672 case '#':
3673 renumber_marked();
3674 break;
3675 case ' ':
3676 if (m->n_selected) luscus_gtk_remove_selection(NULL, NULL);
3677 else if (m->n_marked) unmark_all();
3678 rerender_3d();
3679 break;
3680 case 'v':
3681 if(m->n_selected == 2)
3682 {
3683 if(get_vec_rot()==0)
3684 {
3685 luscus_gtk_set_vec_rot(2);
3686 luscus_gtk_pop_message_from_statusbar2();
3687 luscus_gtk_push_message_to_statusbar2("symmetry operation: rotation");
3688 }
3689 else
3690 {
3691 luscus_gtk_set_vec_rot(0);
3692 luscus_gtk_pop_message_from_statusbar2();
3693 luscus_gtk_push_message_to_statusbar2("symmetry operation: translation");
3694 }
3695 }
3696 else ViewPoint(0);
3697 break;
3698
3699 case 'V':
3700 ViewPoint(1);
3701 break;
3702 case 'k':
3703 /* doSlapafDump();*/ printf("doing slapaf dump\n");
3704 break;
3705 case 'K':
3706 /* doIndexDump();*/ printf("doing index dump\n");
3707 break;
3708 case '|':
3709 if (m->n_selected == 2 || m->n_selected == 3)
3710 {
3711 mark_one_side();
3712 rerender_3d();
3713 /* printf("mark one side!\n"); fflush(stdout);*/
3714 }
3715 break;
3716 default: return TRUE;
3717 }
3718 redraw();
3719
3720
3721 return TRUE;
3722 }
3723
luscus_gtk_key_release(GtkWidget * da,GdkEventKey * event,gpointer data)3724 gboolean luscus_gtk_key_release(GtkWidget *da, GdkEventKey *event, gpointer data)
3725 {
3726 if (!accept_keys) return FALSE;
3727 #ifdef GTK_OLD
3728 if(event->keyval == GDK_Control_L || event->keyval == GDK_Control_R)
3729 #else
3730 if(event->keyval == GDK_KEY_Control_L || event->keyval == GDK_KEY_Control_R)
3731 #endif
3732 control_pressed=0;
3733 return TRUE;
3734 }
3735