gui_canvas.itcl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. # --------------------------------------------------------------------
  2. #
  3. # canvas.itcl
  4. #
  5. # The classes in this file draw a CSDL cross section on
  6. # a canvas. They act as visitors to the CSDL structure.
  7. # All canvas drawing code is contained here, while the
  8. # CSDL structures themselves support the navigation through
  9. # the structure.
  10. #
  11. # Example:
  12. #
  13. # # assume that a valid CSDL cross section has already been
  14. # # created. Create a canvas visitor objects to draw the
  15. # # stackup.
  16. # grid [canvas .c]
  17. # canvasDraw cd
  18. # Stackup::accept cd .c
  19. #
  20. #
  21. # Bob Techentin
  22. # February 2, 2001
  23. #
  24. # Copyright 2001-2004 Mayo Foundation. All Rights Reserved
  25. # $Id: gui_canvas.itcl,v 1.8 2004/07/20 14:51:55 techenti Exp $
  26. #
  27. # --------------------------------------------------------------------
  28. # --------------------------------------------------------------------
  29. #
  30. # Notes to the developer
  31. #
  32. # Why is it that layers have both a name and a description?
  33. # Which should be displayed in the annotation? Who sets them?
  34. #
  35. # Isn't there a lot of common code between this visitor and others?
  36. # For example, shouldn't we compute the x0,x1,y0,y1 coordinates
  37. # for a trapezoid just once? Shouldn't there be a common
  38. # visitor, which supports computing the appropriate x/y values?
  39. # Or will that work, given that GPGE visitors must know about
  40. # both the drawing x,y coordinates and the actual x,y coordinates?
  41. #
  42. # --------------------------------------------------------------------
  43. package require Itcl
  44. package provide gui 2.0
  45. # --------------------------------------------------------------------
  46. #
  47. # itcl::class canvasDraw
  48. #
  49. # This class is a visitor to the CSDL structures. It draws
  50. # the cross section structure on a Tk canvas.
  51. #
  52. # --------------------------------------------------------------------
  53. itcl::class canvasDraw {
  54. # Perhaps someday soon ...
  55. #inherit CSDLvisitor
  56. public variable annotate 1
  57. # Parameters describing a layer stackup.
  58. variable xOffsetLayer 0.0
  59. variable totalWidth 0.0
  60. variable totalHeight 0.0
  61. variable minThickness 0.0
  62. variable xoff 0.0
  63. variable yoff 0.0
  64. # Drawing controls
  65. # For groups of conductors, we only want to annotate the
  66. # first one in the group, so set a couple of flags for
  67. # the low level shape drawing callbacks.
  68. variable hlcsdlGroup 0
  69. variable firstInGroup 0
  70. # These variables represent the canvasDraw's State,
  71. # which is set in higher level structures, and used in
  72. # lower level structures. The high level structure can
  73. # set the name, color, and tags, which get used when the
  74. # lower level routines actually draw the polygons.
  75. variable canvas
  76. variable color
  77. variable structName
  78. variable description
  79. variable tags
  80. variable tagToSelect ""
  81. # HLCSDL - Stackup Structures
  82. method visitStackup { stackup canvas }
  83. method visitGroundPlane { groundPlane x y }
  84. method visitDielectricLayer { dielectricLayer x y }
  85. method visitRectangleDielectric { rectangleDielectric x y }
  86. method visitRectangleConductors { rectangleConductors x y }
  87. method visitTrapezoidConductors { trapezoidConductors x y }
  88. method visitCircleConductors { circleConductors x y }
  89. # LLCSDL - low level structures
  90. method visitDielectric { dielectric x y }
  91. method visitConductor { conductivity x y }
  92. method visitGround { ground x y }
  93. method visitRectangle { rectangle x y }
  94. method visitTrapezoid { trapezoid x y }
  95. method visitCircle { circle x y }
  96. method visitLayer { layer x y }
  97. method getWidth {} { return [expr { $totalWidth * 0.5 }] }
  98. method getHeight {} { return $totalHeight }
  99. # annotate the pitch and offsets for a set of conductors
  100. method annotatePitchOffsets { x y width height pitch atags }
  101. # get the current color
  102. method getFillColor {}
  103. # set the tag of the object that needs to be drawn selected
  104. method setTagToSelect { tagPrefix } {
  105. set tagToSelect $tagPrefix
  106. }
  107. }
  108. # --------------------------------------------------------------------
  109. # --------------------------------------------------------------------
  110. # --------------------------------------------------------------------
  111. #
  112. # HLCSDL - Stackup Structures
  113. #
  114. # --------------------------------------------------------------------
  115. # --------------------------------------------------------------------
  116. #
  117. # canvasDraw::visitStackup
  118. #
  119. # The canvasDraw visits the layer stackup before any of the
  120. # high level or low level structures. This routine will
  121. # compute scale factors for canvasDraw drawing based on
  122. # total cross section height and width.
  123. #
  124. # --------------------------------------------------------------------
  125. itcl::body canvasDraw::visitStackup { stackup widget } {
  126. set canvas $widget
  127. set structureList $Stackup::structureList
  128. # Drawn cross section should be twice as wide as
  129. # the widest stackup structure. Note that this is
  130. # distinct from the rules defined for the EM simulators,
  131. # such as the 3x factor for MMTL models, which are
  132. # required for reliable simulation. This just looks pretty.
  133. set totalWidth 0.0
  134. set condWidth 0.0
  135. # Find thinnest structure in the stackup, so if there
  136. # are any zero-thickness structures, we can draw them
  137. # with some minimum thickness.
  138. set minHeight 1.0e10
  139. foreach struct $structureList {
  140. if { ([$struct height] > 0.0) && \
  141. ([$struct height] < $minHeight) } {
  142. set minHeight [$struct height]
  143. }
  144. if { [$struct width] > $totalWidth } {
  145. set totalWidth [$struct width]
  146. }
  147. if {! [$struct isa GroundPlane] && ! [$struct isa DielectricLayer]} {
  148. if { [$struct width] > $condWidth } {
  149. set condWidth [$struct width]
  150. }
  151. }
  152. }
  153. if { $minHeight == 1.0e10 } {
  154. set minHeight 10
  155. }
  156. set minThickness [expr {$minHeight * 0.75}]
  157. set y0 0
  158. foreach struct $structureList {
  159. if {[$struct isa GroundPlane] || [$struct isa DielectricLayer]} {
  160. if { [$struct height] > 0.0 } {
  161. set y0 [expr {$y0 + [$struct height]}]
  162. } else {
  163. set y0 [expr {$y0 + $minThickness}]
  164. }
  165. }
  166. }
  167. if { $y0 > $totalWidth } {
  168. set totalWidth $y0
  169. }
  170. ## set xOffsetLayer [expr {$totalWidth / 2.0}]
  171. set totalWidth [expr { $totalWidth * 2 }]
  172. set xOffsetLayer [expr { ($totalWidth - $condWidth) * 0.5}]
  173. set totalHeight $y0
  174. # Draw all the cross section elements. Increment "y0"
  175. # for ground and dielectric layers.
  176. set y0 0
  177. foreach struct $structureList {
  178. $struct accept $this 0 $y0
  179. if {[$struct isa GroundPlane] || [$struct isa DielectricLayer]} {
  180. if { [$struct height] > 0.0 } {
  181. set y0 [expr {$y0 + [$struct height]}]
  182. } else {
  183. set y0 [expr {$y0 + $minThickness}]
  184. }
  185. }
  186. }
  187. # Mark the origin of the drawing.
  188. set xyP [expr { $minHeight * 0.25 } ]
  189. set xyN [expr { $xyP * -1 } ]
  190. $canvas create line $xyN $xyN $xyP $xyP \
  191. -tag annotation
  192. $canvas create line $xyN $xyP $xyP $xyN \
  193. -tag annotation
  194. # Arrange the canvas items so that layers are on the bottom,
  195. # then rectangles (which might be dielectric rectangles),
  196. # then conductors, then annotations. Note that we've set
  197. # tags on the various drawn items just for this purpose.
  198. $canvas lower layer
  199. $canvas raise rectangle
  200. $canvas raise conductor
  201. $canvas raise annotation
  202. }
  203. # --------------------------------------------------------------------
  204. # Structures
  205. #
  206. # We don't actually draw most of the high level
  207. # structures. We defer drawing to the structure shapes
  208. # (Rectangles, Layers, etc.). The shapes have to get
  209. # drawn anyway, so we're not going to duplicate code here.
  210. # --------------------------------------------------------------------
  211. itcl::body canvasDraw::visitGroundPlane { groundPlane x y } {
  212. set structName [namespace tail $groundPlane]
  213. set tags $structName
  214. }
  215. itcl::body canvasDraw::visitDielectricLayer { dielectricLayer x y } {
  216. set structName [namespace tail $dielectricLayer]
  217. set tags $structName
  218. }
  219. # --------------------------------------------------------------------
  220. # There are special annotations for groups of dielectric blocks.
  221. # First, we have to set a couple of flags so that only the first
  222. # dielectric in the group gets dimension annotations. Then we
  223. # have to add an annotation for the pitch.
  224. # --------------------------------------------------------------------
  225. itcl::body canvasDraw::visitRectangleDielectric { rectangleDielectric x y } {
  226. set structName [namespace tail $rectangleDielectric]
  227. set tags $structName
  228. # Set the group and first flags so that low level routines
  229. # know can handle the first drawn conductor differently.
  230. set xoff [$rectangleDielectric cget -xOffset]
  231. set yoff [$rectangleDielectric cget -yOffset]
  232. set hlcsdlGroup 1
  233. set firstInGroup 1
  234. set number [$rectangleDielectric cget -number]
  235. if { $annotate && $number > 1 } {
  236. # Append "annotation" to the tags list
  237. set atags $tags
  238. lappend atags annotation
  239. # Get parameters from the dielectric
  240. set width [$rectangleDielectric cget -width]
  241. set height [$rectangleDielectric height]
  242. set pitch [$rectangleDielectric cget -pitch]
  243. if { $number < 2 } {
  244. return
  245. }
  246. # Figure out coordinates and draw annotation
  247. annotatePitchOffsets [expr { $x + $xoff }] [expr { $y + $yoff }] \
  248. $width $height $pitch $atags
  249. }
  250. }
  251. # --------------------------------------------------------------------
  252. # There are also special annotations for groups of conductors.
  253. # --------------------------------------------------------------------
  254. itcl::body canvasDraw::visitRectangleConductors { rectangleConductors x y } {
  255. set structName [namespace tail $rectangleConductors]
  256. set tags $structName
  257. # Set the group and first flags so that low level routines
  258. # know can handle the first drawn conductor differently.
  259. set xoff [$rectangleConductors cget -xOffset]
  260. set yoff [$rectangleConductors cget -yOffset]
  261. set hlcsdlGroup 1
  262. set firstInGroup 1
  263. set number [$rectangleConductors cget -number]
  264. if { $annotate && $number > 1 } {
  265. # Append "annotation" to the tags list
  266. set atags $tags
  267. lappend atags annotation
  268. # Get parameters from the conductors
  269. set width [$rectangleConductors cget -width]
  270. set height [$rectangleConductors height]
  271. set pitch [$rectangleConductors cget -pitch]
  272. if { $number < 2 } {
  273. return
  274. }
  275. # Figure out coordinates and draw annotation
  276. annotatePitchOffsets [expr { $x + $xoff }] [expr { $y + $yoff }] \
  277. $width $height $pitch $atags
  278. }
  279. }
  280. itcl::body canvasDraw::visitTrapezoidConductors { trapezoidConductors x y } {
  281. set structName [namespace tail $trapezoidConductors]
  282. set tags $structName
  283. # Set the group and first flags so that low level routines
  284. # know can handle the first drawn conductor differently.
  285. set xoff [$trapezoidConductors cget -xOffset]
  286. set yoff [$trapezoidConductors cget -yOffset]
  287. set hlcsdlGroup 1
  288. set firstInGroup 1
  289. set number [$trapezoidConductors cget -number]
  290. if { $annotate && $number > 1 } {
  291. # Append "annotation" to the tags list
  292. set atags $tags
  293. lappend atags annotation
  294. # Get parameters from the conductors
  295. set height [$trapezoidConductors height]
  296. set pitch [$trapezoidConductors cget -pitch]
  297. set number [$trapezoidConductors cget -number]
  298. set twidth [$trapezoidConductors cget -topWidth]
  299. set twidth [$trapezoidConductors cget -topWidth]
  300. set bwidth [$trapezoidConductors cget -bottomWidth]
  301. set width [expr { ($twidth + $bwidth) * 0.5 }]
  302. # Figure out coordinates and draw annotation
  303. annotatePitchOffsets [expr { $x + $xoff }] [expr { $y + $yoff }] \
  304. $width $height $pitch $atags
  305. }
  306. }
  307. itcl::body canvasDraw::visitCircleConductors { circleConductors x y } {
  308. set structName [namespace tail $circleConductors]
  309. set tags $structName
  310. # Set the group and first flags so that low level routines
  311. # know can handle the first drawn conductor differently.
  312. set xoff [$circleConductors cget -xOffset]
  313. set yoff [$circleConductors cget -yOffset]
  314. set hlcsdlGroup 1
  315. set firstInGroup 1
  316. set number [$circleConductors cget -number]
  317. if { $annotate && $number > 1 } {
  318. # Append "annotation" to the tags list
  319. set atags $tags
  320. lappend atags annotation
  321. # Get parameters from the conductors
  322. set height [$circleConductors height]
  323. set pitch [$circleConductors cget -pitch]
  324. set width [$circleConductors cget -diameter]
  325. # Figure out coordinates and draw annotation
  326. annotatePitchOffsets [expr { $x + $xoff }] [expr { $y + $yoff }] \
  327. $width $height $pitch $atags
  328. }
  329. }
  330. # --------------------------------------------------------------------
  331. # LLCSDL - low level structures
  332. #
  333. # We don't draw the structures either. The actual drawing
  334. # is done by the shapes. But we *do* capture important
  335. # information from the structures which gets used during
  336. # the shape drawing code.
  337. #
  338. # Set the color, append tags for structuture type
  339. # (e.g., "conductor") and structure name. Create
  340. # a description with some properties from the structure.
  341. # --------------------------------------------------------------------
  342. itcl::body canvasDraw::visitDielectric { dielectric x y } {
  343. set color #90ee90 ;# "lightgreen"
  344. lappend tags dielectric $dielectric
  345. set perm [$dielectric cget -permittivity]
  346. set ltan [$dielectric cget -lossTangent]
  347. set description "$structName: econst=$perm, lossTan=$ltan"
  348. }
  349. itcl::body canvasDraw::visitConductor { conductor x y } {
  350. set color #ffff00 ;# "yellow"
  351. lappend tags conductor $conductor
  352. set cond [$conductor cget -conductivity]
  353. set description "$structName cond=$cond"
  354. }
  355. itcl::body canvasDraw::visitGround { ground x y} {
  356. set color #add8e6 ;# "lightblue"
  357. lappend tags ground $ground
  358. set description "$structName"
  359. }
  360. # --------------------------------------------------------------------
  361. #
  362. # getFillColor
  363. #
  364. # If one of the current set of tags matches $tagToSelect,
  365. # then we have to return the select color. Otherwise,
  366. # we use the current fill color.
  367. #
  368. # --------------------------------------------------------------------
  369. itcl::body canvasDraw::getFillColor {} {
  370. if { [lsearch $tags $tagToSelect] < 0 } {
  371. return $color
  372. } else {
  373. return #ff0000 ;# "red"
  374. }
  375. }
  376. # --------------------------------------------------------------------
  377. #
  378. # annotatePitchOffsets
  379. #
  380. # Draw arrows and dimension text for offsets and pitch
  381. # between multiple objects.
  382. #
  383. # --------------------------------------------------------------------
  384. itcl::body canvasDraw::annotatePitchOffsets { x y width height pitch atags } {
  385. set x0 [expr {[length $x] + $width/2.0}]
  386. set x1 [expr {$x0 + [length $pitch]}]
  387. set ycenter [expr {[length $y] + [length $height]/2.0}]
  388. set xcenter [expr {0.5 * ($x0+$x1)}]
  389. $canvas create line $x0 $ycenter $x1 $ycenter \
  390. -arrow both -tag $atags
  391. $canvas create text $xcenter $ycenter \
  392. -anchor s -text $pitch -tag $atags
  393. if { $xoff > 0 } {
  394. set x1 [length $x]
  395. set x0 [expr { $x1 - $xoff }]
  396. set ycenter [expr { [length $y] - $yoff }]
  397. set xcenter [expr {0.5 * ($x0+$x1)}]
  398. $canvas create line $x0 $ycenter $x1 $ycenter \
  399. -arrow both -tag $atags
  400. $canvas create text $xcenter $ycenter \
  401. -anchor n -text $xoff -tag $atags
  402. }
  403. if { $yoff > 0 } {
  404. set xcenter [length $x]
  405. set y1 [length $y]
  406. set y0 [expr { $y1 - $yoff }]
  407. set ycenter [expr {0.5 * ($y0+$y1)}]
  408. $canvas create line $xcenter $y0 $xcenter $y1 \
  409. -arrow both -tag $atags
  410. $canvas create text $xcenter $ycenter \
  411. -anchor e -text $yoff -tag $atags
  412. }
  413. }
  414. # --------------------------------------------------------------------
  415. #
  416. # canvasDraw::visitRectangle
  417. #
  418. # --------------------------------------------------------------------
  419. itcl::body canvasDraw::visitRectangle { rectangle x y } {
  420. # (x0,y1) + ----------- + (x1,y1)
  421. # | |
  422. # (x0,y0) + ----------- + (x1,y0)
  423. set width [$rectangle width]
  424. set height [$rectangle height]
  425. set x0 [length $x]
  426. set y0 [length $y]
  427. set x1 [expr {$x0 + $width}]
  428. set y1 [expr {$y0 + $height}]
  429. set fillcolor [getFillColor]
  430. lappend tags rectangle
  431. $canvas create rectangle $x0 $y0 $x1 $y1 \
  432. -fill $fillcolor -outline black -tags [concat $tags shape]
  433. if { $annotate && ( ! $hlcsdlGroup || $firstInGroup ) } {
  434. # Append "annotation" to the tags list
  435. set atags $tags
  436. lappend atags annotation
  437. set xcenter [expr { ($x0 + $x1) * 0.5 }]
  438. set ycenter [expr { ($y0 + $y1) * 0.5 }]
  439. # Create the text and arrows. Note that we get the
  440. # string values directly from the shape, which
  441. # might include units.
  442. $canvas create line $x0 $y0 $x1 $y0 \
  443. -arrow both -tag $atags
  444. $canvas create text $xcenter $y0 \
  445. -anchor n -text "[$rectangle cget -width]" -tag $atags
  446. $canvas create line $x0 $y0 $x0 $y1 \
  447. -arrow both -tag $atags
  448. $canvas create text $x0 $ycenter \
  449. -anchor e -text "[$rectangle cget -height] " -tag $atags
  450. set firstInGroup 0
  451. }
  452. }
  453. # --------------------------------------------------------------------
  454. #
  455. # canvasDraw::visitTrapezoid
  456. #
  457. # --------------------------------------------------------------------
  458. itcl::body canvasDraw::visitTrapezoid { trapezoid x y } {
  459. # (x1,y1) + ----------- + (x2,y1)
  460. # / \
  461. # (x0,y0) + --------------- + (x3,y0)
  462. set x [length $x]
  463. set y [length $y]
  464. set topWidth [length [$trapezoid cget -topWidth]]
  465. set bottomWidth [length [$trapezoid cget -bottomWidth]]
  466. set width [$trapezoid width]
  467. set height [$trapezoid height]
  468. set x0 [expr {$x + ($width - $bottomWidth)/2}]
  469. set x1 [expr {$x + ($width - $topWidth)/2}]
  470. set x2 [expr {$x + ($width + $topWidth)/2}]
  471. set x3 [expr {$x + ($width + $bottomWidth)/2}]
  472. set y0 $y
  473. set y1 [expr {$y + $height}]
  474. set fillcolor [getFillColor]
  475. lappend tags trapezoid
  476. $canvas create polygon $x0 $y0 $x1 $y1 $x2 $y1 $x3 $y0 \
  477. -fill $fillcolor -outline black -tags [concat $tags shape]
  478. if { $annotate && ( ! $hlcsdlGroup || $firstInGroup ) } {
  479. # Append "annotation" to the tags list
  480. set atags $tags
  481. lappend atags annotation
  482. set xcenter [expr {($x0 + $x3)/2}]
  483. set ycenter [expr {($y0 + $y1)/2}]
  484. $canvas create line $x0 $y0 $x3 $y0 \
  485. -arrow both -tag $atags
  486. $canvas create text $xcenter $y0 \
  487. -anchor n -text $bottomWidth -tag $atags
  488. $canvas create line $x1 $y1 $x2 $y1 \
  489. -arrow both -tag annotation
  490. $canvas create text $xcenter $y1 \
  491. -anchor s -text $topWidth -tag $atags
  492. $canvas create line $x0 $y0 $x0 $y1 \
  493. -arrow both -tag $atags
  494. $canvas create text $x0 $ycenter \
  495. -anchor e -text "$height " -tag $atags
  496. set firstInGroup 0
  497. }
  498. }
  499. # --------------------------------------------------------------------
  500. #
  501. # canvasDraw::visitCircle
  502. #
  503. # --------------------------------------------------------------------
  504. itcl::body canvasDraw::visitCircle { circle x y } {
  505. # (x0,y1) + --- + (x1,y1)
  506. # | | (just imagine a circle in the box)
  507. # (x0,y0) + --- + (x1,y0)
  508. set diameter [length [$circle cget -diameter]]
  509. set x0 [length $x]
  510. set y0 [length $y]
  511. set x1 [expr {$x0 + $diameter}]
  512. set y1 [expr {$y0 + $diameter}]
  513. set fillcolor [getFillColor]
  514. lappend tags circle
  515. $canvas create oval $x0 $y0 $x1 $y1 \
  516. -fill $fillcolor -outline black -tags [concat $tags shape]
  517. if { $annotate && ( ! $hlcsdlGroup || $firstInGroup ) } {
  518. # Append "annotation" to the tags list
  519. set atags $tags
  520. lappend atags annotation
  521. set xcenter [expr {[length $x] + [length $diameter]/2}]
  522. $canvas create line $x0 $y0 $x1 $y0 \
  523. -arrow both -tag $atags
  524. $canvas create text $xcenter $y0 \
  525. -anchor n -text $diameter -tag $atags
  526. set firstInGroup 0
  527. }
  528. }
  529. # --------------------------------------------------------------------
  530. #
  531. # canvasDraw::visitLayer
  532. #
  533. # --------------------------------------------------------------------
  534. itcl::body canvasDraw::visitLayer { layer x y } {
  535. # The layer width is really $totalWidth. Subtract
  536. # the X offset from X0. (prim_coord will add it back in
  537. # to get us back to zero)
  538. set x0 [expr {[length $x]-$xOffsetLayer}]
  539. set x1 [expr {$x0 + $totalWidth}]
  540. # Figure out the layer thickness. If the thickness is
  541. # zero, then set the drawing thickness to the minimum.
  542. set y0 [length $y]
  543. set thickness [length [$layer cget -thickness]]
  544. if { $thickness > 0.0 } {
  545. set y1 [expr {$y0 + $thickness}]
  546. } else {
  547. set y1 [expr {$y0 + $minThickness}]
  548. set thickness $minThickness
  549. }
  550. set fillcolor [getFillColor]
  551. lappend tags layer
  552. $canvas create rectangle $x0 $y0 $x1 $y1 \
  553. -fill $fillcolor -outline black \
  554. -tags [concat $tags shape]
  555. if { $annotate } {
  556. # Append "annotation" to the tags list
  557. set atags $tags
  558. lappend atags annotation
  559. # Add the description`
  560. set xat [expr { $x1 - ( $x1 - $x0 ) * 0.1 }]
  561. set yat $y1
  562. set anchor ne
  563. $canvas create text $xat $yat -anchor $anchor \
  564. -text $description -tags $atags
  565. # Add a dimension line
  566. set x3 [expr {$x0 + 0.98*($x1-$x0)}]
  567. set x3a [expr {$x0 + 0.97*($x1-$x0)}]
  568. set y3 [expr {double($y0+$y1)/2}]
  569. $canvas create line $x3 $y0 $x3 $y1 \
  570. -arrow both -tag $atags
  571. $canvas create text $x3a $y3 \
  572. -anchor e -text $thickness -tag $atags
  573. }
  574. }