mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Apply black formatting to fix CI lint-formatting drift
20 files had fallen out of sync with the project's black version; running `black .` brings them back in line with no logic changes.
This commit is contained in:
@@ -981,7 +981,9 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
# Specifically for PLAN_VIEW and REFLECTED_PLAN_VIEW, any Plan context is also prioritised.
|
# Specifically for PLAN_VIEW and REFLECTED_PLAN_VIEW, any Plan context is also prioritised.
|
||||||
contexts = self.get_linework_contexts(ifc, target_view)
|
contexts = self.get_linework_contexts(ifc, target_view)
|
||||||
self.serialize_contexts_elements(ifc, tree, contexts, "body", drawing_elements, target_view, link_matrix)
|
self.serialize_contexts_elements(ifc, tree, contexts, "body", drawing_elements, target_view, link_matrix)
|
||||||
self.serialize_contexts_elements(ifc, tree, contexts, "annotation", drawing_elements, target_view, link_matrix)
|
self.serialize_contexts_elements(
|
||||||
|
ifc, tree, contexts, "annotation", drawing_elements, target_view, link_matrix
|
||||||
|
)
|
||||||
|
|
||||||
if tool.Ifc.get() == ifc and self.camera_element not in drawing_elements:
|
if tool.Ifc.get() == ifc and self.camera_element not in drawing_elements:
|
||||||
with profile("Camera element"):
|
with profile("Camera element"):
|
||||||
|
|||||||
@@ -302,23 +302,25 @@ def add_drawing(
|
|||||||
context=drawing.get_body_context(),
|
context=drawing.get_body_context(),
|
||||||
ifc_representation_class=None,
|
ifc_representation_class=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
drawings_parent_group = None
|
drawings_parent_group = None
|
||||||
for group in ifc.get().by_type("IfcGroup"):
|
for group in ifc.get().by_type("IfcGroup"):
|
||||||
if group.Name == "DRAWINGS" and group.ObjectType == "DRAWINGS":
|
if group.Name == "DRAWINGS" and group.ObjectType == "DRAWINGS":
|
||||||
drawings_parent_group = group
|
drawings_parent_group = group
|
||||||
break
|
break
|
||||||
|
|
||||||
if not drawings_parent_group:
|
if not drawings_parent_group:
|
||||||
drawings_parent_group = ifc.run("group.add_group")
|
drawings_parent_group = ifc.run("group.add_group")
|
||||||
ifc.run("group.edit_group", group=drawings_parent_group, attributes={"Name": "DRAWINGS", "ObjectType": "DRAWINGS"})
|
ifc.run(
|
||||||
|
"group.edit_group", group=drawings_parent_group, attributes={"Name": "DRAWINGS", "ObjectType": "DRAWINGS"}
|
||||||
|
)
|
||||||
|
|
||||||
group = ifc.run("group.add_group")
|
group = ifc.run("group.add_group")
|
||||||
ifc.run("group.edit_group", group=group, attributes={"Name": drawing_name, "ObjectType": "DRAWING"})
|
ifc.run("group.edit_group", group=group, attributes={"Name": drawing_name, "ObjectType": "DRAWING"})
|
||||||
ifc.run("group.assign_group", group=group, products=[element])
|
ifc.run("group.assign_group", group=group, products=[element])
|
||||||
|
|
||||||
ifc.run("group.assign_group", group=drawings_parent_group, products=[group])
|
ifc.run("group.assign_group", group=drawings_parent_group, products=[group])
|
||||||
|
|
||||||
collector.assign(camera)
|
collector.assign(camera)
|
||||||
pset = ifc.run("pset.add_pset", product=element, name="EPset_Drawing")
|
pset = ifc.run("pset.add_pset", product=element, name="EPset_Drawing")
|
||||||
if drawing.get_unit_system() == "METRIC":
|
if drawing.get_unit_system() == "METRIC":
|
||||||
@@ -355,7 +357,7 @@ def add_drawing(
|
|||||||
if document.Name == "DRAWINGS" and document.Scope == "DRAWINGS":
|
if document.Name == "DRAWINGS" and document.Scope == "DRAWINGS":
|
||||||
drawings_parent_document = document
|
drawings_parent_document = document
|
||||||
break
|
break
|
||||||
|
|
||||||
if not drawings_parent_document:
|
if not drawings_parent_document:
|
||||||
drawings_parent_document = ifc.run("document.add_information")
|
drawings_parent_document = ifc.run("document.add_information")
|
||||||
if ifc.get_schema() == "IFC2X3":
|
if ifc.get_schema() == "IFC2X3":
|
||||||
@@ -363,7 +365,7 @@ def add_drawing(
|
|||||||
else:
|
else:
|
||||||
attributes = {"Identification": "DRAWINGS", "Name": "DRAWINGS", "Scope": "DRAWINGS"}
|
attributes = {"Identification": "DRAWINGS", "Name": "DRAWINGS", "Scope": "DRAWINGS"}
|
||||||
ifc.run("document.edit_information", information=drawings_parent_document, attributes=attributes)
|
ifc.run("document.edit_information", information=drawings_parent_document, attributes=attributes)
|
||||||
|
|
||||||
information = ifc.run("document.add_information", parent=drawings_parent_document)
|
information = ifc.run("document.add_information", parent=drawings_parent_document)
|
||||||
uri = drawing.get_default_drawing_path(drawing_name)
|
uri = drawing.get_default_drawing_path(drawing_name)
|
||||||
reference = ifc.run("document.add_reference", information=information)
|
reference = ifc.run("document.add_reference", information=information)
|
||||||
@@ -392,17 +394,19 @@ def duplicate_drawing(
|
|||||||
drawing_tool.set_name(new_drawing, drawing_name)
|
drawing_tool.set_name(new_drawing, drawing_name)
|
||||||
group = drawing_tool.get_drawing_group(new_drawing)
|
group = drawing_tool.get_drawing_group(new_drawing)
|
||||||
ifc.run("group.unassign_group", group=group, products=[new_drawing])
|
ifc.run("group.unassign_group", group=group, products=[new_drawing])
|
||||||
|
|
||||||
drawings_parent_group = None
|
drawings_parent_group = None
|
||||||
for parent_group in ifc.get().by_type("IfcGroup"):
|
for parent_group in ifc.get().by_type("IfcGroup"):
|
||||||
if parent_group.Name == "DRAWINGS" and parent_group.ObjectType == "DRAWINGS":
|
if parent_group.Name == "DRAWINGS" and parent_group.ObjectType == "DRAWINGS":
|
||||||
drawings_parent_group = parent_group
|
drawings_parent_group = parent_group
|
||||||
break
|
break
|
||||||
|
|
||||||
if not drawings_parent_group:
|
if not drawings_parent_group:
|
||||||
drawings_parent_group = ifc.run("group.add_group")
|
drawings_parent_group = ifc.run("group.add_group")
|
||||||
ifc.run("group.edit_group", group=drawings_parent_group, attributes={"Name": "DRAWINGS", "ObjectType": "DRAWINGS"})
|
ifc.run(
|
||||||
|
"group.edit_group", group=drawings_parent_group, attributes={"Name": "DRAWINGS", "ObjectType": "DRAWINGS"}
|
||||||
|
)
|
||||||
|
|
||||||
new_group = ifc.run("group.add_group")
|
new_group = ifc.run("group.add_group")
|
||||||
ifc.run("group.edit_group", group=new_group, attributes={"Name": drawing_name, "ObjectType": "DRAWING"})
|
ifc.run("group.edit_group", group=new_group, attributes={"Name": drawing_name, "ObjectType": "DRAWING"})
|
||||||
ifc.run("group.assign_group", group=new_group, products=[new_drawing])
|
ifc.run("group.assign_group", group=new_group, products=[new_drawing])
|
||||||
@@ -427,7 +431,7 @@ def duplicate_drawing(
|
|||||||
if document.Name == "DRAWINGS" and document.Scope == "DRAWINGS":
|
if document.Name == "DRAWINGS" and document.Scope == "DRAWINGS":
|
||||||
drawings_parent_document = document
|
drawings_parent_document = document
|
||||||
break
|
break
|
||||||
|
|
||||||
if not drawings_parent_document:
|
if not drawings_parent_document:
|
||||||
drawings_parent_document = ifc.run("document.add_information")
|
drawings_parent_document = ifc.run("document.add_information")
|
||||||
if ifc.get_schema() == "IFC2X3":
|
if ifc.get_schema() == "IFC2X3":
|
||||||
|
|||||||
@@ -146,7 +146,9 @@ def test_fit_flow_segments_with_single_segment_dispatches_obstruction():
|
|||||||
mep.tool.Model, "get_flow_segment_profile", return_value=segment_profile
|
mep.tool.Model, "get_flow_segment_profile", return_value=segment_profile
|
||||||
), patch.object(mep.MEPAddObstruction, "_execute", return_value=None) as obstruction, patch.object(
|
), patch.object(mep.MEPAddObstruction, "_execute", return_value=None) as obstruction, patch.object(
|
||||||
mep.MEPAddBend, "_execute", return_value=None
|
mep.MEPAddBend, "_execute", return_value=None
|
||||||
) as bend, patch.object(mep.MEPAddTransition, "_execute", return_value=None) as transition:
|
) as bend, patch.object(
|
||||||
|
mep.MEPAddTransition, "_execute", return_value=None
|
||||||
|
) as transition:
|
||||||
mep.FitFlowSegments._execute(op, context=context)
|
mep.FitFlowSegments._execute(op, context=context)
|
||||||
|
|
||||||
assert obstruction.call_count == 1
|
assert obstruction.call_count == 1
|
||||||
@@ -178,7 +180,9 @@ def test_fit_flow_segments_refuses_mixed_pipe_and_duct():
|
|||||||
mep.tool.Model, "get_flow_segment_profile", return_value=profile
|
mep.tool.Model, "get_flow_segment_profile", return_value=profile
|
||||||
), patch.object(mep.MEPAddObstruction, "_execute", return_value=None) as obstruction, patch.object(
|
), patch.object(mep.MEPAddObstruction, "_execute", return_value=None) as obstruction, patch.object(
|
||||||
mep.MEPAddBend, "_execute", return_value=None
|
mep.MEPAddBend, "_execute", return_value=None
|
||||||
) as bend, patch.object(mep.MEPAddTransition, "_execute", return_value=None) as transition:
|
) as bend, patch.object(
|
||||||
|
mep.MEPAddTransition, "_execute", return_value=None
|
||||||
|
) as transition:
|
||||||
mep.FitFlowSegments._execute(op, context=context)
|
mep.FitFlowSegments._execute(op, context=context)
|
||||||
|
|
||||||
obstruction.assert_not_called()
|
obstruction.assert_not_called()
|
||||||
|
|||||||
@@ -173,8 +173,9 @@ def test_gizmo_group_class_wiring(gizmo_cls_name, bl_idname, is_element_predicat
|
|||||||
predicate = getattr(tool.Parametric, is_element_predicate)
|
predicate = getattr(tool.Parametric, is_element_predicate)
|
||||||
fake_element = Mock()
|
fake_element = Mock()
|
||||||
fake_element.is_a.return_value = True
|
fake_element.is_a.return_value = True
|
||||||
with patch.object(tool.Parametric, is_element_predicate, side_effect=predicate) as p, patch.object(
|
with (
|
||||||
tool.System, "has_parametric_body", return_value=True
|
patch.object(tool.Parametric, is_element_predicate, side_effect=predicate) as p,
|
||||||
|
patch.object(tool.System, "has_parametric_body", return_value=True),
|
||||||
):
|
):
|
||||||
cls.is_element_type(fake_element)
|
cls.is_element_type(fake_element)
|
||||||
assert p.called, f"{gizmo_cls_name}.is_element_type did not delegate to Parametric.{is_element_predicate}"
|
assert p.called, f"{gizmo_cls_name}.is_element_type did not delegate to Parametric.{is_element_predicate}"
|
||||||
|
|||||||
@@ -139,6 +139,5 @@ def test_every_cancel_ops_entry_has_a_real_preview_propertygroup() -> None:
|
|||||||
orphaned = [attr for attr, _op in preview_base.PREVIEW_CANCEL_OPS if attr not in declared_attrs]
|
orphaned = [attr for attr, _op in preview_base.PREVIEW_CANCEL_OPS if attr not in declared_attrs]
|
||||||
assert not orphaned, (
|
assert not orphaned, (
|
||||||
"PREVIEW_CANCEL_OPS contains entries whose PointerProperty child no longer "
|
"PREVIEW_CANCEL_OPS contains entries whose PointerProperty child no longer "
|
||||||
f"exists on {UMBRELLA_CLASS}. Drop the stale tuple(s):\n "
|
f"exists on {UMBRELLA_CLASS}. Drop the stale tuple(s):\n " + "\n ".join(orphaned)
|
||||||
+ "\n ".join(orphaned)
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ class CsvHeader(TypedDict):
|
|||||||
|
|
||||||
# Formula
|
# Formula
|
||||||
Formula: NotRequired[str]
|
Formula: NotRequired[str]
|
||||||
#QuantityClass: NotRequired[str]
|
# QuantityClass: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
# Currently we assume that if column is not part of the main header,
|
# Currently we assume that if column is not part of the main header,
|
||||||
# then it is a cost value category. So here we list any additional column
|
# then it is a cost value category. So here we list any additional column
|
||||||
@@ -97,7 +98,8 @@ class CostItem(TypedDict):
|
|||||||
Query: Union[str, None]
|
Query: Union[str, None]
|
||||||
|
|
||||||
Formula: Union[str, None]
|
Formula: Union[str, None]
|
||||||
#QuantityClass: Union[str, None]
|
# QuantityClass: Union[str, None]
|
||||||
|
|
||||||
|
|
||||||
class Csv2Ifc:
|
class Csv2Ifc:
|
||||||
# Inputs.
|
# Inputs.
|
||||||
@@ -420,7 +422,7 @@ class Csv2Ifc:
|
|||||||
products=results,
|
products=results,
|
||||||
formula=cost_item["Formula"],
|
formula=cost_item["Formula"],
|
||||||
ifc_class=ifc_quantity_class,
|
ifc_class=ifc_quantity_class,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
||||||
|
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ def create(
|
|||||||
_create_geometric_representation(file, alignment)
|
_create_geometric_representation(file, alignment)
|
||||||
|
|
||||||
referent_name = ifcopenshell.util.alignment.station_as_string(file, start_station)
|
referent_name = ifcopenshell.util.alignment.station_as_string(file, start_station)
|
||||||
referent = ifcopenshell.api.alignment.add_stationing_referent(
|
referent = ifcopenshell.api.alignment.add_stationing_referent(file, referent_name, alignment, 0.0, start_station)
|
||||||
file, referent_name, alignment, 0.0, start_station
|
|
||||||
)
|
|
||||||
|
|
||||||
for layout in alignment_layouts:
|
for layout in alignment_layouts:
|
||||||
_add_zero_length_segment(file, layout)
|
_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
|
return station - start_station
|
||||||
|
|
||||||
stations = [
|
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
|
for referent in referent_nest.RelatedObjects
|
||||||
]
|
]
|
||||||
stations.sort(key=lambda entry: entry[0])
|
stations.sort(key=lambda entry: entry[0])
|
||||||
|
|||||||
@@ -36,12 +36,11 @@ def update_fallback_position(file: ifcopenshell.file, lp: entity_instance):
|
|||||||
|
|
||||||
p = ifcopenshell.util.placement.get_local_placement(lp)
|
p = ifcopenshell.util.placement.get_local_placement(lp)
|
||||||
|
|
||||||
|
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
||||||
|
|
||||||
x = float(p[0, 3])*unit_scale
|
x = float(p[0, 3]) * unit_scale
|
||||||
y = float(p[1, 3])*unit_scale
|
y = float(p[1, 3]) * unit_scale
|
||||||
z = float(p[2, 3])*unit_scale
|
z = float(p[2, 3]) * unit_scale
|
||||||
|
|
||||||
rx = float(p[0, 0])
|
rx = float(p[0, 0])
|
||||||
ry = float(p[1, 0])
|
ry = float(p[1, 0])
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ def assign_cost_item_quantity(
|
|||||||
"products": products or [],
|
"products": products or [],
|
||||||
"prop_name": prop_name,
|
"prop_name": prop_name,
|
||||||
"formula": formula,
|
"formula": formula,
|
||||||
"ifc_class" : ifc_class
|
"ifc_class": ifc_class,
|
||||||
}
|
}
|
||||||
return usecase.execute()
|
return usecase.execute()
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ class Usecase:
|
|||||||
continue
|
continue
|
||||||
self.assign_cost_control(related_object=product, cost_item=self.settings["cost_item"])
|
self.assign_cost_control(related_object=product, cost_item=self.settings["cost_item"])
|
||||||
if self.settings["formula"]:
|
if self.settings["formula"]:
|
||||||
tree = ast.parse(self.settings["formula"], mode = "eval")
|
tree = ast.parse(self.settings["formula"], mode="eval")
|
||||||
collector = VariableExtractor()
|
collector = VariableExtractor()
|
||||||
collector.visit(tree)
|
collector.visit(tree)
|
||||||
variables = collector.variables
|
variables = collector.variables
|
||||||
@@ -144,10 +144,10 @@ class Usecase:
|
|||||||
value = getter(product, variable)
|
value = getter(product, variable)
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
print(
|
print(
|
||||||
f"WARNING: Variable '{variable}' in product '{product.Name}' "
|
f"WARNING: Variable '{variable}' in product '{product.Name}' "
|
||||||
f"is missing (None). Check Pset/Qset or property name."
|
f"is missing (None). Check Pset/Qset or property name."
|
||||||
)
|
)
|
||||||
elif value == 0:
|
elif value == 0:
|
||||||
print(
|
print(
|
||||||
f"WARNING: Variable '{variable}' in product '{product.Name}' "
|
f"WARNING: Variable '{variable}' in product '{product.Name}' "
|
||||||
@@ -159,7 +159,9 @@ class Usecase:
|
|||||||
|
|
||||||
new_quantity = None
|
new_quantity = None
|
||||||
for quantity in self.quantities:
|
for quantity in self.quantities:
|
||||||
if quantity.Formula == self.settings["formula"] and len(self.settings["products"]) == 1: #Todo improve it
|
if (
|
||||||
|
quantity.Formula == self.settings["formula"] and len(self.settings["products"]) == 1
|
||||||
|
): # Todo improve it
|
||||||
new_quantity = quantity
|
new_quantity = quantity
|
||||||
self.settings["ifc_class"] = quantity.is_a()
|
self.settings["ifc_class"] = quantity.is_a()
|
||||||
continue
|
continue
|
||||||
@@ -184,23 +186,23 @@ class Usecase:
|
|||||||
self.update_cost_item_count()
|
self.update_cost_item_count()
|
||||||
|
|
||||||
def get_value_from_pset(
|
def get_value_from_pset(
|
||||||
self,
|
self,
|
||||||
product:ifcopenshell.entity_instance,
|
product: ifcopenshell.entity_instance,
|
||||||
v: str,
|
v: str,
|
||||||
) -> float:
|
) -> float:
|
||||||
pset_name = v.split(".")[0]
|
pset_name = v.split(".")[0]
|
||||||
pset = ifcopenshell.util.element.get_pset(product, pset_name)
|
pset = ifcopenshell.util.element.get_pset(product, pset_name)
|
||||||
pset_property_name = v.split(".")[1]
|
pset_property_name = v.split(".")[1]
|
||||||
return (pset or {}).get(pset_property_name,None)
|
return (pset or {}).get(pset_property_name, None)
|
||||||
|
|
||||||
def get_value_from_qset(
|
def get_value_from_qset(
|
||||||
self,
|
self,
|
||||||
product:ifcopenshell.entity_instance,
|
product: ifcopenshell.entity_instance,
|
||||||
v: str,
|
v: str,
|
||||||
) -> float:
|
) -> float:
|
||||||
qtos = ifcopenshell.util.element.get_psets(product, qtos_only = True)
|
qtos = ifcopenshell.util.element.get_psets(product, qtos_only=True)
|
||||||
quantities = next(iter(qtos.values()), {})
|
quantities = next(iter(qtos.values()), {})
|
||||||
return (quantities or {}).get(v,None)
|
return (quantities or {}).get(v, None)
|
||||||
|
|
||||||
def assign_cost_control(
|
def assign_cost_control(
|
||||||
self, related_object: ifcopenshell.entity_instance, cost_item: ifcopenshell.entity_instance
|
self, related_object: ifcopenshell.entity_instance, cost_item: ifcopenshell.entity_instance
|
||||||
@@ -243,6 +245,7 @@ class Usecase:
|
|||||||
count += 1
|
count += 1
|
||||||
quantity[3] = count
|
quantity[3] = count
|
||||||
|
|
||||||
|
|
||||||
OPERATORS = {
|
OPERATORS = {
|
||||||
ast.Add: operator.add,
|
ast.Add: operator.add,
|
||||||
ast.Sub: operator.sub,
|
ast.Sub: operator.sub,
|
||||||
@@ -252,18 +255,20 @@ OPERATORS = {
|
|||||||
ast.USub: operator.neg,
|
ast.USub: operator.neg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_full_name(node):
|
def build_full_name(node):
|
||||||
#used for variables with dots
|
# used for variables with dots
|
||||||
parts = []
|
parts = []
|
||||||
while isinstance(node, ast.Attribute):
|
while isinstance(node, ast.Attribute):
|
||||||
parts.append(node.attr)
|
parts.append(node.attr)
|
||||||
node = node.value
|
node = node.value
|
||||||
|
|
||||||
if isinstance(node, ast.Name):
|
if isinstance(node, ast.Name):
|
||||||
parts.append(node.id)
|
parts.append(node.id)
|
||||||
|
|
||||||
return ".".join(reversed(parts))
|
return ".".join(reversed(parts))
|
||||||
|
|
||||||
|
|
||||||
class VariableExtractor(ast.NodeVisitor):
|
class VariableExtractor(ast.NodeVisitor):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.variables = set()
|
self.variables = set()
|
||||||
@@ -274,6 +279,7 @@ class VariableExtractor(ast.NodeVisitor):
|
|||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
self.variables.add(build_full_name(node))
|
self.variables.add(build_full_name(node))
|
||||||
|
|
||||||
|
|
||||||
class FormulaEvaluator(ast.NodeVisitor):
|
class FormulaEvaluator(ast.NodeVisitor):
|
||||||
def __init__(self, values):
|
def __init__(self, values):
|
||||||
self.values = values
|
self.values = values
|
||||||
|
|||||||
@@ -221,8 +221,7 @@ for id in to_emit:
|
|||||||
statements.append("%s << %s" % (id, stmt))
|
statements.append("%s << %s" % (id, stmt))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(
|
print(r"""
|
||||||
r"""
|
|
||||||
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -261,6 +260,4 @@ if __name__ == "__main__":
|
|||||||
mdl = importlib.import_module(output)
|
mdl = importlib.import_module(output)
|
||||||
mdl.Generator(m).emit()
|
mdl.Generator(m).emit()
|
||||||
sys.stdout.write(m.schema.name)
|
sys.stdout.write(m.schema.name)
|
||||||
"""
|
""" % ("\n ".join(statements)))
|
||||||
% ("\n ".join(statements))
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -695,6 +695,7 @@ codegen_rule("MOD", lambda context: "%")
|
|||||||
codegen_rule("TRUE", lambda context: "True")
|
codegen_rule("TRUE", lambda context: "True")
|
||||||
codegen_rule("FALSE", lambda context: "False")
|
codegen_rule("FALSE", lambda context: "False")
|
||||||
|
|
||||||
|
|
||||||
def _dotted_name(node: ast.AST):
|
def _dotted_name(node: ast.AST):
|
||||||
"""Return dotted name for Name/Attribute chains, else None."""
|
"""Return dotted name for Name/Attribute chains, else None."""
|
||||||
if isinstance(node, ast.Name):
|
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 f"{base}.{node.attr}" if base else node.attr
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class AttributeGetattrTransformer(ast.NodeTransformer):
|
class AttributeGetattrTransformer(ast.NodeTransformer):
|
||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
parents = []
|
parents = []
|
||||||
@@ -720,7 +722,7 @@ class AttributeGetattrTransformer(ast.NodeTransformer):
|
|||||||
if isinstance(node.ctx, ast.Store):
|
if isinstance(node.ctx, ast.Store):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
if _dotted_name(node) in ('ifcopenshell.create_entity', 'str.lower'):
|
if _dotted_name(node) in ("ifcopenshell.create_entity", "str.lower"):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
if node.attr.startswith("__"):
|
if node.attr.startswith("__"):
|
||||||
|
|||||||
@@ -363,24 +363,18 @@ class EarlyBoundCodeWriter:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.statements[self.statements.index("{factory_placeholder}")] = (
|
self.statements[self.statements.index("{factory_placeholder}")] = """
|
||||||
"""
|
|
||||||
class %(schema_name)s_instance_factory : public IfcParse::instance_factory {
|
class %(schema_name)s_instance_factory : public IfcParse::instance_factory {
|
||||||
virtual IfcUtil::IfcBaseClass* operator()(const IfcParse::declaration* decl, IfcEntityInstanceData&& data) const {
|
virtual IfcUtil::IfcBaseClass* operator()(const IfcParse::declaration* decl, IfcEntityInstanceData&& data) const {
|
||||||
%(instance_mapping)s
|
%(instance_mapping)s
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
"""
|
""" % locals()
|
||||||
% locals()
|
|
||||||
)
|
|
||||||
|
|
||||||
""
|
""
|
||||||
self.statements[self.statements.index("{string_pool_placeholder}")] = (
|
self.statements[self.statements.index("{string_pool_placeholder}")] = """
|
||||||
"""
|
|
||||||
const std::string strings[] = {%s};
|
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):
|
def __str__(self):
|
||||||
return "\n".join(self.statements)
|
return "\n".join(self.statements)
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ class configuration:
|
|||||||
config.set(
|
config.set(
|
||||||
"snippets",
|
"snippets",
|
||||||
"print all wall ids",
|
"print all wall ids",
|
||||||
self.config_encode(
|
self.config_encode("""
|
||||||
"""
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# A simple script that iterates over all walls in the current model #
|
# A simple script that iterates over all walls in the current model #
|
||||||
# and prints their Globally unique IDs (GUIDS) to the console window #
|
# and prints their Globally unique IDs (GUIDS) to the console window #
|
||||||
@@ -154,15 +153,13 @@ class configuration:
|
|||||||
|
|
||||||
for wall in model.by_type("IfcWall"):
|
for wall in model.by_type("IfcWall"):
|
||||||
print ("wall with global id: "+str(wall.GlobalId))
|
print ("wall with global id: "+str(wall.GlobalId))
|
||||||
""".lstrip()
|
""".lstrip()),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
config.set(
|
config.set(
|
||||||
"snippets",
|
"snippets",
|
||||||
"print properties of current selection",
|
"print properties of current selection",
|
||||||
self.config_encode(
|
self.config_encode("""
|
||||||
"""
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# A simple script that iterates over all IfcPropertySets of the currently #
|
# A simple script that iterates over all IfcPropertySets of the currently #
|
||||||
# selected object and prints them to the console #
|
# selected object and prints them to the console #
|
||||||
@@ -180,8 +177,7 @@ if selection:
|
|||||||
for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties:
|
for prop in relDefinesByProperties.RelatingPropertyDefinition.HasProperties:
|
||||||
print ("{:<20} :{}".format(prop.Name,prop.NominalValue.wrappedValue))
|
print ("{:<20} :{}".format(prop.Name,prop.NominalValue.wrappedValue))
|
||||||
print ("\\n")
|
print ("\\n")
|
||||||
""".lstrip()
|
""".lstrip()),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
with open(conf_file, "w") as configfile:
|
with open(conf_file, "w") as configfile:
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
|
|||||||
@@ -355,8 +355,7 @@ def get_cost_rate(
|
|||||||
|
|
||||||
class CostValueUnserialiser:
|
class CostValueUnserialiser:
|
||||||
def parse(self, formula: str):
|
def parse(self, formula: str):
|
||||||
l = lark.Lark(
|
l = lark.Lark("""start: formula
|
||||||
"""start: formula
|
|
||||||
formula: operand (operator operand)*
|
formula: operand (operator operand)*
|
||||||
operand: value | category "(" formula ")"
|
operand: value | category "(" formula ")"
|
||||||
value: NUMBER?
|
value: NUMBER?
|
||||||
@@ -393,8 +392,7 @@ class CostValueUnserialiser:
|
|||||||
NEWLINE: (CR? LF)+
|
NEWLINE: (CR? LF)+
|
||||||
|
|
||||||
%ignore WS // Disregard spaces in text
|
%ignore WS // Disregard spaces in text
|
||||||
"""
|
""")
|
||||||
)
|
|
||||||
start = l.parse(formula)
|
start = l.parse(formula)
|
||||||
return self.get_formula(start.children[0])
|
return self.get_formula(start.children[0])
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ import ifcopenshell.util.shape
|
|||||||
import ifcopenshell.util.system
|
import ifcopenshell.util.system
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
|
|
||||||
filter_elements_grammar = lark.Lark(
|
filter_elements_grammar = lark.Lark("""start: filter_group
|
||||||
"""start: filter_group
|
|
||||||
filter_group: facet_list ("+" facet_list)*
|
filter_group: facet_list ("+" facet_list)*
|
||||||
facet_list: facet ("," facet)*
|
facet_list: facet ("," facet)*
|
||||||
|
|
||||||
@@ -111,11 +110,9 @@ filter_elements_grammar = lark.Lark(
|
|||||||
NEWLINE: (CR? LF)+
|
NEWLINE: (CR? LF)+
|
||||||
|
|
||||||
%ignore WS // Disregard spaces in text
|
%ignore WS // Disregard spaces in text
|
||||||
"""
|
""")
|
||||||
)
|
|
||||||
|
|
||||||
get_element_grammar = lark.Lark(
|
get_element_grammar = lark.Lark("""start: keys
|
||||||
"""start: keys
|
|
||||||
|
|
||||||
keys: key ("." key)*
|
keys: key ("." key)*
|
||||||
key: quoted_string | regex_string | unquoted_string
|
key: quoted_string | regex_string | unquoted_string
|
||||||
@@ -130,11 +127,9 @@ get_element_grammar = lark.Lark(
|
|||||||
WS: /[ \\t\\f\\r\\n]/+
|
WS: /[ \\t\\f\\r\\n]/+
|
||||||
|
|
||||||
%ignore WS // Disregard spaces in text
|
%ignore WS // Disregard spaces in text
|
||||||
"""
|
""")
|
||||||
)
|
|
||||||
|
|
||||||
format_grammar = lark.Lark(
|
format_grammar = lark.Lark("""start: expression
|
||||||
"""start: expression
|
|
||||||
|
|
||||||
?expression: add_sub
|
?expression: add_sub
|
||||||
?add_sub: mul_div
|
?add_sub: mul_div
|
||||||
@@ -193,8 +188,7 @@ format_grammar = lark.Lark(
|
|||||||
NEWLINE: (CR? LF)+
|
NEWLINE: (CR? LF)+
|
||||||
|
|
||||||
%ignore WS // Disregard spaces in text
|
%ignore WS // Disregard spaces in text
|
||||||
"""
|
""")
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class FormatTransformer(lark.Transformer):
|
class FormatTransformer(lark.Transformer):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
|
||||||
|
|
||||||
def test_skip_over_non_entity_instance():
|
def test_skip_over_non_entity_instance():
|
||||||
data = """
|
data = """
|
||||||
ISO-10303-21;
|
ISO-10303-21;
|
||||||
|
|||||||
@@ -46,4 +46,4 @@ def test_file(filename):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pytest.main(["-sx", __file__, '--import-mode=importlib'])
|
pytest.main(["-sx", __file__, "--import-mode=importlib"])
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class Patcher(ifcpatch.BasePatcher):
|
|||||||
if element.is_a("IfcProject"):
|
if element.is_a("IfcProject"):
|
||||||
proj = self.new.add(element)
|
proj = self.new.add(element)
|
||||||
for ctx in element.RepresentationContexts or ():
|
for ctx in element.RepresentationContexts or ():
|
||||||
for coop in getattr(ctx, 'HasCoordinateOperation', ()):
|
for coop in getattr(ctx, "HasCoordinateOperation", ()):
|
||||||
self.new.add(coop)
|
self.new.add(coop)
|
||||||
return proj
|
return proj
|
||||||
return ifcopenshell.api.project.append_asset(
|
return ifcopenshell.api.project.append_asset(
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ class TestDowngradeIndexedPolyCurve(test.bootstrap.IFC4):
|
|||||||
Points=point_list,
|
Points=point_list,
|
||||||
Segments=segments,
|
Segments=segments,
|
||||||
)
|
)
|
||||||
self.file.create_entity(
|
self.file.create_entity("IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve)
|
||||||
"IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve
|
|
||||||
)
|
|
||||||
return curve
|
return curve
|
||||||
|
|
||||||
def test_run_without_segments(self):
|
def test_run_without_segments(self):
|
||||||
@@ -80,9 +78,7 @@ class TestDowngradeIndexedPolyCurve(test.bootstrap.IFC4):
|
|||||||
Points=point_list,
|
Points=point_list,
|
||||||
Segments=[self.file.createIfcLineIndex((1, 2, 3, 4, 1))],
|
Segments=[self.file.createIfcLineIndex((1, 2, 3, 4, 1))],
|
||||||
)
|
)
|
||||||
self.file.create_entity(
|
self.file.create_entity("IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve)
|
||||||
"IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve
|
|
||||||
)
|
|
||||||
ifcpatch.execute(
|
ifcpatch.execute(
|
||||||
{"input": "input.ifc", "file": self.file, "recipe": "DowngradeIndexedPolyCurve", "arguments": []}
|
{"input": "input.ifc", "file": self.file, "recipe": "DowngradeIndexedPolyCurve", "arguments": []}
|
||||||
)
|
)
|
||||||
@@ -110,9 +106,7 @@ class TestDowngradeIndexedPolyCurve(test.bootstrap.IFC4):
|
|||||||
self.file.createIfcLineIndex((3, 4)),
|
self.file.createIfcLineIndex((3, 4)),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.file.create_entity(
|
self.file.create_entity("IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve)
|
||||||
"IfcArbitraryClosedProfileDef", ProfileType="AREA", OuterCurve=curve
|
|
||||||
)
|
|
||||||
ifcpatch.execute(
|
ifcpatch.execute(
|
||||||
{"input": "input.ifc", "file": self.file, "recipe": "DowngradeIndexedPolyCurve", "arguments": []}
|
{"input": "input.ifc", "file": self.file, "recipe": "DowngradeIndexedPolyCurve", "arguments": []}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user