mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 02:21:02 +00:00
#1153 Reimplement metadata keys so you can specify attribute-based classes in drawings
This commit is contained in:
@@ -5,12 +5,13 @@ FILE_NAME('EPset_Drawing.ifc','2020-01-01T00:00:00',(),(),'EPset_Drawing','EPset
|
|||||||
FILE_SCHEMA(('IFC4'));
|
FILE_SCHEMA(('IFC4'));
|
||||||
ENDSEC;
|
ENDSEC;
|
||||||
DATA;
|
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.);
|
#2=IFCSIMPLEPROPERTYTEMPLATE('23JavTMk98ZxXhrUEnjAcf',$,'TargetView','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
|
||||||
#3=IFCSIMPLEPROPERTYTEMPLATE('1yVWUt5H9DAOuu0OaMMLpe',$,'Scale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
|
#3=IFCSIMPLEPROPERTYTEMPLATE('1yVWUt5H9DAOuu0OaMMLpe',$,'Scale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
|
||||||
#4=IFCSIMPLEPROPERTYTEMPLATE('3gsuPBtU93b8f0gg1pjkq6',$,'HumanScale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
|
#4=IFCSIMPLEPROPERTYTEMPLATE('3gsuPBtU93b8f0gg1pjkq6',$,'HumanScale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
|
||||||
#5=IFCSIMPLEPROPERTYTEMPLATE('0AK5C2UpL4$eaac2LszAx$',$,'HasUnderlay','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
#5=IFCSIMPLEPROPERTYTEMPLATE('0AK5C2UpL4$eaac2LszAx$',$,'HasUnderlay','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
||||||
#6=IFCSIMPLEPROPERTYTEMPLATE('2j2ZEZR8X5tONm7kli5hM6',$,'HasLinework','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
#6=IFCSIMPLEPROPERTYTEMPLATE('2j2ZEZR8X5tONm7kli5hM6',$,'HasLinework','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
||||||
#7=IFCSIMPLEPROPERTYTEMPLATE('1ttChRysH9UuEX2FeMj5Hu',$,'HasAnnotation','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
#7=IFCSIMPLEPROPERTYTEMPLATE('1ttChRysH9UuEX2FeMj5Hu',$,'HasAnnotation','',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
|
||||||
|
#8=IFCSIMPLEPROPERTYTEMPLATE('10hT_1zrzEbRRKMXYAWvtD',$,'Metadata','',.P_SINGLEVALUE.,'IfcText',$,$,$,$,$,.READWRITE.);
|
||||||
ENDSEC;
|
ENDSEC;
|
||||||
END-ISO-10303-21;
|
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))
|
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 = sorted(elements, key=lambda a : tool.Drawing.get_annotation_z_index(a))
|
||||||
|
svg_writer.metadata = tool.Drawing.get_drawing_metadata(self.camera_element)
|
||||||
#svg_writer.annotations["attributes"] = [a.name for a in drawing_style.attributes]
|
|
||||||
|
|
||||||
svg_writer.write("annotation")
|
svg_writer.write("annotation")
|
||||||
return svg_writer.output
|
return svg_writer.output
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class SvgWriter:
|
|||||||
self.vector_style = None
|
self.vector_style = None
|
||||||
self.human_scale = "NTS"
|
self.human_scale = "NTS"
|
||||||
self.annotations = []
|
self.annotations = []
|
||||||
|
self.metadata = []
|
||||||
self.background_image = None
|
self.background_image = None
|
||||||
self.scale = 1 / 100 # 1:100
|
self.scale = 1 / 100 # 1:100
|
||||||
|
|
||||||
@@ -331,43 +332,15 @@ class SvgWriter:
|
|||||||
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]
|
||||||
# TODO: reimplement
|
for key in self.metadata:
|
||||||
# for attribute in self.annotations.get("attributes", []):
|
value = ifcopenshell.util.selector.Selector.get_element_value(element, key)
|
||||||
# result = self.get_obj_value(obj, attribute)
|
if value:
|
||||||
# if result:
|
classes.append(self.canonicalise_class_name(key) + "-" + self.canonicalise_class_name(str(value)))
|
||||||
# classes.append(
|
|
||||||
# "{}-{}".format(re.sub("[^0-9a-zA-Z]+", "", attribute), re.sub("[^0-9a-zA-Z]+", "", result))
|
|
||||||
# )
|
|
||||||
return classes
|
return classes
|
||||||
|
|
||||||
def canonicalise_class_name(self, name):
|
def canonicalise_class_name(self, name):
|
||||||
return re.sub("[^0-9a-zA-Z]+", "", 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):
|
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
|
||||||
|
|||||||
@@ -723,15 +723,22 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_reference_element(cls, reference):
|
def get_reference_element(cls, reference):
|
||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
if tool.Ifc.get_schema() == "IFC2X3":
|
||||||
return [
|
return [r for r in tool.Ifc.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference][
|
||||||
r for r in tool.Ifc.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == reference
|
0
|
||||||
][0].RelatedObjects[0]
|
].RelatedObjects[0]
|
||||||
return reference.DocumentRefForObjects[0].RelatedObjects[0]
|
return reference.DocumentRefForObjects[0].RelatedObjects[0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_drawing_human_scale(cls, drawing):
|
def get_drawing_human_scale(cls, drawing):
|
||||||
return ifcopenshell.util.element.get_psets(drawing)["EPset_Drawing"].get("HumanScale", "NTS")
|
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
|
@classmethod
|
||||||
def get_annotation_z_index(cls, drawing):
|
def get_annotation_z_index(cls, drawing):
|
||||||
return ifcopenshell.util.element.get_psets(drawing).get("EPset_Annotation", {}).get("ZIndex", 0)
|
return ifcopenshell.util.element.get_psets(drawing).get("EPset_Annotation", {}).get("ZIndex", 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user