DM_get_by_id.py
## @package python.DM_get_by_id
## @brief unkown python script prefix=autobuild.swdvlp64.opals.distro.demo
#
# Each object that is inserted into odm gets a unique 64bit id that can be used for directly accessing the object.
#
# The following example creates an odm that contains two points, a polygon and a polygon. First the ids of the objects
# are collected and then used to access them by the getGeometry function
# (script works in python 2 and 3)
#
from __future__ import print_function # print function syntax as in python 3
from opals.tools.flags import Debug_Mode
if Debug_Mode == False:
from opals import pyDM
else:
from opals import pyDM_d as pyDM
odm = pyDM.Datamanager.create("get_by_id_test.odm", False)
# add two points to odm
pt1 = pyDM.Point(15.00, 85.00, 30.00)
pt2 = pyDM.Point(90.00, 10.00, 55.00)
odm.addPoint(pt1)
odm.addPoint(pt2)
# add polyline to odm
lf = pyDM.PolylineFactory()
lf.addPoint(5.00, 5.00, 10.00)
lf.addPoint(20.00, 60.00, 25.00)
lf.addPoint(95.00, 92.00, 88.00)
line = lf.getPolyline()
odm.addPolyline(line)
# add polygon to odm
pf = pyDM.PolygonFactory()
pf.addPoint(35.00, 35.00, 40.00)
pf.addPoint(45.00, 50.00, 60.00)
pf.addPoint(55.00, 40.00, 75.00)
pf.closePart()
polygon = pf.getPolygon()
odm.addPolygon(polygon)
#save odm
odm.save()
lf = pyDM.AddInfoLayoutFactory()
lf.addColumn(pyDM.ColumnSemantic.Id)
layout = lf.getLayout()
ids = []
print("List objects within odm:")
for obj in odm.geometries(layout):
print("\tType:",obj.type(),"\tId:",obj.info().get(0))
ids.append(obj.info().get(0))
print("\nAccess objects by id:")
for id in ids:
obj = odm.getGeometry(id)
obj.cloneAddInfoView(layout,False)
print("\tType:", obj.type(),"\tId:",id,"(check id:",obj.info().get(0),")")