Skip to content

Commit

Permalink
boiler-plate for move V mged cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Eric Hollister committed Aug 14, 2015
1 parent 1dc5b18 commit bf83734
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libged/CMakeLists.txt
Expand Up @@ -169,6 +169,7 @@ set(LIBGED_SOURCES
nmg_simplify.c
nmg_kill_v.c
nmg_kill_f.c
nmg_move_v.c
ocenter.c
open.c
orient.c
Expand Down
11 changes: 11 additions & 0 deletions src/libged/nmg.c
Expand Up @@ -39,6 +39,7 @@ extern int ged_nmg_mm(struct ged *gedp, int argc, const char *argv[]);
extern int ged_nmg_cmface(struct ged *gedp, int argc, const char *argv[]);
extern int ged_nmg_kill_v(struct ged *gedp, int argc, const char *argv[]);
extern int ged_nmg_kill_f(struct ged *gedp, int argc, const char *argv[]);
extern int ged_nmg_move_v(struct ged *gedp, int argc, const char *argv[]);

int
ged_nmg(struct ged *gedp, int argc, const char *argv[])
Expand Down Expand Up @@ -69,6 +70,10 @@ ged_nmg(struct ged *gedp, int argc, const char *argv[])
"index). When specifying the face to be removed, user generally "
"will display face indices in object via the MGED command "
"labelface.\n");
bu_vls_printf(gedp->ged_result_str, "\tmove V - moves an existing "
"vertex specified by the coordinates x_initial y_initial "
"z_initial to the position with coordinates x_final y_final "
"z_final.\n");
return GED_HELP;
}

Expand All @@ -95,6 +100,12 @@ ged_nmg(struct ged *gedp, int argc, const char *argv[])
ged_nmg_kill_f(gedp, argc, argv);
}
}
else if( BU_STR_EQUAL( "move", subcmd ) ) {
const char* opt = argv[2];
if ( BU_STR_EQUAL( "V", opt ) ) {
ged_nmg_move_v(gedp, argc, argv);
}
}
else {
bu_vls_printf(gedp->ged_result_str, "%s is not a subcommand.", subcmd );
return GED_ERROR;
Expand Down
151 changes: 151 additions & 0 deletions src/libged/nmg_move_v.c
@@ -0,0 +1,151 @@
/* N M G _ M O V E _ V. C
* BRL-CAD
*
* Copyright (c) 2015 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This library 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 library 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 libged/nmg_move_v.c
*
* The move V subcommand for nmg top-level command.
*
*/

#include "common.h"

#include <string.h>

#include "bu/cmd.h"
#include "rt/geom.h"

#include "./ged_private.h"

#if 0
void remove_face(const struct model* m, long int fid)
{
struct nmgregion *r;
struct shell *s;
struct faceuse *fu;
struct face *f;

NMG_CK_MODEL(m);

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);
}
}
}
}
}
#endif

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

static const char *usage = "kill F id";

GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
GED_CHECK_DRAWABLE(gedp, GED_ERROR);
GED_CHECK_READ_ONLY(gedp, GED_ERROR);
GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);

/* initialize result */
bu_vls_trunc(gedp->ged_result_str, 0);

/* must be wanting help */
if (argc < 4) {
bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
return GED_HELP;
}

/* attempt to resolve and verify */
name = argv[0];

if ( (dp=db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET))
== RT_DIR_NULL ) {
bu_vls_printf(gedp->ged_result_str, "%s does not exist\n", name);
return GED_ERROR;
}

if (rt_db_get_internal(&internal, dp, gedp->ged_wdbp->dbip,
bn_mat_identity, &rt_uniresource) < 0) {
bu_vls_printf(gedp->ged_result_str, "rt_db_get_internal() error\n");
return GED_ERROR;
}

if (internal.idb_type != ID_NMG) {
bu_vls_printf(gedp->ged_result_str, "%s is not an NMG solid\n", name);
rt_db_free_internal(&internal);
return GED_ERROR;
}

/* get face index from command line */
fid = (long int)atoi(argv[3]);

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

remove_face(m, fid);

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]);
rt_db_free_internal(&internal);
return GED_ERROR;
}

rt_db_free_internal(&internal);
#endif
return GED_OK;
}

/*
* Local Variables:
* tab-width: 8
* mode: C
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/

0 comments on commit bf83734

Please sign in to comment.