Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/landuse/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
import shutil
23
import tempfile
24
25
from agilepy.lib_wx.modulegui import ModuleGui
26
from agilepy.lib_wx.ogleditor import *
27
from agilepy.lib_wx.processdialog import ProcessDialog, ProcessDialogInteractive
28
import landuse
29
import maps
30
31
from coremodules.misc import shapeformat
32
33
34
class ParkingDrawings(Lines):
35
def __init__(self, ident, parking, parent, **kwargs):
36
37
Lines.__init__(self, ident, parent,
38
name='Parking drawings',
39
linewidth=3,
40
**kwargs)
41
42
self.delete('vertices')
43
44
self.add(cm.AttrConf('color_default', np.array([0.0, 0.0, 0.7, 1.0], np.float32),
45
groupnames=['options'],
46
perm='wr',
47
metatype='color',
48
name='Default color',
49
info='Default color.',
50
))
51
52
self.set_parking(parking)
53
54
def get_netelement(self):
55
return self._parking
56
57
def get_vertices_array(self):
58
# print 'get_vertices_array'
59
# print ' vertices',self._parking.vertices.value
60
return self._parking.vertices[self.get_ids()] # .value[self._inds_map]
61
62
def set_netelement(self, element):
63
self.set_parking(element)
64
65
def set_parking(self, parking):
66
# print '\nset_parking',len(parking)
67
self._parking = parking
68
if len(self) > 0:
69
self.clear_rows() # self.del_rows(1*self.get_ids())
70
71
ids = self._parking.get_ids()
72
#self._inds_map = self._parking.get_inds(ids)
73
self.add_rows(ids=ids)
74
self.update()
75
76
def update(self, is_update=True):
77
# assumes that arrsy structure did not change
78
# print 'FacilityDrawings.update'
79
n = len(self)
80
self.colors.value[:] = np.ones((n, 4), np.float32)*self.color_default.get_value()
81
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
82
83
if is_update:
84
self._update_vertexvbo()
85
self._update_colorvbo()
86
87
88
class ZoneDrawings(Polygons):
89
def __init__(self, ident, zones, parent, **kwargs):
90
91
Polygons.__init__(self, ident, parent,
92
name='Transport assignment zone drawings',
93
linewidth=4,
94
**kwargs)
95
96
self.delete('vertices')
97
98
self.add(cm.AttrConf('color_zone', np.array([0.3, 0.9, 0.5, 0.8], dtype=np.float32),
99
groupnames=['options'],
100
perm='wr',
101
metatype='color',
102
name='TAZ color',
103
info='Default color of traffic assignment zone.',
104
))
105
106
self.set_netelement(zones)
107
108
def get_netelement(self):
109
return self._zones
110
111
def get_vertices_array(self):
112
# if self._is_not_synched:
113
# self._inds_map = self._zones.get_inds(self._zones.get_ids())
114
# self._is_not_synched = False
115
return self._zones.shapes[self.get_ids()] # .value[self._inds_map]
116
117
def set_netelement(self, zones):
118
# print '\nset_facilities',facilities.get_ids()
119
self._zones = zones
120
if len(self) > 0:
121
self.clear_rows() # self.del_rows(self.get_ids())
122
123
ids = self._zones.get_ids()
124
#self._inds_map = self._zones.get_inds(ids)
125
self.add_rows(ids=ids)
126
127
# plugins to keep grapgics syncronized with netelements
128
zones.unplug()
129
zones.shapes.plugin.add_event(cm.EVTADDITEM, self.on_add_element)
130
zones.plugin.add_event(cm.EVTDELITEM, self.on_del_element)
131
132
self._id_target = -1
133
self.update()
134
135
def update(self, is_update=True):
136
# assumes that arrsy structure did not change
137
self.update_colours(is_update=False)
138
139
if is_update:
140
self.update_internal()
141
142
def update_colours(self, ids=None, is_update=True):
143
if ids is None:
144
ids = self.get_ids()
145
146
inds = self._zones.get_inds(ids)
147
# print 'update_colours',ids, inds, type(inds)
148
# print ' ids_landusetype',self._zones.ids_landusetype.value
149
landusetypes = self._zones.parent.landusetypes
150
for id_landusetype in landusetypes.get_ids():
151
# print ' is=',id_landusetype,self._zones.ids_landusetype.value[inds]==id_landusetype,ids
152
ids_zone = ids[self._zones.ids_landusetype.value[inds] == id_landusetype]
153
self.colors[ids_zone] = np.ones((len(ids_zone), 4), np.float32)*landusetypes.colors[id_landusetype]
154
155
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
156
if is_update:
157
self._update_colorvbo()
158
159
def update_internal(self):
160
# print 'update_internal'
161
# print ' len(self),len(self._zones)',len(self),len(self._zones)
162
#self._is_not_synched = True
163
self._update_vertexvbo()
164
self._update_colorvbo()
165
166
def make_zone(self, shape, zonename='', id_landusetype=-1):
167
# print 'make_zone shape',shape,type(shape)
168
# print ' id_landusetype',id_landusetype
169
return self._zones.make(zonename=zonename, shape=shape,
170
id_landusetype=id_landusetype)
171
172
def on_add_element(self, shapes, ids):
173
print 'on_add_element', shapes.attrname, ids
174
if shapes == self._zones.shapes:
175
self._id_target = ids[0]
176
self.add_row(_id=self._id_target,
177
colors=self.color_zone.value,
178
colors_highl=self._get_colors_highl(self.color_zone.value)
179
)
180
181
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
182
# self._update_vertexvbo()
183
# self._update_colorvbo()
184
185
def begin_animation(self, id_target):
186
# print 'ZoneDrawings.begin_animation zones.shapes=\n',id_target,self._id_target, self._zones.shapes[id_target]
187
if self._id_target == -1:
188
self._id_target = id_target
189
self._drawobj_anim = self.parent.get_drawobj_by_ident(self._ident_drawobj_anim)
190
self.id_anim = self._drawobj_anim.add_drawobj(np.array(self._zones.shapes[self._id_target], np.float32).tolist(),
191
self.color_anim.value,
192
)
193
# print 'begin_animation',self.ident,_id,self._drawobj_anim
194
return True
195
196
def end_animation(self, is_del_last_vert=False):
197
# print 'ZoneDrawings.end_animation',self.ident,self._id_target,self.id_anim
198
199
# print ' verices =',self._drawobj_anim.vertices[self.id_anim]
200
# print ' self._drawobj_anim.vertices[self.id_anim]=',self._drawobj_anim.vertices[self.id_anim]
201
shape = self._drawobj_anim.vertices[self.id_anim]
202
self._zones.shapes[self._id_target] = shape
203
self._zones.coords[self._id_target] = self._zones.get_coords_from_shape(shape)
204
self.update_colours(ids=np.array([self._id_target])) # must pass np array
205
self.del_animation()
206
# print ' self.get_vertices_array()=\n',self.get_vertices_array()
207
# self._drawobj_anim.del_drawobj(self.id_anim)
208
209
self.update_internal()
210
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
211
# self._update_vertexvbo()
212
# self._update_colorvbo()
213
return True
214
215
def del_elem(self, id_zone):
216
"""
217
Deletes an element from network and then in on canvas
218
through callback on_del_element
219
"""
220
# print 'del_elem'
221
# print ' len(self),len(self._zones)',len(self),len(self._zones)
222
223
self._zones.del_element(id_zone)
224
225
def on_del_element(self, obj, ids):
226
"""
227
callback from netelement
228
"""
229
if len(ids) != 1:
230
return False
231
# print 'on_del_element',obj,ids,self._id_target
232
# print ' len(self),len(self._zones)',len(self),len(self._zones)
233
# print ' verices =',self._drawobj_anim.vertices[self.id_anim]
234
self._is_not_synched = True
235
self.del_drawobj(ids[0])
236
# print ' len(self),len(self._zones)',len(self),len(self._zones)
237
# wx.CallAfter(self.update_internal)
238
# self.update_internal()
239
# print ' after CallAfter'
240
# print ' len(self),len(self._zones)',len(self),len(self._zones)
241
return True
242
243
def del_animation(self, is_del_main=False):
244
# print 'end_animation',self.ident,_id,self._drawobj_anim
245
self._drawobj_anim.del_drawobj(self.id_anim)
246
self._drawobj_anim = None
247
248
if is_del_main:
249
# self.del_drawobj(self._id_target)
250
# delete first element from net, which will
251
# call back on_del_netelement where the main drawobj is deleted
252
self.del_elem(self._id_target)
253
254
self._id_target = -1
255
self.id_anim = -1
256
return True
257
258
259
class AddZoneTool(AddPolygonTool):
260
"""
261
Mixin for Selection tools for OGL canvas.
262
"""
263
264
def __init__(self, parent, mainframe=None):
265
self.init_common('add_zone', parent, 'Add zone tool',
266
info='Click on canvas to add a zone. Add a vertex with a single click, double click to finish, right click to aboard.',
267
is_textbutton=False,
268
)
269
self.init_options()
270
271
def init_options(self):
272
self.add(cm.AttrConf('zonename', '',
273
groupnames=['options'],
274
perm='rw',
275
name='Zone name',
276
info='Name of zone. Must be unique. If left blanc, a zone number will be automatically assigned.',
277
))
278
279
self.add(cm.AttrConf('id_landusetype', '',
280
groupnames=['options'],
281
choices={'': -1},
282
perm='rw',
283
name='Type',
284
info='Landusetype of this zone. Use Mixed when unknown or ambiguous.',
285
))
286
287
def activate(self, canvas=None):
288
"""
289
This call by metacanvas??TooldsPallet signals that the tool has been
290
activated and can now interact with metacanvas.
291
"""
292
# print 'activate'
293
AddPolygonTool.activate(self, canvas)
294
295
landusetypes = self.get_landusetypes()
296
typekeychoice = landusetypes.typekeys.get_indexmap().copy()
297
typekeychoice[''] = -1
298
# print ' typekeys',landusetypes.typekeys.value
299
# print ' typekeychoice',typekeychoice
300
self.id_landusetype.choices = typekeychoice
301
self.id_landusetype.set_value(typekeychoice['mixed'])
302
canvas.draw()
303
304
def get_scenario(self):
305
# get net and scenario via netdrawing
306
return self.get_drawing().get_net().parent
307
308
def get_landusetypes(self):
309
return self.get_scenario().landuse.landusetypes
310
311
def get_optionspanel(self, parent, size=(200, -1)):
312
"""
313
Return tool option widgets on given parent
314
"""
315
self._optionspanel = ObjPanel(parent, obj=self,
316
id=None,
317
attrconfigs=None,
318
#tables = None,
319
# table = None, id=None, ids=None,
320
groupnames=['options'],
321
func_change_obj=None,
322
show_groupnames=False, show_title=True, is_modal=False,
323
mainframe=self.parent.get_mainframe(),
324
pos=wx.DefaultPosition, size=size, style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER,
325
func_apply=self.on_apply_option,
326
immediate_apply=False, panelstyle='default', # 'instrumental'
327
standartbuttons=['apply', 'restore'])
328
329
return self._optionspanel
330
331
def set_button_info(self, bsize=(32, 32)):
332
# print 'set_button_info select tool' self.get_icon("icon_sumo_24px.png")
333
iconpath = os.path.join(os.path.dirname(__file__), 'images')
334
self._bitmap = wx.Bitmap(os.path.join(iconpath, 'fig_zone_24px.png'), wx.BITMAP_TYPE_PNG)
335
self._bitmap_sel = self._bitmap
336
337
def begin_animation(self, event):
338
# print 'AddLineTool.begin_animation'
339
#self.drawobj_anim, _id, self.ind_vert = self.get_current_vertexselection()
340
self._optionspanel.apply()
341
self.drawobj_anim = self._canvas.get_drawing().get_drawobj_by_ident('zonedraws')
342
self.coord_last = self._canvas.unproject(event.GetPosition())
343
#vertices = [list(self.coord_last),list(self.coord_last) ]
344
vertices = [1.0*self.coord_last, 1.0*self.coord_last, ] # attention, we need copies here!!
345
# print ' vertices ',vertices#,self.width.get_value(),self.color.get_value(),
346
347
# make drawobj make a zone
348
if self.id_landusetype.get_value() >= 0:
349
_id = self.drawobj_anim.make_zone(vertices,
350
zonename=self.zonename.get_value(),
351
id_landusetype=self.id_landusetype.get_value(),
352
)
353
self.ind_vert = 1
354
self.drawobj_anim.begin_animation(_id)
355
356
# http://www.wxpython.org/docs/api/wx.Cursor-class.html
357
self._canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
358
self.is_animated = True
359
360
self.parent.refresh_optionspanel(self)
361
return True # True for redrawing
362
else:
363
# option values not valid
364
return False
365
366
367
class FacilityDrawings(ZoneDrawings):
368
def __init__(self, ident, facilities, parent, **kwargs):
369
370
Polygons.__init__(self, ident, parent,
371
name='Facility drawings',
372
linewidth=1,
373
**kwargs)
374
375
self.delete('vertices')
376
377
self.add(cm.AttrConf('color_facility_default', np.array([0.921875, 0.78125, 0.4375, 1.0], np.float32),
378
groupnames=['options'],
379
perm='wr',
380
metatype='color',
381
name='Default color',
382
info='Default facility color.',
383
))
384
385
self.set_facilities(facilities)
386
387
# def is_tool_allowed(self, tool, id_drawobj = -1):
388
# """
389
# Returns True if this tool can be applied to this drawobj.
390
# Optionally a particular drawobj can be specified with id_drawobj.
391
# """
392
# # basic tools:
393
# #return tool.ident not in ['configure','select_handles','delete','move','stretch']
394
# return tool.ident not in ['delete',]
395
396
def get_netelement(self):
397
return self._facilities
398
399
def get_vertices_array(self):
400
return self._facilities.shapes[self.get_ids()] # .value[self._inds_map]
401
402
def get_vertices(self, ids):
403
return self._facilities.shapes[ids]
404
405
def set_vertices(self, ids, vertices, is_update=True):
406
self._facilities.set_shapes(ids, vertices)
407
if is_update:
408
self._update_vertexvbo()
409
410
def set_netelement(self, element):
411
self.set_facilities(element)
412
413
def set_facilities(self, facilities):
414
# print '\nset_facilities'#,facilities.get_ids()
415
416
self._facilities = facilities
417
# print ' vertices ',self.get_vertices(facilities.get_ids())
418
if len(self) > 0:
419
self.clear_rows() # del_rows(self.get_ids())
420
421
ids = self._facilities.get_ids()
422
#self._inds_map = self._facilities.get_inds(ids)
423
self.add_rows(ids=ids)
424
self._id_target = -1
425
426
# plugins to keep grapgics syncronized with netelements
427
facilities.unplug()
428
facilities.shapes.plugin.add_event(cm.EVTADDITEM, self.on_add_element)
429
facilities.plugin.add_event(cm.EVTDELITEM, self.on_del_element)
430
431
self.update()
432
433
def update(self, is_update=True):
434
# assumes that arrsy structure did not change
435
# print 'FacilityDrawings.update'
436
n = len(self)
437
438
# if n==0:return# causes problems with drawing the first houses
439
440
self.colors.value[:] = np.ones((n, 4), np.float32)*self.color_facility_default.value
441
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
442
443
landusetypes = self._facilities.get_landusetypes()
444
ids_landusetype = self._facilities.ids_landusetype
445
for id_landusetype in landusetypes.get_ids():
446
#inds = np.flatnonzero(ids_landusetype == id_landusetype)
447
#color = landusetypes.colors[id_landusetype]
448
#self.colors.value[self._inds_map[inds]] = color
449
#self.colors.value[self._inds_map[np.flatnonzero(ids_landusetype == id_landusetype)]] = landusetypes.colors[id_landusetype]
450
self.colors[self._facilities.select_ids(
451
ids_landusetype.value == id_landusetype)] = landusetypes.colors[id_landusetype]
452
if is_update:
453
self._update_vertexvbo()
454
self._update_colorvbo()
455
456
def update_colours(self, ids=None, is_update=True):
457
if ids is None:
458
ids = self.get_ids()
459
460
inds = self._facilities.get_inds(ids)
461
# print 'update_colours',ids, inds, type(inds)
462
# print ' self.colors.value',self.colors.value
463
landusetypes = self._facilities.parent.landusetypes
464
# print ' ids_landusetype',self._facilities.ids_landusetype.value[inds]
465
for id_landusetype in landusetypes.get_ids():
466
# print ' is=',id_landusetype,self._zones.ids_landusetype.value[inds]==id_landusetype,ids
467
ids_fac = ids[self._facilities.ids_landusetype.value[inds] == id_landusetype]
468
# print ' ids_fac',ids_fac
469
470
self.colors[ids_fac] = np.ones((len(ids_fac), 4), np.float32)*landusetypes.colors[id_landusetype]
471
472
self.colors_highl.value[:] = self._get_colors_highl(self.colors.value)
473
if is_update:
474
self._update_colorvbo()
475
476
def make(self, shape, id_sumo=None, osmkey='', id_landusetype=-1):
477
# print 'make_zone shape',shape,type(shape)
478
# print ' id_landusetype',id_landusetype
479
if id_sumo == '':
480
id_sumo = None
481
return self._facilities.make(id_sumo=id_sumo,
482
osmkey=osmkey, shape=shape,
483
id_landusetype=id_landusetype)
484
485
def on_add_element(self, shapes, ids):
486
# print 'on_add_element',shapes.attrname,ids
487
if shapes == self._facilities.shapes:
488
self._id_target = ids[0]
489
id_target = self.add_row(_id=self._id_target,
490
colors=self.color_facility_default.get_value(),
491
colors_highl=self._get_colors_highl(self.color_facility_default.get_value())
492
)
493
# print ' self.colors.value',self.colors.value, id_target,self._id_target
494
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
495
# self._update_vertexvbo()
496
# self._update_colorvbo()
497
498
def begin_animation(self, id_target):
499
# print 'ZoneDrawings.begin_animation zones.shapes=\n',id_target,self._id_target, self._zones.shapes[id_target]
500
if self._id_target == -1:
501
self._id_target = id_target
502
self._drawobj_anim = self.parent.get_drawobj_by_ident(self._ident_drawobj_anim)
503
self.id_anim = self._drawobj_anim.add_drawobj(np.array(self._facilities.shapes[self._id_target], np.float32).tolist(),
504
self.color_anim.value,
505
)
506
# print 'begin_animation',self.ident,_id,self._drawobj_anim
507
return True
508
509
def end_animation(self, is_del_last_vert=False):
510
# print 'ZoneDrawings.end_animation',self.ident,self._id_target,self.id_anim
511
512
# print ' verices =',self._drawobj_anim.vertices[self.id_anim]
513
# print ' self._drawobj_anim.vertices[self.id_anim]=',self._drawobj_anim.vertices[self.id_anim]
514
shape = self._drawobj_anim.vertices[self.id_anim]
515
self._facilities.set_shape(self._id_target, shape)
516
#self._facilities.coords[self._id_target] = self._zones.get_coords_from_shape(shape)
517
self.update_colours(ids=np.array([self._id_target])) # must pass np array
518
self.del_animation()
519
# print ' self.get_vertices_array()=\n',self.get_vertices_array()
520
# self._drawobj_anim.del_drawobj(self.id_anim)
521
522
# self.update_internal()
523
#self._inds_map = self._zones.get_inds(self._zones.get_ids())
524
self._update_vertexvbo()
525
self._update_colorvbo()
526
return True
527
528
def del_elem(self, id_fac):
529
"""
530
Deletes an element from network and then in on canvas
531
through callback on_del_element
532
"""
533
# print 'del_elem'
534
535
self._facilities.del_element(id_fac)
536
537
538
class AddFacilityTool(AddZoneTool):
539
"""
540
Mixin for Selection tools for OGL canvas.
541
"""
542
543
def __init__(self, parent, mainframe=None):
544
self.init_common('add_facility', parent, 'Add buildings tool',
545
info='Click on canvas to add a building or facility. Add a vertex with a single click, double click to finish, right click to aboard.',
546
is_textbutton=False,
547
)
548
self.init_options()
549
550
def init_options(self):
551
552
self.add(cm.AttrConf('id_sumo', '',
553
groupnames=['options'],
554
perm='rw',
555
name='Unique name',
556
info='Unique name. When left blanc, a number will be assigned automatically.',
557
))
558
559
self.add(cm.AttrConf('id_landusetype', '',
560
groupnames=['options'],
561
choices={'': -1},
562
perm='rw',
563
name='Type',
564
info='Landusetype of this facility. Use Mixed when unknown or ambiguous.',
565
))
566
567
self.add(cm.AttrConf('osmkey', '',
568
groupnames=['options'],
569
perm='rw',
570
name='OSM key',
571
info='OSM key of facility.',
572
))
573
574
def set_button_info(self, bsize=(32, 32)):
575
# print 'set_button_info select tool' self.get_icon("icon_sumo_24px.png")
576
iconpath = os.path.join(os.path.dirname(__file__), 'images')
577
self._bitmap = wx.Bitmap(os.path.join(iconpath, 'city-icon_24px.png'), wx.BITMAP_TYPE_PNG)
578
self._bitmap_sel = self._bitmap
579
580
def begin_animation(self, event):
581
# print 'AddLineTool.begin_animation'
582
#self.drawobj_anim, _id, self.ind_vert = self.get_current_vertexselection()
583
self._optionspanel.apply()
584
self.drawobj_anim = self._canvas.get_drawing().get_drawobj_by_ident('facilitydraws')
585
self.coord_last = self._canvas.unproject(event.GetPosition())
586
#vertices = [list(self.coord_last),list(self.coord_last) ]
587
vertices = [1.0*self.coord_last, 1.0*self.coord_last, ] # attention, we need copies here!!
588
# print ' vertices ',vertices#,self.width.get_value(),self.color.get_value(),
589
590
# make drawobj make a zone
591
if self.id_landusetype.get_value() >= 0:
592
_id = self.drawobj_anim.make(vertices, id_sumo=self.id_sumo.get_value(),
593
osmkey=self.osmkey.get_value(),
594
id_landusetype=self.id_landusetype.get_value(),
595
)
596
self.ind_vert = 1
597
self.drawobj_anim.begin_animation(_id)
598
self.id_sumo.set_value('')
599
600
# http://www.wxpython.org/docs/api/wx.Cursor-class.html
601
self._canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
602
self.is_animated = True
603
604
self.parent.refresh_optionspanel(self)
605
return True # True for redrawing
606
else:
607
# option values not valid
608
return False
609
610
611
class WxGui(ModuleGui):
612
"""Contains functions that communicate between the widgets of the main wx gui
613
and the functions of the plugin.
614
"""
615
616
def __init__(self, ident):
617
self._landuse = None
618
self._canvas = None
619
self._init_common(ident, priority=100,
620
icondirpath=os.path.join(os.path.dirname(__file__), 'images'))
621
622
def get_module(self):
623
return self._landuse
624
625
def get_scenario(self):
626
return self._mainframe.get_modulegui('coremodules.scenario').get_scenario()
627
628
def get_neteditor(self):
629
return self._mainframe.get_modulegui('coremodules.network').get_neteditor()
630
631
def get_canvas(self):
632
return self.get_neteditor().get_canvas()
633
634
def get_drawing(self):
635
return self.get_canvas().get_drawing()
636
637
def init_widgets(self, mainframe):
638
"""
639
Set mainframe and initialize widgets to various places.
640
"""
641
self._mainframe = mainframe
642
#self._neteditor = mainframe.add_view("Network", Neteditor)
643
644
# mainframe.browse_obj(self._module)
645
self.make_menu()
646
self.make_toolbar()
647
648
def refresh_widgets(self):
649
"""
650
Check through mainframe what the state of the application is
651
and reset widgets. For exampe enable/disable widgets
652
dependent on the availability of data.
653
"""
654
scenario = self.get_scenario()
655
# print 'landuse refresh_widgets',id(self._landuse),id(scenario.landuse),scenario.is_modified()
656
# if self._landuse:
657
# print ' self._landuse.is_modified',self._landuse.is_modified(),self._landuse == scenario.landuse
658
is_refresh = False
659
if self._landuse != scenario.landuse:
660
# print ' make new landuse instance'
661
del self._landuse
662
self._landuse = scenario.landuse
663
is_refresh = True
664
665
elif self._landuse.is_modified():
666
# print ' self._landuse.is_modified',self._landuse.is_modified()
667
is_refresh = True
668
669
elif self.get_canvas() != self._canvas:
670
is_refresh = True
671
672
# print ' is_refresh',is_refresh
673
if is_refresh | self._is_needs_refresh:
674
self._is_needs_refresh = False
675
# print ' is_refresh',is_refresh,id(self._landuse)
676
neteditor = self.get_neteditor()
677
#canvas = self.get_canvas()
678
drawing = self.get_drawing() # canvas.get_drawing()
679
680
# add or refresh facility drawing
681
drawing.set_element('facilitydraws', FacilityDrawings,
682
self._landuse.facilities, layer=5)
683
#drawobj = drawing.get_drawobj_by_ident('facilitydraws')
684
# if drawobj is not None:
685
# drawobj.set_facilities(self._landuse.facilities)
686
# else:
687
# facilitydrawings = FacilityDrawings(self._landuse.facilities, drawing)
688
# drawing.add_drawobj(facilitydrawings, layer = 5)
689
690
# add or refresh zone drawing
691
drawing.set_element('zonedraws', ZoneDrawings,
692
self._landuse.zones, layer=100)
693
#drawobj = drawing.get_drawobj_by_ident('zonedraws')
694
# if drawobj is not None:
695
# drawobj.set_netelement(self._landuse.zones)
696
# else:
697
# zonedrawings = ZoneDrawings(self._landuse.zones, drawing)
698
# drawing.add_drawobj(zonedrawings, layer = 100)
699
700
# add or refresh parking drawing
701
drawing.set_element('parkingdraws', ParkingDrawings,
702
self._landuse.parking, layer=50)
703
704
#drawobj = drawing.get_drawobj_by_ident('parkingdraws')
705
# if drawobj is not None:
706
# drawobj.set_parking(self._landuse.parking)
707
# else:
708
# parkingdrawings = ParkingDrawings(self._landuse.parking, drawing)
709
# drawing.add_drawobj(parkingdrawings, layer = 50)
710
711
neteditor.get_toolbox().add_toolclass(AddZoneTool) # will check if tool is already there
712
neteditor.get_toolbox().add_toolclass(AddFacilityTool)
713
neteditor.draw()
714
715
self._canvas = self.get_canvas()
716
717
def make_menu(self):
718
# print 'make_menu'
719
menubar = self._mainframe.menubar
720
menubar.append_menu('landuse')
721
722
menubar.append_item('landuse/browse',
723
self.on_browse_obj, # common function in modulegui
724
info='View and browse landuse in object panel.',
725
bitmap=self.get_agileicon('icon_browse_24px.png'), # ,
726
)
727
728
# wx.Bitmap(os.path.join(IMAGEDIR,'icon_sumo_24px.png'),wx.BITMAP_TYPE_PNG)
729
menubar.append_menu('landuse/maps',
730
bitmap=self.get_icon("map_24px.png"),
731
)
732
733
menubar.append_item('landuse/maps/download...',
734
self.on_import_backgroundmaps,
735
info='Download backgroundmaps from the Intenet. Requires active Internet connection, and python packages pyproj and PIL.',
736
bitmap=self.get_icon('map_add_24px.png'),
737
)
738
739
menubar.append_item('landuse/maps/clear',
740
self.on_clear_backgroundmaps,
741
info='Clear all background maps.',
742
bitmap=self.get_icon('map_del_24px.png'),
743
)
744
745
menubar.append_item('landuse/maps/import elevations from csv',
746
self.on_import_elevations_from_csv,
747
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU),
748
)
749
750
menubar.append_menu('landuse/zones',
751
bitmap=self.get_icon("fig_zone_24px.png"),
752
)
753
754
menubar.append_item('landuse/zones/import from shapefile...',
755
self.on_import_zones_from_shape,
756
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
757
)
758
menubar.append_item('landuse/zones/identify zone edges',
759
self.on_refresh_zoneedges,
760
info='Identify network edges that are located within each zone.',
761
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
762
)
763
menubar.append_item('landuse/zones/identify zone areas',
764
self.on_refresh_zoneareas,
765
info='Identify area of each zone in square kilometers.',
766
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
767
)
768
menubar.append_item('landuse/zones/export zone.kml',
769
self.on_export_zone_kml,
770
info='Export zones in .kml format.',
771
bitmap=self.get_agileicon("Document_Export_24px.png"),
772
)
773
menubar.append_item('landuse/zones/export to shape file...',
774
self.on_zones_to_shapefile,
775
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU)
776
bitmap=self.get_agileicon("Document_Export_24px.png"),
777
)
778
menubar.append_item('landuse/zones/clear all',
779
self.on_clear_zones,
780
info='Delete all zones.',
781
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
782
)
783
784
menubar.append_menu('landuse/facilities',
785
bitmap=self.get_icon("city-icon_24px.png"),
786
)
787
788
menubar.append_item('landuse/facilities/import from poly file...',
789
self.on_import_poly, info='Import SUMO poly xml file...',
790
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU)
791
bitmap=self.get_agileicon("Document_Import_24px.png"),
792
)
793
794
menubar.append_item('landuse/facilities/export to poly file...',
795
self.on_export_poly, info='Export facilities to SUMO poly xml file...',
796
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU)
797
bitmap=self.get_agileicon("Document_Export_24px.png"),
798
)
799
menubar.append_item('landuse/facilities/export to shape file...',
800
self.on_facilities_to_shapefile,
801
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU)
802
bitmap=self.get_agileicon("Document_Export_24px.png"),
803
)
804
menubar.append_item('landuse/facilities/export kml file...',
805
self.on_facilities_to_kml,
806
#bitmap = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,wx.ART_MENU)
807
bitmap=self.get_agileicon("Document_Export_24px.png"),
808
)
809
menubar.append_item('landuse/facilities/clean osm file...',
810
self.on_clean_osm,
811
info='Cleans OSM file from strange characters. Use if you have trouble importing from OSM.',
812
bitmap=self.get_icon('Files-Osm-icon_24.png'),
813
)
814
815
menubar.append_item('landuse/facilities/import from osm...',
816
self.on_import_osm,
817
info='Import landuse from osm files.',
818
bitmap=self.get_icon('Files-Osm-icon_24.png'),
819
)
820
821
menubar.append_item('landuse/facilities/generate facilities...',
822
self.on_generate_facilities,
823
)
824
825
menubar.append_item('landuse/facilities/identify zone',
826
self.on_identify_taz,
827
info='Identify the traffic assignment zone for each facility.',
828
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
829
)
830
831
menubar.append_item('landuse/facilities/find closest edge',
832
self.on_identify_closest_edge,
833
info='Find for each building the closes access to the network. This will be the point on the network where people access the facility.',
834
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
835
)
836
menubar.append_item('landuse/facilities/update all facilities',
837
self.on_update_facilities,
838
)
839
menubar.append_item('landuse/facilities/clear all facilities',
840
self.on_clear_facilities,
841
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
842
)
843
844
menubar.append_menu('landuse/parking',
845
#bitmap = self.get_icon("Document_Import_24px.png"),
846
)
847
menubar.append_item('landuse/parking/generate parking...',
848
self.on_make_parking,
849
#bitmap = self.get_icon('Files-Osm-icon_24.png'),#
850
)
851
menubar.append_item('landuse/parking/clear parking',
852
self.on_clear_parking,
853
info='Delete all parking.',
854
bitmap=wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU),
855
)
856
857
def on_import_elevations_from_csv(self, event=None):
858
"""
859
Import elevation from a csv file.
860
"""
861
p = landuse.maps.CsvElevationsImport(self.get_scenario().net, logger=self._mainframe.get_logger())
862
dlg = ProcessDialog(self._mainframe, p, immediate_apply=True)
863
864
dlg.CenterOnScreen()
865
866
# this does not return until the dialog is closed.
867
val = dlg.ShowModal()
868
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
869
# print ' status =',dlg.get_status()
870
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
871
# print ">>>>>>>>>Unsuccessful\n"
872
dlg.Destroy()
873
874
if dlg.get_status() == 'success':
875
# print ">>>>>>>>>successful\n"
876
# apply current widget values to scenario instance
877
dlg.apply()
878
dlg.Destroy()
879
# self._mainframe.browse_obj(self.get_scenario().net.edges)
880
self._mainframe.refresh_moduleguis()
881
#self._is_needs_refresh = True
882
# self.refresh_widgets()
883
884
def on_import_zones_from_shape(self, event=None):
885
"""
886
Import zones from shape file format.
887
"""
888
889
proc = landuse.ZonesFromShapeImporter('shapeimporter', self._landuse.zones, logger=self._mainframe.get_logger())
890
dlg = ProcessDialog(self._mainframe, proc, immediate_apply=True)
891
892
dlg.CenterOnScreen()
893
894
# this does not return until the dialog is closed.
895
val = dlg.ShowModal()
896
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
897
# print ' status =',dlg.get_status()
898
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
899
# print ">>>>>>>>>Unsuccessful\n"
900
dlg.Destroy()
901
902
if dlg.get_status() == 'success':
903
# print ">>>>>>>>>successful\n"
904
# apply current widget values to scenario instance
905
dlg.apply()
906
dlg.Destroy()
907
# self._landuse.zones.refresh_zoneedges()
908
self._mainframe.browse_obj(self._landuse.zones)
909
self._is_needs_refresh = True
910
self._mainframe.refresh_moduleguis()
911
912
def on_refresh_zoneedges(self, event=None):
913
self._landuse.zones.refresh_zoneedges()
914
self._mainframe.browse_obj(self._landuse.zones)
915
916
def on_refresh_zoneareas(self, event=None):
917
self._landuse.zones.refresh_zonearea()
918
self._mainframe.browse_obj(self._landuse.zones)
919
920
def on_identify_taz(self, event=None):
921
self._landuse.facilities.identify_taz()
922
self._mainframe.browse_obj(self._landuse.facilities)
923
924
def on_identify_closest_edge(self, event=None):
925
self._landuse.facilities.identify_closest_edge()
926
self._mainframe.browse_obj(self._landuse.facilities)
927
928
def on_make_parking(self, event=None):
929
"""
930
Generate on road parking areas on the street network
931
"""
932
# self._landuse.parking.make_parking()
933
#self._canvas = canvas.draw()
934
#drawing = self.get_drawing().get_drawobj_by_ident('parkingdraws')
935
936
# TODO: make a proper import mask that allows to set parameters
937
# self._landuse.maps.download()
938
proc = landuse.ParkingGenerator('parkinggenerator', self._landuse.parking, logger=self._mainframe.get_logger())
939
dlg = ProcessDialog(self._mainframe, proc, immediate_apply=True)
940
941
dlg.CenterOnScreen()
942
943
# this does not return until the dialog is closed.
944
val = dlg.ShowModal()
945
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
946
# print ' status =',dlg.get_status()
947
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
948
# print ">>>>>>>>>Unsuccessful\n"
949
dlg.Destroy()
950
951
if dlg.get_status() == 'success':
952
# print ">>>>>>>>>successful\n"
953
# apply current widget values to scenario instance
954
dlg.apply()
955
dlg.Destroy()
956
self._mainframe.browse_obj(self._landuse.parking)
957
self._mainframe.refresh_moduleguis()
958
959
def on_clear_parking(self, event=None):
960
self._landuse.parking.clear()
961
#self._canvas = canvas.draw()
962
#drawing = self.get_drawing().get_drawobj_by_ident('parkingdraws')
963
self._mainframe.browse_obj(self._landuse.parking)
964
self._mainframe.refresh_moduleguis()
965
966
def on_clean_osm(self, event=None):
967
968
scenario = self.get_scenario()
969
wildcards_all = "All files (*.*)|*.*"
970
wildcards_xml = "Poly xml files (*.osm.xml)|*.osm.xml|XML files (*.xml)|*.xml"
971
wildcards = wildcards_xml+"|"+wildcards_all
972
973
# Finally, if the directory is changed in the process of getting files, this
974
# dialog is set up to change the current working directory to the path chosen.
975
dlg = wx.FileDialog(
976
self._mainframe, message="Choose one or more osm files to clean",
977
defaultDir=scenario.get_workdirpath(),
978
# defaultFile = os.path.join(scenario.get_workdirpath(), scenario.get_rootfilename()+'osm.xml'),
979
wildcard=wildcards,
980
style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
981
)
982
983
# Show the dialog and retrieve the user response. If it is the OK response,
984
# process the data.
985
if dlg.ShowModal() == wx.ID_OK:
986
# This returns a Python list of files that were selected.
987
paths = dlg.GetPaths()
988
# print 'You selected %d files:' % len(paths)
989
if len(paths) > 0:
990
991
for path in paths:
992
# print ' %s' % path
993
path_temp = path+'.clean'
994
landuse.clean_osm(path, path_temp)
995
#shutil.copy (path_temp, path)
996
shutil.move(path_temp, path)
997
998
self._mainframe.browse_obj(self._landuse)
999
self._mainframe.refresh_moduleguis()
1000
1001
# inform plugins
1002
1003
# Destroy the dialog. Don't do this until you are done with it!
1004
# BAD things can happen otherwise!
1005
dlg.Destroy()
1006
1007
def on_import_poly(self, event=None):
1008
# TODO: here we could make a nice dialog asking if
1009
# existing file should be overwritten.
1010
#self.write_to_statusbar('Import facilities', key='action')
1011
# Create the dialog. In this case the current directory is forced as the starting
1012
# directory for the dialog, and no default file name is forced. This can easilly
1013
# be changed in your program. This is an 'open' dialog, and allows multitple
1014
# file selections as well.
1015
#
1016
scenario = self.get_scenario()
1017
wildcards_all = "All files (*.*)|*.*"
1018
wildcards_xml = "Poly xml files (*.poly.xml)|*.poly.xml|XML files (*.xml)|*.xml"
1019
wildcards = wildcards_xml+"|"+wildcards_all
1020
1021
# Finally, if the directory is changed in the process of getting files, this
1022
# dialog is set up to change the current working directory to the path chosen.
1023
dlg = wx.FileDialog(
1024
self._mainframe, message="Choose one or more poly files",
1025
defaultDir=scenario.get_workdirpath(),
1026
# defaultFile = scenario.get_rootfilepath()+'.poly.xml',
1027
wildcard=wildcards,
1028
style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
1029
)
1030
1031
# Show the dialog and retrieve the user response. If it is the OK response,
1032
# process the data.
1033
if dlg.ShowModal() == wx.ID_OK:
1034
# This returns a Python list of files that were selected.
1035
paths = dlg.GetPaths()
1036
# print 'You selected %d files:' % len(paths)
1037
if len(paths) > 0:
1038
1039
for path in paths:
1040
# print ' %s' % path
1041
#readNet(path, net = net)
1042
dirname = os.path.dirname(path)
1043
filename_raw = os.path.basename(path)
1044
filename = filename_raw.split('.')[0]
1045
self._landuse.import_polyxml(filename, dirname=dirname)
1046
1047
self._mainframe.browse_obj(self._landuse)
1048
self._is_needs_refresh = True
1049
self._mainframe.refresh_moduleguis()
1050
1051
# Destroy the dialog. Don't do this until you are done with it!
1052
# BAD things can happen otherwise!
1053
dlg.Destroy()
1054
1055
def on_zones_to_shapefile(self, event=None):
1056
"""
1057
Export facility data to shape file.
1058
"""
1059
# print 'on_edges_to_shapefile'
1060
1061
dirpath = self._landuse.parent.get_workdirpath()
1062
defaultFile = self._landuse.parent.get_rootfilename()+'.facil.shp'
1063
wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'
1064
dlg = wx.FileDialog(None, message='Export facilities to shapefile',
1065
defaultDir=dirpath,
1066
# defaultFile=defaultFile,
1067
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
1068
if dlg.ShowModal() == wx.ID_OK:
1069
filepath = dlg.GetPath()
1070
1071
else:
1072
return
1073
1074
shapeformat.zones_to_shapefile(self._landuse.zones,
1075
filepath,
1076
log=self._mainframe.get_logger())
1077
1078
def on_export_zone_kml(self, event=None):
1079
self._landuse.zones.export_sumokml()
1080
self._mainframe.browse_obj(self._landuse.zones)
1081
self._is_needs_refresh = True
1082
self._mainframe.refresh_moduleguis()
1083
1084
def on_clear_zones(self, event=None):
1085
self._landuse.zones.clear()
1086
self._mainframe.browse_obj(self._landuse.zones)
1087
self._is_needs_refresh = True
1088
self._mainframe.refresh_moduleguis()
1089
1090
def on_generate_facilities(self, event=None):
1091
"""
1092
Generates mobility plans using different strategies..
1093
"""
1094
self._landuse.facilities.unplug()
1095
self.proc = landuse.FacilityGenerator('facilitygenerator',
1096
self._landuse.facilities,
1097
logger=self._mainframe.get_logger()
1098
)
1099
1100
dlg = ProcessDialogInteractive(self._mainframe,
1101
self.proc,
1102
title=self.proc.get_name(),
1103
func_close=self.close_process_facilities,
1104
)
1105
1106
dlg.CenterOnScreen()
1107
1108
# this does not return until the dialog is closed.
1109
#val = dlg.ShowModal()
1110
dlg.Show()
1111
dlg.MakeModal(True)
1112
1113
def close_process_facilities(self, dlg):
1114
# called before destroying the process dialog
1115
print 'close_process_facilities', self.proc.status
1116
if self.proc.status == 'success':
1117
self._mainframe.browse_obj(self._landuse.facilities)
1118
self._is_needs_refresh = True
1119
1120
self._mainframe.refresh_moduleguis()
1121
1122
def on_clear_facilities(self, event=None):
1123
"""Delete all facilities."""
1124
self._landuse.facilities.clear()
1125
self._mainframe.browse_obj(self._landuse.facilities)
1126
self._is_needs_refresh = True
1127
self._mainframe.refresh_moduleguis()
1128
1129
def on_update_facilities(self, event=None):
1130
"""Update area and capacities of all facilities."""
1131
self._landuse.facilities.update()
1132
self._mainframe.browse_obj(self._landuse.facilities)
1133
#self._is_needs_refresh = True
1134
# self._mainframe.refresh_moduleguis()
1135
1136
def on_export_poly(self, event=None):
1137
scenario = self.get_scenario()
1138
wildcards_all = "All files (*.*)|*.*"
1139
wildcards_xml = "Poly xml files (*.poly.xml)|*.poly.xml|XML files (*.xml)|*.xml"
1140
wildcards = wildcards_xml+"|"+wildcards_all
1141
1142
# Finally, if the directory is changed in the process of getting files, this
1143
# dialog is set up to change the current working directory to the path chosen.
1144
dlg = wx.FileDialog(
1145
self._mainframe, message="Choose one or more poly files",
1146
defaultDir=scenario.get_workdirpath(),
1147
# defaultFile = scenario.get_rootfilepath()+'.poly.xml',
1148
wildcard=wildcards,
1149
style=wx.SAVE | wx.CHANGE_DIR
1150
)
1151
1152
# Show the dialog and retrieve the user response. If it is the OK response,
1153
# process the data.
1154
if dlg.ShowModal() == wx.ID_OK:
1155
# This returns a Python list of files that were selected.
1156
path = dlg.GetPath()
1157
# print 'You selected %d files:' % len(paths)
1158
if path is not "":
1159
self._landuse.export_polyxml(path)
1160
1161
dlg.Destroy()
1162
1163
def on_facilities_to_shapefile(self, event=None):
1164
"""
1165
Export facility data to shape file.
1166
"""
1167
# print 'on_edges_to_shapefile'
1168
1169
dirpath = self._landuse.parent.get_workdirpath()
1170
defaultFile = self._landuse.parent.get_rootfilename()+'.facil.shp'
1171
wildcards_all = 'All files (*.*)|*.*|SHP files (*.shp)|*.shp'
1172
dlg = wx.FileDialog(None, message='Export facilities to shapefile',
1173
defaultDir=dirpath,
1174
# defaultFile=defaultFile,
1175
wildcard=wildcards_all, style=wx.SAVE | wx.CHANGE_DIR)
1176
if dlg.ShowModal() == wx.ID_OK:
1177
filepath = dlg.GetPath()
1178
1179
else:
1180
return
1181
1182
shapeformat.facilities_to_shapefile(self._landuse.facilities,
1183
filepath,
1184
log=self._mainframe.get_logger())
1185
1186
def on_facilities_to_kml(self, event=None):
1187
"""
1188
Export facility data to kml file.
1189
"""
1190
# print 'on_edges_to_kml'
1191
1192
self._landuse.facilities.export_sumokml()
1193
self._mainframe.browse_obj(self._landuse.zones)
1194
self._is_needs_refresh = True
1195
self._mainframe.refresh_moduleguis()
1196
1197
def on_import_osm(self, event=None):
1198
importer = landuse.OsmPolyImporter(self._landuse, logger=self._mainframe.get_logger())
1199
dlg = ProcessDialog(self._mainframe, importer)
1200
1201
dlg.CenterOnScreen()
1202
1203
# this does not return until the dialog is closed.
1204
val = dlg.ShowModal()
1205
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1206
# print ' status =',dlg.get_status()
1207
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1208
dlg.Destroy()
1209
1210
if dlg.get_status() == 'success':
1211
dlg.apply()
1212
dlg.Destroy()
1213
self._mainframe.browse_obj(self._landuse)
1214
self._is_needs_refresh = True
1215
self._mainframe.refresh_moduleguis()
1216
1217
def on_clear_backgroundmaps(self, event=None):
1218
self._landuse.maps.clear_all()
1219
self._mainframe.browse_obj(self._landuse.maps)
1220
1221
def on_import_backgroundmaps(self, event=None):
1222
# TODO: make a proper import mask that allows to set parameters
1223
# self._landuse.maps.download()
1224
importer = maps.MapsImporter(self._landuse.maps, logger=self._mainframe.get_logger())
1225
dlg = ProcessDialog(self._mainframe, importer, immediate_apply=True)
1226
1227
dlg.CenterOnScreen()
1228
1229
# this does not return until the dialog is closed.
1230
val = dlg.ShowModal()
1231
# print ' val,val == wx.ID_OK',val,wx.ID_OK,wx.ID_CANCEL,val == wx.ID_CANCEL
1232
# print ' status =',dlg.get_status()
1233
if dlg.get_status() != 'success': # val == wx.ID_CANCEL:
1234
# print ">>>>>>>>>Unsuccessful\n"
1235
dlg.Destroy()
1236
1237
if dlg.get_status() == 'success':
1238
# print ">>>>>>>>>successful\n"
1239
# apply current widget values to scenario instance
1240
dlg.apply()
1241
dlg.Destroy()
1242
self._mainframe.browse_obj(self._landuse.maps)
1243
1244