Skip to content

Commit ef4def8

Browse files
committed
clean up kwargs
1 parent 38a7d63 commit ef4def8

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/compas/scene/context.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def detect_current_context():
119119
return None
120120

121121

122-
def get_sceneobject_cls(item, context=None, sceneobject_type=None):
122+
def get_sceneobject_cls(item, context=None):
123123
"""Get the scene object class for a given item in the current context. If no context is provided, the current context is detected.
124124
If the exact item type is not registered, a closest match in its inheritance hierarchy is used.
125125
@@ -129,8 +129,6 @@ def get_sceneobject_cls(item, context=None, sceneobject_type=None):
129129
The item to get the scene object class for.
130130
context : Literal['Viewer', 'Rhino', 'Grasshopper', 'Blender'], optional
131131
The visualization context in which the pair should be registered.
132-
sceneobject_type : :class:`~compas.scene.SceneObject`, optional
133-
The scene object type to use.
134132
135133
Raises
136134
------
@@ -156,17 +154,15 @@ def get_sceneobject_cls(item, context=None, sceneobject_type=None):
156154
context = detect_current_context()
157155

158156
itemtype = type(item)
159-
cls = None
160157

161-
if sceneobject_type is not None:
162-
cls = sceneobject_type
163-
else:
164-
context = ITEM_SCENEOBJECT[context]
158+
context = ITEM_SCENEOBJECT[context]
159+
160+
cls = None
165161

166-
for inheritancetype in inspect.getmro(itemtype):
167-
cls = context.get(inheritancetype, None)
168-
if cls is not None:
169-
break
162+
for inheritancetype in inspect.getmro(itemtype):
163+
cls = context.get(inheritancetype, None)
164+
if cls is not None:
165+
break
170166

171167
if cls is None:
172168
raise SceneObjectNotRegisteredError("No scene object is registered for this data type: {} in this context: {}".format(itemtype, context))

src/compas/scene/sceneobject.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
from .descriptors.protocol import DescriptorProtocol
2222

2323

24-
def SceneObjectFactory(item=None, scene=None, **kwargs):
24+
def SceneObjectFactory(item=None, scene=None, context=None, **kwargs):
2525
"""Create appropriate SceneObject instance based on item type.
2626
2727
Parameters
2828
----------
2929
item : :class:`compas.data.Data`
3030
The data item to create a scene object for.
31+
scene : :class:`compas.scene.Scene`, optional
32+
The scene in which the scene object is created.
33+
context : str, optional
34+
The context in which the scene object is created.
3135
**kwargs : dict
3236
Additional keyword arguments to pass to the SceneObject constructor.
3337
@@ -50,10 +54,10 @@ def SceneObjectFactory(item=None, scene=None, **kwargs):
5054
item._scene = scene
5155
return item
5256

53-
sceneobject_cls = get_sceneobject_cls(item, **kwargs)
57+
sceneobject_cls = get_sceneobject_cls(item, context=context)
5458

5559
# Create and return an instance of the appropriate scene object class
56-
return sceneobject_cls(item=item, scene=scene, **kwargs)
60+
return sceneobject_cls(item=item, scene=scene, context=context, **kwargs)
5761

5862

5963
class SceneObject(Data):

tests/compas/scene/test_scene.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ def test_get_sceneobject_cls_inheritance():
159159
cls = get_sceneobject_cls(item, context="fake")
160160
assert cls == FakeSceneObject
161161

162-
def test_get_sceneobject_cls_custom_type():
163-
item = FakeItem()
164-
cls = get_sceneobject_cls(item, context="fake", sceneobject_type=FakeSubSceneObject)
165-
assert cls == FakeSubSceneObject
166-
167162
def test_get_sceneobject_cls_no_registration():
168163
# Clear the registration
169164
context.ITEM_SCENEOBJECT.clear()

0 commit comments

Comments
 (0)