2022-01-19 12:18:33 +11:00
|
|
|
# IfcOpenShell - IFC toolkit and geometry engine
|
|
|
|
|
# Copyright (C) 2021 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/>.
|
|
|
|
|
|
|
|
|
|
|
2021-01-21 21:58:27 +11:00
|
|
|
class Usecase:
|
2022-11-21 12:05:30 +09:00
|
|
|
def __init__(self, file, classification=None):
|
2022-11-15 16:11:47 +09:00
|
|
|
"""Removes an IfcClassification from the project and all references
|
|
|
|
|
|
|
|
|
|
The classification and all of its relationships, children references,
|
|
|
|
|
and relationships between objectse and child references are completely
|
|
|
|
|
removed from a project.
|
|
|
|
|
|
|
|
|
|
:param classification: The IfcClassification entity you want to remove
|
|
|
|
|
:type classification: ifcopenshell.entity_instance.entity_instance
|
|
|
|
|
:return: None
|
|
|
|
|
:rtype: None
|
|
|
|
|
|
2023-01-10 10:16:28 +11:00
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code:: python
|
2022-11-15 16:11:47 +09:00
|
|
|
|
|
|
|
|
classification = model.by_type("IfcClassification")[0]
|
|
|
|
|
ifcopenshell.api.run("classification.remove_classification", model,
|
|
|
|
|
classification=classification)
|
|
|
|
|
"""
|
2021-01-21 21:58:27 +11:00
|
|
|
self.file = file
|
2022-11-15 16:11:47 +09:00
|
|
|
self.settings = {"classification": classification}
|
2021-01-21 21:58:27 +11:00
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
|
references = self.get_references(self.settings["classification"])
|
|
|
|
|
for reference in references:
|
|
|
|
|
self.file.remove(reference)
|
|
|
|
|
self.file.remove(self.settings["classification"])
|
|
|
|
|
for rel in self.file.by_type("IfcRelAssociatesClassification"):
|
|
|
|
|
if not rel.RelatingClassification:
|
|
|
|
|
self.file.remove(rel)
|
2022-09-05 16:51:42 +10:00
|
|
|
for rel in self.file.by_type("IfcExternalReferenceRelationship"):
|
|
|
|
|
if not rel.RelatingReference:
|
|
|
|
|
self.file.remove(rel)
|
2021-01-21 21:58:27 +11:00
|
|
|
|
|
|
|
|
def get_references(self, classification):
|
|
|
|
|
results = []
|
|
|
|
|
if not classification.HasReferences:
|
|
|
|
|
return results
|
|
|
|
|
for reference in classification.HasReferences:
|
|
|
|
|
results.append(reference)
|
|
|
|
|
results.extend(self.get_references(reference))
|
|
|
|
|
return results
|