[brlcad-commits] SF.net SVN: brlcad:[31857] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <bo...@us...> - 2008-07-17 11:43:03
|
Revision: 31857 http://brlcad.svn.sourceforge.net/brlcad/?rev=31857&view=rev Author: bob1961 Date: 2008-07-17 11:41:36 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Added the following commands to libged: isize, keypoint, lookat, m2v_point, model2view, orient, perspective, pmat, pmodel2view, pov, rmat, rot_point, rotate_about, scale, setview, v2m_point, view2model, viewdir, c, cat, color and prcolor. Modified Paths: -------------- brlcad/trunk/include/ged.h brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj brlcad/trunk/src/libged/Makefile.am brlcad/trunk/src/libged/autoview.c brlcad/trunk/src/libged/center.c brlcad/trunk/src/libged/ged.c brlcad/trunk/src/libged/size.c brlcad/trunk/src/libged/vutil.c brlcad/trunk/src/libtclcad/ged_obj.c Added Paths: ----------- brlcad/trunk/src/libged/cat.c brlcad/trunk/src/libged/color.c brlcad/trunk/src/libged/comb_std.c brlcad/trunk/src/libged/isize.c brlcad/trunk/src/libged/keypoint.c brlcad/trunk/src/libged/lookat.c brlcad/trunk/src/libged/m2v_point.c brlcad/trunk/src/libged/model2view.c brlcad/trunk/src/libged/orient.c brlcad/trunk/src/libged/pmat.c brlcad/trunk/src/libged/pmodel2view.c brlcad/trunk/src/libged/pov.c brlcad/trunk/src/libged/prcolor.c brlcad/trunk/src/libged/rot_point.c brlcad/trunk/src/libged/rotate_about.c brlcad/trunk/src/libged/scale.c brlcad/trunk/src/libged/setview.c brlcad/trunk/src/libged/v2m_point.c brlcad/trunk/src/libged/view2model.c brlcad/trunk/src/libged/viewdir.c Modified: brlcad/trunk/include/ged.h =================================================================== --- brlcad/trunk/include/ged.h 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/include/ged.h 2008-07-17 11:41:36 UTC (rev 31857) @@ -236,7 +236,7 @@ struct bu_list l; fastf_t gv_scale; fastf_t gv_size; /**< @brief 2.0 * scale */ - fastf_t gv_invSize; /**< @brief 1.0 / size */ + fastf_t gv_isize; /**< @brief 1.0 / size */ fastf_t gv_perspective; /**< @brief perspective angle */ vect_t gv_aet; vect_t gv_eye_pos; /**< @brief eye position */ @@ -1020,14 +1020,30 @@ GED_EXPORT BU_EXTERN(int ged_bot_face_sort, (struct ged *gedp, int argc, const char *argv[])); /** - * Get or set the view center + * List attributes (brief). * * Usage: + * cat <objects> + */ +GED_EXPORT BU_EXTERN(int ged_cat, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Get or set the view center. + * + * Usage: * center ["x y z"] */ GED_EXPORT BU_EXTERN(int ged_center, (struct ged *gedp, int argc, const char *argv[])); /** + * Make color entry. + * + * Usage: + * color low high r g b + */ +GED_EXPORT BU_EXTERN(int ged_color, (struct ged *gedp, int argc, const char *argv[])); + +/** * Set combination color. * * Usage: @@ -1036,6 +1052,14 @@ GED_EXPORT BU_EXTERN(int ged_comb_color, (struct ged *gedp, int argc, const char *argv[])); /** + * Create or extend a combination using standard notation. + * + * Usage: + * c [-cr] comb_name <boolean_expr> + */ +GED_EXPORT BU_EXTERN(int ged_comb_std, (struct ged *gedp, int argc, const char *argv[])); + +/** * Convert a direction vector to az/el. * * Usage: @@ -1166,6 +1190,14 @@ GED_EXPORT BU_EXTERN(int ged_illum, (struct ged *gedp, int argc, const char *argv[])); /** + * Returns the inverse view size. + * + * Usage: + * isize + */ +GED_EXPORT BU_EXTERN(int ged_isize, (struct ged *gedp, int argc, const char *argv[])); + +/** * Set region ident codes. * * Usage: @@ -1174,6 +1206,14 @@ GED_EXPORT BU_EXTERN(int ged_item, (struct ged *gedp, int argc, const char *argv[])); /** + * Set/get the keypoint + * + * Usage: + * keypoint [x y z] + */ +GED_EXPORT BU_EXTERN(int ged_keypoint, (struct ged *gedp, int argc, const char *argv[])); + +/** * List object information, verbose. * * Usage: @@ -1190,6 +1230,14 @@ GED_EXPORT BU_EXTERN(int ged_log, (struct ged *gedp, int argc, const char *argv[])); /** + * Set the look-at point + * + * Usage: + * lookat x y z + */ +GED_EXPORT BU_EXTERN(int ged_lookat, (struct ged *gedp, int argc, const char *argv[])); + +/** * List the objects in this database * * Usage: @@ -1198,6 +1246,14 @@ GED_EXPORT BU_EXTERN(int ged_ls, (struct ged *gedp, int argc, const char *argv[])); /** + * Convert the specified model point to a view point. + * + * Usage: + * m2v_point x y z + */ +GED_EXPORT BU_EXTERN(int ged_m2v_point, (struct ged *gedp, int argc, const char *argv[])); + +/** * Make a new primitive. * * Usage: @@ -1231,6 +1287,14 @@ GED_EXPORT BU_EXTERN(int ged_mirror, (struct ged *gedp, int argc, const char *argv[])); /** + * Get the model to view matrix + * + * Usage: + * model2view + */ +GED_EXPORT BU_EXTERN(int ged_model2view, (struct ged *gedp, int argc, const char *argv[])); + +/** * Rotate the view. Note - x, y and z are rotations in model coordinates. * * Usage: @@ -1256,6 +1320,14 @@ GED_EXPORT BU_EXTERN(int ged_ocenter, (struct ged *gedp, int argc, const char *argv[])); /** + * Set the view orientation using a quaternion. + * + * Usage: + * orient quat + */ +GED_EXPORT BU_EXTERN(int ged_orient, (struct ged *gedp, int argc, const char *argv[])); + +/** * Rotate obj about the keypoint by * * Usage: @@ -1296,6 +1368,46 @@ GED_EXPORT BU_EXTERN(int ged_pathsum, (struct ged *gedp, int argc, const char *argv[])); /** + * Set/get the perspective angle. + * + * Usage: + * perspective [angle] + */ +GED_EXPORT BU_EXTERN(int ged_perspective, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Set/get the perspective matrix. + * + * Usage: + * pmat [mat] + */ +GED_EXPORT BU_EXTERN(int ged_pmat, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Get the pmodel2view matrix. + * + * Usage: + * pmodel2view + */ +GED_EXPORT BU_EXTERN(int ged_pmodel2view, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Set point of view + * + * Usage: + * pov center quat scale eye_pos perspective + */ +GED_EXPORT BU_EXTERN(int ged_pov, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Print color table + * + * Usage: + * prcolor + */ +GED_EXPORT BU_EXTERN(int ged_prcolor, (struct ged *gedp, int argc, const char *argv[])); + +/** * Create a database object * * Usage: @@ -1325,6 +1437,14 @@ GED_EXPORT BU_EXTERN(int ged_report, (struct ged *gedp, int argc, const char *argv[])); /** + * Set/get the rotation matrix. + * + * Usage: + * rmat [mat] + */ +GED_EXPORT BU_EXTERN(int ged_rmat, (struct ged *gedp, int argc, const char *argv[])); + +/** * Read material properties from a file. * * Usage: @@ -1341,6 +1461,22 @@ GED_EXPORT BU_EXTERN(int ged_rot, (struct ged *gedp, int argc, const char *argv[])); /** + * Set/get the rotate_about point. + * + * Usage: + * rotate_about [e|k|m|v] + */ +GED_EXPORT BU_EXTERN(int ged_rotate_about, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Rotate the point. + * + * Usage: + * rot_point x y z + */ +GED_EXPORT BU_EXTERN(int ged_rot_point, (struct ged *gedp, int argc, const char *argv[])); + +/** * Run the raytracing application. * * Usage: @@ -1349,6 +1485,14 @@ GED_EXPORT BU_EXTERN(int ged_rt, (struct ged *gedp, int argc, const char *argv[])); /** + * Scale the view. + * + * Usage: + * sca sf + */ +GED_EXPORT BU_EXTERN(int ged_scale, (struct ged *gedp, int argc, const char *argv[])); + +/** * Get/set the output handler script * * Usage: @@ -1373,6 +1517,14 @@ GED_EXPORT BU_EXTERN(int ged_set_transparency, (struct ged *gedp, int argc, const char *argv[])); /** + * Set the view orientation given the angles x, y and z in degrees. + * + * Usage: + * setview x y z + */ +GED_EXPORT BU_EXTERN(int ged_setview, (struct ged *gedp, int argc, const char *argv[])); + +/** * Simpler, command-line version of 'mater' command. * * Usage: @@ -1392,7 +1544,7 @@ * Slew the view * * Usage: - * slew x y z + * slew x y [z] */ GED_EXPORT BU_EXTERN(int ged_slew, (struct ged *gedp, int argc, const char *argv[])); @@ -1413,6 +1565,22 @@ GED_EXPORT BU_EXTERN(int ged_tree, (struct ged *gedp, int argc, const char *argv[])); /** + * Convert the specified view point to a model point. + * + * Usage: + * v2m_point x y z + */ +GED_EXPORT BU_EXTERN(int ged_v2m_point, (struct ged *gedp, int argc, const char *argv[])); + +/** + * Get the view2model matrix. + * + * Usage: + * view2model + */ +GED_EXPORT BU_EXTERN(int ged_view2model, (struct ged *gedp, int argc, const char *argv[])); + +/** * Rotate the view. Note - x, y and z are rotations in view coordinates. * * Usage: @@ -1421,6 +1589,14 @@ GED_EXPORT BU_EXTERN(int ged_vrot, (struct ged *gedp, int argc, const char *argv[])); /** + * Return the view direction. + * + * Usage: + * viewdir [-i] + */ +GED_EXPORT BU_EXTERN(int ged_viewdir, (struct ged *gedp, int argc, const char *argv[])); + +/** * List the objects currently prepped for drawing * * Usage: Modified: brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj =================================================================== --- brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/misc/win32-msvc8/libged/libged.vcproj 2008-07-17 11:41:36 UTC (rev 31857) @@ -174,14 +174,26 @@ > </File> <File + RelativePath="..\..\..\src\libged\cat.c" + > + </File> + <File RelativePath="..\..\..\src\libged\center.c" > </File> <File + RelativePath="..\..\..\src\libged\color.c" + > + </File> + <File RelativePath="..\..\..\src\libged\comb_color.c" > </File> <File + RelativePath="..\..\..\src\libged\comb_std.c" + > + </File> + <File RelativePath="..\..\..\src\libged\dg_obj.c" > </File> @@ -262,10 +274,18 @@ > </File> <File + RelativePath="..\..\..\src\libged\isize.c" + > + </File> + <File RelativePath="..\..\..\src\libged\item.c" > </File> <File + RelativePath="..\..\..\src\libged\keypoint.c" + > + </File> + <File RelativePath="..\..\..\src\libged\list.c" > </File> @@ -274,10 +294,18 @@ > </File> <File + RelativePath="..\..\..\src\libged\lookat.c" + > + </File> + <File RelativePath="..\..\..\src\libged\ls.c" > </File> <File + RelativePath="..\..\..\src\libged\m2v_point.c" + > + </File> + <File RelativePath="..\..\..\src\libged\make.c" > </File> @@ -294,6 +322,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\model2view.c" + > + </File> + <File RelativePath="..\..\..\src\libged\mrot.c" > </File> @@ -306,6 +338,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\orient.c" + > + </File> + <File RelativePath="..\..\..\src\libged\orotate.c" > </File> @@ -326,6 +362,26 @@ > </File> <File + RelativePath="..\..\..\src\libged\perspective.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\pmat.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\pmodel2view.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\pov.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\prcolor.c" + > + </File> + <File RelativePath="..\..\..\src\libged\put.c" > </File> @@ -338,6 +394,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\rmat.c" + > + </File> + <File RelativePath="..\..\..\src\libged\rmater.c" > </File> @@ -346,10 +406,22 @@ > </File> <File + RelativePath="..\..\..\src\libged\rot_point.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\rotate_about.c" + > + </File> + <File RelativePath="..\..\..\src\libged\rt.c" > </File> <File + RelativePath="..\..\..\src\libged\scale.c" + > + </File> + <File RelativePath="..\..\..\src\libged\set_outputHandler.c" > </File> @@ -362,6 +434,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\setview.c" + > + </File> + <File RelativePath="..\..\..\src\libged\shader.c" > </File> @@ -390,6 +466,10 @@ > </File> <File + RelativePath="..\..\..\src\libged\v2m_point.c" + > + </File> + <File RelativePath="..\..\..\src\libged\vdraw.c" > </File> @@ -398,6 +478,14 @@ > </File> <File + RelativePath="..\..\..\src\libged\view2model.c" + > + </File> + <File + RelativePath="..\..\..\src\libged\viewdir.c" + > + </File> + <File RelativePath="..\..\..\src\libged\vrot.c" > </File> Modified: brlcad/trunk/src/libged/Makefile.am =================================================================== --- brlcad/trunk/src/libged/Makefile.am 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/src/libged/Makefile.am 2008-07-17 11:41:36 UTC (rev 31857) @@ -15,8 +15,11 @@ blast.c \ bot_decimate.c \ bot_face_sort.c \ + cat.c \ center.c \ + color.c \ comb_color.c \ + comb_std.c \ dg_obj.c \ dir2ae.c \ draw.c \ @@ -37,31 +40,47 @@ how.c \ importFg4Section.c \ illum.c \ + isize.c \ item.c \ + keypoint.c \ list.c \ log.c \ + lookat.c \ ls.c \ + m2v_point.c \ make.c \ make_name.c \ mater.c \ mirror.c \ + model2view.c \ mrot.c \ nirt.c \ ocenter.c \ + orient.c \ orotate.c \ oscale.c \ otranslate.c \ overlay.c \ pathsum.c \ + perspective.c \ + pmat.c \ + pmodel2view.c \ + pov.c \ + prcolor.c \ put.c \ qray.c \ report.c \ + rmat.c \ rmater.c \ rot.c \ + rot_point.c \ + rotate_about.c \ rt.c \ + scale.c \ set_outputHandler.c \ set_transparency.c \ set_uplotOutputMode.c \ + setview.c \ shader.c \ size.c \ slew.c \ @@ -69,8 +88,11 @@ trace.c \ track.c \ tree.c \ + v2m_point.c \ vdraw.c \ view_obj.c \ + view2model.c \ + viewdir.c \ vrot.c \ vutil.c \ wdb_comb_std.c \ Modified: brlcad/trunk/src/libged/autoview.c =================================================================== --- brlcad/trunk/src/libged/autoview.c 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/src/libged/autoview.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -96,7 +96,7 @@ V_MAX(gedp->ged_gvp->gv_scale, radial[Z]); gedp->ged_gvp->gv_size = 2.0 * gedp->ged_gvp->gv_scale; - gedp->ged_gvp->gv_invSize = 1.0 / gedp->ged_gvp->gv_size; + gedp->ged_gvp->gv_isize = 1.0 / gedp->ged_gvp->gv_size; ged_view_update(gedp->ged_gvp); return BRLCAD_OK; Added: brlcad/trunk/src/libged/cat.c =================================================================== --- brlcad/trunk/src/libged/cat.c (rev 0) +++ brlcad/trunk/src/libged/cat.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,79 @@ +/* C 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 cat.c + * + * The cat command. + * + */ + +#include "common.h" + +#include <string.h> + +#include "bio.h" +#include "cmd.h" +#include "ged_private.h" + +int +ged_cat(struct ged *gedp, int argc, const char *argv[]) +{ + register struct directory *dp; + register int arg; + static const char *usage = "<objects>"; + + GED_CHECK_DATABASE_OPEN(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 || MAXARGS < argc) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + for (arg = 1; arg < argc; arg++) { + if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[arg], LOOKUP_NOISY)) == DIR_NULL) + continue; + + ged_do_list(gedp, dp, 0); /* non-verbose */ + } + + 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/cat.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/libged/center.c =================================================================== --- brlcad/trunk/src/libged/center.c 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/src/libged/center.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -36,9 +36,8 @@ ged_center(struct ged *gedp, int argc, const char *argv[]) { point_t center; + static const char *usage = "[x y z]"; - static const char *usage = "[\"x y z\"]"; - GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); GED_CHECK_VIEW(gedp, BRLCAD_ERROR); @@ -56,39 +55,39 @@ return BRLCAD_OK; } + if (argc != 2 && argc != 4) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + /* set view center */ - if (argc == 2 || argc == 4) { - if (argc == 2) { - if (bn_decode_vect(center, argv[1]) != 3) { - bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); - return BRLCAD_ERROR; - } - } else { - if (sscanf(argv[1], "%lf", ¢er[X]) != 1) { - bu_vls_printf(&gedp->ged_result_str, "ged_center: bad X value - %s\n", argv[1]); - return BRLCAD_ERROR; - } + if (argc == 2) { + if (bn_decode_vect(center, argv[1]) != 3) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + } else { + if (sscanf(argv[1], "%lf", ¢er[X]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_center: bad X value - %s\n", argv[1]); + return BRLCAD_ERROR; + } - if (sscanf(argv[2], "%lf", ¢er[Y]) != 1) { - bu_vls_printf(&gedp->ged_result_str, "ged_center: bad Y value - %s\n", argv[2]); - return BRLCAD_ERROR; - } - - if (sscanf(argv[3], "%lf", ¢er[Z]) != 1) { - bu_vls_printf(&gedp->ged_result_str, "ged_center: bad Z value - %s\n", argv[3]); - return BRLCAD_ERROR; - } + if (sscanf(argv[2], "%lf", ¢er[Y]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_center: bad Y value - %s\n", argv[2]); + return BRLCAD_ERROR; } - VSCALE(center, center, gedp->ged_wdbp->dbip->dbi_local2base); - MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, center); - ged_view_update(gedp->ged_gvp); - - return BRLCAD_OK; + if (sscanf(argv[3], "%lf", ¢er[Z]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_center: bad Z value - %s\n", argv[3]); + return BRLCAD_ERROR; + } } - bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); - return BRLCAD_ERROR; + VSCALE(center, center, gedp->ged_wdbp->dbip->dbi_local2base); + MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, center); + ged_view_update(gedp->ged_gvp); + + return BRLCAD_OK; } Added: brlcad/trunk/src/libged/color.c =================================================================== --- brlcad/trunk/src/libged/color.c (rev 0) +++ brlcad/trunk/src/libged/color.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,211 @@ +/* C O L O 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 color.c + * + * The color command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged.h" +#include "db.h" +#include "mater.h" + +static void +ged_color_putrec(register struct mater *mp, + struct ged *gedp); +static void +ged_color_zaprec(register struct mater *mp, + struct ged *gedp); + + +int +ged_color(struct ged *gedp, int argc, const char *argv[]) +{ + register struct mater *newp; + register struct mater *mp; + register struct mater *next_mater; + static const char *usage = "low high r g b"; + + 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 != 6) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + if (gedp->ged_wdbp->dbip->dbi_version < 5) { + /* Delete all color records from the database */ + mp = rt_material_head(); + while (mp != MATER_NULL) { + next_mater = mp->mt_forw; + ged_color_zaprec(mp, gedp); + mp = next_mater; + } + + /* construct the new color record */ + BU_GETSTRUCT(newp, mater); + newp->mt_low = atoi(argv[1]); + newp->mt_high = atoi(argv[2]); + newp->mt_r = atoi(argv[3]); + newp->mt_g = atoi(argv[4]); + newp->mt_b = atoi(argv[5]); + newp->mt_daddr = MATER_NO_ADDR; /* not in database yet */ + + /* Insert new color record in the in-memory list */ + rt_insert_color(newp); + + /* Write new color records for all colors in the list */ + mp = rt_material_head(); + while (mp != MATER_NULL) { + next_mater = mp->mt_forw; + ged_color_putrec(mp, gedp); + mp = next_mater; + } + } else { + struct bu_vls colors; + + /* construct the new color record */ + BU_GETSTRUCT(newp, mater); + newp->mt_low = atoi(argv[1]); + newp->mt_high = atoi(argv[2]); + newp->mt_r = atoi(argv[3]); + newp->mt_g = atoi(argv[4]); + newp->mt_b = atoi(argv[5]); + newp->mt_daddr = MATER_NO_ADDR; /* not in database yet */ + + /* Insert new color record in the in-memory list */ + rt_insert_color(newp); + + /* + * Gather color records from the in-memory list to build + * the _GLOBAL objects regionid_colortable attribute. + */ + bu_vls_init(&colors); + rt_vls_color_map(&colors); + + db5_update_attribute("_GLOBAL", "regionid_colortable", bu_vls_addr(&colors), gedp->ged_wdbp->dbip); + bu_vls_free(&colors); + } + + return BRLCAD_OK; +} + + +/** + * G E D _ C O L O R _ P U T R E C + *@brief + * Used to create a database record and get it written out to a granule. + * In some cases, storage will need to be allocated. + */ +static void +ged_color_putrec(register struct mater *mp, + struct ged *gedp) +{ + struct directory dir; + union record rec; + + /* we get here only if database is NOT read-only */ + + rec.md.md_id = ID_MATERIAL; + rec.md.md_low = mp->mt_low; + rec.md.md_hi = mp->mt_high; + rec.md.md_r = mp->mt_r; + rec.md.md_g = mp->mt_g; + rec.md.md_b = mp->mt_b; + + /* Fake up a directory entry for db_* routines */ + RT_DIR_SET_NAMEP( &dir, "color_putrec" ); + dir.d_magic = RT_DIR_MAGIC; + dir.d_flags = 0; + + if (mp->mt_daddr == MATER_NO_ADDR) { + /* Need to allocate new database space */ + if (db_alloc(gedp->ged_wdbp->dbip, &dir, 1) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Database alloc error, aborting"); + return; + } + mp->mt_daddr = dir.d_addr; + } else { + dir.d_addr = mp->mt_daddr; + dir.d_len = 1; + } + + if (db_put(gedp->ged_wdbp->dbip, &dir, &rec, 0, 1) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Database write error, aborting"); + return; + } +} + +/** + * W D B _ C O L O R _ Z A P R E C + *@brief + * Used to release database resources occupied by a material record. + */ +static void +ged_color_zaprec(register struct mater *mp, + struct ged *gedp) +{ + struct directory dir; + + /* we get here only if database is NOT read-only */ + if (mp->mt_daddr == MATER_NO_ADDR) + return; + + dir.d_magic = RT_DIR_MAGIC; + RT_DIR_SET_NAMEP( &dir, "color_zaprec" ); + dir.d_len = 1; + dir.d_addr = mp->mt_daddr; + dir.d_flags = 0; + + if (db_delete(gedp->ged_wdbp->dbip, &dir) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Database delete error, aborting"); + return; + } + mp->mt_daddr = MATER_NO_ADDR; +} + +/* + * 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/color.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/comb_std.c =================================================================== --- brlcad/trunk/src/libged/comb_std.c (rev 0) +++ brlcad/trunk/src/libged/comb_std.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,730 @@ +/* C O M B _ S T D . 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 comb_std.c + * + * The c command. + * + */ + + +#include "common.h" + +#include <stdio.h> +#include <string.h> +#include "bio.h" + +#include "tcl.h" +#include "bu.h" +#include "vmath.h" +#include "rtgeom.h" +#include "ged.h" + + +struct tokens { + struct bu_list l; + short type; + union tree *tp; +}; + +/* token types */ +#define GED_TOK_NULL 0 +#define GED_TOK_LPAREN 1 +#define GED_TOK_RPAREN 2 +#define GED_TOK_UNION 3 +#define GED_TOK_INTER 4 +#define GED_TOK_SUBTR 5 +#define GED_TOK_TREE 6 + +HIDDEN void +ged_free_tokens(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + while (BU_LIST_WHILE(tok, tokens, hp)) { + BU_LIST_DEQUEUE(&tok->l); + if (tok->type == GED_TOK_TREE) { + if (tok->tp) + db_free_tree(tok->tp, &rt_uniresource); + } + } +} + +HIDDEN void +ged_append_union(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD( hp ); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_UNION; + tok->tp = (union tree *)NULL; + BU_LIST_INSERT(hp, &tok->l); +} + +HIDDEN void +ged_append_inter(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_INTER; + tok->tp = (union tree *)NULL; + BU_LIST_INSERT( hp, &tok->l ); +} + +HIDDEN void +ged_append_subtr(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_SUBTR; + tok->tp = (union tree *)NULL; + BU_LIST_INSERT( hp, &tok->l ); +} + +HIDDEN void +ged_append_lparen(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_LPAREN; + tok->tp = (union tree *)NULL; + BU_LIST_INSERT( hp, &tok->l ); +} + +HIDDEN void +ged_append_rparen(struct bu_list *hp) +{ + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_RPAREN; + tok->tp = (union tree *)NULL; + BU_LIST_INSERT(hp, &tok->l); +} + +HIDDEN int +ged_add_operator(struct ged *gedp, struct bu_list *hp, char ch, short int *last_tok) +{ + char illegal[2]; + + BU_CK_LIST_HEAD(hp); + + switch ( ch ) + { + case 'u': + ged_append_union(hp); + *last_tok = GED_TOK_UNION; + break; + case '+': + ged_append_inter(hp); + *last_tok = GED_TOK_INTER; + break; + case '-': + ged_append_subtr(hp); + *last_tok = GED_TOK_SUBTR; + break; + default: + illegal[0] = ch; + illegal[1] = '\0'; + bu_vls_printf(&gedp->ged_result_str, "Illegal operator: %s, aborting\n", illegal); + ged_free_tokens(hp); + return BRLCAD_ERROR; + } + return BRLCAD_OK; +} + +HIDDEN int +ged_add_operand(struct ged *gedp, struct bu_list *hp, char *name) +{ + char *ptr_lparen; + char *ptr_rparen; + int name_len; + union tree *node; + struct tokens *tok; + + BU_CK_LIST_HEAD(hp); + + ptr_lparen = strchr(name, '('); + ptr_rparen = strchr(name, ')'); + + RT_GET_TREE( node, &rt_uniresource ); + node->magic = RT_TREE_MAGIC; + node->tr_op = OP_DB_LEAF; + node->tr_l.tl_mat = (matp_t)NULL; + if (ptr_lparen || ptr_rparen) { + int tmp1, tmp2; + + if (ptr_rparen) + tmp1 = ptr_rparen - name; + else + tmp1 = (-1); + if (ptr_lparen) + tmp2 = ptr_lparen - name; + else + tmp2 = (-1); + + if (tmp2 == (-1) && tmp1 > 0) + name_len = tmp1; + else if (tmp1 == (-1) && tmp2 > 0) + name_len = tmp2; + else if (tmp1 > 0 && tmp2 > 0) { + if (tmp1 < tmp2) + name_len = tmp1; + else + name_len = tmp2; + } + else { + bu_vls_printf(&gedp->ged_result_str, "Cannot determine length of operand name: %s, aborting\n", name); + return (0); + } + } else + name_len = strlen( name ); + + node->tr_l.tl_name = (char *)bu_malloc(name_len+1, "node name"); + bu_strlcpy(node->tr_l.tl_name, name, name_len+1); + + tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); + tok->type = GED_TOK_TREE; + tok->tp = node; + BU_LIST_INSERT(hp, &tok->l); + return (name_len); +} + +HIDDEN void +ged_do_inter(struct bu_list *hp) +{ + struct tokens *tok; + + for (BU_LIST_FOR(tok, tokens, hp )) { + struct tokens *prev, *next; + union tree *tp; + + if (tok->type != GED_TOK_INTER) + continue; + + prev = BU_LIST_PREV( tokens, &tok->l ); + next = BU_LIST_NEXT( tokens, &tok->l ); + + if (prev->type !=GED_TOK_TREE || next->type != GED_TOK_TREE) + continue; + + /* this is an eligible intersection operation */ + tp = (union tree *)bu_malloc( sizeof( union tree ), "tp" ); + tp->magic = RT_TREE_MAGIC; + tp->tr_b.tb_op = OP_INTERSECT; + tp->tr_b.tb_regionp = (struct region *)NULL; + tp->tr_b.tb_left = prev->tp; + tp->tr_b.tb_right = next->tp; + BU_LIST_DEQUEUE( &tok->l ); + bu_free( (char *)tok, "tok" ); + BU_LIST_DEQUEUE( &prev->l ); + bu_free( (char *)prev, "prev" ); + next->tp = tp; + tok = next; + } +} + +HIDDEN void +ged_do_union_subtr(struct bu_list *hp) +{ + struct tokens *tok; + + for (BU_LIST_FOR(tok, tokens, hp)) { + struct tokens *prev, *next; + union tree *tp; + + if (tok->type != GED_TOK_UNION && tok->type != GED_TOK_SUBTR) + continue; + + prev = BU_LIST_PREV( tokens, &tok->l ); + next = BU_LIST_NEXT( tokens, &tok->l ); + + if (prev->type !=GED_TOK_TREE || next->type != GED_TOK_TREE) + continue; + + /* this is an eligible operation */ + tp = (union tree *)bu_malloc( sizeof( union tree ), "tp" ); + tp->magic = RT_TREE_MAGIC; + if (tok->type == GED_TOK_UNION) + tp->tr_b.tb_op = OP_UNION; + else + tp->tr_b.tb_op = OP_SUBTRACT; + tp->tr_b.tb_regionp = (struct region *)NULL; + tp->tr_b.tb_left = prev->tp; + tp->tr_b.tb_right = next->tp; + BU_LIST_DEQUEUE(&tok->l); + bu_free((char *)tok, "tok"); + BU_LIST_DEQUEUE(&prev->l); + bu_free((char *)prev, "prev"); + next->tp = tp; + tok = next; + } +} + +HIDDEN int +ged_do_paren(struct bu_list *hp) +{ + struct tokens *tok; + + for (BU_LIST_FOR(tok, tokens, hp)) { + struct tokens *prev, *next; + + if (tok->type != GED_TOK_TREE) + continue; + + prev = BU_LIST_PREV( tokens, &tok->l ); + next = BU_LIST_NEXT( tokens, &tok->l ); + + if (prev->type !=GED_TOK_LPAREN || next->type != GED_TOK_RPAREN) + continue; + + /* this is an eligible operand surrounded by parens */ + BU_LIST_DEQUEUE(&next->l); + bu_free((char *)next, "next"); + BU_LIST_DEQUEUE(&prev->l); + bu_free((char *)prev, "prev"); + } + + if (hp->forw == hp->back && hp->forw != hp) + return 1; /* done */ + else if (BU_LIST_IS_EMPTY(hp)) + return -1; /* empty tree!!!! */ + else + return 0; /* more to do */ + +} + +HIDDEN union tree * +ged_eval_bool(struct bu_list *hp) +{ + int done=0; + union tree *final_tree; + struct tokens *tok; + + while (done != 1) { + ged_do_inter(hp); + ged_do_union_subtr(hp); + done = ged_do_paren(hp); + } + + if (done == 1) { + tok = BU_LIST_NEXT(tokens, hp); + final_tree = tok->tp; + BU_LIST_DEQUEUE(&tok->l); + bu_free((char *)tok, "tok"); + return(final_tree); + } + + return (union tree *)NULL; +} + +HIDDEN int +ged_check_syntax(struct ged *gedp, struct bu_list *hp, char *comb_name, struct directory *dp) +{ + struct tokens *tok; + int paren_count=0; + int paren_error=0; + int missing_exp=0; + int missing_op=0; + int op_count=0; + int arg_count=0; + int circular_ref=0; + int errors=0; + short last_tok=GED_TOK_NULL; + + for (BU_LIST_FOR(tok, tokens, hp)) { + switch (tok->type) { + case GED_TOK_LPAREN: + paren_count++; + if ( last_tok == GED_TOK_RPAREN ) + missing_op++; + break; + case GED_TOK_RPAREN: + paren_count--; + if ( last_tok == GED_TOK_LPAREN ) + missing_exp++; + break; + case GED_TOK_UNION: + case GED_TOK_SUBTR: + case GED_TOK_INTER: + op_count++; + break; + case GED_TOK_TREE: + arg_count++; + if ( !dp && !strcmp( comb_name, tok->tp->tr_l.tl_name ) ) + circular_ref++; + else if ( db_lookup( gedp->ged_wdbp->dbip, tok->tp->tr_l.tl_name, LOOKUP_QUIET ) == DIR_NULL ) + bu_vls_printf(&gedp->ged_result_str, "WARNING: '%s' does not actually exist\n", tok->tp->tr_l.tl_name); + break; + } + if (paren_count < 0) + paren_error++; + last_tok = tok->type; + } + + if (paren_count || paren_error) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: unbalanced parenthesis\n"); + errors++; + } + + if (missing_exp) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: empty parenthesis (missing expression)\n"); + errors++; + } + + if (missing_op) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: must have operator between ')('\n"); + errors++; + } + + if (op_count != arg_count-1) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: mismatch of operators and operands\n"); + errors++; + } + + if (circular_ref) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: combination cannot reference itself during initial creation\n"); + errors++; + } + + if (errors) { + bu_vls_printf(&gedp->ged_result_str, "\t---------aborting!\n"); + return( 1 ); + } + + return( 0 ); +} + +int +ged_comb_std(struct ged *gedp, int argc, const char *argv[]) +{ + char *comb_name; + int ch; + int region_flag = -1; + register struct directory *dp; + struct rt_db_internal intern; + struct rt_comb_internal *comb = NULL; + struct tokens tok_hd; + struct tokens *tok; + short last_tok; + int i; + union tree *final_tree; + static const char *usage = "[-cr] comb_name <boolean_expr>"; + + 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 < 3 || RT_MAXARGS < argc) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + /* Parse options */ + bu_optind = 1; /* re-init bu_getopt() */ + while ((ch = bu_getopt(argc, (char * const *)argv, "cgr?")) != EOF) { + switch (ch) { + case 'c': + case 'g': + region_flag = 0; + break; + case 'r': + region_flag = 1; + break; + /* XXX How about -p and -v for FASTGEN? */ + case '?': + default: + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + } + argc -= (bu_optind + 1); + argv += bu_optind; + + comb_name = (char *)*argv++; + if (argc == -1) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_OK; + } + + if ((region_flag != -1) && (argc == 0)) { + /* + * Set/Reset the REGION flag of an existing combination + */ + if ((dp = db_lookup(gedp->ged_wdbp->dbip, comb_name, LOOKUP_NOISY)) == DIR_NULL) + return BRLCAD_ERROR; + + if (!(dp->d_flags & DIR_COMB)) { + bu_vls_printf(&gedp->ged_result_str, "%s is not a combination\n", comb_name); + return BRLCAD_ERROR; + } + + 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\n"); + return BRLCAD_ERROR; + } + comb = (struct rt_comb_internal *)intern.idb_ptr; + RT_CK_COMB(comb); + + if (region_flag) { + if ( !comb->region_flag ) { + /* assign values from the defaults */ + comb->region_id = gedp->ged_wdbp->wdb_item_default++; + comb->aircode = gedp->ged_wdbp->wdb_air_default; + comb->GIFTmater = gedp->ged_wdbp->wdb_mat_default; + comb->los = gedp->ged_wdbp->wdb_los_default; + } + comb->region_flag = 1; + } + else + comb->region_flag = 0; + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + rt_db_free_internal(&intern, &rt_uniresource); + bu_vls_printf(&gedp->ged_result_str, "Database write error, aborting\n"); + return BRLCAD_ERROR; + } + + return BRLCAD_OK; + } + /* + * At this point, we know we have a Boolean expression. + * If the combination already existed and region_flag is -1, + * then leave its region_flag alone. + * If the combination didn't exist yet, + * then pretend region_flag was 0. + * Otherwise, make sure to set its c_flags according to region_flag. + */ + + dp = db_lookup( gedp->ged_wdbp->dbip, comb_name, LOOKUP_QUIET ); + if (dp != DIR_NULL) { + bu_vls_printf(&gedp->ged_result_str, "ERROR: %s already exists\n", comb_name); + return BRLCAD_ERROR; + } + + /* parse Boolean expression */ + BU_LIST_INIT(&tok_hd.l); + tok_hd.type = GED_TOK_NULL; + + last_tok = GED_TOK_LPAREN; + for (i=0; i<argc; i++) { + char *ptr; + + ptr = (char *)argv[i]; + while (*ptr) { + while (*ptr == '(' || *ptr == ')') { + switch (*ptr) { + case '(': + ged_append_lparen( &tok_hd.l ); + last_tok = GED_TOK_LPAREN; + break; + case ')': + ged_append_rparen( &tok_hd.l ); + last_tok = GED_TOK_RPAREN; + break; + } + ptr++; + } + + if (*ptr == '\0') + continue; + + if (last_tok == GED_TOK_RPAREN) { + /* next token MUST be an operator */ + if (ged_add_operator(gedp, &tok_hd.l, *ptr, &last_tok) == BRLCAD_ERROR) { + ged_free_tokens(&tok_hd.l); + if (dp != DIR_NULL) + rt_db_free_internal(&intern, &rt_uniresource); + return BRLCAD_ERROR; + } + ptr++; + } else if (last_tok == GED_TOK_LPAREN) { + /* next token MUST be an operand */ + int name_len; + + name_len = ged_add_operand(gedp, &tok_hd.l, ptr ); + if (name_len < 1) { + ged_free_tokens(&tok_hd.l); + if (dp != DIR_NULL) + rt_db_free_internal(&intern, &rt_uniresource); + return BRLCAD_ERROR; + } + last_tok = GED_TOK_TREE; + ptr += name_len; + } else if (last_tok == GED_TOK_TREE) { + /* must be an operator */ + if (ged_add_operator(gedp, &tok_hd.l, *ptr, &last_tok) == BRLCAD_ERROR) { + ged_free_tokens(&tok_hd.l); + if (dp != DIR_NULL) + rt_db_free_internal(&intern, &rt_uniresource); + return BRLCAD_ERROR; + } + ptr++; + } else if (last_tok == GED_TOK_UNION || + last_tok == GED_TOK_INTER || + last_tok == GED_TOK_SUBTR) { + /* must be an operand */ + int name_len; + + name_len = ged_add_operand(gedp, &tok_hd.l, ptr ); + if (name_len < 1) { + ged_free_tokens(&tok_hd.l); + if (dp != DIR_NULL) + rt_db_free_internal(&intern, &rt_uniresource); + return BRLCAD_ERROR; + } + last_tok = GED_TOK_TREE; + ptr += name_len; + } + } + } + + if (ged_check_syntax(gedp, &tok_hd.l, comb_name, dp)) { + ged_free_tokens(&tok_hd.l); + return BRLCAD_ERROR; + } + + /* replace any occurences of comb_name with existing tree */ + if (dp != DIR_NULL) { + for (BU_LIST_FOR(tok, tokens, &tok_hd.l)) { + struct rt_db_internal intern1; + struct rt_comb_internal *comb1; + + switch (tok->type) { + case GED_TOK_LPAREN: + case GED_TOK_RPAREN: + case GED_TOK_UNION: + case GED_TOK_INTER: + case GED_TOK_SUBTR: + break; + case GED_TOK_TREE: + if (!strcmp(tok->tp->tr_l.tl_name, comb_name)) { + db_free_tree( tok->tp, &rt_uniresource ); + if (rt_db_get_internal(&intern1, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Cannot get records for %s\n", comb_name); + bu_vls_printf(&gedp->ged_result_str, "Database read error, aborting\n"); + return BRLCAD_ERROR; + } + comb1 = (struct rt_comb_internal *)intern1.idb_ptr; + RT_CK_COMB(comb1); + + tok->tp = comb1->tree; + comb1->tree = (union tree *)NULL; + rt_db_free_internal(&intern1, &rt_uniresource); + } + break; + default: + bu_vls_printf(&gedp->ged_result_str, "ERROR: Unrecognized token type\n"); + ged_free_tokens(&tok_hd.l); + return BRLCAD_ERROR; + } + } + } + + final_tree = ged_eval_bool(&tok_hd.l); + + if (dp == DIR_NULL) { + int flags; + + flags = DIR_COMB; + BU_GETSTRUCT(comb, rt_comb_internal); + comb->magic = RT_COMB_MAGIC; + comb->tree = final_tree; + bu_vls_init(&comb->shader); + bu_vls_init(&comb->material); + comb->region_id = -1; + if (region_flag == (-1)) + comb->region_flag = 0; + else + comb->region_flag = region_flag; + + if (comb->region_flag) { + comb->region_flag = 1; + comb->region_id = gedp->ged_wdbp->wdb_item_default++;; + comb->aircode = gedp->ged_wdbp->wdb_air_default; + comb->los = gedp->ged_wdbp->wdb_los_default; + comb->GIFTmater = gedp->ged_wdbp->wdb_mat_default; + bu_vls_printf(&gedp->ged_result_str, + "Creating region id=%d, air=%d, los=%d, GIFTmaterial=%d\n", + comb->region_id, comb->aircode, comb->los, comb->GIFTmater); + + flags |= DIR_REGION; + } + + RT_INIT_DB_INTERNAL(&intern); + intern.idb_major_type = DB5_MAJORTYPE_BRLCAD; + intern.idb_type = ID_COMBINATION; + intern.idb_meth = &rt_functab[ID_COMBINATION]; + intern.idb_ptr = (genptr_t)comb; + + if ((dp=db_diradd(gedp->ged_wdbp->dbip, comb_name, -1L, 0, flags, (genptr_t)&intern.idb_type)) == DIR_NULL) { + bu_vls_printf(&gedp->ged_result_str, "Failed to add %s to directory, aborting\n", comb_name); + return BRLCAD_ERROR; + } + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Failed to write %s", dp->d_namep); + return BRLCAD_ERROR; + } + } else { + db_delete(gedp->ged_wdbp->dbip, dp); + + dp->d_len = 0; + dp->d_un.file_offset = -1; + db_free_tree(comb->tree, &rt_uniresource); + comb->tree = final_tree; + + if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { + bu_vls_printf(&gedp->ged_result_str, "Failed to write %s", dp->d_namep); + return BRLCAD_ERROR; + } + } + + return BRLCAD_OK; +} + + +/* + * Local Variables: + * mode: C + * tab-width: 8 + * indent-tabs-mode: t + * c-file-style: "stroustrup" + * End: + * ex: shiftwidth=4 tabstop=8 + */ Property changes on: brlcad/trunk/src/libged/comb_std.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: brlcad/trunk/src/libged/ged.c =================================================================== --- brlcad/trunk/src/libged/ged.c 2008-07-17 10:03:06 UTC (rev 31856) +++ brlcad/trunk/src/libged/ged.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -149,7 +149,7 @@ { gvp->gv_scale = 1.0; gvp->gv_size = 2.0 * gvp->gv_scale; - gvp->gv_invSize = 1.0 / gvp->gv_size; + gvp->gv_isize = 1.0 / gvp->gv_size; VSET(gvp->gv_eye_pos, 0.0, 0.0, 1.0); MAT_IDN(gvp->gv_rotation); MAT_IDN(gvp->gv_center); Added: brlcad/trunk/src/libged/isize.c =================================================================== --- brlcad/trunk/src/libged/isize.c (rev 0) +++ brlcad/trunk/src/libged/isize.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,66 @@ +/* I S I Z 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 isize.c + * + * The isize command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + + +int +ged_isize(struct ged *gedp, int argc, const char *argv[]) +{ + 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; + + /* get the isize (i.e. inverse view size) */ + if (argc == 1) { + bu_vls_printf(&gedp->ged_result_str, "%g", + gedp->ged_gvp->gv_isize * gedp->ged_wdbp->dbip->dbi_base2local); + return BRLCAD_OK; + } + + bu_vls_printf(&gedp->ged_result_str, "Usage: %s", argv[0]); + 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/isize.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/keypoint.c =================================================================== --- brlcad/trunk/src/libged/keypoint.c (rev 0) +++ brlcad/trunk/src/libged/keypoint.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,99 @@ +/* K E Y P O I N 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 keypoint.c + * + * The keypoint command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + + +int +ged_keypoint(struct ged *gedp, int argc, const char *argv[]) +{ + point_t keypoint; + static const char *usage = "[x y z]"; + + 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; + + /* get keypoint */ + if (argc == 1) { + VSCALE(keypoint, gedp->ged_gvp->gv_keypoint, gedp->ged_wdbp->dbip->dbi_base2local); + bn_encode_vect(&gedp->ged_result_str, keypoint); + + return BRLCAD_OK; + } + + if (argc != 2 && argc != 4) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + /* set view keypoint */ + if (argc == 2) { + if (bn_decode_vect(keypoint, argv[1]) != 3) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + } else { + if (sscanf(argv[1], "%lf", &keypoint[X]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_keypoint: bad X value - %s\n", argv[1]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[2], "%lf", &keypoint[Y]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_keypoint: bad Y value - %s\n", argv[2]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[3], "%lf", &keypoint[Z]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_keypoint: bad Z value - %s\n", argv[3]); + return BRLCAD_ERROR; + } + } + + VSCALE(gedp->ged_gvp->gv_keypoint, keypoint, gedp->ged_wdbp->dbip->dbi_local2base); + + 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/keypoint.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/lookat.c =================================================================== --- brlcad/trunk/src/libged/lookat.c (rev 0) +++ brlcad/trunk/src/libged/lookat.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,111 @@ +/* L O O K 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 lookat.c + * + * The lookat command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + + +int +ged_lookat(struct ged *gedp, int argc, const char *argv[]) +{ + point_t look; + point_t eye; + point_t tmp; + point_t new_center; + vect_t dir; + fastf_t new_az, new_el; + struct bu_vls vls; + static const char *usage = "x y z"; + + 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; + + if (argc != 2 && argc != 4) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + if (argc == 2) { + if (bn_decode_vect(look, argv[1]) != 3) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + } else { + if (sscanf(argv[1], "%lf", &look[X]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_lookat: bad X value - %s\n", argv[1]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[2], "%lf", &look[Y]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_lookat: bad Y value - %s\n", argv[2]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[3], "%lf", &look[Z]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_lookat: bad Z value - %s\n", argv[3]); + return BRLCAD_ERROR; + } + } + + VSCALE(look, look, gedp->ged_wdbp->dbip->dbi_local2base); + + VSET(tmp, 0.0, 0.0, 1.0); + MAT4X3PNT(eye, gedp->ged_gvp->gv_view2model, tmp); + + VSUB2(dir, eye, look); + VUNITIZE(dir); + bn_ae_vec(&new_az, &new_el, dir); + + VSET(gedp->ged_gvp->gv_aet, new_az, new_el, gedp->ged_gvp->gv_aet[Z]); + ged_mat_aet(gedp->ged_gvp); + + VJOIN1(new_center, eye, -gedp->ged_gvp->gv_scale, dir); + MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, new_center); + + 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/lookat.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/m2v_point.c =================================================================== --- brlcad/trunk/src/libged/m2v_point.c (rev 0) +++ brlcad/trunk/src/libged/m2v_point.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,93 @@ +/* M 2 V _ P O I N 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 m2v_point.c + * + * The m2v_point command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + + +int +ged_m2v_point(struct ged *gedp, int argc, const char *argv[]) +{ + point_t model; + point_t view; + static const char *usage = "x y z"; + + 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; + + if (argc != 2 && argc != 4) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + + if (argc == 2) { + if (bn_decode_vect(model, argv[1]) != 3) { + bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage); + return BRLCAD_ERROR; + } + } else { + if (sscanf(argv[1], "%lf", &model[X]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_m2v_point: bad X value - %s\n", argv[1]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[2], "%lf", &model[Y]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_m2v_point: bad Y value - %s\n", argv[2]); + return BRLCAD_ERROR; + } + + if (sscanf(argv[3], "%lf", &model[Z]) != 1) { + bu_vls_printf(&gedp->ged_result_str, "ged_m2v_point: bad Z value - %s\n", argv[3]); + return BRLCAD_ERROR; + } + } + + /* Convert the incoming model point to a view point */ + MAT4X3PNT(view, gedp->ged_gvp->gv_model2view, model); + bn_encode_vect(&gedp->ged_result_str, view); + + 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/m2v_point.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/model2view.c =================================================================== --- brlcad/trunk/src/libged/model2view.c (rev 0) +++ brlcad/trunk/src/libged/model2view.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,65 @@ +/* M O D E L 2 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 model2view.c + * + * The model2view command. + * + */ + +#include "common.h" + +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +#include "ged_private.h" + + +int +ged_model2view(struct ged *gedp, int argc, const char *argv[]) +{ + 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; + + /* get the model2view matrix */ + if (argc == 1) { + bn_encode_mat(&gedp->ged_result_str, gedp->ged_gvp->gv_model2view); + return BRLCAD_OK; + } + + bu_vls_printf(&gedp->ged_result_str, "Usage: %s", argv[0]); + 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/model2view.c ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: brlcad/trunk/src/libged/orient.c =================================================================== --- brlcad/trunk/src/libged/orient.c (rev 0) +++ brlcad/trunk/src/libged/orient.c 2008-07-17 11:41:36 UTC (rev 31857) @@ -0,0 +1,85 @@ +/* O R I E N 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... [truncated message content] |