atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
close_p.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
23/*
24* This file: 'close_p.c'
25*
26* Contains:
27*
28
29 - the functions to close an atomes project
30 - the callbacks to close an atomes project
31
32*
33* List of functions:
34
35 void update_insert_combos ();
36 void close_project (project * to_close);
37
38 void to_close_this_project (int to_activate, project * this_proj);
39 G_MODULE_EXPORT void on_close_activate (GtkWidget * widg, gpointer cdata);
40
41*/
42
43#include "global.h"
44#include "bind.h"
45#include "callbacks.h"
46#include "interface.h"
47#include "project.h"
48#include "workspace.h"
49#include "curve.h"
50#include "glview.h"
51
52extern GtkTreeStore * tool_model;
53extern GtkTreeModel * replace_combo_tree (gboolean insert, int proj);
54
61{
62 GtkTreeModel * model;
63 project * this_proj;
64 GtkWidget * box;
65 int i;
66 for (i=0; i<nprojects; i++)
67 {
68 this_proj = get_project_by_id(i);
69 if (this_proj -> modelgl)
70 {
71 if ((this_proj -> modelgl -> atom_win && this_proj -> modelgl -> atom_win -> visible) || this_proj -> modelgl -> builder_win)
72 {
73 model = replace_combo_tree (TRUE, i);
74 box = (this_proj -> modelgl -> builder_win) ? this_proj -> modelgl -> builder_win -> add_combo : this_proj -> modelgl -> atom_win -> atom_combo[3];
75 gtk_combo_box_set_model (GTK_COMBO_BOX(box), model);
78 g_object_unref (model);
79 }
80 }
81 }
82}
83
91void close_project (project * to_close)
92{
93 int i, j, k, l;
94
95#ifdef DEBUG
96 g_debug ("CLOSE_PROJECT: proj to close= %d", to_close -> id);
97 g_debug ("CLOSE_PROJECT: nprojects = %d", nprojects);
98 g_debug ("CLOSE_PROJECT: activep = %d", activep);
99#endif
100
101 if (to_close -> modelgl)
102 {
103 if (to_close -> modelgl -> rep_win)
104 {
105 to_close -> modelgl -> rep_win -> win = destroy_this_widget (to_close -> modelgl -> rep_win -> win);
106 g_free (to_close -> modelgl -> rep_win);
107 }
108 if (to_close -> modelgl -> gradient_win)
109 {
110 to_close -> modelgl -> gradient_win -> win = destroy_this_widget (to_close -> modelgl -> gradient_win -> win);
111 g_free (to_close -> modelgl -> gradient_win);
112 }
113 if (to_close -> modelgl -> box_win)
114 {
115 to_close -> modelgl -> box_win -> win = destroy_this_widget (to_close -> modelgl -> box_win -> win);
116 g_free (to_close -> modelgl -> box_win);
117 }
118 if (to_close -> modelgl -> axis_win)
119 {
120 to_close -> modelgl -> axis_win -> win = destroy_this_widget (to_close -> modelgl -> axis_win -> win);
121 g_free (to_close -> modelgl -> axis_win);
122 }
123 if (to_close -> modelgl -> measure_win)
124 {
125 to_close -> modelgl -> measure_win -> win = destroy_this_widget (to_close -> modelgl -> measure_win -> win);
126 g_free (to_close -> modelgl -> measure_win);
127 }
128 if (to_close -> modelgl -> volume_win)
129 {
130 to_close -> modelgl -> volume_win -> win = destroy_this_widget (to_close -> modelgl -> volume_win -> win);
131 g_free (to_close -> modelgl -> volume_win);
132 }
133 if (to_close -> modelgl -> player)
134 {
135 to_close -> modelgl -> player -> win = destroy_this_widget (to_close -> modelgl -> player -> win);
136 g_free (to_close -> modelgl -> player);
137 }
138 if (to_close -> modelgl -> spiner)
139 {
140 to_close -> modelgl -> spiner -> win = destroy_this_widget (to_close -> modelgl -> spiner -> win);
141 g_free (to_close -> modelgl -> spiner);
142 }
143 if (to_close -> modelgl -> rec)
144 {
145 to_close -> modelgl -> rec -> win = destroy_this_widget (to_close -> modelgl -> rec -> win);
146 g_free (to_close -> modelgl -> rec);
147 }
148 if (to_close -> modelgl -> atom_win)
149 {
150 to_close -> modelgl -> atom_win -> win = destroy_this_widget (to_close -> modelgl -> atom_win -> win);
151 g_free (to_close -> modelgl -> atom_win);
152 }
153 if (to_close -> modelgl -> cell_win)
154 {
155 to_close -> modelgl -> cell_win -> win = destroy_this_widget (to_close -> modelgl -> cell_win -> win);
156 g_free (to_close -> modelgl -> cell_win);
157 }
158 if (to_close -> modelgl -> builder_win)
159 {
160 to_close -> modelgl -> builder_win -> win = destroy_this_widget (to_close -> modelgl -> builder_win -> win);
161 g_free (to_close -> modelgl -> builder_win);
162 }
163 if (to_close -> modelgl -> coord_win)
164 {
165 to_close -> modelgl -> coord_win -> win = destroy_this_widget (to_close -> modelgl -> coord_win -> win);
166 g_free (to_close -> modelgl -> coord_win);
167 }
168 for (i=0; i<2; i++)
169 {
170 if (to_close -> modelgl -> model_win[i])
171 {
172 to_close -> modelgl -> model_win[i] -> win = destroy_this_widget (to_close -> modelgl -> model_win[i] -> win);
173 g_free (to_close -> modelgl -> model_win[i]);
174 }
175 }
176 if (to_close -> modelgl -> opengl_win)
177 {
178 to_close -> modelgl -> opengl_win -> win = destroy_this_widget (to_close -> modelgl -> opengl_win -> win);
179 g_free (to_close -> modelgl -> opengl_win);
180 }
181 to_close -> modelgl -> win = destroy_this_widget (to_close -> modelgl -> win);
182 for (i=0; i<NGLOBAL_SHADERS; i++) cleaning_shaders (to_close -> modelgl, i);
183 g_free (to_close -> modelgl);
184 if (to_close -> modelfc)
185 {
186 for (i=0; i< to_close -> steps; i++)
187 {
188 g_free (to_close -> modelfc -> mols[i]);
189 }
190 }
191 }
192 if (to_close -> atoms)
193 {
194 for (i=0; i<to_close -> steps; i++)
195 {
196 if (to_close -> atoms[i]) g_free (to_close -> atoms[i]);
197 }
198 g_free (to_close -> atoms);
199 }
200 if (to_close -> run)
201 {
202 for (i=0 ; i<NGRAPHS ; i++)
203 {
204 to_close -> visok[i]=FALSE;
205 if (to_close -> curves[i])
206 {
207 hide_curves (to_close, i);
208 erase_curves (to_close, i);
209 }
210 }
211 }
212 clean_view ();
213 if (nprojects == 1)
214 {
216 workzone.first = NULL;
217 workzone.last = NULL;
218 activep = -1;
219 correct_this_window_title (MainWindow, g_strdup_printf ("%s", PACKAGE));
220 correct_this_window_title (curvetoolbox, g_strdup_printf ("Toolboxes"));
221 if (workspacefile != NULL)
222 {
223 g_free (workspacefile);
224 workspacefile = NULL;
225 }
226 newspace = TRUE;
227 }
228 else if (nprojects > 1)
229 {
230 if (to_close == workzone.first)
231 {
232 workzone.first = workzone.first -> next;
233 workzone.first -> prev = NULL;
234 }
235 else if (to_close == workzone.last)
236 {
237 workzone.last = workzone.last -> prev;
238 workzone.last -> next = NULL;
239 }
240 else
241 {
242 to_close -> prev -> next = to_close -> next;
243 to_close -> next -> prev = to_close -> prev;
244 }
245 }
246 g_free (to_close);
247 nprojects --;
248 if (nprojects)
249 {
250 project * this_proj = workzone.first;
251 for (i=0 ; i<nprojects ; i++)
252 {
253 this_proj -> id = i;
254 if (this_proj -> initgl && this_proj -> modelgl)
255 {
256 this_proj -> modelgl -> proj = i;
257 for (j=0; j<NUM_COLORS; j++)
258 {
259 for (k=0; k<this_proj -> nspec*2; k++)
260 {
261 this_proj -> modelgl -> colorp[j][k].a = i;
262 }
263 }
264 for (j=0; j<10; j++)
265 {
266 if (this_proj -> modelgl -> gcid[j] != NULL)
267 {
268 for (k=0; k<this_proj -> coord -> totcoord[j]; k++)
269 {
270 for (l=0; l<NUM_COLORS; l++)
271 {
272 this_proj -> modelgl -> gcid[j][k][l].a = i;
273 }
274 }
275 }
276 }
277 if (this_proj -> modelgl -> atom_win)
278 {
279 for (j=0; j<8; j++)
280 {
281 if (this_proj -> modelgl -> search_widg[j])
282 {
283 for (k=0; k<3; k++) this_proj -> modelgl -> search_widg[j] -> pointer[k].a = i;
284 }
285 }
286 }
287 }
288 for (j=0; j<NGRAPHS; j++)
289 {
290 if (this_proj -> idcc[j] != NULL)
291 {
292 for (k=0; k<this_proj -> numc[j]; k++)
293 {
294 this_proj -> idcc[j][k].a = i;
295 }
296 }
297 }
298 if (this_proj -> next != NULL) this_proj = this_proj -> next;
299 }
300 this_proj = workzone.first;
301 for (i=0 ; i<nprojects ; i++)
302 {
303 this_proj -> id = i;
304 for (j=0; j<NGRAPHS; j++)
305 {
306 for (k=0; k<this_proj -> numc[j]; k++)
307 {
308 if (this_proj -> curves[j][k] -> window)
309 {
310 curve_window_add_menu_bar (& this_proj -> idcc[j][k]);
311 if (is_the_widget_visible(this_proj -> curves[j][k] -> plot))
312 {
313 gtk_widget_queue_draw (this_proj -> curves[j][k] -> plot);
314 }
315 }
316 }
317 }
318 if (this_proj -> next != NULL) this_proj = this_proj -> next;
319 }
320 }
322}
323
332void to_close_this_project (int to_activate, project * this_proj)
333{
334 if (nprojects > 0) close_project (this_proj);
335 if (nprojects > 0)
336 {
337 activate_project (NULL, GINT_TO_POINTER(to_activate));
338 }
339 else
340 {
342 active_project = NULL;
344 }
345}
346
355G_MODULE_EXPORT void on_close_activate (GtkWidget * widg, gpointer cdata)
356{
357 if (nprojects > 0)
358 {
359 int i = GPOINTER_TO_INT(cdata);
360 int j = activep;
361 if (j >= i && j > 0) j--;
362 gtk_tree_store_clear (tool_model);
365 if (nprojects > 0)
366 {
367 activate_project (NULL, GINT_TO_POINTER(j));
368 }
369 else
370 {
372 active_project = NULL;
374 }
375 }
376 else
377 {
378 show_warning ("No project to be closed", MainWindow);
379 }
380}
Binding to the Fortran90 subroutines.
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:87
GtkWidget * builder_win(project *this_proj, gpointer data)
create crystal builder window
GtkTreeModel * replace_combo_tree(gboolean insert, int proj)
replace combo box in the tree view
Definition w_search.c:2626
void close_project(project *to_close)
close a project
Definition close_p.c:91
GtkTreeStore * tool_model
Definition tools.c:60
void update_insert_combos()
update some GtkComboBox in the workspace if a project is removed
Definition close_p.c:60
void to_close_this_project(int to_activate, project *this_proj)
to close this project
Definition close_p.c:332
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:355
color colorp[64]
#define PACKAGE
Definition config.h:46
void erase_curves(project *this_proj, int c)
free all curve(s) data
Definition curve.c:526
void hide_curves(project *this_proj, int c)
for project hide all curves for a calculation
Definition curve.c:451
Variable declarations for the curve widget Functions for interactions with the curve widget.
void curve_window_add_menu_bar(tint *data)
add menu bar to the curve window
Definition m_curve.c:614
int atoms[NUM_STYLES][2]
gchar * workspacefile
Definition global.c:156
gboolean newspace
Definition global.c:181
int activep
Definition global.c:159
int nprojects
Definition global.c:158
GtkWidget * MainWindow
Definition global.c:201
GtkWidget * curvetoolbox
Definition global.c:205
Global variable declarations Global convenience function declarations Global data structure defin...
workspace workzone
Definition project.c:46
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:724
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:944
project * proj
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
#define NGRAPHS
void remove_edition_and_analyze_actions()
remove all edition and analysis action
Definition gui.c:433
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2169
struct model model
data structure to describe the topology
Definition global.h:830
project * active_project
Definition project.c:47
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
image * plot
Definition ogl_draw.c:70
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
struct box box
box layout data structure
Definition glwin.h:349
#define NUM_COLORS
Definition glwin.h:65
#define NGLOBAL_SHADERS
Definition glwin.h:69
void clean_view()
clean the main window
Definition gui.c:286
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
Messaging function declarations.
void prep_calc_actions()
prepare analysis widgets
Definition update_p.c:58
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:351
project * last
Definition global.h:1050
project * first
Definition global.h:1049
int a
Definition tab-1.c:95
void remove_project_from_workspace(int id)
remove project from workspace
Definition workspace.c:666
void correct_this_window_title(GtkWidget *win, gchar *str)
use new title for GtkWindow, providing it exists
Definition workspace.c:337
G_MODULE_EXPORT void activate_project(GtkWidget *widg, gpointer data)
activate a project
Definition workspace.c:191
Function declarations for workspace managment.