WIP assigning a class now ported over to partial editing and creates an IFC element. See #1222.

This commit is contained in:
Dion Moult
2021-01-04 11:08:15 +11:00
parent af5350bb9f
commit 0c0ffce908
8 changed files with 234 additions and 122 deletions
@@ -12,6 +12,7 @@ class Usecase:
definition = self.settings["product"].Representation
if not definition:
definition = self.file.createIfcProductDefinitionShape()
representations = list(definition.Representations)
self.settings["product"].Representation = definition
representations = list(definition.Representations) if definition.Representations else []
representations.append(self.settings["representation"])
definition.Representations = representations
@@ -6,6 +6,8 @@ class Usecase:
self.settings[key] = value
def execute(self):
if not self.settings["styles"]:
return []
self.results = []
for element in self.file.traverse(self.settings["shape_representation"]):
if not element.is_a("IfcShapeRepresentation"):
@@ -22,20 +22,35 @@ class AddRepresentation(bpy.types.Operator):
self.context_id = bpy.context.scene.BIMProperties.contexts
element = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
usecase = add_representation.Usecase(self.file, {
"context": self.file.by_id(int(self.context_id)),
"geometry": obj.data,
"total_items": max(1, len(obj.material_slots)),
})
usecase = add_representation.Usecase(
self.file,
{
"context": self.file.by_id(int(self.context_id)),
"geometry": obj.data,
"total_items": max(1, len(obj.material_slots)),
},
)
result = usecase.execute()
if not result:
print("Failed to write shape representation")
return {"FINISHED"}
usecase = assign_representation.Usecase(self.file, {
"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
"representation": result
})
usecase = assign_styles.Usecase(
self.file,
{
"shape_representation": result,
"styles": [
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
for s in obj.material_slots
if s.material
],
},
)
usecase.execute()
usecase = assign_representation.Usecase(
self.file, {"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id), "representation": result}
)
usecase.execute()
existing_mesh = obj.data
@@ -116,27 +131,40 @@ class BakeParametricGeometry(bpy.types.Operator):
obj = bpy.context.active_object
self.file = IfcStore.get_file()
usecase = add_object_placement.Usecase(self.file, {
"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
"matrix": np.array(obj.matrix_world)
})
usecase = add_object_placement.Usecase(
self.file,
{
"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
"matrix": np.array(obj.matrix_world),
},
)
result = usecase.execute()
element = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
usecase = add_representation.Usecase(self.file, {
"context": element.ContextOfItems,
"geometry": obj.data,
"total_items": max(1, len(obj.material_slots)),
})
usecase = add_representation.Usecase(
self.file,
{
"context": element.ContextOfItems,
"geometry": obj.data,
"total_items": max(1, len(obj.material_slots)),
},
)
result = usecase.execute()
if not result:
print("Failed to write shape representation")
return {"FINISHED"}
usecase = assign_styles.Usecase(self.file, {
"shape_representation": result,
"styles": [self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id) for s in obj.material_slots if s.material]
})
usecase = assign_styles.Usecase(
self.file,
{
"shape_representation": result,
"styles": [
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
for s in obj.material_slots
if s.material
],
},
)
usecase.execute()
for inverse in self.file.get_inverse(element):
@@ -157,7 +185,7 @@ class UpdateIfcRepresentation(bpy.types.Operator):
props = obj.data.BIMMeshProperties
parameter = props.ifc_parameters[self.index]
element = IfcStore.get_file().by_id(parameter.step_id)[parameter.index] = parameter.value
bpy.ops.bim.switch_representation(ifc_definition_id = props.ifc_definition_id)
bpy.ops.bim.switch_representation(ifc_definition_id=props.ifc_definition_id)
return {"FINISHED"}