Fix #6318. Fix warnings when decorator cannot convert 3D to 2D screen space location.

This commit is contained in:
Dion Moult
2025-03-18 01:06:44 +11:00
parent 0abe6329d6
commit 6cf5cc002e
@@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import os
import gpu
import bpy
import blf
@@ -29,7 +28,7 @@ import ifcopenshell.util.unit
import bonsai.tool as tool
import bonsai.bim.module.drawing.helper as helper
from pathlib import Path
from math import pi, sin, cos, tan, acos, atan, degrees, radians, ceil
from math import pi, sin, cos, acos, atan, degrees, radians
from bpy.types import SpaceView3D
from mathutils import Vector, Matrix
from bpy_extras.view3d_utils import location_3d_to_region_2d
@@ -595,7 +594,8 @@ class BaseDecorator:
region3d = context.region_data
text_dir = self.get_annotation_direction(context, obj)
pos = location_3d_to_region_2d(region, region3d, text_world_position)
if not (pos := location_3d_to_region_2d(region, region3d, text_world_position)):
return
props = tool.Drawing.get_text_props(obj)
text_data = DecoratorData.get_ifc_text_data(obj)
if props.is_editing:
@@ -728,6 +728,8 @@ class DimensionDecorator(BaseDecorator):
v1 = Vector(vertices[i1])
p0 = location_3d_to_region_2d(region, region3d, v0)
p1 = location_3d_to_region_2d(region, region3d, v1)
if not p0 or not p1:
return
text_dir = p1 - p0
if text_dir.length < 1:
continue
@@ -878,6 +880,8 @@ class AngleDecorator(BaseDecorator):
# calculate angle position
p0, p1, p2 = [location_3d_to_region_2d(region, region3d, p) for p in vertices[i0 : i1 + 2]]
if not p0 or not p1 or not p2:
continue
edge0 = p0 - p1
edge1 = p2 - p1
radius = min(edge0.length_squared, edge1.length_squared) ** 0.5
@@ -942,6 +946,8 @@ class RadiusDecorator(BaseDecorator):
spline_points = self.get_spline_points(obj)
p0, p1 = [location_3d_to_region_2d(region, region3d, p) for p in self.get_spline_points(obj)]
if not p0 or not p1:
return
element = tool.Ifc.get_entity(obj)
description = element.Description
dimension_data = DecoratorData.get_dimension_data(obj)
@@ -974,7 +980,8 @@ class FallDecorator(BaseDecorator):
region = context.region
region3d = context.region_data
dir = Vector((1, 0))
pos = location_3d_to_region_2d(region, region3d, self.get_spline_end(obj))
if not (pos := location_3d_to_region_2d(region, region3d, self.get_spline_end(obj))):
return
spline = obj.data.splines[0]
spline_points = spline.bezier_points if spline.bezier_points else spline.points
@@ -1165,7 +1172,6 @@ class PlanLevelDecorator(BaseDecorator):
self.draw_labels(context, obj, self.get_splines(obj))
def draw_labels(self, context, obj, splines):
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
region = context.region
region3d = context.region_data
@@ -1175,6 +1181,8 @@ class PlanLevelDecorator(BaseDecorator):
for verts in splines:
p0, p1 = [location_3d_to_region_2d(region, region3d, v) for v in verts[:2]]
if not p0 or not p1:
continue
text_dir = p1 - p0
if text_dir.length < 1:
continue
@@ -1441,8 +1449,10 @@ class GridDecorator(BaseDecorator):
p1 = location_3d_to_region_2d(region, region3d, v1)
dir = Vector((1, 0))
text = obj.name.split("/")[1].split(".")[0]
self.draw_label(context, text, p0, dir, vcenter=True, gap=0)
self.draw_label(context, text, p1, dir, vcenter=True, gap=0)
if p0:
self.draw_label(context, text, p0, dir, vcenter=True, gap=0)
if p1:
self.draw_label(context, text, p1, dir, vcenter=True, gap=0)
class ElevationDecorator(BaseDecorator):