minor improvements

This commit is contained in:
Kristoffer
2020-11-06 16:53:42 +01:00
parent 5928ddba40
commit 9a385c2118
3 changed files with 61 additions and 52 deletions
@@ -404,7 +404,7 @@ class IfcParser:
) )
if obj.instance_type == "COLLECTION" and self.is_a_rel_aggregates( if obj.instance_type == "COLLECTION" and self.is_a_rel_aggregates(
self.get_ifc_class(obj.instance_collection.name) self.get_ifc_class(obj.instance_collection.name)
): ):
self.rel_aggregates[self.product_index] = obj.name self.rel_aggregates[self.product_index] = obj.name
@@ -434,7 +434,7 @@ class IfcParser:
elif obj.BIMObjectProperties.material_type == "IfcMaterialLayerSet": elif obj.BIMObjectProperties.material_type == "IfcMaterialLayerSet":
self.rel_associates_material_layer_set[self.product_index] = obj.BIMObjectProperties.material_set self.rel_associates_material_layer_set[self.product_index] = obj.BIMObjectProperties.material_set
elif obj.BIMObjectProperties.material_type == "IfcMaterialProfileSet": elif obj.BIMObjectProperties.material_type == "IfcMaterialProfileSet":
pass # TODO pass # TODO
return product return product
@@ -980,7 +980,11 @@ class IfcParser:
def load_presentation_layer_assignments(self): def load_presentation_layer_assignments(self):
for representation in self.representations.values(): for representation in self.representations.values():
if representation["presentation_layer"]: if representation["presentation_layer"]:
self.presentation_layer_assignments.setdefault(representation["presentation_layer"], []).append( pl = representation["presentation_layer"]
print('Presentation load: ', pl.name)
defaults = [[], pl.description, pl.identifier, pl.layer_on, pl.layer_frozen, pl.layer_blocked,
pl.layer_styles]
self.presentation_layer_assignments.setdefault(pl.name, defaults)[0].append(
representation representation
) )
@@ -999,9 +1003,9 @@ class IfcParser:
def prevent_data_name_duplicates(self, product): def prevent_data_name_duplicates(self, product):
if ( if (
product["raw"].data product["raw"].data
and bpy.data.meshes.get(product["raw"].data.name) and bpy.data.meshes.get(product["raw"].data.name)
and bpy.data.curves.get(product["raw"].data.name) and bpy.data.curves.get(product["raw"].data.name)
): ):
product["raw"].data.name += "~" product["raw"].data.name += "~"
@@ -1074,7 +1078,8 @@ class IfcParser:
"Model/Box/MODEL_VIEW/{}".format(mesh_name.split("/")[3]) "Model/Box/MODEL_VIEW/{}".format(mesh_name.split("/")[3])
] = self.get_representation(obj.data, obj, "Model", "Box", "MODEL_VIEW") ] = self.get_representation(obj.data, obj, "Model", "Box", "MODEL_VIEW")
elif ( elif (
context_prefix == "Model/Body/MODEL_VIEW" and obj.data and not self.is_mesh_context_sensitive(obj.data.name) context_prefix == "Model/Body/MODEL_VIEW" and obj.data and not self.is_mesh_context_sensitive(
obj.data.name)
): ):
self.append_default_representation(obj) self.append_default_representation(obj)
elif context_prefix == "Model/Body/MODEL_VIEW" and self.is_point_cloud(obj): elif context_prefix == "Model/Body/MODEL_VIEW" and self.is_point_cloud(obj):
@@ -1245,15 +1250,15 @@ class IfcParser:
return children return children
for reference, element in enumerate(self.spatial_structure_elements): for reference, element in enumerate(self.spatial_structure_elements):
if ( # A convention is established that spatial elements may be if ( # A convention is established that spatial elements may be
# an object placed in a collection of the same name # an object placed in a collection of the same name
element["raw"].name == element["raw"].users_collection[0].name element["raw"].name == element["raw"].users_collection[0].name
and element["raw"].users_collection[0].name and element["raw"].users_collection[0].name
in [c.name for c in bpy.data.collections[parent["raw"].name].children] in [c.name for c in bpy.data.collections[parent["raw"].name].children]
) or ( # We allow finer grain spatial elements such as IfcSpace to ) or ( # We allow finer grain spatial elements such as IfcSpace to
# break the convention to prevent collection overload in Blender # break the convention to prevent collection overload in Blender
element["raw"].name != element["raw"].users_collection[0].name element["raw"].name != element["raw"].users_collection[0].name
and element["raw"].users_collection[0].name and element["raw"].users_collection[0].name
in [o.name for o in bpy.data.collections[parent["raw"].name].objects] in [o.name for o in bpy.data.collections[parent["raw"].name].objects]
): ):
children.append({"reference": reference, "children": self.get_spatial_structure_elements_tree(element)}) children.append({"reference": reference, "children": self.get_spatial_structure_elements_tree(element)})
return children return children
@@ -1311,7 +1316,7 @@ class IfcParser:
def is_a_type(self, class_name): def is_a_type(self, class_name):
return (class_name[0:3] == "Ifc" and class_name[-4:] == "Type") or ( return (class_name[0:3] == "Ifc" and class_name[-4:] == "Type") or (
class_name[0:3] == "Ifc" and class_name[-5:] == "Style" class_name[0:3] == "Ifc" and class_name[-5:] == "Style"
) )
@@ -1388,10 +1393,10 @@ class IfcExporter:
self.file.wrapped_data.header.file_name.name = os.path.basename(self.ifc_export_settings.output_file) self.file.wrapped_data.header.file_name.name = os.path.basename(self.ifc_export_settings.output_file)
self.file.wrapped_data.header.file_name.time_stamp = ( self.file.wrapped_data.header.file_name.time_stamp = (
datetime.datetime.utcnow() datetime.datetime.utcnow()
.replace(tzinfo=datetime.timezone.utc) .replace(tzinfo=datetime.timezone.utc)
.astimezone() .astimezone()
.replace(microsecond=0) .replace(microsecond=0)
.isoformat() .isoformat()
) )
self.file.wrapped_data.header.file_name.preprocessor_version = "IfcOpenShell {}".format(ifcopenshell.version) self.file.wrapped_data.header.file_name.preprocessor_version = "IfcOpenShell {}".format(ifcopenshell.version)
self.file.wrapped_data.header.file_name.originating_system = "{} {}".format( self.file.wrapped_data.header.file_name.originating_system = "{} {}".format(
@@ -1415,10 +1420,10 @@ class IfcExporter:
[ [
str(x) str(x)
for x in [ for x in [
addon.bl_info.get("version", (-1, -1, -1)) addon.bl_info.get("version", (-1, -1, -1))
for addon in addon_utils.modules() for addon in addon_utils.modules()
if addon.bl_info["name"] == "BlenderBIM" if addon.bl_info["name"] == "BlenderBIM"
][0] ][0]
] ]
) )
@@ -1613,8 +1618,8 @@ class IfcExporter:
def create_document_references(self): def create_document_references(self):
for reference in self.ifc_parser.document_references.values(): for reference in self.ifc_parser.document_references.values():
if ( if (
reference["referenced_document"] reference["referenced_document"]
and reference["referenced_document"] in self.ifc_parser.document_information and reference["referenced_document"] in self.ifc_parser.document_information
): ):
reference["attributes"]["ReferencedDocument"] = self.ifc_parser.document_information[ reference["attributes"]["ReferencedDocument"] = self.ifc_parser.document_information[
reference["referenced_document"] reference["referenced_document"]
@@ -2023,9 +2028,11 @@ class IfcExporter:
return self.file.createIfcStyledItem(representation_item, [surface_style], item["attributes"]["Name"]) return self.file.createIfcStyledItem(representation_item, [surface_style], item["attributes"]["Name"])
def create_presentation_layer_assignments(self): def create_presentation_layer_assignments(self):
for name, assigned_items in self.ifc_parser.presentation_layer_assignments.items(): for name, props in self.ifc_parser.presentation_layer_assignments.items():
assigned_items, description, identifier, layer_on, layer_frozen, layer_blocked, layer_styles = props
print('Presentation Export: ', name, assigned_items)
self.file.createIfcPresentationLayerAssignment( self.file.createIfcPresentationLayerAssignment(
name, None, [i["ifc"].MappedRepresentation for i in assigned_items], None name, description, [i["ifc"].MappedRepresentation for i in assigned_items], identifier
) )
def create_materials(self): def create_materials(self):
@@ -2101,9 +2108,9 @@ class IfcExporter:
def get_rendering_attributes(self, material): def get_rendering_attributes(self, material):
if ( if (
not material.use_nodes not material.use_nodes
or not hasattr(material.node_tree, "nodes") or not hasattr(material.node_tree, "nodes")
or "Principled BSDF" not in material.node_tree.nodes or "Principled BSDF" not in material.node_tree.nodes
): ):
return {} return {}
bsdf = material.node_tree.nodes["Principled BSDF"] bsdf = material.node_tree.nodes["Principled BSDF"]
@@ -3330,7 +3337,8 @@ class IfcExporter:
tmp_file = os.path.join(unzipped_path, tmp_name) tmp_file = os.path.join(unzipped_path, tmp_name)
self.file.write(tmp_file) self.file.write(tmp_file)
with zipfile.ZipFile( with zipfile.ZipFile(
self.ifc_export_settings.output_file, mode="w", compression=zipfile.ZIP_DEFLATED, compresslevel=9 self.ifc_export_settings.output_file, mode="w", compression=zipfile.ZIP_DEFLATED,
compresslevel=9
) as zf: ) as zf:
zf.write(tmp_file) zf.write(tmp_file)
elif extension == "ifc": elif extension == "ifc":
@@ -4284,11 +4284,13 @@ class AddToPresentationLayer(bpy.types.Operator):
bl_idname = "bim.add_to_presentation_layer" bl_idname = "bim.add_to_presentation_layer"
bl_label = "Add To Presentation Layer" bl_label = "Add To Presentation Layer"
index: bpy.props.IntProperty() index: bpy.props.IntProperty()
guid: bpy.props.StringProperty()
def execute(self, context): def execute(self, context):
bpy.context.active_object.BIMObjectProperties.presentation_layer = \ name = bpy.context.scene.BIMProperties.presentation_layers[self.index].name
bpy.context.scene.BIMProperties.presentation_layers[self.index] bpy.context.active_object.BIMObjectProperties.presentation_layer.name = name
print(f'Adding "{self.index} - {name}" to "{bpy.context.scene.BIMProperties.name}"')
return {"FINISHED"} return {"FINISHED"}
+16 -17
View File
@@ -785,28 +785,27 @@ class BIM_PT_presentation_layer_data(Panel):
if not context.active_object.data: if not context.active_object.data:
return return
layout = self.layout layout = self.layout
curr_props = context.active_object.data.BIMMeshProperties.presentation_layer elem_props = context.active_object.data.BIMMeshProperties.presentation_layer
scene_props = context.scene.BIMProperties
# if len(curr_props.values()) > 0: if elem_props.name != '':
layout.row(align=True).prop(elem_props, "name")
layout.row().prop(elem_props, "description")
layout.row().prop(elem_props, "identifier")
layout.row().prop(elem_props, "layer_on")
layout.row().prop(elem_props, "layer_frozen")
layout.row().prop(elem_props, "layer_blocked")
layout.row().prop(elem_props, "layer_styles")
else:
layout.label(text='Not included in any presentation layer')
layout.row(align=True).prop(curr_props, "name") if scene_props.presentation_layers:
layout.row().prop(curr_props, "description") layout.template_list("BIM_UL_presentation_layers", "", scene_props, "presentation_layers", scene_props,
layout.row().prop(curr_props, "identifier")
layout.row().prop(curr_props, "layer_on")
layout.row().prop(curr_props, "layer_frozen")
layout.row().prop(curr_props, "layer_blocked")
layout.row().prop(curr_props, "layer_styles")
props = context.scene.BIMProperties
cur_elem = bpy.context.active_object.BIMObjectProperties
if props.presentation_layers:
layout.template_list("BIM_UL_presentation_layers", "", props, "presentation_layers", props,
"active_presentation_layer_index") "active_presentation_layer_index")
pres_layer = props.presentation_layers[props.active_presentation_layer_index] pres_layer = scene_props.presentation_layers[scene_props.active_presentation_layer_index]
if pres_layer.name in bpy.context.scene.BIMProperties.presentation_layers: if pres_layer.name in bpy.context.scene.BIMProperties.presentation_layers:
op = layout.row().operator("bim.add_to_presentation_layer") op = layout.row().operator("bim.add_to_presentation_layer")
op.index = props.active_presentation_layer_index op.index = scene_props.active_presentation_layer_index
op.guid = cur_elem.attributes['GlobalId'].string_value
else: else:
layout.label(text="Presentation Layer is invalid") layout.label(text="Presentation Layer is invalid")