Changeset 1342 for trunk/gui/scripts/deviceLayout1D.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/deviceLayout1D.tcl
r676 r1342 53 53 private variable _slabs "" ;# list of node names for slabs in device 54 54 private variable _z0 "" ;# list parallel to _slabs with z0 55 55 ;# coord for lhs of each slab 56 56 private variable _z1 "" ;# list parallel to _slabs with z1 57 57 ;# coord for rhs of each slab 58 58 private variable _maters "" ;# list parallel to _slabs with material 59 59 ;# for each slab 60 60 private variable _colors "" ;# list parallel to _slabs with color 61 61 ;# for each slab 62 62 63 63 private variable _controls ;# maps control path => status on/off … … 65 65 private variable _icons ;# maps icon data => image handle 66 66 } 67 67 68 68 itk::usual DeviceLayout1D { 69 69 keep -background -cursor … … 86 86 87 87 itk_component add area { 88 88 canvas $itk_interior.area -borderwidth 0 -highlightthickness 0 89 89 } { 90 91 92 90 usual 91 ignore -borderwidth -relief 92 ignore -highlightthickness -highlightbackground -highlightcolor 93 93 } 94 94 pack $itk_component(area) -expand yes -fill both 95 95 bind $itk_component(area) <Configure> \ 96 96 [list $_dispatcher event -idle !redraw] 97 97 98 98 eval itk_initialize $args … … 111 111 itcl::body Rappture::DeviceLayout1D::limits {} { 112 112 if {[$_dispatcher ispending !layout]} { 113 114 113 $_dispatcher cancel !layout 114 _layout 115 115 } 116 116 set zmin [lindex $_z0 0] … … 128 128 itcl::body Rappture::DeviceLayout1D::extents {what} { 129 129 switch -- $what { 130 131 132 133 130 bar3D { return $_sizes(bar45) } 131 default { 132 error "bad option \"$what\": should be bar3D" 133 } 134 134 } 135 135 } … … 144 144 itcl::body Rappture::DeviceLayout1D::controls {option args} { 145 145 switch -- $option { 146 147 148 149 150 151 152 153 154 155 156 146 add { 147 if {[llength $args] != 1} { 148 error "wrong # args: should be \"controls add path\"" 149 } 150 set path [lindex $args 0] 151 set _controls($path) 1 152 $_dispatcher event -idle !layout 153 } 154 remove { 155 error "not yet implemented" 156 } 157 157 } 158 158 } … … 180 180 # add the maximum size of any embedded icons: 181 181 if {$_device != ""} { 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 182 foreach nn [$_device children components] { 183 set icon [$_device get components.$nn.about.icon] 184 if {"" != $icon} { 185 if {[info exists _icons($icon)]} { 186 set imh $_icons($icon) 187 } else { 188 set imh [image create photo -data $icon] 189 set _icons($icon) $imh 190 } 191 192 set w [image width $_icons($icon)] 193 if {$w > $wmax} { 194 set wmax $w 195 } 196 197 set h [image height $_icons($icon)] 198 if {$h > $hmax} { 199 set hmax $h 200 } 201 } 202 } 203 203 } 204 204 set _sizes(bararea) $hmax … … 207 207 # see if any of the slabs has a material 208 208 foreach m $_maters { 209 210 211 212 213 209 if {"" != $m} { 210 set extra [expr {1.5*[font metrics $fnt -linespace]}] 211 set hmax [expr {$hmax+$extra}] 212 break 213 } 214 214 } 215 215 216 216 # see if any of the slabs has a label 217 217 if {$_device != ""} { 218 219 220 221 222 223 224 218 foreach nn [$_device children components] { 219 if {"" != [$_device get components.$nn.about.label]} { 220 set extra [expr {1.2*[font metrics $fnt -linespace]}] 221 set hmax [expr {$hmax+$extra}] 222 break 223 } 224 } 225 225 } 226 226 … … 228 228 set oldh [component hull cget -height] 229 229 if {$wmax != $oldw || $hmax != $oldh} { 230 231 230 component hull configure -width $wmax -height $hmax 231 $_dispatcher event -idle !redraw 232 232 } 233 233 set _sizes(header) [expr {$hmax - $_sizes(bararea)}] … … 241 241 242 242 if {$_device != ""} { 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 243 # get the default system of units 244 set units [set defunits [$_device get units]] 245 if {$units == "arbitrary" || $units == ""} { 246 set defunits "m" 247 set units "um" 248 } 249 250 foreach nn [$_device children components] { 251 switch -glob -- $nn { 252 box* { 253 # get x-coord for each corner 254 set c0 [$_device get components.$nn.corner0] 255 regsub -all , $c0 { } c0 256 set c0 [lindex $c0 0] 257 set c0 [Rappture::Units::convert $c0 \ 258 -context $defunits -to $units -units off] 259 260 set c1 [$_device get components.$nn.corner1] 261 regsub -all , $c1 { } c1 262 set c1 [lindex $c1 0] 263 set c1 [Rappture::Units::convert $c1 \ 264 -context $defunits -to $units -units off] 265 266 lappend slabs components.$nn 267 lappend z0 $c0 268 lappend z1 $c1 269 270 set m [$_device get components.$nn.material] 271 lappend maters $m 272 273 if {"" != $m} { 274 set c [_mater2color $m] 275 } else { 276 set c [$_device get components.$nn.about.color] 277 } 278 if {"" == $c} { set c gray } 279 lappend colors $c 280 } 281 default { 282 # element not recognized -- skip it 283 } 284 } 285 } 286 286 } 287 287 288 288 # something change? then store new layout and redraw 289 289 if {![string equal $z0 $_z0] 290 291 292 293 294 295 296 297 298 299 290 || ![string equal $z1 $_z1] 291 || ![string equal $maters $_maters] 292 || ![string equal $colors $_colors]} { 293 set _slabs $slabs 294 set _z0 $z0 295 set _z1 $z1 296 set _maters $maters 297 set _colors $colors 298 299 $_dispatcher event -idle !redraw 300 300 } 301 301 } … … 323 323 324 324 for {set i 0} {$i < [llength $_slabs]} {incr i} { 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 325 set name [lindex $_slabs $i] 326 set z0 [lindex $_z0 $i] 327 set z1 [lindex $_z1 $i] 328 set xx0 [expr {double($z0)/$zmax * ($x1-$x0) + $x0}] 329 set xx1 [expr {double($z1)/$zmax * ($x1-$x0) + $x0}] 330 331 set icon [$_device get $name.about.icon] 332 if {"" != $icon} { 333 if {[info exists _icons($icon)]} { 334 set imh $_icons($icon) 335 } else { 336 set imh [image create photo -data $icon] 337 set _icons($icon) $imh 338 } 339 _drawIcon $i $xx0 $xx1 $imh 340 } else { 341 _drawLayer $i $xx0 $xx1 342 } 343 _drawAnnotation $i $xx0 $xx1 344 344 } 345 345 } … … 368 368 369 369 if {$index < [llength $_slabs]} { 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 370 set fcolor [lindex $_colors $index] 371 372 # 373 # Draw one segment of the bar in the canvas: 374 # 375 # ___________________ ____ y1 376 # / /| ____ y0p 377 # /__________________/ / ____ y1p 378 # |__________________|/: ____ y0 379 # : : : : 380 # x0 x0p x1 x1p 381 # 382 $c create polygon \ 383 $x0 $y0 $x1 $y0 $x1p $y0p $x1p $y1 $x0p $y1 $x0 $y1p $x0 $y0 \ 384 -outline $lcolor -fill $fcolor 385 $c create line $x0 $y1p $x1 $y1p -fill $lcolor 386 387 # 388 # Draw the outline around the end cap 389 # 390 $c create line $x1 $y0 $x1 $y1p $x1p $y1 -fill $lcolor 391 391 } 392 392 } … … 445 445 set mater [lindex $_maters $index] 446 446 if {"" != $mater} { 447 448 449 450 451 452 453 454 447 set x $x1p 448 $c create rectangle [expr {$x-10}] [expr {$y-14}] \ 449 [expr {$x-0}] [expr {$y-4}] \ 450 -outline black -fill [_mater2color $mater] 451 set x [expr {$x-12}] 452 $c create text $x [expr {$y-7}] -anchor e \ 453 -text $mater 454 set y [expr {$y-1.5*$lh}] 455 455 } 456 456 … … 459 459 # 460 460 if {"" != $_device} { 461 462 463 464 465 461 set label [$_device get $elem.about.label] 462 if {"" != $label} { 463 $c create text [expr {0.5*($x0p+$x1p)}] $y -anchor s \ 464 -text $label 465 } 466 466 } 467 467 } … … 477 477 set color [$lib get materials.($mater).color] 478 478 if {$color != ""} { 479 479 return $color 480 480 } 481 481 return gray … … 501 501 itcl::configbody Rappture::DeviceLayout1D::device { 502 502 if {$itk_option(-device) != ""} { 503 504 505 503 if {![Rappture::library isvalid $itk_option(-device)]} { 504 error "bad value \"$itk_option(-device)\": should be Rappture::Library" 505 } 506 506 } 507 507 set _device $itk_option(-device) … … 516 516 itcl::configbody Rappture::DeviceLayout1D::width { 517 517 if {[catch { 518 518 winfo pixels $itk_component(hull) $itk_option(-width) 519 519 } pixels]} { 520 520 error "bad screen distance \"$itk_option(-width)\"" 521 521 } 522 522 $_dispatcher event -idle !layout … … 530 530 itcl::configbody Rappture::DeviceLayout1D::devicesize { 531 531 if {[catch { 532 532 winfo pixels $itk_component(hull) $itk_option(-devicesize) 533 533 } pixels]} { 534 534 error "bad screen distance \"$itk_option(-devicesize)\"" 535 535 } 536 536 set _sizes(bar) $pixels … … 561 561 itcl::configbody Rappture::DeviceLayout1D::leftmargin { 562 562 if {[catch { 563 563 winfo pixels $itk_component(hull) $itk_option(-leftmargin) 564 564 } pixels]} { 565 565 error "bad screen distance \"$itk_option(-leftmargin)\"" 566 566 } 567 567 set _sizes(lm) $pixels … … 579 579 itcl::configbody Rappture::DeviceLayout1D::rightmargin { 580 580 if {[catch { 581 581 winfo pixels $itk_component(hull) $itk_option(-rightmargin) 582 582 } pixels]} { 583 583 error "bad screen distance \"$itk_option(-rightmargin)\"" 584 584 } 585 585 set _sizes(rm) [expr {($pixels > 0) ? $pixels : $_sizes(bar45)}]
Note: See TracChangeset
for help on using the changeset viewer.