mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Skip unavailable shape-stat kernels
Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -170,7 +170,12 @@ SETTING = Literal[
|
|||||||
# It's possible to use any hybrid combination by the format below:
|
# It's possible to use any hybrid combination by the format below:
|
||||||
# "hybrid-library1-library2".
|
# "hybrid-library1-library2".
|
||||||
# List is updated from abstract_kernel.cpp.
|
# List is updated from abstract_kernel.cpp.
|
||||||
GEOMETRY_LIBRARY = Literal["cgal", "cgal-simple", "opencascade", "hybrid-cgal-simple-opencascade"]
|
GEOMETRY_LIBRARY = Literal["cgal", "cgal-simple", "manifold", "opencascade", "hybrid-cgal-simple-opencascade"]
|
||||||
|
|
||||||
|
|
||||||
|
def has_geometry_library(geometry_library: str) -> bool:
|
||||||
|
"""Return whether a geometry kernel library can be loaded."""
|
||||||
|
return ifcopenshell_wrapper.has_geometry_library(geometry_library)
|
||||||
|
|
||||||
|
|
||||||
class missing_setting:
|
class missing_setting:
|
||||||
|
|||||||
@@ -1623,6 +1623,7 @@ def arrange_polygons(
|
|||||||
def get_plugin_search_paths() -> tuple[str, ...]: ...
|
def get_plugin_search_paths() -> tuple[str, ...]: ...
|
||||||
def set_plugin_search_paths(paths: Sequence[str]) -> None: ...
|
def set_plugin_search_paths(paths: Sequence[str]) -> None: ...
|
||||||
def clear_plugin_search_paths() -> None: ...
|
def clear_plugin_search_paths() -> None: ...
|
||||||
|
def has_geometry_library(geometry_library: str) -> bool: ...
|
||||||
def clear_schemas(): ...
|
def clear_schemas(): ...
|
||||||
def construct_iterator(geometry_library, settings, file, num_threads, logger=None): ...
|
def construct_iterator(geometry_library, settings, file, num_threads, logger=None): ...
|
||||||
def construct_iterator_with_include_exclude(
|
def construct_iterator_with_include_exclude(
|
||||||
|
|||||||
@@ -14,17 +14,27 @@ test_files = repo_root / "test" / "input" / "tests"
|
|||||||
settings = ifcopenshell.geom.settings()
|
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:]
|
||||||
|
kernels = [
|
||||||
|
pytest.param(
|
||||||
|
kernel,
|
||||||
|
marks=pytest.mark.skipif(
|
||||||
|
not ifcopenshell.geom.has_geometry_library(kernel),
|
||||||
|
reason=f"{kernel} geometry kernel is unavailable",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for kernel in ("manifold", "opencascade", "cgal")
|
||||||
|
]
|
||||||
|
|
||||||
print(testdata)
|
print(testdata)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("fn,area,volume", testdata)
|
@pytest.mark.parametrize("fn,area,volume", testdata)
|
||||||
def test_conversion(fn, area, volume):
|
@pytest.mark.parametrize("kernel", kernels)
|
||||||
|
def test_conversion(fn, area, volume, kernel):
|
||||||
f = ifcopenshell.open(test_files / fn)
|
f = ifcopenshell.open(test_files / fn)
|
||||||
elem = next(inst for inst in f.by_type("IfcElement") if not inst.is_a("IfcOpeningElement"))
|
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)
|
||||||
shp = ifcopenshell.geom.create_shape(settings, elem, geometry_library=kernel)
|
if area:
|
||||||
if area:
|
assert pytest.approx(float(area), rel=0.05) == ifcopenshell.util.shape.get_area(shp.geometry)
|
||||||
assert pytest.approx(float(area), rel=0.05) == ifcopenshell.util.shape.get_area(shp.geometry)
|
if volume:
|
||||||
if volume:
|
assert pytest.approx(float(volume), rel=0.02) == ifcopenshell.util.shape.get_volume(shp.geometry)
|
||||||
assert pytest.approx(float(volume), rel=0.02) == ifcopenshell.util.shape.get_volume(shp.geometry)
|
|
||||||
|
|||||||
@@ -286,6 +286,7 @@
|
|||||||
#include "../ifcgeom/conversion_result.h"
|
#include "../ifcgeom/conversion_result.h"
|
||||||
#include "../ifcgeom/hybrid_kernel.h"
|
#include "../ifcgeom/hybrid_kernel.h"
|
||||||
#include "../ifcgeom/geometry_serializer.h"
|
#include "../ifcgeom/geometry_serializer.h"
|
||||||
|
#include "../ifcgeom/kernel_plugin.h"
|
||||||
|
|
||||||
#include "../ifcparse/express.h"
|
#include "../ifcparse/express.h"
|
||||||
#include "../ifcparse/file.h"
|
#include "../ifcparse/file.h"
|
||||||
@@ -325,6 +326,16 @@ std::vector<std::string> get_plugin_search_paths() {
|
|||||||
void clear_plugin_search_paths() {
|
void clear_plugin_search_paths() {
|
||||||
ifcopenshell::plugin::clear_search_paths();
|
ifcopenshell::plugin::clear_search_paths();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_geometry_library(const std::string& geometry_library) {
|
||||||
|
auto& registry = ifcopenshell::geom::kernels::kernel_registry_instance();
|
||||||
|
try {
|
||||||
|
return registry.has(geometry_library) ||
|
||||||
|
ifcopenshell::geom::kernels::load_kernel_plugin(registry, geometry_library);
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "IfcGeomWrapper.i"
|
%include "IfcGeomWrapper.i"
|
||||||
|
|||||||
Reference in New Issue
Block a user