Revision: 75487
          http://sourceforge.net/p/brlcad/code/75487
Author:   starseeker
Date:     2020-04-21 12:23:34 +0000 (Tue, 21 Apr 2020)
Log Message:
-----------
Put the open calls in the calltree for dm, fix memory setup in most of the dm 
backends (had only done ogl and X...)

Modified Paths:
--------------
    brlcad/branches/dm-fb-merge/include/dm.h
    brlcad/branches/dm-fb-merge/src/libdm/X/dm-X.c
    brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c
    brlcad/branches/dm-fb-merge/src/libdm/glx/dm-ogl.c
    brlcad/branches/dm-fb-merge/src/libdm/include/calltable.h
    brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c
    brlcad/branches/dm-fb-merge/src/libdm/options.c
    brlcad/branches/dm-fb-merge/src/libdm/osgl/dm-osgl.cpp
    brlcad/branches/dm-fb-merge/src/libdm/plot/dm-plot.c
    brlcad/branches/dm-fb-merge/src/libdm/postscript/dm-ps.c
    brlcad/branches/dm-fb-merge/src/libdm/qt/dm-qt.cpp
    brlcad/branches/dm-fb-merge/src/libdm/tk/dm-tk.c
    brlcad/branches/dm-fb-merge/src/libdm/txt/dm-txt.c
    brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c
    brlcad/branches/dm-fb-merge/src/mged/attach.c

Modified: brlcad/branches/dm-fb-merge/include/dm.h
===================================================================
--- brlcad/branches/dm-fb-merge/include/dm.h    2020-04-21 11:00:00 UTC (rev 
75486)
+++ brlcad/branches/dm-fb-merge/include/dm.h    2020-04-21 12:23:34 UTC (rev 
75487)
@@ -85,7 +85,9 @@
     const struct dm * const p;
 };
 
-
+/* TODO - after plugins are established, these should be movable to
+ * the private subheaders */
+DM_EXPORT extern struct dm dm_null;
 DM_EXPORT extern struct dm dm_ogl;
 DM_EXPORT extern struct dm dm_plot;
 DM_EXPORT extern struct dm dm_ps;
@@ -117,7 +119,7 @@
                                  int use_aspect);
 DM_EXPORT extern void dm_fogHint(struct dm *dmp,
                                 int fastfog);
-DM_EXPORT extern int dm_processOptions(struct dm *dmp, struct bu_vls 
*init_proc_vls, int argc, char **argv);
+DM_EXPORT extern int dm_processOptions(struct dm *dmp, struct bu_vls 
*init_proc_vls, int argc, const char **argv);
 DM_EXPORT extern int dm_limit(int i);
 DM_EXPORT extern int dm_unlimit(int i);
 DM_EXPORT extern fastf_t dm_wrap(fastf_t f);

Modified: brlcad/branches/dm-fb-merge/src/libdm/X/dm-X.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/X/dm-X.c      2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/X/dm-X.c      2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -421,8 +421,9 @@
  *
  */
 struct dm *
