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.
43 #include <unistd.h> // for fork()
46 #include "gromacs/legacyheaders/macros.h"
51 #include "gromacs/legacyheaders/names.h"
55 #include "gromacs/utility/cstringutil.h"
56 #include "gromacs/utility/fatalerror.h"
57 #include "gromacs/utility/futil.h"
58 #include "gromacs/utility/smalloc.h"
60 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
62 void write_gmx(t_x11 *x11, t_gmx *gmx, int mess)
66 letter.type = ClientMessage;
67 letter.xclient.display = x11->disp;
68 letter.xclient.window = gmx->wd->self;
69 letter.xclient.message_type = 0;
70 letter.xclient.format = 32;
71 letter.xclient.data.l[0] = mess;
72 letter.xclient.data.l[1] = Button1;
73 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
76 static void shell_comm(const char *title, const char *script, int nsleep)
82 strcpy(tmp, "dialogXXXXXX");
85 if ((tfil = fopen(tmp, "w")) == NULL)
87 sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR);
94 if ((tfil = fopen(tmp, "w")) == NULL)
96 gmx_fatal(FARGS, "Can not open tmp file %s", tmp);
99 fprintf(tfil, "%s\n", script);
100 fprintf(tfil, "sleep %d\n", nsleep);
103 sprintf(command, "xterm -title %s -e sh %s", title, tmp);
105 fprintf(stderr, "command: %s\n", command);
109 printf("Warning-- No calls to system(3) supported on this platform.");
110 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
112 if (0 != system(command))
114 gmx_fatal(FARGS, "Failed to execute command: %s", command);
123 void show_mb(t_gmx *gmx, int mb)
125 if (mb >= 0 && mb < emNR)
128 ShowDlg(gmx->mboxes[mb]);
132 static void hide_mb(t_gmx *gmx)
134 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
136 HideDlg(gmx->mboxes[gmx->which_mb]);
141 static void MBCallback(t_x11 * /*x11*/, int dlg_mess, int /*item_id*/,
142 char * /*set*/, void *data)
147 if (dlg_mess == DLG_EXIT)
153 static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx)
155 const char *lines[] = {
157 " Machine for Simulating Chemistry",
158 " Copyright (c) 1992-2013",
159 " Berk Hess, David van der Spoel, Erik Lindahl",
160 " and many collaborators!"
163 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
164 asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS,
168 static void QuitCB(t_x11 *x11, int dlg_mess, int /*item_id*/,
169 char *set, void *data)
175 if (dlg_mess == DLG_EXIT)
177 if (gmx_strcasecmp("yes", set) == 0)
179 write_gmx(x11, gmx, IDTERM);
184 static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx)
186 const char *lines[] = {
187 " Do you really want to Quit ?"
190 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
192 MB_YESNO | MB_ICONSTOP | MBFLAGS,
196 static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx)
198 const char *lines[] = {
199 " Help will soon be added"
202 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
204 MB_OK | MB_ICONINFORMATION | MBFLAGS,
208 static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx)
210 const char *lines[] = {
211 " This feature has not been",
215 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
217 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
222 eExE, eExGrom, eExPdb, eExConf, eExNR
225 static void ExportCB(t_x11 *x11, int dlg_mess, int item_id,
226 char *set, void *data)
233 dlg = gmx->dlgs[edExport];
240 gmx->ExpMode = eExpGromos;
243 gmx->ExpMode = eExpPDB;
249 fprintf(stderr, "exportcb: item_id=%d\n", item_id);
253 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
255 strcpy(gmx->confout, EditText(dlg, eExConf));
260 write_gmx(x11, gmx, IDDOEXPORT);
267 eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC
270 static void Extract(t_dlg *dlg, int ID, char *buf)
274 et = EditText(dlg, ID);
282 ebShowH = 11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait
285 static void BondsCB(t_x11 *x11, int dlg_mess, int item_id,
286 char *set, void *data)
288 static int ebond = -1;
289 static int ebox = -1;
290 bool bOk, bBond = false;
298 ebond = gmx->man->molw->bond_type;
299 ebox = gmx->man->molw->boxtype;
309 else if (item_id <= eBNR+esbNR+1)
311 ebox = item_id-eBNR-2;
317 #define DO_NOT(b) (b) = (!(b))
322 toggle_hydrogen(x11, gmx->man->molw);
325 DO_NOT(gmx->man->bPlus);
327 fprintf(stderr, "gmx->man->bPlus=%s\n",
328 gmx->man->bPlus ? "true" : "false");
332 toggle_pbc(gmx->man);
335 DO_NOT(gmx->man->bSort);
337 fprintf(stderr, "gmx->man->bSort=%s\n",
338 gmx->man->bSort ? "true" : "false");
342 nskip = strtol(set, &endptr, 10);
346 fprintf(stderr, "nskip: %d frames\n", nskip);
350 gmx->man->nSkip = nskip;
355 nwait = strtol(set, &endptr, 10);
359 fprintf(stderr, "wait: %d ms\n", nwait);
363 gmx->man->nWait = nwait;
368 fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
375 bOk = (gmx_strcasecmp("ok", set) == 0);
376 HideDlg(gmx->dlgs[edBonds]);
384 write_gmx(x11, gmx, IDTHIN);
387 write_gmx(x11, gmx, IDFAT);
390 write_gmx(x11, gmx, IDVERYFAT);
393 write_gmx(x11, gmx, IDBALLS);
396 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d",
397 ebond, __FILE__, __LINE__);
405 write_gmx(x11, gmx, IDNOBOX);
408 write_gmx(x11, gmx, IDRECTBOX);
411 write_gmx(x11, gmx, IDTRIBOX);
414 write_gmx(x11, gmx, IDTOBOX);
417 gmx_fatal(FARGS, "Invalid box type %d at %s, %d",
418 ebox, __FILE__, __LINE__);
427 esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL
430 static bool in_set(int i, int n, int set[])
433 for (j = 0; (j < n); j++)
443 typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx);
450 void init_dlgs(t_x11 *x11, t_gmx *gmx)
452 static t_dlginit di[] = {
453 { "export.dlg", ExportCB },
454 { "bonds.dlg", BondsCB }
456 static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
459 snew(gmx->dlgs, edNR);
460 for (i = 0; (i < asize(di)); i++)
462 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile,
464 0, 0, true, false, di[i].cb, gmx);
467 gmx->dlgs[edFilter] = select_filter(x11, gmx);
469 snew(gmx->mboxes, emNR);
470 for (i = 0; (i < emNR); i++)
472 gmx->mboxes[i] = mi[i](x11, gmx);
477 void done_dlgs(t_gmx *gmx)
481 for (i = 0; (i < edNR); i++)
483 FreeDlg(gmx->dlgs[i]);
485 for (i = 0; (i < emNR); i++)
487 FreeDlg(gmx->mboxes[i]);
491 void edit_file(const char *fn)
497 sprintf(script, "vi %s", fn);
498 shell_comm(fn, script, 0);