Skip to content

Commit

Permalink
Fold keypoint per-primitive logic into MGED functab
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Dec 30, 2024
1 parent b2ac6ba commit 4979010
Show file tree
Hide file tree
Showing 25 changed files with 430 additions and 176 deletions.
3 changes: 3 additions & 0 deletions src/mged/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(
primitives/edepa.c
primitives/edeto.c
primitives/edextrude.c
primitives/edgrip.c
primitives/edhyp.c
primitives/edmetaball.c
primitives/ednmg.c
Expand All @@ -58,6 +59,7 @@ set(
primitives/edtgc.c
primitives/edtor.c
primitives/edvol.c
primitives/generic.c
primitives/table.cpp
rect.c
rtif.c
Expand Down Expand Up @@ -149,6 +151,7 @@ set(
primitives/edepa.h
primitives/edeto.h
primitives/edextrude.h
primitives/edgrip.h
primitives/edhyp.h
primitives/edmetaball.h
primitives/ednmg.h
Expand Down
117 changes: 9 additions & 108 deletions src/mged/edsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,118 +300,19 @@ set_e_axes_pos(struct mged_state *s, int both)
void
get_solid_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat)
{
static const char *vert_str = "V";
const char *cp = *strp;
point_t mpt = VINIT_ZERO;
static char buf[BUFSIZ];
if (!strp)
return;

RT_CK_DB_INTERNAL(ip);
memset(buf, 0, BUFSIZ);

switch (ip->idb_type) {
case ID_PIPE:
get_pipe_keypoint(s, pt, strp, ip, mat);
return;
case ID_METABALL:
get_metaball_keypoint(s, pt, strp, ip, mat);
return;
case ID_BOT:
{
*strp = OBJ[ip->idb_type].ft_keypoint(pt, cp, mat, ip, &s->tol.tol);
// If we're editing, use that position instead
if (bot_verts[0] > -1) {
struct rt_bot_internal *bot = (struct rt_bot_internal *)ip->idb_ptr;
RT_BOT_CK_MAGIC(bot);
VMOVE(mpt, &bot->vertices[bot_verts[0]*3]);
MAT4X3PNT(*pt, mat, mpt);
}
return;
}
case ID_ARB8:
if (*cp == 'V') {
*strp = OBJ[ip->idb_type].ft_keypoint(pt, cp, mat, ip, &s->tol.tol);
} else {
static const char *vstr = "V1";
*strp = OBJ[ip->idb_type].ft_keypoint(pt, vstr, mat, ip, &s->tol.tol);
}
return;
case ID_BSPLINE:
bspline_solid_keypoint(s, pt, strp, ip, mat);
return;
case ID_GRIP:
{
*strp = OBJ[ip->idb_type].ft_keypoint(pt, cp, mat, ip, &s->tol.tol);
if (!*strp) {
static const char *c_str = "C";
*strp = OBJ[ip->idb_type].ft_keypoint(pt, c_str, mat, ip, &s->tol.tol);
}
return;
}
case ID_ARS:
{
struct rt_ars_internal *ars =
(struct rt_ars_internal *)s->edit_state.es_int.idb_ptr;
RT_ARS_CK_MAGIC(ars);

if (es_ars_crv < 0 || es_ars_col < 0) {
VMOVE(mpt, es_pt);
} else {
VMOVE(mpt, &ars->curves[es_ars_crv][es_ars_col*3]);
}

MAT4X3PNT(*pt, mat, mpt);
*strp = "V";
return;
}
case ID_EXTRUDE:
{
struct rt_extrude_internal *extr = (struct rt_extrude_internal *)ip->idb_ptr;
RT_EXTRUDE_CK_MAGIC(extr);
if (extr->skt && extr->skt->verts) {
static const char *vstr = "V1";
*strp = OBJ[ip->idb_type].ft_keypoint(pt, vstr, mat, ip, &s->tol.tol);
} else {
*strp = OBJ[ip->idb_type].ft_keypoint(pt, NULL, mat, ip, &s->tol.tol);
}
return;
}
case ID_NMG:
get_nmg_keypoint(s, pt, strp, ip, mat);
return;
case ID_CLINE:
case ID_PARTICLE:
case ID_ARBN:
case ID_EBM:
case ID_DSP:
case ID_HF:
case ID_VOL:
case ID_HALF:
case ID_ELL:
case ID_SPH:
case ID_SUPERELL:
case ID_TOR:
case ID_TGC:
case ID_REC:
case ID_RPC:
case ID_RHC:
case ID_EPA:
case ID_EHY:
case ID_HYP:
case ID_ETO:
case ID_POLY:
case ID_SKETCH:
case ID_ANNOT:
case ID_DATUM:
*strp = OBJ[ip->idb_type].ft_keypoint(pt, cp, mat, ip, &s->tol.tol);
if (!*strp)
*strp = OBJ[ip->idb_type].ft_keypoint(pt, vert_str, mat, ip, &s->tol.tol);
return;
default:
Tcl_AppendResult(s->interp, "get_solid_keypoint: unrecognized solid type (setting keypoint to origin)\n", (char *)NULL);
VSETALL(mpt, 0.0);
*strp = "(origin)";
break;
if (MGED_OBJ[ip->idb_type].ft_keypoint) {
*strp = (*MGED_OBJ[ip->idb_type].ft_keypoint)(pt, *strp, mat, ip, &s->tol.tol);
return;
}

Tcl_AppendResult(s->interp, "get_solid_keypoint: unrecognized solid type (setting keypoint to origin)\n", (char *)NULL);
VSETALL(*pt, 0.0);
*strp = "(origin)";
}

int
Expand Down
1 change: 1 addition & 0 deletions src/mged/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "primitives/edepa.h"
#include "primitives/edeto.h"
#include "primitives/edextrude.h"
#include "primitives/edgrip.h"
#include "primitives/edhyp.h"
#include "primitives/edmetaball.h"
#include "primitives/ednmg.h"
Expand Down
17 changes: 17 additions & 0 deletions src/mged/primitives/edarb.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,23 @@ struct menu_item *which_menu[] = {
rot8_menu
};

const char *
mged_arb_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol)
{
if (*keystr == 'V') {
const char *strp = OBJ[ip->idb_type].ft_keypoint(pt, keystr, mat, ip, tol);
return strp;
}
static const char *vstr = "V1";
const char *strp = OBJ[ip->idb_type].ft_keypoint(pt, vstr, mat, ip, tol);
return strp;
}

/*
* An ARB edge is moved by finding the direction of the line
* containing the edge and the 2 "bounding" planes. The new edge is
Expand Down
9 changes: 9 additions & 0 deletions src/mged/primitives/edarb.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ extern struct menu_item *which_menu[];

extern fastf_t es_peqn[7][4]; /* ARBs defining plane equations */

const char *
mged_arb_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol);


int editarb(struct mged_state *s, vect_t pos_model);
void ecmd_arb_main_menu(struct mged_state *s);
int ecmd_arb_specific_menu(struct mged_state *s);
Expand Down
23 changes: 23 additions & 0 deletions src/mged/primitives/edars.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ mged_ars_labels(
pl[npl].str[0] = '\0'; /* Mark ending */
}

const char *
mged_ars_keypoint(
point_t *pt,
const char *UNUSED(keystr),
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *UNUSED(tol))
{
point_t mpt = VINIT_ZERO;
static const char *strp = "V";
struct rt_ars_internal *ars = (struct rt_ars_internal *)ip->idb_ptr;
RT_ARS_CK_MAGIC(ars);

if (es_ars_crv < 0 || es_ars_col < 0) {
VMOVE(mpt, es_pt);
} else {
VMOVE(mpt, &ars->curves[es_ars_crv][es_ars_col*3]);
}

MAT4X3PNT(*pt, mat, mpt);
return strp;
}

void
ecmd_ars_pick(struct mged_state *s)
{
Expand Down
8 changes: 8 additions & 0 deletions src/mged/primitives/edars.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ mged_ars_labels(
struct rt_db_internal *ip,
struct bn_tol *tol);

const char *
mged_ars_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol);

void ecmd_ars_pick(struct mged_state *s);
void ecmd_ars_next_pt(struct mged_state *s);
void ecmd_ars_prev_pt(struct mged_state *s);
Expand Down
20 changes: 20 additions & 0 deletions src/mged/primitives/edbot.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ mged_bot_labels(

}

const char *
mged_bot_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol)
{
const char *strp = OBJ[ip->idb_type].ft_keypoint(pt, keystr, mat, ip, tol);
// If we're editing, use that position instead
if (bot_verts[0] > -1) {
point_t mpt = VINIT_ZERO;
struct rt_bot_internal *bot = (struct rt_bot_internal *)ip->idb_ptr;
RT_BOT_CK_MAGIC(bot);
VMOVE(mpt, &bot->vertices[bot_verts[0]*3]);
MAT4X3PNT(*pt, mat, mpt);
}
return strp;
}

