[Brlcad-commits] CVS: brlcad/src/tclscripts/mged reid.tcl,NONE,1.1
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: Sean M. <br...@us...> - 2005-12-30 00:25:00
|
Update of /cvsroot/brlcad/brlcad/src/tclscripts/mged In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7851 Added Files: reid.tcl Log Message: add a new reid and get_regions command to mged. reid assigns region IDs to all regions under some assembly starting at some given region ID number. get_regions is used by reid to obtain the names of regions under a given combination. --- NEW FILE: reid.tcl --- # R E I D . T C L # BRL-CAD # # Copyright (c) 2005 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 # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # 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. # ### # Author: Christopher Sean Morrison # # assign region IDs to all regions under some assembly starting at # some given region ID number. # set extern_commands "attr" foreach cmd $extern_commands { if {[expr [string compare [info command $cmd] $cmd] != 0]} { puts stderr "[info script]: Application fails to provide command '$cmd'" return } } proc get_regions { args } { if { [llength $args] != 1 } { puts "Usage: get_regions object" return "" } set object [lindex $args 0] set objectData [db get $object] if { [lindex $objectData 0] != "comb" } { # found primitive return "" } set regions "" set children [lt $object] if { $children != "" } { foreach node $children { set child [lindex $node 1] if { [lindex [db get $child] 0] != "comb" } { # ignore primitive continue } if { [lindex [db get $child] 2] == "yes" } { # found a region, add to the list and stop recursion set regions [concat $regions $child] } else { # found a combination, recurse set regions [concat $regions [get_regions $child]] } } } return "$regions" } proc reid { args } { if { [llength $args] != 2 } { puts "Usage: reid assembly regionID" return } set name [lindex $args 0] set regionid [lindex $args 1] set objData [db get $name] if { [lindex $objData 0] != "comb" } { return } set regions [get_regions $name] foreach region $regions { attr set $region region_id $regionid incr regionid } } # Local Variables: # mode: Tcl # tab-width: 8 # c-basic-offset: 4 # tcl-indent-level: 4 # indent-tabs-mode: t # End: # ex: shiftwidth=4 tabstop=8 |