mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
black .
This commit is contained in:
@@ -107,6 +107,7 @@ else:
|
||||
def optional_logger_args(logger: ifcopenshell_wrapper.logger | None) -> tuple[logger] | tuple[()]:
|
||||
return (logger,) if logger is not None else ()
|
||||
|
||||
|
||||
# explicitly specify available imported symbols
|
||||
# (it's a requirement for a typed library)
|
||||
__all__ = [
|
||||
|
||||
@@ -87,9 +87,7 @@ def create(
|
||||
_create_geometric_representation(file, alignment)
|
||||
|
||||
referent_name = ifcopenshell.util.alignment.station_as_string(file, start_station)
|
||||
referent = ifcopenshell.api.alignment.add_stationing_referent(
|
||||
file, referent_name, alignment, 0.0, start_station
|
||||
)
|
||||
referent = ifcopenshell.api.alignment.add_stationing_referent(file, referent_name, alignment, 0.0, start_station)
|
||||
|
||||
for layout in alignment_layouts:
|
||||
_add_zero_length_segment(file, layout)
|
||||
|
||||
@@ -73,7 +73,10 @@ def distance_along_from_station(file: ifcopenshell.file, alignment: entity_insta
|
||||
return station - start_station
|
||||
|
||||
stations = [
|
||||
(_distance_along_of_referent(referent), ifcopenshell.util.element.get_pset(referent, name="Pset_Stationing", prop="Station"))
|
||||
(
|
||||
_distance_along_of_referent(referent),
|
||||
ifcopenshell.util.element.get_pset(referent, name="Pset_Stationing", prop="Station"),
|
||||
)
|
||||
for referent in referent_nest.RelatedObjects
|
||||
]
|
||||
stations.sort(key=lambda entry: entry[0])
|
||||
|
||||
@@ -161,7 +161,18 @@ keywords = list(filter(operator.attrgetter("is_keyword"), terminals))
|
||||
# terminals is identity-ordered (no __eq__/__hash__), so sort for determinism
|
||||
keywords.sort(key=lambda x: repr(x))
|
||||
negated_keywords = map(lambda s: "~%s" % s, keywords)
|
||||
no_action = {"letter", "digit", "digits", "real_literal", "integer_literal", "string_literal", "simple_string_literal", "letter", "not_quote", "not_paren_star_quote_special"}
|
||||
no_action = {
|
||||
"letter",
|
||||
"digit",
|
||||
"digits",
|
||||
"real_literal",
|
||||
"integer_literal",
|
||||
"string_literal",
|
||||
"simple_string_literal",
|
||||
"letter",
|
||||
"not_quote",
|
||||
"not_paren_star_quote_special",
|
||||
}
|
||||
|
||||
while True:
|
||||
emitted_in_loop = set()
|
||||
@@ -197,7 +208,9 @@ for id in sorted(to_emit):
|
||||
elif id in to_original_text:
|
||||
stmt = "(original_text_for%s).add_parse_action(token_map(str.lower))" % stmt
|
||||
if id not in no_action and not isinstance(expr.contents, Keyword):
|
||||
children = list(map(operator.attrgetter('contents'), reduce(lambda x, y: x | y, (find_bytype(e, Keyword) for e in [expr]))))
|
||||
children = list(
|
||||
map(operator.attrgetter("contents"), reduce(lambda x, y: x | y, (find_bytype(e, Keyword) for e in [expr])))
|
||||
)
|
||||
has_duplicates = len(children) > len(set(children))
|
||||
node_type = "ListNode" if ("ZeroOrMore" in stmt or has_duplicates) else "Node"
|
||||
action = ".set_parse_action(%s)" % (
|
||||
@@ -246,6 +259,4 @@ if __name__ == "__main__":
|
||||
mdl = importlib.import_module(output)
|
||||
mdl.Generator(m).emit()
|
||||
sys.stdout.write(m.schema.name)
|
||||
"""
|
||||
% ("\n ".join(statements))
|
||||
)
|
||||
""" % ("\n ".join(statements)))
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import sys, fileinput
|
||||
|
||||
if sys.platform == "win32" and not hasattr(sys.stdout, 'buffer'):
|
||||
if sys.platform == "win32" and not hasattr(sys.stdout, "buffer"):
|
||||
import os, msvcrt
|
||||
|
||||
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
||||
|
||||
files = sys.argv[1:]
|
||||
if files[0] == '-o':
|
||||
b = open(files[1], 'wb')
|
||||
if files[0] == "-o":
|
||||
b = open(files[1], "wb")
|
||||
files = files[2:]
|
||||
else:
|
||||
b = getattr(sys.stdout, 'buffer', sys.stdout)
|
||||
b = getattr(sys.stdout, "buffer", sys.stdout)
|
||||
|
||||
for line in fileinput.input(files=files, mode='rb'):
|
||||
for line in fileinput.input(files=files, mode="rb"):
|
||||
b.write(line)
|
||||
|
||||
@@ -27,7 +27,7 @@ def indent(n, s):
|
||||
else:
|
||||
strs = s
|
||||
splitted = itertools.chain.from_iterable(map(functools.partial(str.split, sep="\n"), map(str, strs)))
|
||||
return "\n".join(" "*n + l for l in splitted)
|
||||
return "\n".join(" " * n + l for l in splitted)
|
||||
|
||||
|
||||
class Base:
|
||||
|
||||
@@ -26,6 +26,7 @@ import documentation
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
class Header(codegen.Base):
|
||||
def __init__(self, mapping):
|
||||
declarations = []
|
||||
@@ -41,7 +42,12 @@ class Header(codegen.Base):
|
||||
% dict({"documentation": templates.multi_line_comment(documentation.description(kwargs["name"]))}, **kwargs)
|
||||
)
|
||||
|
||||
forward_names = list(mapping.schema.entities.keys()) + list(mapping.schema.simpletypes.keys()) + list(mapping.schema.selects.keys()) + list(mapping.schema.enumerations.keys())
|
||||
forward_names = (
|
||||
list(mapping.schema.entities.keys())
|
||||
+ list(mapping.schema.simpletypes.keys())
|
||||
+ list(mapping.schema.selects.keys())
|
||||
+ list(mapping.schema.enumerations.keys())
|
||||
)
|
||||
forward_definitions = "".join(["class %s; " % n for n in forward_names])
|
||||
|
||||
select_super_types = defaultdict(list)
|
||||
@@ -57,11 +63,14 @@ class Header(codegen.Base):
|
||||
yield x
|
||||
if mapping.schema.is_select(x):
|
||||
yield from visit_select(mapping.schema.selects[x])
|
||||
|
||||
write(templates.select,
|
||||
name=name,
|
||||
template_items="\n".join(templates.select_list_item % {'item_name': nm} for nm in visit_select(type)),
|
||||
cast_functions="\n".join(templates.select_cast_function % {'name': name, 'item_name': nm} for nm in visit_select(type)),
|
||||
|
||||
write(
|
||||
templates.select,
|
||||
name=name,
|
||||
template_items="\n".join(templates.select_list_item % {"item_name": nm} for nm in visit_select(type)),
|
||||
cast_functions="\n".join(
|
||||
templates.select_cast_function % {"name": name, "item_name": nm} for nm in visit_select(type)
|
||||
),
|
||||
)
|
||||
|
||||
def get_select_super_types(nm, bases=[]):
|
||||
@@ -115,10 +124,15 @@ class Header(codegen.Base):
|
||||
# with the v1 data model we're back to exactly one supertype, no more virtual inheritance to handle selects
|
||||
assert len(superclasses) == 1
|
||||
superclass_statement = superclasses[0]
|
||||
superclass_2 = superclass_statement.split('::')[-1]
|
||||
superclass_2 = superclass_statement.split("::")[-1]
|
||||
|
||||
write(
|
||||
templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement, superclass_2=superclass_2
|
||||
templates.simpletype,
|
||||
name=name,
|
||||
type=type_str,
|
||||
attr_type=attr_type,
|
||||
superclass=superclass_statement,
|
||||
superclass_2=superclass_2,
|
||||
)
|
||||
|
||||
class_definitions = []
|
||||
@@ -145,7 +159,7 @@ class Header(codegen.Base):
|
||||
if mapping.make_argument_type(attr) != "ifcopenshell::Argument_UNKNOWN":
|
||||
attr_lines.append("%s %s() const;" % (type_str, attr.name))
|
||||
attr_lines.append("void set%s(const %s& v);" % (attr.name, type_str))
|
||||
if type_str == 'std::optional< std::string >':
|
||||
if type_str == "std::optional< std::string >":
|
||||
# because a 2-step char[] -> std::string -> optional<string> is not allowed
|
||||
# attr_lines.append("void set%s(const %s& v);" % (attr.name, 'std::string'))
|
||||
pass
|
||||
@@ -182,7 +196,7 @@ class Header(codegen.Base):
|
||||
supertypes = list(map(case_normalize, supertypes))
|
||||
assert len(supertypes) == 1
|
||||
superclass = supertypes[0]
|
||||
superclass_2 = superclass.split('::')[-1]
|
||||
superclass_2 = superclass.split("::")[-1]
|
||||
|
||||
argument_count = mapping.argument_count(type)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class Implementation(codegen.Base):
|
||||
templates.enum_from_string_stmt % dict(context, **locals()) for value in enum.values
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
for name, enum in mapping.schema.selects.items():
|
||||
write(
|
||||
templates.select_function,
|
||||
@@ -107,21 +107,18 @@ class Implementation(codegen.Base):
|
||||
return templates.get_attr_stmt_nested_array
|
||||
elif arg["is_templated_list"] and not (simple or express):
|
||||
return templates.get_attr_stmt_array
|
||||
elif arg["argument_type_enum"] == 'ifcopenshell::Argument_ENTITY_INSTANCE':
|
||||
elif arg["argument_type_enum"] == "ifcopenshell::Argument_ENTITY_INSTANCE":
|
||||
return templates.get_attr_stmt_entity
|
||||
else:
|
||||
return templates.get_attr_stmt
|
||||
|
||||
null_check = ""
|
||||
if arg["is_optional"]:
|
||||
attr_check = (
|
||||
"if(get_attribute_value(%d).isNull()) { return %%s; }"
|
||||
% (arg["index"] - 1,)
|
||||
)
|
||||
attr_check = "if(get_attribute_value(%d).isNull()) { return %%s; }" % (arg["index"] - 1,)
|
||||
if "std::optional" in arg["full_type"]:
|
||||
null_check = attr_check % "std::nullopt"
|
||||
else:
|
||||
null_check = attr_check % (arg['full_type'] + "{}")
|
||||
null_check = attr_check % (arg["full_type"] + "{}")
|
||||
|
||||
tmpl = find_template(arg)
|
||||
write_attr(
|
||||
@@ -154,7 +151,7 @@ class Implementation(codegen.Base):
|
||||
return templates.set_attr_stmt_nested_array
|
||||
elif arg["is_templated_list"] and not (simple or express):
|
||||
return templates.set_attr_stmt_array
|
||||
elif arg["argument_type_enum"] == 'ifcopenshell::Argument_ENTITY_INSTANCE':
|
||||
elif arg["argument_type_enum"] == "ifcopenshell::Argument_ENTITY_INSTANCE":
|
||||
return templates.set_attr_instance
|
||||
else:
|
||||
return templates.set_attr_stmt
|
||||
@@ -175,7 +172,9 @@ class Implementation(codegen.Base):
|
||||
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||
"star_if_optional": "*" if "std::optional" in arg["full_type"] else "",
|
||||
"check_optional_set_begin": "if (v) {" if "std::optional" in arg["full_type"] else "",
|
||||
"check_optional_set_else": "} else {" if "std::optional" in arg["full_type"] else "if constexpr (false)",
|
||||
"check_optional_set_else": (
|
||||
"} else {" if "std::optional" in arg["full_type"] else "if constexpr (false)"
|
||||
),
|
||||
"check_optional_set_end": "}" if "std::optional" in arg["full_type"] else "",
|
||||
},
|
||||
)
|
||||
@@ -190,11 +189,15 @@ class Implementation(codegen.Base):
|
||||
tmpl = (
|
||||
templates.constructor_stmt_array
|
||||
if arg["is_templated_list"]
|
||||
else templates.constructor_stmt_enum
|
||||
if arg["is_enum"]
|
||||
else templates.constructor_stmt_instance
|
||||
if arg["full_type"].endswith('*')
|
||||
else templates.constructor_stmt
|
||||
else (
|
||||
templates.constructor_stmt_enum
|
||||
if arg["is_enum"]
|
||||
else (
|
||||
templates.constructor_stmt_instance
|
||||
if arg["full_type"].endswith("*")
|
||||
else templates.constructor_stmt
|
||||
)
|
||||
)
|
||||
)
|
||||
impl = tmpl % {
|
||||
"name": deref_name,
|
||||
@@ -236,11 +239,7 @@ class Implementation(codegen.Base):
|
||||
for i in type.inverse
|
||||
]
|
||||
|
||||
superclass = (
|
||||
"%s(e)" % type.supertypes[0]
|
||||
if len(type.supertypes) == 1
|
||||
else "express::Entity(e)"
|
||||
)
|
||||
superclass = "%s(e)" % type.supertypes[0] if len(type.supertypes) == 1 else "express::Entity(e)"
|
||||
|
||||
superclass_num_attrs = (
|
||||
"%s(const std::weak_ptr<instance_data>&(in_memory_attribute_storage(%%d)))" % type.supertypes[0]
|
||||
@@ -371,7 +370,17 @@ class Implementation(codegen.Base):
|
||||
# ("const std::weak_ptr<instance_data>& e",),
|
||||
# "",
|
||||
# ),
|
||||
("", "", initializer, "", ("%s v" % type_str,), ("set_attribute_value(0, %s(v));" % ("cast_vector<express::Base>" if mapping.is_templated_list(type) else ""))),
|
||||
(
|
||||
"",
|
||||
"",
|
||||
initializer,
|
||||
"",
|
||||
("%s v" % type_str,),
|
||||
(
|
||||
"set_attribute_value(0, %s(v));"
|
||||
% ("cast_vector<express::Base>" if mapping.is_templated_list(type) else "")
|
||||
),
|
||||
),
|
||||
# ("v", "", constructor, "", ("%s v" % type_str,), ""),
|
||||
("", "", templates.cast_function, type_str, (), simpletype_impl_cast),
|
||||
),
|
||||
|
||||
@@ -23,6 +23,7 @@ import operator
|
||||
import collections
|
||||
import bootstrap
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, s, loc, tokens, rule=None):
|
||||
self.rule = rule or (type(self).__name__)
|
||||
@@ -58,15 +59,15 @@ class ListNode:
|
||||
|
||||
rules_as_list = set()
|
||||
for t in self.tokens:
|
||||
r = getattr(t, 'rule', None)
|
||||
r = getattr(t, "rule", None)
|
||||
if r:
|
||||
rules_as_list.add(r)
|
||||
self.dict_tokens[r].append(t)
|
||||
|
||||
|
||||
for r, t in tokens.asDict().items():
|
||||
if r not in rules_as_list:
|
||||
self.dict_tokens[r].append(t)
|
||||
|
||||
|
||||
self.flat = sum([getattr(t, "flat", [t]) for t in self.tokens], [])
|
||||
|
||||
def __repr__(self):
|
||||
@@ -74,7 +75,7 @@ class ListNode:
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.tokens)
|
||||
|
||||
|
||||
# Somehow indexing messes up the pyparsing results, so instead of x[0] use list(x)[0]
|
||||
# def __getitem__(self, i):
|
||||
# return self.tokens[i]
|
||||
@@ -110,7 +111,7 @@ def format_clause(exp):
|
||||
return "".join(whitespace(term) for term in exp.flat)
|
||||
|
||||
|
||||
class TypeDeclaration(Node):
|
||||
class TypeDeclaration(Node):
|
||||
name = property(lambda self: self.type_id[0])
|
||||
utype = property(lambda self: self.underlying_type.any().any())
|
||||
type = property(lambda self: self.utype[0] if isinstance(self.utype, list) else self.utype)
|
||||
@@ -245,7 +246,8 @@ class NamedType(Node):
|
||||
def do_try(fn):
|
||||
try:
|
||||
return fn()
|
||||
except: pass
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def get_rule_id(x):
|
||||
@@ -255,8 +257,14 @@ def get_rule_id(x):
|
||||
if matches:
|
||||
return matches[0]
|
||||
|
||||
|
||||
rule_dependencies = {
|
||||
k: list(map(operator.attrgetter('contents'), bootstrap.reduce(lambda x, y: x | y, (bootstrap.find_bytype(e, bootstrap.Keyword) for e in [v])))) \
|
||||
k: list(
|
||||
map(
|
||||
operator.attrgetter("contents"),
|
||||
bootstrap.reduce(lambda x, y: x | y, (bootstrap.find_bytype(e, bootstrap.Keyword) for e in [v])),
|
||||
)
|
||||
)
|
||||
for k, v in bootstrap.express
|
||||
}
|
||||
|
||||
@@ -264,16 +272,17 @@ all_rules = [k for k, e in bootstrap.express]
|
||||
|
||||
rule_definitions = {k: v for k, v in bootstrap.express}
|
||||
|
||||
|
||||
def to_tree(x, key=None):
|
||||
|
||||
|
||||
def prune(di):
|
||||
# translate class names back to grammar rules if nested actions are encountered
|
||||
di = {get_rule_id(k) or k: v for k, v in di.items()}
|
||||
|
||||
|
||||
def replace_synonyms(x):
|
||||
for y in x:
|
||||
yield y
|
||||
if False: # y in di:
|
||||
if False: # y in di:
|
||||
# production element from grammar is found in parsed data,
|
||||
# return that.
|
||||
|
||||
@@ -292,19 +301,21 @@ def to_tree(x, key=None):
|
||||
yield S
|
||||
# Do this recursively
|
||||
yield from replace_synonyms([S])
|
||||
|
||||
|
||||
# is this a concatenation with zero or more synonyms? then also processs that
|
||||
# @todo catches:
|
||||
# - simple_expression = term { add_like_op term } .
|
||||
# but should probably also work on
|
||||
# - a = b { b }
|
||||
# in which case the second Concat would be eliminated
|
||||
elif isinstance(rule, bootstrap.Concat) and \
|
||||
len(rule.contents) == 2 and \
|
||||
is_synonym(rule.contents[0]) and \
|
||||
isinstance(rule.contents[1].contents, bootstrap.Repeated) and \
|
||||
isinstance(rule.contents[1].contents.contents[0], bootstrap.Concat) and \
|
||||
str(rule.contents[1].contents.contents[0].contents[1]) == str(rule.contents[0]):
|
||||
elif (
|
||||
isinstance(rule, bootstrap.Concat)
|
||||
and len(rule.contents) == 2
|
||||
and is_synonym(rule.contents[0])
|
||||
and isinstance(rule.contents[1].contents, bootstrap.Repeated)
|
||||
and isinstance(rule.contents[1].contents.contents[0], bootstrap.Concat)
|
||||
and str(rule.contents[1].contents.contents[0].contents[1]) == str(rule.contents[0])
|
||||
):
|
||||
S = is_synonym(rule.contents[0])
|
||||
yield S
|
||||
# Do this recursively
|
||||
@@ -315,13 +326,13 @@ def to_tree(x, key=None):
|
||||
if key == "aggregation_types":
|
||||
# hack hack hack apparently the parser can't distinguish these
|
||||
subrules += list(replace_synonyms(rule_dependencies["general_aggregation_types"]))
|
||||
|
||||
|
||||
if rule_dependencies[key] and not subrules:
|
||||
# sometimes an intermediate production rule is missing
|
||||
# from the pyparsing output, e.g from parameter to simple_expression
|
||||
# directly. Recover from this.
|
||||
subrules = sum(map(rule_dependencies.__getitem__, rule_dependencies[key]), [])
|
||||
|
||||
|
||||
if not isinstance(rule_definitions[key], bootstrap.Union):
|
||||
# Filter out terminals when not a union. E.g no
|
||||
# reason to retain TYPE, END_TYPE, but operators
|
||||
@@ -331,7 +342,7 @@ def to_tree(x, key=None):
|
||||
vs = list(di.values())
|
||||
|
||||
return {k: v for k, v in di.items() if k in subrules or (k == key and len(vs) == 1 and vs[0] not in all_rules)}
|
||||
|
||||
|
||||
def simplify(di):
|
||||
if isinstance(di, list):
|
||||
if set(map(type, di)) == {str} and set(map(len, di)) == {1}:
|
||||
@@ -343,11 +354,11 @@ def to_tree(x, key=None):
|
||||
return {k: simplify(v) for k, v in di.items()}
|
||||
else:
|
||||
return di
|
||||
|
||||
|
||||
if isinstance(x, ListNode):
|
||||
d = to_tree(x.dict_tokens, key=get_rule_id(x) or key)
|
||||
|
||||
if key == 'if_stmt':
|
||||
if key == "if_stmt":
|
||||
# The definition of if statement if (roughy):
|
||||
# 'if' expr 'then' stmt+ 'else' stmt+
|
||||
# this causes stmt to be joined under the same
|
||||
@@ -355,39 +366,41 @@ def to_tree(x, key=None):
|
||||
# `else_stmt` that collects the second group
|
||||
# of stmts.
|
||||
|
||||
statements = x.dict_tokens['stmt']
|
||||
|
||||
statements = x.dict_tokens["stmt"]
|
||||
|
||||
else_index = None
|
||||
if_nesting = 0
|
||||
for i, tk in enumerate(x.flat):
|
||||
if tk == 'if': if_nesting += 1
|
||||
if tk == 'end_if': if_nesting -= 1
|
||||
if tk == 'else' and if_nesting == 1:
|
||||
for i, tk in enumerate(x.flat):
|
||||
if tk == "if":
|
||||
if_nesting += 1
|
||||
if tk == "end_if":
|
||||
if_nesting -= 1
|
||||
if tk == "else" and if_nesting == 1:
|
||||
else_index = i
|
||||
|
||||
if else_index:
|
||||
indices = []
|
||||
for s in statements:
|
||||
for i in range(max(indices, default=0), len(x.flat)):
|
||||
if x.flat[i:i+len(s.flat)] == s.flat:
|
||||
if x.flat[i : i + len(s.flat)] == s.flat:
|
||||
indices.append(i)
|
||||
break
|
||||
|
||||
assert len(indices) == len(statements)
|
||||
before_else = [i < else_index for i in indices]
|
||||
|
||||
else_stmt = [st for b, st in zip(before_else, d['stmt']) if not b]
|
||||
d['stmt'] = [st for b, st in zip(before_else, d['stmt']) if b]
|
||||
else_stmt = [st for b, st in zip(before_else, d["stmt"]) if not b]
|
||||
d["stmt"] = [st for b, st in zip(before_else, d["stmt"]) if b]
|
||||
|
||||
if else_stmt:
|
||||
d['else_stmt'] = else_stmt
|
||||
|
||||
if key == 'formal_parameter':
|
||||
d["else_stmt"] = else_stmt
|
||||
|
||||
if key == "formal_parameter":
|
||||
# Not so pretty hack to fix the overwriting of simple_id-like
|
||||
# ast nodes. The full solution would probably to register parse
|
||||
# actions. And directly reassign.
|
||||
pid = d['parameter_id'][0][0]
|
||||
d['parameter_id'][0] = x.flat[:x.flat.index(pid)+1:2]
|
||||
pid = d["parameter_id"][0][0]
|
||||
d["parameter_id"][0] = x.flat[: x.flat.index(pid) + 1 : 2]
|
||||
|
||||
if key is None:
|
||||
return {get_rule_id(x): d}
|
||||
@@ -400,7 +413,10 @@ def to_tree(x, key=None):
|
||||
elif isinstance(x, dict):
|
||||
# d = {k: to_tree(v, key=k) for k, v in x.items()}
|
||||
# not fully understood, but when finding specific node Types and production rules, prioritize the former
|
||||
d = {get_rule_id(k) or k: to_tree(v, key=k) for k, v in sorted(x.items(), key=lambda p: get_rule_id(p[0]) is not None)}
|
||||
d = {
|
||||
get_rule_id(k) or k: to_tree(v, key=k)
|
||||
for k, v in sorted(x.items(), key=lambda p: get_rule_id(p[0]) is not None)
|
||||
}
|
||||
return simplify(prune(d))
|
||||
elif isinstance(x, list):
|
||||
return [to_tree(v, key=key) for v in x]
|
||||
@@ -459,7 +475,8 @@ class SuperTypeExpression(Node):
|
||||
else:
|
||||
constraint = self.supertype_rule[0]
|
||||
return [
|
||||
list(list(s)[0])[0].simple_id for s in list(list(list(constraint.subtype_constraint[0].supertype_expression[0])[0])[0].one_of[0])[2::2]
|
||||
list(list(s)[0])[0].simple_id
|
||||
for s in list(list(list(constraint.subtype_constraint[0].supertype_expression[0])[0])[0].one_of[0])[2::2]
|
||||
]
|
||||
|
||||
sub_types = property(get_sub_types)
|
||||
@@ -576,10 +593,11 @@ class ProcedureDeclaration(ListNode):
|
||||
@property
|
||||
def name(self):
|
||||
return self.flat[1]
|
||||
|
||||
|
||||
|
||||
|
||||
class FunctionDeclaration(ProcedureDeclaration):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class RuleDeclaration(ProcedureDeclaration):
|
||||
pass
|
||||
|
||||
@@ -695,6 +695,7 @@ codegen_rule("MOD", lambda context: "%")
|
||||
codegen_rule("TRUE", lambda context: "True")
|
||||
codegen_rule("FALSE", lambda context: "False")
|
||||
|
||||
|
||||
def _dotted_name(node: ast.AST):
|
||||
"""Return dotted name for Name/Attribute chains, else None."""
|
||||
if isinstance(node, ast.Name):
|
||||
@@ -704,6 +705,7 @@ def _dotted_name(node: ast.AST):
|
||||
return f"{base}.{node.attr}" if base else node.attr
|
||||
return None
|
||||
|
||||
|
||||
class AttributeGetattrTransformer(ast.NodeTransformer):
|
||||
def visit_Attribute(self, node):
|
||||
parents = []
|
||||
@@ -720,7 +722,7 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
||||
if isinstance(node.ctx, ast.Store):
|
||||
return node
|
||||
|
||||
if _dotted_name(node) in ('ifcopenshell.create_entity', 'str.lower'):
|
||||
if _dotted_name(node) in ("ifcopenshell.create_entity", "str.lower"):
|
||||
return node
|
||||
|
||||
if node.attr.startswith("__"):
|
||||
|
||||
@@ -87,14 +87,8 @@ class Schema:
|
||||
|
||||
sort = lambda d: OrderedCaseInsensitiveDict(sorted(d))
|
||||
|
||||
declarations = [
|
||||
d.any()[0]
|
||||
for d in schema_declarations
|
||||
if d.rule == "declaration"
|
||||
] + [
|
||||
d
|
||||
for d in schema_declarations
|
||||
if d.rule == "RuleDeclaration"
|
||||
declarations = [d.any()[0] for d in schema_declarations if d.rule == "declaration"] + [
|
||||
d for d in schema_declarations if d.rule == "RuleDeclaration"
|
||||
]
|
||||
|
||||
self.types = sort([(t.name, t) for t in declarations if isinstance(t, nodes.TypeDeclaration)])
|
||||
@@ -102,8 +96,12 @@ class Schema:
|
||||
self.rules = sort([(t.name, t) for t in declarations if isinstance(t, nodes.RuleDeclaration)])
|
||||
self.functions = sort([(t.name, t) for t in declarations if isinstance(t, nodes.FunctionDeclaration)])
|
||||
|
||||
self.keys = list(self.types.keys()) + list(self.entities.keys()) + list(self.rules.keys()) + list(self.functions.keys())
|
||||
self.all_declarations = {k: v for d in (self.types, self.entities, self.rules, self.functions) for k, v in d.items()}
|
||||
self.keys = (
|
||||
list(self.types.keys()) + list(self.entities.keys()) + list(self.rules.keys()) + list(self.functions.keys())
|
||||
)
|
||||
self.all_declarations = {
|
||||
k: v for d in (self.types, self.entities, self.rules, self.functions) for k, v in d.items()
|
||||
}
|
||||
|
||||
of_type = lambda *types: sort(
|
||||
[(a, b.type) for a, b in self.types.items() if any(isinstance(b.type, ty) for ty in types)]
|
||||
|
||||
@@ -110,9 +110,7 @@ class LateBoundSchemaInstantiator:
|
||||
self.declarations[str(name)].set_subtypes([self.declarations[str(v)] for v in tys])
|
||||
|
||||
def finalize(self, can_be_instantiated_set, override_schema_name=None):
|
||||
self.schema = w.schema_definition(
|
||||
override_schema_name or self.schema_name, list(self.declarations.values())
|
||||
)
|
||||
self.schema = w.schema_definition(override_schema_name or self.schema_name, list(self.declarations.values()))
|
||||
|
||||
def disown(self):
|
||||
for elem in self.cache + list(self.declarations.values()):
|
||||
@@ -123,6 +121,7 @@ class string_pool:
|
||||
def __init__(self, fn):
|
||||
self.di = {}
|
||||
self.fn = fn
|
||||
|
||||
def append(self, v):
|
||||
def _():
|
||||
if i := self.di.get(v):
|
||||
@@ -131,7 +130,9 @@ class string_pool:
|
||||
i = len(self.di)
|
||||
self.di[v] = i
|
||||
return i
|
||||
|
||||
return self.fn(_())
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.di.keys())
|
||||
|
||||
@@ -146,9 +147,9 @@ class EarlyBoundCodeWriter:
|
||||
"",
|
||||
'#include "../../ifcparse/schema.h"',
|
||||
'#include "../../ifcparse/schemas/%(schema_name_title)s.h"' % self.__dict__,
|
||||
'#include <string>',
|
||||
"#include <string>",
|
||||
"",
|
||||
'using namespace std::string_literals;',
|
||||
"using namespace std::string_literals;",
|
||||
"using namespace ifcopenshell;",
|
||||
"",
|
||||
]
|
||||
@@ -180,18 +181,18 @@ class EarlyBoundCodeWriter:
|
||||
|
||||
# self.statements.append("{factory_placeholder}")
|
||||
|
||||
# self.statements.append(
|
||||
# """
|
||||
# #if defined(__clang__)
|
||||
# __attribute__((optnone))
|
||||
# #elif defined(__GNUC__) || defined(__GNUG__)
|
||||
# #pragma GCC push_options
|
||||
# #pragma GCC optimize ("O0")
|
||||
# #elif defined(_MSC_VER)
|
||||
# #pragma optimize("", off)
|
||||
# #endif
|
||||
# """
|
||||
# )
|
||||
# self.statements.append(
|
||||
# """
|
||||
# #if defined(__clang__)
|
||||
# __attribute__((optnone))
|
||||
# #elif defined(__GNUC__) || defined(__GNUG__)
|
||||
# #pragma GCC push_options
|
||||
# #pragma GCC optimize ("O0")
|
||||
# #elif defined(_MSC_VER)
|
||||
# #pragma optimize("", off)
|
||||
# #endif
|
||||
# """
|
||||
# )
|
||||
self.statements.append("ifcopenshell::schema_definition* %s_populate_schema() {" % self.schema_name.upper())
|
||||
self.statements.append("{string_pool_placeholder}")
|
||||
|
||||
@@ -200,7 +201,7 @@ class EarlyBoundCodeWriter:
|
||||
index_in_schema = self.names.index(name)
|
||||
ref = self.strings.append(name)
|
||||
self.statements.append(
|
||||
' %(schema_name)s_types[%(index_in_schema)d] = new type_declaration(%(ref)s, %(index_in_schema)d, %(declared_type)s);'
|
||||
" %(schema_name)s_types[%(index_in_schema)d] = new type_declaration(%(ref)s, %(index_in_schema)d, %(declared_type)s);"
|
||||
% locals()
|
||||
)
|
||||
|
||||
@@ -210,7 +211,7 @@ class EarlyBoundCodeWriter:
|
||||
ref = self.strings.append(name)
|
||||
items = ",".join(self.strings.append(v) for v in enum.values)
|
||||
self.statements.append(
|
||||
' %(schema_name)s_types[%(index_in_schema)d] = new enumeration_type(%(ref)s, %(index_in_schema)d, {%(items)s});'
|
||||
" %(schema_name)s_types[%(index_in_schema)d] = new enumeration_type(%(ref)s, %(index_in_schema)d, {%(items)s});"
|
||||
% locals()
|
||||
)
|
||||
|
||||
@@ -218,10 +219,14 @@ class EarlyBoundCodeWriter:
|
||||
schema_name = self.schema_name.upper()
|
||||
index_in_schema = self.names.index(name)
|
||||
ref = self.strings.append(name)
|
||||
supertype = "0" if len(type.supertypes) == 0 else "%s_types[%d]" % (self.schema_name, self.names.index(type.supertypes[0]))
|
||||
supertype = (
|
||||
"0"
|
||||
if len(type.supertypes) == 0
|
||||
else "%s_types[%d]" % (self.schema_name, self.names.index(type.supertypes[0]))
|
||||
)
|
||||
is_abstract = "true" if type.abstract else "false"
|
||||
self.statements.append(
|
||||
' %(schema_name)s_types[%(index_in_schema)d] = new entity(%(ref)s, %(is_abstract)s, %(index_in_schema)d, (entity*) %(supertype)s);'
|
||||
" %(schema_name)s_types[%(index_in_schema)d] = new entity(%(ref)s, %(is_abstract)s, %(index_in_schema)d, (entity*) %(supertype)s);"
|
||||
% locals()
|
||||
)
|
||||
|
||||
@@ -233,73 +238,86 @@ class EarlyBoundCodeWriter:
|
||||
map(lambda v: "%s_types[%d]" % (self.schema_name, self.names.index(v)), sorted(map(str, type.values)))
|
||||
)
|
||||
self.statements.append(
|
||||
' %(schema_name)s_types[%(index_in_schema)d] = new select_type(%(ref)s, %(index_in_schema)d, {%(items)s});'
|
||||
" %(schema_name)s_types[%(index_in_schema)d] = new select_type(%(ref)s, %(index_in_schema)d, {%(items)s});"
|
||||
% locals()
|
||||
)
|
||||
|
||||
def entity_attributes(self, name, attribute_definitions, is_derived):
|
||||
schema_name = self.schema_name.upper()
|
||||
index_in_schema = self.names.index(name)
|
||||
|
||||
def _():
|
||||
index_in_schema = self.names.index(name)
|
||||
schema_name = self.schema_name
|
||||
for attr_name, decl_type, optional in attribute_definitions:
|
||||
attr_name_ref = self.strings.append(attr_name)
|
||||
optional_cpp = str(optional).lower()
|
||||
yield 'new attribute(%(attr_name_ref)s, %(decl_type)s, %(optional_cpp)s)' % locals()
|
||||
yield "new attribute(%(attr_name_ref)s, %(decl_type)s, %(optional_cpp)s)" % locals()
|
||||
|
||||
attributes = ",".join(_())
|
||||
derived = ",".join(map(lambda b: str(b).lower(), is_derived))
|
||||
self.statements.append(" ((entity*)%(schema_name)s_types[%(index_in_schema)d])->set_attributes({%(attributes)s}, {%(derived)s});" % locals())
|
||||
self.statements.append(
|
||||
" ((entity*)%(schema_name)s_types[%(index_in_schema)d])->set_attributes({%(attributes)s}, {%(derived)s});"
|
||||
% locals()
|
||||
)
|
||||
|
||||
def inverse_attributes(self, name, inv_attrs):
|
||||
schema_name = self.schema_name.upper()
|
||||
index_in_schema = self.names.index(name)
|
||||
|
||||
def _():
|
||||
schema_name = self.schema_name
|
||||
index_in_schema = self.names.index(name)
|
||||
for attr_name, aggr_type, bound1, bound2, entity_ref, attribute_entity, attribute_entity_index in inv_attrs:
|
||||
attr_name_ref = self.strings.append(attr_name)
|
||||
opposite_index_in_schema = self.names.index(entity_ref)
|
||||
opposite1 = '%(schema_name)s_types[%(opposite_index_in_schema)d]' % locals()
|
||||
opposite1 = "%(schema_name)s_types[%(opposite_index_in_schema)d]" % locals()
|
||||
opposite_index_in_schema = self.names.index(attribute_entity)
|
||||
opposite2 = '%(schema_name)s_types[%(opposite_index_in_schema)d]' % locals()
|
||||
yield 'new inverse_attribute(%(attr_name_ref)s, inverse_attribute::%(aggr_type)s_type, %(bound1)d, %(bound2)d, ((entity*) %(opposite1)s), ((entity*) %(opposite2)s)->attributes()[%(attribute_entity_index)d])' % locals()
|
||||
opposite2 = "%(schema_name)s_types[%(opposite_index_in_schema)d]" % locals()
|
||||
yield "new inverse_attribute(%(attr_name_ref)s, inverse_attribute::%(aggr_type)s_type, %(bound1)d, %(bound2)d, ((entity*) %(opposite1)s), ((entity*) %(opposite2)s)->attributes()[%(attribute_entity_index)d])" % locals()
|
||||
|
||||
attributes = ",".join(_())
|
||||
self.statements.append(" ((entity*) %(schema_name)s_types[%(index_in_schema)d])->set_inverse_attributes({%(attributes)s});" % locals())
|
||||
self.statements.append(
|
||||
" ((entity*) %(schema_name)s_types[%(index_in_schema)d])->set_inverse_attributes({%(attributes)s});"
|
||||
% locals()
|
||||
)
|
||||
|
||||
def entity_subtypes(self, name, tys):
|
||||
schema_name = self.schema_name.upper()
|
||||
index_in_schema = self.names.index(name)
|
||||
subtypes = ",".join(map(lambda t: ("((entity*) %%(schema_name)s_types[%d])" % self.names.index(t)), tys)) % locals()
|
||||
self.statements.append(" ((entity*) %(schema_name)s_types[%(index_in_schema)d])->set_subtypes({%(subtypes)s});" % locals())
|
||||
subtypes = (
|
||||
",".join(map(lambda t: ("((entity*) %%(schema_name)s_types[%d])" % self.names.index(t)), tys)) % locals()
|
||||
)
|
||||
self.statements.append(
|
||||
" ((entity*) %(schema_name)s_types[%(index_in_schema)d])->set_subtypes({%(subtypes)s});" % locals()
|
||||
)
|
||||
|
||||
def finalize(self, can_be_instantiated_set):
|
||||
schema_name = self.schema_name.upper()
|
||||
schema_name_title = self.schema_name.capitalize()
|
||||
|
||||
def _():
|
||||
schema_name = self.schema_name.upper()
|
||||
schema_name_title = self.schema_name.capitalize()
|
||||
for type_name in self.names:
|
||||
index_in_schema = self.names.index(type_name)
|
||||
yield "%(schema_name)s_types[%(index_in_schema)d]" % locals()
|
||||
|
||||
declarations = ",".join(_())
|
||||
schema_name_ref = self.strings.append(schema_name)
|
||||
self.statements.append(
|
||||
' return new schema_definition(%(schema_name_ref)s, {%(declarations)s});'
|
||||
% locals()
|
||||
)
|
||||
self.statements.append("}");
|
||||
self.statements.append(" return new schema_definition(%(schema_name_ref)s, {%(declarations)s});" % locals())
|
||||
self.statements.append("}")
|
||||
|
||||
# self.statements.append(
|
||||
# """
|
||||
# #if defined(__clang__)
|
||||
# #elif defined(__GNUC__) || defined(__GNUG__)
|
||||
# #pragma GCC pop_options
|
||||
# #elif defined(_MSC_VER)
|
||||
# #pragma optimize("", on)
|
||||
# #endif
|
||||
# """
|
||||
# )
|
||||
# self.statements.append(
|
||||
# """
|
||||
# #if defined(__clang__)
|
||||
# #elif defined(__GNUC__) || defined(__GNUG__)
|
||||
# #pragma GCC pop_options
|
||||
# #elif defined(_MSC_VER)
|
||||
# #pragma optimize("", on)
|
||||
# #endif
|
||||
# """
|
||||
# )
|
||||
|
||||
self.statements.extend(
|
||||
(
|
||||
@@ -353,12 +371,9 @@ class EarlyBoundCodeWriter:
|
||||
# )
|
||||
|
||||
""
|
||||
self.statements[self.statements.index("{string_pool_placeholder}")] = (
|
||||
"""
|
||||
self.statements[self.statements.index("{string_pool_placeholder}")] = """
|
||||
const std::string strings[] = {%s};
|
||||
"""
|
||||
% ",".join(map(lambda s: '"%s"s' % s, self.strings))
|
||||
)
|
||||
""" % ",".join(map(lambda s: '"%s"s' % s, self.strings))
|
||||
|
||||
def __str__(self):
|
||||
return "\n".join(self.statements)
|
||||
@@ -380,16 +395,19 @@ class SchemaClass(codegen.Base):
|
||||
def wrapper(*args, **kwargs):
|
||||
schema_name_upper = mapping.schema.name.upper()
|
||||
declared_type = fn(*args, **kwargs)
|
||||
if 'simple_type' in declared_type:
|
||||
if "simple_type" in declared_type:
|
||||
pass
|
||||
else:
|
||||
match = re.search(r'\((\w+?_[\w+]+?_\w+?)\)', declared_type)
|
||||
match = re.search(r"\((\w+?_[\w+]+?_\w+?)\)", declared_type)
|
||||
if match:
|
||||
old_decl = match.group(1)
|
||||
name = old_decl.lower().replace(schema_name.lower() + '_', '').replace('_type', '')
|
||||
name = old_decl.lower().replace(schema_name.lower() + "_", "").replace("_type", "")
|
||||
idx = [n.lower() for n in x.names].index(name)
|
||||
declared_type = declared_type.replace(old_decl, '%(schema_name_upper)s_types[%(idx)d]' % locals())
|
||||
declared_type = declared_type.replace(
|
||||
old_decl, "%(schema_name_upper)s_types[%(idx)d]" % locals()
|
||||
)
|
||||
return declared_type
|
||||
|
||||
return wrapper if code == EarlyBoundCodeWriter else fn
|
||||
|
||||
@transform_to_indexed
|
||||
|
||||
@@ -129,14 +129,16 @@ simpletype_impl_is_without_supertype = "return v == %(class_name)s_type;"
|
||||
simpletype_impl_type = "return *((ifcopenshell::type_declaration*)%(schema_name_upper)s_types[%(index_in_schema)d]);"
|
||||
simpletype_impl_class = "return *((ifcopenshell::type_declaration*)%(schema_name_upper)s_types[%(index_in_schema)d]);"
|
||||
simpletype_impl_explicit_constructor = "data_ = e;"
|
||||
simpletype_impl_constructor = (
|
||||
"data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, v);"
|
||||
)
|
||||
simpletype_impl_constructor = "data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, v);"
|
||||
simpletype_impl_constructor_templated = "data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, cast_vector<express::Base>(v));"
|
||||
simpletype_impl_cast = "return get_attribute_value(0);"
|
||||
simpletype_impl_cast_templated = "std::vector<express::Base> es = get_attribute_value(0); return cast_vector<%(underlying_type)s>(es);"
|
||||
simpletype_impl_cast_templated = (
|
||||
"std::vector<express::Base> es = get_attribute_value(0); return cast_vector<%(underlying_type)s>(es);"
|
||||
)
|
||||
|
||||
simpletype_impl_declaration = "return *((ifcopenshell::type_declaration*)%(schema_name_upper)s_types[%(index_in_schema)d]);"
|
||||
simpletype_impl_declaration = (
|
||||
"return *((ifcopenshell::type_declaration*)%(schema_name_upper)s_types[%(index_in_schema)d]);"
|
||||
)
|
||||
|
||||
select = """%(documentation)s
|
||||
class IFC_SCHEMA_API %(name)s : public express::Select {
|
||||
@@ -226,7 +228,7 @@ const ifcopenshell::entity& %(schema_name)s::%(name)s::Class() { return *((ifcop
|
||||
%(schema_name)s::%(name)s %(schema_name)s::%(name)s::initialize(%(constructor_arguments)s) { %(constructor_implementation)s; return *this; }
|
||||
"""
|
||||
|
||||
# data_ = e;
|
||||
# data_ = e;
|
||||
# data_ = new const std::weak_ptr<instance_data>&(%(schema_name_upper)s_types[%(index_in_schema)d]);
|
||||
|
||||
optional_attribute_description = "/// Whether the optional attribute %s is defined for this %s"
|
||||
@@ -234,9 +236,7 @@ optional_attribute_description = "/// Whether the optional attribute %s is defin
|
||||
function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) { %(body)s }"
|
||||
const_function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) const { %(body)s }"
|
||||
constructor = "%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) { %(body)s }"
|
||||
initialize_single_initlist = (
|
||||
"%(schema_name)s::%(class_name)s %(schema_name)s::%(class_name)s::initialize(%(arguments)s) { %(body)s; return *this; }"
|
||||
)
|
||||
initialize_single_initlist = "%(schema_name)s::%(class_name)s %(schema_name)s::%(class_name)s::initialize(%(arguments)s) { %(body)s; return *this; }"
|
||||
cast_function = "%(schema_name)s::%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
||||
|
||||
array_type = "std::vector< %(instance_type)s > /*[%(lower)s:%(upper)s]*/"
|
||||
@@ -258,41 +258,25 @@ optional_attr_stmt = "return !get_attribute_value(%(index)d).isNull();"
|
||||
|
||||
get_attr_stmt = "%(null_check)s %(non_optional_type)s v = get_attribute_value(%(index)d); return v;"
|
||||
get_attr_stmt_enum = "%(null_check)s return %(non_optional_type)s::FromString(get_attribute_value(%(index)d));"
|
||||
get_attr_stmt_entity = "%(null_check)s return ((express::Base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();"
|
||||
get_attr_stmt_entity = (
|
||||
"%(null_check)s return ((express::Base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();"
|
||||
)
|
||||
get_attr_stmt_array = "%(null_check)s std::vector<express::Base> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
|
||||
get_attr_stmt_nested_array = "%(null_check)s std::vector<std::vector<express::Base>> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
|
||||
|
||||
get_inverse = "return cast_vector<%(type)s>(file()->get_inverse(data()->id(), %(schema_name_upper)s_types[%(type_index)d], %(index)d));"
|
||||
|
||||
set_attr_stmt = (
|
||||
"%(check_optional_set_begin)sset_attribute_value(%(index)d, %(star_if_optional)sv);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
)
|
||||
set_attr_instance = (
|
||||
"%(check_optional_set_begin)sset_attribute_value(%(index)d, v);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
)
|
||||
set_attr_stmt_enum = "%(check_optional_set_begin)sset_attribute_value(%(index)d, enumeration_reference(&%(non_optional_type)s::Class(), (size_t) %(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
set_attr_stmt_array = (
|
||||
"%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
)
|
||||
set_attr_stmt_nested_array = (
|
||||
"%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
)
|
||||
set_attr_stmt = "%(check_optional_set_begin)sset_attribute_value(%(index)d, %(star_if_optional)sv);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
set_attr_instance = "%(check_optional_set_begin)sset_attribute_value(%(index)d, v);%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
set_attr_stmt_enum = "%(check_optional_set_begin)sset_attribute_value(%(index)d, enumeration_reference(&%(non_optional_type)s::Class(), (size_t) %(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
set_attr_stmt_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
set_attr_stmt_nested_array = "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
|
||||
|
||||
constructor_stmt = (
|
||||
"set_attribute_value(%(index)d, (%(name)s));"
|
||||
)
|
||||
constructor_stmt_enum = (
|
||||
"set_attribute_value(%(index)d, (enumeration_reference(&%(type)s::Class(),(size_t)%(name)s)));"
|
||||
)
|
||||
constructor_stmt_array = (
|
||||
"set_attribute_value(%(index)d, cast_vector<express::Base>(%(name)s));"
|
||||
)
|
||||
constructor_stmt_derived = (
|
||||
""
|
||||
)
|
||||
constructor_stmt_instance = (
|
||||
"set_attribute_value(%(index)d, %(name)s);"
|
||||
)
|
||||
constructor_stmt = "set_attribute_value(%(index)d, (%(name)s));"
|
||||
constructor_stmt_enum = "set_attribute_value(%(index)d, (enumeration_reference(&%(type)s::Class(),(size_t)%(name)s)));"
|
||||
constructor_stmt_array = "set_attribute_value(%(index)d, cast_vector<express::Base>(%(name)s));"
|
||||
constructor_stmt_derived = ""
|
||||
constructor_stmt_instance = "set_attribute_value(%(index)d, %(name)s);"
|
||||
|
||||
constructor_stmt_optional = " if (%(name)s) {%(stmt)s }"
|
||||
|
||||
@@ -301,5 +285,3 @@ inverse_implementation = ' inverse_map[Type::%(type)s].insert(std::make_pair(
|
||||
|
||||
def multi_line_comment(li):
|
||||
return ("/// %s" % ("\n/// ".join(li))) if len(li) else ""
|
||||
|
||||
|
||||
|
||||
@@ -145,8 +145,7 @@ class configuration:
|
||||
config.set(
|
||||
"snippets",
|
||||
"print all wall ids",
|
||||
self.config_encode(
|
||||
"""
|
||||
self.config_encode("""
|
||||
###########################################################################
|
||||
# A simple script that iterates over all walls in the current model #
|
||||
# and prints their Globally unique IDs (GUIDS) to the console window #
|
||||
@@ -154,15 +153,13 @@ class configuration:
|
||||
|
||||
for wall in model.by_type("IfcWall"):
|
||||
print ("wall with global id: "+str(wall.GlobalId))
|
||||
""".lstrip()
|
||||
),
|
||||
""".lstrip()),
|
||||
)
|
||||
|
||||
config.set(
|
||||
"snippets",
|
||||
"print properties of current selection",
|
||||
self.config_encode(
|
||||
"""
|
||||
self.config_encode("""
|
||||
###########################################################################
|
||||
# A simple script that iterates over all IfcPropertySets of the currently #
|
||||
# selected object and prints them to the console #
|
||||
@@ -180,8 +177,7 @@ if selection:
|
||||
for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties:
|
||||
print ("{:<20} :{}".format(prop.Name,prop.NominalValue.wrappedValue))
|
||||
print ("\\n")
|
||||
""".lstrip()
|
||||
),
|
||||
""".lstrip()),
|
||||
)
|
||||
with open(conf_file, "w") as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
@@ -547,9 +547,20 @@ def create_shape(
|
||||
return wrap_shape_creation(
|
||||
settings,
|
||||
(
|
||||
ifcopenshell_wrapper.create_shape(settings, inst, repr, geometry_library, *ifcopenshell.optional_logger_args(logger),)
|
||||
ifcopenshell_wrapper.create_shape(
|
||||
settings,
|
||||
inst,
|
||||
repr,
|
||||
geometry_library,
|
||||
*ifcopenshell.optional_logger_args(logger),
|
||||
)
|
||||
if repr
|
||||
else ifcopenshell_wrapper.create_shape(settings, inst, geometry_library, *ifcopenshell.optional_logger_args(logger),)
|
||||
else ifcopenshell_wrapper.create_shape(
|
||||
settings,
|
||||
inst,
|
||||
geometry_library,
|
||||
*ifcopenshell.optional_logger_args(logger),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -330,7 +330,6 @@ class Iterator:
|
||||
def unit_magnitude(self): ...
|
||||
def unit_name(self): ...
|
||||
|
||||
|
||||
class OpaqueCoordinate_3:
|
||||
def __init__(self, *args): ...
|
||||
def get(self, i): ...
|
||||
@@ -755,13 +754,10 @@ class entity_instance(entity_instance_mixin):
|
||||
def declaration(self) -> declaration: ...
|
||||
@property
|
||||
def file(self) -> file: ...
|
||||
|
||||
def get_argument(self, *args: int | str) -> Any: ...
|
||||
def get_argument_index(self, a: str) -> int: ...
|
||||
def attribute_name(self, i: int) -> str: ...
|
||||
def attribute_type(
|
||||
self, *args: int | str
|
||||
) -> Literal[
|
||||
def attribute_type(self, *args: int | str) -> Literal[
|
||||
"NULL",
|
||||
"DERIVED",
|
||||
"INT",
|
||||
@@ -915,7 +911,6 @@ class file(file_mixin):
|
||||
def good(self): ...
|
||||
@property
|
||||
def header(self) -> spf_header: ...
|
||||
|
||||
def ifcroot_type(self) -> entity: ...
|
||||
def initialize(self, *args): ...
|
||||
def key_value_store_iter(self, prefix): ...
|
||||
@@ -1619,9 +1614,15 @@ def set_plugin_search_paths(paths: Sequence[str]) -> None: ...
|
||||
def clear_plugin_search_paths() -> None: ...
|
||||
def clear_schemas(): ...
|
||||
def construct_iterator(geometry_library, settings, file, num_threads, logger=None): ...
|
||||
def construct_iterator_with_include_exclude(geometry_library, settings, file, elems, include, num_threads, logger=None): ...
|
||||
def construct_iterator_with_include_exclude_globalid(geometry_library, settings, file, elems, include, num_threads, logger=None): ...
|
||||
def construct_iterator_with_include_exclude_id(geometry_library, settings, file, elems, include, num_threads, logger=None): ...
|
||||
def construct_iterator_with_include_exclude(
|
||||
geometry_library, settings, file, elems, include, num_threads, logger=None
|
||||
): ...
|
||||
def construct_iterator_with_include_exclude_globalid(
|
||||
geometry_library, settings, file, elems, include, num_threads, logger=None
|
||||
): ...
|
||||
def construct_iterator_with_include_exclude_id(
|
||||
geometry_library, settings, file, elems, include, num_threads, logger=None
|
||||
): ...
|
||||
def convert_loop_to_function_item(loop): ...
|
||||
def create_box(*args): ...
|
||||
def create_epeck(*args): ...
|
||||
|
||||
@@ -83,7 +83,7 @@ class sqlite(file):
|
||||
|
||||
if not Path(filepath).exists():
|
||||
raise FileNotFoundError(f"File doesn't exist: {filepath}")
|
||||
|
||||
|
||||
# See ifcopenshell.file.file_mixin.post_init()
|
||||
# history, future and transaction are stored in a list so that they
|
||||
# can easily be shared among file instances that are the same C++
|
||||
|
||||
@@ -355,8 +355,7 @@ def get_cost_rate(
|
||||
|
||||
class CostValueUnserialiser:
|
||||
def parse(self, formula: str):
|
||||
l = lark.Lark(
|
||||
"""start: formula
|
||||
l = lark.Lark("""start: formula
|
||||
formula: operand (operator operand)*
|
||||
operand: value | category "(" formula ")"
|
||||
value: NUMBER?
|
||||
@@ -393,8 +392,7 @@ class CostValueUnserialiser:
|
||||
NEWLINE: (CR? LF)+
|
||||
|
||||
%ignore WS // Disregard spaces in text
|
||||
"""
|
||||
)
|
||||
""")
|
||||
start = l.parse(formula)
|
||||
return self.get_formula(start.children[0])
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ import ifcopenshell.util.shape_builder
|
||||
import ifcopenshell.util.system
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
filter_elements_grammar = lark.Lark(
|
||||
"""start: filter_group
|
||||
filter_elements_grammar = lark.Lark("""start: filter_group
|
||||
filter_group: facet_list ("+" facet_list)* "+"?
|
||||
facet_list: facet ("," facet)*
|
||||
|
||||
@@ -114,11 +113,9 @@ filter_elements_grammar = lark.Lark(
|
||||
|
||||
%ignore WS // Disregard spaces in text
|
||||
%ignore COMMENT // Allow /* ... */ block comments to toggle parts of a query
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
get_element_grammar = lark.Lark(
|
||||
"""start: keys
|
||||
get_element_grammar = lark.Lark("""start: keys
|
||||
|
||||
keys: key ("." key)*
|
||||
key: quoted_string | regex_string | unquoted_string
|
||||
@@ -133,11 +130,9 @@ get_element_grammar = lark.Lark(
|
||||
WS: /[ \\t\\f\\r\\n]/+
|
||||
|
||||
%ignore WS // Disregard spaces in text
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
format_grammar = lark.Lark(
|
||||
"""start: expression
|
||||
format_grammar = lark.Lark("""start: expression
|
||||
|
||||
?expression: add_sub
|
||||
?add_sub: mul_div
|
||||
@@ -196,8 +191,7 @@ format_grammar = lark.Lark(
|
||||
NEWLINE: (CR? LF)+
|
||||
|
||||
%ignore WS // Disregard spaces in text
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
|
||||
class FormatTransformer(lark.Transformer):
|
||||
|
||||
@@ -24,7 +24,6 @@ import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
from ifcopenshell.api.alignment._add_segment_to_layout import _add_segment_to_layout
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -24,7 +24,6 @@ import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -25,7 +25,6 @@ import ifcopenshell.api.unit
|
||||
import ifcopenshell.util
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import pytest
|
||||
import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -24,7 +24,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import pytest
|
||||
import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -29,6 +29,7 @@ try:
|
||||
except RuntimeError:
|
||||
IFC4X3_AVAILABLE = False
|
||||
|
||||
|
||||
def _BlossCurve_100_0_300_1000_1_Meter(file):
|
||||
design_parameters = file.createIfcAlignmentCantSegment(
|
||||
StartDistAlong=0.0,
|
||||
|
||||
@@ -33,6 +33,7 @@ try:
|
||||
except RuntimeError:
|
||||
IFC4X3_AVAILABLE = False
|
||||
|
||||
|
||||
def _BlossCurve_100_0_300_1000_1_Meter(file):
|
||||
design_parameters = file.createIfcAlignmentHorizontalSegment(
|
||||
StartPoint=file.createIfcCartesianPoint((0.0, 0.0)),
|
||||
|
||||
@@ -32,6 +32,7 @@ try:
|
||||
except RuntimeError:
|
||||
IFC4X3_AVAILABLE = False
|
||||
|
||||
|
||||
def _CircularArc_100_0_10_0_0_0_0_5_1_Meter(file):
|
||||
design_parameters = file.createIfcAlignmentVerticalSegment(
|
||||
StartDistAlong=0.0,
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ try:
|
||||
except RuntimeError:
|
||||
IFC4X3_AVAILABLE = False
|
||||
|
||||
|
||||
def _test1():
|
||||
file = ifcopenshell.file(schema="IFC4X3")
|
||||
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -23,7 +23,6 @@ import ifcopenshell.api.alignment
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.unit
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.cogo
|
||||
import ifcopenshell.api.context
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.cogo
|
||||
import ifcopenshell.api.context
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.cogo
|
||||
import ifcopenshell.api.context
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
@@ -20,6 +20,7 @@ import ifcopenshell
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
|
||||
|
||||
class TestGetInfo2(test.bootstrap.IFC4):
|
||||
def test_instance_attribute(self):
|
||||
brep = self.file.create_entity("IfcFacetedBrep")
|
||||
@@ -65,25 +66,27 @@ class TestGetInfo2(test.bootstrap.IFC4):
|
||||
"type": "IfcFacetedBrep",
|
||||
}
|
||||
|
||||
|
||||
def test_equality():
|
||||
f = ifcopenshell.file()
|
||||
g = ifcopenshell.file()
|
||||
f.createIfcCartesianPoint((0., 0.))
|
||||
g.createIfcCartesianPoint((0., 0.))
|
||||
f.createIfcCartesianPoint((0.0, 0.0))
|
||||
g.createIfcCartesianPoint((0.0, 0.0))
|
||||
assert f[1] == g[1]
|
||||
g[1].Coordinates = (1., 0.)
|
||||
g[1].Coordinates = (1.0, 0.0)
|
||||
assert f[1] != g[1]
|
||||
|
||||
|
||||
def test_setting_logical():
|
||||
f = ifcopenshell.file()
|
||||
inst = f.createIfcPresentationLayerWithStyle(LayerOn="UNKNOWN")
|
||||
assert inst.LayerOn == "UNKNOWN"
|
||||
assert '.U.' in str(inst)
|
||||
assert ".U." in str(inst)
|
||||
with pytest.raises(Exception):
|
||||
inst.LayerOn = "SOME_OTHER_STRING"
|
||||
inst.LayerOn = False
|
||||
assert inst.LayerOn is False
|
||||
assert '.F.' in str(inst)
|
||||
assert ".F." in str(inst)
|
||||
inst.LayerOn = True
|
||||
assert inst.LayerOn is True
|
||||
assert '.T.' in str(inst)
|
||||
assert ".T." in str(inst)
|
||||
|
||||
@@ -21,13 +21,13 @@ import pytest
|
||||
import ifcopenshell
|
||||
import test.bootstrap
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3")
|
||||
IFC4X3_AVAILABLE = True
|
||||
except RuntimeError:
|
||||
IFC4X3_AVAILABLE = False
|
||||
|
||||
|
||||
class TestTransaction(test.bootstrap.IFC4):
|
||||
def test_that_nothing_happens_without_a_transaction(self):
|
||||
wall = self.file.createIfcWall()
|
||||
@@ -296,9 +296,10 @@ class TestFile(test.bootstrap.IFC4):
|
||||
g.assign_header_from(f)
|
||||
assert g.header.file_name.name == "test"
|
||||
|
||||
|
||||
@pytest.mark.skipif(not IFC4X3_AVAILABLE, reason="IFC4X3 not available")
|
||||
def test_schema_identifier():
|
||||
f = ifcopenshell.file(schema='IFC4X3')
|
||||
assert f.schema_identifier == 'IFC4X3_ADD2'
|
||||
assert f.schema == 'IFC4X3'
|
||||
assert f.schema_version == (4,3,2,0)
|
||||
f = ifcopenshell.file(schema="IFC4X3")
|
||||
assert f.schema_identifier == "IFC4X3_ADD2"
|
||||
assert f.schema == "IFC4X3"
|
||||
assert f.schema_version == (4, 3, 2, 0)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def test_skip_over_non_entity_instance():
|
||||
data = """
|
||||
ISO-10303-21;
|
||||
|
||||
@@ -8,6 +8,7 @@ import tabulate
|
||||
import ifcopenshell.express.rule_executor
|
||||
import ifcopenshell.validate
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filename",
|
||||
[
|
||||
@@ -45,4 +46,4 @@ def test_file(filename):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main(["-sx", __file__, '--import-mode=importlib'])
|
||||
pytest.main(["-sx", __file__, "--import-mode=importlib"])
|
||||
|
||||
@@ -9,19 +9,20 @@ import ifcopenshell.util.shape
|
||||
from pathlib import Path
|
||||
|
||||
repo_root = Path(__file__).resolve().parent.parent.parent.parent
|
||||
test_files = repo_root / 'test' / 'input' / 'tests'
|
||||
test_files = repo_root / "test" / "input" / "tests"
|
||||
|
||||
settings = ifcopenshell.geom.settings()
|
||||
|
||||
testdata = list(csv.reader((test_files / 'data.csv').open(newline='')))[1:]
|
||||
testdata = list(csv.reader((test_files / "data.csv").open(newline="")))[1:]
|
||||
|
||||
print(testdata)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fn,area,volume", testdata)
|
||||
def test_conversion(fn, area, volume):
|
||||
f = ifcopenshell.open(test_files / fn)
|
||||
elem = next(inst for inst in f.by_type('IfcElement') if not inst.is_a('IfcOpeningElement'))
|
||||
for kernel in ('manifold', 'opencascade', 'cgal'):
|
||||
elem = next(inst for inst in f.by_type("IfcElement") if not inst.is_a("IfcOpeningElement"))
|
||||
for kernel in ("manifold", "opencascade", "cgal"):
|
||||
shp = ifcopenshell.geom.create_shape(settings, elem, geometry_library=kernel)
|
||||
if area:
|
||||
assert pytest.approx(float(area), rel=0.05) == ifcopenshell.util.shape.get_area(shp.geometry)
|
||||
|
||||
@@ -22,7 +22,6 @@ import ifcopenshell
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.util.alignment as sta
|
||||
|
||||
|
||||
try:
|
||||
ifcopenshell.file(schema="IFC4X3_ADD2")
|
||||
IFC4X3_AVAILABLE = True
|
||||
|
||||
Reference in New Issue
Block a user