mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Add ability to map representations. See #1222.
This commit is contained in:
@@ -4,6 +4,7 @@ from . import ui, prop, operator
|
||||
classes = (
|
||||
operator.EditObjectPlacement,
|
||||
operator.AddRepresentation,
|
||||
operator.MapRepresentation,
|
||||
operator.SwitchRepresentation,
|
||||
operator.RemoveRepresentation,
|
||||
operator.UpdateMeshRepresentation,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"representation": None,
|
||||
}
|
||||
self.ifc_vertices = []
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
self.get_mapping_source()
|
||||
|
||||
self.zero = self.file.createIfcCartesianPoint((0.0, 0.0, 0.0))
|
||||
self.x_axis = self.file.createIfcDirection((1.0, 0.0, 0.0))
|
||||
self.y_axis = self.file.createIfcDirection((0.0, 1.0, 0.0))
|
||||
self.z_axis = self.file.createIfcDirection((0.0, 0.0, 1.0))
|
||||
mapping_target = self.file.createIfcCartesianTransformationOperator3D(
|
||||
self.x_axis, self.y_axis, self.zero, 1, self.z_axis
|
||||
)
|
||||
mapped_item = self.file.createIfcMappedItem(self.get_mapping_source(), mapping_target)
|
||||
return self.file.create_entity(
|
||||
"IfcShapeRepresentation",
|
||||
**{
|
||||
"ContextOfItems": self.settings["representation"].ContextOfItems,
|
||||
"RepresentationIdentifier": self.settings["representation"].RepresentationIdentifier,
|
||||
"RepresentationType": "MappedRepresentation",
|
||||
"Items": [mapped_item],
|
||||
}
|
||||
)
|
||||
|
||||
def get_mapping_source(self):
|
||||
if self.settings["representation"].RepresentationMap:
|
||||
return self.settings["representation"].RepresentationMap[0]
|
||||
return self.file.create_entity(
|
||||
"IfcRepresentationMap",
|
||||
**{
|
||||
"MappingOrigin": self.file.createIfcAxis2Placement3D(zero, z_axis, x_axis),
|
||||
"MappedRepresentation": self.settings["representation"],
|
||||
}
|
||||
)
|
||||
@@ -4,6 +4,7 @@ import ifcopenshell
|
||||
import logging
|
||||
import blenderbim.bim.module.geometry.edit_object_placement as edit_object_placement
|
||||
import blenderbim.bim.module.geometry.add_representation as add_representation
|
||||
import blenderbim.bim.module.geometry.map_representation as map_representation
|
||||
import blenderbim.bim.module.geometry.assign_styles as assign_styles
|
||||
import blenderbim.bim.module.geometry.assign_representation as assign_representation
|
||||
import blenderbim.bim.module.geometry.remove_representation as remove_representation
|
||||
@@ -174,6 +175,37 @@ class RemoveRepresentation(bpy.types.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class MapRepresentation(bpy.types.Operator):
|
||||
bl_idname = "bim.map_representation"
|
||||
bl_label = "Map Representation"
|
||||
obj: bpy.props.StringProperty()
|
||||
target_obj: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
objs = [bpy.data.objects.get(self.obj)] if self.obj else bpy.context.selected_objects
|
||||
target_obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object
|
||||
objs = [o for o in objs if o != target_obj]
|
||||
self.file = IfcStore.get_file()
|
||||
|
||||
for obj in objs:
|
||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
target_representation = self.file.by_id(target_obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
obj.data = target_obj.data
|
||||
result = map_representation.Usecase(
|
||||
self.file,
|
||||
{
|
||||
"product": product,
|
||||
"representation": target_representation,
|
||||
},
|
||||
).execute()
|
||||
assign_representation.Usecase(self.file, {"product": product, "representation": result}).execute()
|
||||
bpy.ops.bim.remove_representation(ifc_definition_id=old_representation.id())
|
||||
Data.load(obj.BIMObjectProperties.ifc_definition_id)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class UpdateMeshRepresentation(bpy.types.Operator):
|
||||
bl_idname = "bim.update_mesh_representation"
|
||||
bl_label = "Update Mesh Representation"
|
||||
|
||||
@@ -14,4 +14,23 @@ class Usecase:
|
||||
[self.file.remove(s) for s in subelement.StyledByItem]
|
||||
elif subelement.is_a("IfcRepresentation"):
|
||||
subelement.ContextOfItems = dummy_context
|
||||
self.purge_representation_inverses(subelement)
|
||||
self.purge_representation_inverses(self.settings["representation"])
|
||||
ifcopenshell.util.element.remove_deep(self.file, self.settings["representation"])
|
||||
|
||||
def purge_representation_inverses(self, element):
|
||||
for inverse in self.file.get_inverse(element):
|
||||
if inverse.is_a("IfcPresentationLayerAssignment"):
|
||||
assigned_items = set(inverse.AssignedItems)
|
||||
if len(assigned_items) == 1:
|
||||
self.file.remove(inverse)
|
||||
else:
|
||||
assigned_items.remove(element)
|
||||
inverse.AssignedItems == list(assigned_items)
|
||||
elif inverse.is_a("IfcProductRepresentation"):
|
||||
representations = set(inverse.Representations)
|
||||
if len(representations) == 1:
|
||||
self.file.remove(inverse)
|
||||
else:
|
||||
representations.remove(element)
|
||||
inverse.Representations = list(representations)
|
||||
|
||||
@@ -68,6 +68,8 @@ class BIM_PT_mesh(Panel):
|
||||
row.operator("bim.get_representation_ifc_parameters")
|
||||
row = layout.row()
|
||||
row.operator("bim.update_mesh_representation")
|
||||
row = layout.row()
|
||||
row.operator("bim.map_representation")
|
||||
for index, ifc_parameter in enumerate(props.ifc_parameters):
|
||||
row = layout.row(align=True)
|
||||
row.prop(ifc_parameter, "name", text="")
|
||||
|
||||
@@ -107,6 +107,7 @@ class VIEW3D_MT_PIE_bim(bpy.types.Menu):
|
||||
pie = self.layout.menu_pie()
|
||||
pie.operator("bim.edit_object_placement")
|
||||
pie.operator("bim.update_mesh_representation")
|
||||
pie.operator("bim.map_representation")
|
||||
pie.operator("bim.pie_add_opening")
|
||||
pie.operator("bim.pie_update_container")
|
||||
pie.operator("bim.open_pie_class", text="Assign IFC Class")
|
||||
|
||||
Reference in New Issue
Block a user