mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Merge remote-tracking branch 'origin/v0.8.0' into tfk-rocksdb-storage
This commit is contained in:
@@ -27,23 +27,33 @@ class TestAssignControl(test.bootstrap.IFC4):
|
||||
control = ifcopenshell.api.cost.add_cost_schedule(self.file)
|
||||
|
||||
# simple assignment
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
|
||||
assert relation
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatingControl == control
|
||||
assert relation.RelatedObjects == (wall,)
|
||||
|
||||
# trying to establish existing relationship
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
|
||||
assert relation is None
|
||||
|
||||
# assigning same control to another object
|
||||
wall1 = self.file.createIfcWall()
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall1)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall1])
|
||||
assert relation is not None
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatingControl == control
|
||||
assert set(relation.RelatedObjects) == set((wall, wall1))
|
||||
|
||||
def test_batch_assignment(self):
|
||||
walls = [self.file.createIfcWall() for _ in range(5)]
|
||||
control = ifcopenshell.api.cost.add_cost_schedule(self.file)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=walls)
|
||||
assert relation
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatingControl == control
|
||||
assert set(relation.RelatedObjects) == set(walls)
|
||||
|
||||
|
||||
class TestAssignControlIFC2X3(test.bootstrap.IFC2X3, TestAssignControl):
|
||||
pass
|
||||
|
||||
@@ -27,15 +27,17 @@ class TestUnassignControl(test.bootstrap.IFC4):
|
||||
control = ifcopenshell.api.cost.add_cost_schedule(self.file)
|
||||
|
||||
# assign and unassign
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
|
||||
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
|
||||
assert relation
|
||||
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_objects=[wall])
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 0
|
||||
|
||||
# 1 control 2 related objects
|
||||
wall1 = self.file.createIfcWall()
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall)
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_object=wall1)
|
||||
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall1)
|
||||
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
|
||||
assert relation
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall1])
|
||||
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_objects=[wall1])
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatedObjects == (wall,)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestAddCostItemQuantity(test.bootstrap.IFC4):
|
||||
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file)
|
||||
item = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=item, related_object=wall)
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=item, related_objects=[wall])
|
||||
|
||||
quantities = []
|
||||
for quantity_type in quantity_types:
|
||||
|
||||
@@ -95,7 +95,7 @@ class TestEditTaskTime(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
calendar = ifcopenshell.api.sequence.add_work_calendar(self.file)
|
||||
task = self.file.createIfcTask()
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=calendar, related_object=task)
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=calendar, related_objects=[task])
|
||||
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task=task)
|
||||
ifcopenshell.api.sequence.edit_task_time(
|
||||
self.file,
|
||||
@@ -195,7 +195,7 @@ class TestEditTaskTime(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
calendar = ifcopenshell.api.sequence.add_work_calendar(self.file)
|
||||
task = self.file.createIfcTask()
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=calendar, related_object=task)
|
||||
ifcopenshell.api.control.assign_control(self.file, relating_control=calendar, related_objects=[task])
|
||||
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task=task)
|
||||
ifcopenshell.api.sequence.edit_task_time(
|
||||
self.file,
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestRemoveWorkCalendar(test.bootstrap.IFC4):
|
||||
|
||||
# Assign tasks.
|
||||
task = ifcopenshell.api.sequence.add_task(self.file)
|
||||
ifcopenshell.api.control.assign_control(self.file, work_calendar, task)
|
||||
ifcopenshell.api.control.assign_control(self.file, work_calendar, [task])
|
||||
|
||||
ifcopenshell.api.sequence.remove_work_calendar(self.file, work_calendar)
|
||||
|
||||
|
||||
@@ -16,19 +16,39 @@
|
||||
# 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 ifcopenshell.api.cost
|
||||
import ifcopenshell.api.root
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.control
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.util.element
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
|
||||
def deprecation_check(test):
|
||||
def new_test(self):
|
||||
assert datetime.now().date() < datetime(2024, 8, 1).date(), "API arguments are completely deprecated"
|
||||
assert datetime.now().date() < datetime(2026, 1, 9).date(), "API arguments are completely deprecated"
|
||||
test(self)
|
||||
|
||||
return new_test
|
||||
|
||||
|
||||
class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
||||
pass
|
||||
@deprecation_check
|
||||
def test_assigning_control(self):
|
||||
model = self.file
|
||||
element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
control = ifcopenshell.api.cost.add_cost_schedule(model)
|
||||
ifcopenshell.api.control.assign_control(model, relating_control=control, related_objects=[element])
|
||||
assert list(ifcopenshell.util.element.get_controls(element)) == [control]
|
||||
|
||||
@deprecation_check
|
||||
def test_unassigning_control(self):
|
||||
TestTemporarySupportForDeprecatedAPIArguments.test_assigning_control(self)
|
||||
model = self.file
|
||||
element = model.by_type("IfcWall")[0]
|
||||
control = model.by_type("IfcCostSchedule")[0]
|
||||
ifcopenshell.api.control.unassign_control(model, relating_control=control, related_objects=[element])
|
||||
assert list(ifcopenshell.util.element.get_controls(element)) == []
|
||||
|
||||
@@ -145,14 +145,20 @@ class TestAssignType(test.bootstrap.IFC4):
|
||||
This is because the type will have its own PredefinedType, and the element's PredefinedType
|
||||
will conflict with it. (See #7006)
|
||||
"""
|
||||
is_ifc2x3 = self.file.schema == "IFC2X3"
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "MOVABLE"
|
||||
element_type.PredefinedType = "POLYGONAL"
|
||||
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
if not is_ifc2x3:
|
||||
# In IFC2X3, there seems to be no example when both type and occurence have PredefinedType.
|
||||
# So we just ignore it.
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
element.ObjectType = "Test"
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert element.PredefinedType is None
|
||||
|
||||
if not is_ifc2x3:
|
||||
assert element.PredefinedType is None
|
||||
assert element.ObjectType is None
|
||||
|
||||
def test_keep_predefined_type_if_type_assignment_is_notdefined(self):
|
||||
@@ -160,16 +166,26 @@ class TestAssignType(test.bootstrap.IFC4):
|
||||
if an element has a PredefinedType, it will be removed when assigning a type.(See #7006)
|
||||
This behavior needs to be blocked if the PredefinedType of the typing Entity is set to "NOTDEFINED". (See #7011)
|
||||
"""
|
||||
is_ifc2x3 = self.file.schema == "IFC2X3"
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "NOTDEFINED"
|
||||
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
if not is_ifc2x3:
|
||||
# In IFC2X3, there seems to be no example when both type and occurence have PredefinedType.
|
||||
# So we just ignore it.
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
element.ObjectType = "Test"
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
|
||||
if not is_ifc2x3:
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ObjectType == "Test"
|
||||
|
||||
|
||||
class TestAssignTypeIFC2X3(test.bootstrap.IFC2X3, TestAssignType):
|
||||
pass
|
||||
|
||||
|
||||
class TestAssignTypeIFC4X3(test.bootstrap.IFC4X3, TestAssignType):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user