Path: blob/main/tools/contributed/sumopy/coremodules/simulation/wxgui.py
169689 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file wxgui.py15# @author Joerg Schweizer16# @date 20121718import os19import wx2021from agilepy.lib_wx.modulegui import ModuleGui22from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive23from coremodules.scenario.scenario import Scenario24from coremodules.network import routing25from coremodules.misc.matplottools import ResultDialog26import sumo27import results2829from result_oglviewer import Resultviewer3031try:32import results_mpl as results_mpl33is_mpl = True # we have matplotlib support34except:35print "WARNING: python matplotlib package not installed, no matplotlib plots."36is_mpl = False373839class EnergyResultDialog(ProcessDialog):40def _get_buttons(self):41buttons = [('Plot and close', self.on_run, 'Plot energy results in matplotlib window and close this window thereafter.'),42('Plot', self.on_show, 'Plot energy results in matplotlib window.'),43('Save Options...', self.on_save_options, self.on_save_options.__doc__),44('Load Options...', self.on_load_options, self.on_load_options.__doc__),45]46defaultbutton = 'Plot and close'47standartbuttons = ['cancel', ]4849return buttons, defaultbutton, standartbuttons5051def on_show(self, event):52self.process.show()535455class WxGui(ModuleGui):56"""Contains functions that communicate between the widgets of the main wx gui57and the functions of the plugin.58"""5960def __init__(self, ident):61self._net = None62self._init_common(ident, priority=10000,63icondirpath=os.path.join(os.path.dirname(__file__), 'images'))64self._simulation = None65self.simulator = None6667def get_module(self):68return self._simulation6970def get_scenario(self):71return self._mainframe.get_modulegui('coremodules.scenario').get_module()7273def get_neteditor(self):74return self._mainframe.get_modulegui('coremodules.network').get_neteditor()7576def get_resultviewer(self):77return self._resultviewer7879def init_widgets(self, mainframe):80"""81Set mainframe and initialize widgets to various places.82"""83self._mainframe = mainframe84print 'SimulationGui.init_widgets'85# mainframe.browse_obj(self._net)86self.make_menu()87self.make_toolbar()88self._resultviewer = mainframe.add_view("Result viewer", Resultviewer)89print ' self._resultviewer', self._resultviewer, self._resultviewer.get_drawing()9091def refresh_widgets(self):92"""93Check through mainframe what the state of the application is94and reset widgets. For exampe enable/disable widgets95dependent on the availability of data.96"""97scenario = self.get_scenario()98print 'simulation.WxGui.refresh_widgets', self._simulation != scenario.simulation99is_refresh = False100101if self._simulation != scenario.simulation:102print ' id(self._simulation)', id(self._simulation), 'id(scenario.simulation)', id(scenario.simulation), scenario.rootname103del self._simulation104self._simulation = scenario.simulation105is_refresh = True106107# if self._simulation.results is not None:108# print ' results is_modified',self._simulation.results.is_modified()109# if is_refresh110if self._simulation.results.is_modified():111#112print ' refresh of _resultviewer'113drawing = self._resultviewer.set_results(self._simulation.results)114# canvas = self._neteditor.get_canvas()115else:116print ' no refresh of _resultviewer :('117118def make_menu(self):119# print 'make_menu'120menubar = self._mainframe.menubar121menubar.append_menu('simulation', bitmap=self.get_icon('icon_sumo.png'))122123menubar.append_item('simulation/browse',124self.on_browse_obj, # common function in modulegui125info='View and browse simulation panel.',126bitmap=self.get_agileicon('icon_browse_24px.png'), # ,127)128129menubar.append_menu('simulation/microscopic simulation',130bitmap=self.get_icon('icon_sumo.png'),131)132133menubar.append_item('simulation/microscopic simulation/SUMO...',134self.on_sumo,135bitmap=self.get_icon('icon_sumo.png'), # ,136)137138# menubar.append_item( 'simulation/micro-simulation/Low memory SUMO...',139# self.on_sumo_lowmem,140# 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.',141# bitmap = self.get_icon('icon_sumo.png'),#,142# )143144if sumo.traci is not None:145menubar.append_item('simulation/microscopic simulation/SUMO traci...',146self.on_sumo_traci,147info='Define simulation parameters and simulate with SUMO with interactive control via TRACI.',148bitmap=self.get_icon('icon_sumo.png'), # ,149)150151menubar.append_item('simulation/microscopic simulation/Dynamic User Equilibrium...',152self.on_duaiterate,153bitmap=self.get_icon('icon_sumo.png'), # ,154)155156menubar.append_menu('simulation/mesoscopic simulation',157bitmap=self.get_icon('icon_sumo.png'),158)159160menubar.append_item('simulation/mesoscopic simulation/MESO...',161self.on_meso,162)163164menubar.append_menu('simulation/macroscopic simulation',165#bitmap = self.get_icon('icon_sumo.png'),166)167168menubar.append_item('simulation/macroscopic simulation/macroscopic router...',169self.on_maroute,170# bitmap = self.get_icon('icon_sumo.png'),#,171)172173menubar.append_item('simulation/macroscopic simulation/estimate entered from routes',174self.on_estimate_entered_demand,175info='Use routes from demand to compute how many vehicle entered each edge.',176# bitmap = self.get_icon('icon_sumo.png'),#,177)178179menubar.append_item('simulation/macroscopic simulation/estimate entered from turnflows',180self.on_estimate_entered_turnflows,181info='Use turnflows from demand to compute how many vehicle entered each edge.',182# bitmap = self.get_icon('icon_sumo.png'),#,183)184185menubar.append_menu('simulation/results',186bitmap=self.get_icon('icon_results_24px.png'), # ,187)188189menubar.append_item('simulation/results/browse',190self.on_show_results,191info='Browse simulation result table and graphics.',192bitmap=self.get_agileicon('icon_browse_24px.png'),193)194195# TODO: Error: Simresults instance has no attribute 'process'196# migh have been implemented in an older version!!197menubar.append_item('simulation/results/process',198self.on_process_results,199info='Process results. Update demand models with results from last simulation run.',200#bitmap = self.get_agileicon('icon_browse_24px.png'),#201)202203menubar.append_item('simulation/results/add edge length to edgeresults',204self.on_add_edgelength,205)206207menubar.append_item('simulation/results/add detector flow measurements to edgeresults',208self.on_add_detectorflows_to_edgeresults,209)210211# menubar.append_item( 'simulation/results/safe',212# self.on_save,213# info='Save current results in a Python binary file.',214# bitmap = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,wx.ART_MENU),215# )216217menubar.append_item('simulation/results/safe as...',218self.on_save_as,219info='Save results in a new Python binary file.',220bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_MENU),221)222223menubar.append_item('simulation/results/export edge results in csv...',224self.on_export_edgeresults_csv,225info='Save edge related results in a CSV file.',226bitmap=self.get_agileicon("Document_Export_24px.png"),227)228menubar.append_item('simulation/results/export trip results in csv...',229self.on_export_tripresults_csv,230info='Save trip related results in a CSV file.',231bitmap=self.get_agileicon("Document_Export_24px.png"),232)233234menubar.append_item('simulation/results/filter edgresults...',235self.on_filter_edgeresults,236)237238if is_mpl:239menubar.append_item('simulation/results/plot edge results on map',240self.on_plot_results,241bitmap=self.get_icon('icon_mpl.png'), # ,242)243244menubar.append_item('simulation/results/plot 2 edge results on XY plot...',245self.on_plot_xy_edgeresults,246bitmap=self.get_icon('icon_mpl.png'), # ,247)248menubar.append_item('simulation/results/plot speedprofiles...',249self.on_plot_speedprofiles,250bitmap=self.get_icon('icon_mpl.png'), # ,251)252253menubar.append_item('simulation/results/plot travel times...',254self.on_plot_traveltimes,255bitmap=self.get_icon('icon_mpl.png'), # ,256)257258menubar.append_item('simulation/results/plot electrical energy...',259self.on_plot_electrical_energy_results,260bitmap=self.get_icon('icon_mpl.png'), # ,261)262# menubar.append_item( 'simulation/results/Flowcompare with matplotlib',263# self.on_mpl_flowcompare,264# info='Compare simulated and estimated flows in Matplotlib plotting envitonment.',265# bitmap = self.get_icon('icon_mpl.png'),#,266# )267268menubar.append_item('simulation/results/open...',269self.on_open,270info='Open previousely saved simulation results from a Python binary file.',271bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU),272)273274menubar.append_item('simulation/results/clear all',275self.on_clear_results,276bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),277)278279# menubar.append_item( 'simulation/results/refresh results',280# self.on_refresh,281# info='refresh results.',282# #bitmap = self.get_icon('icon_sumo.png'),#,283# )284285def on_process_results(self, event=None):286"""287Deletes all results.288"""289if (self._simulation.results is not None):290self._simulation.results.process(self.simulator)291self._mainframe.browse_obj(self._simulation.results)292self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without293294def on_clear_results(self, event=None):295if (self._simulation.results is not None):296self._simulation.results.clear_results()297self._mainframe.browse_obj(self._simulation.results)298self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without299self.refresh_widgets()300301def on_show_results(self, event=None):302if self._simulation.results is None:303self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)304305self._mainframe.browse_obj(self._simulation.results)306self._mainframe.select_view(name="Result viewer") # !!!!!!!! tricky, crashes without307308# def on_refresh(self,event = None):309# #print 'on_refresh neteditor',id(self._neteditor.get_drawing())310#311#312# wx.CallAfter(self.refresh_widgets)313#314# if event:315# event.Skip()316317def on_open(self, event=None):318319wildcards_all = "All files (*.*)|*.*"320wildcards_obj = "Python binary result files (*.res.obj)|*.res.obj|Python binary files (*.obj)|*.obj"321wildcards = wildcards_obj+"|"+wildcards_all322323# Finally, if the directory is changed in the process of getting files, this324# dialog is set up to change the current working directory to the path chosen.325dlg = wx.FileDialog(326self._mainframe, message="Open results file",327defaultDir=self.get_scenario().get_workdirpath(),328#defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),329wildcard=wildcards,330style=wx.OPEN | wx.CHANGE_DIR331)332333# Show the dialog and retrieve the user response. If it is the OK response,334# process the data.335is_newresults = False336if dlg.ShowModal() == wx.ID_OK:337# This returns a Python list of files that were selected.338filepath = dlg.GetPath()339if len(filepath) > 0:340if self._simulation.results is not None:341# browse away from results342# self._mainframe.browse_obj(self._simulation.results.get_scenario())343del self._simulation.results344345self._simulation.results = results.load_results(filepath,346parent=self._simulation,347logger=self._mainframe.get_logger()348)349is_newresults = True350351# Destroy the dialog. Don't do this until you are done with it!352# BAD things can happen otherwise!353dlg.Destroy()354355if is_newresults:356# this should update all widgets for the new scenario!!357# print 'call self._mainframe.refresh_moduleguis()'358self._mainframe.browse_obj(self._simulation.results)359self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without360self.refresh_widgets()361# wx.CallAfter(self.refresh_widgets)362# self._mainframe.refresh_moduleguis()363#if event: event.Skip()364365# def on_save(self, event=None):366# if self._simulation.results is None: return367# self._simulation.results.save()368# #if event:369# # event.Skip()370371def on_save_as(self, event=None):372if self._simulation.results is None:373return374scenario = self._simulation.results.get_scenario()375wildcards_all = "All files (*.*)|*.*"376wildcards_obj = "Python binary result files (*.res.obj)|*.res.obj|Python binary files (*.obj)|*.obj"377wildcards = wildcards_obj+"|"+wildcards_all378379# Finally, if the directory is changed in the process of getting files, this380# dialog is set up to change the current working directory to the path chosen.381dlg = wx.FileDialog(382self._mainframe, message="Save results to file",383defaultDir=scenario.get_workdirpath(),384#defaultFile = scenario.get_rootfilepath()+'.res.obj',385wildcard=wildcards,386style=wx.SAVE | wx.CHANGE_DIR387)388val = dlg.ShowModal()389# Show the dialog and retrieve the user response. If it is the OK response,390# process the data.391if val == wx.ID_OK:392# This returns a Python list of files that were selected.393filepath = dlg.GetPath()394if len(filepath) > 0:395# now set new filename and workdir396self._simulation.results.save(filepath)397398# Destroy the dialog. Don't do this until you are done with it!399# BAD things can happen otherwise!400dlg.Destroy()401402def on_export_edgeresults_csv(self, event=None):403if self._simulation.results is None:404return405scenario = self._simulation.results.get_scenario()406wildcards_all = "All files (*.*)|*.*"407wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"408wildcards = wildcards_obj+"|"+wildcards_all409410# Finally, if the directory is changed in the process of getting files, this411# dialog is set up to change the current working directory to the path chosen.412dlg = wx.FileDialog(413self._mainframe, message="Export edge results to CSV file",414defaultDir=scenario.get_workdirpath(),415# defaultFile = scenario.get_rootfilepath()+'.edgeres.csv',416wildcard=wildcards,417style=wx.SAVE | wx.CHANGE_DIR418)419val = dlg.ShowModal()420# Show the dialog and retrieve the user response. If it is the OK response,421# process the data.422if val == wx.ID_OK:423# This returns a Python list of files that were selected.424filepath = dlg.GetPath()425if len(filepath) > 0:426# now set new filename and workdir427self._simulation.results.edgeresults.export_csv(filepath)428429# Destroy the dialog. Don't do this until you are done with it!430# BAD things can happen otherwise!431dlg.Destroy()432433def on_export_tripresults_csv(self, event=None):434if self._simulation.results is None:435return436scenario = self._simulation.results.get_scenario()437wildcards_all = "All files (*.*)|*.*"438wildcards_obj = "CSV files (*.csv)|*.csv|Text file (*.txt)|*.txt"439wildcards = wildcards_obj+"|"+wildcards_all440441# Finally, if the directory is changed in the process of getting files, this442# dialog is set up to change the current working directory to the path chosen.443dlg = wx.FileDialog(444self._mainframe, message="Export trip results to CSV file",445defaultDir=scenario.get_workdirpath(),446# defaultFile = scenario.get_rootfilepath()+'.tripres.csv',447wildcard=wildcards,448style=wx.SAVE | wx.CHANGE_DIR449)450val = dlg.ShowModal()451# Show the dialog and retrieve the user response. If it is the OK response,452# process the data.453if val == wx.ID_OK:454# This returns a Python list of files that were selected.455filepath = dlg.GetPath()456if len(filepath) > 0:457# now set new filename and workdir458self._simulation.results.tripresults.export_csv(filepath)459460# Destroy the dialog. Don't do this until you are done with it!461# BAD things can happen otherwise!462dlg.Destroy()463464def on_filter_edgeresults(self, event=None):465"""Filter edgeresults by zone, etc."""466if self._simulation.results is None:467self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)468469edgeresultfilter = results.EdgeresultFilter(self._simulation.results.edgeresults,470logger=self._mainframe.get_logger())471dlg = ProcessDialog(self._mainframe, edgeresultfilter)472473dlg.CenterOnScreen()474475# this does not return until the dialog is closed.476val = dlg.ShowModal()477# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL478# print ' status =',dlg.get_status()479if dlg.get_status() != 'success': # val == wx.ID_CANCEL:480# print ">>>>>>>>>Unsuccessful\n"481dlg.Destroy()482483if dlg.get_status() == 'success':484# print ">>>>>>>>>successful\n"485# apply current widget values to scenario instance486dlg.apply()487dlg.Destroy()488self._mainframe.browse_obj(self._simulation.results.edgeresults)489490def on_plot_results(self, event=None):491"""Plot edge results on map using the Matplotlib plotting envitonment."""492if self._simulation.results is None:493self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)494495if is_mpl:496resultplotter = results_mpl.Resultplotter(self._simulation.results,497logger=self._mainframe.get_logger())498dlg = ResultDialog(self._mainframe, resultplotter)499500dlg.CenterOnScreen()501502# this does not return until the dialog is closed.503val = dlg.ShowModal()504# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL505# print ' status =',dlg.get_status()506if dlg.get_status() != 'success': # val == wx.ID_CANCEL:507# print ">>>>>>>>>Unsuccessful\n"508dlg.Destroy()509510if dlg.get_status() == 'success':511# print ">>>>>>>>>successful\n"512# apply current widget values to scenario instance513dlg.apply()514dlg.Destroy()515516def on_plot_xy_edgeresults(self, event=None):517"""Plot one edge result attribute versus another result attribute using matplotlib."""518if self._simulation.results is None:519self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)520521if is_mpl:522resultplotter = results_mpl.XYEdgeresultsPlotter(self._simulation.results,523logger=self._mainframe.get_logger())524dlg = ResultDialog(self._mainframe, resultplotter)525526dlg.CenterOnScreen()527528# this does not return until the dialog is closed.529val = dlg.ShowModal()530# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL531# print ' status =',dlg.get_status()532if dlg.get_status() != 'success': # val == wx.ID_CANCEL:533# print ">>>>>>>>>Unsuccessful\n"534dlg.Destroy()535536if dlg.get_status() == 'success':537# print ">>>>>>>>>successful\n"538# apply current widget values to scenario instance539dlg.apply()540dlg.Destroy()541542def on_plot_speedprofiles(self, event=None):543"""Plot speed profiles using the Matplotlib plotting envitonment."""544if self._simulation.results is None:545self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)546547if is_mpl:548resultplotter = results_mpl.SpeedprofilePlotter(self._simulation.results,549logger=self._mainframe.get_logger())550dlg = ResultDialog(self._mainframe, resultplotter)551552dlg.CenterOnScreen()553554# this does not return until the dialog is closed.555val = dlg.ShowModal()556# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL557# print ' status =',dlg.get_status()558if dlg.get_status() != 'success': # val == wx.ID_CANCEL:559# print ">>>>>>>>>Unsuccessful\n"560dlg.Destroy()561562if dlg.get_status() == 'success':563# print ">>>>>>>>>successful\n"564# apply current widget values to scenario instance565dlg.apply()566dlg.Destroy()567568def on_plot_traveltimes(self, event=None):569"""Plot travel times to/from specific edges using the Matplotlib plotting envitonment."""570if self._simulation.results is None:571self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)572573if is_mpl:574resultplotter = results_mpl.TraveltimePlotter(self._simulation.results,575logger=self._mainframe.get_logger())576dlg = ResultDialog(self._mainframe, resultplotter)577578dlg.CenterOnScreen()579580# this does not return until the dialog is closed.581val = dlg.ShowModal()582if dlg.get_status() != 'success': # val == wx.ID_CANCEL:583dlg.Destroy()584585if dlg.get_status() == 'success':586dlg.apply()587dlg.Destroy()588589def on_plot_electrical_energy_results(self, event=None):590"""Plot energy results using the Matplotlib plotting envitonment."""591if self._simulation.results is None:592self._simulation.results = results.Simresults(ident='simresults', simulation=self._simulation)593594if is_mpl:595resultplotter = results_mpl.ElectricalEnergyResultsPlotter(self._simulation.results,596logger=self._mainframe.get_logger())597dlg = EnergyResultDialog(self._mainframe, resultplotter)598599dlg.CenterOnScreen()600601# this does not return until the dialog is closed.602val = dlg.ShowModal()603# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL604# print ' status =',dlg.get_status()605if dlg.get_status() != 'success': # val == wx.ID_CANCEL:606# print ">>>>>>>>>Unsuccessful\n"607dlg.Destroy()608609if dlg.get_status() == 'success':610# print ">>>>>>>>>successful\n"611# apply current widget values to scenario instance612dlg.apply()613dlg.Destroy()614615# def on_mpl_flowcompare(self, event = None):616# if self._simulation.results is None:617# self._simulation.results = results.Simresults(ident= 'simresults', simulation=self._simulation)618#619# if is_mpl:620# resultplotter = results_mpl.Flowcomparison( self._simulation.results,621# logger = self._mainframe.get_logger())622# dlg = ResultDialog(self._mainframe, resultplotter)623#624# dlg.CenterOnScreen()625#626# # this does not return until the dialog is closed.627# val = dlg.ShowModal()628# #print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL629# #print ' status =',dlg.get_status()630# if dlg.get_status() != 'success':#val == wx.ID_CANCEL:631# #print ">>>>>>>>>Unsuccessful\n"632# dlg.Destroy()633#634# if dlg.get_status() == 'success':635# #print ">>>>>>>>>successful\n"636# # apply current widget values to scenario instance637# dlg.apply()638# dlg.Destroy()639640def on_add_detectorflows_to_edgeresults(self, event=None):641"""Add detector flow measurements to edge results.642"""643# self._demand.detectorflows.clear()644# self._mainframe.browse_obj(self._demand.detectorflows)645detectorflows = self.get_scenario().demand.detectorflows646detectorflows.add_flows_to_edgeresults(self._simulation.results.edgeresults)647self._mainframe.browse_obj(self._simulation.results.edgeresults)648649def on_sumo(self, event=None):650"""651Set simulation parameters and simulate with SUMO micro-simulator652"""653# self.prepare_results()654self.simulator = sumo.Sumo(scenario=self.get_scenario(),655results=self._simulation.results,656logger=self._mainframe.get_logger(),657is_gui=True,658is_export_net=True,659is_export_poly=True,660is_export_rou=True,661is_prompt_filepaths=False,662)663self.open_sumodialog()664665# def on_sumo_lowmem(self, event = None):666# #self.prepare_results()667# # delete current scenario668# #del self._scenario669# scenario = self.get_scenario()670#671# # set dummy scenario672# dummyscenario = Scenario('empty', name_scenario = 'Empty')673# self._mainframe.get_modulegui('coremodules.scenario').set_module(dummyscenario)674# #self._scenario = scenariocreator.get_scenario()675#676# # this should update all widgets for the new scenario!!677# #print 'call self._mainframe.refresh_moduleguis()'678# self._mainframe.refresh_moduleguis()679# self._mainframe.browse_obj(dummyscenario)680#681# del scenario682683def on_sumo_prompt(self, event=None):684# self.prepare_results()685self.simulator = sumo.Sumo(scenario=self.get_scenario(),686results=self._simulation.results,687logger=self._mainframe.get_logger(),688is_gui=True,689is_export_net=False,690is_export_poly=False,691is_export_rou=False,692is_prompt_filepaths=True,693)694self.open_sumodialog()695696def on_sumo_traci(self, event=None):697# self.prepare_results()698self.simulator = sumo.SumoTraci(699scenario=self.get_scenario(),700results=self._simulation.results,701logger=self._mainframe.get_logger(),702is_gui=True,703is_export_net=True,704is_export_poly=True,705is_export_rou=True,706is_prompt_filepaths=False,707is_quit_on_end=True,708is_start=True,709)710self.open_sumodialog_interactive()711712def open_sumodialog(self):713dlg = ProcessDialog(self._mainframe, self.simulator)714715dlg.CenterOnScreen()716717# this does not return until the dialog is closed.718val = dlg.ShowModal()719# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL720# print ' status =',dlg.get_status()721if dlg.get_status() != 'success': # val == wx.ID_CANCEL:722# print ">>>>>>>>>Unsuccessful\n"723dlg.Destroy()724725if dlg.get_status() == 'success':726# print ">>>>>>>>>successful\n"727# apply current widget values to scenario instance728dlg.apply()729dlg.Destroy()730if self.simulator.status == 'success':731self.simulator.import_results()732733self._mainframe.browse_obj(self._simulation.results)734# print ' select_view'735# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without736# print ' call refresh_widgets'737self.refresh_widgets()738# print 'call self._mainframe.refresh_moduleguis()'739# self._mainframe.refresh_moduleguis()740741def open_sumodialog_interactive(self):742dlg = ProcessDialogInteractive(self._mainframe,743self.simulator,744title='SUMO-Traci Dialog',745func_close=self.close_sumodialog_interactive,746)747748dlg.CenterOnScreen()749750# this does not return until the dialog is closed.751#val = dlg.ShowModal()752print 'open_sumodialog_interactive'753dlg.Show()754dlg.MakeModal(True)755# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL756# print ' status =',dlg.get_status()757# print 'returned to main window self.simulator.status',self.simulator.status758759def close_sumodialog_interactive(self, dlg):760# called before destroying the dialog761if self.simulator.status == 'success':762self.simulator.import_results()763764self._mainframe.browse_obj(self._simulation.results)765self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without766self.refresh_widgets()767# print 'call self._mainframe.refresh_moduleguis()'768# self._mainframe.refresh_moduleguis()769770def on_estimate_entered_demand(self, event=None):771results = self._simulation.results772trips = self.get_scenario().demand.trips773results.edgeresults.add_entered_est(*trips.estimate_entered())774self._mainframe.browse_obj(results.edgeresults)775self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without776self.refresh_widgets()777778def on_add_edgelength(self, event=None):779"""780Add edgelength to edgeresults.781"""782results = self._simulation.results783results.edgeresults.add_edgelength()784self._mainframe.browse_obj(results.edgeresults)785self.refresh_widgets()786787def on_estimate_entered_turnflows(self, event=None):788results = self._simulation.results789turnflows = self.get_scenario().demand.turnflows790ids_edge, flows = turnflows.estimate_entered()791print 'on_estimate_entered_turnflows'792print 'ids_edge', ids_edge793print 'flows', flows794results.edgeresults.add_entered_est(*turnflows.estimate_entered())795self._mainframe.browse_obj(results.edgeresults)796self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without797self.refresh_widgets()798799def on_duaiterate(self, event=None):800"""Dynamic User equilibrium Assignment (DuaIterate).801"""802803p = sumo.Duaiterate(self.get_scenario(),804results=self._simulation.results,805logger=self._mainframe.get_logger(),806)807dlg = ProcessDialog(self._mainframe, p)808809dlg.CenterOnScreen()810811# this does not return until the dialog is closed.812val = dlg.ShowModal()813# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL814# print ' status =',dlg.get_status()815if dlg.get_status() != 'success': # val == wx.ID_CANCEL:816# print ">>>>>>>>>Unsuccessful\n"817dlg.Destroy()818819if dlg.get_status() == 'success':820# print ">>>>>>>>>successful\n"821# apply current widget values to scenario instance822dlg.apply()823dlg.Destroy()824self._mainframe.browse_obj(self.get_scenario().demand.trips)825826# p.import_results()827# self._mainframe.browse_obj(p.get_results())828# self._mainframe.select_view(name = "Result viewer") #!!!!!!!!tricky, crashes without829# self.refresh_widgets()830831def on_meso(self, event=None):832"""Simulate scenario with Mesoscopic, queue based simulator.833"""834835p = sumo.Meso(836scenario=self.get_scenario(),837results=self._simulation.results,838logger=self._mainframe.get_logger(),839is_gui=True,840is_export_net=True,841is_export_poly=True,842is_export_rou=True,843is_prompt_filepaths=False,844is_quit_on_end=False,845is_start=False,846)847848dlg = ProcessDialog(self._mainframe, p)849850dlg.CenterOnScreen()851852# this does not return until the dialog is closed.853val = dlg.ShowModal()854# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL855# print ' status =',dlg.get_status()856if dlg.get_status() != 'success': # val == wx.ID_CANCEL:857# print ">>>>>>>>>Unsuccessful\n"858dlg.Destroy()859860if dlg.get_status() == 'success':861# print ">>>>>>>>>successful\n"862# apply current widget values to scenario instance863dlg.apply()864dlg.Destroy()865# self._mainframe.browse_obj(self._simulation.results)866p.import_results()867self._mainframe.browse_obj(p.get_results())868self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without869self.refresh_widgets()870871def on_maroute(self, event=None):872"""Simulate scenario with Macrosopic router (marouter).873"""874875p = routing.MaRouter(self.get_scenario(),876results=self._simulation.results,877logger=self._mainframe.get_logger(),878)879dlg = ProcessDialog(self._mainframe, p)880881dlg.CenterOnScreen()882883# this does not return until the dialog is closed.884val = dlg.ShowModal()885# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL886# print ' status =',dlg.get_status()887if dlg.get_status() != 'success': # val == wx.ID_CANCEL:888# print ">>>>>>>>>Unsuccessful\n"889dlg.Destroy()890891if dlg.get_status() == 'success':892# print ">>>>>>>>>successful\n"893# apply current widget values to scenario instance894dlg.apply()895dlg.Destroy()896# self._mainframe.browse_obj(self._simulation.results)897p.import_results()898self._mainframe.browse_obj(p.get_results())899self._mainframe.select_view(name="Result viewer") # !!!!!!!!tricky, crashes without900self.refresh_widgets()901902903