tnt.tcl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #! /bin/sh
  2. # restart using wish \
  3. exec wish "$0" "$@"
  4. #----------------------------------------------------------------
  5. #
  6. # tnt.tcl
  7. #
  8. # Main entry point for the TNT interface program
  9. # for Mayo SPPDG MMTL and other transmission line
  10. # simulators.
  11. #
  12. # This module creates the BWidget mainframe framework
  13. # for the main window, and defines procedures for
  14. # accessing numerous other integrated simulation programs
  15. # and utilities.
  16. #
  17. # The actual GUI is constructed by [createElements]
  18. #
  19. #
  20. # Copyright 2002-2004 Mayo Foundation. All Rights Reserved.
  21. # $Id: tnt.tcl,v 1.27 2004/09/10 20:04:53 techenti Exp $
  22. #
  23. #----------------------------------------------------------------
  24. set TNT_VERSION 1.2.2
  25. #----------------------------------------------------------------
  26. # From whence is this script run?
  27. # For there shall we find the rest.
  28. #----------------------------------------------------------------
  29. set ::scriptDir [file dirname [info script]]
  30. #----------------------------------------------------------------
  31. # TNT's application-specific libraries are usually found
  32. # in the ../lib directory, relative to this script's location.
  33. #----------------------------------------------------------------
  34. set ::auto_path [linsert $auto_path 0 [file join $scriptDir .. lib]]
  35. #----------------------------------------------------------------
  36. # TNT executes binaries out of the same bin directory
  37. # as this script. Add this directory to the head of our
  38. # path, so [auto_execok] can easily find executables.
  39. #----------------------------------------------------------------
  40. if { $::tcl_platform(platform) eq "windows" } {
  41. set sep ";"
  42. } else {
  43. set sep ":"
  44. }
  45. set ::env(PATH) $::scriptDir$sep$::env(PATH)
  46. #----------------------------------------------------------------
  47. # TNT's documentation is usually found in ../doc,
  48. # relative to this script's location.
  49. #----------------------------------------------------------------
  50. set ::docDirPath [file join $scriptDir .. doc]
  51. #----------------------------------------------------------------
  52. # But for 'developer mode,' things are a little messy.
  53. # Application libraries are subdirectories under $scriptDir.
  54. # Executables (e.g., bem) are found in their respecitve
  55. # subdirectories, and docs are found under $scriptDir/doc.
  56. #----------------------------------------------------------------
  57. if { [file exists [file join $scriptDir bem]] } {
  58. lappend ::auto_path $scriptDir [file join $scriptDir bem]
  59. set ::env(PATH) [file join $::scriptDir bem]$sep$::env(PATH)
  60. }
  61. if { [file exists [file join $scriptDir calcRL]] } {
  62. lappend ::auto_path $scriptDir [file join $scriptDir calcRL]
  63. set ::env(PATH) [file join $::scriptDir calcRL]$sep$::env(PATH)
  64. }
  65. if { [file exists [file join $scriptDir calcCAP]] } {
  66. lappend ::auto_path $scriptDir [file join $scriptDir calcCAP]
  67. set ::env(PATH) [file join $::scriptDir calcCAP]$sep$::env(PATH)
  68. }
  69. if { [file exists [file join $scriptDir doc]] } {
  70. set ::docDirPath [file join $scriptDir doc]
  71. }
  72. #----------------------------------------------------------------
  73. # Splash Screen
  74. #
  75. # Before anything else, find the GUI components, and throw
  76. # up a nice splash screen while we're doing the rest of the
  77. # initialization.
  78. #
  79. # The splash screen is part of the GUI package, but we don't
  80. # want to do a package require. That's too slow. So we
  81. # create the "gui" namespace, locate the source directory,
  82. # and directly source the splash screen code.
  83. #----------------------------------------------------------------
  84. package require Tk
  85. wm withdraw .
  86. toplevel .splash
  87. namespace eval gui {
  88. set LIBRARY [file join $::scriptDir .. lib]
  89. set flist [glob -nocomplain [file join $LIBRARY gui* splash.tcl]]
  90. if { [llength $flist] == 0 } {
  91. set flist [glob -nocomplain [file join $::scriptDir gui* splash.tcl]]
  92. }
  93. set splash [lindex $flist 0]
  94. set LIBRARY [file normalize [file dirname $splash]]
  95. }
  96. source $::gui::splash
  97. ::gui::splash .splash
  98. #----------------------------------------------------------------
  99. # Load Required Packages
  100. #----------------------------------------------------------------
  101. package require Itcl
  102. package require BWidget
  103. #----------------------------------------------------------------
  104. # Load application-specific packages
  105. #----------------------------------------------------------------
  106. package require gui
  107. package require csdl
  108. package require units
  109. package require bem
  110. # Optional packages
  111. set femPkg [catch { package require fem }]
  112. set calcRLpkg [catch { package require calcRL}]
  113. set calcCAPpkg [catch { package require calcCAP}]
  114. #----------------------------------------------------------------
  115. # Create the main window.
  116. #----------------------------------------------------------------
  117. proc createMain { mmtlInitialize } {
  118. #----------------------------------------------------------------
  119. # BWidget Menu description
  120. # Each menubar entry is
  121. # menuname tags menuid tearoff menuentries
  122. # where menuentries are one of
  123. # separator
  124. # command menuname ?tags? ?desc? ?accel? ?option value?...
  125. # checkbutton menuname ?tags? ?desc? ?accel? ?option value?...
  126. # radiobutton menuname ?tags? ?desc? ?accel? ?option value?...
  127. # radiobutton menuname ?tags? ?desc? ?accel? ?option value?...
  128. # cascade menuname tags menuID tearoff menuentries
  129. #----------------------------------------------------------------
  130. set descmenu {
  131. "&File" all file 0 {
  132. {command "Ne&w" {} "Create a new file" {Ctrl n} \
  133. -command ::gui::guiNew}
  134. {command "&Open..." {} "Open existing file" {Ctrl o} \
  135. -command ::gui::guiOpenExisting}
  136. {command "&Save" {} "Save cross section" \
  137. {Ctrl s} -command ::gui::guiSave}
  138. {command "Sa&ve As..." {} \
  139. "Save cross section to new file" {Ctrl v} \
  140. -command ::gui::guiSaveAs}
  141. {command "&Print..." {} "Print the cross section" {Ctrl p} \
  142. -command ::gui::_canvas_print}
  143. {command "E&xit" {} "Exit" {Ctrl x} -command _exit}
  144. }
  145. "View" all view 0 {
  146. {checkbutton "Console" {} "Show/hide command console" {} \
  147. -variable ::gui::_showConsole}
  148. {checkbutton "Annotation" {} \
  149. "Show/hide dimensions and descriptions" {} \
  150. -variable ::gui::_annotateFlag \
  151. -command gui::_canvas_toggleAnnotation}
  152. {command "Redraw" {} "Redraw cross section" \
  153. {} -command gui::_canvas_redraw}
  154. }
  155. "&Setup" all setup 0 {
  156. {command "Re-read conductivity list" {} \
  157. "Read in a new conductivity list" {} \
  158. -command ::gui::guiReadNewConductivityList}
  159. {command "Re-read lossTangent list" {} \
  160. "Read in a new lossTangent list" {} \
  161. -command ::gui::guiReadNewLossTangentList}
  162. {command "Re-read permittivity list" {} \
  163. "Read in a new permittivity list" {} \
  164. -command ::gui::guiReadNewPermittivityList}
  165. }
  166. "&BEM" all bem 0 {
  167. {command "Run BEM MMTL S&imulation" {} \
  168. "Save cross section file and run MMTL" \
  169. {Ctrl i} -command ::gui::saveAndRunBem}
  170. {command "View BEM MMTL Result" {} \
  171. "Vie&w BEM MMTL results" {Ctrl w} \
  172. -command {::gui::guiPopupResultsFile "result"}}
  173. {command "Generate &HSPICE W" {} \
  174. "Generate HSPICE W-element from MMTL results" \
  175. {Ctrl h} -command ::gui::writeHspiceW}
  176. }
  177. "&Sweep" all sweep 0 {
  178. {command "S&weep Simulation" {} \
  179. "Run current node in sweep mode" {} \
  180. -command ::gui::guiRunSweepMMTL }
  181. {command "View \"swept_result\" file" {} \
  182. "Display swept_result file" {} \
  183. -command {::gui::guiPopupResultsFile "swept_result"} }
  184. {command "Write csv file" {} \
  185. "Write swept results into csv file" {} \
  186. -command "::gui::writeSweptCsvFile swept_result" }
  187. }
  188. "&Iterate" all iterate 0 {
  189. {command "I&terate Conductor Width" {} \
  190. "Sweep conductor width or diameter to achieve impendance" {} \
  191. -command ::gui::guiRunIterateMMTL }
  192. {command "View \"iterate_result\" file" {} \
  193. "Display iterate_result file" {} \
  194. -command {::gui::guiPopupResultsFile "iterate_result"}}
  195. {command "Write csv file" {} \
  196. "Write iterate results into csv file" {} \
  197. -command "::gui::writeSweptCsvFile iterate_result" }
  198. }
  199. }
  200. #----------------------------------------------------------------
  201. # Optional experimental wavelet simulators
  202. #----------------------------------------------------------------
  203. if { ($::calcRLpkg==0) || ($::calcCAPpkg==0) } {
  204. append descmenu "\"Wavelet Simulators\" all calcrl 0 \{"
  205. }
  206. if { $::calcRLpkg == 0 } {
  207. append descmenu {
  208. {command "Run RL Calculator" \
  209. {} "Run full-wave wavelet-based RL calculator" {} \
  210. -command ::gui::runCalcRL}
  211. {command "View RL result file" {} \
  212. "Display RL Calculator result file" {} \
  213. -command {::gui::guiPopupResultsFile ri.out} }
  214. }
  215. }
  216. if { $::calcCAPpkg == 0 } {
  217. append descmenu {
  218. {command "Run Capacitance Calculator" \
  219. {} "Run full-wave wavelet-based Capacitance calculator" {} \
  220. -command ::gui::runCalcCap}
  221. {command "View Capacitance result file" {} \
  222. "Display Capacitance Calculator result file" {} \
  223. -command {::gui::guiPopupResultsFile cap.out} }
  224. }
  225. }
  226. if { ($::calcRLpkg==0) || ($::calcCAPpkg==0) } {
  227. append descmenu "\}"
  228. }
  229. append descmenu {
  230. "&Help" all help 0 {
  231. {command "User Guide" {} "" {} \
  232. -command {::gui::tnt_help userguide}}
  233. {command "About TNT" {} "" {} \
  234. -command {wm deiconify .splash}}
  235. }
  236. }
  237. set ::gui::mainframe [MainFrame .mainframe \
  238. -menu $descmenu]
  239. set ::gui::f1 [$::gui::mainframe getframe]
  240. set ::gui::f2 [::gui::guiCreateElements $::gui::f1 $mmtlInitialize]
  241. pack $::gui::f2 -expand true -fill both
  242. pack $::gui::f1 -expand true -fill both
  243. pack $::gui::mainframe -expand true -fill both
  244. wm protocol . WM_DELETE_WINDOW {_exit}
  245. }
  246. #----------------------------------------------------------------
  247. #
  248. # _exit
  249. #
  250. # Application exit point.
  251. # This would be a good place to catch model changes and
  252. # prompt for save before exiting.
  253. #
  254. #----------------------------------------------------------------
  255. proc _exit {} {
  256. exit
  257. }
  258. #----------------------------------------------------------------
  259. #
  260. # main
  261. #
  262. # Controls splash screen, creates main window, and opens
  263. # a file, if specified on the command line.
  264. #
  265. #----------------------------------------------------------------
  266. proc main { argv } {
  267. set mmtlInitialize 1
  268. wm withdraw .
  269. # Create main window
  270. createMain $mmtlInitialize
  271. BWidget::place . 0 0 center
  272. # Swap out splash screen with main window.
  273. wm withdraw .splash
  274. wm title . "TNT Cross Section Generator"
  275. wm deiconify .
  276. update
  277. # If there was a filename supplied on the command line,
  278. # then open that file
  279. if { [llength $argv] > 0 } {
  280. set filename [lindex $argv 0]
  281. ::gui::guiOpenExisting $filename
  282. }
  283. }
  284. main $argv