mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
project.assign_declaration - support batching #4474
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
# 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
|
||||
|
||||
|
||||
# NOTE: supported only in IFC4+
|
||||
class TestAssignDeclaration(test.bootstrap.IFC4):
|
||||
def get_declared_definitions(self, project: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]:
|
||||
definitions = set()
|
||||
for declares in project.Declares:
|
||||
definitions.update(declares.RelatedDefinitions)
|
||||
return definitions
|
||||
|
||||
def test_assign_a_declaration(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
self.file,
|
||||
definitions=[element_type, element_type2],
|
||||
relating_context=library,
|
||||
)
|
||||
assert self.get_declared_definitions(library) == {element_type, element_type2}
|
||||
assert len(self.file.by_type("IfcRelDeclares")) == 1
|
||||
|
||||
def test_doing_nothing_if_the_library_is_already_assigned(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration", self.file, definitions=[element_type, element_type2], relating_context=library
|
||||
)
|
||||
total_elements = len([e for e in self.file])
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration", self.file, definitions=[element_type, element_type2], relating_context=library
|
||||
)
|
||||
assert len([e for e in self.file]) == total_elements
|
||||
|
||||
def test_that_old_relationships_are_updated_if_they_still_contain_elements(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration", self.file, definitions=[element_type], relating_context=library
|
||||
)
|
||||
rel = self.file.by_type("IfcRelDeclares")[0]
|
||||
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration", self.file, definitions=[element_type2, element_type3], relating_context=library
|
||||
)
|
||||
assert len(rel.RelatedDefinitions) == 3
|
||||
@@ -303,11 +303,26 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
||||
def test_unassigning_a_constraint(self):
|
||||
constraint = ifcopenshell.api.run("constraint.add_objective", self.file)
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"constraint.assign_constraint", self.file, product=element, constraint=constraint
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"constraint.unassign_constraint", self.file, product=element, constraint=constraint
|
||||
)
|
||||
ifcopenshell.api.run("constraint.assign_constraint", self.file, product=element, constraint=constraint)
|
||||
ifcopenshell.api.run("constraint.unassign_constraint", self.file, product=element, constraint=constraint)
|
||||
assert ifcopenshell.util.constraint.get_constrained_elements(element) == set()
|
||||
assert len(self.file.by_type("IfcRelAssociatesConstraint")) == 0
|
||||
|
||||
@deprecation_check
|
||||
def test_assign_a_declaration(self):
|
||||
def get_declared_definitions(project: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]:
|
||||
definitions = set()
|
||||
for declares in project.Declares:
|
||||
definitions.update(declares.RelatedDefinitions)
|
||||
return definitions
|
||||
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
self.file,
|
||||
definition=element_type,
|
||||
relating_context=library,
|
||||
)
|
||||
assert get_declared_definitions(library) == {element_type}
|
||||
assert len(self.file.by_type("IfcRelDeclares")) == 1
|
||||
|
||||
Reference in New Issue
Block a user