Skip to content

Commit

Permalink
Work towards eliminating mged_state in primitives dir
Browse files Browse the repository at this point in the history
Not compiling yet, since there is a lot to do here and some corner cases to
deal with, but checkpointing process towards pushing mged_state out of
primitives directory.
  • Loading branch information
starseeker committed Jan 28, 2025
1 parent ae965b3 commit b638e8f
Show file tree
Hide file tree
Showing 40 changed files with 2,398 additions and 2,391 deletions.
10 changes: 5 additions & 5 deletions src/mged/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ f_press(ClientData clientData,
/* It's up to the menu_func to set menu_state->ms_flag = 0
* if no arrow is desired */
if (mptr->menu_func != NULL)
(*(mptr->menu_func))(s, mptr->menu_arg, menu, item, s);
(*(mptr->menu_func))(s->s_edit, mptr->menu_arg, menu, item, s);

goto next;
}
Expand Down Expand Up @@ -846,7 +846,7 @@ be_reject(ClientData clientData, Tcl_Interp *UNUSED(interp), int UNUSED(argc), c
movedir = 0;
edsol = 0;
edobj = 0;
mged_set_edflag(s, -1);
mged_set_edflag(s->s_edit, -1);
illum_gdlp = GED_DISPLAY_LIST_NULL;
illump = NULL; /* None selected */

Expand Down Expand Up @@ -901,7 +901,7 @@ be_s_rotate(ClientData clientData, Tcl_Interp *UNUSED(interp), int UNUSED(argc),
if (not_state(s, ST_S_EDIT, "Primitive Rotate"))
return TCL_ERROR;

mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
edsol = BE_S_ROTATE;
mmenu_set(s, MENU_L1, NULL);

Expand All @@ -923,7 +923,7 @@ be_s_trans(ClientData clientData, Tcl_Interp *UNUSED(interp), int UNUSED(argc),
return TCL_ERROR;

edsol = BE_S_TRANS;
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
movedir = UARROW | RARROW;
mmenu_set(s, MENU_L1, NULL);

Expand All @@ -945,7 +945,7 @@ be_s_scale(ClientData clientData, Tcl_Interp *UNUSED(interp), int UNUSED(argc),
return TCL_ERROR;

edsol = BE_S_SCALE;
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
mmenu_set(s, MENU_L1, NULL);
s->s_edit->acc_sc_sol = 1.0;

Expand Down
2 changes: 2 additions & 0 deletions src/mged/chgtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ cmd_oed(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
s->s_edit = mged_solid_edit_create(NULL, &s->tol.tol, view_state->vs_gvp);
Tcl_LinkVar(s->interp, "edit_solid_flag", (char *)&s->s_edit->edit_flag, TCL_LINK_INT);
s->s_edit->mv_context = mged_variables->mv_context;
s->s_edit->local2base = s->dbip->dbi_local2base;
s->s_edit->base2local = s->dbip->dbi_base2local;
mged_sedit_clbk_sync(s->s_edit, s);

/* Patterned after ill_common() ... */
Expand Down
8 changes: 5 additions & 3 deletions src/mged/chgview.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,8 @@ f_sed(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
s->s_edit = mged_solid_edit_create(NULL, &s->tol.tol, view_state->vs_gvp);
Tcl_LinkVar(s->interp, "edit_solid_flag", (char *)&s->s_edit->edit_flag, TCL_LINK_INT);
s->s_edit->mv_context = mged_variables->mv_context;
s->s_edit->local2base = s->dbip->dbi_local2base;
s->s_edit->base2local = s->dbip->dbi_base2local;
mged_sedit_clbk_sync(s->s_edit, s);

/* Common part of illumination */
Expand Down Expand Up @@ -3248,7 +3250,7 @@ mged_erot(struct mged_state *s,
save_pic = s->s_edit->solid_edit_pick;

if (!SEDIT_ROTATE) {
mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
}

s->s_edit->e_inpara = 0;
Expand Down Expand Up @@ -3650,7 +3652,7 @@ mged_etran(struct mged_state *s,


if (!SEDIT_TRAN) {
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
}

VADD2(s->s_edit->e_para, delta, s->s_edit->curr_e_axes_pos);
Expand Down Expand Up @@ -3798,7 +3800,7 @@ mged_escale(struct mged_state *s, fastf_t sfactor)
save_pic = s->s_edit->solid_edit_pick;

if (!SEDIT_SCALE) {
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
}

s->s_edit->es_scale = sfactor;
Expand Down
2 changes: 1 addition & 1 deletion src/mged/dm-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ common_dm(struct mged_state *s, int argc, const char *argv[])
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_TRAN)
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
} else {
save_edflag = edobj;
edobj = BE_O_XY;
Expand Down
24 changes: 12 additions & 12 deletions src/mged/doevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_ROTATE)
mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
} else {
save_edflag = edobj;
edobj = BE_O_ROTATE;
Expand Down Expand Up @@ -290,7 +290,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_TRAN)
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
} else {
save_edflag = edobj;
edobj = BE_O_XY;
Expand Down Expand Up @@ -358,7 +358,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_tra = s->s_edit->solid_edit_translate;
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_SCALE) {
save_edflag = edobj;
edobj = BE_O_SCALE;
Expand Down Expand Up @@ -421,7 +421,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_ROTATE)
mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
} else {
save_edflag = edobj;
edobj = BE_O_ROTATE;
Expand Down Expand Up @@ -450,7 +450,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_ROTATE)
mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
} else {
save_edflag = edobj;
edobj = BE_O_ROTATE;
Expand Down Expand Up @@ -479,7 +479,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_ROTATE)
mged_set_edflag(s, SROT);
mged_set_edflag(s->s_edit, SROT);
} else {
save_edflag = edobj;
edobj = BE_O_ROTATE;
Expand Down Expand Up @@ -508,7 +508,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_TRAN)
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_TRAN) {
save_edflag = edobj;
edobj = BE_O_X;
Expand Down Expand Up @@ -536,7 +536,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_TRAN)
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_TRAN) {
save_edflag = edobj;
edobj = BE_O_Y;
Expand Down Expand Up @@ -564,7 +564,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_TRAN)
mged_set_edflag(s, STRANS);
mged_set_edflag(s->s_edit, STRANS);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_TRAN) {
save_edflag = edobj;
edobj = BE_O_XY;
Expand Down Expand Up @@ -592,7 +592,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_SCALE)
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_SCALE) {
save_edflag = edobj;
edobj = BE_O_XSCALE;
Expand Down Expand Up @@ -620,7 +620,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_SCALE)
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_SCALE) {
save_edflag = edobj;
edobj = BE_O_YSCALE;
Expand Down Expand Up @@ -648,7 +648,7 @@ motion_event_handler(struct mged_state *s, XMotionEvent *xmotion)
save_sca = s->s_edit->solid_edit_scale;
save_pic = s->s_edit->solid_edit_pick;
if (!SEDIT_SCALE)
mged_set_edflag(s, SSCALE);
mged_set_edflag(s->s_edit, SSCALE);
} else if (s->edit_state.global_editing_state == ST_O_EDIT && !OEDIT_SCALE) {
save_edflag = edobj;
edobj = BE_O_ZSCALE;
Expand Down
24 changes: 12 additions & 12 deletions src/mged/edsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ set_e_axes_pos(int UNUSED(ac), const char **UNUSED(av), void *d, void *id)

if (MGED_OBJ[ip->idb_type].ft_e_axes_pos) {
bu_vls_trunc(s->s_edit->log_str, 0);
(*MGED_OBJ[ip->idb_type].ft_e_axes_pos)(s, ip, &s->tol.tol);
(*MGED_OBJ[ip->idb_type].ft_e_axes_pos)(s->s_edit, ip, &s->tol.tol);
if (bu_vls_strlen(s->s_edit->log_str)) {
Tcl_AppendResult(s->interp, bu_vls_cstr(s->s_edit->log_str), (char *)NULL);
bu_vls_trunc(s->s_edit->log_str, 0);
Expand Down Expand Up @@ -252,7 +252,7 @@ init_sedit(struct mged_state *s)

// TODO - indicates we need per-primitive init of sedit state
if (id == ID_BSPLINE) {
bspline_init_sedit(s);
bspline_init_sedit(s->s_edit);
}

/* Save aggregate path matrix */
Expand All @@ -279,7 +279,7 @@ init_sedit(struct mged_state *s)
/* Finally, enter solid edit state */
(void)chg_state(s, ST_S_PICK, ST_S_EDIT, "Keyboard illuminate");
chg_l2menu(s, ST_S_EDIT);
mged_set_edflag(s, IDLE);
mged_set_edflag(s->s_edit, IDLE);

button(s, BE_S_EDIT); /* Drop into edit menu right away */
init_sedit_vars(s);
Expand Down Expand Up @@ -403,7 +403,7 @@ sedit_menu(struct mged_state *s) {
mmenu_set_all(s, MENU_L1, mi);
}

mged_set_edflag(s, IDLE); /* Drop out of previous edit mode */
mged_set_edflag(s->s_edit, IDLE); /* Drop out of previous edit mode */
s->s_edit->edit_menu = 0;
}

Expand Down Expand Up @@ -495,7 +495,7 @@ sedit(struct mged_solid_edit *s)
const struct rt_db_internal *ip = &s->es_int;
if (MGED_OBJ[ip->idb_type].ft_edit) {
bu_vls_trunc(s->log_str, 0);
if ((*MGED_OBJ[ip->idb_type].ft_edit)(MGED_STATE, s->edit_flag)) {
if ((*MGED_OBJ[ip->idb_type].ft_edit)(s, s->edit_flag)) {
if (bu_vls_strlen(s->log_str)) {
mged_sedit_clbk_get(&f, &d, s, ECMD_PRINT_STR, 0, GED_CLBK_DURING);
if (f)
Expand Down Expand Up @@ -584,7 +584,7 @@ sedit_mouse(struct mged_state *s, const vect_t mousevec)
const struct rt_db_internal *ip = &s->s_edit->es_int;
if (MGED_OBJ[ip->idb_type].ft_edit_xy) {
bu_vls_trunc(s->s_edit->log_str, 0);
(*MGED_OBJ[ip->idb_type].ft_edit_xy)(s, s->s_edit->edit_flag, mousevec);
(*MGED_OBJ[ip->idb_type].ft_edit_xy)(s->s_edit, s->s_edit->edit_flag, mousevec);
if (bu_vls_strlen(s->s_edit->log_str)) {
Tcl_AppendResult(s->interp, bu_vls_cstr(s->s_edit->log_str), (char *)NULL);
bu_vls_trunc(s->s_edit->log_str, 0);
Expand Down Expand Up @@ -716,7 +716,7 @@ objedit_mouse(struct mged_state *s, const vect_t mousevec)
MAT_IDN(s->s_edit->incr_change);
new_edit_mats(s);

update_edit_absolute_tran(s, pos_view);
update_edit_absolute_tran(s->s_edit, pos_view);
} else {
Tcl_AppendResult(s->interp, "No object edit mode selected; mouse press ignored\n", (char *)NULL);
return;
Expand Down Expand Up @@ -841,7 +841,7 @@ init_oedit_guts(struct mged_state *s)

/* for safety sake */
s->s_edit->edit_menu = 0;
mged_set_edflag(s, -1);
mged_set_edflag(s->s_edit, -1);
MAT_IDN(s->s_edit->e_mat);

if (s->dbip == DBI_NULL || !illump) {
Expand Down Expand Up @@ -1091,7 +1091,7 @@ f_eqn(ClientData clientData, Tcl_Interp *UNUSED(interp), int argc, const char *a
return TCL_ERROR;
}

int ret = arb_f_eqn(s, argc, argv);
int ret = arb_f_eqn(s->s_edit, argc, argv);
if (ret != TCL_OK)
return ret;

Expand Down Expand Up @@ -1197,7 +1197,7 @@ sedit_apply(struct mged_state *s, int accept_flag)
if (accept_flag) {
menu_state->ms_flag = 0;
movedir = 0;
mged_set_edflag(s, -1);
mged_set_edflag(s->s_edit, -1);
s->edit_state.e_edclass = EDIT_CLASS_NULL;

rt_db_free_internal(&s->s_edit->es_int);
Expand Down Expand Up @@ -1310,7 +1310,7 @@ sedit_reject(struct mged_state *s)

menu_state->ms_flag = 0;
movedir = 0;
mged_set_edflag(s, -1);
mged_set_edflag(s->s_edit, -1);
s->edit_state.e_edclass = EDIT_CLASS_NULL;

rt_db_free_internal(&s->s_edit->es_int);
Expand Down Expand Up @@ -2047,7 +2047,7 @@ f_edgedir(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[
if (not_state(s, ST_S_EDIT, "Edgedir"))
return TCL_ERROR;

return arb_edgedir(s, argc, argv);
return arb_edgedir(s->s_edit, argc, argv);
}

/* Permute command - permute the vertex labels of an ARB
Expand Down
17 changes: 9 additions & 8 deletions src/mged/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
#include "ged.h"


extern void sl_halt_scroll(struct mged_state *s, int, int, int, void *); /* in scroll.c */
extern void sl_halt_scroll(struct mged_solid_edit *, int, int, int, void *); /* in scroll.c */
extern void sl_toggle_scroll(struct mged_solid_edit *, int, int, int, void *);

extern void sl_toggle_scroll(struct mged_state *s, int, int, int, void *);

void btn_head_menu(struct mged_state *s, int i, int menu, int item, void *data);
void btn_item_hit(struct mged_state *s, int arg, int menu, int item, void *data);
void btn_head_menu(struct mged_solid_edit *s, int i, int menu, int item, void *data);
void btn_item_hit(struct mged_solid_edit *s, int arg, int menu, int item, void *data);

struct menu_item first_menu[] = {
{ "BUTTON MENU", btn_head_menu, 1 }, /* chg to 2nd menu */
Expand Down Expand Up @@ -96,8 +95,9 @@ struct menu_item oed_menu[] = {
* Called when a menu item is hit
*/
void
btn_item_hit(struct mged_state *s, int arg, int menu, int UNUSED(item), void *UNUSED(data))
btn_item_hit(struct mged_solid_edit *UNUSED(es), int arg, int menu, int UNUSED(item), void *data)
{
struct mged_state *s = (struct mged_state *)data;
button(s, arg);
if (menu == MENU_GEN &&
(arg != BE_O_ILLUMINATE && arg != BE_S_ILLUMINATE))
Expand All @@ -109,8 +109,9 @@ btn_item_hit(struct mged_state *s, int arg, int menu, int UNUSED(item), void *UN
* Also called from main() with arg 0 in init.
*/
void
btn_head_menu(struct mged_state *s, int i, int UNUSED(menu), int UNUSED(item), void *UNUSED(data))
btn_head_menu(struct mged_solid_edit *UNUSED(es), int i, int UNUSED(menu), int UNUSED(item), void *data)
{
struct mged_state *s = (struct mged_state *)data;
switch (i) {
case 0:
mmenu_set(s, MENU_GEN, first_menu);
Expand Down Expand Up @@ -441,7 +442,7 @@ mmenu_select(struct mged_state *s, int pen_y, int do_func)
/* It's up to the menu_func to set menu_state->ms_flag=0
* if no arrow is desired */
if (do_func && mptr->menu_func != NULL)
(*(mptr->menu_func))(s, mptr->menu_arg, menu, item, s);
(*(mptr->menu_func))(s->s_edit, mptr->menu_arg, menu, item, s);

return 1; /* menu claims pen value */
}
Expand Down
6 changes: 4 additions & 2 deletions src/mged/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

__BEGIN_DECLS

struct mged_solid_edit;

/* Menu structures and defines
*
* Each active menu is installed by having a non-null entry in
Expand All @@ -36,7 +38,7 @@ __BEGIN_DECLS
*/
struct menu_item {
char *menu_string;
void (*menu_func)(struct mged_state *, int, int, int, void *);
void (*menu_func)(struct mged_solid_edit *, int, int, int, void *);
int menu_arg;
};

Expand All @@ -62,7 +64,7 @@ struct menu_item {
extern struct menu_item sed_menu[];
extern struct menu_item oed_menu[];

void btn_head_menu(struct mged_state *s, int i, int menu, int item, void *data);
void btn_head_menu(struct mged_solid_edit *s, int i, int menu, int item, void *data);
void chg_l2menu(struct mged_state *s, int i);

extern void mmenu_init(struct mged_state *s);
Expand Down
Loading

0 comments on commit b638e8f

Please sign in to comment.