atomes 1.2.1
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-2025 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 = button_get_status ((GtkWidget *)but);
72 get_project_by_id(dat -> a) -> modelgl -> rebuild[0][dat -> c] = i;
73#ifdef GTK3
74 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)get_project_by_id(dat -> a) -> modelgl -> rbuild[i], i);
75#endif
76}
77
78#ifdef GTK4
87G_MODULE_EXPORT void turn_bonding_on (GtkCheckButton * but, gpointer data)
88#else
97G_MODULE_EXPORT void turn_bonding_on (GtkToggleButton * but, gpointer data)
98#endif
99{
100 atom_search * asearch = (atom_search *) data;
101 asearch -> recompute_bonding = button_get_status ((GtkWidget *)but);
102}
103
112GtkWidget * create_search_box (int aid, project * this_proj)
113{
114 gchar * appl[5] = {" Move atom(s)", " Replace atom(s)", " Remove atom(s)", " Insert atom(s)", " Move atom(s)"};
115 gchar * img[4]= {EDITA, LIST_REM, LIST_ADD, MEDIA_PLAY};
116 GtkWidget * vbox = create_vbox (BSEP);
117 GtkWidget * hbox;
118 GtkWidget * widg;
119 int i;
120 if (aid == 4)
121 {
122 i = (this_proj -> modelgl -> search_widg[aid+1] != NULL) ? this_proj -> modelgl -> search_widg[aid+1] -> in_selection : 0;
123 }
124 else if (aid == 8)
125 {
126 i = this_proj -> nspec;
127 }
128 else
129 {
130 i = this_proj -> modelgl -> search_widg[aid+1] -> todo_size;
131 }
132 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, selection_tab (this_proj -> modelgl -> search_widg[aid+1], i), FALSE, FALSE, 0);
133 if (aid == 1 || aid == 5)
134 {
135 int j = (aid == 1) ? 0 : 1;
136 hbox = create_hbox (0);
137 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
138 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)",
139 -1, 25, this_proj -> modelgl -> rebuild[0][j], G_CALLBACK(turn_rebuild_on), & this_proj -> modelgl -> colorp[0][j]);
140 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, this_proj -> modelgl -> atom_win -> edition_but[j], FALSE, FALSE, 50);
141 }
142 if (aid == 1 || aid == 3 || aid == 5)
143 {
144 hbox = create_hbox (0);
145 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
146 widg = check_button("Recompute bonding information using bond cutoff(s)",
147 -1, 25, this_proj -> modelgl -> search_widg[aid+1] -> recompute_bonding, G_CALLBACK(turn_bonding_on), this_proj -> modelgl -> search_widg[aid+1]);
148 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, widg, FALSE, FALSE, 50);
149 }
150
151 if (aid > 1 && aid < 6)
152 {
153 GtkWidget * lay = create_layout (-1, 100);
154 GtkWidget * but;
155 if (aid == 5)
156 {
157 layout_add_widget (lay, markup_label("Repeat <i>n</i> times, <i>n</i>= ", 100, -1, 0.0, 0.5), 125, 25);
158 layout_add_widget (lay, spin_button (G_CALLBACK(repeat_move), 1, 1, 1000, 1, 0, 100, this_proj), 275, 20);
159 }
160 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]);
161 layout_add_widget (lay, but, 500, 20);
162 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, lay, FALSE, FALSE, 0);
163 }
164 return vbox;
165}
166
175G_MODULE_EXPORT void set_atoms_for_action (GtkComboBox * box, gpointer data)
176{
177 tint * id = (tint *)data;
178 project * this_proj = get_project_by_id (id -> a);
179 int i, j, k;
180 i = combo_get_active ((GtkWidget *)box);
181 this_proj -> modelgl -> search_widg[id -> c] -> status = i;
182 if (id -> c == 2)
183 {
184 for (j=0; j<2; j++)
185 {
186 combo_set_active (this_proj -> modelgl -> atom_win -> axis_combo[j], this_proj -> modelgl -> atom_win -> axis[j]);
187 for (k=0; k<6; k++)
188 {
189 gtk_range_set_value (GTK_RANGE(this_proj -> modelgl -> atom_win -> edit_scale[k]), this_proj -> modelgl -> atom_win -> new_param[i][j][k]);
190 update_range_and_entry (this_proj, i, this_proj -> modelgl -> atom_win -> axis[j], k);
191 }
192 }
193 }
194 clean_picked_and_labelled (this_proj -> modelgl -> search_widg[id -> c], TRUE);
195 update_search_tree (this_proj -> modelgl -> search_widg[id -> c]);
196}
197
206GtkWidget * create_action_combo (int id, project * this_proj)
207{
208 GtkWidget * combo;
209 if (id == 3 || id == 5)
210 {
211 GtkTreeModel * model = replace_combo_tree (TRUE, this_proj -> id);
212 combo = gtk_combo_box_new_with_model (model);
213 g_object_unref (model);
214 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
215 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
216 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", 0, NULL);
217 g_signal_connect (G_OBJECT(combo), "changed", G_CALLBACK(set_atoms_to_insert), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
218 combo_set_active (combo, 0);
219 combo_set_markup (combo);
220 set_atoms_to_insert (GTK_COMBO_BOX(combo), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
221 }
222 else
223 {
224 combo = create_combo ();
225 int i;
226 for (i=0; i<3; i++) combo_text_append (combo, action_atoms[i]);
227 combo_set_active (combo, this_proj -> modelgl -> search_widg[id+2] -> status);
228 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(set_atoms_for_action), & this_proj -> modelgl -> search_widg[id+2] -> pointer[0]);
229 }
230
231 return combo;
232}
233
242G_MODULE_EXPORT void expanding_atoms (GtkWidget * exp, gpointer data)
243{
244 tint * dat = (tint *)data;
245 project * this_proj = get_project_by_id (dat -> a);
246 int i;
247 for (i=0; i<3; i++)
248 {
249 if (i != dat -> c - 1)
250 {
251 if (gtk_expander_get_expanded (GTK_EXPANDER (this_proj -> modelgl -> atom_win -> at_expand[i])))
252 {
253 gtk_expander_set_expanded (GTK_EXPANDER (this_proj -> modelgl -> atom_win -> at_expand[i]), FALSE);
254 }
255 }
256 }
257}
258
267GtkWidget * action_tab (int aid, project * this_proj)
268{
269 gchar * action[7] = {"moved", "replaced", "removed", "inserted", "moved randomly", " ", "passivated"};
270 GtkWidget * vbox = create_vbox (BSEP);
271 atom_search * asearch = this_proj -> modelgl -> search_widg[aid+2];
272 GtkWidget * hbox;
273 if (aid < 5)
274 {
275 hbox = create_hbox (5);
276 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
277 gchar * str = g_strdup_printf ("<u>Select the object(s) to be %s in:</u> ", action[aid]);
278 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 200, -1, 0.0, 0.5), FALSE, FALSE, 20);
279 g_free (str);
280 this_proj -> modelgl -> atom_win -> atom_combo[aid] = create_action_combo (aid, this_proj);
281 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, this_proj -> modelgl -> atom_win -> atom_combo[aid], FALSE, FALSE, 20);
282 }
283 GtkWidget * sbox = create_vbox (BSEP);
284 GtkWidget * tbox = create_search_box (aid+1, this_proj);
285 if (! aid)
286 {
287 gchar * exp_name[3] = {"<b>Atom selection:</b>", "<b>Translate:</b>", "<b>Rotate:</b>"};
288 int i;
289 for (i=0; i<3; i++)
290 {
291 this_proj -> modelgl -> atom_win -> at_expand[i] = create_expander (exp_name[i], NULL);
292 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, this_proj -> modelgl -> atom_win -> at_expand[i], TRUE, TRUE, 10);
293 if (! i)
294 {
295 add_container_child (CONTAINER_EXP, this_proj -> modelgl -> atom_win -> at_expand[i], tbox);
296 gtk_expander_set_expanded (GTK_EXPANDER(this_proj -> modelgl -> atom_win -> at_expand[i]), TRUE);
297 }
298 else
299 {
300 add_container_child (CONTAINER_EXP, this_proj -> modelgl -> atom_win -> at_expand[i], add_motion_interaction (asearch, i-1, this_proj));
301 gtk_expander_set_expanded (GTK_EXPANDER(this_proj -> modelgl -> atom_win -> at_expand[i]), FALSE);
302 if (i == 2) widget_set_sensitive (this_proj -> modelgl -> atom_win -> at_expand[2], asearch -> object);
303
304 }
305 g_signal_connect (G_OBJECT(this_proj -> modelgl -> atom_win -> at_expand[i]), "activate", G_CALLBACK(expanding_atoms), & asearch -> pointer[0]);
306 }
307 }
308 else
309 {
310 if (aid < 3)
311 {
312 asearch -> mode_box = create_combo ();
313 combo_text_append (asearch -> mode_box, "Normally");
314 combo_text_append (asearch -> mode_box, "Randomly");
315 combo_set_active (asearch -> mode_box, 0);
316 g_signal_connect (G_OBJECT (asearch -> mode_box), "changed", G_CALLBACK(set_search_mode), asearch);
317 GtkWidget * box = create_hbox (0);
318 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, box, FALSE, FALSE, 5);
319 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, markup_label("<b>.</b>", 5, -1, 0.0, 0.5), FALSE, FALSE, 10);
320 gchar * type_of[2]={"Replace: ", "Remove: "};
321 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, markup_label(type_of[aid-1], 50, -1, 0.0, 0.5), FALSE, FALSE, 0);
322 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, asearch -> mode_box, FALSE, FALSE, 5);
323 }
324 add_box_child_start (GTK_ORIENTATION_VERTICAL, sbox, tbox, FALSE, FALSE, 0);
325 }
326 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, sbox, FALSE, FALSE, 5);
327 if (! aid || aid == 4)
328 {
329 hbox = create_hbox (5);
330 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 20);
331 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox,
332 check_button ("Reset transformation(s)", -1, 35, FALSE, G_CALLBACK(set_reset_transformation), & asearch -> pointer[0]),
333 FALSE, FALSE, 10);
334 }
336 if (aid != 3) widget_set_sensitive (vbox, this_proj -> nspec);
337 return vbox;
338}
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:275
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:2626
GtkWidget * selection_tab(atom_search *asearch, int nats)
create the search widget
Definition w_search.c:4128
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:1305
GtkWidget * add_motion_interaction(atom_search *asearch, int axd, project *this_proj)
add motion interaction widgets
Definition atom_move.c:1225
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:3789
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:3981
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
Definition atom_search.c:97
color colorp[64]
@ IMG_STOCK
Definition global.h:266
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:909
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:944
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
#define BSEP
Definition global.h:247
#define EDITA
Definition global.h:204
void layout_add_widget(GtkWidget *layout, GtkWidget *child, int x_pos, int y_pos)
Add a GtkWidget in a GtkLayout.
Definition gtk-misc.c:856
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:1833
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1893
#define LIST_ADD
Definition global.h:215
@ CONTAINER_EXP
Definition global.h:257
#define MEDIA_PLAY
Definition global.h:189
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:1955
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:984
#define LIST_REM
Definition global.h:216
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1646
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:308
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:215
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:823
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:961
GtkWidget * create_layout(int x, int y)
create a GtkLayout / GtkFixed widget
Definition gtk-misc.c:890
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:235
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:811
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1855
GtkWidget * create_expander(gchar *name, gchar *file_img)
create GtkExpander
Definition gtk-misc.c:2119
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:182
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
action
Definition glview.h:198
Definition glwin.h:333
Definition glwin.h:351
Definition global.h:106
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
int status
Definition w_advance.c:178
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72