[brlcad-commits] SF.net SVN: brlcad:[32248] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <bo...@us...> - 2008-08-04 16:12:12
|
Revision: 32248 http://brlcad.svn.sourceforge.net/brlcad/?rev=32248&view=rev Author: bob1961 Date: 2008-08-04 16:11:53 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Added fracture, prefix, quat, regdef, view and ypr to libged. Modified Paths: -------------- brlcad/trunk/include/bn.h brlcad/trunk/include/ged.h brlcad/trunk/src/libbn/mat.c brlcad/trunk/src/libged/Makefile.am brlcad/trunk/src/libged/vrot.c brlcad/trunk/src/libtclcad/ged_obj.c Added Paths: ----------- brlcad/trunk/src/libged/fracture.c brlcad/trunk/src/libged/prefix.c brlcad/trunk/src/libged/quat.c brlcad/trunk/src/libged/regdef.c brlcad/trunk/src/libged/view.c brlcad/trunk/src/libged/ypr.c Modified: brlcad/trunk/include/bn.h =================================================================== --- brlcad/trunk/include/bn.h 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/include/bn.h 2008-08-04 16:11:53 UTC (rev 32248) @@ -488,6 +488,14 @@ BN_EXPORT BU_EXTERN(int bn_mat_is_non_unif, (const mat_t m)); +void +BN_EXPORT BU_EXTERN(bn_wrt_point_direc, + (mat_t out, + const mat_t change, + const mat_t in, + const point_t point, + const vect_t direc)); + /*----------------------------------------------------------------------*/ /* msr.c */ /** @addtogroup msr */ Modified: brlcad/trunk/include/ged.h =================================================================== --- brlcad/trunk/include/ged.h 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/include/ged.h 2008-08-04 16:11:53 UTC (rev 32248) @@ -1239,6 +1239,15 @@ GED_EXPORT BU_EXTERN(int ged_form, (struct ged *gedp, int argc, const char *argv[])); /** + * Given an NMG solid, break it up into several NMG solids, each + * containing a single shell with a single sub-element. + * + * Usage: + * fracture nmgsolid [prefix] + */ +GED_EXPORT BU_EXTERN(int ged_fracture, (struct ged *gedp, int argc, const char *argv[])); + +/** * Get object attributes * * Usage: @@ -1665,6 +1674,14 @@ GED_EXPORT BU_EXTERN(int ged_prcolor, (struct ged *gedp, int argc, const char *argv[])); /** + * Prefix the specified objects with the specified prefix + * + * Usage: + * prefix new_prefix object(s) + */ +GED_EXPORT BU_EXTERN(int ged_prefix, (struct ged *gedp, int argc, const char *argv[])); + +/** * Push objects' path transformations to primitives * * Usage: @@ -1688,12 +1705,28 @@ */ GED_EXPORT BU_EXTERN(int ged_qray, (struct ged *gedp, int argc, const char *argv[])); +/** + * Get/set the view orientation using a quaternion + * + * Usage: + * quat a b c d + */ +GED_EXPORT BU_EXTERN(int ged_quat, (struct ged *gedp, int argc, const char *argv[])); + GED_EXPORT BU_EXTERN(void ged_init_qray, (struct ged_drawable *gdp)); GED_EXPORT BU_EXTERN(void ged_free_qray, (struct ged_drawable *gdp)); /** + * Change the default region ident codes: item air los mat + * + * Usage: + * regdef item air los mat + */ +GED_EXPORT BU_EXTERN(int ged_regdef, (struct ged *gedp, int argc, const char *argv[])); + +/** * Create or append objects to a region * * Usage: @@ -1983,6 +2016,14 @@ GED_EXPORT BU_EXTERN(int ged_version, (struct ged *gedp, int argc, const char *argv[])); /** + * Get/set view attributes + * + * Usage: + * view quat|ypr|aet|center|eye|size [args] + */ +GED_EXPORT BU_EXTERN(int ged_view, (struct ged *gedp, int argc, const char *argv[])); + +/** * Get the view2model matrix. * * Usage: @@ -2056,6 +2097,14 @@ GED_EXPORT BU_EXTERN(int ged_xpush, (struct ged *gedp, int argc, const char *argv[])); /** + * Get/set the view orientation using yaw, pitch and roll + * + * Usage: + * ypr yaw pitch roll + */ +GED_EXPORT BU_EXTERN(int ged_ypr, (struct ged *gedp, int argc, const char *argv[])); + +/** * Erase all currently displayed geometry * * Usage: Modified: brlcad/trunk/src/libbn/mat.c =================================================================== --- brlcad/trunk/src/libbn/mat.c 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/src/libbn/mat.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -1367,6 +1367,49 @@ return 0; } +/* + * B N _ W R T _ P O I N T _ D I R E C + * + * Given a model-space transformation matrix "change", + * return a matrix which applies the change with-respect-to + * given "point" and "direc". + */ +void +bn_wrt_point_direc( mat_t out, const mat_t change, const mat_t in, const point_t point, const vect_t direc ) +{ + static mat_t t1; + static mat_t pt_to_origin, origin_to_pt; + static mat_t d_to_zaxis, zaxis_to_d; + static vect_t zaxis; + + /* build "point to origin" matrix */ + MAT_IDN( pt_to_origin ); + MAT_DELTAS_VEC_NEG(pt_to_origin, point); + + /* build "origin to point" matrix */ + MAT_IDN( origin_to_pt ); + MAT_DELTAS_VEC_NEG(origin_to_pt, point); + + /* build "direc to zaxis" matrix */ + VSET(zaxis, 0.0, 0.0, 1.0); + bn_mat_fromto(d_to_zaxis, direc, zaxis); + + /* build "zaxis to direc" matrix */ + bn_mat_inv(zaxis_to_d, d_to_zaxis); + + /* apply change matrix... + * t1 = change * d_to_zaxis * pt_to_origin * in + */ + bn_mat_mul4( t1, change, d_to_zaxis, pt_to_origin, in ); + + /* apply origin_to_pt matrix: + * out = origin_to_pt * zaxis_to_d * + * change * d_to_zaxis * pt_to_origin * in + */ + bn_mat_mul3( out, origin_to_pt, zaxis_to_d, t1 ); +} + + /** @} */ /* * Local Variables: Modified: brlcad/trunk/src/libged/Makefile.am =================================================================== --- brlcad/trunk/src/libged/Makefile.am 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/src/libged/Makefile.am 2008-08-04 16:11:53 UTC (rev 32248) @@ -42,6 +42,7 @@ facetize.c \ find.c \ form.c \ + fracture.c \ ged.c \ get.c \ get_autoview.c \ @@ -99,9 +100,12 @@ pmodel2view.c \ pov.c \ prcolor.c \ + prefix.c \ push.c \ put.c \ qray.c \ + quat.c \ + regdef.c \ region.c \ remove.c \ report.c \ @@ -139,6 +143,7 @@ v2m_point.c \ vdraw.c \ version.c \ + view.c \ view2model.c \ view_obj.c \ viewdir.c \ @@ -154,6 +159,7 @@ who.c \ wmater.c \ xpush.c \ + ypr.c \ zap.c \ zoom.c Added: brlcad/trunk/src/libged/fracture.c =================================================================== --- brlcad/trunk/src/libged/fracture.c (rev 0) +++ brlcad/trunk/src/libged/fracture.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,252 @@ +/* F R A C T U R E . C + * BRL-CAD + * + * Copyright (c) 2008 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 fracture.c + * + * The fracture command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + +static void ged_add_nmg_part(struct ged *gedp, char *newname, struct model *m); + +static int frac_stat; + +int +ged_fracture(struct ged *gedp, int argc, const char *argv[]) +{ + register int i; + struct directory *old_dp; + struct rt_db_internal old_intern; + struct model *m, *new_model; + char newname[32]; + char prefix[32]; + int maxdigits; + struct nmgregion *r, *new_r; + struct shell *s, *new_s; + struct faceuse *fu; + struct vertex *v_new, *v; + unsigned long tw, tf, tp; + static const char *usage = "nmg_solid [prefix]"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_READ_ONLY(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* must be wanting help */ + if (argc == 1) { + gedp->ged_result_flags |= GED_RESULT_FLAGS_HELP_BIT; + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + + if (argc < 2 || 3 < argc) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + bu_vls_printf(&gedp->ged_result_str, "fracture:"); + for (i=0; i < argc; i++) + bu_vls_printf(&gedp->ged_result_str, " %s", argv[i]); + bu_vls_printf(&gedp->ged_result_str, "\n"); + + if ((old_dp = db_lookup(gedp->ged_wdbp->dbip, argv[1], LOOKUP_NOISY)) == DIR_NULL) + return BRLCAD_ERROR; + + if (rt_db_get_internal(&old_intern, old_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 BRLCAD_ERROR; + } + + if (old_intern.idb_type != ID_NMG) { + bu_vls_printf(&gedp->ged_result_str, " is not an NMG solid!!\n"); + rt_db_free_internal( &old_intern, &rt_uniresource ); + return BRLCAD_ERROR; + } + + m = (struct model *)old_intern.idb_ptr; + NMG_CK_MODEL(m); + + /* how many characters of the solid names do we reserve for digits? */ + nmg_count_shell_kids(m, &tf, &tw, &tp); + + maxdigits = (int)(log10((double)(tf+tw+tp)) + 1.0); + + bu_vls_printf(&gedp->ged_result_str, "%ld = %d digits\n", (long)(tf+tw+tp), maxdigits); + + /* for (maxdigits=1, i=tf+tw+tp; i > 0; i /= 10) + * maxdigits++; + */ + + /* get the prefix for the solids to be created. */ + memset(prefix, 0, sizeof(prefix)); + bu_strlcpy(prefix, argv[argc-1], sizeof(prefix)); + bu_strlcat(prefix, "_", sizeof(prefix)); + + /* Bust it up here */ + + i = 1; + for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) { + NMG_CK_REGION(r); + for (BU_LIST_FOR(s, shell, &r->s_hd)) { + NMG_CK_SHELL(s); + if (s->vu_p) { + NMG_CK_VERTEXUSE(s->vu_p); + NMG_CK_VERTEX(s->vu_p->v_p); + v = s->vu_p->v_p; + +/* nmg_start_dup(m); */ + new_model = nmg_mm(); + new_r = nmg_mrsv(new_model); + new_s = BU_LIST_FIRST(shell, &r->s_hd); + v_new = new_s->vu_p->v_p; + if (v->vg_p) { + nmg_vertex_gv(v_new, v->vg_p->coord); + } +/* nmg_end_dup(); */ + + snprintf(newname, 32, "%s%0*d", prefix, maxdigits, i++); + + ged_add_nmg_part(gedp, newname, new_model); + if (frac_stat) return BRLCAD_ERROR; + continue; + } + for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { + if (fu->orientation != OT_SAME) + continue; + + NMG_CK_FACEUSE(fu); + + new_model = nmg_mm(); + NMG_CK_MODEL(new_model); + new_r = nmg_mrsv(new_model); + NMG_CK_REGION(new_r); + new_s = BU_LIST_FIRST(shell, &new_r->s_hd); + NMG_CK_SHELL(new_s); +/* nmg_start_dup(m); */ + NMG_CK_SHELL(new_s); + nmg_dup_face(fu, new_s); +/* nmg_end_dup(); */ + + snprintf(newname, 32, "%s%0*d", prefix, maxdigits, i++); + ged_add_nmg_part(gedp, newname, new_model); + if (frac_stat) return BRLCAD_ERROR; + } +#if 0 + while (BU_LIST_NON_EMPTY(&s->lu_hd)) { + lu = BU_LIST_FIRST(loopuse, &s->lu_hd); + new_model = nmg_mm(); + r = nmg_mrsv(new_model); + new_s = BU_LIST_FIRST(shell, &r->s_hd); + + nmg_dup_loop(lu, new_s); + nmg_klu(lu); + + snprintf(newname, 32, "%s%0*d", prefix, maxdigits, i++); + ged_add_nmg_part(gedp, newname, new_model); + if (frac_stat) return BRLCAD_ERROR; + } + while (BU_LIST_NON_EMPTY(&s->eu_hd)) { + eu = BU_LIST_FIRST(edgeuse, &s->eu_hd); + new_model = nmg_mm(); + r = nmg_mrsv(new_model); + new_s = BU_LIST_FIRST(shell, &r->s_hd); + + nmg_dup_edge(eu, new_s); + nmg_keu(eu); + + snprintf(newname, 32, "%s%0*d", prefix, maxdigits, i++); + + ged_add_nmg_part(gedp, newname, new_model); + if (frac_stat) return BRLCAD_ERROR; + } +#endif + } + } + + return BRLCAD_OK; +} + +static void +ged_add_nmg_part(struct ged *gedp, char *newname, struct model *m) +{ + struct rt_db_internal new_intern; + struct directory *new_dp; + struct nmgregion *r; + + if ( db_lookup( gedp->ged_wdbp->dbip, newname, LOOKUP_QUIET ) != DIR_NULL ) { + bu_vls_printf(&gedp->ged_result_str, "%s: already exists\n", newname); + /* Free memory here */ + nmg_km(m); + frac_stat = 1; + return; + } + + if ( (new_dp=db_diradd( gedp->ged_wdbp->dbip, newname, -1, 0, DIR_SOLID, (genptr_t)&new_intern.idb_type)) == DIR_NULL ) { + bu_vls_printf(&gedp->ged_result_str, + "Failed to add new object name (%s) to directory - aborting!!\n", + newname); + return; + } + + /* make sure the geometry/bounding boxes are up to date */ + for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) + nmg_region_a(r, &gedp->ged_wdbp->wdb_tol); + + + /* Export NMG as a new solid */ + RT_INIT_DB_INTERNAL(&new_intern); + new_intern.idb_major_type = DB5_MAJORTYPE_BRLCAD; + new_intern.idb_type = ID_NMG; + new_intern.idb_meth = &rt_functab[ID_NMG]; + new_intern.idb_ptr = (genptr_t)m; + + if ( rt_db_put_internal( new_dp, gedp->ged_wdbp->dbip, &new_intern, &rt_uniresource ) < 0 ) { + /* Free memory */ + nmg_km(m); + bu_vls_printf(&gedp->ged_result_str, "rt_db_put_internal() failure\n"); + frac_stat = 1; + return; + } + /* Internal representation has been freed by rt_db_put_internal */ + new_intern.idb_ptr = (genptr_t)NULL; + frac_stat = 0; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/fracture.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/prefix.c =================================================================== --- brlcad/trunk/src/libged/prefix.c (rev 0) +++ brlcad/trunk/src/libged/prefix.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,174 @@ +/* P R E F I X . C + * BRL-CAD + * + * Copyright (c) 2008 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 prefix.c + * + * The prefix command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + +static void ged_do_prefix(struct db_i *dbip, struct rt_comb_internal *comb, union tree *comb_leaf, genptr_t prefix_ptr, genptr_t obj_ptr, genptr_t user_ptr3); + +int +ged_prefix(struct ged *gedp, int argc, const char *argv[]) +{ + register int i, k; + register struct directory *dp; + struct rt_db_internal intern; + struct rt_comb_internal *comb; + char tempstring_v4[NAMESIZE+1]; + struct bu_vls tempstring_v5; + char *tempstring; + int len = NAMESIZE+1; + static const char *usage = "quat|ypr|aet|center|eye|size [args]"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_READ_ONLY(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* must be wanting help */ + if (argc == 1) { + gedp->ged_result_flags |= GED_RESULT_FLAGS_HELP_BIT; + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + + if (argc < 3) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + bu_vls_init(&tempstring_v5); + + /* First, check validity, and change node names */ + for (i = 2; i < argc; i++) { + if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == DIR_NULL) { + argv[i] = ""; + continue; + } + + if (gedp->ged_wdbp->dbip->dbi_version < 5 && (int)(strlen(argv[1]) + strlen(argv[i])) > NAMESIZE) { + bu_vls_printf(&gedp->ged_result_str, "'%s%s' too long, must be %d characters or less.\n", + argv[1], argv[i], NAMESIZE); + + argv[i] = ""; + continue; + } + + if (gedp->ged_wdbp->dbip->dbi_version < 5) { + bu_strlcpy(tempstring_v4, argv[1], len); + bu_strlcat(tempstring_v4, argv[i], len); + tempstring = tempstring_v4; + } else { + bu_vls_trunc(&tempstring_v5, 0); + bu_vls_strcpy(&tempstring_v5, argv[1]); + bu_vls_strcat(&tempstring_v5, argv[i]); + tempstring = bu_vls_addr(&tempstring_v5); + } + + if (db_lookup( gedp->ged_wdbp->dbip, tempstring, LOOKUP_QUIET) != DIR_NULL) { + bu_vls_printf(&gedp->ged_result_str, "%s: already exists\n", tempstring); + argv[i] = ""; + continue; + } + /* Change object name in the directory. */ + if (db_rename(gedp->ged_wdbp->dbip, dp, tempstring) < 0) { + bu_vls_free(&tempstring_v5); + bu_vls_printf(&gedp->ged_result_str, "error in rename to %s, aborting\n", tempstring); + return BRLCAD_ERROR; + } + } + + bu_vls_free(&tempstring_v5); + + /* Examine all COMB nodes */ + FOR_ALL_DIRECTORY_START(dp, gedp->ged_wdbp->dbip) { + if (!(dp->d_flags & DIR_COMB)) + continue; + + if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Database read error, aborting"); + return BRLCAD_ERROR; + } + comb = (struct rt_comb_internal *)intern.idb_ptr; + + for (k=2; k<argc; k++) + db_tree_funcleaf(gedp->ged_wdbp->dbip, comb, comb->tree, ged_do_prefix, + (genptr_t)argv[1], (genptr_t)argv[k], (genptr_t)NULL); + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource)) { + bu_vls_printf(&gedp->ged_result_str, "Database write error, aborting"); + return BRLCAD_ERROR; + } + } FOR_ALL_DIRECTORY_END; + + return BRLCAD_OK; +} + +static void +ged_do_prefix(struct db_i *dbip, struct rt_comb_internal *comb, union tree *comb_leaf, genptr_t prefix_ptr, genptr_t obj_ptr, genptr_t user_ptr3) +{ + char *prefix, *obj; + char tempstring_v4[NAMESIZE+1]; + int len = NAMESIZE+1; + + RT_CK_DBI( dbip ); + RT_CK_TREE( comb_leaf ); + + prefix = (char *)prefix_ptr; + obj = (char *)obj_ptr; + + if ( strcmp( comb_leaf->tr_l.tl_name, obj ) ) + return; + + bu_free( comb_leaf->tr_l.tl_name, "comb_leaf->tr_l.tl_name" ); + if ( dbip->dbi_version < 5 ) { + bu_strlcpy( tempstring_v4, prefix, len); + bu_strlcat( tempstring_v4, obj, len); + comb_leaf->tr_l.tl_name = bu_strdup( tempstring_v4 ); + } else { + len = strlen(prefix)+strlen(obj)+1; + comb_leaf->tr_l.tl_name = (char *)bu_malloc( len, "Adding prefix" ); + + bu_strlcpy( comb_leaf->tr_l.tl_name , prefix, len); + bu_strlcat( comb_leaf->tr_l.tl_name , obj, len ); + } +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/prefix.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/quat.c =================================================================== --- brlcad/trunk/src/libged/quat.c (rev 0) +++ brlcad/trunk/src/libged/quat.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,85 @@ +/* Q U A T . C + * BRL-CAD + * + * Copyright (c) 2008 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 quat.c + * + * The quat command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + +int +ged_quat(struct ged *gedp, int argc, const char *argv[]) +{ + quat_t quat; + static const char *usage = "a b c d"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_VIEW(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* return Viewrot as a quaternion */ + if (argc == 1) { + quat_mat2quat(quat, gedp->ged_gvp->gv_rotation); + bu_vls_printf(&gedp->ged_result_str, "%.12g %.12g %.12g %.12g", V4ARGS(quat)); + return BRLCAD_OK; + } + + if (argc != 6) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + /* Set the view orientation given a quaternion */ + if (sscanf(argv[2], "%lf", quat) != 1 || + sscanf(argv[3], "%lf", quat+1) != 1 || + sscanf(argv[4], "%lf", quat+2) != 1 || + sscanf(argv[5], "%lf", quat+3) != 1) { + + bu_vls_printf(&gedp->ged_result_str, "%s quat: bad value detected - %s %s %s %s", + argv[0], argv[2], argv[3], argv[4], argv[5]); + return BRLCAD_ERROR; + } + + quat_quat2mat(gedp->ged_gvp->gv_rotation, quat); + ged_view_update(gedp->ged_gvp); + + return BRLCAD_OK; +} + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/quat.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/regdef.c =================================================================== --- brlcad/trunk/src/libged/regdef.c (rev 0) +++ brlcad/trunk/src/libged/regdef.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,107 @@ +/* R E G D E F . C + * BRL-CAD + * + * Copyright (c) 2008 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 regdef.c + * + * The regdef command. + * + */ + +#include <stdlib.h> +#include "ged.h" + +int +ged_regdef(struct ged *gedp, int argc, const char *argv[]) +{ + int item, air, los, mat; + static const char *usage = "item air los mat"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_READ_ONLY(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + if (argc < 2 || 5 < argc) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + /* Get region defaults */ + if (argc == 1) { + bu_vls_printf(&gedp->ged_result_str, "ident %d air %d los %d material %d", + gedp->ged_wdbp->wdb_item_default, + gedp->ged_wdbp->wdb_air_default, + gedp->ged_wdbp->wdb_los_default, + gedp->ged_wdbp->wdb_mat_default); + return BRLCAD_OK; + } + + if (sscanf(argv[1], "%d", &item) != 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + gedp->ged_wdbp->wdb_item_default = item; + + if (argc == 2) + return BRLCAD_OK; + + if (sscanf(argv[2], "%d", &air) != 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + gedp->ged_wdbp->wdb_air_default = air; + if (air) { + item = 0; + gedp->ged_wdbp->wdb_item_default = 0; + } + + if (argc == 3) + return BRLCAD_OK; + + if (sscanf(argv[3], "%d", &los) != 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + gedp->ged_wdbp->wdb_los_default = los; + + if (argc == 4) + return BRLCAD_OK; + + if (sscanf(argv[4], "%d", &mat) != 1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + gedp->ged_wdbp->wdb_mat_default = mat; + + return BRLCAD_OK; +} + + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/regdef.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/view.c =================================================================== --- brlcad/trunk/src/libged/view.c (rev 0) +++ brlcad/trunk/src/libged/view.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,95 @@ +/* V I E W . C + * BRL-CAD + * + * Copyright (c) 2008 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 view.c + * + * The view command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + +int +ged_view(struct ged *gedp, int argc, const char *argv[]) +{ + static const char *usage = "quat|ypr|aet|center|eye|size [args]"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_VIEW(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* must be wanting help */ + if (argc == 1) { + gedp->ged_result_flags |= GED_RESULT_FLAGS_HELP_BIT; + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + + if (argc < 1 || 6 < argc) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + if (!strcmp(argv[1], "quat")) { + return ged_quat(gedp, argc-1, argv+1); + } + + if (!strcmp(argv[1], "ypr")) { + return ged_ypr(gedp, argc-1, argv+1); + } + + if (!strcmp(argv[1], "aet")) { + return ged_aet(gedp, argc-1, argv+1); + } + + if (!strcmp(argv[1], "center")) { + return ged_center(gedp, argc-1, argv+1); + } + + if (!strcmp(argv[1], "eye")) { + return ged_eye(gedp, argc-1, argv+1); + } + + if (!strcmp(argv[1], "size")) { + return ged_size(gedp, argc-1, argv+1); + } + + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; +} + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/view.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/libged/vrot.c =================================================================== --- brlcad/trunk/src/libged/vrot.c 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/src/libged/vrot.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -42,6 +42,18 @@ GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); GED_CHECK_VIEW(gedp, BRLCAD_ERROR); + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* must be wanting help */ + if (argc == 1) { + gedp->ged_result_flags |= GED_RESULT_FLAGS_HELP_BIT; + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + if (argc != 2 && argc != 4) { bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return BRLCAD_ERROR; Added: brlcad/trunk/src/libged/ypr.c =================================================================== --- brlcad/trunk/src/libged/ypr.c (rev 0) +++ brlcad/trunk/src/libged/ypr.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -0,0 +1,99 @@ +/* Y P R . C + * BRL-CAD + * + * Copyright (c) 2008 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 ypr.c + * + * The ypr command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + +int +ged_ypr(struct ged *gedp, int argc, const char *argv[]) +{ + vect_t ypr; + mat_t mat; + static const char *usage = "yaw pitch roll"; + + GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); + GED_CHECK_VIEW(gedp, BRLCAD_ERROR); + + /* initialize result */ + bu_vls_trunc(&gedp->ged_result_str, 0); + gedp->ged_result = GED_RESULT_NULL; + gedp->ged_result_flags = 0; + + /* return Viewrot as yaw, pitch and roll */ + if (argc == 1) { + int n; + point_t pt; + + bn_mat_trn(mat, gedp->ged_gvp->gv_rotation); + anim_v_unpermute(mat); + + if (anim_mat2ypr(pt, mat) == 2) { + bu_vls_printf(&gedp->ged_result_str, "%s ypr - matrix is not a rotation matrix", argv[0]); + return BRLCAD_ERROR; + } + + VSCALE(pt, pt, bn_radtodeg); + bu_vls_printf(&gedp->ged_result_str, "%.12g %.12g %.12g", V3ARGS(pt)); + + return BRLCAD_OK; + } + + if (argc != 5) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + /* attempt to set Viewrot given yaw, pitch and roll */ + if (sscanf(argv[2], "%lf", ypr) != 1 || + sscanf(argv[3], "%lf", ypr+1) != 1 || + sscanf(argv[4], "%lf", ypr+2) != 1) { + + bu_vls_printf(&gedp->ged_result, "%s ypr: bad value detected - %s %s %s", + argv[0], argv[2], argv[3], argv[4]); + return BRLCAD_ERROR; + } + + anim_dy_p_r2mat(mat, V3ARGS(ypr)); + anim_v_permute(mat); + bn_mat_trn(gedp->ged_gvp->gv_rotation, mat); + ged_view_update(gedp->ged_gvp); + + return BRLCAD_OK; +} + +/* + * Local Variables: + * tab-width: 8 + * mode: C + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/ypr.c ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/libtclcad/ged_obj.c =================================================================== --- brlcad/trunk/src/libtclcad/ged_obj.c 2008-08-04 16:08:35 UTC (rev 32247) +++ brlcad/trunk/src/libtclcad/ged_obj.c 2008-08-04 16:11:53 UTC (rev 32248) @@ -357,6 +357,8 @@ {"constrain_tmode", "vname x|y|z x y", MAXARGS, go_constrain_tmode, GED_FUNC_PTR_NULL}, {"copyeval", (char *)0, MAXARGS, go_pass_through_func, ged_copyeval}, {"cp", (char *)0, MAXARGS, go_pass_through_func, ged_copy}, + {"d", (char *)0, MAXARGS, go_pass_through_and_refresh_func, ged_erase}, + {"dall", (char *)0, MAXARGS, go_pass_through_and_refresh_func, ged_erase_all}, {"dbip", (char *)0, MAXARGS, go_pass_through_func, ged_dbip}, {"delete_view", "vname", MAXARGS, go_delete_view, GED_FUNC_PTR_NULL}, {"dir2ae", (char *)0, MAXARGS, go_pass_through_func, ged_dir2ae}, @@ -364,6 +366,7 @@ {"dump", (char *)0, MAXARGS, go_pass_through_func, ged_dump}, {"dup", (char *)0, MAXARGS, go_pass_through_func, ged_dup}, {"E", (char *)0, MAXARGS, go_autoview_func, ged_E}, + {"e", (char *)0, MAXARGS, go_autoview_func, ged_draw}, {"edcomb", (char *)0, MAXARGS, go_pass_through_func, ged_edcomb}, {"edmater", (char *)0, MAXARGS, go_pass_through_func, ged_edmater}, {"erase", (char *)0, MAXARGS, go_pass_through_and_refresh_func, ged_erase}, @@ -375,6 +378,7 @@ {"facetize", (char *)0, MAXARGS, go_pass_through_func, ged_facetize}, {"find", (char *)0, MAXARGS, go_pass_through_func, ged_find}, {"form", (char *)0, MAXARGS, go_pass_through_func, ged_form}, + {"fracture", (char *)0, MAXARGS, go_pass_through_func, ged_fracture}, {"g", (char *)0, MAXARGS, go_pass_through_func, ged_group}, {"get", (char *)0, MAXARGS, go_pass_through_func, ged_get}, {"get_autoview", (char *)0, MAXARGS, go_pass_through_func, ged_get_autoview}, @@ -437,12 +441,15 @@ {"pmodel2view", "vname", 2, go_view_func, ged_pmodel2view}, {"pov", "vname center quat scale eye_pos perspective", 7, go_view_func, ged_pmat}, {"prcolor", (char *)0, MAXARGS, go_pass_through_func, ged_prcolor}, + {"prefix", (char *)0, MAXARGS, go_pass_through_func, ged_prefix}, {"push", (char *)0, MAXARGS, go_pass_through_func, ged_push}, {"put", (char *)0, MAXARGS, go_pass_through_func, ged_put}, {"qray", (char *)0, MAXARGS, go_pass_through_func, ged_qray}, + {"quat", "vname a b c d", 5, go_view_func, ged_quat}, {"r", (char *)0, MAXARGS, go_pass_through_func, ged_region}, {"refresh", "vname", MAXARGS, go_refresh, GED_FUNC_PTR_NULL}, {"refresh_all", (char *)0, MAXARGS, go_refresh_all, GED_FUNC_PTR_NULL}, + {"regdef", (char *)0, MAXARGS, go_pass_through_func, ged_regdef}, {"report", (char *)0, MAXARGS, go_pass_through_func, ged_report}, {"rm", (char *)0, MAXARGS, go_pass_through_func, ged_remove}, {"rmap", (char *)0, MAXARGS, go_pass_through_func, ged_rmap}, @@ -486,6 +493,7 @@ {"v2m_point", "vname x y z", 5, go_view_func, ged_v2m_point}, {"vdraw", (char *)0, MAXARGS, go_autoview_func, ged_vdraw}, {"version", (char *)0, MAXARGS, go_pass_through_func, ged_version}, + {"view", "vname quat|ypr|aet|center|eye|size [args]", 3, go_view_func, ged_view}, {"view2model", "vname", 2, go_view_func, ged_view2model}, {"viewdir", "vname [-i]", 3, go_view_func, ged_viewdir}, {"vmake", "vname pname ptype", MAXARGS, go_vmake, GED_FUNC_PTR_NULL}, @@ -497,6 +505,7 @@ {"who", (char *)0, MAXARGS, go_pass_through_func, ged_who}, {"wmater", (char *)0, MAXARGS, go_pass_through_func, ged_wmater}, {"xpush", (char *)0, MAXARGS, go_pass_through_func, ged_xpush}, + {"ypr", "vname yaw pitch roll", 3, go_view_func, ged_ypr}, {"zap", (char *)0, MAXARGS, go_pass_through_and_refresh_func, ged_zap}, {"zbuffer", "vname [0|1]", MAXARGS, go_zbuffer, GED_FUNC_PTR_NULL}, {"zclip", "vname [0|1]", MAXARGS, go_zclip, GED_FUNC_PTR_NULL}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |