This commit is contained in:
Andrej730
2024-07-15 14:40:33 +05:00
parent 7e117bca90
commit 66877c227b
2 changed files with 54 additions and 10 deletions
+1
View File
@@ -23,6 +23,7 @@ import bpy
import bmesh import bmesh
import ifcopenshell.geom import ifcopenshell.geom
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.shape
import ifcopenshell.util.unit import ifcopenshell.util.unit
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
@@ -20,15 +20,50 @@ import numpy as np
import numpy.typing as npt import numpy.typing as npt
import ifcopenshell import ifcopenshell
import ifcopenshell.util.placement import ifcopenshell.util.placement
from typing import Optional, Union, TypedDict from typing import Optional, Union, TypedDict, Literal
CONTEXT_TYPE = Literal["Model", "Plan", "NotDefined"]
REPRESENTATION_IDENTIFIER = Literal[
"CoG",
"Box",
"Annotation",
"Axis",
"FootPrint",
"Profile",
"Surface",
"Reference",
"Body",
"Body-Fallback",
"Clearance",
"Lighting",
]
TARGET_VIEW = Literal[
"ELEVATION_VIEW",
"GRAPH_VIEW",
"MODEL_VIEW",
"PLAN_VIEW",
"REFLECTED_PLAN_VIEW",
"SECTION_VIEW",
"SKETCH_VIEW",
"USERDEFINED",
"NOTDEFINED",
]
def get_context( def get_context(
ifc_file: ifcopenshell.file, ifc_file: ifcopenshell.file,
context: str, context: CONTEXT_TYPE,
subcontext: Optional[str] = None, subcontext: Optional[REPRESENTATION_IDENTIFIER] = None,
target_view: Optional[str] = None, target_view: Optional[TARGET_VIEW] = None,
) -> Union[ifcopenshell.entity_instance, None]: ) -> Union[ifcopenshell.entity_instance, None]:
"""Get IfcGeometricRepresentationSubContext by the provided context type, identifier, and target view.
:param context: ContextType.
:param subcontext: A ContextIdentifier string, or any if left blank.
:param target_view: A TargetView string, or any if left blank.
"""
if subcontext or target_view: if subcontext or target_view:
elements = ifc_file.by_type("IfcGeometricRepresentationSubContext") elements = ifc_file.by_type("IfcGeometricRepresentationSubContext")
else: else:
@@ -45,10 +80,18 @@ def get_context(
def is_representation_of_context( def is_representation_of_context(
representation: ifcopenshell.entity_instance, representation: ifcopenshell.entity_instance,
context: Union[ifcopenshell.entity_instance, str], context: Union[ifcopenshell.entity_instance, CONTEXT_TYPE],
subcontext: Optional[str] = None, subcontext: Optional[REPRESENTATION_IDENTIFIER] = None,
target_view: Optional[str] = None, target_view: Optional[TARGET_VIEW] = None,
) -> bool: ) -> bool:
"""Check if representation has specified context or context type, identifier, and target view.
:param representation: IfcShapeRepresentation.
:param context: Either a specific IfcGeometricRepresentationContext or a ContextType.
:param subcontext: A ContextIdentifier string, or any if left blank.
:param target_view: A TargetView string, or any if left blank.
"""
if isinstance(context, ifcopenshell.entity_instance): if isinstance(context, ifcopenshell.entity_instance):
return representation.ContextOfItems == context return representation.ContextOfItems == context
@@ -71,9 +114,9 @@ def is_representation_of_context(
def get_representation( def get_representation(
element: ifcopenshell.entity_instance, element: ifcopenshell.entity_instance,
context: Union[ifcopenshell.entity_instance, str], context: Union[ifcopenshell.entity_instance, CONTEXT_TYPE],
subcontext: Optional[str] = None, subcontext: Optional[REPRESENTATION_IDENTIFIER] = None,
target_view: Optional[str] = None, target_view: Optional[TARGET_VIEW] = None,
) -> Union[ifcopenshell.entity_instance, None]: ) -> Union[ifcopenshell.entity_instance, None]:
"""Gets a IfcShapeRepresentation filtered by the context type, identifier, and target view """Gets a IfcShapeRepresentation filtered by the context type, identifier, and target view