MeasText.itcl 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #---------------------------------------------------------------------
  2. #
  3. #
  4. # MeasText.itcl
  5. #
  6. # Class for lab applications using SPPDG *measure.txt files.
  7. # This class opens measure.txt files, parses headers and tests,
  8. # and holds onto notes, vendor, serial number.
  9. #
  10. # Eric Amundsen
  11. # May 28, 2004
  12. #
  13. # Copyright 2004 Mayo Foundation. All rights reserved.
  14. #
  15. #
  16. # $Id: MeasText.itcl,v 1.4 2004/06/04 16:18:08 amundsen Exp $ --------------------------------------------------------------
  17. package provide MeasText 1.0
  18. package require Itcl
  19. # +-Class Name-------------------------------------------------------+
  20. # |
  21. # | itcl::class MeasText
  22. # |
  23. # +-Attributes-------------------------------------------------------+
  24. # |
  25. # | Protected:
  26. # | tests
  27. # | currentTest
  28. # | measFilename
  29. # | header
  30. # | measFile
  31. # | vendor
  32. # | serialNumber
  33. # | displayedNotes
  34. # | nonDisplayedNotes
  35. # |
  36. # +-Methods----------------------------------------------------------+
  37. # |
  38. # | Public:
  39. # | constructor
  40. # | destructor
  41. # | parseMeasFilename
  42. # |
  43. # | getTestNumbers
  44. # | setHeader
  45. # | getHeader
  46. # | setMeasFilename
  47. # | getMeasFilename
  48. # | setSerialNumber
  49. # | getSerialNumber
  50. # | setVendor
  51. # | getVendor
  52. # | setCurrentTest
  53. # | getCurrentTest
  54. # | setDisplayedNotes
  55. # | getDisplayedNotes
  56. # | setNonDisplayedNotes
  57. # | getNonDisplayedNotes
  58. # |
  59. # | Private:
  60. # | parseHeader
  61. # | parseTests
  62. # |
  63. # +------------------------------------------------------------------+
  64. itcl::class MeasText {
  65. public {
  66. method constructor {args} { array set tests [list] }
  67. method parseMeasFilename {}
  68. method setHeader {value} { set header $value }
  69. method getHeader {} { return $header }
  70. method setMeasFilename {value} { set measFilename $value }
  71. method getMeasFilename {} { return $measFilename }
  72. method setSerialNumber {value} { set serialNumber $value }
  73. method getSerialNumber {} { return $serialNumber }
  74. method setVendor {value} { set vendor $value }
  75. method getVendor {} { return $vendor }
  76. method setDisplayedNotes {value} { set displayedNotes $value }
  77. method getDisplayedNotes {} { return $displayedNotes }
  78. method setNonDisplayedNotes {value} { set nonDisplayedNotes $value }
  79. method getNonDisplayedNotes {} { return $nonDisplayedNotes }
  80. method setCurrentTest {value} { set currentTest $value }
  81. method getFooter {} {return [lindex [getCurrentTest] 1]}
  82. method getCurrentTest {} {
  83. set returnValue [list $currentTest]
  84. lappend returnValue [lindex [array get tests $currentTest] 1]
  85. return $returnValue
  86. }
  87. method getTestNumbers {} {
  88. # return a list of the tests indices
  89. return [array names tests]
  90. }
  91. }
  92. protected {
  93. # an array indexed by test numbers, each element containing a list
  94. # of strings corresponding to the test text
  95. variable tests
  96. # an index to get the current selected test out of the tests array
  97. variable currentTest ""
  98. # the fully qualified filename of the current measure.txt file
  99. variable measFilename ""
  100. # a list of header lines - parsed by parseHeader
  101. variable header [list]
  102. # a list of lines from the measure.txt file
  103. variable measFile [list]
  104. variable vendor ""
  105. variable serialNumber ""
  106. # these should be handled as lists of strings, although this class
  107. # doesn't do anything to enforce that, but the derived GUI class
  108. # transacts with these variables in that fashion, so it's probably
  109. # a good idea to stick with that
  110. variable displayedNotes [list]
  111. variable nonDisplayedNotes [list]
  112. }
  113. private {
  114. method parseHeader {}
  115. method parseTests {}
  116. }
  117. }
  118. # +-Public Method----------------------------------------------------+
  119. # |
  120. # | MeasText::parseMeasFilename
  121. # |
  122. # +-Description------------------------------------------------------+
  123. # |
  124. # | Make sure the filename exists, open it, read it,
  125. # | split it into list, parse the header and the tests
  126. # |
  127. # +-Arguments--------------------------------------------------------+
  128. # |
  129. # +-Return value-----------------------------------------------------+
  130. # |
  131. # +------------------------------------------------------------------+
  132. itcl::body MeasText::parseMeasFilename {} {
  133. if {![catch {open $measFilename r} {handle}]} {
  134. # read the entire measure.txt file
  135. set measFile [split [read $handle] "\n"]
  136. close $handle
  137. # get the header out of the measFile variable
  138. parseHeader
  139. # get the tests out too
  140. parseTests
  141. }
  142. }
  143. # +-Private Method---------------------------------------------------+
  144. # |
  145. # | MeasText::parseHeader
  146. # |
  147. # +-Description------------------------------------------------------+
  148. # |
  149. # | Finds the lines following the "Header:" line
  150. # |
  151. # +-Arguments--------------------------------------------------------+
  152. # |
  153. # +-Return value-----------------------------------------------------+
  154. # |
  155. # +------------------------------------------------------------------+
  156. itcl::body MeasText::parseHeader {} {
  157. set headerStart [lsearch $measFile "Header:"]
  158. # If found
  159. if {$headerStart >= 0} {
  160. # Find the next empty line
  161. set headerEnd [lsearch -start $headerStart $measFile ""]
  162. # Stick the lines between the "Header:" line and the empty
  163. # line into the header attribute
  164. set header [lrange $measFile \
  165. [expr {$headerStart + 1}] \
  166. [expr {$headerEnd - 1}]]
  167. } else {
  168. # If not found make sure the header attribute is empty
  169. set header [list]
  170. }
  171. }
  172. # +-Private Method---------------------------------------------------+
  173. # |
  174. # | MeasText::parseTests
  175. # |
  176. # +-Description------------------------------------------------------+
  177. # |
  178. # | Find all the "Test*" lines and stick the following lines
  179. # | (up to the next empty line), as a list of strings, into
  180. # | an array indexed by the "Test*" line
  181. # |
  182. # +-Arguments--------------------------------------------------------+
  183. # |
  184. # +-Return value-----------------------------------------------------+
  185. # |
  186. # +------------------------------------------------------------------+
  187. itcl::body MeasText::parseTests {} {
  188. # clear the tests array
  189. array unset tests
  190. # search for all strings starting with Test
  191. foreach testStart [lsearch -all -glob $measFile "Test*"] {
  192. # then find the next empty line
  193. set testEnd [lsearch -start $testStart $measFile ""]
  194. # then stick these lines into the array with the Test*
  195. # string as the index
  196. set tests([lindex $measFile $testStart]) \
  197. [lrange $measFile [expr {$testStart + 1}] [expr {$testEnd - 1}]]
  198. }
  199. }