mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
system.unassign_system - support batching #4474
This commit is contained in:
@@ -59,7 +59,7 @@ def assign_system(ifc, system=None, product=None):
|
||||
|
||||
|
||||
def unassign_system(ifc, system=None, product=None):
|
||||
ifc.run("system.unassign_system", product=product, system=system)
|
||||
ifc.run("system.unassign_system", products=[product], system=system)
|
||||
|
||||
|
||||
def select_system_products(system_tool, system=None):
|
||||
|
||||
@@ -80,7 +80,7 @@ class TestAssignSystem:
|
||||
|
||||
class TestUnassignSystem:
|
||||
def test_run(self, ifc):
|
||||
ifc.run("system.unassign_system", product="product", system="system").should_be_called()
|
||||
ifc.run("system.unassign_system", products=["product"], system="system").should_be_called()
|
||||
subject.unassign_system(ifc, system="system", product="product")
|
||||
|
||||
|
||||
|
||||
@@ -82,6 +82,9 @@ ARGUMENTS_DEPRECATION = {
|
||||
"system.assign_system": partial(
|
||||
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||
),
|
||||
"system.unassign_system": partial(
|
||||
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,11 +22,16 @@ import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, product=None, system=None):
|
||||
"""Unassigns a product from a system
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.entity_instance,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
system: ifcopenshell.entity_instance,
|
||||
):
|
||||
"""Unassigns list of products from a system
|
||||
|
||||
:param product: The IfcDistributionElement to unassign from the system.
|
||||
:type product: ifcopenshell.entity_instance.entity_instance
|
||||
:param products: The list of IfcDistributionElements to unassign from the system.
|
||||
:type products: list[ifcopenshell.entity_instance.entity_instance]
|
||||
:param system: The IfcSystem you want to unassign the element from.
|
||||
:type system: ifcopenshell.entity_instance.entity_instance
|
||||
:return: None
|
||||
@@ -47,25 +52,15 @@ class Usecase:
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
|
||||
|
||||
# Not anymore!
|
||||
ifcopenshell.api.run("system.unassign_system", model, product=duct, system=system)
|
||||
ifcopenshell.api.run("system.unassign_system", model, products=[duct], system=system)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": product,
|
||||
"products": products,
|
||||
"system": system,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
if not self.settings["system"].IsGroupedBy:
|
||||
return
|
||||
rel = self.settings["system"].IsGroupedBy[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
self.file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
ifcopenshell.api.run(
|
||||
"group.unassign_group", self.file, products=self.settings["products"], group=self.settings["system"]
|
||||
)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# 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 pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.system
|
||||
|
||||
|
||||
class TestUnassignSystem(test.bootstrap.IFC4):
|
||||
def test_unassign_system(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
system = ifcopenshell.api.run("system.add_system", self.file)
|
||||
ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2, element3], system=system)
|
||||
ifcopenshell.api.run("system.unassign_system", self.file, products=[element2, element3], system=system)
|
||||
assert ifcopenshell.util.system.get_system_elements(system) == [element]
|
||||
|
||||
ifcopenshell.api.run("system.unassign_system", self.file, products=[element], system=system)
|
||||
assert ifcopenshell.util.system.get_system_elements(system) == []
|
||||
|
||||
|
||||
class TestUnassignSystemIFC2X3(test.bootstrap.IFC2X3, TestUnassignSystem):
|
||||
pass
|
||||
@@ -19,6 +19,7 @@
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.system
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@@ -151,3 +152,15 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
||||
rel = rels[0]
|
||||
assert rel.RelatingGroup == system
|
||||
assert rel.RelatedObjects == (element,)
|
||||
|
||||
@deprecation_check
|
||||
def test_unassign_system(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
system = ifcopenshell.api.run("system.add_system", self.file)
|
||||
ifcopenshell.api.run("system.assign_system", self.file, products=[element, element2], system=system)
|
||||
ifcopenshell.api.run("system.unassign_system", self.file, product=element, system=system)
|
||||
assert ifcopenshell.util.system.get_system_elements(system) == [element2]
|
||||
|
||||
ifcopenshell.api.run("system.unassign_system", self.file, product=element2, system=system)
|
||||
assert ifcopenshell.util.system.get_system_elements(system) == []
|
||||
|
||||
Reference in New Issue
Block a user