changed reading hint
[gromacs/adressmacs.git] / src / ngmx / dialogs.c
blobaf3ae4d6492cc55432a547d3dfb251addcbe8454
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_dialogs_c = "$Id$";
31 #include "smalloc.h"
32 #include "sysstuff.h"
33 #include "macros.h"
34 #include "string2.h"
35 #include "x11.h"
36 #include "xdlghi.h"
37 #include "xmb.h"
38 #include "dialogs.h"
39 #include "names.h"
40 #include "nmol.h"
41 #include "manager.h"
43 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
45 void write_gmx(t_x11 *x11,t_gmx *gmx,int mess)
47 XEvent letter;
49 letter.type=ClientMessage;
50 letter.xclient.display=x11->disp;
51 letter.xclient.window=gmx->wd->self;
52 letter.xclient.message_type=0;
53 letter.xclient.format=32;
54 letter.xclient.data.l[0]=mess;
55 letter.xclient.data.l[1]=Button1;
56 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
59 static void shell_comm(char *title,char *script,int nsleep)
61 FILE *tfil;
62 char command[STRLEN];
63 char *tmp;
65 tmp=tmpnam(NULL);
66 if ((tfil=fopen(tmp,"w"))==NULL) {
67 perror(tmp);
68 exit(1);
70 fprintf(tfil,"%s\n",script);
71 fprintf(tfil,"sleep %d\n",nsleep);
72 fclose(tfil);
74 sprintf(command,"xterm -title %s -e sh %s",title,tmp);
75 #ifdef DEBUG
76 fprintf(stderr,"command: %s\n",command);
77 #endif
78 system(command);
79 #ifdef DEBUG
80 unlink(tmp)
81 #endif
84 void show_mb(t_gmx *gmx,int mb)
86 if (mb >=0 && mb < emNR) {
87 gmx->which_mb=mb;
88 ShowDlg(gmx->mboxes[mb]);
92 static void hide_mb(t_gmx *gmx)
94 if (gmx->which_mb > 0 && gmx->which_mb < emNR)
95 HideDlg(gmx->mboxes[gmx->which_mb]);
98 static void MBCallback(t_x11 *x11,int dlg_mess,int item_id,
99 char *set,void *data)
101 t_gmx *gmx;
103 gmx=(t_gmx *)data;
104 if (dlg_mess==DLG_EXIT)
105 hide_mb(gmx);
108 static t_dlg *about_mb(t_x11 *x11,t_gmx *gmx)
110 static char *lines[]={
111 " G R O M A C S",
112 " Machine for Simulating Chemistry",
113 " Copyright (c) 1992",
114 " Dept. of Biophysical Chemistry",
115 " University of Groningen"
118 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
119 asize(lines),lines,MB_OK | MB_ICONGMX | MBFLAGS,
120 MBCallback,gmx);
123 static void QuitCB(t_x11 *x11,int dlg_mess,int item_id,
124 char *set,void *data)
126 t_gmx *gmx;
127 gmx=(t_gmx *)data;
129 if (dlg_mess==DLG_EXIT) {
130 hide_mb(gmx);
131 if (strcasecmp("yes",set)==0)
132 write_gmx(x11,gmx,IDTERM);
136 static t_dlg *quit_mb(t_x11 *x11,t_gmx *gmx)
138 static char *lines[]={
139 " Do you really want to Quit ?"
142 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
143 asize(lines),lines,
144 MB_YESNO | MB_ICONSTOP | MBFLAGS,
145 QuitCB,gmx);
148 static t_dlg *help_mb(t_x11 *x11,t_gmx *gmx)
150 static char *lines[]={
151 " Help will soon be added"
154 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
155 asize(lines),lines,
156 MB_OK | MB_ICONINFORMATION | MBFLAGS,
157 MBCallback,gmx);
160 static t_dlg *ni_mb(t_x11 *x11,t_gmx *gmx)
162 static char *lines[]={
163 " This feature has not been",
164 " implemented yet."
167 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
168 asize(lines),lines,
169 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
170 MBCallback,gmx);
173 enum { eExE, eExGrom, eExPdb, eExConf, eExNR };
175 static void ExportCB(t_x11 *x11,int dlg_mess,int item_id,
176 char *set,void *data)
178 bool bOk;
179 t_gmx *gmx;
180 t_dlg *dlg;
182 gmx=(t_gmx *)data;
183 dlg=gmx->dlgs[edExport];
184 switch (dlg_mess) {
185 case DLG_SET:
186 switch (item_id) {
187 case eExGrom:
188 gmx->ExpMode=eExpGromos;
189 break;
190 case eExPdb:
191 gmx->ExpMode=eExpPDB;
192 break;
193 default:
194 break;
196 #ifdef DEBUG
197 fprintf(stderr,"exportcb: item_id=%d\n",item_id);
198 #endif
199 break;
200 case DLG_EXIT:
201 if ((bOk=(strcasecmp("ok",set))==0))
202 strcpy(gmx->confout,EditText(dlg,eExConf));
203 HideDlg(dlg);
204 if (bOk)
205 write_gmx(x11,gmx,IDDOEXPORT);
206 break;
210 enum { eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC };
212 static void Extract(t_dlg *dlg,int ID,char *buf)
214 char *et;
216 et=EditText(dlg,ID);
217 if (et)
218 strcpy(buf,et);
221 enum bond_set { ebShowH=6, ebDPlus, ebSBox, ebRMPBC, ebCue, ebSkip };
223 static void BondsCB(t_x11 *x11,int dlg_mess,int item_id,
224 char *set,void *data)
226 static int eb=-1;
227 bool bOk;
228 int nskip;
229 t_gmx *gmx;
231 gmx=(t_gmx *)data;
232 if (eb==-1)
233 eb=gmx->man->molw->bond_type;
235 switch (dlg_mess) {
236 case DLG_SET:
237 if (item_id <= eBNR)
238 eb=item_id-1;
239 else {
241 #define DO_NOT(b) (b) = (!(b))
243 switch (item_id) {
244 case ebShowH:
245 toggle_hydrogen(x11,gmx->man->molw);
246 break;
247 case ebDPlus:
248 DO_NOT(gmx->man->bPlus);
249 #ifdef DEBUG
250 fprintf(stderr,"gmx->man->bPlus=%s\n",bool_names[gmx->man->bPlus]);
251 #endif
252 break;
253 case ebSBox:
254 toggle_box(x11,gmx->man->molw);
255 break;
256 case ebRMPBC:
257 toggle_pbc(gmx->man);
258 break;
259 case ebCue:
260 DO_NOT(gmx->man->bSort);
261 #ifdef DEBUG
262 fprintf(stderr,"gmx->man->bSort=%s\n",bool_names[gmx->man->bSort]);
263 #endif
264 break;
265 case ebSkip:
266 sscanf(set,"%d",&nskip);
267 #ifdef DEBUG
268 fprintf(stderr,"nskip: %d frames\n",nskip);
269 #endif
270 if (nskip >= 0)
271 gmx->man->nSkip=nskip;
272 break;
273 default:
274 #ifdef DEBUG
275 fprintf(stderr,"item_id: %d, set: %s\n",item_id,set);
276 #endif
277 break;
280 break;
281 case DLG_EXIT:
282 bOk=(strcasecmp("ok",set)==0);
283 HideDlg(gmx->dlgs[edBonds]);
284 if (bOk)
285 switch (eb) {
286 case eBThin:
287 write_gmx(x11,gmx,IDTHIN);
288 break;
289 case eBFat:
290 write_gmx(x11,gmx,IDFAT);
291 break;
292 case eBVeryFat:
293 write_gmx(x11,gmx,IDVERYFAT);
294 break;
295 case eBSpheres:
296 write_gmx(x11,gmx,IDBALLS);
297 break;
300 break;
304 enum { esFUNCT=1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL };
306 static bool in_set(int i,int n,int set[])
308 int j;
309 for(j=0; (j<n); j++)
310 if (set[j]==i)
311 return TRUE;
312 return FALSE;
315 typedef t_dlg *t_mmb(t_x11 *x11,t_gmx *gmx);
317 typedef struct {
318 eDialogs ed;
319 char *dlgfile;
320 DlgCallback *cb;
321 } t_dlginit;
323 typedef struct {
324 eMBoxes ed;
325 t_mmb *mmb;
326 DlgCallback *cb;
327 } t_mbinit;
329 void init_dlgs(t_x11 *x11,t_gmx *gmx)
331 static t_dlginit di[] = {
332 { edExport, "export.dlg", ExportCB },
333 { edBonds, "bonds.dlg", BondsCB }
335 static t_mbinit mi[emNR] = {
336 { emQuit, quit_mb, QuitCB },
337 { emHelp, help_mb, MBCallback },
338 { emAbout, about_mb, MBCallback },
339 { emNotImplemented, ni_mb, MBCallback }
341 int i;
343 snew(gmx->dlgs,edNR);
344 for(i=0; (i<asize(di)); i++)
345 gmx->dlgs[i]=ReadDlg(x11,gmx->wd->self,di[i].dlgfile,
346 x11->fg,x11->bg,di[i].dlgfile,
347 0,0,TRUE,FALSE,di[i].cb,gmx);
349 gmx->dlgs[edFilter]=select_filter(x11,gmx);
351 snew(gmx->mboxes,emNR);
352 for(i=0; (i<emNR); i++)
353 gmx->mboxes[i]=mi[i].mmb(x11,gmx);
356 void done_dlgs(t_gmx *gmx)
358 int i;
360 for(i=0; (i<edNR); i++)
361 FreeDlg(gmx->dlgs[i]);
362 for(i=0; (i<emNR); i++)
363 FreeDlg(gmx->mboxes[i]);
366 void edit_file(char *fn)
368 if (fork()==0) {
369 char script[256];
371 sprintf(script,"vi %s",fn);
372 shell_comm(fn,script,0);
373 exit(0);