Revision: 45500
          http://brlcad.svn.sourceforge.net/brlcad/?rev=45500&view=rev
Author:   bhinesley
Date:     2011-07-15 02:43:54 +0000 (Fri, 15 Jul 2011)

Log Message:
-----------
Validate subcommand names, add ged_edit stuff to a few places I missed before, 
cleanup.

Modified Paths:
--------------
    brlcad/trunk/src/libged/edit.c
    brlcad/trunk/src/libged/wdb_obj.c
    brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl
    brlcad/trunk/src/tclscripts/archer/tclIndex
    brlcad/trunk/src/tclscripts/lib/Db.tcl
    brlcad/trunk/src/tclscripts/lib/Ged.tcl
    brlcad/trunk/src/tclscripts/lib/Mged.tcl
    brlcad/trunk/src/tclscripts/lib/tclIndex

Modified: brlcad/trunk/src/libged/edit.c
===================================================================
--- brlcad/trunk/src/libged/edit.c      2011-07-15 02:37:15 UTC (rev 45499)
+++ brlcad/trunk/src/libged/edit.c      2011-07-15 02:43:54 UTC (rev 45500)
@@ -22,6 +22,18 @@
  * Command to edit objects by translating, rotating, and scaling.
  */
 
+#include "common.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "vmath.h"
+#include "db.h"
+#include "raytrace.h"
+#include "ged.h"
+#include "./ged_private.h"
+
 /* edit: Proposed manual page
  *
  * NAME
@@ -652,18 +664,6 @@
  *                                                         
  */
 
-#include "common.h"
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "vmath.h"
-#include "db.h"
-#include "raytrace.h"
-#include "ged.h"
-#include "./ged_private.h"
-
 /* This function will be removed soon */
 #if 0
 int
@@ -798,6 +798,28 @@
 #define EDIT_MAX_ARG_OPTIONS 3
 
 /*
+ * Use one of these nodes for each argument for the edit subcommands
+ * (see manuals)
+ */
+struct edit_arg {
+    struct edit_arg *next; /* link to next argument */
+
+    /* command line options, e.g. "Rnk", to convert to option flags */
+    char cl_options[EDIT_MAX_ARG_OPTIONS];
+
+    /* flag which coords from the vector/object are being used */
+    unsigned int coords_used : 3;
+
+    /* flag the argument type and type modifiers */
+    unsigned int type : 10;
+
+    struct db_full_path *object;
+
+    /* if object != NULL, vector is an offset distance from object */
+    vect_t *vector;
+};
+
+/*
  * edit_arg flags of coordinates being used
  */
 #define EDIT_X_COORD   0x1
@@ -827,32 +849,23 @@
 #define EDIT_NATURAL_ORIGIN            0x100 /* use natural origin of object 
instead of center */
 #define EDIT_USE_TARGETS               0x200 /* for batch ops */
 