-X_open_dm(Tcl_Interp *interp, int argc, char **argv)
+X_open(void *vinterp, int argc, const char **argv)
 {
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
     static int count = 0;
     int make_square = -1;
     XGCValues gcv;
@@ -530,7 +531,7 @@
     }
 
     if (pubvars->xtkwin == NULL) {
-       bu_log("X_open_dm: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
+       bu_log("X_open: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
        (void)X_close(dmp);
        return DM_NULL;
     }
@@ -621,7 +622,7 @@
 
     /* must do this before MakeExist */
     if ((pubvars->vip = X_choose_visual(dmp)) == NULL) {
-       bu_log("X_open_dm: Can't get an appropriate visual.\n");
+       bu_log("X_open: Can't get an appropriate visual.\n");
        (void)X_close(dmp);
        return DM_NULL;
     }
@@ -708,7 +709,7 @@
            if (BU_STR_EQUAL(list->name, "dial+buttons")) {
                if ((dev = XOpenDevice(pubvars->dpy,
                                       list->id)) == (XDevice *)NULL) {
-                   bu_log("X_open_dm: Couldn't open the dials+buttons\n");
+                   bu_log("X_open: Couldn't open the dials+buttons\n");
                    goto Done;
                }
 
@@ -2048,6 +2049,7 @@
 
 /* Display Manager package interface */
 struct dm_impl dm_X_impl = {
+    X_open,
     X_close,
     X_drawBegin,
     X_drawEnd,

Modified: brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c  2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c  2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -38,6 +38,7 @@
 #include "./include/private.h"
 #include "./null/dm-Null.h"
 
+extern struct dm *null_open(void *interp, int argc, const char *argv[]);
 extern struct dm *plot_open(void *interp, int argc, const char *argv[]);
 extern struct dm *ps_open(void *interp, int argc, const char *argv[]);
 extern struct dm *txt_open(void *interp, int argc, const char **argv);
@@ -44,12 +45,12 @@
 
 #ifdef DM_X
 #  if defined(HAVE_TK)
-extern struct dm *X_open_dm(void *interp, int argc, const char **argv);
+extern struct dm *X_open(void *interp, int argc, const char **argv);
 #  endif
 #endif /* DM_X */
 
 #ifdef DM_TK
-extern struct dm *tk_open_dm(void *interp, int argc, const char **argv);
+extern struct dm *tk_open(void *interp, int argc, const char **argv);
 #endif /* DM_TK */
 
 #ifdef DM_OGL
@@ -76,22 +77,6 @@
 extern struct dm *qt_open(void *interp, int argc, const char **argv);
 #endif /* DM_QT */
 
-HIDDEN struct dm *
-null_dm_open(void *interp, int argc, const char *argv[])
-{
-    struct dm *dmp = DM_NULL;
-
-    if (argc < 0 || !argv)
-       return DM_NULL;
-
-    BU_ALLOC(dmp, struct dm);
-
-    *dmp = dm_null;
-    dmp->i->dm_interp = interp;
-
-    return dmp;
-}
-
 /* TODO - in a plugin system this function will be provided for all acive
  * backends via bu_dlsym and loaded into a lookup system mapped to the dm_name
  * string provided with the plugin. */
@@ -99,7 +84,7 @@
 dm_open(void *interp, const char *type, int argc, const char *argv[])
 {
     if (BU_STR_EQUIV(type, "null")) {
-       return null_dm_open(interp, argc, argv);
+       return null_open(interp, argc, argv);
     }
     if (BU_STR_EQUIV(type, "txt")) {
        return txt_open(interp, argc, argv);
@@ -118,12 +103,12 @@
     }
 #if defined(DM_X) && defined(HAVE_TK)
     if (BU_STR_EQUIV(type, "X")) {
-       return X_open_dm(interp, argc, argv);
+       return X_open(interp, argc, argv);
     }
 #endif
 #if defined(DM_TK)
     if (BU_STR_EQUIV(type, "tk")) {
-       return tk_open_dm(interp, argc, argv);
+       return tk_open(interp, argc, argv);
     }
 #endif
 #if defined(DM_OGL) && defined(HAVE_TK)

Modified: brlcad/branches/dm-fb-merge/src/libdm/glx/dm-ogl.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/glx/dm-ogl.c  2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/glx/dm-ogl.c  2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -104,7 +104,7 @@
 #define IRBOUND 4095.9 /* Max magnification in Rot matrix */
 #define PLOTBOUND 1000.0       /* Max magnification in Rot matrix */
 
-struct dm *ogl_open(Tcl_Interp *vinterp, int argc, char **argv);
+struct dm *ogl_open(void *vinterp, int argc, const char **argv);
 HIDDEN int ogl_close(struct dm *dmp);
 HIDDEN int ogl_drawBegin(struct dm *dmp);
 HIDDEN int ogl_drawEnd(struct dm *dmp);
@@ -658,7 +658,7 @@
  *
  */
 struct dm *
-ogl_open(Tcl_Interp *vinterp, int argc, char **argv)
+ogl_open(void *vinterp, int argc, const char **argv)
 {
     static int count = 0;
     GLfloat backgnd[4];
@@ -2907,6 +2907,7 @@
 }
 
 struct dm_impl dm_ogl_impl = {
+    ogl_open,
     ogl_close,
     ogl_drawBegin,
     ogl_drawEnd,

Modified: brlcad/branches/dm-fb-merge/src/libdm/include/calltable.h
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/include/calltable.h   2020-04-21 
11:00:00 UTC (rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/include/calltable.h   2020-04-21 
12:23:34 UTC (rev 75487)
@@ -55,6 +55,9 @@
  * Tk information...
  */
 struct dm_impl {
+    struct dm *(*dm_open)(void *interp, int argc, const char *argv[]);
+    // TODO - dm_open currently does both new windows and existing windows - 
rework
+    // to operate like framebuffer API and separate them.
     int (*dm_close)(struct dm *dmp);
     int (*dm_drawBegin)(struct dm *dmp);       /**< @brief formerly dmr_prolog 
*/
     int (*dm_drawEnd)(struct dm *dmp);         /**< @brief formerly dmr_epilog 
*/

Modified: brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c        2020-04-21 
11:00:00 UTC (rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c        2020-04-21 
12:23:34 UTC (rev 75487)
@@ -33,10 +33,28 @@
 #include "../null/dm-Null.h"
 #include "../include/private.h"
 
+struct dm *
+null_open(void *interp, int argc, const char *argv[])
+{
+    struct dm *dmp = DM_NULL;
 
+    if (argc < 0 || !argv)
+        return DM_NULL;
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
+
+    *dmp->i = *dm_null.i;
+    dmp->i->dm_interp = interp;
+
+    return dmp;
+}
+
 int
-null_close(struct dm *UNUSED(dmp))
+null_close(struct dm *dmp)
 {
+    bu_free(dmp->i, "dmp impl");
+    bu_free(dmp, "dmp");
     return 0;
 }
 
@@ -285,6 +303,7 @@
 
 
 struct dm_impl dm_null_impl = {
+    null_open,
     null_close,
     null_drawBegin,
     null_drawEnd,

Modified: brlcad/branches/dm-fb-merge/src/libdm/options.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/options.c     2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/options.c     2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -30,18 +30,21 @@
 #include "tcl.h"
 
 #include "bu/getopt.h"
+#include "bu/str.h"
 #include "vmath.h"
 #include "dm.h"
 #include "./include/private.h"
 
 int
-dm_processOptions(struct dm *dmp, struct bu_vls *init_proc_vls, int argc, char 
**argv)
+dm_processOptions(struct dm *dmp, struct bu_vls *init_proc_vls, int argc, 
const char **argv)
 {
     int c;
 
+    char **av = bu_argv_dup(argc, argv);
+
     bu_optind = 0;      /* re-init bu_getopt */
     bu_opterr = 0;
-    while ((c = bu_getopt(argc, argv, "N:S:W:s:d:i:n:t:")) != -1) {
+    while ((c = bu_getopt(argc, av, "N:S:W:s:d:i:n:t:")) != -1) {
        switch (c) {
            case 'N':
                dmp->i->dm_height = atoi(bu_optarg);
@@ -74,6 +77,8 @@
        }
     }
 
+    bu_argv_free(argc, av);
+
     return bu_optind;
 }
 

Modified: brlcad/branches/dm-fb-merge/src/libdm/osgl/dm-osgl.cpp
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/osgl/dm-osgl.cpp      2020-04-21 
11:00:00 UTC (rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/osgl/dm-osgl.cpp      2020-04-21 
12:23:34 UTC (rev 75487)
@@ -370,6 +370,7 @@
     bu_vls_free(&dmp->i->dm_dName);
     bu_free(dmp->i->dm_vars.priv_vars, "osgl_close: osgl_vars");
     bu_free(dmp->i->dm_vars.pub_vars, "osgl_close: dm_osglvars");
+    bu_free(dmp->i, "osgl_close: dmp impl");
     bu_free(dmp, "osgl_close: dmp");
 
     return TCL_OK;
@@ -400,8 +401,9 @@
     }
 
     BU_GET(dmp, struct dm);
+    BU_GET(dmp->i, struct dm_impl);
 
-    *dmp = dm_osgl; /* struct copy */
+    *dmp->i = *dm_osgl.i; /* struct copy */
     dmp->i->dm_interp = interp;
     dmp->i->dm_lineWidth = 1;
     dmp->i->dm_light = 1;
@@ -2540,6 +2542,7 @@
 }
 
 struct dm_impl dm_osgl_impl = {
+    osgl_open,
     osgl_close,
     osgl_drawBegin,
     osgl_drawEnd,

Modified: brlcad/branches/dm-fb-merge/src/libdm/plot/dm-plot.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/plot/dm-plot.c        2020-04-21 
11:00:00 UTC (rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/plot/dm-plot.c        2020-04-21 
12:23:34 UTC (rev 75487)
@@ -63,6 +63,134 @@
 
 struct plot_vars head_plot_vars;
 
+static int plot_close(struct dm *dmp);
+
+/*
+ * Fire up the display manager, and the display processor.
+ *
+ */
+struct dm *
+plot_open(void *vinterp, int argc, const char *argv[])
+{
+    static int count = 0;
+    struct dm *dmp;
+    Tcl_Obj *obj;
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
+
+    *dmp->i = *dm_plot.i; /* struct copy */
+    dmp->i->dm_interp = interp;
+
+    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct plot_vars);
+
+    struct plot_vars *privars = (struct plot_vars *)dmp->i->dm_vars.priv_vars;
+
+    obj = Tcl_GetObjResult(interp);
+    if (Tcl_IsShared(obj))
+       obj = Tcl_DuplicateObj(obj);
+
+    bu_vls_init(&privars->vls);
+    bu_vls_init(&dmp->i->dm_pathName);
+    bu_vls_init(&dmp->i->dm_tkName);
+    bu_vls_printf(&dmp->i->dm_pathName, ".dm_plot%d", count++);
+    bu_vls_printf(&dmp->i->dm_tkName, "dm_plot%d", count++);
+
+    /* skip first argument */
+    --argc;
+    ++argv;
+
+    /* Process any options */
+    privars->is_3D = 1;          /* 3-D w/color, by default */
+    while (argv[0] != (char *)0 && argv[0][0] == '-') {
+       switch (argv[0][1]) {
+           case '3':
+               break;
+           case '2':
+               privars->is_3D = 0;             /* 2-D, for portability */
+               break;
+           case 'g':
+               privars->grid = 1;
+               break;
+           case 'f':
+               privars->floating = 1;
+               break;
+           case 'z':
+           case 'Z':
+               /* Enable Z clipping */
+               Tcl_AppendStringsToObj(obj, "Clipped in Z to viewing cube\n", 
(char *)NULL);
+
+               dmp->i->dm_zclip = 1;
+               break;
+           default:
+               Tcl_AppendStringsToObj(obj, "bad PLOT option ", argv[0], "\n", 
(char *)NULL);
+               (void)plot_close(dmp);
+
+               Tcl_SetObjResult(interp, obj);
+               return DM_NULL;
+       }
+       argv++;
+    }
+    if (argv[0] == (char *)0) {
+       Tcl_AppendStringsToObj(obj, "no filename or filter specified\n", (char 
*)NULL);
+       (void)plot_close(dmp);
+
+       Tcl_SetObjResult(interp, obj);
+       return DM_NULL;
+    }
+
+    if (argv[0][0] == '|') {
+       bu_vls_strcpy(&privars->vls, &argv[0][1]);
+       while ((++argv)[0] != (char *)0) {
+           bu_vls_strcat(&privars->vls, " ");
+           bu_vls_strcat(&privars->vls, argv[0]);
+       }
+
+       privars->is_pipe = 1;
+    } else {
+       bu_vls_strcpy(&privars->vls, argv[0]);
+    }
+
+    if (privars->is_pipe) {
+       if ((privars->up_fp = popen(bu_vls_addr(&privars->vls), "w")) == NULL) {
+           perror(bu_vls_addr(&privars->vls));
+           (void)plot_close(dmp);
+           Tcl_SetObjResult(interp, obj);
+           return DM_NULL;
+       }
+
+       Tcl_AppendStringsToObj(obj, "piped to ",
+                              bu_vls_addr(&privars->vls),
+                              "\n", (char *)NULL);
+    } else {
+       if ((privars->up_fp = fopen(bu_vls_addr(&privars->vls), "wb")) == NULL) 
{
+           perror(bu_vls_addr(&privars->vls));
+           (void)plot_close(dmp);
+           Tcl_SetObjResult(interp, obj);
+           return DM_NULL;
+       }
+
+       Tcl_AppendStringsToObj(obj, "plot stored in ",
+                              bu_vls_addr(&privars->vls),
+                              "\n", (char *)NULL);
+    }
+
+    setbuf(privars->up_fp, privars->ttybuf);
+
+    if (privars->is_3D)
+       pl_3space(privars->up_fp, -2048, -2048, -2048, 2048, 2048, 2048);
+    else
+       pl_space(privars->up_fp, -2048, -2048, 2048, 2048);
+
+    MAT_IDN(privars->mod_mat);
+    MAT_IDN(privars->disp_mat);
+    MAT_COPY(privars->plotmat, privars->mod_mat);
+
+    Tcl_SetObjResult(interp, obj);
+    return dmp;
+}
+
 /**
  * Gracefully release the display.
  */
@@ -83,6 +211,7 @@
 
     bu_vls_free(&dmp->i->dm_pathName);
     bu_free((void *)dmp->i->dm_vars.priv_vars, "plot_close: plot_vars");
+    bu_free((void *)dmp->i, "plot_close: dmp impl");
     bu_free((void *)dmp, "plot_close: dmp");
 
     return BRLCAD_OK;
@@ -530,6 +659,7 @@
 
 
 struct dm_impl dm_plot_impl = {
+    plot_open,
     plot_close,
     plot_drawBegin,
     plot_drawEnd,
@@ -629,132 +759,7 @@
 }
 #endif
 
-/*
- * Fire up the display manager, and the display processor.
- *
- */
-struct dm *
-plot_open(void *vinterp, int argc, const char *argv[])
-{
-    static int count = 0;
-    struct dm *dmp;
-    Tcl_Obj *obj;
-    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
 
-    BU_ALLOC(dmp, struct dm);
-
-    *dmp = dm_plot; /* struct copy */
-    dmp->i->dm_interp = interp;
-
-    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct plot_vars);
-
-    struct plot_vars *privars = (struct plot_vars *)dmp->i->dm_vars.priv_vars;
-
-    obj = Tcl_GetObjResult(interp);
-    if (Tcl_IsShared(obj))
-       obj = Tcl_DuplicateObj(obj);
-
-    bu_vls_init(&privars->vls);
-    bu_vls_init(&dmp->i->dm_pathName);
-    bu_vls_init(&dmp->i->dm_tkName);
-    bu_vls_printf(&dmp->i->dm_pathName, ".dm_plot%d", count++);
-    bu_vls_printf(&dmp->i->dm_tkName, "dm_plot%d", count++);
-
-    /* skip first argument */
-    --argc;
-    ++argv;
-
-    /* Process any options */
-    privars->is_3D = 1;          /* 3-D w/color, by default */
-    while (argv[0] != (char *)0 && argv[0][0] == '-') {
-       switch (argv[0][1]) {
-           case '3':
-               break;
-           case '2':
-               privars->is_3D = 0;             /* 2-D, for portability */
-               break;
-           case 'g':
-               privars->grid = 1;
-               break;
-           case 'f':
-               privars->floating = 1;
-               break;
-           case 'z':
-           case 'Z':
-               /* Enable Z clipping */
-               Tcl_AppendStringsToObj(obj, "Clipped in Z to viewing cube\n", 
(char *)NULL);
-
-               dmp->i->dm_zclip = 1;
-               break;
-           default:
-               Tcl_AppendStringsToObj(obj, "bad PLOT option ", argv[0], "\n", 
(char *)NULL);
-               (void)plot_close(dmp);
-
-               Tcl_SetObjResult(interp, obj);
-               return DM_NULL;
-       }
-       argv++;
-    }
-    if (argv[0] == (char *)0) {
-       Tcl_AppendStringsToObj(obj, "no filename or filter specified\n", (char 
*)NULL);
-       (void)plot_close(dmp);
-
-       Tcl_SetObjResult(interp, obj);
-       return DM_NULL;
-    }
-
-    if (argv[0][0] == '|') {
-       bu_vls_strcpy(&privars->vls, &argv[0][1]);
-       while ((++argv)[0] != (char *)0) {
-           bu_vls_strcat(&privars->vls, " ");
-           bu_vls_strcat(&privars->vls, argv[0]);
-       }
-
-       privars->is_pipe = 1;
-    } else {
-       bu_vls_strcpy(&privars->vls, argv[0]);
-    }
-
-    if (privars->is_pipe) {
-       if ((privars->up_fp = popen(bu_vls_addr(&privars->vls), "w")) == NULL) {
-           perror(bu_vls_addr(&privars->vls));
-           (void)plot_close(dmp);
-           Tcl_SetObjResult(interp, obj);
-           return DM_NULL;
-       }
-
-       Tcl_AppendStringsToObj(obj, "piped to ",
-                              bu_vls_addr(&privars->vls),
-                              "\n", (char *)NULL);
-    } else {
-       if ((privars->up_fp = fopen(bu_vls_addr(&privars->vls), "wb")) == NULL) 
{
-           perror(bu_vls_addr(&privars->vls));
-           (void)plot_close(dmp);
-           Tcl_SetObjResult(interp, obj);
-           return DM_NULL;
-       }
-
-       Tcl_AppendStringsToObj(obj, "plot stored in ",
-                              bu_vls_addr(&privars->vls),
-                              "\n", (char *)NULL);
-    }
-
-    setbuf(privars->up_fp, privars->ttybuf);
-
-    if (privars->is_3D)
-       pl_3space(privars->up_fp, -2048, -2048, -2048, 2048, 2048, 2048);
-    else
-       pl_space(privars->up_fp, -2048, -2048, 2048, 2048);
-
-    MAT_IDN(privars->mod_mat);
-    MAT_IDN(privars->disp_mat);
-    MAT_COPY(privars->plotmat, privars->mod_mat);
-
-    Tcl_SetObjResult(interp, obj);
-    return dmp;
-}
-
-
 /*
  * Local Variables:
  * mode: C

Modified: brlcad/branches/dm-fb-merge/src/libdm/postscript/dm-ps.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/postscript/dm-ps.c    2020-04-21 
11:00:00 UTC (rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/postscript/dm-ps.c    2020-04-21 
12:23:34 UTC (rev 75487)
@@ -64,7 +64,233 @@
 static mat_t mod_mat;
 
 
+static int ps_close(struct dm *dmp);
+
 /*
+ * Open the output file, and output the PostScript prolog.
+ *
+ */
+struct dm *
+ps_open(void *vinterp, int argc, const char *argv[])
+{
+    static int count = 0;
+    struct dm *dmp;
+    Tcl_Obj *obj;
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
+
+    *dmp->i = *dm_ps.i;  /* struct copy */
+    dmp->i->dm_interp = interp;
+
+    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct ps_vars);
+
+    obj = Tcl_GetObjResult(interp);
+    if (Tcl_IsShared(obj))
+       obj = Tcl_DuplicateObj(obj);
+
+    bu_vls_init(&dmp->i->dm_pathName);
+    bu_vls_init(&dmp->i->dm_tkName);
+    bu_vls_printf(&dmp->i->dm_pathName, ".dm_ps%d", count++);
+    bu_vls_printf(&dmp->i->dm_tkName, "dm_ps%d", count++);
+
+    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->fname);
+    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font);
+    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title);
+    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->creator);
+
+    /* set defaults */
+    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font, 
"Courier");
+    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title, "No 
Title");
+    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->creator, 
"LIBDM dm-ps");
+    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale = 0.0791;
+    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->linewidth = 4;
+    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->zclip = 0;
+
+    /* skip first argument */
+    --argc; ++argv;
+
+    /* Process any options */
+    while (argv[0] != (char *)0 && argv[0][0] == '-') {
+       switch (argv[0][1]) {
+           case 'f':               /* font */
+               if (argv[0][2] != '\0')
+                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->font, &argv[0][2]);
+               else {
+                   argv++;
+                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
+                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+                       (void)ps_close(dmp);
+
+                       Tcl_SetObjResult(interp, obj);
+                       return DM_NULL;
+                   } else
+                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->font, &argv[0][0]);
+               }
+               break;
+           case 't':               /* title */
+               if (argv[0][2] != '\0')
+                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->title, &argv[0][2]);
+               else {
+                   argv++;
+                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
+                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+                       (void)ps_close(dmp);
+
+                       Tcl_SetObjResult(interp, obj);
+                       return DM_NULL;
+                   } else
+                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->title, &argv[0][0]);
+               }
+               break;
+           case 'c':               /* creator */
+               if (argv[0][2] != '\0')
+                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator, &argv[0][2]);
+               else {
+                   argv++;
+                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
+                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+                       (void)ps_close(dmp);
+
+                       Tcl_SetObjResult(interp, obj);
+                       return DM_NULL;
+                   } else
+                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator, &argv[0][0]);
+               }
+               break;
+           case 's':               /* size in inches */
+               {
+                   double size;
+
+                   if (argv[0][2] != '\0')
+                       sscanf(&argv[0][2], "%lf", &size);
+                   else {
+                       argv++;
+                       if (argv[0] == (char *)0 || argv[0][0] == '-') {
+                           Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+                           (void)ps_close(dmp);
+
+                           Tcl_SetObjResult(interp, obj);
+                           return DM_NULL;
+                       } else
+                           sscanf(&argv[0][0], "%lf", &size);
+                   }
+
+                   ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale = size 
* 0.017578125;
+               }
+               break;
+           case 'l':               /* line width */
+               if (argv[0][2] != '\0')
+                   sscanf(&argv[0][2], "%d", &((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->linewidth);
+               else {
+                   argv++;
+                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
+                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+                       (void)ps_close(dmp);
+
+                       Tcl_SetObjResult(interp, obj);
+                       return DM_NULL;
+                   } else
+                       sscanf(&argv[0][0], "%d", &((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->linewidth);
+               }
+               break;
+           case 'z':
+               dmp->i->dm_zclip = 1;
+               break;
+           default:
+               Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
+               (void)ps_close(dmp);
+
+               Tcl_SetObjResult(interp, obj);
+               return DM_NULL;
+       }
+       argv++;
+    }
+
+    if (argv[0] == (char *)0) {
+       Tcl_AppendStringsToObj(obj, "no filename specified\n", (char *)NULL);
+       (void)ps_close(dmp);
+
+       Tcl_SetObjResult(interp, obj);
+       return DM_NULL;
+    }
+
+    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->fname, 
argv[0]);
+
+    if ((((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp =
+        fopen(bu_vls_addr(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->fname), "wb")) == NULL) {
+       Tcl_AppendStringsToObj(obj, "f_ps: Error opening file - ",
+                              ((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->fname,
+                              "\n", (char *)NULL);
+       (void)ps_close(dmp);
+
+       Tcl_SetObjResult(interp, obj);
+       return DM_NULL;
+    }
+
+    setbuf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp,
+          ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ttybuf);
+    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, 
"%%!PS-Adobe-1.0\n\
+%%begin(plot)\n\
+%%%%DocumentFonts:  %s\n",
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font));
+
+    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "%%%%Title: 
%s\n",
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title));
+
+    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
+%%%%Creator: %s\n\
+%%%%BoundingBox: 0 0 324 324   %% 4.5in square, for TeX\n\
+%%%%EndComments\n\
+\n",
+           bu_vls_addr(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator));
+
+    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
+%d setlinewidth\n\
+\n\
+%% Sizes, made functions to avoid scaling if not needed\n\
+/FntH /%s findfont 80 scalefont def\n\
+/DFntL { /FntL /%s findfont 73.4 scalefont def } def\n\
+/DFntM { /FntM /%s findfont 50.2 scalefont def } def\n\
+/DFntS { /FntS /%s findfont 44 scalefont def } def\n\
+",
+           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->linewidth,
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
+           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font));
+
+    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
+\n\
+%% line styles\n\
+/NV { [] 0 setdash } def       %% normal vectors\n\
+/DV { [8] 0 setdash } def      %% dotted vectors\n\
+/DDV { [8 8 32 8] 0 setdash } def      %% dot-dash vectors\n\
+/SDV { [32 8] 0 setdash } def  %% short-dash vectors\n\
+/LDV { [64 8] 0 setdash } def  %% long-dash vectors\n\
+\n\
+/NEWPG {\n\
+       %f %f scale     %% 0-4096 to 324 units (4.5 inches)\n\
+} def\n\
+\n\
+FntH setfont\n\
+NEWPG\n\
+",
+           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale,
+           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale);
+
+    MAT_IDN(mod_mat);
+    MAT_IDN(disp_mat);
+    MAT_COPY(psmat, mod_mat);
+
+    Tcl_SetObjResult(interp, obj);
+    return dmp;
+}
+
+
+
+/*
  * Gracefully release the display.
  */
 HIDDEN int
