mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Qtos now support being added to types and contexts (despite being rare)
This commit is contained in:
@@ -28,7 +28,7 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
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 []:
|
for rel in self.settings["product"].IsDefinedBy or []:
|
||||||
if (
|
if (
|
||||||
rel.is_a("IfcRelDefinesByProperties")
|
rel.is_a("IfcRelDefinesByProperties")
|
||||||
@@ -36,14 +36,7 @@ class Usecase:
|
|||||||
):
|
):
|
||||||
return rel.RelatingPropertyDefinition
|
return rel.RelatingPropertyDefinition
|
||||||
|
|
||||||
qto = self.file.create_entity(
|
qto = self.create_qto()
|
||||||
"IfcElementQuantity",
|
|
||||||
**{
|
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
|
||||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
|
||||||
"Name": self.settings["name"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
self.file.create_entity(
|
self.file.create_entity(
|
||||||
"IfcRelDefinesByProperties",
|
"IfcRelDefinesByProperties",
|
||||||
**{
|
**{
|
||||||
@@ -54,3 +47,20 @@ class Usecase:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return qto
|
return qto
|
||||||
|
elif self.settings["product"].is_a("IfcTypeObject"):
|
||||||
|
for definition in self.settings["product"].HasPropertySets or []:
|
||||||
|
if definition.Name == self.settings["name"]:
|
||||||
|
return definition
|
||||||
|
qto = self.create_qto()
|
||||||
|
has_property_sets = list(self.settings["product"].HasPropertySets or [])
|
||||||
|
has_property_sets.append(qto)
|
||||||
|
self.settings["product"].HasPropertySets = has_property_sets
|
||||||
|
return qto
|
||||||
|
|
||||||
|
def create_qto(self):
|
||||||
|
return self.file.create_entity(
|
||||||
|
"IfcElementQuantity",
|
||||||
|
GlobalId=ifcopenshell.guid.new(),
|
||||||
|
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
|
Name=self.settings["name"],
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# 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 TestAddQto(test.bootstrap.IFC4):
|
||||||
|
def test_adding_a_qto_to_an_object(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Qto_WallBaseQuantities")
|
||||||
|
assert qto.is_a("IfcElementQuantity")
|
||||||
|
assert "Qto_WallBaseQuantities" in ifcopenshell.util.element.get_psets(element)
|
||||||
|
|
||||||
|
def test_adding_a_qto_to_a_type_object(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||||
|
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||||
|
assert qto.is_a("IfcElementQuantity")
|
||||||
|
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||||
|
|
||||||
|
def test_adding_a_qto_to_a_context(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||||
|
assert qto.is_a("IfcElementQuantity")
|
||||||
|
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||||
|
|
||||||
|
|
||||||
|
class TestAddQtoIFC2X3(test.bootstrap.IFC2X3):
|
||||||
|
def test_adding_a_qto_to_a_project(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||||
|
assert qto.is_a("IfcElementQuantity")
|
||||||
|
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||||
Reference in New Issue
Block a user