Skip to content

Commit

Permalink
Work towards making sedit use mged_solid_state only.
Browse files Browse the repository at this point in the history
The update_views block needs another callback, but this gets us closer to being
able to define sedit without mged_state.
  • Loading branch information
starseeker committed Jan 27, 2025
1 parent 89e3c87 commit 2dc1ca8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
12 changes: 12 additions & 0 deletions src/mged/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,18 @@ mged_print_result(int UNUSED(ac), const char **UNUSED(av), void *d, void *UNUSED
return TCL_OK;
}


int
mged_print_str(int UNUSED(ac), const char **UNUSED(av), void *d, void *UNUSED(ud))
{
struct mged_state *s = (struct mged_state *)d;

Tcl_AppendResult(s->interp, bu_vls_cstr(s->s_edit->log_str), (char *)NULL);

return TCL_OK;
}


/**
* Let the user temporarily escape from the editor Format: %
*/
Expand Down
67 changes: 40 additions & 27 deletions src/mged/edsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,33 +470,38 @@ get_sketch_name(struct mged_state *s, const char *sk_n)
* can operate on an equal footing to mouse events.
*/
void
sedit(struct mged_state *s)
sedit(struct mged_state *ms)
{
if (s->dbip == DBI_NULL)
return;
bu_clbk_t f = NULL;
void *d = NULL;
struct mged_solid_edit *s = ms->s_edit;

sedraw = 0;
++update_views;

int had_method = 0;
const struct rt_db_internal *ip = &s->s_edit->es_int;
const struct rt_db_internal *ip = &s->es_int;
if (MGED_OBJ[ip->idb_type].ft_edit) {
bu_vls_trunc(s->s_edit->log_str, 0);
if ((*MGED_OBJ[ip->idb_type].ft_edit)(s, s->s_edit->edit_flag)) {
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);
bu_vls_trunc(s->log_str, 0);
if ((*MGED_OBJ[ip->idb_type].ft_edit)(ms, 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)
(*f)(0, NULL, d, NULL);
bu_vls_trunc(s->log_str, 0);
}
return;
}
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);
if (bu_vls_strlen(s->log_str)) {
mged_sedit_clbk_get(&f, &d, s, ECMD_PRINT_STR, 0, GED_CLBK_DURING);
if (f)
(*f)(0, NULL, d, NULL);
bu_vls_trunc(s->log_str, 0);
}
had_method = 1;
}

switch (s->s_edit->edit_flag) {
switch (s->edit_flag) {

case IDLE:
/* do nothing more */
Expand All @@ -507,37 +512,45 @@ sedit(struct mged_state *s)
if (had_method)
break;
struct bu_vls tmp_vls = BU_VLS_INIT_ZERO;

bu_vls_printf(&tmp_vls, "sedit(s): unknown edflag = %d.\n", s->s_edit->edit_flag);
Tcl_AppendResult(s->interp, bu_vls_addr(&tmp_vls), (char *)NULL);
bu_clbk_t f = NULL;
void *d = NULL;
mged_state_clbk_get(&f, &d, s, 0, ECMD_PRINT_RESULTS, 0, GED_CLBK_DURING);
bu_vls_sprintf(&tmp_vls, "%s", bu_vls_cstr(s->log_str));
bu_vls_sprintf(s->log_str, "sedit(s): unknown edflag = %d.\n", s->edit_flag);
mged_sedit_clbk_get(&f, &d, s, ECMD_PRINT_STR, 0, GED_CLBK_DURING);
if (f)
(*f)(0, NULL, d, NULL);
bu_vls_sprintf(s->log_str, "%s", bu_vls_cstr(&tmp_vls));
bu_vls_free(&tmp_vls);
mged_sedit_clbk_get(&f, &d, s, ECMD_PRINT_RESULTS, 0, GED_CLBK_DURING);
if (f)
(*f)(0, NULL, d, NULL);
}
}

/* If the keypoint changed location, find about it here */
if (!s->s_edit->e_keyfixed)
get_solid_keypoint(s, &s->s_edit->e_keypoint, &s->s_edit->e_keytag, &s->s_edit->es_int, s->s_edit->e_mat);
if (!s->e_keyfixed)
get_solid_keypoint(ms, &s->e_keypoint, &s->e_keytag, &s->es_int, s->e_mat);

int flag = 0;
set_e_axes_pos(0, NULL, (void *)s, (void *)&flag);
replot_editing_solid(0, NULL, s, NULL);
f = NULL; d = NULL;
mged_sedit_clbk_get(&f, &d, s, ECMD_EAXES_POS, 0, GED_CLBK_DURING);
if (f)
(*f)(0, NULL, d, &flag);

f = NULL; d = NULL;
mged_sedit_clbk_get(&f, &d, s, ECMD_REPLOT_EDITING_SOLID, 0, GED_CLBK_DURING);
if (f)
(*f)(0, NULL, d, NULL);

if (update_views) {
dm_set_dirty(DMP, 1);
dm_set_dirty(ms->mged_curr_dm->dm_dmp, 1);
struct bu_vls vls = BU_VLS_INIT_ZERO;

bu_vls_printf(&vls, "active_edit_callback");
(void)Tcl_Eval(s->interp, bu_vls_addr(&vls));
(void)Tcl_Eval(ms->interp, bu_vls_addr(&vls));
bu_vls_free(&vls);
}

s->s_edit->e_inpara = 0;
s->s_edit->e_mvalid = 0;
s->e_inpara = 0;
s->e_mvalid = 0;
}


Expand Down
1 change: 1 addition & 0 deletions src/mged/mged.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ extern void view_ring_destroy(struct mged_dm *dlp);
/* cmd.c */
int cmdline(struct mged_state *s, struct bu_vls *vp, int record);
int mged_print_result(int, const char **, void *, void*);
int mged_print_str(int, const char **, void *, void*);
int gui_output(void *clientData, void *str);
void mged_pr_output(Tcl_Interp *interp);

Expand Down
9 changes: 5 additions & 4 deletions src/mged/mged_ecmd_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ main(int argc, const char *argv[])
ofile << "#include \"common.h\"\n";
ofile << "\n";

ofile << "#define ECMD_PRINT_RESULTS 10\n";
ofile << "#define ECMD_EAXES_POS 20\n";
ofile << "#define ECMD_REPLOT_EDITING_SOLID 30\n";
ofile << "#define ECMD_VIEW_UPDATE 40\n";
ofile << "#define ECMD_PRINT_STR 10\n";
ofile << "#define ECMD_PRINT_RESULTS 20\n";
ofile << "#define ECMD_EAXES_POS 30\n";
ofile << "#define ECMD_REPLOT_EDITING_SOLID 40\n";
ofile << "#define ECMD_VIEW_UPDATE 50\n";
ofile << "\n";

std::set<std::pair<std::string, long>>::iterator m_it;
Expand Down
1 change: 1 addition & 0 deletions src/mged/mged_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mged_state_create(void)
s->s_edit = NULL;

// Register default callbacks
mged_state_clbk_set(s, 0, ECMD_PRINT_STR, 0, GED_CLBK_DURING, mged_print_str, s);
mged_state_clbk_set(s, 0, ECMD_PRINT_RESULTS, 0, GED_CLBK_DURING, mged_print_result, s);
mged_state_clbk_set(s, 0, ECMD_EAXES_POS , 0, GED_CLBK_DURING, set_e_axes_pos, s);
mged_state_clbk_set(s, 0, ECMD_REPLOT_EDITING_SOLID, 0, GED_CLBK_DURING, replot_editing_solid, s);
Expand Down

0 comments on commit 2dc1ca8

Please sign in to comment.