void
ecmd_bot_mode(struct mged_state *s)
{
Expand Down
9 changes: 9 additions & 0 deletions src/mged/primitives/edbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ mged_bot_labels(
struct rt_db_internal *ip,
struct bn_tol *tol);


const char *
mged_bot_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol);

void ecmd_bot_mode(struct mged_state *s);
void ecmd_bot_orient(struct mged_state *s);
void ecmd_bot_thick(struct mged_state *s);
Expand Down
14 changes: 9 additions & 5 deletions src/mged/primitives/edbspline.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,21 @@ mged_bspline_labels(
pl[npl].str[0] = '\0'; /* Mark ending */
}

void
bspline_solid_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat)
const char *
mged_bspline_keypoint(
point_t *pt,
const char *UNUSED(keystr),
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *UNUSED(tol))
{
point_t mpt = VINIT_ZERO;
static char buf[BUFSIZ];

RT_CK_DB_INTERNAL(ip);
memset(buf, 0, BUFSIZ);

struct rt_nurb_internal *sip =
(struct rt_nurb_internal *) s->edit_state.es_int.idb_ptr;
struct rt_nurb_internal *sip = (struct rt_nurb_internal *)ip->idb_ptr;
struct face_g_snurb *surf;
fastf_t *fp;

Expand All @@ -250,8 +254,8 @@ bspline_solid_keypoint(struct mged_state *s, point_t *pt, const char **strp, str
VMOVE(mpt, fp);
sprintf(buf, "Surf %d, index %d,%d",
spl_surfno, spl_ui, spl_vi);
*strp = buf;
MAT4X3PNT(*pt, mat, mpt);
return (const char *)buf;
}

// I think this is bspline only??
Expand Down
9 changes: 7 additions & 2 deletions src/mged/primitives/edbspline.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ mged_bspline_labels(
struct rt_db_internal *ip,
struct bn_tol *tol);

void
bspline_solid_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat);
const char *
mged_bspline_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol);

