mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Attribute filtering in IDS now checks null-like values too.
This commit is contained in:
@@ -584,7 +584,7 @@ class attribute(facet):
|
||||
self.message = "foo"
|
||||
return facet_evaluation(value == self.value, f"an entity with {self.name} set to '{value}'")
|
||||
else:
|
||||
return facet_evaluation(value, f"an entity with {self.name}")
|
||||
return facet_evaluation(value is not None and value != "", f"an entity with {self.name}")
|
||||
|
||||
|
||||
class classification(facet):
|
||||
@@ -834,36 +834,32 @@ class property(facet):
|
||||
|
||||
# self.location = self.node["@location"]
|
||||
|
||||
# TODO add documentation that attributes should have "attribute" as propertySets
|
||||
if self.propertySet == "attribute":
|
||||
val = {k.lower(): v for k, v in inst.get_info().items()}.get(self.name, None)
|
||||
else:
|
||||
# TODO sometimes AttributeError: 'str' object has no attribute 'wrappedValue'
|
||||
try:
|
||||
instance_props = ifcopenshell.util.element.get_psets(inst)
|
||||
except AttributeError:
|
||||
instance_props = {}
|
||||
|
||||
if ifcopenshell.util.element.get_type(inst):
|
||||
# TODO sometimes AttributeError: 'str' object has no attribute 'wrappedValue'
|
||||
try:
|
||||
instance_props = ifcopenshell.util.element.get_psets(inst)
|
||||
type_props = ifcopenshell.util.element.get_psets(ifcopenshell.util.element.get_type(inst))
|
||||
except AttributeError:
|
||||
instance_props = {}
|
||||
|
||||
if ifcopenshell.util.element.get_type(inst):
|
||||
# TODO sometimes AttributeError: 'str' object has no attribute 'wrappedValue'
|
||||
try:
|
||||
type_props = ifcopenshell.util.element.get_psets(ifcopenshell.util.element.get_type(inst))
|
||||
except AttributeError:
|
||||
type_props = {}
|
||||
else:
|
||||
type_props = {}
|
||||
else:
|
||||
type_props = {}
|
||||
|
||||
if self.location == "instance":
|
||||
props = instance_props
|
||||
elif self.location == "type" and type_props:
|
||||
props = type_props
|
||||
elif self.location == "any" and (instance_props or type_props):
|
||||
props = {**instance_props, **type_props}
|
||||
else:
|
||||
props = {}
|
||||
if self.location == "instance":
|
||||
props = instance_props
|
||||
elif self.location == "type" and type_props:
|
||||
props = type_props
|
||||
elif self.location == "any" and (instance_props or type_props):
|
||||
props = {**instance_props, **type_props}
|
||||
else:
|
||||
props = {}
|
||||
|
||||
pset = props.get(self.propertySet)
|
||||
val = pset.get(self.name) if pset else None
|
||||
pset = props.get(self.propertySet)
|
||||
val = pset.get(self.name) if pset else None
|
||||
|
||||
self.location_msg = location[self.location]
|
||||
di = {"name": self.name, "propertySet": self.propertySet, "value": "'%s'" % val, "location": self.location_msg}
|
||||
|
||||
@@ -307,7 +307,7 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
assert bool(facet(ifc.createIfcWall())) is False
|
||||
assert bool(facet(ifc.createIfcWallType())) is True
|
||||
|
||||
def test_attribute_create(self):
|
||||
def test_creating_an_attribute_facet(self):
|
||||
attribute = ids.attribute.create(name="Name", value="Value")
|
||||
assert attribute.name == "Name"
|
||||
assert attribute.value == "Value"
|
||||
@@ -317,6 +317,34 @@ class TestIdsAuthoring(unittest.TestCase):
|
||||
"@location": "any",
|
||||
}
|
||||
|
||||
def test_filtering_using_an_attribute_facet(self):
|
||||
ifc = ifcopenshell.file()
|
||||
|
||||
facet = ids.attribute.create(name="Foobar")
|
||||
assert bool(facet(ifc.createIfcWall())) is False
|
||||
|
||||
facet = ids.attribute.create(name="Name")
|
||||
assert bool(facet(ifc.createIfcWall())) is False
|
||||
assert bool(facet(ifc.createIfcWall(Name=""))) is False
|
||||
assert bool(facet(ifc.createIfcWall(Name="Foobar"))) is True
|
||||
|
||||
facet = ids.attribute.create(name="Name", value="Foobar")
|
||||
assert bool(facet(ifc.createIfcWall(Name="Foobar"))) is True
|
||||
assert bool(facet(ifc.createIfcWall(Name="Foobaz"))) is False
|
||||
|
||||
facet = ids.attribute.create(name="Eastings")
|
||||
assert bool(facet(ifc.createIfcMapConversion(Eastings=0))) is True
|
||||
|
||||
facet = ids.attribute.create(name="Eastings", value=42)
|
||||
assert bool(facet(ifc.createIfcMapConversion(Eastings=0))) is False
|
||||
assert bool(facet(ifc.createIfcMapConversion(Eastings=42))) is True
|
||||
|
||||
restriction = ids.restriction.create(options=["Foo", "Bar"], type="enumeration", base="string")
|
||||
facet = ids.attribute.create(name="Name", value=restriction)
|
||||
assert bool(facet(ifc.createIfcWall(Name="Foo"))) is True
|
||||
assert bool(facet(ifc.createIfcWall(Name="Bar"))) is True
|
||||
assert bool(facet(ifc.createIfcWall(Name="Foobar"))) is False
|
||||
|
||||
def test_classification_create(self):
|
||||
c = ids.classification.create(location="any", value="Test_Value", system="Test_System")
|
||||
self.assertEqual(c.location, "any")
|
||||
|
||||
Reference in New Issue
Block a user