atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cell_edit.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-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'cell_edit.c'
24*
25* Contains:
26*
27
28 - The functions to create the cell edition window
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT gboolean close_cell (GtkWindow * widg, gpointer data);
34 G_MODULE_EXPORT gboolean close_cell (GtkWidget * widg, GdkEvent * event, gpointer data);
35
36 G_MODULE_EXPORT void close_cell_edit (GtkButton * but, gpointer data);
37 G_MODULE_EXPORT void edition_win (GSimpleAction * action, GVariant * parameter, gpointer data);
38 G_MODULE_EXPORT void edition_win (GtkWidget * widg, gpointer data);
39
40 GtkWidget * cell_tab (int i, project * this_proj);
41 GtkWidget * create_cell_notebook (project * this_proj, GtkWidget * vbox);
42 GtkWidget * create_cell_edition_window (project * this_proj, gpointer data);
43
44*/
45
46#include "cell_edit.h"
47
48gchar * edit_names[7] = {i18n("Wrap All Atoms in"),
49 i18n("Shift Center"),
50 i18n("Add Extra(s)"),
51 i18n("Create Super-Cell"),
52 i18n("Adjust Density"),
53 i18n("Cut Slab"),
54 i18n("PBC Pixels Debug")};
55
64G_MODULE_EXPORT void close_cell_edit (GtkButton * but, gpointer data)
65{
66 project * this_proj = (project *)data;
67 int i;
68 for (i=0; i<3; i++) this_proj -> modelgl -> cshift[i] = this_proj -> modelgl -> cell_win -> cparam[i];
69 this_proj -> modelgl -> cell_win -> win = destroy_this_widget (this_proj -> modelgl -> cell_win -> win);
70 g_free (this_proj -> modelgl -> cell_win);
71 this_proj -> modelgl -> cell_win = NULL;
72 cleaning_shaders (this_proj -> modelgl, SLABS);
73 update (this_proj -> modelgl);
74}
75
76#ifdef GTK4
85G_MODULE_EXPORT gboolean close_cell (GtkWindow * widg, gpointer data)
86#else
96G_MODULE_EXPORT gboolean close_cell (GtkWidget * widg, GdkEvent * event, gpointer data)
97#endif
98{
99 close_cell_edit (NULL, data);
100 return FALSE;
101}
102
111GtkWidget * cell_tab (int i, project * this_proj)
112{
113 switch (i)
114 {
115 case 0:
116 return shift_center_tab (this_proj);
117 break;
118 case 1:
119 return add_extra_cell_tab (this_proj -> modelgl);
120 break;
121 case 2:
122 return adjust_density_tab (this_proj);
123 break;
124 case 3:
125 return cut_in_model (this_proj);
126 break;
127#ifdef DEBUG
128 default:
129 return pixels_tab (this_proj);
130 break;
131#else
132 default:
133 return NULL;
134 break;
135#endif
136 }
137}
138
147GtkWidget * create_cell_notebook (project * this_proj, GtkWidget * vbox)
148{
149 GtkWidget * notebook = gtk_notebook_new ();
150 gchar * str;
151 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, notebook, TRUE, TRUE, 0);
152
153 int i, j;
154 gboolean doit;
155#ifdef DEBUG
156 for (i=0; i<5; i ++)
157#else
158 for (i=0; i<4; i ++)
159#endif
160 {
161#ifdef DEBUG
162 doit = (i == 4 && ! this_proj -> pix[0]) ? FALSE : TRUE;
163#else
164 doit = TRUE;
165#endif
166 if (doit)
167 {
168 j = (i < 2) ? i+1 : i+2;
169 str = g_strdup_printf ("<b>%s</b>", _(edit_names[j]));
170 gtk_notebook_insert_page (GTK_NOTEBOOK(notebook), cell_tab (i, this_proj), markup_label(str, -1, -1, 0.0, 0.5), i);
171 if (i > 1) widget_set_sensitive (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i), (this_proj -> steps) > 1 ? 0 : 1);
172 g_free (str);
173 }
174 }
175
176 show_the_widgets (notebook);
177 return notebook;
178}
179
188GtkWidget * create_cell_edition_window (project * this_proj, gpointer data)
189{
190 gchar * str = g_strdup_printf (_("Cell edition - %s"), this_proj -> name);
191 GtkWidget * win = create_win (str, this_proj -> modelgl -> win, FALSE, FALSE);
192 g_free (str);
193 GtkWidget * vbox = create_vbox (5);
195 gtk_widget_set_size_request (vbox, 700 , -1);
196
197 int i;
198 for (i=0; i<3; i++) this_proj -> modelgl -> cell_win -> cparam[i] = this_proj -> modelgl -> cshift[i];
199 this_proj -> modelgl -> cell_win -> notebook = create_cell_notebook (this_proj, vbox);
200
201 GtkWidget * hbox = create_hbox (5);
202 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, FALSE, 0);
203 GtkWidget * but = create_button (_("Close"), IMG_STOCK, FCLOSE, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(close_cell_edit), this_proj);
204 add_box_child_end (hbox, but, FALSE, FALSE, 5);
205 add_gtk_close_event (win, G_CALLBACK(close_cell), this_proj);
206
207 return win;
208}
209
210#ifdef GTK4
220G_MODULE_EXPORT void edition_win (GSimpleAction * action, GVariant * parameter, gpointer data)
221#else
230G_MODULE_EXPORT void edition_win (GtkWidget * widg, gpointer data)
231#endif
232{
233 tint * id = (tint *) data;
234 int i;
235 project * this_proj = get_project_by_id(id -> a);
236 if (this_proj -> modelgl -> cell_win == NULL)
237 {
238 this_proj -> modelgl -> cell_win = g_malloc0(sizeof*this_proj -> modelgl -> cell_win);
239 this_proj -> modelgl -> cell_win -> homo_density = TRUE;
240 this_proj -> modelgl -> cell_win -> slab_alpha = 0.75;
241 this_proj -> modelgl -> cell_win -> slab_lot = allocint (this_proj -> nspec);
242 this_proj -> modelgl -> cell_win -> slab_pbc = this_proj -> cell.pbc;
243 for (i=0; i<5; i++)
244 {
245 this_proj -> modelgl -> cell_win -> slab_pointer[i].a = id -> a;
246 this_proj -> modelgl -> cell_win -> slab_pointer[i].b = i;
247 }
248 for (i=9; i<13; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 5.0;
249 for (i=13; i<15; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 2.5;
250 for (i=15; i<18; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 90.0;
251 this_proj -> modelgl -> cell_win -> win = create_cell_edition_window (this_proj, data);
252 }
253 show_the_widgets (this_proj -> modelgl -> cell_win -> win);
254
255 for (i=1; i<6; i++)
256 {
257 if (i < 3) hide_the_widgets (this_proj -> modelgl -> cell_win -> slab_hbox[i]);
258 hide_the_widgets (this_proj -> modelgl -> cell_win -> slab_box[i]);
259 }
260 int page = id -> b;
261 gtk_notebook_set_current_page (GTK_NOTEBOOK (this_proj -> modelgl -> cell_win -> notebook), page);
262}
GtkWidget * cut_in_model(project *this_proj)
create the cut slab tab
Definition cell_cut.c:654
GtkWidget * adjust_density_tab(project *this_proj)
create the density tab
G_MODULE_EXPORT void edition_win(GtkWidget *widg, gpointer data)
create the cell edition window callback GTK3
Definition cell_edit.c:230
GtkWidget * cell_tab(int i, project *this_proj)
create the 'i'th cell tab
Definition cell_edit.c:111
GtkWidget * create_cell_edition_window(project *this_proj, gpointer data)
create the cell editon window
Definition cell_edit.c:188
G_MODULE_EXPORT gboolean close_cell(GtkWidget *widg, GdkEvent *event, gpointer data)
cell edition window close event callback GTK3
Definition cell_edit.c:96
G_MODULE_EXPORT void close_cell_edit(GtkButton *but, gpointer data)
close cell edition window and free the associated data pointers
Definition cell_edit.c:64
gchar * edit_names[7]
Definition cell_edit.c:48
GtkWidget * create_cell_notebook(project *this_proj, GtkWidget *vbox)
create the cell edition notebook
Definition cell_edit.c:147
Function declarations for the cell edition window.
GtkWidget * add_extra_cell_tab(glwin *view)
create the add cell(s) tab
Definition cell_extra.c:81
GtkWidget * shift_center_tab(project *this_proj)
create the shift cell center tab
Definition cell_shift.c:560
GtkWidget * pixels_tab(project *this_proj)
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
#define i18n(String)
Definition global.c:80
@ IMG_STOCK
Definition global.h:280
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:486
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2557
@ CONTAINER_WIN
Definition global.h:266
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:1999
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
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:340
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
void add_box_child_end(GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the end position.
Definition gtk-misc.c:318
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
#define FCLOSE
Definition global.h:227
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:461
action
Definition glview.h:198
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
@ SLABS
Definition glwin.h:101
Definition global.h:118
GdkPixbuf * pix
Definition workspace.c:69
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72