From b8359f52d0ce3de285d468786813965ced776e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20S=C3=A9guin-C?= Date: Wed, 16 Jan 2019 17:54:28 -0500 Subject: [PATCH] Load IGES files from python --- libsrc/occ/python_occ.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index eec271a1..aa68d6aa 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -13,10 +13,15 @@ namespace netgen extern std::shared_ptr ng_geometry; } +inline bool ends_with(std::string const & value, std::string const & ending) +{ + if (ending.size() > value.size()) return false; + return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); +} DLL_HEADER void ExportNgOCC(py::module &m) { - py::class_, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string") + py::class_, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step or *.iges file.)raw_string") .def(py::init<>()) .def(NGSPickle()) .def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions) @@ -113,7 +118,15 @@ DLL_HEADER void ExportNgOCC(py::module &m) cout << "load OCC geometry"; ifstream ist(filename); OCCGeometry * instance = new OCCGeometry(); - instance = LoadOCC_STEP(filename.c_str()); + if (ends_with(filename, ".stp") || ends_with(filename, ".step") || + ends_with(filename, ".STP") || ends_with(filename, ".STEP")) + { + instance = LoadOCC_STEP(filename.c_str()); + } + else + { + instance = LoadOCC_IGES(filename.c_str()); + } ng_geometry = shared_ptr(instance, NOOP_Deleter); return ng_geometry; }),py::call_guard());