@@ -83,6 +309,7 @@
     bu_vls_free(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title);
     bu_vls_free(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->creator);
     bu_free((void *)dmp->i->dm_vars.priv_vars, "ps_close: ps_vars");
+    bu_free((void *)dmp->i, "ps_close: dmp impl");
     bu_free((void *)dmp, "ps_close: dmp");
 
     return BRLCAD_OK;
@@ -500,6 +727,7 @@
 
 
 struct dm_impl dm_ps_impl = {
+    ps_open,
     ps_close,
     ps_drawBegin,
     ps_drawEnd,
@@ -600,228 +828,7 @@
 }
 #endif
 
-/*
- * Open the output file, and output the PostScript prolog.
- *
- */
-struct dm *
-ps_open(void *vinterp, int argc, const char *argv[])
-{
-    static int count = 0;
-    struct dm *dmp;
-    Tcl_Obj *obj;
-    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
 
-    BU_ALLOC(dmp, struct dm);
-
-    *dmp = dm_ps;  /* struct copy */
-    dmp->i->dm_interp = interp;
-
-    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct ps_vars);
-
-    obj = Tcl_GetObjResult(interp);
-    if (Tcl_IsShared(obj))
-       obj = Tcl_DuplicateObj(obj);
-
-    bu_vls_init(&dmp->i->dm_pathName);
-    bu_vls_init(&dmp->i->dm_tkName);
-    bu_vls_printf(&dmp->i->dm_pathName, ".dm_ps%d", count++);
-    bu_vls_printf(&dmp->i->dm_tkName, "dm_ps%d", count++);
-
-    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->fname);
-    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font);
-    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title);
-    bu_vls_init(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->creator);
-
-    /* set defaults */
-    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font, 
"Courier");
-    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title, "No 
Title");
-    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->creator, 
"LIBDM dm-ps");
-    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale = 0.0791;
-    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->linewidth = 4;
-    ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->zclip = 0;
-
-    /* skip first argument */
-    --argc; ++argv;
-
-    /* Process any options */
-    while (argv[0] != (char *)0 && argv[0][0] == '-') {
-       switch (argv[0][1]) {
-           case 'f':               /* font */
-               if (argv[0][2] != '\0')
-                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->font, &argv[0][2]);
-               else {
-                   argv++;
-                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
-                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-                       (void)ps_close(dmp);
-
-                       Tcl_SetObjResult(interp, obj);
-                       return DM_NULL;
-                   } else
-                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->font, &argv[0][0]);
-               }
-               break;
-           case 't':               /* title */
-               if (argv[0][2] != '\0')
-                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->title, &argv[0][2]);
-               else {
-                   argv++;
-                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
-                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-                       (void)ps_close(dmp);
-
-                       Tcl_SetObjResult(interp, obj);
-                       return DM_NULL;
-                   } else
-                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->title, &argv[0][0]);
-               }
-               break;
-           case 'c':               /* creator */
-               if (argv[0][2] != '\0')
-                   bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator, &argv[0][2]);
-               else {
-                   argv++;
-                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
-                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-                       (void)ps_close(dmp);
-
-                       Tcl_SetObjResult(interp, obj);
-                       return DM_NULL;
-                   } else
-                       bu_vls_strcpy(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator, &argv[0][0]);
-               }
-               break;
-           case 's':               /* size in inches */
-               {
-                   double size;
-
-                   if (argv[0][2] != '\0')
-                       sscanf(&argv[0][2], "%lf", &size);
-                   else {
-                       argv++;
-                       if (argv[0] == (char *)0 || argv[0][0] == '-') {
-                           Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-                           (void)ps_close(dmp);
-
-                           Tcl_SetObjResult(interp, obj);
-                           return DM_NULL;
-                       } else
-                           sscanf(&argv[0][0], "%lf", &size);
-                   }
-
-                   ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale = size 
* 0.017578125;
-               }
-               break;
-           case 'l':               /* line width */
-               if (argv[0][2] != '\0')
-                   sscanf(&argv[0][2], "%d", &((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->linewidth);
-               else {
-                   argv++;
-                   if (argv[0] == (char *)0 || argv[0][0] == '-') {
-                       Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-                       (void)ps_close(dmp);
-
-                       Tcl_SetObjResult(interp, obj);
-                       return DM_NULL;
-                   } else
-                       sscanf(&argv[0][0], "%d", &((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->linewidth);
-               }
-               break;
-           case 'z':
-               dmp->i->dm_zclip = 1;
-               break;
-           default:
-               Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
-               (void)ps_close(dmp);
-
-               Tcl_SetObjResult(interp, obj);
-               return DM_NULL;
-       }
-       argv++;
-    }
-
-    if (argv[0] == (char *)0) {
-       Tcl_AppendStringsToObj(obj, "no filename specified\n", (char *)NULL);
-       (void)ps_close(dmp);
-
-       Tcl_SetObjResult(interp, obj);
-       return DM_NULL;
-    }
-
-    bu_vls_strcpy(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->fname, 
argv[0]);
-
-    if ((((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp =
-        fopen(bu_vls_addr(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->fname), "wb")) == NULL) {
-       Tcl_AppendStringsToObj(obj, "f_ps: Error opening file - ",
-                              ((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->fname,
-                              "\n", (char *)NULL);
-       (void)ps_close(dmp);
-
-       Tcl_SetObjResult(interp, obj);
-       return DM_NULL;
-    }
-
-    setbuf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp,
-          ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ttybuf);
-    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, 
"%%!PS-Adobe-1.0\n\
-%%begin(plot)\n\
-%%%%DocumentFonts:  %s\n",
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font));
-
-    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "%%%%Title: 
%s\n",
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->title));
-
-    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
-%%%%Creator: %s\n\
-%%%%BoundingBox: 0 0 324 324   %% 4.5in square, for TeX\n\
-%%%%EndComments\n\
-\n",
-           bu_vls_addr(&((struct ps_vars 
*)dmp->i->dm_vars.priv_vars)->creator));
-
-    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
-%d setlinewidth\n\
-\n\
-%% Sizes, made functions to avoid scaling if not needed\n\
-/FntH /%s findfont 80 scalefont def\n\
-/DFntL { /FntL /%s findfont 73.4 scalefont def } def\n\
-/DFntM { /FntM /%s findfont 50.2 scalefont def } def\n\
-/DFntS { /FntS /%s findfont 44 scalefont def } def\n\
-",
-           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->linewidth,
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font),
-           bu_vls_addr(&((struct ps_vars *)dmp->i->dm_vars.priv_vars)->font));
-
-    fprintf(((struct ps_vars *)dmp->i->dm_vars.priv_vars)->ps_fp, "\
-\n\
-%% line styles\n\
-/NV { [] 0 setdash } def       %% normal vectors\n\
-/DV { [8] 0 setdash } def      %% dotted vectors\n\
-/DDV { [8 8 32 8] 0 setdash } def      %% dot-dash vectors\n\
-/SDV { [32 8] 0 setdash } def  %% short-dash vectors\n\
-/LDV { [64 8] 0 setdash } def  %% long-dash vectors\n\
-\n\
-/NEWPG {\n\
-       %f %f scale     %% 0-4096 to 324 units (4.5 inches)\n\
-} def\n\
-\n\
-FntH setfont\n\
-NEWPG\n\
-",
-           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale,
-           ((struct ps_vars *)dmp->i->dm_vars.priv_vars)->scale);
-
-    MAT_IDN(mod_mat);
-    MAT_IDN(disp_mat);
-    MAT_COPY(psmat, mod_mat);
-
-    Tcl_SetObjResult(interp, obj);
-    return dmp;
-}
-
-
 /*
  * Local Variables:
  * mode: C

Modified: brlcad/branches/dm-fb-merge/src/libdm/qt/dm-qt.cpp
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/qt/dm-qt.cpp  2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/qt/dm-qt.cpp  2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -46,7 +46,266 @@
 /* token used to cancel previous scheduled function using 
Tcl_CreateTimerHandler */
 Tcl_TimerToken token = NULL;
 
