mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Add support for IDS attribute use/instructions
This commit is contained in:
@@ -530,15 +530,19 @@ class attribute(facet):
|
||||
parameters = ["name", "value", "location"]
|
||||
|
||||
@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.
|
||||
|
||||
:param name: Attribute name, such as "Description"
|
||||
:type name: str
|
||||
:param value: Attribute value
|
||||
:param value: Attribute value, with type being strictly checked
|
||||
:type value: str, optional
|
||||
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
||||
: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
|
||||
:rtype: entity
|
||||
"""
|
||||
@@ -547,6 +551,8 @@ class attribute(facet):
|
||||
inst.name = name
|
||||
inst.value = value
|
||||
inst.location = location
|
||||
inst.use = use
|
||||
inst.instructions = instructions
|
||||
return inst
|
||||
|
||||
def asdict(self):
|
||||
@@ -560,6 +566,10 @@ class attribute(facet):
|
||||
fac_dict["value"] = parameter_asdict(self.value)
|
||||
if 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
|
||||
|
||||
def __call__(self, inst, logger=None):
|
||||
@@ -608,7 +618,6 @@ class classification(facet):
|
||||
:return: classification object
|
||||
:rtype: classification
|
||||
"""
|
||||
|
||||
inst = classification()
|
||||
inst.location = location
|
||||
inst.value = value
|
||||
|
||||
@@ -232,7 +232,7 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
def test_create_specification_with_all_possible_information(self):
|
||||
spec = ids.specification(
|
||||
name="name",
|
||||
use="use",
|
||||
use="required",
|
||||
ifcVersion="IFC4",
|
||||
identifier="identifier",
|
||||
description="description",
|
||||
@@ -240,7 +240,7 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
)
|
||||
assert spec.asdict() == {
|
||||
"@name": "name",
|
||||
"@use": "use",
|
||||
"@use": "required",
|
||||
"@ifcVersion": "IFC4",
|
||||
"@identifier": "identifier",
|
||||
"@description": "description",
|
||||
@@ -297,6 +297,9 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
facet = ids.entity.create(name="IfcWallType", predefinedType="WALDO")
|
||||
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")
|
||||
facet = ids.entity.create(name=restriction)
|
||||
assert bool(facet(ifc.createIfcWall())) is True
|
||||
@@ -309,14 +312,22 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
assert bool(facet(ifc.createIfcWallType())) is True
|
||||
|
||||
def test_creating_an_attribute_facet(self):
|
||||
attribute = ids.attribute.create(name="Name", value="Value")
|
||||
assert attribute.name == "Name"
|
||||
assert attribute.value == "Value"
|
||||
attribute = ids.attribute.create(name="name")
|
||||
assert attribute.asdict() == {"name": {"simpleValue": "name"}, "@location": "any"}
|
||||
attribute = ids.attribute.create(name="name", value="value")
|
||||
assert attribute.asdict() == {
|
||||
"name": {"simpleValue": "Name"},
|
||||
"value": {"simpleValue": "Value"},
|
||||
"name": {"simpleValue": "name"},
|
||||
"value": {"simpleValue": "value"},
|
||||
"@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):
|
||||
ifc = ifcopenshell.file()
|
||||
|
||||
Reference in New Issue
Block a user