1 /* Status.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 
10   The above copyright notice and this permission notice shall be included in all copies or substantial portions
11   of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19 
20 
21 #include "../../Config.h"
22 #include "GlobalOrb.h"
23 #include "Orbitals.h"
24 #include "../Utils/Vector3d.h"
25 #include "../Utils/Transformation.h"
26 #include "../Utils/Utils.h"
27 #include "../Utils/UtilsInterface.h"
28 
29 static GtkWidget *ProgressBar = NULL;
30 static	GtkWidget* Status[2][4];
31 static	GtkWidget *StatusProgress = NULL;
32 static	GtkWidget *button = NULL;
33 static  GtkWidget *handleboxStatus = NULL;
34 static GtkWidget *tableProgressBar = NULL;
35 /********************************************************************************/
show_handlebox_status(gboolean show)36 void show_handlebox_status(gboolean show)
37 {
38 	if(!handleboxStatus) return;
39 	gtk_widget_hide(handleboxStatus);
40 	if(show) gtk_widget_show(handleboxStatus);
41 }
42 /********************************************************************************/
show_progress_bar(gboolean show)43 void show_progress_bar(gboolean show)
44 {
45 	if(!tableProgressBar) return;
46 	gtk_widget_hide(tableProgressBar);
47 	if(show) gtk_widget_show(tableProgressBar);
48 }
49 /********************************************************************************/
set_button_sensitive(gboolean sens)50 void set_button_sensitive(gboolean sens)
51 {
52 	if(this_is_an_object((GtkObject*)button))
53 		gtk_widget_set_sensitive(button, sens);
54 
55 }
56 /********************************************************************************/
setTextInProgress(gchar * t)57 void setTextInProgress(gchar* t)
58 {
59 
60 	guint idStatus = 0;
61 	idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusProgress),"Testing");
62 	gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
63 	gtk_statusbar_push(GTK_STATUSBAR(StatusProgress),idStatus, t);
64     	while( gtk_events_pending() ) gtk_main_iteration();
65 }
66 /********************************************************************************/
progress_orb_txt(gdouble scal,gchar * str,gboolean reset)67 gint progress_orb_txt(gdouble scal,gchar* str,gboolean reset)
68 {
69 
70 	gdouble new_val;
71 	guint idStatus = 0;
72 
73 	gtk_widget_set_sensitive(button, FALSE);
74 	idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusProgress),"Testing");
75 	gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
76 	if(reset)
77 	{
78 		gtk_widget_show(ProgressBar);
79 		new_val = 0;
80 		gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (ProgressBar), new_val);
81 		gtk_widget_set_sensitive(button, FALSE);
82 
83 		gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
84 		gtk_statusbar_push(GTK_STATUSBAR(StatusProgress),idStatus, str);
85 		while( gtk_events_pending() ) gtk_main_iteration();
86 		return TRUE;
87 	}
88 	else if(scal>0)
89 	{
90     		new_val = gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(ProgressBar) ) + scal;
91 		if (new_val > 1) new_val = 1;
92 	}
93 	else
94 	{
95     		new_val = gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(ProgressBar) ) - scal;
96 		if (new_val > 1) new_val = 1;
97 		if (new_val <0 ) new_val = 0;
98 	}
99 	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (ProgressBar), new_val);
100 	gtk_widget_set_sensitive(button, TRUE);
101 
102 	gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
103 	gtk_statusbar_push(GTK_STATUSBAR(StatusProgress),idStatus, str);
104 	while( gtk_events_pending() ) gtk_main_iteration();
105 
106 	return TRUE;
107 }
108 /********************************************************************************/
progress_orb(gdouble scal,GabEditTypeProgressOrb type,gboolean reset)109 gint progress_orb(gdouble scal,GabEditTypeProgressOrb  type,gboolean reset)
110 {
111 
112 	gdouble new_val;
113 	gchar *t = NULL;
114 	guint idStatus = 0;
115 
116 	if(reset)
117 	{
118 		gtk_widget_show(ProgressBar);
119 		new_val = 0;
120 
121     		gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (ProgressBar), new_val);
122 
123 		gtk_widget_set_sensitive(button, FALSE);
124 		idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusProgress),"Testing");
125 		gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
126 
127 		while( gtk_events_pending() ) gtk_main_iteration();
128 
129 		return TRUE;
130 	}
131 	else
132 		if(scal>0)
133 		{
134     			new_val = gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(ProgressBar) ) + scal;
135 			if (new_val > 1) new_val = 1;
136 		}
137 		else
138 		{
139     			new_val = gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(ProgressBar) ) - scal;
140 			if (new_val > 1) new_val = 1;
141 			if (new_val <0 ) new_val = 0;
142 		}
143 
144 		while( gtk_events_pending() ) gtk_main_iteration();
145 
146     /* Set the new value */
147     gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (ProgressBar), new_val);
148 
149 	switch(type)
150 	{
151 
152 	case GABEDIT_PROGORB_UNK :
153 		t = g_strdup_printf(_(" %.0f%%"),new_val*100);
154 		break;
155 
156 	case  GABEDIT_PROGORB_READGEOM:
157 		t = g_strdup_printf(_(" Geometry Reading : %.0f%%"),new_val*100);
158 		break;
159 	case  GABEDIT_PROGORB_SAVEGEOM:
160 		t = g_strdup_printf(_(" Recording of the geometry : %.0f%%"),new_val*100);
161 		break;
162 	case  GABEDIT_PROGORB_COMPINTEG:
163 		t = g_strdup_printf(_(" Computing of an integral : %.0f%%"),new_val*100);
164 		break;
165 	case GABEDIT_PROGORB_COMPGRID :
166 		if(TypeGrid == GABEDIT_TYPEGRID_EDENSITY)
167 		t = g_strdup_printf(_(" Computing of the electronic density grid : %.0f%%"),new_val*100);
168 		else
169 		if(TypeGrid == GABEDIT_TYPEGRID_ORBITAL)
170 		t = g_strdup_printf(_(" Grid computing for an orbital : %.0f%%"),new_val*100);
171 		else
172 		if(TypeGrid == GABEDIT_TYPEGRID_ELFBECKE || TypeGrid == GABEDIT_TYPEGRID_ELFSAVIN)
173 		t = g_strdup_printf(_(" Grid computing for the ELF : %.0f%%"),new_val*100);
174 		else
175 		if(TypeGrid == GABEDIT_TYPEGRID_FEDELECTROPHILIC)
176 		t = g_strdup_printf(_(" Grid computing for the Electro. susceptibility : %.0f%%"),new_val*100);
177 		else
178 		if(TypeGrid == GABEDIT_TYPEGRID_FEDNUCLEOPHILIC)
179 		t = g_strdup_printf(_(" Grid computing for the Nucleo. susceptibility : %.0f%%"),new_val*100);
180 		else
181 		if(TypeGrid == GABEDIT_TYPEGRID_FEDRADICAL)
182 		t = g_strdup_printf(_(" Grid computing for the Radical. susceptibility : %.0f%%"),new_val*100);
183 		else
184 		t = g_strdup_printf(_(" Grid Computing : %.0f%%"),new_val*100);
185 		break;
186 	case GABEDIT_PROGORB_SCALEGRID :
187 		t = g_strdup_printf(_(" Scale grid : %.0f%%"),new_val*100);
188 		break;
189 	case GABEDIT_PROGORB_SUBSGRID :
190 		t = g_strdup_printf(_(" Substract grid : %.0f%%"),new_val*100);
191 		break;
192 	case GABEDIT_PROGORB_COMPISOSURFACE :
193 		t = g_strdup_printf(_(" Isosurface Computing : %.0f%%"),new_val*100);
194 		break;
195 	case GABEDIT_PROGORB_SAVEGRID :
196 		t = g_strdup_printf(_(" Save Grid : %.0f%%"),new_val*100);
197 		break;
198 	case GABEDIT_PROGORB_READGRID :
199 		t = g_strdup_printf(_(" Grid reading : %.0f%%"),new_val*100);
200 		break;
201 	case GABEDIT_PROGORB_MAPGRID :
202 		t = g_strdup_printf(_(" Grid mapping : %.0f%%"),new_val*100);
203 		break;
204 	case GABEDIT_PROGORB_COMPLAPGRID :
205 		t = g_strdup_printf(_(" Computing of the laplacian of the grid : %.0f%%"),new_val*100);
206 		break;
207 	case GABEDIT_PROGORB_COMPGRADGRID :
208 		t = g_strdup_printf(_(" Computing of the gradient of the grid : %.0f%%"),new_val*100);
209 		break;
210 	case GABEDIT_PROGORB_COMPNCIGRID :
211 		t = g_strdup_printf(_(" Computing NCI from the density grid : %.0f%%"),new_val*100);
212 		break;
213 	case GABEDIT_PROGORB_COMPL2GRID :
214 		t = g_strdup_printf(_(" Computing sign of middle eigenvalue hessian * grid : %.0f%%"),new_val*100);
215 		break;
216 	case GABEDIT_PROGORB_SCANFILEGRID :
217 		t = g_strdup_printf(_(" Scan file for get the total orbitals number ....."));
218 		break;
219 	case GABEDIT_PROGORB_COMPMEPGRID :
220 		t = g_strdup_printf(_(" Computing of the MEP : %.0f%%"),new_val*100);
221 		break;
222 	case GABEDIT_PROGORB_COMPMULTIPOL :
223 		t = g_strdup_printf(_(" Multipole Computing : %.0f%%"),new_val*100);
224 		break;
225 	}
226 	if(type!= GABEDIT_PROGORB_SCANFILEGRID || (type==GABEDIT_PROGORB_SCANFILEGRID && scal==0))
227 	{
228 		idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusProgress),"Testing");
229 		gtk_statusbar_pop(GTK_STATUSBAR(StatusProgress),idStatus);
230 		gtk_statusbar_push(GTK_STATUSBAR(StatusProgress),idStatus, t);
231 	}
232 	if(
233 		type==GABEDIT_PROGORB_READGRID ||
234 		type==GABEDIT_PROGORB_COMPGRID ||
235 		type==GABEDIT_PROGORB_COMPINTEG ||
236 		type == GABEDIT_PROGORB_SCANFILEGRID ||
237 		type==GABEDIT_PROGORB_COMPMULTIPOL ||
238 		type==GABEDIT_PROGORB_COMPLAPGRID ||
239 		type==GABEDIT_PROGORB_COMPGRADGRID ||
240 		type==GABEDIT_PROGORB_COMPNCIGRID ||
241 		type==GABEDIT_PROGORB_COMPL2GRID ||
242 		type==GABEDIT_PROGORB_COMPMEPGRID
243 	)
244 		gtk_widget_set_sensitive(button, TRUE);
245 
246     g_free(t);
247     while( gtk_events_pending() ) gtk_main_iteration();
248 
249     return TRUE;
250 }
251 /***********************************************************/
set_status_label_info(gchar * type,gchar * txt)252 void set_status_label_info(gchar* type,gchar* txt)
253 {
254 	gchar* tlabels[2][4]={{_("File name"),_("File type"),_("Geometry"),_("Mol. Orb.")},
255 			    {_("At. Orb."),_("Grid"),_("IsoSurface")," "}};
256 	guint idStatus = 0;
257 	gint i;
258 	gint j;
259 
260 	for(i=0;i<2;i++)
261 		for(j=0;j<4;j++)
262 		if(strcmp(type,tlabels[i][j])==0)
263 		{
264 			gchar*t = g_strdup_printf(" %s : %s ",tlabels[i][j],txt);
265 			idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(Status[i][j]),"Testing");
266 			gtk_statusbar_pop(GTK_STATUSBAR(Status[i][j]),idStatus);
267 			gtk_statusbar_push(GTK_STATUSBAR(Status[i][j]),idStatus, t);
268 			g_free(t);
269 			break;
270 		}
271 	progress_orb(0,GABEDIT_PROGORB_READGEOM,TRUE);
272         while( gtk_events_pending() )
273           gtk_main_iteration();
274 }
275 /***********************************************************/
cancel_calcul(GtkWidget * win,gpointer data)276 void cancel_calcul(GtkWidget* win,gpointer data)
277 {
278 	CancelCalcul = TRUE;
279 }
280 /***********************************************************/
create_progress_bar_orb(GtkWidget * box)281 GtkWidget *create_progress_bar_orb(GtkWidget *box)
282 {
283 	GtkWidget *pbar;
284 	GtkWidget *table;
285 
286 	table = gtk_table_new(1,4,FALSE);
287 
288 	gtk_box_pack_start (GTK_BOX(box), table, FALSE, TRUE, 2);
289 	gtk_widget_show (table);
290 
291 	StatusProgress = gtk_statusbar_new();
292 	gtk_widget_show(StatusProgress);
293 	gtk_table_attach(GTK_TABLE(table),StatusProgress,0,2,0,1,
294 			(GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
295 			(GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
296 			1,1);
297     	pbar = gtk_progress_bar_new ();
298     	gtk_widget_show(pbar);
299 
300 	gtk_table_attach(GTK_TABLE(table),pbar,2,3,0,1,
301 			(GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
302 			(GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
303 			1,1);
304 	/*
305 	gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(pbar),GTK_PROGRESS_DISCRETE);
306 	gtk_progress_bar_set_discrete_blocks(GTK_PROGRESS_BAR(pbar),15);
307 	*/
308 
309   	button = gtk_button_new_with_label(_("Cancel"));
310 	gtk_table_attach(GTK_TABLE(table),button,3,4,0,1,
311 			(GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
312 			(GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
313 			1,1);
314   	gtk_widget_show_all (button);
315 	gtk_widget_set_sensitive(button, FALSE);
316 	g_signal_connect(G_OBJECT(button), "clicked", (GCallback)cancel_calcul,NULL);
317 	tableProgressBar = table;
318 
319 	return pbar;
320 }
321 /********************************************************************************/
create_status_bar_orb(GtkWidget * box)322 void create_status_bar_orb(GtkWidget* box)
323 {
324   	GtkWidget *handlebox;
325 	GtkWidget* table;
326 	gchar* label[2][4]={{_(" File name : Nothing"),_(" File type : Nothing"),_(" Geometry : Nothing"),_(" Mol. Orb. : Nothing")},
327 			    {_(" Atomic orb. : Nothing"),_(" Grid : Nothing"),_(" Iso Surface : Nothing"),_(" Right mouse button for popup menu.")}};
328 	guint idStatus = 0;
329 	gint i;
330 	gint j;
331 
332   	handlebox = gtk_handle_box_new ();
333   	gtk_handle_box_set_shadow_type(GTK_HANDLE_BOX(handlebox),GTK_SHADOW_NONE);
334 	gtk_handle_box_set_handle_position  (GTK_HANDLE_BOX(handlebox),GTK_POS_LEFT);
335   	gtk_widget_show (handlebox);
336   	gtk_box_pack_start (GTK_BOX (box), handlebox, FALSE, FALSE, 0);
337 	table = gtk_table_new(2,4,FALSE);
338 
339 	gtk_container_add (GTK_CONTAINER (handlebox), table);
340 	/* Mode Status */
341 	for(i=0;i<2;i++)
342 		for(j=0;j<4;j++)
343 		{
344 			Status[i][j] = gtk_statusbar_new();
345 			gtk_widget_show(Status[i][j]);
346 			gtk_table_attach(GTK_TABLE(table),Status[i][j],j,j+1,i,i+1,
347 					(GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
348 					(GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
349 					1,1);
350 			idStatus= gtk_statusbar_get_context_id(GTK_STATUSBAR(Status[i][j]),"Testing");
351 			gtk_statusbar_pop(GTK_STATUSBAR(Status[i][j]),idStatus);
352 			gtk_statusbar_push(GTK_STATUSBAR(Status[i][j]),idStatus, label[i][j]);
353 		}
354 
355 
356 	gtk_widget_show(table);
357 	handleboxStatus = handlebox;
358 }
359 /********************************************************************************/
create_status_progress_bar_orb(GtkWidget * vbox)360 void create_status_progress_bar_orb(GtkWidget* vbox)
361 {
362 	ProgressBar = create_progress_bar_orb(vbox);
363 }
364 /********************************************************************************/
365