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/>.
|
|
|
|
|
|
|
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
def remove_metric(file, metric=None) -> None:
|
|
|
|
|
"""Remove a metric benchmark
|
|
|
|
|
|
|
|
|
|
Removes a metric benchmark and all of its associations to any products
|
|
|
|
|
and objectives.
|
2022-11-16 08:56:55 +09:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
:param metric: The IfcMetric you want to remove.
|
|
|
|
|
:type metric: ifcopenshell.entity_instance
|
|
|
|
|
:return: None
|
|
|
|
|
:rtype: None
|
2022-11-16 08:56:55 +09:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
Example:
|
2022-11-16 08:56:55 +09:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
.. code:: python
|
2023-01-10 10:16:28 +11:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
objective = ifcopenshell.api.run("constraint.add_objective", model)
|
|
|
|
|
metric = ifcopenshell.api.run("constraint.add_metric", model,
|
|
|
|
|
objective=objective)
|
|
|
|
|
ifcopenshell.api.run("constraint.remove_metric", model,
|
|
|
|
|
metric=metric)
|
|
|
|
|
"""
|
|
|
|
|
usecase = Usecase()
|
|
|
|
|
usecase.file = file
|
|
|
|
|
usecase.settings = {"metric": metric}
|
|
|
|
|
return usecase.execute()
|
2022-11-16 08:56:55 +09:00
|
|
|
|
2021-08-16 01:35:14 +01:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
class Usecase:
|
2021-08-16 01:35:14 +01:00
|
|
|
def execute(self):
|
2023-08-22 19:36:01 +01:00
|
|
|
if self.settings["metric"].ReferencePath:
|
|
|
|
|
reference = self.settings["metric"].ReferencePath
|
|
|
|
|
self.delete_reference(reference)
|
|
|
|
|
|
2021-08-16 01:35:14 +01:00
|
|
|
self.file.remove(self.settings["metric"])
|
|
|
|
|
for rel in self.file.by_type("IfcRelAssociatesConstraint"):
|
|
|
|
|
if not rel.RelatingConstraint:
|
2023-11-28 10:45:49 +11:00
|
|
|
history = rel.OwnerHistory
|
2021-08-16 01:35:14 +01:00
|
|
|
self.file.remove(rel)
|
2023-11-28 10:45:49 +11:00
|
|
|
if history:
|
|
|
|
|
ifcopenshell.util.element.remove_deep2(self.file, history)
|
2021-08-16 01:35:14 +01:00
|
|
|
for resource_rel in self.file.by_type("IfcResourceConstraintRelationship"):
|
|
|
|
|
if not resource_rel.RelatingConstraint:
|
|
|
|
|
self.file.remove(resource_rel)
|
2023-08-22 19:36:01 +01:00
|
|
|
|
|
|
|
|
def delete_reference(self, reference):
|
|
|
|
|
if reference.InnerReference:
|
|
|
|
|
self.delete_reference(reference.InnerReference)
|
|
|
|
|
self.file.remove(reference)
|