gui.tcl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # gui.tcl
  4. #
  5. # Support functions for TNT GUI construction.
  6. #
  7. # ::gui::guiBuildComboBox
  8. # ::gui::guiBuildButton
  9. # ::gui::guiPopupWarning
  10. # ::gui::guiBuildLabelEntry
  11. # ::gui::guiCheckbox_create
  12. # ::gui::guiCheckbox_add
  13. # ::gui::guiCheckbox_destroy
  14. # ::gui::guiPopdownBusy
  15. # ::gui::guiPopupBusy
  16. # ::gui::guiPopupFile
  17. # ::gui::guiCloseResults
  18. # ::gui::guiSetCursorBusy
  19. # ::gui::guiSetCursorNormal
  20. # ::gui::guiBuildNmeValList
  21. # ::gui::drainEventQueue
  22. #
  23. # Copyright 2002-2004 Mayo Foundation. All Rights Reserved
  24. # $Id: gui.tcl,v 1.11 2004/07/20 14:51:55 techenti Exp $
  25. #
  26. #-----------------------------------------------------------------
  27. package provide gui 2.0
  28. namespace eval ::gui:: {
  29. variable busyLabel
  30. variable rbInfo
  31. variable ButtonCount 0
  32. variable CheckboxCount 0
  33. variable LabelCount 0
  34. variable ComboCount 0
  35. variable _annotateFlag 1
  36. variable f1
  37. variable tf1
  38. variable tf3
  39. variable _groundFrame
  40. variable _activeFrame
  41. variable rectCondCB
  42. variable circCondCB
  43. variable trapCondCB
  44. variable permittivityCB
  45. variable ltangentCB
  46. variable _tree
  47. variable _treect 0
  48. variable _title ""
  49. variable _canvas
  50. variable _canvasDraw_visitor
  51. variable _xSectionObjectList
  52. variable _xSectionIndexList
  53. ######################################
  54. # Groundplane variables
  55. ######################################
  56. variable _gname
  57. variable _gthickness
  58. ######################################
  59. # Dielectric variables
  60. ######################################
  61. variable _dname
  62. variable _thickness 0
  63. variable _permittivity 1.0
  64. variable _permeability 1.0
  65. variable _lossTangent 0.0
  66. ######################################
  67. # Rectangular dielectric variables
  68. ######################################
  69. variable _dRname
  70. variable _dpermittivity 1.0
  71. variable _dpermeability 1.0
  72. variable _dlossTangent 0.0
  73. variable _dwidth 1
  74. variable _dheight 1
  75. variable _dnumber 1
  76. variable _dpitch 0
  77. variable _dxoffset 0
  78. variable _dyoffset 0
  79. ######################################
  80. # Rectangular conductor variables
  81. ######################################
  82. variable _rname
  83. variable _rconductivity copper
  84. variable _rwidth 1
  85. variable _rheight 1
  86. variable _rnumber 1
  87. variable _rpitch 0
  88. variable _rxoffset 0
  89. variable _ryoffset 0
  90. ######################################
  91. # Circular conductor variables
  92. ######################################
  93. variable _cname
  94. variable _cconductivity copper
  95. variable _cdiameter 1
  96. variable _cnumber 1
  97. variable _cpitch 0
  98. variable _cxoffset 0
  99. variable _cyoffset 0
  100. ######################################
  101. # Trapezoidal conductor variables
  102. ######################################
  103. variable _tname
  104. variable _tconductivity copper
  105. variable _ttopwidth 1
  106. variable _tbotwidth 1
  107. variable _theight 1
  108. variable _tnumber 1
  109. variable _tpitch 0
  110. variable _txoffset 0
  111. variable _tyoffset 0
  112. ######################################
  113. # Counter for ground-plane
  114. ######################################
  115. variable _grndCount 0
  116. ######################################
  117. # Counter for dielectrics
  118. ######################################
  119. variable _dielCount 0
  120. ######################################
  121. # Counter for ground-plane
  122. ######################################
  123. variable _condCount 0
  124. variable _nodename ""
  125. variable _nodedirectory ""
  126. variable _currentNode ""
  127. variable scaleFactor
  128. variable xrange
  129. variable yrange
  130. variable selectedObject
  131. variable _tagSelected ""
  132. variable _previousColor black
  133. variable _cValList
  134. variable _pValList
  135. variable _ltValList
  136. variable _printerName princess
  137. variable _colorMode color
  138. variable _savePrinterName
  139. variable _saveColorMode
  140. variable _num_c_segs 10
  141. variable _num_p_segs 10
  142. namespace export _xSectionObjectList
  143. namespace export _xSectionIndexList
  144. namespace export f1
  145. namespace export tf1
  146. namespace export tf3
  147. namespace export _nodename
  148. namespace export guiBuildButton
  149. namespace export guiOpenExisting
  150. namespace export guiOpenNew
  151. namespace export guiBuildComboBox
  152. namespace export guiBuildLabelEntry
  153. namespace export guiBuildNmeValList
  154. namespace export guiCheckbox_create
  155. namespace export guiCheckbox_add
  156. namespace export guiCheckbox_destroy
  157. namespace export guiCreateElements
  158. namespace export guiPopdownBusy
  159. namespace export guiPopupBusy
  160. namespace export guiPopupFile
  161. namespace export guiPopupResultsFile
  162. namespace export guiPopupWarning
  163. namespace export guiSetCursorBusy
  164. namespace export guiSetCursorNormal
  165. namespace export guiSetupPrinter
  166. namespace export guiGenRLinputFiles
  167. namespace export guiRunRLbatch
  168. namespace export guiRunRLgraphical
  169. namespace export guiGenCAPinputFiles
  170. namespace export guiRunCAPbatch
  171. namespace export guiRunCAPgraphical
  172. namespace export guiPrintPS
  173. namespace export guiReadNewConductivityList
  174. namespace export guiReadNewLossTangentList
  175. namespace export guiReadNewPermittivityList
  176. namespace export guiRunFee2dDisplay
  177. namespace export guiRunFee2dRun
  178. namespace export guiRunFee2dPlotTranParameter
  179. namespace export guiSaveFee2d
  180. namespace export guiRunSweepMMTL
  181. namespace export guiRunIterateMMTL
  182. namespace export guiSave
  183. namespace export guiSaveAndRun
  184. namespace export guiSaveAs
  185. namespace export guiSaveGraphicAndRunOld
  186. namespace export guiSim2hspicew
  187. namespace export gui_toggleAnnotation
  188. namespace export guiViewPlotP
  189. namespace export guiViewTheGraph
  190. # Canvas functions
  191. namespace export _canvas_zoom
  192. namespace export _canvas_zoom_fit
  193. namespace export _canvas_zooming_mode
  194. namespace export _canvas_zoomStart
  195. namespace export _canvas_zoomMove
  196. namespace export _canvas_zoomEnd
  197. namespace export _canvas_redraw
  198. namespace export _canvas_toggleAnnotation
  199. namespace export _canvas_select
  200. namespace export _canvas_print
  201. namespace export _helpModCom
  202. namespace export _helpDelComp
  203. namespace export _helpMovComp
  204. namespace export _helpAddComp
  205. namespace export _helpSweep
  206. namespace export _helpIterate
  207. namespace export _helpRunSimulation
  208. namespace export _helpSaveRunSimulation
  209. namespace export _helpMaterialLists
  210. namespace export _helpFiles
  211. namespace export _helpFEE2D
  212. #-------------------------------------------------------------
  213. # Routines called by xmission.
  214. #-------------------------------------------------------------
  215. namespace export _mmtlCreateMain
  216. namespace export _runAndSend
  217. }
  218. ##################################################################
  219. # Bulid a ComboBox widget.
  220. # parent : parent widget
  221. # varg : variable that contains the value
  222. # labelStrg: label
  223. ##################################################################
  224. proc ::gui::guiBuildComboBox { parent varg labelStrg } {
  225. set lb [Label $parent.l$::gui::ComboCount -text $labelStrg]
  226. set sb [ComboBox $parent.s$::gui::ComboCount \
  227. -textvariable $varg \
  228. -values {1 2 3 4 5 6 7 8 9 10} \
  229. -width 10]
  230. incr ::gui::ComboCount
  231. grid $lb $sb -sticky news -padx 4 -pady 4
  232. grid $lb -sticky e
  233. }
  234. ##################################################################
  235. # Build a button.
  236. ##################################################################
  237. proc ::gui::guiBuildButton { parent txt cmmnd helptxt} {
  238. set but [Button $parent.but$::gui::ButtonCount \
  239. -text $txt -borderwidth 8 \
  240. -helptext $helptxt \
  241. -command $cmmnd \
  242. -relief link]
  243. incr ::gui::ButtonCount
  244. return $but
  245. }
  246. proc ::gui::guiPopupWarning { mssge } {
  247. tk_dialog .tkw "Warning" $mssge warning {} "OK"
  248. }
  249. ##################################################################
  250. # Build a LabelEntry widget.
  251. # parent : parent widget
  252. # varg : variable that contains the value
  253. # labelStrg: label
  254. ##################################################################
  255. proc ::gui::guiBuildLabelEntry { parent varg labelStrg } {
  256. set lab [Label $parent.lab$::gui::LabelCount -text $labelStrg]
  257. set ent [Entry $parent.ent$::gui::LabelCount -textvariable $varg -width 10]
  258. incr ::gui::LabelCount
  259. grid $lab $ent -sticky new -padx 4 -pady 4
  260. grid $lab -sticky e
  261. }
  262. proc ::gui::guiCheckbox_create {win {title ""}} {
  263. set ::gui::rbInfo($win-current) ""
  264. set ::gui::rbInfo($win-count) 0
  265. frame $win -class Checkbox
  266. grid rowconfigure $win 0 -weight 1
  267. grid columnconfigure $win 0 -weight 1
  268. if { $title != "" } {
  269. label $win.title -text $title
  270. pack $win.title -side top
  271. }
  272. frame $win.border -borderwidth 2 -relief groove
  273. pack $win.border -side top -expand true -fill both
  274. bind $win <Destroy> [ list ::gui::guiCheckbox_destroy $win ]
  275. return $win
  276. }
  277. proc ::gui::guiCheckbox_add { win choice varble {command ""}} {
  278. set cmnd [format {set %s 0} $varble]
  279. eval $cmnd
  280. set name "$win.border.rb[incr ::gui::rbInfo($win-count)]"
  281. checkbutton $name -text $choice -command $command \
  282. -variable $varble
  283. grid $name -row $::gui::CheckboxCount -sticky w
  284. incr ::gui::CheckboxCount
  285. }
  286. proc ::gui::guiCheckbox_destroy { win } {
  287. unset ::gui::rbInfo($win-count)
  288. unset ::gui::rbInfo($win-current)
  289. }
  290. ##################################################################
  291. ##################################################################
  292. proc ::gui::guiPopdownBusy {} {
  293. destroy $::gui::busyLbl
  294. }
  295. ##################################################################
  296. ##################################################################
  297. proc ::gui::guiPopupBusy { wdgt txt } {
  298. set ::gui::busyLbl [toplevel .busyLbl]
  299. set lbl [Label $::gui::busyLbl.busyLbl -width 100 -height 50 \
  300. -fg red -bg black \
  301. -justify center -text $txt]
  302. pack $lbl -side top -expand false
  303. grab $::gui::busyLbl
  304. update
  305. }
  306. #-----------------------------------------------------------------
  307. #
  308. # ::gui::guiPopupFile
  309. #
  310. # Pop up a non-modal dialog showing the contents of a file.
  311. # Make it non-modal, so that users can have more than one up
  312. # at the same time. This implies that it chooses a unique name
  313. # and destroys itself when done.
  314. #
  315. # Handy for displaying results from simulation runs.
  316. #
  317. #-----------------------------------------------------------------
  318. proc ::gui::guiPopupFile { filename } {
  319. # Check that filename exists
  320. if { ! [file exists $filename] } {
  321. ::gui::guiPopupWarning "$filename doesn't exist!"
  322. return
  323. }
  324. # Create dialog with unique name
  325. set i 1
  326. while { [winfo exists .result$i] } {
  327. incr i
  328. }
  329. set dlg .result$i
  330. Dialog $dlg -title $filename -modal none -transient 0 \
  331. -homogeneous 1 -side bottom -anchor e -default 0 -cancel 0
  332. $dlg add -text Close -command [list destroy $dlg]
  333. set sw [ScrolledWindow [$dlg getframe].sw]
  334. set txt [text $sw.text]
  335. $sw setwidget $txt
  336. pack $sw -padx 4 -pady 4 -expand true -fill both
  337. # Read data
  338. if { [catch {set fp [open $filename "r"]} result] } {
  339. set data "<empty>"
  340. } else {
  341. set data [read $fp]
  342. close $fp
  343. }
  344. # Display data
  345. $txt delete 1.0 end
  346. $txt insert end $data
  347. $txt see 1.0
  348. $dlg draw
  349. }
  350. ##################################################################
  351. ##################################################################
  352. proc ::gui::guiSetCursorBusy {f1} {
  353. eval $f1 configure -cursor watch
  354. update
  355. }
  356. ##################################################################
  357. ##################################################################
  358. proc ::gui::guiSetCursorNormal {f1} {
  359. eval $f1 configure -cursor left_ptr
  360. update
  361. }
  362. ##################################################################
  363. # Build the material/value list.
  364. ##################################################################
  365. proc ::gui::guiBuildNmeValList { parent valList labelString varble} {
  366. global $valList
  367. set lst ""
  368. foreach { name value } [ eval array get $valList ] {
  369. set val [format "\{%s %s\}" $name $value]
  370. append lst "$val "
  371. }
  372. set lb [label $parent.lb$::gui::ComboCount -text $labelString]
  373. set sb [ComboBox $parent.sb$::gui::ComboCount \
  374. -textvariable $varble -width 10 \
  375. -values $lst ]
  376. incr ::gui::ComboCount
  377. grid $lb $sb -sticky news -padx 4 -pady 4
  378. return $sb
  379. }
  380. #-----------------------------------------------------------------
  381. #
  382. # ::gui::_drainEventQueue
  383. #
  384. # Windows has a rather odd bug with the native file-open
  385. # dialog, which Tk uses for tk_getOpenFile and tk_getSaveFile.
  386. # If you double-click on a filename, the Windows dialog only
  387. # consumes 1.5 clicks (<down><up><down>), then closes the
  388. # dialog. The remaining half click (<up> event) propagates
  389. # down to the window below. Since this application has a
  390. # number of buttons on the main window, it is common to have
  391. # these buttons fire their command event after double-click
  392. # selecting a file.
  393. #
  394. # Several workaround hacks are described in comp.lang.tcl,
  395. # including draining the event queue, revectoring bindings
  396. # for a fraction of a second, and even some C code patches
  397. # to Tk.
  398. #
  399. # This code uses [grab] to direct all events to an
  400. # inoccuous widget (a label), drains the event
  401. # queue by calling [update], then releases the grab.
  402. # The draining widget must be mapped, so we search
  403. # [winfo children .].
  404. #
  405. #-----------------------------------------------------------------
  406. proc ::gui::drainEventQueue {} {
  407. # Search for a mapped Label widget in children of "."
  408. set wlist [winfo children .]
  409. while { [llength $wlist] > 0 } {
  410. set w [lindex $wlist 0]
  411. set wlist [lrange $wlist 1 end]
  412. # If we've got a mapped Label Widget, drain the queue
  413. if { [winfo ismapped $w] } {
  414. if { [winfo class $w] eq "Label" } {
  415. grab $w
  416. update
  417. grab release $w
  418. return
  419. }
  420. # Not a label, but ismapped, so add chldren to search
  421. set wlist [concat $wlist [winfo children $w]]
  422. }
  423. }
  424. # if we fall through, then there wan't a suitable widget.
  425. # Tough luck.
  426. }