Skip to content

Commit

Permalink
move V cmd implementation. More or less a variation on kill V.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Eric Hollister committed Aug 14, 2015
1 parent bf83734 commit 777e9e0
Showing 1 changed file with 227 additions and 39 deletions.
266 changes: 227 additions & 39 deletions src/libged/nmg_move_v.c
Expand Up @@ -32,59 +32,242 @@

#include "./ged_private.h"

#if 0
void remove_face(const struct model* m, long int fid)
void move_vertex(const struct model* m, point_t v_old, point_t v_new)
{
struct nmgregion *r;
struct shell *s;
struct faceuse *fu;
struct face *f;
struct loopuse *lu;
struct loop *l;
struct edgeuse *eu;
struct edge *e;
struct vertexuse *vu;
struct vertex *v;

NMG_CK_MODEL(m);

/* Traverse NMG model to find specified vertex and sets the new coords.
*/

for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) {
NMG_CK_REGION(r);

if (r->ra_p) {
NMG_CK_REGION_A(r->ra_p);
}

for (BU_LIST_FOR(s, shell, &r->s_hd)) {
NMG_CK_SHELL(s);

if (s->sa_p) {
NMG_CK_SHELL_A(s->sa_p);
}

/* Faces in shell */
for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
NMG_CK_FACEUSE(fu);
f = fu->f_p;
NMG_CK_FACE(f);

if ( fid == f->index ) {
/* this kills both facesuses using the face,
* and the face itself.
*/
nmg_kfu(fu);
}
}
}
NMG_CK_REGION(r);

if (r->ra_p) {
NMG_CK_REGION_A(r->ra_p);
}

for (BU_LIST_FOR(s, shell, &r->s_hd)) {
NMG_CK_SHELL(s);

if (s->sa_p) {
NMG_CK_SHELL_A(s->sa_p);
}

/* Faces in shell */
for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
NMG_CK_FACEUSE(fu);
f = fu->f_p;
NMG_CK_FACE(f);

if (f->g.magic_p) switch (*f->g.magic_p) {
case NMG_FACE_G_PLANE_MAGIC:
break;
case NMG_FACE_G_SNURB_MAGIC:
break;
}

/* Loops in face */
for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) {
NMG_CK_LOOPUSE(lu);
l = lu->l_p;
NMG_CK_LOOP(l);

if (l->lg_p) {
NMG_CK_LOOP_G(l->lg_p);
}

if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC) {
/* Loop of Lone vertex */
vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);

/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);

if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}

continue;
}

for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
NMG_CK_EDGEUSE(eu);
e = eu->e_p;
NMG_CK_EDGE(e);

if (eu->g.magic_p) {
switch (*eu->g.magic_p) {
case NMG_EDGE_G_LSEG_MAGIC:
break;
case NMG_EDGE_G_CNURB_MAGIC:
break;
}
}

vu = eu->vu_p;

/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);

if ( VNEAR_EQUAL(v->vg_p->coord,
v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}
}
}
}

/* Wire loops in shell */
for (BU_LIST_FOR(lu, loopuse, &s->lu_hd)) {
NMG_CK_LOOPUSE(lu);
l = lu->l_p;
NMG_CK_LOOP(l);

if (l->lg_p) {
NMG_CK_LOOP_G(l->lg_p);
}

if (BU_LIST_FIRST_MAGIC(&lu->down_hd) == NMG_VERTEXUSE_MAGIC) {
/* Wire loop of Lone vertex */
vu = BU_LIST_FIRST(vertexuse, &lu->down_hd);
/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);
if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);
if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}
continue;
}

for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
NMG_CK_EDGEUSE(eu);
e = eu->e_p;
NMG_CK_EDGE(e);

if (eu->g.magic_p) switch (*eu->g.magic_p) {
case NMG_EDGE_G_LSEG_MAGIC:
break;
case NMG_EDGE_G_CNURB_MAGIC:
break;
}
vu = eu->vu_p;

/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);
if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}
}
}

/* Wire edges in shell */
for (BU_LIST_FOR(eu, edgeuse, &s->eu_hd)) {
NMG_CK_EDGEUSE(eu);
e = eu->e_p;
NMG_CK_EDGE(e);

if (eu->g.magic_p) {
switch (*eu->g.magic_p) {
case NMG_EDGE_G_LSEG_MAGIC:
break;
case NMG_EDGE_G_CNURB_MAGIC:
break;
}
}

vu = eu->vu_p;

/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);

if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}
}

/* Lone vertex in shell */
vu = s->vu_p;

if (vu) {
/* check and remove vertexuse */
NMG_CK_VERTEXUSE(vu);
v = vu->v_p;
NMG_CK_VERTEX(v);

if (v->vg_p) {
NMG_CK_VERTEX_G(v->vg_p);

if ( VNEAR_EQUAL(v->vg_p->coord, v_old, BN_TOL_DIST) ) {
v->vg_p->coord[0] = v_new[0];
v->vg_p->coord[1] = v_new[1];
v->vg_p->coord[2] = v_new[2];
}
}
}
}
}
}
#endif

int
ged_nmg_move_v(struct ged* UNUSED(gedp), int UNUSED(argc), const char* UNUSED(argv[]))
ged_nmg_move_v(struct ged* gedp, int argc, const char* argv[])
{
#if 0
struct rt_db_internal internal;
struct directory *dp;
struct model* m;
const char* name;
long int fid;
point_t vtold;
point_t vtnew;

static const char *usage = "kill F id";
static const char *usage = "move V x_old y_old z_old x_new y_new z_new";

GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
GED_CHECK_DRAWABLE(gedp, GED_ERROR);
Expand All @@ -95,7 +278,7 @@ ged_nmg_move_v(struct ged* UNUSED(gedp), int UNUSED(argc), const char* UNUSED(ar
bu_vls_trunc(gedp->ged_result_str, 0);

/* must be wanting help */
if (argc < 4) {
if (argc < 9) {
bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
return GED_HELP;
}
Expand All @@ -121,13 +304,18 @@ ged_nmg_move_v(struct ged* UNUSED(gedp), int UNUSED(argc), const char* UNUSED(ar
return GED_ERROR;
}

/* get face index from command line */
fid = (long int)atoi(argv[3]);
vtold[0] = atof(argv[3]);
vtold[1] = atof(argv[4]);
vtold[2] = atof(argv[5]);

vtnew[0] = atof(argv[6]);
vtnew[1] = atof(argv[7]);
vtnew[2] = atof(argv[8]);

m = (struct model *)internal.idb_ptr;
NMG_CK_MODEL(m);

remove_face(m, fid);
move_vertex(m, vtold, vtnew);

if ( wdb_put_internal(gedp->ged_wdbp, name, &internal, 1.0) < 0 ) {
bu_vls_printf(gedp->ged_result_str, "wdb_put_internal(%s)", argv[1]);
Expand All @@ -136,7 +324,7 @@ ged_nmg_move_v(struct ged* UNUSED(gedp), int UNUSED(argc), const char* UNUSED(ar
}

rt_db_free_internal(&internal);
#endif

return GED_OK;
}

Expand Down

0 comments on commit 777e9e0

Please sign in to comment.