mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +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):
|
||||
"""The IDS attribute facet"""
|
||||
|
||||
parameters = ["name", "value", "location"]
|
||||
parameters = ["name", "value", "location", "use", "instructions"]
|
||||
|
||||
@staticmethod
|
||||
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
|
||||
"""
|
||||
|
||||
parameters = ["system", "value", "location"]
|
||||
parameters = ["system", "value", "location", "uri", "use", "instructions"]
|
||||
message = "%(location)sclassification reference %(value)s from '%(system)s'"
|
||||
|
||||
@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.
|
||||
|
||||
: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
|
||||
"""
|
||||
inst = classification()
|
||||
inst.location = location
|
||||
inst.value = value
|
||||
inst.system = system
|
||||
inst.location = location
|
||||
inst.uri = uri
|
||||
inst.use = use
|
||||
inst.instructions = instructions
|
||||
return inst
|
||||
|
||||
def asdict(self):
|
||||
@@ -659,13 +662,18 @@ class classification(facet):
|
||||
:return: Xmlschema compliant dictionary.
|
||||
:rtype: dict
|
||||
"""
|
||||
fac_dict = {
|
||||
"value": parameter_asdict(self.value),
|
||||
"system": parameter_asdict(self.system),
|
||||
"@location": self.location,
|
||||
# "instructions": "SAMPLE_INSTRUCTIONS",
|
||||
}
|
||||
return fac_dict
|
||||
results = {"@location": self.location}
|
||||
if self.value:
|
||||
results["value"] = parameter_asdict(self.value)
|
||||
if self.system:
|
||||
results["system"] = parameter_asdict(self.system)
|
||||
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 classification facet.
|
||||
|
||||
@@ -320,7 +320,9 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
|
||||
# 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_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)
|
||||
facet = ids.entity.create(name="IfcWall", predefinedType="X")
|
||||
assert bool(facet(wall)) is True
|
||||
@@ -346,21 +348,22 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
assert bool(facet(wall)) is True
|
||||
assert bool(facet(wall2)) is True
|
||||
|
||||
|
||||
def test_creating_an_attribute_facet(self):
|
||||
attribute = ids.attribute.create(name="name")
|
||||
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() == {
|
||||
"name": {"simpleValue": "name"},
|
||||
"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() == {
|
||||
"name": {"simpleValue": "name"},
|
||||
"value": {"simpleValue": "value"},
|
||||
"@location": "any",
|
||||
"@location": "instance",
|
||||
"@use": "required",
|
||||
"@instructions": "instructions",
|
||||
}
|
||||
@@ -452,10 +455,30 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
assert bool(facet(wall)) is True
|
||||
|
||||
def test_creating_a_classification_facet(self):
|
||||
c = ids.classification.create(location="any", value="Test_Value", system="Test_System")
|
||||
self.assertEqual(c.location, "any")
|
||||
self.assertEqual(c.value, "Test_Value")
|
||||
self.assertEqual(c.system, "Test_System")
|
||||
facet = ids.classification.create()
|
||||
assert facet.asdict() == {"@location": "any"}
|
||||
facet = ids.classification.create(value="value", system="system", location="instance")
|
||||
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):
|
||||
p = ids.property.create(
|
||||
|
||||
Reference in New Issue
Block a user