Skip to content

Commit

Permalink
Minimize use of env vars for new cmd behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Mar 10, 2025
1 parent dc99c84 commit 8ac6b3a
Show file tree
Hide file tree
Showing 43 changed files with 816 additions and 832 deletions.
5 changes: 5 additions & 0 deletions include/ged/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ struct ged {
// bv.h gv_callback (only used by MGED?)

void *ged_interp; /* Temporary - do not rely on when designing new functionality */

// The following is used instead of environment variables to select old or new
// command paths. Primarily relates to the next generation drawing setup with
// view objects and the new BoT LoD logic.
int new_cmd_forms;
};

// Create and destroy a ged container. Handles all initialization - no
Expand Down
21 changes: 10 additions & 11 deletions src/gtools/gsh/gsh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ Gsh_ClearScreen(int UNUSED(ac), const char **UNUSED(av), void *UNUSED(gedp), voi

GshState::GshState()
{
const char *ncmd = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(ncmd, "1"))
new_cmd_forms = true;

BU_GET(gedp, struct ged);
ged_init(gedp);
BU_GET(gedp->ged_gvp, struct bview);
Expand Down Expand Up @@ -740,13 +736,6 @@ main(int argc, const char **argv)
bu_exit(EXIT_SUCCESS, NULL);
}

/* If we're using new (qged style) commands, set the relevant env variables.
* Do this *before* we create the GshState instance. */
if (new_cmd_forms) {
bu_setenv("LIBGED_DBI_STATE", "1", 1);
bu_setenv("GED_TEST_NEW_CMD_FORMS", "1", 1);
}

/* If anything went wrong during LIBGED initialization, let the user know */
const char *ged_init_str = ged_init_msgs();
if (strlen(ged_init_str)) {
Expand All @@ -756,6 +745,16 @@ main(int argc, const char **argv)
// Use a C++ class to manage info we will need
std::shared_ptr<GshState> gs = std::make_shared<GshState>();

// If we're using the new command forms, there's a little bit
// of setup to do at the moment (eventually, once this cmd
// behavior is the default, ged setup will do this automatically)
gs->new_cmd_forms = (new_cmd_forms) ? true : false;
if (gs->new_cmd_forms) {
gs->gedp->dbi_state = new DbiState(gs->gedp);
gs->gedp->new_cmd_forms = 1;
bu_setenv("DM_SWRAST", "1", 1);
}

// If we're non-interactive, just evaluate and exit without getting into
// linenoise and threading. First, see if we've got a viable .g file.
if (argc && bu_file_exists(argv[0], NULL)) {
Expand Down
4 changes: 2 additions & 2 deletions src/libdm/dm_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ dm_list_types(struct bu_vls *list, const char *separator)
}

/* Report anything not included in the priority list but still available */
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
const char *cmd2 = getenv("DM_SWRAST");
int report_swrast = 0;
if (BU_STR_EQUAL(cmd2, "1"))
report_swrast = 1;
Expand Down Expand Up @@ -196,7 +196,7 @@ dm_validXType(const char *dpy_string, const char *name)
return 0;
}

