Fix bug where you could not add properties to projects themselves.

This commit is contained in:
Dion Moult
2022-01-21 12:01:19 +11:00
parent 67952ed159
commit 5709efbdcb
2 changed files with 61 additions and 1 deletions
@@ -27,7 +27,7 @@ class Usecase:
self.settings[key] = value
def execute(self):
if self.settings["product"].is_a("IfcObject"):
if self.settings["product"].is_a("IfcObject") or self.settings["product"].is_a("IfcContext"):
for rel in self.settings["product"].IsDefinedBy or []:
if (
rel.is_a("IfcRelDefinesByProperties")
@@ -0,0 +1,60 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2022 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 TestAddPset(test.bootstrap.IFC4):
def test_adding_a_pset_to_an_object(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
assert pset.is_a("IfcPropertySet")
assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element)
def test_adding_a_pset_to_a_type_object(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
assert pset.is_a("IfcPropertySet")
assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element)
def test_adding_a_pset_to_a_material(self):
material = ifcopenshell.api.run("material.add_material", self.file)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Pset_MaterialCommon")
assert pset.is_a("IfcMaterialProperties")
assert "Pset_MaterialCommon" in ifcopenshell.util.element.get_psets(material)
def test_adding_a_pset_to_a_profile(self):
profile = ifcopenshell.api.run("profile.add_parameterized_profile", self.file, ifc_class="IfcCircleProfileDef")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="Pset_ProfileMechanical")
assert pset.is_a("IfcProfileProperties")
assert "Pset_ProfileMechanical" in ifcopenshell.util.element.get_psets(profile)
def test_adding_a_pset_to_a_context(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset")
assert pset.is_a("IfcPropertySet")
assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)
class TestAddPsetIFC2X3(test.bootstrap.IFC2X3):
def test_adding_a_pset_to_a_project(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset")
assert pset.is_a("IfcPropertySet")
assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)