atomes 1.1.15
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-2024 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 GList * cell_list;
65 GtkWidget * box;
66 int i;
67 for (i=0; i<nprojects; i++)
68 {
69 this_proj = get_project_by_id(i);
70 if (this_proj -> modelgl)
71 {
72 if ((this_proj -> modelgl -> atom_win && this_proj -> modelgl -> atom_win -> visible) || this_proj -> modelgl -> builder_win)
73 {
74 model = replace_combo_tree (TRUE, i);
75 box = (this_proj -> modelgl -> builder_win) ? this_proj -> modelgl -> builder_win -> add_combo : this_proj -> modelgl -> atom_win -> atom_combo[3];
76 gtk_combo_box_set_model (GTK_COMBO_BOX(box), model);
77 gtk_combo_box_set_active (GTK_COMBO_BOX(box), 0);
78 cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(box));
79 if (cell_list && cell_list -> data)
80 {
81 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(box), cell_list -> data, "markup", 0, NULL);
82 }
83 g_object_unref (model);
84 }
85 }
86 }
87}
88
96void close_project (project * to_close)
97{
98 int i, j, k, l;
99
100#ifdef DEBUG
101 g_debug ("CLOSE_PROJECT: proj to close= %d", to_close -> id);
102 g_debug ("CLOSE_PROJECT: nprojects = %d", nprojects);
103 g_debug ("CLOSE_PROJECT: activep = %d", activep);
104#endif
105
106 if (to_close -> initgl)
107 {
108 if (to_close -> modelgl -> measure_win)
109 {
110 to_close -> modelgl -> measure_win -> win = destroy_this_widget (to_close -> modelgl -> measure_win -> win);
111 g_free (to_close -> modelgl -> measure_win);
112 }
113 if (to_close -> modelgl -> volume_win)
114 {
115 to_close -> modelgl -> volume_win -> win = destroy_this_widget (to_close -> modelgl -> volume_win -> win);
116 g_free (to_close -> modelgl -> volume_win);
117 }
118 if (to_close -> modelgl -> player)
119 {
120 to_close -> modelgl -> player -> win = destroy_this_widget (to_close -> modelgl -> player -> win);
121 g_free (to_close -> modelgl -> player);
122 }
123 if (to_close -> modelgl -> spiner)
124 {
125 to_close -> modelgl -> spiner -> win = destroy_this_widget (to_close -> modelgl -> spiner -> win);
126 g_free (to_close -> modelgl -> spiner);
127 }
128 if (to_close -> modelgl -> rec)
129 {
130 to_close -> modelgl -> rec -> win = destroy_this_widget (to_close -> modelgl -> rec -> win);
131 g_free (to_close -> modelgl -> rec);
132 }
133 if (to_close -> modelgl -> atom_win)
134 {
135 to_close -> modelgl -> atom_win -> win = destroy_this_widget (to_close -> modelgl -> atom_win -> win);
136 g_free (to_close -> modelgl -> atom_win);
137 }
138 if (to_close -> modelgl -> cell_win)
139 {
140 to_close -> modelgl -> cell_win -> win = destroy_this_widget (to_close -> modelgl -> cell_win -> win);
141 g_free (to_close -> modelgl -> cell_win);
142 }
143 if (to_close -> modelgl -> builder_win)
144 {
145 to_close -> modelgl -> builder_win -> win = destroy_this_widget (to_close -> modelgl -> builder_win -> win);
146 g_free (to_close -> modelgl -> builder_win);
147 }
148 if (to_close -> modelgl -> coord_win)
149 {
150 to_close -> modelgl -> coord_win -> win = destroy_this_widget (to_close -> modelgl -> coord_win -> win);
151 g_free (to_close -> modelgl -> coord_win);
152 }
153 for (i=0; i<2; i++)
154 {
155 if (to_close -> modelgl -> model_win[i])
156 {
157 to_close -> modelgl -> model_win[i] -> win = destroy_this_widget (to_close -> modelgl -> model_win[i] -> win);
158 g_free (to_close -> modelgl -> model_win[i]);
159 }
160 }
161 if (to_close -> modelgl -> opengl_win)
162 {
163 to_close -> modelgl -> opengl_win -> win = destroy_this_widget (to_close -> modelgl -> opengl_win -> win);
164 g_free (to_close -> modelgl -> opengl_win);
165 }
166 to_close -> modelgl -> win = destroy_this_widget (to_close -> modelgl -> win);
167 for (i=0; i<NGLOBAL_SHADERS; i++) cleaning_shaders (to_close -> modelgl, i);
168 g_free (to_close -> modelgl);
169 if (to_close -> modelfc)
170 {
171 for (i=0; i< to_close -> steps; i++)
172 {
173 g_free (to_close -> modelfc -> mols[i]);
174 }
175 }
176 }
177 if (to_close -> run)
178 {
179 for (i=0 ; i<NGRAPHS ; i++)
180 {
181 to_close -> visok[i]=FALSE;
182 if (to_close -> curves[i])
183 {
184 hide_curves (to_close, i);
185 erase_curves (to_close, i);
186 }
187 }
188 }
189 clean_view ();
190 if (nprojects == 1)
191 {
193 workzone.first = NULL;
194 workzone.last = NULL;
195 activep = -1;
196 correct_this_window_title (MainWindow, g_strdup_printf ("%s", PACKAGE));
197 correct_this_window_title (curvetoolbox, g_strdup_printf ("Toolboxes"));
198 if (workspacefile != NULL)
199 {
200 g_free (workspacefile);
201 workspacefile = NULL;
202 }
203 newspace = TRUE;
204 }
205 else if (nprojects > 1)
206 {
207 if (to_close == workzone.first)
208 {
209 workzone.first = workzone.first -> next;
210 workzone.first -> prev = NULL;
211 }
212 else if (to_close == workzone.last)
213 {
214 workzone.last = workzone.last -> prev;
215 workzone.last -> next = NULL;
216 }
217 else
218 {
219 to_close -> prev -> next = to_close -> next;
220 to_close -> next -> prev = to_close -> prev;
221 }
222 g_free (to_close);
223 }
224 nprojects --;
225 if (nprojects)
226 {
227 project * this_proj = workzone.first;
228 for (i=0 ; i<nprojects ; i++)
229 {
230 this_proj -> id = i;
231 if (this_proj -> initgl)
232 {
233 this_proj -> modelgl -> proj = i;
234 for (j=0; j<NUM_COLORS; j++)
235 {
236 for (k=0; k<this_proj -> nspec*2; k++)
237 {
238 this_proj -> modelgl -> colorp[j][k].a = i;
239 }
240 }
241 for (j=0; j<10; j++)
242 {
243 if (this_proj -> modelgl -> gcid[j] != NULL)
244 {
245 for (k=0; k<this_proj -> coord -> totcoord[j]; k++)
246 {
247 for (l=0; l<NUM_COLORS; l++)
248 {
249 this_proj -> modelgl -> gcid[j][k][l].a = i;
250 }
251 }
252 }
253 }
254 if (this_proj -> modelgl -> atom_win)
255 {
256 for (j=0; j<8; j++)
257 {
258 if (this_proj -> modelgl -> search_widg[j])
259 {
260 for (k=0; k<3; k++) this_proj -> modelgl -> search_widg[j] -> pointer[k].a = i;
261 }
262 }
263 }
264 }
265 for (j=0; j<NGRAPHS; j++)
266 {
267 if (this_proj -> idcc[j] != NULL)
268 {
269 for (k=0; k<this_proj -> numc[j]; k++)
270 {
271 this_proj -> idcc[j][k].a = i;
272 }
273 }
274 }
275 if (this_proj -> next != NULL) this_proj = this_proj -> next;
276 }
277 this_proj = workzone.first;
278 for (i=0 ; i<nprojects ; i++)
279 {
280 this_proj -> id = i;
281 for (j=0; j<NGRAPHS; j++)
282 {
283 for (k=0; k<this_proj -> numc[j]; k++)
284 {
285 if (this_proj -> curves[j][k] -> window)
286 {
287 curve_window_add_menu_bar (& this_proj -> idcc[j][k]);
288 if (is_the_widget_visible(this_proj -> curves[j][k] -> plot))
289 {
290 gtk_widget_queue_draw (this_proj -> curves[j][k] -> plot);
291 }
292 }
293 }
294 }
295 if (this_proj -> next != NULL) this_proj = this_proj -> next;
296 }
297 }
299}
300
309void to_close_this_project (int to_activate, project * this_proj)
310{
311 if (nprojects > 0) close_project (this_proj);
312 if (nprojects > 0)
313 {
314 activate_project (NULL, GINT_TO_POINTER(to_activate));
315 }
316 else
317 {
319 active_project = NULL;
321 }
322}
323
332G_MODULE_EXPORT void on_close_activate (GtkWidget * widg, gpointer cdata)
333{
334 if (nprojects > 0)
335 {
336 int i = GPOINTER_TO_INT(cdata);
337 int j = activep;
338 if (j >= i && j > 0) j--;
339 gtk_tree_store_clear (tool_model);
342 if (nprojects > 0)
343 {
344 activate_project (NULL, GINT_TO_POINTER(j));
345 }
346 else
347 {
349 active_project = NULL;
351 }
352 }
353 else
354 {
355 show_warning ("No project to be closed", MainWindow);
356 }
357}
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:2615
void close_project(project *to_close)
close a project
Definition close_p.c:96
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:309
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:332
color colorp[64]
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:612
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:714
project * proj
struct model model
data structure to describe the topology
Definition global.h:825
#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:2034
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:66
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: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...
project * last
Definition global.h:1045
project * first
Definition global.h:1044
int a
Definition tab-1.c:95
void remove_project_from_workspace(int id)
remove project from workspace
Definition workspace.c:650
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.