Changeset 2138 for trunk/lang/tcl/scripts/objects
- Timestamp:
- Mar 18, 2011, 8:42:59 AM (14 years ago)
- Location:
- trunk/lang/tcl/scripts/objects
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/tcl/scripts/objects/boolean/boolean.rp
r2134 r2138 11 11 12 12 import xml {xmlobj path} { 13 attr import $xmlobj $path 13 14 import_string [$xmlobj get $path.current] 14 15 } -
trunk/lang/tcl/scripts/objects/curve/curve.rp
r2134 r2138 35 35 36 36 storage { 37 private variable _xvecs ;# maps comp name => x-axis vector 38 private variable _yvecs ;# maps comp name => y-axis vector 37 private variable _xvecs ;# maps comp name => x-axis vector 38 private variable _yvecs ;# maps comp name => y-axis vector 39 private variable _hints ;# store "hints" based on attributes 40 private variable _xmarkers "" ;# list of {x,label,options} for markers 41 private variable _ymarkers "" ;# list of {y,label,options} for markers 39 42 } 40 43 clear { … … 45 48 catch {unset _xvecs} 46 49 catch {unset _yvecs} 47 } 48 50 catch {unset _hints} 51 set _xmarkers "" 52 set _ymarkers "" 53 } 54 55 # ------------------------------------------------------------------ 56 # IMPORT: string 57 # ------------------------------------------------------------------ 49 58 import string {val} { 50 59 set xv [blt::vector create \#auto] … … 95 104 } 96 105 106 # ------------------------------------------------------------------ 107 # EXPORT: string 108 # ------------------------------------------------------------------ 97 109 export string {var} { 98 110 upvar $var v … … 113 125 } 114 126 127 # ------------------------------------------------------------------ 128 # IMPORT: xml 129 # ------------------------------------------------------------------ 115 130 import xml {xmlobj path} { 131 attr import $xmlobj $path 132 116 133 foreach cname [$xmlobj children -type component $path] { 117 134 set xv [blt::vector create \#auto] … … 141 158 set _yvecs($cname) $yv 142 159 } 143 } 144 160 161 foreach elem [$xmlobj children -type "marker" $path.xaxis] { 162 set at [$xmlobj get $path.xaxis.$elem.at] 163 set label [$xmlobj get $path.xaxis.$elem.label] 164 set styles [$xmlobj get $path.xaxis.$elem.style] 165 lappend _xmarkers [list $at $label $styles] 166 } 167 foreach elem [$xmlobj children -type "marker" $path.yaxis] { 168 set at [$xmlobj get $path.yaxis.$elem.at] 169 set label [$xmlobj get $path.yaxis.$elem.label] 170 set styles [$xmlobj get $path.yaxis.$elem.style] 171 lappend _ymarkers [list $at $label $styles] 172 } 173 } 174 175 # ------------------------------------------------------------------ 176 # EXPORT: xml 177 # ------------------------------------------------------------------ 145 178 export xml {xmlobj path} { 146 179 foreach cname [array names _xvecs] { … … 158 191 } 159 192 193 # ------------------------------------------------------------------ 194 # COMPARE 195 # ------------------------------------------------------------------ 160 196 compare { 161 197 if {[array size _xvecs] != [array size _xvecs2]} { 162 puts "components: [array size _xvecs] vs [array size _xvecs2]"163 198 return 1 ;# different numbers of components 164 199 } 165 200 foreach cname [array names _xvecs] cname2 [array names _xvecs2] { 166 puts "checking component $cname..."167 201 # take a quick look at the x vector 168 202 set xvlen [$_xvecs($cname) length] 169 puts " x-lengths: [$_xvecs($cname) length] [$_xvecs2($cname2) length]"170 203 if {$xvlen != [$_xvecs2($cname2) length]} { 171 puts " different lengths"172 204 return 1 ;# different lengths of this component 173 205 } … … 175 207 # take a quick look at the y vector 176 208 set yvlen [$_yvecs($cname) length] 177 puts " y-lengths: [$_yvecs($cname) length] [$_yvecs2($cname2) length]"178 209 if {$yvlen != [$_yvecs2($cname2) length]} { 179 puts " different lengths"180 210 return 1 ;# different lengths of this component 181 211 } … … 184 214 set xv $_xvecs($cname) 185 215 set xv2 $_xvecs2($cname2) 186 puts " comparing: $xv vs $xv2"187 216 set scale [blt::vector expr {0.5*(abs(max($xv)-min($xv)) 188 217 + abs(max($xv2)-min($xv2)))}] … … 197 226 set yv $_yvecs($cname) 198 227 set yv2 $_yvecs2($cname2) 199 puts " comparing: $yv vs $yv2"200 228 set scale [blt::vector expr {0.5*(abs(max($yv)-min($yv)) 201 229 + abs(max($yv2)-min($yv2)))}] … … 209 237 return 0 ;# same! 210 238 } 239 240 # ------------------------------------------------------------------ 241 # USAGE: components ?<pattern>? 242 # 243 # Returns a list of names for the various components of this 244 # curve. If the optional glob-style <pattern> is specified, then 245 # it returns only the component names matching the pattern. 246 # ------------------------------------------------------------------ 247 method components {{pattern *}} { 248 set rlist "" 249 foreach cname [array names _xvecs] { 250 if {[string match $pattern $cname]} { 251 lappend rlist $cname 252 } 253 } 254 return $rlist 255 } 256 257 # ------------------------------------------------------------------ 258 # USAGE: mesh <name> 259 # 260 # Returns the xvec for the specified curve component <name>. 261 # ------------------------------------------------------------------ 262 method mesh {cname} { 263 if {[info exists _xvecs($cname)]} { 264 return $_xvecs($cname) ;# return xv 265 } 266 error "bad option \"$cname\": should be [join [lsort [array names _xvecs]] {, }]" 267 } 268 269 # ------------------------------------------------------------------ 270 # USAGE: values <name> 271 # 272 # Returns the yvec for the specified curve component <name>. 273 # ------------------------------------------------------------------ 274 method values {cname} { 275 if {[info exists _yvecs($cname)]} { 276 return $_yvecs($cname) ;# return yv 277 } 278 error "bad option \"$cname\": should be [join [lsort [array names _yvecs]] {, }]" 279 } 280 281 # ------------------------------------------------------------------ 282 # USAGE: limits x|xlin|xlog|y|ylin|ylog 283 # 284 # Returns the {min max} limits for the specified axis. 285 # ------------------------------------------------------------------ 286 method limits {which} { 287 set min "" 288 set max "" 289 switch -- $which { 290 x - xlin { set pos 0; set log 0; set axis xaxis } 291 xlog { set pos 0; set log 1; set axis xaxis } 292 y - ylin - v - vlin { set pos 1; set log 0; set axis yaxis } 293 ylog - vlog { set pos 1; set log 1; set axis yaxis } 294 default { 295 error "bad option \"$which\": should be x, xlin, xlog, y, ylin, ylog, v, vlin, vlog" 296 } 297 } 298 299 blt::vector create tmp zero 300 foreach comp [array names _xvecs] { 301 set arrvar [lindex {_xvecs _yvecs} $pos] 302 set vname [set ${arrvar}($comp)] 303 $vname variable vec 304 305 if {$log} { 306 # on a log scale, use abs value and ignore 0's 307 $vname dup tmp 308 $vname dup zero 309 zero expr {tmp == 0} ;# find the 0's 310 tmp expr {abs(tmp)} ;# get the abs value 311 tmp expr {tmp + zero*max(tmp)} ;# replace 0's with abs max 312 set vmin [blt::vector expr min(tmp)] 313 set vmax [blt::vector expr max(tmp)] 314 } else { 315 set vmin $vec(min) 316 set vmax $vec(max) 317 } 318 319 if {"" == $min} { 320 set min $vmin 321 } elseif {$vmin < $min} { 322 set min $vmin 323 } 324 if {"" == $max} { 325 set max $vmax 326 } elseif {$vmax > $max} { 327 set max $vmax 328 } 329 } 330 blt::vector destroy tmp zero 331 332 set val [attr get min] 333 if {$val ne "" && $min ne ""} { 334 if {$val > $min} { 335 # tool specified this min -- don't go any lower 336 set min $val 337 } 338 } 339 340 set val [attr get max] 341 if {$val ne "" && $max ne ""} { 342 if {$val < $max} { 343 # tool specified this max -- don't go any higher 344 set max $val 345 } 346 } 347 348 return [list $min $max] 349 } 350 351 # ------------------------------------------------------------------ 352 # USAGE: xmarkers 353 # 354 # Returns the list of settings for each marker on the x-axis. 355 # If no markers have been specified the empty string is returned. 356 # ------------------------------------------------------------------ 357 method xmarkers {} { 358 return $_xmarkers 359 } 360 361 # ------------------------------------------------------------------ 362 # USAGE: ymarkers 363 # 364 # Returns the list of settings for each marker on the y-axis. 365 # If no markers have been specified the empty string is returned. 366 # ------------------------------------------------------------------ 367 method ymarkers {} { 368 return $_ymarkers 369 } 370 371 # ------------------------------------------------------------------ 372 # USAGE: hints ?keyword? 373 # 374 # This has been replaced by the "attrs" method in the ObjVal 375 # base class, but is provided here for backward-compatibility 376 # with the XyResult viewer. 377 # 378 # With no args, it returns a list of keywords and corresponding 379 # values for all attributes in this object. If a particular 380 # keyword is specified, then it returns the value for that 381 # attribute. There are a few more "hints" defined here beyond 382 # the object attributes. 383 # ------------------------------------------------------------------ 384 method hints {{keyword ""}} { 385 # first time through, build all of these hint values 386 if {![info exists _hints]} { 387 # start with all of the usual attributes 388 foreach key [attr get] { 389 set _hints($key) [attr get $key] 390 } 391 392 # tweak them a little to produce the values needed for XyResult 393 if {[info exists _hints(xlabel)] && "" != $_hints(xlabel) 394 && [info exists _hints(xunits)] && "" != $_hints(xunits)} { 395 set _hints(xlabel) "$_hints(xlabel) ($_hints(xunits))" 396 } 397 if {[info exists _hints(ylabel)] && "" != $_hints(ylabel) 398 && [info exists _hints(yunits)] && "" != $_hints(yunits)} { 399 set _hints(ylabel) "$_hints(ylabel) ($_hints(yunits))" 400 } 401 402 if {[info exists _hints(group)] && [info exists _hints(label)]} { 403 # pop-up help for each curve 404 set _hints(tooltip) $_hints(label) 405 } 406 } 407 if {$keyword != ""} { 408 if {[info exists _hints($keyword)]} { 409 return $_hints($keyword) 410 } 411 return "" 412 } 413 return [array get _hints] 414 } 211 415 } -
trunk/lang/tcl/scripts/objects/integer/integer.rp
r2134 r2138 31 31 32 32 import xml {xmlobj path} { 33 attr import $xmlobj $path 33 34 import_string [$xmlobj get $path.current] 34 35 } -
trunk/lang/tcl/scripts/objects/number/number.rp
r2134 r2138 85 85 86 86 import xml {xmlobj path} { 87 set units [getAttr units $xmlobj $path]88 import_string [$xmlobj get $path.current] $units87 attr import $xmlobj $path 88 import_string [$xmlobj get $path.current] [attr get units] 89 89 } 90 90 -
trunk/lang/tcl/scripts/objects/string/string.rp
r2134 r2138 13 13 14 14 import xml {xmlobj path} { 15 attr import $xmlobj $path 15 16 import_string [$xmlobj get $path.current] 16 17 }
Note: See TracChangeset
for help on using the changeset viewer.