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-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
43 #include <unistd.h> // for fork()
48 #include "gromacs/legacyheaders/macros.h"
49 #include "gromacs/legacyheaders/names.h"
50 #include "gromacs/utility/cstringutil.h"
51 #include "gromacs/utility/dir_separator.h"
52 #include "gromacs/utility/fatalerror.h"
53 #include "gromacs/utility/futil.h"
54 #include "gromacs/utility/smalloc.h"
62 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
64 void write_gmx(t_x11
*x11
, t_gmx
*gmx
, int mess
)
68 letter
.type
= ClientMessage
;
69 letter
.xclient
.display
= x11
->disp
;
70 letter
.xclient
.window
= gmx
->wd
->self
;
71 letter
.xclient
.message_type
= 0;
72 letter
.xclient
.format
= 32;
73 letter
.xclient
.data
.l
[0] = mess
;
74 letter
.xclient
.data
.l
[1] = Button1
;
75 XSendEvent(x11
->disp
, letter
.xclient
.window
, True
, 0, &letter
);
78 static void shell_comm(const char *title
, const char *script
, int nsleep
)
84 strcpy(tmp
, "dialogXXXXXX");
87 if ((tfil
= fopen(tmp
, "w")) == NULL
)
89 sprintf(tmp
, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR
, DIR_SEPARATOR
);
96 if ((tfil
= fopen(tmp
, "w")) == NULL
)
98 gmx_fatal(FARGS
, "Can not open tmp file %s", tmp
);
101 fprintf(tfil
, "%s\n", script
);
102 fprintf(tfil
, "sleep %d\n", nsleep
);
105 sprintf(command
, "xterm -title %s -e sh %s", title
, tmp
);
107 fprintf(stderr
, "command: %s\n", command
);
110 if (0 != system(command
))
112 gmx_fatal(FARGS
, "Failed to execute command: %s", command
);
120 void show_mb(t_gmx
*gmx
, int mb
)
122 if (mb
>= 0 && mb
< emNR
)
125 ShowDlg(gmx
->mboxes
[mb
]);
129 static void hide_mb(t_gmx
*gmx
)
131 if (gmx
->which_mb
>= 0 && gmx
->which_mb
< emNR
)
133 HideDlg(gmx
->mboxes
[gmx
->which_mb
]);
138 static void MBCallback(t_x11
* /*x11*/, int dlg_mess
, int /*item_id*/,
139 char * /*set*/, void *data
)
144 if (dlg_mess
== DLG_EXIT
)
150 static t_dlg
*about_mb(t_x11
*x11
, t_gmx
*gmx
)
152 const char *lines
[] = {
154 " Machine for Simulating Chemistry",
155 " Copyright (c) 1992-2013",
156 " Berk Hess, David van der Spoel, Erik Lindahl",
157 " and many collaborators!"
160 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
161 asize(lines
), lines
, MB_OK
| MB_ICONGMX
| MBFLAGS
,
165 static void QuitCB(t_x11
*x11
, int dlg_mess
, int /*item_id*/,
166 char *set
, void *data
)
172 if (dlg_mess
== DLG_EXIT
)
174 if (gmx_strcasecmp("yes", set
) == 0)
176 write_gmx(x11
, gmx
, IDTERM
);
181 static t_dlg
*quit_mb(t_x11
*x11
, t_gmx
*gmx
)
183 const char *lines
[] = {
184 " Do you really want to Quit ?"
187 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
189 MB_YESNO
| MB_ICONSTOP
| MBFLAGS
,
193 static t_dlg
*help_mb(t_x11
*x11
, t_gmx
*gmx
)
195 const char *lines
[] = {
196 " Help will soon be added"
199 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
201 MB_OK
| MB_ICONINFORMATION
| MBFLAGS
,
205 static t_dlg
*ni_mb(t_x11
*x11
, t_gmx
*gmx
)
207 const char *lines
[] = {
208 " This feature has not been",
212 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
214 MB_OK
| MB_ICONEXCLAMATION
| MBFLAGS
,
219 eExE
, eExGrom
, eExPdb
, eExConf
, eExNR
222 static void ExportCB(t_x11
*x11
, int dlg_mess
, int item_id
,
223 char *set
, void *data
)
230 dlg
= gmx
->dlgs
[edExport
];
237 gmx
->ExpMode
= eExpGromos
;
240 gmx
->ExpMode
= eExpPDB
;
246 fprintf(stderr
, "exportcb: item_id=%d\n", item_id
);
250 if ((bOk
= gmx_strcasecmp("ok", set
)) == 0)
252 strcpy(gmx
->confout
, EditText(dlg
, eExConf
));
257 write_gmx(x11
, gmx
, IDDOEXPORT
);
264 eg0
, egTOPOL
, egCONFIN
, egPARAM
, eg1
, eg1PROC
, eg32PROC
267 static void Extract(t_dlg
*dlg
, int ID
, char *buf
)
271 et
= EditText(dlg
, ID
);
279 ebShowH
= 11, ebDPlus
, ebRMPBC
, ebCue
, ebSkip
, ebWait
282 static void BondsCB(t_x11
*x11
, int dlg_mess
, int item_id
,
283 char *set
, void *data
)
285 static int ebond
= -1;
286 static int ebox
= -1;
287 bool bOk
, bBond
= false;
295 ebond
= gmx
->man
->molw
->bond_type
;
296 ebox
= gmx
->man
->molw
->boxtype
;
306 else if (item_id
<= eBNR
+esbNR
+1)
308 ebox
= item_id
-eBNR
-2;
314 #define DO_NOT(b) (b) = (!(b))
319 toggle_hydrogen(x11
, gmx
->man
->molw
);
322 DO_NOT(gmx
->man
->bPlus
);
324 fprintf(stderr
, "gmx->man->bPlus=%s\n",
325 gmx
->man
->bPlus
? "true" : "false");
329 toggle_pbc(gmx
->man
);
332 DO_NOT(gmx
->man
->bSort
);
334 fprintf(stderr
, "gmx->man->bSort=%s\n",
335 gmx
->man
->bSort
? "true" : "false");
339 nskip
= strtol(set
, &endptr
, 10);
343 fprintf(stderr
, "nskip: %d frames\n", nskip
);
347 gmx
->man
->nSkip
= nskip
;
352 nwait
= strtol(set
, &endptr
, 10);
356 fprintf(stderr
, "wait: %d ms\n", nwait
);
360 gmx
->man
->nWait
= nwait
;
365 fprintf(stderr
, "item_id: %d, set: %s\n", item_id
, set
);
372 bOk
= (gmx_strcasecmp("ok", set
) == 0);
373 HideDlg(gmx
->dlgs
[edBonds
]);
381 write_gmx(x11
, gmx
, IDTHIN
);
384 write_gmx(x11
, gmx
, IDFAT
);
387 write_gmx(x11
, gmx
, IDVERYFAT
);
390 write_gmx(x11
, gmx
, IDBALLS
);
393 gmx_fatal(FARGS
, "Invalid bond type %d at %s, %d",
394 ebond
, __FILE__
, __LINE__
);
402 write_gmx(x11
, gmx
, IDNOBOX
);
405 write_gmx(x11
, gmx
, IDRECTBOX
);
408 write_gmx(x11
, gmx
, IDTRIBOX
);
411 write_gmx(x11
, gmx
, IDTOBOX
);
414 gmx_fatal(FARGS
, "Invalid box type %d at %s, %d",
415 ebox
, __FILE__
, __LINE__
);
424 esFUNCT
= 1, esBSHOW
, esINFIL
, esINDEXFIL
, esLSQ
, esSHOW
, esPLOTFIL
427 static bool in_set(int i
, int n
, int set
[])
430 for (j
= 0; (j
< n
); j
++)
440 typedef t_dlg
*t_mmb (t_x11
*x11
, t_gmx
*gmx
);
447 void init_dlgs(t_x11
*x11
, t_gmx
*gmx
)
449 static t_dlginit di
[] = {
450 { "export.dlg", ExportCB
},
451 { "bonds.dlg", BondsCB
}
453 static t_mmb
*mi
[emNR
] = { quit_mb
, help_mb
, about_mb
, ni_mb
};
456 snew(gmx
->dlgs
, edNR
);
457 for (i
= 0; (i
< asize(di
)); i
++)
459 gmx
->dlgs
[i
] = ReadDlg(x11
, gmx
->wd
->self
, di
[i
].dlgfile
,
461 0, 0, true, false, di
[i
].cb
, gmx
);
464 gmx
->dlgs
[edFilter
] = select_filter(x11
, gmx
);
466 snew(gmx
->mboxes
, emNR
);
467 for (i
= 0; (i
< emNR
); i
++)
469 gmx
->mboxes
[i
] = mi
[i
](x11
, gmx
);
474 void done_dlgs(t_gmx
*gmx
)
478 for (i
= 0; (i
< edNR
); i
++)
480 FreeDlg(gmx
->dlgs
[i
]);
482 for (i
= 0; (i
< emNR
); i
++)
484 FreeDlg(gmx
->mboxes
[i
]);
488 void edit_file(const char *fn
)
494 sprintf(script
, "vi %s", fn
);
495 shell_comm(fn
, script
, 0);