Add support for IDS attribute use/instructions

This commit is contained in:
Dion Moult
2022-05-11 10:12:36 +10:00
parent eb3e137a6e
commit 7e09ab0ced
2 changed files with 30 additions and 10 deletions
+12 -3
View File
@@ -530,15 +530,19 @@ class attribute(facet):
parameters = ["name", "value", "location"] parameters = ["name", "value", "location"]
@staticmethod @staticmethod
def create(name=None, value=None, location="any"): def create(name="Name", value=None, location="any", use=None, instructions=None):
"""Create an attribute facet that can be added to applicability or requirements of IDS specification. """Create an attribute facet that can be added to applicability or requirements of IDS specification.
:param name: Attribute name, such as "Description" :param name: Attribute name, such as "Description"
:type name: str :type name: str
:param value: Attribute value :param value: Attribute value, with type being strictly checked
:type value: str, optional :type value: str, optional
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any" :param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
:type location: str, optional :type location: str, optional
:param use: 'required'|'optional', defaults to "required"
:type use: str, optional
:param instructions: Instructions as a guide for model authors when reading the requirements
:type instructions: str, optional
:return: entity object :return: entity object
:rtype: entity :rtype: entity
""" """
@@ -547,6 +551,8 @@ class attribute(facet):
inst.name = name inst.name = name
inst.value = value inst.value = value
inst.location = location inst.location = location
inst.use = use
inst.instructions = instructions
return inst return inst
def asdict(self): def asdict(self):
@@ -560,6 +566,10 @@ class attribute(facet):
fac_dict["value"] = parameter_asdict(self.value) fac_dict["value"] = parameter_asdict(self.value)
if self.location: if self.location:
fac_dict["@location"] = self.location fac_dict["@location"] = self.location
if self.use:
fac_dict["@use"] = self.use
if self.instructions:
fac_dict["@instructions"] = self.instructions
return fac_dict return fac_dict
def __call__(self, inst, logger=None): def __call__(self, inst, logger=None):
@@ -608,7 +618,6 @@ class classification(facet):
:return: classification object :return: classification object
:rtype: classification :rtype: classification
""" """
inst = classification() inst = classification()
inst.location = location inst.location = location
inst.value = value inst.value = value
+18 -7
View File
@@ -232,7 +232,7 @@ class TestIdsAuthoring(unittest.TestCase):
def test_create_specification_with_all_possible_information(self): def test_create_specification_with_all_possible_information(self):
spec = ids.specification( spec = ids.specification(
name="name", name="name",
use="use", use="required",
ifcVersion="IFC4", ifcVersion="IFC4",
identifier="identifier", identifier="identifier",
description="description", description="description",
@@ -240,7 +240,7 @@ class TestIdsAuthoring(unittest.TestCase):
) )
assert spec.asdict() == { assert spec.asdict() == {
"@name": "name", "@name": "name",
"@use": "use", "@use": "required",
"@ifcVersion": "IFC4", "@ifcVersion": "IFC4",
"@identifier": "identifier", "@identifier": "identifier",
"@description": "description", "@description": "description",
@@ -297,6 +297,9 @@ class TestIdsAuthoring(unittest.TestCase):
facet = ids.entity.create(name="IfcWallType", predefinedType="WALDO") facet = ids.entity.create(name="IfcWallType", predefinedType="WALDO")
assert bool(facet(ifc.createIfcWallType(PredefinedType="USERDEFINED", ElementType="WALDO"))) is True assert bool(facet(ifc.createIfcWallType(PredefinedType="USERDEFINED", ElementType="WALDO"))) is True
facet = ids.entity.create(name="IfcWall", predefinedType="USERDEFINED")
assert bool(facet(ifc.createIfcWall(PredefinedType="USERDEFINED", ObjectType="WALDO"))) is False
restriction = ids.restriction.create(options=["IfcWall", "IfcSlab"], type="enumeration", base="string") restriction = ids.restriction.create(options=["IfcWall", "IfcSlab"], type="enumeration", base="string")
facet = ids.entity.create(name=restriction) facet = ids.entity.create(name=restriction)
assert bool(facet(ifc.createIfcWall())) is True assert bool(facet(ifc.createIfcWall())) is True
@@ -309,14 +312,22 @@ class TestIdsAuthoring(unittest.TestCase):
assert bool(facet(ifc.createIfcWallType())) is True assert bool(facet(ifc.createIfcWallType())) is True
def test_creating_an_attribute_facet(self): def test_creating_an_attribute_facet(self):
attribute = ids.attribute.create(name="Name", value="Value") attribute = ids.attribute.create(name="name")
assert attribute.name == "Name" assert attribute.asdict() == {"name": {"simpleValue": "name"}, "@location": "any"}
assert attribute.value == "Value" attribute = ids.attribute.create(name="name", value="value")
assert attribute.asdict() == { assert attribute.asdict() == {
"name": {"simpleValue": "Name"}, "name": {"simpleValue": "name"},
"value": {"simpleValue": "Value"}, "value": {"simpleValue": "value"},
"@location": "any", "@location": "any",
} }
attribute = ids.attribute.create(name="name", value="value", use="required", instructions="instructions")
assert attribute.asdict() == {
"name": {"simpleValue": "name"},
"value": {"simpleValue": "value"},
"@location": "any",
"@use": "required",
"@instructions": "instructions",
}
def test_filtering_using_an_attribute_facet(self): def test_filtering_using_an_attribute_facet(self):
ifc = ifcopenshell.file() ifc = ifcopenshell.file()