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()
48 #include "gromacs/legacyheaders/macros.h"
49 #include "gromacs/legacyheaders/names.h"
50 #include "gromacs/utility/cstringutil.h"
51 #include "gromacs/utility/fatalerror.h"
52 #include "gromacs/utility/futil.h"
53 #include "gromacs/utility/smalloc.h"
61 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
63 void write_gmx(t_x11 *x11, t_gmx *gmx, int mess)
67 letter.type = ClientMessage;
68 letter.xclient.display = x11->disp;
69 letter.xclient.window = gmx->wd->self;
70 letter.xclient.message_type = 0;
71 letter.xclient.format = 32;
72 letter.xclient.data.l[0] = mess;
73 letter.xclient.data.l[1] = Button1;
74 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
77 static void shell_comm(const char *title, const char *script, int nsleep)
83 strcpy(tmp, "dialogXXXXXX");
86 if ((tfil = fopen(tmp, "w")) == NULL)
88 sprintf(tmp, "%ctmp%cdialogXXXXXX", DIR_SEPARATOR, DIR_SEPARATOR);
95 if ((tfil = fopen(tmp, "w")) == NULL)
97 gmx_fatal(FARGS, "Can not open tmp file %s", tmp);
100 fprintf(tfil, "%s\n", script);
101 fprintf(tfil, "sleep %d\n", nsleep);
104 sprintf(command, "xterm -title %s -e sh %s", title, tmp);
106 fprintf(stderr, "command: %s\n", command);
110 printf("Warning-- No calls to system(3) supported on this platform.");
111 printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
113 if (0 != system(command))
115 gmx_fatal(FARGS, "Failed to execute command: %s", command);
124 void show_mb(t_gmx *gmx, int mb)
126 if (mb >= 0 && mb < emNR)
129 ShowDlg(gmx->mboxes[mb]);
133 static void hide_mb(t_gmx *gmx)
135 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
137 HideDlg(gmx->mboxes[gmx->which_mb]);
142 static void MBCallback(t_x11 * /*x11*/, int dlg_mess, int /*item_id*/,
143 char * /*set*/, void *data)
148 if (dlg_mess == DLG_EXIT)
154 static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx)
156 const char *lines[] = {
158 " Machine for Simulating Chemistry",
159 " Copyright (c) 1992-2013",
160 " Berk Hess, David van der Spoel, Erik Lindahl",
161 " and many collaborators!"
164 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
165 asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS,
169 static void QuitCB(t_x11 *x11, int dlg_mess, int /*item_id*/,
170 char *set, void *data)
176 if (dlg_mess == DLG_EXIT)
178 if (gmx_strcasecmp("yes", set) == 0)
180 write_gmx(x11, gmx, IDTERM);
185 static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx)
187 const char *lines[] = {
188 " Do you really want to Quit ?"
191 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
193 MB_YESNO | MB_ICONSTOP | MBFLAGS,
197 static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx)
199 const char *lines[] = {
200 " Help will soon be added"
203 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
205 MB_OK | MB_ICONINFORMATION | MBFLAGS,
209 static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx)
211 const char *lines[] = {
212 " This feature has not been",
216 return MessageBox(x11, gmx->wd->self, gmx->wd->text,
218 MB_OK | MB_ICONEXCLAMATION | MBFLAGS,
223 eExE, eExGrom, eExPdb, eExConf, eExNR
226 static void ExportCB(t_x11 *x11, int dlg_mess, int item_id,
227 char *set, void *data)
234 dlg = gmx->dlgs[edExport];
241 gmx->ExpMode = eExpGromos;
244 gmx->ExpMode = eExpPDB;
250 fprintf(stderr, "exportcb: item_id=%d\n", item_id);
254 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
256 strcpy(gmx->confout, EditText(dlg, eExConf));
261 write_gmx(x11, gmx, IDDOEXPORT);
268 eg0, egTOPOL, egCONFIN, egPARAM, eg1, eg1PROC, eg32PROC
271 static void Extract(t_dlg *dlg, int ID, char *buf)
275 et = EditText(dlg, ID);
283 ebShowH = 11, ebDPlus, ebRMPBC, ebCue, ebSkip, ebWait
286 static void BondsCB(t_x11 *x11, int dlg_mess, int item_id,
287 char *set, void *data)
289 static int ebond = -1;
290 static int ebox = -1;
291 bool bOk, bBond = false;
299 ebond = gmx->man->molw->bond_type;
300 ebox = gmx->man->molw->boxtype;
310 else if (item_id <= eBNR+esbNR+1)
312 ebox = item_id-eBNR-2;
318 #define DO_NOT(b) (b) = (!(b))
323 toggle_hydrogen(x11, gmx->man->molw);
326 DO_NOT(gmx->man->bPlus);
328 fprintf(stderr, "gmx->man->bPlus=%s\n",
329 gmx->man->bPlus ? "true" : "false");
333 toggle_pbc(gmx->man);
336 DO_NOT(gmx->man->bSort);
338 fprintf(stderr, "gmx->man->bSort=%s\n",
339 gmx->man->bSort ? "true" : "false");
343 nskip = strtol(set, &endptr, 10);
347 fprintf(stderr, "nskip: %d frames\n", nskip);
351 gmx->man->nSkip = nskip;
356 nwait = strtol(set, &endptr, 10);
360 fprintf(stderr, "wait: %d ms\n", nwait);
364 gmx->man->nWait = nwait;
369 fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
376 bOk = (gmx_strcasecmp("ok", set) == 0);
377 HideDlg(gmx->dlgs[edBonds]);
385 write_gmx(x11, gmx, IDTHIN);
388 write_gmx(x11, gmx, IDFAT);
391 write_gmx(x11, gmx, IDVERYFAT);
394 write_gmx(x11, gmx, IDBALLS);
397 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d",
398 ebond, __FILE__, __LINE__);
406 write_gmx(x11, gmx, IDNOBOX);
409 write_gmx(x11, gmx, IDRECTBOX);
412 write_gmx(x11, gmx, IDTRIBOX);
415 write_gmx(x11, gmx, IDTOBOX);
418 gmx_fatal(FARGS, "Invalid box type %d at %s, %d",
419 ebox, __FILE__, __LINE__);
428 esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL
431 static bool in_set(int i, int n, int set[])
434 for (j = 0; (j < n); j++)
444 typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx);
451 void init_dlgs(t_x11 *x11, t_gmx *gmx)
453 static t_dlginit di[] = {
454 { "export.dlg", ExportCB },
455 { "bonds.dlg", BondsCB }
457 static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
460 snew(gmx->dlgs, edNR);
461 for (i = 0; (i < asize(di)); i++)
463 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile,
465 0, 0, true, false, di[i].cb, gmx);
468 gmx->dlgs[edFilter] = select_filter(x11, gmx);
470 snew(gmx->mboxes, emNR);
471 for (i = 0; (i < emNR); i++)
473 gmx->mboxes[i] = mi[i](x11, gmx);
478 void done_dlgs(t_gmx *gmx)
482 for (i = 0; (i < edNR); i++)
484 FreeDlg(gmx->dlgs[i]);
486 for (i = 0; (i < emNR); i++)
488 FreeDlg(gmx->mboxes[i]);
492 void edit_file(const char *fn)
498 sprintf(script, "vi %s", fn);
499 shell_comm(fn, script, 0);