-/*
- * Use one of these nodes for each argument for the edit subcommands
- * (see manuals)
- */
-struct edit_arg {
-    struct edit_arg *next; /* link to next argument */
+enum edit_cmd_name {
+    /* alphabetize */
+    EDIT_CMD_HELP,
+    EDIT_CMD_ROTATE,
+    EDIT_CMD_SCALE,
+    EDIT_CMD_TRANSLATE,
+    /* end alphabetize */
 
-    /* command line options, e.g. "Rnk", to convert to option flags */
-    char cl_options[EDIT_MAX_ARG_OPTIONS];
-
-    /* flag which coords from the vector/object are being used */
-    unsigned int coords_used : 3;
-
-    /* flag the argument type and type modifiers */
-    unsigned int type : 10;
-
-    struct db_full_path *object;
-
-    /* if object != NULL, vector is an offset distance from object */
-    vect_t *vector;
+    EDIT_CMD_MAX, /* count of commands, size of char array */
+    EDIT_CMD_UNKNOWN = EDIT_CMD_MAX
 };
-
-enum edit_cmd_name {
-    EDIT_TRANSLATE,
-    EDIT_ROTATE,
-    EDIT_SCALE
+static const char * const edit_cmd_names[EDIT_CMD_MAX] = {
+    /* alphabetize to keep in same order as enum edit_cmd_name */
+    "help",
+    "rotate",
+    "scale",
+    "translate"
 };
 
 /* argument structure of each command */
@@ -1026,6 +1039,7 @@
  * batch operations, and accepts objects and distances in addition to
  * coordinates.
  */
+#if 0
 int
 edit(struct ged *gedp, struct edit_arg *args_head, const char *global_opts)
 {
@@ -1035,6 +1049,7 @@
 
     return GED_OK;
 }
+#endif
 
 /**
  * A command line interface to the edit commands.
@@ -1042,25 +1057,61 @@
 int
 ged_edit(struct ged *gedp, int argc, const char *argv[])
 {
-    (void)argv;
-    (void)edit(gedp, NULL, NULL);
+    const char * const cmd_name = argv[0];
+    const char *subcmd_name;
+    static const char * const usage = "subcmd args";
+    static char *subcmd_usage;
+    union edit_cmd subcmd = {.name = EDIT_CMD_UNKNOWN};
+    int i; /* iterator */
 
     GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
     GED_CHECK_READ_ONLY(gedp, GED_ERROR);
     GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
 
+    /* initialize result */
     bu_vls_trunc(gedp->ged_result_str, 0);
 
+    /* must be wanting help */
+    if (argc == 1) {
+        bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", cmd_name, usage);
+        return GED_HELP;
+    }
+
+    subcmd_name = argv[1];
     /*
+     * validate subcommand name
+     */
+
+    for (i = 0; i < EDIT_CMD_MAX; ++i)
+       if (BU_STR_EQUAL(edit_cmd_names[i], subcmd_name))
+           break;
+
+    subcmd.name = (enum edit_cmd_name)i;
+    switch (subcmd.name) {
+       case EDIT_CMD_UNKNOWN:
+           bu_vls_printf(gedp->ged_result_str, "unknown subcommand: %s\n",
+                         subcmd_name);
+           /* fall through */
+       case EDIT_CMD_HELP:
+           bu_vls_printf(gedp->ged_result_str, "Available subcommands: ");
+           for (i = 0; i < EDIT_CMD_MAX; ++i)
+               bu_vls_printf(gedp->ged_result_str, "%s ",
+                             edit_cmd_names[i]);
+           return (subcmd.name == EDIT_CMD_HELP ? GED_HELP : GED_ERROR);
+       default: /* quiet compiler */
+           break;
+    }
+
+    /* TODO: set subcmd_usage */
+
+    /*
      * testing
      */
+
 #if 0
-    union edit_cmd cmd;
-    cmd.name = EDIT_TRANSLATE;
-
-    edit_arg_postfix_new(&cmd.common.objects);
-    edit_arg_postfix_new(&cmd.common.objects);
-    edit_cmd_free(&cmd);
+    edit_arg_postfix_new(&subcmd.common.objects);
+    edit_arg_postfix_new(&subcmd.common.objects);
+    edit_cmd_free(&subcmd);
 #endif
 
 #if 0

Modified: brlcad/trunk/src/libged/wdb_obj.c
===================================================================
--- brlcad/trunk/src/libged/wdb_obj.c   2011-07-15 02:37:15 UTC (rev 45499)
+++ brlcad/trunk/src/libged/wdb_obj.c   2011-07-15 02:43:54 UTC (rev 45500)
@@ -287,6 +287,7 @@
     {"color",          ged_color},
     {"comb_color",     ged_comb_color},
     {"edcomb",         ged_edcomb},
+    {"edit",           ged_edit},
     {"edmater",                ged_edmater},
     {"item",           ged_item},
     {"log",            ged_log},
@@ -325,6 +326,7 @@
     {"dump",           wdb_dump_tcl},
     {"dup",            wdb_dup_tcl},
     {"edcomb",         wdb_newcmds_tcl},
+    {"edit",           wdb_newcmds_tcl},
     {"edmater",                wdb_newcmds_tcl},
     {"expand",         wdb_expand_tcl},
     {"facetize",       wdb_facetize_tcl},

Modified: brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl   2011-07-15 02:37:15 UTC 
(rev 45499)
+++ brlcad/trunk/src/tclscripts/archer/ArcherCore.tcl   2011-07-15 02:43:54 UTC 
(rev 45500)
@@ -4848,20 +4848,6 @@
     eval gedWrapper adjust 0 1 1 1 $args
 }
 
-::itcl::body ArcherCore::edit {args} {
-    # For some reason, if args is empty ged_edit isn't called.
-    if {[llength $args] == 0} {
-       set args "help"
-    }
-
-    eval gedWrapper edit 0 0 1 0 $args
-
-    #FIXME: not right at all; we need to redraw all edited objects
-    if {[llength $args] > 2} {
-       redrawObj [lindex $args end] 0
-    }
-}
-
 ::itcl::body ArcherCore::arced {args} {
     eval gedWrapper arced 0 0 1 0 $args
 }
@@ -5136,6 +5122,16 @@
     eval gedWrapper edcomb 0 0 1 1 $args
 }
 
