mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Fix #4649. Bug where editing property set template enumerations didn't clean up properly.
This commit is contained in:
@@ -47,7 +47,20 @@ def edit_prop_template(
|
||||
ifcopenshell.api.run("pset_template.edit_prop_template", model,
|
||||
prop_template=prop, attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLengthMeasure"})
|
||||
"""
|
||||
settings = {"prop_template": prop_template, "attributes": attributes}
|
||||
if enum_values := attributes.get("Enumerators", None):
|
||||
prop_name = attributes.get("Name", None) or getattr(prop_template, "Name", None) or "Unnamed"
|
||||
primary_measure_type = (
|
||||
attributes.get("PrimaryMeasureType", None) or getattr(prop_template, "PrimaryMeasureType", None) or "IfcLabel"
|
||||
)
|
||||
enum_values = [file.create_entity(primary_measure_type, v) for v in enum_values]
|
||||
if enumerators := prop_template.Enumerators:
|
||||
enumerators.Name = prop_name
|
||||
enumerators.EnumerationValues = enum_values
|
||||
else:
|
||||
prop_template.Enumerators = file.create_entity("IfcPropertyEnumeration", prop_name, enum_values)
|
||||
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["prop_template"], name, value)
|
||||
if "Enumerators" in attributes:
|
||||
del attributes["Enumerators"]
|
||||
|
||||
for name, value in attributes.items():
|
||||
setattr(prop_template, name, value)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# 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/>.
|
||||
@@ -0,0 +1,62 @@
|
||||
# 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/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestEditPropTemplate(test.bootstrap.IFC4):
|
||||
def test_editing_a_simple_template(self):
|
||||
template = ifcopenshell.api.run("pset_template.add_pset_template", self.file, name="ABC_RiskFactors")
|
||||
prop = ifcopenshell.api.run("pset_template.add_prop_template", self.file, pset_template=template)
|
||||
ifcopenshell.api.run(
|
||||
"pset_template.edit_prop_template",
|
||||
self.file,
|
||||
prop_template=prop,
|
||||
attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLabel"},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset_template.edit_prop_template", self.file, prop_template=prop, attributes={"Name": "DemoB"}
|
||||
)
|
||||
assert prop.Name == "DemoB"
|
||||
|
||||
def test_editing_an_enumeration(self):
|
||||
template = ifcopenshell.api.run("pset_template.add_pset_template", self.file, name="ABC_RiskFactors")
|
||||
prop = ifcopenshell.api.run("pset_template.add_prop_template", self.file, pset_template=template)
|
||||
ifcopenshell.api.run(
|
||||
"pset_template.edit_prop_template",
|
||||
self.file,
|
||||
prop_template=prop,
|
||||
attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLabel"},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset_template.edit_prop_template",
|
||||
self.file,
|
||||
prop_template=prop,
|
||||
attributes={"Enumerators": ["FOO", "BAR"]},
|
||||
)
|
||||
assert prop.Enumerators.EnumerationValues == tuple(self.file.createIfcLabel(v) for v in ("FOO", "BAR"))
|
||||
ifcopenshell.api.run(
|
||||
"pset_template.edit_prop_template",
|
||||
self.file,
|
||||
prop_template=prop,
|
||||
attributes={"Name": "DemoC", "Enumerators": ["BAZ", "BAR"]},
|
||||
)
|
||||
assert prop.Enumerators.Name == "DemoC"
|
||||
assert prop.Enumerators.EnumerationValues == tuple(self.file.createIfcLabel(v) for v in ("BAZ", "BAR"))
|
||||
assert len(self.file.by_type("IfcPropertyEnumeration")) == 1
|
||||
Reference in New Issue
Block a user