+/**
+ * ================================================== Event bindings 
declaration ==========================================================
+ */
 
+/* left click press */
+char* qt_mouseButton1Press(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<1> -x %d -y %d", mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+/* left click release */
+char* qt_mouseButton1Release(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonRelease) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<ButtonRelease-1>");
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+/* right click press */
+char* qt_mouseButton3Press(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::RightButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<3> -x %d -y %d", mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+/* right click release */
+char* qt_mouseButton3Release(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::RightButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<ButtonRelease-3>");
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+/* middle mouse button press */
+char* qt_mouseButton2Press(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::MiddleButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<2> -x %d -y %d", mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+/* middle mouse button release */
+char* qt_mouseButton2Release(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::MiddleButton) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<ButtonRelease-2>");
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+char* qt_controlMousePress(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == 
Qt::ControlModifier) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<Control-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+char* qt_altMousePress(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == 
Qt::AltModifier) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+char* qt_altControlMousePress(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & 
Qt::AltModifier && mouseEv->modifiers() & Qt::ControlModifier) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<Control-Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+char* qt_controlShiftMousePress(QEvent *event) {
+    if (event->type() ==  QEvent::MouseButtonPress) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & 
Qt::ShiftModifier && mouseEv->modifiers() & Qt::ControlModifier) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "<Shift-Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
+           return bu_vls_addr(&str);
+       }
+    }
+    return NULL;
+}
+
+char* qt_mouseMove(QEvent *event) {
+    if (event->type() ==  QEvent::MouseMove) {
+       QMouseEvent *mouseEv = (QMouseEvent *)event;
+       struct bu_vls str = BU_VLS_INIT_ZERO;
+       bu_vls_printf(&str, "<Motion> -x %d -y %d", mouseEv->x(), mouseEv->y());
+       return bu_vls_addr(&str);
+    }
+    return NULL;
+}
+
+char* qt_keyPress(QEvent *event) {
+    /* FIXME numeric constant needs to be changed to QEvent::KeyPress but at 
this moment this does not compile */
+    if (event->type() ==  6 /* QEvent::KeyPress */) {
+       QKeyEvent *keyEv = (QKeyEvent *)event;
+       struct bu_vls str = BU_VLS_INIT_ZERO;
+       bu_vls_printf(&str, "<KeyPress-%c>", keyEv->text().data()->toLatin1());
+       return bu_vls_addr(&str);
+    }
+    return NULL;
+}
+
+char* qt_keyRelease(QEvent *event) {
+    /* FIXME numeric constant needs to be changed to QEvent::KeyRelease but at 
this moment this does not compile */
+    if (event->type() ==  7 /* QEvent::KeyRelease */) {
+       QKeyEvent *keyEv = (QKeyEvent *)event;
+       struct bu_vls str = BU_VLS_INIT_ZERO;
+       bu_vls_printf(&str, "<KeyRelease-%c>", 
keyEv->text().data()->toLatin1());
+       return bu_vls_addr(&str);
+    }
+    return NULL;
+}
+
+static struct qt_tk_bind qt_bindings[] = {
+    {qt_keyPress, "keypress"},
+    {qt_keyRelease, "keyrelease"},
+    {qt_controlMousePress, "controlbutton1"},
+    {qt_altMousePress, "altbutton1"},
+    {qt_altControlMousePress, "altcontrolbutton1"},
+    {qt_controlShiftMousePress, "controlshiftbutton1"},
+    {qt_mouseButton1Press, "button1press"},
+    {qt_mouseButton1Release, "button1release"},
+    {qt_mouseButton3Press, "button3press"},
+    {qt_mouseButton3Release, "button3release"},
+    {qt_mouseButton2Press, "button2press"},
+    {qt_mouseButton2Release, "button2release"},
+    {qt_mouseMove, "mouseMove"},
+    {NULL, NULL}
+};
+
+/**
+ * ===================================================== Main window class 
===============================================
+ */
+
+QTkMainWindow::QTkMainWindow(QPixmap *p, QWindow *win, void *d)
+    : QWindow(win)
+    , m_update_pending(false)
+{
+    m_backingStore = new QBackingStore(this);
+    create();
+    pixmap = p;
+    dmp = d;
+}
+
+QTkMainWindow::~QTkMainWindow()
+{
+    delete m_backingStore;
+    close();
+}
+
+void QTkMainWindow::exposeEvent(QExposeEvent *)
+{
+    if (isExposed()) {
+       renderNow();
+    }
+}
+
+void QTkMainWindow::resizeEvent(QResizeEvent *resizeEv)
+{
+    m_backingStore->resize(resizeEv->size());
+    if (isExposed())
+       renderNow();
+}
+
+bool QTkMainWindow::event(QEvent *ev)
+{
+    int index = 0;
+    if (ev->type() == QEvent::UpdateRequest) {
+       m_update_pending = false;
+       renderNow();
+       return true;
+    }
+    while (qt_bindings[index].name != NULL) {
+       char *tk_event = qt_bindings[index].bind_function(ev);
+       if (tk_event != NULL) {
+           struct bu_vls str = BU_VLS_INIT_ZERO;
+           bu_vls_printf(&str, "event generate %s %s", bu_vls_addr(&((struct 
dm *)dmp)->dm_pathName), tk_event);
+           if (Tcl_Eval(((struct dm *)dmp)->dm_interp, bu_vls_addr(&str)) == 
TCL_ERROR) {
+               bu_log("error generate event %s\n", tk_event);
+           }
+           return true;
+       }
+       index++;
+    }
+    return QWindow::event(ev);
+}
+
+void QTkMainWindow::renderNow()
+{
+    if (!isExposed()) {
+       return;
+    }
+
+    QRect rect(0, 0, width(), height());
+    m_backingStore->beginPaint(rect);
+
+    QPaintDevice *device = m_backingStore->paintDevice();
+    QPainter painter(device);
+
+    render(&painter);
+
+    m_backingStore->endPaint();
+    m_backingStore->flush(rect);
+}
+
+void QTkMainWindow::render(QPainter *painter)
+{
+    painter->drawPixmap(0, 0, *pixmap);
+}
+
+
 HIDDEN bool
 qt_sendRepaintEvent(struct dm *dmp)
 {
@@ -55,6 +314,194 @@
     return privars->qapp->sendEvent(privars->win, &e);
 }
 
+/*
+ * Fire up the display manager, and the display processor.
+ *
+ */
+extern "C" struct dm *
+qt_open(void *vinterp, int argc, char **argv)
+{
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+    static int count = 0;
+    int make_square = -1;
+    struct dm *dmp = (struct dm *)NULL;
+    struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
+    struct bu_vls str = BU_VLS_INIT_ZERO;
+    Tk_Window tkwin;
+
+    struct dm_qtvars *pubvars = NULL;
+    struct qt_vars *privars = NULL;
+
+    if (argc < 0 || !argv) {
+       return DM_NULL;
+    }
+
+    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
+       return DM_NULL;
+    }
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
+
+    *dmp->i = *dm_qt.i; /* struct copy */
+    dmp->i->dm_interp = interp;
+
+    BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_qtvars);
+    pubvars = (struct dm_qtvars *)dmp->i->dm_vars.pub_vars;
+
+    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct qt_vars);
+    privars = (struct qt_vars *)dmp->i->dm_vars.priv_vars;
+
+    bu_vls_init(&dmp->i->dm_pathName);
+    bu_vls_init(&dmp->i->dm_tkName);
+    bu_vls_init(&dmp->i->dm_dName);
+
+    dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
+
+    if (bu_vls_strlen(&dmp->i->dm_pathName) == 0) {
+       bu_vls_printf(&dmp->i->dm_pathName, ".dm_qt%d", count);
+    }
+    ++count;
+
+    if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
+       char *dp;
+
+       dp = getenv("DISPLAY");
+       if (dp)
+           bu_vls_strcpy(&dmp->i->dm_dName, dp);
+       else
+           bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
+    }
+    if (bu_vls_strlen(&init_proc_vls) == 0) {
+       bu_vls_strcpy(&init_proc_vls, "bind_dm");
+    }
+
+    /* initialize dm specific variables */
+    pubvars->devmotionnotify = LASTEvent;
+    pubvars->devbuttonpress = LASTEvent;
+    pubvars->devbuttonrelease = LASTEvent;
+    dmp->i->dm_aspect = 1.0;
+
+    if (dmp->i->dm_top) {
+       /* Make xtkwin a toplevel window */
+       pubvars->xtkwin = Tk_CreateWindowFromPath(interp, tkwin,
+                                                 
bu_vls_addr(&dmp->i->dm_pathName),
+                                                 
bu_vls_addr(&dmp->i->dm_dName));
+       pubvars->top = pubvars->xtkwin;
+    } else {
+       char *cp;
+
+       cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
+       if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
+           pubvars->top = tkwin;
+       } else {
+           struct bu_vls top_vls = BU_VLS_INIT_ZERO;
+
+           bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
+
+           pubvars->top = Tk_NameToWindow(interp, bu_vls_addr(&top_vls), 
tkwin);
+           bu_vls_free(&top_vls);
+       }
+
+       /* Make xtkwin an embedded window */
+       pubvars->xtkwin =
+           Tk_CreateWindow(interp, pubvars->top,
+                           cp + 1, (char *)NULL);
+    }
+
+    if (pubvars->xtkwin == NULL) {
+       bu_log("qt_open: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
+       (void)qt_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_printf(&dmp->i->dm_tkName, "%s", (char *)Tk_Name(pubvars->xtkwin));
+
+    bu_vls_printf(&str, "_init_dm %s %s\n", bu_vls_addr(&init_proc_vls), 
bu_vls_addr(&dmp->i->dm_pathName));
+
+    if (Tcl_Eval(interp, bu_vls_addr(&str)) == TCL_ERROR) {
+       bu_log("qt_open: _init_dm failed\n");
+       bu_vls_free(&init_proc_vls);
+       bu_vls_free(&str);
+       (void)qt_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_free(&init_proc_vls);
+    bu_vls_free(&str);
+
+    pubvars->dpy = Tk_Display(pubvars->top);
+
+    /* make sure there really is a display before proceeding. */
+    if (!pubvars->dpy) {
+       bu_log("qt_open: Unable to attach to display (%s)\n", 
bu_vls_addr(&dmp->i->dm_pathName));
+       (void)qt_close(dmp);
+       return DM_NULL;
+    }
+
+    if (dmp->i->dm_width == 0) {
+       dmp->i->dm_width =
+           WidthOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
+       ++make_square;
+    }
+
+    if (dmp->i->dm_height == 0) {
+       dmp->i->dm_height =
+           HeightOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
+       ++make_square;
+    }
+
+    if (make_square > 0) {
+       /* Make window square */
+       if (dmp->i->dm_height <
+           dmp->i->dm_width)
+           dmp->i->dm_width = dmp->i->dm_height;
+       else
+           dmp->i->dm_height = dmp->i->dm_width;
+    }
+
+    Tk_GeometryRequest(pubvars->xtkwin, dmp->i->dm_width, dmp->i->dm_height);
+
+    Tk_MakeWindowExist(pubvars->xtkwin);
+    pubvars->win = Tk_WindowId(pubvars->xtkwin);
+    dmp->i->dm_id = pubvars->win;
+
+    Tk_SetWindowBackground(pubvars->xtkwin, 0);
+    Tk_MapWindow(pubvars->xtkwin);
+    privars->qapp = new QApplication(argc, argv);
+
+    privars->parent = QWindow::fromWinId(pubvars->win);
+
+    privars->pix = new QPixmap(dmp->i->dm_width, dmp->i->dm_height);
+
+    privars->win = new QTkMainWindow(privars->pix, privars->parent, dmp);
+    privars->win->resize(dmp->i->dm_width, dmp->i->dm_height);
+    privars->win->show();
+
+    privars->font = NULL;
+
+    privars->painter = new QPainter(privars->pix);
+    qt_setFGColor(dmp, 1, 0, 0, 0, 0);
+    qt_setBGColor(dmp, 0, 0, 0);
+
+    qt_configureWin(dmp, 1);
+
+    MAT_IDN(privars->mod_mat);
+    MAT_IDN(privars->disp_mat);
+
+    privars->qmat = &(privars->mod_mat[0]);
+    /* inputs and outputs assume POSIX/C locale settings */
+    setlocale(LC_ALL, "POSIX");
+
+    /* Make Tcl_DoOneEvent call QApplication::processEvents */
+    Tcl_CreateEventSource(NULL, processQtEvents, NULL);
+
+    /* Try to process Qt events when idle */
+    Tcl_DoWhenIdle(IdleCall, NULL);
+
+    return dmp;
+}
+
 /**
  * Release the display manager
  */
@@ -82,6 +529,7 @@
     bu_vls_free(&dmp->i->dm_dName);
     bu_free((void *)dmp->i->dm_vars.priv_vars, "qt_close: qt_vars");
     bu_free((void *)dmp->i->dm_vars.pub_vars, "qt_close: dm_qtvars");
+    bu_free((void *)dmp->i, "qt_close: dmp impl");
     bu_free((void *)dmp, "qt_close: dmp");
 
     return TCL_OK;
@@ -767,192 +1215,6 @@
 
 __BEGIN_DECLS
 
-/*
- * Fire up the display manager, and the display processor.
- *
- */
-struct dm *
-qt_open(Tcl_Interp *interp, int argc, char **argv)
-{
-    static int count = 0;
-    int make_square = -1;
-    struct dm *dmp = (struct dm *)NULL;
-    struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
-    struct bu_vls str = BU_VLS_INIT_ZERO;
-    Tk_Window tkwin;
-
-    struct dm_qtvars *pubvars = NULL;
-    struct qt_vars *privars = NULL;
-
-    if (argc < 0 || !argv) {
-       return DM_NULL;
-    }
-
-    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
-       return DM_NULL;
-    }
-
-    BU_ALLOC(dmp, struct dm);
-
-    *dmp = dm_qt; /* struct copy */
-    dmp->i->dm_interp = interp;
-
-    BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_qtvars);
-    pubvars = (struct dm_qtvars *)dmp->i->dm_vars.pub_vars;
-
-    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct qt_vars);
-    privars = (struct qt_vars *)dmp->i->dm_vars.priv_vars;
-
-    bu_vls_init(&dmp->i->dm_pathName);
-    bu_vls_init(&dmp->i->dm_tkName);
-    bu_vls_init(&dmp->i->dm_dName);
-
-    dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
-
-    if (bu_vls_strlen(&dmp->i->dm_pathName) == 0) {
-       bu_vls_printf(&dmp->i->dm_pathName, ".dm_qt%d", count);
-    }
-    ++count;
-
-    if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
-       char *dp;
-
-       dp = getenv("DISPLAY");
-       if (dp)
-           bu_vls_strcpy(&dmp->i->dm_dName, dp);
-       else
-           bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
-    }
-    if (bu_vls_strlen(&init_proc_vls) == 0) {
-       bu_vls_strcpy(&init_proc_vls, "bind_dm");
-    }
-
-    /* initialize dm specific variables */
-    pubvars->devmotionnotify = LASTEvent;
-    pubvars->devbuttonpress = LASTEvent;
-    pubvars->devbuttonrelease = LASTEvent;
-    dmp->i->dm_aspect = 1.0;
-
-    if (dmp->i->dm_top) {
-       /* Make xtkwin a toplevel window */
-       pubvars->xtkwin = Tk_CreateWindowFromPath(interp, tkwin,
-                                                 
bu_vls_addr(&dmp->i->dm_pathName),
-                                                 
bu_vls_addr(&dmp->i->dm_dName));
-       pubvars->top = pubvars->xtkwin;
-    } else {
-       char *cp;
-
-       cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
-       if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
-           pubvars->top = tkwin;
-       } else {
-           struct bu_vls top_vls = BU_VLS_INIT_ZERO;
-
-           bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
-
-           pubvars->top = Tk_NameToWindow(interp, bu_vls_addr(&top_vls), 
tkwin);
-           bu_vls_free(&top_vls);
-       }
-
-       /* Make xtkwin an embedded window */
-       pubvars->xtkwin =
-           Tk_CreateWindow(interp, pubvars->top,
-                           cp + 1, (char *)NULL);
-    }
-
-    if (pubvars->xtkwin == NULL) {
-       bu_log("qt_open: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
-       (void)qt_close(dmp);
-       return DM_NULL;
-    }
-
-    bu_vls_printf(&dmp->i->dm_tkName, "%s", (char *)Tk_Name(pubvars->xtkwin));
-
-    bu_vls_printf(&str, "_init_dm %s %s\n", bu_vls_addr(&init_proc_vls), 
bu_vls_addr(&dmp->i->dm_pathName));
-
-    if (Tcl_Eval(interp, bu_vls_addr(&str)) == TCL_ERROR) {
-       bu_log("qt_open: _init_dm failed\n");
-       bu_vls_free(&init_proc_vls);
-       bu_vls_free(&str);
-       (void)qt_close(dmp);
-       return DM_NULL;
-    }
-
-    bu_vls_free(&init_proc_vls);
-    bu_vls_free(&str);
-
-    pubvars->dpy = Tk_Display(pubvars->top);
-
-    /* make sure there really is a display before proceeding. */
-    if (!pubvars->dpy) {
-       bu_log("qt_open: Unable to attach to display (%s)\n", 
bu_vls_addr(&dmp->i->dm_pathName));
-       (void)qt_close(dmp);
-       return DM_NULL;
-    }
-
-    if (dmp->i->dm_width == 0) {
-       dmp->i->dm_width =
-           WidthOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
-       ++make_square;
-    }
-
-    if (dmp->i->dm_height == 0) {
-       dmp->i->dm_height =
-           HeightOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
-       ++make_square;
-    }
-
-    if (make_square > 0) {
-       /* Make window square */
-       if (dmp->i->dm_height <
-           dmp->i->dm_width)
-           dmp->i->dm_width = dmp->i->dm_height;
-       else
-           dmp->i->dm_height = dmp->i->dm_width;
-    }
-
-    Tk_GeometryRequest(pubvars->xtkwin, dmp->i->dm_width, dmp->i->dm_height);
-
-    Tk_MakeWindowExist(pubvars->xtkwin);
-    pubvars->win = Tk_WindowId(pubvars->xtkwin);
-    dmp->i->dm_id = pubvars->win;
-
-    Tk_SetWindowBackground(pubvars->xtkwin, 0);
-    Tk_MapWindow(pubvars->xtkwin);
-    privars->qapp = new QApplication(argc, argv);
-
-    privars->parent = QWindow::fromWinId(pubvars->win);
-
-    privars->pix = new QPixmap(dmp->i->dm_width, dmp->i->dm_height);
-
-    privars->win = new QTkMainWindow(privars->pix, privars->parent, dmp);
-    privars->win->resize(dmp->i->dm_width, dmp->i->dm_height);
-    privars->win->show();
-
-    privars->font = NULL;
-
-    privars->painter = new QPainter(privars->pix);
-    qt_setFGColor(dmp, 1, 0, 0, 0, 0);
-    qt_setBGColor(dmp, 0, 0, 0);
-
-    qt_configureWin(dmp, 1);
-
-    MAT_IDN(privars->mod_mat);
-    MAT_IDN(privars->disp_mat);
-
-    privars->qmat = &(privars->mod_mat[0]);
-    /* inputs and outputs assume POSIX/C locale settings */
-    setlocale(LC_ALL, "POSIX");
-
-    /* Make Tcl_DoOneEvent call QApplication::processEvents */
-    Tcl_CreateEventSource(NULL, processQtEvents, NULL);
-
-    /* Try to process Qt events when idle */
-    Tcl_DoWhenIdle(IdleCall, NULL);
-
-    return dmp;
-}
-
 static void
 Qt_zclip_hook(const struct bu_structparse *sdp,
        const char *name,
@@ -1045,6 +1307,7 @@
 __END_DECLS
 
 struct dm_impl dm_qt_impl = {
+    qt_open,
     qt_close,
     qt_drawBegin,
     qt_drawEnd,
@@ -1148,265 +1411,7 @@
 #endif
 }
 
-/**
- * ================================================== Event bindings 
declaration ==========================================================
- */
 
-/* left click press */
-char* qt_mouseButton1Press(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<1> -x %d -y %d", mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-/* left click release */
-char* qt_mouseButton1Release(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonRelease) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<ButtonRelease-1>");
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-/* right click press */
-char* qt_mouseButton3Press(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::RightButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<3> -x %d -y %d", mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-/* right click release */
-char* qt_mouseButton3Release(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::RightButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<ButtonRelease-3>");
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-/* middle mouse button press */
-char* qt_mouseButton2Press(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::MiddleButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<2> -x %d -y %d", mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-/* middle mouse button release */
-char* qt_mouseButton2Release(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::MiddleButton) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<ButtonRelease-2>");
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-char* qt_controlMousePress(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == 
Qt::ControlModifier) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<Control-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-char* qt_altMousePress(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == 
Qt::AltModifier) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-char* qt_altControlMousePress(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & 
Qt::AltModifier && mouseEv->modifiers() & Qt::ControlModifier) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<Control-Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-char* qt_controlShiftMousePress(QEvent *event) {
-    if (event->type() ==  QEvent::MouseButtonPress) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       if (mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() & 
Qt::ShiftModifier && mouseEv->modifiers() & Qt::ControlModifier) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "<Shift-Alt-ButtonPress-1> -x %d -y %d", 
mouseEv->x(), mouseEv->y());
-           return bu_vls_addr(&str);
-       }
-    }
-    return NULL;
-}
-
-char* qt_mouseMove(QEvent *event) {
-    if (event->type() ==  QEvent::MouseMove) {
-       QMouseEvent *mouseEv = (QMouseEvent *)event;
-       struct bu_vls str = BU_VLS_INIT_ZERO;
-       bu_vls_printf(&str, "<Motion> -x %d -y %d", mouseEv->x(), mouseEv->y());
-       return bu_vls_addr(&str);
-    }
-    return NULL;
-}
-
-char* qt_keyPress(QEvent *event) {
-    /* FIXME numeric constant needs to be changed to QEvent::KeyPress but at 
this moment this does not compile */
-    if (event->type() ==  6 /* QEvent::KeyPress */) {
-       QKeyEvent *keyEv = (QKeyEvent *)event;
-       struct bu_vls str = BU_VLS_INIT_ZERO;
-       bu_vls_printf(&str, "<KeyPress-%c>", keyEv->text().data()->toLatin1());
-       return bu_vls_addr(&str);
-    }
-    return NULL;
-}
-
-char* qt_keyRelease(QEvent *event) {
-    /* FIXME numeric constant needs to be changed to QEvent::KeyRelease but at 
this moment this does not compile */
-    if (event->type() ==  7 /* QEvent::KeyRelease */) {
-       QKeyEvent *keyEv = (QKeyEvent *)event;
-       struct bu_vls str = BU_VLS_INIT_ZERO;
-       bu_vls_printf(&str, "<KeyRelease-%c>", 
keyEv->text().data()->toLatin1());
-       return bu_vls_addr(&str);
-    }
-    return NULL;
-}
-
-static struct qt_tk_bind qt_bindings[] = {
-    {qt_keyPress, "keypress"},
-    {qt_keyRelease, "keyrelease"},
-    {qt_controlMousePress, "controlbutton1"},
-    {qt_altMousePress, "altbutton1"},
-    {qt_altControlMousePress, "altcontrolbutton1"},
-    {qt_controlShiftMousePress, "controlshiftbutton1"},
-    {qt_mouseButton1Press, "button1press"},
-    {qt_mouseButton1Release, "button1release"},
-    {qt_mouseButton3Press, "button3press"},
-    {qt_mouseButton3Release, "button3release"},
-    {qt_mouseButton2Press, "button2press"},
-    {qt_mouseButton2Release, "button2release"},
-    {qt_mouseMove, "mouseMove"},
-    {NULL, NULL}
-};
-
-/**
- * ===================================================== Main window class 
===============================================
- */
-
-QTkMainWindow::QTkMainWindow(QPixmap *p, QWindow *win, void *d)
-    : QWindow(win)
-    , m_update_pending(false)
-{
-    m_backingStore = new QBackingStore(this);
-    create();
-    pixmap = p;
-    dmp = d;
-}
-
-QTkMainWindow::~QTkMainWindow()
-{
-    delete m_backingStore;
-    close();
-}
-
-void QTkMainWindow::exposeEvent(QExposeEvent *)
-{
-    if (isExposed()) {
-       renderNow();
-    }
-}
-
-void QTkMainWindow::resizeEvent(QResizeEvent *resizeEv)
-{
-    m_backingStore->resize(resizeEv->size());
-    if (isExposed())
-       renderNow();
-}
-
-bool QTkMainWindow::event(QEvent *ev)
-{
-    int index = 0;
-    if (ev->type() == QEvent::UpdateRequest) {
-       m_update_pending = false;
-       renderNow();
-       return true;
-    }
-    while (qt_bindings[index].name != NULL) {
-       char *tk_event = qt_bindings[index].bind_function(ev);
-       if (tk_event != NULL) {
-           struct bu_vls str = BU_VLS_INIT_ZERO;
-           bu_vls_printf(&str, "event generate %s %s", bu_vls_addr(&((struct 
dm *)dmp)->dm_pathName), tk_event);
-           if (Tcl_Eval(((struct dm *)dmp)->dm_interp, bu_vls_addr(&str)) == 
TCL_ERROR) {
-               bu_log("error generate event %s\n", tk_event);
-           }
-           return true;
-       }
-       index++;
-    }
-    return QWindow::event(ev);
-}
-
-void QTkMainWindow::renderNow()
-{
-    if (!isExposed()) {
-       return;
-    }
-
-    QRect rect(0, 0, width(), height());
-    m_backingStore->beginPaint(rect);
-
-    QPaintDevice *device = m_backingStore->paintDevice();
-    QPainter painter(device);
-
-    render(&painter);
-
-    m_backingStore->endPaint();
-    m_backingStore->flush(rect);
-}
-
-void QTkMainWindow::render(QPainter *painter)
-{
-    painter->drawPixmap(0, 0, *pixmap);
-}
-
 #endif /* DM_QT */
 /*
  * Local Variables:

Modified: brlcad/branches/dm-fb-merge/src/libdm/tk/dm-tk.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/tk/dm-tk.c    2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/tk/dm-tk.c    2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -71,7 +71,204 @@
 
 extern int vectorThreshold;    /* defined in libdm/tcl.c */
 
+static int tk_close(struct dm *dmp);
+static int tk_configureWin_guts(struct dm *dmp, int force);
 
+/*
+ * Fire up the display manager, and the display processor.
+ *
+ */
+struct dm *
+tk_open(void *vinterp, int argc, const char **argv)
+{
+    static int count = 0;
+    int make_square = -1;
+    XGCValues gcv;
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+
+    struct bu_vls str = BU_VLS_INIT_ZERO;
+    struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
+    struct dm *dmp = NULL;
+    struct dm_impl *dmp_impl = NULL;
+    Tk_Window tkwin;
+    Display *dpy = (Display *)NULL;
+    XColor fg, bg;
+
+    INIT_XCOLOR(&fg);
+    INIT_XCOLOR(&bg);
+
+    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
+       return DM_NULL;
+    }
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp_impl, struct dm_impl);
+
+    *dmp_impl = *dm_tk.i; /* struct copy */
+    dmp->i = dmp_impl;
+    dmp->i->dm_interp = interp;
+
+    BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_tkvars);
+    struct dm_tkvars *pubvars = (struct dm_tkvars *)dmp->i->dm_vars.pub_vars;
+    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct tk_vars);
+    struct tk_vars *privars = (struct tk_vars *)dmp->i->dm_vars.priv_vars;
+
+    bu_vls_init(&dmp->i->dm_pathName);
+    bu_vls_init(&dmp->i->dm_tkName);
+    bu_vls_init(&dmp->i->dm_dName);
+
+    dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
+
+    if (bu_vls_strlen(&dmp->i->dm_pathName) == 0) {
+       bu_vls_printf(&dmp->i->dm_pathName, ".dm_tk%d", count);
+    }
+
+    ++count;
+    if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
+       char *dp;
+
+       dp = DisplayString(Tk_Display(tkwin));
+
+       if (dp)
+           bu_vls_strcpy(&dmp->i->dm_dName, dp);
+       else
+           bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
+    }
+    if (bu_vls_strlen(&init_proc_vls) == 0)
+       bu_vls_strcpy(&init_proc_vls, "bind_dm");
+
+    /* initialize dm specific variables */
+    pubvars->devmotionnotify = LASTEvent;
+    pubvars->devbuttonpress = LASTEvent;
+    pubvars->devbuttonrelease = LASTEvent;
+    dmp->i->dm_aspect = 1.0;
+
+    privars->tkfontset = 0;
+
+    if (dmp->i->dm_top) {
+       /* Make xtkwin a toplevel window */
+       pubvars->xtkwin = Tk_CreateWindowFromPath(interp,
+               tkwin, bu_vls_addr(&dmp->i->dm_pathName), 
bu_vls_addr(&dmp->i->dm_dName));
+       pubvars->top = pubvars->xtkwin;
+    } else {
+       char *cp;
+
+       cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
+       if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
+           pubvars->top = tkwin;
+       } else {
+           struct bu_vls top_vls = BU_VLS_INIT_ZERO;
+
+           bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
+
+           pubvars->top = Tk_NameToWindow(interp, bu_vls_addr(&top_vls), 
tkwin);
+           bu_vls_free(&top_vls);
+       }
+
+       /* Make xtkwin an embedded window */
+       pubvars->xtkwin =
+           Tk_CreateWindow(interp, pubvars->top,
+                           cp + 1, (char *)NULL);
+    }
+
+    if (pubvars->xtkwin == NULL) {
+       bu_log("tk_open: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
+       (void)tk_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_printf(&dmp->i->dm_tkName, "%s",
+                 (char *)Tk_Name(pubvars->xtkwin));
+
+    bu_vls_printf(&str, "_init_dm %s %s\n",
+                 bu_vls_addr(&init_proc_vls),
+                 bu_vls_addr(&dmp->i->dm_pathName));
+
+    if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
+       bu_vls_free(&str);
+       (void)tk_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_free(&init_proc_vls);
+    bu_vls_free(&str);
+
+    pubvars->dpy = Tk_Display(pubvars->top);
+    dpy = pubvars->dpy;
+
+    /* make sure there really is a display before proceeding. */
+    if (!dpy) {
+       (void)tk_close(dmp);
+       return DM_NULL;
+    }
+
+    if (dmp->i->dm_width == 0) {
+       dmp->i->dm_width =
+           WidthOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
+       ++make_square;
+    }
+
+    if (dmp->i->dm_height == 0) {
+       dmp->i->dm_height = HeightOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
+       ++make_square;
+    }
+
+    if (make_square > 0) {
+       /* Make window square */
+       if (dmp->i->dm_height <
+           dmp->i->dm_width)
+           dmp->i->dm_width = dmp->i->dm_height;
+       else
+           dmp->i->dm_height = dmp->i->dm_width;
+    }
+
+    Tk_GeometryRequest(pubvars->xtkwin,
+                      dmp->i->dm_width,
+                      dmp->i->dm_height);
+
+    Tk_MakeWindowExist(pubvars->xtkwin);
+    pubvars->win = Tk_WindowId(pubvars->xtkwin);
+    dmp->i->dm_id = pubvars->win;
+
+    privars->pix =
+       Tk_GetPixmap(pubvars->dpy,
+                    DefaultRootWindow(pubvars->dpy),
+                    dmp->i->dm_width,
+                    dmp->i->dm_height,
+                    Tk_Depth(pubvars->xtkwin));
+
+    fg.red = 65535;
+    fg.green = fg.blue = 0;
+
+    privars->fg = Tk_GetColorByValue(pubvars->xtkwin, &fg)->pixel;
+
+    bg.red = bg.green = bg.blue = 3277;
+
+    privars->bg = Tk_GetColorByValue(pubvars->xtkwin, &bg)->pixel;
+
+    gcv.background = privars->bg;
+    gcv.foreground = privars->fg;
+
+    privars->gc = Tk_GetGC(pubvars->xtkwin, (GCForeground|GCBackground), &gcv);
+
+    (void)tk_configureWin_guts(dmp, 1);
+
+    /*
+      Tk_SetWindowBackground(pubvars->xtkwin,
+      privars->bg);
+    */
+    Tk_MapWindow(pubvars->xtkwin);
+
+    MAT_IDN(privars->mod_mat);
+    MAT_IDN(privars->disp_mat);
+
+    privars->xmat = &(privars->mod_mat[0]);
+
+    return dmp;
+}
+
+
+
 /**
  * @proc tk_close
  *
@@ -909,6 +1106,7 @@
 }
 
 struct dm_impl dm_tk_impl = {
+    tk_open,
     tk_close,
     tk_drawBegin,
     tk_drawEnd,
@@ -1009,202 +1207,7 @@
 #endif
 
 
-/* Display Manager package interface */
 
-/*
- * Fire up the display manager, and the display processor.
- *
- */
-struct dm *
-tk_open_dm(void *vinterp, int argc, char **argv)
-{
-    static int count = 0;
-    int make_square = -1;
-    XGCValues gcv;
-    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
-
-    struct bu_vls str = BU_VLS_INIT_ZERO;
-    struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
-    struct dm *dmp = NULL;
-    struct dm_impl *dmp_impl = NULL;
-    Tk_Window tkwin;
-    Display *dpy = (Display *)NULL;
-    XColor fg, bg;
-
-    INIT_XCOLOR(&fg);
-    INIT_XCOLOR(&bg);
-
-    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
-       return DM_NULL;
-    }
-
-    BU_ALLOC(dmp, struct dm);
-    BU_ALLOC(dmp_impl, struct dm_impl);
-
-    *dmp_impl = *dm_tk.i; /* struct copy */
-    dmp->i = dmp_impl;
-    dmp->i->dm_interp = interp;
-
-    BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_tkvars);
-    struct dm_tkvars *pubvars = (struct dm_tkvars *)dmp->i->dm_vars.pub_vars;
-    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct tk_vars);
-    struct tk_vars *privars = (struct tk_vars *)dmp->i->dm_vars.priv_vars;
-
-    bu_vls_init(&dmp->i->dm_pathName);
-    bu_vls_init(&dmp->i->dm_tkName);
-    bu_vls_init(&dmp->i->dm_dName);
-
-    dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
-
-    if (bu_vls_strlen(&dmp->i->dm_pathName) == 0) {
-       bu_vls_printf(&dmp->i->dm_pathName, ".dm_tk%d", count);
-    }
-
-    ++count;
-    if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
-       char *dp;
-
-       dp = DisplayString(Tk_Display(tkwin));
-
-       if (dp)
-           bu_vls_strcpy(&dmp->i->dm_dName, dp);
-       else
-           bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
-    }
-    if (bu_vls_strlen(&init_proc_vls) == 0)
-       bu_vls_strcpy(&init_proc_vls, "bind_dm");
-
-    /* initialize dm specific variables */
-    pubvars->devmotionnotify = LASTEvent;
-    pubvars->devbuttonpress = LASTEvent;
-    pubvars->devbuttonrelease = LASTEvent;
-    dmp->i->dm_aspect = 1.0;
-
-    privars->tkfontset = 0;
-
-    if (dmp->i->dm_top) {
-       /* Make xtkwin a toplevel window */
-       pubvars->xtkwin = Tk_CreateWindowFromPath(interp,
-               tkwin, bu_vls_addr(&dmp->i->dm_pathName), 
bu_vls_addr(&dmp->i->dm_dName));
-       pubvars->top = pubvars->xtkwin;
-    } else {
-       char *cp;
-
-       cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
-       if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
-           pubvars->top = tkwin;
-       } else {
-           struct bu_vls top_vls = BU_VLS_INIT_ZERO;
-
-           bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
-
-           pubvars->top = Tk_NameToWindow(interp, bu_vls_addr(&top_vls), 
tkwin);
-           bu_vls_free(&top_vls);
-       }
-
-       /* Make xtkwin an embedded window */
-       pubvars->xtkwin =
-           Tk_CreateWindow(interp, pubvars->top,
-                           cp + 1, (char *)NULL);
-    }
-
-    if (pubvars->xtkwin == NULL) {
-       bu_log("tk_open: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
-       (void)tk_close(dmp);
-       return DM_NULL;
-    }
-
-    bu_vls_printf(&dmp->i->dm_tkName, "%s",
-                 (char *)Tk_Name(pubvars->xtkwin));
-
-    bu_vls_printf(&str, "_init_dm %s %s\n",
-                 bu_vls_addr(&init_proc_vls),
-                 bu_vls_addr(&dmp->i->dm_pathName));
-
-    if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
-       bu_vls_free(&str);
-       (void)tk_close(dmp);
-       return DM_NULL;
-    }
-
-    bu_vls_free(&init_proc_vls);
-    bu_vls_free(&str);
-
-    pubvars->dpy = Tk_Display(pubvars->top);
-    dpy = pubvars->dpy;
-
-    /* make sure there really is a display before proceeding. */
-    if (!dpy) {
-       (void)tk_close(dmp);
-       return DM_NULL;
-    }
-
-    if (dmp->i->dm_width == 0) {
-       dmp->i->dm_width =
-           WidthOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
-       ++make_square;
-    }
-
-    if (dmp->i->dm_height == 0) {
-       dmp->i->dm_height = HeightOfScreen(Tk_Screen(pubvars->xtkwin)) - 30;
-       ++make_square;
-    }
-
-    if (make_square > 0) {
-       /* Make window square */
-       if (dmp->i->dm_height <
-           dmp->i->dm_width)
-           dmp->i->dm_width = dmp->i->dm_height;
-       else
-           dmp->i->dm_height = dmp->i->dm_width;
-    }
-
-    Tk_GeometryRequest(pubvars->xtkwin,
-                      dmp->i->dm_width,
-                      dmp->i->dm_height);
-
-    Tk_MakeWindowExist(pubvars->xtkwin);
-    pubvars->win = Tk_WindowId(pubvars->xtkwin);
-    dmp->i->dm_id = pubvars->win;
-
-    privars->pix =
-       Tk_GetPixmap(pubvars->dpy,
-                    DefaultRootWindow(pubvars->dpy),
-                    dmp->i->dm_width,
-                    dmp->i->dm_height,
-                    Tk_Depth(pubvars->xtkwin));
-
-    fg.red = 65535;
-    fg.green = fg.blue = 0;
-
-    privars->fg = Tk_GetColorByValue(pubvars->xtkwin, &fg)->pixel;
-
-    bg.red = bg.green = bg.blue = 3277;
-
-    privars->bg = Tk_GetColorByValue(pubvars->xtkwin, &bg)->pixel;
-
-    gcv.background = privars->bg;
-    gcv.foreground = privars->fg;
-
-    privars->gc = Tk_GetGC(pubvars->xtkwin, (GCForeground|GCBackground), &gcv);
-
-    (void)tk_configureWin_guts(dmp, 1);
-
-    /*
-      Tk_SetWindowBackground(pubvars->xtkwin,
-      privars->bg);
-    */
-    Tk_MapWindow(pubvars->xtkwin);
-
-    MAT_IDN(privars->mod_mat);
-    MAT_IDN(privars->disp_mat);
-
-    privars->xmat = &(privars->mod_mat[0]);
-
-    return dmp;
-}
-
-
 #endif /* DM_TK */
 
 /*

Modified: brlcad/branches/dm-fb-merge/src/libdm/txt/dm-txt.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/txt/dm-txt.c  2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/txt/dm-txt.c  2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -42,8 +42,9 @@
        return DM_NULL;
 
     BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
 
-    *dmp = dm_txt;
+    *dmp->i = *dm_txt.i;
     dmp->i->dm_interp = interp;
 
     bu_log("open called\n");
@@ -53,9 +54,11 @@
 
 
 HIDDEN int
-txt_close(struct dm *UNUSED(dmp))
+txt_close(struct dm *dmp)
 {
     bu_log("close called\n");
+    bu_free(dmp->i, "dmp impl");
+    bu_free(dmp, "dmp");
     return 0;
 }
 
@@ -341,6 +344,7 @@
 
 
 struct dm_impl dm_txt_impl = {
+    txt_open,
     txt_close,
     txt_drawBegin,
     txt_drawEnd,

Modified: brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c  2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c  2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -368,7 +368,297 @@
     return BRLCAD_OK;
 }
 
+/*
+ * Fire up the display manager, and the display processor.
+ *
+ */
+struct dm *
+wgl_open(void *vinterp, int argc, char *argv[])
+{
+    static int count = 0;
+    GLfloat backgnd[4];
+    int make_square = -1;
+    struct bu_vls str = BU_VLS_INIT_ZERO;
+    struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
+    struct modifiable_ogl_vars *mvars = NULL;
+    struct dm *dmp = NULL;
+    Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+    Tk_Window tkwin;
+    HWND hwnd;
+    HDC hdc;
+    int gotvisual;
 
+    if ((tkwin = Tk_MainWindow(interp)) == NULL) {
+       return DM_NULL;
+    }
+
+    BU_ALLOC(dmp, struct dm);
+    BU_ALLOC(dmp->i, struct dm_impl);
+
+    *dmpi->i = *dm_wgl_impl; /* struct copy */
+    dmp->i->dm_interp = interp;
+    dmp->i->dm_light = 1;
+
+    BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_wglvars);
+    BU_ALLOC(dmp->i->dm_vars.priv_vars, struct wgl_vars);
+
+    dmp->i->dm_get_internal(dmp);
+    mvars = (struct modifiable_ogl_vars *)dmp->i->m_vars;
+
+    dmp->i->dm_vp = &default_viewscale;
+
+    bu_vls_init(&dmp->i->dm_pathName);
+    bu_vls_init(&dmp->i->dm_tkName);
+    bu_vls_init(&dmp->i->dm_dName);
+
+    dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
+
+    if (bu_vls_strlen(&dmp->i->dm_pathName) == 0)
+       bu_vls_printf(&dmp->i->dm_pathName, ".dm_wgl%d", count);
+    ++count;
+
+    if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
+       char *dp;
+
+       dp = getenv("DISPLAY");
+       if (dp)
+           bu_vls_strcpy(&dmp->i->dm_dName, dp);
+       else
+           bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
+    }
+    if (bu_vls_strlen(&init_proc_vls) == 0)
+       bu_vls_strcpy(&init_proc_vls, "bind_dm");
+
+    /* initialize dm specific variables */
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devmotionnotify = 
LASTEvent;
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonpress = 
LASTEvent;
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonrelease = 
LASTEvent;
+    dmp->i->dm_aspect = 1.0;
+
+    /* initialize modifiable variables */
+    mvars->rgb = 1;
+    mvars->doublebuffer = 1;
+    mvars->fastfog = 1;
+    mvars->fogdensity = 1.0;
+    mvars->lighting_on = dmp->i->dm_light;
+    mvars->zbuffer_on = dmp->i->dm_zbuffer;
+    mvars->zclipping_on = dmp->i->dm_zclip;
+    mvars->debug = dmp->i->dm_debugLevel;
+    mvars->bound = dmp->i->dm_bound;
+    mvars->boundFlag = dmp->i->dm_boundFlag;
+
+    /* this is important so that wgl_configureWin knows to set the font */
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->fontstruct = NULL;
+
+    if (dmp->i->dm_width == 0) {
+       dmp->i->dm_width = GetSystemMetrics(SM_CXSCREEN) - 30;
+       ++make_square;
+    }
+    if (dmp->i->dm_height == 0) {
+       dmp->i->dm_height = GetSystemMetrics(SM_CYSCREEN) - 30;
+       ++make_square;
+    }
+
+    if (make_square > 0) {
+       /* Make window square */
+       if (dmp->i->dm_height <
+               dmp->i->dm_width)
+           dmp->i->dm_width =
+               dmp->i->dm_height;
+       else
+           dmp->i->dm_height =
+               dmp->i->dm_width;
+    }
+
+    if (dmp->i->dm_top) {
+       /* Make xtkwin a toplevel window */
+       Tcl_DString ds;
+
+       Tcl_DStringInit(&ds);
+       Tcl_DStringAppend(&ds, "toplevel ", -1);
+       Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
+       Tcl_DStringAppend(&ds, "; wm deiconify ", -1);
+       Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
+       if (Tcl_Eval(interp, Tcl_DStringValue(&ds)) != BRLCAD_OK) {
+           Tcl_DStringFree(&ds);
+           return DM_NULL;
+       }
+       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
+           Tk_NameToWindow(interp, bu_vls_addr(&dmp->i->dm_pathName), tkwin);
+       Tcl_DStringFree(&ds);
+       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = ((struct 
dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin;
+    }
+    else {
+       char *cp;
+
+       cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
+       if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
+           ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = tkwin;
+       }
+       else {
+           struct bu_vls top_vls = BU_VLS_INIT_ZERO;
+
+           bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
+
+           ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top =
+               Tk_NameToWindow(interp, bu_vls_addr(&top_vls), tkwin);
+           bu_vls_free(&top_vls);
+       }
+
+       /* Make xtkwin an embedded window */
+       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
+           Tk_CreateWindow(interp, ((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->top,
+                   cp + 1, (char *)NULL);
+    }
+
+    if (((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin == NULL) {
+       bu_log("open_gl: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
+       bu_vls_free(&init_proc_vls);
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_printf(&dmp->i->dm_tkName, "%s",
+           (char *)Tk_Name(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin));
+
+    bu_vls_printf(&str, "_init_dm %s %s\n",
+           bu_vls_addr(&init_proc_vls),
+           bu_vls_addr(&dmp->i->dm_pathName));
+
+    if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
+       bu_log("open_wgl: _init_dm failed\n");
+       bu_vls_free(&init_proc_vls);
+       bu_vls_free(&str);
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    bu_vls_free(&init_proc_vls);
+    bu_vls_free(&str);
+
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy =
+       Tk_Display(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top);
+
+    /* make sure there really is a display before proceeding. */
+    if (!((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy) {
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    Tk_GeometryRequest(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin,
+           dmp->i->dm_width,
+           dmp->i->dm_height);
+
+    Tk_MakeWindowExist(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin);
+
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win =
+       Tk_WindowId(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
+    dmp->i->dm_id = ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win;
+
+    hwnd = TkWinGetHWND(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win);
+    hdc = GetDC(hwnd);
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc = hdc;
+
+    gotvisual = wgl_choose_visual(dmp, ((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin);
+    if (!gotvisual) {
+       bu_log("wgl_open: Can't get an appropriate visual.\n");
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->depth = mvars->depth;
+
+    /* open GLX context */
+    if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc =
+               wglCreateContext(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->hdc)) == NULL) {
+       bu_log("wgl_open: couldn't create glXContext.\n");
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    if (!wglMakeCurrent(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc,
+               ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc)) {
+       bu_log("wgl_open: couldn't make context current\n");
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    /* display list (fontOffset + char) will display a given ASCII char */
+    if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->fontOffset = 
glGenLists(128)) == 0) {
+       bu_log("wgl_open: couldn't make display lists for font.\n");
+       (void)wgl_close(dmp);
+       return DM_NULL;
+    }
+
+    /* This is the applications display list offset */
+    dmp->i->dm_displaylist = ((struct wgl_vars 
*)dmp->i->dm_vars.priv_vars)->fontOffset + 128;
+
+    wgl_setBGColor(dmp, 0, 0, 0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+    if (mvars->doublebuffer)
+       glDrawBuffer(GL_BACK);
+    else
+       glDrawBuffer(GL_FRONT);
+
+    /* do viewport, ortho commands and initialize font */
+    (void)wgl_configureWin_guts(dmp, 1);
+
+    /* Lines will be solid when stippling disabled, dashed when enabled*/
+    glLineStipple(1, 0xCF33);
+    glDisable(GL_LINE_STIPPLE);
+
+    backgnd[0] = backgnd[1] = backgnd[2] = backgnd[3] = 0.0;
+    glFogi(GL_FOG_MODE, GL_LINEAR);
+    glFogf(GL_FOG_START, 0.0);
+    glFogf(GL_FOG_END, 2.0);
+    glFogfv(GL_FOG_COLOR, backgnd);
+
+    /*XXX Need to do something about VIEWFACTOR */
+    glFogf(GL_FOG_DENSITY, VIEWFACTOR);
+
+    /* Initialize matrices */
+    /* Leave it in model_view mode normally */
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    glOrtho(-xlim_view, xlim_view, -ylim_view, ylim_view, 0.0, 2.0);
+    glGetDoublev(GL_PROJECTION_MATRIX, ((struct wgl_vars 
*)dmp->i->dm_vars.priv_vars)->faceplate_mat);
+    glPushMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+    glPushMatrix();
+    glLoadIdentity();
+    ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->face_flag = 1;     /* 
faceplate matrix is on top of stack */
+
+    wgl_setZBuffer(dmp, dmp->i->dm_zbuffer);
+    wgl_setLight(dmp, dmp->i->dm_light);
+
+    if (!wglMakeCurrent((HDC)NULL, (HGLRC)NULL)) {
+       LPVOID buf;
+
+       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+               FORMAT_MESSAGE_FROM_SYSTEM |
+               FORMAT_MESSAGE_IGNORE_INSERTS,
+               NULL,
+               GetLastError(),
+               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+               (LPTSTR)&buf,
+               0,
+               NULL);
+       bu_log("wgl_drawBegin: Couldn't release the current context.\n");
+       bu_log("wgl_drawBegin: %s", buf);
+       LocalFree(buf);
+
+       return DM_NULL;
+    }
+
+    Tk_MapWindow(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
+
+    Tk_CreateEventHandler(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc, 
(ClientData)dmp);
+
+    return dmp;
+}
+
 /*
  *  Gracefully release the display.
  */
@@ -2194,6 +2484,7 @@
 }
 
 struct dm_impl dm_wgl_impl = {
+    wgl_open,
     wgl_close,
     wgl_drawBegin,
     wgl_drawEnd,
@@ -2294,298 +2585,7 @@
 }
 #endif
 
-/*
- * Fire up the display manager, and the display processor.
- *
- */
-struct dm *
-       wgl_open(void *vinterp, int argc, char *argv[])
-{
-       static int count = 0;
-       GLfloat backgnd[4];
-       int make_square = -1;
-       struct bu_vls str = BU_VLS_INIT_ZERO;
-       struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
-       struct modifiable_ogl_vars *mvars = NULL;
-       struct dm *dmp = NULL;
-       struct dm_impl *dmpi = NULL;
-       Tcl_Interp *interp = (Tcl_Interp *)vinterp;
-       Tk_Window tkwin;
-       HWND hwnd;
-       HDC hdc;
-       int gotvisual;
 
-       if ((tkwin = Tk_MainWindow(interp)) == NULL) {
-               return DM_NULL;
-       }
-
-       BU_ALLOC(dmp, struct dm);
-       BU_ALLOC(dmpi, struct dm_impl);
-
-       (*dmpi) = dm_wgl_impl; /* struct copy */
-       dmp->i = dmpi;
-       dmp->i->dm_interp = interp;
-       dmp->i->dm_light = 1;
-
-       BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_wglvars);
-       BU_ALLOC(dmp->i->dm_vars.priv_vars, struct wgl_vars);
-
-       dmp->i->dm_get_internal(dmp);
-       mvars = (struct modifiable_ogl_vars *)dmp->i->m_vars;
-
-       dmp->i->dm_vp = &default_viewscale;
-
-       bu_vls_init(&dmp->i->dm_pathName);
-       bu_vls_init(&dmp->i->dm_tkName);
-       bu_vls_init(&dmp->i->dm_dName);
-
-       dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
-
-       if (bu_vls_strlen(&dmp->i->dm_pathName) == 0)
-               bu_vls_printf(&dmp->i->dm_pathName, ".dm_wgl%d", count);
-       ++count;
-
-       if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
-               char *dp;
-
-               dp = getenv("DISPLAY");
-               if (dp)
-                       bu_vls_strcpy(&dmp->i->dm_dName, dp);
-               else
-                       bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
-       }
-       if (bu_vls_strlen(&init_proc_vls) == 0)
-               bu_vls_strcpy(&init_proc_vls, "bind_dm");
-
-       /* initialize dm specific variables */
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devmotionnotify = 
LASTEvent;
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonpress = 
LASTEvent;
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonrelease = 
LASTEvent;
-       dmp->i->dm_aspect = 1.0;
-
-       /* initialize modifiable variables */
-       mvars->rgb = 1;
-       mvars->doublebuffer = 1;
-       mvars->fastfog = 1;
-       mvars->fogdensity = 1.0;
-       mvars->lighting_on = dmp->i->dm_light;
-       mvars->zbuffer_on = dmp->i->dm_zbuffer;
-       mvars->zclipping_on = dmp->i->dm_zclip;
-       mvars->debug = dmp->i->dm_debugLevel;
-       mvars->bound = dmp->i->dm_bound;
-       mvars->boundFlag = dmp->i->dm_boundFlag;
-
-       /* this is important so that wgl_configureWin knows to set the font */
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->fontstruct = NULL;
-
-       if (dmp->i->dm_width == 0) {
-               dmp->i->dm_width = GetSystemMetrics(SM_CXSCREEN) - 30;
-               ++make_square;
-       }
-       if (dmp->i->dm_height == 0) {
-               dmp->i->dm_height = GetSystemMetrics(SM_CYSCREEN) - 30;
-               ++make_square;
-       }
-
-       if (make_square > 0) {
-               /* Make window square */
-               if (dmp->i->dm_height <
-                       dmp->i->dm_width)
-                       dmp->i->dm_width =
-                       dmp->i->dm_height;
-               else
-                       dmp->i->dm_height =
-                       dmp->i->dm_width;
-       }
-
-       if (dmp->i->dm_top) {
-               /* Make xtkwin a toplevel window */
-               Tcl_DString ds;
-
-               Tcl_DStringInit(&ds);
-               Tcl_DStringAppend(&ds, "toplevel ", -1);
-               Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
-               Tcl_DStringAppend(&ds, "; wm deiconify ", -1);
-               Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
-               if (Tcl_Eval(interp, Tcl_DStringValue(&ds)) != BRLCAD_OK) {
-                       Tcl_DStringFree(&ds);
-                       return DM_NULL;
-               }
-               ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
-                       Tk_NameToWindow(interp, 
bu_vls_addr(&dmp->i->dm_pathName), tkwin);
-               Tcl_DStringFree(&ds);
-               ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = ((struct 
dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin;
-       }
-       else {
-               char *cp;
-
-               cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
-               if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
-                       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = 
tkwin;
-               }
-               else {
-                       struct bu_vls top_vls = BU_VLS_INIT_ZERO;
-
-                       bu_vls_strncpy(&top_vls, (const char 
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
-
-                       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top =
-                               Tk_NameToWindow(interp, bu_vls_addr(&top_vls), 
tkwin);
-                       bu_vls_free(&top_vls);
-               }
-
-               /* Make xtkwin an embedded window */
-               ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
-                       Tk_CreateWindow(interp, ((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->top,
-                               cp + 1, (char *)NULL);
-       }
-
-       if (((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin == NULL) {
-               bu_log("open_gl: Failed to open %s\n", 
bu_vls_addr(&dmp->i->dm_pathName));
-               bu_vls_free(&init_proc_vls);
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       bu_vls_printf(&dmp->i->dm_tkName, "%s",
-               (char *)Tk_Name(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin));
-
-       bu_vls_printf(&str, "_init_dm %s %s\n",
-               bu_vls_addr(&init_proc_vls),
-               bu_vls_addr(&dmp->i->dm_pathName));
-
-       if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
-               bu_log("open_wgl: _init_dm failed\n");
-               bu_vls_free(&init_proc_vls);
-               bu_vls_free(&str);
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       bu_vls_free(&init_proc_vls);
-       bu_vls_free(&str);
-
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy =
-               Tk_Display(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->top);
-
-       /* make sure there really is a display before proceeding. */
-       if (!((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy) {
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       Tk_GeometryRequest(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin,
-               dmp->i->dm_width,
-               dmp->i->dm_height);
-
-       Tk_MakeWindowExist(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin);
-
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win =
-               Tk_WindowId(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin);
-       dmp->i->dm_id = ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win;
-
-       hwnd = TkWinGetHWND(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->win);
-       hdc = GetDC(hwnd);
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc = hdc;
-
-       gotvisual = wgl_choose_visual(dmp, ((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin);
-       if (!gotvisual) {
-               bu_log("wgl_open: Can't get an appropriate visual.\n");
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->depth = mvars->depth;
-
-       /* open GLX context */
-       if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc =
-               wglCreateContext(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->hdc)) == NULL) {
-               bu_log("wgl_open: couldn't create glXContext.\n");
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       if (!wglMakeCurrent(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->hdc,
-               ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc)) {
-               bu_log("wgl_open: couldn't make context current\n");
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       /* display list (fontOffset + char) will display a given ASCII char */
-       if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->fontOffset = 
glGenLists(128)) == 0) {
-               bu_log("wgl_open: couldn't make display lists for font.\n");
-               (void)wgl_close(dmp);
-               return DM_NULL;
-       }
-
-       /* This is the applications display list offset */
-       dmp->i->dm_displaylist = ((struct wgl_vars 
*)dmp->i->dm_vars.priv_vars)->fontOffset + 128;
-
-       wgl_setBGColor(dmp, 0, 0, 0);
-       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-       if (mvars->doublebuffer)
-               glDrawBuffer(GL_BACK);
-       else
-               glDrawBuffer(GL_FRONT);
-
-       /* do viewport, ortho commands and initialize font */
-       (void)wgl_configureWin_guts(dmp, 1);
-
-       /* Lines will be solid when stippling disabled, dashed when enabled*/
-       glLineStipple(1, 0xCF33);
-       glDisable(GL_LINE_STIPPLE);
-
-       backgnd[0] = backgnd[1] = backgnd[2] = backgnd[3] = 0.0;
-       glFogi(GL_FOG_MODE, GL_LINEAR);
-       glFogf(GL_FOG_START, 0.0);
-       glFogf(GL_FOG_END, 2.0);
-       glFogfv(GL_FOG_COLOR, backgnd);
-
-       /*XXX Need to do something about VIEWFACTOR */
-       glFogf(GL_FOG_DENSITY, VIEWFACTOR);
-
-       /* Initialize matrices */
-       /* Leave it in model_view mode normally */
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       glOrtho(-xlim_view, xlim_view, -ylim_view, ylim_view, 0.0, 2.0);
-       glGetDoublev(GL_PROJECTION_MATRIX, ((struct wgl_vars 
*)dmp->i->dm_vars.priv_vars)->faceplate_mat);
-       glPushMatrix();
-       glMatrixMode(GL_MODELVIEW);
-       glLoadIdentity();
-       glPushMatrix();
-       glLoadIdentity();
-       ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->face_flag = 1;  /* 
faceplate matrix is on top of stack */
-
-       wgl_setZBuffer(dmp, dmp->i->dm_zbuffer);
-       wgl_setLight(dmp, dmp->i->dm_light);
-
-       if (!wglMakeCurrent((HDC)NULL, (HGLRC)NULL)) {
-               LPVOID buf;
-
-               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                       FORMAT_MESSAGE_FROM_SYSTEM |
-                       FORMAT_MESSAGE_IGNORE_INSERTS,
-                       NULL,
-                       GetLastError(),
-                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                       (LPTSTR)&buf,
-                       0,
-                       NULL);
-               bu_log("wgl_drawBegin: Couldn't release the current 
context.\n");
-               bu_log("wgl_drawBegin: %s", buf);
-               LocalFree(buf);
-
-               return DM_NULL;
-       }
-
-       Tk_MapWindow(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
-
-       Tk_CreateEventHandler(((struct dm_wglvars 
*)dmp->i->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc, 
(ClientData)dmp);
-
-       return dmp;
-}
 #endif /* DM_WGL */
 
 /*

Modified: brlcad/branches/dm-fb-merge/src/mged/attach.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/mged/attach.c       2020-04-21 11:00:00 UTC 
(rev 75486)
+++ brlcad/branches/dm-fb-merge/src/mged/attach.c       2020-04-21 12:23:34 UTC 
(rev 75487)
@@ -594,7 +594,7 @@
 
        opt_argc = argc - 1;
        opt_argv = bu_argv_dup(opt_argc, argv + 1);
-       dm_processOptions(tmp_dmp, &tmp_vls, opt_argc, opt_argv);
+       dm_processOptions(tmp_dmp, &tmp_vls, opt_argc, (const char **)opt_argv);
        bu_argv_free(opt_argc, opt_argv);
 
        if (dm_get_dname(tmp_dmp) && 
strlen(bu_vls_addr(dm_get_dname(tmp_dmp)))) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to