1 #!/home/people/tkys/Eos/util/I386LINUX/bin/bltwish
6 # ----------------------------------------------------------------------
7 # EXAMPLE: simple driver for stripchart widget
8 # ----------------------------------------------------------------------
10 # mmclennan@lucent.com
11 # Bell Labs Innovations for Lucent Technologies
12 # ======================================================================
13 # Copyright (c) 1996 Lucent Technologies
14 # ======================================================================
16 option add *x.range 20.0
17 option add *x.shiftBy 15.0
18 option add *bufferElements no
19 option add *symbol scross
20 option add *pixels 1.25m
21 option add *PlotPad 25
22 option add *Stripchart.width 400
23 option add *Smooth natural
24 #option add *Stripchart.invertXY yes
25 #option add *x.descending yes
27 # ----------------------------------------------------------------------
28 # USAGE: random ?<max>? ?<min>?
30 # Returns a random number in the range <min> to <max>.
31 # If <min> is not specified, the default is 0; if max is not
32 # specified, the default is 1.
33 # ----------------------------------------------------------------------
35 proc random {{max 1.0} {min 0.0}} {
38 set randomSeed [expr (7141*$randomSeed+54773) % 259200]
39 set num [expr $randomSeed/259200.0*($max-$min)+$min]
44 # ----------------------------------------------------------------------
47 wm title .addSource "Add Source"
49 wm withdraw .addSource
50 wm protocol .addSource WM_DELETE_WINDOW {.addSource.controls.cancel invoke}
53 pack .addSource.info -expand yes -fill both -padx 4 -pady 4
54 label .addSource.info.namel -text "Name:"
55 entry .addSource.info.name
56 label .addSource.info.maxl -text "Maximum:"
57 entry .addSource.info.max
58 label .addSource.info.minl -text "Minimum:"
59 entry .addSource.info.min
60 table .addSource.info \
61 .addSource.info.namel 0,0 -anchor e \
62 .addSource.info.name 0,1 -fill x \
63 .addSource.info.maxl 1,0 -anchor e \
64 .addSource.info.max 1,1 -fill x \
65 .addSource.info.minl 2,0 -anchor e \
66 .addSource.info.min 2,1 -fill x
68 frame .addSource.color
69 pack .addSource.color -padx 8 -pady 4
70 frame .addSource.color.sample -width 30 -height 30 -borderwidth 2 -relief raised
71 pack .addSource.color.sample -side top -fill both
72 scale .addSource.color.r -label "Red" -orient vertical \
73 -from 100 -to 0 -command source_color
74 pack .addSource.color.r -side left -fill y
75 scale .addSource.color.g -label "Green" -orient vertical \
76 -from 100 -to 0 -command source_color
77 pack .addSource.color.g -side left -fill y
78 scale .addSource.color.b -label "Blue" -orient vertical \
79 -from 100 -to 0 -command source_color
80 pack .addSource.color.b -side left -fill y
82 proc source_color {args} {
83 set r [expr round(2.55*[.addSource.color.r get])]
84 set g [expr round(2.55*[.addSource.color.g get])]
85 set b [expr round(2.55*[.addSource.color.b get])]
86 set color [format "#%2.2x%2.2x%2.2x" $r $g $b]
87 .addSource.color.sample configure -background $color
91 frame .addSource.sep -borderwidth 1 -height 2 -relief sunken
92 pack .addSource.sep -fill x -pady 4
94 frame .addSource.controls
95 pack .addSource.controls -fill x -padx 4 -pady 4
96 button .addSource.controls.ok -text "OK" -command {
97 wm withdraw .addSource
98 set name [.addSource.info.name get]
99 set color [.addSource.color.sample cget -background]
100 set max [.addSource.info.max get]
101 set min [.addSource.info.min get]
102 if {[catch {source_create $name $color $min $max} err] != 0} {
106 pack .addSource.controls.ok -side left -expand yes -padx 4
107 button .addSource.controls.cancel -text "Cancel" -command {
108 wm withdraw .addSource
110 pack .addSource.controls.cancel -side left -expand yes -padx 4
112 proc source_create {name color min max} {
115 if {[info exists sources($name-controls)]} {
116 error "source \"$name\" already exists"
119 error "bad range: $min - $max"
123 set win ".sources.nb.s[incr unique]"
124 while {[winfo exists $win]} {
125 set win ".sources.nb.s[incr unique]"
128 set xvname "xvector$unique"
129 set yvname "yvector$unique"
130 set wvname "wvector$unique"
131 global $xvname $yvname $wvname
132 # catch { $xvname delete }
133 # catch { $yvname delete }
134 # catch { $wvname delete }
135 vector $xvname $yvname $wvname
137 if {$xvname == "xvector1"} {
140 xvector1 variable thisVec
141 $xvname append $thisVec(end)
143 $yvname append [random $max $min]
146 catch {.sc element delete $name}
147 .sc element create $name -xdata $xvname -ydata $yvname -color $color
148 if { $name != "default" } {
149 .sc axis create $name -limitcolor $color -limits "%4.4g"
150 .sc element configure $name -mapy $name
152 set cwin .sources.choices.rb$unique
153 radiobutton $cwin -text $name \
154 -variable choices -value $win -command "
155 foreach w \[pack slaves .sources.nb\] {
164 label $win.limsl -text "Limits:"
166 bind $win.lims <KeyPress-Return> "
167 .sc yaxis configure -limits {%%g}
169 label $win.smoothl -text "Smooth:"
171 radiobutton $win.smooth.linear -text "Linear" \
172 -variable smooth -value linear -command "
173 .sc element configure $name -smooth linear
175 pack $win.smooth.linear -side left
176 radiobutton $win.smooth.step -text "Step" \
177 -variable smooth -value step -command "
178 .sc element configure $name -smooth step
180 pack $win.smooth.step -side left
181 radiobutton $win.smooth.natural -text "Natural" \
182 -variable smooth -value natural -command "
183 .sc element configure $name -smooth natural
185 pack $win.smooth.natural -side left
186 label $win.ratel -text "Sampling Rate:"
187 scale $win.rate -orient horizontal -from 10 -to 1000
190 $win.smoothl 0,0 -anchor e \
191 $win.smooth 0,1 -fill x -padx 4 \
192 $win.limsl 1,0 -anchor e \
193 $win.lims 1,1 -fill x -padx 4 \
194 $win.ratel 2,0 -anchor e \
195 $win.rate 2,1 -fill x -padx 2
198 button $win.del -text "Delete" -command [list source_delete $name]
199 pack $win.del -anchor w
200 table $win $win.del 3,1 -anchor e -padx 4 -pady 4
204 catch {$win.smooth.[.sc element cget $name -smooth] invoke} mesg
206 set sources($name-choice) $cwin
207 set sources($name-controls) $win
208 set sources($name-stream) [after 100 [list source_event $name 100]]
209 set sources($name-x) $xvname
210 set sources($name-y) $yvname
211 set sources($name-w) $wvname
212 set sources($name-max) $max
213 set sources($name-min) $min
214 set sources($name-steady) [random $max $min]
219 proc source_delete {name} {
222 after cancel $sources($name-stream)
223 destroy $sources($name-choice)
224 destroy $sources($name-controls)
225 unset sources($name-controls)
227 set first [lindex [pack slaves .sources.choices] 0]
231 proc source_event {name delay} {
234 set xv $sources($name-x)
235 set yv $sources($name-y)
236 set wv $sources($name-w)
240 set x(++end) [expr $x(end) + 0.001 * $delay]
243 if {[random] > 0.97} {
244 set y(++end) [random $sources($name-max) $sources($name-min)]
246 set y(++end) [expr $y(end)+0.1*($sources($name-steady)-$y(end))]
252 } elseif {$val > 0.8} {
259 set win $sources($name-controls)
260 set delay [$win.rate get]
261 set sources($name-stream) [after $delay [list source_event $name $delay]]
264 # ----------------------------------------------------------------------
265 frame .mbar -borderwidth 2 -relief raised
268 menubutton .mbar.main -text "Main" -menu .mbar.main.m
269 pack .mbar.main -side left -padx 4
271 .mbar.main.m add command -label "Add Source..." -command {
272 set x [expr [winfo rootx .]+50]
273 set y [expr [winfo rooty .]+50]
274 wm geometry .addSource +$x+$y
275 wm deiconify .addSource
277 .mbar.main.m add separator
278 .mbar.main.m add command -label "Quit" -command exit
280 menubutton .mbar.prefs -text "Preferences" -menu .mbar.prefs.m
281 pack .mbar.prefs -side left -padx 4
284 .mbar.prefs.m add cascade -label "Warning Symbol" -menu .mbar.prefs.m.wm
285 menu .mbar.prefs.m.wm
286 .mbar.prefs.m add cascade -label "Error Symbol" -menu .mbar.prefs.m.em
287 menu .mbar.prefs.m.em
289 foreach sym {square circle diamond plus cross triangle} {
290 .mbar.prefs.m.wm add radiobutton -label $sym \
291 -variable warningsym -value $sym \
292 -command {.sc pen configure "warning" -symbol $warningsym}
294 .mbar.prefs.m.em add radiobutton -label $sym \
295 -variable errorsym -value $sym \
296 -command {.sc pen configure "error" -symbol $errorsym}
298 catch {.mbar.prefs.m.wm invoke "circle"}
299 catch {.mbar.prefs.m.em invoke "cross"}
301 # ----------------------------------------------------------------------
302 stripchart .sc -title "Stripchart"
303 pack .sc -expand yes -fill both
305 .sc xaxis configure -title "Time (s)"
306 .sc yaxis configure -title "Samples"
309 pack .sources -fill x -padx 10 -pady 4
310 frame .sources.nb -borderwidth 2 -relief sunken
311 pack .sources.nb -side right -expand yes -fill both -padx 4 -pady 4
312 label .sources.title -text "Sources:"
313 pack .sources.title -side top -anchor w -padx 4
314 frame .sources.choices -borderwidth 2 -relief groove
315 pack .sources.choices -expand yes -fill both -padx 4 -pady 4
317 source_create default red 0 10
318 source_create temp blue3 0 10
319 source_create pressure green3 0 200
320 source_create volume purple3 0 1020
321 source_create power yellow3 0 0.01999
322 source_create work magenta3 0 10
323 source_create huh cyan3 0 10000
324 source_create ok violet 0 8.001