mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-01 20:49:44 +00:00
Add support for IDS classification uri, use, and instructions
This commit is contained in:
@@ -535,7 +535,7 @@ class entity(facet):
|
|||||||
class attribute(facet):
|
class attribute(facet):
|
||||||
"""The IDS attribute facet"""
|
"""The IDS attribute facet"""
|
||||||
|
|
||||||
parameters = ["name", "value", "location"]
|
parameters = ["name", "value", "location", "use", "instructions"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(name="Name", value=None, location="any", use=None, instructions=None):
|
def create(name="Name", value=None, location="any", use=None, instructions=None):
|
||||||
@@ -631,11 +631,11 @@ class classification(facet):
|
|||||||
The IDS classification facet by traversing the HasAssociations inverse attribute
|
The IDS classification facet by traversing the HasAssociations inverse attribute
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parameters = ["system", "value", "location"]
|
parameters = ["system", "value", "location", "uri", "use", "instructions"]
|
||||||
message = "%(location)sclassification reference %(value)s from '%(system)s'"
|
message = "%(location)sclassification reference %(value)s from '%(system)s'"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(location="any", value=None, system=None):
|
def create(value=None, system=None, location="any", uri=None, use=None, instructions=None):
|
||||||
"""Create a classification facet that can be added to applicability or requirements of IDS specification.
|
"""Create a classification 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"
|
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
||||||
@@ -648,9 +648,12 @@ class classification(facet):
|
|||||||
:rtype: classification
|
:rtype: classification
|
||||||
"""
|
"""
|
||||||
inst = classification()
|
inst = classification()
|
||||||
inst.location = location
|
|
||||||
inst.value = value
|
inst.value = value
|
||||||
inst.system = system
|
inst.system = system
|
||||||
|
inst.location = location
|
||||||
|
inst.uri = uri
|
||||||
|
inst.use = use
|
||||||
|
inst.instructions = instructions
|
||||||
return inst
|
return inst
|
||||||
|
|
||||||
def asdict(self):
|
def asdict(self):
|
||||||
@@ -659,13 +662,18 @@ class classification(facet):
|
|||||||
:return: Xmlschema compliant dictionary.
|
:return: Xmlschema compliant dictionary.
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
fac_dict = {
|
results = {"@location": self.location}
|
||||||
"value": parameter_asdict(self.value),
|
if self.value:
|
||||||
"system": parameter_asdict(self.system),
|
results["value"] = parameter_asdict(self.value)
|
||||||
"@location": self.location,
|
if self.system:
|
||||||
# "instructions": "SAMPLE_INSTRUCTIONS",
|
results["system"] = parameter_asdict(self.system)
|
||||||
}
|
if self.uri:
|
||||||
return fac_dict
|
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):
|
def __call__(self, inst, logger):
|
||||||
"""Validate an ifc instance against that classification facet.
|
"""Validate an ifc instance against that classification facet.
|
||||||
|
|||||||
@@ -320,7 +320,9 @@ class TestIdsAuthoring(unittest.TestCase):
|
|||||||
|
|
||||||
# Predefined types should match overridden predefined types from the element type
|
# Predefined types should match overridden predefined types from the element type
|
||||||
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="X")
|
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="X")
|
||||||
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType", predefined_type="NOTDEFINED")
|
wall_type = ifcopenshell.api.run(
|
||||||
|
"root.create_entity", ifc, ifc_class="IfcWallType", predefined_type="NOTDEFINED"
|
||||||
|
)
|
||||||
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
|
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
|
||||||
facet = ids.entity.create(name="IfcWall", predefinedType="X")
|
facet = ids.entity.create(name="IfcWall", predefinedType="X")
|
||||||
assert bool(facet(wall)) is True
|
assert bool(facet(wall)) is True
|
||||||
@@ -346,21 +348,22 @@ class TestIdsAuthoring(unittest.TestCase):
|
|||||||
assert bool(facet(wall)) is True
|
assert bool(facet(wall)) is True
|
||||||
assert bool(facet(wall2)) is True
|
assert bool(facet(wall2)) is True
|
||||||
|
|
||||||
|
|
||||||
def test_creating_an_attribute_facet(self):
|
def test_creating_an_attribute_facet(self):
|
||||||
attribute = ids.attribute.create(name="name")
|
attribute = ids.attribute.create(name="name")
|
||||||
assert attribute.asdict() == {"name": {"simpleValue": "name"}, "@location": "any"}
|
assert attribute.asdict() == {"name": {"simpleValue": "name"}, "@location": "any"}
|
||||||
attribute = ids.attribute.create(name="name", value="value")
|
attribute = ids.attribute.create(name="name", value="value", location="instance")
|
||||||
assert attribute.asdict() == {
|
assert attribute.asdict() == {
|
||||||
"name": {"simpleValue": "name"},
|
"name": {"simpleValue": "name"},
|
||||||
"value": {"simpleValue": "value"},
|
"value": {"simpleValue": "value"},
|
||||||
"@location": "any",
|
"@location": "instance",
|
||||||
}
|
}
|
||||||
attribute = ids.attribute.create(name="name", value="value", use="required", instructions="instructions")
|
attribute = ids.attribute.create(
|
||||||
|
name="name", value="value", location="instance", use="required", instructions="instructions"
|
||||||
|
)
|
||||||
assert attribute.asdict() == {
|
assert attribute.asdict() == {
|
||||||
"name": {"simpleValue": "name"},
|
"name": {"simpleValue": "name"},
|
||||||
"value": {"simpleValue": "value"},
|
"value": {"simpleValue": "value"},
|
||||||
"@location": "any",
|
"@location": "instance",
|
||||||
"@use": "required",
|
"@use": "required",
|
||||||
"@instructions": "instructions",
|
"@instructions": "instructions",
|
||||||
}
|
}
|
||||||
@@ -452,10 +455,30 @@ class TestIdsAuthoring(unittest.TestCase):
|
|||||||
assert bool(facet(wall)) is True
|
assert bool(facet(wall)) is True
|
||||||
|
|
||||||
def test_creating_a_classification_facet(self):
|
def test_creating_a_classification_facet(self):
|
||||||
c = ids.classification.create(location="any", value="Test_Value", system="Test_System")
|
facet = ids.classification.create()
|
||||||
self.assertEqual(c.location, "any")
|
assert facet.asdict() == {"@location": "any"}
|
||||||
self.assertEqual(c.value, "Test_Value")
|
facet = ids.classification.create(value="value", system="system", location="instance")
|
||||||
self.assertEqual(c.system, "Test_System")
|
assert facet.asdict() == {
|
||||||
|
"value": {"simpleValue": "value"},
|
||||||
|
"system": {"simpleValue": "system"},
|
||||||
|
"@location": "instance",
|
||||||
|
}
|
||||||
|
facet = ids.classification.create(
|
||||||
|
value="value",
|
||||||
|
system="system",
|
||||||
|
location="instance",
|
||||||
|
uri="https://test.com",
|
||||||
|
use="required",
|
||||||
|
instructions="instructions",
|
||||||
|
)
|
||||||
|
assert facet.asdict() == {
|
||||||
|
"value": {"simpleValue": "value"},
|
||||||
|
"system": {"simpleValue": "system"},
|
||||||
|
"@location": "instance",
|
||||||
|
"@uri": "https://test.com",
|
||||||
|
"@use": "required",
|
||||||
|
"@instructions": "instructions",
|
||||||
|
}
|
||||||
|
|
||||||
def test_property_create(self):
|
def test_property_create(self):
|
||||||
p = ids.property.create(
|
p = ids.property.create(
|
||||||
|
|||||||
Reference in New Issue
Block a user