mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.util.brick as subject
|
||||
|
||||
|
||||
@@ -34,7 +35,7 @@ class TestGetBrickTypeIFC4(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetBrickTypeIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowController")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAirTerminalBoxType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowController")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcAirTerminalBoxType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=type_element)
|
||||
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit"
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
# 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.root
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.classification
|
||||
import ifcopenshell.util.classification as subject
|
||||
|
||||
|
||||
@@ -28,18 +29,16 @@ class TestGetReferences(test.bootstrap.IFC4):
|
||||
classification = library.createIfcClassification(Name="Name")
|
||||
reference1 = library.createIfcClassificationReference(Identification="1", ReferencedSource=classification)
|
||||
reference2 = library.createIfcClassificationReference(Identification="2", ReferencedSource=classification)
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.classification.add_classification(self.file, classification=classification)
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
reference=reference1,
|
||||
classification=classification,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
reference=reference2,
|
||||
@@ -48,11 +47,10 @@ class TestGetReferences(test.bootstrap.IFC4):
|
||||
assert subject.get_references(element) == set(self.file.by_type("IfcClassificationReference"))
|
||||
|
||||
def test_get_references_of_a_non_rooted_element(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = self.file.createIfcMaterial()
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
identification="X",
|
||||
@@ -66,20 +64,18 @@ class TestGetReferences(test.bootstrap.IFC4):
|
||||
classification = library.createIfcClassification(Name="Name")
|
||||
reference1 = library.createIfcClassificationReference(Identification="1", ReferencedSource=classification)
|
||||
reference2 = library.createIfcClassificationReference(Identification="2", ReferencedSource=classification)
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
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)
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.classification.add_classification(self.file, classification=classification)
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
reference=reference1,
|
||||
classification=classification,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element_type],
|
||||
reference=reference2,
|
||||
@@ -95,20 +91,18 @@ class TestGetReferences(test.bootstrap.IFC4):
|
||||
classification = library.createIfcClassification(Name="Name")
|
||||
reference1 = library.createIfcClassificationReference(Identification="1", ReferencedSource=classification)
|
||||
reference2 = library.createIfcClassificationReference(Identification="2", ReferencedSource=classification)
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
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)
|
||||
ifcopenshell.api.run("classification.add_classification", self.file, classification=classification)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.classification.add_classification(self.file, classification=classification)
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
reference=reference1,
|
||||
classification=classification,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element_type],
|
||||
reference=reference2,
|
||||
|
||||
@@ -18,18 +18,34 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.void
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.nest
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.layer
|
||||
import ifcopenshell.api.library
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.spatial
|
||||
import ifcopenshell.api.geometry
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.api.classification
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.api.document
|
||||
import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.guid
|
||||
import ifcopenshell.util.element as subject
|
||||
|
||||
|
||||
class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_psets_of_a_product_as_a_dictionary(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_pset(element, "name") is None
|
||||
assert subject.get_pset(element, "name", "a") is None
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_pset(element, "name") == {"a": "b", "id": pset.id()}
|
||||
assert subject.get_pset(element, "name", "a") == "b"
|
||||
assert subject.get_pset(element, "name", "a", verbose=True) == {
|
||||
@@ -39,10 +55,10 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
}
|
||||
|
||||
def test_getting_the_psets_of_a_product_type_as_a_dictionary(self):
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
foo = subject.get_pset(type_element, "name") is None
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_pset(type_element, "name") == {"x": "y", "id": pset.id()}
|
||||
assert subject.get_pset(type_element, "name", verbose=True) == {
|
||||
"x": {
|
||||
@@ -54,13 +70,13 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
}
|
||||
|
||||
def test_getting_inherited_psets(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
result = subject.get_pset(element, "name")
|
||||
assert result["id"] == pset.id()
|
||||
assert result["a"] == 2
|
||||
@@ -69,8 +85,8 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
assert subject.get_pset(element, "name", "a") == 2
|
||||
assert subject.get_pset(element, "name", "x") == 1
|
||||
assert subject.get_pset(element, "name", "b") == 3
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name2")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"z": False})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name2")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"z": False})
|
||||
assert subject.get_pset(element, "name2", "z") is False
|
||||
|
||||
# test filters with inherited psets
|
||||
@@ -78,13 +94,13 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
assert subject.get_pset(element, "name", qtos_only=True) == None
|
||||
|
||||
def test_excluding_inherited_psets(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
result = subject.get_pset(element, "name", should_inherit=False)
|
||||
assert result["id"] == pset.id()
|
||||
assert result["a"] == 2
|
||||
@@ -97,8 +113,8 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
material = self.file.createIfcMaterial()
|
||||
assert subject.get_pset(material, "name") is None
|
||||
assert subject.get_pset(material, "name", "x") is None
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_pset(material, "name") == {"x": "y", "id": pset.id()}
|
||||
assert subject.get_pset(material, "name", "x") == "y"
|
||||
|
||||
@@ -106,8 +122,8 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
profile = self.file.createIfcCircleProfileDef()
|
||||
assert subject.get_pset(profile, "name") is None
|
||||
assert subject.get_pset(profile, "name", "x") is None
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=profile, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_pset(profile, "name") == {"x": "y", "id": pset.id()}
|
||||
assert subject.get_pset(profile, "name", "x") == "y"
|
||||
|
||||
@@ -118,27 +134,27 @@ class TestGetPsetIFC4(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetPsetsIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_psets_of_a_product_as_a_dictionary(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_psets(element) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_psets(element) == {"name": {"a": "b", "id": pset.id()}}
|
||||
|
||||
def test_getting_the_psets_of_a_product_type_as_a_dictionary(self):
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
assert subject.get_psets(type_element) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_psets(type_element) == {"name": {"x": "y", "id": pset.id()}}
|
||||
|
||||
def test_getting_inherited_psets(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=type_element)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
psets = subject.get_psets(element)
|
||||
assert psets["name"]["id"] == pset.id()
|
||||
assert psets["name"]["a"] == 2
|
||||
@@ -148,58 +164,58 @@ class TestGetPsetsIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_psets_of_a_material_as_a_dictionary(self):
|
||||
material = self.file.createIfcMaterial()
|
||||
assert subject.get_psets(material) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_psets(material) == {"name": {"x": "y", "id": pset.id()}}
|
||||
|
||||
def test_getting_the_psets_of_a_profile_as_a_dictionary(self):
|
||||
profile = self.file.createIfcCircleProfileDef()
|
||||
assert subject.get_psets(profile) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=profile, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_psets(profile) == {"name": {"x": "y", "id": pset.id()}}
|
||||
|
||||
def test_getting_psets_from_an_element_which_cannot_have_psets(self):
|
||||
assert subject.get_psets(self.file.create_entity("IfcPerson")) == {}
|
||||
|
||||
def test_only_getting_psets_and_not_qtos(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")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="pset")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="qto")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_psets(element, psets_only=True) == {"pset": {"a": "b", "id": pset.id()}}
|
||||
|
||||
def test_only_getting_qtos_and_not_psets(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")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="pset")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="qto")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_psets(element, qtos_only=True) == {"qto": {"x": 42, "id": qto.id()}}
|
||||
|
||||
|
||||
class TestGetPropertyDefinitionIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_properties_of_a_pset(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="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_property_definition(pset) == {"a": "b", "id": pset.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_qto(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_property_definition(qto) == {"x": 42, "id": qto.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_material_property(self):
|
||||
pset = self.file.createIfcMaterialProperties()
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_property_definition(pset) == {"a": "b", "id": pset.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_profile_property(self):
|
||||
pset = self.file.createIfcProfileProperties()
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_property_definition(pset) == {"a": "b", "id": pset.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_predefined_pset(self):
|
||||
@@ -210,29 +226,29 @@ class TestGetPropertyDefinitionIFC4(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetQuantitiesIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_quantities_from_a_qto(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_quantities(qto.Quantities) == {"x": 42}
|
||||
|
||||
|
||||
class TestGetPropertiesIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_no_properties_when_none_are_available(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="name")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
assert subject.get_properties(pset.HasProperties) == {}
|
||||
|
||||
def test_getting_single_properties_from_a_list_of_properties(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="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="name")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_properties(pset.HasProperties) == {"a": "b"}
|
||||
|
||||
def test_getting_complex_properties_from_a_list_of_properties(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")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="pset")
|
||||
complex_property = self.file.createIfcComplexProperty(Name="prop", UsageName="usage_name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=complex_property, properties={"a": "b"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=complex_property, properties={"a": "b"})
|
||||
pset.HasProperties = [complex_property]
|
||||
assert subject.get_properties(pset.HasProperties) == {
|
||||
"prop": {
|
||||
@@ -246,68 +262,68 @@ class TestGetPropertiesIFC4(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetPredefinedTypeIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_an_element_predefined_type(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "PARTITIONING"
|
||||
assert subject.get_predefined_type(element) == "PARTITIONING"
|
||||
|
||||
def test_getting_an_element_userdefined_type(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
element.ObjectType = "FOOBAR"
|
||||
assert subject.get_predefined_type(element) == "FOOBAR"
|
||||
|
||||
def test_getting_an_element_type_without_a_predefined_type_attribute(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAnnotation")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcAnnotation")
|
||||
element.ObjectType = "FOOBAR"
|
||||
assert subject.get_predefined_type(element) == "FOOBAR"
|
||||
|
||||
def test_getting_an_inherited_predefined_type(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
element_type.PredefinedType = "PARTITIONING"
|
||||
assert subject.get_predefined_type(element) == "PARTITIONING"
|
||||
|
||||
def test_getting_an_inherited_userdefined_type_for_an_element_type(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
element_type.PredefinedType = "USERDEFINED"
|
||||
element_type.ElementType = "FOOBAR"
|
||||
assert subject.get_predefined_type(element) == "FOOBAR"
|
||||
|
||||
def test_getting_an_overriden_predefined_type(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
element_type.PredefinedType = "NOTDEFINED"
|
||||
element.PredefinedType = "PARTITIONING"
|
||||
assert subject.get_predefined_type(element) == "PARTITIONING"
|
||||
|
||||
def test_getting_an_inherited_userdefined_type_for_a_process_type(self):
|
||||
element = ifcopenshell.api.run("sequence.add_task", self.file)
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTaskType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
||||
element = ifcopenshell.api.sequence.add_task(self.file)
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcTaskType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
element_type.PredefinedType = "USERDEFINED"
|
||||
element_type.ProcessType = "FOOBAR"
|
||||
assert subject.get_predefined_type(element) == "FOOBAR"
|
||||
|
||||
def test_getting_an_element_type_predefined_type(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "PARTITIONING"
|
||||
assert subject.get_predefined_type(element_type) == "PARTITIONING"
|
||||
|
||||
def test_getting_an_element_type_null_predefined_type(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "NOTDEFINED"
|
||||
assert subject.get_predefined_type(element_type) == "NOTDEFINED"
|
||||
|
||||
|
||||
class TestGetTypeIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_type_of_a_product(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert subject.get_type(element) == element_type
|
||||
assert subject.get_type(element_type) == element_type
|
||||
|
||||
@@ -318,9 +334,9 @@ class TestGetTypeIFC2X3(test.bootstrap.IFC2X3, TestGetTypeIFC4):
|
||||
|
||||
class TestGetTypes(test.bootstrap.IFC4):
|
||||
def test_getting_the_type_of_a_product(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert subject.get_types(element_type) == (element,)
|
||||
|
||||
|
||||
@@ -330,7 +346,7 @@ class TestGetTypesIFC2X3(test.bootstrap.IFC2X3, TestGetTypes):
|
||||
|
||||
class TestGetShapeAspects(test.bootstrap.IFC4):
|
||||
def test_getting_the_shape_aspects_of_a_product_type(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
shape_aspect = self.file.createIfcShapeAspect()
|
||||
representation_map = self.file.createIfcRepresentationMap()
|
||||
element_type.RepresentationMaps = (representation_map,)
|
||||
@@ -338,7 +354,7 @@ class TestGetShapeAspects(test.bootstrap.IFC4):
|
||||
assert tuple(subject.get_shape_aspects(element_type)) == (shape_aspect,)
|
||||
|
||||
def test_getting_the_shape_aspects_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
shape_aspect = self.file.createIfcShapeAspect()
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
@@ -348,105 +364,104 @@ class TestGetShapeAspects(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetMaterial(test.bootstrap.IFC4):
|
||||
def test_getting_the_material_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
assert subject.get_material(element) == material
|
||||
|
||||
def test_getting_a_material_list_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialList", material=material
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialList", material=material
|
||||
)
|
||||
assert subject.get_material(element) == rel.RelatingMaterial
|
||||
|
||||
def test_getting_a_material_layer_set_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSet"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialLayerSet"
|
||||
)
|
||||
assert subject.get_material(element) == rel.RelatingMaterial
|
||||
|
||||
def test_getting_a_material_profile_set_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialProfileSet"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialProfileSet"
|
||||
)
|
||||
assert subject.get_material(element) == rel.RelatingMaterial
|
||||
|
||||
def test_getting_a_material_layer_set_usage_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSetUsage"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
assert subject.get_material(element) == rel.RelatingMaterial
|
||||
|
||||
def test_getting_a_material_profile_set_usage_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
assert subject.get_material(element) == rel.RelatingMaterial
|
||||
|
||||
def test_getting_a_material_layer_set_indirectly_from_an_assigned_usage(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSetUsage"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
assert subject.get_material(element, should_skip_usage=True) == rel.RelatingMaterial.ForLayerSet
|
||||
|
||||
def test_getting_a_material_profile_set_indirectly_from_an_assigned_usage(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
rel = ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
assert subject.get_material(element, should_skip_usage=True) == rel.RelatingMaterial.ForProfileSet
|
||||
|
||||
def test_getting_an_inherited_material_from_the_elements_type(self):
|
||||
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)
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material)
|
||||
assert subject.get_material(element) == material
|
||||
|
||||
def test_getting_an_overridden_material_from_the_elements_occurrence(self):
|
||||
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)
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], material=material)
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
assert subject.get_material(element) == material
|
||||
|
||||
def test_getting_direct_materials_without_checking_inheritance(self):
|
||||
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)
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material)
|
||||
assert subject.get_material(element, should_inherit=False) is None
|
||||
|
||||
|
||||
class TestGetMaterials(test.bootstrap.IFC4):
|
||||
def test_getting_the_materials_of_a_product(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
assert subject.get_materials(element) == [material]
|
||||
|
||||
|
||||
class TestGetStyles(test.bootstrap.IFC4):
|
||||
def test_getting_the_styles_of_a_product(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_styles(element) == []
|
||||
|
||||
model = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
body = ifcopenshell.api.run(
|
||||
"context.add_context",
|
||||
model = ifcopenshell.api.context.add_context(self.file, context_type="Model")
|
||||
body = ifcopenshell.api.context.add_context(
|
||||
self.file,
|
||||
context_type="Model",
|
||||
context_identifier="Body",
|
||||
@@ -454,12 +469,11 @@ class TestGetStyles(test.bootstrap.IFC4):
|
||||
parent=model,
|
||||
)
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
|
||||
style = ifcopenshell.api.run("style.add_style", self.file)
|
||||
ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
style = ifcopenshell.api.style.add_style(self.file)
|
||||
ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
@@ -468,13 +482,12 @@ class TestGetStyles(test.bootstrap.IFC4):
|
||||
"Transparency": 0.0, # 0 is opaque, 1 is transparent
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=body)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=body)
|
||||
|
||||
assert subject.get_styles(element) == [style]
|
||||
|
||||
style2 = ifcopenshell.api.run("style.add_style", self.file)
|
||||
ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
style2 = ifcopenshell.api.style.add_style(self.file)
|
||||
ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style2,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
@@ -484,15 +497,15 @@ class TestGetStyles(test.bootstrap.IFC4):
|
||||
},
|
||||
)
|
||||
|
||||
representation = ifcopenshell.api.run(
|
||||
"geometry.add_wall_representation", self.file, context=body, length=5, height=3, thickness=0.118
|
||||
representation = ifcopenshell.api.geometry.add_wall_representation(
|
||||
self.file, context=body, length=5, height=3, thickness=0.118
|
||||
)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"geometry.assign_representation", self.file, product=element, representation=representation
|
||||
ifcopenshell.api.geometry.assign_representation(
|
||||
self.file, product=element, representation=representation
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, shape_representation=representation, styles=[style2]
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, shape_representation=representation, styles=[style2]
|
||||
)
|
||||
|
||||
assert subject.get_styles(element) == [style, style2]
|
||||
@@ -500,35 +513,35 @@ class TestGetStyles(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetElementsByMaterial(test.bootstrap.IFC4):
|
||||
def test_getting_elements_of_a_material(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
assert subject.get_elements_by_material(self.file, material) == {element}
|
||||
|
||||
def test_getting_elements_of_a_material_layer_set(self):
|
||||
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)
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
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=[element_type], material=material_set)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], type="IfcMaterialLayerSetUsage")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material_set)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSetUsage")
|
||||
usage = self.file.by_type("IfcMaterialLayerSetUsage")[0]
|
||||
assert subject.get_elements_by_material(self.file, material) == {element, element_type}
|
||||
assert subject.get_elements_by_material(self.file, material_set) == {element, element_type}
|
||||
assert subject.get_elements_by_material(self.file, usage) == {element}
|
||||
|
||||
def test_getting_elements_of_a_material_profile_set(self):
|
||||
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)
|
||||
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=[element_type], material=material_set)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.material.add_profile(self.file, profile_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], material=material_set)
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
usage = self.file.by_type("IfcMaterialProfileSetUsage")[0]
|
||||
assert subject.get_elements_by_material(self.file, material) == {element, element_type}
|
||||
@@ -536,22 +549,22 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
|
||||
assert subject.get_elements_by_material(self.file, usage) == {element}
|
||||
|
||||
def test_getting_elements_of_a_material_constituent_set(self):
|
||||
element = 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"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.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=[element], material=material_set)
|
||||
ifcopenshell.api.material.add_constituent(self.file, constituent_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
assert subject.get_elements_by_material(self.file, material) == {element}
|
||||
assert subject.get_elements_by_material(self.file, material_set) == {element}
|
||||
|
||||
def test_getting_elements_of_a_material_list(self):
|
||||
element = 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")
|
||||
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material_set)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.material.add_list_item(self.file, material_list=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
assert subject.get_elements_by_material(self.file, material) == {element}
|
||||
assert subject.get_elements_by_material(self.file, material_set) == {element}
|
||||
|
||||
@@ -601,8 +614,8 @@ class TestGetElementsByStyle(test.bootstrap.IFC4):
|
||||
|
||||
def test_getting_elements_of_a_styled_material(self):
|
||||
element = self.file.createIfcWall()
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
self.file.createIfcMaterialDefinitionRepresentation(
|
||||
RepresentedMaterial=material,
|
||||
@@ -645,85 +658,85 @@ class TestGetElementsByRepresentation(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetElementsByLayer(test.bootstrap.IFC4):
|
||||
def test_getting_the_elements_of_a_layer(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.layer.add_layer(self.file)
|
||||
representation = self.file.createIfcShapeRepresentation()
|
||||
element.Representation = self.file.createIfcProductDefinitionShape(Representations=[representation])
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=[representation], layer=layer)
|
||||
ifcopenshell.api.layer.assign_layer(self.file, items=[representation], layer=layer)
|
||||
assert list(subject.get_elements_by_layer(self.file, layer)) == [element]
|
||||
|
||||
|
||||
class TestGetlayersIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_getting_the_layer_of_a_product_item(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.layer.add_layer(self.file)
|
||||
item = self.file.createIfcExtrudedAreaSolid()
|
||||
representation = self.file.createIfcShapeRepresentation(Items=[item])
|
||||
element.Representation = self.file.createIfcProductDefinitionShape(Representations=[representation])
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=[item], layer=layer)
|
||||
ifcopenshell.api.layer.assign_layer(self.file, items=[item], layer=layer)
|
||||
assert subject.get_layers(self.file, element) == [layer]
|
||||
|
||||
def test_getting_the_layer_of_a_type_product_item(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
layer = ifcopenshell.api.layer.add_layer(self.file)
|
||||
item = self.file.createIfcExtrudedAreaSolid()
|
||||
representation = self.file.createIfcShapeRepresentation(Items=[item])
|
||||
element.RepresentationMaps = [self.file.createIfcRepresentationMap(MappedRepresentation=representation)]
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=[item], layer=layer)
|
||||
ifcopenshell.api.layer.assign_layer(self.file, items=[item], layer=layer)
|
||||
assert subject.get_layers(self.file, element) == [layer]
|
||||
|
||||
|
||||
class TestGetlayers(test.bootstrap.IFC4, TestGetlayersIFC2X3):
|
||||
def test_getting_the_layer_of_a_product_representation(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.layer.add_layer(self.file)
|
||||
representation = self.file.createIfcShapeRepresentation()
|
||||
element.Representation = self.file.createIfcProductDefinitionShape(Representations=[representation])
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=[representation], layer=layer)
|
||||
ifcopenshell.api.layer.assign_layer(self.file, items=[representation], layer=layer)
|
||||
assert subject.get_layers(self.file, element) == [layer]
|
||||
|
||||
def test_getting_the_layer_of_a_type_product_representation(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
layer = ifcopenshell.api.layer.add_layer(self.file)
|
||||
representation = self.file.createIfcShapeRepresentation()
|
||||
element.RepresentationMaps = [self.file.createIfcRepresentationMap(MappedRepresentation=representation)]
|
||||
ifcopenshell.api.run("layer.assign_layer", self.file, items=[representation], layer=layer)
|
||||
ifcopenshell.api.layer.assign_layer(self.file, items=[representation], layer=layer)
|
||||
assert subject.get_layers(self.file, element) == [layer]
|
||||
|
||||
|
||||
class TestGetContainerIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_spatial_container_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=building)
|
||||
assert subject.get_container(element) == building
|
||||
|
||||
def test_getting_an_indirect_spatial_container_of_an_element(self):
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_container(subelement) == building
|
||||
|
||||
def test_getting_nothing_if_we_enforce_only_getting_direct_spatial_containers(self):
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_container(subelement, should_get_direct=True) is None
|
||||
|
||||
|
||||
class TestGetReferencedStructures(test.bootstrap.IFC4):
|
||||
def test_getting_references_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_referenced_structures(element) == []
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[element], relating_structure=building)
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.reference_structure(self.file, products=[element], relating_structure=building)
|
||||
assert subject.get_referenced_structures(element) == [building]
|
||||
building2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[element], relating_structure=building2)
|
||||
building2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.reference_structure(self.file, products=[element], relating_structure=building2)
|
||||
assert subject.get_referenced_structures(element) == [building, building2]
|
||||
|
||||
|
||||
@@ -733,13 +746,13 @@ class TestGetReferencedStructuresIFC2X3(test.bootstrap.IFC2X3, TestGetReferenced
|
||||
|
||||
class TestGetStructureReferencedElements(test.bootstrap.IFC4):
|
||||
def test_getting_references_of_an_element(self):
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
assert subject.get_structure_referenced_elements(building) == set()
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[element], relating_structure=building)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.spatial.reference_structure(self.file, products=[element], relating_structure=building)
|
||||
assert subject.get_structure_referenced_elements(building) == {element}
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[element2], relating_structure=building)
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.spatial.reference_structure(self.file, products=[element2], relating_structure=building)
|
||||
assert subject.get_structure_referenced_elements(building) == {element, element2}
|
||||
|
||||
|
||||
@@ -749,21 +762,21 @@ class TestGetStructureReferencedElementsIFC2X3(test.bootstrap.IFC2X3, TestGetStr
|
||||
|
||||
class TestGetDecompositionIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_decomposed_subelements_of_an_element(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")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBeam")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
|
||||
results = subject.get_decomposition(building)
|
||||
assert element in results
|
||||
assert subelement in results
|
||||
|
||||
def test_getting_openings_and_fills_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")
|
||||
subsubelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindow")
|
||||
ifcopenshell.api.run("void.add_opening", self.file, element=element, opening=subelement)
|
||||
ifcopenshell.api.run("void.add_filling", self.file, element=subsubelement, opening=subelement)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcOpeningElement")
|
||||
subsubelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWindow")
|
||||
ifcopenshell.api.void.add_opening(self.file, element=element, opening=subelement)
|
||||
ifcopenshell.api.void.add_filling(self.file, element=subsubelement, opening=subelement)
|
||||
results = subject.get_decomposition(element)
|
||||
assert subelement in results
|
||||
assert subsubelement in results
|
||||
@@ -771,13 +784,13 @@ class TestGetDecompositionIFC4(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetGroupsIFC4(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
group1 = ifcopenshell.api.run("group.add_group", self.file)
|
||||
group2 = ifcopenshell.api.run("group.add_group", self.file)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group1 = ifcopenshell.api.group.add_group(self.file)
|
||||
group2 = ifcopenshell.api.group.add_group(self.file)
|
||||
|
||||
# assign group for multiple elements
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group1)
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group2)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group1)
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group2)
|
||||
|
||||
assert set(subject.get_groups(element)) == set([group1, group2])
|
||||
|
||||
@@ -788,17 +801,17 @@ class TestGetGroupsIFC2X3(test.bootstrap.IFC2X3, TestGetGroupsIFC4):
|
||||
|
||||
class TestGetAggregateIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCovering")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcCovering")
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_aggregate(subelement) == element
|
||||
|
||||
|
||||
class TestGetNestIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_nest_parent_of_an_element(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcTask")
|
||||
ifcopenshell.api.run("nest.assign_object", self.file, related_objects=[subelement], relating_object=element)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcTask")
|
||||
subelement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcTask")
|
||||
ifcopenshell.api.nest.assign_object(self.file, related_objects=[subelement], relating_object=element)
|
||||
assert subject.get_nest(subelement) == element
|
||||
|
||||
|
||||
@@ -812,13 +825,12 @@ class TestGetReferencedElements(test.bootstrap.IFC4):
|
||||
# IfcExternallyDefinedSurfaceStyle
|
||||
# IfcExternallyDefinedTextFont
|
||||
def test_get_elements_referenced_by_classification_reference(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
elements = [ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")]
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
elements = [ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")]
|
||||
if self.file.schema != "IFC2X3":
|
||||
elements.append(self.file.create_entity("IfcCostValue"))
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
reference = ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
reference = ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=elements,
|
||||
identification="X",
|
||||
@@ -830,19 +842,19 @@ class TestGetReferencedElements(test.bootstrap.IFC4):
|
||||
def test_get_elements_referenced_by_library_reference(self):
|
||||
reference = self.file.createIfcLibraryReference()
|
||||
elements = [
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall"),
|
||||
]
|
||||
ifcopenshell.api.run("library.assign_reference", self.file, reference=reference, products=elements)
|
||||
ifcopenshell.api.library.assign_reference(self.file, reference=reference, products=elements)
|
||||
assert subject.get_referenced_elements(reference) == set(elements)
|
||||
|
||||
def test_get_elements_referenced_by_document_reference(self):
|
||||
reference = ifcopenshell.api.run("document.add_reference", self.file, information=None)
|
||||
reference = ifcopenshell.api.document.add_reference(self.file, information=None)
|
||||
elements = [
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall"),
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall"),
|
||||
]
|
||||
ifcopenshell.api.run("document.assign_document", self.file, document=reference, products=elements)
|
||||
ifcopenshell.api.document.assign_document(self.file, document=reference, products=elements)
|
||||
assert subject.get_referenced_elements(reference) == set(elements)
|
||||
|
||||
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
# 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.project
|
||||
import ifcopenshell.util.schema as subject
|
||||
|
||||
|
||||
class TestMigrator(test.bootstrap.IFC4):
|
||||
def test_migrate_element_using_attribute_mapping_ifc4_ifc4x3(self):
|
||||
ifc4_file = ifcopenshell.api.run("project.create_file")
|
||||
ifc4_file = ifcopenshell.api.project.create_file()
|
||||
original_element = ifc4_file.createIfcWorkTime(Start="2024-01-01", Finish="2024-01-01")
|
||||
ifc4x3_file = ifcopenshell.api.run("project.create_file", version="IFC4X3")
|
||||
ifc4x3_file = ifcopenshell.api.project.create_file(version="IFC4X3")
|
||||
|
||||
migrator = subject.Migrator()
|
||||
for element in ifc4_file:
|
||||
@@ -37,9 +36,9 @@ class TestMigrator(test.bootstrap.IFC4):
|
||||
assert original_element.Finish == new_element.FinishDate
|
||||
|
||||
def test_migrate_element_using_attribute_mapping_ifc4x3_ifc4(self):
|
||||
ifc4x3_file = ifcopenshell.api.run("project.create_file", version="IFC4X3")
|
||||
ifc4x3_file = ifcopenshell.api.project.create_file(version="IFC4X3")
|
||||
original_element = ifc4x3_file.createIfcWorkTime(StartDate="2024-01-01", FinishDate="2024-01-01")
|
||||
ifc4_file = ifcopenshell.api.run("project.create_file")
|
||||
ifc4_file = ifcopenshell.api.project.create_file()
|
||||
|
||||
migrator = subject.Migrator()
|
||||
for element in ifc4x3_file:
|
||||
@@ -50,9 +49,9 @@ class TestMigrator(test.bootstrap.IFC4):
|
||||
assert original_element.FinishDate == new_element.Finish
|
||||
|
||||
def test_migrate_element_using_attribute_mapping_ifc2x3_ifc4(self):
|
||||
ifc2x3_file = ifcopenshell.api.run("project.create_file", version="IFC2X3")
|
||||
ifc2x3_file = ifcopenshell.api.project.create_file(version="IFC2X3")
|
||||
original_element = ifc2x3_file.createIfcImageTexture(TextureType="SPECULAR")
|
||||
ifc4_file = ifcopenshell.api.run("project.create_file")
|
||||
ifc4_file = ifcopenshell.api.project.create_file()
|
||||
|
||||
migrator = subject.Migrator()
|
||||
for element in ifc2x3_file:
|
||||
@@ -62,9 +61,9 @@ class TestMigrator(test.bootstrap.IFC4):
|
||||
assert original_element.TextureType == new_element.Mode
|
||||
|
||||
def test_migrate_element_using_attribute_mapping_ifc4_ifc2x3(self):
|
||||
ifc4_file = ifcopenshell.api.run("project.create_file")
|
||||
ifc4_file = ifcopenshell.api.project.create_file()
|
||||
original_element = ifc4_file.createIfcImageTexture(Mode="SPECULAR")
|
||||
ifc2x3_file = ifcopenshell.api.run("project.create_file", version="IFC2X3")
|
||||
ifc2x3_file = ifcopenshell.api.project.create_file(version="IFC2X3")
|
||||
|
||||
migrator = subject.Migrator()
|
||||
for element in ifc4_file:
|
||||
|
||||
@@ -18,7 +18,16 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.spatial
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.api.classification
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.api.geometry
|
||||
import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.group
|
||||
import ifcopenshell.util.selector as subject
|
||||
import ifcopenshell.util.placement
|
||||
import ifcopenshell.util.pset
|
||||
@@ -64,28 +73,28 @@ class TestFormat:
|
||||
|
||||
class TestGetElementValue(test.bootstrap.IFC4):
|
||||
def test_selecting_an_elements_class_or_id_using_a_query(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_element_value(element, "class") == "IfcWall"
|
||||
assert subject.get_element_value(element, "id") == element.id()
|
||||
|
||||
def test_selecting_an_elements_value_using_a_query(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foobar"
|
||||
assert subject.get_element_value(element, "Name") == "Foobar"
|
||||
|
||||
def test_selecting_using_a_multiple_key_query(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
material2 = ifcopenshell.api.material.add_material(self.file, name="CON02")
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
||||
)
|
||||
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
layer.Name = "L1"
|
||||
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
layer.Name = "L2"
|
||||
ifcopenshell.api.run("material.edit_layer", self.file, layer=layer, attributes={"LayerThickness": 13})
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material_set)
|
||||
ifcopenshell.api.material.edit_layer(self.file, layer=layer, attributes={"LayerThickness": 13})
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
assert subject.get_element_value(element, "material.MaterialLayers.Name") == ["L1", "L2"]
|
||||
# Allow to use "item" to generically select an item in a material set
|
||||
assert subject.get_element_value(element, "material.item.Name") == ["L1", "L2"]
|
||||
@@ -97,45 +106,45 @@ class TestGetElementValue(test.bootstrap.IFC4):
|
||||
assert subject.get_element_value(element, "mat.i.Name") == ["L1", "L2"]
|
||||
|
||||
def test_selecting_a_query_that_fails_silently(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.get_element_value(element, "material.item.Name.0") is None
|
||||
|
||||
def test_selecting_a_list_item_that_fails_silently(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material2 = ifcopenshell.api.run("material.add_material", self.file, name="CON02")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
material2 = ifcopenshell.api.material.add_material(self.file, name="CON02")
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, name="FOO", set_type="IfcMaterialLayerSet"
|
||||
)
|
||||
layer = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
layer = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
layer.Name = "L1"
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material_set)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
assert subject.get_element_value(element, "material.item.Name.0") == "L1"
|
||||
assert subject.get_element_value(element, "material.item.Name.1") is None
|
||||
|
||||
def test_selecting_a_pset(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert subject.get_element_value(element, "Foobar.Foo") == "Bar"
|
||||
assert subject.get_element_value(element, "Foobar./F.*/") == "Bar"
|
||||
assert subject.get_element_value(element, "/Foo.*/./F.*/") == "Bar"
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Baz": 123})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Baz": 123})
|
||||
assert subject.get_element_value(element, "/Foo.*/./B.*/") == 123
|
||||
assert subject.get_element_value(element, "/Foo.*/./.*/") == ["Bar", 123]
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bay": 123.3})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Bay": 123.3})
|
||||
assert subject.get_element_value(element, "/Foo.*/./B.*/") == [123, 123.3]
|
||||
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"]})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Status": ["New"]})
|
||||
assert subject.get_element_value(element, "/Pset_.*Common/.Status") == ["New"]
|
||||
assert subject.get_element_value(element, "/Pset_.*Common/.Status.0") == "New"
|
||||
|
||||
|
||||
class TestFilterElements(test.bootstrap.IFC4):
|
||||
def test_selecting_by_globalid(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
guid1 = element.GlobalId
|
||||
guid2 = element2.GlobalId
|
||||
assert subject.filter_elements(self.file, f"{guid1}") == {element}
|
||||
@@ -144,18 +153,18 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, f"IfcElement, ! {guid2}") == {element}
|
||||
|
||||
def test_selecting_by_class(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foo"
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
assert subject.filter_elements(self.file, "IfcWall") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcElement, ! IfcWall") == {element2}
|
||||
|
||||
def test_selecting_by_attribute(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foo"
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2.Name = "Bar"
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
assert subject.filter_elements(self.file, "IfcWall, Name=Foo") == {element}
|
||||
element.Name = 'Foo\'s "quoted" name...'
|
||||
assert subject.filter_elements(self.file, 'IfcWall, Name="Foo\'s \\"quoted\\" name..."') == {element}
|
||||
@@ -165,15 +174,15 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
element.Description = "Foobar"
|
||||
assert subject.filter_elements(self.file, "IfcWall, Name=Foo, Description=Foobar") == {element}
|
||||
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "SOLIDWALL"
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert subject.filter_elements(self.file, "IfcWall, PredefinedType=SOLIDWALL") == {element}
|
||||
|
||||
def test_selecting_by_type(self):
|
||||
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)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == set()
|
||||
element_type.Name = "Foo"
|
||||
assert subject.filter_elements(self.file, "IfcWall, type=Foo") == {element}
|
||||
@@ -181,54 +190,53 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, "IfcWall, type=/Fo.*/") == {element}
|
||||
|
||||
def test_selecting_by_material(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.filter_elements(self.file, "IfcWall, material=NULL") == {element, element2}
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
assert subject.filter_elements(self.file, "IfcWall, material=CON01") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, material!=CON01") == {element2}
|
||||
|
||||
def test_selecting_by_property(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo=Bar") == {element}
|
||||
assert subject.filter_elements(self.file, 'IfcWall, Foobar."Foo"=Bar') == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar./Fo.*/=Bar") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar./Fo.*/!=Bar") == {element2}
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bar": False})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Bar": False})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Bar=FALSE") == {element}
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Baz": 123})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Baz": 123})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz=123") == {element}
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Bay": 123.3})
|
||||
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"]})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Bay": 123.3})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Status": ["New"]})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Pset_WallCommon.Status=New") == {element}
|
||||
|
||||
def test_selecting_by_property_with_comparisons(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Baz": 123})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foobar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Baz": 123})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz>100") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz<100") == set()
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz>=100") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Baz<=100") == set()
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo*=ar") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo!*=ar") == {element2}
|
||||
assert subject.filter_elements(self.file, "IfcWall, Foobar.Foo*=Foo") == set()
|
||||
|
||||
def test_selecting_by_classification(self):
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
assert subject.filter_elements(self.file, "IfcWall, classification=NULL") == {element, element2}
|
||||
result = ifcopenshell.api.run("classification.add_classification", self.file, classification="Name")
|
||||
ifcopenshell.api.run(
|
||||
"classification.add_reference",
|
||||
result = ifcopenshell.api.classification.add_classification(self.file, classification="Name")
|
||||
ifcopenshell.api.classification.add_reference(
|
||||
self.file,
|
||||
products=[element],
|
||||
identification="X",
|
||||
@@ -241,17 +249,17 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, "IfcWall, classification!=X") == {element2}
|
||||
|
||||
def test_selecting_by_location(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
space = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace", name="Space")
|
||||
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="G")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding", name="Building")
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[space], relating_object=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=project)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
space = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSpace", name="Space")
|
||||
storey = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuildingStorey", name="G")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding", name="Building")
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name="Project")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=space)
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element2], relating_structure=storey)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[space], relating_object=storey)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[storey], relating_object=building)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[building], relating_object=project)
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=NULL") == set()
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
|
||||
@@ -259,36 +267,36 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, "IfcWall, location!=Space") == {element2}
|
||||
|
||||
def test_selecting_by_group(self):
|
||||
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, name="Foo")
|
||||
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
group = ifcopenshell.api.group.add_group(self.file, name="Foo")
|
||||
ifcopenshell.api.group.assign_group(self.file, products=[element], group=group)
|
||||
assert subject.filter_elements(self.file, "IfcWall, group=Foo") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, group!=Foo") == {element2}
|
||||
|
||||
def test_selecting_by_parent(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall", name="Element1")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall", name="Element2")
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall", name="Element3")
|
||||
space = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSpace", name="Space")
|
||||
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey", name="G")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding", name="Building")
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[element3], relating_object=element2)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[space], relating_object=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=project)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall", name="Element1")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall", name="Element2")
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall", name="Element3")
|
||||
space = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSpace", name="Space")
|
||||
storey = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuildingStorey", name="G")
|
||||
building = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcBuilding", name="Building")
|
||||
project = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name="Project")
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element], relating_structure=space)
|
||||
ifcopenshell.api.spatial.assign_container(self.file, products=[element2], relating_structure=storey)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[element3], relating_object=element2)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[space], relating_object=storey)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[storey], relating_object=building)
|
||||
ifcopenshell.api.aggregate.assign_object(self.file, products=[building], relating_object=project)
|
||||
assert subject.filter_elements(self.file, "IfcWall, parent=Project") == {element, element2, element3}
|
||||
assert subject.filter_elements(self.file, "IfcWall, parent=Space") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, parent=G") == {element, element2, element3}
|
||||
assert subject.filter_elements(self.file, "IfcWall, parent=Element2") == {element3}
|
||||
|
||||
def test_selecting_multiple_filter_groups(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foo"
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
element2.Name = "Bar"
|
||||
assert subject.filter_elements(self.file, "IfcWall + IfcSlab") == {element, element2}
|
||||
assert subject.filter_elements(self.file, "IfcWall, IfcSlab, Name=Foo") == {element}
|
||||
@@ -296,9 +304,9 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, "IfcWall, Name=Foo + IfcSlab, Name=Bar") == {element, element2}
|
||||
|
||||
def test_using_elements_argument(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
slab = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
door = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcDoor")
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
slab = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
door = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcDoor")
|
||||
elements = {wall, slab}
|
||||
results = subject.filter_elements(self.file, "IfcWall", {wall, slab})
|
||||
assert results != elements
|
||||
@@ -307,7 +315,7 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
assert subject.filter_elements(self.file, "IfcWall, IfcSlab", elements) == {wall, slab}
|
||||
|
||||
def test_editing_in_place(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
original_set = {wall}
|
||||
new_set = subject.filter_elements(self.file, "IfcWall", original_set, edit_in_place=True)
|
||||
assert new_set == original_set == {wall}
|
||||
@@ -315,20 +323,20 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
|
||||
class TestSetElementValue(test.bootstrap.IFC4):
|
||||
def test_set_xyz_coordinates(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.unit.assign_unit(self.file)
|
||||
|
||||
items = list(zip("xyz", ("5", "10", "15")))
|
||||
matrix = np.eye(4)
|
||||
matrix[:, 3] = (5, 10, 15, 1)
|
||||
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, is_si=False)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element, is_si=False)
|
||||
for coord, value in items:
|
||||
subject.set_element_value(self.file, element, coord, value)
|
||||
assert np.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
|
||||
|
||||
element_without_placement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element_without_placement = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
for coord, value in items:
|
||||
subject.set_element_value(self.file, element_without_placement, coord, value)
|
||||
assert np.array_equal(
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.system
|
||||
import ifcopenshell.util.system as subject
|
||||
|
||||
|
||||
@@ -34,31 +36,29 @@ class TestIsAssignable(test.bootstrap.IFC4):
|
||||
|
||||
class TestGetSystemElements(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
system = ifcopenshell.api.run("system.add_system", self.file, ifc_class="IfcSystem")
|
||||
ifcopenshell.api.run("system.assign_system", self.file, products=[element], system=system)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcPump")
|
||||
system = ifcopenshell.api.system.add_system(self.file, ifc_class="IfcSystem")
|
||||
ifcopenshell.api.system.assign_system(self.file, products=[element], system=system)
|
||||
assert subject.get_system_elements(system) == [element]
|
||||
|
||||
|
||||
class TestGetElementSystems(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
system = ifcopenshell.api.run("system.add_system", self.file, ifc_class="IfcSystem")
|
||||
ifcopenshell.api.run("system.assign_system", self.file, products=[element], system=system)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcPump")
|
||||
system = ifcopenshell.api.system.add_system(self.file, ifc_class="IfcSystem")
|
||||
ifcopenshell.api.system.assign_system(self.file, products=[element], system=system)
|
||||
assert subject.get_element_systems(element) == [system]
|
||||
|
||||
def test_do_not_get_non_services_groups(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcPump")
|
||||
ifcopenshell.api.run(
|
||||
"system.assign_system",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcPump")
|
||||
ifcopenshell.api.system.assign_system(
|
||||
self.file,
|
||||
products=[element],
|
||||
system=self.file.createIfcGroup(),
|
||||
)
|
||||
for not_assignable_system_class in ("IfcZone", "IfcStructuralAnalysisModel"):
|
||||
with pytest.raises(TypeError):
|
||||
ifcopenshell.api.run(
|
||||
"system.assign_system",
|
||||
ifcopenshell.api.system.assign_system(
|
||||
self.file,
|
||||
products=[element],
|
||||
system=self.file.create_entity(not_assignable_system_class),
|
||||
@@ -69,8 +69,8 @@ class TestGetElementSystems(test.bootstrap.IFC4):
|
||||
class TestGetPorts(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
port = self.file.createIfcDistributionPort()
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.system.assign_port(self.file, element=element, port=port)
|
||||
assert subject.get_ports(element) == [port]
|
||||
|
||||
|
||||
@@ -80,30 +80,30 @@ class TestGetPortsIFC2X3(test.bootstrap.IFC2X3, TestGetPorts):
|
||||
|
||||
class TestGetConnectedPort(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
port1 = ifcopenshell.api.run("system.add_port", self.file)
|
||||
port2 = ifcopenshell.api.run("system.add_port", self.file)
|
||||
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2)
|
||||
port1 = ifcopenshell.api.system.add_port(self.file)
|
||||
port2 = ifcopenshell.api.system.add_port(self.file)
|
||||
ifcopenshell.api.system.connect_port(self.file, port1=port1, port2=port2)
|
||||
assert subject.get_connected_port(port1) == port2
|
||||
assert subject.get_connected_port(port2) == port1
|
||||
|
||||
|
||||
class TestGetConnectedToFrom(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
port1 = ifcopenshell.api.run("system.add_port", self.file)
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.run("system.assign_port", self.file, element=element1, port=port1)
|
||||
port1 = ifcopenshell.api.system.add_port(self.file)
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.system.assign_port(self.file, element=element1, port=port1)
|
||||
|
||||
port2 = ifcopenshell.api.run("system.add_port", self.file)
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2)
|
||||
port2 = ifcopenshell.api.system.add_port(self.file)
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcFlowSegment")
|
||||
ifcopenshell.api.system.assign_port(self.file, element=element2, port=port2)
|
||||
|
||||
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SOURCE")
|
||||
ifcopenshell.api.system.connect_port(self.file, port1=port1, port2=port2, direction="SOURCE")
|
||||
assert subject.get_connected_to(element1) == [element2]
|
||||
assert subject.get_connected_from(element1) == []
|
||||
assert subject.get_connected_to(element2) == []
|
||||
assert subject.get_connected_from(element2) == [element1]
|
||||
|
||||
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SINK")
|
||||
ifcopenshell.api.system.connect_port(self.file, port1=port1, port2=port2, direction="SINK")
|
||||
assert subject.get_connected_to(element1) == []
|
||||
assert subject.get_connected_from(element1) == [element2]
|
||||
assert subject.get_connected_to(element2) == [element1]
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.util.unit as subject
|
||||
from math import pi
|
||||
|
||||
@@ -34,15 +35,15 @@ class TestConvert(test.bootstrap.IFC4):
|
||||
|
||||
class TestCalculateUnitScale(test.bootstrap.IFC4):
|
||||
def test_prefix_and_conversion_based_units_are_considered(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
length = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="foot")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
length = ifcopenshell.api.unit.add_conversion_based_unit(self.file, name="foot")
|
||||
length.ConversionFactor.UnitComponent.Prefix = "MILLI"
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file, units=[length])
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[length])
|
||||
assert subject.calculate_unit_scale(self.file) == 0.3048 * 0.001
|
||||
|
||||
angle = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="degree")
|
||||
angle = ifcopenshell.api.unit.add_conversion_based_unit(self.file, name="degree")
|
||||
angle.ConversionFactor.UnitComponent.Prefix = "MILLI"
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file, units=[angle])
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[angle])
|
||||
assert subject.calculate_unit_scale(self.file, "PLANEANGLEUNIT") == pi / 180 * 0.001
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user