1 /* Psicode.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 "../Psicode/PsicodeTypes.h"
24 #include "../Psicode/PsicodeGlobal.h"
25 #include "../Psicode/PsicodeMolecule.h"
26 #include "../Psicode/PsicodeKeywords.h"
27 #include "../Psicode/PsicodeBasis.h"
28 #include "../Psicode/PsicodeGuess.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 	psicodeColorFore.keyWord.red = 65535;
48 	psicodeColorFore.keyWord.green = 0;
49 	psicodeColorFore.keyWord.blue = 0;
50 
51 	psicodeColorBack.keyWord.red = (gushort)(65535/1.2);
52 	psicodeColorBack.keyWord.green = (gushort)(65535/1.2);
53 	psicodeColorBack.keyWord.blue = (gushort)(65535/1.2);
54 
55 	psicodeColorFore.description.red = 0;
56 	psicodeColorFore.description.green = 65535;
57 	psicodeColorFore.description.blue = 65535;
58 
59 	psicodeColorBack.description.red = (gushort)(65535/2.0);
60 	psicodeColorBack.description.green = (gushort)(65535/2.0);
61 	psicodeColorBack.description.blue = (gushort)(65535/2.0);
62 
63 }
64 /************************************************************************************************************/
destroyWinsPsicode(GtkWidget * win)65 void destroyWinsPsicode(GtkWidget *win)
66 {
67 	destroy(Wins,NULL);
68 	Wins = NULL;
69 	initPsicodeMoleculeButtons();
70 	initPsicodeGuessFrame();
71 	/*
72 	freePsicodeMolecule();
73 	freePsicodeMpqc();
74 	freePsicodeBasis();
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 Psicode input file made in Gabedit\n",'#');
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 }
96 /************************************************************************************************************/
putInfoInTextEditor(GtkWidget * button,gpointer data)97 static void putInfoInTextEditor(GtkWidget *button, gpointer data)
98 {
99 	setColors();
100 	if(newFile)
101 	{
102 		reset_name_files();
103 		ClearText(text);
104 	}
105 	else
106 	{
107         	gint nchar;
108         	nchar=gabedit_text_get_length(GABEDIT_TEXT(text));
109         	gabedit_text_set_point(GABEDIT_TEXT(text),nchar);
110 	}
111 	data_modify(TRUE);
112 
113 	putTitleInTextEditor();
114 
115 	putPsicodeMoleculeInfoInTextEditor();
116 
117 	putPsicodeKeywordsInfoInTextEditor();
118 
119 
120 	iprogram = PROG_IS_PSICODE;
121 	fileopen.command=g_strdup(NameCommandPsicode);
122 	gtk_notebook_set_current_page((GtkNotebook*)NoteBookText,0);
123 }
124 /*********************************************************************************************/
addHboxToTable(GtkWidget * table,gint i,gint j,gint ki,gint kj)125 static GtkWidget* addHboxToTable(GtkWidget* table, gint i, gint j, gint ki, gint kj)
126 {
127 	GtkWidget *hbox = gtk_hbox_new(TRUE, 5);
128 
129 	gtk_table_attach(GTK_TABLE(table),hbox,j,j+kj,i,i+ki,
130 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
131 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
132                   3,3);
133 
134 	return hbox;
135 }
136 /************************************************************************************************************/
psicodeInputFileWindow(gboolean newInputFile)137 static void psicodeInputFileWindow(gboolean newInputFile)
138 {
139 	GtkWidget *button;
140 	GtkWidget *hbox = NULL;
141 	GtkWidget *hboxChargeMultiplicity = NULL;
142 
143 	GtkWidget *table = gtk_table_new(6,2,FALSE);
144 
145 	newFile = newInputFile;
146 
147 	initPsicodeMolecule();
148 	setPsicodeMolecule();
149 
150 
151 	if(psicodeMolecule.numberOfAtoms <1)
152 	{
153 		Message(
154 			_(
155 			"You must initially define your geometry.\n\n"
156 			"From the principal Menu select : Geometry/Draw\n"
157 			"and draw (or read) your molecule."),
158 			_("Error"),TRUE);
159 		return;
160 	}
161 
162 	if(Wins) destroy_children(Wins);
163 
164 	Wins= gtk_dialog_new ();
165 	gtk_window_set_position(GTK_WINDOW(Wins),GTK_WIN_POS_CENTER);
166 	gtk_window_set_transient_for(GTK_WINDOW(Wins),GTK_WINDOW(Fenetre));
167 	gtk_window_set_title(&GTK_DIALOG(Wins)->window,_("Psicode input"));
168     	gtk_window_set_modal (GTK_WINDOW (Wins), TRUE);
169 
170 	init_child(Wins, destroyWinsPsicode,_(" Psicode input "));
171 	g_signal_connect(G_OBJECT(Wins),"delete_event",(GCallback)destroy_children,NULL);
172 
173 	gtk_widget_realize(Wins);
174 
175 	button = create_button(Wins,_("Cancel"));
176 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
177 	g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK( toCancelWin),GTK_OBJECT(Wins));
178 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
179 	gtk_widget_show (button);
180 
181 	button = create_button(Wins,_("OK"));
182 
183 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->vbox), table, FALSE, TRUE, 5);
184 
185 	hbox =addHboxToTable(table, 0, 0, 1, 1);
186 	hboxChargeMultiplicity = hbox;
187 
188 	hbox =addHboxToTable(table, 1, 0, 1, 2);
189 	initPsicodeGuessFrame();
190 	createPsicodeKeywordsFrame(Wins, hbox);
191 	createPsicodeChargeMultiplicityFrame(hboxChargeMultiplicity);
192 
193 	hbox =addHboxToTable(table, 2, 0, 1, 2);
194 	createPsicodeGuessFrame(Wins, hbox);
195 
196 
197 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
198 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
199 	gtk_widget_grab_default(button);
200 	gtk_widget_show (button);
201 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(putInfoInTextEditor),GTK_OBJECT(Wins));
202 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(destroy_children),GTK_OBJECT(Wins));
203 
204 
205 	gtk_widget_show_all(Wins);
206 	psicodeWin = Wins;
207 }
208 /************************************************************************************************************/
newPsicode()209 void newPsicode()
210 {
211 	psicodeInputFileWindow(TRUE);
212 }
213 /************************************************************************************************************/
insertPsicode()214 void insertPsicode()
215 {
216 	psicodeInputFileWindow(FALSE);
217 }
218