Statistics
| Branch: | Revision:

root / src / tkenv / modinsp1.tcl @ e1750c09

History | View | Annotate | Download (11.5 KB)

1 01873262 Georg Kunz
#=================================================================
2
#  MODINSP1.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
#  non-graphical module inspectors etc.
18
#
19
20
proc moduleinspector_add_run_buttons {w} {
21
    global icons help_tips
22
23
    pack_iconbutton $w.toolbar.minfo   -image $icons(info) -command "modelinfo_dialog $w"
24
    pack_iconbutton $w.toolbar.type    -image $icons(modtype) -command "inspect_componenttype $w"
25
    #pack_iconbutton $w.toolbar.sep15   -separator
26
    pack_iconbutton $w.toolbar.objs    -image $icons(findobj) -command "inspect_filteredobjectlist $w"
27
    pack_iconbutton $w.toolbar.sep11   -separator
28
29
    pack_iconbutton $w.toolbar.mrun    -image $icons(mrun)    -command "runsimulation_local $w normal"
30
    pack_iconbutton $w.toolbar.mfast   -image $icons(mfast)   -command "runsimulation_local $w fast"
31
    #pack_iconbutton $w.toolbar.sep13   -separator
32
33
    pack_iconbutton $w.toolbar.vrun     -image $icons(run)     -command {run_normal}
34
    pack_iconbutton $w.toolbar.vruncfg  -image $icons(down_vs) -command "moduleinspector_setrunmode $w.toolbar.vrun"
35
36
    #pack_iconbutton $w.toolbar.fastrun -image $icons(fast)    -command {run_fast}
37
    #pack_iconbutton $w.toolbar.exprrun -image $icons(express) -command {run_express}
38
    #pack_iconbutton $w.toolbar.sep12   -separator
39
    #pack_iconbutton $w.toolbar.until   -image $icons(until)   -command {run_until}
40
    #pack_iconbutton $w.toolbar.sep14   -separator
41
42
    pack_iconbutton $w.toolbar.stop    -image $icons(stop)    -command {stop_simulation}
43
    pack_iconbutton $w.toolbar.sep16   -separator
44
45
    bind $w <Control-F4> "runsimulation_local $w fast"
46
47
    set help_tips($w.toolbar.type)    {Inspect component type}
48
    set help_tips(.toolbar.minfo)     {Model information}
49
    set help_tips($w.toolbar.objs)    {Find and inspect messages, queues, watched variables, statistics, etc (Ctrl+S)}
50
    set help_tips($w.toolbar.mrun)    {Run until next event in this module}
51
    set help_tips($w.toolbar.mfast)   {Fast run until next event in this module (Ctrl+F4)}
52
    set help_tips($w.toolbar.vrun)    {Run with full animation (F5)}
53
    set help_tips($w.toolbar.stop)    {Stop the simulation (F8)}
54
}
55
56
#
57
# Invoked by the small down arrow next to the "Run" icon on the toolbar, and displays
58
# a menu to select between Run, Fast, Express and Until. $w is the icon button to configure.
59
#
60
proc moduleinspector_setrunmode {w} {
61
    global icons help_tips
62
63
    catch {destroy .popup}
64
    menu .popup -tearoff 0
65
66
    .popup add command -label "Run" \
67
        -command [list config_iconbutton $w $icons(run)  run_normal "Run with full animation (F5)"]
68
    .popup add command -label "Fast Run" \
69
        -command [list config_iconbutton $w $icons(fast) run_fast "Run faster: no animation and rare inspector updates (F6)"]
70
    .popup add command -label "Express Run" \
71
        -command [list config_iconbutton $w $icons(express) run_express "Run at full speed: no text output, animation or inspector updates (F7)"]
72
    .popup add command -label "Until..."  \
73
        -command [list config_iconbutton $w $icons(until) run_until "Run until time or event number"]
74
75
    tk_popup .popup [winfo rootx $w] [expr [winfo rooty $w]+[winfo height $w]]
76
77
}
78
79
#proc create_compoundmodinspector {name geom} {
80
#    global icons help_tips
81
#
82
#    set w $name
83
#    create_inspector_toplevel $w $geom
84
#
85
#    pack_iconbutton $w.toolbar.graph   -image $icons(asgraphics) -command "inspect_this $w {As Graphics}"
86
#    pack_iconbutton $w.toolbar.win     -image $icons(asoutput) -command "inspect_this $w {Module output}"
87
#    pack_iconbutton $w.toolbar.sep1    -separator
88
#
89
#    moduleinspector_add_run_buttons $w
90
#
91
#    rpack_iconbutton $w.toolbar.apply  -image $icons(apply) -command "opp_writebackinspector $w; opp_updateinspectors"
92
#    rpack_iconbutton $w.toolbar.revert -image $icons(revert) -command "opp_updateinspectors"
93
#
94
#    set help_tips($w.toolbar.owner)   {Inspect parent module}
95
#    set help_tips($w.toolbar.graph)   {Inspect as network graphics}
96
#    set help_tips($w.toolbar.win)     {See module output}
97
#    set help_tips($w.toolbar.apply)   {Apply changes (Enter)}
98
#    set help_tips($w.toolbar.revert)  {Revert}
99
#
100
#    set nb [inspector_createnotebook $w]
101
#
102
#    notebook_addpage $nb info    {Info}
103
#    notebook_addpage $nb contents {Contents}
104
#
105
#    notebook_showpage $nb contents
106
#
107
#    # page 1: info
108
#    label-entry $nb.info.name {Module name:}
109
#    label-sunkenlabel $nb.info.id {Module ID:}
110
#    label-entry $nb.info.dispstr {Display string:}
111
#    label-entry $nb.info.dispstrpt {Background disp.str:}
112
#    pack $nb.info.name -anchor center -fill x -side top
113
#    pack $nb.info.id -anchor center -fill x -side top
114
#    pack $nb.info.dispstr -anchor center -fill x -side top
115
#    pack $nb.info.dispstrpt -anchor center -fill x -side top
116
#
117
#    # other pages:
118
#    create_inspector_listbox $nb.contents
119
#
120
#    # note: experimental page
121
#    inspector_createfields2page $w
122
#}
123
#
124
#proc create_simplemodinspector {name geom} {
125
#    global icons help_tips
126
#
127
#    set w $name
128
#    create_inspector_toplevel $w $geom
129
#
130
#    pack_iconbutton $w.toolbar.win    -image $icons(asoutput) -command "inspect_this $w {Module output}"
131
#    pack_iconbutton $w.toolbar.sep1   -separator
132
#
133
#    moduleinspector_add_run_buttons $w
134
#
135
#    rpack_iconbutton $w.toolbar.apply  -image $icons(apply) -command "opp_writebackinspector $w; opp_updateinspectors"
136
#    rpack_iconbutton $w.toolbar.revert -image $icons(revert) -command "opp_updateinspectors"
137
#
138
#    set help_tips($w.toolbar.owner)   {Inspect parent module}
139
#    set help_tips($w.toolbar.win)     {See module output}
140
#    set help_tips($w.toolbar.apply)   {Apply changes (Enter)}
141
#    set help_tips($w.toolbar.revert)  {Revert}
142
#
143
#    bind $w <Control-F4> "runsimulation_local $w fast"
144
#
145
#    set nb [inspector_createnotebook $w]
146
#
147
#    notebook_addpage $nb info    {Info}
148
#    notebook_addpage $nb contents {Contents}
149
#
150
#    notebook_showpage $nb contents
151
#
152
#    # page 1: info
153
#    label-entry $nb.info.name {Module name:}
154
#    label-sunkenlabel $nb.info.id {Module ID:}
155
#    #label-sunkenlabel $nb.info.phase {Phase:}
156
#    label-entry $nb.info.dispstr {Display string:}
157
#    label-entry $nb.info.dispstrpt {Background disp.str:}
158
#    label-sunkenlabel $nb.info.state {State:}
159
#    label-sunkenlabel $nb.info.stacksize {Stack size:}
160
#    label-sunkenlabel $nb.info.stackused {Stack used:}
161
#    pack $nb.info.name -anchor center -fill x -side top
162
#    pack $nb.info.id -anchor center -fill x -side top
163
#    pack $nb.info.state -anchor center  -fill x -side top
164
#    pack $nb.info.dispstr -anchor center -fill x -side top
165
#    pack $nb.info.dispstrpt -anchor center -fill x -side top
166
#    #pack $nb.info.phase -anchor center  -fill x -side top
167
#    pack $nb.info.stacksize -anchor center  -fill x -side top
168
#    pack $nb.info.stackused -anchor center  -fill x -side top
169
#
170
#    # other pages:
171
#    create_inspector_listbox $nb.contents
172
#
173
#    # note: experimental page
174
#    inspector_createfields2page $w
175
#}
176
177
proc runsimulation_local {w mode} {
178
    # invoked from toolbar in module inspectors
179
    if [is_running] {
180
        set_gui_for_runmode $mode $w
181
        opp_set_run_mode $mode
182
        opp_set_run_until_module $w
183
    } else {
184
        if {![network_ready]} {return}
185
        set_gui_for_runmode $mode $w
186
        opp_onestepinmodule $w $mode
187
        set_gui_for_runmode notrunning
188
    }
189
}
190
191
proc create_simplemodulewindow {name geom} {
192
    _create_modulewindow $name $geom 0
193
}
194
195
proc create_compoundmodulewindow {name geom} {
196
    _create_modulewindow $name $geom 1
197
}
198
199
proc _create_modulewindow {name geom iscompound} {
200
    global icons fonts help_tips B2 B3
201
202
    set w $name
203
    create_inspector_toplevel $w $geom
204
205
    regexp {\.(ptr.*)-[0-9]+} $w match modptr
206
207
    # Add icons
208
    if {$iscompound} {
209
        # for compound module
210
        pack_iconbutton $w.toolbar.graph  -image $icons(asgraphics) -command "inspect_this $w {As Graphics}"
211
        pack_iconbutton $w.toolbar.obj    -image $icons(asobject) -command "inspect_this $w {As Object}"
212
        pack_iconbutton $w.toolbar.sep1   -separator
213
        set help_tips($w.toolbar.owner)  {Inspect parent module}
214
        set help_tips($w.toolbar.graph)  {Inspect as network graphics}
215
        set help_tips($w.toolbar.obj)    {Inspect as object}
216
217
        textwindow_add_icons $w modulewindow
218
219
        moduleinspector_add_run_buttons $w
220
221
    } else {
222
        # for simple module
223
        pack_iconbutton $w.toolbar.obj    -image $icons(asobject) -command "inspect_this $w {As Object}"
224
        pack_iconbutton $w.toolbar.sep1   -separator
225
        set help_tips($w.toolbar.owner)  {Inspect parent module}
226
        set help_tips($w.toolbar.obj)    {Inspect as object}
227
228
        textwindow_add_icons $w modulewindow
229
230
        moduleinspector_add_run_buttons $w
231
    }
232
233
    frame $w.main
234
    text $w.main.text -yscrollcommand "$w.main.sb set" -width 80 -height 15 -font $fonts(text)
235
    scrollbar $w.main.sb -command "$w.main.text yview"
236
    logtextwidget_configuretags $w.main.text
237
238
    #pack $w.statusbar -anchor center -expand 0 -fill x -side top
239
    #pack $w.statusbar.name -anchor n -expand 1 -fill x -side left
240
    #pack $w.statusbar.phase   -anchor n -expand 1 -fill x -side right
241
    pack $w.main -anchor center -expand 1 -fill both -side top
242
    pack $w.main.sb -anchor center -expand 0 -fill y -side right
243
    pack $w.main.text -anchor center -expand 1 -fill both -side left
244
245
    # bindings for find
246
    bind_commands_to_textwidget $w.main.text modulewindow
247
}
248
249
proc logtextwidget_configuretags {txt} {
250
    $txt tag configure SELECT -back #808080 -fore #ffffff
251
    $txt tag configure event -foreground blue
252
    $txt tag configure log -foreground #006000
253
}
254
255
proc logtextwidget_clear {txt} {
256
    # Note: the direct way ($txt delete 0.1 end) is very slow if there's
257
    # a lot of lines (100,000). Luckily, removing all tags beforehand
258
    # speeds up the whole process about a hundred times. We need to
259
    # re-define the tags afterwards though.
260
261
    $txt tag delete log event
262
    $txt delete 0.1 end
263
    logtextwidget_configuretags $txt
264
}
265
266
proc mainlogwindow_filterdialog {} {
267
    set modptr [opp_object_systemmodule]
268
    set excludedModuleIds [opp_getmainwindowexcludedmoduleids]
269
    set excludedModuleIds [moduleOutputFilterDialog $modptr $excludedModuleIds]
270
    if {$excludedModuleIds!="0"} {
271
        opp_setmainwindowexcludedmoduleids $excludedModuleIds
272
    }
273
}
274
275
proc modulewindow_filterdialog {w} {
276
    regexp {\.(ptr.*)-[0-9]+} $w match modptr
277
    set excludedModuleIds [opp_inspectorcommand $w getexcludedmoduleids]
278
    set excludedModuleIds [moduleOutputFilterDialog $modptr $excludedModuleIds]
279
    if {$excludedModuleIds!="0"} {
280
        opp_inspectorcommand $w setexcludedmoduleids $excludedModuleIds
281
    }
282
}
283
284
proc mainlogwindow_trimlines {} {
285
    global config
286
    text_trimlines .main.text $config(logwindow-scrollbacklines)
287
}
288
289
proc modulewindow_trimlines {w} {
290
    global config
291
    text_trimlines $w.main.text $config(logwindow-scrollbacklines)
292
}
293
294
proc text_trimlines {t numlines} {
295
    if {$numlines==""} {return}
296
    set endline [$t index {end linestart}]
297
    if {$endline > $numlines + 100} {  ;# for performance, we want to delete in at least 100-line chunks
298
        set linestodelete [expr int($endline-$numlines)]
299
        $t delete 1.0 $linestodelete.0
300
    }
301
}
302