mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
typing
This commit is contained in:
@@ -56,13 +56,10 @@ def add_axis_representation(
|
||||
:param context: The IfcGeometricRepresentationContext that the
|
||||
representation is part of. This must be either a
|
||||
Model/Axis/GRAPH_VIEW (3D) or Plan/Axis/GRAPH_VIEW (2D).
|
||||
:type context: ifcopenshell.entity_instance
|
||||
:param axis: The axis, as a list of two coordinates, the coordinates
|
||||
being either a list of 2 or 3 float coordinates depending on whether
|
||||
the axis is 2D or 3D.
|
||||
:type axis: list[list[float]]
|
||||
:return: The newly created IfcShapeRepresentation entity
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
@@ -29,20 +29,14 @@ def connect_element(
|
||||
related_element: ifcopenshell.entity_instance,
|
||||
description: Optional[str] = None,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
settings = {
|
||||
"relating_element": relating_element,
|
||||
"related_element": related_element,
|
||||
"description": description,
|
||||
}
|
||||
|
||||
incompatible_connections = []
|
||||
|
||||
for rel in settings["relating_element"].ConnectedFrom:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatingElement == settings["related_element"]:
|
||||
for rel in relating_element.ConnectedFrom:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatingElement == related_element:
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
for rel in settings["related_element"].ConnectedTo:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == settings["relating_element"]:
|
||||
for rel in related_element.ConnectedTo:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == relating_element:
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
if incompatible_connections:
|
||||
@@ -52,15 +46,15 @@ def connect_element(
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
|
||||
for rel in settings["relating_element"].ConnectedTo:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == settings["related_element"]:
|
||||
rel.Description = settings["description"]
|
||||
for rel in relating_element.ConnectedTo:
|
||||
if rel.is_a() == "IfcRelConnectsElements" and rel.RelatedElement == related_element:
|
||||
rel.Description = description
|
||||
return rel
|
||||
|
||||
return file.createIfcRelConnectsElements(
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.owner.create_owner_history(file),
|
||||
Description=settings["description"],
|
||||
RelatingElement=settings["relating_element"],
|
||||
RelatedElement=settings["related_element"],
|
||||
Description=description,
|
||||
RelatingElement=relating_element,
|
||||
RelatedElement=related_element,
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
from typing import Any
|
||||
|
||||
|
||||
def map_representation(
|
||||
@@ -25,15 +24,14 @@ def map_representation(
|
||||
) -> ifcopenshell.entity_instance:
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {"representation": representation}
|
||||
return usecase.execute()
|
||||
return usecase.execute(representation)
|
||||
|
||||
|
||||
class Usecase:
|
||||
file: ifcopenshell.file
|
||||
settings: dict[str, Any]
|
||||
|
||||
def execute(self) -> ifcopenshell.entity_instance:
|
||||
def execute(self, representation: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
||||
self.representation = representation
|
||||
mapping_source = self.get_mapping_source()
|
||||
|
||||
zero = self.file.createIfcCartesianPoint((0.0, 0.0, 0.0))
|
||||
@@ -46,15 +44,15 @@ class Usecase:
|
||||
return self.file.create_entity(
|
||||
"IfcShapeRepresentation",
|
||||
**{
|
||||
"ContextOfItems": self.settings["representation"].ContextOfItems,
|
||||
"RepresentationIdentifier": self.settings["representation"].RepresentationIdentifier,
|
||||
"ContextOfItems": representation.ContextOfItems,
|
||||
"RepresentationIdentifier": representation.RepresentationIdentifier,
|
||||
"RepresentationType": "MappedRepresentation",
|
||||
"Items": [mapped_item],
|
||||
}
|
||||
)
|
||||
|
||||
def get_mapping_source(self) -> ifcopenshell.entity_instance:
|
||||
for inverse in self.file.get_inverse(self.settings["representation"]):
|
||||
for inverse in self.file.get_inverse(self.representation):
|
||||
if inverse.is_a("IfcRepresentationMap"):
|
||||
return inverse
|
||||
zero = self.file.createIfcCartesianPoint((0.0, 0.0, 0.0))
|
||||
@@ -62,5 +60,5 @@ class Usecase:
|
||||
z_axis = self.file.createIfcDirection((0.0, 0.0, 1.0))
|
||||
mapping_origin = self.file.createIfcAxis2Placement3D(zero, z_axis, x_axis)
|
||||
return self.file.createIfcRepresentationMap(
|
||||
MappingOrigin=mapping_origin, MappedRepresentation=self.settings["representation"]
|
||||
MappingOrigin=mapping_origin, MappedRepresentation=self.representation
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user