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, 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*/,
128 char * /*set*/, void *data
)
133 if (dlg_mess
== DLG_EXIT
)
139 static t_dlg
*about_mb(t_x11
*x11
, t_gmx
*gmx
)
141 const char *lines
[] = {
143 " Machine for Simulating Chemistry",
144 " Copyright (c) 1992-2013",
145 " Berk Hess, David van der Spoel, Erik Lindahl",
146 " and many collaborators!"
149 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
150 asize(lines
), lines
, MB_OK
| MB_ICONGMX
| MBFLAGS
,
154 static void QuitCB(t_x11
*x11
, int dlg_mess
, int /*item_id*/,
155 char *set
, void *data
)
161 if (dlg_mess
== DLG_EXIT
)
163 if (gmx_strcasecmp("yes", set
) == 0)
165 write_gmx(x11
, gmx
, IDTERM
);
170 static t_dlg
*quit_mb(t_x11
*x11
, t_gmx
*gmx
)
172 const char *lines
[] = {
173 " Do you really want to Quit ?"
176 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
178 MB_YESNO
| MB_ICONSTOP
| MBFLAGS
,
182 static t_dlg
*help_mb(t_x11
*x11
, t_gmx
*gmx
)
184 const char *lines
[] = {
185 " Help will soon be added"
188 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
190 MB_OK
| MB_ICONINFORMATION
| MBFLAGS
,
194 static t_dlg
*ni_mb(t_x11
*x11
, t_gmx
*gmx
)
196 const char *lines
[] = {
197 " This feature has not been",
201 return MessageBox(x11
, gmx
->wd
->self
, gmx
->wd
->text
,
203 MB_OK
| MB_ICONEXCLAMATION
| MBFLAGS
,
208 eExE
, eExGrom
, eExPdb
, eExConf
, eExNR
211 static void ExportCB(t_x11
*x11
, int dlg_mess
, int item_id
,
212 char *set
, void *data
)
219 dlg
= gmx
->dlgs
[edExport
];
226 gmx
->ExpMode
= eExpGromos
;
229 gmx
->ExpMode
= eExpPDB
;
235 std::fprintf(stderr
, "exportcb: item_id=%d\n", item_id
);
239 if ((bOk
= gmx_strcasecmp("ok", set
)) == 0)
241 std::strcpy(gmx
->confout
, EditText(dlg
, eExConf
));
246 write_gmx(x11
, gmx
, IDDOEXPORT
);
253 eg0
, egTOPOL
, egCONFIN
, egPARAM
, eg1
, eg1PROC
, eg32PROC
256 static void Extract(t_dlg
*dlg
, int ID
, char *buf
)
260 et
= EditText(dlg
, ID
);
263 std::strcpy(buf
, et
);
268 ebShowH
= 11, ebDPlus
, ebRMPBC
, ebCue
, ebSkip
, ebWait
271 static void BondsCB(t_x11
*x11
, int dlg_mess
, int item_id
,
272 char *set
, void *data
)
274 static int ebond
= -1;
275 static int ebox
= -1;
276 bool bOk
, bBond
= false;
284 ebond
= gmx
->man
->molw
->bond_type
;
285 ebox
= gmx
->man
->molw
->boxtype
;
295 else if (item_id
<= eBNR
+esbNR
+1)
297 ebox
= item_id
-eBNR
-2;
303 #define DO_NOT(b) (b) = (!(b))
308 toggle_hydrogen(x11
, gmx
->man
->molw
);
311 DO_NOT(gmx
->man
->bPlus
);
313 std::fprintf(stderr
, "gmx->man->bPlus=%s\n",
314 gmx
->man
->bPlus
? "true" : "false");
318 toggle_pbc(gmx
->man
);
321 DO_NOT(gmx
->man
->bSort
);
323 std::fprintf(stderr
, "gmx->man->bSort=%s\n",
324 gmx
->man
->bSort
? "true" : "false");
328 nskip
= std::strtol(set
, &endptr
, 10);
332 std::fprintf(stderr
, "nskip: %d frames\n", nskip
);
336 gmx
->man
->nSkip
= nskip
;
341 nwait
= std::strtol(set
, &endptr
, 10);
345 std::fprintf(stderr
, "wait: %d ms\n", nwait
);
349 gmx
->man
->nWait
= nwait
;
354 std::fprintf(stderr
, "item_id: %d, set: %s\n", item_id
, set
);
361 bOk
= (gmx_strcasecmp("ok", set
) == 0);
362 HideDlg(gmx
->dlgs
[edBonds
]);
370 write_gmx(x11
, gmx
, IDTHIN
);
373 write_gmx(x11
, gmx
, IDFAT
);
376 write_gmx(x11
, gmx
, IDVERYFAT
);
379 write_gmx(x11
, gmx
, IDBALLS
);
382 gmx_fatal(FARGS
, "Invalid bond type %d at %s, %d",
383 ebond
, __FILE__
, __LINE__
);
391 write_gmx(x11
, gmx
, IDNOBOX
);
394 write_gmx(x11
, gmx
, IDRECTBOX
);
397 write_gmx(x11
, gmx
, IDTRIBOX
);
400 write_gmx(x11
, gmx
, IDTOBOX
);
403 gmx_fatal(FARGS
, "Invalid box type %d at %s, %d",
404 ebox
, __FILE__
, __LINE__
);
413 esFUNCT
= 1, esBSHOW
, esINFIL
, esINDEXFIL
, esLSQ
, esSHOW
, esPLOTFIL
416 static bool in_set(int i
, int n
, int set
[])
419 for (j
= 0; (j
< n
); j
++)
429 typedef t_dlg
*t_mmb (t_x11
*x11
, t_gmx
*gmx
);
436 void init_dlgs(t_x11
*x11
, t_gmx
*gmx
)
438 static t_dlginit di
[] = {
439 { "export.dlg", ExportCB
},
440 { "bonds.dlg", BondsCB
}
442 static t_mmb
*mi
[emNR
] = { quit_mb
, help_mb
, about_mb
, ni_mb
};
445 snew(gmx
->dlgs
, edNR
);
446 for (i
= 0; (i
< asize(di
)); i
++)
448 gmx
->dlgs
[i
] = ReadDlg(x11
, gmx
->wd
->self
, di
[i
].dlgfile
,
450 0, 0, true, false, di
[i
].cb
, gmx
);
453 gmx
->dlgs
[edFilter
] = select_filter(x11
, gmx
);
455 snew(gmx
->mboxes
, emNR
);
456 for (i
= 0; (i
< emNR
); i
++)
458 gmx
->mboxes
[i
] = mi
[i
](x11
, gmx
);
463 void done_dlgs(t_gmx
*gmx
)
467 for (i
= 0; (i
< edNR
); i
++)
469 FreeDlg(gmx
->dlgs
[i
]);
471 for (i
= 0; (i
< emNR
); i
++)
473 FreeDlg(gmx
->mboxes
[i
]);
477 void edit_file(const char *fn
)
483 std::sprintf(script
, "vi %s", fn
);
484 shell_comm(fn
, script
, 0);