diff --git a/src/mged/CMakeLists.txt b/src/mged/CMakeLists.txt index 7521e2f1bb..a0a30e6f08 100644 --- a/src/mged/CMakeLists.txt +++ b/src/mged/CMakeLists.txt @@ -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 @@ -58,6 +59,7 @@ set( primitives/edtgc.c primitives/edtor.c primitives/edvol.c + primitives/generic.c primitives/table.cpp rect.c rtif.c @@ -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 diff --git a/src/mged/edsol.c b/src/mged/edsol.c index 7b8e44d098..36195234e9 100644 --- a/src/mged/edsol.c +++ b/src/mged/edsol.c @@ -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 diff --git a/src/mged/menu.h b/src/mged/menu.h index 1806a397d3..ab87f10669 100644 --- a/src/mged/menu.h +++ b/src/mged/menu.h @@ -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" diff --git a/src/mged/primitives/edarb.c b/src/mged/primitives/edarb.c index a97abce30e..e53d251af7 100644 --- a/src/mged/primitives/edarb.c +++ b/src/mged/primitives/edarb.c @@ -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 diff --git a/src/mged/primitives/edarb.h b/src/mged/primitives/edarb.h index 4080532271..63ebc5e1a5 100644 --- a/src/mged/primitives/edarb.h +++ b/src/mged/primitives/edarb.h @@ -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); diff --git a/src/mged/primitives/edars.c b/src/mged/primitives/edars.c index 566456c319..d7b12c3408 100644 --- a/src/mged/primitives/edars.c +++ b/src/mged/primitives/edars.c @@ -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) { diff --git a/src/mged/primitives/edars.h b/src/mged/primitives/edars.h index 321c2482d8..f73b26b55c 100644 --- a/src/mged/primitives/edars.h +++ b/src/mged/primitives/edars.h @@ -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); diff --git a/src/mged/primitives/edbot.c b/src/mged/primitives/edbot.c index 6d2e096c1e..dc0d4520c8 100644 --- a/src/mged/primitives/edbot.c +++ b/src/mged/primitives/edbot.c @@ -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) { diff --git a/src/mged/primitives/edbot.h b/src/mged/primitives/edbot.h index f9205dde6b..93598fa85e 100644 --- a/src/mged/primitives/edbot.h +++ b/src/mged/primitives/edbot.h @@ -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); diff --git a/src/mged/primitives/edbspline.c b/src/mged/primitives/edbspline.c index bd26c3471a..04be173ad1 100644 --- a/src/mged/primitives/edbspline.c +++ b/src/mged/primitives/edbspline.c @@ -229,8 +229,13 @@ 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]; @@ -238,8 +243,7 @@ bspline_solid_keypoint(struct mged_state *s, point_t *pt, const char **strp, str 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; @@ -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?? diff --git a/src/mged/primitives/edbspline.h b/src/mged/primitives/edbspline.h index 07c70b118b..569459ef36 100644 --- a/src/mged/primitives/edbspline.h +++ b/src/mged/primitives/edbspline.h @@ -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); diff --git a/src/mged/primitives/edextrude.c b/src/mged/primitives/edextrude.c index d9b7f3432c..1a977a9f40 100644 --- a/src/mged/primitives/edextrude.c +++ b/src/mged/primitives/edextrude.c @@ -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) { diff --git a/src/mged/primitives/edextrude.h b/src/mged/primitives/edextrude.h index 72eb7ce3ec..c3920b464e 100644 --- a/src/mged/primitives/edextrude.h +++ b/src/mged/primitives/edextrude.h @@ -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); diff --git a/src/mged/primitives/edgrip.c b/src/mged/primitives/edgrip.c new file mode 100644 index 0000000000..116c4fee09 --- /dev/null +++ b/src/mged/primitives/edgrip.c @@ -0,0 +1,64 @@ +/* E D G R I P . C + * BRL-CAD + * + * Copyright (c) 1996-2024 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file mged/primitives/edgrip.c + * + */ + +#include "common.h" + +#include +#include + +#include "vmath.h" +#include "nmg.h" +#include "raytrace.h" +#include "rt/geom.h" +#include "wdb.h" + +#include "../mged.h" +#include "../sedit.h" +#include "../mged_dm.h" +#include "./edgrip.h" + +const char * +mged_grp_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 (!strp) { + static const char *c_str = "C"; + strp = OBJ[ip->idb_type].ft_keypoint(pt, c_str, mat, ip, tol); + } + return strp; +} + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ diff --git a/src/mged/primitives/edgrip.h b/src/mged/primitives/edgrip.h new file mode 100644 index 0000000000..4e9a2ceacf --- /dev/null +++ b/src/mged/primitives/edgrip.h @@ -0,0 +1,50 @@ +/* E D G R I P . H + * BRL-CAD + * + * Copyright (c) 1985-2024 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file mged/edgrip.h + */ + +#ifndef EDGRIP_H +#define EDGRIP_H + +#include "common.h" +#include "vmath.h" +#include "raytrace.h" +#include "mged.h" + +const char * +mged_grp_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); + + +#endif /* EDGRIP_H */ + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ diff --git a/src/mged/primitives/edmetaball.c b/src/mged/primitives/edmetaball.c index 48fbc8018c..c83188a193 100644 --- a/src/mged/primitives/edmetaball.c +++ b/src/mged/primitives/edmetaball.c @@ -182,8 +182,13 @@ mged_metaball_labels( pl[npl].str[0] = '\0'; /* Mark ending */ } -void -get_metaball_keypoint(struct mged_state *UNUSED(s), point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat) +const char * +mged_metaball_keypoint( + point_t *pt, + const char *UNUSED(keystr), + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *UNUSED(tol)) { RT_CK_DB_INTERNAL(ip); point_t mpt = VINIT_ZERO; @@ -201,8 +206,8 @@ get_metaball_keypoint(struct mged_state *UNUSED(s), point_t *pt, const char **st snprintf(buf, BUFSIZ, "V %f", es_metaball_pnt->fldstr); } - *strp = buf; MAT4X3PNT(*pt, mat, mpt); + return (const char *)buf; } void diff --git a/src/mged/primitives/edmetaball.h b/src/mged/primitives/edmetaball.h index e486a44f50..f64dfdcfef 100644 --- a/src/mged/primitives/edmetaball.h +++ b/src/mged/primitives/edmetaball.h @@ -63,8 +63,13 @@ mged_metaball_labels( struct rt_db_internal *ip, struct bn_tol *tol); -void -get_metaball_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat); +const char * +mged_metaball_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); void menu_metaball_set_threshold(struct mged_state *s); void menu_metaball_set_method(struct mged_state *s); diff --git a/src/mged/primitives/ednmg.c b/src/mged/primitives/ednmg.c index d69cd9ce51..6b08ecf352 100644 --- a/src/mged/primitives/ednmg.c +++ b/src/mged/primitives/ednmg.c @@ -319,12 +319,18 @@ struct menu_item nmg_menu[] = { -void -get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat) +const char * +mged_nmg_keypoint( + point_t *pt, + const char *UNUSED(keystr), + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *UNUSED(tol)) { + const char *strp = NULL; point_t mpt = VINIT_ZERO; if (ip->idb_type != ID_NMG) - return; + return strp; struct vertex *v; struct vertexuse *vu; @@ -333,14 +339,13 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt struct faceuse *fu; struct shell *nmg_s; struct nmgregion *r; - struct model *m = - (struct model *) s->edit_state.es_int.idb_ptr; + struct model *m = (struct model *) ip->idb_ptr; NMG_CK_MODEL(m); /* XXX Fall through, for now (How about first vertex?? - JRA) */ /* set default first */ VSETALL(mpt, 0.0); - *strp = "(origin)"; + strp = "(origin)"; /* XXX Try to use the first point of the selected edge */ if (es_eu != (struct edgeuse *)NULL && @@ -363,7 +368,7 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt goto nmg_keypoint_finalize; nmg_s = BU_LIST_FIRST(shell, &r->s_hd); - if (!s) + if (!nmg_s) goto nmg_keypoint_finalize; NMG_CK_SHELL(nmg_s); @@ -389,7 +394,7 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt if (!v->vg_p) goto nmg_keypoint_finalize; VMOVE(mpt, v->vg_p->coord); - *strp = "V"; + strp = "V"; goto nmg_keypoint_finalize; } if (BU_LIST_IS_EMPTY(&nmg_s->lu_hd)) @@ -412,7 +417,7 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt if (!v->vg_p) goto nmg_keypoint_finalize; VMOVE(mpt, v->vg_p->coord); - *strp = "V"; + strp = "V"; goto nmg_keypoint_finalize; } if (BU_LIST_IS_EMPTY(&nmg_s->eu_hd)) @@ -427,7 +432,7 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt if (!v->vg_p) goto nmg_keypoint_finalize; VMOVE(mpt, v->vg_p->coord); - *strp = "V"; + strp = "V"; goto nmg_keypoint_finalize; } vu = nmg_s->vu_p; @@ -438,12 +443,13 @@ get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt if (!v->vg_p) goto nmg_keypoint_finalize; VMOVE(mpt, v->vg_p->coord); - *strp = "V"; + strp = "V"; goto nmg_keypoint_finalize; } nmg_keypoint_finalize: MAT4X3PNT(*pt, mat, mpt); + return strp; } diff --git a/src/mged/primitives/ednmg.h b/src/mged/primitives/ednmg.h index c59c901a0b..fd1360d428 100644 --- a/src/mged/primitives/ednmg.h +++ b/src/mged/primitives/ednmg.h @@ -47,8 +47,13 @@ extern struct shell *es_s; extern struct menu_item nmg_menu[]; -extern void -get_nmg_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat); +extern const char * +mged_nmg_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); extern void mged_nmg_labels( diff --git a/src/mged/primitives/edpipe.c b/src/mged/primitives/edpipe.c index b8f0bca2a6..0382f5aede 100644 --- a/src/mged/primitives/edpipe.c +++ b/src/mged/primitives/edpipe.c @@ -591,9 +591,15 @@ pipe_move_pnt(struct mged_state *s, struct rt_pipe_internal *pipeip, struct wdb_ } } -void -get_pipe_keypoint(struct mged_state *UNUSED(s), point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat) +const char * +mged_pipe_keypoint( + point_t *pt, + const char *UNUSED(keystr), + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *UNUSED(tol)) { + static const char *strp = "V"; point_t mpt = VINIT_ZERO; RT_CK_DB_INTERNAL(ip); struct rt_pipe_internal *pipeip =(struct rt_pipe_internal *)ip->idb_ptr; @@ -605,9 +611,8 @@ get_pipe_keypoint(struct mged_state *UNUSED(s), point_t *pt, const char **strp, } else { VMOVE(mpt, es_pipe_pnt->pp_coord); } - *strp = "V"; MAT4X3PNT(*pt, mat, mpt); - return; + return strp; } void diff --git a/src/mged/primitives/edpipe.h b/src/mged/primitives/edpipe.h index a6546ae4ce..64fe75162b 100644 --- a/src/mged/primitives/edpipe.h +++ b/src/mged/primitives/edpipe.h @@ -69,7 +69,13 @@ void pipe_move_pnt(struct mged_state *s, struct rt_pipe_internal *, struct wdb_p void pipe_split_pnt(struct bu_list *, struct wdb_pipe_pnt *, point_t); struct wdb_pipe_pnt *pipe_add_pnt(struct rt_pipe_internal *, struct wdb_pipe_pnt *, const point_t); -void get_pipe_keypoint(struct mged_state *s, point_t *pt, const char **strp, struct rt_db_internal *ip, fastf_t *mat); +const char * +mged_pipe_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); void mged_pipe_labels( diff --git a/src/mged/primitives/generic.c b/src/mged/primitives/generic.c new file mode 100644 index 0000000000..6d7632d8eb --- /dev/null +++ b/src/mged/primitives/generic.c @@ -0,0 +1,64 @@ +/* G E N E R I C . C + * BRL-CAD + * + * Copyright (c) 1996-2024 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ +/** @file mged/primitives/generic.c + * + */ + +#include "common.h" + +#include +#include + +#include "vmath.h" +#include "nmg.h" +#include "raytrace.h" +#include "rt/geom.h" +#include "wdb.h" + +#include "../mged.h" +#include "../sedit.h" +#include "../mged_dm.h" + +#include "./mged_functab.h" + +const char * +mged_generic_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol) +{ + static const char *vert_str = "V"; + const char *strp = OBJ[ip->idb_type].ft_keypoint(pt, keystr, mat, ip, tol); + if (strp) + strp = OBJ[ip->idb_type].ft_keypoint(pt, vert_str, mat, ip, tol); + return strp; +} + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ diff --git a/src/mged/primitives/mged_functab.h b/src/mged/primitives/mged_functab.h index a208c1274b..4bf9d52e60 100644 --- a/src/mged/primitives/mged_functab.h +++ b/src/mged/primitives/mged_functab.h @@ -25,9 +25,20 @@ #include "common.h" +#include "vmath.h" #include "bn.h" #include "raytrace.h" +const char * +mged_generic_keypoint( + point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); + + + struct mged_functab { uint32_t magic; char ft_name[17]; /* current longest name is 16 chars, need one element for terminating NULL */ @@ -42,7 +53,11 @@ struct mged_functab { struct bn_tol *tol); #define MGEDFUNCTAB_FUNC_LABELS_CAST(_func) ((void (*)(int *, point_t *, struct rt_point_labels *, int, const mat_t, struct rt_db_internal *, struct bn_tol *))((void (*)(void))_func)) - const char *(*ft_keypoint)(point_t *pt, const char *keystr, const mat_t mat, const struct rt_db_internal *ip, const struct bn_tol *tol); + const char *(*ft_keypoint)(point_t *pt, + const char *keystr, + const mat_t mat, + const struct rt_db_internal *ip, + const struct bn_tol *tol); #define MGEDFUNCTAB_FUNC_KEYPOINT_CAST(_func) ((const char *(*)(point_t *, const char *, const mat_t, const struct rt_db_internal *, const struct bn_tol *))((void (*)(void))_func)) }; diff --git a/src/mged/primitives/table.cpp b/src/mged/primitives/table.cpp index b6e44d391c..fea27aea27 100644 --- a/src/mged/primitives/table.cpp +++ b/src/mged/primitives/table.cpp @@ -33,7 +33,7 @@ extern "C" { #define MGED_DECLARE_INTERFACE(name) \ extern void mged_##name##_labels(int *num_lines, point_t *lines, struct rt_point_labels *pl, int max_pl, const mat_t xform, struct rt_db_internal *ip, struct bn_tol *); \ - extern const char *(*ft_keypoint)(point_t *pt, const char *keystr, const mat_t mat, const struct rt_db_internal *ip, const struct bn_tol *tol); \ + extern const char *mged_##name##_keypoint(point_t *pt, const char *keystr, const mat_t mat, const struct rt_db_internal *ip, const struct bn_tol *tol); \ MGED_DECLARE_INTERFACE(tor); @@ -92,14 +92,14 @@ const struct mged_functab MGED_OBJ[] = { /* 1 */ RT_FUNCTAB_MAGIC, "ID_TOR", "tor", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 2 */ RT_FUNCTAB_MAGIC, "ID_TGC", "tgc", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { @@ -113,133 +113,133 @@ const struct mged_functab MGED_OBJ[] = { /* 4 */ RT_FUNCTAB_MAGIC, "ID_ARB8", "arb8", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_arb_keypoint) /* keypoint */ }, { /* 5 */ RT_FUNCTAB_MAGIC, "ID_ARS", "ars", - MGEDFUNCTAB_FUNC_LABELS_CAST(mged_ars_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_LABELS_CAST(mged_ars_labels), /* label */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_ars_keypoint) /* keypoint */ }, { /* 6 */ RT_FUNCTAB_MAGIC, "ID_HALF", "half", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 7 */ RT_FUNCTAB_MAGIC, "ID_REC", "rec", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 8 */ RT_FUNCTAB_MAGIC, "ID_POLY", "poly", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 9 */ RT_FUNCTAB_MAGIC, "ID_BSPLINE", "bspline", MGEDFUNCTAB_FUNC_LABELS_CAST(mged_bspline_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_bspline_keypoint) /* keypoint */ }, { /* 10 */ RT_FUNCTAB_MAGIC, "ID_SPH", "sph", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 11 */ RT_FUNCTAB_MAGIC, "ID_NMG", "nmg", - MGEDFUNCTAB_FUNC_LABELS_CAST(mged_nmg_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_LABELS_CAST(mged_nmg_labels), /* label */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_nmg_keypoint) /* keypoint */ }, { /* 12 */ RT_FUNCTAB_MAGIC, "ID_EBM", "ebm", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 13 */ RT_FUNCTAB_MAGIC, "ID_VOL", "vol", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 14 */ RT_FUNCTAB_MAGIC, "ID_ARBN", "arbn", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 15 */ RT_FUNCTAB_MAGIC, "ID_PIPE", "pipe", MGEDFUNCTAB_FUNC_LABELS_CAST(mged_pipe_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_pipe_keypoint) /* keypoint */ }, { /* 16 */ RT_FUNCTAB_MAGIC, "ID_PARTICLE", "part", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 17 */ RT_FUNCTAB_MAGIC, "ID_RPC", "rpc", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 18 */ RT_FUNCTAB_MAGIC, "ID_RHC", "rhc", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 19 */ RT_FUNCTAB_MAGIC, "ID_EPA", "epa", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 20 */ RT_FUNCTAB_MAGIC, "ID_EHY", "ehy", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 21 */ RT_FUNCTAB_MAGIC, "ID_ETO", "eto", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 22 */ RT_FUNCTAB_MAGIC, "ID_GRIP", "grip", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_grp_keypoint) /* keypoint */ }, { @@ -253,28 +253,28 @@ const struct mged_functab MGED_OBJ[] = { /* 24 */ RT_FUNCTAB_MAGIC, "ID_HF", "hf", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 25 Displacement Map (alt. height field) */ RT_FUNCTAB_MAGIC, "ID_DSP", "dsp", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 26 2D sketch */ RT_FUNCTAB_MAGIC, "ID_SKETCH", "sketch", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 27 Solid of extrusion */ RT_FUNCTAB_MAGIC, "ID_EXTRUDE", "extrude", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_extrude_keypoint) /* keypoint */ }, { @@ -288,14 +288,14 @@ const struct mged_functab MGED_OBJ[] = { /* 29 Fastgen cline solid */ RT_FUNCTAB_MAGIC, "ID_CLINE", "cline", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 30 Bag o' Triangles */ RT_FUNCTAB_MAGIC, "ID_BOT", "bot", - MGEDFUNCTAB_FUNC_LABELS_CAST(mged_bot_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_LABELS_CAST(mged_bot_labels), /* label */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_bot_keypoint) /* keypoint */ }, { @@ -334,14 +334,14 @@ const struct mged_functab MGED_OBJ[] = { /* 35 (but "should" be 31) Superquadratic Ellipsoid */ RT_FUNCTAB_MAGIC, "ID_SUPERELL", "superell", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { /* 36 (but "should" be 32) Metaball */ RT_FUNCTAB_MAGIC, "ID_METABALL", "metaball", - MGEDFUNCTAB_FUNC_LABELS_CAST(mged_metaball_labels), /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_LABELS_CAST(mged_metaball_labels), /* label */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_metaball_keypoint) /* keypoint */ }, { @@ -355,7 +355,7 @@ const struct mged_functab MGED_OBJ[] = { /* 38 (but "should" be 34) Hyperboloid */ RT_FUNCTAB_MAGIC, "ID_HYP", "hyp", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { @@ -383,7 +383,7 @@ const struct mged_functab MGED_OBJ[] = { /* 42 */ RT_FUNCTAB_MAGIC, "ID_ANNOT", "annot", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, { @@ -398,7 +398,7 @@ const struct mged_functab MGED_OBJ[] = { /* 44 */ RT_FUNCTAB_MAGIC, "ID_DATUM", "datum", NULL, /* label */ - NULL /* keypoint */ + MGEDFUNCTAB_FUNC_KEYPOINT_CAST(mged_generic_keypoint) /* keypoint */ }, diff --git a/src/mged/sedit.h b/src/mged/sedit.h index 977bdfc929..1e787f7a3e 100644 --- a/src/mged/sedit.h +++ b/src/mged/sedit.h @@ -58,6 +58,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"