From 0cf2d7e05ef8287155d5d2cf11aec879d9aa575f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 11 May 2022 23:30:10 +1000 Subject: [PATCH] Implement IDS uri/use/instructions for material facet --- src/ifcopenshell-python/ifcopenshell/ids.py | 28 +++++++++++---------- src/ifcopenshell-python/test/test_ids.py | 22 ++++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/ids.py b/src/ifcopenshell-python/ifcopenshell/ids.py index a1171c2ba8..0c5f0ccfaf 100644 --- a/src/ifcopenshell-python/ifcopenshell/ids.py +++ b/src/ifcopenshell-python/ifcopenshell/ids.py @@ -979,7 +979,7 @@ class material(facet): message = "%(location)smaterial '%(value)s'" @staticmethod - def create(location="any", value=None): + def create(value=None, location="any", uri=None, use=None, instructions=None): """Create a material facet that can be added to applicability or requirements of IDS specification. :param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any" @@ -990,11 +990,11 @@ class material(facet): :rtype: material """ inst = material() - inst.location = location inst.value = value - # TODO '@use': 'optional' - # TODO '@href': 'https://identifier.buildingsmart.org/uri/something', - # TODO 'instructions': 'Please add the desired...', + inst.location = location + inst.uri = uri + inst.use = use + inst.instructions = instructions return inst def asdict(self): @@ -1003,14 +1003,16 @@ class material(facet): :return: Xmlschema compliant dictionary. :rtype: dict """ - fac_dict = { - "value": parameter_asdict(self.value), - "@location": self.location, - # TODO "instructions": "SAMPLE_INSTRUCTIONS", - # TODO '@href': 'http://identifier.buildingsmart.org/uri/buildingsmart/ifc-4.3/prop/FireRating', #https://identifier.buildingsmart.org/uri/something - # TODO '@use': 'optional' - } - return fac_dict + results = { "@location": self.location } + if self.value: + results["value"] = parameter_asdict(self.value) + if self.uri: + results["@uri"] = self.uri + if self.use: + results["@use"] = self.use + if self.instructions: + results["@instructions"] = self.instructions + return results def __call__(self, inst, logger): """Validate an ifc instance against that material facet. diff --git a/src/ifcopenshell-python/test/test_ids.py b/src/ifcopenshell-python/test/test_ids.py index bc52c5c32a..80f3b21f39 100644 --- a/src/ifcopenshell-python/test/test_ids.py +++ b/src/ifcopenshell-python/test/test_ids.py @@ -636,8 +636,12 @@ class TestIdsAuthoring(unittest.TestCase): ifc.createIfcProject() # Milli prefix used to check measurement conversions lengthunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", name="METRE", prefix="MILLI") - areaunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="AREAUNIT", name="SQUARE_METRE", prefix="MILLI") - volumeunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="VOLUMEUNIT", name="CUBIC_METRE", prefix="MILLI") + areaunit = ifcopenshell.api.run( + "unit.add_si_unit", ifc, unit_type="AREAUNIT", name="SQUARE_METRE", prefix="MILLI" + ) + volumeunit = ifcopenshell.api.run( + "unit.add_si_unit", ifc, unit_type="VOLUMEUNIT", name="CUBIC_METRE", prefix="MILLI" + ) timeunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="TIMEUNIT", name="SECOND") ifcopenshell.api.run("unit.assign_unit", ifc, units=[lengthunit, areaunit, volumeunit, timeunit]) @@ -797,9 +801,17 @@ class TestIdsAuthoring(unittest.TestCase): assert bool(facet(wall_type)) is False def test_material_create(self): - m = ids.material.create(location="any", value="Test_Value") - self.assertEqual(m.location, "any") - self.assertEqual(m.value, "Test_Value") + facet = ids.material.create() + assert facet.asdict() == {"@location": "any"} + facet = ids.material.create(value="value", location="instance", uri="https://test.com", use="required", instructions="instructions") + assert facet.asdict() == { + "value": {"simpleValue": "value"}, + "@location": "instance", + "@uri": "https://test.com", + "@use": "required", + "@instructions": "instructions", + } + """ Creating IDS with restrictions """