From 3beddf1e238e898a2b6d38318ee55e2effbe2129 Mon Sep 17 00:00:00 2001 From: David van der Spoel Date: Sat, 31 Aug 2013 14:44:53 +0200 Subject: [PATCH] Moved ngmx to C++, renamed it to view. Part of #673 Moved all files to src/programs/view and made executable part of the gmx binary as "gmx view". Removed warnings. Replacing min and max by std::min and std::max. Removed warning in asize macro. Changed typedef enums to C++ enums. Changed gmx_bool to bool. Removed g_showcol, g_xrama, xstat, test_ngmx_dialog Change-Id: I88fc541e27705c498703006f461dd2b9b1e6a3f5 --- CMakeLists.txt | 3 + src/CMakeLists.txt | 5 +- src/config.h.cmakein | 3 + src/gromacs/legacyheaders/macros.h | 2 +- src/ngmx/CMakeLists.txt | 31 -- src/ngmx/g_showcol.c | 312 -------------- src/ngmx/g_xrama.cpp | 392 ------------------ src/ngmx/rama.bm | 65 --- src/ngmx/test_ngmx_dialog.c | 68 --- src/ngmx/xstat.c | 231 ----------- src/programs/CMakeLists.txt | 16 +- src/programs/gmx/legacymodules.cpp | 4 +- src/{ngmx => programs/view}/Xstuff.h | 0 src/{ngmx => programs/view}/alert.bm | 0 .../buttons.c => programs/view/buttons.cpp} | 24 +- src/{ngmx => programs/view}/buttons.h | 2 +- .../dialogs.c => programs/view/dialogs.cpp} | 92 ++-- src/{ngmx => programs/view}/dialogs.h | 14 +- src/{ngmx => programs/view}/ff.bm | 0 src/{ngmx/fgrid.c => programs/view/fgrid.cpp} | 39 +- src/{ngmx => programs/view}/fgrid.h | 14 +- .../filter.c => programs/view/filter.cpp} | 12 +- src/{ngmx => programs/view}/gromacs.bm | 0 src/{ngmx => programs/view}/info.bm | 0 src/{ngmx/logo.c => programs/view/logo.cpp} | 22 +- src/{ngmx => programs/view}/logo.h | 8 +- .../manager.c => programs/view/manager.cpp} | 105 ++--- src/{ngmx => programs/view}/manager.h | 40 +- src/{ngmx/molps.c => programs/view/molps.cpp} | 29 +- src/{ngmx => programs/view}/molps.h | 0 src/{ngmx/nleg.c => programs/view/nleg.cpp} | 12 +- src/{ngmx => programs/view}/nleg.h | 0 src/{ngmx/nmol.c => programs/view/nmol.cpp} | 44 +- src/{ngmx => programs/view}/nmol.h | 2 +- src/{ngmx => programs/view}/play.bm | 0 src/{ngmx/popup.c => programs/view/popup.cpp} | 20 +- src/{ngmx => programs/view}/popup.h | 8 +- .../pulldown.c => programs/view/pulldown.cpp} | 22 +- src/{ngmx => programs/view}/pulldown.h | 4 +- src/{ngmx => programs/view}/rewind.bm | 0 src/{ngmx => programs/view}/stop.bm | 0 src/{ngmx => programs/view}/stop_ani.bm | 0 src/{ngmx/ngmx.cpp => programs/view/view.cpp} | 110 ++--- src/{ngmx/g_logo.c => programs/view/view.h} | 31 +- src/{ngmx/x11.c => programs/view/x11.cpp} | 96 +---- src/{ngmx => programs/view}/x11.h | 12 +- src/{ngmx/xdlg.c => programs/view/xdlg.cpp} | 65 ++- src/{ngmx => programs/view}/xdlg.h | 24 +- .../xdlghi.c => programs/view/xdlghi.cpp} | 40 +- src/{ngmx => programs/view}/xdlghi.h | 6 +- .../xdlgitem.c => programs/view/xdlgitem.cpp} | 105 ++--- src/{ngmx => programs/view}/xdlgitem.h | 38 +- src/{ngmx/xmb.c => programs/view/xmb.cpp} | 18 +- src/{ngmx => programs/view}/xmb.h | 4 +- src/{ngmx/xutil.c => programs/view/xutil.cpp} | 22 +- src/{ngmx => programs/view}/xutil.h | 10 +- 56 files changed, 510 insertions(+), 1716 deletions(-) delete mode 100644 src/ngmx/CMakeLists.txt delete mode 100644 src/ngmx/g_showcol.c delete mode 100644 src/ngmx/g_xrama.cpp delete mode 100644 src/ngmx/rama.bm delete mode 100644 src/ngmx/test_ngmx_dialog.c delete mode 100644 src/ngmx/xstat.c rename src/{ngmx => programs/view}/Xstuff.h (100%) rename src/{ngmx => programs/view}/alert.bm (100%) rename src/{ngmx/buttons.c => programs/view/buttons.cpp} (95%) rename src/{ngmx => programs/view}/buttons.h (99%) rename src/{ngmx/dialogs.c => programs/view/dialogs.cpp} (85%) rename src/{ngmx => programs/view}/dialogs.h (97%) rename src/{ngmx => programs/view}/ff.bm (100%) rename src/{ngmx/fgrid.c => programs/view/fgrid.cpp} (93%) rename src/{ngmx => programs/view}/fgrid.h (87%) rename src/{ngmx/filter.c => programs/view/filter.cpp} (93%) rename src/{ngmx => programs/view}/gromacs.bm (100%) rename src/{ngmx => programs/view}/info.bm (100%) rename src/{ngmx/logo.c => programs/view/logo.cpp} (94%) rename src/{ngmx => programs/view}/logo.h (92%) rename src/{ngmx/manager.c => programs/view/manager.cpp} (90%) rename src/{ngmx => programs/view}/manager.h (86%) rename src/{ngmx/molps.c => programs/view/molps.cpp} (91%) rename src/{ngmx => programs/view}/molps.h (100%) rename src/{ngmx/nleg.c => programs/view/nleg.cpp} (94%) rename src/{ngmx => programs/view}/nleg.h (100%) rename src/{ngmx/nmol.c => programs/view/nmol.cpp} (94%) rename src/{ngmx => programs/view}/nmol.h (97%) rename src/{ngmx => programs/view}/play.bm (100%) rename src/{ngmx/popup.c => programs/view/popup.cpp} (93%) rename src/{ngmx => programs/view}/popup.h (93%) rename src/{ngmx/pulldown.c => programs/view/pulldown.cpp} (88%) rename src/{ngmx => programs/view}/pulldown.h (97%) rename src/{ngmx => programs/view}/rewind.bm (100%) rename src/{ngmx => programs/view}/stop.bm (100%) rename src/{ngmx => programs/view}/stop_ani.bm (100%) rename src/{ngmx/ngmx.cpp => programs/view/view.cpp} (86%) rename src/{ngmx/g_logo.c => programs/view/view.h} (67%) rename src/{ngmx/x11.c => programs/view/x11.cpp} (81%) rename src/{ngmx => programs/view}/x11.h (95%) rename src/{ngmx/xdlg.c => programs/view/xdlg.cpp} (94%) rename src/{ngmx => programs/view}/xdlg.h (86%) rename src/{ngmx/xdlghi.c => programs/view/xdlghi.cpp} (90%) rename src/{ngmx => programs/view}/xdlghi.h (92%) rename src/{ngmx/xdlgitem.c => programs/view/xdlgitem.cpp} (89%) rename src/{ngmx => programs/view}/xdlgitem.h (84%) rename src/{ngmx/xmb.c => programs/view/xmb.cpp} (93%) rename src/{ngmx => programs/view}/xmb.h (95%) rename src/{ngmx/xutil.c => programs/view/xutil.cpp} (96%) rename src/{ngmx => programs/view}/xutil.h (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc8deea853..ae04ed474f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -471,6 +471,9 @@ if (GMX_X11) # X11 includes/libraries are only set in the ngmx subdirectory! if(NOT X11_FOUND) message(WARNING "X11 include files and/or libraries were not found. Will not build the GROMACS X11-binaries, such as ngmx") + else() + set(HAVE_X11 1) + include_directories(${X11_INCLUDE_DIR}) endif() endif(GMX_X11) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f1d6f02a6..6a551a16af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,9 +18,6 @@ endif (BUILD_TESTING) add_subdirectory(gromacs) add_subdirectory(programs) -if (NOT GMX_FAHCORE AND NOT GMX_BUILD_MDRUN_ONLY) - add_subdirectory(ngmx) -endif() if (NOT GMX_FAHCORE) - add_subdirectory(contrib) + add_subdirectory(contrib) endif() diff --git a/src/config.h.cmakein b/src/config.h.cmakein index e515c0fa30..3bf56ecc9e 100644 --- a/src/config.h.cmakein +++ b/src/config.h.cmakein @@ -196,6 +196,9 @@ /* Define for GetSystemInfo() */ #cmakedefine HAVE_SYSTEM_INFO +/* Define for X-Windows */ +#cmakedefine HAVE_X11 + /* Enable x86 gcc inline assembly */ #cmakedefine GMX_X86_GCC_INLINE_ASM diff --git a/src/gromacs/legacyheaders/macros.h b/src/gromacs/legacyheaders/macros.h index 46ca3f387a..261c86f6eb 100644 --- a/src/gromacs/legacyheaders/macros.h +++ b/src/gromacs/legacyheaders/macros.h @@ -66,6 +66,6 @@ #endif /* This macro calculates the size of a array */ -#define asize(a) (sizeof(a)/sizeof((a)[0])) +#define asize(a) ((int)(sizeof(a)/sizeof((a)[0]))) #endif /* _macros_h */ diff --git a/src/ngmx/CMakeLists.txt b/src/ngmx/CMakeLists.txt deleted file mode 100644 index 10e3f09a6b..0000000000 --- a/src/ngmx/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -if(X11_FOUND) - -set(NGMX_COMMON_SOURCE - xutil.c xmb.c x11.c - xdlghi.c fgrid.c xdlgitem.c - popup.c pulldown.c xdlg.c - manager.c buttons.c nmol.c - nleg.c dialogs.c logo.c - filter.c molps.c) - -include_directories(${X11_INCLUDE_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - -# List of programs with single corresponding *.c source file, -# used to create build rules automatically. -# -set(NGMX_PROGRAMS - ngmx g_xrama) - -foreach(PROG ${NGMX_PROGRAMS}) - add_executable(${PROG} ${PROG}.cpp ${NGMX_COMMON_SOURCE}) - target_link_libraries(${PROG} libgromacs ${GMX_EXTRA_LIBRARIES}) - gmx_add_man_page(${PROG}) - set_target_properties(${PROG} PROPERTIES OUTPUT_NAME "${PROG}${GMX_BINARY_SUFFIX}") -endforeach(PROG) - -install(TARGETS ${NGMX_PROGRAMS} - COMPONENT ngmx - RUNTIME DESTINATION ${BIN_INSTALL_DIR}) - -endif(X11_FOUND) diff --git a/src/ngmx/g_showcol.c b/src/ngmx/g_showcol.c deleted file mode 100644 index fddc62c4d0..0000000000 --- a/src/ngmx/g_showcol.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * - * This source code is part of - * - * G R O M A C S - * - * GROningen MAchine for Chemical Simulations - * - * VERSION 3.2.0 - * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, - * check out http://www.gromacs.org for more information. - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * If you want to redistribute modifications, please consider that - * scientific software is very special. Version control is crucial - - * bugs must be traceable. We will be happy to consider code for - * inclusion in the official distribution, but derived work must not - * be called official GROMACS. Details are found in the README & COPYING - * files - if they are missing, get the official version at www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the papers on the package - you can find them in the top README file. - * - * For more info, check our website at http://www.gromacs.org - * - * And Hey: - * Gyas ROwers Mature At Cryogenic Speed - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include "xutil.h" -#include "futil.h" - -typedef struct { - XColor xc; - t_windata wd; -} t_col; - -typedef struct { - t_windata wd; - t_windata but; - int ncol; - t_col *col; -} t_sc; - -static gmx_bool ColCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_col *col; - XColor *xc; - int r, g, b; - t_windata *wd; - - col = (t_col *)data; - xc = &(col->xc); - wd = &(col->wd); - switch (event->type) - { - case ButtonPress: - r = xc->red >> 8; - g = xc->green >> 8; - b = xc->blue >> 8; - printf("%6d%6d%6d\t\t%-20s\n", r, g, b, wd->text); - break; - } - return FALSE; -} - -static gmx_bool BCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_sc *sc; - - sc = (t_sc *)data; - switch (event->type) - { - case Expose: - XSetForeground(x11->disp, x11->gc, sc->col[sc->ncol-1].xc.pixel); - TextInWin(x11, &sc->but, sc->but.text, eXCenter, eYCenter); - break; - case ConfigureNotify: - sc->but.width = event->xconfigure.width; - sc->but.height = event->xconfigure.height; - break; - case EnterNotify: - LightBorder(x11->disp, sc->but.self, sc->col[sc->ncol-1].xc.pixel); - break; - case LeaveNotify: - LightBorder(x11->disp, sc->but.self, sc->col[0].xc.pixel); - break; - case ButtonPress: - x11->UnRegisterCallback(x11, sc->wd.self); - x11->UnRegisterCallback(x11, sc->but.self); - return TRUE; - } - return FALSE; -} - -static gmx_bool scCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_sc *sc; - int i; - int nx, ny, X, Y, Dx, Dy, th; - float x, y, dx, dy; - - th = XTextHeight(x11->font)+6; - sc = (t_sc *)data; - switch (event->type) - { - case ConfigureNotify: - x = sc->wd.width = event->xconfigure.width; - y = sc->wd.height = event->xconfigure.height-th; - if ((x >= 100) && (y >= 100)) - { -#ifdef DEBUG - printf("Disp: %x, But: %x, Font: %x x: %d, th: %d\n", - x11->disp, sc->but.self, x11->font, (int)x, th); -#endif - XResizeWindow(x11->disp, sc->but.self, (int)x-4, th-4); - nx = sqrt(sc->ncol); - ny = sc->ncol/nx; - while (nx*ny < sc->ncol) - { - ny++; - } - dx = ((float)x) / nx; - dy = ((float)y) / ny; - for (i = 0; (i < sc->ncol); i++) - { - X = x = (i%nx) * dx; - Y = y = (i/nx) * dy; - Dx = (int)(x+dx)-X; - Dy = (int)(y+dy)-Y; - XMoveWindow(x11->disp, sc->col[i].wd.self, X, th+Y); - XResizeWindow(x11->disp, sc->col[i].wd.self, Dx, Dy); - } - } - break; - } - return FALSE; -} - -static int col_comp(const void *c1, const void *c2) -{ - XColor *x1, *x2; - int dr, dg; - int diff; - - x1 = &(((t_col *)c1)->xc); - x2 = &(((t_col *)c2)->xc); - - /* sort on intensity */ - diff = (x1->red+x1->green+x1->blue)-(x2->red+x2->green+x2->blue); - - if (diff == 0) - { - if ((dr = (x1->red-x2->red)) != 0) - { - return dr; - } - if ((dg = (x1->green-x2->green)) != 0) - { - return dg; - } - return x1->blue-x2->blue; - } - else - { - return diff; - } -} - -static void read_col(t_x11 *x11, t_sc *sc, char *rgb) -{ - FILE *fp; - char buf[STRLEN], name[STRLEN], *dummy; - int i, j; - int r, g, b; - XColor xc, exact; - t_col *cols; - - if ((fp = fopen(rgb, "r")) == NULL) - { - perror(rgb); - exit(1); - } - do - { - dummy = NULL; - if (fscanf(fp, "%d%d%d", &r, &g, &b) == 3) - { - dummy = fgets2(buf, STRLEN-1, fp); - if (dummy) - { - trim(buf); - /* Filter out colours with names of two words */ - sscanf(buf, "%s", name); - /* Filter out duplicate colours (grey and gray) */ - if (strstr(name, "gray") == 0) - { - if (XAllocNamedColor(x11->disp, x11->cmap, name, &xc, &exact)) - { - srenew(sc->col, ++sc->ncol); - sc->col[sc->ncol-1].xc = xc; -#ifdef DEBUG - printf("color %3d: %s\n", sc->ncol, buf); -#endif - InitWin(&(sc->col[sc->ncol-1].wd), 0, 0, 1, 1, 0, name); - } - } - } - } - } - while (dummy); - fclose(fp); - if (sc->ncol) - { - qsort(sc->col, sc->ncol, sizeof(sc->col[0]), col_comp); - } - /* Now filter out doubles */ - cols = &(sc->col[0]); - for (i = 1, j = 0; (i < sc->ncol); i++) - { - if ((cols[i].xc.red != cols[j].xc.red) || - (cols[i].xc.green != cols[j].xc.green) || - (cols[i].xc.blue != cols[j].xc.blue)) - { - j++; - cols[j] = cols[i]; - } - } - sc->ncol = j; -} - -static t_sc *init_sc(t_x11 *x11, Window Parent, char *rgb) -{ - t_sc *sc; - Window w; - int i; - - snew(sc, 1); - InitWin(&sc->wd, 0, 0, 400, 300, 1, "Show Colours"); - sc->wd.self = XCreateSimpleWindow(x11->disp, Parent, sc->wd.x, sc->wd.y, - sc->wd.width, sc->wd.height, - sc->wd.bwidth, WHITE, BLACK); - x11->RegisterCallback(x11, sc->wd.self, Parent, scCallBack, sc); - x11->SetInputMask(x11, sc->wd.self, ButtonPressMask | ExposureMask | - StructureNotifyMask); - InitWin(&sc->but, 0, 0, sc->wd.width-2, XTextHeight(x11->font)+2, 1, "Quit"); - sc->but.self = XCreateSimpleWindow(x11->disp, sc->wd.self, sc->but.x, sc->but.y, - sc->but.width, sc->but.height, - sc->but.bwidth, BLACK, BLACK); - x11->RegisterCallback(x11, sc->but.self, sc->but.self, BCallBack, sc); - x11->SetInputMask(x11, sc->but.self, ButtonPressMask | ExposureMask | - StructureNotifyMask | EnterWindowMask | - LeaveWindowMask); - - read_col(x11, sc, rgb); - fprintf(stderr, "%d colors found\n", sc->ncol); - fprintf(stderr, "%6s%6s%6s\t\t%-20s\n", "Red", "Green", "Blue", "name"); - for (i = 0; (i < sc->ncol); i++) - { - sc->col[i].wd.self = w = XCreateSimpleWindow(x11->disp, sc->wd.self, 0, 0, 1, 1, 0, - BLACK, sc->col[i].xc.pixel); - x11->RegisterCallback(x11, w, sc->wd.self, ColCallBack, &(sc->col[i])); - x11->SetInputMask(x11, w, ButtonPressMask); - } - - return sc; -} - -int -main(int argc, char *argv[]) -{ - t_x11 *x11; - t_sc *sc; - char *fn; - - x11 = GetX11(&argc, argv); - if (argc > 1) - { - fn = argv[1]; - } - else - { - fn = "/usr/lib/X11/rgb.txt"; - } - if (!gmx_fexist(fn)) - { - fprintf(stderr, "Usage: %s rgb.txt\n", argv[0]); - fprintf(stderr, "rgb.txt is usually somewhere in your X windows directories.\n"); - exit(1); - } - sc = init_sc(x11, x11->root, fn); - XMapWindow(x11->disp, sc->wd.self); - XMapSubwindows(x11->disp, sc->wd.self); - x11->MainLoop(x11); - x11->CleanUp(x11); - - return 0; -} diff --git a/src/ngmx/g_xrama.cpp b/src/ngmx/g_xrama.cpp deleted file mode 100644 index 5d553b4b69..0000000000 --- a/src/ngmx/g_xrama.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/* - * - * This source code is part of - * - * G R O M A C S - * - * GROningen MAchine for Chemical Simulations - * - * VERSION 3.2.0 - * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, - * check out http://www.gromacs.org for more information. - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * If you want to redistribute modifications, please consider that - * scientific software is very special. Version control is crucial - - * bugs must be traceable. We will be happy to consider code for - * inclusion in the official distribution, but derived work must not - * be called official GROMACS. Details are found in the README & COPYING - * files - if they are missing, get the official version at www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the papers on the package - you can find them in the top README file. - * - * For more info, check our website at http://www.gromacs.org - * - * And Hey: - * Gyas ROwers Mature At Cryogenic Speed - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include "macros.h" -#include "Xstuff.h" -#include "xutil.h" -#include "futil.h" -#include "x11.h" -#include "smalloc.h" -#include "statutil.h" -#include "rama.bm" -#include "nrama.h" - -#include "gromacs/commandline/cmdlinemodulemanager.h" - -#define MAXDEG 360 - -enum { - ebQuit, ebStart, ebStop, ebRewind, ebGly, ebutNR -}; - -static real scx, scy; -#define SX(x) ((int)(((x)+M_PI)*scx)) -#define SY(y) ((int)((M_PI-(y))*scy)) - -enum { - esStop, esGo, esNR -}; - -typedef struct { - int status; - gmx_bool bShowGly; - gmx_bool *bIsGly; - t_windata wd; - t_windata xrwd; - t_xrama *xr; - t_windata but[ebutNR]; -} t_app; - -static void plot_pp(t_x11 *x11, Window w, t_phipsi *pp, t_dih dih[]) -{ - int x0, y0; - int th = (XTextHeight(x11->font)+6)/2; - - x0 = SX(dih[pp->iphi].ang); - y0 = SY(dih[pp->ipsi].ang); - XFillRectangle(x11->disp, w, x11->gc, x0-1, y0-1, 4, 4); - /* Draw Label ? */ - if (pp->bShow) - { - TextInRect(x11, w, pp->label, x0+6, y0-th, 30, 2*th, eXLeft, eYCenter); - } -} - -static gmx_bool label_pp(t_x11 *x11, Window w, int npp, t_phipsi pp[], - t_dih dih[], int mx, int my) -{ - int d, md, x0, y0; - int i, imin; - - imin = -1; - md = 16; - for (i = 0; (i < npp); i++) - { - x0 = SX(dih[pp[i].iphi].ang); - y0 = SY(dih[pp[i].ipsi].ang); - d = (mx-x0)*(mx-x0)+(my-y0)*(my-y0); - if (d < md) - { - md = d; - imin = i; - } - } - if (imin != -1) - { - pp[imin].bShow = !pp[imin].bShow; - return TRUE; - } - return FALSE; -} - -static gmx_bool xrCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_app *app; - t_xrama *xr; - char buf[256]; - int i; - - (void)XTextHeight(x11->font); - app = (t_app *)data; - xr = app->xr; - scx = app->xrwd.width/(2.0*M_PI); - scy = app->xrwd.height/(2.0*M_PI); - switch (event->type) - { - case Expose: - XClearWindow(x11->disp, app->xrwd.self); - XDrawLine(x11->disp, app->xrwd.self, x11->gc, - SX(0), SY(-M_PI)+1, SX(0), SY(M_PI)-1); - XDrawLine(x11->disp, app->xrwd.self, x11->gc, - SX(-M_PI)+1, SY(0), SX(M_PI)-1, SY(0)); - TextInRect(x11, app->xrwd.self, "Phi", SX(M_PI)-50, SY(0)+4, 46, 20, eXRight, eYTop); - TextInRect(x11, app->xrwd.self, "Psi", SX(0)+4, 4, 46, 20, eXLeft, eYTop); - for (i = 0; (i < xr->npp); i++) - { - if (app->bShowGly || !app->bIsGly[i]) - { - plot_pp(x11, app->xrwd.self, &(xr->pp[i]), xr->dih); - } - } - break; - case ButtonPress: - if (label_pp(x11, app->xrwd.self, xr->npp, xr->pp, xr->dih, - event->xbutton.x, event->xbutton.y)) - { - ExposeWin(x11->disp, app->xrwd.self); - } - break; - case ConfigureNotify: - app->xrwd.width = event->xconfigure.width; - app->xrwd.height = event->xconfigure.height; - break; - } - if (app->status == esGo) - { - if (!new_data(app->xr)) - { - app->status = ebStop; - } - else - { - ExposeWin(x11->disp, app->xrwd.self); - sprintf(buf, "Rama: t=%.2f", app->xr->t); - XSetStandardProperties(x11->disp, app->wd.self, buf, - "Rama", 0, NULL, 0, NULL); - - } - } - return FALSE; -} - -static gmx_bool appCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_app *app; - int win; - - app = (t_app *)data; - for (win = 0; (win < ebutNR); win++) - { - if (app->but[win].self == w) - { - break; - } - } - if (win == ebutNR) - { - return FALSE; - } - - switch (event->type) - { - case Expose: - TextInWin(x11, &(app->but[win]), app->but[win].text, eXCenter, eYCenter); - break; - case ButtonPress: - switch (win) - { - case ebQuit: - exit(1); - case ebStart: - app->status = esGo; - ExposeWin(x11->disp, app->xrwd.self); - break; - case ebStop: - app->status = esStop; - break; - case ebRewind: - rewind_trj(app->xr->traj); - break; - case ebGly: - app->bShowGly = !app->bShowGly; - ExposeWin(x11->disp, app->xrwd.self); - break; - default: - XBell(x11->disp, 50); - break; - } - break; - } - return FALSE; -} - -static void size_app(t_x11 *x11, t_app *app) -{ - int i, dx, th; - - th = XTextHeight(x11->font)+4; - dx = app->wd.width/ebutNR; - for (i = 0; (i < ebutNR); i++) - { - app->but[i].width = dx-4; - app->but[i].height = th+4; - XMoveResizeWindow(x11->disp, app->but[i].self, i*dx+2, 2, dx-4, th+4); - } - XMoveResizeWindow(x11->disp, app->xrwd.self, 2, th+10, - app->wd.width-6, app->wd.height-th-10-4); -} - -static gmx_bool mainCallBack(struct t_x11 *x11, XEvent *event, Window w, void *data) -{ - t_app *app; - int wt, ht; - - app = (t_app *)data; - switch (event->type) - { - case ConfigureNotify: - wt = event->xconfigure.width; - ht = event->xconfigure.height; - if ((app->wd.width != wt) || (app->wd.height != ht)) - { - fprintf(stderr, "New wxh = %dx%d\n", wt, ht); - app->wd.width = wt; - app->wd.height = ht; - size_app(x11, app); - } - break; - } - return FALSE; -} - -static t_xrama *init_xrama(t_x11 *x11, Window Parent, int y0, t_app *app) -{ - t_xrama *xr; - - snew(xr, 1); - - InitWin(&(app->xrwd), 2, y0, MAXDEG+1, MAXDEG+1, 1, "Ramachandran Movie"); - app->xrwd.self = XCreateSimpleWindow(x11->disp, Parent, app->xrwd.x, app->xrwd.y, - app->xrwd.width, app->xrwd.height, - app->xrwd.bwidth, x11->fg, x11->bg); - x11->RegisterCallback(x11, app->xrwd.self, Parent, xrCallBack, app); - x11->SetInputMask(x11, app->xrwd.self, ButtonPressMask | ExposureMask | - StructureNotifyMask); - - return xr; -} - -static t_app *init_app(t_x11 *x11, int argc, char *argv[]) -{ - static const char *but_nm[ebutNR] = { "Quit", "Start", "Stop", "Rewind", "Toggle Gly" }; - XSizeHints hints; - Pixmap pm; - int th; - t_app *app; - t_windata *wd; - int i, dx; - - snew(app, 1); - th = XTextHeight(x11->font)+4; - InitWin(&(app->wd), 0, 0, MAXDEG+6, MAXDEG+6+th+6, 0, "Ramachandran Movie"); - dx = app->wd.width/ebutNR; - app->wd.self = XCreateSimpleWindow(x11->disp, x11->root, app->wd.x, app->wd.y, - app->wd.width, app->wd.height, - app->wd.bwidth, x11->fg, x11->bg); - x11->RegisterCallback(x11, app->wd.self, x11->root, mainCallBack, app); - x11->SetInputMask(x11, app->wd.self, StructureNotifyMask); - hints.flags = 0; - pm = XCreatePixmapFromBitmapData(x11->disp, x11->root, (char *)rama_bits, - rama_width, rama_height, WHITE, BLACK, 1); - XSetStandardProperties(x11->disp, app->wd.self, app->wd.text, - "Rama", pm, argv, argc, &hints); - x11->RegisterCallback(x11, app->wd.self, x11->root, appCallBack, app); - x11->SetInputMask(x11, app->wd.self, ButtonPressMask | ExposureMask | - StructureNotifyMask); - - app->xr = init_xrama(x11, app->wd.self, th+6, app); - for (i = 0; (i < ebutNR); i++) - { - wd = &(app->but[i]); - InitWin(wd, i*dx+2, 2, dx-4, th, 1, but_nm[i]); - wd->self = XCreateSimpleWindow(x11->disp, app->wd.self, - wd->x, wd->y, wd->width, wd->height, - wd->bwidth, x11->fg, x11->bg); - x11->RegisterCallback(x11, wd->self, app->wd.self, appCallBack, app); - x11->SetInputMask(x11, wd->self, ButtonPressMask | ExposureMask); - } - return app; -} - -static void mk_gly(t_app *app) -{ - int i; - - snew(app->bIsGly, app->xr->npp); - for (i = 0; (i < app->xr->npp); i++) - { - if (strstr(app->xr->pp[i].label, "GLY") != NULL) - { - app->bIsGly[i] = TRUE; - } - } -} - -int gmx_xrama(int argc, char *argv[]) -{ - const char *desc[] = { - "[TT]g_xrama[tt] shows a Ramachandran movie, that is, it shows", - "the Phi/Psi angles as a function of time in an X-Window.[PAR]" - "Static Phi/Psi plots for printing can be made with [TT]g_rama[tt].[PAR]", - "Some of the more common X command line options can be used:[BR]", - "[TT]-bg[tt], [TT]-fg[tt] change colors, [TT]-font fontname[tt], changes the font." - }; - - output_env_t oenv; - t_x11 *x11; - t_app *app; - t_filenm fnm[] = { - { efTRX, "-f", NULL, ffREAD }, - { efTPX, NULL, NULL, ffREAD } - }; -#define NFILE asize(fnm) - - if (!parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, - 0, NULL, asize(desc), desc, 0, NULL, &oenv)) - { - return 0; - } - - - if ((x11 = GetX11(&argc, argv)) == NULL) - { - fprintf(stderr, "Can't open display, set your DISPLAY environment variable\n"); - exit(1); - } - XSetForeground(x11->disp, x11->gc, x11->fg); - app = init_app(x11, argc, argv); - - init_rama(oenv, ftp2fn(efTRX, NFILE, fnm), ftp2fn(efTPX, NFILE, fnm), - app->xr, 3); - mk_gly(app); - - XMapWindow(x11->disp, app->wd.self); - XMapSubwindows(x11->disp, app->wd.self); - x11->MainLoop(x11); - x11->CleanUp(x11); - - return 0; -} - -int main(int argc, char *argv[]) -{ - return gmx::CommandLineModuleManager::runAsMainCMain(argc, argv, &gmx_xrama); -} diff --git a/src/ngmx/rama.bm b/src/ngmx/rama.bm deleted file mode 100644 index eca879327d..0000000000 --- a/src/ngmx/rama.bm +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of the GROMACS molecular simulation package. - * - * Copyright (c) 1991-2001 - * BIOSON Research Institute, Dept. of Biophysical Chemistry - * University of Groningen, The Netherlands - * Copyright (c) 2012, by the GROMACS development team, led by - * David van der Spoel, Berk Hess, Erik Lindahl, and including many - * others, as listed in the AUTHORS file in the top-level source - * directory and at http://www.gromacs.org. - * - * GROMACS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * GROMACS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with GROMACS; if not, see - * http://www.gnu.org/licenses, or write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * If you want to redistribute modifications to GROMACS, please - * consider that scientific software is very special. Version - * control is crucial - bugs must be traceable. We will be happy to - * consider code for inclusion in the official distribution, but - * derived work must not be called official GROMACS. Details are found - * in the README & COPYING files - if they are missing, get the - * official version at http://www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the research papers on the package. Check out http://www.gromacs.org. - */ - -#define rama_width 48 -#define rama_height 48 -static unsigned char rama_bits[] = { - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x00, 0x00, - 0x80, 0x0d, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, - 0x18, 0x33, 0x80, 0x00, 0x00, 0x00, 0x18, 0x30, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x03, 0x00, 0x00, 0x03, 0x80, 0x00, 0x03, 0x00, - 0x00, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}; diff --git a/src/ngmx/test_ngmx_dialog.c b/src/ngmx/test_ngmx_dialog.c deleted file mode 100644 index 7008b6434a..0000000000 --- a/src/ngmx/test_ngmx_dialog.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * This source code is part of - * - * G R O M A C S - * - * GROningen MAchine for Chemical Simulations - * - * VERSION 3.2.0 - * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, - * check out http://www.gromacs.org for more information. - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * If you want to redistribute modifications, please consider that - * scientific software is very special. Version control is crucial - - * bugs must be traceable. We will be happy to consider code for - * inclusion in the official distribution, but derived work must not - * be called official GROMACS. Details are found in the README & COPYING - * files - if they are missing, get the official version at www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the papers on the package - you can find them in the top README file. - * - * For more info, check our website at http://www.gromacs.org - * - * And Hey: - * Gyas ROwers Mature At Cryogenic Speed - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -int main(int argc, char *argv[]) -{ - t_x11 *x11; - t_dlg *dlg; - - if ((x11 = GetX11(&argc, argv)) == NULL) - { - fprintf(stderr, "No X!\n"); - exit(1); - } - if (argc > 1) - { - dlg = ReadDlg(x11, 0, x11->title, x11->fg, x11->bg, argv[1], 100, 100, TRUE, - TRUE, NULL, NULL); - ShowDlg(dlg); - x11->MainLoop(x11); - } - else - { - fprintf(stderr, "Usage: %s [ X options ] infile\n", argv[0]); - } - - x11->CleanUp(x11); - - return 0; -} diff --git a/src/ngmx/xstat.c b/src/ngmx/xstat.c deleted file mode 100644 index 77c455cbc3..0000000000 --- a/src/ngmx/xstat.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * - * This source code is part of - * - * G R O M A C S - * - * GROningen MAchine for Chemical Simulations - * - * VERSION 3.2.0 - * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, - * check out http://www.gromacs.org for more information. - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * If you want to redistribute modifications, please consider that - * scientific software is very special. Version control is crucial - - * bugs must be traceable. We will be happy to consider code for - * inclusion in the official distribution, but derived work must not - * be called official GROMACS. Details are found in the README & COPYING - * files - if they are missing, get the official version at www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the papers on the package - you can find them in the top README file. - * - * For more info, check our website at http://www.gromacs.org - * - * And Hey: - * Gyas ROwers Mature At Cryogenic Speed - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "sysstuff.h" -#include "smalloc.h" -#include "x11.h" -#include "string2.h" -#include "macros.h" -#include "fgrid.h" -#include "futil.h" -#include "xdlg.h" -#include "xdlghi.h" - -typedef struct { - int nopt, nAppl; - char **name; - char **description; - char **dlgfile; - t_dlg *dlg; - t_dlg *appl; -} t_data; - -static void ApplCallback(t_x11 *x11, int dlg_mess, int item_id, - char *set, void *dta) -{ - t_data *data; - t_dlg *dlg; - t_dlgitem *item; - int i; - char doit[1024]; - - data = (t_data *)dta; - dlg = data->appl; - - fprintf(stderr, "item_id: %d (%s)\n", item_id, set); - if (gmx_strcasecmp(set, "OK") == 0) - { - /* Doit */ - sprintf(doit, - "xterm -geometry +100+100 -n %s" - " -title \"GROMACS: %s\" -e nice %s ", - data->name[data->nAppl], - data->name[data->nAppl], - data->name[data->nAppl]); - for (i = 0; (i < dlg->nitem); i++) - { - item = dlg->dlgitem[i]; - switch (item->type) - { - case edlgRB: - strcat(doit, item->set); - strcat(doit, " "); - break; - case edlgCB: - if (item->u.checkbox.bChecked) - { - strcat(doit, item->set); - } - strcat(doit, " "); - break; - case edlgET: - if (strlen(item->u.edittext.buf) > 0) - { - strcat(doit, item->set); - strcat(doit, " "); - strcat(doit, item->u.edittext.buf); - strcat(doit, " "); - } - break; - default: - fprintf(stderr, "Type: %d\n", item->type); - } - } - strcat(doit, " &"); - fprintf(stderr, "Going to exec: '%s'\n", doit); - -#ifdef GMX_NO_SYSTEM - printf("Warning-- No calls to system(3) supported on this platform."); - printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf); -#else - system(doit); -#endif - - HideDlg(data->appl); - } - else if (gmx_strcasecmp(set, "Cancel") == 0) - { - data->nAppl = -1; - HideDlg(data->appl); - } -} - -static void Callback(t_x11 *x11, int dlg_mess, int item_id, - char *set, void *dta) -{ - t_data *data = (t_data *)dta; - - if (item_id == data->nopt) - { - fprintf(stderr, "Doei...\n"); - exit(0); - } - else - { - fprintf(stderr, "%d: %s\n", item_id, data->description[item_id]); - if (data->nAppl != -1) - { - HideDlg(data->appl); - } - data->nAppl = item_id; - data->appl = ReadDlg(x11, 0, data->name[item_id], - BLACK, LIGHTGREY, data->dlgfile[item_id], - 50, 50, FALSE, FALSE, ApplCallback, data); - ShowDlg(data->appl); - } -} - -static void read_opts(t_data *data) -{ - FILE *in; - char fn[STRLEN], buf[STRLEN]; - int i, n; - - sprintf(fn, "xstat.dat"); - in = libopen(fn); - fscanf(in, "%d", &n); - data->nopt = n; - snew(data->name, data->nopt); - snew(data->description, data->nopt); - snew(data->dlgfile, data->nopt); - - for (i = 0; (i < data->nopt); i++) - { - ReadQuoteString(fn, in, buf); - data->name[i] = strdup(buf); - ReadQuoteString(fn, in, buf); - data->description[i] = strdup(buf); - ReadQuoteString(fn, in, buf); - data->dlgfile[i] = strdup(buf); - } - ffclose(in); -} - -static void add_opts(t_x11 *x11, t_data *data) -{ - t_dlgitem *but; - int i, y0, w; - - y0 = OFFS_Y; - for (i = 0; (i < data->nopt); i++) - { - but = CreateButton(x11, data->description[i], FALSE, - (t_id)i, (t_id)0, - OFFS_X, y0, 0, 0, 1); - AddDlgItem(data->dlg, but); - y0 += but->win.height+OFFS_Y; - } - but = CreateButton(x11, "Quit", TRUE, (t_id)data->nopt, (t_id)0, - OFFS_X, y0, 0, 0, 1); - AddDlgItem(data->dlg, but); - y0 += but->win.height+OFFS_Y; - - w = 0; - for (i = 0; (i <= data->nopt); i++) - { - w = max(w, QueryDlgItemW(data->dlg, i)); - } - w += 2*OFFS_X; - for (i = 0; (i <= data->nopt); i++) - { - SetDlgItemSize(data->dlg, i, w, 0); - } - SetDlgSize(data->dlg, w+2*OFFS_X, y0, TRUE); -} - -int -main(int argc, char *argv[]) -{ - t_x11 *x11; - t_data data; - - /* Initiate X and data */ - if ((x11 = GetX11(&argc, argv)) == NULL) - { - fprintf(stderr, "Can't open DISPLAY\n"); - exit(1); - } - read_opts(&data); - data.dlg = CreateDlg(x11, 0, argv[0], 0, 0, 0, 0, 0, BLACK, LIGHTGREY, Callback, &data); - add_opts(x11, &data); - data.nAppl = -1; - - ShowDlg(data.dlg); - x11->MainLoop(x11); - HideDlg(data.dlg); -} diff --git a/src/programs/CMakeLists.txt b/src/programs/CMakeLists.txt index 02998643d4..a67168a5cf 100644 --- a/src/programs/CMakeLists.txt +++ b/src/programs/CMakeLists.txt @@ -35,6 +35,11 @@ include_directories(${CMAKE_SOURCE_DIR}/src/gromacs/gmxpreprocess) file(GLOB MDRUN_SOURCES mdrun/*.c mdrun/*.cpp) +if(X11_FOUND) + file(GLOB VIEW_SOURCES view/*.cpp) +else() + file(GLOB VIEW_SOURCES view/view.cpp) +endif(X11_FOUND) if(GMX_FAHCORE) add_library(fahcore ${MDRUN_SOURCES}) @@ -48,9 +53,14 @@ elseif(GMX_BUILD_MDRUN_ONLY) install(TARGETS mdrun DESTINATION ${BIN_INSTALL_DIR} COMPONENT mdrun) else() file(GLOB GMX_EXECUTABLE_SOURCES gmx/*.c gmx/*.cpp) - add_executable(gmx ${GMX_EXECUTABLE_SOURCES} ${MDRUN_SOURCES}) - target_link_libraries(gmx - ${GMX_EXTRA_LIBRARIES} libgromacs ${GMX_EXE_LINKER_FLAGS}) + add_executable(gmx ${GMX_EXECUTABLE_SOURCES} ${MDRUN_SOURCES} ${VIEW_SOURCES}) + if(X11_FOUND) + target_link_libraries(gmx + ${GMX_EXTRA_LIBRARIES} libgromacs ${GMX_EXE_LINKER_FLAGS} ${X11_LIBRARIES}) + else() + target_link_libraries(gmx + ${GMX_EXTRA_LIBRARIES} libgromacs ${GMX_EXE_LINKER_FLAGS}) + endif(X11_FOUND) set_target_properties(gmx PROPERTIES OUTPUT_NAME "gmx${GMX_BINARY_SUFFIX}" COMPILE_FLAGS "${OpenMP_C_FLAGS}") diff --git a/src/programs/gmx/legacymodules.cpp b/src/programs/gmx/legacymodules.cpp index d1c81499f8..f5ca50ea25 100644 --- a/src/programs/gmx/legacymodules.cpp +++ b/src/programs/gmx/legacymodules.cpp @@ -46,6 +46,7 @@ #include "gromacs/gmxana/gmx_ana.h" +#include "../view/view.h" #include "../mdrun/mdrun_main.h" extern "C" @@ -274,10 +275,11 @@ void registerLegacyModules(gmx::CommandLineModuleManager *manager) "Perform weighted histogram analysis after umbrella sampling"); registerModule(manager, &gmx_wheel, "wheel", "Plot helical wheels"); + registerModule(manager, &gmx_view, "view", + "View a trajectory on an X-Windows terminal"); // TODO: Also include binaries from other directories than src/tools/: // "g_xrama|Show animated Ramachandran plots"); // "mdrun|finds a potential energy minimum and calculates the Hessian"); // "mdrun|with -rerun (re)calculates energies for trajectory frames"); - // "ngmx|Display a trajectory"); } diff --git a/src/ngmx/Xstuff.h b/src/programs/view/Xstuff.h similarity index 100% rename from src/ngmx/Xstuff.h rename to src/programs/view/Xstuff.h diff --git a/src/ngmx/alert.bm b/src/programs/view/alert.bm similarity index 100% rename from src/ngmx/alert.bm rename to src/programs/view/alert.bm diff --git a/src/ngmx/buttons.c b/src/programs/view/buttons.cpp similarity index 95% rename from src/ngmx/buttons.c rename to src/programs/view/buttons.cpp index b46f8ff547..5a0fc376b8 100644 --- a/src/ngmx/buttons.c +++ b/src/programs/view/buttons.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -40,8 +40,8 @@ #include #include #include -#include -#include +#include "x11.h" +#include "xutil.h" #include "buttons.h" #include "stop_ani.bm" #include "play.bm" @@ -52,14 +52,14 @@ static void move_bbox(t_x11 *x11, t_butbox *bbox) { int x0, y0; int i, bw; - real idb, bh; + real idb, bh, one = 1.0; t_windata *wd; - bw = max(1, bbox->wd.width-2*(AIR+BORDER)); + bw = std::max(1, bbox->wd.width-2*(AIR+BORDER)); idb = bbox->nbut; bh = (bbox->wd.height-AIR*(bbox->nbut+1)); bh /= idb; - bh = max(bh, 1.0); + bh = std::max(bh, one); x0 = AIR; y0 = AIR; @@ -75,7 +75,7 @@ static void move_bbox(t_x11 *x11, t_butbox *bbox) } } -static gmx_bool BBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool BBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_butbox *bbox; @@ -86,10 +86,10 @@ static gmx_bool BBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) bbox->wd.height = event->xconfigure.height; move_bbox(x11, bbox); } - return FALSE; + return false; } -static gmx_bool VBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool VBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_butbox *vbox; int y0; @@ -105,7 +105,7 @@ static gmx_bool VBCallBack(t_x11 *x11, XEvent *event, Window w, void *data) XDrawLine(x11->disp, vbox->wd.self, x11->gc, 0, y0, vbox->wd.width, y0); XSetForeground(x11->disp, x11->gc, x11->fg); } - return FALSE; + return false; } void set_vbtime(t_x11 *x11, t_butbox *vbox, char *text) @@ -115,7 +115,7 @@ void set_vbtime(t_x11 *x11, t_butbox *vbox, char *text) ExposeWin(x11->disp, vbox->wd.self); } -static gmx_bool ButtonCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool ButtonCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { XEvent letter; t_mwbut *but; @@ -162,7 +162,7 @@ static gmx_bool ButtonCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } t_butbox *init_vbox(t_x11 *x11, Window Parent, Window SendTo, unsigned long fg, unsigned long bg) diff --git a/src/ngmx/buttons.h b/src/programs/view/buttons.h similarity index 99% rename from src/ngmx/buttons.h rename to src/programs/view/buttons.h index b5937bdc0c..94688268e7 100644 --- a/src/ngmx/buttons.h +++ b/src/programs/view/buttons.h @@ -36,7 +36,7 @@ #ifndef _buttons_h #define _buttons_h -#include +#include "xutil.h" enum { IDROTX, IDROTY, IDROTZ, IDTRANSX, IDTRANSY, IDTRANSZ, IDZOOM, IDBUTNR, diff --git a/src/ngmx/dialogs.c b/src/programs/view/dialogs.cpp similarity index 85% rename from src/ngmx/dialogs.c rename to src/programs/view/dialogs.cpp index d46f33d38d..4f6515bff4 100644 --- a/src/ngmx/dialogs.c +++ b/src/programs/view/dialogs.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -145,12 +145,12 @@ static void MBCallback(t_x11 *x11, int dlg_mess, int item_id, static t_dlg *about_mb(t_x11 *x11, t_gmx *gmx) { - char *lines[] = { + const char *lines[] = { " G R O M A C S", " Machine for Simulating Chemistry", - " Copyright (c) 1992-2000", - " Dept. of Biophysical Chemistry", - " University of Groningen" + " Copyright (c) 1992-2013", + " Berk Hess, David van der Spoel, Erik Lindahl", + " and many collaborators!" }; return MessageBox(x11, gmx->wd->self, gmx->wd->text, @@ -176,7 +176,7 @@ static void QuitCB(t_x11 *x11, int dlg_mess, int item_id, static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx) { - char *lines[] = { + const char *lines[] = { " Do you really want to Quit ?" }; @@ -188,7 +188,7 @@ static t_dlg *quit_mb(t_x11 *x11, t_gmx *gmx) static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx) { - char *lines[] = { + const char *lines[] = { " Help will soon be added" }; @@ -200,7 +200,7 @@ static t_dlg *help_mb(t_x11 *x11, t_gmx *gmx) static t_dlg *ni_mb(t_x11 *x11, t_gmx *gmx) { - char *lines[] = { + const char *lines[] = { " This feature has not been", " implemented yet." }; @@ -218,7 +218,7 @@ enum { static void ExportCB(t_x11 *x11, int dlg_mess, int item_id, char *set, void *data) { - gmx_bool bOk; + bool bOk; t_gmx *gmx; t_dlg *dlg; @@ -280,9 +280,10 @@ static void BondsCB(t_x11 *x11, int dlg_mess, int item_id, { static int ebond = -1; static int ebox = -1; - gmx_bool bOk, bBond = FALSE; + bool bOk, bBond = false; int nskip, nwait; t_gmx *gmx; + char *endptr; gmx = (t_gmx *)data; if (ebond == -1) @@ -296,12 +297,12 @@ static void BondsCB(t_x11 *x11, int dlg_mess, int item_id, if (item_id <= eBNR) { ebond = item_id-1; - bBond = FALSE; + bBond = false; } else if (item_id <= eBNR+esbNR+1) { ebox = item_id-eBNR-2; - bBond = TRUE; + bBond = true; } else { @@ -316,39 +317,44 @@ static void BondsCB(t_x11 *x11, int dlg_mess, int item_id, case ebDPlus: DO_NOT(gmx->man->bPlus); #ifdef DEBUG - fprintf(stderr, "gmx->man->bPlus=%s\n", gmx_bool_names[gmx->man->bPlus]); + fprintf(stderr, "gmx->man->bPlus=%s\n", + gmx->man->bPlus ? "true" : "false"); #endif break; - /*case ebSBox: - set_box_type(x11,gmx->man->molw,ebond); - break;*/ case ebRMPBC: toggle_pbc(gmx->man); break; case ebCue: DO_NOT(gmx->man->bSort); #ifdef DEBUG - fprintf(stderr, "gmx->man->bSort=%s\n", gmx_bool_names[gmx->man->bSort]); + fprintf(stderr, "gmx->man->bSort=%s\n", + gmx->man->bSort ? "true" : "false"); #endif break; case ebSkip: - sscanf(set, "%d", &nskip); + nskip = strtol(set, &endptr, 10); + if (endptr != set) + { #ifdef DEBUG - fprintf(stderr, "nskip: %d frames\n", nskip); + fprintf(stderr, "nskip: %d frames\n", nskip); #endif - if (nskip >= 0) - { - gmx->man->nSkip = nskip; + if (nskip >= 0) + { + gmx->man->nSkip = nskip; + } } break; case ebWait: - sscanf(set, "%d", &nwait); + nwait = strtol(set, &endptr, 10); + if (endptr != set) + { #ifdef DEBUG - fprintf(stderr, "wait: %d ms\n", nwait); + fprintf(stderr, "wait: %d ms\n", nwait); #endif - if (nwait >= 0) - { - gmx->man->nWait = nwait; + if (nwait >= 0) + { + gmx->man->nWait = nwait; + } } default: #ifdef DEBUG @@ -414,53 +420,41 @@ enum { esFUNCT = 1, esBSHOW, esINFIL, esINDEXFIL, esLSQ, esSHOW, esPLOTFIL }; -static gmx_bool in_set(int i, int n, int set[]) +static bool in_set(int i, int n, int set[]) { int j; for (j = 0; (j < n); j++) { if (set[j] == i) { - return TRUE; + return true; } } - return FALSE; + return false; } typedef t_dlg *t_mmb (t_x11 *x11, t_gmx *gmx); typedef struct { - eDialogs ed; const char *dlgfile; DlgCallback *cb; } t_dlginit; -typedef struct { - eMBoxes ed; - t_mmb *mmb; - DlgCallback *cb; -} t_mbinit; - void init_dlgs(t_x11 *x11, t_gmx *gmx) { static t_dlginit di[] = { - { edExport, "export.dlg", ExportCB }, - { edBonds, "bonds.dlg", BondsCB } + { "export.dlg", ExportCB }, + { "bonds.dlg", BondsCB } }; - static t_mbinit mi[emNR] = { - { emQuit, quit_mb, QuitCB }, - { emHelp, help_mb, MBCallback }, - { emAbout, about_mb, MBCallback }, - { emNotImplemented, ni_mb, MBCallback } - }; - int i; + static t_mmb *mi[emNR] = { quit_mb, help_mb, about_mb, ni_mb }; + unsigned int i; snew(gmx->dlgs, edNR); for (i = 0; (i < asize(di)); i++) { gmx->dlgs[i] = ReadDlg(x11, gmx->wd->self, di[i].dlgfile, - x11->fg, x11->bg, di[i].dlgfile, - 0, 0, TRUE, FALSE, di[i].cb, gmx); + di[i].dlgfile, + 0, 0, true, false, di[i].cb, gmx); } gmx->dlgs[edFilter] = select_filter(x11, gmx); @@ -468,7 +462,7 @@ void init_dlgs(t_x11 *x11, t_gmx *gmx) snew(gmx->mboxes, emNR); for (i = 0; (i < emNR); i++) { - gmx->mboxes[i] = mi[i].mmb(x11, gmx); + gmx->mboxes[i] = mi[i](x11, gmx); } gmx->which_mb = -1; } diff --git a/src/ngmx/dialogs.h b/src/programs/view/dialogs.h similarity index 97% rename from src/ngmx/dialogs.h rename to src/programs/view/dialogs.h index e3a9170f0f..cdb3d43bf0 100644 --- a/src/ngmx/dialogs.h +++ b/src/programs/view/dialogs.h @@ -42,21 +42,21 @@ #include "logo.h" typedef struct { - gmx_bool bMapped; + bool bMapped; t_dlg *dlg; } t_dialogs; -typedef enum { +enum eDialogs { edExport, edBonds, edFilter, edNR -} eDialogs; +}; -typedef enum { +enum eMBoxes { emQuit, emHelp, emAbout, emNotImplemented, emNR -} eMBoxes; +}; -typedef enum { +enum eExport { eExpGromos, eExpPDB, eExpNR -} eExport; +}; typedef struct { char confout[256]; /* Export file */ diff --git a/src/ngmx/ff.bm b/src/programs/view/ff.bm similarity index 100% rename from src/ngmx/ff.bm rename to src/programs/view/ff.bm diff --git a/src/ngmx/fgrid.c b/src/programs/view/fgrid.cpp similarity index 93% rename from src/ngmx/fgrid.c rename to src/programs/view/fgrid.cpp index 172e40cb7e..a8ca085246 100644 --- a/src/ngmx/fgrid.c +++ b/src/programs/view/fgrid.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -91,24 +91,17 @@ void ReadDlgError(const char *infile, eDLGERR err, const char *s, break; } fprintf(stderr, " in file %s\n", infile); - fprintf(stderr, "C-File: %s, line: %d\n", file, line); + fprintf(stderr, "source file: %s, line: %d\n", file, line); exit(1); } #define ReadDlgErr(in, er, es) ReadDlgError(in, er, es, __FILE__, __LINE__) -static void GetBuf(FILE *in, char *buf) -{ - int rc; - - rc = fscanf(in, "%s", buf); -} - static void ReadAccOpen(const char *infile, FILE *in) { char buf[STRLEN]; - GetBuf(in, buf); + fscanf(in, "%4s", buf); if (strcmp(buf, "{") != 0) { ReadDlgErr(infile, eACCOEXP, buf); @@ -119,7 +112,7 @@ static void ReadAccClose(const char *infile, FILE *in) { char buf[STRLEN]; - GetBuf(in, buf); + fscanf(in, "%4s", buf); if (strcmp(buf, "}") != 0) { ReadDlgErr(infile, eACCCEXP, buf); @@ -174,7 +167,7 @@ static void ReadQuoteStringOrAccClose(FILE *in, char *buf) buf[i] = '\0'; } -static gmx_bool bNotAccClose(const char *buf) +static bool bNotAccClose(const char *buf) { return (strcmp(buf, "}") != 0); } @@ -324,7 +317,7 @@ static t_fitem *ScanFItem(const char *infile, FILE *in, char *buf) { /* Special case */ edlg = edlgBN; - fitem->bDef = TRUE; + fitem->bDef = true; } if (edlg == edlgNR+1) { @@ -373,8 +366,6 @@ t_fgrid *FGridFromFile(const char *infile) { FILE *in; char buf[STRLEN]; - char *gmxlib; - char newinfile[STRLEN]; t_fgrid *fgrid; t_fgroup *fgroup; @@ -382,20 +373,20 @@ t_fgrid *FGridFromFile(const char *infile) int gridx, gridy; in = libopen(infile); - GetBuf(in, buf); + fscanf(in, "%6s", buf); if (strcmp(buf, "grid") != 0) { ReadDlgErr(infile, eGRIDEXP, buf); } fgrid = NewFGrid(); - if ((fscanf(in, "%d%d", &gridx, &gridy)) != 2) + if ((fscanf(in, "%5d%5d", &gridx, &gridy)) != 2) { ReadDlgErr(infile, eNOVALS, "grid w,h"); } fgrid->w = gridx; fgrid->h = gridy; ReadAccOpen(infile, in); - GetBuf(in, buf); + fscanf(in, "%15s", buf); while (bNotAccClose(buf)) { if (strcmp(buf, "group") == 0) @@ -403,7 +394,7 @@ t_fgrid *FGridFromFile(const char *infile) fgroup = AddFGridFGroup(fgrid); ReadQuoteString(infile, in, buf); fgroup->name = strdup(buf); - if ((fscanf(in, "%d%d%d%d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4) + if ((fscanf(in, "%5d%5d%5d%5d", &fgroup->x, &fgroup->y, &fgroup->w, &fgroup->h)) != 4) { ReadDlgErr(infile, eNOVALS, "group x,y,w,h"); } @@ -416,17 +407,17 @@ t_fgrid *FGridFromFile(const char *infile) ReadDlgErr(infile, eTOOHIGH, buf); } ReadAccOpen(infile, in); - GetBuf(in, buf); + fscanf(in, "%15s", buf); while (bNotAccClose(buf)) { AddFGroupFItem(fgroup, ScanFItem(infile, in, buf)); - GetBuf(in, buf); + fscanf(in, "%15s", buf); } } else if (strcmp(buf, "simple") == 0) { fsimple = AddFGridFSimple(fgrid); - if ((fscanf(in, "%d%d%d%d", &fsimple->x, &fsimple->y, &fsimple->w, &fsimple->h)) != 4) + if ((fscanf(in, "%5d%5d%5d%5d", &fsimple->x, &fsimple->y, &fsimple->w, &fsimple->h)) != 4) { ReadDlgErr(infile, eNOVALS, "simple x,y,w,h"); } @@ -439,11 +430,11 @@ t_fgrid *FGridFromFile(const char *infile) ReadDlgErr(infile, eTOOHIGH, "simple"); } ReadAccOpen(infile, in); - GetBuf(in, buf); + fscanf(in, "%15s", buf); fsimple->fitem = ScanFItem(infile, in, buf); ReadAccClose(infile, in); } - GetBuf(in, buf); + fscanf(in, "%15s", buf); } ffclose(in); diff --git a/src/ngmx/fgrid.h b/src/programs/view/fgrid.h similarity index 87% rename from src/ngmx/fgrid.h rename to src/programs/view/fgrid.h index 08b16d0d6c..b90978dcd8 100644 --- a/src/ngmx/fgrid.h +++ b/src/programs/view/fgrid.h @@ -37,11 +37,11 @@ #define _fgrid_h #include -#include +#include "xdlgitem.h" typedef struct { edlgitem edlg; - gmx_bool bDef; + bool bDef; int nname; char **name; char *set, *get, *def, *help; @@ -72,14 +72,14 @@ typedef enum { eTOOWIDE, eTOOHIGH, eQUOTE, eNOVALS } eDLGERR; -extern void ReadDlgErr(const char *infile, eDLGERR err, const char *s); +void ReadDlgErr(const char *infile, eDLGERR err, const char *s); -extern t_fgrid *FGridFromFile(const char *infile); +t_fgrid *FGridFromFile(const char *infile); -extern void DoneFGrid(t_fgrid *fgrid); +void DoneFGrid(t_fgrid *fgrid); -extern void DumpFGrid(t_fgrid *fgrid); +void DumpFGrid(t_fgrid *fgrid); -extern void ReadQuoteString(const char *infile, FILE *in, char *buf); +void ReadQuoteString(const char *infile, FILE *in, char *buf); #endif /* _fgrid_h */ diff --git a/src/ngmx/filter.c b/src/programs/view/filter.cpp similarity index 93% rename from src/ngmx/filter.c rename to src/programs/view/filter.cpp index b5cfdeec0d..a9cec7e0b5 100644 --- a/src/ngmx/filter.c +++ b/src/programs/view/filter.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -61,7 +61,7 @@ t_filter *init_filter(t_atoms *atoms, const char *fn, int natom_trx) { snew(f->grps, 1); snew(f->grps->index, 1); - analyse(atoms, f->grps, &f->grpnames, FALSE, FALSE); + analyse(atoms, f->grps, &f->grpnames, false, false); } snew(f->bDisable, f->grps->nr); for (g = 0; g < f->grps->nr; g++) @@ -97,7 +97,7 @@ static void FilterCB(t_x11 *x11, int dlg_mess, int item_id, case DLG_SET: if (set) { - if (sscanf(set, "%d", &nset) == 1) + if (sscanf(set, "%10d", &nset) == 1) { f->bShow[nset] = !f->bShow[nset]; } @@ -123,7 +123,7 @@ t_dlg *select_filter(t_x11 *x11, t_gmx *gmx) len = strlen(title); for (i = 0; (i < (int)gmx->filter->grps->nr); i++) { - len = max(len, (int)strlen(gmx->filter->grpnames[i])); + len = std::max(len, (int)strlen(gmx->filter->grpnames[i])); } len += 2; @@ -181,8 +181,8 @@ t_dlg *select_filter(t_x11 *x11, t_gmx *gmx) fprintf(tmp, "}\n\n}\n"); fclose(tmp); - dlg = ReadDlg(x11, gmx->wd->self, title, x11->fg, x11->bg, tmpfile, - 0, 0, TRUE, FALSE, FilterCB, gmx); + dlg = ReadDlg(x11, gmx->wd->self, title, tmpfile, + 0, 0, true, false, FilterCB, gmx); remove(tmpfile); diff --git a/src/ngmx/gromacs.bm b/src/programs/view/gromacs.bm similarity index 100% rename from src/ngmx/gromacs.bm rename to src/programs/view/gromacs.bm diff --git a/src/ngmx/info.bm b/src/programs/view/info.bm similarity index 100% rename from src/ngmx/info.bm rename to src/programs/view/info.bm diff --git a/src/ngmx/logo.c b/src/programs/view/logo.cpp similarity index 94% rename from src/ngmx/logo.c rename to src/programs/view/logo.cpp index 4a4dbb5e9b..f0980df082 100644 --- a/src/ngmx/logo.c +++ b/src/programs/view/logo.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -37,10 +37,10 @@ #endif #include "sysstuff.h" +#include "macros.h" #include "xutil.h" #include "Xstuff.h" #include "smalloc.h" -#include "macros.h" #include "copyrite.h" #include "logo.h" @@ -66,10 +66,10 @@ void hide_logo(t_x11 *x11, t_logo *logo) XUnmapWindow(x11->disp, logo->wd.self); } -static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { /* Assume window is 100x110 */ - static gmx_bool bFirst = TRUE; + static bool bFirst = true; #define CSIZE 9 #define NSIZE 8 #define OSIZE 9 @@ -84,7 +84,7 @@ static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { 40, YOFFS+22, CSIZE, &LIGHTGREEN }, { 40, YOFFS+34, CSIZE, &LIGHTGREEN }, { 50, YOFFS+12, CSIZE, &LIGHTGREEN }, - { 50, YOFFS, OSIZE, &LIGHTRED }, + { 50, YOFFS, OSIZE, &LIGHTRED }, { 60, YOFFS+22, NSIZE, &LIGHTCYAN }, { 60, YOFFS+32, HSIZE, &WHITE }, { 70, YOFFS+12, CSIZE, &LIGHTGREEN }, @@ -102,7 +102,7 @@ static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) static t_mess Mess[] = { { "GROMACS", 0, 20, NULL }, { NULL, 16, 9, NULL }, - { "Copyright (c) 1991-2010", COFFS+ 2, 9, NULL }, + { "Copyright (c) 1991-2013", COFFS+ 2, 9, NULL }, { "D.v.d.Spoel, E.Lindahl, B.Hess", COFFS+11, 9, NULL }, { "& Groningen University ", COFFS+20, 9, NULL }, { "click to dismiss", COFFS+31, 8, NULL } @@ -132,7 +132,7 @@ static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) Mess[i].fnt = (i == 0) ? logo->bigfont : (i == NMESS-1) ? x11->font : logo->smallfont; } - bFirst = FALSE; + bFirst = false; } switch (event->type) { @@ -152,7 +152,7 @@ static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) } XSetForeground(x11->disp, x11->gc, BLACK); XDrawRectangle(x11->disp, wd->self, x11->gc, 2, 2, wd->width-5, wd->height-5); - for (i = 0; (i < asize(Mess)); i++) + for (i = 0; (i < NMESS); i++) { SpecialTextInRect(x11, Mess[i].fnt, wd->self, Mess[i].text, 0, Mess[i].y, wd->width, Mess[i].h, @@ -168,10 +168,10 @@ static gmx_bool LogoCallBack(t_x11 *x11, XEvent *event, Window w, void *data) break; } - return FALSE; + return false; } -t_logo *init_logo(t_x11 *x11, Window parent, gmx_bool bQuitOnClick) +t_logo *init_logo(t_x11 *x11, Window parent, bool bQuitOnClick) { static const char *bfname[] = { "-b&h-lucida-bold-i-normal-sans-34-240-100-100-p-215-iso8859-1", @@ -188,7 +188,7 @@ t_logo *init_logo(t_x11 *x11, Window parent, gmx_bool bQuitOnClick) "fixed" }; #define NSF asize(sfname) - int i; + unsigned int i; unsigned long bg; char *newcol; t_logo *logo; diff --git a/src/ngmx/logo.h b/src/programs/view/logo.h similarity index 92% rename from src/ngmx/logo.h rename to src/programs/view/logo.h index 0d29ff62c3..9f1cdc3e0b 100644 --- a/src/ngmx/logo.h +++ b/src/programs/view/logo.h @@ -36,21 +36,21 @@ #ifndef _logo_h #define _logo_h -#include -#include +#include "x11.h" +#include "xutil.h" typedef struct { XFontStruct *bigfont; XFontStruct *smallfont; t_windata wd; - gmx_bool bQuitOnClick; + bool bQuitOnClick; } t_logo; extern void show_logo(t_x11 *x11, t_logo *logo); extern void hide_logo(t_x11 *x11, t_logo *logo); -extern t_logo *init_logo(t_x11 *x11, Window parent, gmx_bool bQuitOnClick); +extern t_logo *init_logo(t_x11 *x11, Window parent, bool bQuitOnClick); extern void done_logo(t_x11 *x11, t_logo *logo); diff --git a/src/ngmx/manager.c b/src/programs/view/manager.cpp similarity index 90% rename from src/ngmx/manager.c rename to src/programs/view/manager.cpp index cf4d4c0dd7..63e42164ee 100644 --- a/src/ngmx/manager.c +++ b/src/programs/view/manager.cpp @@ -69,9 +69,9 @@ static void add_object(t_manager *man, eObject eO, atom_id ai, atom_id aj) } static void add_bonds(t_manager *man, t_functype func[], - t_ilist *b, gmx_bool bB[]) + t_ilist *b, bool bB[]) { - gmx_bool *bH = man->bHydro; + bool *bH = man->bHydro; t_iatom *ia; t_iatom type, ai, aj, ak; int i, delta, ftype; @@ -91,7 +91,7 @@ static void add_bonds(t_manager *man, t_functype func[], { aj = ia[2]; ak = ia[3]; - bB[ai] = bB[aj] = bB[ak] = TRUE; + bB[ai] = bB[aj] = bB[ak] = true; add_object(man, eOHBond, ai, aj); add_object(man, eOHBond, ai, ak); } @@ -101,7 +101,7 @@ static void add_bonds(t_manager *man, t_functype func[], #ifdef DEBUG fprintf(stderr, "Adding bond from %d to %d\n", ai, aj); #endif - bB[ai] = bB[aj] = TRUE; + bB[ai] = bB[aj] = true; if (!(bH[ai] == bH[aj])) { add_object(man, eOHBond, ai, aj); @@ -119,7 +119,7 @@ static void add_bonds(t_manager *man, t_functype func[], } } -static void add_bpl(t_manager *man, t_idef *idef, gmx_bool bB[]) +static void add_bpl(t_manager *man, t_idef *idef, bool bB[]) { int ftype; @@ -151,7 +151,7 @@ static atom_id which_atom(t_manager *man, int x, int y) return NO_ATID; } -static void do_label(t_x11 *x11, t_manager *man, int x, int y, gmx_bool bSet) +static void do_label(t_x11 *x11, t_manager *man, int x, int y, bool bSet) { atom_id ai; unsigned long col; @@ -163,12 +163,12 @@ static void do_label(t_x11 *x11, t_manager *man, int x, int y, gmx_bool bSet) if (bSet && !man->bLabel[ai]) { col = WHITE; - man->bLabel[ai] = TRUE; + man->bLabel[ai] = true; } else if (!bSet && man->bLabel[ai]) { col = BLUE; - man->bLabel[ai] = FALSE; + man->bLabel[ai] = false; } else { @@ -183,12 +183,12 @@ static void do_label(t_x11 *x11, t_manager *man, int x, int y, gmx_bool bSet) static void show_label(t_x11 *x11, t_manager *man, int x, int y) { - do_label(x11, man, x, y, TRUE); + do_label(x11, man, x, y, true); } static void hide_label(t_x11 *x11, t_manager *man, int x, int y) { - do_label(x11, man, x, y, FALSE); + do_label(x11, man, x, y, false); } void set_file(t_x11 *x11, t_manager *man, const char *trajectory, @@ -198,10 +198,10 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory, char buf[256], quote[256]; t_tpxheader sh; t_atoms *at; - gmx_bool *bB; - int i, idum; + bool *bB; + int i; - read_tpxheader(status, &sh, TRUE, NULL, NULL); + read_tpxheader(status, &sh, true, NULL, NULL); snew(man->ix, sh.natoms); snew(man->zz, sh.natoms); snew(man->col, sh.natoms); @@ -211,16 +211,16 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory, snew(man->bVis, sh.natoms); for (i = 0; (i < sh.natoms); i++) { - man->bVis[i] = FALSE; + man->bVis[i] = false; } - man->bPbc = FALSE; + man->bPbc = false; snew(man->szLab, sh.natoms); snew(man->bHydro, sh.natoms); snew(bB, sh.natoms); read_tpx_top(status, NULL, man->box, &man->natom, NULL, NULL, NULL, &man->top); - man->gpbc = gmx_rmpbc_init(&man->top.idef, -1, man->natom, man->box); + man->gpbc = gmx_rmpbc_init(&man->top.idef, -1, man->natom); man->natom = read_first_x(man->oenv, &man->status, trajectory, &(man->time), &(man->x), @@ -292,24 +292,6 @@ void step_message(t_x11 *x11, t_manager *man) XSendEvent(x11->disp, letter.xclient.window, True, 0, &letter); } -gmx_bool ReadMonfile(char *fn, int *nbars, int *bars) -{ - FILE *fp; - if ((fp = fopen(fn, "r")) == NULL) - { - return(FALSE); - } - else - { - for ((*nbars) = 0; fscanf(fp, "%d", &bars[*nbars]) > 0; (*nbars)++) - { - ; - } - fclose(fp); - return (TRUE); - } -} - static void reset_mols(t_block *mols, matrix box, rvec x[]) { int i, m0, m1, j, m; @@ -357,12 +339,11 @@ static void reset_mols(t_block *mols, matrix box, rvec x[]) } } -static gmx_bool step_man(t_manager *man, int *nat) +static bool step_man(t_manager *man, int *nat) { static int ncount = 0; - static gmx_bool bWarn = FALSE; - gmx_bool bEof; - int dum; + static bool bWarn = false; + bool bEof; const char *warn; if (!man->natom) @@ -370,7 +351,7 @@ static gmx_bool step_man(t_manager *man, int *nat) fprintf(stderr, "Not initiated yet!"); exit(1); } - bEof = read_next_x(man->oenv, man->status, &man->time, man->natom, man->x, man->box); + bEof = read_next_x(man->oenv, man->status, &man->time, man->x, man->box); *nat = man->natom; if (ncount == man->nSkip) { @@ -385,7 +366,7 @@ static gmx_bool step_man(t_manager *man, int *nat) if (warn && !bWarn) { fprintf(stderr, "\n%s\n", warn); - bWarn = TRUE; + bWarn = true; } break; case esbRect: @@ -414,9 +395,9 @@ static gmx_bool step_man(t_manager *man, int *nat) static void HandleClient(t_x11 *x11, t_manager *man, long data[]) { - int ID, button, x, y; - gmx_bool bPos; - real fac; + int ID, button, x, y; + bool bPos; + real fac; ID = data[0]; button = data[1]; @@ -458,9 +439,9 @@ static void HandleClient(t_x11 *x11, t_manager *man, long data[]) if (man->status) { rewind_trj(man->status); - read_next_x(man->oenv, man->status, &(man->time), man->natom, man->x, + read_next_x(man->oenv, man->status, &(man->time), man->x, man->box); - man->bEof = FALSE; + man->bEof = false; draw_mol(x11, man); } break; @@ -471,8 +452,8 @@ static void HandleClient(t_x11 *x11, t_manager *man, long data[]) nat = 0; if (!step_man(man, &nat)) { - man->bEof = TRUE; - man->bStop = TRUE; + man->bEof = true; + man->bStop = true; } else { @@ -485,10 +466,10 @@ static void HandleClient(t_x11 *x11, t_manager *man, long data[]) break; } case IDFF: - man->bStop = FALSE; + man->bStop = false; break; case IDSTOP_ANI: - man->bStop = TRUE; + man->bStop = true; break; case IDDRAWMOL: draw_mol(x11, man); @@ -514,7 +495,7 @@ static void HandleClient(t_x11 *x11, t_manager *man, long data[]) } } -static gmx_bool TitleCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool TitleCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_windata *wd; @@ -535,10 +516,10 @@ static gmx_bool TitleCallBack(t_x11 *x11, XEvent *event, Window w, void *data) wd->height = event->xconfigure.height; break; } - return FALSE; + return false; } -static gmx_bool ManCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool ManCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_manager *man; int width, height; @@ -560,7 +541,7 @@ static gmx_bool ManCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } void no_labels(t_x11 *x11, t_manager *man) @@ -569,7 +550,7 @@ void no_labels(t_x11 *x11, t_manager *man) for (i = 0; (i < man->natom); i++) { - man->bLabel[i] = FALSE; + man->bLabel[i] = false; } draw_mol(x11, man); } @@ -626,13 +607,13 @@ void map_man(t_x11 *x11, t_manager *man) show_but(x11, man->bbox); } -gmx_bool toggle_animate (t_x11 *x11, t_manager *man) +bool toggle_animate (t_x11 *x11, t_manager *man) { if (man->status) { man->bAnimate = !man->bAnimate; - man->bStop = TRUE; - man->bEof = FALSE; + man->bStop = true; + man->bEof = false; if (man->bAnimate) { show_but(x11, man->vbox); @@ -645,7 +626,7 @@ gmx_bool toggle_animate (t_x11 *x11, t_manager *man) return man->bAnimate; } -gmx_bool toggle_pbc (t_manager *man) +bool toggle_pbc (t_manager *man) { man->bPbc = !man->bPbc; @@ -663,8 +644,8 @@ t_manager *init_man(t_x11 *x11, Window Parent, snew(man, 1); man->status = NULL; - man->bPlus = TRUE; - man->bSort = TRUE; + man->bPlus = true; + man->bSort = true; man->oenv = oenv; InitWin(&(man->wd), x, y, width, height, 0, "Manager"); man->wd.self = XCreateSimpleWindow(x11->disp, Parent, man->wd.x, man->wd.y, @@ -724,7 +705,7 @@ void do_filter(t_x11 *x11, t_manager *man, t_filter *filter) for (i = 0; (i < man->natom); i++) { - man->bVis[i] = FALSE; + man->bVis[i] = false; } for (i = 0; (i < filter->grps->nr); i++) { @@ -732,7 +713,7 @@ void do_filter(t_x11 *x11, t_manager *man, t_filter *filter) { for (j = filter->grps->index[i]; (j < filter->grps->index[i+1]); j++) { - man->bVis[filter->grps->a[j]] = TRUE; + man->bVis[filter->grps->a[j]] = true; } } } diff --git a/src/ngmx/manager.h b/src/programs/view/manager.h similarity index 86% rename from src/ngmx/manager.h rename to src/programs/view/manager.h index 3f87674053..4a15076490 100644 --- a/src/ngmx/manager.h +++ b/src/programs/view/manager.h @@ -52,25 +52,25 @@ #define LDHEIGHT 0 #define LEGHEIGHT 60 -typedef enum { +enum eObject { eOSingle, eOBond, eOHBond, eONR -} eObject; +}; -typedef enum { +enum eVisible { eVNormal, eVSpecial, eVHidden, evNR -} eVisible; +}; -enum { +enum eBwidth { eBThin, eBFat, eBVeryFat, eBSpheres, eBNR }; -enum { +enum esBox { esbNone, esbRect, esbTri, esbTrunc, esbNR }; typedef struct { t_windata wd; /* Mol window structure */ - gmx_bool bShowHydrogen; /* Show Hydrogens? */ + bool bShowHydrogen; /* Show Hydrogens? */ int bond_type; /* Show one of the above bondtypes */ int ePBC; /* PBC type */ int boxtype; /* Rectangular, Tric, TruncOct (display)*/ @@ -88,8 +88,8 @@ typedef struct { typedef struct { t_blocka *grps; /* Blocks with atom numbers */ char **grpnames; /* The names of the groups */ - gmx_bool *bDisable; /* Group indexes out of natoms in TRX */ - gmx_bool *bShow; /* Show a group ? */ + bool *bDisable; /* Group indexes out of natoms in TRX */ + bool *bShow; /* Show a group ? */ } t_filter; /* @@ -113,19 +113,19 @@ typedef struct { matrix box; /* The box */ int nobj; /* The number of objects */ t_object *obj; /* The objects on screen */ - gmx_bool *bHydro; /* TRUE for hydrogen atoms */ - gmx_bool *bLabel; /* Show a label on atom i? */ + bool *bHydro; /* true for hydrogen atoms */ + bool *bLabel; /* Show a label on atom i? */ char **szLab; /* Array of pointers to labels */ unsigned long *col; /* The colour of the atoms */ int *size; /* The size of the atoms */ real *vdw; /* The VDWaals radius of the atoms */ - gmx_bool *bVis; /* visibility of atoms */ - gmx_bool bPbc; /* Remove Periodic boundary */ - gmx_bool bAnimate; /* Animation going on? */ - gmx_bool bEof; /* End of file reached? */ - gmx_bool bStop; /* Stopped by user? */ - gmx_bool bSort; /* Sort the coordinates */ - gmx_bool bPlus; /* Draw plus for single atom */ + bool *bVis; /* visibility of atoms */ + bool bPbc; /* Remove Periodic boundary */ + bool bAnimate; /* Animation going on? */ + bool bEof; /* End of file reached? */ + bool bStop; /* Stopped by user? */ + bool bSort; /* Sort the coordinates */ + bool bPlus; /* Draw plus for single atom */ int nSkip; /* Skip n steps after each frame */ int nWait; /* Wait n ms after each frame */ gmx_rmpbc_t gpbc; /* For removing peridiocity */ @@ -161,9 +161,9 @@ extern void map_man(t_x11 *x11, t_manager *man); extern void move_man(t_x11 *x11, t_manager *man, int width, int height); -extern gmx_bool toggle_animate (t_x11 *x11, t_manager *man); +extern bool toggle_animate (t_x11 *x11, t_manager *man); -extern gmx_bool toggle_pbc (t_manager *man); +extern bool toggle_pbc (t_manager *man); extern void no_labels(t_x11 *x11, t_manager *man); /* Turn off all labels */ diff --git a/src/ngmx/molps.c b/src/programs/view/molps.cpp similarity index 91% rename from src/ngmx/molps.c rename to src/programs/view/molps.cpp index 736594e404..a2f851e79a 100644 --- a/src/ngmx/molps.c +++ b/src/programs/view/molps.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -78,7 +78,7 @@ static void init_pbc(matrix box) } } -static gmx_bool local_pbc_dx(rvec x1, rvec x2) +static bool local_pbc_dx(rvec x1, rvec x2) { int i; real dx; @@ -88,19 +88,19 @@ static gmx_bool local_pbc_dx(rvec x1, rvec x2) dx = x1[i]-x2[i]; if (dx > gl_hbox[i]) { - return FALSE; + return false; } else if (dx <= gl_mhbox[i]) { - return FALSE; + return false; } } - return TRUE; + return true; } static void ps_draw_bond(t_psdata ps, atom_id ai, atom_id aj, iv2 vec2[], - rvec x[], char **atomnm[], int size[], gmx_bool bBalls) + rvec x[], char **atomnm[], int size[], bool bBalls) { char *ic, *jc; int xi, yi, xj, yj; @@ -142,14 +142,14 @@ static void ps_draw_bond(t_psdata ps, } void ps_draw_objects(t_psdata ps, int nobj, t_object objs[], iv2 vec2[], rvec x[], - char **atomnm[], int size[], gmx_bool bShowHydro, int bond_type, - gmx_bool bPlus) + char **atomnm[], int size[], bool bShowHydro, int bond_type, + bool bPlus) { - gmx_bool bBalls; + bool bBalls; int i; t_object *obj; - bBalls = FALSE; + bBalls = false; for (i = 0; (i < nobj); i++) { obj = &(objs[i]); @@ -219,8 +219,6 @@ static void draw_box(t_psdata ps, t_3dview *view, matrix box, void ps_draw_mol(t_psdata ps, t_manager *man) { - static char tstr[2][20]; - static int ntime = 0; t_windata *win; t_3dview *view; t_molwin *mw; @@ -265,13 +263,6 @@ void ps_draw_mol(t_psdata ps, t_manager *man) /* Start drawing XClearWindow(x11->disp,win->self); */ - /* Draw Time - sprintf(tstr[ntime],"Time: %.3 ps",man->time); - if (strcmp(tstr[ntime],tstr[1-ntime]) != 0) { - set_vbtime(x11,man->vbox,tstr[ntime]); - ntime=1-ntime; - }*/ - if (mw->boxtype != esbNone) { draw_box(ps, view, man->box, x0, y0, sx, sy); diff --git a/src/ngmx/molps.h b/src/programs/view/molps.h similarity index 100% rename from src/ngmx/molps.h rename to src/programs/view/molps.h diff --git a/src/ngmx/nleg.c b/src/programs/view/nleg.cpp similarity index 94% rename from src/ngmx/nleg.c rename to src/programs/view/nleg.cpp index d5f25eadab..acc23e10d5 100644 --- a/src/ngmx/nleg.c +++ b/src/programs/view/nleg.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -66,15 +66,15 @@ static t_atomcolor ac[] = { int search_ac(const char *type) { - int i, nb, mij, best, besti; + unsigned int i, nb, mij, best, besti; best = 0; besti = 0; - if (type) + if (NULL != type) { for (i = 0; (i < NAC); i++) { - mij = min((int)strlen(type), (int)strlen(ac[i].tp)); + mij = std::min((int)strlen(type), (int)strlen(ac[i].tp)); for (nb = 0; (nb < mij); nb++) { if (type[nb] != ac[i].tp[nb]) @@ -141,7 +141,7 @@ void DrawLegend(t_x11 *x11, t_windata *Win) XSetForeground(x11->disp, x11->gc, x11->fg); } -static gmx_bool LegWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool LegWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_legendwin *lw; @@ -154,7 +154,7 @@ static gmx_bool LegWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } t_legendwin *init_legw(t_x11 *x11, Window Parent, diff --git a/src/ngmx/nleg.h b/src/programs/view/nleg.h similarity index 100% rename from src/ngmx/nleg.h rename to src/programs/view/nleg.h diff --git a/src/ngmx/nmol.c b/src/programs/view/nmol.cpp similarity index 94% rename from src/ngmx/nmol.c rename to src/programs/view/nmol.cpp index c9dd2f781d..8851f6c5fa 100644 --- a/src/ngmx/nmol.c +++ b/src/programs/view/nmol.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -53,7 +53,7 @@ #define MSIZE 4 -static gmx_bool MWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool MWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_molwin *mw; Window To; @@ -93,12 +93,12 @@ static gmx_bool MWCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } void set_def (t_molwin *mw, int ePBC, matrix box) { - mw->bShowHydrogen = TRUE; + mw->bShowHydrogen = true; mw->bond_type = eBFat; mw->ePBC = ePBC; mw->boxtype = esbRect; @@ -131,7 +131,7 @@ void map_mw(t_x11 *x11, t_molwin *mw) XMapWindow(x11->disp, mw->wd.self); } -gmx_bool toggle_hydrogen(t_x11 *x11, t_molwin *mw) +bool toggle_hydrogen(t_x11 *x11, t_molwin *mw) { mw->bShowHydrogen = !mw->bShowHydrogen; ExposeWin(x11->disp, mw->wd.self); @@ -175,7 +175,7 @@ void done_mw(t_x11 *x11, t_molwin *mw) static void draw_atom(Display *disp, Window w, GC gc, atom_id ai, iv2 vec2[], unsigned long col[], int size[], - gmx_bool bBall, gmx_bool bPlus) + bool bBall, bool bPlus) { int xi, yi; @@ -217,7 +217,7 @@ static void my_init_pbc(matrix box) } } -static gmx_bool local_pbc_dx(rvec x1, rvec x2) +static bool local_pbc_dx(rvec x1, rvec x2) { int i; real dx; @@ -227,19 +227,19 @@ static gmx_bool local_pbc_dx(rvec x1, rvec x2) dx = x1[i]-x2[i]; if (dx > gl_hbox[i]) { - return FALSE; + return false; } else if (dx <= gl_mhbox[i]) { - return FALSE; + return false; } } - return TRUE; + return true; } static void draw_bond(Display *disp, Window w, GC gc, atom_id ai, atom_id aj, iv2 vec2[], - rvec x[], unsigned long col[], int size[], gmx_bool bBalls) + rvec x[], unsigned long col[], int size[], bool bBalls) { unsigned long ic, jc; int xi, yi, xj, yj; @@ -247,8 +247,8 @@ static void draw_bond(Display *disp, Window w, GC gc, if (bBalls) { - draw_atom(disp, w, gc, ai, vec2, col, size, TRUE, FALSE); - draw_atom(disp, w, gc, aj, vec2, col, size, TRUE, FALSE); + draw_atom(disp, w, gc, ai, vec2, col, size, true, false); + draw_atom(disp, w, gc, aj, vec2, col, size, true, false); } else { @@ -313,12 +313,12 @@ void create_visibility(t_manager *man) { if (obj->eV != eVHidden) { - man->bVis[obj->ai] = TRUE; + man->bVis[obj->ai] = true; switch (obj->eO) { case eOBond: case eOHBond: - man->bVis[obj->aj] = TRUE; + man->bVis[obj->aj] = true; break; default: break; @@ -353,7 +353,7 @@ int filter_vis(t_manager *man) { int i, nobj, nvis, nhide; atom_id ai; - gmx_bool bAdd, *bVis; + bool bAdd, *bVis; t_object *obj; t_object *newobj; @@ -391,14 +391,14 @@ int filter_vis(t_manager *man) void draw_objects(Display *disp, Window w, GC gc, int nobj, t_object objs[], iv2 vec2[], rvec x[], - unsigned long col[], int size[], gmx_bool bShowHydro, int bond_type, - gmx_bool bPlus) + unsigned long col[], int size[], bool bShowHydro, int bond_type, + bool bPlus) { - gmx_bool bBalls; + bool bBalls; int i; t_object *obj; - bBalls = FALSE; + bBalls = false; switch (bond_type) { case eBThin: @@ -411,8 +411,8 @@ void draw_objects(Display *disp, Window w, GC gc, int nobj, XSetLineAttributes(disp, gc, 5, LineSolid, CapNotLast, JoinRound); break; case eBSpheres: - bBalls = TRUE; - bPlus = FALSE; + bBalls = true; + bPlus = false; break; default: gmx_fatal(FARGS, "Invalid bond_type selected: %d\n", bond_type); diff --git a/src/ngmx/nmol.h b/src/programs/view/nmol.h similarity index 97% rename from src/ngmx/nmol.h rename to src/programs/view/nmol.h index 1fb529f4fd..4c0d81248b 100644 --- a/src/ngmx/nmol.h +++ b/src/programs/view/nmol.h @@ -53,7 +53,7 @@ extern int compare_obj(const void *a, const void *b); extern int filter_vis(t_manager *man); extern void set_sizes(t_manager *man, real sx, real sy); -extern gmx_bool toggle_hydrogen(t_x11 *x11, t_molwin *mw); +extern bool toggle_hydrogen(t_x11 *x11, t_molwin *mw); /* Toggle the state of the hydrogen drawing, * return the current state */ diff --git a/src/ngmx/play.bm b/src/programs/view/play.bm similarity index 100% rename from src/ngmx/play.bm rename to src/programs/view/play.bm diff --git a/src/ngmx/popup.c b/src/programs/view/popup.cpp similarity index 93% rename from src/ngmx/popup.c rename to src/programs/view/popup.cpp index d0d465f34c..df45e2fa21 100644 --- a/src/ngmx/popup.c +++ b/src/programs/view/popup.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -40,11 +40,11 @@ #include #include #include -#include -#include +#include "x11.h" +#include "xutil.h" #include "popup.h" -gmx_bool ChildCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +bool ChildCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_child *child; t_mentry *m; @@ -86,10 +86,10 @@ gmx_bool ChildCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } -gmx_bool MenuCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +bool MenuCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_menu *m; @@ -116,7 +116,7 @@ gmx_bool MenuCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned long bg, @@ -137,7 +137,7 @@ t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned long bg, mlen = 0; for (i = 0; (i < nent); i++) { - mlen = max(mlen, XTextWidth(x11->font, ent[i].str, strlen(ent[i].str))); + mlen = std::max(mlen, XTextWidth(x11->font, ent[i].str, strlen(ent[i].str))); } mht = XTextHeight(x11->font); /* Now we have the biggest single box, add a border of 2 pixels */ @@ -202,7 +202,7 @@ t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned long bg, return m; } -void show_menu(t_x11 *x11, t_menu *m, int x, int y, gmx_bool bGrab) +void show_menu(t_x11 *x11, t_menu *m, int x, int y, bool bGrab) { XMoveWindow(x11->disp, m->wd.self, x, y); m->bGrabbed = bGrab; @@ -219,7 +219,7 @@ void hide_menu(t_x11 *x11, t_menu *m) XUnmapWindow(x11->disp, m->wd.self); } -void check_menu_item(t_menu *m, int nreturn, gmx_bool bStatus) +void check_menu_item(t_menu *m, int nreturn, bool bStatus) { int i; diff --git a/src/ngmx/popup.h b/src/programs/view/popup.h similarity index 93% rename from src/ngmx/popup.h rename to src/programs/view/popup.h index 285e277dba..882a09d241 100644 --- a/src/ngmx/popup.h +++ b/src/programs/view/popup.h @@ -42,7 +42,7 @@ typedef struct { Window send_to; /* Window to send messages to */ int nreturn; /* Value returned when entry is selected */ - gmx_bool bChecked; /* Indicate whether menu item is check-marked */ + bool bChecked; /* Indicate whether menu item is check-marked */ const char *str; /* Text for menu entry */ } t_mentry; @@ -57,7 +57,7 @@ typedef struct { Window Parent; /* The parent of the menu */ int nitem; /* The number of menu items */ t_child *item; /* Array of child windows */ - gmx_bool bGrabbed; /* Did this menu grab the pointer? */ + bool bGrabbed; /* Did this menu grab the pointer? */ } t_menu; extern t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned long bg, @@ -76,7 +76,7 @@ extern t_menu *init_menu(t_x11 *x11, Window Parent, unsigned long fg, unsigned l * has to be shown, call show_menu. */ -extern void show_menu(t_x11 *x11, t_menu *m, int x, int y, gmx_bool bGrab); +extern void show_menu(t_x11 *x11, t_menu *m, int x, int y, bool bGrab); /* Show the menu in m at (x,y) * This will popup the menu, and when a button is released in the * menu send a ClientMessage to the Parent window of the menu @@ -87,7 +87,7 @@ extern void show_menu(t_x11 *x11, t_menu *m, int x, int y, gmx_bool bGrab); extern void hide_menu(t_x11 *x11, t_menu *m); /* Unmaps the window for m, hides the window */ -extern void check_menu_item(t_menu *m, int nreturn, gmx_bool bStatus); +extern void check_menu_item(t_menu *m, int nreturn, bool bStatus); /* Set the bChecked field in the menu item with return code * nreturn to bStatus. This function must always be called when * the bChecked flag has to changed. diff --git a/src/ngmx/pulldown.c b/src/programs/view/pulldown.cpp similarity index 88% rename from src/ngmx/pulldown.c rename to src/programs/view/pulldown.cpp index 398a997923..f621b9add9 100644 --- a/src/ngmx/pulldown.c +++ b/src/programs/view/pulldown.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -38,12 +38,12 @@ #include #include -#include #include +#include "x11.h" #include "popup.h" #include "pulldown.h" -static gmx_bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_pulldown *pd; int i, x, x1, y, nsel; @@ -70,8 +70,8 @@ static gmx_bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data) ; } pd->nsel = nsel; - x1 = max(0, min(pd_width(pd)-menu_width(pd->m[nsel]), pd->xpos[nsel])); - show_menu(x11, pd->m[nsel], x1, y+1, FALSE); + x1 = std::max(0, std::min(pd_width(pd)-menu_width(pd->m[nsel]), pd->xpos[nsel])); + show_menu(x11, pd->m[nsel], x1, y+1, false); } break; case ButtonRelease: @@ -80,10 +80,10 @@ static gmx_bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data) default: break; } - return FALSE; + return false; } -t_pulldown *init_pd(t_x11 *x11, Window Parent, int width, int height, +t_pulldown *init_pd(t_x11 *x11, Window Parent, int width, unsigned long fg, unsigned long bg, int nmenu, int *nsub, t_mentry *ent[], const char **title) { @@ -134,7 +134,7 @@ void hide_pd(t_x11 *x11, t_pulldown *pd) pd->nsel = -1; } -void check_pd_item(t_pulldown *pd, int nreturn, gmx_bool bStatus) +void check_pd_item(t_pulldown *pd, int nreturn, bool bStatus) { int i; @@ -164,9 +164,9 @@ int pd_width(t_pulldown *pd) w = 0; for (i = 0; (i < pd->nmenu); i++) { - w = max(w, menu_width(pd->m[i])); + w = std::max(w, menu_width(pd->m[i])); } - w = max(w, pd->xpos[pd->nmenu]); + w = std::max(w, pd->xpos[pd->nmenu]); return w; } @@ -177,7 +177,7 @@ int pd_height(t_pulldown *pd) h = 0; for (i = 0; (i < pd->nmenu); i++) { - h = max(h, menu_height(pd->m[i])); + h = std::max(h, menu_height(pd->m[i])); } return h; diff --git a/src/ngmx/pulldown.h b/src/programs/view/pulldown.h similarity index 97% rename from src/ngmx/pulldown.h rename to src/programs/view/pulldown.h index 951cd4aaae..b122625a07 100644 --- a/src/ngmx/pulldown.h +++ b/src/programs/view/pulldown.h @@ -47,7 +47,7 @@ typedef struct { const char **title; } t_pulldown; -extern t_pulldown *init_pd(t_x11 *x11, Window Parent, int width, int height, +extern t_pulldown *init_pd(t_x11 *x11, Window Parent, int width, unsigned long fg, unsigned long bg, int nmenu, int *nsub, t_mentry *ent[], const char **title); @@ -69,7 +69,7 @@ extern t_pulldown *init_pd(t_x11 *x11, Window Parent, int width, int height, extern void hide_pd(t_x11 *x11, t_pulldown *pd); /* Hides any menu that is still on the screen when it shouldn't */ -extern void check_pd_item(t_pulldown *pd, int nreturn, gmx_bool bStatus); +extern void check_pd_item(t_pulldown *pd, int nreturn, bool bStatus); /* Set the bChecked field in the pd item with return code * nreturn to bStatus. This function must always be called when * the bChecked flag has to changed. diff --git a/src/ngmx/rewind.bm b/src/programs/view/rewind.bm similarity index 100% rename from src/ngmx/rewind.bm rename to src/programs/view/rewind.bm diff --git a/src/ngmx/stop.bm b/src/programs/view/stop.bm similarity index 100% rename from src/ngmx/stop.bm rename to src/programs/view/stop.bm diff --git a/src/ngmx/stop_ani.bm b/src/programs/view/stop_ani.bm similarity index 100% rename from src/ngmx/stop_ani.bm rename to src/programs/view/stop_ani.bm diff --git a/src/ngmx/ngmx.cpp b/src/programs/view/view.cpp similarity index 86% rename from src/ngmx/ngmx.cpp rename to src/programs/view/view.cpp index 2aa3e0123e..b640e4dd3a 100644 --- a/src/ngmx/ngmx.cpp +++ b/src/programs/view/view.cpp @@ -36,9 +36,9 @@ #include #endif +#include #include #include - #include "sysstuff.h" #include "macros.h" #include "smalloc.h" @@ -46,17 +46,19 @@ #include "typedefs.h" #include "string2.h" #include "statutil.h" -#include "Xstuff.h" -#include "gromacs.bm" #include "copyrite.h" #include "confio.h" +#include "tpxio.h" + +#ifdef HAVE_X11 + +#include "Xstuff.h" +#include "gromacs.bm" +#include "xutil.h" #include "dialogs.h" #include "writeps.h" #include "molps.h" #include "nmol.h" -#include "tpxio.h" - -#include "gromacs/commandline/cmdlinemodulemanager.h" /* Forward declarations: I Don't want all that init shit here */ void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[], @@ -66,7 +68,7 @@ static void dump_it(t_manager *man) { t_psdata ps; - ps = ps_open("ngmx.ps", 0, 0, man->molw->wd.width, man->molw->wd.height); + ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height); ps_draw_mol(ps, man); ps_close(ps); } @@ -81,7 +83,7 @@ static void done_gmx(t_x11 *x11, t_gmx *gmx) } static void move_gmx(t_x11 *x11, t_gmx *gmx, int width, int height, - gmx_bool bSizePD) + bool bSizePD) { int y0, wl, hl; #ifdef DEBUG @@ -102,7 +104,7 @@ static void move_gmx(t_x11 *x11, t_gmx *gmx, int width, int height, XMoveWindow(x11->disp, gmx->logo->wd.self, (width-wl)/2, (height-y0-hl)/2); } -static gmx_bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx) +static bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx) { t_pulldown *pd; @@ -140,7 +142,7 @@ static gmx_bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx) break; case IDTERM: done_gmx(x11, gmx); - return TRUE; + return true; /* Edit Menu */ case IDEDITTOP: @@ -226,16 +228,16 @@ static gmx_bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx) default: break; } - return FALSE; + return false; } -static gmx_bool MainCallBack(t_x11 *x11, XEvent *event, Window w, void *data) +static bool MainCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_gmx *gmx; int nsel, width, height; - gmx_bool result; + bool result; - result = FALSE; + result = false; gmx = (t_gmx *)data; switch (event->type) { @@ -247,7 +249,7 @@ static gmx_bool MainCallBack(t_x11 *x11, XEvent *event, Window w, void *data) height = event->xconfigure.height; if ((width != gmx->wd->width) || (height != gmx->wd->height)) { - move_gmx(x11, gmx, width, height, TRUE); + move_gmx(x11, gmx, width, height, true); } break; case ClientMessage: @@ -260,11 +262,13 @@ static gmx_bool MainCallBack(t_x11 *x11, XEvent *event, Window w, void *data) } return result; } +//! HAVE_X11 +#endif -int gmx_ngmx(int argc, char *argv[]) +int gmx_view(int argc, char *argv[]) { const char *desc[] = { - "[TT]ngmx[tt] is the GROMACS trajectory viewer. This program reads a", + "[TT]view[tt] is the GROMACS trajectory viewer. This program reads a", "trajectory file, a run input file and an index file and plots a", "3D structure of your molecule on your standard X Window", "screen. No need for a high end graphics workstation, it even", @@ -285,7 +289,6 @@ int gmx_ngmx(int argc, char *argv[]) }; output_env_t oenv; - t_x11 *x11; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPX, NULL, NULL, ffREAD }, @@ -293,48 +296,48 @@ int gmx_ngmx(int argc, char *argv[]) }; #define NFILE asize(fnm) - if (!parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, - 0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv)) + if (parse_common_args(&argc, argv, PCA_CAN_TIME, NFILE, fnm, + 0, NULL, asize(desc), desc, asize(bugs), bugs, &oenv)) { - return 0; - } - - if ((x11 = GetX11(&argc, argv)) == NULL) - { - fprintf(stderr, "Can't connect to X Server.\n" - "Check your DISPLAY environment variable\n"); - exit(1); +#ifndef HAVE_X11 + fprintf(stderr, "Compiled without X-Windows - can not run viewer.\n"); +#else + t_x11 *x11; + + if ((x11 = GetX11(&argc, argv)) == NULL) + { + fprintf(stderr, "Can't connect to X Server.\n" + "Check your DISPLAY environment variable\n"); + } + else + { + init_gmx(x11, argv[0], NFILE, fnm, oenv); + x11->MainLoop(x11); + x11->CleanUp(x11); + } +#endif } - init_gmx(x11, argv[0], NFILE, fnm, oenv); - - x11->MainLoop(x11); - x11->CleanUp(x11); - return 0; } -int main(int argc, char *argv[]) -{ - return gmx::CommandLineModuleManager::runAsMainCMain(argc, argv, &gmx_ngmx); -} - +#ifdef HAVE_X11 static t_mentry FileMenu[] = { - { 0, IDEXPORT, FALSE, "Export..." }, - { 0, IDDUMPWIN, FALSE, "Print" }, - { 0, IDQUIT, FALSE, "Quit" } + { 0, IDEXPORT, false, "Export..." }, + { 0, IDDUMPWIN, false, "Print" }, + { 0, IDQUIT, false, "Quit" } }; static t_mentry DispMenu[] = { - { 0, IDFILTER, FALSE, "Filter..." }, - { 0, IDANIMATE, FALSE, "Animate" }, - { 0, IDLABELSOFF, FALSE, "Labels Off"}, - { 0, IDRESETVIEW, FALSE, "Reset View"}, - { 0, IDBONDOPTS, FALSE, "Options..."} + { 0, IDFILTER, false, "Filter..." }, + { 0, IDANIMATE, false, "Animate" }, + { 0, IDLABELSOFF, false, "Labels Off"}, + { 0, IDRESETVIEW, false, "Reset View"}, + { 0, IDBONDOPTS, false, "Options..."} }; static t_mentry HelpMenu[] = { - { 0, IDHELP, FALSE, "Help" }, - { 0, IDABOUT, FALSE, "About Gromacs..." } + { 0, IDHELP, false, "Help" }, + { 0, IDABOUT, false, "About Gromacs..." } }; static t_mentry *gmx_pd[] = { FileMenu, DispMenu, HelpMenu }; @@ -402,17 +405,17 @@ void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[], /* The order of creating windows is important here! */ /* Manager */ gmx->man = init_man(x11, gmx->wd->self, 0, 0, 1, 1, WHITE, BLACK, ePBC, box, oenv); - gmx->logo = init_logo(x11, gmx->wd->self, FALSE); + gmx->logo = init_logo(x11, gmx->wd->self, false); /* Now put all windows in the proper place */ - move_gmx(x11, gmx, w0, h0, FALSE); + move_gmx(x11, gmx, w0, h0, false); XMapWindow(x11->disp, gmx->wd->self); map_man(x11, gmx->man); /* Pull Down menu */ gmx->pd = init_pd(x11, gmx->wd->self, gmx->wd->width, - XTextHeight(x11->font), x11->fg, x11->bg, + x11->fg, x11->bg, MSIZE, gmx_pd_size, gmx_pd, MenuTitle); /* Dialogs & Filters */ @@ -425,7 +428,8 @@ void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[], /* Now do file shit */ set_file(x11, gmx->man, ftp2fn(efTRX, nfile, fnm), ftp2fn(efTPX, nfile, fnm)); - /*show_logo(x11,gmx->logo);*/ - ShowDlg(gmx->dlgs[edFilter]); } + +//! HAVE_X11 +#endif diff --git a/src/ngmx/g_logo.c b/src/programs/view/view.h similarity index 67% rename from src/ngmx/g_logo.c rename to src/programs/view/view.h index d60eada32f..7e1a06cceb 100644 --- a/src/ngmx/g_logo.c +++ b/src/programs/view/view.h @@ -6,10 +6,8 @@ * * GROningen MAchine for Chemical Simulations * - * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -30,29 +28,14 @@ * For more info, check our website at http://www.gromacs.org * * And Hey: - * Gyas ROwers Mature At Cryogenic Speed + * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon */ -#ifdef HAVE_CONFIG_H -#include -#endif -#include "logo.h" +#ifndef _view_h +#define _view_h int -main(int argc, char *argv[]) -{ - t_x11 *x11; - t_logo *logo; - - if ((x11 = GetX11(&argc, argv)) == NULL) - { - fprintf(stderr, "No X!\n"); - exit(1); - } - logo = init_logo(x11, x11->root, TRUE); - show_logo(x11, logo); - x11->MainLoop(x11); +gmx_view(int argc, char *argv[]); - x11->CleanUp(x11); - return 0; -} +#endif +/* _view_h */ diff --git a/src/ngmx/x11.c b/src/programs/view/x11.cpp similarity index 81% rename from src/ngmx/x11.c rename to src/programs/view/x11.cpp index b5b6997210..49534d1ff4 100644 --- a/src/ngmx/x11.c +++ b/src/programs/view/x11.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -36,13 +36,13 @@ #include #endif +#include #include "typedefs.h" -#include -#include #include "sysstuff.h" -#include #include "smalloc.h" #include "string2.h" +#include "Xstuff.h" +#include "x11.h" /* These colours will be mapped to black on a monochrome screen */ unsigned long BLACK, BLUE, GREEN, CYAN, RED, BROWN, GREY, DARKGREY; @@ -69,15 +69,15 @@ static XFontStruct *GetFont(FILE *err, Display *disp, char *name) "9x15", "6x13", "fixed" }; #define MAXNAMES (sizeof(fontnames)/sizeof(fontnames[0])) - int i; + unsigned int i; XFontStruct *font; int count; char **fontlist; - gmx_bool bFont = FALSE; + bool bFont = false; if (name) { - bFont = (gmx_bool) ((font = XLQF(err, disp, name)) != NULL); + bFont = ((font = XLQF(err, disp, name)) != NULL); } else { @@ -86,7 +86,7 @@ static XFontStruct *GetFont(FILE *err, Display *disp, char *name) for (i = 0; (!bFont && (i < MAXNAMES)); i++) { - bFont = (gmx_bool) ((font = XLQF(err, disp, fontnames[i])) != NULL); + bFont = ((font = XLQF(err, disp, fontnames[i])) != NULL); } if (!bFont) @@ -94,7 +94,7 @@ static XFontStruct *GetFont(FILE *err, Display *disp, char *name) fontlist = XListFonts(disp, "?", 1, &count); if (count != 0) { - bFont = (gmx_bool) ((font = XLQF(err, disp, fontlist[0])) != NULL); + bFont = ((font = XLQF(err, disp, fontlist[0])) != NULL); } } if (!bFont) @@ -142,33 +142,14 @@ static t_wlist *GetWList(t_x11 *x11, Window w) return curs; } -typedef struct { - Window w; - gmx_bool b; -} t_peek; - -static Bool TestEvent(Display *disp, XEvent *event, char *arg) -{ - t_peek *tp; - - fprintf(stderr, "TestEvent\n"); - tp = (t_peek *)arg; - if ((event->xany.window == tp->w) && (event->type == ConfigureNotify)) - { - tp->b = TRUE; - return True; - } - return False; -} - static void MainLoop(t_x11 *x11) { - gmx_bool bReturn; + bool bReturn; XEvent event; t_wlist *curs; Window w; - for (bReturn = FALSE; (!bReturn); ) + for (bReturn = false; (!bReturn); ) { if (x11->wlist) { @@ -177,7 +158,7 @@ static void MainLoop(t_x11 *x11) curs = GetWList(x11, w); if (!curs) { - bReturn = TRUE; + bReturn = true; } if (!bReturn) { @@ -310,53 +291,6 @@ static void CleanUp(t_x11 *x11) XCloseDisplay(x11->disp); } -static void Xrm(int *argc, char *argv[]) -{ - /* - static XrmOptionDescRec opTable[] = { - {"-background", "*background", - XrmoptionSepArg, (caddr_t) NULL}, - {"-bd", "*borderColor", - XrmoptionSepArg, (caddr_t) NULL}, - {"-bg", "*background", - XrmoptionSepArg, (caddr_t) NULL}, - {"-borderwidth", "*TopLevelShell.borderwidth", - XrmoptionSepArg, (caddr_t) NULL}, - {"-bordercolor", "*borderColor", - XrmoptionSepArg, (caddr_t) NULL}, - {"-bw", "*TopLevelShell.borderColor", - XrmoptionSepArg, (caddr_t) NULL}, - {"-display", ".display", - XrmoptionSepArg, (caddr_t) NULL}, - {"-fg", "*foreground", - XrmoptionSepArg, (caddr_t) NULL}, - {"-fn", "*font", - XrmoptionSepArg, (caddr_t) NULL}, - {"-font", "*font", - XrmoptionSepArg, (caddr_t) NULL}, - {"-foreground", "*foreground", - XrmoptionSepArg, (caddr_t) NULL}, - {"-geometry", ".TopLevelShell.geometry", - XrmoptionSepArg, (caddr_t) NULL}, - {"-iconic", ".TopLevelShell.iconic", - XrmoptionNoArg, (caddr_t) "on"}, - {"-name", ".name", - XrmoptionSepArg, (caddr_t) NULL}, - {"-reverse", "*reverseVideo", - XrmoptionNoArg, (caddr_t) "on"}, - {"-rv", "*reverseVideo", - XrmoptionNoArg, (caddr_t) "on"}, - {"-synchronous", ".synchronous", - XrmoptionNoArg, (caddr_t) "on"}, - {"-title", ".TopLevelShell.title", - XrmoptionSepArg, (caddr_t) NULL}, - {"-xrm", NULL, - XrmoptionSepArg, (caddr_t) NULL}, - }; - #define TABLELENGTH (sizeof(opTable)/sizeof(opTable[0])) - XrmInitialize();*/ -} - static void Flush(t_x11 *x11) { fflush(x11->console); @@ -381,7 +315,7 @@ t_x11 *GetX11(int *argc, char *argv[]) char *display; char *fontname; char *title, *FG = NULL, *BG = NULL; - gmx_bool bVerbose = FALSE; + bool bVerbose = false; int i; title = strdup(argv[0]); @@ -424,7 +358,7 @@ t_x11 *GetX11(int *argc, char *argv[]) title = strdup(argv[++i]); break; case 'v': - bVerbose = TRUE; + bVerbose = true; break; default: ARGV[ARGC++] = argv[i]; @@ -492,7 +426,7 @@ t_x11 *GetX11(int *argc, char *argv[]) if (x11->depth > 1) { /* Not B & W, Look what kind of screen we've got... */ - for (i = 0; (i < NCLASS); i++) + for (i = 0; (i < (int)NCLASS); i++) { if (!XMatchVisualInfo(x11->disp, x11->screen, x11->depth, v_class[i], &v_info)) diff --git a/src/ngmx/x11.h b/src/programs/view/x11.h similarity index 95% rename from src/ngmx/x11.h rename to src/programs/view/x11.h index b30c647083..2d7cf04928 100644 --- a/src/ngmx/x11.h +++ b/src/programs/view/x11.h @@ -47,12 +47,8 @@ extern unsigned long BLACK, BLUE, GREEN, CYAN, RED, BROWN, GREY, DARKGREY; extern unsigned long LIGHTBLUE, LIGHTGREY, LIGHTGREEN, LIGHTCYAN, LIGHTRED, VIOLET, YELLOW, WHITE; -typedef enum { - ecbOK -} ecbReturn; - #define CBARGS (struct t_x11 *x11, XEvent *event, Window w, void *data) -/* Callback function. Return FALSE to continue, TRUE to exit */ +/* Callback function. Return false to continue, true to exit */ typedef struct t_x11 { Display *disp; @@ -69,7 +65,7 @@ typedef struct t_x11 { void (*GetNamedColor)(struct t_x11 *x11, const char *name, unsigned long *col); void (*MainLoop)(struct t_x11 *x11); void (*RegisterCallback)(struct t_x11 *x11, Window w, Window Parent, - gmx_bool cb CBARGS, void *data); + bool cb CBARGS, void *data); void (*UnRegisterCallback)(struct t_x11 *x11, Window w); void (*SetInputMask)(struct t_x11 *x11, Window w, unsigned long mask); unsigned long (*GetInputMask)(struct t_x11 *x11, Window w); @@ -77,7 +73,7 @@ typedef struct t_x11 { void (*Flush)(struct t_x11 *x11); } t_x11; -typedef gmx_bool CallBack CBARGS; +typedef bool CallBack CBARGS; typedef struct t_wlist { Window w; /* The window itself */ @@ -126,7 +122,7 @@ t_x11 *GetX11(int *argc, char *argv[]); * events. It is up to the window to destroy itself. The MainLoop * routine exits when there are no more windows to manage, i.e. when * all routines have called UnRegisterCallback, OR when one Callback - * routine returns non-zero (TRUE). + * routine returns non-zero (true). * 5. Call x11->CleanUp. This closes the display, and frees all * memory allocated by x11 before. */ diff --git a/src/ngmx/xdlg.c b/src/programs/view/xdlg.cpp similarity index 94% rename from src/ngmx/xdlg.c rename to src/programs/view/xdlg.cpp index 6705135365..8d5e2cf2fe 100644 --- a/src/ngmx/xdlg.c +++ b/src/programs/view/xdlg.cpp @@ -85,7 +85,7 @@ t_dlgitem *FindWin(t_dlg *dlg, Window win) * Routines to manipulate items on a dialog box * ****************************/ -gmx_bool QueryDlgItemSize(t_dlg *dlg, t_id id, int *w, int *h) +bool QueryDlgItemSize(t_dlg *dlg, t_id id, int *w, int *h) { t_dlgitem *dlgitem; @@ -93,12 +93,12 @@ gmx_bool QueryDlgItemSize(t_dlg *dlg, t_id id, int *w, int *h) { *w = dlgitem->win.width; *h = dlgitem->win.height; - return TRUE; + return true; } - return FALSE; + return false; } -gmx_bool QueryDlgItemPos(t_dlg *dlg, t_id id, int *x0, int *y0) +bool QueryDlgItemPos(t_dlg *dlg, t_id id, int *x0, int *y0) { t_dlgitem *dlgitem; @@ -106,9 +106,9 @@ gmx_bool QueryDlgItemPos(t_dlg *dlg, t_id id, int *x0, int *y0) { *x0 = dlgitem->win.x; *y0 = dlgitem->win.y; - return TRUE; + return true; } - return FALSE; + return false; } int QueryDlgItemX(t_dlg *dlg, t_id id) @@ -155,7 +155,7 @@ int QueryDlgItemH(t_dlg *dlg, t_id id) return 0; } -gmx_bool SetDlgItemSize(t_dlg *dlg, t_id id, int w, int h) +bool SetDlgItemSize(t_dlg *dlg, t_id id, int w, int h) { t_dlgitem *dlgitem; #ifdef DEBUG @@ -201,12 +201,12 @@ gmx_bool SetDlgItemSize(t_dlg *dlg, t_id id, int w, int h) } } } - return TRUE; + return true; } - return FALSE; + return false; } -gmx_bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0) +bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0) { t_dlgitem *dlgitem; int old_x, old_y; @@ -242,9 +242,9 @@ gmx_bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0) } } } - return TRUE; + return true; } - return FALSE; + return false; } /***************************** @@ -253,7 +253,7 @@ gmx_bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0) * after dlg is exec'ed * ****************************/ -gmx_bool IsCBChecked(t_dlg *dlg, t_id id) +bool IsCBChecked(t_dlg *dlg, t_id id) { t_dlgitem *dlgitem; @@ -265,7 +265,7 @@ gmx_bool IsCBChecked(t_dlg *dlg, t_id id) } } - return FALSE; + return false; } t_id RBSelected(t_dlg *dlg, int gid) @@ -342,11 +342,11 @@ void ShowDlg(t_dlg *dlg) { PushMouse(dlg->x11->disp, dlgitem->win.self, dlgitem->win.width/2, dlgitem->win.height/2); - dlg->bPop = TRUE; + dlg->bPop = true; break; } } - dlg->bGrab = FALSE; + dlg->bGrab = false; } void HideDlg(t_dlg *dlg) @@ -362,21 +362,17 @@ void HideDlg(t_dlg *dlg) void NoHelp(t_dlg *dlg) { - char **lines = NULL; - - snew(lines, 2); - lines[0] = strdup("Error"); - lines[1] = strdup("No help for this item"); + const char *lines[2] = { + "Error", + "No help for this item" + }; MessageBox(dlg->x11, dlg->wDad, "No Help", 2, lines, MB_OK | MB_ICONSTOP | MB_APPLMODAL, NULL, NULL); - sfree(lines[0]); - sfree (lines[1]); - sfree(lines); } void HelpDlg(t_dlg *dlg) { - char *lines[] = { + const char *lines[] = { "Place the cursor over one of the items", "and press the F1 key to get more help.", "First press the OK button." @@ -388,7 +384,7 @@ void HelpDlg(t_dlg *dlg) void HelpNow(t_dlg *dlg, t_dlgitem *dlgitem) { char buf[80]; - gmx_bool bCont = TRUE; + bool bCont = true; int i, nlines = 0; char **lines = NULL; @@ -429,7 +425,8 @@ void HelpNow(t_dlg *dlg, t_dlgitem *dlgitem) } while (bCont); MessageBox(dlg->x11, dlg->wDad, "Help", - nlines, lines, MB_OK | MB_ICONINFORMATION | MB_APPLMODAL, NULL, NULL); + nlines, lines, + MB_OK | MB_ICONINFORMATION | MB_APPLMODAL, NULL, NULL); for (i = 0; (i < nlines); i++) { sfree(lines[i]); @@ -454,7 +451,7 @@ static void ExitDlg(t_dlg *dlg) if (dlg->bGrab) { XUngrabPointer(dlg->x11->disp, CurrentTime); - dlg->bGrab = FALSE; + dlg->bGrab = false; } HideDlg(dlg); if (dlg->flags & DLG_FREEONBUTTON) @@ -463,7 +460,7 @@ static void ExitDlg(t_dlg *dlg) } } -static gmx_bool DlgCB(t_x11 *x11, XEvent *event, Window w, void *data) +static bool DlgCB(t_x11 *x11, XEvent *event, Window w, void *data) { t_dlg *dlg = (t_dlg *)data; int i, nWndProc; @@ -526,14 +523,14 @@ static gmx_bool DlgCB(t_x11 *x11, XEvent *event, Window w, void *data) if (tid != -1) { t_dlgitem *dit = FindItem(dlg, tid); - dit->u.radiobutton.bSelect = FALSE; + dit->u.radiobutton.bSelect = false; ExposeWin(x11->disp, dit->win.self); } else { gmx_fatal(FARGS, "No RB Selected initially!\n"); } - dlgitem->u.radiobutton.bSelect = TRUE; + dlgitem->u.radiobutton.bSelect = true; ExposeWin(x11->disp, dlgitem->win.self); if (dlg->cb) { @@ -586,7 +583,7 @@ static gmx_bool DlgCB(t_x11 *x11, XEvent *event, Window w, void *data) break; } } - return FALSE; + return false; } /***************************** @@ -765,7 +762,7 @@ void FreeDlg(t_dlg *dlg) * ****************************/ t_dlg *CreateDlg(t_x11 *x11, Window Parent, const char *title, - int x0, int y0, int w, int h, int bw, unsigned long fg, unsigned long bg, + int x0, int y0, int w, int h, int bw, DlgCallback *cb, void *data) { t_dlg *dlg; @@ -831,7 +828,7 @@ t_dlg *CreateDlg(t_x11 *x11, Window Parent, const char *title, return dlg; } -void SetDlgSize(t_dlg *dlg, int w, int h, gmx_bool bAutoPosition) +void SetDlgSize(t_dlg *dlg, int w, int h, bool bAutoPosition) { if (bAutoPosition) { diff --git a/src/ngmx/xdlg.h b/src/programs/view/xdlg.h similarity index 86% rename from src/ngmx/xdlg.h rename to src/programs/view/xdlg.h index 11909233fa..c4aeb26011 100644 --- a/src/ngmx/xdlg.h +++ b/src/programs/view/xdlg.h @@ -36,7 +36,7 @@ #ifndef _xdlg_h #define _xdlg_h -#include +#include "xdlgitem.h" #define DLG_SHOW (1<<0) #define DLG_HIDE (1<<1) @@ -65,8 +65,8 @@ typedef struct { unsigned int xmax, ymax; /* Dimensions of parent window */ unsigned long flags; /* Flags for display */ unsigned long fg, bg; /* The colours */ - gmx_bool bPop; /* Should we pop the mouse back */ - gmx_bool bGrab; /* Have we grabbed the mouse ? */ + bool bPop; /* Should we pop the mouse back */ + bool bGrab; /* Have we grabbed the mouse ? */ int nitem; /* The number of items */ t_dlgitem **dlgitem; /* The array of item pointers */ DlgCallback *cb; /* User call back function */ @@ -80,7 +80,7 @@ typedef struct { * ****************************/ t_dlg *CreateDlg(t_x11 *x11, Window Parent, const char *title, - int x0, int y0, int w, int h, int bw, unsigned long fg, unsigned long bg, + int x0, int y0, int w, int h, int bw, DlgCallback *cb, void *data); /***************************** @@ -97,13 +97,13 @@ void AddDlgItems(t_dlg *dlg, int nitem, t_dlgitem *item[]); /***************************** * * Routines to manipulate items on a dialog box - * They return TRUE on succes, FALSE otherwise - * FALSE will mean most of the time, that item id was not found + * They return true on succes, false otherwise + * false will mean most of the time, that item id was not found * ****************************/ -gmx_bool QueryDlgItemSize(t_dlg *dlg, t_id id, int *w, int *h); +bool QueryDlgItemSize(t_dlg *dlg, t_id id, int *w, int *h); -gmx_bool QueryDlgItemPos(t_dlg *dlg, t_id id, int *x0, int *y0); +bool QueryDlgItemPos(t_dlg *dlg, t_id id, int *x0, int *y0); int QueryDlgItemX(t_dlg *dlg, t_id id); @@ -113,11 +113,11 @@ int QueryDlgItemW(t_dlg *dlg, t_id id); int QueryDlgItemH(t_dlg *dlg, t_id id); -gmx_bool SetDlgItemSize(t_dlg *dlg, t_id id, int w, int h); +bool SetDlgItemSize(t_dlg *dlg, t_id id, int w, int h); -gmx_bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0); +bool SetDlgItemPos(t_dlg *dlg, t_id id, int x0, int y0); -void SetDlgSize(t_dlg *dlg, int w, int h, gmx_bool bAutoPosition); +void SetDlgSize(t_dlg *dlg, int w, int h, bool bAutoPosition); /***************************** * @@ -125,7 +125,7 @@ void SetDlgSize(t_dlg *dlg, int w, int h, gmx_bool bAutoPosition); * after dlg is exec'ed * ****************************/ -gmx_bool IsCBChecked(t_dlg *dlg, t_id id); +bool IsCBChecked(t_dlg *dlg, t_id id); t_id RBSelected(t_dlg *dlg, int gid); diff --git a/src/ngmx/xdlghi.c b/src/programs/view/xdlghi.cpp similarity index 90% rename from src/ngmx/xdlghi.c rename to src/programs/view/xdlghi.cpp index b8193ae5d8..832ef437ed 100644 --- a/src/ngmx/xdlghi.c +++ b/src/programs/view/xdlghi.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -43,6 +43,7 @@ #include "sysstuff.h" #include "smalloc.h" #include "macros.h" +#include "xutil.h" #include "xdlghi.h" #include "fgrid.h" @@ -71,7 +72,7 @@ t_dlgitem **CreateRadioButtonGroup(t_x11 *x11, char *szTitle, dlgitem[i+1] = CreateRadioButton(x11, szRB[i], (i == nSelect), rb[i], GroupID, x, y, 0, 0, 0); y += dlgitem[i+1]->win.height+OFFS_Y; - w = max(w, dlgitem[i+1]->win.width); + w = std::max(w, dlgitem[i+1]->win.width); } for (i = 0; (i < nrb); i++) { @@ -98,7 +99,7 @@ t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle, t_id *ids; edlgitem edlg; char *name; - gmx_bool bBool; + bool bBool; Pixmap pm; int nlines, buflen; char *buf, **lines; @@ -135,7 +136,7 @@ t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle, break; case edlgPM: pm = va_arg(ap, Pixmap); - dlgitem[i+1] = CreatePixmap(x11, pm, ids[i], GroupID, x, y, 0, 0, 0); + dlgitem[i+1] = CreatePixmap(pm, ids[i], GroupID, x, y, 0, 0, 0); break; case edlgST: nlines = va_arg(ap, int); @@ -155,7 +156,7 @@ t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle, gmx_fatal(FARGS, "Invalid dlgitem type: %d\n", edlg); } y += dlgitem[i+1]->win.height+OFFS_Y; - w = max(w, dlgitem[i+1]->win.width); + w = std::max(w, dlgitem[i+1]->win.width); } va_end(ap); sfree(dlgitem[0]->u.groupbox.item); @@ -171,7 +172,7 @@ t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle, } static void AddDlgItemGroups(t_dlg *dlg, int gridx, int gridy, - t_dlgitemlist **grid, gmx_bool bAutoPosition) + t_dlgitemlist **grid, bool bAutoPosition) { t_dlgitemlist *item; int x1, y1, w1, h1; @@ -198,8 +199,8 @@ static void AddDlgItemGroups(t_dlg *dlg, int gridx, int gridy, AddDlgItems(dlg, item->nitem, item->list); dw = item->w; dh = item->h; - w = max(w, ((float) QueryDlgItemW(dlg, item->list[0]->ID))/dw); - h = max(h, ((float) QueryDlgItemH(dlg, item->list[0]->ID))/dh); + w = std::max(w, ((float) QueryDlgItemW(dlg, item->list[0]->ID))/dw); + h = std::max(h, ((float) QueryDlgItemH(dlg, item->list[0]->ID))/dh); } } } @@ -259,7 +260,7 @@ static void AddListItem(t_dlgitemlist *list, t_dlgitem *item) static void AddListFItem(t_x11 *x11, t_dlgitemlist *list, t_fitem *fitem, t_id GroupID, t_id *ID, - int x, int *y, int *w, gmx_bool bUseMon) + int x, int *y, int *w, bool bUseMon) { int i, iSel, slen; char buf[STRLEN]; @@ -292,14 +293,14 @@ static void AddListFItem(t_x11 *x11, t_dlgitemlist *list, CreateRadioButton(x11, fitem->name[i], (iSel == i), (*ID)++, GroupID, x, (*y), 0, 0, 0)); (*y) += list->list[list->nitem-1]->win.height+OFFS_Y; - (*w) = max((*w), list->list[list->nitem-1]->win.width); + (*w) = std::max((*w), list->list[list->nitem-1]->win.width); SetDlgitemOpts(list->list[list->nitem-1], bUseMon, fitem->set, fitem->get, fitem->help); } break; case edlgCB: { - gmx_bool bCheck; + bool bCheck; bCheck = gmx_strcasecmp(fitem->def, "TRUE") == 0; AddListItem(list, CreateCheckBox(x11, fitem->name[0], bCheck, @@ -308,7 +309,8 @@ static void AddListFItem(t_x11 *x11, t_dlgitemlist *list, } case edlgST: AddListItem(list, - CreateStaticText(x11, fitem->nname, fitem->name, (*ID)++, + CreateStaticText(x11, fitem->nname, + fitem->name, (*ID)++, GroupID, x, (*y), 0, 0, 0)); break; case edlgET: @@ -327,12 +329,12 @@ static void AddListFItem(t_x11 *x11, t_dlgitemlist *list, if (fitem->edlg != edlgRB) { (*y) += list->list[list->nitem-1]->win.height+OFFS_Y; - (*w) = max((*w), list->list[list->nitem-1]->win.width); + (*w) = std::max((*w), list->list[list->nitem-1]->win.width); } } static void AddListFGroup(t_x11 *x11, t_dlgitemlist **grid, - t_fgroup *fgroup, t_id *ID, gmx_bool bUseMon) + t_fgroup *fgroup, t_id *ID, bool bUseMon) { int i; t_id GroupID, *ids; @@ -351,7 +353,7 @@ static void AddListFGroup(t_x11 *x11, t_dlgitemlist **grid, AddListFItem(x11, item, fgroup->fitem[i], GroupID, ID, x, &y, &w, bUseMon); } - w = max(w, item->list[0]->win.width+4*OFFS_X); + w = std::max(w, item->list[0]->win.width+4*OFFS_X); sfree(item->list[0]->u.groupbox.item); sfree(item->list[0]->win.text); snew(ids, item->nitem); @@ -368,7 +370,7 @@ static void AddListFGroup(t_x11 *x11, t_dlgitemlist **grid, } static void AddListFSimple(t_x11 *x11, t_dlgitemlist **grid, - t_fsimple *fsimple, t_id *ID, gmx_bool bUseMon) + t_fsimple *fsimple, t_id *ID, bool bUseMon) { t_dlgitemlist *item; int x, y, w; @@ -383,8 +385,8 @@ static void AddListFSimple(t_x11 *x11, t_dlgitemlist **grid, } t_dlg *ReadDlg(t_x11 *x11, Window Parent, const char *title, - unsigned long fg, unsigned long bg, const char *infile, - int x0, int y0, gmx_bool bAutoPosition, gmx_bool bUseMon, + const char *infile, + int x0, int y0, bool bAutoPosition, bool bUseMon, DlgCallback *cb, void *data) { t_fgrid *fgrid; @@ -394,7 +396,7 @@ t_dlg *ReadDlg(t_x11 *x11, Window Parent, const char *title, t_id ID; fgrid = FGridFromFile(infile); - dlg = CreateDlg(x11, Parent, title, x0, y0, 0, 0, 0, fg, bg, cb, data); + dlg = CreateDlg(x11, Parent, title, x0, y0, 0, 0, 0, cb, data); grid = NewDlgitemList(fgrid->w, fgrid->h); ID = 0; diff --git a/src/ngmx/xdlghi.h b/src/programs/view/xdlghi.h similarity index 92% rename from src/ngmx/xdlghi.h rename to src/programs/view/xdlghi.h index 1bf5e18955..376ddc718d 100644 --- a/src/ngmx/xdlghi.h +++ b/src/programs/view/xdlghi.h @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -68,8 +68,8 @@ extern t_dlgitem **CreateDlgitemGroup(t_x11 *x11, const char *szTitle, */ extern t_dlg *ReadDlg(t_x11 *x11, Window Parent, const char *title, - unsigned long fg, unsigned long bg, const char *infile, - int x0, int y0, gmx_bool bAutoPosition, gmx_bool bUseMon, + const char *infile, + int x0, int y0, bool bAutoPosition, bool bUseMon, DlgCallback *cb, void *data); /* Read a dialog box from a template file */ diff --git a/src/ngmx/xdlgitem.c b/src/programs/view/xdlgitem.cpp similarity index 89% rename from src/ngmx/xdlgitem.c rename to src/programs/view/xdlgitem.cpp index eecc300fb3..a53ba68115 100644 --- a/src/ngmx/xdlgitem.c +++ b/src/programs/view/xdlgitem.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -50,7 +50,7 @@ #define BUFSIZE 16 -t_dlgitem *newitem(t_x11 *x11) +static t_dlgitem *newitem(void) { t_dlgitem *item; @@ -119,12 +119,12 @@ static int DefWndProc(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) } break; case EnterNotify: - dlgitem->win.bFocus = TRUE; + dlgitem->win.bFocus = true; ShowCaret(x11, dlgitem); /* LightBorder(x11->disp,dlgitem->win.self,x11->fg); */ break; case LeaveNotify: - dlgitem->win.bFocus = FALSE; + dlgitem->win.bFocus = false; HideCaret(x11, dlgitem); /* LightBorder(x11->disp,dlgitem->win.self,x11->bg); */ break; @@ -319,7 +319,7 @@ static int WndProcST(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) return ITEMOK; } -static gmx_bool insert(char *s, char c, int *pos) +static bool insert(char *s, char c, int *pos) { int i, sl; @@ -333,12 +333,12 @@ static gmx_bool insert(char *s, char c, int *pos) } s[*pos] = c; (*pos)++; - return TRUE; + return true; } - return FALSE; + return false; } -static gmx_bool my_backspace(char *s, int *pos) +static bool my_backspace(char *s, int *pos) { int i, sl; @@ -349,13 +349,13 @@ static gmx_bool my_backspace(char *s, int *pos) { s[i] = s[i+1]; } - (*pos) = max(0, (*pos)-1); - return TRUE; + (*pos) = std::max(0, (*pos)-1); + return true; } - return FALSE; + return false; } -static gmx_bool my_delete(char *s, int *pos) +static bool my_delete(char *s, int *pos) { int i, sl; @@ -366,19 +366,20 @@ static gmx_bool my_delete(char *s, int *pos) { s[i] = s[i+1]; } - return TRUE; + return true; } - return FALSE; + return false; } static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) { - t_edittext *et; - t_windata *win; - KeySym keysym; - char c[BUFSIZE+1], *bp; - char scrbuf[STRLEN]; - int i, xp, xtitle, ewidth; + t_edittext *et; + t_windata *win; + KeySym keysym; + char c[BUFSIZE+1], *bp; + char scrbuf[STRLEN]; + int i; + int xp, xtitle, ewidth; if (dlgitem->type != edlgET) { @@ -425,7 +426,7 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) bp[et->pos] = '\0'; } sfree(bp); - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; case KeyPress: /* Check for HelpKey */ @@ -442,7 +443,7 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) case XK_Delete: if (my_delete(et->buf, &(et->pos))) { - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; } else @@ -453,7 +454,7 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) case XK_BackSpace: if (my_backspace(et->buf, &(et->pos))) { - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; } else @@ -467,10 +468,10 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) case XK_Home: et->pos = 0; et->strbegin = 0; - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; case XK_End: - if (strlen(et->buf) <= et->buflen) + if (strlen(et->buf) <= (unsigned int)et->buflen) { et->pos = strlen(et->buf); } @@ -479,20 +480,21 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) et->pos = et->buflen; et->strbegin = strlen(et->buf)-et->buflen; } - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; case XK_Left: - et->pos = max(0, et->pos-1); - et->strbegin = min(et->strbegin, et->pos); - et->bChanged = TRUE; + et->pos = std::max(0, et->pos-1); + et->strbegin = std::min(et->strbegin, et->pos); + et->bChanged = true; return ETCHANGED; case XK_Right: - if ((et->pos < et->buflen) && (et->strbegin+et->buflen > strlen(et->buf))) + if ((et->pos < et->buflen) && + (et->strbegin+et->buflen > (int)strlen(et->buf))) { et->pos++; } - else if ((et->buflen < strlen(et->buf)) && - (et->strbegin < strlen(et->buf)-et->buflen)) + else if ((et->buflen < (int)strlen(et->buf)) && + (et->strbegin < (int)strlen(et->buf)-et->buflen)) { et->strbegin++; } @@ -500,14 +502,14 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) { break; } - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; default: if (keysym < 256) { if (insert(et->buf, c[0], &(et->pos))) { - et->bChanged = TRUE; + et->bChanged = true; return ETCHANGED; } } @@ -516,11 +518,11 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) } break; case LeaveNotify: - win->bFocus = FALSE; + win->bFocus = false; HideCaret(x11, dlgitem); if (et->bChanged) { - et->bChanged = FALSE; + et->bChanged = false; } break; default: @@ -544,13 +546,13 @@ static int WndProcET(t_x11 *x11, t_dlgitem *dlgitem, XEvent *event) * ****************************/ t_dlgitem *CreateButton(t_x11 *x11, - const char *szLab, gmx_bool bDef, t_id id, t_id groupid, + const char *szLab, bool bDef, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw) { t_dlgitem *dlgitem; char *lab; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = XTextHeight(x11->font)+2*OFFS_Y; @@ -580,13 +582,13 @@ t_dlgitem *CreateButton(t_x11 *x11, } t_dlgitem *CreateRadioButton(t_x11 *x11, - const char *szLab, gmx_bool bSet, t_id id, + const char *szLab, bool bSet, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw) { t_dlgitem *dlgitem; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = XTextHeight(x11->font)+OFFS_Y; @@ -612,7 +614,7 @@ t_dlgitem *CreateGroupBox(t_x11 *x11, { t_dlgitem *dlgitem; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = XTextHeight(x11->font)+OFFS_Y; @@ -635,13 +637,13 @@ t_dlgitem *CreateGroupBox(t_x11 *x11, } t_dlgitem *CreateCheckBox(t_x11 *x11, - const char *szLab, gmx_bool bCheckedInitial, t_id id, + const char *szLab, bool bCheckedInitial, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw) { t_dlgitem *dlgitem; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = XTextHeight(x11->font)+OFFS_Y; @@ -660,13 +662,12 @@ t_dlgitem *CreateCheckBox(t_x11 *x11, return dlgitem; } -t_dlgitem *CreatePixmap(t_x11 *x11, - Pixmap pm, t_id id, +t_dlgitem *CreatePixmap(Pixmap pm, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw) { t_dlgitem *dlgitem; - dlgitem = newitem(x11); + dlgitem = newitem(); InitWin(&(dlgitem->win), x0, y0, w, h, bw, NULL); dlgitem->ID = id; dlgitem->type = edlgPM; @@ -677,14 +678,14 @@ t_dlgitem *CreatePixmap(t_x11 *x11, } t_dlgitem *CreateStaticText(t_x11 *x11, - int nlines, char * const * lines, t_id id, + int nlines, const char * const *lines, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw) { t_dlgitem *dlgitem; int i; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = (XTextHeight(x11->font)+OFFS_Y)*nlines+OFFS_Y; @@ -693,7 +694,7 @@ t_dlgitem *CreateStaticText(t_x11 *x11, { for (i = 0; (i < nlines); i++) { - w = max(w, XTextWidth(x11->font, lines[i], strlen(lines[i]))); + w = std::max(w, XTextWidth(x11->font, lines[i], strlen(lines[i]))); } w += 2*OFFS_X; } @@ -720,7 +721,7 @@ t_dlgitem *CreateEditText(t_x11 *x11, t_dlgitem *dlgitem; t_edittext *et; - dlgitem = newitem(x11); + dlgitem = newitem(); if (h == 0) { h = XTextHeight(x11->font)+OFFS_Y; @@ -745,7 +746,7 @@ t_dlgitem *CreateEditText(t_x11 *x11, strcpy(et->buf, buf); et->buflen = screenbuf; et->strbegin = 0; - et->bChanged = FALSE; + et->bChanged = false; dlgitem->WndProc = WndProcET; return dlgitem; @@ -753,7 +754,7 @@ t_dlgitem *CreateEditText(t_x11 *x11, #define SC(src) (strlen(src) ? strdup(src) : NULL) -void SetDlgitemOpts(t_dlgitem *dlgitem, gmx_bool bUseMon, +void SetDlgitemOpts(t_dlgitem *dlgitem, bool bUseMon, char *set, char *get, char *help) { dlgitem->bUseMon = bUseMon; diff --git a/src/ngmx/xdlgitem.h b/src/programs/view/xdlgitem.h similarity index 84% rename from src/ngmx/xdlgitem.h rename to src/programs/view/xdlgitem.h index a1076045c9..e4f011e762 100644 --- a/src/ngmx/xdlgitem.h +++ b/src/programs/view/xdlgitem.h @@ -37,10 +37,13 @@ #define _xdlgitem_h #include -#include -#include -#include +#include "Xstuff.h" +#include "xutil.h" +#include "x11.h" +typedef enum { + edlgBN, edlgRB, edlgGB, edlgCB, edlgPM, edlgST, edlgET, edlgNR +} edlgitem; #define XCARET 2 enum { @@ -50,15 +53,15 @@ enum { typedef int t_id; typedef struct { - gmx_bool bDefault; /* This is the default button */ + bool bDefault; /* This is the default button */ } t_button; typedef struct { - gmx_bool bSelect; /* Is this rb selected ? */ + bool bSelect; /* Is this rb selected ? */ } t_radiobutton; typedef struct { - gmx_bool bChecked; /* Is this cb checked ? */ + bool bChecked; /* Is this cb checked ? */ } t_checkbox; typedef struct { @@ -72,10 +75,10 @@ typedef struct { typedef struct { int buflen, strbegin; /* Length of the screen buf and begin of string */ - int pos /*,len*/; /* Current length of the string and pos of caret */ + int pos; /* Current length of the string and pos of caret */ /* Pos is relative to strbegin, and is the pos */ /* in the window. */ - gmx_bool bChanged; + bool bChanged; char *buf; } t_edittext; @@ -84,14 +87,11 @@ typedef struct { t_id *item; } t_groupbox; -typedef enum { - edlgBN, edlgRB, edlgGB, edlgCB, edlgPM, edlgST, edlgET, edlgNR -} edlgitem; typedef struct t_dlgitem { t_windata win; t_id ID, GroupID; - gmx_bool bUseMon; + bool bUseMon; char *set, *get, *help; edlgitem type; int (*WndProc)(t_x11 *x11, struct t_dlgitem *dlgitem, XEvent *event); @@ -120,12 +120,12 @@ typedef struct t_dlgitem { * on the dlg box, and if wished resize them. * ****************************/ -extern t_dlgitem *CreateButton(t_x11 *x11, const char *szLab, gmx_bool bDef, +extern t_dlgitem *CreateButton(t_x11 *x11, const char *szLab, bool bDef, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); extern t_dlgitem *CreateRadioButton(t_x11 *x11, - const char *szLab, gmx_bool bSet, t_id id, + const char *szLab, bool bSet, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); @@ -134,23 +134,23 @@ extern t_dlgitem *CreateGroupBox(t_x11 *x11, const char *szLab, t_id id, int x0, int y0, int w, int h, int bw); extern t_dlgitem *CreateCheckBox(t_x11 *x11, const char *szLab, - gmx_bool bCheckedInitial, + bool bCheckedInitial, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); -extern t_dlgitem *CreatePixmap(t_x11 *x11, Pixmap pm, t_id id, t_id groupid, +extern t_dlgitem *CreatePixmap(Pixmap pm, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); extern t_dlgitem *CreateStaticText(t_x11 *x11, - int nlines, char * const * lines, t_id id, - t_id groupid, + int nlines, const char * const *lines, + t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); extern t_dlgitem *CreateEditText(t_x11 *x11, const char *title, int screenbuf, char *buf, t_id id, t_id groupid, int x0, int y0, int w, int h, int bw); -extern void SetDlgitemOpts(t_dlgitem *dlgitem, gmx_bool bUseMon, +extern void SetDlgitemOpts(t_dlgitem *dlgitem, bool bUseMon, char *set, char *get, char *help); #endif /* _xdlgitem_h */ diff --git a/src/ngmx/xmb.c b/src/programs/view/xmb.cpp similarity index 93% rename from src/ngmx/xmb.c rename to src/programs/view/xmb.cpp index a840367edf..643b2605bf 100644 --- a/src/ngmx/xmb.c +++ b/src/programs/view/xmb.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -44,6 +44,7 @@ #include "macros.h" #include "Xstuff.h" #include "x11.h" +#include "xutil.h" #include "xdlg.h" #include "xmb.h" #include "gmx_fatal.h" @@ -72,7 +73,7 @@ void SetIcon(unsigned char *bits, int w, int h, unsigned long fg, unsigned long } t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, - int nlines, char ** lines, unsigned long Flags, + int nlines, const char * const * lines, unsigned long Flags, DlgCallback *cb, void *data) { t_dlg *dlg; @@ -132,12 +133,12 @@ t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, } } - dlg = CreateDlg(x11, Parent, title, 0, 0, 0, 0, 3, x11->fg, bg, cb, data); + dlg = CreateDlg(x11, Parent, title, 0, 0, 0, 0, 3, cb, data); x = 2*OFFS_X; if (nicon > 0) { AddDlgItem(dlg, CreatePixmap - (x11, XCreatePixmapFromBitmapData + (XCreatePixmapFromBitmapData (x11->disp, dlg->win.self, icon_bits, icon_width, icon_height, icon_fg, icon_bg, x11->depth), ID_ICON, ID_BOX, 2*OFFS_X, 2*OFFS_Y, icon_width, icon_height, 0)); @@ -160,7 +161,10 @@ t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, { SetDlgItemPos(dlg, ID_ICON, 2*OFFS_X, 2*OFFS_Y+(y-yi)/2); } - y = max(y, yi); + if (yi > y) + { + y = yi; + } } x += QueryDlgItemW(dlg, ID_TEXT)+2*OFFS_X; y += 2*OFFS_Y; @@ -177,7 +181,7 @@ t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, } #define CB(name, butx, id) AddDlgItem(dlg, CreateButton(x11, name, \ - TRUE, id, ID_BOX, \ + true, id, ID_BOX, \ butx, y, width, 0, 0)) if (Flags & MB_OK) { @@ -197,7 +201,7 @@ t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, } SetDlgSize(dlg, x, y+2*OFFS_Y+ - QueryDlgItemH(dlg, (Flags & MB_OK) ? MB_OK : MB_YES), TRUE); + QueryDlgItemH(dlg, (Flags & MB_OK) ? MB_OK : MB_YES), true); if (Flags & MB_SYSTEMMODAL) { diff --git a/src/ngmx/xmb.h b/src/programs/view/xmb.h similarity index 95% rename from src/ngmx/xmb.h rename to src/programs/view/xmb.h index da8b4c4caf..c470c85e6c 100644 --- a/src/ngmx/xmb.h +++ b/src/programs/view/xmb.h @@ -36,7 +36,7 @@ #ifndef _xmb_h #define _xmb_h -#include +#include "x11.h" #define MB_OK 1 #define MB_CANCEL (1<<1) @@ -53,7 +53,7 @@ #define MB_DONTSHOW (1<<22) t_dlg *MessageBox(t_x11 *x11, Window Parent, const char *title, - int nlines, char ** lines, unsigned long Flags, + int nlines, const char * const *lines, unsigned long Flags, DlgCallback *cb, void *data); #endif /* _xmb_h */ diff --git a/src/ngmx/xutil.c b/src/programs/view/xutil.cpp similarity index 96% rename from src/ngmx/xutil.c rename to src/programs/view/xutil.cpp index da23521f55..8da40ba688 100644 --- a/src/ngmx/xutil.c +++ b/src/programs/view/xutil.cpp @@ -9,7 +9,7 @@ * VERSION 3.2.0 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2004, The GROMACS development team, + * Copyright (c) 2001-2013, The GROMACS development team, * check out http://www.gromacs.org for more information. * This program is free software; you can redistribute it and/or @@ -39,19 +39,19 @@ #include #include #include -#include -#include #include "smalloc.h" #include "typedefs.h" #include "string2.h" +#include "xutil.h" +#include "Xstuff.h" int CheckWin(Window win, const char *file, int line) { typedef struct { - int n; + Window n; const char *s; } t_winerr; - t_winerr winerr[] = { + t_winerr winerr[] = { { BadAlloc, "Bad Alloc" }, { BadColor, "Bad Color" }, { BadCursor, "Bad Cursor"}, @@ -61,7 +61,7 @@ int CheckWin(Window win, const char *file, int line) { BadWindow, "Bad Window"} }; #define NERR (sizeof(winerr)/sizeof(winerr[0])) - int i; + unsigned int i; for (i = 0; (i < NERR); i++) { @@ -162,7 +162,7 @@ void InitWin(t_windata *win, int x0, int y0, int w, int h, int bw, const char *t win->width = w; win->height = h; win->bwidth = bw; - win->bFocus = FALSE; + win->bFocus = false; win->cursor = 0; if (text) { @@ -295,7 +295,7 @@ void PopMouse(Display *disp) sfree(old); } -gmx_bool HelpPressed(XEvent *event) +bool HelpPressed(XEvent *event) { #define BUFSIZE 24 char buf[BUFSIZE+1]; @@ -307,12 +307,12 @@ gmx_bool HelpPressed(XEvent *event) return (keysym == XK_F1); } -gmx_bool GrabOK(FILE *out, int err) +bool GrabOK(FILE *out, int err) { switch (err) { case GrabSuccess: - return TRUE; + return true; case GrabNotViewable: fprintf(out, "GrabNotViewable\n"); break; case AlreadyGrabbed: @@ -324,5 +324,5 @@ gmx_bool GrabOK(FILE *out, int err) default: break; } - return FALSE; + return false; } diff --git a/src/ngmx/xutil.h b/src/programs/view/xutil.h similarity index 93% rename from src/ngmx/xutil.h rename to src/programs/view/xutil.h index a251030415..b69452d9a2 100644 --- a/src/ngmx/xutil.h +++ b/src/programs/view/xutil.h @@ -48,7 +48,7 @@ typedef struct { Window self, Parent; unsigned long color; char *text; - gmx_bool bFocus; + bool bFocus; int x, y, width, height, bwidth; Cursor cursor; } t_windata; @@ -87,11 +87,11 @@ extern void PushMouse(Display *disp, Window dest, int x, int y); extern void PopMouse(Display *disp); -extern gmx_bool HelpPressed(XEvent *event); +extern bool HelpPressed(XEvent *event); -extern gmx_bool GrabOK(FILE *out, int err); -/* Return TRUE if grab succeeded, prints a message to out - * and returns FALSE otherwise. +extern bool GrabOK(FILE *out, int err); +/* Return true if grab succeeded, prints a message to out + * and returns false otherwise. */ #endif /* _xutil_h */ -- 2.22.0