Fix #3974. Bug where orphaned histories would be left in API remove operations.

This commit is contained in:
Dion Moult
2023-11-28 10:45:49 +11:00
parent 58414777be
commit 6e932ec2fb
50 changed files with 314 additions and 86 deletions
@@ -16,6 +16,9 @@
# 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
import ifcopenshell.util.element
class Usecase:
def __init__(self, file, structural_analysis_model=None):
@@ -34,5 +37,11 @@ class Usecase:
def execute(self):
for rel in self.settings["structural_analysis_model"].IsGroupedBy or []:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["structural_analysis_model"].OwnerHistory
self.file.remove(self.settings["structural_analysis_model"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# 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
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -38,6 +40,9 @@ class Usecase:
ifcopenshell.api.run(
"structural.remove_structural_boundary_condition",
self.file,
**{"connection": self.settings["relation"].RelatedStructuralConnection}
connection=self.settings["relation"].RelatedStructuralConnection
)
history = self.settings["relation"].OwnerHistory
self.file.remove(self.settings["relation"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# 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
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -34,5 +36,10 @@ class Usecase:
def execute(self):
# TODO: do a deep purge
for rel in self.settings["load_case"].IsGroupedBy or []:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["load_case"].OwnerHistory
self.file.remove(self.settings["load_case"])
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -16,7 +16,9 @@
# 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
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -35,5 +37,11 @@ class Usecase:
# TODO: do a deep purge
for inverse in self.file.get_inverse(self.settings["load_group"]):
if inverse.is_a("IfcRelAssignsToGroup") and len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["load_group"].OwnerHistory
self.file.remove(self.settings["load_group"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -48,4 +49,7 @@ class Usecase:
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)