Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/demand/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
27
28
from coremodules.network import routing
29
from coremodules.scenario.scenario import load_scenario
30
31
import demand
32
import turnflows
33
import origin_to_destination_wxgui as odgui
34
import turnflows_wxgui as turnflowsgui
35
import virtualpop_wxgui as virtualpopgui
36
import detectorflows_wxgui as detectorflowsgui
37
import publictransportservices_wxgui as pt
38
39
40
class TripDrawings(Polygons):
41
def __init__(self, facilities, parent, **kwargs):
42
43
Polygons.__init__(self, 'facilitydraws', parent,
44
name='Facility drawings',
45
linewidth=1,
46
detectwidth=3.0,
47
**kwargs)
48
49
self.delete('vertices')
50
51
self.add(cm.AttrConf('color_facility_default', np.array([0.921875, 0.78125, 0.4375, 1.0], np.float32),
52
groupnames=['options'],
53
perm='wr',
54
metatype='color',
55
name='Default color',
56
info='Default facility color.',
57
))
58
59
self.set_facilities(facilities)
60
61
def get_netelement(self):
62
return self._facilities
63
64
def get_vertices_array(self):
65
return self._facilities.shapes.value[self._inds_map]
66
67
def set_facilities(self, facilities):
68
# print '\nset_facilities',facilities.get_ids()
69
self._facilities = facilities
70
if len(self) > 0:
71
self.del_rows(self.get_ids())
72
73
ids = self._facilities.get_ids()
74
self._inds_map = self._facilities.get_inds(ids)
75
self.add_rows(ids=ids)
76
self.update()
77
78
def update(self, is_update=True):
79
# assumes that arrsy structure did not change
80
# print 'FacilityDrawings.update'
81
n = len(self)
82
self.colors.value[:] = np.ones((n, 4), np.float32)*self.color_facility_default.value
83
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
84
85
landusetypes = self._facilities.get_landusetypes()
86
ids_landusetype = self._facilities.ids_landusetype.value
87
for id_landusetype in landusetypes.get_ids():
88
#inds = np.flatnonzero(ids_landusetype == id_landusetype)
89
#color = landusetypes.colors[id_landusetype]
90
#self.colors.value[self._inds_map[inds]] = color
91
self.colors.value[self._inds_map[np.flatnonzero(
92
ids_landusetype == id_landusetype)]] = landusetypes.colors[id_landusetype]
93
94
if is_update:
95
self._update_vertexvbo()
96
self._update_colorvbo()
97
98
99
class RouteDrawings(Polygons):
100
def __init__(self, zones, parent, **kwargs):
101
102
Polygons.__init__(self, 'zonedraws', parent,
103
name='Transport assignment zone drawings',
104
linewidth=4,
105
detectwidth=5.0,
106
**kwargs)
107
108
self.delete('vertices')
109
110
self.add(cm.AttrConf('color_default', np.array([0.3, 0.9, 0.5, 0.8], dtype=np.float32),
111
groupnames=['options'],
112
perm='wr',
113
metatype='color',
114
name='Default color',
115
info='Default facility color.',
116
))
117
118
self.set_netelement(zones)
119
120
def get_netelement(self):
121
return self._zones
122
123
def get_vertices_array(self):
124
if self._is_not_synched:
125
self._inds_map = self._zones.get_inds(self._zones.get_ids())
126
self._is_not_synched = False
127
return self._zones.shapes.value[self._inds_map]
128
129
def set_netelement(self, zones):
130
# print '\nset_facilities',facilities.get_ids()
131
self._zones = zones
132
if len(self) > 0:
133
self.del_rows(self.get_ids())
134
135
ids = self._zones.get_ids()
136
#self._inds_map = self._zones.get_inds(ids)
137
self.add_rows(ids=ids)
138
139
# plugins to keep grapgics syncronized with netelements
140
zones.shapes.plugin.add_event(cm.EVTADDITEM, self.on_add_element)
141
zones.plugin.add_event(cm.EVTDELITEM, self.on_del_element)
142
143
self._id_target = -1
144
self.update()
145
146
def update(self, is_update=True):
147
# assumes that arrsy structure did not change
148
# print 'FacilityDrawings.update'
149
n = len(self)
150
self.colors.value[:] = np.ones((n, 4), np.float32)*self.color_default.value
151
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
152
153
if is_update:
154
self.update_internal()
155
156
def update_internal(self):
157
# print 'update_internal'
158
# print ' len(self),len(self._zones)',len(self),len(self._zones)
159
self._is_not_synched = True
160
self._update_vertexvbo()
161
self._update_colorvbo()
162
163
def make_zone(self, shape, color):
164
# print 'make_zone shape',shape,type(shape)
165
return self._zones.make(shape=shape)
166
167
def on_add_element(self, shapes, ids):
168
# print 'on_add_element',shapes.attrname,ids
169
if shapes == self._zones.shapes:
170
self._id_target = ids[0]
171
self.add_row(_id=self._id_target,
172
colors=self.color_default.value,
173
colors_highl=self._get_colors_highl(self.color_default.value)
174
)
175
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
176
# self._update_vertexvbo()
177
# self._update_colorvbo()
178
179
def begin_animation(self, id_target):
180
# print 'ZoneDrawings.begin_animation zones.shapes=\n',id_target,self._id_target, self._zones.shapes[id_target]
181
if self._id_target == -1:
182
self._id_target = id_target
183
self._drawobj_anim = self.parent.get_drawobj_by_ident(self._ident_drawobj_anim)
184
self.id_anim = self._drawobj_anim.add_drawobj(self._zones.shapes[self._id_target],
185
self.color_anim.value,
186
)
187
# print 'begin_animation',self.ident,_id,self._drawobj_anim
188
return True
189
190
def end_animation(self, is_del_last_vert=False):
191
# print 'ZoneDrawings.end_animation',self.ident,self._id_target,self.id_anim
192
193
# print ' verices =',self._drawobj_anim.vertices[self.id_anim]
194
# print ' self._drawobj_anim.vertices[self.id_anim]=',self._drawobj_anim.vertices[self.id_anim]
195
shape = self._drawobj_anim.vertices[self.id_anim]
196
self._zones.shapes[self._id_target] = shape
197
self._zones.coords[self._id_target] = self._zones.get_coords_from_shape(shape)
198
199
self.del_animation()
200
# print ' self.get_vertices_array()=\n',self.get_vertices_array()
201
# self._drawobj_anim.del_drawobj(self.id_anim)
202
self.update_internal()
203
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
204
# self._update_vertexvbo()
205
# self._update_colorvbo()
206
return True
207
208
def del_elem(self, id_zone):
209
"""
210
Deletes an element from network and then in on canvas
211
through callback on_del_element
212
"""
213
# print 'del_elem'
214
# print ' len(self),len(self._zones)',len(self),len(self._zones)
215
216
self._zones.del_element(id_zone)
217
218
def on_del_element(self, shapes, ids):
219
"""
220
callback from netelement
221
"""
222
# print 'on_del_element',shapes.attrname,ids,self._id_target
223
# print ' len(self),len(self._zones)',len(self),len(self._zones)
224
# print ' verices =',self._drawobj_anim.vertices[self.id_anim]
225
self._is_not_synched = True
226
self.del_drawobj(ids[0])
227
# print ' len(self),len(self._zones)',len(self),len(self._zones)
228
# wx.CallAfter(self.update_internal)
229
# self.update_internal()
230
# print ' after CallAfter'
231
# print ' len(self),len(self._zones)',len(self),len(self._zones)
232
return True
233
234
def del_animation(self, is_del_main=False):
235
# print 'end_animation',self.ident,_id,self._drawobj_anim
236
self._drawobj_anim.del_drawobj(self.id_anim)
237
self._drawobj_anim = None
238
239
if is_del_main:
240
# self.del_drawobj(self._id_target)
241
# delete first element from net, which will
242
# call back on_del_netelement where the main drawobj is deleted
243
self.del_elem(self._id_target)
244
245
self._id_target = -1
246
self.id_anim = -1
247
return True
248
249
250
class WxGui(turnflowsgui.TurnflowWxGuiMixin,
251
odgui.OdFlowsWxGuiMixin,
252
virtualpopgui.VirtualpopWxGuiMixin,
253
detectorflowsgui.DetectorflowsWxGuiMixin,
254
pt.PublicTransportWxGuiMixin,
255
ModuleGui):
256
257
"""Contains functions that communicate between the widgets of the main wx gui
258
and the functions of the plugin.
259
"""
260
261
def __init__(self, ident):
262
self._demand = None
263
self._init_common(ident, priority=1000,
264
icondirpath=os.path.join(os.path.dirname(__file__), 'images'))
265
266
def get_module(self):
267
return self._demand
268
269
def get_scenario(self):
270
return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()
271
272
def get_neteditor(self):
273
return self._mainframe.get_modulegui('coremodules.network').get_neteditor()
274
275
def init_widgets(self, mainframe):
276
"""
277
Set mainframe and initialize widgets to various places.
278
"""
279
self._mainframe = mainframe
280
#self._neteditor = mainframe.add_view("Network", Neteditor)
281
282
# mainframe.browse_obj(self._module)
283
self.make_menu()
284
self.make_toolbar()
285
286
def refresh_widgets(self):
287
"""
288
Check through mainframe what the state of the application is
289
and reset widgets. For exampe enable/disable widgets
290
dependent on the availability of data.
291
"""
292
scenario = self.get_scenario()
293
# print 'demand refresh_widgets',scenario.net
294
is_refresh = False
295
if self._demand != scenario.demand:
296
del self._demand
297
self._demand = scenario.demand
298
is_refresh = True
299
# self.get_neteditor().get_toolbox().add_toolclass(AddZoneTool)
300
# print ' odintervals',self._demand.odintervals#,self.odintervals.times_start
301
# print ' ',dir(self._demand.odintervals)
302
303
elif self._demand.is_modified():
304
is_refresh = True
305
306
self.refresh_odflow(is_refresh)
307
self.refresh_turnflow(is_refresh)
308
self.refresh_pt(is_refresh)
309
310
def make_menu(self):
311
# print 'make_menu'
312
menubar = self._mainframe.menubar
313
menubar.append_menu('demand')
314
315
menubar.append_item('demand/browse',
316
self.on_browse_obj, # common function in modulegui
317
info='View and browse demand in object panel.',
318
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
319
)
320
# ----------------------------------------------------------------------
321
menubar.append_menu('demand/vehicles',
322
bitmap=self.get_icon("vehicle_24px.png"),
323
)
324
325
menubar.append_item('demand/vehicles/clear vehicle types',
326
self.on_clear_vtypes,
327
info='Remove all vehicle types .',
328
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
329
)
330
331
menubar.append_item('demand/vehicles/import vehicle types from xml...',
332
self.on_import_vtypes_xml,
333
info='Import vehicle types from xml file',
334
bitmap=self.get_agileicon("Document_Import_24px.png"),
335
)
336
menubar.append_item('demand/vehicles/export vehicle types from xml...',
337
self.on_export_vtypes,
338
bitmap=self.get_agileicon("Document_Export_24px.png"),
339
)
340
menubar.append_item('demand/vehicles/load defaults',
341
self.on_load_vtypes_defaults,
342
info='Load default vehicle types, removing all existing vehicle types.',
343
#bitmap = self.get_icon("route3_24px.png"),
344
)
345
346
# ----------------------------------------------------------------------
347
self.add_menu_odflows(menubar)
348
# ----------------------------------------------------------------------
349
self.add_menu_turnflow(menubar)
350
# ----------------------------------------------------------------------
351
self.add_menu_detectorflow(menubar)
352
# ----------------------------------------------------------------------
353
self.add_menu_pt(menubar)
354
# ----------------------------------------------------------------------
355
356
menubar.append_menu('demand/trips and routes',
357
bitmap=self.get_icon("trip3_24px.png"),
358
)
359
360
menubar.append_item('demand/trips and routes/quickroute with fastest path',
361
self.on_route,
362
bitmap=self.get_icon("route3_24px.png"),
363
)
364
# menubar.append_item( 'demand/trips and routes/trips to routes with fastest path, del. disconnected',
365
# self.on_route_del_disconnected,
366
# bitmap = self.get_icon("route3_24px.png"),
367
# )
368
369
menubar.append_item('demand/trips and routes/duarouter fastest route',
370
self.on_duaroute,
371
bitmap=self.get_icon("route3_24px.png"),
372
)
373
374
menubar.append_item('demand/trips and routes/duarouter stochastic assignment...',
375
self.on_duaroute_stochastic,
376
bitmap=self.get_icon("route3_24px.png"),
377
)
378
379
# menubar.append_item( 'demand/trips and routes/trips to routes with congested net ...',
380
# self.on_route_congested,
381
# bitmap = self.get_icon("route3_24px.png"),
382
# )
383
384
menubar.append_item('demand/trips and routes/generate taxi trips...',
385
self.on_generate_taxitrips,
386
)
387
388
menubar.append_item('demand/trips and routes/export trips to SUMO xml...',
389
self.on_export_sumotrips,
390
info='Export all trips to SUMO XML format.',
391
bitmap=self.get_agileicon("Document_Export_24px.png"),
392
)
393
394
# menubar.append_item( 'demand/trips and routes/export routes to SUMO xml...',
395
# self.on_export_sumoroutes,
396
# info='Export all trips to SUMO XML format.',
397
# bitmap = self.get_agileicon("Document_Export_24px.png"),
398
# )
399
400
menubar.append_item('demand/trips and routes/import trips from SUMO xml...',
401
self.on_import_trips_xml,
402
bitmap=self.get_agileicon("Document_Import_24px.png"),
403
)
404
405
menubar.append_item('demand/trips and routes/import trips with routes from SUMO xml...',
406
self.on_import_triproutes_xml,
407
bitmap=self.get_agileicon("Document_Import_24px.png"),
408
)
409
410
menubar.append_item('demand/trips and routes/import and overwrite routes to existing trips from SUMO xml...',
411
self.on_import_routes_overwrite_xml,
412
bitmap=self.get_agileicon("Document_Import_24px.png"),
413
)
414
415
menubar.append_item('demand/trips and routes/import and add routes to existing trips from SUMO xml...',
416
self.on_import_routes_alternative_xml,
417
bitmap=self.get_agileicon("Document_Import_24px.png"),
418
)
419
420
menubar.append_item('demand/trips and routes/import trips from scenario...',
421
self.on_import_trips_from_scenario,
422
info='Import trips from another scenario',
423
## bitmap = self.get_agileicon("Document_Import_24px.png"),
424
)
425
426
menubar.append_item('demand/trips and routes/clear all trips and routes',
427
self.on_clear_trips,
428
info='Clear all trips with respective routes.',
429
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
430
)
431
432
menubar.append_item('demand/trips and routes/clear all routes',
433
self.on_clear_routes,
434
info='Clear all routes, trips will remain.',
435
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
436
)
437
438
menubar.append_item('demand/trips and routes/clear alternative routes',
439
self.on_clear_route_alternatves,
440
info='Clear alternative routes, only current route will remain.',
441
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
442
)
443
# ----------------------------------------------------------------------
444
445
self.add_menu_virtualpop(menubar)
446
447
# ----------------------------------------------------------------------
448
menubar.append_item('demand/export all routes to SUMO xml...',
449
self.on_export_all_sumoroutes,
450
info='Export all routes available in the demand database to SUMO XML format.',
451
bitmap=self.get_agileicon("Document_Export_24px.png"),
452
)
453
454
menubar.append_item('demand/update all routes from SUMO xml...',
455
self.on_update_all_sumoroutes,
456
info='Update all routes available in the demand database from SUMO XML format. Note that no new routes are going to be imported.',
457
bitmap=self.get_agileicon("Document_Import_24px.png"),
458
)
459
# (self._menuitem_draw_route, id_item,) = menubar.append_item(
460
## 'plugins/traces/draw selected route in network',
461
# self.on_renew_objectbrowser,
462
## info='Enable visualization of routes in network tab. Double-click on trace in table.',
463
# check=True)
464
# self._menuitem_draw_route.Check(False)
465
##
466
# (self._menuitem_plot_route, id_item,) = menubar.append_item(
467
## 'plugins/traces/add plot selected route',
468
# self.on_renew_objectbrowser,
469
## info='Enable adding of routes to graphics in trace tab. Double-click on trace in table.',
470
# check=True)
471
# self._menuitem_plot_route.Check(False)
472
473
def on_clear_vtypes(self, event=None):
474
self._demand.vtypes.clear_vtypes()
475
self._mainframe.browse_obj(self._demand.vtypes)
476
#if event: event.Skip()
477
478
def on_load_vtypes_defaults(self, event=None):
479
self._demand.vtypes.clear_vtypes()
480
self._demand.vtypes.eprofiles.get_value().add_profiles_default()
481
self._demand.vtypes.add_vtypes_default()
482
self._mainframe.browse_obj(self._demand.vtypes)
483
#if event: event.Skip()
484
485
def on_clear_trips(self, event=None):
486
self._demand.trips.clear_trips()
487
self._mainframe.browse_obj(self._demand.trips)
488
489
def on_clear_routes(self, event=None):
490
self._demand.trips.clear_routes()
491
self._mainframe.browse_obj(self._demand.trips)
492
493
def on_clear_route_alternatves(self, event=None):
494
self._demand.trips.clear_route_alternatves()
495
self._mainframe.browse_obj(self._demand.trips)
496
497
def on_route(self, event=None):
498
"""Generates routes from current trip info. Uses a python implementation of a fastest path router.
499
"""
500
# self._demand.trips.clear_routes()
501
self._demand.trips.route(is_set_current=True)
502
self._mainframe.browse_obj(self._demand.trips)
503
504
# def on_route_del_disconnected(self, event=None):
505
# """Generates routes from current trip info and deletes disconnected trips. Uses a python implementation of a fastest path router.
506
# """
507
# #self._demand.trips.clear_routes()
508
# self._demand.trips.route(is_del_disconnected = True)
509
# self._mainframe.browse_obj(self._demand.trips)
510
511
def on_duaroute(self, event=None):
512
"""Fastest route traffic assignment with duarouter.
513
"""
514
# self._demand.trips.clear_routes()
515
self._demand.trips.duaroute(is_export_net=True, is_export_trips=True)
516
self._mainframe.browse_obj(self._demand.trips)
517
518
def on_generate_taxitrips(self, event=None):
519
"""Stochastic traffic assignment with duarouter.
520
"""
521
522
obj = demand.TaxiGenerator(self._demand,
523
logger=self._mainframe.get_logger())
524
525
dlg = ProcessDialog(self._mainframe, obj)
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
534
if dlg.get_status() == 'success':
535
dlg.apply()
536
dlg.Destroy()
537
538
self._mainframe.browse_obj(self._demand.trips)
539
540
def on_duaroute_stochastic(self, event=None):
541
"""Stochastic traffic assignment with duarouter.
542
"""
543
# self._demand.trips.clear_routes()
544
545
obj = routing.DuaRouter(self.get_scenario().net,
546
trips=self._demand.trips,
547
logger=self._mainframe.get_logger())
548
549
dlg = ProcessDialog(self._mainframe, obj)
550
551
dlg.CenterOnScreen()
552
553
# this does not return until the dialog is closed.
554
val = dlg.ShowModal()
555
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
556
# print ' status =',dlg.get_status()
557
558
if dlg.get_status() == 'success':
559
dlg.apply()
560
dlg.Destroy()
561
562
self._mainframe.browse_obj(self._demand.trips)
563
564
# this should update all widgets for the new scenario!!
565
# print 'call self._mainframe.refresh_moduleguis()'
566
# self._mainframe.refresh_moduleguis()
567
568
def on_import_vtypes_xml(self, event=None):
569
"""Select xml file and import new vehicle types.
570
"""
571
filepath = self._demand.trips.get_routefilepath()
572
# defaultFile = = os.path.dirname(filepath)
573
dirpath = os.path.dirname(filepath)
574
wildcards_all = 'XML files (*.xml)|*.xml|All files (*.*)|*.*'
575
dlg = wx.FileDialog(None, message='Import vtypes from SUMO xml',
576
defaultDir=dirpath,
577
# defaultFile = =# defaultFile = ,
578
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
579
if dlg.ShowModal() == wx.ID_OK:
580
filepath = dlg.GetPath()
581
582
else:
583
return
584
585
self._demand.vtypes.import_xml(filepath)
586
self._mainframe.browse_obj(self._demand.vtypes)
587
588
def on_import_trips_xml(self, event=None):
589
"""Select xml file and import new trips.
590
New trips with associated routes will generated.
591
"""
592
filepath = self._demand.trips.get_routefilepath()
593
# defaultFile = = os.path.dirname(filepath)
594
dirpath = os.path.dirname(filepath)
595
wildcards_all = 'XML trip files (*.trip.xml)|*.trip.xml|All files (*.*)|*.*'
596
dlg = wx.FileDialog(None, message='Import trips and routes from SUMO xml',
597
defaultDir=dirpath,
598
# defaultFile = =# defaultFile = ,
599
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
600
if dlg.ShowModal() == wx.ID_OK:
601
filepath = dlg.GetPath()
602
603
else:
604
return
605
606
self._demand.trips.import_trips_xml(filepath, is_clear_trips=False,
607
is_generate_ids=True)
608
self._mainframe.browse_obj(self._demand.trips)
609
610
def on_import_triproutes_xml(self, event=None):
611
"""Select xml file and import trips and routes.
612
New trips with associated routes will generated.
613
"""
614
filepath = self._demand.trips.get_routefilepath()
615
# defaultFile = = os.path.dirname(filepath)
616
dirpath = os.path.dirname(filepath)
617
wildcards_all = 'XML route files (*.rou.xml)|*.rou.xml|All files (*.*)|*.*'
618
dlg = wx.FileDialog(None, message='Import trips and routes from SUMO xml',
619
defaultDir=dirpath,
620
# defaultFile = =# defaultFile = ,
621
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
622
if dlg.ShowModal() == wx.ID_OK:
623
filepath = dlg.GetPath()
624
625
else:
626
return
627
628
self._demand.trips.import_routes_xml(filepath, is_clear_trips=False,
629
is_generate_ids=True,
630
is_add=False)
631
self._mainframe.browse_obj(self._demand.trips)
632
633
def on_import_routes_overwrite_xml(self, event=None):
634
"""Select xml file and import routes.
635
Overwrite current routes of existing trips.
636
"""
637
filepath = self._demand.trips.get_routefilepath()
638
# defaultFile = = os.path.dirname(filepath)
639
dirpath = os.path.dirname(filepath)
640
wildcards_all = 'XML route files (*.rou.xml)|*.rou.xml|All files (*.*)|*.*'
641
dlg = wx.FileDialog(None, message='Import trips and routes from SUMO xml',
642
defaultDir=dirpath,
643
# defaultFile = =# defaultFile = ,
644
wildcard=wildcards_all, style=wx.OPEN | wx.CHANGE_DIR
645
)
646
647
if dlg.ShowModal() == wx.ID_OK:
648
filepath = dlg.GetPath()
649
650
else:
651
return
652
653
self._demand.trips.import_routes_xml(filepath, is_clear_trips=False,
654
is_overwrite_only=True,
655
is_generate_ids=False,
656
is_add=False)
657
self._mainframe.browse_obj(self._demand.trips)
658
659
def on_import_routes_alternative_xml(self, event=None):
660
"""Select xml file and import routes.
661
Add routes as alternative of existing trips.
662
"""
663
filepath = self._demand.trips.get_routefilepath()
664
# defaultFile = = os.path.dirname(filepath)
665
dirpath = os.path.dirname(filepath)
666
wildcards_all = 'XML route files (*.rou.xml)|*.rou.xml|All files (*.*)|*.*'
667
dlg = wx.FileDialog(None, message='Import trips and routes from SUMO xml',
668
defaultDir=dirpath,
669
# defaultFile = =# defaultFile = ,
670
wildcard=wildcards_all, style=wx.OPEN | wx.CHANGE_DIR
671
)
672
673
if dlg.ShowModal() == wx.ID_OK:
674
filepath = dlg.GetPath()
675
676
else:
677
return
678
679
self._demand.trips.import_routes_xml(filepath, is_clear_trips=False,
680
is_generate_ids=False,
681
is_add=True)
682
self._mainframe.browse_obj(self._demand.trips)
683
684
def on_import_trips_from_scenario(self, event=None):
685
"""Select xml file and import new vehicle types.
686
"""
687
filepath = self.get_scenario().get_rootfilepath()
688
# defaultFile = = os.path.dirname(filepath)
689
dirpath = os.path.dirname(filepath)
690
wildcards_all = "All files (*.*)|*.*"
691
wildcards_obj = "Python binary files (*.obj)|*.obj"
692
wildcards = wildcards_obj+"|"+wildcards_all
693
dlg = wx.FileDialog(
694
self._mainframe, message="Open scenario file",
695
defaultDir=dirpath,
696
# # defaultFile = = filepath+'.obj',
697
wildcard=wildcards,
698
style=wx.OPEN | wx.CHANGE_DIR
699
)
700
if dlg.ShowModal() == wx.ID_OK:
701
filepath = dlg.GetPath()
702
703
else:
704
return
705
scenario2 = load_scenario(filepath, logger=None)
706
self._demand.trips.import_trips_from_scenario(scenario2)
707
self._mainframe.browse_obj(self._demand.trips)
708
709
def on_export_sumotrips(self, event=None):
710
# print 'on_export_sumotrips'
711
filepath = self._demand.trips.get_tripfilepath()
712
# defaultFile = = os.path.dirname(filepath)
713
dirpath = os.path.dirname(filepath)
714
wildcards_all = '*.*|XML trip files (*.trip.xml)|*.trip.xml|All files (*.*)'
715
dlg = wx.FileDialog(None, message='Write trips to SUMO xml',
716
defaultDir=dirpath,
717
# defaultFile = =# defaultFile = ,
718
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
719
if dlg.ShowModal() == wx.ID_OK:
720
filepath = dlg.GetPath()
721
722
else:
723
return
724
725
self._demand.trips.export_trips_xml(filepath)
726
727
def on_export_vtypes(self, event=None):
728
"""
729
Write vtypes to SUMO xml
730
"""
731
# print 'on_export_vtypes'
732
filepath = self._demand.trips.get_tripfilepath()
733
# defaultFile = = os.path.dirname(filepath)
734
dirpath = os.path.dirname(filepath)
735
wildcards_all = '*.*|XML vtype files (*.vtype.xml)|*.vtype.xml|All files (*.*)'
736
dlg = wx.FileDialog(None, message='Write vtypes to SUMO xml',
737
defaultDir=dirpath,
738
# defaultFile = =# defaultFile = ,
739
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
740
if dlg.ShowModal() == wx.ID_OK:
741
filepath = dlg.GetPath()
742
743
else:
744
return
745
746
self._demand.vtypes.export_xml(filepath)
747
748
# def on_export_sumoroutes(self, event = None):
749
# #print 'on_export_sumotrips'
750
# filepath = self._demand.trips.get_routefilepath()
751
# # defaultFile = = os.path.basename(filepath)
752
# dirpath = os.path.dirname(filepath)
753
# wildcards_all = 'XML route files (*rou.xml)|*rou.xml|All files (*.*)|*.*'
754
# dlg = wx.FileDialog(None, message='Write routes to SUMO xml',
755
# defaultDir=dirpath,
756
# # defaultFile = =# defaultFile = ,
757
# wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
758
# if dlg.ShowModal() == wx.ID_OK:
759
# filepath = dlg.GetPath()
760
#
761
# else:
762
# return
763
#
764
# self._demand.trips.export_routes_xml(filepath)
765
766
def on_export_all_sumoroutes(self, event=None):
767
# print 'on_export_sumotrips'
768
filepath = self._demand.get_routefilepath()
769
# defaultFile = = os.path.basename(filepath)
770
dirpath = os.path.dirname(filepath)
771
wildcards_all = 'XML route files (*rou.xml)|*rou.xml|All files (*.*)|*.*'
772
dlg = wx.FileDialog(None, message='Write all routes to SUMO xml',
773
defaultDir=dirpath,
774
# defaultFile = =# defaultFile = ,
775
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
776
if dlg.ShowModal() == wx.ID_OK:
777
filepath = dlg.GetPath()
778
779
else:
780
return
781
782
self._demand.export_routes_xml(filepath)
783
784
def on_update_all_sumoroutes(self, event=None):
785
# print 'on_export_sumotrips'
786
filepath = self._demand.get_routefilepath()
787
# defaultFile = = os.path.basename(filepath)
788
dirpath = os.path.dirname(filepath)
789
wildcards_all = 'XML route files (*rou.xml)|*rou.xml|All files (*.*)|*.*'
790
dlg = wx.FileDialog(None, message='Update all routes from SUMO xml',
791
defaultDir=dirpath,
792
# defaultFile = =# defaultFile = ,
793
wildcard=wildcards_all, style=wx.OPEN | wx.CHANGE_DIR)
794
if dlg.ShowModal() == wx.ID_OK:
795
filepath = dlg.GetPath()
796
797
else:
798
return
799
800
self._demand.import_routes_xml(filepath)
801
802