mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
typing
also small optimization in MaterialCreator.create to address ifc a couple times less
This commit is contained in:
@@ -40,29 +40,33 @@ from typing import Dict, Union, Optional, Any
|
|||||||
|
|
||||||
|
|
||||||
class MaterialCreator:
|
class MaterialCreator:
|
||||||
|
mesh: bpy.types.Mesh
|
||||||
|
obj: bpy.types.Object
|
||||||
|
|
||||||
def __init__(self, ifc_import_settings: IfcImportSettings, ifc_importer: IfcImporter):
|
def __init__(self, ifc_import_settings: IfcImportSettings, ifc_importer: IfcImporter):
|
||||||
self.mesh: bpy.types.Mesh = None
|
|
||||||
self.obj: bpy.types.Object = None
|
|
||||||
self.styles: Dict[int, bpy.types.Material] = {}
|
self.styles: Dict[int, bpy.types.Material] = {}
|
||||||
self.parsed_meshes: set[str] = set()
|
self.parsed_meshes: set[str] = set()
|
||||||
self.ifc_import_settings = ifc_import_settings
|
self.ifc_import_settings = ifc_import_settings
|
||||||
self.ifc_importer = ifc_importer
|
self.ifc_importer = ifc_importer
|
||||||
|
|
||||||
def create(self, element: ifcopenshell.entity_instance, obj: bpy.types.Object, mesh: OBJECT_DATA_TYPE) -> None:
|
def create(
|
||||||
self.mesh = mesh
|
self, element: ifcopenshell.entity_instance, obj: bpy.types.Object, mesh: Union[OBJECT_DATA_TYPE, None]
|
||||||
# as ifcopenshell triangulates the mesh, we need to merge it to quads again
|
) -> None:
|
||||||
self.obj = obj
|
if ((rep := getattr(element, "Representation", ...) is not ...) and not rep) or (
|
||||||
if (hasattr(element, "Representation") and not element.Representation) or (
|
(rep := getattr(element, "RepresentationMaps", ...) is not ...) and not rep
|
||||||
hasattr(element, "RepresentationMaps") and not element.RepresentationMaps
|
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
if not self.mesh or self.mesh.name in self.parsed_meshes:
|
|
||||||
|
if not mesh or mesh.name in self.parsed_meshes:
|
||||||
return
|
return
|
||||||
|
|
||||||
# We don't support curve styles yet.
|
# We don't support curve styles yet.
|
||||||
if isinstance(mesh, bpy.types.Curve):
|
if isinstance(mesh, bpy.types.Curve):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.mesh = mesh
|
||||||
|
self.obj = obj
|
||||||
|
|
||||||
# mesh["ios_materials"] can contain:
|
# mesh["ios_materials"] can contain:
|
||||||
# - ifc style id if style assigned to the representation items directly
|
# - ifc style id if style assigned to the representation items directly
|
||||||
# or through material with a style;
|
# or through material with a style;
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instanc
|
|||||||
style is reused.
|
style is reused.
|
||||||
|
|
||||||
:param material: The IfcMaterialDefinition to copy
|
:param material: The IfcMaterialDefinition to copy
|
||||||
:type material: ifcopenshell.entity_instance
|
|
||||||
:return: The new copy of the material
|
:return: The new copy of the material
|
||||||
:rtype: ifcopenshell.entity_instance
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -68,9 +66,13 @@ def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instanc
|
|||||||
return _copy_material_with_inverses(file, material)
|
return _copy_material_with_inverses(file, material)
|
||||||
elif material.is_a("IfcMaterialList"):
|
elif material.is_a("IfcMaterialList"):
|
||||||
return _copy_material_with_inverses(file, material)
|
return _copy_material_with_inverses(file, material)
|
||||||
|
else:
|
||||||
|
raise Exception(f"Unexpected material type: '{material.is_a()}' ({material}).")
|
||||||
|
|
||||||
|
|
||||||
def _copy_material_with_inverses(file, material):
|
def _copy_material_with_inverses(
|
||||||
|
file: ifcopenshell.file, material: ifcopenshell.entity_instance
|
||||||
|
) -> ifcopenshell.entity_instance:
|
||||||
new = ifcopenshell.util.element.copy(file, material)
|
new = ifcopenshell.util.element.copy(file, material)
|
||||||
for inverse in file.get_inverse(material):
|
for inverse in file.get_inverse(material):
|
||||||
if inverse.is_a("IfcMaterialProperties"):
|
if inverse.is_a("IfcMaterialProperties"):
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def assign_representation_styles(
|
def assign_representation_styles(
|
||||||
@@ -112,6 +113,10 @@ def assign_representation_styles(
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
|
file: ifcopenshell.file
|
||||||
|
settings: dict[str, Any]
|
||||||
|
results: list[ifcopenshell.entity_instance]
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
if not self.settings["styles"]:
|
if not self.settings["styles"]:
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import lark
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import ifcopenshell.api.pset
|
import ifcopenshell.api.pset
|
||||||
import ifcopenshell.api.geometry
|
import ifcopenshell.api.geometry
|
||||||
import ifcopenshell.ifcopenshell_wrapper as W
|
|
||||||
import ifcopenshell.util
|
import ifcopenshell.util
|
||||||
import ifcopenshell.util.attribute
|
import ifcopenshell.util.attribute
|
||||||
import ifcopenshell.util.fm
|
import ifcopenshell.util.fm
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import operator
|
|
||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
import ifcopenshell.api.pset
|
import ifcopenshell.api.pset
|
||||||
import ifcopenshell.api.root
|
import ifcopenshell.api.root
|
||||||
|
|||||||
Reference in New Issue
Block a user