mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
minor improvements in ui,export and operator
This commit is contained in:
@@ -206,6 +206,7 @@ if bpy is not None:
|
|||||||
operator.AddPresentationLayer,
|
operator.AddPresentationLayer,
|
||||||
operator.AddToPresentationLayer,
|
operator.AddToPresentationLayer,
|
||||||
operator.RemovePresentationLayer,
|
operator.RemovePresentationLayer,
|
||||||
|
operator.UpdatePresentationLayer,
|
||||||
operator.AddDrawingStyleAttribute,
|
operator.AddDrawingStyleAttribute,
|
||||||
operator.RemoveDrawingStyleAttribute,
|
operator.RemoveDrawingStyleAttribute,
|
||||||
operator.CopyPropertyToSelection,
|
operator.CopyPropertyToSelection,
|
||||||
|
|||||||
@@ -981,12 +981,10 @@ class IfcParser:
|
|||||||
for representation in self.representations.values():
|
for representation in self.representations.values():
|
||||||
if representation["presentation_layer"]:
|
if representation["presentation_layer"]:
|
||||||
pl = representation["presentation_layer"]
|
pl = representation["presentation_layer"]
|
||||||
print('Presentation load: ', pl.name)
|
if pl.name == '':
|
||||||
defaults = [[], pl.description, pl.identifier, pl.layer_on, pl.layer_frozen, pl.layer_blocked,
|
continue
|
||||||
pl.layer_styles]
|
print("Presentation load: ", pl.name)
|
||||||
self.presentation_layer_assignments.setdefault(pl.name, defaults)[0].append(
|
self.presentation_layer_assignments.setdefault(pl.name, []).append(representation)
|
||||||
representation
|
|
||||||
)
|
|
||||||
|
|
||||||
def load_representations(self):
|
def load_representations(self):
|
||||||
if not self.ifc_export_settings.has_representations:
|
if not self.ifc_export_settings.has_representations:
|
||||||
@@ -1078,8 +1076,7 @@ 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(
|
context_prefix == "Model/Body/MODEL_VIEW" and obj.data and not self.is_mesh_context_sensitive(obj.data.name)
|
||||||
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):
|
||||||
@@ -1119,9 +1116,7 @@ class IfcParser:
|
|||||||
"is_native": mesh.BIMMeshProperties.is_native if hasattr(mesh, "BIMMeshProperties") else False,
|
"is_native": mesh.BIMMeshProperties.is_native if hasattr(mesh, "BIMMeshProperties") else False,
|
||||||
"is_swept_solid": mesh.BIMMeshProperties.is_swept_solid if hasattr(mesh, "BIMMeshProperties") else False,
|
"is_swept_solid": mesh.BIMMeshProperties.is_swept_solid if hasattr(mesh, "BIMMeshProperties") else False,
|
||||||
"is_generated": False,
|
"is_generated": False,
|
||||||
"presentation_layer": mesh.BIMMeshProperties.presentation_layer
|
"presentation_layer": obj.BIMObjectProperties.presentation_layer if hasattr(obj, "BIMObjectProperties") else None,
|
||||||
if hasattr(mesh, "BIMMeshProperties")
|
|
||||||
else None,
|
|
||||||
"attributes": {"Name": mesh.name},
|
"attributes": {"Name": mesh.name},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2028,11 +2023,25 @@ 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, props in self.ifc_parser.presentation_layer_assignments.items():
|
scene_props = bpy.context.scene.BIMProperties
|
||||||
assigned_items, description, identifier, layer_on, layer_frozen, layer_blocked, layer_styles = props
|
for name, assigned_items in self.ifc_parser.presentation_layer_assignments.items():
|
||||||
print('Presentation Export: ', name, assigned_items)
|
if name == '':
|
||||||
|
continue
|
||||||
|
pl = scene_props.presentation_layers[name]
|
||||||
|
print("Presentation Export: ", name, pl.identifier, pl.layer_on)
|
||||||
|
|
||||||
|
with_style = False
|
||||||
|
if pl.layer_on is False:
|
||||||
|
with_style = True
|
||||||
|
|
||||||
|
if with_style is False:
|
||||||
self.file.createIfcPresentationLayerAssignment(
|
self.file.createIfcPresentationLayerAssignment(
|
||||||
name, description, [i["ifc"].MappedRepresentation for i in assigned_items], identifier
|
name, pl.description, [i["ifc"].MappedRepresentation for i in assigned_items], pl.identifier
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.file.createIfcPresentationLayerWithStyle(
|
||||||
|
name, pl.description, [i["ifc"].MappedRepresentation for i in assigned_items], pl.identifier,
|
||||||
|
pl.layer_on, pl.layer_frozen, pl.layer_blocked, pl.layer_styles
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_materials(self):
|
def create_materials(self):
|
||||||
@@ -3223,7 +3232,10 @@ class IfcExporter:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def relate_spaces_to_boundary_elements(self):
|
def relate_spaces_to_boundary_elements(self):
|
||||||
for (relating_space_index, relationships,) in self.ifc_parser.rel_space_boundaries.items():
|
for (
|
||||||
|
relating_space_index,
|
||||||
|
relationships,
|
||||||
|
) in self.ifc_parser.rel_space_boundaries.items():
|
||||||
for relationship in relationships:
|
for relationship in relationships:
|
||||||
relationship["attributes"]["GlobalId"] = ifcopenshell.guid.new()
|
relationship["attributes"]["GlobalId"] = ifcopenshell.guid.new()
|
||||||
relationship["attributes"]["RelatedBuildingElement"] = self.ifc_parser.products[
|
relationship["attributes"]["RelatedBuildingElement"] = self.ifc_parser.products[
|
||||||
@@ -3337,8 +3349,7 @@ 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,
|
self.ifc_export_settings.output_file, mode="w", compression=zipfile.ZIP_DEFLATED, compresslevel=9
|
||||||
compresslevel=9
|
|
||||||
) as zf:
|
) as zf:
|
||||||
zf.write(tmp_file)
|
zf.write(tmp_file)
|
||||||
elif extension == "ifc":
|
elif extension == "ifc":
|
||||||
|
|||||||
@@ -4288,8 +4288,9 @@ class AddToPresentationLayer(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
name = bpy.context.scene.BIMProperties.presentation_layers[self.index].name
|
name = bpy.context.scene.BIMProperties.presentation_layers[self.index].name
|
||||||
bpy.context.active_object.BIMObjectProperties.presentation_layer.name = name
|
bpy.context.active_object.BIMObjectProperties.presentation_layer.name = name
|
||||||
|
bpy.context.active_object.BIMObjectProperties.presentation_layer.name = name
|
||||||
print(f'Adding "{self.index} - {name}" to "{bpy.context.scene.BIMProperties.name}"')
|
elem_name = bpy.context.active_object.BIMObjectProperties.attributes["Name"].string_value
|
||||||
|
print(f'Adding "({self.index} - {name})" to "{elem_name}"')
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -4298,21 +4299,16 @@ class AddPresentationLayer(bpy.types.Operator):
|
|||||||
bl_idname = "bim.add_presentation_layer"
|
bl_idname = "bim.add_presentation_layer"
|
||||||
bl_label = "Add Presentation Layer"
|
bl_label = "Add Presentation Layer"
|
||||||
|
|
||||||
_name = 'New Presentation Layer'
|
|
||||||
descript = 'A Description'
|
|
||||||
identifier = 'Something'
|
|
||||||
layer_on = True
|
|
||||||
layer_frozen = False
|
|
||||||
layer_blocked = False
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
new = bpy.context.scene.BIMProperties.presentation_layers.add()
|
new = bpy.context.scene.BIMProperties.presentation_layers.add()
|
||||||
new.name = self._name
|
|
||||||
new.description = self.descript
|
# Default values of a new presentation layer
|
||||||
new.identifier = self.identifier
|
new.name = "New Presentation Layer"
|
||||||
new.layer_on = self.layer_on
|
new.description = "A Description"
|
||||||
new.layer_frozen = self.layer_frozen
|
new.identifier = "Something"
|
||||||
new.layer_blocked = self.layer_blocked
|
new.layer_on = True
|
||||||
|
new.layer_frozen = False
|
||||||
|
new.layer_blocked = False
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -4322,11 +4318,35 @@ class RemovePresentationLayer(bpy.types.Operator):
|
|||||||
bl_label = "Remove Presentation Layer"
|
bl_label = "Remove Presentation Layer"
|
||||||
index: bpy.props.IntProperty()
|
index: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
bpy.context.scene.BIMProperties.presentation_layers.remove(self.index)
|
bpy.context.scene.BIMProperties.presentation_layers.remove(self.index)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class UpdatePresentationLayer(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.update_presentation_layer"
|
||||||
|
bl_label = "Update Presentation Layer"
|
||||||
|
index: bpy.props.IntProperty()
|
||||||
|
pl_name = bpy.props.StringProperty()
|
||||||
|
pl_description = bpy.props.StringProperty()
|
||||||
|
pl_identifier = bpy.props.StringProperty()
|
||||||
|
pl_layer_on = bpy.props.BoolProperty()
|
||||||
|
pl_layer_frozen = bpy.props.BoolProperty()
|
||||||
|
pl_layer_blocked = bpy.props.BoolProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
pl = bpy.context.scene.BIMProperties.presentation_layers[self.index]
|
||||||
|
pl.name = self.pl_name
|
||||||
|
pl.description = self.pl_description
|
||||||
|
pl.identifier = self.pl_identifier
|
||||||
|
pl.layer_on = self.pl_layer_on
|
||||||
|
pl.layer_frozen = self.pl_layer_frozen
|
||||||
|
pl.layer_blocked = self.pl_layer_blocked
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddDrawingStyleAttribute(bpy.types.Operator):
|
class AddDrawingStyleAttribute(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_drawing_style_attribute"
|
bl_idname = "bim.add_drawing_style_attribute"
|
||||||
bl_label = "Add Drawing Style Attribute"
|
bl_label = "Add Drawing Style Attribute"
|
||||||
|
|||||||
@@ -799,8 +799,8 @@ class PresentationLayer(PropertyGroup):
|
|||||||
description: StringProperty(name="Description")
|
description: StringProperty(name="Description")
|
||||||
identifier: StringProperty(name="Identifier")
|
identifier: StringProperty(name="Identifier")
|
||||||
layer_on: BoolProperty(name="LayerOn", default=True)
|
layer_on: BoolProperty(name="LayerOn", default=True)
|
||||||
layer_frozen: BoolProperty(name="LayerFrozen")
|
layer_frozen: BoolProperty(name="LayerFrozen", default=False)
|
||||||
layer_blocked: BoolProperty(name="LayerBlocked")
|
layer_blocked: BoolProperty(name="LayerBlocked", default=False)
|
||||||
layer_styles: EnumProperty(items=[], name="LayerStyles")
|
layer_styles: EnumProperty(items=[], name="LayerStyles")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -788,7 +788,7 @@ class BIM_PT_presentation_layer_data(Panel):
|
|||||||
elem_props = context.active_object.data.BIMMeshProperties.presentation_layer
|
elem_props = context.active_object.data.BIMMeshProperties.presentation_layer
|
||||||
scene_props = context.scene.BIMProperties
|
scene_props = context.scene.BIMProperties
|
||||||
|
|
||||||
if elem_props.name != '':
|
if elem_props.name != "":
|
||||||
layout.row(align=True).prop(elem_props, "name")
|
layout.row(align=True).prop(elem_props, "name")
|
||||||
layout.row().prop(elem_props, "description")
|
layout.row().prop(elem_props, "description")
|
||||||
layout.row().prop(elem_props, "identifier")
|
layout.row().prop(elem_props, "identifier")
|
||||||
@@ -797,11 +797,17 @@ class BIM_PT_presentation_layer_data(Panel):
|
|||||||
layout.row().prop(elem_props, "layer_blocked")
|
layout.row().prop(elem_props, "layer_blocked")
|
||||||
layout.row().prop(elem_props, "layer_styles")
|
layout.row().prop(elem_props, "layer_styles")
|
||||||
else:
|
else:
|
||||||
layout.label(text='Not included in any presentation layer')
|
layout.label(text="Not included in any presentation layer")
|
||||||
|
|
||||||
if scene_props.presentation_layers:
|
if scene_props.presentation_layers:
|
||||||
layout.template_list("BIM_UL_presentation_layers", "", scene_props, "presentation_layers", scene_props,
|
layout.template_list(
|
||||||
"active_presentation_layer_index")
|
"BIM_UL_presentation_layers",
|
||||||
|
"",
|
||||||
|
scene_props,
|
||||||
|
"presentation_layers",
|
||||||
|
scene_props,
|
||||||
|
"active_presentation_layer_index",
|
||||||
|
)
|
||||||
pres_layer = scene_props.presentation_layers[scene_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")
|
||||||
@@ -950,8 +956,9 @@ class BIM_PT_presentation_layers(Panel):
|
|||||||
layout.row().operator("bim.add_presentation_layer")
|
layout.row().operator("bim.add_presentation_layer")
|
||||||
|
|
||||||
if props.presentation_layers:
|
if props.presentation_layers:
|
||||||
layout.template_list("BIM_UL_presentation_layers", "", props, "presentation_layers", props,
|
layout.template_list(
|
||||||
"active_presentation_layer_index")
|
"BIM_UL_presentation_layers", "", props, "presentation_layers", props, "active_presentation_layer_index"
|
||||||
|
)
|
||||||
pres_layer = props.presentation_layers[props.active_presentation_layer_index]
|
pres_layer = props.presentation_layers[props.active_presentation_layer_index]
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
@@ -963,8 +970,6 @@ class BIM_PT_presentation_layers(Panel):
|
|||||||
).index = props.active_presentation_layer_index
|
).index = props.active_presentation_layer_index
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(pres_layer, "description")
|
row.prop(pres_layer, "description")
|
||||||
# row = layout.row()
|
|
||||||
# row.prop(pres_layer, "assigned_items")
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(pres_layer, "identifier")
|
row.prop(pres_layer, "identifier")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@@ -975,6 +980,11 @@ class BIM_PT_presentation_layers(Panel):
|
|||||||
row.prop(pres_layer, "layer_blocked")
|
row.prop(pres_layer, "layer_blocked")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(pres_layer, "layer_styles")
|
row.prop(pres_layer, "layer_styles")
|
||||||
|
|
||||||
|
op = layout.row().operator("bim.update_presentation_layer")
|
||||||
|
op.index = props.active_presentation_layer_index
|
||||||
|
op.pl_name = pres_layer.name
|
||||||
|
op.pl_description = pres_layer.description
|
||||||
else:
|
else:
|
||||||
layout.label(text="Presentation Layer is invalid")
|
layout.label(text="Presentation Layer is invalid")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user