mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
api for assigning/unassigning flow controls #3981
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcOpenShell.
|
||||
#
|
||||
# IfcOpenShell is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcOpenShell is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAssignFlowControl(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
flow_element = self.file.createIfcFlowSegment()
|
||||
flow_control = self.file.createIfcController()
|
||||
|
||||
# simple assignment
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelFlowControlElements")) == 1
|
||||
assert relation.RelatingFlowElement == flow_element
|
||||
assert relation.RelatedControlElements == (flow_control,)
|
||||
|
||||
# trying to establish existing relationship
|
||||
relation0 = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
assert relation == relation0
|
||||
|
||||
# assigning same control to another object
|
||||
flow_element1 = self.file.createIfcFlowSegment()
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element1,
|
||||
)
|
||||
assert relation is None
|
||||
|
||||
# assigning another control to the same object
|
||||
flow_control1 = self.file.createIfcController()
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control1,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelFlowControlElements")) == 1
|
||||
assert relation.RelatingFlowElement == flow_element
|
||||
assert set(relation.RelatedControlElements) == set((flow_control, flow_control1))
|
||||
@@ -0,0 +1,64 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcOpenShell.
|
||||
#
|
||||
# IfcOpenShell is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcOpenShell is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestUnassignFlowControl(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
flow_element = self.file.createIfcFlowSegment()
|
||||
flow_control = self.file.createIfcController()
|
||||
|
||||
# assign and unassign
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"system.unassign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelFlowControlElements")) == 0
|
||||
|
||||
# 1 element 2 controls
|
||||
flow_control1 = self.file.createIfcController()
|
||||
relation = ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control1,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"system.unassign_flow_control",
|
||||
self.file,
|
||||
related_flow_control=flow_control1,
|
||||
relating_flow_element=flow_element,
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelFlowControlElements")) == 1
|
||||
assert relation.RelatedControlElements == (flow_control,)
|
||||
Reference in New Issue
Block a user