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, 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.
41 #include <unistd.h> // for fork()
53 #include "gromacs/utility/cstringutil.h"
54 #include "gromacs/utility/fatalerror.h"
55 #include "gromacs/utility/futil.h"
56 #include "gromacs/utility/smalloc.h"
58 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
60 void write_gmx(t_x11 *x11, t_gmx *gmx, int mess)
64 letter.type = ClientMessage;
65 letter.xclient.display = x11->disp;
66 letter.xclient.window = gmx->wd->self;
67 letter.xclient.message_type = 0;
68 letter.xclient.format = 32;
69 letter.xclient.data.l[0] = mess;
70 letter.xclient.data.l[1] = Button1;
71 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
74 static void shell_comm(const char *title, const char *script, int nsleep)
80 strcpy(tmp, "dialogXXXXXX");
83 if ((tfil = fopen(tmp, "w")) == NULL)
85 sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR);
92 if ((tfil = fopen(tmp, "w")) == NULL)
94 gmx_fatal(FARGS, "Can not open tmp file %s", tmp);
97 fprintf(tfil, "%s\n", script);
98 fprintf(tfil, "sleep %d\n", nsleep);
101 sprintf(command, "xterm -title %s -e sh %s", title, tmp);
103 fprintf(stderr, "command: %s\n", command);
107 printf("Warning-- No calls to system(3) supported on this platform.");
108 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
110 if (0 != system(command))
112 gmx_fatal(FARGS, "Failed to execute command: %s", command);
121 void show_mb(t_gmx *gmx, int mb)
123 if (mb >= 0 && mb < emNR)
126 ShowDlg(gmx->mboxes[mb]);
130 static void hide_mb(t_gmx *gmx)
132 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
134 HideDlg(gmx->mboxes[gmx->which_mb]);
139 static void MBCallback(t_x11 * /*x11*/, int dlg_mess, int /*item_id*/,
140 char * /*set*/, void *data)
145 if (dlg_mess == DLG_EXIT)
151 static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx)
153 const char *lines[] = {
155 " Machine for Simulating Chemistry",
156 " Copyright (c) 1992-2013",
157 " Berk Hess, David van der Spoel, Erik Lindahl",
158 " and many collaborators!"
161 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
162 asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS,
166 static void QuitCB(t_x11 *x11, int dlg_mess, int /*item_id*/,
167 char *set, void *data)
173 if (dlg_mess == DLG_EXIT)
175 if (gmx_strcasecmp("yes", set) == 0)
177 write_gmx(x11, gmx, IDTERM);
182 static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx)
184 const char *lines[] = {
185 " Do you really want to Quit ?"
188 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
190 MB_YESNO | MB_ICONSTOP | MBFLAGS,
194 static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx)
196 const char *lines[] = {
197 " Help will soon be added"
200 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
202 MB_OK | MB_ICONINFORMATION | MBFLAGS,
206 static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx)
208 const char *lines[] = {
209 " This feature has not been",
213 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
215 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
220 eExE, eExGrom, eExPdb, eExConf, eExNR
223 static void ExportCB(t_x11 *x11, int dlg_mess, int item_id,
224 char *set, void *data)
231 dlg = gmx->dlgs[edExport];
238 gmx->ExpMode = eExpGromos;
241 gmx->ExpMode = eExpPDB;
247 fprintf(stderr, "exportcb: item_id=%d\n", item_id);
251 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
253 strcpy(gmx->confout, EditText(dlg, eExConf));
258 write_gmx(x11, gmx, IDDOEXPORT);
265 eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC
268 static void Extract(t_dlg *dlg, int ID, char *buf)
272 et = EditText(dlg, ID);
280 ebShowH = 11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait
283 static void BondsCB(t_x11 *x11, int dlg_mess, int item_id,
284 char *set, void *data)
286 static int ebond = -1;
287 static int ebox = -1;
288 bool bOk, bBond = false;
296 ebond = gmx->man->molw->bond_type;
297 ebox = gmx->man->molw->boxtype;
307 else if (item_id <= eBNR+esbNR+1)
309 ebox = item_id-eBNR-2;
315 #define DO_NOT(b) (b) = (!(b))
320 toggle_hydrogen(x11, gmx->man->molw);
323 DO_NOT(gmx->man->bPlus);
325 fprintf(stderr, "gmx->man->bPlus=%s\n",
326 gmx->man->bPlus ? "true" : "false");
330 toggle_pbc(gmx->man);
333 DO_NOT(gmx->man->bSort);
335 fprintf(stderr, "gmx->man->bSort=%s\n",
336 gmx->man->bSort ? "true" : "false");
340 nskip = strtol(set, &endptr, 10);
344 fprintf(stderr, "nskip: %d frames\n", nskip);
348 gmx->man->nSkip = nskip;
353 nwait = strtol(set, &endptr, 10);
357 fprintf(stderr, "wait: %d ms\n", nwait);
361 gmx->man->nWait = nwait;
366 fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
373 bOk = (gmx_strcasecmp("ok", set) == 0);
374 HideDlg(gmx->dlgs[edBonds]);
382 write_gmx(x11, gmx, IDTHIN);
385 write_gmx(x11, gmx, IDFAT);
388 write_gmx(x11, gmx, IDVERYFAT);
391 write_gmx(x11, gmx, IDBALLS);
394 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d",
395 ebond, __FILE__, __LINE__);
403 write_gmx(x11, gmx, IDNOBOX);
406 write_gmx(x11, gmx, IDRECTBOX);
409 write_gmx(x11, gmx, IDTRIBOX);
412 write_gmx(x11, gmx, IDTOBOX);
415 gmx_fatal(FARGS, "Invalid box type %d at %s, %d",
416 ebox, __FILE__, __LINE__);
425 esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL
428 static bool in_set(int i, int n, int set[])
431 for (j = 0; (j < n); j++)
441 typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx);
448 void init_dlgs(t_x11 *x11, t_gmx *gmx)
450 static t_dlginit di[] = {
451 { "export.dlg", ExportCB },
452 { "bonds.dlg", BondsCB }
454 static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
457 snew(gmx->dlgs, edNR);
458 for (i = 0; (i < asize(di)); i++)
460 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile,
462 0, 0, true, false, di[i].cb, gmx);
465 gmx->dlgs[edFilter] = select_filter(x11, gmx);
467 snew(gmx->mboxes, emNR);
468 for (i = 0; (i < emNR); i++)
470 gmx->mboxes[i] = mi[i](x11, gmx);
475 void done_dlgs(t_gmx *gmx)
479 for (i = 0; (i < edNR); i++)
481 FreeDlg(gmx->dlgs[i]);
483 for (i = 0; (i < emNR); i++)
485 FreeDlg(gmx->mboxes[i]);
489 void edit_file(const char *fn)
495 sprintf(script, "vi %s", fn);
496 shell_comm(fn, script, 0);