|
9 | 9 | import compas.data # noqa: F401 |
10 | 10 | import compas.datastructures # noqa: F401 |
11 | 11 | import compas.geometry # noqa: F401 |
| 12 | +import compas.scene # noqa: F401 |
12 | 13 | from compas.colors import Color |
13 | 14 | from compas.data import Data |
14 | 15 | from compas.datastructures import TreeNode |
@@ -87,9 +88,23 @@ def __new__(cls, item=None, **kwargs): |
87 | 88 | sceneobject_cls = get_sceneobject_cls(item, **kwargs) |
88 | 89 | return super(SceneObject, cls).__new__(sceneobject_cls) |
89 | 90 |
|
90 | | - def __init__(self, item=None, name=None, color=None, opacity=1.0, show=True, frame=None, transformation=None, context=None, **kwargs): # fmt: skip |
91 | | - # type: (compas.data.Data | None, str | None, compas.colors.Color | None, float, bool, compas.geometry.Frame | None, compas.geometry.Transformation | None, str | None, dict) -> None |
92 | | - name = item.name if isinstance(item, Data) and name is None else name |
| 91 | + def __init__( |
| 92 | + self, |
| 93 | + item=None, # type: compas.data.Data | None |
| 94 | + name=None, # type: str | None |
| 95 | + color=None, # type: compas.colors.Color | None |
| 96 | + opacity=1.0, # type: float |
| 97 | + show=True, # type: bool |
| 98 | + frame=None, # type: compas.geometry.Frame | None |
| 99 | + transformation=None, # type: compas.geometry.Transformation | None |
| 100 | + context=None, # type: str | None |
| 101 | + **kwargs # type: dict |
| 102 | + ): # fmt: skip |
| 103 | + # type: (...) -> None |
| 104 | + if not isinstance(item, Data): |
| 105 | + raise ValueError("The item assigned to this scene object should be a data object: {}".format(type(item))) |
| 106 | + |
| 107 | + name = name or item.name |
93 | 108 | super(SceneObject, self).__init__(name=name, **kwargs) |
94 | 109 | # the scene object needs to store the context |
95 | 110 | # because it has no access to the tree and/or the scene before it is added |
@@ -125,12 +140,12 @@ def __repr__(self): |
125 | 140 |
|
126 | 141 | @property |
127 | 142 | def scene(self): |
128 | | - # type: () -> compas.scene.Scene |
| 143 | + # type: () -> compas.scene.Scene | None |
129 | 144 | return self.tree |
130 | 145 |
|
131 | 146 | @property |
132 | 147 | def item(self): |
133 | | - # type: () -> compas.geometry.Geometry | compas.datastructures.Datastructure |
| 148 | + # type: () -> compas.data.Data |
134 | 149 | return self._item |
135 | 150 |
|
136 | 151 | @property |
@@ -180,7 +195,7 @@ def worldtransformation(self): |
180 | 195 |
|
181 | 196 | @property |
182 | 197 | def contrastcolor(self): |
183 | | - # type: () -> compas.colors.Color |
| 198 | + # type: () -> compas.colors.Color | None |
184 | 199 | if not self._contrastcolor: |
185 | 200 | if self.color: |
186 | 201 | if self.color.is_light: |
|
0 commit comments