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, 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.
52 #include "gromacs/fileio/futil.h"
53 #include "gmx_fatal.h"
55 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
57 void write_gmx(t_x11 *x11, t_gmx *gmx, int mess)
61 letter.type = ClientMessage;
62 letter.xclient.display = x11->disp;
63 letter.xclient.window = gmx->wd->self;
64 letter.xclient.message_type = 0;
65 letter.xclient.format = 32;
66 letter.xclient.data.l[0] = mess;
67 letter.xclient.data.l[1] = Button1;
68 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
71 static void shell_comm(const char *title, const char *script, int nsleep)
77 strcpy(tmp, "dialogXXXXXX");
80 if ((tfil = fopen(tmp, "w")) == NULL)
82 sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR);
89 if ((tfil = fopen(tmp, "w")) == NULL)
91 gmx_fatal(FARGS, "Can not open tmp file %s", tmp);
94 fprintf(tfil, "%s\n", script);
95 fprintf(tfil, "sleep %d\n", nsleep);
98 sprintf(command, "xterm -title %s -e sh %s", title, tmp);
100 fprintf(stderr, "command: %s\n", command);
104 printf("Warning-- No calls to system(3) supported on this platform.");
105 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
107 if (0 != system(command))
109 gmx_fatal(FARGS, "Failed to execute command: %s", command);
118 void show_mb(t_gmx *gmx, int mb)
120 if (mb >= 0 && mb < emNR)
123 ShowDlg(gmx->mboxes[mb]);
127 static void hide_mb(t_gmx *gmx)
129 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
131 HideDlg(gmx->mboxes[gmx->which_mb]);
136 static void MBCallback(t_x11 * /*x11*/, int dlg_mess, int /*item_id*/,
137 char * /*set*/, void *data)
142 if (dlg_mess == DLG_EXIT)
148 static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx)
150 const char *lines[] = {
152 " Machine for Simulating Chemistry",
153 " Copyright (c) 1992-2013",
154 " Berk Hess, David van der Spoel, Erik Lindahl",
155 " and many collaborators!"
158 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
159 asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS,
163 static void QuitCB(t_x11 *x11, int dlg_mess, int /*item_id*/,
164 char *set, void *data)
170 if (dlg_mess == DLG_EXIT)
172 if (gmx_strcasecmp("yes", set) == 0)
174 write_gmx(x11, gmx, IDTERM);
179 static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx)
181 const char *lines[] = {
182 " Do you really want to Quit ?"
185 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
187 MB_YESNO | MB_ICONSTOP | MBFLAGS,
191 static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx)
193 const char *lines[] = {
194 " Help will soon be added"
197 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
199 MB_OK | MB_ICONINFORMATION | MBFLAGS,
203 static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx)
205 const char *lines[] = {
206 " This feature has not been",
210 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
212 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
217 eExE, eExGrom, eExPdb, eExConf, eExNR
220 static void ExportCB(t_x11 *x11, int dlg_mess, int item_id,
221 char *set, void *data)
228 dlg = gmx->dlgs[edExport];
235 gmx->ExpMode = eExpGromos;
238 gmx->ExpMode = eExpPDB;
244 fprintf(stderr, "exportcb: item_id=%d\n", item_id);
248 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
250 strcpy(gmx->confout, EditText(dlg, eExConf));
255 write_gmx(x11, gmx, IDDOEXPORT);
262 eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC
265 static void Extract(t_dlg *dlg, int ID, char *buf)
269 et = EditText(dlg, ID);
277 ebShowH = 11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait
280 static void BondsCB(t_x11 *x11, int dlg_mess, int item_id,
281 char *set, void *data)
283 static int ebond = -1;
284 static int ebox = -1;
285 bool bOk, bBond = false;
293 ebond = gmx->man->molw->bond_type;
294 ebox = gmx->man->molw->boxtype;
304 else if (item_id <= eBNR+esbNR+1)
306 ebox = item_id-eBNR-2;
312 #define DO_NOT(b) (b) = (!(b))
317 toggle_hydrogen(x11, gmx->man->molw);
320 DO_NOT(gmx->man->bPlus);
322 fprintf(stderr, "gmx->man->bPlus=%s\n",
323 gmx->man->bPlus ? "true" : "false");
327 toggle_pbc(gmx->man);
330 DO_NOT(gmx->man->bSort);
332 fprintf(stderr, "gmx->man->bSort=%s\n",
333 gmx->man->bSort ? "true" : "false");
337 nskip = strtol(set, &endptr, 10);
341 fprintf(stderr, "nskip: %d frames\n", nskip);
345 gmx->man->nSkip = nskip;
350 nwait = strtol(set, &endptr, 10);
354 fprintf(stderr, "wait: %d ms\n", nwait);
358 gmx->man->nWait = nwait;
363 fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
370 bOk = (gmx_strcasecmp("ok", set) == 0);
371 HideDlg(gmx->dlgs[edBonds]);
379 write_gmx(x11, gmx, IDTHIN);
382 write_gmx(x11, gmx, IDFAT);
385 write_gmx(x11, gmx, IDVERYFAT);
388 write_gmx(x11, gmx, IDBALLS);
391 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d",
392 ebond, __FILE__, __LINE__);
400 write_gmx(x11, gmx, IDNOBOX);
403 write_gmx(x11, gmx, IDRECTBOX);
406 write_gmx(x11, gmx, IDTRIBOX);
409 write_gmx(x11, gmx, IDTOBOX);
412 gmx_fatal(FARGS, "Invalid box type %d at %s, %d",
413 ebox, __FILE__, __LINE__);
422 esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL
425 static bool in_set(int i, int n, int set[])
428 for (j = 0; (j < n); j++)
438 typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx);
445 void init_dlgs(t_x11 *x11, t_gmx *gmx)
447 static t_dlginit di[] = {
448 { "export.dlg", ExportCB },
449 { "bonds.dlg", BondsCB }
451 static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
454 snew(gmx->dlgs, edNR);
455 for (i = 0; (i < asize(di)); i++)
457 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile,
459 0, 0, true, false, di[i].cb, gmx);
462 gmx->dlgs[edFilter] = select_filter(x11, gmx);
464 snew(gmx->mboxes, emNR);
465 for (i = 0; (i < emNR); i++)
467 gmx->mboxes[i] = mi[i](x11, gmx);
472 void done_dlgs(t_gmx *gmx)
476 for (i = 0; (i < edNR); i++)
478 FreeDlg(gmx->dlgs[i]);
480 for (i = 0; (i < emNR); i++)
482 FreeDlg(gmx->mboxes[i]);
486 void edit_file(const char *fn)
492 sprintf(script, "vi %s", fn);
493 shell_comm(fn, script, 0);