|
21 | 21 | from .descriptors.protocol import DescriptorProtocol |
22 | 22 |
|
23 | 23 |
|
24 | | -class SceneObjectFactory: |
25 | | - """Factory class for creating appropriate SceneObject instances based on input item type. |
| 24 | +def SceneObjectFactory(item=None, scene=None, **kwargs): |
| 25 | + """Create appropriate SceneObject instance based on item type. |
26 | 26 |
|
27 | | - This factory encapsulates the logic for selecting the right SceneObject subclass |
28 | | - for a given data item, making the creation process more explicit and easier to understand. |
| 27 | + Parameters |
| 28 | + ---------- |
| 29 | + item : :class:`compas.data.Data` |
| 30 | + The data item to create a scene object for. |
| 31 | + **kwargs : dict |
| 32 | + Additional keyword arguments to pass to the SceneObject constructor. |
| 33 | +
|
| 34 | + Returns |
| 35 | + ------- |
| 36 | + :class:`compas.scene.SceneObject` |
| 37 | + A SceneObject instance of the appropriate subclass for the given item. |
| 38 | +
|
| 39 | + Raises |
| 40 | + ------ |
| 41 | + ValueError |
| 42 | + If item is None. |
| 43 | + SceneObjectNotRegisteredError |
| 44 | + If no scene object is registered for the item type in the current context. |
29 | 45 | """ |
| 46 | + if item is None: |
| 47 | + raise ValueError("Cannot create a scene object for None. Please ensure you pass an instance of a supported class.") |
30 | 48 |
|
31 | | - @staticmethod |
32 | | - def create(item=None, scene=None, **kwargs): |
33 | | - """Create appropriate SceneObject instance based on item type. |
34 | | -
|
35 | | - Parameters |
36 | | - ---------- |
37 | | - item : :class:`compas.data.Data` |
38 | | - The data item to create a scene object for. |
39 | | - **kwargs : dict |
40 | | - Additional keyword arguments to pass to the SceneObject constructor. |
41 | | -
|
42 | | - Returns |
43 | | - ------- |
44 | | - :class:`compas.scene.SceneObject` |
45 | | - A SceneObject instance of the appropriate subclass for the given item. |
46 | | -
|
47 | | - Raises |
48 | | - ------ |
49 | | - ValueError |
50 | | - If item is None. |
51 | | - SceneObjectNotRegisteredError |
52 | | - If no scene object is registered for the item type in the current context. |
53 | | - """ |
54 | | - if item is None: |
55 | | - raise ValueError("Cannot create a scene object for None. Please ensure you pass an instance of a supported class.") |
56 | | - |
57 | | - if isinstance(item, SceneObject): |
58 | | - item._scene = scene |
59 | | - return item |
| 49 | + if isinstance(item, SceneObject): |
| 50 | + item._scene = scene |
| 51 | + return item |
60 | 52 |
|
61 | | - sceneobject_cls = get_sceneobject_cls(item, **kwargs) |
| 53 | + sceneobject_cls = get_sceneobject_cls(item, **kwargs) |
62 | 54 |
|
63 | | - # Create and return an instance of the appropriate scene object class |
64 | | - return sceneobject_cls(item=item, scene=scene, **kwargs) |
| 55 | + # Create and return an instance of the appropriate scene object class |
| 56 | + return sceneobject_cls(item=item, scene=scene, **kwargs) |
65 | 57 |
|
66 | 58 |
|
67 | 59 | class SceneObject(Data): |
|
0 commit comments