Moved ngmx to C++, renamed it to view.
[alexxy/gromacs.git] / src / programs / view / view.cpp
similarity index 86%
rename from src/ngmx/ngmx.cpp
rename to src/programs/view/view.cpp
index 2aa3e0123ee131755312928aa43971b3d1a1ed72..b640e4dd3abc9f8f9ad5bad9bec7eca8b3b5f3a0 100644 (file)
@@ -36,9 +36,9 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
 #include <ctype.h>
 #include <string.h>
-
 #include "sysstuff.h"
 #include "macros.h"
 #include "smalloc.h"
 #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