mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,48 +17,51 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.profile
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAddPset(test.bootstrap.IFC4):
|
||||
def test_adding_a_pset_to_an_object(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
assert pset.is_a("IfcPropertySet")
|
||||
assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
def test_adding_a_pset_to_a_type_object(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
assert pset.is_a("IfcPropertySet")
|
||||
assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
def test_adding_a_pset_to_a_material(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Pset_MaterialCommon")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="Pset_MaterialCommon")
|
||||
assert pset.is_a("IfcMaterialProperties")
|
||||
assert pset.Name == "Pset_MaterialCommon"
|
||||
assert pset.Material == material
|
||||
|
||||
def test_adding_a_pset_to_a_profile(self):
|
||||
profile = ifcopenshell.api.run("profile.add_parameterized_profile", self.file, ifc_class="IfcCircleProfileDef")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="Pset_ProfileMechanical")
|
||||
profile = ifcopenshell.api.profile.add_parameterized_profile(self.file, ifc_class="IfcCircleProfileDef")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=profile, name="Pset_ProfileMechanical")
|
||||
assert pset.is_a("IfcProfileProperties")
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert pset.Name == "Pset_ProfileMechanical"
|
||||
assert pset.ProfileDefinition == profile
|
||||
|
||||
def test_adding_a_pset_to_a_context(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Custom_Pset")
|
||||
assert pset.is_a("IfcPropertySet")
|
||||
assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
|
||||
class TestAddPsetIFC2X3(test.bootstrap.IFC2X3, TestAddPset):
|
||||
def test_adding_a_pset_to_a_project(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Custom_Pset")
|
||||
assert pset.is_a("IfcPropertySet")
|
||||
assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
@@ -17,33 +17,34 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAddQto(test.bootstrap.IFC4):
|
||||
def test_adding_a_qto_to_an_object(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
assert qto.is_a("IfcElementQuantity")
|
||||
assert "Qto_WallBaseQuantities" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
def test_adding_a_qto_to_a_type_object(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Custom_Qto")
|
||||
assert qto.is_a("IfcElementQuantity")
|
||||
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
def test_adding_a_qto_to_a_context(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Custom_Qto")
|
||||
assert qto.is_a("IfcElementQuantity")
|
||||
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
|
||||
class TestAddQtoIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_adding_a_qto_to_a_project(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Custom_Qto")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Custom_Qto")
|
||||
assert qto.is_a("IfcElementQuantity")
|
||||
assert "Custom_Qto" in ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
|
||||
import operator
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
class TestEditPset(test.bootstrap.IFC4):
|
||||
def test_editing_a_blank_buildingsmart_templated_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="Pset_WallCommon")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={"Reference": "reference", "Status": ["NEW"], "Combustible": True, "ThermalTransmittance": 42},
|
||||
@@ -51,16 +51,15 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[3].NominalValue.wrappedValue == 42
|
||||
|
||||
def test_editing_an_existing_buildingsmart_templated_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="Pset_WallCommon")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={"Reference": "foo", "Status": ["NEW"], "Combustible": True, "ThermalTransmittance": 42},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": []}, should_purge=False
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file, pset=pset, properties={"Reference": "bar", "Status": []}, should_purge=False
|
||||
)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
|
||||
@@ -72,15 +71,14 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[1].EnumerationValues is None
|
||||
|
||||
def test_editing_a_templated_pset_with_automatic_casting_of_primitive_data_types(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={"ThermalTransmittance": "42"},
|
||||
)
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": None})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Reference": "bar", "Status": None})
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
|
||||
assert pset.HasProperties[0].Name == "ThermalTransmittance"
|
||||
@@ -88,49 +86,48 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[0].NominalValue.wrappedValue == 42
|
||||
|
||||
def test_adding_a_property_if_it_is_none(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=False)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Reference": None}, should_purge=False)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 1
|
||||
|
||||
def test_not_adding_a_property_if_it_is_none_and_should_purge_is_true(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=True)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Reference": None}, should_purge=True)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 0
|
||||
|
||||
def test_removing_a_none_property_if_specified(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": "Foo"})
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=True)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Reference": "Foo"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Reference": None}, should_purge=True)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 0
|
||||
|
||||
def test_removing_a_none_enumeration_property_if_specified(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
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 pset.HasProperties[0].Name == "Status"
|
||||
assert pset.HasProperties[0].EnumerationValues[0].wrappedValue == "NEW"
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": []}, should_purge=True)
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Status": []}, should_purge=True)
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(pset.HasProperties) == 0
|
||||
|
||||
def test_editing_a_pset_name(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="foo")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, name="bar")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="foo")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, name="bar")
|
||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert pset.Name == "bar"
|
||||
|
||||
def test_adding_properties_without_a_template_with_autodetected_and_manual_data_types(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
@@ -164,18 +161,16 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[4].NominalValue.wrappedValue == 123.0
|
||||
|
||||
def test_editing_properties_with_autodetected_existing_types(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
"MyCustom": self.file.createIfcContextDependentMeasure(12),
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
@@ -188,12 +183,11 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[0].NominalValue.wrappedValue == 34
|
||||
|
||||
def test_editing_list_valued_properties(self):
|
||||
cable = ifcopenshell.api.run(
|
||||
"root.create_entity", self.file, ifc_class="IfcDistributionPort", predefined_type="CABLE"
|
||||
cable = ifcopenshell.api.root.create_entity(
|
||||
self.file, ifc_class="IfcDistributionPort", predefined_type="CABLE"
|
||||
)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=cable, name="Pset_DistributionPortTypeCable")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=cable, name="Pset_DistributionPortTypeCable")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
@@ -206,18 +200,16 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert list(map(operator.itemgetter(0), pset.HasProperties[0].ListValues)) == ["One", "Two", "Three"]
|
||||
|
||||
def test_editing_properties_with_an_explicit_type(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
"MyCustom": self.file.createIfcLabel("True"),
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
@@ -230,19 +222,17 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
assert pset.HasProperties[0].NominalValue.wrappedValue is True
|
||||
|
||||
def test_editing_properties_with_custom_units(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
custom_unit = self.file.createIfcSIUnit(UnitType="PRESSUREUNIT", Prefix="GIGA", Name="PASCAL")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
"MyCustom": self.file.createIfcModulusOfElasticityMeasure(20),
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={
|
||||
@@ -260,8 +250,8 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
|
||||
def test_editing_properties_of_non_rooted_elements(self):
|
||||
element = self.file.createIfcMaterial()
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"foo": "bar"})
|
||||
|
||||
assert element.HasProperties[0] == pset
|
||||
assert pset.Properties[0].Name == "foo"
|
||||
@@ -289,10 +279,9 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
],
|
||||
},
|
||||
)
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
pset_template=template,
|
||||
@@ -308,15 +297,15 @@ class TestEditPset(test.bootstrap.IFC4):
|
||||
def test_editing_a_shared_property(self):
|
||||
element1 = self.file.createIfcMaterial()
|
||||
element2 = self.file.createIfcMaterial()
|
||||
pset1 = ifcopenshell.api.run("pset.add_pset", self.file, product=element1, name="Foo_Bar")
|
||||
pset2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element2, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset1, properties={"foo": "bar"})
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset2, properties={"foo2": "bar2"})
|
||||
pset1 = ifcopenshell.api.pset.add_pset(self.file, product=element1, name="Foo_Bar")
|
||||
pset2 = ifcopenshell.api.pset.add_pset(self.file, product=element2, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset1, properties={"foo": "bar"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset2, properties={"foo2": "bar2"})
|
||||
element1.HasProperties[0].Properties = list(element1.HasProperties[0].Properties) + list(
|
||||
element2.HasProperties[0].Properties
|
||||
)
|
||||
assert ifcopenshell.util.element.get_pset(element1, "Foo_Bar", "foo2") == "bar2"
|
||||
assert ifcopenshell.util.element.get_pset(element2, "Foo_Bar", "foo2") == "bar2"
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset1, properties={"foo2": "bar3"})
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset1, properties={"foo2": "bar3"})
|
||||
assert ifcopenshell.util.element.get_pset(element1, "Foo_Bar", "foo2") == "bar3"
|
||||
assert ifcopenshell.util.element.get_pset(element2, "Foo_Bar", "foo2") == "bar2"
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
|
||||
|
||||
class TestEditQto(test.bootstrap.IFC4):
|
||||
def test_editing_a_blank_buildingsmart_templated_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="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={"Length": 1, "NetSideArea": 2, "NetVolume": 3},
|
||||
@@ -42,15 +42,14 @@ class TestEditQto(test.bootstrap.IFC4):
|
||||
assert pset.Quantities[2].VolumeValue == 3
|
||||
|
||||
def test_editing_an_existing_buildingsmart_templated_pset(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={"Length": 1, "NetSideArea": 2, "NetVolume": 3},
|
||||
)
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"Length": 42, "NetSideArea": None})
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"Length": 42, "NetSideArea": None})
|
||||
qto = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
|
||||
assert qto.Quantities[0].Name == "Length"
|
||||
@@ -62,24 +61,23 @@ class TestEditQto(test.bootstrap.IFC4):
|
||||
assert len(qto.Quantities) == 2
|
||||
|
||||
def test_not_adding_a_property_if_it_is_none(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"Length": None})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Qto_WallBaseQuantities")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"Length": None})
|
||||
qto = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert len(qto.Quantities) == 0
|
||||
|
||||
def test_editing_a_qto_name(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="foo")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, name="bar")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="foo")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, name="bar")
|
||||
qto = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||
assert qto.Name == "bar"
|
||||
|
||||
def test_adding_quantities_without_a_template_with_autodetected_and_manual_data_types(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="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={
|
||||
@@ -112,18 +110,16 @@ class TestEditQto(test.bootstrap.IFC4):
|
||||
assert qto.Quantities[5].WeightValue == 7
|
||||
|
||||
def test_editing_quantities_with_autodetected_existing_types(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="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={
|
||||
"MyLength": self.file.createIfcLengthMeasure(12),
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={
|
||||
@@ -135,18 +131,16 @@ class TestEditQto(test.bootstrap.IFC4):
|
||||
assert qto.Quantities[0].LengthValue == 34
|
||||
|
||||
def test_editing_properties_with_an_explicit_type(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="Foo_Bar")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={
|
||||
"MyLength": self.file.createIfcLengthMeasure(12),
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_qto",
|
||||
ifcopenshell.api.pset.edit_qto(
|
||||
self.file,
|
||||
qto=qto,
|
||||
properties={
|
||||
|
||||
@@ -17,94 +17,95 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestRemovePset(test.bootstrap.IFC4):
|
||||
def test_removing_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="Foo_Bar")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 1
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySet")) == 0
|
||||
|
||||
def test_removing_material_psets(self):
|
||||
element = self.file.createIfcMaterial()
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
assert len(element.HasProperties) == 1
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(element.HasProperties) == 0
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 0
|
||||
|
||||
def test_removing_profile_psets(self):
|
||||
element = self.file.createIfcProfileDef()
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
assert len(element.HasProperties) == 1
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(element.HasProperties) == 0
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 0
|
||||
|
||||
def test_only_unassigning_if_pset_is_used_by_other_elements(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="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="Foo_Bar")
|
||||
rel = self.file.by_type("IfcRelDefinesByProperties")[0]
|
||||
rel.RelatedObjects = [element, element2]
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 1
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert ifcopenshell.util.element.get_psets(element) == {}
|
||||
assert "Foo_Bar" in ifcopenshell.util.element.get_psets(element2)
|
||||
|
||||
def test_removing_a_pset_with_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="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySet")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySingleValue")) == 0
|
||||
|
||||
def test_removing_a_qto_with_quantities(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="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"Foo": 42})
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=qto)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.pset.add_qto(self.file, product=element, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_qto(self.file, qto=qto, properties={"Foo": 42})
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=qto)
|
||||
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
|
||||
assert len(self.file.by_type("IfcQuantitySet")) == 0
|
||||
assert len(self.file.by_type("IfcPhysicalSimpleQuantity")) == 0
|
||||
|
||||
def test_removing_a_pset_with_shared_properties(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="Foo_Bar")
|
||||
pset2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element2, name="Foo_Bar")
|
||||
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="Foo_Bar")
|
||||
pset2 = ifcopenshell.api.pset.add_pset(self.file, product=element2, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
pset2.HasProperties = pset.HasProperties
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert pset2.HasProperties
|
||||
|
||||
def test_removing_a_pset_with_enumeration(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
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"]})
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(self.file.by_type("IfcPropertyEnumeration")) == 0
|
||||
|
||||
def test_removing_a_pset_with_shared_enumeration(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
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"]})
|
||||
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element2, name="Pset_WallCommon")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset2, properties={"Status": ["NEW"]})
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
pset2 = ifcopenshell.api.pset.add_pset(self.file, product=element2, name="Pset_WallCommon")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset2, properties={"Status": ["NEW"]})
|
||||
|
||||
enumeration1 = pset.HasProperties[0].EnumerationReference
|
||||
enumeration2 = pset2.HasProperties[0].EnumerationReference
|
||||
pset2.HasProperties[0].EnumerationReference = enumeration1
|
||||
self.file.remove(enumeration2)
|
||||
|
||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||
ifcopenshell.api.pset.remove_pset(self.file, product=element, pset=pset)
|
||||
assert len(self.file.by_type("IfcPropertyEnumeration")) == 1
|
||||
|
||||
Reference in New Issue
Block a user