+::itcl::body ArcherCore::edit {args} {
+    eval gedWrapper edit 0 0 1 0 $args
+
+    #FIXME: not right at all; we need to redraw all edited objects
+    #set len [llength $args]
+    #if {$len > 2} {
+       #redrawObj [lindex $args end] 0
+    #}
+}
+
 ::itcl::body ArcherCore::edmater {args} {
     eval gedWrapper edmater 0 0 1 0 $args
 }

Modified: brlcad/trunk/src/tclscripts/archer/tclIndex
===================================================================
--- brlcad/trunk/src/tclscripts/archer/tclIndex 2011-07-15 02:37:15 UTC (rev 
45499)
+++ brlcad/trunk/src/tclscripts/archer/tclIndex 2011-07-15 02:43:54 UTC (rev 
45500)
@@ -447,6 +447,7 @@
 set auto_index(::ArcherCore::edcodes) [list source [file join $dir 
ArcherCore.tcl]]
 set auto_index(::ArcherCore::edcolor) [list source [file join $dir 
ArcherCore.tcl]]
 set auto_index(::ArcherCore::edcomb) [list source [file join $dir 
ArcherCore.tcl]]
+set auto_index(::ArcherCore::edit) [list source [file join $dir 
ArcherCore.tcl]]
 set auto_index(::ArcherCore::edmater) [list source [file join $dir 
ArcherCore.tcl]]
 set auto_index(::ArcherCore::endViewMeasure) [list source [file join $dir 
ArcherCore.tcl]]
 set auto_index(::ArcherCore::endViewRotate) [list source [file join $dir 
ArcherCore.tcl]]

Modified: brlcad/trunk/src/tclscripts/lib/Db.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/lib/Db.tcl      2011-07-15 02:37:15 UTC (rev 
45499)
+++ brlcad/trunk/src/tclscripts/lib/Db.tcl      2011-07-15 02:43:54 UTC (rev 
45500)
@@ -45,6 +45,7 @@
        method dump {args}
        method dup {args}
        method edcomb {args}
+       method edit {args}
        method edmater {args}
        method expand {args}
        method facetize {args}
@@ -324,6 +325,10 @@
     eval $db edcomb $args
 }
 
+::itcl::body Db::edit {args} {
+    eval $db edit $args
+}
+
 ::itcl::body Db::edmater {args} {
     eval $db edmater $args
 }
@@ -561,6 +566,7 @@
     $help add dump     {{file} {write current state of database object to 
file}}
     $help add dup      {{file [prefix]} {check for dup names in 'file'}}
     $help add edcomb   {{comb rflag rid air los mid} {modify combination 
record information}}
+    $help add edit      {{[help] subcmd args} {edit objects via subcommands}}
     $help add edmater  {{comb1 [comb2 ...]} {edit combination materials}}
     $help add expand   {{expression} {globs expression against database 
objects}}
     $help add find     {{[-s] <objects>} {find all references to objects}}

Modified: brlcad/trunk/src/tclscripts/lib/Ged.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/lib/Ged.tcl     2011-07-15 02:37:15 UTC (rev 
45499)
+++ brlcad/trunk/src/tclscripts/lib/Ged.tcl     2011-07-15 02:43:54 UTC (rev 
45500)
@@ -4115,6 +4115,7 @@
     $help add edcodes          {{object(s)} {edit the various codes for the 
specified objects}}
     $help add edcolor          {{} {edit the color table}}
     $help add edcomb           {{comb rflag rid air los mid} {modify 
combination record information}}
+    $help add edit             {{[help] subcmd args} {edit objects via 
subcommands}}
     $help add edmater          {{comb1 [comb2 ...]} {edit combination 
materials}}
     $help add erase            {{<objects>} {remove objects from the screen}}
     $help add ev               {{"[-dfnqstuvwT] [-P #] <objects>"} {evaluate 
objects via NMG tessellation}}
@@ -4248,7 +4249,6 @@
     $help add tops             {{} {find all top level objects}}
     $help add tra              {{[-v|-m] "x y z"} {translate the view}}
     $help add track            {{args} {create a track}}
