bim.generate_space not to fail silently

This commit is contained in:
Andrej730
2024-10-22 15:11:58 +05:00
parent 7bebd2f7ce
commit 7544053f0b
5 changed files with 34 additions and 14 deletions
+20 -6
View File
@@ -17,7 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Optional, Union, assert_never
if TYPE_CHECKING:
import bpy
@@ -152,9 +152,14 @@ def select_decomposed_element(ifc: tool.Ifc, spatial: tool.Spatial, element: ifc
spatial.set_active_object(ifc.get_object(element))
def generate_space(ifc: tool.Ifc, model: tool.Model, root: tool.Root, spatial: tool.Spatial, type: tool.Type) -> None:
def generate_space(
ifc: tool.Ifc, model: tool.Model, root: tool.Root, spatial: tool.Spatial, type: tool.Type
) -> Union[None, str]:
"""
:return: None if successful, error message string if not.
"""
if not root.get_default_container():
raise NoDefaultContainer()
raise SpaceGenerationError("Please set a default container to create the space in.")
active_obj = spatial.get_active_obj()
selected_objects = spatial.get_selected_objects()
@@ -175,8 +180,17 @@ def generate_space(ifc: tool.Ifc, model: tool.Model, root: tool.Root, spatial: t
space_polygon = spatial.get_space_polygon_from_context_visible_objects(x, y)
if not space_polygon:
return
if isinstance(space_polygon, str):
if space_polygon == "NO POLYGONS FOUND":
raise SpaceGenerationError(
"Couldn't find any polygons to form the space shape. Perhaps, RL value need to be adjusted."
)
elif space_polygon == "NO POLYGON FOR POINT":
raise SpaceGenerationError(
f"Couldn't find any polygons containing the position ({x}, {y}). Perhaps, RL value need to be adjusted."
)
else:
assert space_polygon
bm = spatial.get_bmesh_from_polygon(space_polygon, h=h, polygon_is_si=True)
@@ -244,5 +258,5 @@ def set_default_container(spatial: tool.Spatial, container: ifcopenshell.entity_
spatial.set_default_container(container)
class NoDefaultContainer(Exception):
class SpaceGenerationError(Exception):
pass