From 7de13ef7cb6ab9c611da53d9a5d327ba1af45bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Mar 2023 18:20:40 +0100 Subject: [PATCH] python: drop a SceneConverter helper that's used exactly once. --- src/python/magnum/trade.cpp | 42 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/python/magnum/trade.cpp b/src/python/magnum/trade.cpp index b1e883f..f8822f5 100644 --- a/src/python/magnum/trade.cpp +++ b/src/python/magnum/trade.cpp @@ -428,28 +428,6 @@ template void checkSceneConverterResult(Trade::AbstractSceneConverter& self, const T& mesh, const std::string& filename) { - /** @todo log redirection -- but we'd need assertions to not be part of - that so when it dies, the user can still see why */ - bool out = (self.*f)(mesh, - #ifdef CORRADE_TARGET_WINDOWS - /* To allow people to conveniently use Python's os.path, we need to - convert backslashes to forward slashes as all Corrade and Magnum - APIs expect forward */ - Utility::Path::fromNativeSeparators(filename) - #else - filename - #endif - ); - if(!out) { - PyErr_SetString(PyExc_RuntimeError, "conversion failed"); - throw py::error_already_set{}; - } -} - Containers::Triple accessorsForMeshIndexType(const MeshIndexType type) { switch(type) { #define _c(type) \ @@ -1560,7 +1538,25 @@ void trade(py::module_& m) { py::class_, PluginManager::AbstractPlugin> abstractSceneConverter{m, "AbstractSceneConverter", "Interface for scene converter plugins"}; abstractSceneConverter /** @todo features */ - .def("convert_to_file", checkSceneConverterResult, "Convert a mesh to a file", py::arg("mesh"), py::arg("filename")); + /** @todo drop std::string in favor of our own string caster */ + .def("convert_to_file", [](Trade::AbstractSceneConverter& self, const Trade::MeshData& mesh, const std::string& filename) { + /** @todo log redirection -- but we'd need assertions to not be + part of that so when it dies, the user can still see why */ + bool out = self.convertToFile(mesh, + #ifdef CORRADE_TARGET_WINDOWS + /* To allow people to conveniently use Python's os.path, we + need to convert backslashes to forward slashes as all + Corrade and Magnum APIs expect forward */ + Utility::Path::fromNativeSeparators(filename) + #else + filename + #endif + ); + if(!out) { + PyErr_SetString(PyExc_RuntimeError, "conversion failed"); + throw py::error_already_set{}; + } + }, "Convert a mesh to a file", py::arg("mesh"), py::arg("filename")); corrade::plugin(abstractSceneConverter); py::class_, PluginManager::AbstractManager> sceneConverterManager{m, "SceneConverterManager", "Manager for scene converter plugins"};