-    $help add translate                {{x [y [z]] object(s)} {translate 
object(s)}}
     $help add tree             {{[-c] [-i n] [-d n] [-o outfile] object(s)} 
{print out a tree of all members of an object, or all members to depth n in the 
tree if n -d option is supplied}}
     $help add unhide           {{[objects]} {unset the "hidden" flag for the 
specified objects so they will appear in a "t" or "ls" command output}}
     $help add units            {{[mm|cm|m|in|ft|...]}  {change units}}

Modified: brlcad/trunk/src/tclscripts/lib/Mged.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/lib/Mged.tcl    2011-07-15 02:37:15 UTC (rev 
45499)
+++ brlcad/trunk/src/tclscripts/lib/Mged.tcl    2011-07-15 02:43:54 UTC (rev 
45500)
@@ -63,6 +63,7 @@
        method dup {args}
        method E {args}
        method edcomb {args}
+       method edit {args}
        method edmater {args}
        method erase {args}
        method ev {args}
@@ -636,6 +637,10 @@
     return [eval run_cmd edcomb $args]
 }
 
+::itcl::body Mged::edit {args} {
+    return [eval run_cmd edit $args]
+}
+
 ::itcl::body Mged::edmater {args} {
     return [eval run_cmd edmater $args]
 }

Modified: brlcad/trunk/src/tclscripts/lib/tclIndex
===================================================================
--- brlcad/trunk/src/tclscripts/lib/tclIndex    2011-07-15 02:37:15 UTC (rev 
45499)
+++ brlcad/trunk/src/tclscripts/lib/tclIndex    2011-07-15 02:43:54 UTC (rev 
45500)
@@ -105,6 +105,7 @@
 set auto_index(::Db::dump) [list source [file join $dir Db.tcl]]
 set auto_index(::Db::dup) [list source [file join $dir Db.tcl]]
 set auto_index(::Db::edcomb) [list source [file join $dir Db.tcl]]
+set auto_index(::Db::edit) [list source [file join $dir Db.tcl]]
 set auto_index(::Db::edmater) [list source [file join $dir Db.tcl]]
 set auto_index(::Db::expand) [list source [file join $dir Db.tcl]]
 set auto_index(::Db::facetize) [list source [file join $dir Db.tcl]]
@@ -411,6 +412,7 @@
 set auto_index(::Mged::dump) [list source [file join $dir Mged.tcl]]
 set auto_index(::Mged::dup) [list source [file join $dir Mged.tcl]]
 set auto_index(::Mged::edcomb) [list source [file join $dir Mged.tcl]]
+set auto_index(::Mged::edit) [list source [file join $dir Mged.tcl]]
 set auto_index(::Mged::edmater) [list source [file join $dir Mged.tcl]]
 set auto_index(::Mged::erase) [list source [file join $dir Mged.tcl]]
 set auto_index(::Mged::erase_all) [list source [file join $dir Mged.tcl]]
@@ -1085,6 +1087,7 @@
 set auto_index(::cadwidgets::Ged::edcodes) [list source [file join $dir 
Ged.tcl]]
 set auto_index(::cadwidgets::Ged::edcolor) [list source [file join $dir 
Ged.tcl]]
 set auto_index(::cadwidgets::Ged::edcomb) [list source [file join $dir 
Ged.tcl]]
+set auto_index(::cadwidgets::Ged::edit) [list source [file join $dir Ged.tcl]]
 set auto_index(::cadwidgets::Ged::edmater) [list source [file join $dir 
Ged.tcl]]
 set auto_index(::cadwidgets::Ged::end_data_arrow) [list source [file join $dir 
Ged.tcl]]
 set auto_index(::cadwidgets::Ged::end_data_line) [list source [file join $dir 
Ged.tcl]]


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to