Skip to content

Commit 82fa199

Browse files
committed
objectstore
1 parent e8b5fab commit 82fa199

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/compas/scene/scene.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ def __data__(self):
4848
"name": self.name,
4949
"attributes": self.attributes,
5050
"datastore": self.datastore,
51-
"objects": self.objects,
51+
"objectstore": self.objectstore,
5252
"tree": self.tree,
5353
}
5454

55-
def __init__(self, context=None, datastore=None, objects=None, tree=None, **kwargs):
55+
def __init__(self, context=None, datastore=None, objectstore=None, tree=None, **kwargs):
5656
# type: (str | None, dict | None, dict | None, Tree | None, **kwargs) -> None
5757
super(Scene, self).__init__(**kwargs)
5858

5959
self.context = context or detect_current_context()
6060
self.datastore = datastore or {}
61-
self.objects = objects or {}
61+
self.objectstore = objectstore or {}
6262
self.tree = tree or Tree()
6363
if self.tree.root is None:
6464
self.tree.add(TreeNode(name=self.name))
@@ -71,16 +71,26 @@ def node_repr(node):
7171
if node.is_root:
7272
return node.name
7373
else:
74-
sceneobject = self.objects[node.name]
74+
sceneobject = self.objectstore[node.name]
7575
return str(sceneobject)
7676

7777
return self.tree.get_hierarchy_string(node_repr=node_repr)
7878

79+
@property
80+
def items(self):
81+
# type: () -> list
82+
return list(self.datastore.values())
83+
84+
@property
85+
def objects(self):
86+
# type: () -> list
87+
return list(self.objectstore.values())
88+
7989
@property
8090
def context_objects(self):
8191
# type: () -> list
8292
guids = []
83-
for obj in self.objects.values():
93+
for obj in self.objects:
8494
guids += obj.guids
8595
return guids
8696

@@ -107,7 +117,7 @@ def add(self, item, parent=None, **kwargs):
107117
sceneobject = SceneObjectFactory.create(item=item, context=self.context, scene=self, **kwargs)
108118

109119
# Add the scene object and item to the data store
110-
self.objects[str(sceneobject.guid)] = sceneobject
120+
self.objectstore[str(sceneobject.guid)] = sceneobject
111121
self.datastore[str(item.guid)] = item
112122

113123
# Add the scene object to the hierarchical tree
@@ -134,11 +144,11 @@ def remove(self, sceneobject):
134144
"""
135145
# type: (SceneObject) -> None
136146
guid = str(sceneobject.guid)
137-
self.objects.pop(guid, None)
147+
self.objectstore.pop(guid, None)
138148
node = self.tree.get_node_by_name(guid)
139149
if node:
140150
for descendant in node.descendants:
141-
self.objects.pop(descendant.name, None)
151+
self.objectstore.pop(descendant.name, None)
142152
self.tree.remove(node)
143153

144154
def clear_context(self, guids=None):
@@ -193,7 +203,7 @@ def clear(self, clear_scene=True, clear_context=True):
193203
"""
194204
guids = []
195205

196-
for sceneobject in list(self.objects.values()):
206+
for sceneobject in self.objects:
197207
guids += sceneobject.guids
198208
sceneobject._guids = None
199209

@@ -266,7 +276,7 @@ def find_by_itemtype(self, itemtype):
266276
:class:`SceneObject` or None
267277
268278
"""
269-
for obj in self.objects.values():
279+
for obj in self.objects:
270280
if isinstance(obj.item, itemtype):
271281
return obj
272282

@@ -285,7 +295,7 @@ def find_all_by_itemtype(self, itemtype):
285295
286296
"""
287297
sceneobjects = []
288-
for obj in self.objects.values():
298+
for obj in self.objects:
289299
if isinstance(obj.item, itemtype):
290300
sceneobjects.append(obj)
291301
return sceneobjects

src/compas/scene/sceneobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ def childnodes(self):
225225
def parent(self):
226226
# type: () -> compas.scene.SceneObject | None
227227
if self.parentnode and not self.parentnode.is_root:
228-
return self.scene.objects[self.parentnode.name]
228+
return self.scene.objectstore[self.parentnode.name]
229229
return None
230230

231231
@property
232232
def children(self):
233233
# type: () -> list[compas.scene.SceneObject]
234-
return [self.scene.objects[child.name] for child in self.childnodes]
234+
return [self.scene.objectstore[child.name] for child in self.childnodes]
235235

236236
@property
237237
def guids(self):

0 commit comments

Comments
 (0)