mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 05:00:53 +00:00
Reformat ids.py
This commit is contained in:
@@ -4,7 +4,9 @@ import ifcopenshell.util.element
|
|||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
|
|
||||||
|
|
||||||
class exception(Exception): pass
|
class exception(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def error(msg):
|
def error(msg):
|
||||||
raise exception(msg)
|
raise exception(msg)
|
||||||
@@ -77,10 +79,7 @@ class entity(facet):
|
|||||||
logger.debug("Testing %s == %s", inst.is_a(), self.name)
|
logger.debug("Testing %s == %s", inst.is_a(), self.name)
|
||||||
# @nb with inheritance
|
# @nb with inheritance
|
||||||
# return inst.is_a() == self.name
|
# return inst.is_a() == self.name
|
||||||
return facet_evaluation(
|
return facet_evaluation(inst.is_a(self.name), self.message % {"name": inst.is_a()})
|
||||||
inst.is_a(self.name),
|
|
||||||
self.message % {'name':inst.is_a()}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class classification(facet):
|
class classification(facet):
|
||||||
@@ -101,11 +100,10 @@ class classification(facet):
|
|||||||
return facet_evaluation(
|
return facet_evaluation(
|
||||||
(self.system, self.value) in refs,
|
(self.system, self.value) in refs,
|
||||||
# @todo
|
# @todo
|
||||||
''
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class property(facet):
|
class property(facet):
|
||||||
"""
|
"""
|
||||||
The IDS property facet implenented using `ifcopenshell.util.element`
|
The IDS property facet implenented using `ifcopenshell.util.element`
|
||||||
@@ -121,9 +119,9 @@ class property(facet):
|
|||||||
logger.debug("Testing %s == %s", val, self.value)
|
logger.debug("Testing %s == %s", val, self.value)
|
||||||
|
|
||||||
di = {
|
di = {
|
||||||
'property': self.property,
|
"property": self.property,
|
||||||
'propertyset': self.propertyset,
|
"propertyset": self.propertyset,
|
||||||
'value': val
|
"value": val,
|
||||||
}
|
}
|
||||||
|
|
||||||
if val is not None:
|
if val is not None:
|
||||||
@@ -134,10 +132,7 @@ class property(facet):
|
|||||||
else:
|
else:
|
||||||
msg = "no set '%(propertyset)s'" % di
|
msg = "no set '%(propertyset)s'" % di
|
||||||
|
|
||||||
return facet_evaluation(
|
return facet_evaluation(val == self.value, msg)
|
||||||
val == self.value,
|
|
||||||
msg
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class boolean_logic:
|
class boolean_logic:
|
||||||
@@ -151,10 +146,7 @@ class boolean_logic:
|
|||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
eval = [t(*args) for t in self.terms]
|
eval = [t(*args) for t in self.terms]
|
||||||
join = [" and ", " or "][self.fold == any]
|
join = [" and ", " or "][self.fold == any]
|
||||||
return facet_evaluation(
|
return facet_evaluation(self.fold(eval), join.join(map(str, eval)))
|
||||||
self.fold(eval),
|
|
||||||
join.join(map(str, eval))
|
|
||||||
)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return [" and ", " or "][self.fold == any].join(map(str, self.terms))
|
return [" and ", " or "][self.fold == any].join(map(str, self.terms))
|
||||||
@@ -205,9 +197,7 @@ class specification:
|
|||||||
phrases[0].tagName == "applicability" or error("expected <applicability>")
|
phrases[0].tagName == "applicability" or error("expected <applicability>")
|
||||||
phrases[1].tagName == "requirements" or error("expected <requirements>")
|
phrases[1].tagName == "requirements" or error("expected <requirements>")
|
||||||
|
|
||||||
self.applicabiliy, self.requirements = (
|
self.applicabiliy, self.requirements = (boolean_and(parse_rules(phrase)) for phrase in phrases)
|
||||||
boolean_and(parse_rules(phrase)) for phrase in phrases
|
|
||||||
)
|
|
||||||
|
|
||||||
def __call__(self, inst, logger):
|
def __call__(self, inst, logger):
|
||||||
if self.applicabiliy(inst, logger):
|
if self.applicabiliy(inst, logger):
|
||||||
@@ -232,9 +222,7 @@ class ids:
|
|||||||
ids.tagName == "ids" or error("expected <ids>")
|
ids.tagName == "ids" or error("expected <ids>")
|
||||||
|
|
||||||
self.specifications = [
|
self.specifications = [
|
||||||
specification(n)
|
specification(n) for n in ids.childNodes if n.nodeType == n.ELEMENT_NODE and n.tagName == "specification"
|
||||||
for n in ids.childNodes
|
|
||||||
if n.nodeType == n.ELEMENT_NODE and n.tagName == "specification"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate(self, ifc_file, logger):
|
def validate(self, ifc_file, logger):
|
||||||
@@ -249,7 +237,7 @@ if __name__ == "__main__":
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
|
||||||
logger = logging.getLogger("IDS")
|
logger = logging.getLogger("IDS")
|
||||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||||
|
|
||||||
ids_file = ids(sys.argv[1])
|
ids_file = ids(sys.argv[1])
|
||||||
ifc_file = ifcopenshell.open(sys.argv[2])
|
ifc_file = ifcopenshell.open(sys.argv[2])
|
||||||
|
|||||||
Reference in New Issue
Block a user