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,2019, 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.
48 # include <unistd.h> // for fork()
51 #include "gromacs/mdtypes/md_enums.h"
52 #include "gromacs/utility/arraysize.h"
53 #include "gromacs/utility/cstringutil.h"
54 #include "gromacs/utility/dir_separator.h"
55 #include "gromacs/utility/fatalerror.h"
56 #include "gromacs/utility/futil.h"
57 #include "gromacs/utility/smalloc.h"
65 #define MBFLAGS /* MB_APPLMODAL | */ MB_DONTSHOW
67 void write_gmx(t_x11* x11, t_gmx* gmx, int mess)
71 letter.type = ClientMessage;
72 letter.xclient.display = x11->disp;
73 letter.xclient.window = gmx->wd->self;
74 letter.xclient.message_type = 0;
75 letter.xclient.format = 32;
76 letter.xclient.data.l[0] = mess;
77 letter.xclient.data.l[1] = Button1;
78 XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter);
81 static void shell_comm(const char* title, const char* script, int nsleep)
87 std::strcpy(tmp, "dialogXXXXXX");
88 tfil = gmx_fopen_temporary(tmp);
90 fprintf(tfil, "%s\n", script);
91 fprintf(tfil, "sleep %d\n", nsleep);
94 std::sprintf(command, "xterm -title %s -e sh %s", title, tmp);
96 std::fprintf(stderr, "command: %s\n", command);
99 if (0 != std::system(command))
101 gmx_fatal(FARGS, "Failed to execute command: %s", command);
109 void show_mb(t_gmx* gmx, int mb)
111 if (mb >= 0 && mb < emNR)
114 ShowDlg(gmx->mboxes[mb]);
118 static void hide_mb(t_gmx* gmx)
120 if (gmx->which_mb >= 0 && gmx->which_mb < emNR)
122 HideDlg(gmx->mboxes[gmx->which_mb]);
127 static void MBCallback(t_x11* /*x11*/, int dlg_mess, int /*item_id*/, char* /*set*/, void* data)
131 gmx = static_cast<t_gmx*>(data);
132 if (dlg_mess == DLG_EXIT)
138 static t_dlg* about_mb(t_x11* x11, t_gmx* gmx)
140 const char* lines[] = { " G R O M A C S", " Machine for Simulating Chemistry",
141 " Copyright (c) 1992-2013",
142 " Berk Hess, David van der Spoel, Erik Lindahl",
143 " and many collaborators!" };
145 return MessageBox(x11, gmx->wd->self, gmx->wd->text, asize(lines), lines,
146 MB_OK | MB_ICONGMX | MBFLAGS, MBCallback, gmx);
149 static void QuitCB(t_x11* x11, int dlg_mess, int /*item_id*/, char* set, void* data)
152 gmx = static_cast<t_gmx*>(data);
155 if (dlg_mess == DLG_EXIT)
157 if (gmx_strcasecmp("yes", set) == 0)
159 write_gmx(x11, gmx, IDTERM);
164 static t_dlg* quit_mb(t_x11* x11, t_gmx* gmx)
166 const char* lines[] = { " Do you really want to Quit ?" };
168 return MessageBox(x11, gmx->wd->self, gmx->wd->text, asize(lines), lines,
169 MB_YESNO | MB_ICONSTOP | MBFLAGS, QuitCB, gmx);
172 static t_dlg* help_mb(t_x11* x11, t_gmx* gmx)
174 const char* lines[] = { " Help will soon be added" };
176 return MessageBox(x11, gmx->wd->self, gmx->wd->text, asize(lines), lines,
177 MB_OK | MB_ICONINFORMATION | MBFLAGS, MBCallback, gmx);
180 static t_dlg* ni_mb(t_x11* x11, t_gmx* gmx)
182 const char* lines[] = { " This feature has not been", " implemented yet." };
184 return MessageBox(x11, gmx->wd->self, gmx->wd->text, asize(lines), lines,
185 MB_OK | MB_ICONEXCLAMATION | MBFLAGS, MBCallback, gmx);
197 static void ExportCB(t_x11* x11, int dlg_mess, int item_id, char* set, void* data)
203 gmx = static_cast<t_gmx*>(data);
204 dlg = gmx->dlgs[edExport];
210 case eExGrom: gmx->ExpMode = eExpGromos; break;
211 case eExPdb: gmx->ExpMode = eExpPDB; break;
215 std::fprintf(stderr, "exportcb: item_id=%d\n", item_id);
219 if ((bOk = gmx_strcasecmp("ok", set)) == 0)
221 std::strcpy(gmx->confout, EditText(dlg, eExConf));
226 write_gmx(x11, gmx, IDDOEXPORT);
253 static void BondsCB(t_x11* x11, int dlg_mess, int item_id, char* set, void* data)
255 static int ebond = -1;
256 static int ebox = -1;
257 bool bOk, bBond = false;
262 gmx = static_cast<t_gmx*>(data);
265 ebond = gmx->man->molw->bond_type;
266 ebox = gmx->man->molw->boxtype;
276 else if (item_id <= eBNR + esbNR + 1)
278 ebox = item_id - eBNR - 2;
284 #define DO_NOT(b) (b) = (!(b))
288 case ebShowH: toggle_hydrogen(x11, gmx->man->molw); break;
289 case ebDPlus: DO_NOT(gmx->man->bPlus);
291 std::fprintf(stderr, "gmx->man->bPlus=%s\n", gmx->man->bPlus ? "true" : "false");
294 case ebRMPBC: toggle_pbc(gmx->man); break;
295 case ebCue: DO_NOT(gmx->man->bSort);
297 std::fprintf(stderr, "gmx->man->bSort=%s\n", gmx->man->bSort ? "true" : "false");
301 nskip = std::strtol(set, &endptr, 10);
305 std::fprintf(stderr, "nskip: %d frames\n", nskip);
309 gmx->man->nSkip = nskip;
314 nwait = std::strtol(set, &endptr, 10);
318 std::fprintf(stderr, "wait: %d ms\n", nwait);
322 gmx->man->nWait = nwait;
327 std::fprintf(stderr, "item_id: %d, set: %s\n", item_id, set);
334 bOk = (gmx_strcasecmp("ok", set) == 0);
335 HideDlg(gmx->dlgs[edBonds]);
342 case eBThin: write_gmx(x11, gmx, IDTHIN); break;
343 case eBFat: write_gmx(x11, gmx, IDFAT); break;
344 case eBVeryFat: write_gmx(x11, gmx, IDVERYFAT); break;
345 case eBSpheres: write_gmx(x11, gmx, IDBALLS); break;
347 gmx_fatal(FARGS, "Invalid bond type %d at %s, %d", ebond, __FILE__, __LINE__);
354 case esbNone: write_gmx(x11, gmx, IDNOBOX); break;
355 case esbRect: write_gmx(x11, gmx, IDRECTBOX); break;
356 case esbTri: write_gmx(x11, gmx, IDTRIBOX); break;
357 case esbTrunc: write_gmx(x11, gmx, IDTOBOX); break;
359 gmx_fatal(FARGS, "Invalid box type %d at %s, %d", ebox, __FILE__, __LINE__);
378 typedef t_dlg* t_mmb(t_x11* x11, t_gmx* gmx);
386 void init_dlgs(t_x11* x11, t_gmx* gmx)
388 static t_dlginit di[] = { { "export.dlg", ExportCB }, { "bonds.dlg", BondsCB } };
389 static t_mmb* mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb };
391 snew(gmx->dlgs, edNR);
392 for (int i = 0; (i < asize(di)); i++)
394 gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile, di[i].dlgfile, 0, 0, true, false,
398 gmx->dlgs[edFilter] = select_filter(x11, gmx);
400 snew(gmx->mboxes, emNR);
401 for (int i = 0; (i < emNR); i++)
403 gmx->mboxes[i] = mi[i](x11, gmx);
408 void done_dlgs(t_gmx* gmx)
412 for (i = 0; (i < edNR); i++)
414 FreeDlg(gmx->dlgs[i]);
416 for (i = 0; (i < emNR); i++)
418 FreeDlg(gmx->mboxes[i]);
422 void edit_file(const char* fn)
428 std::sprintf(script, "vi %s", fn);
429 shell_comm(fn, script, 0);