mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Fix #2986. Reimplement Metadata property of EPset_Drawing to include arbitrary metadata as CSS classes.
This commit is contained in:
@@ -187,6 +187,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
with profile("Initialize drawing generation process"):
|
with profile("Initialize drawing generation process"):
|
||||||
self.cprops = self.camera.data.BIMCameraProperties
|
self.cprops = self.camera.data.BIMCameraProperties
|
||||||
self.drawing_name = self.file.by_id(drawing_id).Name
|
self.drawing_name = self.file.by_id(drawing_id).Name
|
||||||
|
self.metadata = tool.Drawing.get_drawing_metadata(self.camera_element)
|
||||||
self.get_scale()
|
self.get_scale()
|
||||||
if self.cprops.update_representation(self.camera):
|
if self.cprops.update_representation(self.camera):
|
||||||
bpy.ops.bim.update_representation(obj=self.camera.name, ifc_representation_class="")
|
bpy.ops.bim.update_representation(obj=self.camera.name, ifc_representation_class="")
|
||||||
@@ -543,8 +544,16 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
material_name = material.LayerSetName or "null"
|
material_name = material.LayerSetName or "null"
|
||||||
else:
|
else:
|
||||||
material_name = getattr(material, "Name", "null") or "null"
|
material_name = getattr(material, "Name", "null") or "null"
|
||||||
material_name = self.canonicalise_class_name(material_name)
|
material_name = tool.Drawing.canonicalise_class_name(material_name)
|
||||||
classes.append(f"material-{material_name}")
|
classes.append(f"material-{material_name}")
|
||||||
|
|
||||||
|
for key in self.metadata:
|
||||||
|
value = ifcopenshell.util.selector.get_element_value(element, key)
|
||||||
|
if value:
|
||||||
|
classes.append(
|
||||||
|
tool.Drawing.canonicalise_class_name(key) + "-" + tool.Drawing.canonicalise_class_name(str(value))
|
||||||
|
)
|
||||||
|
|
||||||
el.set("class", (el.get("class", "") + " " + " ".join(classes)).strip())
|
el.set("class", (el.get("class", "") + " " + " ".join(classes)).strip())
|
||||||
|
|
||||||
# Drawing convention states that objects with the same material are merged when cut.
|
# Drawing convention states that objects with the same material are merged when cut.
|
||||||
@@ -594,9 +603,6 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
if group is not None:
|
if group is not None:
|
||||||
group[:] = reversed(group)
|
group[:] = reversed(group)
|
||||||
|
|
||||||
def canonicalise_class_name(self, name):
|
|
||||||
return re.sub("[^0-9a-zA-Z]+", "", name)
|
|
||||||
|
|
||||||
def generate_annotation(self, context):
|
def generate_annotation(self, context):
|
||||||
if not self.cprops.has_annotation:
|
if not self.cprops.has_annotation:
|
||||||
return
|
return
|
||||||
@@ -613,7 +619,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision")
|
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision")
|
||||||
if not precision:
|
if not precision:
|
||||||
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "ImperialPrecision")
|
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "ImperialPrecision")
|
||||||
self.svg_writer.metadata = tool.Drawing.get_drawing_metadata(self.camera_element)
|
self.svg_writer.metadata = self.metadata
|
||||||
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision).save()
|
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision).save()
|
||||||
|
|
||||||
return svg_path
|
return svg_path
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ class SvgWriter:
|
|||||||
def get_attribute_classes(self, obj):
|
def get_attribute_classes(self, obj):
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
global_id = "GlobalId-{}".format(element.GlobalId)
|
global_id = "GlobalId-{}".format(element.GlobalId)
|
||||||
predefined_type = "PredefinedType-" + self.canonicalise_class_name(
|
predefined_type = "PredefinedType-" + tool.Drawing.canonicalise_class_name(
|
||||||
str(ifcopenshell.util.element.get_predefined_type(element))
|
str(ifcopenshell.util.element.get_predefined_type(element))
|
||||||
)
|
)
|
||||||
classes = [global_id, element.is_a(), predefined_type]
|
classes = [global_id, element.is_a(), predefined_type]
|
||||||
@@ -364,12 +364,11 @@ class SvgWriter:
|
|||||||
for key in self.metadata:
|
for key in self.metadata:
|
||||||
value = ifcopenshell.util.selector.get_element_value(element, key)
|
value = ifcopenshell.util.selector.get_element_value(element, key)
|
||||||
if value:
|
if value:
|
||||||
classes.append(self.canonicalise_class_name(key) + "-" + self.canonicalise_class_name(str(value)))
|
classes.append(
|
||||||
|
tool.Drawing.canonicalise_class_name(key) + "-" + tool.Drawing.canonicalise_class_name(str(value))
|
||||||
|
)
|
||||||
return classes
|
return classes
|
||||||
|
|
||||||
def canonicalise_class_name(self, name):
|
|
||||||
return re.sub("[^0-9a-zA-Z]+", "", name)
|
|
||||||
|
|
||||||
def draw_line_annotation(self, obj):
|
def draw_line_annotation(self, obj):
|
||||||
# TODO: properly scope these offsets
|
# TODO: properly scope these offsets
|
||||||
x_offset = self.raw_width / 2
|
x_offset = self.raw_width / 2
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ import collections
|
|||||||
|
|
||||||
|
|
||||||
class Drawing(blenderbim.core.tool.Drawing):
|
class Drawing(blenderbim.core.tool.Drawing):
|
||||||
|
@classmethod
|
||||||
|
def canonicalise_class_name(self, name):
|
||||||
|
return re.sub("[^0-9a-zA-Z]+", "", name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def copy_representation(cls, source, dest):
|
def copy_representation(cls, source, dest):
|
||||||
if source.Representation:
|
if source.Representation:
|
||||||
|
|||||||
Reference in New Issue
Block a user