2021-01-05 21:15:52 +11:00
|
|
|
import bpy
|
2021-01-20 16:53:34 +11:00
|
|
|
import logging
|
2021-01-05 21:15:52 +11:00
|
|
|
import ifcopenshell
|
2021-03-27 22:52:52 +11:00
|
|
|
import ifcopenshell.api
|
2021-06-30 18:34:12 +10:00
|
|
|
import ifcopenshell.util.representation
|
2021-01-05 21:15:52 +11:00
|
|
|
import bpy
|
2021-06-18 15:54:01 +10:00
|
|
|
import blenderbim.bim.handler
|
2021-01-05 21:15:52 +11:00
|
|
|
from blenderbim.bim.ifc import IfcStore
|
2021-04-21 16:45:11 +10:00
|
|
|
from blenderbim.bim import import_ifc
|
2021-01-05 21:15:52 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CreateProject(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.create_project"
|
|
|
|
|
bl_label = "Create Project"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-01-05 21:15:52 +11:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
|
|
|
|
IfcStore.add_transaction_operation(self, rollback=self.rollback, commit=lambda data: True)
|
2021-07-01 20:43:16 +10:00
|
|
|
result = self._execute(context)
|
|
|
|
|
self.transaction_data = {"file": self.file}
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self, rollback=lambda data: True, commit=self.commit)
|
|
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-01-05 21:15:52 +11:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
if self.file:
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-03-27 22:52:52 +11:00
|
|
|
IfcStore.file = ifcopenshell.api.run(
|
2021-07-29 23:08:17 +02:00
|
|
|
"project.create_file", **{"version": context.scene.BIMProperties.export_schema}
|
2021-03-27 22:52:52 +11:00
|
|
|
)
|
2021-01-05 21:15:52 +11:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
|
2021-01-26 13:56:38 +11:00
|
|
|
bpy.ops.bim.add_person()
|
|
|
|
|
bpy.ops.bim.add_organisation()
|
|
|
|
|
|
2021-07-28 18:43:20 +10:00
|
|
|
project = bpy.data.objects.new(self.get_name("IfcProject", "My Project"), None)
|
|
|
|
|
site = bpy.data.objects.new(self.get_name("IfcSite", "My Site"), None)
|
|
|
|
|
building = bpy.data.objects.new(self.get_name("IfcBuilding", "My Building"), None)
|
|
|
|
|
building_storey = bpy.data.objects.new(self.get_name("IfcBuildingStorey", "My Storey"), None)
|
2021-01-05 21:15:52 +11:00
|
|
|
|
2021-07-02 19:10:51 +10:00
|
|
|
bpy.ops.bim.assign_class(obj=project.name, ifc_class="IfcProject")
|
2021-01-05 21:15:52 +11:00
|
|
|
bpy.ops.bim.assign_unit()
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model", subcontext="Body", target_view="MODEL_VIEW")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Model", subcontext="Box", target_view="MODEL_VIEW")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Plan")
|
|
|
|
|
bpy.ops.bim.add_subcontext(context="Plan", subcontext="Annotation", target_view="PLAN_VIEW")
|
2021-01-06 15:19:55 +11:00
|
|
|
|
2021-07-29 23:08:17 +02:00
|
|
|
context.scene.BIMProperties.contexts = str(
|
2021-06-30 18:34:12 +10:00
|
|
|
ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW").id()
|
|
|
|
|
)
|
2021-01-06 15:19:55 +11:00
|
|
|
|
2021-07-02 19:10:51 +10:00
|
|
|
bpy.ops.bim.assign_class(obj=site.name, ifc_class="IfcSite")
|
|
|
|
|
bpy.ops.bim.assign_class(obj=building.name, ifc_class="IfcBuilding")
|
|
|
|
|
bpy.ops.bim.assign_class(obj=building_storey.name, ifc_class="IfcBuildingStorey")
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=site.name, relating_object=project.name)
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=building.name, relating_object=site.name)
|
|
|
|
|
bpy.ops.bim.assign_object(related_object=building_storey.name, relating_object=building.name)
|
2021-06-30 18:34:12 +10:00
|
|
|
|
2021-01-05 21:15:52 +11:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-07-28 18:43:20 +10:00
|
|
|
def get_name(self, ifc_class, name):
|
|
|
|
|
if not bpy.data.objects.get(f"{ifc_class}/{name}"):
|
|
|
|
|
return name
|
|
|
|
|
i = 2
|
|
|
|
|
while bpy.data.objects.get(f"{ifc_class}/{name} {i}"):
|
|
|
|
|
i += 1
|
|
|
|
|
return f"{name} {i}"
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def rollback(self, data):
|
|
|
|
|
IfcStore.file = None
|
|
|
|
|
|
|
|
|
|
def commit(self, data):
|
|
|
|
|
IfcStore.file = data["file"]
|
|
|
|
|
|
2021-01-20 16:53:34 +11:00
|
|
|
|
2021-04-11 21:56:45 +10:00
|
|
|
class CreateProjectLibrary(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.create_project_library"
|
|
|
|
|
bl_label = "Create Project Library"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-11 21:56:45 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
|
|
|
|
IfcStore.add_transaction_operation(self, rollback=self.rollback, commit=lambda data: True)
|
2021-07-01 20:43:16 +10:00
|
|
|
result = self._execute(context)
|
|
|
|
|
self.transaction_data = {"file": self.file}
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self, rollback=lambda data: True, commit=self.commit)
|
|
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-04-11 21:56:45 +10:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
if self.file:
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
IfcStore.file = ifcopenshell.api.run(
|
2021-07-29 23:08:17 +02:00
|
|
|
"project.create_file", **{"version": context.scene.BIMProperties.export_schema}
|
2021-04-11 21:56:45 +10:00
|
|
|
)
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
|
|
|
|
|
if self.file.schema == "IFC2X3":
|
|
|
|
|
bpy.ops.bim.add_person()
|
|
|
|
|
bpy.ops.bim.add_organisation()
|
|
|
|
|
|
|
|
|
|
project_library = bpy.data.objects.new("My Project Library", None)
|
2021-07-02 19:10:51 +10:00
|
|
|
bpy.ops.bim.assign_class(obj=project_library.name, ifc_class="IfcProjectLibrary")
|
2021-04-11 21:56:45 +10:00
|
|
|
bpy.ops.bim.assign_unit()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def rollback(self, data):
|
|
|
|
|
IfcStore.file = None
|
2021-04-11 21:56:45 +10:00
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def commit(self, data):
|
|
|
|
|
IfcStore.file = data["file"]
|
2021-04-20 12:45:20 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class SelectLibraryFile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.select_library_file"
|
|
|
|
|
bl_label = "Select Library File"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-20 12:45:20 +10:00
|
|
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
|
|
|
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
2021-06-30 18:34:12 +10:00
|
|
|
old_filepath = IfcStore.library_path
|
2021-07-01 20:43:16 +10:00
|
|
|
result = self._execute(context)
|
|
|
|
|
self.transaction_data = {"old_filepath": old_filepath, "filepath": self.filepath}
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self)
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-04-20 12:45:20 +10:00
|
|
|
IfcStore.library_path = self.filepath
|
|
|
|
|
IfcStore.library_file = ifcopenshell.open(self.filepath)
|
|
|
|
|
bpy.ops.bim.refresh_library()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
|
|
context.window_manager.fileselect_add(self)
|
|
|
|
|
return {"RUNNING_MODAL"}
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def rollback(self, data):
|
|
|
|
|
if data["old_filepath"]:
|
|
|
|
|
IfcStore.library_path = data["old_filepath"]
|
|
|
|
|
IfcStore.library_file = ifcopenshell.open(data["old_filepath"])
|
|
|
|
|
else:
|
|
|
|
|
IfcStore.library_path = ""
|
|
|
|
|
IfcStore.library_file = None
|
|
|
|
|
|
|
|
|
|
def commit(self, data):
|
|
|
|
|
IfcStore.library_path = data["filepath"]
|
|
|
|
|
IfcStore.library_file = ifcopenshell.open(data["filepath"])
|
|
|
|
|
|
2021-04-20 12:45:20 +10:00
|
|
|
|
|
|
|
|
class RefreshLibrary(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.refresh_library"
|
|
|
|
|
bl_label = "Refresh Library"
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.props = context.scene.BIMProjectProperties
|
|
|
|
|
|
|
|
|
|
while len(self.props.library_elements) > 0:
|
|
|
|
|
self.props.library_elements.remove(0)
|
|
|
|
|
|
|
|
|
|
while len(self.props.library_breadcrumb) > 0:
|
|
|
|
|
self.props.library_breadcrumb.remove(0)
|
|
|
|
|
|
|
|
|
|
self.props.active_library_element = ""
|
|
|
|
|
|
|
|
|
|
types = IfcStore.library_file.wrapped_data.types_with_super()
|
2021-08-14 12:05:59 +10:00
|
|
|
for importable_type in ["IfcTypeProduct", "IfcMaterial", "IfcCostSchedule", "IfcProfileDef"]:
|
2021-08-09 11:17:10 +10:00
|
|
|
if importable_type in types:
|
|
|
|
|
new = self.props.library_elements.add()
|
|
|
|
|
new.name = importable_type
|
2021-04-20 12:45:20 +10:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeLibraryElement(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.change_library_element"
|
|
|
|
|
bl_label = "Change Library Element"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-20 12:45:20 +10:00
|
|
|
element_name: bpy.props.StringProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.props = context.scene.BIMProjectProperties
|
|
|
|
|
ifc_classes = set()
|
|
|
|
|
self.props.active_library_element = self.element_name
|
|
|
|
|
crumb = self.props.library_breadcrumb.add()
|
|
|
|
|
crumb.name = self.element_name
|
|
|
|
|
elements = IfcStore.library_file.by_type(self.element_name)
|
|
|
|
|
[ifc_classes.add(e.is_a()) for e in elements]
|
|
|
|
|
while len(self.props.library_elements) > 0:
|
|
|
|
|
self.props.library_elements.remove(0)
|
2021-06-18 16:05:58 +10:00
|
|
|
if len(ifc_classes) == 1 and list(ifc_classes)[0] == self.element_name:
|
2021-04-20 12:45:20 +10:00
|
|
|
for element in elements:
|
|
|
|
|
new = self.props.library_elements.add()
|
2021-08-14 12:05:59 +10:00
|
|
|
if element.is_a("IfcProfileDef"):
|
|
|
|
|
new.name = element.ProfileName or "Unnamed"
|
|
|
|
|
else:
|
|
|
|
|
new.name = element.Name or "Unnamed"
|
2021-04-20 12:45:20 +10:00
|
|
|
new.ifc_definition_id = element.id()
|
2021-04-20 13:51:41 +10:00
|
|
|
if IfcStore.library_file.schema == "IFC2X3" or not IfcStore.library_file.by_type("IfcProjectLibrary"):
|
|
|
|
|
new.is_declared = False
|
2021-08-09 11:17:10 +10:00
|
|
|
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a(
|
|
|
|
|
"IfcProjectLibrary"
|
|
|
|
|
):
|
2021-04-20 13:51:41 +10:00
|
|
|
new.is_declared = True
|
2021-04-20 12:45:20 +10:00
|
|
|
else:
|
|
|
|
|
for ifc_class in ifc_classes:
|
|
|
|
|
new = self.props.library_elements.add()
|
|
|
|
|
new.name = ifc_class
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RewindLibrary(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.rewind_library"
|
|
|
|
|
bl_label = "Rewind Library"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-20 12:45:20 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.props = context.scene.BIMProjectProperties
|
|
|
|
|
total_breadcrumbs = len(self.props.library_breadcrumb)
|
|
|
|
|
if total_breadcrumbs < 2:
|
|
|
|
|
bpy.ops.bim.refresh_library()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
element_name = self.props.library_breadcrumb[total_breadcrumbs - 2].name
|
|
|
|
|
self.props.library_breadcrumb.remove(total_breadcrumbs - 1)
|
|
|
|
|
self.props.library_breadcrumb.remove(total_breadcrumbs - 2)
|
2021-04-20 13:51:41 +10:00
|
|
|
bpy.ops.bim.change_library_element(element_name=element_name)
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AssignLibraryDeclaration(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.assign_library_declaration"
|
|
|
|
|
bl_label = "Assign Library Declaration"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-20 13:51:41 +10:00
|
|
|
definition: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
IfcStore.library_file.begin_transaction()
|
|
|
|
|
result = self._execute(context)
|
|
|
|
|
IfcStore.library_file.end_transaction()
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self)
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-04-20 13:51:41 +10:00
|
|
|
self.props = context.scene.BIMProjectProperties
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file = IfcStore.library_file
|
2021-04-20 13:51:41 +10:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"project.assign_declaration",
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file,
|
|
|
|
|
definition=self.file.by_id(self.definition),
|
|
|
|
|
relating_context=self.file.by_type("IfcProjectLibrary")[0],
|
2021-04-20 13:51:41 +10:00
|
|
|
)
|
|
|
|
|
element_name = self.props.active_library_element
|
|
|
|
|
bpy.ops.bim.rewind_library()
|
2021-06-30 18:34:12 +10:00
|
|
|
bpy.ops.bim.change_library_element(element_name=element_name)
|
2021-04-20 12:45:20 +10:00
|
|
|
return {"FINISHED"}
|
2021-04-20 13:51:41 +10:00
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def rollback(self, data):
|
|
|
|
|
IfcStore.library_file.undo()
|
|
|
|
|
|
|
|
|
|
def commit(self, data):
|
|
|
|
|
IfcStore.library_file.redo()
|
|
|
|
|
|
2021-04-20 13:51:41 +10:00
|
|
|
|
|
|
|
|
class UnassignLibraryDeclaration(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.unassign_library_declaration"
|
|
|
|
|
bl_label = "Unassign Library Declaration"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-20 13:51:41 +10:00
|
|
|
definition: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
IfcStore.library_file.begin_transaction()
|
|
|
|
|
result = self._execute(context)
|
|
|
|
|
IfcStore.library_file.end_transaction()
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self)
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-04-20 13:51:41 +10:00
|
|
|
self.props = context.scene.BIMProjectProperties
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file = IfcStore.library_file
|
2021-04-20 13:51:41 +10:00
|
|
|
ifcopenshell.api.run(
|
|
|
|
|
"project.unassign_declaration",
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file,
|
|
|
|
|
definition=self.file.by_id(self.definition),
|
|
|
|
|
relating_context=self.file.by_type("IfcProjectLibrary")[0],
|
2021-04-20 13:51:41 +10:00
|
|
|
)
|
|
|
|
|
element_name = self.props.active_library_element
|
|
|
|
|
bpy.ops.bim.rewind_library()
|
2021-06-30 18:34:12 +10:00
|
|
|
bpy.ops.bim.change_library_element(element_name=element_name)
|
2021-04-20 13:51:41 +10:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def rollback(self, data):
|
|
|
|
|
IfcStore.library_file.undo()
|
|
|
|
|
|
|
|
|
|
def commit(self, data):
|
|
|
|
|
IfcStore.library_file.redo()
|
|
|
|
|
|
2021-04-20 13:51:41 +10:00
|
|
|
|
|
|
|
|
class SaveLibraryFile(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.save_library_file"
|
|
|
|
|
bl_label = "Save Library File"
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
IfcStore.library_file.write(IfcStore.library_path)
|
|
|
|
|
return {"FINISHED"}
|
2021-04-21 16:45:11 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppendLibraryElement(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.append_library_element"
|
|
|
|
|
bl_label = "Append Library Element"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-04-21 16:45:11 +10:00
|
|
|
definition: bpy.props.IntProperty()
|
|
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-01 20:43:16 +10:00
|
|
|
return IfcStore.execute_ifc_operator(self, context)
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file = IfcStore.get_file()
|
2021-04-21 16:45:11 +10:00
|
|
|
element = ifcopenshell.api.run(
|
|
|
|
|
"project.append_asset",
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file,
|
2021-06-18 15:54:01 +10:00
|
|
|
library=IfcStore.library_file,
|
2021-04-21 16:45:11 +10:00
|
|
|
element=IfcStore.library_file.by_id(self.definition),
|
|
|
|
|
)
|
2021-08-07 18:37:45 +10:00
|
|
|
if not element:
|
|
|
|
|
return {"FINISHED"}
|
2021-08-09 11:17:10 +10:00
|
|
|
if element.is_a("IfcTypeProduct"):
|
|
|
|
|
self.import_type_from_ifc(element, context)
|
|
|
|
|
elif element.is_a("IfcMaterial"):
|
|
|
|
|
self.import_material_from_ifc(element, context)
|
2021-06-18 15:54:01 +10:00
|
|
|
blenderbim.bim.handler.purge_module_data()
|
2021-04-21 16:45:11 +10:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-08-09 11:17:10 +10:00
|
|
|
def import_material_from_ifc(self, element, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
logger = logging.getLogger("ImportIFC")
|
|
|
|
|
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
|
|
|
|
|
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
|
|
|
|
ifc_importer.file = self.file
|
|
|
|
|
blender_material = ifc_importer.create_material(element)
|
|
|
|
|
self.import_material_styles(blender_material, element, ifc_importer)
|
|
|
|
|
|
2021-07-29 23:08:17 +02:00
|
|
|
def import_type_from_ifc(self, element, context):
|
2021-04-21 16:45:11 +10:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
logger = logging.getLogger("ImportIFC")
|
2021-07-29 23:08:17 +02:00
|
|
|
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
|
2021-04-21 16:45:11 +10:00
|
|
|
|
|
|
|
|
type_collection = bpy.data.collections.get("Types")
|
|
|
|
|
if not type_collection:
|
|
|
|
|
type_collection = bpy.data.collections.new("Types")
|
|
|
|
|
for collection in bpy.data.collections:
|
|
|
|
|
if "IfcProject/" in collection.name:
|
|
|
|
|
collection.children.link(type_collection)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
|
|
|
|
ifc_importer.file = self.file
|
|
|
|
|
ifc_importer.type_collection = type_collection
|
2021-08-04 20:27:00 +10:00
|
|
|
self.import_type_materials(element, ifc_importer)
|
|
|
|
|
self.import_type_styles(element, ifc_importer)
|
2021-04-21 16:45:11 +10:00
|
|
|
ifc_importer.create_type_product(element)
|
|
|
|
|
ifc_importer.place_objects_in_spatial_tree()
|
2021-05-28 09:50:55 +10:00
|
|
|
|
2021-08-04 20:27:00 +10:00
|
|
|
def import_type_materials(self, element, ifc_importer):
|
|
|
|
|
for rel in element.HasAssociations:
|
|
|
|
|
if not rel.is_a("IfcRelAssociatesMaterial"):
|
|
|
|
|
continue
|
|
|
|
|
for material in [e for e in self.file.traverse(rel) if e.is_a("IfcMaterial")]:
|
|
|
|
|
if IfcStore.get_element(material.id()):
|
|
|
|
|
continue
|
|
|
|
|
blender_material = ifc_importer.create_material(material)
|
|
|
|
|
self.import_material_styles(blender_material, material, ifc_importer)
|
|
|
|
|
|
|
|
|
|
def import_type_styles(self, element, ifc_importer):
|
|
|
|
|
for representation_map in element.RepresentationMaps or []:
|
|
|
|
|
for element in self.file.traverse(representation_map):
|
|
|
|
|
if not element.is_a("IfcRepresentationItem") or not element.StyledByItem:
|
|
|
|
|
continue
|
|
|
|
|
for element2 in self.file.traverse(element.StyledByItem[0]):
|
|
|
|
|
if element2.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element2.id()):
|
|
|
|
|
ifc_importer.create_style(element2)
|
|
|
|
|
|
|
|
|
|
def import_material_styles(self, blender_material, material, ifc_importer):
|
|
|
|
|
if not material.HasRepresentation:
|
|
|
|
|
return
|
|
|
|
|
for element in self.file.traverse(material.HasRepresentation[0]):
|
|
|
|
|
if element.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element.id()):
|
|
|
|
|
ifc_importer.create_style(element, blender_material)
|
|
|
|
|
|
2021-05-28 09:50:55 +10:00
|
|
|
|
|
|
|
|
class EnableEditingHeader(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.enable_editing_header"
|
|
|
|
|
bl_label = "Enable Editing Header"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-05-28 09:50:55 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
props = context.scene.BIMProjectProperties
|
|
|
|
|
props.is_editing = True
|
|
|
|
|
|
|
|
|
|
mvd = "".join(IfcStore.get_file().wrapped_data.header.file_description.description)
|
|
|
|
|
if "[" in mvd:
|
|
|
|
|
props.mvd = mvd.split("[")[1][0:-1]
|
|
|
|
|
else:
|
|
|
|
|
props.mvd = ""
|
|
|
|
|
|
|
|
|
|
author = self.file.wrapped_data.header.file_name.author
|
|
|
|
|
if author:
|
|
|
|
|
props.author_name = author[0]
|
|
|
|
|
if len(author) > 1:
|
|
|
|
|
props.author_email = author[1]
|
|
|
|
|
|
|
|
|
|
organisation = self.file.wrapped_data.header.file_name.organization
|
|
|
|
|
if organisation:
|
|
|
|
|
props.organisation_name = organisation[0]
|
|
|
|
|
if len(organisation) > 1:
|
|
|
|
|
props.organisation_email = organisation[1]
|
|
|
|
|
|
|
|
|
|
props.authorisation = self.file.wrapped_data.header.file_name.authorization
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditHeader(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.edit_header"
|
|
|
|
|
bl_label = "Edit Header"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-05-28 09:50:55 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.begin_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
self.transaction_data = {}
|
|
|
|
|
self.transaction_data["old"] = self.record_state()
|
|
|
|
|
result = self._execute(context)
|
|
|
|
|
self.transaction_data["new"] = self.record_state()
|
2021-07-02 19:10:51 +10:00
|
|
|
IfcStore.add_transaction_operation(self)
|
2021-07-06 14:21:02 +10:00
|
|
|
IfcStore.end_transaction(self)
|
2021-07-01 20:43:16 +10:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def _execute(self, context):
|
2021-05-28 09:50:55 +10:00
|
|
|
self.file = IfcStore.get_file()
|
|
|
|
|
props = context.scene.BIMProjectProperties
|
|
|
|
|
props.is_editing = True
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
self.file.wrapped_data.header.file_description.description = (f"ViewDefinition[{props.mvd}]",)
|
2021-05-28 09:50:55 +10:00
|
|
|
self.file.wrapped_data.header.file_name.author = (props.author_name, props.author_email)
|
|
|
|
|
self.file.wrapped_data.header.file_name.organization = (props.organisation_name, props.organisation_email)
|
|
|
|
|
self.file.wrapped_data.header.file_name.authorization = props.authorisation
|
|
|
|
|
bpy.ops.bim.disable_editing_header()
|
|
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
2021-06-30 18:34:12 +10:00
|
|
|
def record_state(self):
|
2021-07-01 20:43:16 +10:00
|
|
|
self.file = IfcStore.get_file()
|
2021-06-30 18:34:12 +10:00
|
|
|
return {
|
|
|
|
|
"description": self.file.wrapped_data.header.file_description.description,
|
|
|
|
|
"author": self.file.wrapped_data.header.file_name.author,
|
|
|
|
|
"organisation": self.file.wrapped_data.header.file_name.organization,
|
|
|
|
|
"authorisation": self.file.wrapped_data.header.file_name.authorization,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def rollback(self, data):
|
|
|
|
|
file = IfcStore.get_file()
|
|
|
|
|
file.wrapped_data.header.file_description.description = data["old"]["description"]
|
|
|
|
|
file.wrapped_data.header.file_name.author = data["old"]["author"]
|
|
|
|
|
file.wrapped_data.header.file_name.organization = data["old"]["organisation"]
|
|
|
|
|
file.wrapped_data.header.file_name.authorization = data["old"]["authorisation"]
|
|
|
|
|
|
|
|
|
|
def commit(self, data):
|
|
|
|
|
file = IfcStore.get_file()
|
|
|
|
|
file.wrapped_data.header.file_description.description = data["new"]["description"]
|
|
|
|
|
file.wrapped_data.header.file_name.author = data["new"]["author"]
|
|
|
|
|
file.wrapped_data.header.file_name.organization = data["new"]["organisation"]
|
|
|
|
|
file.wrapped_data.header.file_name.authorization = data["new"]["authorisation"]
|
|
|
|
|
|
2021-05-28 09:50:55 +10:00
|
|
|
|
|
|
|
|
class DisableEditingHeader(bpy.types.Operator):
|
|
|
|
|
bl_idname = "bim.disable_editing_header"
|
|
|
|
|
bl_label = "Disable Editing Header"
|
2021-06-30 18:34:12 +10:00
|
|
|
bl_options = {"REGISTER", "UNDO"}
|
2021-05-28 09:50:55 +10:00
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
context.scene.BIMProjectProperties.is_editing = False
|
|
|
|
|
return {"FINISHED"}
|