more consistency in values for plan-, section level and diameter

This commit is contained in:
Andrej730
2023-07-12 11:40:44 +05:00
parent 669dbd2e8d
commit db910d4024
2 changed files with 62 additions and 110 deletions
@@ -470,13 +470,7 @@ class BaseDecorator:
return
text = description
self.draw_label(
context,
text=text,
line_no=line_number_start,
multiline=True,
**draw_label_kwargs
)
self.draw_label(context, text=text, line_no=line_number_start, multiline=True, **draw_label_kwargs)
@lru_cache(maxsize=None)
def format_value(self, context, value):
@@ -671,6 +665,8 @@ class DimensionDecorator(BaseDecorator):
if not show_description_only:
length = (v1 - v0).length
text = self.format_value(context, length)
if isinstance(self, DiameterDecorator):
text = "D" + text
text = text_prefix + text + text_suffix
else:
if not description:
@@ -850,7 +846,7 @@ class RadiusDecorator(BaseDecorator):
spline = obj.data.splines[0]
spline_points = spline.bezier_points if spline.bezier_points else spline.points
if not spline_points:
spline_points = [Vector([0,0,0])] * 2
spline_points = [Vector([0, 0, 0])] * 2
elif len(spline_points) == 1:
spline_points = [spline_points[0]] * 2
@@ -864,7 +860,7 @@ class RadiusDecorator(BaseDecorator):
region = context.region
region3d = context.region_data
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)]
element = tool.Ifc.get_entity(obj)
description = element.Description
@@ -872,16 +868,14 @@ class RadiusDecorator(BaseDecorator):
viewportDrawingScale = self.get_viewport_drawing_scale(context)
text_offset = 20 * viewportDrawingScale
pos = p0 - (p1-p0).normalized() * text_offset
pos = p0 - (p1 - p0).normalized() * text_offset
def get_text():
length = (spline_points[-1] - spline_points[-2]).length
return "R" + self.format_value(context, length)
self.draw_dimension_text(context,
get_text, description, dimension_data,
pos=pos,
text_dir=Vector((1, 0)),
box_alignment="center"
self.draw_dimension_text(
context, get_text, description, dimension_data, pos=pos, text_dir=Vector((1, 0)), box_alignment="center"
)
@@ -1110,18 +1104,21 @@ class PlanLevelDecorator(BaseDecorator):
text_dir *= -1
def get_text():
z = verts[0].z / unit_scale
z = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), z)
z *= unit_scale
text = "RL " + self.format_value(context, z)
z = verts[0].z
rl = self.format_value(context, z)
text = "{}{}".format("" if z < 0 else "+", rl)
return text
self.draw_dimension_text(context, get_text, description, dimension_data,
box_alignment=box_alignment,
self.draw_dimension_text(
context,
get_text,
description,
dimension_data,
box_alignment=box_alignment,
pos=p0,
text_dir=text_dir,
text_dir=text_dir,
gap=8,
center=False
center=False,
)
@@ -1169,8 +1166,6 @@ class SectionLevelDecorator(BaseDecorator):
self.draw_labels(context, obj, self.get_splines(obj), text_position.to_2d(), text_dir.to_2d())
def draw_labels(self, context, obj, splines, text_position, text_dir):
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
element = tool.Ifc.get_entity(obj)
storey = tool.Drawing.get_annotation_element(element)
tag = storey.Name if storey else element.Description
@@ -1178,18 +1173,21 @@ class SectionLevelDecorator(BaseDecorator):
dimension_data = DecoratorData.get_dimension_data(obj)
for verts in splines:
def get_text():
z = verts[0].z / unit_scale
z = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), z)
z *= unit_scale
text = "RL " + self.format_value(context, z)
z = verts[0].z
rl = self.format_value(context, z)
text = "RL {}{}".format("" if z < 0 else "+", rl)
return text
self.draw_dimension_text(context,
get_text, tag, dimension_data,
box_alignment="bottom-left",
self.draw_dimension_text(
context,
get_text,
tag,
dimension_data,
box_alignment="bottom-left",
pos=text_position,
text_dir=text_dir,
text_dir=text_dir,
)
break # support only 1 label
@@ -228,10 +228,7 @@ class SvgWriter:
storey = tool.Drawing.get_annotation_element(element)
tag = storey.Name if storey else element.Description
dimension_data = DecoratorData.get_dimension_data(obj)
prefix = dimension_data["text_prefix"]
suffix = dimension_data["text_suffix"]
show_description_only = dimension_data["show_description_only"]
fill_bg = dimension_data["fill_bg"]
suppress_zero_inches = dimension_data["suppress_zero_inches"]
base_offset_y = 3.5
for spline in obj.data.splines:
@@ -247,42 +244,20 @@ class SvgWriter:
# TODO: allow metric to be configurable
def get_text():
rl_value = (matrix_world @ points[0].co.xyz).z
if bpy.context.scene.unit_settings.system == "IMPERIAL":
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl = rl_value / unit_scale
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
rl *= unit_scale
rl = "{:.3f}m".format(rl)
text = "RL {}{}".format("" if rl_value < 0 else "+", rl)
z = (matrix_world @ points[0].co.xyz).z
rl = helper.format_distance(
z,
precision=self.precision,
decimal_places=self.decimal_places,
suppress_zero_inches=suppress_zero_inches,
)
text = "RL {}{}".format("" if z < 0 else "+", rl)
return text
text_tags = []
line_number_start = 0
if not show_description_only:
text = get_text()
full_prefix = ((tag + "\\n") if tag else "") + prefix
text = full_prefix + text + suffix
line_number_start -= full_prefix.count("\\n")
else:
if not tag:
continue
text = tag
text_tags += self.create_text_tag(
text,
text_position,
angle=angle,
class_str="SECTIONLEVEL",
line_number_start=line_number_start,
fill_bg=fill_bg
self.draw_dimension_text(
get_text, tag, dimension_data, text_position=text_position, angle=angle, class_str="SECTIONLEVEL"
)
for text in text_tags:
self.svg.add(text)
def draw_stair_annotation(self, obj):
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2
@@ -890,10 +865,7 @@ class SvgWriter:
description = element.Description
dimension_data = DecoratorData.get_dimension_data(obj)
prefix = dimension_data["text_prefix"]
suffix = dimension_data["text_suffix"]
show_description_only = dimension_data["show_description_only"]
fill_bg = dimension_data["fill_bg"]
suppress_zero_inches = dimension_data["suppress_zero_inches"]
base_offset_y = 1.0
for spline in obj.data.splines:
@@ -908,43 +880,28 @@ class SvgWriter:
angle = math.degrees(vector.angle_signed(Vector((1, 0))))
# TODO: allow metric to be configurable
rl_value = (matrix_world @ points[0].co).z
if bpy.context.scene.unit_settings.system == "IMPERIAL":
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl = rl_value / unit_scale
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
rl *= unit_scale
rl = "{:.3f}m".format(rl)
def get_text():
z = (matrix_world @ points[0].co.xyz).z
rl = helper.format_distance(
z,
precision=self.precision,
decimal_places=self.decimal_places,
suppress_zero_inches=suppress_zero_inches,
)
text = "{}{}".format("" if z < 0 else "+", rl)
return text
text_tags = []
box_alignment = "bottom-left" if projected_points[0].x <= projected_points[-1].x else "bottom-right"
line_number_start = 0
if not show_description_only:
text = "{}{}".format("" if rl_value < 0 else "+", rl)
full_prefix = ((description + "\\n") if description else "") + prefix
text = full_prefix + text + suffix
line_number_start -= full_prefix.count("\\n")
else:
if not description:
continue
text = description
text_tags += self.create_text_tag(
text,
text_position,
self.draw_dimension_text(
get_text,
description,
dimension_data,
text_position=text_position,
angle=angle,
class_str="PLANLEVEL",
line_number_start=line_number_start,
box_alignment=box_alignment,
fill_bg=fill_bg
)
for text in text_tags:
self.svg.add(text)
def draw_angle_annotations(self, obj):
points = obj.data.splines[0].points
region = bpy.context.region
@@ -1109,9 +1066,10 @@ class SvgWriter:
radius = helper.format_distance(radius, precision=self.precision, decimal_places=self.decimal_places)
text = f"R{radius}"
return text
self.draw_dimension_text(get_text, tag, dimension_data, text_position=text_position, class_str="RADIUS", box_alignment="center")
self.draw_dimension_text(
get_text, tag, dimension_data, text_position=text_position, class_str="RADIUS", box_alignment="center"
)
def draw_dimension_text(self, get_text, tag, dimension_data, **create_text_kwargs):
prefix = dimension_data["text_prefix"]
@@ -1132,16 +1090,12 @@ class SvgWriter:
text = tag
text_tags += self.create_text_tag(
text,
line_number_start=line_number_start,
fill_bg=fill_bg,
**create_text_kwargs
text, line_number_start=line_number_start, fill_bg=fill_bg, **create_text_kwargs
)
for text in text_tags:
self.svg.add(text)
def draw_fall_annotations(self, obj):
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2