mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 06:18:09 +00:00
more consistency in values for plan-, section level and diameter
This commit is contained in:
@@ -470,13 +470,7 @@ class BaseDecorator:
|
|||||||
return
|
return
|
||||||
text = description
|
text = description
|
||||||
|
|
||||||
self.draw_label(
|
self.draw_label(context, text=text, line_no=line_number_start, multiline=True, **draw_label_kwargs)
|
||||||
context,
|
|
||||||
text=text,
|
|
||||||
line_no=line_number_start,
|
|
||||||
multiline=True,
|
|
||||||
**draw_label_kwargs
|
|
||||||
)
|
|
||||||
|
|
||||||
@lru_cache(maxsize=None)
|
@lru_cache(maxsize=None)
|
||||||
def format_value(self, context, value):
|
def format_value(self, context, value):
|
||||||
@@ -671,6 +665,8 @@ class DimensionDecorator(BaseDecorator):
|
|||||||
if not show_description_only:
|
if not show_description_only:
|
||||||
length = (v1 - v0).length
|
length = (v1 - v0).length
|
||||||
text = self.format_value(context, length)
|
text = self.format_value(context, length)
|
||||||
|
if isinstance(self, DiameterDecorator):
|
||||||
|
text = "D" + text
|
||||||
text = text_prefix + text + text_suffix
|
text = text_prefix + text + text_suffix
|
||||||
else:
|
else:
|
||||||
if not description:
|
if not description:
|
||||||
@@ -850,7 +846,7 @@ class RadiusDecorator(BaseDecorator):
|
|||||||
spline = obj.data.splines[0]
|
spline = obj.data.splines[0]
|
||||||
spline_points = spline.bezier_points if spline.bezier_points else spline.points
|
spline_points = spline.bezier_points if spline.bezier_points else spline.points
|
||||||
if not 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:
|
elif len(spline_points) == 1:
|
||||||
spline_points = [spline_points[0]] * 2
|
spline_points = [spline_points[0]] * 2
|
||||||
|
|
||||||
@@ -872,16 +868,14 @@ class RadiusDecorator(BaseDecorator):
|
|||||||
viewportDrawingScale = self.get_viewport_drawing_scale(context)
|
viewportDrawingScale = self.get_viewport_drawing_scale(context)
|
||||||
text_offset = 20 * viewportDrawingScale
|
text_offset = 20 * viewportDrawingScale
|
||||||
|
|
||||||
pos = p0 - (p1-p0).normalized() * text_offset
|
pos = p0 - (p1 - p0).normalized() * text_offset
|
||||||
|
|
||||||
def get_text():
|
def get_text():
|
||||||
length = (spline_points[-1] - spline_points[-2]).length
|
length = (spline_points[-1] - spline_points[-2]).length
|
||||||
return "R" + self.format_value(context, length)
|
return "R" + self.format_value(context, length)
|
||||||
|
|
||||||
self.draw_dimension_text(context,
|
self.draw_dimension_text(
|
||||||
get_text, description, dimension_data,
|
context, get_text, description, dimension_data, pos=pos, text_dir=Vector((1, 0)), box_alignment="center"
|
||||||
pos=pos,
|
|
||||||
text_dir=Vector((1, 0)),
|
|
||||||
box_alignment="center"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1110,18 +1104,21 @@ class PlanLevelDecorator(BaseDecorator):
|
|||||||
text_dir *= -1
|
text_dir *= -1
|
||||||
|
|
||||||
def get_text():
|
def get_text():
|
||||||
z = verts[0].z / unit_scale
|
z = verts[0].z
|
||||||
z = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), z)
|
rl = self.format_value(context, z)
|
||||||
z *= unit_scale
|
text = "{}{}".format("" if z < 0 else "+", rl)
|
||||||
text = "RL " + self.format_value(context, z)
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
self.draw_dimension_text(context, get_text, description, dimension_data,
|
self.draw_dimension_text(
|
||||||
|
context,
|
||||||
|
get_text,
|
||||||
|
description,
|
||||||
|
dimension_data,
|
||||||
box_alignment=box_alignment,
|
box_alignment=box_alignment,
|
||||||
pos=p0,
|
pos=p0,
|
||||||
text_dir=text_dir,
|
text_dir=text_dir,
|
||||||
gap=8,
|
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())
|
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):
|
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)
|
element = tool.Ifc.get_entity(obj)
|
||||||
storey = tool.Drawing.get_annotation_element(element)
|
storey = tool.Drawing.get_annotation_element(element)
|
||||||
tag = storey.Name if storey else element.Description
|
tag = storey.Name if storey else element.Description
|
||||||
@@ -1178,15 +1173,18 @@ class SectionLevelDecorator(BaseDecorator):
|
|||||||
dimension_data = DecoratorData.get_dimension_data(obj)
|
dimension_data = DecoratorData.get_dimension_data(obj)
|
||||||
|
|
||||||
for verts in splines:
|
for verts in splines:
|
||||||
|
|
||||||
def get_text():
|
def get_text():
|
||||||
z = verts[0].z / unit_scale
|
z = verts[0].z
|
||||||
z = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), z)
|
rl = self.format_value(context, z)
|
||||||
z *= unit_scale
|
text = "RL {}{}".format("" if z < 0 else "+", rl)
|
||||||
text = "RL " + self.format_value(context, z)
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
self.draw_dimension_text(context,
|
self.draw_dimension_text(
|
||||||
get_text, tag, dimension_data,
|
context,
|
||||||
|
get_text,
|
||||||
|
tag,
|
||||||
|
dimension_data,
|
||||||
box_alignment="bottom-left",
|
box_alignment="bottom-left",
|
||||||
pos=text_position,
|
pos=text_position,
|
||||||
text_dir=text_dir,
|
text_dir=text_dir,
|
||||||
|
|||||||
@@ -228,10 +228,7 @@ class SvgWriter:
|
|||||||
storey = tool.Drawing.get_annotation_element(element)
|
storey = tool.Drawing.get_annotation_element(element)
|
||||||
tag = storey.Name if storey else element.Description
|
tag = storey.Name if storey else element.Description
|
||||||
dimension_data = DecoratorData.get_dimension_data(obj)
|
dimension_data = DecoratorData.get_dimension_data(obj)
|
||||||
prefix = dimension_data["text_prefix"]
|
suppress_zero_inches = dimension_data["suppress_zero_inches"]
|
||||||
suffix = dimension_data["text_suffix"]
|
|
||||||
show_description_only = dimension_data["show_description_only"]
|
|
||||||
fill_bg = dimension_data["fill_bg"]
|
|
||||||
base_offset_y = 3.5
|
base_offset_y = 3.5
|
||||||
|
|
||||||
for spline in obj.data.splines:
|
for spline in obj.data.splines:
|
||||||
@@ -247,42 +244,20 @@ class SvgWriter:
|
|||||||
|
|
||||||
# TODO: allow metric to be configurable
|
# TODO: allow metric to be configurable
|
||||||
def get_text():
|
def get_text():
|
||||||
rl_value = (matrix_world @ points[0].co.xyz).z
|
z = (matrix_world @ points[0].co.xyz).z
|
||||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
rl = helper.format_distance(
|
||||||
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
|
z,
|
||||||
else:
|
precision=self.precision,
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
decimal_places=self.decimal_places,
|
||||||
rl = rl_value / unit_scale
|
suppress_zero_inches=suppress_zero_inches,
|
||||||
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
)
|
||||||
rl *= unit_scale
|
text = "RL {}{}".format("" if z < 0 else "+", rl)
|
||||||
rl = "{:.3f}m".format(rl)
|
|
||||||
text = "RL {}{}".format("" if rl_value < 0 else "+", rl)
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
text_tags = []
|
self.draw_dimension_text(
|
||||||
line_number_start = 0
|
get_text, tag, dimension_data, text_position=text_position, angle=angle, class_str="SECTIONLEVEL"
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for text in text_tags:
|
|
||||||
self.svg.add(text)
|
|
||||||
|
|
||||||
def draw_stair_annotation(self, obj):
|
def draw_stair_annotation(self, obj):
|
||||||
x_offset = self.raw_width / 2
|
x_offset = self.raw_width / 2
|
||||||
y_offset = self.raw_height / 2
|
y_offset = self.raw_height / 2
|
||||||
@@ -890,10 +865,7 @@ class SvgWriter:
|
|||||||
description = element.Description
|
description = element.Description
|
||||||
|
|
||||||
dimension_data = DecoratorData.get_dimension_data(obj)
|
dimension_data = DecoratorData.get_dimension_data(obj)
|
||||||
prefix = dimension_data["text_prefix"]
|
suppress_zero_inches = dimension_data["suppress_zero_inches"]
|
||||||
suffix = dimension_data["text_suffix"]
|
|
||||||
show_description_only = dimension_data["show_description_only"]
|
|
||||||
fill_bg = dimension_data["fill_bg"]
|
|
||||||
base_offset_y = 1.0
|
base_offset_y = 1.0
|
||||||
|
|
||||||
for spline in obj.data.splines:
|
for spline in obj.data.splines:
|
||||||
@@ -908,43 +880,28 @@ class SvgWriter:
|
|||||||
angle = math.degrees(vector.angle_signed(Vector((1, 0))))
|
angle = math.degrees(vector.angle_signed(Vector((1, 0))))
|
||||||
|
|
||||||
# TODO: allow metric to be configurable
|
# TODO: allow metric to be configurable
|
||||||
rl_value = (matrix_world @ points[0].co).z
|
def get_text():
|
||||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
z = (matrix_world @ points[0].co.xyz).z
|
||||||
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
|
rl = helper.format_distance(
|
||||||
else:
|
z,
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
precision=self.precision,
|
||||||
rl = rl_value / unit_scale
|
decimal_places=self.decimal_places,
|
||||||
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
suppress_zero_inches=suppress_zero_inches,
|
||||||
rl *= unit_scale
|
)
|
||||||
rl = "{:.3f}m".format(rl)
|
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"
|
box_alignment = "bottom-left" if projected_points[0].x <= projected_points[-1].x else "bottom-right"
|
||||||
line_number_start = 0
|
self.draw_dimension_text(
|
||||||
|
get_text,
|
||||||
if not show_description_only:
|
description,
|
||||||
text = "{}{}".format("" if rl_value < 0 else "+", rl)
|
dimension_data,
|
||||||
full_prefix = ((description + "\\n") if description else "") + prefix
|
text_position=text_position,
|
||||||
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,
|
|
||||||
angle=angle,
|
angle=angle,
|
||||||
class_str="PLANLEVEL",
|
class_str="PLANLEVEL",
|
||||||
line_number_start=line_number_start,
|
|
||||||
box_alignment=box_alignment,
|
box_alignment=box_alignment,
|
||||||
fill_bg=fill_bg
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for text in text_tags:
|
|
||||||
self.svg.add(text)
|
|
||||||
|
|
||||||
def draw_angle_annotations(self, obj):
|
def draw_angle_annotations(self, obj):
|
||||||
points = obj.data.splines[0].points
|
points = obj.data.splines[0].points
|
||||||
region = bpy.context.region
|
region = bpy.context.region
|
||||||
@@ -1110,8 +1067,9 @@ class SvgWriter:
|
|||||||
text = f"R{radius}"
|
text = f"R{radius}"
|
||||||
return text
|
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):
|
def draw_dimension_text(self, get_text, tag, dimension_data, **create_text_kwargs):
|
||||||
prefix = dimension_data["text_prefix"]
|
prefix = dimension_data["text_prefix"]
|
||||||
@@ -1132,16 +1090,12 @@ class SvgWriter:
|
|||||||
text = tag
|
text = tag
|
||||||
|
|
||||||
text_tags += self.create_text_tag(
|
text_tags += self.create_text_tag(
|
||||||
text,
|
text, line_number_start=line_number_start, fill_bg=fill_bg, **create_text_kwargs
|
||||||
line_number_start=line_number_start,
|
|
||||||
fill_bg=fill_bg,
|
|
||||||
**create_text_kwargs
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for text in text_tags:
|
for text in text_tags:
|
||||||
self.svg.add(text)
|
self.svg.add(text)
|
||||||
|
|
||||||
|
|
||||||
def draw_fall_annotations(self, obj):
|
def draw_fall_annotations(self, obj):
|
||||||
x_offset = self.raw_width / 2
|
x_offset = self.raw_width / 2
|
||||||
y_offset = self.raw_height / 2
|
y_offset = self.raw_height / 2
|
||||||
|
|||||||
Reference in New Issue
Block a user