Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/agilepy/lib_base/test_classman_save.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 test_classman_save.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
#from classman import *
20
21
from test_classman_classes import *
22
from arrayman import *
23
import xmlman as xm
24
# TODOD: create a test object with all tests
25
is_all = 0
26
27
28
if 0 | is_all:
29
class Lines(ArrayObjman):
30
31
def __init__(self, ident, parent=None, xmltag=('lines', 'line', 'ids_sumo'), **kwargs):
32
33
self._init_objman(ident, parent=parent, is_plugin=True, xmltag=xmltag, **kwargs)
34
35
self.add(AttrConf('offset', 0.0,
36
groupnames=['state'],
37
perm='r',
38
is_save=True,
39
unit='m',
40
metatype='length',
41
is_plugin=False,
42
name='offset',
43
info='Test offset position',
44
#xmltag = 'offset',
45
))
46
47
self.add_col(ArrayConf('vertices', np.zeros((2, 3), float),
48
groupnames=['internal'],
49
perm='rw',
50
name='Vertex',
51
is_save=True,
52
is_plugin=True,
53
info='Vertex coordinate vectors of points. with format [[[x11,y11,z11],[x12,y12,z12]],[[x21,y21,z21],[x22,y22,z122]],...]',
54
xmltag='vertices',
55
))
56
57
self.add_col(ArrayConf('polygons', None,
58
dtype='object',
59
groupnames=['landuse'],
60
perm='rw',
61
name='Polygon',
62
info='Polygons [[ (x11,y11,z11), (x12,y12,z13), (x13, y13,z13),...],[...]]',
63
xmltag='shapes',
64
))
65
66
self.add_col(ArrayConf('ids_sumo', None,
67
dtype='object',
68
is_index=True,
69
perm='rw',
70
name='Polygon',
71
info='Polygons [[ (x11,y11,z11), (x12,y12,z13), (x13, y13,z13),...],[...]]',
72
xmltag='id_geom',
73
))
74
75
###########################################################################
76
# Instance creation
77
78
lines = Lines('lines')
79
# vertices = [ [0.0,10.0,10.0,10.0,10.0,0.0],
80
# [10.0,20.0,20.0,20.0,20.0,10.0],
81
# [20.0,30.0,30.0,20.0,30.0,20.0],
82
# ]
83
84
# vertices = [ [(0.0,10.0),(10.0,10.0)],
85
# [(10.0,20.0),(20.0,20.0)],
86
# [(20.0,30.0),(30.0,20.0)],
87
# ]
88
vertices = [
89
[[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]], # 0
90
[[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]], # 1
91
[[0.5, 0.0, 0.1], [1.9, 0.0, 0.0]], # 2
92
]
93
polygons = [
94
np.array([[0.0, 0.0, 0.0], [0.2, 0.0, 0.0], [0.2, 0.0, 0.1], [0.3, 0.3, 0.3]]), # 0
95
np.array([[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]]), # 1
96
np.array([[0.5, 0.0, 0.1], [1.9, 0.0, 0.0], [0.2, 0.2, 0.2]]), # 2
97
]
98
ids_sumo = ['aa10', 'bb22', 'cc333']
99
# lines.add_rows(3)
100
lines.add_rows(3, vertices=vertices, polygons=polygons, ids_sumo=ids_sumo)
101
lines.print_attrs()
102
103
xm.write_obj_to_xml(lines, 'test_lines.xml')
104
105
# save/load
106
save_obj(lines, 'test_lines.obj')
107
del lines
108
print '\nreload'+60*'.'
109
lines = load_obj('test_lines.obj')
110
lines.print_attrs()
111
112
print 'direct access vertex=\n', lines.vertices.value
113
print 'direct access polygons=\n', lines.polygons.value
114
print 'id for index bb22=', lines.ids_sumo.get_id_from_index('bb22')
115
print 'ids for index bb22,cc333=', lines.ids_sumo.get_ids_from_indices(['bb22', 'cc333'])
116
lines.del_row(2)
117
lines.print_attrs()
118
print 'id for index bb22=', lines.ids_sumo.get_id_from_index('cc333')
119
120
if 0 | is_all:
121
class Lines(ArrayObjman):
122
123
def __init__(self, ident, parent=None, **kwargs):
124
125
self._init_objman(ident, parent=parent, **kwargs)
126
127
self.add_col(ArrayConf('vertices', np.zeros((2, 3), float),
128
groupnames=['internal'],
129
perm='rw',
130
name='Vertex',
131
is_save=True,
132
info='Vertex coordinate vectors of points. with format [[[x11,y11,z11],[x12,y12,z12]],[[x21,y21,z21],[x22,y22,z122]],...]',
133
))
134
135
self.add_col(ArrayConf('polygons', None,
136
dtype='object',
137
groupnames=['landuse'],
138
perm='rw',
139
name='Polygon',
140
info='Polygons [[ (x11,y11,z11), (x12,y12,z13), (x13, y13,z13),...],[...]]',
141
))
142
143
###########################################################################
144
# Instance creation
145
146
lines = Lines('lines')
147
# vertices = [ [0.0,10.0,10.0,10.0,10.0,0.0],
148
# [10.0,20.0,20.0,20.0,20.0,10.0],
149
# [20.0,30.0,30.0,20.0,30.0,20.0],
150
# ]
151
152
# vertices = [ [(0.0,10.0),(10.0,10.0)],
153
# [(10.0,20.0),(20.0,20.0)],
154
# [(20.0,30.0),(30.0,20.0)],
155
# ]
156
vertices = [
157
[[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]], # 0
158
[[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]], # 1
159
[[0.5, 0.0, 0.1], [1.9, 0.0, 0.0]], # 2
160
]
161
polygons = [
162
np.array([[0.0, 0.0, 0.0], [0.2, 0.0, 0.0], [0.2, 0.0, 0.1], [0.3, 0.3, 0.3]]), # 0
163
np.array([[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]]), # 1
164
np.array([[0.5, 0.0, 0.1], [1.9, 0.0, 0.0], [0.2, 0.2, 0.2]]), # 2
165
]
166
# lines.add_rows(3)
167
lines.add_rows(3, vertices=vertices, polygons=polygons)
168
lines.print_attrs()
169
print 'direct access vertex=\n', lines.vertices.value
170
print 'direct access polygons=\n', lines.polygons.value
171
172
# save/load
173
save_obj(lines, 'test_lines.obj')
174
del lines
175
print '\nreload'+60*'.'
176
lines = load_obj('test_lines.obj')
177
178
# print
179
lines.print_attrs()
180
print 'direct access vertex=\n', lines.vertices.value
181
print 'direct access polygons=\n', lines.polygons.value
182
183
vertices2 = [
184
[[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]], # 0
185
[[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]], # 1
186
[[0.5, 0.0, 0.1], [1.9, 0.0, 0.0]], # 2
187
]
188
polygons2 = [
189
np.array([[0.0, 0.0, 0.0], [0.2, 0.0, 0.0], [0.2, 0.0, 0.1], [0.3, 0.3, 0.3]]), # 0
190
np.array([[0.3, 0.0, 0.0], [0.9, 0.0, 0.0]]), # 1
191
np.array([[0.5, 0.0, 0.1], [1.9, 0.0, 0.0], [0.2, 0.2, 0.2]]), # 2
192
]
193
lines.add_rows(3, vertices=vertices2, polygons=polygons2)
194
lines.print_attrs()
195
196
if 0 | is_all:
197
class ZonesTab(ArrayObjman):
198
def __init__(self, ident, parent=None, **kwargs):
199
self._init_objman(ident, parent=parent, xmltag=('taz', 'district', 'zonenames'), **kwargs)
200
201
self.add_col(ArrayConf('zonenames', None,
202
dtype='object',
203
is_index=True,
204
perm='rw',
205
name='Zone names',
206
info='Name of zone',
207
xmltag='zone',
208
))
209
210
self.add_col(ColConf('shapes', [],
211
groupnames=['state'],
212
perm='rw',
213
is_save=True,
214
name='Shape',
215
info='Shape of zone which is a list of (x,y) coordinates',
216
xmltag='shape'
217
))
218
219
class OdTripsTab(ArrayObjman):
220
def __init__(self, ident, parent, zones, **kwargs):
221
self._init_objman(ident, parent=parent, xmltag=('odtrips', 'odtrip', None), **kwargs)
222
223
self.add_col(IdsConf('ids_orig', zones, is_child=False,
224
groupnames=['state'],
225
is_save=True,
226
name='ID Orig',
227
info='ID of traffic assignment zone of origin of trip.',
228
xmltag='id_orig',
229
))
230
231
self.add_col(IdsConf('ids_dest', zones, is_child=False,
232
groupnames=['state'],
233
is_save=True,
234
name='ID Dest',
235
info='ID of traffic assignment zone of destination of trip.',
236
xmltag='id_dest',
237
))
238
239
self.add_col(ColConf('tripnumbers', 0,
240
groupnames=['state'],
241
perm='rw',
242
is_save=True,
243
name='Trip number',
244
info='Number of trips from zone with ID Orig to zone with ID Dest.',
245
xmltag='tripnumber',
246
))
247
248
class OdModesTab(ArrayObjman):
249
def __init__(self, ident, parent=None, **kwargs):
250
self._init_objman(ident, parent=parent, xmltag=('odmodes', 'odmode', 'modes'), **kwargs)
251
252
self.add_col(ArrayConf('modes', None,
253
dtype='object',
254
is_index=True,
255
perm='rw',
256
name='Mode',
257
info='Mode of transport',
258
xmltag='mode',
259
))
260
self.add_col(ObjsConf('odtrips',
261
groupnames=['state'],
262
is_save=True,
263
name='OD matrix',
264
info='Matrix with trips from origin to destintion',
265
))
266
267
class OdIntervalsTab(ArrayObjman):
268
def __init__(self, ident, parent=None, **kwargs):
269
self._init_objman(ident, parent=parent, xmltag=('odintervals', 'odinteval', None), **kwargs)
270
271
self.add_col(ColConf('t_start', 0.0,
272
groupnames=['state'],
273
perm='rw',
274
is_save=True,
275
name='Start time',
276
unit='s',
277
info='Start time of interval',
278
xmltag='t_start',
279
))
280
281
self.add_col(ColConf('t_end', 3600.0,
282
groupnames=['state'],
283
perm='rw',
284
is_save=True,
285
name='End time',
286
unit='s',
287
info='End time of interval',
288
xmltag='t_end',
289
))
290
291
self.add_col(ObjsConf('odmodes',
292
groupnames=['state'],
293
is_save=True,
294
name='Modes',
295
info='Transport mode',
296
))
297
298
###########################################################################
299
# Instance creation
300
301
demand = BaseObjman('demand', xmltag='demand')
302
303
zones = ZonesTab('zones', parent=demand)
304
demand.zones = demand.get_attrsman().add(ObjConf(zones))
305
shapes = [[(0.0, 10.0), (10.0, 10.0), (10.0, 0.0)],
306
[(10.0, 20.0), (20.0, 20.0), (20.0, 10.0)],
307
[(20.0, 30.0), (30.0, 20.0), (30.0, 20.0)],
308
]
309
zones.add_rows(3, shapes=shapes, zonenames=['center', 'periphery', 'residential'])
310
311
odintervals = OdIntervalsTab('odintervals', parent=demand, info='OD data for different time intervals')
312
demand.odintervals = demand.get_attrsman().add(ObjConf(odintervals))
313
odintervals.add_rows(2, t_start=[0, 3601], t_end=[3600, 7200])
314
for id_odmodes in odintervals.get_ids():
315
odmodes = OdModesTab((odintervals.odmodes.attrname, id_odmodes), parent=odintervals)
316
odintervals.odmodes[id_odmodes] = odmodes
317
318
odmodes.add_rows(2, modes=['bus', 'train'])
319
for id_odtrips in odmodes.get_ids():
320
odtrips = OdTripsTab((odmodes.odtrips.attrname, id_odtrips), odmodes, zones)
321
odtrips.add_rows(3, ids_orig=[3, 2, 1], ids_dest=[3, 3, 3], tripnumbers=[10, 200, 555])
322
odmodes.odtrips[id_odtrips] = odtrips
323
324
# print
325
demand.get_attrsman().print_attrs()
326
odintervals.print_attrs()
327
for id_odmodes in odintervals.get_ids():
328
print '\nMODE:'
329
odintervals.odmodes[id_odmodes].print_attrs()
330
print '\nTRIPS:'
331
for id_odtrips in odmodes.get_ids():
332
odmodes.odtrips[id_odtrips].print_attrs()
333
334
xm.write_obj_to_xml(demand, 'test_demand.xml')
335
# save/load
336
save_obj(demand, 'test_demand_array.obj')
337
del demand
338
print '\nreload'+60*'.'
339
demand = load_obj('test_demand_array.obj')
340
341
# print
342
demand.get_attrsman().print_attrs()
343
odintervals.print_attrs()
344
for id_odmodes in odintervals.get_ids():
345
print '\nMODE:'
346
odintervals.odmodes[id_odmodes].print_attrs()
347
print '\nTRIPS:'
348
for id_odtrips in odmodes.get_ids():
349
odmodes.odtrips[id_odtrips].print_attrs()
350
351
if 0 | is_all: # OLD BROKEN??!!
352
class ZonesTab(TableObjman):
353
def __init__(self, ident, parent=None, **kwargs):
354
self._init_objman(ident, parent=parent, **kwargs)
355
356
self.add_col(ColConf('shapes', [],
357
groupnames=['state'],
358
perm='rw',
359
is_save=True,
360
name='Shape',
361
info='Shape of zone which is a list of (x,y) coordinates',
362
))
363
364
class OdTripsTab(TableObjman):
365
def __init__(self, ident, parent, zones, **kwargs):
366
self._init_objman(ident, parent=parent, **kwargs)
367
368
self.add_col(IdsConf('ids_orig', zones, is_child=False,
369
groupnames=['state'],
370
is_save=True,
371
name='ID Orig',
372
info='ID of traffic assignment zone of origin of trip.',
373
))
374
375
self.add_col(IdsConf('ids_dest', zones, is_child=False,
376
groupnames=['state'],
377
is_save=True,
378
name='ID Dest',
379
info='ID of traffic assignment zone of destination of trip.',
380
))
381
382
self.add_col(ColConf('tripnumbers', 0,
383
groupnames=['state'],
384
perm='rw',
385
is_save=True,
386
name='Trip number',
387
info='Number of trips from zone with ID Orig to zone with ID Dest.',
388
))
389
390
class OdModesTab(TableObjman):
391
def __init__(self, ident, parent=None, **kwargs):
392
self._init_objman(ident, parent=parent, **kwargs)
393
394
self.add_col(ObjsConf('odtrips',
395
groupnames=['state'],
396
is_save=True,
397
name='OD matrix',
398
info='Matrix with trips from origin to destintion',
399
))
400
401
class OdIntervalsTab(TableObjman):
402
def __init__(self, ident, parent=None, **kwargs):
403
self._init_objman(ident, parent=parent, **kwargs)
404
405
self.add_col(ColConf('t_start', 0.0,
406
groupnames=['state'],
407
perm='rw',
408
is_save=True,
409
name='Start time',
410
unit='s',
411
info='Start time of interval',
412
))
413
414
self.add_col(ColConf('t_end', 3600.0,
415
groupnames=['state'],
416
perm='rw',
417
is_save=True,
418
name='End time',
419
unit='s',
420
info='End time of interval',
421
))
422
423
self.add_col(ObjsConf('odmodes',
424
groupnames=['state'],
425
is_save=True,
426
name='Modes',
427
info='Transport mode',
428
))
429
430
###########################################################################
431
# Instance creation
432
433
demand = BaseObjman('demand')
434
435
zones = ZonesTab('zones', parent=demand)
436
demand.zones = demand.get_attrsman().add(ObjConf(zones))
437
shapes = [[(0.0, 10.0), (10.0, 10.0), (10.0, 0.0)],
438
[(10.0, 20.0), (20.0, 20.0), (20.0, 10.0)],
439
[(20.0, 30.0), (30.0, 20.0), (30.0, 20.0)],
440
]
441
zones.add_rows(3, shapes=shapes)
442
443
odintervals = OdIntervalsTab('odintervals', parent=demand, info='OD data for different time intervals')
444
demand.odintervals = demand.get_attrsman().add(ObjConf(odintervals, is_child=True))
445
odintervals.add_rows(2, t_start=[0, 3600], t_end=[3600, 7200])
446
for id_odmodes in odintervals.get_ids():
447
odmodes = OdModesTab((odintervals.odmodes.attrname, id_odmodes), parent=odintervals)
448
odintervals.odmodes[id_odmodes] = odmodes
449
450
odmodes.add_rows(2)
451
for id_odtrips in odmodes.get_ids():
452
odtrips = OdTripsTab((odmodes.odtrips.attrname, id_odtrips), odmodes, zones)
453
odtrips.add_rows(3, ids_orig=[3, 2, 1], ids_dest=[3, 3, 3], tripnumbers=[10, 200, 555])
454
odmodes.odtrips[id_odtrips] = odtrips
455
456
# print
457
demand.get_attrsman().print_attrs()
458
odintervals.print_attrs()
459
for id_odmodes in odintervals.get_ids():
460
print '\nMODE:'
461
odintervals.odmodes[id_odmodes].print_attrs()
462
print '\nTRIPS:'
463
for id_odtrips in odmodes.get_ids():
464
odmodes.odtrips[id_odtrips].print_attrs()
465
466
# save/load
467
save_obj(demand, 'test_demand.obj')
468
del demand
469
print '\nreload'+60*'.'
470
demand = load_obj('test_demand.obj')
471
472
# print
473
demand.get_attrsman().print_attrs()
474
odintervals.print_attrs()
475
for id_odmodes in odintervals.get_ids():
476
print '\nMODE:'
477
odintervals.odmodes[id_odmodes].print_attrs()
478
print '\nTRIPS:'
479
for id_odtrips in odmodes.get_ids():
480
odmodes.odtrips[id_odtrips].print_attrs()
481
482
if 0 | is_all: # OK
483
net = BaseObjman('net')
484
485
# TODO: could be put in 2 statements
486
edges = TableObjman('edges', parent=net, info='Network edges')
487
nodes = TableObjman('nodes', parent=net, info='Network nodes')
488
489
net.edges = net.get_attrsman().add(ObjConf(edges, is_child=True))
490
net.nodes = net.get_attrsman().add(ObjConf(nodes, is_child=True))
491
492
net.edges.add(AttrConf('status', 'idle',
493
groupnames=['state'],
494
is_save=True,
495
is_plugin=True,
496
name='Status',
497
info='System Status',
498
))
499
500
net.edges.add_col(IdsConf('ids_node_from', net.nodes, is_child=False,
501
groupnames=['state'],
502
is_save=True,
503
#is_plugin = True,
504
name='ID from nodes',
505
info='ID from nodes',
506
))
507
508
net.edges.add_col(IdsConf('ids_node_to', net.nodes, is_child=False,
509
groupnames=['state'],
510
is_save=True,
511
name='ID to nodes',
512
info='ID to nodes',
513
))
514
515
net.nodes.add_col(ColConf('coords', (0.0, 0.0),
516
groupnames=['state'],
517
perm='rw',
518
is_save=True,
519
is_plugin=True,
520
name='Coords',
521
info='Coordinates',
522
))
523
524
net.nodes.add_rows(4,
525
# 1 2 3 4
526
coords=[(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)],
527
)
528
529
net.edges.add_rows(2)
530
net.edges.ids_node_from[[1, 2]] = [1, 4]
531
net.edges.ids_node_to[[1, 2]] = [3, 2]
532
net.get_attrsman().print_attrs()
533
net.edges.print_attrs()
534
net.nodes.print_attrs()
535
save_obj(net, 'test_net.obj')
536
del net
537
print '\nreload'+60*'.'
538
net_new = load_obj('test_net.obj')
539
net_new.get_attrsman().print_attrs()
540
net_new.edges.print_attrs()
541
net_new.nodes.print_attrs()
542
543
544
if 0 | is_all:
545
tab1 = TableObjman('simple_table')
546
547
tab1.add_col(ColConf('surname', 'xx',
548
groupnames=['state'],
549
perm='rw',
550
is_save=True,
551
name='Family name',
552
info='Name of Family',
553
))
554
555
tab1.add_col(ColConf('streetname', 'via della...',
556
groupnames=['state'],
557
perm='rw',
558
is_save=True,
559
name='Street name',
560
info='Name of the street',
561
))
562
tab1.add_rows(4,
563
surname=['walt', 'greg', 'bob', 'duck'],
564
streetname=['a', 'bb', 'ccc', 'dddd'],
565
)
566
567
print 'direct access: tab1.surname.value', tab1.surname.value
568
print 'direct access: tab1.streetname.value', tab1.streetname.value
569
tab1.print_attrs()
570
571
save_obj(tab1, 'test_tab.obj')
572
del tab1
573
print '\nreload'+60*'.'
574
tab1_new = load_obj('test_tab.obj')
575
tab1_new.print_attrs()
576
print 'direct access: tab1_new.surname.value', tab1_new.surname.value
577
print 'direct access: tab1_new.streetname.value', tab1_new.streetname.value
578
if 0 | is_all:
579
tab1 = TableObjman('tab1')
580
print '\ntab1.ident', tab1.ident
581
582
tab2 = TableObjman('tab2', parent=tab1)
583
print '\ntab2.ident', tab2.ident
584
585
# TODO: seperate attrname from linked obj ident because restrictive and makes problems with multiple tab destinations
586
# this should be possible ...following the path of attrnames of absident
587
# -
588
tab1.add_col(IdsConf(tab2))
589
590
tab2.add_col(IdsConf(tab1, is_child=False))
591
592
tab2.add_col(ColConf('surname', 'xx',
593
groupnames=['state'],
594
perm='rw',
595
is_save=True,
596
name='Family name',
597
info='Name of Family',
598
))
599
600
tab2.add_col(ColConf('streetname', 'via della...',
601
groupnames=['state'],
602
perm='rw',
603
is_save=False,
604
name='Street name',
605
info='Name of the street',
606
))
607
tab2.add_rows(4,
608
surname=['walt', 'greg', 'bob', 'duck'],
609
streetname=['a', 'bb', 'ccc', 'dddd'],
610
tab1=[2, 1, 3, 1, ],
611
)
612
613
tab2.print_attrs()
614
615
tab1.add_rows(3,
616
tab2=[3, 1, 2],
617
)
618
619
tab1.print_attrs()
620
621
save_obj(tab1, 'test_tab.obj')
622
del tab1
623
print '\nreload'+60*'.'
624
tab1_new = load_obj('test_tab.obj')
625
626
tab1_new.print_attrs()
627
tab2_new = tab1_new.tab2.get_valueobj()
628
tab2_new.print_attrs()
629
print tab2_new.get_ident_abs()
630
631
632
if False | is_all: # False:#True:
633
obj = TestTabman()
634
635
print 'obj.ident', obj.ident
636
637
obj.attrsman.print_attrs()
638
save_obj(obj, 'test_obj.obj')
639
del obj
640
print '\nreload'+60*'.'
641
obj_new = load_obj('test_obj.obj')
642
obj_new.attrsman.print_attrs()
643
# streetname
644
# print 'This is the value of the attribute: obj.streetname=',obj.streetname
645
# print 'This is the configuration instance of the attribute x',obj.attrsman.x
646
#
647
648
if 0 | is_all: # False:#True: ###!!!!!!!!!!!!!!!!check this : failed to reload!!
649
obj = TestTableObjMan()
650
651
print 'obj.ident', obj.ident
652
653
obj.x.set(1.0/3)
654
# obj.is_pos_ok.set(True)
655
656
obj.print_attrs()
657
save_obj(obj, 'test_obj.obj')
658
del obj
659
print '\nreload'+60*'.'
660
obj_new = load_obj('test_obj.obj')
661
obj_new.x.set(2.0/3)
662
obj_new.print_attrs()
663
664
# streetname
665
# print 'This is the value of the attribute: obj.streetname=',obj.streetname
666
# print 'This is the configuration instance of the attribute x',obj.attrsman.x
667
#
668
669
if 0 | is_all:
670
print 'TestTableObjMan export'
671
obj = TestTableObjMan()
672
obj.get_attrsman().print_attrs()
673
xm.write_obj_to_xml(obj, 'test_obj.xml')
674
del obj
675
print '\nreload'+60*'.'
676
obj_new = load_obj('test_obj.obj')
677
obj_new.get_attrsman().print_attrs()
678
# sys.exit()
679
680
if 0 | is_all:
681
obj2 = TestClass2()
682
683
obj2.child1.get_attrsman().x.set(1.99)
684
685
#obj3 = TestClass3(ident = 'testobj3', parent=obj2, name = 'Test Object3')
686
obj2.get_attrsman().print_attrs()
687
obj2.child1.get_attrsman().print_attrs()
688
obj2.child3.get_attrsman().print_attrs()
689
save_obj(obj2, 'test_obj2.obj')
690
xm.write_obj_to_xml(obj2, 'test_obj2.xml')
691
del obj2
692
print '\nreload'+60*'.'
693
obj2_new = load_obj('test_obj2.obj')
694
obj2_new.get_attrsman().print_attrs()
695
696
obj2_new.child1.get_attrsman().print_attrs()
697
obj2_new.child3.get_attrsman().print_attrs()
698
# sys.exit()
699
700
if 0 | is_all: # False:#True:
701
obj = TestClass()
702
print 'obj.ident', obj.ident
703
704
print 'This is the value of the attribute: obj.x=', obj.x
705
# print 'This is the configuration instance of the attribute x',obj.attrsman.x
706
obj.get_attrsman().print_attrs()
707
# obj.get_attrsman().x.plugin.add_event(EVTSET,on_event_setattr)
708
# obj.get_attrsman().x.add_event(EVTGET,on_event_getattr)
709
# print 'obj.get_attrsman().get_groups()',obj.attrsman.get_groups()
710
# print 'obj.tab.get_groups()',obj.tab.get_groups()
711
712
# print 'Test func...',obj.attrsman.testfunc.get()
713
# obj.get_attrsman().testfunc.add_event(EVTGET,on_event_getattr)
714
# obj.get_attrsman().testfunc.get()
715
print 'obj.get_attrsman().x.get()', obj.get_attrsman().x.get(), 'is_modified', obj.is_modified()
716
obj.get_attrsman().x.set(1.0)
717
print 'obj.get_attrsman().x.get()', obj.get_attrsman().x.get(), 'is_modified', obj.is_modified()
718
719
# obj.attrsman.delete('x')
720
obj.get_attrsman().print_attrs()
721
save_obj(obj, 'test_obj.obj')
722
xm.write_obj_to_xml(obj, 'test_obj.xml')
723
del obj
724
print '\nreload'+60*'.'
725
obj_new = load_obj('test_obj.obj')
726
obj_new.get_attrsman().print_attrs()
727
# print 'obj.get_attrsman().x.get_formatted()=',obj.get_attrsman().x.get_formatted()
728
# print 'obj.x',obj.x
729
730
if 1 | is_all:
731
save_obj(drawing, 'test_drawing.obj')
732
print '\nreload'+60*'.'
733
obj_new = load_obj('test_drawing.obj')
734
obj_new.get_attrsman().print_attrs()
735
736
obj_new.collections.print_attrs()
737
738
tab_check, ids_check = obj_new.collections.tab_id_lists[1][1]
739
print ' check tab, ids=', tab_check, ids_check
740
tab_check.print_attrs()
741
742