atomes 1.3.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-2026 by CNRS and University of Strasbourg */
15
22
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 glwin * free_glwin (project * to_close, glwin * to_clow);
36
37 void update_insert_combos ();
38 void close_project (project * to_close);
39
40 void to_close_this_project (int to_activate, project * this_proj);
41 G_MODULE_EXPORT void on_close_activate (GtkWidget * widg, gpointer cdata);
42
43*/
44
45#include "global.h"
46#include "bind.h"
47#include "callbacks.h"
48#include "interface.h"
49#include "project.h"
50#include "workspace.h"
51#include "curve.h"
52#include "glview.h"
53
54extern GtkTreeStore * tool_model;
55extern GtkTreeModel * replace_combo_tree (gboolean insert, int proj);
56extern G_MODULE_EXPORT void spin_stop (GtkButton * but, gpointer data);
57extern void clean_animation (project * proj, glwin * view);
58extern void free_glwin_spec_data (project * this_proj, int spec);
59
66{
67 GtkTreeModel * model;
68 project * this_proj;
69 GtkWidget * box;
70 int i;
71 for (i=0; i<nprojects; i++)
72 {
73 this_proj = get_project_by_id(i);
74 if (this_proj -> modelgl)
75 {
76 if ((this_proj -> modelgl -> atom_win && this_proj -> modelgl -> atom_win -> visible) || this_proj -> modelgl -> builder_win)
77 {
78 model = replace_combo_tree (TRUE, i);
79 box = (this_proj -> modelgl -> builder_win) ? this_proj -> modelgl -> builder_win -> add_combo : this_proj -> modelgl -> atom_win -> atom_combo[3];
80 gtk_combo_box_set_model (GTK_COMBO_BOX(box), model);
83 g_object_unref (model);
84 }
85 }
86 }
87}
88
97glwin * free_glwin (project * to_close, glwin * to_clow)
98{
99 int i, j, k;
100 if (to_clow -> color_to_pick != NULL)
101 {
102 g_free (to_clow -> color_to_pick);
103 to_clow -> color_to_pick = NULL;
104 }
105
106#ifdef GTK3
107 for (i=0; i<2; i++)
108 {
109 g_free (to_clow -> ogl_box_axis[i]);
110 for (j=0; j<10; j++)
111 {
112 if (to_clow -> ogl_geom[i][j]) g_free (to_clow -> ogl_geom[i][j]);
113 if (to_clow -> oglmv[i][j]) g_free (to_clow -> oglmv[i][j]);
114 if (j < 9)
115 {
116 if (to_clow -> ogl_poly[i][j]) g_free (to_clow -> ogl_poly[i][j]);
117 if (to_clow -> oglmc[i][j]) g_free (to_clow -> oglmc[i][j]);
118 }
119 }
120 }
121#endif
122 for (i=0; i<10; i++)
123 {
124 if (to_clow -> gcid[i])
125 {
126 for (j=0; j < to_close -> coord -> totcoord[i]; j++)
127 {
128 if (to_clow -> gcid[i][j])
129 {
130 g_free (to_clow -> gcid[i][j]);
131 }
132 }
133 g_free (to_clow -> gcid[i]);
134 }
135 }
136 for (i=0; i<to_close -> steps; i++)
137 {
138 if (to_clow -> bondid[i])
139 {
140 for (j=0; j<2; j++)
141 {
142 if (to_clow -> bondid[i][j])
143 {
144 for (k=0; k<to_clow -> bonds[i][j]; k++)
145 {
146 if (to_clow -> bondid[i][j][k]) g_free(to_clow -> bondid[i][j][k]);
147 }
148 g_free(to_clow -> bondid[i][j]);
149 }
150 }
151 g_free(to_clow -> bondid[i]);
152 }
153 if (to_clow -> clones[i]) g_free(to_clow -> clones[i]);
154 }
155
156 if (to_clow -> bondid) g_free(to_clow -> bondid);
157 if (to_clow -> clones) g_free(to_clow -> clones);
158
159 free_glwin_spec_data (to_close, to_close -> nspec);
160
161 if (to_clow -> rep_win)
162 {
163 to_clow -> rep_win -> win = destroy_this_widget (to_clow -> rep_win -> win);
164 g_free (to_clow -> rep_win);
165 }
166 if (to_clow -> gradient_win)
167 {
168 to_clow -> gradient_win -> win = destroy_this_widget (to_clow -> gradient_win -> win);
169 g_free (to_clow -> gradient_win);
170 }
171 if (to_clow -> box_win)
172 {
173 to_clow -> box_win -> win = destroy_this_widget (to_clow -> box_win -> win);
174 g_free (to_clow -> box_win);
175 }
176 if (to_clow -> axis_win)
177 {
178 to_clow -> axis_win -> win = destroy_this_widget (to_clow -> axis_win -> win);
179 g_free (to_clow -> axis_win);
180 }
181 if (to_clow -> measure_win)
182 {
183 to_clow -> measure_win -> win = destroy_this_widget (to_clow -> measure_win -> win);
184 g_free (to_clow -> measure_win);
185 }
186 if (to_clow -> volume_win)
187 {
188 to_clow -> volume_win -> win = destroy_this_widget (to_clow -> volume_win -> win);
189 g_free (to_clow -> volume_win);
190 }
191 if (to_clow -> player)
192 {
193 to_clow -> player -> win = destroy_this_widget (to_clow -> player -> win);
194 g_free (to_clow -> player);
195 }
196 // Stop the spinning if any
197 spin_stop (NULL, to_clow);
198 if (to_clow -> spiner)
199 {
200 to_clow -> spiner -> win = destroy_this_widget (to_clow -> spiner -> win);
201 g_free (to_clow -> spiner);
202 }
203 if (to_clow -> rec)
204 {
205 to_clow -> rec -> win = destroy_this_widget (to_clow -> rec -> win);
206 g_free (to_clow -> rec);
207 }
208 if (to_clow -> atom_win)
209 {
210 to_clow -> atom_win -> win = destroy_this_widget (to_clow -> atom_win -> win);
211 g_free (to_clow -> atom_win);
212 }
213 if (to_clow -> cell_win)
214 {
215 to_clow -> cell_win -> win = destroy_this_widget (to_clow -> cell_win -> win);
216 g_free (to_clow -> cell_win);
217 }
218 if (to_clow -> builder_win)
219 {
220 to_clow -> builder_win -> win = destroy_this_widget (to_clow -> builder_win -> win);
221 g_free (to_clow -> builder_win);
222 }
223 if (to_clow -> coord_win)
224 {
225 to_clow -> coord_win -> win = destroy_this_widget (to_clow -> coord_win -> win);
226 g_free (to_clow -> coord_win);
227 }
228 for (i=0; i<2; i++)
229 {
230 if (to_clow -> model_win[i])
231 {
232 to_clow -> model_win[i] -> win = destroy_this_widget (to_clow -> model_win[i] -> win);
233 g_free (to_clow -> model_win[i]);
234 }
235 }
236 if (to_clow -> opengl_win)
237 {
238 to_clow -> opengl_win -> win = destroy_this_widget (to_clow -> opengl_win -> win);
239 g_free (to_clow -> opengl_win);
240 }
241 to_clow -> win = destroy_this_widget (to_clow -> win);
242 for (i=0; i<NGLOBAL_SHADERS; i++)
243 {
244 cleaning_shaders (to_clow, i);
245 g_free (to_clow -> ogl_glsl[i]);
246 g_free (to_clow -> n_shaders[i]);
247 }
248 clean_animation (to_close, to_clow);
249 g_free (to_clow);
250 return NULL;
251}
252
260void close_project (project * to_close)
261{
262 int i, j, k, l;
263
264#ifdef DEBUG
265 g_debug ("CLOSE_PROJECT: proj to close= %d", to_close -> id);
266 g_debug ("CLOSE_PROJECT: nprojects = %d", nprojects);
267 g_debug ("CLOSE_PROJECT: activep = %d", activep);
268 if (to_close -> pixels)
269 {
270 for (i=0; i<active_project -> pix[0]*active_project -> pix[1]*active_project -> pix[2]; i++)
271 {
272 g_free (to_close -> pixels[i]);
273 }
274 g_free (to_close -> pixels);
275 }
276#endif
277
278 if (to_close -> modelgl)
279 {
280 to_close -> modelgl = free_glwin (to_close, to_close -> modelgl);
281 if (to_close -> modelfc)
282 {
283 if (to_close -> modelfc -> mols)
284 {
285 for (i=0; i< to_close -> steps; i++)
286 {
287 if (to_close -> modelfc -> mols[i])
288 {
289 for (j=0; j<to_close -> modelfc -> mol_by_step[i]; j++)
290 {
291 g_free (to_close -> modelfc -> mols[i][j].fragments);
292 g_free (to_close -> modelfc -> mols[i][j].species);
293 }
294 g_free (to_close -> modelfc -> mols[i]);
295 }
296 }
297 g_free (to_close -> modelfc -> mols);
298 }
299 }
300 }
301 if (to_close -> atoms)
302 {
303 for (i=0; i<to_close -> steps; i++)
304 {
305 for (j=0; j<to_close -> natomes; j++)
306 {
307 g_free (to_close -> atoms[i][j].vois);
308 }
309 if (to_close -> atoms[i]) g_free (to_close -> atoms[i]);
310 }
311 g_free (to_close -> atoms);
312 }
313 if (to_close -> cell.box) g_free (to_close -> cell.box);
314 if (to_close -> cell.sp_group) g_free (to_close -> cell.sp_group);
315
316 if (to_close -> run)
317 {
318 if (to_close -> analysis)
319 {
320 for (i=0 ; i<NCALCS ; i++)
321 {
322 if (to_close -> analysis[i])
323 {
324 to_close -> analysis[i] -> calc_ok = FALSE;
325 if (to_close -> analysis[i] -> name) g_free (to_close -> analysis[i] -> name);
326 if (to_close -> analysis[i] -> x_title) g_free (to_close -> analysis[i] -> x_title);
327 if (to_close -> analysis[i] -> compat_id) g_free (to_close -> analysis[i] -> compat_id);
328 if (to_close -> analysis[i] -> curves)
329 {
330 hide_curves (to_close, i);
331 erase_curves (to_close, i);
332 g_free (to_close -> analysis[i] -> idcc);
333 g_free (to_close -> analysis[i] -> curves);
334 }
335 g_free (to_close -> analysis[i]);
336 }
337 }
338 g_free (to_close -> analysis);
339 }
340 }
341
343 g_free (to_close -> projfile);
344
345 if (nprojects > 1)
346 {
347 if (to_close == workzone.first)
348 {
349 workzone.first = workzone.first -> next;
350 workzone.first -> prev = NULL;
351 }
352 else if (to_close == workzone.last)
353 {
354 workzone.last = workzone.last -> prev;
355 workzone.last -> next = NULL;
356 }
357 else
358 {
359 to_close -> prev -> next = to_close -> next;
360 to_close -> next -> prev = to_close -> prev;
361 }
362 }
363 else if (! atomes_render_image)
364 {
365 // if (workzone.first) g_free (workzone.first);
366 workzone.first = NULL;
367 // if (workzone.last) g_free (workzone.last);
368 workzone.last = NULL;
369 activep = -1;
370 correct_this_window_title (MainWindow, g_strdup_printf ("%s", PACKAGE));
371 correct_this_window_title (curvetoolbox, g_strdup_printf (_("Toolboxes")));
372 if (workspacefile != NULL)
373 {
374 g_free (workspacefile);
375 workspacefile = NULL;
376 }
377 newspace = TRUE;
378 }
379 g_free (to_close);
380 nprojects --;
381
382 if (nprojects)
383 {
384 project * this_proj = workzone.first;
385 for (i=0 ; i<nprojects ; i++)
386 {
387 this_proj -> id = i;
388 if (this_proj -> initgl && this_proj -> modelgl)
389 {
390 this_proj -> modelgl -> proj = i;
391 for (j=0; j<NUM_COLORS; j++)
392 {
393 for (k=0; k<this_proj -> nspec*2; k++)
394 {
395 this_proj -> modelgl -> colorp[j][k].a = i;
396 }
397 }
398 for (j=0; j<10; j++)
399 {
400 if (this_proj -> modelgl -> gcid[j] != NULL)
401 {
402 for (k=0; k<this_proj -> coord -> totcoord[j]; k++)
403 {
404 for (l=0; l<NUM_COLORS; l++)
405 {
406 this_proj -> modelgl -> gcid[j][k][l].a = i;
407 }
408 }
409 }
410 }
411 if (this_proj -> modelgl -> atom_win)
412 {
413 for (j=0; j<8; j++)
414 {
415 if (this_proj -> modelgl -> search_widg[j])
416 {
417 for (k=0; k<3; k++) this_proj -> modelgl -> search_widg[j] -> pointer[k].a = i;
418 }
419 }
420 }
421 }
422 if (this_proj -> analysis)
423 {
424 for (j=0; j<NCALCS; j++)
425 {
426 if (this_proj -> analysis[j])
427 {
428 if (this_proj -> analysis[j] -> idcc != NULL)
429 {
430 for (k=0; k<this_proj -> analysis[j] -> numc; k++)
431 {
432 this_proj -> analysis[j] -> idcc[k].a = i;
433 }
434 }
435 }
436 }
437 }
438 if (this_proj -> next != NULL) this_proj = this_proj -> next;
439 }
440 this_proj = workzone.first;
441 for (i=0 ; i<nprojects ; i++)
442 {
443 this_proj -> id = i;
444 if (this_proj -> analysis)
445 {
446 for (j=0; j<NCALCS; j++)
447 {
448 if (this_proj -> analysis[j])
449 {
450 for (k=0; k<this_proj -> analysis[j] -> numc; k++)
451 {
452 if (this_proj -> analysis[j] -> curves[k] -> window)
453 {
454 curve_window_add_menu_bar (& this_proj -> analysis[j] -> idcc[k]);
455 if (is_the_widget_visible(this_proj -> analysis[j] -> curves[k] -> plot))
456 {
457 gtk_widget_queue_draw (this_proj -> analysis[j] -> curves[k] -> plot);
458 }
459 }
460 }
461 }
462 }
463 }
464 if (this_proj -> next != NULL) this_proj = this_proj -> next;
465 }
466 }
467
469}
470
479void to_close_this_project (int to_activate, project * this_proj)
480{
481 if (nprojects > 0) close_project (this_proj);
482 if (nprojects > 0)
483 {
484 int new_p = (to_activate >= nprojects) ? nprojects - 1 : to_activate;
485 activate_project (NULL, GINT_TO_POINTER(new_p));
486 }
488 {
490 active_project = NULL;
492 }
493}
494
503G_MODULE_EXPORT void on_close_activate (GtkWidget * widg, gpointer cdata)
504{
505 if (nprojects > 0)
506 {
507 int i = GPOINTER_TO_INT(cdata);
508 int j = activep;
509 if (j >= i && j > 0) j--;
510 gtk_tree_store_clear (tool_model);
513 if (nprojects > 0)
514 {
515 activate_project (NULL, GINT_TO_POINTER(j));
516 }
517 else
518 {
520 active_project = NULL;
522 }
523 }
524 else
525 {
526 show_warning (_("No project to be closed"), MainWindow);
527 }
528}
Binding to the Fortran90 subroutines.
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:91
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:2612
void close_project(project *to_close)
close a project
Definition close_p.c:260
void update_insert_combos()
update some GtkComboBox in the workspace if a project is removed
Definition close_p.c:65
void free_glwin_spec_data(project *this_proj, int spec)
free the memory used by the chemical species related data in a glwin data structure
Definition glview.c:1602
void to_close_this_project(int to_activate, project *this_proj)
to close this project
Definition close_p.c:479
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:503
glwin * free_glwin(project *to_close, glwin *to_clow)
free all memory related to a gliwn data structure
Definition close_p.c:97
G_MODULE_EXPORT void spin_stop(GtkButton *but, gpointer data)
stop spin
Definition w_spiner.c:155
void clean_animation(project *proj, glwin *view)
clean saved animation data
Definition w_encode.c:324
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:552
void hide_curves(project *this_proj, int c)
for project hide all curves for a calculation
Definition curve.c:472
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:625
int atoms[NUM_STYLES][2]
int bonds[NUM_STYLES][2]
gchar * workspacefile
Definition global.c:159
gboolean newspace
Definition global.c:185
int activep
Definition global.c:162
int nprojects
Definition global.c:161
GtkWidget * MainWindow
Definition global.c:207
gchar * projfile
Definition global.c:144
gboolean atomes_render_image
Definition global.c:196
GtkWidget * curvetoolbox
Definition global.c:211
gboolean atomes_from_libreoffice
Definition global.c:195
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:183
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:970
project * proj
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
void remove_edition_and_analyze_actions()
remove all edition and analysis action
Definition gui.c:575
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
project * active_project
Definition project.c:47
#define NCALCS
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:72
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
#define NUM_COLORS
Definition glwin.h:65
#define NGLOBAL_SHADERS
Definition glwin.h:69
void clean_view()
clean the main window
Definition gui.c:288
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:350
Definition glwin.h:967
GtkTreeStore * tool_model
Definition tools.c:60
GdkPixbuf * pix
Definition workspace.c:69
void remove_project_from_workspace(int id)
remove project from workspace
Definition workspace.c:653
void correct_this_window_title(GtkWidget *win, gchar *str)
use new title for GtkWindow, providing it exists
Definition workspace.c:324
G_MODULE_EXPORT void activate_project(GtkWidget *widg, gpointer data)
activate a project
Definition workspace.c:179
Function declarations for workspace managment.