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.
42 #include <unistd.h> // for fork()
45 #include "gromacs/utility/smalloc.h"
48 #include "gromacs/utility/cstringutil.h"
56 #include "gromacs/fileio/futil.h"
57 #include "gmx_fatal.h"
59 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
61 void write_gmx(t_x11 *x11, t_gmx *gmx, int mess)
65 letter.type = ClientMessage;
66 letter.xclient.display = x11->disp;
67 letter.xclient.window = gmx->wd->self;
68 letter.xclient.message_type = 0;
69 letter.xclient.format = 32;
70 letter.xclient.data.l[0] = mess;
71 letter.xclient.data.l[1] = Button1;
72 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
75 static void shell_comm(const char *title, const char *script, int nsleep)
81 strcpy(tmp, "dialogXXXXXX");
84 if ((tfil = fopen(tmp, "w")) == NULL)
86 sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR);
93 if ((tfil = fopen(tmp, "w")) == NULL)
95 gmx_fatal(FARGS, "Can not open tmp file %s", tmp);
98 fprintf(tfil, "%s\n", script);
99 fprintf(tfil, "sleep %d\n", nsleep);
102 sprintf(command, "xterm -title %s -e sh %s", title, tmp);
104 fprintf(stderr, "command: %s\n", command);
108 printf("Warning-- No calls to system(3) supported on this platform.");
109 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
111 if (0 != system(command))
113 gmx_fatal(FARGS, "Failed to execute command: %s", command);
122 void show_mb(t_gmx *gmx, int mb)
124 if (mb >= 0 && mb < emNR)
127 ShowDlg(gmx->mboxes[mb]);
131 static void hide_mb(t_gmx *gmx)
133 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
135 HideDlg(gmx->mboxes[gmx->which_mb]);
140 static void MBCallback(t_x11 * /*x11*/, int dlg_mess, int /*item_id*/,
141 char * /*set*/, void *data)
146 if (dlg_mess == DLG_EXIT)
152 static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx)
154 const char *lines[] = {
156 " Machine for Simulating Chemistry",
157 " Copyright (c) 1992-2013",
158 " Berk Hess, David van der Spoel, Erik Lindahl",
159 " and many collaborators!"
162 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
163 asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS,
167 static void QuitCB(t_x11 *x11, int dlg_mess, int /*item_id*/,
168 char *set, void *data)
174 if (dlg_mess == DLG_EXIT)
176 if (gmx_strcasecmp("yes", set) == 0)
178 write_gmx(x11, gmx, IDTERM);
183 static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx)
185 const char *lines[] = {
186 " Do you really want to Quit ?"
189 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
191 MB_YESNO | MB_ICONSTOP | MBFLAGS,
195 static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx)
197 const char *lines[] = {
198 " Help will soon be added"
201 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
203 MB_OK | MB_ICONINFORMATION | MBFLAGS,
207 static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx)
209 const char *lines[] = {
210 " This feature has not been",
214 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
216 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
221 eExE, eExGrom, eExPdb, eExConf, eExNR
224 static void ExportCB(t_x11 *x11, int dlg_mess, int item_id,
225 char *set, void *data)
232 dlg = gmx->dlgs[edExport];
239 gmx->ExpMode = eExpGromos;
242 gmx->ExpMode = eExpPDB;
248 fprintf(stderr, "exportcb: item_id=%d\n", item_id);
252 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
254 strcpy(gmx->confout, EditText(dlg, eExConf));
259 write_gmx(x11, gmx, IDDOEXPORT);
266 eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC
269 static void Extract(t_dlg *dlg, int ID, char *buf)
273 et = EditText(dlg, ID);
281 ebShowH = 11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait
284 static void BondsCB(t_x11 *x11, int dlg_mess, int item_id,
285 char *set, void *data)
287 static int ebond = -1;
288 static int ebox = -1;
289 bool bOk, bBond = false;
297 ebond = gmx->man->molw->bond_type;
298 ebox = gmx->man->molw->boxtype;
308 else if (item_id <= eBNR+esbNR+1)
310 ebox = item_id-eBNR-2;
316 #define DO_NOT(b) (b) = (!(b))
321 toggle_hydrogen(x11, gmx->man->molw);
324 DO_NOT(gmx->man->bPlus);
326 fprintf(stderr, "gmx->man->bPlus=%s\n",
327 gmx->man->bPlus ? "true" : "false");
331 toggle_pbc(gmx->man);
334 DO_NOT(gmx->man->bSort);
336 fprintf(stderr, "gmx->man->bSort=%s\n",
337 gmx->man->bSort ? "true" : "false");
341 nskip = strtol(set, &endptr, 10);
345 fprintf(stderr, "nskip: %d frames\n", nskip);
349 gmx->man->nSkip = nskip;
354 nwait = strtol(set, &endptr, 10);
358 fprintf(stderr, "wait: %d ms\n", nwait);
362 gmx->man->nWait = nwait;
367 fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
374 bOk = (gmx_strcasecmp("ok", set) == 0);
375 HideDlg(gmx->dlgs[edBonds]);
383 write_gmx(x11, gmx, IDTHIN);
386 write_gmx(x11, gmx, IDFAT);
389 write_gmx(x11, gmx, IDVERYFAT);
392 write_gmx(x11, gmx, IDBALLS);
395 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d",
396 ebond, __FILE__, __LINE__);
404 write_gmx(x11, gmx, IDNOBOX);
407 write_gmx(x11, gmx, IDRECTBOX);
410 write_gmx(x11, gmx, IDTRIBOX);
413 write_gmx(x11, gmx, IDTOBOX);
416 gmx_fatal(FARGS, "Invalid box type %d at %s, %d",
417 ebox, __FILE__, __LINE__);
426 esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL
429 static bool in_set(int i, int n, int set[])
432 for (j = 0; (j < n); j++)
442 typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx);
449 void init_dlgs(t_x11 *x11, t_gmx *gmx)
451 static t_dlginit di[] = {
452 { "export.dlg", ExportCB },
453 { "bonds.dlg", BondsCB }
455 static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
458 snew(gmx->dlgs, edNR);
459 for (i = 0; (i < asize(di)); i++)
461 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile,
463 0, 0, true, false, di[i].cb, gmx);
466 gmx->dlgs[edFilter] = select_filter(x11, gmx);
468 snew(gmx->mboxes, emNR);
469 for (i = 0; (i < emNR); i++)
471 gmx->mboxes[i] = mi[i](x11, gmx);
476 void done_dlgs(t_gmx *gmx)
480 for (i = 0; (i < edNR); i++)
482 FreeDlg(gmx->dlgs[i]);
484 for (i = 0; (i < emNR); i++)
486 FreeDlg(gmx->mboxes[i]);
490 void edit_file(const char *fn)
496 sprintf(script, "vi %s", fn);
497 shell_comm(fn, script, 0);