Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/simulation/wxgui.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file wxgui.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
import os
20
import wx
21
22
from agilepy.lib_wx.modulegui import ModuleGui
23
from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive
24
from coremodules.scenario.scenario import Scenario
25
from coremodules.network import routing
26
from coremodules.misc.matplottools import ResultDialog
27
import sumo
28
import results
29
30
from result_oglviewer import Resultviewer
31
32
try:
33
import results_mpl as results_mpl
34
is_mpl = True # we have matplotlib support
35
except:
36
print "WARNING: python matplotlib package not installed, no matplotlib plots."
37
is_mpl = False
38
39
40
class EnergyResultDialog(ProcessDialog):
41
def _get_buttons(self):
42
buttons = [('Plot and close', self.on_run, 'Plot energy results in matplotlib window and close this window thereafter.'),
43
('Plot', self.on_show, 'Plot energy results in matplotlib window.'),
44
('Save Options...', self.on_save_options, self.on_save_options.__doc__),
45
('Load Options...', self.on_load_options, self.on_load_options.__doc__),
46
]
47
defaultbutton = 'Plot and close'
48
standartbuttons = ['cancel', ]
49
50
return buttons, defaultbutton, standartbuttons
51
52
def on_show(self, event):
53
self.process.show()
54
55
56
class WxGui(ModuleGui):
57
"""Contains functions that communicate between the widgets of the main wx gui
58
and the functions of the plugin.
59
"""
60
61
def __init__(self, ident):
62
self._net = None
63
self._init_common(ident, priority=10000,
64
icondirpath=os.path.join(os.path.dirname(__file__), 'images'))
65
self._simulation = None
66
self.simulator = None
67
68
def get_module(self):
69
return self._simulation
70
71
def get_scenario(self):
72
return self._mainframe.get_modulegui('coremodules.scenario').get_module()
73
74
def get_neteditor(self):
75
return self._mainframe.get_modulegui('coremodules.network').get_neteditor()
76
77
def get_resultviewer(self):
78
return self._resultviewer
79
80
def init_widgets(self, mainframe):
81
"""
82
Set mainframe and initialize widgets to various places.
83
"""
84
self._mainframe = mainframe
85
print 'SimulationGui.init_widgets'
86
# mainframe.browse_obj(self._net)
87
self.make_menu()
88
self.make_toolbar()
89
self._resultviewer = mainframe.add_view("Result viewer", Resultviewer)
90
print ' self._resultviewer', self._resultviewer, self._resultviewer.get_drawing()
91
92
def refresh_widgets(self):
93
"""
94
Check through mainframe what the state of the application is
95
and reset widgets. For exampe enable/disable widgets
96
dependent on the availability of data.
97
"""
98
scenario = self.get_scenario()
99
print 'simulation.WxGui.refresh_widgets', self._simulation != scenario.simulation
100
is_refresh = False
101
102
if self._simulation != scenario.simulation:
103
print ' id(self._simulation)', id(self._simulation), 'id(scenario.simulation)', id(scenario.simulation), scenario.rootname
104
del self._simulation
105
self._simulation = scenario.simulation
106
is_refresh = True
107
108
# if self._simulation.results is not None:
109
# print ' results is_modified',self._simulation.results.is_modified()
110
# if is_refresh
111
if self._simulation.results.is_modified():
112
#
113
print ' refresh of _resultviewer'
114
drawing = self._resultviewer.set_results(self._simulation.results)
115
# canvas = self._neteditor.get_canvas()
116
else:
117
print ' no refresh of _resultviewer :('
118
119
def make_menu(self):
120
# print 'make_menu'
121
menubar = self._mainframe.menubar
122
menubar.append_menu('simulation', bitmap=self.get_icon('icon_sumo.png'))
123
124
menubar.append_item('simulation/browse',
125
self.on_browse_obj, # common function in modulegui
126
info='View and browse simulation panel.',
127
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
128
)
129
130
menubar.append_menu('simulation/microscopic simulation',
131
bitmap=self.get_icon('icon_sumo.png'),
132
)
133
134
menubar.append_item('simulation/microscopic simulation/SUMO...',
135
self.on_sumo,
136
bitmap=self.get_icon('icon_sumo.png'), # ,
137
)
138
139
# menubar.append_item( 'simulation/micro-simulation/Low memory SUMO...',
140
# self.on_sumo_lowmem,
141
# info='Define simulation parameters and simulate with SUMO micro-simulator. Low memory is used because the SUMOPy scenario will be deleted prior to run the simulation.',
142
# bitmap = self.get_icon('icon_sumo.png'),#,
143
# )
144
145
if sumo.traci is not None:
146
menubar.append_item('simulation/microscopic simulation/SUMO traci...',
147
self.on_sumo_traci,
148
info='Define simulation parameters and simulate with SUMO with interactive control via TRACI.',
149
bitmap=self.get_icon('icon_sumo.png'), # ,
150
)
151
152
menubar.append_item('simulation/microscopic simulation/Dynamic User Equilibrium...',
153
self.on_duaiterate,
154
bitmap=self.get_icon('icon_sumo.png'), # ,
155
)
156
157
menubar.append_menu('simulation/mesoscopic simulation',
158
bitmap=self.get_icon('icon_sumo.png'),
159
)
160
161
menubar.append_item('simulation/mesoscopic simulation/MESO...',
162
self.on_meso,
163
)
164
165
menubar.append_menu('simulation/macroscopic simulation',
166
#bitmap = self.get_icon('icon_sumo.png'),
167
)
168
169
menubar.append_item('simulation/macroscopic simulation/macroscopic router...',
170
self.on_maroute,
171
# bitmap = self.get_icon('icon_sumo.png'),#,
172
)
173
174
menubar.append_item('simulation/macroscopic simulation/estimate entered from routes',
175
self.on_estimate_entered_demand,
176
info='Use routes from demand to compute how many vehicle entered each edge.',
177
# bitmap = self.get_icon('icon_sumo.png'),#,
178
)
179
180
menubar.append_item('simulation/macroscopic simulation/estimate entered from turnflows',
181
self.on_estimate_entered_turnflows,
182
info='Use turnflows from demand to compute how many vehicle entered each edge.',
183
# bitmap = self.get_icon('icon_sumo.png'),#,
184
)
185
186
menubar.append_menu('simulation/results',
187
bitmap=self.get_icon('icon_results_24px.png'), # ,
188
)
189
190
menubar.append_item('simulation/results/browse',
191
self.on_show_results,
192
info='Browse simulation result table and graphics.',
193
bitmap=self.get_agileicon('icon_browse_24px.png'),
194
)
195
196
# TODO: Error: Simresults instance has no attribute 'process'
197
# migh have been implemented in an older version!!
198
menubar.append_item('simulation/results/process',
199
self.on_process_results,
200
info='Process results. Update demand models with results from last simulation run.',
201
#bitmap = self.get_agileicon('icon_browse_24px.png'),#
202
)
203
204
menubar.append_item('simulation/results/add edge length to edgeresults',
205
self.on_add_edgelength,
206
)
207
208
menubar.append_item('simulation/results/add detector flow measurements to edgeresults',
209
self.on_add_detectorflows_to_edgeresults,
210
)
211
212
# menubar.append_item( 'simulation/results/safe',
213
# self.on_save,
214
# info='Save current results in a Python binary file.',
215
# bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,wx.ART_MENU),
216
# )
217
218
menubar.append_item('simulation/results/safe as...',
219
self.on_save_as,
220
info='Save results in a new Python binary file.',
221
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),
222
)
223
224
menubar.append_item('simulation/results/export edge results in csv...',
225
self.on_export_edgeresults_csv,
226
info='Save edge related results in a CSV file.',
227
bitmap=self.get_agileicon("Document_Export_24px.png"),
228
)
229
menubar.append_item('simulation/results/export trip results in csv...',
230
self.on_export_tripresults_csv,
231
info='Save trip related results in a CSV file.',
232
bitmap=self.get_agileicon("Document_Export_24px.png"),
233
)
234
235
menubar.append_item('simulation/results/filter edgresults...',
236
self.on_filter_edgeresults,
237
)
238
239
if is_mpl:
240
menubar.append_item('simulation/results/plot edge results on map',
241
self.on_plot_results,
242
bitmap=self.get_icon('icon_mpl.png'), # ,
243
)
244
245
menubar.append_item('simulation/results/plot 2 edge results on XY plot...',
246
self.on_plot_xy_edgeresults,
247
bitmap=self.get_icon('icon_mpl.png'), # ,
248
)
249
menubar.append_item('simulation/results/plot speedprofiles...',
250
self.on_plot_speedprofiles,
251
bitmap=self.get_icon('icon_mpl.png'), # ,
252
)
253
254
menubar.append_item('simulation/results/plot travel times...',
255
self.on_plot_traveltimes,
256
bitmap=self.get_icon('icon_mpl.png'), # ,
257
)
258
259
menubar.append_item('simulation/results/plot electrical energy...',
260
self.on_plot_electrical_energy_results,
261
bitmap=self.get_icon('icon_mpl.png'), # ,
262
)
263
# menubar.append_item( 'simulation/results/Flowcompare with matplotlib',
264
# self.on_mpl_flowcompare,
265
# info='Compare simulated and estimated flows in Matplotlib plotting envitonment.',
266
# bitmap = self.get_icon('icon_mpl.png'),#,
267
# )
268
269
menubar.append_item('simulation/results/open...',
270
self.on_open,
271
info='Open previousely saved simulation results from a Python binary file.',
272
bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),
273
)
274
275
menubar.append_item('simulation/results/clear all',
276
self.on_clear_results,
277
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
278
)
279
280
# menubar.append_item( 'simulation/results/refresh results',
281
# self.on_refresh,
282
# info='refresh results.',
283
# #bitmap = self.get_icon('icon_sumo.png'),#,
284
# )
285
286
def on_process_results(self, event=None):
287
"""
288
Deletes all results.
289
"""
290
if (self._simulation.results is not None):
291
self._simulation.results.process(self.simulator)
292
self._mainframe.browse_obj(self._simulation.results)
293
self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without
294
295
def on_clear_results(self, event=None):
296
if (self._simulation.results is not None):
297
self._simulation.results.clear_results()
298
self._mainframe.browse_obj(self._simulation.results)
299
self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without
300
self.refresh_widgets()
301
302
def on_show_results(self, event=None):
303
if self._simulation.results is None:
304
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
305
306
self._mainframe.browse_obj(self._simulation.results)
307
self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without
308
309
# def on_refresh(self,event = None):
310
# #print 'on_refresh neteditor',id(self._neteditor.get_drawing())
311
#
312
#
313
# wx.CallAfter(self.refresh_widgets)
314
#
315
# if event:
316
# event.Skip()
317
318
def on_open(self, event=None):
319
320
wildcards_all = "All files (*.*)|*.*"
321
wildcards_obj = "Python binary result files (*.res.obj)|*.res.obj|Python binary files (*.obj)|*.obj"
322
wildcards = wildcards_obj+"|"+wildcards_all
323
324
# Finally, if the directory is changed in the process of getting files, this
325
# dialog is set up to change the current working directory to the path chosen.
326
dlg = wx.FileDialog(
327
self._mainframe, message="Open results file",
328
defaultDir=self.get_scenario().get_workdirpath(),
329
#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),
330
wildcard=wildcards,
331
style=wx.OPEN | wx.CHANGE_DIR
332
)
333
334
# Show the dialog and retrieve the user response. If it is the OK response,
335
# process the data.
336
is_newresults = False
337
if dlg.ShowModal() == wx.ID_OK:
338
# This returns a Python list of files that were selected.
339
filepath = dlg.GetPath()
340
if len(filepath) > 0:
341
if self._simulation.results is not None:
342
# browse away from results
343
# self._mainframe.browse_obj(self._simulation.results.get_scenario())
344
del self._simulation.results
345
346
self._simulation.results = results.load_results(filepath,
347
parent=self._simulation,
348
logger=self._mainframe.get_logger()
349
)
350
is_newresults = True
351
352
# Destroy the dialog. Don't do this until you are done with it!
353
# BAD things can happen otherwise!
354
dlg.Destroy()
355
356
if is_newresults:
357
# this should update all widgets for the new scenario!!
358
# print 'call self._mainframe.refresh_moduleguis()'
359
self._mainframe.browse_obj(self._simulation.results)
360
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
361
self.refresh_widgets()
362
# wx.CallAfter(self.refresh_widgets)
363
# self._mainframe.refresh_moduleguis()
364
#if event: event.Skip()
365
366
# def on_save(self, event=None):
367
# if self._simulation.results is None: return
368
# self._simulation.results.save()
369
# #if event:
370
# # event.Skip()
371
372
def on_save_as(self, event=None):
373
if self._simulation.results is None:
374
return
375
scenario = self._simulation.results.get_scenario()
376
wildcards_all = "All files (*.*)|*.*"
377
wildcards_obj = "Python binary result files (*.res.obj)|*.res.obj|Python binary files (*.obj)|*.obj"
378
wildcards = wildcards_obj+"|"+wildcards_all
379
380
# Finally, if the directory is changed in the process of getting files, this
381
# dialog is set up to change the current working directory to the path chosen.
382
dlg = wx.FileDialog(
383
self._mainframe, message="Save results to file",
384
defaultDir=scenario.get_workdirpath(),
385
#defaultFile = scenario.get_rootfilepath()+'.res.obj',
386
wildcard=wildcards,
387
style=wx.SAVE | wx.CHANGE_DIR
388
)
389
val = dlg.ShowModal()
390
# Show the dialog and retrieve the user response. If it is the OK response,
391
# process the data.
392
if val == wx.ID_OK:
393
# This returns a Python list of files that were selected.
394
filepath = dlg.GetPath()
395
if len(filepath) > 0:
396
# now set new filename and workdir
397
self._simulation.results.save(filepath)
398
399
# Destroy the dialog. Don't do this until you are done with it!
400
# BAD things can happen otherwise!
401
dlg.Destroy()
402
403
def on_export_edgeresults_csv(self, event=None):
404
if self._simulation.results is None:
405
return
406
scenario = self._simulation.results.get_scenario()
407
wildcards_all = "All files (*.*)|*.*"
408
wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"
409
wildcards = wildcards_obj+"|"+wildcards_all
410
411
# Finally, if the directory is changed in the process of getting files, this
412
# dialog is set up to change the current working directory to the path chosen.
413
dlg = wx.FileDialog(
414
self._mainframe, message="Export edge results to CSV file",
415
defaultDir=scenario.get_workdirpath(),
416
# defaultFile = scenario.get_rootfilepath()+'.edgeres.csv',
417
wildcard=wildcards,
418
style=wx.SAVE | wx.CHANGE_DIR
419
)
420
val = dlg.ShowModal()
421
# Show the dialog and retrieve the user response. If it is the OK response,
422
# process the data.
423
if val == wx.ID_OK:
424
# This returns a Python list of files that were selected.
425
filepath = dlg.GetPath()
426
if len(filepath) > 0:
427
# now set new filename and workdir
428
self._simulation.results.edgeresults.export_csv(filepath)
429
430
# Destroy the dialog. Don't do this until you are done with it!
431
# BAD things can happen otherwise!
432
dlg.Destroy()
433
434
def on_export_tripresults_csv(self, event=None):
435
if self._simulation.results is None:
436
return
437
scenario = self._simulation.results.get_scenario()
438
wildcards_all = "All files (*.*)|*.*"
439
wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"
440
wildcards = wildcards_obj+"|"+wildcards_all
441
442
# Finally, if the directory is changed in the process of getting files, this
443
# dialog is set up to change the current working directory to the path chosen.
444
dlg = wx.FileDialog(
445
self._mainframe, message="Export trip results to CSV file",
446
defaultDir=scenario.get_workdirpath(),
447
# defaultFile = scenario.get_rootfilepath()+'.tripres.csv',
448
wildcard=wildcards,
449
style=wx.SAVE | wx.CHANGE_DIR
450
)
451
val = dlg.ShowModal()
452
# Show the dialog and retrieve the user response. If it is the OK response,
453
# process the data.
454
if val == wx.ID_OK:
455
# This returns a Python list of files that were selected.
456
filepath = dlg.GetPath()
457
if len(filepath) > 0:
458
# now set new filename and workdir
459
self._simulation.results.tripresults.export_csv(filepath)
460
461
# Destroy the dialog. Don't do this until you are done with it!
462
# BAD things can happen otherwise!
463
dlg.Destroy()
464
465
def on_filter_edgeresults(self, event=None):
466
"""Filter edgeresults by zone, etc."""
467
if self._simulation.results is None:
468
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
469
470
edgeresultfilter = results.EdgeresultFilter(self._simulation.results.edgeresults,
471
logger=self._mainframe.get_logger())
472
dlg = ProcessDialog(self._mainframe, edgeresultfilter)
473
474
dlg.CenterOnScreen()
475
476
# this does not return until the dialog is closed.
477
val = dlg.ShowModal()
478
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
479
# print ' status =',dlg.get_status()
480
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
481
# print ">>>>>>>>>Unsuccessful\n"
482
dlg.Destroy()
483
484
if dlg.get_status() == 'success':
485
# print ">>>>>>>>>successful\n"
486
# apply current widget values to scenario instance
487
dlg.apply()
488
dlg.Destroy()
489
self._mainframe.browse_obj(self._simulation.results.edgeresults)
490
491
def on_plot_results(self, event=None):
492
"""Plot edge results on map using the Matplotlib plotting envitonment."""
493
if self._simulation.results is None:
494
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
495
496
if is_mpl:
497
resultplotter = results_mpl.Resultplotter(self._simulation.results,
498
logger=self._mainframe.get_logger())
499
dlg = ResultDialog(self._mainframe, resultplotter)
500
501
dlg.CenterOnScreen()
502
503
# this does not return until the dialog is closed.
504
val = dlg.ShowModal()
505
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
506
# print ' status =',dlg.get_status()
507
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
508
# print ">>>>>>>>>Unsuccessful\n"
509
dlg.Destroy()
510
511
if dlg.get_status() == 'success':
512
# print ">>>>>>>>>successful\n"
513
# apply current widget values to scenario instance
514
dlg.apply()
515
dlg.Destroy()
516
517
def on_plot_xy_edgeresults(self, event=None):
518
"""Plot one edge result attribute versus another result attribute using matplotlib."""
519
if self._simulation.results is None:
520
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
521
522
if is_mpl:
523
resultplotter = results_mpl.XYEdgeresultsPlotter(self._simulation.results,
524
logger=self._mainframe.get_logger())
525
dlg = ResultDialog(self._mainframe, resultplotter)
526
527
dlg.CenterOnScreen()
528
529
# this does not return until the dialog is closed.
530
val = dlg.ShowModal()
531
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
532
# print ' status =',dlg.get_status()
533
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
534
# print ">>>>>>>>>Unsuccessful\n"
535
dlg.Destroy()
536
537
if dlg.get_status() == 'success':
538
# print ">>>>>>>>>successful\n"
539
# apply current widget values to scenario instance
540
dlg.apply()
541
dlg.Destroy()
542
543
def on_plot_speedprofiles(self, event=None):
544
"""Plot speed profiles using the Matplotlib plotting envitonment."""
545
if self._simulation.results is None:
546
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
547
548
if is_mpl:
549
resultplotter = results_mpl.SpeedprofilePlotter(self._simulation.results,
550
logger=self._mainframe.get_logger())
551
dlg = ResultDialog(self._mainframe, resultplotter)
552
553
dlg.CenterOnScreen()
554
555
# this does not return until the dialog is closed.
556
val = dlg.ShowModal()
557
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
558
# print ' status =',dlg.get_status()
559
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
560
# print ">>>>>>>>>Unsuccessful\n"
561
dlg.Destroy()
562
563
if dlg.get_status() == 'success':
564
# print ">>>>>>>>>successful\n"
565
# apply current widget values to scenario instance
566
dlg.apply()
567
dlg.Destroy()
568
569
def on_plot_traveltimes(self, event=None):
570
"""Plot travel times to/from specific edges using the Matplotlib plotting envitonment."""
571
if self._simulation.results is None:
572
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
573
574
if is_mpl:
575
resultplotter = results_mpl.TraveltimePlotter(self._simulation.results,
576
logger=self._mainframe.get_logger())
577
dlg = ResultDialog(self._mainframe, resultplotter)
578
579
dlg.CenterOnScreen()
580
581
# this does not return until the dialog is closed.
582
val = dlg.ShowModal()
583
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
584
dlg.Destroy()
585
586
if dlg.get_status() == 'success':
587
dlg.apply()
588
dlg.Destroy()
589
590
def on_plot_electrical_energy_results(self, event=None):
591
"""Plot energy results using the Matplotlib plotting envitonment."""
592
if self._simulation.results is None:
593
self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)
594
595
if is_mpl:
596
resultplotter = results_mpl.ElectricalEnergyResultsPlotter(self._simulation.results,
597
logger=self._mainframe.get_logger())
598
dlg = EnergyResultDialog(self._mainframe, resultplotter)
599
600
dlg.CenterOnScreen()
601
602
# this does not return until the dialog is closed.
603
val = dlg.ShowModal()
604
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
605
# print ' status =',dlg.get_status()
606
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
607
# print ">>>>>>>>>Unsuccessful\n"
608
dlg.Destroy()
609
610
if dlg.get_status() == 'success':
611
# print ">>>>>>>>>successful\n"
612
# apply current widget values to scenario instance
613
dlg.apply()
614
dlg.Destroy()
615
616
# def on_mpl_flowcompare(self, event = None):
617
# if self._simulation.results is None:
618
# self._simulation.results = results.Simresults(ident= 'simresults', simulation=self._simulation)
619
#
620
# if is_mpl:
621
# resultplotter = results_mpl.Flowcomparison( self._simulation.results,
622
# logger = self._mainframe.get_logger())
623
# dlg = ResultDialog(self._mainframe, resultplotter)
624
#
625
# dlg.CenterOnScreen()
626
#
627
# # this does not return until the dialog is closed.
628
# val = dlg.ShowModal()
629
# #print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
630
# #print ' status =',dlg.get_status()
631
# if dlg.get_status() != 'success':#val == wx.ID_CANCEL:
632
# #print ">>>>>>>>>Unsuccessful\n"
633
# dlg.Destroy()
634
#
635
# if dlg.get_status() == 'success':
636
# #print ">>>>>>>>>successful\n"
637
# # apply current widget values to scenario instance
638
# dlg.apply()
639
# dlg.Destroy()
640
641
def on_add_detectorflows_to_edgeresults(self, event=None):
642
"""Add detector flow measurements to edge results.
643
"""
644
# self._demand.detectorflows.clear()
645
# self._mainframe.browse_obj(self._demand.detectorflows)
646
detectorflows = self.get_scenario().demand.detectorflows
647
detectorflows.add_flows_to_edgeresults(self._simulation.results.edgeresults)
648
self._mainframe.browse_obj(self._simulation.results.edgeresults)
649
650
def on_sumo(self, event=None):
651
"""
652
Set simulation parameters and simulate with SUMO micro-simulator
653
"""
654
# self.prepare_results()
655
self.simulator = sumo.Sumo(scenario=self.get_scenario(),
656
results=self._simulation.results,
657
logger=self._mainframe.get_logger(),
658
is_gui=True,
659
is_export_net=True,
660
is_export_poly=True,
661
is_export_rou=True,
662
is_prompt_filepaths=False,
663
)
664
self.open_sumodialog()
665
666
# def on_sumo_lowmem(self, event = None):
667
# #self.prepare_results()
668
# # delete current scenario
669
# #del self._scenario
670
# scenario = self.get_scenario()
671
#
672
# # set dummy scenario
673
# dummyscenario = Scenario('empty', name_scenario = 'Empty')
674
# self._mainframe.get_modulegui('coremodules.scenario').set_module(dummyscenario)
675
# #self._scenario = scenariocreator.get_scenario()
676
#
677
# # this should update all widgets for the new scenario!!
678
# #print 'call self._mainframe.refresh_moduleguis()'
679
# self._mainframe.refresh_moduleguis()
680
# self._mainframe.browse_obj(dummyscenario)
681
#
682
# del scenario
683
684
def on_sumo_prompt(self, event=None):
685
# self.prepare_results()
686
self.simulator = sumo.Sumo(scenario=self.get_scenario(),
687
results=self._simulation.results,
688
logger=self._mainframe.get_logger(),
689
is_gui=True,
690
is_export_net=False,
691
is_export_poly=False,
692
is_export_rou=False,
693
is_prompt_filepaths=True,
694
)
695
self.open_sumodialog()
696
697
def on_sumo_traci(self, event=None):
698
# self.prepare_results()
699
self.simulator = sumo.SumoTraci(
700
scenario=self.get_scenario(),
701
results=self._simulation.results,
702
logger=self._mainframe.get_logger(),
703
is_gui=True,
704
is_export_net=True,
705
is_export_poly=True,
706
is_export_rou=True,
707
is_prompt_filepaths=False,
708
is_quit_on_end=True,
709
is_start=True,
710
)
711
self.open_sumodialog_interactive()
712
713
def open_sumodialog(self):
714
dlg = ProcessDialog(self._mainframe, self.simulator)
715
716
dlg.CenterOnScreen()
717
718
# this does not return until the dialog is closed.
719
val = dlg.ShowModal()
720
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
721
# print ' status =',dlg.get_status()
722
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
723
# print ">>>>>>>>>Unsuccessful\n"
724
dlg.Destroy()
725
726
if dlg.get_status() == 'success':
727
# print ">>>>>>>>>successful\n"
728
# apply current widget values to scenario instance
729
dlg.apply()
730
dlg.Destroy()
731
if self.simulator.status == 'success':
732
self.simulator.import_results()
733
734
self._mainframe.browse_obj(self._simulation.results)
735
# print ' select_view'
736
# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without
737
# print ' call refresh_widgets'
738
self.refresh_widgets()
739
# print 'call self._mainframe.refresh_moduleguis()'
740
# self._mainframe.refresh_moduleguis()
741
742
def open_sumodialog_interactive(self):
743
dlg = ProcessDialogInteractive(self._mainframe,
744
self.simulator,
745
title='SUMO-Traci Dialog',
746
func_close=self.close_sumodialog_interactive,
747
)
748
749
dlg.CenterOnScreen()
750
751
# this does not return until the dialog is closed.
752
#val = dlg.ShowModal()
753
print 'open_sumodialog_interactive'
754
dlg.Show()
755
dlg.MakeModal(True)
756
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
757
# print ' status =',dlg.get_status()
758
# print 'returned to main window self.simulator.status',self.simulator.status
759
760
def close_sumodialog_interactive(self, dlg):
761
# called before destroying the dialog
762
if self.simulator.status == 'success':
763
self.simulator.import_results()
764
765
self._mainframe.browse_obj(self._simulation.results)
766
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
767
self.refresh_widgets()
768
# print 'call self._mainframe.refresh_moduleguis()'
769
# self._mainframe.refresh_moduleguis()
770
771
def on_estimate_entered_demand(self, event=None):
772
results = self._simulation.results
773
trips = self.get_scenario().demand.trips
774
results.edgeresults.add_entered_est(*trips.estimate_entered())
775
self._mainframe.browse_obj(results.edgeresults)
776
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
777
self.refresh_widgets()
778
779
def on_add_edgelength(self, event=None):
780
"""
781
Add edgelength to edgeresults.
782
"""
783
results = self._simulation.results
784
results.edgeresults.add_edgelength()
785
self._mainframe.browse_obj(results.edgeresults)
786
self.refresh_widgets()
787
788
def on_estimate_entered_turnflows(self, event=None):
789
results = self._simulation.results
790
turnflows = self.get_scenario().demand.turnflows
791
ids_edge, flows = turnflows.estimate_entered()
792
print 'on_estimate_entered_turnflows'
793
print 'ids_edge', ids_edge
794
print 'flows', flows
795
results.edgeresults.add_entered_est(*turnflows.estimate_entered())
796
self._mainframe.browse_obj(results.edgeresults)
797
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
798
self.refresh_widgets()
799
800
def on_duaiterate(self, event=None):
801
"""Dynamic User equilibrium Assignment (DuaIterate).
802
"""
803
804
p = sumo.Duaiterate(self.get_scenario(),
805
results=self._simulation.results,
806
logger=self._mainframe.get_logger(),
807
)
808
dlg = ProcessDialog(self._mainframe, p)
809
810
dlg.CenterOnScreen()
811
812
# this does not return until the dialog is closed.
813
val = dlg.ShowModal()
814
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
815
# print ' status =',dlg.get_status()
816
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
817
# print ">>>>>>>>>Unsuccessful\n"
818
dlg.Destroy()
819
820
if dlg.get_status() == 'success':
821
# print ">>>>>>>>>successful\n"
822
# apply current widget values to scenario instance
823
dlg.apply()
824
dlg.Destroy()
825
self._mainframe.browse_obj(self.get_scenario().demand.trips)
826
827
# p.import_results()
828
# self._mainframe.browse_obj(p.get_results())
829
# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without
830
# self.refresh_widgets()
831
832
def on_meso(self, event=None):
833
"""Simulate scenario with Mesoscopic, queue based simulator.
834
"""
835
836
p = sumo.Meso(
837
scenario=self.get_scenario(),
838
results=self._simulation.results,
839
logger=self._mainframe.get_logger(),
840
is_gui=True,
841
is_export_net=True,
842
is_export_poly=True,
843
is_export_rou=True,
844
is_prompt_filepaths=False,
845
is_quit_on_end=False,
846
is_start=False,
847
)
848
849
dlg = ProcessDialog(self._mainframe, p)
850
851
dlg.CenterOnScreen()
852
853
# this does not return until the dialog is closed.
854
val = dlg.ShowModal()
855
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
856
# print ' status =',dlg.get_status()
857
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
858
# print ">>>>>>>>>Unsuccessful\n"
859
dlg.Destroy()
860
861
if dlg.get_status() == 'success':
862
# print ">>>>>>>>>successful\n"
863
# apply current widget values to scenario instance
864
dlg.apply()
865
dlg.Destroy()
866
# self._mainframe.browse_obj(self._simulation.results)
867
p.import_results()
868
self._mainframe.browse_obj(p.get_results())
869
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
870
self.refresh_widgets()
871
872
def on_maroute(self, event=None):
873
"""Simulate scenario with Macrosopic router (marouter).
874
"""
875
876
p = routing.MaRouter(self.get_scenario(),
877
results=self._simulation.results,
878
logger=self._mainframe.get_logger(),
879
)
880
dlg = ProcessDialog(self._mainframe, p)
881
882
dlg.CenterOnScreen()
883
884
# this does not return until the dialog is closed.
885
val = dlg.ShowModal()
886
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
887
# print ' status =',dlg.get_status()
888
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
889
# print ">>>>>>>>>Unsuccessful\n"
890
dlg.Destroy()
891
892
if dlg.get_status() == 'success':
893
# print ">>>>>>>>>successful\n"
894
# apply current widget values to scenario instance
895
dlg.apply()
896
dlg.Destroy()
897
# self._mainframe.browse_obj(self._simulation.results)
898
p.import_results()
899
self._mainframe.browse_obj(p.get_results())
900
self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without
901
self.refresh_widgets()
902
903