mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Notify if file already contains library element (#1708)
* Notify if file already contains library element * Minor fix. See #1711. * Test util.element module. See #1711. * Test IFC file module. See #1711. * Minor fix. See #1711. * Move logic into operators Co-authored-by: Dion Moult <dion@thinkmoult.com>
This commit is contained in:
@@ -204,11 +204,13 @@ class ChangeLibraryElement(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.props = context.scene.BIMProjectProperties
|
self.props = context.scene.BIMProjectProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
self.library_file = IfcStore.library_file
|
||||||
ifc_classes = set()
|
ifc_classes = set()
|
||||||
self.props.active_library_element = self.element_name
|
self.props.active_library_element = self.element_name
|
||||||
crumb = self.props.library_breadcrumb.add()
|
crumb = self.props.library_breadcrumb.add()
|
||||||
crumb.name = self.element_name
|
crumb.name = self.element_name
|
||||||
elements = IfcStore.library_file.by_type(self.element_name)
|
elements = self.library_file.by_type(self.element_name)
|
||||||
[ifc_classes.add(e.is_a()) for e in elements]
|
[ifc_classes.add(e.is_a()) for e in elements]
|
||||||
self.props.library_elements.clear()
|
self.props.library_elements.clear()
|
||||||
if len(ifc_classes) == 1 and list(ifc_classes)[0] == self.element_name:
|
if len(ifc_classes) == 1 and list(ifc_classes)[0] == self.element_name:
|
||||||
@@ -234,11 +236,21 @@ class ChangeLibraryElement(bpy.types.Operator):
|
|||||||
new = self.props.library_elements.add()
|
new = self.props.library_elements.add()
|
||||||
new.name = name
|
new.name = name
|
||||||
new.ifc_definition_id = ifc_definition_id
|
new.ifc_definition_id = ifc_definition_id
|
||||||
element = IfcStore.library_file.by_id(ifc_definition_id)
|
element = self.library_file.by_id(ifc_definition_id)
|
||||||
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
if self.library_file.schema == "IFC2X3" or not self.library_file.by_type("IfcProjectLibrary"):
|
||||||
new.is_declared = False
|
new.is_declared = False
|
||||||
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a("IfcProjectLibrary"):
|
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a("IfcProjectLibrary"):
|
||||||
new.is_declared = True
|
new.is_declared = True
|
||||||
|
try:
|
||||||
|
if element.is_a("IfcMaterial"):
|
||||||
|
next(e for e in self.file.by_type("IfcMaterial") if e.Name == name)
|
||||||
|
elif element.is_a("IfcProfileDef"):
|
||||||
|
next(e for e in self.file.by_type("IfcProfileDef") if e.ProfileName == name)
|
||||||
|
else:
|
||||||
|
self.file.by_guid(element.GlobalId)
|
||||||
|
new.is_appended = True
|
||||||
|
except (AttributeError, RuntimeError, StopIteration):
|
||||||
|
new.is_appended = False
|
||||||
|
|
||||||
|
|
||||||
class RewindLibrary(bpy.types.Operator):
|
class RewindLibrary(bpy.types.Operator):
|
||||||
@@ -345,6 +357,7 @@ class AppendLibraryElement(bpy.types.Operator):
|
|||||||
bl_label = "Append Library Element"
|
bl_label = "Append Library Element"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
definition: bpy.props.IntProperty()
|
definition: bpy.props.IntProperty()
|
||||||
|
prop_index: bpy.props.IntProperty()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -367,6 +380,7 @@ class AppendLibraryElement(bpy.types.Operator):
|
|||||||
self.import_type_from_ifc(element, context)
|
self.import_type_from_ifc(element, context)
|
||||||
elif element.is_a("IfcMaterial"):
|
elif element.is_a("IfcMaterial"):
|
||||||
self.import_material_from_ifc(element, context)
|
self.import_material_from_ifc(element, context)
|
||||||
|
context.scene.BIMProjectProperties.library_elements[self.prop_index].is_appended = True
|
||||||
blenderbim.bim.handler.purge_module_data()
|
blenderbim.bim.handler.purge_module_data()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class LibraryElement(PropertyGroup):
|
|||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
is_declared: BoolProperty(name="Is Declared", default=False)
|
is_declared: BoolProperty(name="Is Declared", default=False)
|
||||||
|
is_appended: BoolProperty(name="Is Appended", default=False)
|
||||||
|
|
||||||
|
|
||||||
class BIMProjectProperties(PropertyGroup):
|
class BIMProjectProperties(PropertyGroup):
|
||||||
@@ -51,3 +52,6 @@ class BIMProjectProperties(PropertyGroup):
|
|||||||
library_breadcrumb: CollectionProperty(name="Library Breadcrumb", type=StrProperty)
|
library_breadcrumb: CollectionProperty(name="Library Breadcrumb", type=StrProperty)
|
||||||
library_elements: CollectionProperty(name="Library Elements", type=LibraryElement)
|
library_elements: CollectionProperty(name="Library Elements", type=LibraryElement)
|
||||||
active_library_element_index: IntProperty(name="Active Library Element Index")
|
active_library_element_index: IntProperty(name="Active Library Element Index")
|
||||||
|
|
||||||
|
def get_library_element_index(self, lib_element):
|
||||||
|
return next((i for i in range(len(self.library_elements)) if self.library_elements[i] == lib_element))
|
||||||
|
|||||||
@@ -178,5 +178,9 @@ class BIM_UL_library(UIList):
|
|||||||
op = row.operator("bim.assign_library_declaration", text="", icon="KEYFRAME", emboss=False)
|
op = row.operator("bim.assign_library_declaration", text="", icon="KEYFRAME", emboss=False)
|
||||||
op.definition = item.ifc_definition_id
|
op.definition = item.ifc_definition_id
|
||||||
if item.ifc_definition_id:
|
if item.ifc_definition_id:
|
||||||
op = row.operator("bim.append_library_element", text="", icon="APPEND_BLEND")
|
if item.is_appended:
|
||||||
op.definition = item.ifc_definition_id
|
row.label(text="", icon="CHECKMARK")
|
||||||
|
else:
|
||||||
|
op = row.operator("bim.append_library_element", text="", icon="APPEND_BLEND")
|
||||||
|
op.definition = item.ifc_definition_id
|
||||||
|
op.prop_index = data.get_library_element_index(item)
|
||||||
|
|||||||
Reference in New Issue
Block a user