mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix #4203. Fix bug where removing nested cost items left orphaned relationships.
This commit is contained in:
@@ -22,7 +22,7 @@ from datetime import datetime
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, name=None, predefined_type="NOTDEFINED", object_type=None):
|
||||
def __init__(self, file, name=None, predefined_type="NOTDEFINED"):
|
||||
"""Add a new cost schedule
|
||||
|
||||
A cost schedule is a group of cost items which typically represent a
|
||||
@@ -54,7 +54,7 @@ class Usecase:
|
||||
item = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"name": name, "predefined_type": predefined_type, "object_type": object_type}
|
||||
self.settings = {"name": name, "predefined_type": predefined_type}
|
||||
|
||||
def execute(self):
|
||||
cost_schedule = ifcopenshell.api.run(
|
||||
@@ -65,6 +65,4 @@ class Usecase:
|
||||
name=self.settings["name"],
|
||||
)
|
||||
cost_schedule.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
|
||||
if self.settings["object_type"]:
|
||||
cost_schedule.ObjectType = self.settings["object_type"]
|
||||
return cost_schedule
|
||||
|
||||
@@ -52,7 +52,7 @@ class Usecase:
|
||||
if inverse.RelatingObject == self.settings["cost_item"]:
|
||||
for related_object in inverse.RelatedObjects:
|
||||
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=related_object)
|
||||
elif inverse.RelatedObjects == tuple(self.settings["cost_item"]):
|
||||
elif inverse.RelatedObjects == (self.settings["cost_item"],):
|
||||
history = inverse.OwnerHistory
|
||||
self.file.remove(inverse)
|
||||
if history:
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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/>.
|
||||
@@ -0,0 +1,17 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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/>.
|
||||
@@ -0,0 +1,36 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 TestAddCostItem(test.bootstrap.IFC4):
|
||||
def test_add_a_cost_item(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
assert item1.is_a("IfcCostItem")
|
||||
assert item1.HasAssignments[0].is_a("IfcRelAssignsToControl")
|
||||
assert item1.HasAssignments[0].RelatingControl == schedule
|
||||
|
||||
def test_add_a_sub_cost_item(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
|
||||
assert item2.is_a("IfcCostItem")
|
||||
assert item2.Nests[0].RelatingObject == item1
|
||||
@@ -0,0 +1,35 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 TestAddCostSchedule(test.bootstrap.IFC4):
|
||||
def test_add_a_cost_schedule(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
assert schedule.is_a("IfcCostSchedule")
|
||||
assert schedule.Name == "Foo"
|
||||
assert schedule.PredefinedType == "BUDGET"
|
||||
|
||||
def test_adding_a_userdefined_type(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="FOO")
|
||||
assert schedule.is_a("IfcCostSchedule")
|
||||
assert schedule.Name == "Foo"
|
||||
assert schedule.PredefinedType == "USERDEFINED"
|
||||
assert schedule.ObjectType == "FOO"
|
||||
@@ -0,0 +1,47 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 TestRemoveCostItem(test.bootstrap.IFC4):
|
||||
def test_remove_a_cost_item(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item1)
|
||||
assert not self.file.by_type("IfcCostItem")
|
||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||
|
||||
def test_remove_a_sub_cost_item(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
|
||||
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item2)
|
||||
assert self.file.by_type("IfcCostItem") == [item1]
|
||||
assert self.file.by_type("IfcRelAssignsToControl")
|
||||
assert not self.file.by_type("IfcRelNests")
|
||||
|
||||
def test_remove_a_parent_cost_item(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
|
||||
ifcopenshell.api.run("cost.remove_cost_item", self.file, cost_item=item1)
|
||||
assert not self.file.by_type("IfcCostItem")
|
||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||
assert not self.file.by_type("IfcRelNests")
|
||||
@@ -0,0 +1,37 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 TestRemoveCostSchedule(test.bootstrap.IFC4):
|
||||
def test_remove_a_cost_schedule(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
ifcopenshell.api.run("cost.remove_cost_schedule", self.file, cost_schedule=schedule)
|
||||
assert not self.file.by_type("IfcCostSchedule")
|
||||
|
||||
def test_remove_a_schedule_with_items(self):
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file, name="Foo", predefined_type="BUDGET")
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
|
||||
ifcopenshell.api.run("cost.remove_cost_schedule", self.file, cost_schedule=schedule)
|
||||
assert not self.file.by_type("IfcCostSchedule")
|
||||
assert not self.file.by_type("IfcCostItem")
|
||||
assert not self.file.by_type("IfcRelNests")
|
||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||
Reference in New Issue
Block a user