This commit is contained in:
Andrej730
2024-05-17 15:19:22 +05:00
parent 8662e20c58
commit 42be4eb064
14 changed files with 57 additions and 16 deletions
+4 -2
View File
@@ -36,8 +36,9 @@ class AbstractXmlParserSerializer(Protocol):
xml: The XML file as bytes. xml: The XML file as bytes.
clazz: The class to parse to. clazz: The class to parse to.
""" """
...
def serialize(self, obj: T, ns_map: Optional[dict[str, str]] = None) -> str: def serialize(self, obj: object, ns_map: Optional[dict[str, str]] = None) -> str:
""" """
Serialize an object to XML. Serialize an object to XML.
@@ -48,6 +49,7 @@ class AbstractXmlParserSerializer(Protocol):
Returns: Returns:
The XML as string. The XML as string.
""" """
...
class XmlParserSerializer: class XmlParserSerializer:
@@ -68,7 +70,7 @@ class XmlParserSerializer:
""" """
return self.parser.from_bytes(xml, clazz) return self.parser.from_bytes(xml, clazz)
def serialize(self, obj: T, ns_map: Optional[dict[Optional[str], str]] = None) -> str: def serialize(self, obj: object, ns_map: Optional[dict[Optional[str], str]] = None) -> str:
""" """
Serialize an object to XML. Serialize an object to XML.
+3 -1
View File
@@ -756,7 +756,9 @@ class IfcImporter:
return mathutils.Matrix(matrix.tolist()) return mathutils.Matrix(matrix.tolist())
def find_decomposed_ifc_class(self, element, ifc_class): def find_decomposed_ifc_class(
self, element: ifcopenshell.entity_instance, ifc_class: str
) -> Union[ifcopenshell.entity_instance, None]:
if element.is_a(ifc_class): if element.is_a(ifc_class):
return element return element
rel_aggregates = element.IsDecomposedBy rel_aggregates = element.IsDecomposedBy
@@ -19,6 +19,7 @@
import bpy import bpy
import blenderbim.bim.schema import blenderbim.bim.schema
import ifcopenshell import ifcopenshell
import ifcopenshell.util.attribute
import ifcopenshell.util.element import ifcopenshell.util.element
import blenderbim.tool as tool import blenderbim.tool as tool
from blenderbim.bim.prop import Attribute, StrProperty from blenderbim.bim.prop import Attribute, StrProperty
@@ -20,6 +20,7 @@ import bpy
import json import json
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.attribute
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.bim.handler import blenderbim.bim.handler
import blenderbim.core.structural as core import blenderbim.core.structural as core
+3 -2
View File
@@ -24,6 +24,7 @@ import logging
import numpy as np import numpy as np
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.geom
import ifcopenshell.guid import ifcopenshell.guid
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.representation import ifcopenshell.util.representation
@@ -570,11 +571,11 @@ class Geometry(blenderbim.core.tool.Geometry):
new.value = element[i] new.value = element[i]
@classmethod @classmethod
def is_body_representation(cls, representation): def is_body_representation(cls, representation: ifcopenshell.entity_instance) -> bool:
return representation.ContextOfItems.ContextIdentifier == "Body" return representation.ContextOfItems.ContextIdentifier == "Body"
@classmethod @classmethod
def is_box_representation(cls, representation): def is_box_representation(cls, representation: ifcopenshell.entity_instance) -> bool:
return representation.ContextOfItems.ContextIdentifier == "Box" return representation.ContextOfItems.ContextIdentifier == "Box"
@classmethod @classmethod
@@ -19,6 +19,7 @@
import bpy import bpy
import math import math
import ifcopenshell import ifcopenshell
import ifcopenshell.api
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
from mathutils import Vector from mathutils import Vector
@@ -17,12 +17,12 @@
# 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 Optional from typing import Optional, Literal
def add_context( def add_context(
file: ifcopenshell.file, file: ifcopenshell.file,
context_type: str, context_type: Optional[Literal["Model", "Plan"]] = None,
context_identifier: Optional[str] = None, context_identifier: Optional[str] = None,
target_view: Optional[str] = None, target_view: Optional[str] = None,
parent: Optional[ifcopenshell.entity_instance] = None, parent: Optional[ifcopenshell.entity_instance] = None,
@@ -96,7 +96,7 @@ def add_context(
:param context_type: The type of the context, must be one of "Model" or :param context_type: The type of the context, must be one of "Model" or
"Plan" only. "Plan" only.
:type context_type: str :type context_type: str, optional
:param context_identifier: The identifier of the context, chosen from :param context_identifier: The identifier of the context, chosen from
one of the common identifiers above or consult the IFC documentation one of the common identifiers above or consult the IFC documentation
(under the IfcShapeRepresentation page) for more details. Optional (under the IfcShapeRepresentation page) for more details. Optional
@@ -21,7 +21,7 @@ import math
import bmesh import bmesh
import ifcopenshell.util.unit import ifcopenshell.util.unit
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from typing import Union, Optional, Literal from typing import Union, Optional, Literal, Any
Z_AXIS = Vector((0, 0, 1)) Z_AXIS = Vector((0, 0, 1))
@@ -93,6 +93,9 @@ def add_representation(
class Usecase: class Usecase:
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self): def execute(self):
self.is_manifold = None self.is_manifold = None
if ( if (
@@ -16,8 +16,13 @@
# 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.ifcopenshell_wrapper as ifcopenshell_wrapper
from typing import Union
def get_primitive_type(attribute_or_data_type):
def get_primitive_type(
attribute_or_data_type: Union[ifcopenshell_wrapper.attribute, ifcopenshell_wrapper.parameter_type]
) -> Union[str, tuple[str, list[str]]]:
if hasattr(attribute_or_data_type, "type_of_attribute"): if hasattr(attribute_or_data_type, "type_of_attribute"):
data_type = str(attribute_or_data_type.type_of_attribute()) data_type = str(attribute_or_data_type.type_of_attribute())
else: else:
@@ -21,6 +21,7 @@ import lark
import numpy as np import numpy as np
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util import ifcopenshell.util
import ifcopenshell.util.attribute
import ifcopenshell.util.fm import ifcopenshell.util.fm
import ifcopenshell.util.unit import ifcopenshell.util.unit
import ifcopenshell.util.element import ifcopenshell.util.element
@@ -30,7 +31,7 @@ import ifcopenshell.util.classification
import ifcopenshell.util.schema import ifcopenshell.util.schema
import ifcopenshell.util.shape import ifcopenshell.util.shape
from decimal import Decimal from decimal import Decimal
from typing import Optional, Any, Union from typing import Optional, Any, Union, Iterable
filter_elements_grammar = lark.Lark( filter_elements_grammar = lark.Lark(
@@ -326,10 +327,10 @@ def filter_elements(
def set_element_value( def set_element_value(
ifc_file: ifcopenshell.file, ifc_file: ifcopenshell.file,
element: ifcopenshell.entity_instance, element: Union[ifcopenshell.entity_instance, Iterable[ifcopenshell.entity_instance], None],
query: Union[str, list[str]], query: Union[str, list[str]],
value: Optional[str], value: Any,
) -> Union[ifcopenshell.entity_instance, None]: ) -> None:
if isinstance(query, (list, tuple)): if isinstance(query, (list, tuple)):
keys = query keys = query
else: else:
@@ -16,9 +16,29 @@
# 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 IfcPatch. If not, see <http://www.gnu.org/licenses/>. # along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
import logging
import numpy as np
import numpy.typing as npt
import ifcopenshell
from typing import Literal, Optional, Union
class Patcher: class Patcher:
def __init__(self, src, file, logger, mode="geometry", a=None, b=None, c=None, d=None): def __init__(
self,
src: str,
file: ifcopenshell.file,
logger: logging.Logger,
mode: Literal[
"geometry",
"placement",
"both",
] = "geometry",
a: Optional[float] = None,
b: Optional[float] = None,
c: Optional[float] = None,
d: Optional[float] = None,
):
"""Reset any large coordinates to smaller coordinates based on a threshold """Reset any large coordinates to smaller coordinates based on a threshold
If you find large coordinates in your model, the large coordinates may If you find large coordinates in your model, the large coordinates may
@@ -151,7 +171,7 @@ class Patcher:
point.Coordinates[2] + offset_point[2], point.Coordinates[2] + offset_point[2],
) )
def is_point_far_away(self, point): def is_point_far_away(self, point: Union[ifcopenshell.entity_instance, npt.NDArray[np.float64]]) -> bool:
if hasattr(point, "Coordinates"): if hasattr(point, "Coordinates"):
return ( return (
abs(point.Coordinates[0]) > self.threshold abs(point.Coordinates[0]) > self.threshold
+2
View File
@@ -18,6 +18,8 @@
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.representation
from ifcopenshell import template from ifcopenshell import template
@@ -18,6 +18,7 @@
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.api
import ifcsverchok.helper import ifcsverchok.helper
from sverchok.node_tree import SverchCustomTreeNode from sverchok.node_tree import SverchCustomTreeNode
@@ -21,6 +21,7 @@ import bpy
import ifcopenshell import ifcopenshell
import ifcsverchok.helper import ifcsverchok.helper
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.util.representation
from ifcsverchok.ifcstore import SvIfcStore from ifcsverchok.ifcstore import SvIfcStore
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.core.geometry as core import blenderbim.core.geometry as core