This commit is contained in:
Andrej730
2024-04-04 11:18:27 +05:00
parent 635ddce93d
commit b4c5ad1e35
6 changed files with 60 additions and 19 deletions
+8 -7
View File
@@ -35,6 +35,7 @@ import blenderbim.core.spatial
import blenderbim.core.style 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
class IfcExporter: class IfcExporter:
@@ -86,8 +87,8 @@ class IfcExporter:
self.get_application_name(), tool.Blender.get_blenderbim_version() self.get_application_name(), tool.Blender.get_blenderbim_version()
) )
def sync_all_objects(self): def sync_all_objects(self) -> list[ifcopenshell.entity_instance]:
results = [] results: list[ifcopenshell.entity_instance] = []
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file) self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
for ifc_definition_id in list(IfcStore.id_map.keys()): for ifc_definition_id in list(IfcStore.id_map.keys()):
obj = IfcStore.id_map[ifc_definition_id] obj = IfcStore.id_map[ifc_definition_id]
@@ -107,8 +108,8 @@ class IfcExporter:
pass # The object is likely deleted pass # The object is likely deleted
return results return results
def sync_edited_objects(self): def sync_edited_objects(self) -> list[ifcopenshell.entity_instance]:
results = [] results: list[ifcopenshell.entity_instance] = []
for obj in IfcStore.edited_objs.copy(): for obj in IfcStore.edited_objs.copy():
if not obj: if not obj:
continue continue
@@ -126,7 +127,7 @@ class IfcExporter:
IfcStore.edited_objs.clear() IfcStore.edited_objs.clear()
return results return results
def sync_object_material(self, obj): def sync_object_material(self, obj: bpy.types.Object) -> None:
if not obj.data or not isinstance(obj.data, bpy.types.Mesh): if not obj.data or not isinstance(obj.data, bpy.types.Mesh):
return return
if not self.has_changed_materials(obj): if not self.has_changed_materials(obj):
@@ -137,7 +138,7 @@ class IfcExporter:
checksum = obj.data.BIMMeshProperties.material_checksum checksum = obj.data.BIMMeshProperties.material_checksum
return checksum != str([s.id() for s in tool.Geometry.get_styles(obj) if s]) return checksum != str([s.id() for s in tool.Geometry.get_styles(obj) if s])
def sync_object_placement(self, obj): def sync_object_placement(self, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]:
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
if not tool.Ifc.is_moved(obj): if not tool.Ifc.is_moved(obj):
return return
@@ -152,7 +153,7 @@ class IfcExporter:
blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj) blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
return element return element
def sync_grid_axis_object_placement(self, obj, element): def sync_grid_axis_object_placement(self, obj: bpy.types.Object, element: ifcopenshell.entity_instance) -> None:
grid = (element.PartOfU or element.PartOfV or element.PartOfW)[0] grid = (element.PartOfU or element.PartOfV or element.PartOfW)[0]
grid_obj = tool.Ifc.get_object(grid) grid_obj = tool.Ifc.get_object(grid)
if grid_obj: if grid_obj:
@@ -44,7 +44,7 @@ import blenderbim.bim.module.drawing.helper as helper
import blenderbim.bim.export_ifc import blenderbim.bim.export_ifc
from blenderbim.bim.module.drawing.decoration import CutDecorator from blenderbim.bim.module.drawing.decoration import CutDecorator
from blenderbim.bim.module.drawing.data import DecoratorData, DrawingsData from blenderbim.bim.module.drawing.data import DecoratorData, DrawingsData
from typing import NamedTuple, List, Union from typing import NamedTuple, List, Union, Optional
from lxml import etree from lxml import etree
from mathutils import Vector, Color, Matrix from mathutils import Vector, Color, Matrix
from timeit import default_timer as timer from timeit import default_timer as timer
@@ -445,8 +445,14 @@ class CreateDrawing(bpy.types.Operator):
return LineworkContexts(body_contexts, annotation_contexts) return LineworkContexts(body_contexts, annotation_contexts)
def serialize_contexts_elements( def serialize_contexts_elements(
self, ifc, tree: ifcopenshell.geom.tree, contexts: LineworkContexts, context_type, drawing_elements, target_view self,
): ifc: ifcopenshell.file,
tree: ifcopenshell.geom.tree,
contexts: LineworkContexts,
context_type: str,
drawing_elements: set[ifcopenshell.entity_instance],
target_view: str,
) -> None:
drawing_elements = drawing_elements.copy() drawing_elements = drawing_elements.copy()
contexts = getattr(contexts, context_type) contexts = getattr(contexts, context_type)
for context in contexts: for context in contexts:
@@ -472,7 +478,7 @@ class CreateDrawing(bpy.types.Operator):
tree.add_element(elem) tree.add_element(elem)
drawing_elements -= processed drawing_elements -= processed
def generate_linework(self, context): def generate_linework(self, context: bpy.types.Context) -> Union[str, None]:
if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasLinework"): if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasLinework"):
return return
svg_path = self.get_svg_path(cache_type="linework") svg_path = self.get_svg_path(cache_type="linework")
@@ -1115,14 +1121,14 @@ class CreateDrawing(bpy.types.Operator):
continue continue
return space return space
def get_material_name(self, element): def get_material_name(self, element: ifcopenshell.entity_instance) -> str:
if hasattr(element, "Name") and element.Name: if hasattr(element, "Name") and element.Name:
return element.Name return element.Name
elif hasattr(element, "LayerSetName") and element.LayerSetName: elif hasattr(element, "LayerSetName") and element.LayerSetName:
return element.LayerSetName return element.LayerSetName
return "mat-" + str(element.id()) return "mat-" + str(element.id())
def get_svg_path(self, cache_type=None): def get_svg_path(self, cache_type: Optional[str] = None) -> str:
drawing_path = tool.Drawing.get_document_uri(self.camera_document) drawing_path = tool.Drawing.get_document_uri(self.camera_document)
drawings_dir = os.path.dirname(drawing_path) drawings_dir = os.path.dirname(drawing_path)
+9 -1
View File
@@ -16,10 +16,18 @@
# 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 blenderbim.core.style import blenderbim.core.style
from typing import TYPE_CHECKING, Optional
import blenderbim.core.tool as tool
if TYPE_CHECKING:
import bpy
def edit_object_placement(ifc, geometry, surveyor, obj=None): def edit_object_placement(
ifc: tool.Ifc, geometry: tool.Geometry, surveyor: tool.Surveyor, obj: Optional[bpy.types.Object] = None
) -> None:
element = ifc.get_entity(obj) element = ifc.get_entity(obj)
if not element: if not element:
return return
+27 -3
View File
@@ -16,18 +16,42 @@
# 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
from typing import TYPE_CHECKING, Optional, Union
import blenderbim.core.tool as tool
def reference_structure(ifc, spatial, structure=None, element=None): if TYPE_CHECKING:
import bpy
import ifcopenshell
def reference_structure(
ifc: tool.Ifc,
spatial: tool.Spatial,
structure: Optional[ifcopenshell.entity_instance] = None,
element: Optional[ifcopenshell.entity_instance] = None,
) -> Union[ifcopenshell.entity_instance, None]:
if spatial.can_reference(structure, element): if spatial.can_reference(structure, element):
return ifc.run("spatial.reference_structure", product=element, relating_structure=structure) return ifc.run("spatial.reference_structure", product=element, relating_structure=structure)
def dereference_structure(ifc, spatial, structure=None, element=None): def dereference_structure(
ifc: tool.Ifc,
spatial: tool.Spatial,
structure: Optional[ifcopenshell.entity_instance] = None,
element: Optional[ifcopenshell.entity_instance] = None,
) -> None:
if spatial.can_reference(structure, element): if spatial.can_reference(structure, element):
return ifc.run("spatial.dereference_structure", product=element, relating_structure=structure) return ifc.run("spatial.dereference_structure", product=element, relating_structure=structure)
def assign_container(ifc, collector, spatial, structure_obj=None, element_obj=None): def assign_container(
ifc: tool.Ifc,
collector: tool.Collector,
spatial: tool.Spatial,
structure_obj: Optional[bpy.types.Object] = None,
element_obj: Optional[bpy.types.Object] = None,
) -> Union[ifcopenshell.entity_instance, None]:
if not spatial.can_contain(structure_obj, element_obj): if not spatial.can_contain(structure_obj, element_obj):
return return
rel = ifc.run( rel = ifc.run(
@@ -20,6 +20,8 @@ import bpy
import ifcopenshell.util.element import ifcopenshell.util.element
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.core.spatial
import blenderbim.core.aggregate
import blenderbim.tool as tool import blenderbim.tool as tool
from typing import Union from typing import Union
+2 -2
View File
@@ -34,7 +34,7 @@ from shapely import Polygon, MultiPolygon
class Spatial(blenderbim.core.tool.Spatial): class Spatial(blenderbim.core.tool.Spatial):
@classmethod @classmethod
def can_contain(cls, structure_obj, element_obj): def can_contain(cls, structure_obj: bpy.types.Object, element_obj: bpy.types.Object) -> bool:
structure = tool.Ifc.get_entity(structure_obj) structure = tool.Ifc.get_entity(structure_obj)
element = tool.Ifc.get_entity(element_obj) element = tool.Ifc.get_entity(element_obj)
if not structure or not element: if not structure or not element:
@@ -52,7 +52,7 @@ class Spatial(blenderbim.core.tool.Spatial):
return True return True
@classmethod @classmethod
def can_reference(cls, structure, element): def can_reference(cls, structure: ifcopenshell.entity_instance, element: ifcopenshell.entity_instance) -> bool:
if not structure or not element: if not structure or not element:
return False return False
if tool.Ifc.get_schema() == "IFC2X3": if tool.Ifc.get_schema() == "IFC2X3":