Path: blob/main/tools/contributed/sumopy/plugins/hcprt/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 wx20import numpy as np2122from agilepy.lib_wx.modulegui import ModuleGui23from agilepy.lib_wx.ogleditor import *24from agilepy.lib_base.processes import Process25from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive2627from coremodules.network import routing28from coremodules.demand import demand29from coremodules.simulation import sumo, results30import hcprt3132try:33import results_mpl as results_mpl34is_mpl = True # we have matplotlib support35except:36print "WARNING: python matplotlib package not installed, no matplotlib plots."37is_mpl = False383940class ResultDialog(ProcessDialog):41def _get_buttons(self):42buttons = [('Plot and close', self.on_run, 'Plot in matplotlib window and close this window thereafter.'),43('Plot', self.on_show, 'Plot in matplotlib window.'),44]45defaultbutton = 'Plot and close'46standartbuttons = ['cancel', ]4748return buttons, defaultbutton, standartbuttons4950def on_show(self, event):51self.process.show()525354class WxGui(ModuleGui):55"""Contains functions that communicate between PRT plugin and the widgets of the main wx gui56and the functions of the plugin.57"""5859def __init__(self, ident):60self._prtservice = None61self._demand = None62self._simulation = None63self._init_common(ident, priority=100003,64icondirpath=os.path.join(os.path.dirname(__file__), 'images'))6566def get_module(self):67return self._prtservice6869def get_scenario(self):70return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()7172def get_neteditor(self):73return self._mainframe.get_modulegui('coremodules.network').get_neteditor()7475def init_widgets(self, mainframe):76"""77Set mainframe and initialize widgets to various places.78"""79self._mainframe = mainframe80#self._neteditor = mainframe.add_view("Network", Neteditor)8182# mainframe.browse_obj(self._module)83self.make_menu()84self.make_toolbar()8586def refresh_widgets(self):87"""88Check through mainframe what the state of the application is89and reset widgets. For exampe enable/disable widgets90dependent on the availability of data.91"""92scenario = self.get_scenario()93print 'prtgui.refresh_widgets', self._simulation != scenario.simulation9495is_refresh = False96if self._simulation != scenario.simulation:97del self._demand98del self._prtservice99del self._simulation100self._demand = scenario.demand101self._simulation = scenario.simulation102self._prtservice = self._simulation.add_simobject(ident='hcprtservice', SimClass=hcprt.HcPrtService)103is_refresh = True104#neteditor = self.get_neteditor()105# neteditor.get_toolbox().add_toolclass(AddPrtCompressorTool)106# if (self._prtservice is not None)&(self._simulation is not None):107# print ' self._simulation.results,self._prtservice._results:', self._simulation.results,self._prtservice.get_results(),id(self._simulation.results), id(self._prtservice.get_results())108# print ' self._simulation.results',id(self._simulation.results)109110def make_menu(self):111menubar = self._mainframe.menubar112menubar.append_menu('plugins/hcprt', bitmap=self.get_icon('icon_hcprt.png'),)113if sumo.traci is not None:114menubar.append_item('plugins/hcprt/browse',115self.on_browse_obj, # common function in modulegui116info='View and browse High Capacity PRT in object panel.',117bitmap=self.get_agileicon('icon_browse_24px.png'), # ,118)119120menubar.append_item('plugins/hcprt/make stops',121self.on_make_stops,122info='Make HCPRT stops from PT stops with PRT access ("custom1").',123# bitmap = self.get_icon('icon_sumo.png'),#,124)125# menubar.append_item( 'plugins/prt/update compressors',126# self.on_update_compressors,127# #bitmap = self.get_icon('icon_sumo.png'),#,128# )129130# menubar.append_item( 'plugins/prt/clear compressors',131# self.on_clear_compressors,132# bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE,wx.ART_MENU),133# )134# menubar.append_item( 'plugins/prt/update decompressors',135# self.on_update_decompressors,136# #bitmap = self.get_icon('icon_sumo.png'),#,137# )138# menubar.append_item( 'plugins/prt/clear decompressors',139# self.on_clear_decompressors,140# bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE,wx.ART_MENU),141# )142143menubar.append_item('plugins/hcprt/make merge nodes',144self.on_make_merges,145#info='Make PRT merge nodes.',146# bitmap = self.get_icon('icon_sumo.png'),#,147)148menubar.append_item('plugins/hcprt/calculate stop to stop times',149self.on_make_times_stop_to_stop,150# bitmap = self.get_icon('icon_sumo.png'),#,151)152153menubar.append_item('plugins/hcprt/add vehicles...',154self.on_add_vehicles,155info='Add PRT vehicles to network.',156# bitmap = self.get_icon('icon_sumo.png'),#,157)158159menubar.append_item('plugins/hcprt/clear vehicles.',160self.on_clear_vehicles,161info='Clear all PRT vehicles from network.',162bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),163)164165menubar.append_menu('plugins/hcprt/results',166bitmap=self.get_icon('icon_results_24px.png'), # ,167)168if is_mpl:169menubar.append_item('plugins/hcprt/results/stopresults with matplotlib',170self.on_mpl_stopresults,171bitmap=self.get_icon('icon_mpl.png'), # ,172)173174def on_make_stops(self, event=None):175self._prtservice.prtstops.make_from_net()176self._mainframe.browse_obj(self._prtservice.prtstops)177178def on_make_merges(self, event=None):179180self._prtservice.mergenodes.make_from_net()181self._mainframe.browse_obj(self._prtservice.mergenodes)182183def on_make_times_stop_to_stop(self, event=None):184"""Determine stop to sto time matrix"""185186self._prtservice.make_times_stop_to_stop()187self._mainframe.browse_obj(self._prtservice)188189def on_add_vehicles(self, event=None):190p = hcprt.VehicleAdder(self._prtservice.prtvehicles, logger=self._mainframe.get_logger())191dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)192193dlg.CenterOnScreen()194195# this does not return until the dialog is closed.196val = dlg.ShowModal()197# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL198# print ' status =',dlg.get_status()199if dlg.get_status() != 'success': # val == wx.ID_CANCEL:200# print ">>>>>>>>>Unsuccessful\n"201dlg.Destroy()202203if dlg.get_status() == 'success':204# print ">>>>>>>>>successful\n"205# apply current widget values to scenario instance206dlg.apply()207dlg.Destroy()208self._mainframe.browse_obj(self._prtservice.prtvehicles)209210def on_clear_vehicles(self, event=None):211self._prtservice.prtvehicles.clear()212self._prtservice.prtvehicles.make_vtype(is_reset_vtype=True)213self._mainframe.browse_obj(self._prtservice.prtvehicles)214215def on_mpl_stopresults(self, event=None):216print 'on_mpl_stopresults', id(self._simulation.results) # ,id(self._prtservice.get_results())217if self._prtservice is not None:218if self._simulation is not None:219resultplotter = results_mpl.StopresultsPlotter(self._simulation.results, # self._prtservice.get_results(),220logger=self._mainframe.get_logger())221dlg = ResultDialog(self._mainframe, resultplotter)222223dlg.CenterOnScreen()224225# this does not return until the dialog is closed.226val = dlg.ShowModal()227if dlg.get_status() != 'success': # val == wx.ID_CANCEL:228dlg.Destroy()229230elif dlg.get_status() == 'success':231# apply current widget values to scenario instance232dlg.apply()233dlg.Destroy()234235236