2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
54 #include "gmx_fatal.h"
56 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
58 void write_gmx(t_x11 *x11,t_gmx *gmx,int mess)
62 letter.type=ClientMessage;
63 letter.xclient.display=x11->disp;
64 letter.xclient.window=gmx->wd->self;
65 letter.xclient.message_type=0;
66 letter.xclient.format=32;
67 letter.xclient.data.l[0]=mess;
68 letter.xclient.data.l[1]=Button1;
69 XSendEvent(x11->disp,letter.xclient.window,True,0,&letter);
72 static void shell_comm(const char *title,const char *script,int nsleep)
78 strcpy(tmp,"dialogXXXXXX");
81 if ((tfil = fopen(tmp,"w")) == NULL) {
82 sprintf(tmp,"%ctmp%cdialogXXXXXX",DIR_SEPARATOR,DIR_SEPARATOR);
89 if ((tfil = fopen(tmp,"w")) == NULL)
90 gmx_fatal(FARGS,"Can not open tmp file %s",tmp);
92 fprintf(tfil,"%s\n",script);
93 fprintf(tfil,"sleep %d\n",nsleep);
96 sprintf(command,"xterm -title %s -e sh %s",title,tmp);
98 fprintf(stderr,"command: %s\n",command);
102 printf("Warning-- No calls to system(3) supported on this platform.");
103 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
105 if(0 != system(command))
107 gmx_fatal(FARGS,"Failed to execute command: %s",command);
116 void show_mb(t_gmx *gmx,int mb)
118 if (mb >=0 && mb < emNR) {
120 ShowDlg(gmx->mboxes[mb]);
124 static void hide_mb(t_gmx *gmx)
126 if (gmx->which_mb >= 0 && gmx->which_mb < emNR) {
127 HideDlg(gmx->mboxes[gmx->which_mb]);
132 static void MBCallback(t_x11 *x11,int dlg_mess,int item_id,
133 char *set,void *data)
138 if (dlg_mess==DLG_EXIT)
142 static t_dlg *about_mb(t_x11 *x11,t_gmx *gmx)
146 " Machine for Simulating Chemistry",
147 " Copyright (c) 1992-2000",
148 " Dept. of Biophysical Chemistry",
149 " University of Groningen"
152 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
153 asize(lines),lines,MB_OK | MB_ICONGMX | MBFLAGS,
157 static void QuitCB(t_x11 *x11,int dlg_mess,int item_id,
158 char *set,void *data)
164 if (dlg_mess==DLG_EXIT) {
165 if (gmx_strcasecmp("yes",set)==0)
166 write_gmx(x11,gmx,IDTERM);
170 static t_dlg *quit_mb(t_x11 *x11,t_gmx *gmx)
173 " Do you really want to Quit ?"
176 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
178 MB_YESNO | MB_ICONSTOP | MBFLAGS,
182 static t_dlg *help_mb(t_x11 *x11,t_gmx *gmx)
185 " Help will soon be added"
188 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
190 MB_OK | MB_ICONINFORMATION | MBFLAGS,
194 static t_dlg *ni_mb(t_x11 *x11,t_gmx *gmx)
197 " This feature has not been",
201 return MessageBox(x11,gmx->wd->self,gmx->wd->text,
203 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
207 enum { eExE, eExGrom, eExPdb, eExConf, eExNR };
209 static void ExportCB(t_x11 *x11,int dlg_mess,int item_id,
210 char *set,void *data)
217 dlg=gmx->dlgs[edExport];
222 gmx->ExpMode=eExpGromos;
225 gmx->ExpMode=eExpPDB;
231 fprintf(stderr,"exportcb: item_id=%d\n",item_id);
235 if ((bOk=gmx_strcasecmp("ok",set))==0)
236 strcpy(gmx->confout,EditText(dlg,eExConf));
239 write_gmx(x11,gmx,IDDOEXPORT);
244 enum { eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC };
246 static void Extract(t_dlg *dlg,int ID,char *buf)
255 enum bond_set { ebShowH=11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait };
257 static void BondsCB(t_x11 *x11,int dlg_mess,int item_id,
258 char *set,void *data)
262 gmx_bool bOk,bBond=FALSE;
268 ebond = gmx->man->molw->bond_type;
269 ebox = gmx->man->molw->boxtype;
273 if (item_id <= eBNR) {
277 else if (item_id <= eBNR+esbNR+1) {
278 ebox = item_id-eBNR-2;
283 #define DO_NOT(b) (b) = (!(b))
287 toggle_hydrogen(x11,gmx->man->molw);
290 DO_NOT(gmx->man->bPlus);
292 fprintf(stderr,"gmx->man->bPlus=%s\n",gmx_bool_names[gmx->man->bPlus]);
296 set_box_type(x11,gmx->man->molw,ebond);
299 toggle_pbc(gmx->man);
302 DO_NOT(gmx->man->bSort);
304 fprintf(stderr,"gmx->man->bSort=%s\n",gmx_bool_names[gmx->man->bSort]);
308 sscanf(set,"%d",&nskip);
310 fprintf(stderr,"nskip: %d frames\n",nskip);
313 gmx->man->nSkip=nskip;
316 sscanf(set,"%d",&nwait);
318 fprintf(stderr,"wait: %d ms\n",nwait);
321 gmx->man->nWait=nwait;
324 fprintf(stderr,"item_id: %d, set: %s\n",item_id,set);
331 bOk=(gmx_strcasecmp("ok",set)==0);
332 HideDlg(gmx->dlgs[edBonds]);
337 write_gmx(x11,gmx,IDTHIN);
340 write_gmx(x11,gmx,IDFAT);
343 write_gmx(x11,gmx,IDVERYFAT);
346 write_gmx(x11,gmx,IDBALLS);
349 gmx_fatal(FARGS,"Invalid bond type %d at %s, %d",
350 ebond,__FILE__,__LINE__);
356 write_gmx(x11,gmx,IDNOBOX);
359 write_gmx(x11,gmx,IDRECTBOX);
362 write_gmx(x11,gmx,IDTRIBOX);
365 write_gmx(x11,gmx,IDTOBOX);
368 gmx_fatal(FARGS,"Invalid box type %d at %s, %d",
369 ebox,__FILE__,__LINE__);
377 enum { esFUNCT=1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL };
379 static gmx_bool in_set(int i,int n,int set[])
388 typedef t_dlg *t_mmb(t_x11 *x11,t_gmx *gmx);
402 void init_dlgs(t_x11 *x11,t_gmx *gmx)
404 static t_dlginit di[] = {
405 { edExport, "export.dlg", ExportCB },
406 { edBonds, "bonds.dlg", BondsCB }
408 static t_mbinit mi[emNR] = {
409 { emQuit, quit_mb, QuitCB },
410 { emHelp, help_mb, MBCallback },
411 { emAbout, about_mb, MBCallback },
412 { emNotImplemented, ni_mb, MBCallback }
416 snew(gmx->dlgs,edNR);
417 for(i=0; (i<asize(di)); i++)
418 gmx->dlgs[i]=ReadDlg(x11,gmx->wd->self,di[i].dlgfile,
419 x11->fg,x11->bg,di[i].dlgfile,
420 0,0,TRUE,FALSE,di[i].cb,gmx);
422 gmx->dlgs[edFilter]=select_filter(x11,gmx);
424 snew(gmx->mboxes,emNR);
425 for(i=0; (i<emNR); i++)
426 gmx->mboxes[i]=mi[i].mmb(x11,gmx);
430 void done_dlgs(t_gmx *gmx)
434 for(i=0; (i<edNR); i++)
435 FreeDlg(gmx->dlgs[i]);
436 for(i=0; (i<emNR); i++)
437 FreeDlg(gmx->mboxes[i]);
440 void edit_file(const char *fn)
445 sprintf(script,"vi %s",fn);
446 shell_comm(fn,script,0);