#1153 Reimplement metadata keys so you can specify attribute-based classes in drawings

This commit is contained in:
Dion Moult
2022-04-22 10:05:59 +10:00
parent 80d8665992
commit a66ba6a6f9
4 changed files with 18 additions and 38 deletions
@@ -5,12 +5,13 @@ FILE_NAME('EPset_Drawing.ifc','2020-01-01T00:00:00',(),(),'EPset_Drawing','EPset
FILE_SCHEMA(('IFC4'));
ENDSEC;
DATA;
#1=IFCPROPERTYSETTEMPLATE('2JhNIvqZrFnAgxfhK0XVQX',$,'EPset_Drawing','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation',(#2,#3,#4,#5,#6,#7));
#1=IFCPROPERTYSETTEMPLATE('2JhNIvqZrFnAgxfhK0XVQX',$,'EPset_Drawing','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation',(#2,#3,#4,#5,#6,#7,#8));
#2=IFCSIMPLEPROPERTYTEMPLATE('23JavTMk98ZxXhrUEnjAcf',$,'TargetView','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#3=IFCSIMPLEPROPERTYTEMPLATE('1yVWUt5H9DAOuu0OaMMLpe',$,'Scale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#4=IFCSIMPLEPROPERTYTEMPLATE('3gsuPBtU93b8f0gg1pjkq6',$,'HumanScale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#5=IFCSIMPLEPROPERTYTEMPLATE('0AK5C2UpL4$eaac2LszAx$',$,'HasUnderlay','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
#6=IFCSIMPLEPROPERTYTEMPLATE('2j2ZEZR8X5tONm7kli5hM6',$,'HasLinework','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
#7=IFCSIMPLEPROPERTYTEMPLATE('1ttChRysH9UuEX2FeMj5Hu',$,'HasAnnotation','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
#8=IFCSIMPLEPROPERTYTEMPLATE('10hT_1zrzEbRRKMXYAWvtD',$,'Metadata','',.P_SINGLEVALUE.,'IfcText',$,$,$,$,$,.READWRITE.);
ENDSEC;
END-ISO-10303-21;
@@ -444,8 +444,7 @@ class CreateDrawing(bpy.types.Operator):
elements = tool.Drawing.get_group_elements(tool.Drawing.get_drawing_group(self.camera_element))
svg_writer.annotations = sorted(elements, key=lambda a : tool.Drawing.get_annotation_z_index(a))
#svg_writer.annotations["attributes"] = [a.name for a in drawing_style.attributes]
svg_writer.metadata = tool.Drawing.get_drawing_metadata(self.camera_element)
svg_writer.write("annotation")
return svg_writer.output
@@ -66,6 +66,7 @@ class SvgWriter:
self.vector_style = None
self.human_scale = "NTS"
self.annotations = []
self.metadata = []
self.background_image = None
self.scale = 1 / 100 # 1:100
@@ -331,43 +332,15 @@ class SvgWriter:
str(ifcopenshell.util.element.get_predefined_type(element))
)
classes = [global_id, element.is_a(), predefined_type]
# TODO: reimplement
# for attribute in self.annotations.get("attributes", []):
# result = self.get_obj_value(obj, attribute)
# if result:
# classes.append(
# "{}-{}".format(re.sub("[^0-9a-zA-Z]+", "", attribute), re.sub("[^0-9a-zA-Z]+", "", result))
# )
for key in self.metadata:
value = ifcopenshell.util.selector.Selector.get_element_value(element, key)
if value:
classes.append(self.canonicalise_class_name(key) + "-" + self.canonicalise_class_name(str(value)))
return classes
def canonicalise_class_name(self, name):
return re.sub("[^0-9a-zA-Z]+", "", name)
def get_obj_value(self, obj, key):
# This is a duplicate implementation of the IFC selector key in Blender
# In the future if all this becomes purely IFC based this can be deleted
if "." in key and key.split(".")[0] == "type":
try:
obj = obj.BIMObjectProperties.relating_type
except:
return
key = ".".join(key.split(".")[1:])
result = obj.BIMObjectProperties.attributes.get(key)
if result:
return result.string_value
elif key == "Name":
return obj.name.split("/")[1]
elif "." in key:
pset_name, prop = key.split(".")
pset = obj.BIMObjectProperties.psets.get(pset_name)
if not pset:
pset = obj.BIMObjectProperties.qtos.get(pset_name)
if not pset:
return
result = pset.properties.get(prop)
if result:
return result.string_value
def draw_line_annotation(self, obj):
# TODO: properly scope these offsets
x_offset = self.raw_width / 2
+10 -3
View File
@@ -723,15 +723,22 @@ class Drawing(blenderbim.core.tool.Drawing):
@classmethod
def get_reference_element(cls, reference):
if tool.Ifc.get_schema() == "IFC2X3":
return [
r for r in tool.Ifc.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference
][0].RelatedObjects[0]
return [r for r in tool.Ifc.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference][
0
].RelatedObjects[0]
return reference.DocumentRefForObjects[0].RelatedObjects[0]
@classmethod
def get_drawing_human_scale(cls, drawing):
return ifcopenshell.util.element.get_psets(drawing)["EPset_Drawing"].get("HumanScale", "NTS")
@classmethod
def get_drawing_metadata(cls, drawing):
return [
v.strip()
for v in ifcopenshell.util.element.get_psets(drawing)["EPset_Drawing"].get("Metadata", "").split(",")
]
@classmethod
def get_annotation_z_index(cls, drawing):
return ifcopenshell.util.element.get_psets(drawing).get("EPset_Annotation", {}).get("ZIndex", 0)