Skip to content

Commit

Permalink
Not fully correct yet, but first GUI window startup without GEDP global.
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Nov 4, 2024
1 parent e64c377 commit 839b291
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 59 deletions.
14 changes: 7 additions & 7 deletions src/mged/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ mged_dm_init(

#ifdef HAVE_TK
if (dm_graphical(DMP) && !BU_STR_EQUAL(dm_get_dm_name(DMP), "swrast")) {
Tk_DeleteGenericHandler(doEvent, (ClientData)NULL);
Tk_CreateGenericHandler(doEvent, (ClientData)NULL);
Tk_DeleteGenericHandler(doEvent, (ClientData)s);
Tk_CreateGenericHandler(doEvent, (ClientData)s);
}
#endif
(void)dm_configure_win(DMP, 0);
Expand Down Expand Up @@ -200,7 +200,7 @@ release(struct mged_state *s, char *name, int need_close)
if (mged_variables->mv_listen) {
/* drop all clients */
mged_variables->mv_listen = 0;
fbserv_set_port(s, NULL, NULL, NULL, NULL, NULL);
fbserv_set_port(NULL, NULL, NULL, NULL, s);
}

/* release framebuffer resources */
Expand Down Expand Up @@ -328,7 +328,7 @@ f_attach(ClientData clientData, Tcl_Interp *interpreter, int argc, const char *a


int
gui_setup(const char *dstr)
gui_setup(struct mged_state *s, const char *dstr)
{
#ifdef HAVE_TK
Tk_GenericProc *handler = doEvent;
Expand Down Expand Up @@ -393,7 +393,7 @@ gui_setup(const char *dstr)
}

/* create the event handler */
Tk_CreateGenericHandler(handler, (ClientData)NULL);
Tk_CreateGenericHandler(handler, (ClientData)s);

Tcl_Eval(INTERP, "wm withdraw .");
Tcl_Eval(INTERP, "tk appname mged");
Expand Down Expand Up @@ -436,14 +436,14 @@ mged_attach(struct mged_state *s, const char *wp_name, int argc, const char *arg

struct bu_vls *dname = dm_get_dname(tmp_dmp);
if (dname && bu_vls_strlen(dname)) {
if (gui_setup(bu_vls_cstr(dname)) == TCL_ERROR) {
if (gui_setup(s, bu_vls_cstr(dname)) == TCL_ERROR) {
bu_free((void *)mged_curr_dm, "f_attach: dm_list");
set_curr_dm(s, o_dm);
bu_vls_free(&tmp_vls);
dm_close(tmp_dmp);
return TCL_ERROR;
}
} else if (gui_setup((char *)NULL) == TCL_ERROR) {
} else if (gui_setup(s, (char *)NULL) == TCL_ERROR) {
bu_free((void *)mged_curr_dm, "f_attach: dm_list");
set_curr_dm(s, o_dm);
bu_vls_free(&tmp_vls);
Expand Down
8 changes: 6 additions & 2 deletions src/mged/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,12 @@ bv_zoomout(ClientData UNUSED(clientData), Tcl_Interp *UNUSED(interp), int UNUSED


int
bv_rate_toggle(ClientData UNUSED(clientData), Tcl_Interp *UNUSED(interp), int UNUSED(argc), char *UNUSED(argv[]))
bv_rate_toggle(ClientData clientData, Tcl_Interp *UNUSED(interp), int UNUSED(argc), char *UNUSED(argv[]))
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;

mged_variables->mv_rateknobs = !mged_variables->mv_rateknobs;

{
Expand All @@ -371,7 +375,7 @@ bv_rate_toggle(ClientData UNUSED(clientData), Tcl_Interp *UNUSED(interp), int UN
const char name[] = "name";
void *base = 0;
const char value[] = "value";
set_scroll_private(sdp, name, base, value, NULL);
set_scroll_private(sdp, name, base, value, s);
}

return TCL_OK;
Expand Down
10 changes: 7 additions & 3 deletions src/mged/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,12 @@ cmd_ged_dm_wrapper(ClientData clientData, Tcl_Interp *interpreter, int argc, con
* Usage: loadtk [displayname[.screennum]]
*/
int
cmd_tk(ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const char *argv[])
cmd_tk(ClientData clientData, Tcl_Interp *interpreter, int argc, const char *argv[])
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;

int status;

if (argc < 1 || 2 < argc) {
Expand All @@ -870,9 +874,9 @@ cmd_tk(ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const c
}

if (argc == 1)
status = gui_setup((char *)NULL);
status = gui_setup(s, (char *)NULL);
else
status = gui_setup(argv[1]);
status = gui_setup(s, argv[1]);

return status;
}
Expand Down
2 changes: 0 additions & 2 deletions src/mged/color_scheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ cs_update(const struct bu_structparse *sdp,
const char *value,
void *data)
{
struct cmdtab *ctp = (struct cmdtab *)data;
MGED_CK_CMD(ctp);
struct bu_structparse *sp;
struct bu_vls vls = BU_VLS_INIT_ZERO;
int offset;
Expand Down
4 changes: 1 addition & 3 deletions src/mged/doevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ static int button0 = 0;
int
doEvent(ClientData clientData, XEvent *eventPtr)
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;
struct mged_state *s = (struct mged_state *)clientData;
struct mged_dm *save_dm_list;
int status;

Expand Down
6 changes: 3 additions & 3 deletions src/mged/fbserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fbserv_new_client_handler(ClientData clientData,


void
fbserv_set_port(const struct bu_structparse *UNUSED(sp), const char *UNUSED(c1), void *UNUSED(v1), const char *UNUSED(c2), void *UNUSED(v2))
fbserv_set_port(const struct bu_structparse *UNUSED(sp), const char *UNUSED(c1), void *UNUSED(v1), const char *UNUSED(c2), void *v2)
{
int i;
int save_port;
Expand Down Expand Up @@ -440,7 +440,7 @@ fbserv_new_client_handler(ClientData clientData, int UNUSED(mask))


void
fbserv_set_port(struct mged_state *s, const struct bu_structparse *UNUSED(sp), const char *UNUSED(c1), void *UNUSED(v1), const char *UNUSED(c2), void *UNUSED(v2))
fbserv_set_port(const struct bu_structparse *UNUSED(sp), const char *UNUSED(c1), void *UNUSED(v1), const char *UNUSED(c2), void *v2)
{
int i;
int save_port;
Expand Down Expand Up @@ -499,7 +499,7 @@ fbserv_set_port(struct mged_state *s, const struct bu_structparse *UNUSED(sp), c
struct c_data *ncdata;
BU_GET(ncdata, struct c_data);
ncdata->fd = netfd;
ncdata->s = s;
ncdata->s = (struct mged_state *)v2;
Tcl_CreateFileHandler(netfd, TCL_READABLE,
fbserv_new_client_handler, (ClientData)ncdata);
}
Expand Down
8 changes: 6 additions & 2 deletions src/mged/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,12 @@ update_grids(fastf_t sf)


int
f_grid_set (ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const char *argv[])
f_grid_set (ClientData clientData, Tcl_Interp *interpreter, int argc, const char *argv[])
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;

struct bu_vls vls = BU_VLS_INIT_ZERO;

if (argc < 1 || 5 < argc) {
Expand All @@ -461,7 +465,7 @@ f_grid_set (ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, co
return TCL_ERROR;
}

mged_vls_struct_parse(&vls, "Grid", grid_vparse,
mged_vls_struct_parse(s, &vls, "Grid", grid_vparse,
(char *)grid_state, argc, argv);
Tcl_AppendResult(interpreter, bu_vls_addr(&vls), (char *)NULL);
bu_vls_free(&vls);
Expand Down
8 changes: 4 additions & 4 deletions src/mged/mged.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ int is_dm_null(void);
int mged_attach(struct mged_state *s, const char *wp_name, int argc, const char *argv[]);
void mged_link_vars(struct mged_dm *p);
void mged_slider_free_vls(struct mged_dm *p);
int gui_setup(const char *dstr);
int gui_setup(struct mged_state *s, const char *dstr);


/* buttons.c */
Expand Down Expand Up @@ -664,7 +664,7 @@ int epain(struct rt_db_internal *ip, fastf_t thick[2]);
int etoin(struct rt_db_internal *ip, fastf_t thick[1]);

/* set.c */
extern void fbserv_set_port(struct mged_state *s, const struct bu_structparse *, const char *, void *, const char *, void *);
extern void fbserv_set_port(const struct bu_structparse *, const char *, void *, const char *, void *);
extern void set_scroll_private(const struct bu_structparse *, const char *, void *, const char *, void *);
extern void mged_variable_setup(Tcl_Interp *interpreter);

Expand All @@ -687,8 +687,8 @@ struct wdb_pipe_pnt *pipe_del_pnt(struct wdb_pipe_pnt *);
void pipe_move_pnt(struct rt_pipe_internal *, struct wdb_pipe_pnt *, const point_t);

/* vparse.c */
extern void mged_vls_struct_parse(struct bu_vls *vls, const char *title, struct bu_structparse *how_to_parse, const char *structp, int argc, const char *argv[]); /* defined in vparse.c */
extern void mged_vls_struct_parse_old(struct bu_vls *vls, const char *title, struct bu_structparse *how_to_parse, char *structp, int argc, const char *argv[]);
extern void mged_vls_struct_parse(struct mged_state *s, struct bu_vls *vls, const char *title, struct bu_structparse *how_to_parse, const char *structp, int argc, const char *argv[]); /* defined in vparse.c */
extern void mged_vls_struct_parse_old(struct mged_state *s, struct bu_vls *vls, const char *title, struct bu_structparse *how_to_parse, char *structp, int argc, const char *argv[]);

/* rtif.c */
int build_tops(char **start, char **end);
Expand Down
4 changes: 2 additions & 2 deletions src/mged/scroll.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ sl_halt_scroll(int UNUSED(a), int UNUSED(b), int UNUSED(c))


void
sl_toggle_scroll(int UNUSED(a), int UNUSED(b), int UNUSED(c))
sl_toggle_scroll(struct mged_state *s, int UNUSED(a), int UNUSED(b), int UNUSED(c))
{
mged_variables->mv_sliders = mged_variables->mv_sliders ? 0 : 1;

Expand All @@ -141,7 +141,7 @@ sl_toggle_scroll(int UNUSED(a), int UNUSED(b), int UNUSED(c))
const char name[] = "name";
void *base = 0;
const char value[] = "value";
set_scroll_private(sdp, name, base, value, NULL);
set_scroll_private(sdp, name, base, value, s);
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/mged/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ mged_variable_setup(Tcl_Interp *interp)


int
f_set(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *argv[])
f_set(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;

struct bu_vls vls = BU_VLS_INIT_ZERO;

if (argc < 1 || 2 < argc) {
Expand All @@ -293,7 +297,7 @@ f_set(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, const char *a
return TCL_ERROR;
}

mged_vls_struct_parse_old(&vls, "mged variables", mged_vparse,
mged_vls_struct_parse_old(s, &vls, "mged variables", mged_vparse,
(char *)mged_variables, argc, argv);
Tcl_AppendResult(interp, bu_vls_addr(&vls), (char *)NULL);
bu_vls_free(&vls);
Expand All @@ -307,16 +311,17 @@ set_scroll_private(const struct bu_structparse *UNUSED(sdp),
const char *UNUSED(name),
void *UNUSED(base),
const char *UNUSED(value),
void *UNUSED(data))
void *data)
{
struct mged_state *s = (struct mged_state *)data;
struct mged_dm *save_m_dmp;

save_m_dmp = mged_curr_dm;

for (size_t di = 0; di < BU_PTBL_LEN(&active_dm_set); di++) {
struct mged_dm *m_dmp = (struct mged_dm *)BU_PTBL_GET(&active_dm_set, di);
if (m_dmp->dm_mged_variables == save_m_dmp->dm_mged_variables) {
set_curr_dm(m_dmp);
set_curr_dm(s, m_dmp);

if (mged_variables->mv_faceplate && mged_variables->mv_orig_gui) {
if (mged_variables->mv_sliders) /* zero slider variables */
Expand All @@ -329,7 +334,7 @@ set_scroll_private(const struct bu_structparse *UNUSED(sdp),
}
}

set_curr_dm(save_m_dmp);
set_curr_dm(s, save_m_dmp);
}


Expand Down Expand Up @@ -374,8 +379,9 @@ set_dlist(const struct bu_structparse *UNUSED(sdp),
const char *UNUSED(name),
void *UNUSED(base),
const char *UNUSED(value),
void *UNUSED(data))
void *data)
{
struct mged_state *s = (struct mged_state *)data;
struct mged_dm *save_dlp;

/* save current display manager */
Expand All @@ -395,8 +401,8 @@ set_dlist(const struct bu_structparse *UNUSED(sdp),

if (dm_get_displaylist(dlp1->dm_dmp) &&
dlp1->dm_dlist_state->dl_active == 0) {
set_curr_dm(dlp1);
createDLists(GEDP->ged_gdp->gd_headDisplay);
set_curr_dm(s, dlp1);
createDLists(s->GEDP->ged_gdp->gd_headDisplay);
dlp1->dm_dlist_state->dl_active = 1;
dlp1->dm_dirty = 1;
dm_set_dirty(dlp1->dm_dmp, 1);
Expand Down Expand Up @@ -439,8 +445,8 @@ set_dlist(const struct bu_structparse *UNUSED(sdp),

dlp1->dm_dlist_state->dl_active = 0;

gdlp = BU_LIST_NEXT(display_list, GEDP->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, GEDP->ged_gdp->gd_headDisplay)) {
gdlp = BU_LIST_NEXT(display_list, s->GEDP->ged_gdp->gd_headDisplay);
while (BU_LIST_NOT_HEAD(gdlp, s->GEDP->ged_gdp->gd_headDisplay)) {
next_gdlp = BU_LIST_PNEXT(display_list, gdlp);

(void)dm_make_current(dlp1->dm_dmp);
Expand All @@ -457,7 +463,7 @@ set_dlist(const struct bu_structparse *UNUSED(sdp),
}

/* restore current display manager */
set_curr_dm(save_dlp);
set_curr_dm(s, save_dlp);
}


Expand Down
2 changes: 1 addition & 1 deletion src/mged/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ mged_setup(Tcl_Interp **interpreter)

history_setup();
mged_global_variable_setup(*interpreter);
mged_variable_setup(s, *interpreter);
mged_variable_setup(*interpreter);
s->GEDP->cmd_interp = (void *)*interpreter;

/* Tcl needs to write nulls onto subscripted variable names */
Expand Down
26 changes: 15 additions & 11 deletions src/mged/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,29 @@ f_share(ClientData clientData, Tcl_Interp *interpreter, int argc, const char *ar
* rset c bg 0 0 50 ---> sets the background color to dark blue
*/
int
f_rset (ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const char *argv[])
f_rset (ClientData clientData, Tcl_Interp *interpreter, int argc, const char *argv[])
{
struct cmdtab *ctp = (struct cmdtab *)clientData;
MGED_CK_CMD(ctp);
struct mged_state *s = ctp->s;

struct bu_vls vls = BU_VLS_INIT_ZERO;

/* print values for all resources */
if (argc == 1) {
mged_vls_struct_parse(&vls, "Axes, res_type - ax", axes_vparse,
mged_vls_struct_parse(s, &vls, "Axes, res_type - ax", axes_vparse,
(const char *)axes_state, argc, argv);
bu_vls_printf(&vls, "\n");
mged_vls_struct_parse(&vls, "Color Schemes, res_type - c", color_scheme_vparse,
mged_vls_struct_parse(s, &vls, "Color Schemes, res_type - c", color_scheme_vparse,
(const char *)color_scheme, argc, argv);
bu_vls_printf(&vls, "\n");
mged_vls_struct_parse(&vls, "Grid, res_type - g", grid_vparse,
mged_vls_struct_parse(s, &vls, "Grid, res_type - g", grid_vparse,
(const char *)grid_state, argc, argv);
bu_vls_printf(&vls, "\n");
mged_vls_struct_parse(&vls, "Rubber Band, res_type - r", rubber_band_vparse,
mged_vls_struct_parse(s, &vls, "Rubber Band, res_type - r", rubber_band_vparse,
(const char *)rubber_band, argc, argv);
bu_vls_printf(&vls, "\n");
mged_vls_struct_parse(&vls, "MGED Variables, res_type - var", mged_vparse,
mged_vls_struct_parse(s, &vls, "MGED Variables, res_type - var", mged_vparse,
(const char *)mged_variables, argc, argv);

Tcl_AppendResult(interpreter, bu_vls_addr(&vls), (char *)NULL);
Expand All @@ -316,7 +320,7 @@ f_rset (ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const
if (argv[1][1] == 'd' || argv[1][1] == 'D')
bu_vls_printf(&vls, "rset: use the adc command for the 'adc' resource");
else if (argv[1][1] == 'x' || argv[1][1] == 'X')
mged_vls_struct_parse(&vls, "Axes", axes_vparse,
mged_vls_struct_parse(s, &vls, "Axes", axes_vparse,
(const char *)axes_state, argc-1, argv+1);
else {
bu_vls_printf(&vls, "rset: resource type '%s' unknown\n", argv[1]);
Expand All @@ -328,24 +332,24 @@ f_rset (ClientData UNUSED(clientData), Tcl_Interp *interpreter, int argc, const
break;
case 'c':
case 'C':
mged_vls_struct_parse(&vls, "Color Schemes", color_scheme_vparse,
mged_vls_struct_parse(s, &vls, "Color Schemes", color_scheme_vparse,
(const char *)color_scheme, argc-1, argv+1);
break;
case 'g':
case 'G':
mged_vls_struct_parse(&vls, "Grid", grid_vparse,
mged_vls_struct_parse(s, &vls, "Grid", grid_vparse,
(const char *)grid_state, argc-1, argv+1);
break;
case 'r':
case 'R':
mged_vls_struct_parse(&vls, "Rubber Band", rubber_band_vparse,
mged_vls_struct_parse(s, &vls, "Rubber Band", rubber_band_vparse,
(const char *)rubber_band, argc-1, argv+1);
break;
case 'v':
case 'V':
if ((argv[1][1] == 'a' || argv[1][1] == 'A') &&
(argv[1][2] == 'r' || argv[1][2] == 'R'))
mged_vls_struct_parse(&vls, "mged variables", mged_vparse,
mged_vls_struct_parse(s, &vls, "mged variables", mged_vparse,
(const char *)mged_variables, argc-1, argv+1);
else if (argv[1][1] == 'i' || argv[1][1] == 'I')
bu_vls_printf(&vls, "rset: no support available for the 'view' resource");
Expand Down
Loading

0 comments on commit 839b291

Please sign in to comment.