Add support for manual classification references for materials

This commit is contained in:
Dion Moult
2024-05-26 17:10:27 +10:00
parent 687bb32e37
commit 9ec8035a8d
5 changed files with 41 additions and 36 deletions
@@ -54,11 +54,11 @@ classes = (
def register(): def register():
bpy.types.Scene.BIMClassificationProperties = bpy.props.PointerProperty(type=prop.BIMClassificationProperties) bpy.types.Scene.BIMClassificationProperties = bpy.props.PointerProperty(type=prop.BIMClassificationProperties)
bpy.types.Object.BIMClassificationReferenceProperties = bpy.props.PointerProperty( bpy.types.Scene.BIMClassificationReferenceProperties = bpy.props.PointerProperty(
type=prop.BIMClassificationReferenceProperties type=prop.BIMClassificationReferenceProperties
) )
def unregister(): def unregister():
del bpy.types.Scene.BIMClassificationProperties del bpy.types.Scene.BIMClassificationProperties
del bpy.types.Object.BIMClassificationReferenceProperties del bpy.types.Scene.BIMClassificationReferenceProperties
@@ -88,7 +88,7 @@ class ClassificationReferencesData(ReferencesData):
cls.data["references"] = cls.references() cls.data["references"] = cls.references()
cls.data["active_classification_library"] = cls.active_classification_library() cls.data["active_classification_library"] = cls.active_classification_library()
cls.data["classifications"] = cls.classifications() cls.data["classifications"] = cls.classifications()
cls.data["object_type"] = "OBJECT" cls.data["object_type"] = "Object"
@classmethod @classmethod
def references(cls): def references(cls):
@@ -112,7 +112,7 @@ class MaterialClassificationsData(ReferencesData):
cls.data["references"] = cls.references() cls.data["references"] = cls.references()
cls.data["active_classification_library"] = cls.active_classification_library() cls.data["active_classification_library"] = cls.active_classification_library()
cls.data["classifications"] = cls.classifications() cls.data["classifications"] = cls.classifications()
cls.data["object_type"] = "MATERIAL" cls.data["object_type"] = "Material"
@classmethod @classmethod
def references(cls): def references(cls):
@@ -140,7 +140,7 @@ class CostClassificationsData(ReferencesData):
cls.data["references"] = cls.references() cls.data["references"] = cls.references()
cls.data["active_classification_library"] = cls.active_classification_library() cls.data["active_classification_library"] = cls.active_classification_library()
cls.data["classifications"] = cls.classifications() cls.data["classifications"] = cls.classifications()
cls.data["object_type"] = "COST" cls.data["object_type"] = "Cost"
@classmethod @classmethod
def references(cls): def references(cls):
@@ -77,26 +77,37 @@ class AddManualClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.add_manual_classification_reference" bl_idname = "bim.add_manual_classification_reference"
bl_label = "Add Manual Classification Reference" bl_label = "Add Manual Classification Reference"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
obj_type: bpy.props.StringProperty() obj_type: bpy.props.StringProperty()
def _execute(self, context): def _execute(self, context):
obj = context.active_object if self.obj_type == "Object":
props = obj.BIMClassificationReferenceProperties if context.selected_objects:
objects = [o.name for o in context.selected_objects]
else:
objects = [context.active_object.name]
else:
objects = [self.obj]
props = context.scene.BIMClassificationReferenceProperties
attributes = blenderbim.bim.helper.export_attributes(props.reference_attributes) attributes = blenderbim.bim.helper.export_attributes(props.reference_attributes)
product = tool.Ifc.get_entity(obj) products = [
# TODO: refactor and support material and cost item classifications tool.Ifc.get().by_id(ifc_definition_id)
classification = tool.Ifc.get().by_id(int(props.classifications)) for obj in objects
reference = ifcopenshell.api.run( if (ifc_definition_id := tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context))
"classification.add_reference", ]
tool.Ifc.get(), if products:
products=[product], classification = tool.Ifc.get().by_id(int(props.classifications))
classification=classification, reference = ifcopenshell.api.run(
identification="X", "classification.add_reference",
name="Unnamed", tool.Ifc.get(),
) products=products,
ifcopenshell.api.run( classification=classification,
"classification.edit_reference", tool.Ifc.get(), reference=reference, attributes=attributes identification="X",
) name="Unnamed",
)
ifcopenshell.api.run(
"classification.edit_reference", tool.Ifc.get(), reference=reference, attributes=attributes
)
props.is_adding = False props.is_adding = False
@@ -150,8 +161,7 @@ class EnableAddingManualClassificationReference(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
def execute(self, context): def execute(self, context):
obj = context.active_object props = context.scene.BIMClassificationReferenceProperties
props = obj.BIMClassificationReferenceProperties
props.is_adding = True props.is_adding = True
props.reference_attributes.clear() props.reference_attributes.clear()
blenderbim.bim.helper.import_attributes2("IfcClassificationReference", props.reference_attributes) blenderbim.bim.helper.import_attributes2("IfcClassificationReference", props.reference_attributes)
@@ -164,8 +174,7 @@ class DisableAddingManualClassificationReference(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
def execute(self, context): def execute(self, context):
obj = context.active_object props = context.scene.BIMClassificationReferenceProperties
props = obj.BIMClassificationReferenceProperties
props.is_adding = False props.is_adding = False
return {"FINISHED"} return {"FINISHED"}
@@ -257,8 +266,7 @@ class EnableEditingClassificationReference(bpy.types.Operator):
obj: bpy.props.StringProperty() obj: bpy.props.StringProperty()
def execute(self, context): def execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object props = context.scene.BIMClassificationReferenceProperties
props = obj.BIMClassificationReferenceProperties
props.reference_attributes.clear() props.reference_attributes.clear()
blenderbim.bim.helper.import_attributes2(tool.Ifc.get().by_id(self.reference), props.reference_attributes) blenderbim.bim.helper.import_attributes2(tool.Ifc.get().by_id(self.reference), props.reference_attributes)
props.active_reference_id = self.reference props.active_reference_id = self.reference
@@ -272,8 +280,7 @@ class DisableEditingClassificationReference(bpy.types.Operator):
obj: bpy.props.StringProperty() obj: bpy.props.StringProperty()
def execute(self, context): def execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object context.scene.BIMClassificationReferenceProperties.active_reference_id = 0
obj.BIMClassificationReferenceProperties.active_reference_id = 0
return {"FINISHED"} return {"FINISHED"}
@@ -326,8 +333,7 @@ class EditClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
obj: bpy.props.StringProperty() obj: bpy.props.StringProperty()
def _execute(self, context): def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object props = context.scene.BIMClassificationReferenceProperties
props = obj.BIMClassificationReferenceProperties
attributes = {} attributes = {}
for attribute in props.reference_attributes: for attribute in props.reference_attributes:
if attribute.is_null: if attribute.is_null:
@@ -368,9 +374,8 @@ class AddClassificationReference(bpy.types.Operator, tool.Ifc.Operator):
classification = element classification = element
break break
ifc_file = tool.Ifc.get()
products = [ products = [
ifc_file.by_id(ifc_definition_id) tool.Ifc.get().by_id(ifc_definition_id)
for obj in objects for obj in objects
if (ifc_definition_id := tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context)) if (ifc_definition_id := tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context))
] ]
@@ -120,7 +120,7 @@ class ReferenceUI:
obj = context.active_object obj = context.active_object
self.sprops = context.scene.BIMClassificationProperties self.sprops = context.scene.BIMClassificationProperties
self.bprops = context.scene.BIMBSDDProperties self.bprops = context.scene.BIMBSDDProperties
self.props = obj.BIMClassificationReferenceProperties self.props = context.scene.BIMClassificationReferenceProperties
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
self.draw_add_ui(context) self.draw_add_ui(context)
@@ -318,7 +318,7 @@ class BIM_PT_material_classifications(Panel, ReferenceUI):
class BIM_PT_cost_classifications(Panel, ReferenceUI): class BIM_PT_cost_classifications(Panel, ReferenceUI):
bl_label = "Cost Classifications" bl_label = "Cost Item Classifications"
bl_idname = "BIM_PT_cost_classifications" bl_idname = "BIM_PT_cost_classifications"
bl_options = {"DEFAULT_CLOSED"} bl_options = {"DEFAULT_CLOSED"}
bl_space_type = "PROPERTIES" bl_space_type = "PROPERTIES"
@@ -79,7 +79,7 @@ def register():
def unregister(): def unregister():
del bpy.types.Object.PsetProperties del bpy.types.Object.PsetProperties
del bpy.types.Object.MaterialPsetProperties del bpy.types.Scene.MaterialPsetProperties
del bpy.types.Object.MaterialSetPsetProperties del bpy.types.Object.MaterialSetPsetProperties
del bpy.types.Object.MaterialSetItemPsetProperties del bpy.types.Object.MaterialSetItemPsetProperties
del bpy.types.Scene.TaskPsetProperties del bpy.types.Scene.TaskPsetProperties