This commit is contained in:
Andrej730
2024-03-19 16:23:42 +05:00
parent e5dd06c461
commit 89f7105e9c
6 changed files with 38 additions and 20 deletions
@@ -27,6 +27,7 @@ import addon_utils
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.placement
import ifcopenshell.util.unit
import blenderbim.tool as tool
import blenderbim.core.geometry
import blenderbim.core.aggregate
+8 -3
View File
@@ -33,6 +33,7 @@ import ifcopenshell.util.unit
import ifcopenshell.util.element
import ifcopenshell.util.geolocation
import ifcopenshell.util.placement
import ifcopenshell.util.representation
import blenderbim.tool as tool
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
from itertools import chain, accumulate
@@ -797,7 +798,7 @@ class IfcImporter:
continue
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)
mesh = None
if self.ifc_import_settings.should_load_geometry:
@@ -864,7 +865,9 @@ class IfcImporter:
self.create_generic_elements(self.gross_elements)
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:
try:
result = ifcopenshell.geom.create_shape(settings, element)
@@ -1690,7 +1693,9 @@ class IfcImporter:
continue
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:
name = style.Name or str(style.id())
blender_material = bpy.data.materials.new(name)
@@ -454,7 +454,7 @@ class AppendLibraryElement(bpy.types.Operator):
blenderbim.bim.handler.refresh_ui_data()
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()
logger = logging.getLogger("ImportIFC")
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)
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()
logger = logging.getLogger("ImportIFC")
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.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()
logger = logging.getLogger("ImportIFC")
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.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):
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_styles(self, element, ifc_importer):
def import_styles(self, element: ifcopenshell.entity_instance, ifc_importer: import_ifc.IfcImporter) -> None:
if element.is_a("IfcTypeProduct"):
representations = element.RepresentationMaps or []
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()):
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:
return
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
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.core.tool
import blenderbim.tool as tool
import ifcopenshell.util.element
@@ -23,7 +24,7 @@ import ifcopenshell.util.element
class Aggregate(blenderbim.core.tool.Aggregate):
@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)
related_object = tool.Ifc.get_entity(related_obj)
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):
for rel in related_element.Decomposes:
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.tool as tool
from typing import Union
class Collector(blenderbim.core.tool.Collector):
@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
element = tool.Ifc.get_entity(obj)
@@ -81,7 +82,7 @@ class Collector(blenderbim.core.tool.Collector):
)
@classmethod
def assign(cls, obj):
def assign(cls, obj: bpy.types.Object) -> None:
element = tool.Ifc.get_entity(obj)
object_collection = None
@@ -112,7 +113,9 @@ class Collector(blenderbim.core.tool.Collector):
bpy.data.collections.remove(obj.BIMObjectProperties.collection)
@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"):
return cls._create_own_collection(obj)
@@ -161,7 +164,7 @@ class Collector(blenderbim.core.tool.Collector):
return cls._create_own_collection(obj)
@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"):
return cls._create_project_child_collection("Types")
@@ -229,7 +232,7 @@ class Collector(blenderbim.core.tool.Collector):
return collection
@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)
if not collection:
collection = bpy.data.collections.new(name)
@@ -239,7 +242,7 @@ class Collector(blenderbim.core.tool.Collector):
return collection
@classmethod
def _create_own_collection(cls, obj):
def _create_own_collection(cls, obj: bpy.types.Object) -> bpy.types.Collection:
if obj.BIMObjectProperties.collection:
return obj.BIMObjectProperties.collection
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.bim.helper
from mathutils import Color
from typing import Union
# fmt: off
TEXTURE_MAPS_BY_METHODS = {
@@ -103,7 +104,9 @@ class Style(blenderbim.core.tool.Style):
return
@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 not blender_material_or_style.BIMMaterialProperties.ifc_style_id:
return {}
@@ -454,7 +457,7 @@ class Style(blenderbim.core.tool.Style):
return results
@classmethod
def get_style_ui_props_attributes(self, style_type):
def get_style_ui_props_attributes(cls, style_type):
props = bpy.context.scene.BIMStylesProperties
if style_type == "IfcExternallyDefinedSurfaceStyle":
return props.external_style_attributes
@@ -499,7 +502,7 @@ class Style(blenderbim.core.tool.Style):
blenderbim.bim.helper.import_attributes2(style, attributes)
@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)
return bool(external_style and external_style.Location and external_style.Location.endswith(".blend"))