1 /* DeMon.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 "../Common/Global.h"
23 #include "../DeMon/DeMonTypes.h"
24 #include "../DeMon/DeMonGlobal.h"
25 #include "../DeMon/DeMonMolecule.h"
26 #include "../DeMon/DeMonKeywords.h"
27 #include "../DeMon/DeMonBasis.h"
28 #include "../DeMon/DeMonGuess.h"
29 #include "../Utils/UtilsInterface.h"
30 #include "../Geometry/GeomGlobal.h"
31 #include "../Geometry/InterfaceGeom.h"
32 #include "../Utils/Utils.h"
33 #include "../Utils/AtomsProp.h"
34 #include "../Utils/Constants.h"
35 #include "../Utils/GabeditTextEdit.h"
36 
37 static GtkWidget *Wins=NULL;
38 static gboolean newFile = FALSE;
39 /************************************************************************************************************/
setColors()40 static void setColors()
41 {
42 	static gboolean first = TRUE;
43 
44 	if(!first) return;
45 	first = FALSE;
46 
47 	demonColorFore.keyWord.red = 65535;
48 	demonColorFore.keyWord.green = 0;
49 	demonColorFore.keyWord.blue = 0;
50 
51 	demonColorBack.keyWord.red = (gushort)(65535/1.2);
52 	demonColorBack.keyWord.green = (gushort)(65535/1.2);
53 	demonColorBack.keyWord.blue = (gushort)(65535/1.2);
54 
55 	demonColorFore.description.red = 0;
56 	demonColorFore.description.green = 65535;
57 	demonColorFore.description.blue = 65535;
58 
59 	demonColorBack.description.red = (gushort)(65535/2.0);
60 	demonColorBack.description.green = (gushort)(65535/2.0);
61 	demonColorBack.description.blue = (gushort)(65535/2.0);
62 
63 }
64 /************************************************************************************************************/
destroyWinsDeMon(GtkWidget * win)65 void destroyWinsDeMon(GtkWidget *win)
66 {
67 	destroy(Wins,NULL);
68 	Wins = NULL;
69 	initDeMonMoleculeButtons();
70 	initDeMonGuessFrame();
71 	/*
72 	freeDeMonMolecule();
73 	freeDeMonMpqc();
74 	freeDeMonBasis();
75 	*/
76 }
77 /************************************************************************************************************/
toCancelWin(GtkWidget * win,gpointer data)78 static void toCancelWin(GtkWidget* win,gpointer data)
79 {
80 	Cancel_YesNo(win, data, destroy_children);
81 }
82 /************************************************************************************************************/
putTitleInTextEditor()83 static void putTitleInTextEditor()
84 {
85         gchar buffer[BSIZE];
86 
87 	sprintf(buffer,"%c ================================================================\n",'#');
88         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
89 
90 	sprintf(buffer,"%c DeMon input file made in Gabedit\n",'#'); // This line is important. Gabedit uses its to know the type of file
91         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
92 
93 	sprintf(buffer,"%c ================================================================\n",'#');
94         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
95 	sprintf(buffer,"Title DeMon input file made in Gabedit\n");
96         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
97 	sprintf(buffer,"Visualization molden\n");
98 	gabedit_text_insert (GABEDIT_TEXT(text), NULL, &demonColorFore.keyWord, &demonColorBack.keyWord, buffer, -1);
99 }
100 /************************************************************************************************************/
putInfoInTextEditor(GtkWidget * button,gpointer data)101 static void putInfoInTextEditor(GtkWidget *button, gpointer data)
102 {
103 	setColors();
104 	if(newFile)
105 	{
106 		reset_name_files();
107 		ClearText(text);
108 	}
109 	else
110 	{
111         	gint nchar;
112         	nchar=gabedit_text_get_length(GABEDIT_TEXT(text));
113         	gabedit_text_set_point(GABEDIT_TEXT(text),nchar);
114 	}
115 	data_modify(TRUE);
116 
117 	putTitleInTextEditor();
118 
119 	putDeMonKeywordsInfoInTextEditor();
120 
121 	putDeMonMoleculeInfoInTextEditor();
122 
123 	iprogram = PROG_IS_DEMON;
124 	fileopen.command=g_strdup(NameCommandDeMon);
125 	gtk_notebook_set_current_page((GtkNotebook*)NoteBookText,0);
126 }
127 /*********************************************************************************************/
addHboxToTable(GtkWidget * table,gint i,gint j,gint ki,gint kj)128 static GtkWidget* addHboxToTable(GtkWidget* table, gint i, gint j, gint ki, gint kj)
129 {
130 	GtkWidget *hbox = gtk_hbox_new(TRUE, 5);
131 
132 	gtk_table_attach(GTK_TABLE(table),hbox,j,j+kj,i,i+ki,
133 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
134 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
135                   3,3);
136 
137 	return hbox;
138 }
139 /************************************************************************************************************/
demonInputFileWindow(gboolean newInputFile)140 static void demonInputFileWindow(gboolean newInputFile)
141 {
142 	GtkWidget *button;
143 	GtkWidget *hbox = NULL;
144 	GtkWidget *hboxChargeMultiplicity = NULL;
145 
146 	GtkWidget *table = gtk_table_new(6,2,FALSE);
147 
148 	newFile = newInputFile;
149 
150 	initDeMonMolecule();
151 	setDeMonMolecule();
152 
153 
154 	if(demonMolecule.numberOfAtoms <1)
155 	{
156 		Message(
157 			_(
158 			"You must initially define your geometry.\n\n"
159 			"From the principal Menu select : Geometry/Draw\n"
160 			"and draw (or read) your molecule."),
161 			_("Error"),TRUE);
162 		return;
163 	}
164 
165 	if(Wins) destroy_children(Wins);
166 
167 	Wins= gtk_dialog_new ();
168 	gtk_window_set_position(GTK_WINDOW(Wins),GTK_WIN_POS_CENTER);
169 	gtk_window_set_transient_for(GTK_WINDOW(Wins),GTK_WINDOW(Fenetre));
170 	gtk_window_set_title(&GTK_DIALOG(Wins)->window,_("DeMon input"));
171     	gtk_window_set_modal (GTK_WINDOW (Wins), TRUE);
172 
173 	init_child(Wins, destroyWinsDeMon,_(" DeMon input "));
174 	g_signal_connect(G_OBJECT(Wins),"delete_event",(GCallback)destroy_children,NULL);
175 
176 	gtk_widget_realize(Wins);
177 
178 	button = create_button(Wins,_("Cancel"));
179 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
180 	g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK( toCancelWin),GTK_OBJECT(Wins));
181 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
182 	gtk_widget_show (button);
183 
184 	button = create_button(Wins,_("OK"));
185 
186 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->vbox), table, FALSE, TRUE, 5);
187 
188 	hbox =addHboxToTable(table, 0, 0, 1, 1);
189 	hboxChargeMultiplicity = hbox;
190 
191 	hbox =addHboxToTable(table, 1, 0, 1, 2);
192 	initDeMonGuessFrame();
193 	createDeMonKeywordsFrame(Wins, hbox);
194 	createDeMonChargeMultiplicityFrame(hboxChargeMultiplicity);
195 
196 	hbox =addHboxToTable(table, 2, 0, 1, 2);
197 	createDeMonGuessFrame(Wins, hbox);
198 
199 
200 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
201 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
202 	gtk_widget_grab_default(button);
203 	gtk_widget_show (button);
204 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(putInfoInTextEditor),GTK_OBJECT(Wins));
205 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(destroy_children),GTK_OBJECT(Wins));
206 
207 
208 	gtk_widget_show_all(Wins);
209 	demonWin = Wins;
210 }
211 /************************************************************************************************************/
newDeMon()212 void newDeMon()
213 {
214 	demonInputFileWindow(TRUE);
215 }
216 /************************************************************************************************************/
insertDeMon()217 void insertDeMon()
218 {
219 	demonInputFileWindow(FALSE);
220 }
221