mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -21,57 +21,54 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, relating_flow_element=None, related_flow_control=None):
|
||||
"""Unassigns flow control element from the flow element.
|
||||
def unassign_flow_control(file, relating_flow_element=None, related_flow_control=None) -> None:
|
||||
"""Unassigns flow control element from the flow element.
|
||||
|
||||
:param related_flow_control: IfcDistributionControlElement controling the
|
||||
flow element
|
||||
:type related_flow_control: ifcopenshell.entity_instance
|
||||
:param relating_flow_element: The IfcDistributionFlowElement that is being controlled
|
||||
:type relating_flow_element: ifcopenshell.entity_instance
|
||||
:return: If the control still is related to other objects, the
|
||||
IfcRelFlowControlElements is returned, otherwise None.
|
||||
:rtype: ifcopenshell.entity_instance, None
|
||||
:param related_flow_control: IfcDistributionControlElement controling the
|
||||
flow element
|
||||
:type related_flow_control: ifcopenshell.entity_instance
|
||||
:param relating_flow_element: The IfcDistributionFlowElement that is being controlled
|
||||
:type relating_flow_element: ifcopenshell.entity_instance
|
||||
:return: If the control still is related to other objects, the
|
||||
IfcRelFlowControlElements is returned, otherwise None.
|
||||
:rtype: ifcopenshell.entity_instance, None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
# assign control to the flow element
|
||||
flow_element = self.file.createIfcFlowSegment()
|
||||
flow_control = self.file.createIfcController()
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control", self.file,
|
||||
relating_control=flow_control, related_object=flow_element
|
||||
)
|
||||
# assign control to the flow element
|
||||
flow_element = file.createIfcFlowSegment()
|
||||
flow_control = file.createIfcController()
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control", file,
|
||||
relating_control=flow_control, related_object=flow_element
|
||||
)
|
||||
|
||||
# und unassign it
|
||||
ifcopenshell.api.run("system.unassign_flow_control", self.file,
|
||||
relating_control=flow_control, related_object=flow_element
|
||||
)
|
||||
"""
|
||||
# und unassign it
|
||||
ifcopenshell.api.run("system.unassign_flow_control", file,
|
||||
relating_control=flow_control, related_object=flow_element
|
||||
)
|
||||
"""
|
||||
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"relating_flow_element": relating_flow_element,
|
||||
"related_flow_control": related_flow_control,
|
||||
}
|
||||
settings = {
|
||||
"relating_flow_element": relating_flow_element,
|
||||
"related_flow_control": related_flow_control,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
if not self.settings["related_flow_control"].AssignedToFlowElement:
|
||||
return
|
||||
assignment = self.settings["related_flow_control"].AssignedToFlowElement[0]
|
||||
if assignment.RelatingFlowElement != self.settings["relating_flow_element"]:
|
||||
return
|
||||
if len(assignment.RelatedControlElements) == 1:
|
||||
history = assignment.OwnerHistory
|
||||
self.file.remove(assignment)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
return
|
||||
related_flow_controls = list(assignment.RelatedControlElements)
|
||||
related_flow_controls.remove(self.settings["related_flow_control"])
|
||||
assignment.RelatedControlElements = related_flow_controls
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": assignment})
|
||||
return assignment
|
||||
if not settings["related_flow_control"].AssignedToFlowElement:
|
||||
return
|
||||
assignment = settings["related_flow_control"].AssignedToFlowElement[0]
|
||||
if assignment.RelatingFlowElement != settings["relating_flow_element"]:
|
||||
return
|
||||
if len(assignment.RelatedControlElements) == 1:
|
||||
history = assignment.OwnerHistory
|
||||
file.remove(assignment)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
return
|
||||
related_flow_controls = list(assignment.RelatedControlElements)
|
||||
related_flow_controls.remove(settings["related_flow_control"])
|
||||
assignment.RelatedControlElements = related_flow_controls
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": assignment})
|
||||
return assignment
|
||||
|
||||
Reference in New Issue
Block a user