atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
atom_search.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'atom_search.c'
24*
25* Contains:
26*
27
28 - The functions to prepare the model edition 'search' tabs and the associated widgets
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void turn_rebuild_on (GtkCheckButton * but, gpointer data);
34 G_MODULE_EXPORT void turn_rebuild_on (GtkToggleButton * but, gpointer data);
35 G_MODULE_EXPORT void turn_bonding_on (GtkCheckButton * but, gpointer data);
36 G_MODULE_EXPORT void turn_bonding_on (GtkToggleButton * but, gpointer data);
37 G_MODULE_EXPORT void set_atoms_for_action (GtkComboBox * box, gpointer data);
38 G_MODULE_EXPORT void expanding_atoms (GtkWidget * exp, gpointer data);
39
40 GtkWidget * create_search_box (int aid, project * this_proj);
41 GtkWidget * create_action_combo (int id, project * this_proj);
42 GtkWidget * action_tab (int aid, project * this_proj);
43
44*/
45
46#include "atom_edit.h"
47
48#ifdef GTK4
57G_MODULE_EXPORT void turn_rebuild_on (GtkCheckButton * but, gpointer data)
58#else
67G_MODULE_EXPORT void turn_rebuild_on (GtkToggleButton * but, gpointer data)
68#endif
69{
70 tint * dat = (tint *) data;
71 int i;
72#ifdef GTK4
73 i = gtk_check_button_get_active (but);
74 get_project_by_id(dat -> a) -> modelgl -> rebuild[0][dat -> c] = i;
75#else
76 i = gtk_toggle_button_get_active (but);
77 get_project_by_id(dat -> a) -> modelgl -> rebuild[0][dat -> c] = i;
78 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)get_project_by_id(dat -> a) -> modelgl -> rbuild[i], i);
79#endif
80}
81
82#ifdef GTK4
91G_MODULE_EXPORT void turn_bonding_on (GtkCheckButton * but, gpointer data)
92#else
101G_MODULE_EXPORT void turn_bonding_on (GtkToggleButton * but, gpointer data)
102#endif
103{
104 atom_search * asearch = (atom_search *) data;
105 int i;
106#ifdef GTK4
107 i = gtk_check_button_get_active (but);
108#else
109 i = gtk_toggle_button_get_active (but);
110#endif
111 asearch -> recompute_bonding = i;
112}
113
122GtkWidget * create_search_box (int aid, project * this_proj)
123{
124 gchar * appl[5] = {" Move atom(s)", " Replace atom(s)", " Remove atom(s)", " Insert atom(s)", " Move atom(s)"};
125 gchar * img[4]= {EDITA, LIST_REM, LIST_ADD, MEDIA_PLAY};
126 GtkWidget * vbox = create_vbox (BSEP);
127 GtkWidget * hbox;
128 GtkWidget * widg;
129 int i;
130 if (aid == 4)
131 {
132 i = (this_proj -> modelgl -> search_widg[aid+1] != NULL) ? this_proj -> modelgl -> search_widg[aid+1] -> in_selection : 0;
133 }
134 else if (aid == 8)
135 {
136 i = this_proj -> nspec;
137 }
138 else
139 {
140 i = this_proj -> modelgl -> search_widg[aid+1] -> todo_size;
141 }
142 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, selection_tab (this_proj -> modelgl -> search_widg[aid+1], i), FALSE, FALSE, 0);
143 if (aid == 1 || aid == 5)
144 {
145 int j = (aid == 1) ? 0 : 1;
146 hbox = create_hbox (0);
147 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
148 this_proj -> modelgl -> atom_win -> edition_but[j] = check_button("Extract/rebuild the object(s) to be moved, ie. cut/clean bonds with nearest neighbor(s)",
149 -1, 25, this_proj -> modelgl -> rebuild[0][j], G_CALLBACK(turn_rebuild_on), & this_proj -> modelgl -> colorp[0][j]);
150 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, this_proj -> modelgl -> atom_win -> edition_but[j], FALSE, FALSE, 50);
151 }
152 if (aid == 1 || aid == 3 || aid == 5)
153 {
154 hbox = create_hbox (0);
155 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
156 widg = check_button("Recompute bonding information using bond cutoff(s)",
157 -1, 25, this_proj -> modelgl -> search_widg[aid+1] -> recompute_bonding, G_CALLBACK(turn_bonding_on), this_proj -> modelgl -> search_widg[aid+1]);
158 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, widg, FALSE, FALSE, 50);
159 }
160
161 if (aid > 1 && aid < 6)
162 {
163 GtkWidget * lay = create_layout (-1, 100);
164 GtkWidget * but;
165 if (aid == 5)
166 {
167 layout_add_widget (lay, markup_label("Repeat <i>n</i> times, <i>n</i>= ", 100, -1, 0.0, 0.5), 125, 25);
168 layout_add_widget (lay, spin_button (G_CALLBACK(repeat_move), 1, 1, 1000, 1, 0, 100, this_proj), 275, 20);
169 }
170 but = create_button (appl[aid-1], IMG_STOCK, img[aid-2], 100, 35, GTK_RELIEF_NORMAL, G_CALLBACK(take_action), & this_proj -> modelgl -> search_widg[aid+1] -> pointer[0]);
171 layout_add_widget (lay, but, 500, 20);
172 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, lay, FALSE, FALSE, 0);
173 }
174 return vbox;
175}
176
185G_MODULE_EXPORT void set_atoms_for_action (GtkComboBox * box, gpointer data)
186{
187 tint * id = (tint *)data;
188 project * this_proj = get_project_by_id (id -> a);
189 int i, j, k;
190 i = gtk_combo_box_get_active (box);
191 this_proj -> modelgl -> search_widg[id -> c] -> status = i;
192 if (id -> c == 2)
193 {
194 for (j=0; j<2; j++)
195 {
196 gtk_combo_box_set_active (GTK_COMBO_BOX(this_proj -> modelgl -> atom_win -> axis_combo[j]), this_proj -> modelgl -> atom_win -> axis[j]);
197 for (k=0; k<6; k++)
198 {
199 gtk_range_set_value (GTK_RANGE(this_proj -> modelgl -> atom_win -> edit_scale[k]), this_proj -> modelgl -> atom_win -> new_param[i][j][k]);
200 update_range_and_entry (this_proj, i, this_proj -> modelgl -> atom_win -> axis[j], k);
201 }
202 }
203 }
204 clean_picked_and_labelled (this_proj -> modelgl -> search_widg[id -> c], TRUE);
205 update_search_tree (this_proj -> modelgl -> search_widg[id -> c]);
206}
207
216GtkWidget * create_action_combo (int id, project * this_proj)
217{
218 GtkWidget * combo;
219 if (id == 3 || id == 5)
220 {
221 GtkTreeModel * model = replace_combo_tree (TRUE, this_proj -> id);
222 combo = gtk_combo_box_new_with_model (model);
223 g_object_unref (model);
224 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
225 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
226 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", 0, NULL);
227 g_signal_connect (G_OBJECT(combo), "changed", G_CALLBACK(set_atoms_to_insert), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
228 gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0);
229 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combo));
230 if(cell_list && cell_list -> data)
231 {
232 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell_list -> data, "markup", 0, NULL);
233 }
234 set_atoms_to_insert (GTK_COMBO_BOX(combo), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
235 }
236 else
237 {
238 combo = create_combo ();
239 int i;
240 for (i=0; i<3; i++) combo_text_append (combo, action_atoms[i]);
241 gtk_combo_box_set_active (GTK_COMBO_BOX(combo), this_proj -> modelgl -> search_widg[id+2] -> status);
242 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(set_atoms_for_action), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
243 }
244
245 return combo;
246}
247
256G_MODULE_EXPORT void expanding_atoms (GtkWidget * exp, gpointer data)
257{
258 tint * dat = (tint *)data;
259 project * this_proj = get_project_by_id (dat -> a);
260 int i;
261 for (i=0; i<3; i++)
262 {
263 if (i != dat -> c - 1)
264 {
265 if (gtk_expander_get_expanded (GTK_EXPANDER (this_proj -> modelgl -> atom_win -> at_expand[i])))
266 {
267 gtk_expander_set_expanded (GTK_EXPANDER (this_proj -> modelgl -> atom_win -> at_expand[i]), FALSE);
268 }
269 }
270 }
271}
272
281GtkWidget * action_tab (int aid, project * this_proj)
282{
283 gchar * action[7] = {"moved", "replaced", "removed", "inserted", "moved randomly", " ", "passivated"};
284 GtkWidget * vbox = create_vbox (BSEP);
285 atom_search * asearch = this_proj -> modelgl -> search_widg[aid+2];
286 GtkWidget * hbox;
287 if (aid < 5)
288 {
289 hbox = create_hbox (5);
290 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
291 gchar * str = g_strdup_printf ("<u>Select the object(s) to be %s in:</u> ", action[aid]);
292 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 200, -1, 0.0, 0.5), FALSE, FALSE, 20);
293 g_free (str);
294 this_proj -> modelgl -> atom_win -> atom_combo[aid] = create_action_combo (aid, this_proj);
295 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, this_proj -> modelgl -> atom_win -> atom_combo[aid], FALSE, FALSE, 20);
296 }
297 GtkWidget * sbox = create_vbox (BSEP);
298 GtkWidget * tbox = create_search_box (aid+1, this_proj);
299 if (! aid)
300 {
301 gchar * exp_name[3] = {"<b>Atom selection:</b>", "<b>Translate:</b>", "<b>Rotate:</b>"};
302 int i;
303 for (i=0; i<3; i++)
304 {
305 this_proj -> modelgl -> atom_win -> at_expand[i] = create_expander (exp_name[i], NULL);
306 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, this_proj -> modelgl -> atom_win -> at_expand[i], TRUE, TRUE, 10);
307 if (! i)
308 {
309 add_container_child (CONTAINER_EXP, this_proj -> modelgl -> atom_win -> at_expand[i], tbox);
310 gtk_expander_set_expanded (GTK_EXPANDER(this_proj -> modelgl -> atom_win -> at_expand[i]), TRUE);
311 }
312 else
313 {
314 add_container_child (CONTAINER_EXP, this_proj -> modelgl -> atom_win -> at_expand[i], add_motion_interaction (asearch, i-1, this_proj));
315 gtk_expander_set_expanded (GTK_EXPANDER(this_proj -> modelgl -> atom_win -> at_expand[i]), FALSE);
316 if (i == 2) widget_set_sensitive (this_proj -> modelgl -> atom_win -> at_expand[2], asearch -> object);
317
318 }
319 g_signal_connect (G_OBJECT(this_proj -> modelgl -> atom_win -> at_expand[i]), "activate", G_CALLBACK(expanding_atoms), & asearch -> pointer[0]);
320 }
321 }
322 else
323 {
324 if (aid < 3)
325 {
326 asearch -> mode_box = create_combo ();
327 combo_text_append (asearch -> mode_box, "Normally");
328 combo_text_append (asearch -> mode_box, "Randomly");
329 gtk_combo_box_set_active (GTK_COMBO_BOX(asearch -> mode_box), 0);
330 g_signal_connect (G_OBJECT (asearch -> mode_box), "changed", G_CALLBACK(set_search_mode), asearch);
331 GtkWidget * box = create_hbox (0);
332 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, box, FALSE, FALSE, 5);
333 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, markup_label("<b>.</b>", 5, -1, 0.0, 0.5), FALSE, FALSE, 10);
334 gchar * type_of[2]={"Replace: ", "Remove: "};
335 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, markup_label(type_of[aid-1], 50, -1, 0.0, 0.5), FALSE, FALSE, 0);
336 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, asearch -> mode_box, FALSE, FALSE, 5);
337 }
338 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, tbox, FALSE, FALSE, 0);
339 }
340 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, sbox, FALSE, FALSE, 5);
341 if (! aid || aid == 4)
342 {
343 hbox = create_hbox (5);
344 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 20);
345 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox,
346 check_button ("Reset transformation(s)", -1, 35, FALSE, G_CALLBACK(set_reset_transformation), & asearch -> pointer[0]),
347 FALSE, FALSE, 10);
348 }
350 if (aid != 3) widget_set_sensitive (vbox, this_proj -> nspec);
351 return vbox;
352}
G_MODULE_EXPORT void take_action(GtkButton *but, gpointer data)
take edition action
G_MODULE_EXPORT void set_reset_transformation(GtkToggleButton *but, gpointer data)
reset model transformation toggle callback GTK3
Definition atom_edit.c:277
gchar * action_atoms[3]
Definition atom_edit.c:61
Function declarations for the mode edition window.
GtkTreeModel * replace_combo_tree(gboolean insert, int proj)
replace combo box in the tree view
Definition w_search.c:2615
GtkWidget * selection_tab(atom_search *asearch, int nats)
create the search widget
Definition w_search.c:4130
G_MODULE_EXPORT void repeat_move(GtkSpinButton *res, gpointer data)
repeat motion callback
Definition atom_move.c:963
void update_search_tree(atom_search *asearch)
update search tree
Definition w_search.c:1294
GtkWidget * add_motion_interaction(atom_search *asearch, int axd, project *this_proj)
add motion interaction widgets
Definition atom_move.c:1230
G_MODULE_EXPORT void set_atoms_to_insert(GtkComboBox *box, gpointer data)
change the object to insert
void clean_picked_and_labelled(atom_search *asearch, gboolean clean_msd)
initialize atom search data buffers
Definition w_search.c:3791
void update_range_and_entry(project *this_proj, int i, int j, int k)
update motion range
Definition atom_move.c:979
G_MODULE_EXPORT void set_search_mode(GtkComboBox *box, gpointer data)
change search mode
Definition w_search.c:3983
G_MODULE_EXPORT void expanding_atoms(GtkWidget *exp, gpointer data)
expanding motion callback
GtkWidget * action_tab(int aid, project *this_proj)
create model edtion action tab
G_MODULE_EXPORT void set_atoms_for_action(GtkComboBox *box, gpointer data)
change selection status
GtkWidget * create_search_box(int aid, project *this_proj)
create the action search widget
G_MODULE_EXPORT void turn_rebuild_on(GtkToggleButton *but, gpointer data)
rebuild toggle callback GTK3
Definition atom_search.c:67
GtkWidget * create_action_combo(int id, project *this_proj)
create action combo box
G_MODULE_EXPORT void turn_bonding_on(GtkToggleButton *but, gpointer data)
update bonding toggle callback GTK3
gchar * axis[3]
Definition w_axis.c:65
color colorp[64]
@ IMG_STOCK
Definition global.h:264
#define BSEP
Definition global.h:245
#define EDITA
Definition global.h:202
void layout_add_widget(GtkWidget *layout, GtkWidget *child, int x_pos, int y_pos)
Add a GtkWidget in a GtkLayout.
Definition gtk-misc.c:846
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
Definition gtk-misc.c:1772
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1799
#define LIST_ADD
Definition global.h:213
@ CONTAINER_EXP
Definition global.h:255
#define MEDIA_PLAY
Definition global.h:187
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1863
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
#define LIST_REM
Definition global.h:214
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
GtkWidget * create_layout(int x, int y)
create a GtkLayout / GtkFixed widget
Definition gtk-misc.c:880
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
GtkWidget * create_expander(gchar *name, gchar *file_img)
create GtkExpander
Definition gtk-misc.c:1984
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
action
Definition glview.h:189
Definition global.h:104
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
int status
Definition w_advance.c:160
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72