atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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] = {"Wrap All Atoms in", "Shift Center", "Add Extra(s)", "Create Super-Cell", "Adjust Density", "Cut Slab", "PBC Pixels Debug"};
49
58G_MODULE_EXPORT void close_cell_edit (GtkButton * but, gpointer data)
59{
60 project * this_proj = (project *)data;
61 int i;
62 for (i=0; i<3; i++) this_proj -> modelgl -> cshift[i] = this_proj -> modelgl -> cell_win -> cparam[i];
63 this_proj -> modelgl -> cell_win -> win = destroy_this_widget (this_proj -> modelgl -> cell_win -> win);
64 g_free (this_proj -> modelgl -> cell_win);
65 this_proj -> modelgl -> cell_win = NULL;
66 cleaning_shaders (this_proj -> modelgl, SLABS);
67 update (this_proj -> modelgl);
68}
69
70#ifdef GTK4
79G_MODULE_EXPORT gboolean close_cell (GtkWindow * widg, gpointer data)
80#else
90G_MODULE_EXPORT gboolean close_cell (GtkWidget * widg, GdkEvent * event, gpointer data)
91#endif
92{
93 close_cell_edit (NULL, data);
94 return FALSE;
95}
96
105GtkWidget * cell_tab (int i, project * this_proj)
106{
107 switch (i)
108 {
109 case 0:
110 return shift_center_tab (this_proj);
111 break;
112 case 1:
113 return add_extra_cell_tab (this_proj -> modelgl);
114 break;
115 case 2:
116 return adjust_density_tab (this_proj);
117 break;
118 case 3:
119 return cut_in_model (this_proj);
120 break;
121#ifdef DEBUG
122 default:
123 return pixels_tab (this_proj);
124 break;
125#else
126 default:
127 return NULL;
128 break;
129#endif
130 }
131}
132
141GtkWidget * create_cell_notebook (project * this_proj, GtkWidget * vbox)
142{
143 GtkWidget * notebook = gtk_notebook_new ();
144 gchar * str;
145 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, notebook, TRUE, TRUE, 0);
146
147 int i, j;
148 gboolean doit;
149#ifdef DEBUG
150 for (i=0; i<5; i ++)
151#else
152 for (i=0; i<4; i ++)
153#endif
154 {
155#ifdef DEBUG
156 doit = (i == 4 && ! this_proj -> pix[0]) ? FALSE : TRUE;
157#else
158 doit = TRUE;
159#endif
160 if (doit)
161 {
162 j = (i < 2) ? i+1 : i+2;
163 str = g_strdup_printf ("<b>%s</b>", edit_names[j]);
164 gtk_notebook_insert_page (GTK_NOTEBOOK(notebook), cell_tab (i, this_proj), markup_label(str, -1, -1, 0.0, 0.5), i);
165 if (i > 1) widget_set_sensitive (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i), (this_proj -> steps) > 1 ? 0 : 1);
166 g_free (str);
167 }
168 }
169
170 show_the_widgets (notebook);
171 return notebook;
172}
173
182GtkWidget * create_cell_edition_window (project * this_proj, gpointer data)
183{
184 gchar * str = g_strdup_printf ("Cell edition - %s", this_proj -> name);
185 GtkWidget * win = create_win (str, this_proj -> modelgl -> win, FALSE, FALSE);
186 g_free (str);
187 GtkWidget * vbox = create_vbox (5);
189 gtk_widget_set_size_request (vbox, 700 , -1);
190
191 int i;
192 for (i=0; i<3; i++) this_proj -> modelgl -> cell_win -> cparam[i] = this_proj -> modelgl -> cshift[i];
193 this_proj -> modelgl -> cell_win -> notebook = create_cell_notebook (this_proj, vbox);
194
195 GtkWidget * hbox = create_hbox (5);
196 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, FALSE, 0);
197 GtkWidget * but = create_button ("Close", IMG_STOCK, FCLOSE, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(close_cell_edit), this_proj);
198 add_box_child_end (hbox, but, FALSE, FALSE, 5);
199 add_gtk_close_event (win, G_CALLBACK(close_cell), this_proj);
200
201 return win;
202}
203
204#ifdef GTK4
214G_MODULE_EXPORT void edition_win (GSimpleAction * action, GVariant * parameter, gpointer data)
215#else
224G_MODULE_EXPORT void edition_win (GtkWidget * widg, gpointer data)
225#endif
226{
227 tint * id = (tint *) data;
228 int i;
229 project * this_proj = get_project_by_id(id -> a);
230 if (this_proj -> modelgl -> cell_win == NULL)
231 {
232 this_proj -> modelgl -> cell_win = g_malloc0 (sizeof*this_proj -> modelgl -> cell_win);
233 this_proj -> modelgl -> cell_win -> homo_density = TRUE;
234 this_proj -> modelgl -> cell_win -> slab_alpha = 0.75;
235 this_proj -> modelgl -> cell_win -> slab_lot = allocint (this_proj -> nspec);
236 this_proj -> modelgl -> cell_win -> slab_pbc = this_proj -> cell.pbc;
237 for (i=0; i<5; i++)
238 {
239 this_proj -> modelgl -> cell_win -> slab_pointer[i].a = id -> a;
240 this_proj -> modelgl -> cell_win -> slab_pointer[i].b = i;
241 }
242 for (i=9; i<13; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 5.0;
243 for (i=13; i<15; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 2.5;
244 for (i=15; i<18; i++) this_proj -> modelgl -> cell_win -> cparam[i] = 90.0;
245 this_proj -> modelgl -> cell_win -> win = create_cell_edition_window (this_proj, data);
246 }
247 show_the_widgets (this_proj -> modelgl -> cell_win -> win);
248
249 for (i=1; i<6; i++)
250 {
251 if (i < 3) hide_the_widgets (this_proj -> modelgl -> cell_win -> slab_hbox[i]);
252 hide_the_widgets (this_proj -> modelgl -> cell_win -> slab_box[i]);
253 }
254 int page = id -> b;
255 gtk_notebook_set_current_page (GTK_NOTEBOOK (this_proj -> modelgl -> cell_win -> notebook), page);
256}
GtkWidget * cut_in_model(project *this_proj)
create the cut slab tab
Definition cell_cut.c:659
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:224
GtkWidget * cell_tab(int i, project *this_proj)
create the 'i'th cell tab
Definition cell_edit.c:105
GtkWidget * create_cell_edition_window(project *this_proj, gpointer data)
create the cell editon window
Definition cell_edit.c:182
G_MODULE_EXPORT gboolean close_cell(GtkWidget *widg, GdkEvent *event, gpointer data)
cell edition window close event callback GTK3
Definition cell_edit.c:90
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:58
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:141
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:314
@ IMG_STOCK
Definition global.h:264
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
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:2387
@ CONTAINER_WIN
Definition global.h:250
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 * 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
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
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:277
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
#define FCLOSE
Definition global.h:211
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
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
action
Definition glview.h:189
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
@ SLABS
Definition glwin.h:101
Definition global.h:104
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GdkPixbuf * pix
Definition workspace.c:69
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72