This commit is contained in:
Andrej730
2024-03-19 16:23:42 +05:00
parent 8c028827fa
commit bf770ce8d4
6 changed files with 38 additions and 20 deletions
@@ -27,6 +27,7 @@ import addon_utils
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.placement import ifcopenshell.util.placement
import ifcopenshell.util.unit
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.core.geometry import blenderbim.core.geometry
import blenderbim.core.aggregate import blenderbim.core.aggregate
+8 -3
View File
@@ -33,6 +33,7 @@ import ifcopenshell.util.unit
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.geolocation import ifcopenshell.util.geolocation
import ifcopenshell.util.placement import ifcopenshell.util.placement
import ifcopenshell.util.representation
import blenderbim.tool as tool import blenderbim.tool as tool
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
from itertools import chain, accumulate from itertools import chain, accumulate
@@ -797,7 +798,7 @@ class IfcImporter:
continue continue
self.create_element_type(element_type) self.create_element_type(element_type)
def create_element_type(self, element): def create_element_type(self, element: ifcopenshell.entity_instance) -> None:
self.ifc_import_settings.logger.info("Creating object %s", element) self.ifc_import_settings.logger.info("Creating object %s", element)
mesh = None mesh = None
if self.ifc_import_settings.should_load_geometry: if self.ifc_import_settings.should_load_geometry:
@@ -864,7 +865,9 @@ class IfcImporter:
self.create_generic_elements(self.gross_elements) self.create_generic_elements(self.gross_elements)
self.context_settings = tmp self.context_settings = tmp
def create_generic_shape(self, element): def create_generic_shape(
self, element: ifcopenshell.entity_instance
) -> Union[ifcopenshell_wrapper.TriangulationElement, None]:
for settings in self.context_settings: for settings in self.context_settings:
try: try:
result = ifcopenshell.geom.create_shape(settings, element) result = ifcopenshell.geom.create_shape(settings, element)
@@ -1690,7 +1693,9 @@ class IfcImporter:
continue continue
self.create_style(style) self.create_style(style)
def create_style(self, style, blender_material=None): def create_style(
self, style: ifcopenshell.entity_instance, blender_material: Optional[bpy.types.Material] = None
) -> None:
if not blender_material: if not blender_material:
name = style.Name or str(style.id()) name = style.Name or str(style.id())
blender_material = bpy.data.materials.new(name) blender_material = bpy.data.materials.new(name)
@@ -454,7 +454,7 @@ class AppendLibraryElement(bpy.types.Operator):
blenderbim.bim.handler.refresh_ui_data() blenderbim.bim.handler.refresh_ui_data()
return {"FINISHED"} return {"FINISHED"}
def import_material_from_ifc(self, element, context): def import_material_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None:
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
logger = logging.getLogger("ImportIFC") logger = logging.getLogger("ImportIFC")
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
@@ -463,7 +463,7 @@ class AppendLibraryElement(bpy.types.Operator):
blender_material = ifc_importer.create_material(element) blender_material = ifc_importer.create_material(element)
self.import_material_styles(blender_material, element, ifc_importer) self.import_material_styles(blender_material, element, ifc_importer)
def import_product_from_ifc(self, element, context): def import_product_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None:
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
logger = logging.getLogger("ImportIFC") logger = logging.getLogger("ImportIFC")
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
@@ -476,7 +476,7 @@ class AppendLibraryElement(bpy.types.Operator):
ifc_importer.create_generic_elements({element}) ifc_importer.create_generic_elements({element})
ifc_importer.place_objects_in_collections() ifc_importer.place_objects_in_collections()
def import_type_from_ifc(self, element, context): def import_type_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None:
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
logger = logging.getLogger("ImportIFC") logger = logging.getLogger("ImportIFC")
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
@@ -501,14 +501,14 @@ class AppendLibraryElement(bpy.types.Operator):
ifc_importer.create_element_type(element) ifc_importer.create_element_type(element)
ifc_importer.place_objects_in_collections() ifc_importer.place_objects_in_collections()
def import_materials(self, element, ifc_importer): def import_materials(self, element: ifcopenshell.entity_instance, ifc_importer: import_ifc.IfcImporter) -> None:
for material in ifcopenshell.util.element.get_materials(element): for material in ifcopenshell.util.element.get_materials(element):
if IfcStore.get_element(material.id()): if IfcStore.get_element(material.id()):
continue continue
blender_material = ifc_importer.create_material(material) blender_material = ifc_importer.create_material(material)
self.import_material_styles(blender_material, material, ifc_importer) self.import_material_styles(blender_material, material, ifc_importer)
def import_styles(self, element, ifc_importer): def import_styles(self, element: ifcopenshell.entity_instance, ifc_importer: import_ifc.IfcImporter) -> None:
if element.is_a("IfcTypeProduct"): if element.is_a("IfcTypeProduct"):
representations = element.RepresentationMaps or [] representations = element.RepresentationMaps or []
elif element.is_a("IfcProduct"): elif element.is_a("IfcProduct"):
@@ -521,7 +521,12 @@ class AppendLibraryElement(bpy.types.Operator):
if element2.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element2.id()): if element2.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element2.id()):
ifc_importer.create_style(element2) ifc_importer.create_style(element2)
def import_material_styles(self, blender_material, material, ifc_importer): def import_material_styles(
self,
blender_material: bpy.types.Material,
material: ifcopenshell.entity_instance,
ifc_importer: import_ifc.IfcImporter,
) -> None:
if not material.HasRepresentation: if not material.HasRepresentation:
return return
for element in self.file.traverse(material.HasRepresentation[0]): for element in self.file.traverse(material.HasRepresentation[0]):
+3 -2
View File
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
import ifcopenshell.util.element import ifcopenshell.util.element
@@ -23,7 +24,7 @@ import ifcopenshell.util.element
class Aggregate(blenderbim.core.tool.Aggregate): class Aggregate(blenderbim.core.tool.Aggregate):
@classmethod @classmethod
def can_aggregate(cls, relating_obj, related_obj): def can_aggregate(cls, relating_obj: bpy.types.Object, related_obj: bpy.types.Object) -> bool:
relating_object = tool.Ifc.get_entity(relating_obj) relating_object = tool.Ifc.get_entity(relating_obj)
related_object = tool.Ifc.get_entity(related_obj) related_object = tool.Ifc.get_entity(related_obj)
if not relating_object or not related_object: if not relating_object or not related_object:
@@ -60,4 +61,4 @@ class Aggregate(blenderbim.core.tool.Aggregate):
def get_relating_object(cls, related_element): def get_relating_object(cls, related_element):
for rel in related_element.Decomposes: for rel in related_element.Decomposes:
if rel.is_a("IfcRelAggregates"): if rel.is_a("IfcRelAggregates"):
return rel.RelatingObject return rel.RelatingObject
+9 -6
View File
@@ -21,11 +21,12 @@ import ifcopenshell.util.element
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
from typing import Union
class Collector(blenderbim.core.tool.Collector): class Collector(blenderbim.core.tool.Collector):
@classmethod @classmethod
def sync(cls, obj): def sync(cls, obj: bpy.types.Object) -> None:
# This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy # This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
@@ -81,7 +82,7 @@ class Collector(blenderbim.core.tool.Collector):
) )
@classmethod @classmethod
def assign(cls, obj): def assign(cls, obj: bpy.types.Object) -> None:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
object_collection = None object_collection = None
@@ -112,7 +113,9 @@ class Collector(blenderbim.core.tool.Collector):
bpy.data.collections.remove(obj.BIMObjectProperties.collection) bpy.data.collections.remove(obj.BIMObjectProperties.collection)
@classmethod @classmethod
def _get_own_collection(cls, element, obj): def _get_own_collection(
cls, element: ifcopenshell.entity_instance, obj: bpy.types.Object
) -> Union[bpy.types.Collection, None]:
if element.is_a("IfcProject"): if element.is_a("IfcProject"):
return cls._create_own_collection(obj) return cls._create_own_collection(obj)
@@ -161,7 +164,7 @@ class Collector(blenderbim.core.tool.Collector):
return cls._create_own_collection(obj) return cls._create_own_collection(obj)
@classmethod @classmethod
def _get_collection(cls, element, obj): def _get_collection(cls, element: ifcopenshell.entity_instance, obj: bpy.types.Object) -> bpy.types.Collection:
if element.is_a("IfcTypeObject"): if element.is_a("IfcTypeObject"):
return cls._create_project_child_collection("Types") return cls._create_project_child_collection("Types")
@@ -229,7 +232,7 @@ class Collector(blenderbim.core.tool.Collector):
return collection return collection
@classmethod @classmethod
def _create_project_child_collection(cls, name): def _create_project_child_collection(cls, name: str) -> bpy.types.Collection:
collection = bpy.data.collections.get(name) collection = bpy.data.collections.get(name)
if not collection: if not collection:
collection = bpy.data.collections.new(name) collection = bpy.data.collections.new(name)
@@ -239,7 +242,7 @@ class Collector(blenderbim.core.tool.Collector):
return collection return collection
@classmethod @classmethod
def _create_own_collection(cls, obj): def _create_own_collection(cls, obj: bpy.types.Object) -> bpy.types.Collection:
if obj.BIMObjectProperties.collection: if obj.BIMObjectProperties.collection:
return obj.BIMObjectProperties.collection return obj.BIMObjectProperties.collection
collection = bpy.data.collections.new(obj.name) collection = bpy.data.collections.new(obj.name)
+6 -3
View File
@@ -23,6 +23,7 @@ import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.bim.helper import blenderbim.bim.helper
from mathutils import Color from mathutils import Color
from typing import Union
# fmt: off # fmt: off
TEXTURE_MAPS_BY_METHODS = { TEXTURE_MAPS_BY_METHODS = {
@@ -103,7 +104,9 @@ class Style(blenderbim.core.tool.Style):
return return
@classmethod @classmethod
def get_style_elements(cls, blender_material_or_style): def get_style_elements(
cls, blender_material_or_style: Union[bpy.types.Material, ifcopenshell.entity_instance]
) -> dict[str, ifcopenshell.entity_instance]:
if isinstance(blender_material_or_style, bpy.types.Material): if isinstance(blender_material_or_style, bpy.types.Material):
if not blender_material_or_style.BIMMaterialProperties.ifc_style_id: if not blender_material_or_style.BIMMaterialProperties.ifc_style_id:
return {} return {}
@@ -454,7 +457,7 @@ class Style(blenderbim.core.tool.Style):
return results return results
@classmethod @classmethod
def get_style_ui_props_attributes(self, style_type): def get_style_ui_props_attributes(cls, style_type):
props = bpy.context.scene.BIMStylesProperties props = bpy.context.scene.BIMStylesProperties
if style_type == "IfcExternallyDefinedSurfaceStyle": if style_type == "IfcExternallyDefinedSurfaceStyle":
return props.external_style_attributes return props.external_style_attributes
@@ -499,7 +502,7 @@ class Style(blenderbim.core.tool.Style):
blenderbim.bim.helper.import_attributes2(style, attributes) blenderbim.bim.helper.import_attributes2(style, attributes)
@classmethod @classmethod
def has_blender_external_style(cls, style_elements): def has_blender_external_style(cls, style_elements: dict[str, ifcopenshell.entity_instance]) -> bool:
external_style = style_elements.get("IfcExternallyDefinedSurfaceStyle", None) external_style = style_elements.get("IfcExternallyDefinedSurfaceStyle", None)
return bool(external_style and external_style.Location and external_style.Location.endswith(".blend")) return bool(external_style and external_style.Location and external_style.Location.endswith(".blend"))