mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 18:57:17 +00:00
implement _try_purge
per review comment about repeating code
This commit is contained in:
committed by
Thomas Krijnen
parent
3a0aaee03b
commit
afa803ea62
@@ -180,6 +180,19 @@ class Usecase:
|
|||||||
"""
|
"""
|
||||||
return prop.Name in self.settings["properties"]
|
return prop.Name in self.settings["properties"]
|
||||||
|
|
||||||
|
def _try_purge(self, prop) -> bool:
|
||||||
|
"""
|
||||||
|
Tried to remove the property
|
||||||
|
if successful, returns True, otherwise False
|
||||||
|
NOTE: Assumes the prop exists
|
||||||
|
"""
|
||||||
|
if not self.settings["should_purge"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
del self.settings["properties"][prop.Name]
|
||||||
|
self.file.remove(prop)
|
||||||
|
return True
|
||||||
|
|
||||||
# TODO - Add support for changing property types?
|
# TODO - Add support for changing property types?
|
||||||
# For example - IfcPropertyEnumeratedValue to
|
# For example - IfcPropertyEnumeratedValue to
|
||||||
# IfcPropertySingleValue. Or maybe the user should
|
# IfcPropertySingleValue. Or maybe the user should
|
||||||
@@ -197,7 +210,7 @@ class Usecase:
|
|||||||
|
|
||||||
def update_existing_enum(self, prop):
|
def update_existing_enum(self, prop):
|
||||||
"""
|
"""
|
||||||
NOTE: assumes the prop exists
|
NOTE: Assumes the prop exists
|
||||||
"""
|
"""
|
||||||
value = self.settings["properties"][prop.Name]
|
value = self.settings["properties"][prop.Name]
|
||||||
unit, value = self.unpack_unit_value(value)
|
unit, value = self.unpack_unit_value(value)
|
||||||
@@ -217,9 +230,7 @@ class Usecase:
|
|||||||
and value.is_a("IfcPropertyEnumeratedValue")
|
and value.is_a("IfcPropertyEnumeratedValue")
|
||||||
):
|
):
|
||||||
if not value.EnumerationReference.EnumerationValues:
|
if not value.EnumerationReference.EnumerationValues:
|
||||||
if self.settings["should_purge"]:
|
if self._try_purge(prop):
|
||||||
del self.settings["properties"][prop.Name]
|
|
||||||
self.file.remove(prop)
|
|
||||||
return
|
return
|
||||||
prop.EnumerationReference.EnumerationValues = None
|
prop.EnumerationReference.EnumerationValues = None
|
||||||
prop.EnumerationValues = None
|
prop.EnumerationValues = None
|
||||||
@@ -234,14 +245,12 @@ class Usecase:
|
|||||||
|
|
||||||
def update_existing_property(self, prop):
|
def update_existing_property(self, prop):
|
||||||
"""
|
"""
|
||||||
NOTE: assumes the prop exists
|
NOTE: Assumes the prop exists
|
||||||
"""
|
"""
|
||||||
value = self.settings["properties"][prop.Name]
|
value = self.settings["properties"][prop.Name]
|
||||||
unit, value = self.unpack_unit_value(value)
|
unit, value = self.unpack_unit_value(value)
|
||||||
if value is None:
|
if value is None:
|
||||||
if self.settings["should_purge"]:
|
if self._try_purge(prop):
|
||||||
del self.settings["properties"][prop.Name]
|
|
||||||
self.file.remove(prop)
|
|
||||||
return
|
return
|
||||||
prop.NominalValue = None
|
prop.NominalValue = None
|
||||||
elif isinstance(value, ifcopenshell.entity_instance):
|
elif isinstance(value, ifcopenshell.entity_instance):
|
||||||
|
|||||||
Reference in New Issue
Block a user