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,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
49 # include <unistd.h> // for fork()
52 #include "gromacs/mdtypes/md_enums.h"
53 #include "gromacs/utility/arraysize.h"
54 #include "gromacs/utility/cstringutil.h"
55 #include "gromacs/utility/dir_separator.h"
56 #include "gromacs/utility/fatalerror.h"
57 #include "gromacs/utility/futil.h"
58 #include "gromacs/utility/smalloc.h"
66 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
68 void write_gmx(t_x11* x11, t_gmx* gmx, int mess)
72 letter.type = ClientMessage;
73 letter.xclient.display = x11->disp;
74 letter.xclient.window = gmx->wd->self;
75 letter.xclient.message_type = 0;
76 letter.xclient.format = 32;
77 letter.xclient.data.l[0] = mess;
78 letter.xclient.data.l[1] = Button1;
79 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
82 static void shell_comm(const char* title, const char* script, int nsleep)
88 std::strcpy(tmp, "dialogXXXXXX");
89 tfil = gmx_fopen_temporary(tmp);
91 fprintf(tfil, "%s\n", script);
92 fprintf(tfil, "sleep %d\n", nsleep);
95 std::sprintf(command, "xterm -title %s -e sh %s", title, tmp);
97 std::fprintf(stderr, "command: %s\n", command);
100 if (0 != std::system(command))
102 gmx_fatal(FARGS, "Failed to execute command: %s", command);
110 void show_mb(t_gmx* gmx, int mb)
112 if (mb >= 0 && mb < emNR)
115 ShowDlg(gmx->mboxes[mb]);
119 static void hide_mb(t_gmx* gmx)
121 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
123 HideDlg(gmx->mboxes[gmx->which_mb]);
128 static void MBCallback(t_x11* /*x11*/, int dlg_mess, int /*item_id*/, char* /*set*/, void* data)
132 gmx = static_cast<t_gmx*>(data);
133 if (dlg_mess == DLG_EXIT)
139 static t_dlg* about_mb(t_x11* x11, t_gmx* gmx)
141 const char* lines[] = { " G R O M A C S",
142 " Machine for Simulating Chemistry",
143 " Copyright (c) 1992-2013",
144 " Berk Hess, David van der Spoel, Erik Lindahl",
145 " and many collaborators!" };
148 x11, gmx->wd->self, gmx->wd->text, asize(lines), lines, MB_OK | MB_ICONGMX | MBFLAGS, MBCallback, gmx);
151 static void QuitCB(t_x11* x11, int dlg_mess, int /*item_id*/, char* set, void* data)
154 gmx = static_cast<t_gmx*>(data);
157 if (dlg_mess == DLG_EXIT)
159 if (gmx_strcasecmp("yes", set) == 0)
161 write_gmx(x11, gmx, IDTERM);
166 static t_dlg* quit_mb(t_x11* x11, t_gmx* gmx)
168 const char* lines[] = { " Do you really want to Quit ?" };
171 x11, gmx->wd->self, gmx->wd->text, asize(lines), lines, MB_YESNO | MB_ICONSTOP | MBFLAGS, QuitCB, gmx);
174 static t_dlg* help_mb(t_x11* x11, t_gmx* gmx)
176 const char* lines[] = { " Help will soon be added" };
179 x11, gmx->wd->self, gmx->wd->text, asize(lines), lines, MB_OK | MB_ICONINFORMATION | MBFLAGS, MBCallback, gmx);
182 static t_dlg* ni_mb(t_x11* x11, t_gmx* gmx)
184 const char* lines[] = { " This feature has not been", " implemented yet." };
187 x11, gmx->wd->self, gmx->wd->text, asize(lines), lines, MB_OK | MB_ICONEXCLAMATION | MBFLAGS, MBCallback, gmx);
199 static void ExportCB(t_x11* x11, int dlg_mess, int item_id, char* set, void* data)
205 gmx = static_cast<t_gmx*>(data);
206 dlg = gmx->dlgs[edExport];
212 case eExGrom: gmx->ExpMode = eExpGromos; break;
213 case eExPdb: gmx->ExpMode = eExpPDB; break;
217 std::fprintf(stderr, "exportcb: item_id=%d\n", item_id);
221 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
223 std::strcpy(gmx->confout, EditText(dlg, eExConf));
228 write_gmx(x11, gmx, IDDOEXPORT);
255 static void BondsCB(t_x11* x11, int dlg_mess, int item_id, char* set, void* data)
257 static int ebond = -1;
258 static int ebox = -1;
259 bool bOk, bBond = false;
264 gmx = static_cast<t_gmx*>(data);
267 ebond = gmx->man->molw->bond_type;
268 ebox = gmx->man->molw->boxtype;
278 else if (item_id <= eBNR + esbNR + 1)
280 ebox = item_id - eBNR - 2;
286 #define DO_NOT(b) (b) = (!(b))
290 case ebShowH: toggle_hydrogen(x11, gmx->man->molw); break;
291 case ebDPlus: DO_NOT(gmx->man->bPlus);
293 std::fprintf(stderr, "gmx->man->bPlus=%s\n", gmx->man->bPlus ? "true" : "false");
296 case ebRMPBC: toggle_pbc(gmx->man); break;
297 case ebCue: DO_NOT(gmx->man->bSort);
299 std::fprintf(stderr, "gmx->man->bSort=%s\n", gmx->man->bSort ? "true" : "false");
303 nskip = std::strtol(set, &endptr, 10);
307 std::fprintf(stderr, "nskip: %d frames\n", nskip);
311 gmx->man->nSkip = nskip;
316 nwait = std::strtol(set, &endptr, 10);
320 std::fprintf(stderr, "wait: %d ms\n", nwait);
324 gmx->man->nWait = nwait;
329 std::fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
336 bOk = (gmx_strcasecmp("ok", set) == 0);
337 HideDlg(gmx->dlgs[edBonds]);
344 case eBThin: write_gmx(x11, gmx, IDTHIN); break;
345 case eBFat: write_gmx(x11, gmx, IDFAT); break;
346 case eBVeryFat: write_gmx(x11, gmx, IDVERYFAT); break;
347 case eBSpheres: write_gmx(x11, gmx, IDBALLS); break;
349 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d", ebond, __FILE__, __LINE__);
356 case esbNone: write_gmx(x11, gmx, IDNOBOX); break;
357 case esbRect: write_gmx(x11, gmx, IDRECTBOX); break;
358 case esbTri: write_gmx(x11, gmx, IDTRIBOX); break;
359 case esbTrunc: write_gmx(x11, gmx, IDTOBOX); break;
361 gmx_fatal(FARGS, "Invalid box type %d at %s, %d", ebox, __FILE__, __LINE__);
380 typedef t_dlg* t_mmb(t_x11* x11, t_gmx* gmx);
388 void init_dlgs(t_x11* x11, t_gmx* gmx)
390 static t_dlginit di[] = { { "export.dlg", ExportCB }, { "bonds.dlg", BondsCB } };
391 static t_mmb* mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
393 snew(gmx->dlgs, edNR);
394 for (int i = 0; (i < asize(di)); i++)
396 gmx->dlgs[i] = ReadDlg(
397 x11, gmx->wd->self, di[i].dlgfile, di[i].dlgfile, 0, 0, true, false, di[i].cb, gmx);
400 gmx->dlgs[edFilter] = select_filter(x11, gmx);
402 snew(gmx->mboxes, emNR);
403 for (int i = 0; (i < emNR); i++)
405 gmx->mboxes[i] = mi[i](x11, gmx);
410 void done_dlgs(t_gmx* gmx)
414 for (i = 0; (i < edNR); i++)
416 FreeDlg(gmx->dlgs[i]);
418 for (i = 0; (i < emNR); i++)
420 FreeDlg(gmx->mboxes[i]);
424 void edit_file(const char* fn)
430 std::sprintf(script, "vi %s", fn);
431 shell_comm(fn, script, 0);