Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -1,6 +1,9 @@
import pytest
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.unit
import ifcopenshell.api.root
import ifcopenshell.api.context
import ifcopenshell.api.project
import ifcopenshell.geom
import ifcopenshell.api.owner.settings
from typing import get_args
@@ -45,23 +48,15 @@ class TestGeomSettings:
class TestAssignObject:
def test_no_welding_on_distinct_items(self):
self.file = ifcopenshell.api.run("project.create_file")
self.file = ifcopenshell.api.project.create_file()
ifcopenshell.api.owner.settings.get_user = lambda ifc: (ifc.by_type("IfcPersonAndOrganization") or [None])[0]
ifcopenshell.api.owner.settings.get_application = lambda ifc: (ifc.by_type("IfcApplication") or [None])[0]
ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcProject", name="Test"
)
unit = ifcopenshell.api.run(
"unit.add_si_unit", self.file, unit_type="LENGTHUNIT"
)
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
context = ifcopenshell.api.run(
"context.add_context", self.file, context_type="Model"
)
element = ifcopenshell.api.run(
"root.create_entity", self.file, ifc_class="IfcWall"
)
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject", name="Test")
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
context = ifcopenshell.api.context.add_context(self.file, context_type="Model")
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
def create_extrusion(x, y):
points = (
@@ -71,9 +66,7 @@ class TestAssignObject:
(x + 1.0, y + 0.0),
(x + 0.0, y + 0.0),
)
curve = self.file.createIfcPolyline(
[self.file.createIfcCartesianPoint(p) for p in points]
)
curve = self.file.createIfcPolyline([self.file.createIfcCartesianPoint(p) for p in points])
extrusion_direction = self.file.createIfcDirection((0.0, 0.0, 1.0))
return self.file.createIfcExtrudedAreaSolid(
self.file.createIfcArbitraryClosedProfileDef("AREA", None, curve),
@@ -96,21 +89,14 @@ class TestAssignObject:
]
)
obj = ifcopenshell.geom.create_shape(
ifcopenshell.geom.settings(WELD_VERTICES=True), element
)
obj = ifcopenshell.geom.create_shape(ifcopenshell.geom.settings(WELD_VERTICES=True), element)
# item_ids is a per-triangle array, so we have 12 triangles per cube
# even though not documented, the order in representation items should match
assert (
obj.geometry.item_ids
== (extrusions[0].id(),) * 12 + (extrusions[1].id(),) * 12
)
assert obj.geometry.item_ids == (extrusions[0].id(),) * 12 + (extrusions[1].id(),) * 12
# group the vertices
vs = [
obj.geometry.verts[i : i + 3] for i in range(0, len(obj.geometry.verts), 3)
]
vs = [obj.geometry.verts[i : i + 3] for i in range(0, len(obj.geometry.verts), 3)]
# welding should not happen between distinct items so the total number of verts should be 2 times 8
assert len(vs) == 16