const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
const char *cmd2 = getenv("DM_SWRAST");
int report_swrast = 0;
if (BU_STR_EQUAL(cmd2, "1"))
report_swrast = 1;
Expand Down
3 changes: 1 addition & 2 deletions src/libged/bot/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,8 @@ _bot_cmd_sync(void *bs, int argc, const char **argv)
static void
_bot_vlblock_plot(struct ged *gedp, struct bv_vlblock *vbp, const char *sname)
{
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
struct bview *view = gedp->ged_gvp;
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bu_vls nroot = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&nroot, "bot::%s", sname);
bv_vlblock_obj(vbp, view, bu_vls_cstr(&nroot));
Expand Down
3 changes: 1 addition & 2 deletions src/libged/bot/bot_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ show_dangling_edges(struct ged *gedp, const uint32_t *magic_p, const char *name,

if (out_type == 1) {
/* Add overlay */
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bu_vls nroot = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&nroot, "bot_fuse::%s", name);
struct bview *view = gedp->ged_gvp;
Expand Down
3 changes: 1 addition & 2 deletions src/libged/bot/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ draw_edges(struct ged *gedp, struct rt_bot_internal *bot, int num_edges, int edg
BV_ADD_VLIST(vbp->free_vlist_hd, vhead, b, BV_VLIST_LINE_DRAW);
}

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bu_vls nroot = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&nroot, "bot_check::%s", draw_name);
struct bview *view = gedp->ged_gvp;
Expand Down
3 changes: 1 addition & 2 deletions src/libged/brep/brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ _brep_cmd_intersect(void *bs, int argc, const char **argv)
bu_vls_printf(gedp->ged_result_str, "Invalid intersection type %s.\n", argv[6]);
}

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(gb->vbp, view, "brep_intersect");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/brep/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,8 @@ plot_nurbs_cv(struct bu_list *vlfree, struct bv_vlblock *vbp, int ucount, int vc
static void
_brep_vlblock_plot(struct ged *gedp, struct bv_vlblock *vbp, const char *sname)
{
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
struct bview *view = gedp->ged_gvp;
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bu_vls nroot = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&nroot, "brep::%s", sname);
bv_vlblock_obj(vbp, view, bu_vls_cstr(&nroot));
Expand Down
3 changes: 1 addition & 2 deletions src/libged/check/check_overlaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ int check_overlaps(struct ged *gedp, struct current_state *state,
printOverlaps(gedp, &callbackdata, options);

if (options->overlaps_overlay_flag) {
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(check_plot.vbp, view, "check::overlaps");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/close/close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ ged_close_core(struct ged *gedp, int UNUSED(argc), const char **UNUSED(argv))
gedp->dbip = NULL;

/* Clean up any old acceleration states, if present */
const char *use_dbi_state = getenv("LIBGED_DBI_STATE");
if (use_dbi_state && gedp->dbi_state)
if (gedp->dbi_state)
delete gedp->dbi_state;
gedp->dbi_state = NULL;
if (gedp->ged_lod)
Expand Down
6 changes: 2 additions & 4 deletions src/libged/draw/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1628,8 +1628,7 @@ extern int ged_draw2_core(struct ged *gedp, int argc, const char *argv[]);
int
ged_draw_core(struct ged *gedp, int argc, const char *argv[])
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1"))
if (gedp->new_cmd_forms)
return ged_draw2_core(gedp, argc, argv);

return ged_draw_guts(gedp, argc, argv, _GED_DRAW_WIREFRAME);
Expand All @@ -1646,8 +1645,7 @@ extern int ged_redraw2_core(struct ged *gedp, int argc, const char *argv[]);
int
ged_redraw_core(struct ged *gedp, int argc, const char *argv[])
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1"))
if (gedp->new_cmd_forms)
return ged_redraw2_core(gedp, argc, argv);

int ret;
Expand Down
3 changes: 1 addition & 2 deletions src/libged/draw/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ ged_preview_core(struct ged *gedp, int argc, const char *argv[])
fp = NULL;

if (draw_eye_path) {
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(preview_vbp, view, "preview::eye_path");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,8 +1972,7 @@ extern int ged_edit2_core(struct ged *gedp, int argc, const char *argv[]);
int
ged_edit_core(struct ged *gedp, int argc, const char *argv[])
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1"))
if (gedp->new_cmd_forms)
return ged_edit2_core(gedp, argc, argv);

const char *const cmd_name = argv[0];
Expand Down
3 changes: 1 addition & 2 deletions src/libged/erase/erase.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ extern int ged_erase2_core(struct ged *gedp, int argc, const char **argv);
int
ged_erase_core(struct ged *gedp, int argc, const char *argv[])
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1"))
if (gedp->new_cmd_forms)
return ged_erase2_core(gedp, argc, argv);

size_t i;
Expand Down
4 changes: 1 addition & 3 deletions src/libged/garbage_collect/garbage_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ extern "C" int
ged_garbage_collect_core(struct ged *gedp, int argc, const char *argv[])
{
const char *av[10] = {NULL};
const char *ncmd = NULL;
fastf_t fs_percent = 0.0;
int confirmed = 0;
int new_file_size = 0;
Expand Down Expand Up @@ -154,8 +153,7 @@ ged_garbage_collect_core(struct ged *gedp, int argc, const char *argv[])
* views to their original state when we open the garbage collected
* database. Save the who list. (TODO - do we need to save views? Or
* will drawing without resize work?) */
ncmd = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(ncmd, "1")) {
if (gedp->new_cmd_forms) {
BViewState *bvs = gedp->dbi_state->get_view_state(gedp->ged_gvp);
std::vector<std::string> wpaths = bvs->list_drawn_paths(-1, false);
for (size_t i = 0; i < wpaths.size(); i++) {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/gdiff/gdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ ged_gdiff_core(struct ged *gedp, int argc, const char *argv[])
}
}

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(vbp, view, "gdiff");
} else {
Expand Down
9 changes: 2 additions & 7 deletions src/libged/ged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ ged_init(struct ged *gedp)
gedp->dbi_state = NULL;

gedp->ged_interp = NULL;

gedp->new_cmd_forms = 0;
}

struct ged *
Expand Down Expand Up @@ -369,13 +371,6 @@ ged_open(const char *dbtype, const char *filename, int existing_only)

gedp->ged_lod = bv_mesh_lod_context_create(filename);

const char *use_dbi_state = getenv("LIBGED_DBI_STATE");
if (use_dbi_state) {
gedp->dbi_state = new DbiState(gedp);
} else {
gedp->dbi_state = NULL;
}

return gedp;
}

Expand Down
29 changes: 13 additions & 16 deletions src/libged/ged_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,7 @@ ged_scale_args(struct ged *gedp, int argc, const char *argv[], fastf_t *sf1, fas
size_t
ged_who_argc(struct ged *gedp)
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1")) {
if (gedp->new_cmd_forms) {
if (!gedp || !gedp->ged_gvp || !gedp->dbi_state)
return 0;
BViewState *bvs = gedp->dbi_state->get_view_state(gedp->ged_gvp);
Expand Down Expand Up @@ -1100,9 +1099,10 @@ int
ged_who_argv(struct ged *gedp, char **start, const char **end)
{
char **vp = start;
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1")) {
if (!gedp || !gedp->ged_gvp || !gedp->dbi_state)
if (!gedp)
return 0;
if (gedp->new_cmd_forms) {
if (!gedp->ged_gvp || !gedp->dbi_state)
return 0;
BViewState *bvs = gedp->dbi_state->get_view_state(gedp->ged_gvp);
if (bvs) {
Expand Down Expand Up @@ -1427,8 +1427,7 @@ _ged_rt_set_eye_model(struct ged *gedp,
extremum[1][i] = -INFINITY;
}

const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1")) {
if (gedp->new_cmd_forms) {
VSETALL(extremum[0], INFINITY);
VSETALL(extremum[1], -INFINITY);
struct bu_ptbl *db_objs = bv_view_objs(gedp->ged_gvp, BV_DB_OBJS);
Expand Down Expand Up @@ -1578,16 +1577,16 @@ ged_rt_output_handler_helper(struct ged_subprocess* rrtp, bu_process_io_t type)
void
_ged_rt_output_handler(void *clientData, int mask)
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1")) {
_ged_rt_output_handler2(clientData, mask);
return;
}
struct ged_subprocess *rrtp = (struct ged_subprocess *)clientData;

if ((rrtp == (struct ged_subprocess *)NULL) || (rrtp->gedp == (struct ged *)NULL))
return;

struct ged *gedp = rrtp->gedp;
if (gedp->new_cmd_forms) {
_ged_rt_output_handler2(clientData, mask);
return;
}

BU_CKMAG(rrtp, GED_CMD_MAGIC, "ged subprocess");

/* Get data from rt */
Expand All @@ -1597,7 +1596,6 @@ _ged_rt_output_handler(void *clientData, int mask)
return;

int retcode = 0;
struct ged *gedp = rrtp->gedp;

/* Either EOF has been sent or there was a read error.
* there is no need to block indefinitely */
Expand Down Expand Up @@ -1721,8 +1719,7 @@ _ged_rt_write(struct ged *gedp,
* remove the -1 case.) */
if (argc >= 0) {
if (!argc) {
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1")) {
if (gedp->new_cmd_forms) {
BViewState *bvs = gedp->dbi_state->get_view_state(gedp->ged_gvp);
if (bvs) {
std::vector<std::string> drawn_paths = bvs->list_drawn_paths(-1, true);
Expand Down
3 changes: 1 addition & 2 deletions src/libged/gqa/gqa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,8 +2722,7 @@ ged_gqa_core(struct ged *gedp, int argc, const char *argv[])
summary_reports(gedp, &state);

if (analysis_flags & ANALYSIS_PLOT_OVERLAPS) {
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(ged_gqa_plot.vbp, view, "gqa::overlaps");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/joint/joint.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ joint_mesh(struct ged *gedp, int argc, const char *argv[])
}
}

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(vbp, view, "joint");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/lint/lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,8 @@ ged_lint_core(struct ged *gedp, int argc, const char *argv[])
}

if (visualize) {
const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
struct bview *view = gedp->ged_gvp;
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
bv_vlblock_obj(ldata.vbp, view, "lint_visual");
} else {
_ged_cvt_vlblock_to_solids(gedp, ldata.vbp, "lint_visual", 0);
Expand Down
3 changes: 1 addition & 2 deletions src/libged/lod/lod.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ extern int ged_lod2_core(struct ged *gedp, int argc, const char *argv[]);
int
ged_lod_core(struct ged *gedp, int argc, const char *argv[])
{
const char *cmd2 = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(cmd2, "1"))
if (gedp->new_cmd_forms)
return ged_lod2_core(gedp, argc, argv);

struct bview *gvp;
Expand Down
3 changes: 1 addition & 2 deletions src/libged/nirt/nirt.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ ged_nirt_core(struct ged *gedp, int argc, const char *argv[])
qray_data_to_vlist(gedp, vbp, &HeadQRayData, dir, 0);
bu_list_free(&HeadQRayData.l);

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *view = gedp->ged_gvp;
bv_vlblock_obj(vbp, view, "nirt");
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/libged/open/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ ged_opendb_core(struct ged *gedp, int argc, const char *argv[])
gedp->ged_lod = bv_mesh_lod_context_create(argv[0]);

// If enabled, set up the DbiState container for fast structure access
const char *use_dbi_state = getenv("LIBGED_DBI_STATE");
if (use_dbi_state)
if (gedp->new_cmd_forms)
gedp->dbi_state = new DbiState(gedp);

// Set the view units, if we have a view
Expand Down
3 changes: 1 addition & 2 deletions src/libged/overlay/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ ged_overlay_core(struct ged *gedp, int argc, const char *argv[])
}
}

const char *nview = getenv("GED_TEST_NEW_CMD_FORMS");
if (BU_STR_EQUAL(nview, "1")) {
if (gedp->new_cmd_forms) {
struct bview *v = gedp->ged_gvp;
bv_vlblock_obj(vbp, v, bu_vls_cstr(&nroot));
} else {
Expand Down
Loading

0 comments on commit 8ac6b3a

Please sign in to comment.