1 /* PsicodeGuess.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 #include <stdlib.h>
21 #include <ctype.h>
22 #include <math.h>
23 #include <string.h>
24
25 #include "../../Config.h"
26 #include "../Common/Global.h"
27 #include "../Psicode/PsicodeTypes.h"
28 #include "../Psicode/PsicodeGlobal.h"
29 #include "../Psicode/PsicodeBasis.h"
30 #include "../Utils/Utils.h"
31 #include "../Utils/UtilsInterface.h"
32 #include "../Utils/GabeditTextEdit.h"
33 #include "../Common/Windows.h"
34 #include "../Utils/Constants.h"
35
36 static GtkWidget *guessFrame = NULL;
37 /*************************************************************************************************************/
38 static gchar* listGuessMethodView[] = {
39 "Default",
40 "Superposition of Atomic Densities",
41 "Generalized olfsberg-Helmholtz",
42 };
43 static gchar* listGuessMethodReal[] = {
44 "NONE",
45 "SAD",
46 "GWH",
47
48 };
49 static guint numberOfGuessMethods = G_N_ELEMENTS (listGuessMethodView);
50 static gchar selectedGuessMethod[BSIZE]="NONE";
51 /*************************************************************************************************************/
initPsicodeGuessFrame()52 void initPsicodeGuessFrame()
53 {
54 guessFrame = NULL;
55 }
56 /*************************************************************************************************************/
putPsicodeGuessOptionsInfoInTextEditor()57 static void putPsicodeGuessOptionsInfoInTextEditor()
58 {
59 }
60 /************************************************************************************************************/
putPsicodeGuessMethodInfoInTextEditor()61 static void putPsicodeGuessMethodInfoInTextEditor()
62 {
63 if( strcmp(selectedGuessMethod,"NONE")==0 ) return;
64 {
65 gchar buffer[BSIZE];
66 sprintf(buffer,"set guess %s\n",selectedGuessMethod);
67 gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
68 }
69 }
70 /*************************************************************************************************************/
putPsicodeGuessInfoInTextEditor()71 void putPsicodeGuessInfoInTextEditor()
72 {
73 putPsicodeGuessMethodInfoInTextEditor();
74 putPsicodeGuessOptionsInfoInTextEditor();
75
76 }
77 /************************************************************************************************************/
traitementGuessMethod(GtkComboBox * combobox,gpointer d)78 static void traitementGuessMethod (GtkComboBox *combobox, gpointer d)
79 {
80 GtkTreeIter iter;
81 gchar* data = NULL;
82 gchar* res = NULL;
83 gint i;
84
85
86 /* gchar* s;*/
87 if (gtk_combo_box_get_active_iter (combobox, &iter))
88 {
89 GtkTreeModel* model = gtk_combo_box_get_model(combobox);
90 gtk_tree_model_get (model, &iter, 0, &data, -1);
91 }
92 for(i=0;i<numberOfGuessMethods;i++)
93 {
94 if(strcmp((gchar*)data,listGuessMethodView[i])==0) res = listGuessMethodReal[i];
95 }
96 if(res) sprintf(selectedGuessMethod,"%s",res);
97 else sprintf(selectedGuessMethod,"Default");
98
99 }
100 /********************************************************************************************************/
create_list_guessmethods()101 static GtkWidget *create_list_guessmethods()
102 {
103 GtkTreeIter iter;
104 GtkTreeStore *store;
105 GtkTreeModel *model;
106 GtkWidget *combobox;
107 GtkCellRenderer *renderer;
108 gint i;
109 GtkTreeIter iter0;
110
111 store = gtk_tree_store_new (1,G_TYPE_STRING);
112
113 for(i=0;i<numberOfGuessMethods;i++)
114 {
115 gtk_tree_store_append (store, &iter, NULL);
116 if(i==0) iter0 = iter;
117 gtk_tree_store_set (store, &iter, 0, listGuessMethodView[i], -1);
118 }
119
120 model = GTK_TREE_MODEL (store);
121 combobox = gtk_combo_box_new_with_model (model);
122 /*
123 gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
124 */
125 g_object_unref (model);
126 g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(traitementGuessMethod), NULL);
127 renderer = gtk_cell_renderer_text_new ();
128 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
129 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
130
131 gtk_combo_box_set_active_iter(GTK_COMBO_BOX (combobox), &iter0);
132
133 return combobox;
134 }
135 /************************************************************************************************************/
createPsicodeGuessFrame(GtkWidget * win,GtkWidget * box)136 void createPsicodeGuessFrame(GtkWidget *win, GtkWidget *box)
137 {
138 GtkWidget* frame;
139 GtkWidget* vboxFrame;
140 GtkWidget* sep;
141 GtkWidget* combo = NULL;
142 gint l=0;
143 gint c=0;
144 gint ncases=1;
145 GtkWidget *table = gtk_table_new(4,3,FALSE);
146
147 frame = gtk_frame_new (_("Mo Guess"));
148 guessFrame = frame;
149 gtk_widget_show (frame);
150 gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 3);
151 gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5);
152
153 vboxFrame = gtk_vbox_new (FALSE, 3);
154 gtk_widget_show (vboxFrame);
155 gtk_container_add (GTK_CONTAINER (frame), vboxFrame);
156 gtk_box_pack_start (GTK_BOX (vboxFrame), table, TRUE, TRUE, 0);
157
158 /*------------------ Guess Method -----------------------------------------*/
159 l=0;
160 c = 0; ncases=1;
161 add_label_table(table,_("Initial Guess"),l,c);
162 c = 1; ncases=1;
163 add_label_table(table,":",l,c);
164 combo = create_list_guessmethods();
165 c = 2; ncases=1;
166 gtk_table_attach(GTK_TABLE(table),combo,c,c+ncases,l,l+1,
167 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
168 (GtkAttachOptions) (GTK_FILL | GTK_SHRINK),
169 2,2);
170 /*------------------ separator -----------------------------------------*/
171 l++;
172 sep = gtk_hseparator_new ();
173 c = 0; ncases=3;
174 gtk_table_attach(GTK_TABLE(table),sep,c,c+ncases,l,l+1,
175 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
176 (GtkAttachOptions) (GTK_FILL | GTK_SHRINK),
177 2,2);
178
179 }
180