Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/plugins/hcprt/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
import numpy as np
22
23
from agilepy.lib_wx.modulegui import ModuleGui
24
from agilepy.lib_wx.ogleditor import *
25
from agilepy.lib_base.processes import Process
26
from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive
27
28
from coremodules.network import routing
29
from coremodules.demand import demand
30
from coremodules.simulation import sumo, results
31
import hcprt
32
33
try:
34
import results_mpl as results_mpl
35
is_mpl = True # we have matplotlib support
36
except:
37
print "WARNING: python matplotlib package not installed, no matplotlib plots."
38
is_mpl = False
39
40
41
class ResultDialog(ProcessDialog):
42
def _get_buttons(self):
43
buttons = [('Plot and close', self.on_run, 'Plot in matplotlib window and close this window thereafter.'),
44
('Plot', self.on_show, 'Plot in matplotlib window.'),
45
]
46
defaultbutton = 'Plot and close'
47
standartbuttons = ['cancel', ]
48
49
return buttons, defaultbutton, standartbuttons
50
51
def on_show(self, event):
52
self.process.show()
53
54
55
class WxGui(ModuleGui):
56
"""Contains functions that communicate between PRT plugin and the widgets of the main wx gui
57
and the functions of the plugin.
58
"""
59
60
def __init__(self, ident):
61
self._prtservice = None
62
self._demand = None
63
self._simulation = None
64
self._init_common(ident, priority=100003,
65
icondirpath=os.path.join(os.path.dirname(__file__), 'images'))
66
67
def get_module(self):
68
return self._prtservice
69
70
def get_scenario(self):
71
return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()
72
73
def get_neteditor(self):
74
return self._mainframe.get_modulegui('coremodules.network').get_neteditor()
75
76
def init_widgets(self, mainframe):
77
"""
78
Set mainframe and initialize widgets to various places.
79
"""
80
self._mainframe = mainframe
81
#self._neteditor = mainframe.add_view("Network", Neteditor)
82
83
# mainframe.browse_obj(self._module)
84
self.make_menu()
85
self.make_toolbar()
86
87
def refresh_widgets(self):
88
"""
89
Check through mainframe what the state of the application is
90
and reset widgets. For exampe enable/disable widgets
91
dependent on the availability of data.
92
"""
93
scenario = self.get_scenario()
94
print 'prtgui.refresh_widgets', self._simulation != scenario.simulation
95
96
is_refresh = False
97
if self._simulation != scenario.simulation:
98
del self._demand
99
del self._prtservice
100
del self._simulation
101
self._demand = scenario.demand
102
self._simulation = scenario.simulation
103
self._prtservice = self._simulation.add_simobject(ident='hcprtservice', SimClass=hcprt.HcPrtService)
104
is_refresh = True
105
#neteditor = self.get_neteditor()
106
# neteditor.get_toolbox().add_toolclass(AddPrtCompressorTool)
107
# if (self._prtservice is not None)&(self._simulation is not None):
108
# print ' self._simulation.results,self._prtservice._results:', self._simulation.results,self._prtservice.get_results(),id(self._simulation.results), id(self._prtservice.get_results())
109
# print ' self._simulation.results',id(self._simulation.results)
110
111
def make_menu(self):
112
menubar = self._mainframe.menubar
113
menubar.append_menu('plugins/hcprt', bitmap=self.get_icon('icon_hcprt.png'),)
114
if sumo.traci is not None:
115
menubar.append_item('plugins/hcprt/browse',
116
self.on_browse_obj, # common function in modulegui
117
info='View and browse High Capacity PRT in object panel.',
118
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
119
)
120
121
menubar.append_item('plugins/hcprt/make stops',
122
self.on_make_stops,
123
info='Make HCPRT stops from PT stops with PRT access ("custom1").',
124
# bitmap = self.get_icon('icon_sumo.png'),#,
125
)
126
# menubar.append_item( 'plugins/prt/update compressors',
127
# self.on_update_compressors,
128
# #bitmap = self.get_icon('icon_sumo.png'),#,
129
# )
130
131
# menubar.append_item( 'plugins/prt/clear compressors',
132
# self.on_clear_compressors,
133
# bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE,wx.ART_MENU),
134
# )
135
# menubar.append_item( 'plugins/prt/update decompressors',
136
# self.on_update_decompressors,
137
# #bitmap = self.get_icon('icon_sumo.png'),#,
138
# )
139
# menubar.append_item( 'plugins/prt/clear decompressors',
140
# self.on_clear_decompressors,
141
# bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE,wx.ART_MENU),
142
# )
143
144
menubar.append_item('plugins/hcprt/make merge nodes',
145
self.on_make_merges,
146
#info='Make PRT merge nodes.',
147
# bitmap = self.get_icon('icon_sumo.png'),#,
148
)
149
menubar.append_item('plugins/hcprt/calculate stop to stop times',
150
self.on_make_times_stop_to_stop,
151
# bitmap = self.get_icon('icon_sumo.png'),#,
152
)
153
154
menubar.append_item('plugins/hcprt/add vehicles...',
155
self.on_add_vehicles,
156
info='Add PRT vehicles to network.',
157
# bitmap = self.get_icon('icon_sumo.png'),#,
158
)
159
160
menubar.append_item('plugins/hcprt/clear vehicles.',
161
self.on_clear_vehicles,
162
info='Clear all PRT vehicles from network.',
163
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
164
)
165
166
menubar.append_menu('plugins/hcprt/results',
167
bitmap=self.get_icon('icon_results_24px.png'), # ,
168
)
169
if is_mpl:
170
menubar.append_item('plugins/hcprt/results/stopresults with matplotlib',
171
self.on_mpl_stopresults,
172
bitmap=self.get_icon('icon_mpl.png'), # ,
173
)
174
175
def on_make_stops(self, event=None):
176
self._prtservice.prtstops.make_from_net()
177
self._mainframe.browse_obj(self._prtservice.prtstops)
178
179
def on_make_merges(self, event=None):
180
181
self._prtservice.mergenodes.make_from_net()
182
self._mainframe.browse_obj(self._prtservice.mergenodes)
183
184
def on_make_times_stop_to_stop(self, event=None):
185
"""Determine stop to sto time matrix"""
186
187
self._prtservice.make_times_stop_to_stop()
188
self._mainframe.browse_obj(self._prtservice)
189
190
def on_add_vehicles(self, event=None):
191
p = hcprt.VehicleAdder(self._prtservice.prtvehicles, logger=self._mainframe.get_logger())
192
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
193
194
dlg.CenterOnScreen()
195
196
# this does not return until the dialog is closed.
197
val = dlg.ShowModal()
198
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
199
# print ' status =',dlg.get_status()
200
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
201
# print ">>>>>>>>>Unsuccessful\n"
202
dlg.Destroy()
203
204
if dlg.get_status() == 'success':
205
# print ">>>>>>>>>successful\n"
206
# apply current widget values to scenario instance
207
dlg.apply()
208
dlg.Destroy()
209
self._mainframe.browse_obj(self._prtservice.prtvehicles)
210
211
def on_clear_vehicles(self, event=None):
212
self._prtservice.prtvehicles.clear()
213
self._prtservice.prtvehicles.make_vtype(is_reset_vtype=True)
214
self._mainframe.browse_obj(self._prtservice.prtvehicles)
215
216
def on_mpl_stopresults(self, event=None):
217
print 'on_mpl_stopresults', id(self._simulation.results) # ,id(self._prtservice.get_results())
218
if self._prtservice is not None:
219
if self._simulation is not None:
220
resultplotter = results_mpl.StopresultsPlotter(self._simulation.results, # self._prtservice.get_results(),
221
logger=self._mainframe.get_logger())
222
dlg = ResultDialog(self._mainframe, resultplotter)
223
224
dlg.CenterOnScreen()
225
226
# this does not return until the dialog is closed.
227
val = dlg.ShowModal()
228
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
229
dlg.Destroy()
230
231
elif dlg.get_status() == 'success':
232
# apply current widget values to scenario instance
233
dlg.apply()
234
dlg.Destroy()
235
236