mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Merge branch 'v0.7.0' into v0.8.0
This commit is contained in:
@@ -121,3 +121,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=container)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert not ifcopenshell.util.element.get_container(subelement, should_get_direct=True)
|
||||
|
||||
|
||||
class TestAssignObjectIFC2X3(test.bootstrap.IFC2X3, TestAssignObject):
|
||||
pass
|
||||
|
||||
@@ -49,3 +49,7 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, products=[subelement])
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
|
||||
|
||||
class TestUnassignObjectIFC2X3(test.bootstrap.IFC2X3, TestUnassignObject):
|
||||
pass
|
||||
|
||||
@@ -34,3 +34,7 @@ class TestCopyBoundary(test.bootstrap.IFC4):
|
||||
boundary2 = ifcopenshell.api.run("boundary.copy_boundary", self.file, boundary=boundary)
|
||||
assert boundary2.ConnectionGeometry.is_a("IfcConnectionSurfaceGeometry")
|
||||
assert boundary2.ConnectionGeometry != boundary.ConnectionGeometry
|
||||
|
||||
|
||||
class TestCopyBoundaryIFC2X3(test.bootstrap.IFC2X3, TestCopyBoundary):
|
||||
pass
|
||||
|
||||
@@ -33,3 +33,7 @@ class TestRemoveBoundary(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("boundary.remove_boundary", self.file, boundary=boundary)
|
||||
assert not self.file.by_type("IfcRelSpaceBoundary")
|
||||
assert not self.file.by_type("IfcConnectionSurfaceGeometry")
|
||||
|
||||
|
||||
class TestRemoveBoundaryIFC2X3(test.bootstrap.IFC2X3, TestRemoveBoundary):
|
||||
pass
|
||||
|
||||
@@ -32,3 +32,7 @@ class TestAddClassification(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
assert self.file.by_type("IfcClassification")[0].Name == "Name"
|
||||
|
||||
|
||||
class TestAddClassificationIFC2X3(test.bootstrap.IFC2X3, TestAddClassification):
|
||||
pass
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestRemoveClassification(test.bootstrap.IFC4):
|
||||
def test_removing_a_classification_and_all_of_its_references_when_associated_with_a_resource(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
element = self.file.createIfcMaterial(Name="Material")
|
||||
element = self.file.create_entity("IfcWall", Name="Wall")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
self.file,
|
||||
@@ -59,4 +59,9 @@ class TestRemoveClassification(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("classification.remove_classification", self.file, classification=result)
|
||||
assert not self.file.by_type("IfcClassification")
|
||||
assert not self.file.by_type("IfcClassificationReference")
|
||||
assert not self.file.by_type("IfcExternalReferenceRelationship")
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert not self.file.by_type("IfcExternalReferenceRelationship")
|
||||
|
||||
|
||||
class TestRemoveClassificationIFC2X3(test.bootstrap.IFC2X3, TestRemoveClassification):
|
||||
pass
|
||||
|
||||
@@ -75,3 +75,7 @@ class TestAddContext(test.bootstrap.IFC4):
|
||||
self.test_adding_a_2d_context()
|
||||
project = self.file.by_type("IfcProject")[0]
|
||||
assert len(project.RepresentationContexts) == 2
|
||||
|
||||
|
||||
class TestAddContextIFC2X3(test.bootstrap.IFC2X3, TestAddContext):
|
||||
pass
|
||||
|
||||
@@ -58,3 +58,7 @@ class TestEditContext(test.bootstrap.IFC4):
|
||||
assert subcontext.TargetScale == 0.5
|
||||
assert subcontext.TargetView == "MODEL_VIEW"
|
||||
assert subcontext.UserDefinedTargetView == "UserDefinedTargetView"
|
||||
|
||||
|
||||
class TestEditContextIFC2X3(test.bootstrap.IFC2X3, TestEditContext):
|
||||
pass
|
||||
|
||||
@@ -38,16 +38,22 @@ class TestRemoveContext(test.bootstrap.IFC4):
|
||||
subcontext = self.file.createIfcGeometricRepresentationSubcontext()
|
||||
subcontext.ParentContext = context
|
||||
representation = self.file.createIfcRepresentation(ContextOfItems=subcontext)
|
||||
projected_crs = self.file.createIfcProjectedCRS()
|
||||
map_conversion = self.file.createIfcMapConversion(SourceCRS=subcontext, TargetCRS=projected_crs)
|
||||
if self.file.schema != "IFC2X3":
|
||||
projected_crs = self.file.createIfcProjectedCRS()
|
||||
map_conversion = self.file.createIfcMapConversion(SourceCRS=subcontext, TargetCRS=projected_crs)
|
||||
ifcopenshell.api.run("context.remove_context", self.file, context=subcontext)
|
||||
assert len(self.file.by_type("IfcGeometricRepresentationSubcontext")) == 0
|
||||
assert representation in self.file.get_inverse(context)
|
||||
assert len(self.file.by_type("IfcMapConversion")) == 0
|
||||
assert len(self.file.by_type("IfcProjectedCRS")) == 0
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert len(self.file.by_type("IfcMapConversion")) == 0
|
||||
assert len(self.file.by_type("IfcProjectedCRS")) == 0
|
||||
|
||||
def test_removing_a_context_with_references(self):
|
||||
context = self.file.createIfcGeometricRepresentationContext()
|
||||
representation = self.file.createIfcRepresentation(ContextOfItems=context)
|
||||
ifcopenshell.api.run("context.remove_context", self.file, context=context)
|
||||
assert len([e for e in self.file]) == 0
|
||||
|
||||
|
||||
class TestRemoveContextIFC2X3(test.bootstrap.IFC2X3, TestRemoveContext):
|
||||
pass
|
||||
|
||||
@@ -48,3 +48,7 @@ class TestAssignControl(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatingControl == control
|
||||
assert set(relation.RelatedObjects) == set((wall, wall1))
|
||||
|
||||
|
||||
class TestAssignControlIFC2X3(test.bootstrap.IFC2X3, TestAssignControl):
|
||||
pass
|
||||
|
||||
@@ -41,3 +41,7 @@ class TestUnassignControl(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("control.unassign_control", self.file, relating_control=control, related_object=wall1)
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
|
||||
assert relation.RelatedObjects == (wall,)
|
||||
|
||||
|
||||
class TestUnassignControlIFC2X3(test.bootstrap.IFC2X3, TestUnassignControl):
|
||||
pass
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAddCostItem(test.bootstrap.IFC4):
|
||||
@@ -33,4 +34,8 @@ class TestAddCostItem(test.bootstrap.IFC4):
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_item=item1)
|
||||
assert item2.is_a("IfcCostItem")
|
||||
assert item2.Nests[0].RelatingObject == item1
|
||||
assert ifcopenshell.util.element.get_nest(item2) == item1
|
||||
|
||||
|
||||
class TestAddCostItemIFC2X3(test.bootstrap.IFC2X3, TestAddCostItem):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 TestAddCostItemQuantity(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
schema = ifcopenshell.schema_by_name(self.file.schema)
|
||||
quantity_types = [t.name() for t in schema.declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()]
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", self.file)
|
||||
item = ifcopenshell.api.run("cost.add_cost_item", self.file, cost_schedule=schedule)
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("control.assign_control", self.file, relating_control=item, related_object=wall)
|
||||
|
||||
quantities = []
|
||||
for quantity_type in quantity_types:
|
||||
quantity = ifcopenshell.api.run(
|
||||
"cost.add_cost_item_quantity", self.file, cost_item=item, ifc_class=quantity_type
|
||||
)
|
||||
assert quantity.is_a(quantity_type)
|
||||
assert quantity.Name == "Unnamed"
|
||||
if quantity_type == "IfcQuantityCount":
|
||||
assert quantity[3] == 1
|
||||
else:
|
||||
assert quantity[3] == 0.0
|
||||
quantities.append(quantity)
|
||||
assert item.CostQuantities == tuple(quantities)
|
||||
|
||||
|
||||
# CostQuantities was added to IfcCostItem in IFC4.
|
||||
class TestAddCostItemQuantityIFC4X3(test.bootstrap.IFC4X3, TestAddCostItemQuantity):
|
||||
pass
|
||||
@@ -33,3 +33,7 @@ class TestAddCostSchedule(test.bootstrap.IFC4):
|
||||
assert schedule.Name == "Foo"
|
||||
assert schedule.PredefinedType == "USERDEFINED"
|
||||
assert schedule.ObjectType == "FOO"
|
||||
|
||||
|
||||
class TestAddCostScheduleIFC2X3(test.bootstrap.IFC2X3, TestAddCostSchedule):
|
||||
pass
|
||||
|
||||
@@ -45,3 +45,7 @@ class TestRemoveCostItem(test.bootstrap.IFC4):
|
||||
assert not self.file.by_type("IfcCostItem")
|
||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||
assert not self.file.by_type("IfcRelNests")
|
||||
|
||||
|
||||
class TestRemoveCostItemIFC2X3(test.bootstrap.IFC2X3, TestRemoveCostItem):
|
||||
pass
|
||||
|
||||
@@ -35,3 +35,7 @@ class TestRemoveCostSchedule(test.bootstrap.IFC4):
|
||||
assert not self.file.by_type("IfcCostItem")
|
||||
assert not self.file.by_type("IfcRelNests")
|
||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||
|
||||
|
||||
class TestRemoveCostScheduleIFC2X3(test.bootstrap.IFC2X3, TestRemoveCostSchedule):
|
||||
pass
|
||||
|
||||
@@ -30,9 +30,10 @@ class TestAddInformation(test.bootstrap.IFC4):
|
||||
def test_adding_information_to_the_project(self):
|
||||
project = self.file.createIfcProject()
|
||||
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
rel = element.DocumentInfoForObjects[0]
|
||||
rel = self.file.by_type("IfcRelAssociatesDocument")[0]
|
||||
assert rel.is_a("IfcRelAssociatesDocument")
|
||||
assert rel.RelatedObjects[0] == project
|
||||
assert rel.RelatingDocument == element
|
||||
assert rel.RelatedObjects == (project,)
|
||||
|
||||
def test_adding_a_subdocument(self):
|
||||
project = self.file.createIfcProject()
|
||||
@@ -45,3 +46,7 @@ class TestAddInformation(test.bootstrap.IFC4):
|
||||
element2 = ifcopenshell.api.run("document.add_information", self.file, parent=parent)
|
||||
assert element in parent.IsPointer[0].RelatedDocuments
|
||||
assert element2 in parent.IsPointer[0].RelatedDocuments
|
||||
|
||||
|
||||
class TestAddInformationIFC2X3(test.bootstrap.IFC2X3, TestAddInformation):
|
||||
pass
|
||||
|
||||
@@ -22,14 +22,14 @@ import ifcopenshell.api
|
||||
|
||||
class TestRemoveInformation(test.bootstrap.IFC4):
|
||||
def test_remove_information(self):
|
||||
project = self.file.createIfcProject()
|
||||
self.file.createIfcProject()
|
||||
element = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=element)
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
|
||||
|
||||
def test_removing_all_references_of_an_information(self):
|
||||
project = self.file.createIfcProject()
|
||||
self.file.createIfcProject()
|
||||
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
ifcopenshell.api.run("document.add_reference", self.file, information=information)
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=information)
|
||||
@@ -51,7 +51,7 @@ class TestRemoveInformation(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
|
||||
|
||||
def test_removing_all_subdocuments_and_their_references_too(self):
|
||||
project = self.file.createIfcProject()
|
||||
self.file.createIfcProject()
|
||||
information = ifcopenshell.api.run("document.add_information", self.file, parent=None)
|
||||
information2 = ifcopenshell.api.run("document.add_information", self.file, parent=information)
|
||||
ifcopenshell.api.run("document.add_reference", self.file, information=information2)
|
||||
@@ -60,3 +60,7 @@ class TestRemoveInformation(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 0
|
||||
assert len(self.file.by_type("IfcDocumentInformationRelationship")) == 0
|
||||
|
||||
|
||||
class TestRemoveInformationIFC2X3(TestRemoveInformation, test.bootstrap.IFC2X3):
|
||||
pass
|
||||
|
||||
@@ -41,3 +41,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcDocumentReference")) == 0
|
||||
assert len(self.file.by_type("IfcDocumentInformation")) == 1
|
||||
assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1
|
||||
|
||||
|
||||
class TestRemoveReferenceIFC2X3(test.bootstrap.IFC2X3, TestRemoveReference):
|
||||
pass
|
||||
|
||||
@@ -37,3 +37,7 @@ class TestAssignProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("drawing.assign_product", self.file, relating_product=wall, related_object=label)
|
||||
assert len(wall.ReferencedBy) == 1
|
||||
assert wall.ReferencedBy[0].RelatedObjects == (label,)
|
||||
|
||||
|
||||
class TestAssignProductIFC2X3(test.bootstrap.IFC2X3, TestAssignProduct):
|
||||
pass
|
||||
|
||||
@@ -36,3 +36,7 @@ class TestEditTextLiteral(test.bootstrap.IFC4):
|
||||
assert text.Literal == "Literal"
|
||||
assert text.Path == "RIGHT"
|
||||
assert text.BoxAlignment == "middle"
|
||||
|
||||
|
||||
class TestEditTextLiteralIFC2X3(test.bootstrap.IFC2X3, TestEditTextLiteral):
|
||||
pass
|
||||
|
||||
@@ -27,3 +27,7 @@ class TestUnassignProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("drawing.assign_product", self.file, relating_product=wall, related_object=label)
|
||||
ifcopenshell.api.run("drawing.unassign_product", self.file, relating_product=wall, related_object=label)
|
||||
assert len(self.file.by_type("IfcRelAssignsToProduct")) == 0
|
||||
|
||||
|
||||
class TestUnassignProductIFC2X3(test.bootstrap.IFC2X3, TestUnassignProduct):
|
||||
pass
|
||||
|
||||
@@ -53,3 +53,7 @@ class TestAddBoolean(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("geometry.add_boolean", self.file, representation=rep, matrix=np.eye(4))
|
||||
assert rep.Items[0].is_a() == "IfcBooleanClippingResult"
|
||||
assert rep.RepresentationType == "Clipping"
|
||||
|
||||
|
||||
class TestAddBooleanIFC2X3(test.bootstrap.IFC2X3, TestAddBoolean):
|
||||
pass
|
||||
|
||||
@@ -89,3 +89,7 @@ class TestAssignRepresentation(test.bootstrap.IFC4):
|
||||
assert wall.Representation.Representations[0].RepresentationType != "MappedRepresentation"
|
||||
assert wall.Representation.Representations[0] == rep
|
||||
assert not walltype.RepresentationMaps
|
||||
|
||||
|
||||
class TestAssignRepresentationIFC2X3(test.bootstrap.IFC2X3, TestAssignRepresentation):
|
||||
pass
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestConnectPath(test.bootstrap.IFC4):
|
||||
class TestConnectElement(test.bootstrap.IFC4):
|
||||
def test_connecting_an_element(self):
|
||||
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
@@ -85,3 +85,7 @@ class TestConnectPath(test.bootstrap.IFC4):
|
||||
)
|
||||
assert rel.RelatingElement == wall2
|
||||
assert rel.RelatedElement == wall1
|
||||
|
||||
|
||||
class TestConnectElementIFC2X3(test.bootstrap.IFC2X3, TestConnectElement):
|
||||
pass
|
||||
|
||||
@@ -146,3 +146,7 @@ class TestConnectPath(test.bootstrap.IFC4):
|
||||
related_connection=related_connection,
|
||||
description=description,
|
||||
)
|
||||
|
||||
|
||||
class TestConnectPathIFC2X3(test.bootstrap.IFC2X3, TestConnectPath):
|
||||
pass
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestDisconnectPath(test.bootstrap.IFC4):
|
||||
class TestDisconnectElement(test.bootstrap.IFC4):
|
||||
def test_disconnecting_an_element(self):
|
||||
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
@@ -34,3 +34,7 @@ class TestDisconnectPath(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("geometry.connect_element", self.file, relating_element=wall1, related_element=wall2)
|
||||
ifcopenshell.api.run("geometry.disconnect_element", self.file, relating_element=wall2, related_element=wall1)
|
||||
assert not self.file.by_type("IfcRelConnectsElements")
|
||||
|
||||
|
||||
class TestDisconnectElementIFC2X3(test.bootstrap.IFC2X3, TestDisconnectElement):
|
||||
pass
|
||||
|
||||
@@ -68,3 +68,7 @@ class TestDisconnectPath(test.bootstrap.IFC4):
|
||||
total_elements = len([e for e in self.file])
|
||||
ifcopenshell.api.run("geometry.disconnect_path", self.file, relating_element=wall2, related_element=wall1)
|
||||
assert len([e for e in self.file]) == total_elements
|
||||
|
||||
|
||||
class TestDisconnectPathIFC2X3(test.bootstrap.IFC2X3, TestDisconnectPath):
|
||||
pass
|
||||
|
||||
@@ -20,6 +20,7 @@ import numpy
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
import ifcopenshell.util.placement
|
||||
|
||||
|
||||
@@ -267,7 +268,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
def test_changing_placements_relative_to_a_nest_parent(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
subelement = ifcopenshell.api.run("system.add_port", self.file, element=element)
|
||||
matrix = numpy.array(
|
||||
(
|
||||
@@ -545,7 +546,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
def test_changing_placements_always_affecting_child_ports_as_a_special_case(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
subelement = ifcopenshell.api.run("system.add_port", self.file, element=element)
|
||||
|
||||
matrix = numpy.eye(4)
|
||||
@@ -661,7 +662,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(wall.ObjectPlacement), matrix)
|
||||
|
||||
|
||||
class TestEditObjectPlacementIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestEditObjectPlacementIFC2X3(test.bootstrap.IFC2X3, TestEditObjectPlacement):
|
||||
def test_changing_placements_relative_to_a_distribution_element(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
|
||||
@@ -33,3 +33,7 @@ class TestCreateGridAxis(test.bootstrap.IFC4):
|
||||
"grid.create_grid_axis", self.file, axis_tag="axis_tag", same_sense=True, uvw_axes="UAxes", grid=grid
|
||||
)
|
||||
assert grid.UAxes == (axis, axis2)
|
||||
|
||||
|
||||
class TestCreateGridAxisIFC2X3(test.bootstrap.IFC2X3, TestCreateGridAxis):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAddGroup(test.bootstrap.IFC4):
|
||||
def test_add_group_no_arguments(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
assert group.Name == "Unnamed"
|
||||
assert group.Description == None
|
||||
|
||||
def test_add_group(self):
|
||||
group = ifcopenshell.api.run("group.add_group", self.file, name="Name", description="Description")
|
||||
assert group.Name == "Name"
|
||||
assert group.Description == "Description"
|
||||
|
||||
|
||||
class TestAddGroupIFC2X3(test.bootstrap.IFC2X3, TestAddGroup):
|
||||
pass
|
||||
@@ -27,7 +27,7 @@ class TestRemoveGroup(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcGroup")) == 0
|
||||
|
||||
def test_removing_orphaned_group_relationships(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
|
||||
ifcopenshell.api.run("group.remove_group", self.file, group=group)
|
||||
@@ -41,3 +41,7 @@ class TestRemoveGroup(test.bootstrap.IFC4):
|
||||
assert not self.file.by_type("IfcRelDefinesByProperties")
|
||||
assert not self.file.by_type("IfcPropertySet")
|
||||
assert not self.file.by_type("IfcPropertySingleValue")
|
||||
|
||||
|
||||
class TestRemoveGroupIFC2X3(test.bootstrap.IFC2X3, TestRemoveGroup):
|
||||
pass
|
||||
|
||||
@@ -22,9 +22,9 @@ import ifcopenshell.api
|
||||
|
||||
class TestAssignGroup(test.bootstrap.IFC4):
|
||||
def test_group_unassignment(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element, element2, element3], group=group)
|
||||
ifcopenshell.api.run("group.unassign_group", self.file, products=[element2, element3], group=group)
|
||||
@@ -35,9 +35,13 @@ class TestAssignGroup(test.bootstrap.IFC4):
|
||||
assert rel.RelatedObjects == (element,)
|
||||
|
||||
def test_remove_relationship_unassigning_last_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element, element2], group=group)
|
||||
ifcopenshell.api.run("group.unassign_group", self.file, products=[element, element2], group=group)
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 0
|
||||
|
||||
|
||||
class TestAssignGroupIFC2X3(test.bootstrap.IFC2X3, TestAssignGroup):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# 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
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestUpdateGroupProductsIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_update_group_without_products(self):
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements, group=group)
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements)
|
||||
|
||||
def test_update_group_products(self):
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=elements[:2], group=group)
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements[2:], group=group)
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements[2:])
|
||||
assert ifcopenshell.util.element.get_groups(elements[0]) == []
|
||||
assert ifcopenshell.util.element.get_groups(elements[1]) == []
|
||||
|
||||
|
||||
class TestUpdateGroupProductsIFC4(test.bootstrap.IFC4, TestUpdateGroupProductsIFC2X3):
|
||||
def test_update_group_products(self):
|
||||
# in ifc4 IfcGroup can have multiple rels
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") for i in range(4)]
|
||||
group = ifcopenshell.api.run("group.add_group", self.file)
|
||||
|
||||
self.file.create_entity("IfcRelAssignsToGroup", RelatingGroup=group, RelatedObjects=elements[:1])
|
||||
self.file.create_entity("IfcRelAssignsToGroup", RelatingGroup=group, RelatedObjects=elements[1:2])
|
||||
|
||||
ifcopenshell.api.run("group.update_group_products", self.file, products=elements[2:], group=group)
|
||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||
assert set(ifcopenshell.util.element.get_grouped_by(group)) == set(elements[2:])
|
||||
assert ifcopenshell.util.element.get_groups(elements[0]) == []
|
||||
assert ifcopenshell.util.element.get_groups(elements[1]) == []
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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 TestAddLayer(test.bootstrap.IFC4):
|
||||
def test_add_layer_no_arguments(self):
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
assert layer.Name == "Unnamed"
|
||||
|
||||
def test_assign_additional_items(self):
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file, name="Name")
|
||||
assert layer.Name == "Name"
|
||||
|
||||
|
||||
class TestAddLayerIFC2X3(test.bootstrap.IFC2X3, TestAddLayer):
|
||||
pass
|
||||
@@ -37,3 +37,7 @@ class TestAssignLayer(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=items[2:], layer=layer)
|
||||
assert len(layer.AssignedItems) == 4
|
||||
assert set(layer.AssignedItems) == set(items)
|
||||
|
||||
|
||||
class TestAssignLayerIFC2X3(test.bootstrap.IFC2X3, TestAssignLayer):
|
||||
pass
|
||||
|
||||
@@ -37,3 +37,7 @@ class TestUnassignLayer(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=items, layer=layer)
|
||||
ifcopenshell.api.run("layer.unassign_layer", self.file, items=items, layer=layer)
|
||||
assert not self.file.by_type("IfcPresentationLayerAssignment")
|
||||
|
||||
|
||||
class TestUnassignLayerIFC2X3(test.bootstrap.IFC2X3, TestUnassignLayer):
|
||||
pass
|
||||
|
||||
@@ -25,3 +25,7 @@ class TestAddLibrary(test.bootstrap.IFC4):
|
||||
library = ifcopenshell.api.run("library.add_library", self.file, name="Name")
|
||||
assert library.is_a("IfcLibraryInformation")
|
||||
assert library.Name == "Name"
|
||||
|
||||
|
||||
class TestAddLibraryIFC2X3(test.bootstrap.IFC2X3, TestAddLibrary):
|
||||
pass
|
||||
|
||||
@@ -20,28 +20,6 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
def validate_ifc_file(ifc_file: ifcopenshell.file, use_json=True):
|
||||
import ifcopenshell
|
||||
import ifcopenshell.validate
|
||||
|
||||
if use_json:
|
||||
logger = ifcopenshell.validate.json_logger()
|
||||
else:
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger("validate")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
ifcopenshell.validate.validate(ifc_file, logger, express_rules=True)
|
||||
if use_json:
|
||||
if logger.statements:
|
||||
from pprint import pprint
|
||||
|
||||
pprint(logger.statements)
|
||||
else:
|
||||
print("IFC is completely valid.")
|
||||
|
||||
|
||||
class TestAssignReference(test.bootstrap.IFC4):
|
||||
def test_assigning_a_reference(self):
|
||||
reference = self.file.createIfcLibraryReference()
|
||||
|
||||
@@ -17,26 +17,41 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import datetime
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.date
|
||||
|
||||
|
||||
class TestEditLibrary(test.bootstrap.IFC4):
|
||||
def test_editing_a_library(self):
|
||||
library = self.file.createIfcLibraryInformation()
|
||||
dt = datetime.datetime.now()
|
||||
attributes = {
|
||||
"Name": "Name",
|
||||
"Version": "Version",
|
||||
"VersionDate": dt,
|
||||
}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attributes["Location"] = "Location"
|
||||
attributes["Description"] = "Description"
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"library.edit_library",
|
||||
self.file,
|
||||
library=library,
|
||||
attributes={
|
||||
"Name": "Name",
|
||||
"Version": "Version",
|
||||
"VersionDate": "VersionDate",
|
||||
"Location": "Location",
|
||||
"Description": "Description",
|
||||
},
|
||||
attributes=attributes,
|
||||
)
|
||||
assert library.Name == "Name"
|
||||
assert library.Version == "Version"
|
||||
assert library.VersionDate == "VersionDate"
|
||||
assert library.Location == "Location"
|
||||
assert library.Description == "Description"
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert library.VersionDate == ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime")
|
||||
assert library.Location == "Location"
|
||||
assert library.Description == "Description"
|
||||
else:
|
||||
info = library.VersionDate.get_info()
|
||||
del info["id"], info["type"]
|
||||
assert info == ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate")
|
||||
|
||||
|
||||
class TestEditLibraryIFC2X3(test.bootstrap.IFC2X3, TestEditLibrary):
|
||||
pass
|
||||
|
||||
@@ -23,20 +23,28 @@ import ifcopenshell.api
|
||||
class TestEditReference(test.bootstrap.IFC4):
|
||||
def test_editing_a_reference(self):
|
||||
reference = self.file.createIfcLibraryReference()
|
||||
attributes = {
|
||||
"Location": "Location",
|
||||
"Identification" if self.file.schema != "IFC2X3" else "ItemReference": "Identification",
|
||||
"Name": "Name",
|
||||
}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attributes["Description"] = "Description"
|
||||
attributes["Language"] = "Language"
|
||||
ifcopenshell.api.run(
|
||||
"library.edit_reference",
|
||||
self.file,
|
||||
reference=reference,
|
||||
attributes={
|
||||
"Location": "Location",
|
||||
"Identification": "Identification",
|
||||
"Name": "Name",
|
||||
"Description": "Description",
|
||||
"Language": "Language",
|
||||
},
|
||||
attributes=attributes,
|
||||
)
|
||||
assert reference.Location == "Location"
|
||||
assert reference.Identification == "Identification"
|
||||
# 1 IfcExternalReference Identification(>IFC2X3) / ItemReference (IFC2X3)
|
||||
assert reference[1] == "Identification"
|
||||
assert reference.Name == "Name"
|
||||
assert reference.Description == "Description"
|
||||
assert reference.Language == "Language"
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert reference.Description == "Description"
|
||||
assert reference.Language == "Language"
|
||||
|
||||
|
||||
class TestEditReferenceIFC2X3(test.bootstrap.IFC2X3, TestEditReference):
|
||||
pass
|
||||
|
||||
@@ -27,11 +27,21 @@ class TestRemoveLibrary(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcLibraryInformation")) == 0
|
||||
|
||||
def test_removing_a_library_and_all_references(self):
|
||||
library = self.file.createIfcLibraryInformation()
|
||||
reference1 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
|
||||
reference2 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
|
||||
if self.file.schema != "IFC2X3":
|
||||
library = self.file.createIfcLibraryInformation()
|
||||
reference1 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
|
||||
reference2 = self.file.createIfcLibraryReference(ReferencedLibrary=library)
|
||||
else:
|
||||
reference1 = self.file.createIfcLibraryReference()
|
||||
reference2 = self.file.createIfcLibraryReference()
|
||||
library = self.file.createIfcLibraryInformation(LibraryReference=[reference1, reference2])
|
||||
|
||||
self.file.createIfcRelAssociatesLibrary(GlobalId="foo", RelatingLibrary=library)
|
||||
self.file.createIfcRelAssociatesLibrary(GlobalId="bar", RelatingLibrary=reference1)
|
||||
ifcopenshell.api.run("library.remove_library", self.file, library=library)
|
||||
assert len(self.file.by_type("IfcLibraryReference")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
|
||||
|
||||
|
||||
class TestRemoveLibraryIFC2X3(test.bootstrap.IFC2X3, TestRemoveLibrary):
|
||||
pass
|
||||
|
||||
@@ -28,3 +28,7 @@ class TestRemoveReference(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("library.remove_reference", self.file, reference=reference)
|
||||
assert len(self.file.by_type("IfcLibraryReference")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesLibrary")) == 0
|
||||
|
||||
|
||||
class TestRemoveReferenceIFC2X3(test.bootstrap.IFC2X3, TestRemoveReference):
|
||||
pass
|
||||
|
||||
@@ -20,12 +20,19 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAddMaterialSet(test.bootstrap.IFC4):
|
||||
class TestAddMaterialSetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_add_layer_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
assert material.LayerSetName == "Unnamed"
|
||||
assert material.is_a("IfcMaterialLayerSet")
|
||||
|
||||
def test_add_list(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
assert material.is_a("IfcMaterialList")
|
||||
|
||||
|
||||
class TestAddMaterialSetIFC4(test.bootstrap.IFC4, TestAddMaterialSetIFC2X3):
|
||||
# entities added in IFC4
|
||||
def test_add_profile_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialProfileSet")
|
||||
assert material.Name == "Unnamed"
|
||||
@@ -35,7 +42,3 @@ class TestAddMaterialSet(test.bootstrap.IFC4):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialConstituentSet")
|
||||
assert material.Name == "Unnamed"
|
||||
assert material.is_a("IfcMaterialConstituentSet")
|
||||
|
||||
def test_add_list(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
assert material.is_a("IfcMaterialList")
|
||||
|
||||
@@ -33,19 +33,31 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
assert material.AssociatedTo
|
||||
assert not new.AssociatedTo
|
||||
assert ifcopenshell.util.element.get_elements_by_material(self.file, material)
|
||||
assert not ifcopenshell.util.element.get_elements_by_material(self.file, new)
|
||||
|
||||
def test_copy_a_material_with_properties(self):
|
||||
def get_material_props(material: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
|
||||
if self.file.schema != "IFC2X3":
|
||||
return material.HasProperties
|
||||
return [i for i in self.file.get_inverse(material) if i.is_a("IfcMaterialProperties")]
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
assert new.Name == "CON01"
|
||||
assert len(self.file.by_type("IfcMaterial")) == 2
|
||||
assert new.HasProperties[0] != material.HasProperties[0]
|
||||
assert new.HasProperties[0].Properties[0] != material.HasProperties[0].Properties[0]
|
||||
assert ifcopenshell.util.element.get_pset(new, "Foo_Bar", "foo") == "bar"
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 2
|
||||
props_old = get_material_props(material)[0]
|
||||
props_new = get_material_props(new)[0]
|
||||
assert props_old != props_new
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert props_old.Properties[0] != props_new.Properties[0]
|
||||
assert ifcopenshell.util.element.get_pset(new, "Foo_Bar", "foo") == "bar"
|
||||
else:
|
||||
assert props_old.ExtendedProperties[0] != props_new.ExtendedProperties[0]
|
||||
assert props_new.ExtendedProperties[0].NominalValue.wrappedValue == "bar"
|
||||
|
||||
def test_copy_a_material_with_a_style_representation(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
@@ -55,7 +67,91 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
assert new.Name == "CON01"
|
||||
assert len(self.file.by_type("IfcPresentationStyle")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 2
|
||||
assert new.HasRepresentation[0] != material.HasRepresentation[0]
|
||||
assert new.HasRepresentation[0].Representations[0] != material.HasRepresentation[0].Representations[0]
|
||||
assert new.HasRepresentation[0].Representations[0].ContextOfItems == context
|
||||
|
||||
def test_copy_a_material_constituent_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
item = ifcopenshell.api.run(
|
||||
"material.add_constituent", self.file, constituent_set=material_set, material=material
|
||||
)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Name == "Foo"
|
||||
assert new.MaterialConstituents[0] != item
|
||||
assert new.MaterialConstituents[0].Material == material
|
||||
assert len(self.file.by_type("IfcMaterialConstituentSet")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialConstituent")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_copy_a_material_layer_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialLayerSet"
|
||||
)
|
||||
item = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.LayerSetName == "Foo"
|
||||
assert new.MaterialLayers[0] != item
|
||||
assert new.MaterialLayers[0].Material == material
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialLayer")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_copy_a_material_profile_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
profile = self.file.create_entity(
|
||||
"IfcIShapeProfileDef",
|
||||
ProfileName="HEA100",
|
||||
ProfileType="AREA",
|
||||
OverallWidth=100,
|
||||
OverallDepth=96,
|
||||
WebThickness=5,
|
||||
FlangeThickness=8,
|
||||
FilletRadius=12,
|
||||
)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialProfileSet"
|
||||
)
|
||||
item = ifcopenshell.api.run(
|
||||
"material.add_profile", self.file, profile_set=material_set, material=material, profile=profile
|
||||
)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Name == "Foo"
|
||||
assert new.MaterialProfiles[0] != item
|
||||
assert new.MaterialProfiles[0].Material == material
|
||||
assert new.MaterialProfiles[0].Profile == profile
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialProfile")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcProfileDef")) == 1
|
||||
|
||||
def test_copy_a_material_list(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Materials[0] == material
|
||||
assert len(self.file.by_type("IfcMaterialList")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
|
||||
class TestCopyMaterialIFC2X3(test.bootstrap.IFC2X3, TestCopyMaterial):
|
||||
def test_copy_a_material_constituent_set(self):
|
||||
return
|
||||
|
||||
def test_copy_a_material_profile_set(self):
|
||||
return
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemoveMaterial(test.bootstrap.IFC4):
|
||||
class TestRemoveMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_material(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
@@ -37,9 +37,7 @@ class TestRemoveMaterial(test.bootstrap.IFC4):
|
||||
def test_removing_material_in_layer(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialLayerSet"
|
||||
)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")[0].MaterialLayers) == 1
|
||||
@@ -48,40 +46,10 @@ class TestRemoveMaterial(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")[0].MaterialLayers) == 0
|
||||
|
||||
def test_removing_material_in_profile(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialProfileSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.add_profile", self.file, profile_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 0
|
||||
|
||||
def test_removing_material_in_constituent(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.add_constituent", self.file, constituent_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents is None
|
||||
|
||||
def test_removing_material_in_list(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialList"
|
||||
)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialList")[0].Materials) == 1
|
||||
@@ -108,10 +76,44 @@ class TestRemoveMaterial(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcSurfaceStyle")) == 1
|
||||
|
||||
def test_removing_a_material_with_properties(self):
|
||||
def get_material_props(material: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
|
||||
if self.file.schema != "IFC2X3":
|
||||
return material.HasProperties
|
||||
return [i for i in self.file.get_inverse(material) if i.is_a("IfcMaterialProperties")]
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert material.HasProperties
|
||||
assert get_material_props(material)
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySingleValue")) == 0
|
||||
|
||||
|
||||
class TestRemoveMaterialIFC4(test.bootstrap.IFC4, TestRemoveMaterialIFC2X3):
|
||||
# IfcMaterialProfileSet added in IFC4
|
||||
def test_removing_material_in_profile(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.run("material.add_profile", self.file, profile_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 0
|
||||
|
||||
def test_removing_material_in_constituent(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.add_constituent", self.file, constituent_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents is None
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemoveMaterialSet(test.bootstrap.IFC4):
|
||||
class TestRemoveMaterialSetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_material_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.remove_material_set", self.file, material=material)
|
||||
@@ -43,6 +43,9 @@ class TestRemoveMaterialSet(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcMaterialLayer")) == 0
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
|
||||
class TestRemoveMaterialSetIFC4(test.bootstrap.IFC4, TestRemoveMaterialSetIFC2X3):
|
||||
# IFC2X3 doesn't support adding a pset to IfcMaterialLayerSet
|
||||
def test_removing_a_material_set_with_properties(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
|
||||
@@ -66,6 +66,23 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
with pytest.raises(RuntimeError):
|
||||
self.file.by_id(rel_id)
|
||||
|
||||
def test_maintain_assignment_order_in_related_objects(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask")
|
||||
subelements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask") for _ in range(5)]
|
||||
for i in range(5):
|
||||
ifcopenshell.api.run(
|
||||
"nest.assign_object", self.file, related_objects=subelements[: i + 1], relating_object=element
|
||||
)
|
||||
rel = self.file.by_type("IfcRelNests")[0]
|
||||
assert rel.RelatedObjects == tuple(subelements[: i + 1])
|
||||
|
||||
# maintain the order in the affected relationships too
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask")
|
||||
ifcopenshell.api.run(
|
||||
"nest.assign_object", self.file, related_objects=subelements[2:3], relating_object=element2
|
||||
)
|
||||
assert rel.RelatedObjects == tuple(subelements[:2] + subelements[3:])
|
||||
|
||||
|
||||
class TestAssignObjectIFC2X3(test.bootstrap.IFC2X3, TestAssignObject):
|
||||
pass
|
||||
|
||||
@@ -50,5 +50,21 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("nest.unassign_object", self.file, related_objects=[subelement])
|
||||
assert len(self.file.by_type("IfcRelNests")) == 0
|
||||
|
||||
def test_maintain_assignment_order_in_related_objects(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask")
|
||||
subelements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask") for _ in range(5)]
|
||||
rel = self.file.create_entity("IfcRelNests", RelatingObject=element, RelatedObjects=subelements)
|
||||
|
||||
original_order = subelements.copy()
|
||||
# unassign elements in some random order
|
||||
# skip 1 element to make sure rel won't get removed
|
||||
removed_elements = set()
|
||||
for i in (0, 3, 2, 4):
|
||||
subelement = subelements[i]
|
||||
ifcopenshell.api.run("nest.unassign_object", self.file, related_objects=[subelement])
|
||||
removed_elements.add(subelement)
|
||||
assert rel.RelatedObjects == tuple([o for o in original_order if o not in removed_elements])
|
||||
|
||||
|
||||
class TestUnassignObjectIFC2X3(test.bootstrap.IFC2X3, TestUnassignObject):
|
||||
pass
|
||||
|
||||
@@ -32,3 +32,7 @@ class TestAddActor(test.bootstrap.IFC4):
|
||||
actor = ifcopenshell.api.run("owner.add_actor", self.file, ifc_class="IfcOccupant", actor=person)
|
||||
assert actor.is_a() == "IfcOccupant"
|
||||
assert actor.TheActor == person
|
||||
|
||||
|
||||
class TestAddActorIFC2X3(test.bootstrap.IFC2X3, TestAddActor):
|
||||
pass
|
||||
|
||||
@@ -48,3 +48,7 @@ class TestAddAddress(test.bootstrap.IFC4):
|
||||
assert postal.Purpose == telecom.Purpose == "OFFICE"
|
||||
assert postal in organisation.Addresses
|
||||
assert telecom in organisation.Addresses
|
||||
|
||||
|
||||
class TestAddAddressIFC2X3(test.bootstrap.IFC2X3, TestAddAddress):
|
||||
pass
|
||||
|
||||
@@ -28,7 +28,8 @@ class TestAddApplication(test.bootstrap.IFC4):
|
||||
assert application.ApplicationFullName == "IfcOpenShell"
|
||||
assert application.ApplicationIdentifier == "IfcOpenShell"
|
||||
assert developer.is_a("IfcOrganization")
|
||||
assert developer.Identification == "IfcOpenShell"
|
||||
# 0 IfcOrganization Identification(>IFC2X3) / Id (IFC2X3)
|
||||
assert developer[0] == "IfcOpenShell"
|
||||
assert developer.Name == "IfcOpenShell"
|
||||
assert (
|
||||
developer.Description
|
||||
@@ -40,3 +41,7 @@ class TestAddApplication(test.bootstrap.IFC4):
|
||||
assert developer.Addresses[0].Purpose == "USERDEFINED"
|
||||
assert developer.Addresses[0].UserDefinedPurpose == "WEBPAGE"
|
||||
assert developer.Addresses[0].WWWHomePageURL == "https://ifcopenshell.org"
|
||||
|
||||
|
||||
class TestAddApplicationIFC2X3(test.bootstrap.IFC2X3, TestAddApplication):
|
||||
pass
|
||||
|
||||
@@ -23,5 +23,10 @@ import ifcopenshell.api
|
||||
class TestAddOrganisation(test.bootstrap.IFC4):
|
||||
def test_adding_an_organisation(self):
|
||||
org = ifcopenshell.api.run("owner.add_organisation", self.file, identification="Id", name="Name")
|
||||
assert org.Identification == "Id"
|
||||
# 0 IfcOrganization Identification(>IFC2X3) / Id (IFC2X3)
|
||||
assert org[0] == "Id"
|
||||
assert org.Name == "Name"
|
||||
|
||||
|
||||
class TestAddOrganisationIFC2X3(test.bootstrap.IFC2X3, TestAddOrganisation):
|
||||
pass
|
||||
|
||||
@@ -29,6 +29,11 @@ class TestAddPerson(test.bootstrap.IFC4):
|
||||
family_name="FamilyName",
|
||||
given_name="GivenName",
|
||||
)
|
||||
assert person.Identification == "Identification"
|
||||
# 0 IfcPerson Identification(>IFC2X3) / Id (IFC2X3)
|
||||
assert person[0] == "Identification"
|
||||
assert person.FamilyName == "FamilyName"
|
||||
assert person.GivenName == "GivenName"
|
||||
|
||||
|
||||
class TestAddPersonIFC2X3(test.bootstrap.IFC2X3, TestAddPerson):
|
||||
pass
|
||||
|
||||
@@ -27,3 +27,7 @@ class TestAddPersonAndOrganisation(test.bootstrap.IFC4):
|
||||
person_and_organisation = ifcopenshell.api.run(
|
||||
"owner.add_person_and_organisation", self.file, person=person, organisation=organisation
|
||||
)
|
||||
|
||||
|
||||
class TestAddPersonAndOrganisationIFC2X3(test.bootstrap.IFC2X3, TestAddPersonAndOrganisation):
|
||||
pass
|
||||
|
||||
@@ -34,3 +34,7 @@ class TestAddRole(test.bootstrap.IFC4):
|
||||
assert role.is_a("IfcActorRole")
|
||||
assert role.Role == "ARCHITECT"
|
||||
assert organisation.Roles == (role,)
|
||||
|
||||
|
||||
class TestAddRoleIFC2X3(test.bootstrap.IFC2X3, TestAddRole):
|
||||
pass
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAssignProduct(test.bootstrap.IFC4):
|
||||
class TestAssignActor(test.bootstrap.IFC4):
|
||||
def test_assigning_an_actor(self):
|
||||
wall = self.file.createIfcWall()
|
||||
wall2 = self.file.createIfcWall()
|
||||
@@ -36,3 +36,7 @@ class TestAssignProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.assign_actor", self.file, relating_actor=actor, related_object=wall)
|
||||
ifcopenshell.api.run("owner.assign_actor", self.file, relating_actor=actor, related_object=wall)
|
||||
assert actor.IsActingUpon[0].RelatedObjects == (wall,)
|
||||
|
||||
|
||||
class TestAssignActorIFC2X3(test.bootstrap.IFC2X3, TestAssignActor):
|
||||
pass
|
||||
|
||||
@@ -17,25 +17,36 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.owner.settings
|
||||
|
||||
|
||||
class TestCreateOwnerHistory(test.bootstrap.IFC4):
|
||||
def test_creating_nothing_if_no_user_or_application_is_available(self):
|
||||
history = ifcopenshell.api.run("owner.create_owner_history", self.file)
|
||||
assert history is None
|
||||
if self.file.schema != "IFC2X3":
|
||||
history = ifcopenshell.api.run("owner.create_owner_history", self.file)
|
||||
assert history is None
|
||||
else:
|
||||
ifcopenshell.api.owner.settings.factory_reset()
|
||||
# create new file as bootstrap is creating users in ifc2x3 by default
|
||||
file = ifcopenshell.file(schema="IFC2X3")
|
||||
with pytest.raises(Exception) as e:
|
||||
ifcopenshell.api.run("owner.create_owner_history", file)
|
||||
assert "Please create a user to continue" in str(e.value)
|
||||
ifcopenshell.api.owner.settings.restore()
|
||||
|
||||
def test_creating_a_history_using_a_specified_user_and_application(self):
|
||||
old_get_user = ifcopenshell.api.owner.settings.get_user
|
||||
old_get_application = ifcopenshell.api.owner.settings.get_application
|
||||
ifcopenshell.api.owner.settings.factory_reset()
|
||||
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
application = self.file.createIfcApplication()
|
||||
ifcopenshell.api.owner.settings.get_user = lambda x: user
|
||||
ifcopenshell.api.owner.settings.get_application = lambda x: application
|
||||
history = ifcopenshell.api.run("owner.create_owner_history", self.file)
|
||||
ifcopenshell.api.owner.settings.get_user = old_get_user
|
||||
ifcopenshell.api.owner.settings.get_application = old_get_application
|
||||
ifcopenshell.api.owner.settings.restore()
|
||||
|
||||
assert history.is_a("IfcOwnerHistory")
|
||||
assert history.OwningUser == user
|
||||
assert history.OwningApplication == application
|
||||
@@ -45,3 +56,7 @@ class TestCreateOwnerHistory(test.bootstrap.IFC4):
|
||||
assert history.LastModifyingUser == user
|
||||
assert history.LastModifyingApplication == application
|
||||
assert abs(time.time() - history.CreationDate) < 5
|
||||
|
||||
|
||||
class TestCreateOwnerHistoryIFC2X3(test.bootstrap.IFC2X3, TestCreateOwnerHistory):
|
||||
pass
|
||||
|
||||
@@ -52,3 +52,7 @@ class TestEditActor(test.bootstrap.IFC4):
|
||||
assert actor.Description == "Description"
|
||||
assert actor.ObjectType == "ObjectType"
|
||||
assert actor.PredefinedType == "TENANT"
|
||||
|
||||
|
||||
class TestEditActorIFC2X3(test.bootstrap.IFC2X3, TestEditActor):
|
||||
pass
|
||||
|
||||
@@ -53,21 +53,24 @@ class TestEditAddress(test.bootstrap.IFC4):
|
||||
|
||||
def test_editing_a_telecom_address(self):
|
||||
address = self.file.createIfcTelecomAddress()
|
||||
attributes = {
|
||||
"Purpose": "OFFICE",
|
||||
"Description": "Description",
|
||||
"UserDefinedPurpose": "UserDefinedPurpose",
|
||||
"TelephoneNumbers": ["Telephone", "Numbers"],
|
||||
"FacsimileNumbers": ["Facsimile", "Numbers"],
|
||||
"PagerNumber": "PagerNumber",
|
||||
"ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"],
|
||||
"WWWHomePageURL": "WWWHomePageURL",
|
||||
}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attributes["MessagingIDs"] = ["Messaging", "IDs"]
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"owner.edit_address",
|
||||
self.file,
|
||||
address=address,
|
||||
attributes={
|
||||
"Purpose": "OFFICE",
|
||||
"Description": "Description",
|
||||
"UserDefinedPurpose": "UserDefinedPurpose",
|
||||
"TelephoneNumbers": ["Telephone", "Numbers"],
|
||||
"FacsimileNumbers": ["Facsimile", "Numbers"],
|
||||
"PagerNumber": "PagerNumber",
|
||||
"ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"],
|
||||
"WWWHomePageURL": "WWWHomePageURL",
|
||||
"MessagingIDs": ["Messaging", "IDs"],
|
||||
},
|
||||
attributes=attributes,
|
||||
)
|
||||
assert address.Purpose == "OFFICE"
|
||||
assert address.Description == "Description"
|
||||
@@ -77,4 +80,9 @@ class TestEditAddress(test.bootstrap.IFC4):
|
||||
assert address.PagerNumber == "PagerNumber"
|
||||
assert address.ElectronicMailAddresses == ("Electronic", "Mail", "Addresses")
|
||||
assert address.WWWHomePageURL == "WWWHomePageURL"
|
||||
assert address.MessagingIDs == ("Messaging", "IDs")
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert address.MessagingIDs == ("Messaging", "IDs")
|
||||
|
||||
|
||||
class TestEditAddressIFC2X3(test.bootstrap.IFC2X3, TestEditAddress):
|
||||
pass
|
||||
|
||||
@@ -28,11 +28,16 @@ class TestEditOrganisation(test.bootstrap.IFC4):
|
||||
self.file,
|
||||
organisation=organisation,
|
||||
attributes={
|
||||
"Identification": "Identification",
|
||||
"Identification" if self.file.schema != "IFC2X3" else "Id": "Identification",
|
||||
"Name": "Name",
|
||||
"Description": "Description",
|
||||
},
|
||||
)
|
||||
assert organisation.Identification == "Identification"
|
||||
# 0 IfcOrganization Identification(>IFC2X3) / Id (IFC2X3)
|
||||
assert organisation[0] == "Identification"
|
||||
assert organisation.Name == "Name"
|
||||
assert organisation.Description == "Description"
|
||||
|
||||
|
||||
class TestEditOrganisationIFC2X3(test.bootstrap.IFC2X3, TestEditOrganisation):
|
||||
pass
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestEditPerson(test.bootstrap.IFC4):
|
||||
self.file,
|
||||
person=person,
|
||||
attributes={
|
||||
"Identification": "Identification",
|
||||
"Identification" if self.file.schema != "IFC2X3" else "Id": "Identification",
|
||||
"FamilyName": "FamilyName",
|
||||
"GivenName": "GivenName",
|
||||
"MiddleNames": ["Middle", "Names"],
|
||||
@@ -36,9 +36,14 @@ class TestEditPerson(test.bootstrap.IFC4):
|
||||
"SuffixTitles": ["Suffix", "Titles"],
|
||||
},
|
||||
)
|
||||
assert person.Identification == "Identification"
|
||||
# 0 IfcPerson Identification(>IFC2X3) / Id (IFC2X3)
|
||||
assert person[0] == "Identification"
|
||||
assert person.FamilyName == "FamilyName"
|
||||
assert person.GivenName == "GivenName"
|
||||
assert person.MiddleNames == ("Middle", "Names")
|
||||
assert person.PrefixTitles == ("Prefix", "Titles")
|
||||
assert person.SuffixTitles == ("Suffix", "Titles")
|
||||
|
||||
|
||||
class TestEditPersonIFC2X3(test.bootstrap.IFC2X3, TestEditPerson):
|
||||
pass
|
||||
|
||||
@@ -32,3 +32,7 @@ class TestEditRole(test.bootstrap.IFC4):
|
||||
assert role.Role == "ARCHITECT"
|
||||
assert role.UserDefinedRole == "UserDefinedRole"
|
||||
assert role.Description == "Description"
|
||||
|
||||
|
||||
class TestEditRoleIFC2X3(test.bootstrap.IFC2X3, TestEditRole):
|
||||
pass
|
||||
|
||||
@@ -26,3 +26,7 @@ class TestRemoveActor(test.bootstrap.IFC4):
|
||||
actor = ifcopenshell.api.run("owner.add_actor", self.file, ifc_class="IfcActor", actor=person)
|
||||
ifcopenshell.api.run("owner.remove_actor", self.file, actor=actor)
|
||||
assert len(self.file.by_type("IfcActor")) == 0
|
||||
|
||||
|
||||
class TestRemoveActorIFC2X3(test.bootstrap.IFC2X3, TestRemoveActor):
|
||||
pass
|
||||
|
||||
@@ -41,3 +41,7 @@ class TestRemoveAddress(test.bootstrap.IFC4):
|
||||
person.Addresses = [address]
|
||||
ifcopenshell.api.run("owner.remove_address", self.file, address=address)
|
||||
assert person.Addresses is None
|
||||
|
||||
|
||||
class TestRemoveAddressIFC2X3(test.bootstrap.IFC2X3, TestRemoveAddress):
|
||||
pass
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestRemoveOrganisation(test.bootstrap.IFC4):
|
||||
class TestRemoveOrganisationIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_a_organisation(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
@@ -81,26 +82,29 @@ class TestRemoveOrganisation(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert document_information.Editors is None
|
||||
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
def test_deleting_an_application(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcApplication(ApplicationDeveloper=organisation)
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcApplication")) == 0
|
||||
|
||||
|
||||
class TestRemoveOrganisationIFC4(test.bootstrap.IFC4, TestRemoveOrganisationIFC2X3):
|
||||
# IfcResourceLevelRelationships were added in IFC4
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
# 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 pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestRemovePerson(test.bootstrap.IFC4):
|
||||
class TestRemovePersonIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_a_person(self):
|
||||
person = self.file.createIfcPerson()
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
@@ -60,8 +62,13 @@ class TestRemovePerson(test.bootstrap.IFC4):
|
||||
def test_ensuring_inventory_should_not_be_left_in_an_invalid_set_cardinality(self):
|
||||
person = self.file.createIfcPerson()
|
||||
inventory = self.file.createIfcInventory(ResponsiblePersons=[person])
|
||||
inventory_id = inventory.id()
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert inventory.ResponsiblePersons is None
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert inventory.ResponsiblePersons is None
|
||||
else:
|
||||
with pytest.raises(RuntimeError):
|
||||
self.file.by_id(inventory_id)
|
||||
|
||||
def test_deleting_person_and_organisations(self):
|
||||
person = self.file.createIfcPerson()
|
||||
@@ -81,20 +88,23 @@ class TestRemovePerson(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert document_information.Editors is None
|
||||
|
||||
|
||||
class TestRemovePersonIFC4(test.bootstrap.IFC4, TestRemovePersonIFC2X3):
|
||||
# IfcResourceLevelRelationships were added in IFC4
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[person])
|
||||
person = self.file.create_entity("IfcPerson")
|
||||
self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[person])
|
||||
person = self.file.create_entity("IfcPerson")
|
||||
self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
person = self.file.createIfcPerson()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[person])
|
||||
person = self.file.create_entity("IfcPerson")
|
||||
self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[person])
|
||||
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestRemovePersonAndOrganisation(test.bootstrap.IFC4):
|
||||
class TestRemovePersonAndOrganisationIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
@@ -38,26 +39,29 @@ class TestRemovePersonAndOrganisation(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert document_information.Editors is None
|
||||
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
def test_deleting_owner_history(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcOwnerHistory(OwningUser=user)
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcOwnerHistory")) == 0
|
||||
|
||||
|
||||
class TestRemovePersonAndOrganisationIFC4(test.bootstrap.IFC4, TestRemovePersonAndOrganisationIFC2X3):
|
||||
# IfcResourceLevelRelationships were added in IFC4
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
user = self.file.create_entity("IfcPersonAndOrganization")
|
||||
self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
user = self.file.create_entity("IfcPersonAndOrganization")
|
||||
self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
user = self.file.create_entity("IfcPersonAndOrganization")
|
||||
self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
@@ -20,7 +20,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemoveRole(test.bootstrap.IFC4):
|
||||
class TestRemoveRoleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_a_role(self):
|
||||
role = self.file.createIfcActorRole()
|
||||
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||
@@ -47,20 +47,22 @@ class TestRemoveRole(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||
assert person_and_organisation.Roles is None
|
||||
|
||||
|
||||
class TestRemoveRoleIFC4(test.bootstrap.IFC4, TestRemoveRoleIFC2X3):
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[organisation])
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcResourceApprovalRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[organisation])
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcResourceConstraintRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
organisation = self.file.createIfcOrganization()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[organisation])
|
||||
organisation = self.file.create_entity("IfcOrganization")
|
||||
self.file.create_entity("IfcExternalReferenceRelationship", RelatedResourceObjects=[organisation])
|
||||
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
@@ -27,3 +27,7 @@ class TestUnassignActor(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("owner.assign_actor", self.file, relating_actor=actor, related_object=wall)
|
||||
ifcopenshell.api.run("owner.unassign_actor", self.file, relating_actor=actor, related_object=wall)
|
||||
assert len(self.file.by_type("IfcRelAssignsToActor")) == 0
|
||||
|
||||
|
||||
class TestUnassignActorIFC2X3(test.bootstrap.IFC2X3, TestUnassignActor):
|
||||
pass
|
||||
|
||||
@@ -96,3 +96,7 @@ class TestUpdateOwnerHistory(test.bootstrap.IFC4):
|
||||
def test_doing_nothing_if_no_history_can_be_updated(self):
|
||||
person = self.file.createIfcPerson()
|
||||
assert ifcopenshell.api.run("owner.update_owner_history", self.file, element=person) == None
|
||||
|
||||
|
||||
class TestUpdateOwnerHistoryIFC2X3(test.bootstrap.IFC2X3, TestUpdateOwnerHistory):
|
||||
pass
|
||||
|
||||
@@ -21,9 +21,9 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAppendAsset(test.bootstrap.IFC4):
|
||||
class TestAppendAssetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_do_not_append_twice(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", library, name="Schedule")
|
||||
@@ -40,13 +40,13 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
|
||||
def test_append_a_type_product(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
|
||||
def test_reuse_an_existing_context_if_it_was_added_from_library_previously(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
project = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
lib_context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert context.WorldCoordinateSystem
|
||||
|
||||
def test_append_a_single_type_product_even_though_an_inverse_material_relationship_is_shared(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
@@ -76,7 +76,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
|
||||
def test_append_a_type_product_with_its_materials(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element], material=material)
|
||||
@@ -84,7 +84,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert self.file.by_type("IfcWallType")[0].HasAssociations[0].RelatingMaterial.Name == "Material"
|
||||
|
||||
def test_append_a_type_product_where_its_inverse_material_relationship_refers_to_products_not_in_scope(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
@@ -102,34 +102,11 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element_type2)
|
||||
assert set(self.file.by_type("IfcWall")) == set()
|
||||
|
||||
def test_append_two_type_products_sharing_the_same_material_with_properties(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
|
||||
pset = ifcopenshell.api.run("pset.add_pset", library, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", library, pset=pset, properties={"Foo": "Bar"})
|
||||
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element1], material=material)
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element2], material=material)
|
||||
new1 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element1)
|
||||
new2 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
|
||||
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 1
|
||||
material = self.file.by_type("IfcMaterial")[0]
|
||||
assert ifcopenshell.util.element.get_material(new1) == material
|
||||
assert ifcopenshell.util.element.get_material(new2) == material
|
||||
assert ifcopenshell.util.element.get_psets(material)["Foo_Bar"]["Foo"] == "Bar"
|
||||
|
||||
def test_append_two_type_products_sharing_the_same_material_indirectly_via_a_material_set(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element1 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", library, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", library, pset=pset, properties={"Foo": "Bar"})
|
||||
|
||||
layer_set1 = ifcopenshell.api.run("material.add_material_set", library, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.add_layer", library, layer_set=layer_set1, material=material)
|
||||
@@ -145,16 +122,14 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
new1 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element1)
|
||||
new2 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
|
||||
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 1
|
||||
material = self.file.by_type("IfcMaterial")[0]
|
||||
assert ifcopenshell.util.element.get_material(new1).MaterialLayers[0].Material == material
|
||||
assert ifcopenshell.util.element.get_material(new1).MaterialLayers[1].Material == material
|
||||
assert ifcopenshell.util.element.get_material(new2).MaterialLayers[0].Material == material
|
||||
assert ifcopenshell.util.element.get_material(new2).MaterialLayers[1].Material == material
|
||||
assert ifcopenshell.util.element.get_psets(material)["Foo_Bar"]["Foo"] == "Bar"
|
||||
|
||||
def test_append_a_type_product_with_its_styles(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
history = library.createIfcOwnerHistory()
|
||||
element.OwnerHistory = history
|
||||
@@ -175,7 +150,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert self.file.by_type("IfcStyledItem")[0].Item == self.file.by_type("IfcBoundingBox")[0]
|
||||
|
||||
def test_append_product_with_styles_to_reuse_styleditems(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
history = library.createIfcOwnerHistory()
|
||||
element_type.OwnerHistory = history
|
||||
@@ -195,7 +170,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
local_context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
context = ifcopenshell.api.run("context.add_context", library, context_type="Model")
|
||||
|
||||
@@ -210,7 +185,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
|
||||
|
||||
def test_append_a_material(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
@@ -218,7 +193,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
def test_append_a_material_with_a_representation(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
style = ifcopenshell.api.run("style.add_style", library)
|
||||
@@ -234,7 +209,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
file_context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
style = ifcopenshell.api.run("style.add_style", library)
|
||||
@@ -261,7 +236,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
target_view="MODEL_VIEW",
|
||||
)
|
||||
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
style = ifcopenshell.api.run("style.add_style", library)
|
||||
@@ -288,7 +263,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
file_context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcProject")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
style = ifcopenshell.api.run("style.add_style", library)
|
||||
@@ -312,48 +287,27 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert subcontext.TargetView == "MODEL_VIEW"
|
||||
assert subcontext.ParentContext == file_context
|
||||
|
||||
def test_append_a_cost_schedule(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", library, name="Schedule")
|
||||
item = ifcopenshell.api.run("cost.add_cost_item", library, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", library, cost_item=item)
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=schedule)
|
||||
assert len(self.file.by_type("IfcCostSchedule")) == 1
|
||||
assert len(self.file.by_type("IfcCostItem")) == 2
|
||||
assert self.file.by_type("IfcCostSchedule")[0].Name == "Schedule"
|
||||
appended_item = self.file.by_type("IfcCostSchedule")[0].Controls[0].RelatedObjects[0]
|
||||
assert appended_item.is_a("IfcCostItem")
|
||||
assert appended_item.IsNestedBy[0].RelatedObjects[0].is_a("IfcCostItem")
|
||||
|
||||
def test_append_a_profile_def(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
profile = library.createIfcIShapeProfileDef()
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=profile)
|
||||
assert len(self.file.by_type("IfcIShapeProfileDef")) == 1
|
||||
|
||||
def test_append_a_profile_def_with_all_properties(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
profile = library.createIfcIShapeProfileDef()
|
||||
ifcopenshell.api.run("pset.add_pset", library, product=profile, name="Foo_Bar")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=profile)
|
||||
assert len(self.file.by_type("IfcIShapeProfileDef")) == 1
|
||||
assert self.file.by_type("IfcIShapeProfileDef")[0].HasProperties[0].Name == "Foo_Bar"
|
||||
|
||||
def test_append_a_product(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||
assert len(self.file.by_type("IfcWall")) == 1
|
||||
|
||||
def test_append_a_product_with_all_properties(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("pset.add_pset", library, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||
assert ifcopenshell.util.element.get_psets(self.file.by_type("IfcWall")[0])["Foo_Bar"]
|
||||
|
||||
def test_append_a_product_with_its_type(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
|
||||
@@ -361,7 +315,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert ifcopenshell.util.element.get_type(self.file.by_type("IfcWall")[0]).is_a("IfcWallType")
|
||||
|
||||
def test_append_only_specified_occurrences_of_a_typed_product(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
@@ -375,7 +329,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcWall")) == 2
|
||||
|
||||
def test_append_a_product_with_materials(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element], material=material)
|
||||
@@ -383,7 +337,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert ifcopenshell.util.element.get_material(self.file.by_type("IfcWall")[0]).Name == "Material"
|
||||
|
||||
def test_append_a_product_where_its_inverse_material_relationship_refers_to_product_types_not_in_scope(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
@@ -396,7 +350,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert [e.GlobalId for e in self.file.by_type("IfcWallType")] == [element_type.GlobalId]
|
||||
|
||||
def test_append_a_product_with_its_styles(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
item = library.createIfcBoundingBox()
|
||||
library.createIfcStyledItem(Item=item)
|
||||
@@ -406,7 +360,7 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert self.file.by_type("IfcStyledItem")[0].Item == self.file.by_type("IfcBoundingBox")[0]
|
||||
|
||||
def test_append_a_product_with_openings(self):
|
||||
library = ifcopenshell.api.run("project.create_file")
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
opening = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcOpeningElement")
|
||||
ifcopenshell.api.run("void.add_opening", library, opening=opening, element=element)
|
||||
@@ -414,25 +368,50 @@ class TestAppendAsset(test.bootstrap.IFC4):
|
||||
assert self.file.by_type("IfcWall")[0].HasOpenings[0].RelatedOpeningElement.is_a("IfcOpeningElement")
|
||||
|
||||
|
||||
class TestAppendAssetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_append_a_product_with_its_type(self):
|
||||
library = ifcopenshell.api.run("project.create_file", version="IFC2X3")
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||
assert ifcopenshell.util.element.get_type(self.file.by_type("IfcWall")[0]).is_a("IfcWallType")
|
||||
class TestAppendAssetIFC4(test.bootstrap.IFC4, TestAppendAssetIFC2X3):
|
||||
# NOTE: breaks in IFC2X3 since IfcProfileDef doesn't have "HasProperties" inverse in ifc2x3
|
||||
# and we use it in whitelisted_inverse_attributes for appending IfcProfileDef
|
||||
def test_append_a_profile_def_with_all_properties(self):
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
profile = library.createIfcIShapeProfileDef()
|
||||
ifcopenshell.api.run("pset.add_pset", library, product=profile, name="Foo_Bar")
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=profile)
|
||||
assert len(self.file.by_type("IfcIShapeProfileDef")) == 1
|
||||
assert self.file.by_type("IfcIShapeProfileDef")[0].HasProperties[0].Name == "Foo_Bar"
|
||||
|
||||
def test_append_only_specified_occurrences_of_a_typed_product(self):
|
||||
library = ifcopenshell.api.run("project.create_file", version="IFC2X3")
|
||||
element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", library, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.run("type.assign_type", library, related_objects=[element2], relating_type=element_type)
|
||||
ifcopenshell.api.run("type.assign_type", library, related_objects=[element3], relating_type=element_type)
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element)
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
|
||||
assert len(ifcopenshell.util.element.get_types(self.file.by_type("IfcWallType")[0])) == 2
|
||||
assert len(self.file.by_type("IfcWall")) == 2
|
||||
# NOTE: breaks in IFC2X3 since IfcMaterial doesn't have "HasProperties" inverse in ifc2x3
|
||||
# and we use it in whitelisted_inverse_attributes for appending IfcTypeProduct
|
||||
def test_append_two_type_products_sharing_the_same_material_with_properties(self):
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
element1 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", library, name="Material")
|
||||
|
||||
pset = ifcopenshell.api.run("pset.add_pset", library, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", library, pset=pset, properties={"Foo": "Bar"})
|
||||
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element1], material=material)
|
||||
ifcopenshell.api.run("material.assign_material", library, products=[element2], material=material)
|
||||
new1 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element1)
|
||||
new2 = ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element2)
|
||||
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 1
|
||||
material = self.file.by_type("IfcMaterial")[0]
|
||||
assert ifcopenshell.util.element.get_material(new1) == material
|
||||
assert ifcopenshell.util.element.get_material(new2) == material
|
||||
assert ifcopenshell.util.element.get_psets(material)["Foo_Bar"]["Foo"] == "Bar"
|
||||
|
||||
# NOTE: breaks in IFC2X3 since IfcCostItem doesn't have "IsNestedBy" inverse in ifc2x3
|
||||
# and we use it in whitelisted_inverse_attributes for appending IfcCostSchedule
|
||||
def test_append_a_cost_schedule(self):
|
||||
library = ifcopenshell.api.run("project.create_file", version=self.file.schema)
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", library, name="Schedule")
|
||||
item = ifcopenshell.api.run("cost.add_cost_item", library, cost_schedule=schedule)
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", library, cost_item=item)
|
||||
ifcopenshell.api.run("project.append_asset", self.file, library=library, element=schedule)
|
||||
assert len(self.file.by_type("IfcCostSchedule")) == 1
|
||||
assert len(self.file.by_type("IfcCostItem")) == 2
|
||||
assert self.file.by_type("IfcCostSchedule")[0].Name == "Schedule"
|
||||
appended_item = self.file.by_type("IfcCostSchedule")[0].Controls[0].RelatedObjects[0]
|
||||
assert appended_item.is_a("IfcCostItem")
|
||||
assert appended_item.IsNestedBy[0].RelatedObjects[0].is_a("IfcCostItem")
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,82 @@
|
||||
# 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
|
||||
from typing import Union
|
||||
|
||||
|
||||
# NOTE: supported only in IFC4+
|
||||
class TestUnassignDeclaration(test.bootstrap.IFC4):
|
||||
def get_context(self, definition: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]:
|
||||
rel = next(iter(definition.HasContext), None)
|
||||
if rel is not None:
|
||||
return rel.RelatingContext
|
||||
|
||||
def test_unassigning_a_definition(self):
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
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")
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration", self.file, definitions=[element_type, element_type2], relating_context=library
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"project.unassign_declaration",
|
||||
self.file,
|
||||
definitions=[element_type, element_type2],
|
||||
relating_context=library,
|
||||
)
|
||||
assert self.get_context(element_type) == None
|
||||
assert len(self.file.by_type("IfcRelDeclares")) == 0
|
||||
|
||||
def test_doing_nothing_if_there_was_no_declaration(self):
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
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")
|
||||
ifcopenshell.api.run(
|
||||
"project.unassign_declaration",
|
||||
self.file,
|
||||
definitions=[element_type, element_type2],
|
||||
relating_context=library,
|
||||
)
|
||||
assert self.get_context(element_type) == None
|
||||
assert self.get_context(element_type2) == None
|
||||
|
||||
def test_updating_the_rel_when_a_reference_is_removed_with_multipled_elements(self):
|
||||
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
|
||||
element_type1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
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_type1], relating_context=library
|
||||
)
|
||||
rel = self.file.by_type("IfcRelDeclares")[0]
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
self.file,
|
||||
definitions=[element_type2, element_type3],
|
||||
relating_context=library,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"project.unassign_declaration",
|
||||
self.file,
|
||||
definitions=[element_type1, element_type2],
|
||||
relating_context=library,
|
||||
)
|
||||
assert rel.RelatedDefinitions == (element_type3,)
|
||||
@@ -38,13 +38,16 @@ class TestAddPset(test.bootstrap.IFC4):
|
||||
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)
|
||||
assert pset.Name == "Pset_MaterialCommon"
|
||||
assert pset.Material == 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)
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert pset.Name == "Pset_ProfileMechanical"
|
||||
assert pset.ProfileDefinition == profile
|
||||
|
||||
def test_adding_a_pset_to_a_context(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
@@ -53,7 +56,7 @@ class TestAddPset(test.bootstrap.IFC4):
|
||||
assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
|
||||
class TestAddPsetIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestAddPsetIFC2X3(test.bootstrap.IFC2X3, TestAddPset):
|
||||
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")
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import operator
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestEditPset(test.bootstrap.IFC4):
|
||||
@@ -58,7 +59,9 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
pset=pset,
|
||||
properties={"Reference": "foo", "Status": ["NEW"], "Combustible": True, "ThermalTransmittance": 42},
|
||||
)
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": []})
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": []}, should_purge=False
|
||||
)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
|
||||
assert pset.HasProperties[0].Name == "Reference"
|
||||
@@ -87,8 +90,7 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
def test_adding_a_property_if_it_is_none(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")
|
||||
# should_purge is false by default
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None})
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=False)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 1
|
||||
|
||||
@@ -107,6 +109,16 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 0
|
||||
|
||||
def test_removing_a_none_enumeration_property_if_specified(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")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||
assert pset.HasProperties[0].Name == "Status"
|
||||
assert pset.HasProperties[0].EnumerationValues[0].wrappedValue == "NEW"
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": []}, should_purge=True)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 0
|
||||
|
||||
def test_editing_a_pset_name(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="foo")
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestRemovePset(test.bootstrap.IFC4):
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,65 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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 pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.resource
|
||||
import ifcopenshell.util.resource
|
||||
|
||||
|
||||
class TestAddResourceQuantity(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
schema = ifcopenshell.schema_by_name(self.file.schema)
|
||||
quantity_types = [t.name() for t in schema.declaration_by_name("IfcPhysicalSimpleQuantity").subtypes()]
|
||||
resource_types = [t.name() for t in schema.declaration_by_name("IfcConstructionResource").subtypes()]
|
||||
|
||||
self.file.create_entity("IfcProject") # add_resource
|
||||
|
||||
for resource_type in resource_types:
|
||||
resource = ifcopenshell.api.resource.add_resource(self.file, ifc_class=resource_type)
|
||||
available_quantities = ifcopenshell.util.resource.RESOURCES_TO_QUANTITIES[resource_type]
|
||||
|
||||
for quantity_type in quantity_types:
|
||||
if quantity_type not in available_quantities:
|
||||
with pytest.raises(ValueError):
|
||||
quantity = ifcopenshell.api.resource.add_resource_quantity(
|
||||
self.file, resource=resource, ifc_class=quantity_type
|
||||
)
|
||||
continue
|
||||
else:
|
||||
quantity = ifcopenshell.api.resource.add_resource_quantity(
|
||||
self.file, resource=resource, ifc_class=quantity_type
|
||||
)
|
||||
|
||||
assert quantity.is_a(quantity_type)
|
||||
assert quantity.Name == "Unnamed"
|
||||
assert quantity[3] == 0.0
|
||||
# previous quantity is reassigned and removed
|
||||
assert resource.BaseQuantity == quantity
|
||||
assert len(self.file.by_type("IfcPhysicalSimpleQuantity")) == 1
|
||||
|
||||
ifcopenshell.api.resource.remove_resource(self.file, resource)
|
||||
|
||||
|
||||
class TestAddResourceQuantityIFC2X3(test.bootstrap.IFC2X3, TestAddResourceQuantity):
|
||||
pass
|
||||
|
||||
|
||||
class TestAddResourceQuantityIFC4X3(test.bootstrap.IFC4X3, TestAddResourceQuantity):
|
||||
pass
|
||||
@@ -21,6 +21,8 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.constraint
|
||||
|
||||
|
||||
# NOTE: resource module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
class TestCalculateResourceWork(test.bootstrap.IFC4):
|
||||
def test_calculating_resource_work_based_on_a_daily_productivity_rate(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2024 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/>.
|
||||
|
||||
# remove_resource tests is partially covered by test_add_resource_quantity.
|
||||
@@ -23,22 +23,22 @@ import ifcopenshell.api
|
||||
class TestCreateEntity(test.bootstrap.IFC4):
|
||||
def test_creating_a_simple_entity_with_automatic_global_id(self):
|
||||
wall = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="SOLIDWALL", name="Foo"
|
||||
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
|
||||
)
|
||||
assert wall.is_a() == "IfcWall"
|
||||
assert wall.is_a() == "IfcRailing"
|
||||
assert len(wall.GlobalId) == 22
|
||||
assert wall.Name == "Foo"
|
||||
assert wall.PredefinedType == "SOLIDWALL"
|
||||
assert wall.PredefinedType == "HANDRAIL"
|
||||
|
||||
def test_handling_predefined_types(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall", name="Foo")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcRailing", name="Foo")
|
||||
assert element.PredefinedType is None
|
||||
element = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="SHEAR", name="Foo"
|
||||
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="HANDRAIL", name="Foo"
|
||||
)
|
||||
assert element.PredefinedType == "SHEAR"
|
||||
assert element.PredefinedType == "HANDRAIL"
|
||||
element = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcWall", predefined_type="Foobar", name="Foo"
|
||||
"root.create_entity", self.file, ifc_class="IfcRailing", predefined_type="Foobar", name="Foo"
|
||||
)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ObjectType == "Foobar"
|
||||
@@ -47,11 +47,12 @@ class TestCreateEntity(test.bootstrap.IFC4):
|
||||
)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ElementType == "Foobar"
|
||||
element = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcTaskType", predefined_type="Foobar", name="Foo"
|
||||
)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ProcessType == "Foobar"
|
||||
if self.file.schema != "IFC2X3":
|
||||
element = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcTaskType", predefined_type="Foobar", name="Foo"
|
||||
)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ProcessType == "Foobar"
|
||||
|
||||
def test_setting_default_values_for_validity(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType", name="Foo")
|
||||
@@ -66,9 +67,14 @@ class TestCreateEntity(test.bootstrap.IFC4):
|
||||
assert element.ConstructionType == "NOTDEFINED"
|
||||
assert element.ParameterTakesPrecedence == False
|
||||
assert element.Sizeable == False
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorType", name="Foo")
|
||||
assert element.OperationType == "NOTDEFINED"
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowType", name="Foo")
|
||||
assert element.PartitioningType == "NOTDEFINED"
|
||||
if self.file.schema != "IFC2X3":
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoorType", name="Foo")
|
||||
assert element.OperationType == "NOTDEFINED"
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindowType", name="Foo")
|
||||
assert element.PartitioningType == "NOTDEFINED"
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFurnitureType", name="Foo")
|
||||
assert element.AssemblyPlace == "NOTDEFINED"
|
||||
|
||||
|
||||
class TestCreateEntityIFC2X3(test.bootstrap.IFC2X3, TestCreateEntity):
|
||||
pass
|
||||
|
||||
@@ -18,14 +18,17 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestReassignClass(test.bootstrap.IFC4):
|
||||
def test_reassigning_a_simple_class(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
n_elements = len([e for e in self.file])
|
||||
original_id = element.id()
|
||||
new = ifcopenshell.api.run("root.reassign_class", self.file, product=element, ifc_class="IfcSlab")
|
||||
assert len([e for e in self.file]) == 1
|
||||
assert new.id() == 1
|
||||
assert len([e for e in self.file]) == n_elements
|
||||
assert new.id() == original_id
|
||||
assert new.is_a("IfcSlab")
|
||||
|
||||
def test_reassigning_a_predefined_type(self):
|
||||
@@ -92,3 +95,7 @@ class TestReassignClass(test.bootstrap.IFC4):
|
||||
# original clases are gone
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
assert len(self.file.by_type("IfcWallType")) == 0
|
||||
|
||||
|
||||
class TestReassignClassIFC2X3(test.bootstrap.IFC2X3, TestReassignClass):
|
||||
pass
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
@@ -76,6 +77,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
total_entities = len(list(self.file))
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element.Representation = self.file.createIfcProductDefinitionShape(
|
||||
Representations=[
|
||||
@@ -84,9 +86,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
)
|
||||
]
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 4
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcProductDefinitionShape")) == 0
|
||||
assert len(self.file.by_type("IfcShapeRepresentation")) == 0
|
||||
assert len(self.file.by_type("IfcExtrudedAreaSolid")) == 0
|
||||
@@ -96,9 +97,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
||||
rep_map = self.file.createIfcRepresentationMap(
|
||||
MappingOrigin=self.file.createIfcAxis2Placement3D(),
|
||||
MappedRepresentation=self.file.createIfcShapeRepresentation(
|
||||
@@ -106,6 +105,16 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
),
|
||||
)
|
||||
element_type.RepresentationMaps = [rep_map]
|
||||
total_entities = len(list(self.file))
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
# should_map_representations=False to create mapping manually
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type",
|
||||
self.file,
|
||||
related_objects=[element],
|
||||
relating_type=element_type,
|
||||
should_map_representations=False,
|
||||
)
|
||||
element.Representation = self.file.createIfcProductDefinitionShape(
|
||||
Representations=[
|
||||
self.file.createIfcShapeRepresentation(
|
||||
@@ -119,10 +128,9 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
)
|
||||
]
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
assert len(self.file.by_type("IfcShapeRepresentation")) == 2
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 6
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcProductDefinitionShape")) == 0
|
||||
assert len(self.file.by_type("IfcShapeRepresentation")) == 1
|
||||
assert len(self.file.by_type("IfcMappedItem")) == 0
|
||||
@@ -138,9 +146,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
|
||||
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 3
|
||||
assert len(list(self.file)) == 0
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
assert len(self.file.by_type("IfcOpeningElement")) == 0
|
||||
assert len(self.file.by_type("IfcRelVoidsElement")) == 0
|
||||
@@ -157,11 +164,11 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
|
||||
def test_removing_all_void_relationships_of_an_opening(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
total_entities = len(list(self.file))
|
||||
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
|
||||
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=opening)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcOpeningElement")) == 0
|
||||
assert len(self.file.by_type("IfcRelVoidsElement")) == 0
|
||||
|
||||
@@ -169,121 +176,122 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
|
||||
filling = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor")
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=element)
|
||||
ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=filling)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=filling)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcDoor")) == 0
|
||||
assert len(self.file.by_type("IfcRelFillsElement")) == 0
|
||||
|
||||
def test_removing_all_distribution_ports(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcChiller")
|
||||
port = ifcopenshell.api.run("system.add_port", self.file, element=element)
|
||||
total_entities = len(list(self.file))
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
port = ifcopenshell.api.run("system.add_port", self.file, element=element)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 3
|
||||
assert len(self.file.by_type("IfcChiller")) == 0
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcFlowSegment")) == 0
|
||||
assert len(self.file.by_type("IfcRelNests")) == 0
|
||||
assert len(self.file.by_type("IfcDistributionPort")) == 0
|
||||
|
||||
def test_removing_all_nesting_relationships_of_a_whole(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelNests")) == 0
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
assert len(self.file.by_type("IfcBeam")) == 1
|
||||
|
||||
def test_removing_all_nesting_relationships_of_a_part(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
total_entities = len(list(self.file))
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelNests")) == 0
|
||||
assert len(self.file.by_type("IfcWall")) == 1
|
||||
assert len(self.file.by_type("IfcBeam")) == 0
|
||||
|
||||
def test_removing_all_aggregate_relationships_of_a_whole(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
assert len(self.file.by_type("IfcElementAssembly")) == 0
|
||||
assert len(self.file.by_type("IfcBeam")) == 1
|
||||
|
||||
def test_removing_all_aggregate_relationships_of_a_part(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
total_entities = len(list(self.file))
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
assert len(self.file.by_type("IfcElementAssembly")) == 1
|
||||
assert len(self.file.by_type("IfcBeam")) == 0
|
||||
|
||||
def test_removing_all_containment_relationships_of_a_container(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace")
|
||||
total_entities = len(list(self.file))
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
|
||||
assert len(self.file.by_type("IfcSpace")) == 0
|
||||
assert len(self.file.by_type("IfcWall")) == 1
|
||||
|
||||
def test_removing_all_containment_relationships_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace")
|
||||
total_entities = len(list(self.file))
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
|
||||
assert len(self.file.by_type("IfcSpace")) == 1
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
|
||||
def test_removing_path_connection_relationships_of_an_element(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcColumn")
|
||||
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=element1, related_element=element2)
|
||||
total_entities = len(list(self.file))
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=element1, related_element=element2)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 0
|
||||
assert len(self.file.by_type("IfcColumn")) == 1
|
||||
assert len(self.file.by_type("IfcBeam")) == 0
|
||||
|
||||
def test_removing_connection_relationships_of_an_element(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
total_entities = len(list(self.file))
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"geometry.connect_element",
|
||||
self.file,
|
||||
related_element=element1,
|
||||
relating_element=element2,
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element1)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
|
||||
assert len(self.file.by_type("IfcSlab")) == 1
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
|
||||
def test_removing_connection_relationships_of_an_element_with_additional_realizing_element(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
total_entities = len(list(self.file))
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
self.file.createIfcRelConnectsWithRealizingElements(
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
@@ -291,9 +299,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
RelatedElement=slab1,
|
||||
RealizingElements=(wall, slab1, slab2),
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=wall)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
|
||||
assert len(self.file.by_type("IfcSlab")) == 2
|
||||
assert len(self.file.by_type("IfcWall")) == 0
|
||||
@@ -301,7 +308,9 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
def test_removing_connection_relationships_of_an_element_element_is_realizing_element(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
total_entities = len(list(self.file))
|
||||
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
slab2_entities = len(list(self.file)) - total_entities
|
||||
self.file.createIfcRelConnectsWithRealizingElements(
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
@@ -311,7 +320,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=slab2)
|
||||
assert len(list(self.file)) == total_entities - 1
|
||||
assert len(list(self.file)) == (total_entities - slab2_entities)
|
||||
assert len(self.file.by_type("IfcRelConnectsElements")) == 1
|
||||
assert len(self.file.by_type("IfcSlab")) == 1
|
||||
assert len(self.file.by_type("IfcWall")) == 1
|
||||
@@ -319,6 +328,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
def test_removing_connection_relationships_of_an_element_element_is_only_realizing_element(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
slab1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
total_entities = len(list(self.file))
|
||||
slab2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
self.file.createIfcRelConnectsWithRealizingElements(
|
||||
ifcopenshell.guid.new(),
|
||||
@@ -327,9 +337,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
RelatedElement=slab1,
|
||||
RealizingElements=(slab2,),
|
||||
)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=slab2)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
assert len(list(self.file)) == total_entities
|
||||
assert len(self.file.by_type("IfcRelConnectsElements")) == 0
|
||||
assert len(self.file.by_type("IfcSlab")) == 1
|
||||
assert len(self.file.by_type("IfcWall")) == 1
|
||||
@@ -394,15 +403,13 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
|
||||
def test_removing_all_space_boundaries_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
boundary = self.file.createIfcRelSpaceBoundary2ndLevel(
|
||||
GlobalId=ifcopenshell.guid.new(), RelatedBuildingElement=element
|
||||
)
|
||||
boundary = self.file.createIfcRelSpaceBoundary(GlobalId=ifcopenshell.guid.new(), RelatedBuildingElement=element)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert not self.file.by_type("IfcRelSpaceBoundary")
|
||||
|
||||
def test_removing_orphaned_group_relationships(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file, Name="Unit 1A")
|
||||
group = ifcopenshell.api.run("group.add_group", self.file, name="Unit 1A")
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert not self.file.by_type("IfcRelAssignsToGroup")
|
||||
@@ -416,8 +423,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
|
||||
def test_removing_flow_control_elements(self):
|
||||
flow_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcController")
|
||||
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcController")
|
||||
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
|
||||
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
@@ -438,8 +445,8 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
|
||||
def test_removing_flow_element_with_flow_controls(self):
|
||||
flow_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcController")
|
||||
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcController")
|
||||
flow_control = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
|
||||
flow_control1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDistributionControlElement")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"system.assign_flow_control",
|
||||
@@ -455,3 +462,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=flow_element)
|
||||
assert not self.file.by_type("IfcRelFlowControlElements")
|
||||
|
||||
|
||||
class TestRemoveProductIFC2X3(TestRemoveProduct, test.bootstrap.IFC2X3):
|
||||
pass
|
||||
|
||||
@@ -36,3 +36,7 @@ class TestAssignProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task)
|
||||
ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task)
|
||||
assert wall.ReferencedBy[0].RelatedObjects == (task,)
|
||||
|
||||
|
||||
class TestAssignProductIFC2X3(test.bootstrap.IFC2X3, TestAssignProduct):
|
||||
pass
|
||||
|
||||
@@ -20,6 +20,8 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# NOTE: sequence module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
class TestCalculateTaskDuration(test.bootstrap.IFC4):
|
||||
def test_calculating_the_duration_based_on_a_labour_resource_with_work_hours(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
|
||||
@@ -22,6 +22,8 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# NOTE: sequence module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
class TestCascadeSchedule(test.bootstrap.IFC4):
|
||||
def test_doing_nothing_if_the_task_has_no_successors(self):
|
||||
task = ifcopenshell.api.run("sequence.add_task", self.file)
|
||||
|
||||
@@ -21,6 +21,9 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# NOTE: IfcTaskTime was introduced in IFC4
|
||||
|
||||
|
||||
class TestEditTaskTime(test.bootstrap.IFC4):
|
||||
def test_editing_all_attributes(self):
|
||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
|
||||
|
||||
@@ -21,6 +21,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# NOTE: IfcWorkTime was introduced in IFC4
|
||||
class TestEditWorkTime(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
work_time = self.file.createIfcWorkTime()
|
||||
|
||||
@@ -22,6 +22,8 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# NOTE: sequence module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
# A good way for checking these is to recreate them in ProjectLibre
|
||||
class TestRecalculateSchedule(test.bootstrap.IFC4):
|
||||
def test_doing_nothing_if_the_task_has_no_time(self):
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# 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 pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.sequence
|
||||
|
||||
|
||||
def declared_objects(ifc_file: ifcopenshell.file) -> set[ifcopenshell.entity_instance]:
|
||||
project = ifc_file.by_type("IfcProject")[0]
|
||||
declared = {obj for rel in project.Declares for obj in rel.RelatedDefinitions}
|
||||
return declared
|
||||
|
||||
|
||||
# NOTE: sequence module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
class TestRemoveWorkPlan(test.bootstrap.IFC4):
|
||||
def test_remove_work_plan(self):
|
||||
self.file.create_entity("IfcProject")
|
||||
work_plan = ifcopenshell.api.sequence.add_work_plan(self.file)
|
||||
work_schedule = ifcopenshell.api.sequence.add_work_schedule(self.file)
|
||||
ifcopenshell.api.sequence.assign_workplan(self.file, work_schedule, work_plan)
|
||||
ifcopenshell.api.sequence.remove_work_plan(self.file, work_plan=work_plan)
|
||||
assert len(self.file.by_type("IfcWorkPlan")) == 0
|
||||
assert declared_objects(self.file) == set()
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
|
||||
|
||||
class TestRemoveWorkPlanIFC4X3(test.bootstrap.IFC4X3, TestRemoveWorkPlan):
|
||||
pass
|
||||
@@ -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 pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.sequence
|
||||
|
||||
|
||||
def declared_objects(ifc_file: ifcopenshell.file) -> set[ifcopenshell.entity_instance]:
|
||||
project = ifc_file.by_type("IfcProject")[0]
|
||||
declared = {obj for rel in project.Declares for obj in rel.RelatedDefinitions}
|
||||
return declared
|
||||
|
||||
|
||||
# NOTE: sequence module features relies on entities introduced in IFC4
|
||||
# therefore no IFC2X3 tests
|
||||
class TestRemoveWorkSchedule(test.bootstrap.IFC4):
|
||||
def test_remove_work_schedule(self):
|
||||
self.file.create_entity("IfcProject")
|
||||
work_schedule = ifcopenshell.api.sequence.add_work_schedule(self.file)
|
||||
|
||||
work_plan = ifcopenshell.api.sequence.add_work_plan(self.file)
|
||||
ifcopenshell.api.sequence.assign_workplan(self.file, work_schedule, work_plan)
|
||||
|
||||
work_schedule1 = ifcopenshell.api.sequence.add_work_schedule(self.file)
|
||||
rel = self.file.create_entity("IfcRelDefinesByObject")
|
||||
rel.RelatingObject = work_schedule
|
||||
rel.RelatedObjects = [work_schedule1]
|
||||
|
||||
ifcopenshell.api.sequence.add_task(self.file, work_schedule=work_schedule)
|
||||
|
||||
ifcopenshell.api.sequence.remove_work_schedule(self.file, work_schedule=work_schedule)
|
||||
# Remove workschedule and subschedules.
|
||||
assert len(self.file.by_type("IfcWorkSchedule")) == 0
|
||||
assert len(self.file.by_type("IfcRelDefinesByObject")) == 0
|
||||
# Unassign from a work plan.
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
# Remove related IfcTasks.
|
||||
assert len(self.file.by_type("IfcTask")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssignsToControl")) == 0
|
||||
# Unassign from a project.
|
||||
assert declared_objects(self.file) == {work_plan}
|
||||
|
||||
|
||||
class TestRemoveWorkScheduleIFC4X3(test.bootstrap.IFC4X3, TestRemoveWorkSchedule):
|
||||
pass
|
||||
@@ -27,3 +27,7 @@ class TestUnassignProduct(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=wall, related_object=task)
|
||||
ifcopenshell.api.run("sequence.unassign_product", self.file, relating_product=wall, related_object=task)
|
||||
assert len(self.file.by_type("IfcRelAssignsToProduct")) == 0
|
||||
|
||||
|
||||
class TestUnassignProductIFC2X3(test.bootstrap.IFC2X3, TestUnassignProduct):
|
||||
pass
|
||||
|
||||
@@ -121,3 +121,7 @@ class TestAssignContainer(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=aggregate)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||
assert not ifcopenshell.util.element.get_aggregate(subelement)
|
||||
|
||||
|
||||
class TestAssignContainerIFC2X3(test.bootstrap.IFC2X3, TestAssignContainer):
|
||||
pass
|
||||
|
||||
@@ -57,3 +57,7 @@ class TestUnassignContainer(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||
ifcopenshell.api.run("spatial.unassign_container", self.file, products=[subelement])
|
||||
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
|
||||
|
||||
|
||||
class TestUnassignContainerIFC2X3(test.bootstrap.IFC2X3, TestUnassignContainer):
|
||||
pass
|
||||
|
||||
@@ -28,3 +28,7 @@ class TestAddStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||
assert subject == models[0]
|
||||
assert subject.is_a("IfcStructuralAnalysisModel")
|
||||
|
||||
|
||||
class TestAddStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestAddStructuralAnalysisModel):
|
||||
pass
|
||||
|
||||
@@ -37,3 +37,7 @@ class TestAssignStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||
assert rel.is_a("IfcRelAssignsToGroup")
|
||||
assert rel.RelatingGroup == subject
|
||||
assert product in rel.RelatedObjects
|
||||
|
||||
|
||||
class TestAssignStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestAssignStructuralAnalysisModel):
|
||||
pass
|
||||
|
||||
@@ -34,3 +34,7 @@ class TestEditStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||
assert subject == models[0]
|
||||
assert subject.is_a("IfcStructuralAnalysisModel")
|
||||
|
||||
|
||||
class TestEditStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestEditStructuralAnalysisModel):
|
||||
pass
|
||||
|
||||
@@ -32,3 +32,7 @@ class TestRemoveStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||
)
|
||||
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||
assert len(models) == 0
|
||||
|
||||
|
||||
class TestRemoveStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestRemoveStructuralAnalysisModel):
|
||||
pass
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user