Statistics
| Branch: | Revision:

root / src / tkenv / statinsp.tcl @ 79bb12dc

History | View | Annotate | Download (9.07 KB)

1 01873262 Georg Kunz
#=================================================================
2
#  STATINSP.TCL - part of
3
#
4
#                     OMNeT++/OMNEST
5
#            Discrete System Simulation in C++
6
#
7
#=================================================================
8
9
#----------------------------------------------------------------#
10
#  Copyright (C) 1992-2008 Andras Varga
11
#
12
#  This file is distributed WITHOUT ANY WARRANTY. See the file
13
#  `license' for details on this and other legal matters.
14
#----------------------------------------------------------------#
15
16
#
17
# Histogram, output vector and statistic inspectors
18
#
19
20
proc histogramwindow_mouse {w x y on} {
21
    #set obj [$w find closest $x $y]
22
    set tags [$w gettags current]
23
    if [regexp {.*cell([0-9]+).*} $tags match cell] {
24
       set win [winfo toplevel $w]
25
       if {$on == 1} {
26
           $w itemconfig current -fill gray -outline gray
27
           $win.bot.info config -text [opp_inspectorcommand $win cell $cell]
28
       } else {
29
           $w itemconfig current -fill black -outline black
30
           $win.bot.info config -text [opp_inspectorcommand $win cell]
31
       }
32
    }
33
}
34
35
proc create_histogramwindow {name geom} {
36
    global icons help_tips
37
38
    # create histogram inspector
39
    set w $name
40
    create_inspector_toplevel $w $geom
41
42
    # make the window respond to resize events
43
    bind $w <Configure> "opp_updateinspector $w"
44
45
    pack_iconbutton $w.toolbar.obj -image $icons(asobject) -command "inspect_this $w {As Object}"
46
    set help_tips($w.toolbar.obj) {Inspect as object}
47
48
    frame $w.main
49
    frame $w.bot
50
    pack $w.bot  -expand 0 -fill x -side bottom
51
    pack $w.main -expand 1 -fill both -side top
52
53
    canvas $w.main.canvas -borderwidth 2 -relief raised -background lightblue
54
    pack $w.main.canvas -anchor center -expand 1 -fill both -side top
55
56
    label $w.bot.info -relief groove -width 50
57
    pack $w.bot.info -anchor center -expand 1 -fill x -side left
58
59
    $w.main.canvas bind all <Any-Enter> {histogramwindow_mouse %W %x %y 1}
60
    $w.main.canvas bind all <Any-Leave> {histogramwindow_mouse %W %x %y 0}
61
62
    # we need to let the window display, otherwise the canvas size
63
    # (needed by the first draw) returned by [winfo width/height ...]
64
    # will be 1
65
    update idletasks
66
}
67
68
proc outvectorwindow_opt_update {w win} {
69
    global tmp
70
    opp_inspectorcommand $win config \
71
                     $tmp(autoscale) \
72
                     [$w.time.e get] \
73
                     [$w.ymin.e get] \
74
                     [$w.ymax.e get] \
75
                     [$w.combo.e cget -value]
76
    opp_updateinspector $win
77
}
78
79
proc outvectorwindow_options {win} {
80
    set w .ov-options
81
    catch {destroy $w}
82
    global tmp
83
84
    ###################
85
    # CREATING WIDGETS
86
    ###################
87
    toplevel $w -class Toplevel
88
    wm iconname $w Dialog
89
    wm focusmodel $w passive
90
    wm overrideredirect $w 0
91
    wm resizable $w 1 1
92
    wm deiconify $w
93
    wm title $w {Options...}
94
    wm protocol $w WM_DELETE_WINDOW { }
95
    #bind $w <Visibility> "raise $w"  ;# Keep modal window on top
96
97
    label $w.msg -justify left -text {cOutVector window options:}
98
    checkbutton $w.auto -text {Autoscale} -variable tmp(autoscale)
99
    label-entry $w.time {Time factor (sec/pixel):}
100
    label-entry $w.ymin {Ymin:}
101
    label-entry $w.ymax {Ymax:}
102
    label-combo $w.combo {Draw mode:} {dots pins bars sample-hold lines}
103
    frame $w.buttons
104
    button $w.buttons.okbutton -width 10 -text {OK}
105
    button $w.buttons.applybutton -width 10 -text {Apply}
106
    button $w.buttons.cancelbutton -width 10 -text {Cancel}
107
108
    pack $w.msg  -anchor w -expand 0 -fill none -padx 3m -pady 3m -side top
109
    pack $w.auto -anchor w -expand 0 -fill none -padx 3m -pady 3m -side top
110
    pack $w.time -anchor center -expand 1 -fill x -padx 3m -pady 1m -side top
111
    pack $w.ymin -anchor center -expand 1 -fill x -padx 3m -pady 1m -side top
112
    pack $w.ymax -anchor center -expand 1 -fill x -padx 3m -pady 1m -side top
113
    pack $w.combo -anchor center -expand 1 -fill x -padx 3m -pady 1m -side top
114
    pack $w.buttons  -anchor center -expand 0 -fill x -side bottom -padx 5 -pady 5
115
    pack $w.buttons.okbutton  -anchor n -expand 0 -side right
116
    pack $w.buttons.applybutton -anchor n -expand 0 -side right
117
    pack $w.buttons.cancelbutton  -anchor n -expand 0 -side right
118
119
    center $w
120
121
    # 2. Create bindings.
122
    global opp
123
124
    $w.buttons.okbutton configure -command "outvectorwindow_opt_update $w $win; set opp(button) 1"
125
    $w.buttons.applybutton configure -command "outvectorwindow_opt_update $w $win"
126
    $w.buttons.cancelbutton configure -command "set opp(button) 1"
127
128
    bind $w <Return> "outvectorwindow_opt_update $w $win; set opp(button) 1"
129
    bind $w <Escape> "set opp(button) 0"
130
131
    # 3. set initial values
132
    set settings [opp_inspectorcommand $win config]
133
    set tmp(autoscale) [lindex $settings 0]
134
    $w.time.e insert 0 [lindex $settings 1]
135
    $w.ymin.e insert 0 [lindex $settings 2]
136
    $w.ymax.e insert 0 [lindex $settings 3]
137
    $w.combo.e configure -value [lindex $settings 4]
138
139
    # 4. Set a grab and claim the focus too.
140
    set oldFocus [focus]
141
    set oldGrab [grab current $w]
142
    if {$oldGrab != ""} {
143
        set grabStatus [grab status $oldGrab]
144
    }
145
    grab $w
146
    focus $w.time.e
147
148
    # 5. Wait for the user to respond, then restore the focus and
149
    # return the index of the selected button.  Restore the focus
150
    # before deleting the window, since otherwise the window manager
151
    # may take the focus away so we can't redirect it.  Finally,
152
    # restore any grab that was in effect.
153
154
    tkwait variable opp(button)
155
156
    catch {focus $oldFocus}
157
    destroy $w
158
    if {$oldGrab != ""} {
159
        if {$grabStatus == "global"} {
160
            grab -global $oldGrab
161
        } else {
162
            grab $oldGrab
163
        }
164
    }
165
}
166
167
proc outvectorwindow_mouse {w x y on} {
168
    global opp
169
    # mouse enters/leaves a data point's drawing in a outvector window
170
    # the index of the point is in the drawing's tag: "value12"
171
    set tags [$w gettags current]
172
    if [regexp {.*value([0-9]+).*} $tags match value] {
173
       set win [winfo toplevel $w]
174
       set no_outline [catch {$w itemconfig current -outline}]
175
       if {$on == 1} {
176
           # mouse enters a bar/dot/line/etc: paint it black
177
           if {$no_outline} {
178
              set opp(oldfill)    [lindex [$w itemconfig current -fill] 4]
179
              $w itemconfig current -fill black
180
           } else {
181
              set opp(oldfill)    [lindex [$w itemconfig current -fill] 4]
182
              set opp(oldoutline) [lindex [$w itemconfig current -outline] 4]
183
              $w itemconfig current -fill black -outline black
184
           }
185
           $win.bot.info config -text [opp_inspectorcommand $win value $value]
186
       } else {
187
           # mouse leaves the bars/dots/lines: restore original color
188
           if {$no_outline} {
189
              $w itemconfig current -fill $opp(oldfill)
190
           } else {
191
              $w itemconfig current -fill $opp(oldfill) -outline $opp(oldoutline)
192
           }
193
           $win.bot.info config -text [opp_inspectorcommand $win value]
194
       }
195
    }
196
}
197
198
proc create_outvectorwindow {name geom} {
199
    global icons
200
201
    # create histogram inspector
202
    set w $name
203
    create_inspector_toplevel $w $geom
204
205
    # make the window respond to resize events
206
    bind $w <Configure> "opp_updateinspector $w"
207
208
    pack_iconbutton $w.toolbar.obj -image $icons(asobject) -command "inspect_this $w {As Object}"
209
    set help_tips($w.toolbar.obj) {Inspect as object}
210
211
    frame $w.main
212
    frame $w.bot
213
    pack $w.bot -anchor center -expand 0 -fill x -side bottom
214
    pack $w.main -anchor center -expand 1 -fill both -side top
215
216
    canvas $w.main.canvas -borderwidth 2 -relief raised -background wheat1
217
    pack $w.main.canvas -anchor center -expand 1 -fill both -side top
218
219
    label $w.bot.info -width 50 -relief groove
220
    button $w.bot.view -text {Options...} -command "outvectorwindow_options $w"
221
    pack $w.bot.view -anchor center -expand 0 -fill none -side right
222
    pack $w.bot.info -anchor center -expand 1 -fill x -side left
223
224
    $w.main.canvas bind all <Any-Enter> {outvectorwindow_mouse %W %x %y 1}
225
    $w.main.canvas bind all <Any-Leave> {outvectorwindow_mouse %W %x %y 0}
226
227
    # we need to let the window display, otherwise the canvas size
228
    # (needed by the first draw) returned by [winfo width/height ...]
229
    # will be 1
230
    update idletasks
231
}
232
233
#proc create_statisticinspector {name geom} {
234
#    global icons help_tips
235
#
236
#    set w $name
237
#    create_inspector_toplevel $w $geom
238
#
239
#    set nb [inspector_createnotebook $w]
240
#
241
#    inspector_createfields2page $w
242
#
243
#    notebook_addpage $nb info  {Info}
244
#
245
#    pack_iconbutton $w.toolbar.graph -image $icons(asgraphics) -command "inspect_this $w {As Graphics}"
246
#    set help_tips($w.toolbar.graph) {Inspect as histogram graphics}
247
#
248
#    label-sunkenlabel $nb.info.count Count:
249
#    label-sunkenlabel $nb.info.mean Mean:
250
#    label-sunkenlabel $nb.info.stddev Std.dev:
251
#    label-sunkenlabel $nb.info.min Min:
252
#    label-sunkenlabel $nb.info.max Max:
253
#
254
#    pack $nb.info.count -fill x -side top
255
#    pack $nb.info.mean -fill x -side top
256
#    pack $nb.info.stddev -fill x -side top
257
#    pack $nb.info.min -fill x -side top
258
#    pack $nb.info.max -fill x -side top
259
#}
260