This commit is contained in:
Andrej730
2024-04-30 12:17:23 +05:00
parent fc0ffd1c02
commit 137a306269
12 changed files with 50 additions and 23 deletions
+9 -5
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/>.
from __future__ import annotations
import os import os
import bpy import bpy
import json import json
@@ -36,6 +37,7 @@ import blenderbim.core.style
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from mathutils import Vector from mathutils import Vector
from typing import Union from typing import Union
from logging import Logger
class IfcExporter: class IfcExporter:
@@ -163,10 +165,10 @@ class IfcExporter:
bpy.ops.bim.update_representation(obj=obj.name) bpy.ops.bim.update_representation(obj=obj.name)
tool.Geometry.record_object_position(obj) tool.Geometry.record_object_position(obj)
def get_application_name(self): def get_application_name(self) -> str:
return "BlenderBIM" return "BlenderBIM"
def get_application_version(self): def get_application_version(self) -> str:
version = ".".join( version = ".".join(
[ [
str(x) str(x)
@@ -184,11 +186,13 @@ class IfcExporter:
class IfcExportSettings: class IfcExportSettings:
def __init__(self): def __init__(self):
self.logger = None self.logger: Logger = None
self.output_file = None self.output_file: str = None
self.json_version: str = None
self.json_compact: bool = None
@staticmethod @staticmethod
def factory(context, output_file, logger): def factory(context: bpy.types.Context, output_file: str, logger: Logger) -> IfcExportSettings:
settings = IfcExportSettings() settings = IfcExportSettings()
settings.output_file = output_file settings.output_file = output_file
settings.logger = logger settings.logger = logger
+1 -1
View File
@@ -2041,7 +2041,7 @@ class IfcImporter:
class IfcImportSettings: class IfcImportSettings:
def __init__(self): def __init__(self):
self.logger = None self.logger: logging.Logger = None
self.input_file = None self.input_file = None
self.diff_file = None self.diff_file = None
self.should_use_cpu_multiprocessing = True self.should_use_cpu_multiprocessing = True
@@ -29,6 +29,7 @@ import subprocess
import numpy as np import numpy as np
import multiprocessing import multiprocessing
import ifcopenshell import ifcopenshell
import ifcopenshell.ifcopenshell_wrapper
import ifcopenshell.geom import ifcopenshell.geom
import ifcopenshell.util.selector import ifcopenshell.util.selector
import ifcopenshell.util.representation import ifcopenshell.util.representation
@@ -719,7 +719,7 @@ class SvgWriter:
self.svg.text(sheet_id, insert=(text_position[0], text_position[1] + 2.5), class_="ELEVATION", **text_style) self.svg.text(sheet_id, insert=(text_position[0], text_position[1] + 2.5), class_="ELEVATION", **text_style)
) )
def get_reference_and_sheet_id_from_annotation(self, element): def get_reference_and_sheet_id_from_annotation(self, element: ifcopenshell.entity_instance) -> tuple[str, str]:
reference_id = "-" reference_id = "-"
sheet_id = "-" sheet_id = "-"
drawing = tool.Drawing.get_annotation_element(element) drawing = tool.Drawing.get_annotation_element(element)
@@ -17,6 +17,7 @@
# 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 bpy
import ifcopenshell.util.element
import blenderbim.tool as tool import blenderbim.tool as tool
import ifcopenshell.util.placement import ifcopenshell.util.placement
from mathutils import Vector from mathutils import Vector
@@ -19,6 +19,7 @@
import os import os
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.util.element
import ifcopenshell.util.doc import ifcopenshell.util.doc
import ifcopenshell.util.schema import ifcopenshell.util.schema
import blenderbim.tool as tool import blenderbim.tool as tool
@@ -39,6 +39,7 @@ from mathutils import Vector, Matrix
from bpy_extras.object_utils import AddObjectHelper from bpy_extras.object_utils import AddObjectHelper
from . import prop from . import prop
import json import json
from typing import Any
class EnableAddType(bpy.types.Operator, tool.Ifc.Operator): class EnableAddType(bpy.types.Operator, tool.Ifc.Operator):
@@ -511,7 +512,7 @@ def regenerate_profile_usage(usecase_path, ifc_file, settings):
) )
def ensure_material_assigned(usecase_path, ifc_file, settings): def ensure_material_assigned(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
if usecase_path == "material.assign_material": if usecase_path == "material.assign_material":
if not settings.get("material", None): if not settings.get("material", None):
return return
@@ -550,7 +551,7 @@ def ensure_material_assigned(usecase_path, ifc_file, settings):
obj.data.materials.append(IfcStore.get_element(material[0].id())) obj.data.materials.append(IfcStore.get_element(material[0].id()))
def ensure_material_unassigned(usecase_path, ifc_file, settings): def ensure_material_unassigned(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
elements = settings["products"] elements = settings["products"]
if elements[0].is_a("IfcElementType"): if elements[0].is_a("IfcElementType"):
elements.extend(ifcopenshell.util.element.get_types(elements[0])) elements.extend(ifcopenshell.util.element.get_types(elements[0]))
@@ -23,9 +23,14 @@ import hashlib
import logging import logging
import numpy as np import numpy as np
import ifcopenshell import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
import ifcopenshell.util.system
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.core.drawing
import blenderbim.core.style import blenderbim.core.style
import blenderbim.core.spatial import blenderbim.core.spatial
import blenderbim.core.system
import blenderbim.core.geometry import blenderbim.core.geometry
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.bim.import_ifc import blenderbim.bim.import_ifc
@@ -29,7 +29,7 @@ EPSILON = 1e-6
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file: ifcopenshell.file, **settings):
# TODO: This usecase currently depends on Blender's data model # TODO: This usecase currently depends on Blender's data model
self.file = file self.file = file
self.settings = { self.settings = {
@@ -58,7 +58,7 @@ class Usecase:
for key, value in settings.items(): for key, value in settings.items():
self.settings[key] = value self.settings[key] = value
def execute(self): def execute(self) -> ifcopenshell.entity_instance:
self.is_manifold = None self.is_manifold = None
if ( if (
isinstance(self.settings["geometry"], bpy.types.Mesh) isinstance(self.settings["geometry"], bpy.types.Mesh)
@@ -379,7 +379,7 @@ class Usecase:
Axis=self.file.createIfcDirection(polygon.normal), Axis=self.file.createIfcDirection(polygon.normal),
)) ))
def create_annotation_fill_areas(self, is_2d=False): def create_annotation_fill_areas(self, is_2d=False) -> list[ifcopenshell.entity_instance]:
items = [] items = []
if self.file.schema != "IFC2X3": if self.file.schema != "IFC2X3":
points = self.create_cartesian_point_list_from_vertices(self.settings["geometry"].vertices, is_2d=is_2d) points = self.create_cartesian_point_list_from_vertices(self.settings["geometry"].vertices, is_2d=is_2d)
@@ -391,7 +391,9 @@ class Usecase:
items.append(self.file.createIfcAnnotationFillArea(OuterBoundary=curve)) items.append(self.file.createIfcAnnotationFillArea(OuterBoundary=curve))
return items return items
def create_curve_from_polygon(self, points, polygon, is_2d=False): def create_curve_from_polygon(
self, points: ifcopenshell.entity_instance, polygon: bpy.types.MeshPolygon, is_2d=False
) -> ifcopenshell.entity_instance:
indices = list(polygon.vertices) indices = list(polygon.vertices)
indices.append(indices[0]) indices.append(indices[0])
edge_loop = [self.file.createIfcLineIndex((v1 + 1, v2 + 1)) for v1, v2 in zip(indices, indices[1:])] edge_loop = [self.file.createIfcLineIndex((v1 + 1, v2 + 1)) for v1, v2 in zip(indices, indices[1:])]
@@ -460,7 +462,7 @@ class Usecase:
return False return False
return True return True
def create_curves(self, should_exclude_faces=False, is_2d=False): def create_curves(self, should_exclude_faces=False, is_2d=False, ignore_non_loose_edges=False):
geom_data = self.settings["geometry"] geom_data = self.settings["geometry"]
if isinstance(geom_data, bpy.types.Mesh): if isinstance(geom_data, bpy.types.Mesh):
@@ -530,7 +532,9 @@ class Usecase:
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001) bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
tool.Blender.apply_bmesh(mesh, bm) tool.Blender.apply_bmesh(mesh, bm)
def create_curves_from_mesh_ifc2x3(self, should_exclude_faces=False, is_2d=False): def create_curves_from_mesh_ifc2x3(
self, should_exclude_faces=False, is_2d=False
) -> list[ifcopenshell.entity_instance]:
geom_data = self.settings["geometry"].copy() geom_data = self.settings["geometry"].copy()
self.remove_doubles_from_mesh(geom_data) self.remove_doubles_from_mesh(geom_data)
curves = [] curves = []
@@ -810,7 +814,7 @@ class Usecase:
z = self.convert_si_to_unit(z) z = self.convert_si_to_unit(z)
return self.file.createIfcCartesianPoint((x, y, z)) return self.file.createIfcCartesianPoint((x, y, z))
def create_cartesian_point_list_from_vertices(self, vertices, is_2d=False): def create_cartesian_point_list_from_vertices(self, vertices: list[bpy.types.MeshVertex], is_2d=False):
if is_2d: if is_2d:
return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy) for v in vertices]) return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy) for v in vertices])
return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in vertices]) return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in vertices])
@@ -15,10 +15,18 @@
# #
# 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
from typing import Optional
class Usecase: class Usecase:
def __init__(self, file, profile_set=None, material=None, profile=None): def __init__(
self,
file: ifcopenshell.file,
profile_set: ifcopenshell.entity_instance,
material: Optional[ifcopenshell.entity_instance] = None,
profile: Optional[ifcopenshell.entity_instance] = None,
):
"""Add a new profile item to a profile set """Add a new profile item to a profile set
A profile item in a profile set represents an extruded 2D profile curve A profile item in a profile set represents an extruded 2D profile curve
@@ -41,10 +49,10 @@ class Usecase:
how to add a profile set. how to add a profile set.
:type profile_set: ifcopenshell.entity_instance.entity_instance :type profile_set: ifcopenshell.entity_instance.entity_instance
:param material: The IfcMaterial that the profile item is made out of. :param material: The IfcMaterial that the profile item is made out of.
:type material: ifcopenshell.entity_instance.entity_instance :type material: ifcopenshell.entity_instance.entity_instance, optional
:param profile: The IfcProfileDef that represents the 2D cross section :param profile: The IfcProfileDef that represents the 2D cross section
of the the profile item. of the the profile item.
:type profile: ifcopenshell.entity_instance.entity_instance :type profile: ifcopenshell.entity_instance.entity_instance, optional
:return: The newly created IfcMaterialProfile :return: The newly created IfcMaterialProfile
:rtype: ifcopenshell.entity_instance.entity_instance :rtype: ifcopenshell.entity_instance.entity_instance
@@ -84,7 +92,7 @@ class Usecase:
self.file = file self.file = file
self.settings = {"profile_set": profile_set, "material": material, "profile": profile} self.settings = {"profile_set": profile_set, "material": material, "profile": profile}
def execute(self): def execute(self) -> ifcopenshell.entity_instance:
profiles = list(self.settings["profile_set"].MaterialProfiles or []) profiles = list(self.settings["profile_set"].MaterialProfiles or [])
profile = self.file.create_entity("IfcMaterialProfile") profile = self.file.create_entity("IfcMaterialProfile")
if self.settings["material"]: if self.settings["material"]:
@@ -21,10 +21,11 @@ import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.owner.settings import ifcopenshell.api.owner.settings
import ifcopenshell.util.element import ifcopenshell.util.element
from typing import Union
class Usecase: class Usecase:
def __init__(self, file, element=None): def __init__(self, file: ifcopenshell.file, element: ifcopenshell.entity_instance):
"""Updates the owner that is assigned to an object """Updates the owner that is assigned to an object
This ensures that the owner is tracked to have modified the object last, This ensures that the owner is tracked to have modified the object last,
@@ -60,7 +61,7 @@ class Usecase:
self.file = file self.file = file
self.settings = {"element": element} self.settings = {"element": element}
def execute(self): def execute(self) -> Union[ifcopenshell.entity_instance, None]:
if not hasattr(self.settings["element"], "OwnerHistory"): if not hasattr(self.settings["element"], "OwnerHistory"):
return return
user = ifcopenshell.api.owner.settings.get_user(self.file) user = ifcopenshell.api.owner.settings.get_user(self.file)
@@ -17,10 +17,11 @@
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>. # along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell import ifcopenshell
from logging import Logger
class Patcher: class Patcher:
def __init__(self, src, file, logger, only_duplicates=False): def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, only_duplicates=False):
"""Regenerate GlobalIds in an IFC model """Regenerate GlobalIds in an IFC model
All root elements in an IFC model must be identified by a unique Global All root elements in an IFC model must be identified by a unique Global