mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 13:52:23 +00:00
show error if transition length is more the segments length
This commit is contained in:
@@ -642,10 +642,22 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
end_segment_data["end_point"]: end_segment_data["end_port"],
|
end_segment_data["end_point"]: end_segment_data["end_port"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# transition points
|
||||||
start_point, end_point = tool.Cad.closest_points(
|
start_point, end_point = tool.Cad.closest_points(
|
||||||
(start_segment_data["start_point"], start_segment_data["end_point"]),
|
(start_segment_data["start_point"], start_segment_data["end_point"]),
|
||||||
(end_segment_data["start_point"], end_segment_data["end_point"]),
|
(end_segment_data["start_point"], end_segment_data["end_point"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
first_segment_start, second_segment_end = [
|
||||||
|
p for p in (
|
||||||
|
start_segment_data["start_point"],
|
||||||
|
start_segment_data["end_point"],
|
||||||
|
end_segment_data["start_point"],
|
||||||
|
end_segment_data["end_point"])
|
||||||
|
if p not in (start_point, end_point)
|
||||||
|
]
|
||||||
|
entire_length = (first_segment_start - second_segment_end).length
|
||||||
|
|
||||||
transition_dir = (end_point - start_point).normalized()
|
transition_dir = (end_point - start_point).normalized()
|
||||||
start_port = points_ports_map[start_point]
|
start_port = points_ports_map[start_point]
|
||||||
end_port = points_ports_map[end_point]
|
end_port = points_ports_map[end_point]
|
||||||
@@ -659,9 +671,16 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if not rep:
|
if not rep:
|
||||||
self.report({"ERROR"}, f"Failed to add transition - this kind of profiles is not yet supported.")
|
self.report({"ERROR"}, f"Failed to add transition - this kind of profiles is not yet supported.")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
# TODO: test it
|
||||||
|
full_transition_length = transition_data["full_transition_length"] * si_conversion
|
||||||
|
if full_transition_length >= entire_length:
|
||||||
|
self.report({"ERROR"}, f"Failed to add transition - transition length is larger the segments and the distance between them.")
|
||||||
|
# TODO: handle the case without creating representation in the first place?
|
||||||
|
ifcopenshell.api.run("geometry.remove_representation", ifc_file, representation=rep)
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
middle_point = (start_point + end_point) / 2
|
middle_point = (start_point + end_point) / 2
|
||||||
full_transition_length = transition_data["full_transition_length"] * si_conversion
|
|
||||||
start_segment_extend_point = middle_point - transition_dir * full_transition_length / 2
|
start_segment_extend_point = middle_point - transition_dir * full_transition_length / 2
|
||||||
end_segment_extend_point = middle_point + transition_dir * full_transition_length / 2
|
end_segment_extend_point = middle_point + transition_dir * full_transition_length / 2
|
||||||
DumbProfileJoiner().join_E(start_object, start_segment_extend_point)
|
DumbProfileJoiner().join_E(start_object, start_segment_extend_point)
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ class Cad:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def closest_points(cls, edge1, edge2):
|
def closest_points(cls, edge1, edge2) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
closest end points between `edge1` and `edge2` assuming `edge1` and `edge2` are collinear.
|
closest end points between `edge1` and `edge2` assuming `edge1` and `edge2` are collinear.
|
||||||
@@ -263,15 +263,12 @@ class Cad:
|
|||||||
direction = (edge1[1] - edge1[0]).normalized()
|
direction = (edge1[1] - edge1[0]).normalized()
|
||||||
|
|
||||||
# Project points onto the line to get scalar values along the direction
|
# Project points onto the line to get scalar values along the direction
|
||||||
points1_values = [(p, p.dot(direction)) for p in edge1]
|
points_values = [(p, p.dot(direction)) for p in (edge1 + edge2)]
|
||||||
points2_values = [(p, p.dot(direction)) for p in edge2]
|
sorted_points = sorted(points_values, key=lambda el: el[1])
|
||||||
|
|
||||||
# Sort the projections for both edges
|
edge1_point = next((p for p, v in sorted_points[1:3] if p in edge1), None)
|
||||||
sorted_points1 = sorted(points1_values, key=lambda el: el[1])
|
edge2_point = next((p for p, v in sorted_points[1:3] if p in edge2), None)
|
||||||
sorted_points2 = sorted(points2_values, key=lambda el: el[1])
|
return edge1_point, edge2_point
|
||||||
|
|
||||||
# The closest points will be the last point of the first edge and the first point of the second edge
|
|
||||||
return sorted_points1[-1][0], sorted_points2[0][0]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_intersecting_edges(cls, bm, pt, idx1, idx2):
|
def find_intersecting_edges(cls, bm, pt, idx1, idx2):
|
||||||
|
|||||||
Reference in New Issue
Block a user