void ecmd_vtrans(struct mged_state *s);

Expand Down
20 changes: 20 additions & 0 deletions src/mged/primitives/edextrude.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ struct menu_item extr_menu[] = {
{ "", NULL, 0 }
};

const char *
mged_extrude_keypoint(
point_t *pt,
const char *UNUSED(keystr),
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol)
{
const char *strp = NULL;
struct rt_extrude_internal *extr = (struct rt_extrude_internal *)ip->idb_ptr;
RT_EXTRUDE_CK_MAGIC(extr);
if (extr->skt && extr->skt->verts) {
static const char *vstr = "V1";
strp = OBJ[ip->idb_type].ft_keypoint(pt, vstr, mat, ip, tol);
} else {
strp = OBJ[ip->idb_type].ft_keypoint(pt, NULL, mat, ip, tol);
}
return strp;
}

void
ecmd_extr_skt_name(struct mged_state *s)
{
Expand Down
8 changes: 8 additions & 0 deletions src/mged/primitives/edextrude.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

extern struct menu_item extr_menu[];

const char *
mged_extrude_keypoint(
point_t *pt,
const char *keystr,
const mat_t mat,
const struct rt_db_internal *ip,
const struct bn_tol *tol);

void ecmd_extr_skt_name(struct mged_state *s);
void ecmd_extr_mov_h(struct mged_state *s);
void ecmd_extr_scale_h(struct mged_state *s);
Expand Down
Loading

0 comments on commit 4979010

Please sign in to comment.