mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Use fallback elevation value if default container is missing #6470
I guess it's always theoretically possible that user end up without a default container.
This commit is contained in:
@@ -649,7 +649,7 @@ class PolylineDecorator:
|
||||
|
||||
# Plane Method or Default Container
|
||||
if tool.Ifc.get():
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
default_container_elevation = 0.0
|
||||
projection_point = []
|
||||
|
||||
@@ -529,7 +529,7 @@ def get_generic_product_preview_data(context, relating_type):
|
||||
else:
|
||||
rl = 0
|
||||
snap_prop = context.scene.BIMPolylineProperties.snap_mouse_point[0]
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
mouse_point = Vector((snap_prop.x, snap_prop.y, default_container_elevation))
|
||||
snap_obj = bpy.data.objects.get(snap_prop.snap_object)
|
||||
snap_element = tool.Ifc.get_entity(snap_obj)
|
||||
|
||||
@@ -119,7 +119,7 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
last_point_data = None
|
||||
|
||||
if tool.Ifc.get():
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
default_container_elevation = 0
|
||||
|
||||
@@ -267,7 +267,7 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
last_point = Vector((0, 0, 0))
|
||||
|
||||
if tool.Ifc.get():
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
default_container_elevation = 0
|
||||
|
||||
@@ -505,7 +505,7 @@ class Polyline(bonsai.core.tool.Polyline):
|
||||
|
||||
snap_vertex = bpy.context.scene.BIMPolylineProperties.snap_mouse_point[0]
|
||||
if tool_state and tool_state.use_default_container:
|
||||
z = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
z = tool.Root.get_default_container_elevation()
|
||||
|
||||
# Lock one dimension when in plane method
|
||||
if tool_state.plane_origin:
|
||||
|
||||
@@ -331,7 +331,7 @@ class Raycast(bonsai.core.tool.Raycast):
|
||||
ray_origin, ray_target, ray_direction = cls.get_viewport_ray_data(context, event)
|
||||
|
||||
if tool.Ifc.get():
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
default_container_elevation = 0.0
|
||||
intersection = Vector((0, 0, default_container_elevation))
|
||||
|
||||
@@ -128,6 +128,15 @@ class Root(bonsai.core.tool.Root):
|
||||
props.default_container = 0
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_default_container_elevation(cls) -> float:
|
||||
default_container = cls.get_default_container()
|
||||
if not default_container:
|
||||
return 0.0
|
||||
obj = tool.Ifc.get_object(default_container)
|
||||
assert isinstance(obj, bpy.types.Object)
|
||||
return obj.location.z
|
||||
|
||||
@classmethod
|
||||
def get_connection_relationships(
|
||||
cls, objs: list[bpy.types.Object]
|
||||
|
||||
@@ -162,7 +162,7 @@ class Snap(bonsai.core.tool.Snap):
|
||||
snap_threshold = 1 * cls.get_increment_snap_value(bpy.context)
|
||||
|
||||
if tool.Ifc.get():
|
||||
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
default_container_elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
default_container_elevation = 0.0
|
||||
polyline_data = bpy.context.scene.BIMPolylineProperties.insertion_polyline
|
||||
@@ -396,7 +396,7 @@ class Snap(bonsai.core.tool.Snap):
|
||||
|
||||
# Axis and Plane
|
||||
if tool.Ifc.get():
|
||||
elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
|
||||
elevation = tool.Root.get_default_container_elevation()
|
||||
else:
|
||||
elevation = 0.0
|
||||
|
||||
|
||||
@@ -846,9 +846,8 @@ class Spatial(bonsai.core.tool.Spatial):
|
||||
`mat` - identity matrix
|
||||
"""
|
||||
x, y, z = bpy.context.scene.cursor.location.xyz
|
||||
if container := tool.Root.get_default_container():
|
||||
if container_obj := tool.Ifc.get_object(container):
|
||||
z = container_obj.matrix_world.translation.z
|
||||
if tool.Root.get_default_container():
|
||||
z = tool.Root.get_default_container_elevation()
|
||||
mat = Matrix()
|
||||
h = 3
|
||||
return x, y, z, h, mat
|
||||
|
||||
Reference in New Issue
Block a user