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
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.util.element
class Usecase:
@@ -108,13 +109,14 @@ class Usecase:
if fills_voids:
if fills_voids[0].RelatingOpeningElement == self.settings["opening"]:
return
history = fills_voids[0].OwnerHistory
self.file.remove(fills_voids[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.create_entity(
"IfcRelFillsElement",
**{
"GlobalId": ifcopenshell.guid.new(),
"RelatingOpeningElement": self.settings["opening"],
"RelatedBuildingElement": self.settings["element"],
}
GlobalId=ifcopenshell.guid.new(),
RelatingOpeningElement=self.settings["opening"],
RelatedBuildingElement=self.settings["element"],
)
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
import ifcopenshell.util.placement
@@ -108,7 +109,10 @@ class Usecase:
if voids_elements:
if voids_elements[0].RelatingBuildingElement == self.settings["element"]:
return
history = voids_elements[0].OwnerHistory
self.file.remove(voids_elements[0])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
self.file.create_entity(
"IfcRelVoidsElement",
@@ -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, element=None):
@@ -56,5 +59,8 @@ class Usecase:
def execute(self):
for rel in self.file.by_type("IfcRelFillsElement"):
if rel.RelatedBuildingElement == self.settings["element"]:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
break
@@ -49,8 +49,14 @@ class Usecase:
def execute(self):
for rel in self.settings["opening"].VoidsElements:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if self.settings["opening"].is_a("IfcOpeningElement"):
for rel in self.settings["opening"].HasFillings:
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
ifcopenshell.api.run("root.remove_product", self.file, product=self.settings["opening"])