From 293c5eca646de9f0fa61b5bf47b41af48027aa16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 22 May 2019 22:25:46 +0200 Subject: [PATCH] python: *very* little from Trade. --- doc/python/conf.py | 3 +- package/ci/travis-desktop-gles.sh | 4 +-- package/ci/travis-desktop.sh | 4 +-- src/python/CMakeLists.txt | 3 +- src/python/magnum/CMakeLists.txt | 15 +++++++- src/python/magnum/test/test_trade.py | 34 ++++++++++++++++++ src/python/magnum/trade.cpp | 53 ++++++++++++++++++++++++++++ src/python/setup.py.cmake | 1 + 8 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 src/python/magnum/test/test_trade.py create mode 100644 src/python/magnum/trade.cpp diff --git a/doc/python/conf.py b/doc/python/conf.py index efdf1c8..75a1646 100644 --- a/doc/python/conf.py +++ b/doc/python/conf.py @@ -16,10 +16,11 @@ import magnum.platform.glfw import magnum.platform.sdl2 import magnum.shaders import magnum.scenegraph +import magnum.trade # So the doc see everything # TODO: use just +=, m.css should reorder this on its own -magnum.__all__ = ['math', 'gl', 'platform', 'shaders', 'scenegraph'] + magnum.__all__ +magnum.__all__ = ['math', 'gl', 'platform', 'shaders', 'scenegraph', 'trade'] + magnum.__all__ # TODO ugh... can this be expressed directly in pybind? magnum.gl.__annotations__ = {} diff --git a/package/ci/travis-desktop-gles.sh b/package/ci/travis-desktop-gles.sh index a4f3e18..3562623 100755 --- a/package/ci/travis-desktop-gles.sh +++ b/package/ci/travis-desktop-gles.sh @@ -11,7 +11,7 @@ cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_DEPRECATED=$BUILD_DEPRECATED \ -DWITH_INTERCONNECT=OFF \ - -DWITH_PLUGINMANAGER=OFF \ + -DWITH_PLUGINMANAGER=ON \ -DWITH_TESTSUITE=OFF \ -G Ninja ninja install @@ -40,7 +40,7 @@ cmake .. \ -DWITH_SHADERS=ON \ -DWITH_TEXT=OFF \ -DWITH_TEXTURETOOLS=OFF \ - -DWITH_TRADE=OFF \ + -DWITH_TRADE=ON \ -DWITH_VK=OFF \ -DWITH_WINDOWLESSEGLAPPLICATION=ON \ -DBUILD_DEPRECATED=OFF \ diff --git a/package/ci/travis-desktop.sh b/package/ci/travis-desktop.sh index 6e70cab..f1d47ef 100755 --- a/package/ci/travis-desktop.sh +++ b/package/ci/travis-desktop.sh @@ -11,7 +11,7 @@ cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_DEPRECATED=$BUILD_DEPRECATED \ -DWITH_INTERCONNECT=OFF \ - -DWITH_PLUGINMANAGER=OFF \ + -DWITH_PLUGINMANAGER=ON \ -DWITH_TESTSUITE=OFF \ -G Ninja ninja install @@ -34,7 +34,7 @@ cmake .. \ -DWITH_SHADERS=ON \ -DWITH_TEXT=OFF \ -DWITH_TEXTURETOOLS=OFF \ - -DWITH_TRADE=OFF \ + -DWITH_TRADE=ON \ -DWITH_VK=OFF \ -DBUILD_DEPRECATED=OFF \ -G Ninja diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index e51f608..4899adc 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -46,7 +46,8 @@ foreach(target magnum_platform_egl magnum_platform_glx magnum_platform_glfw - magnum_platform_sdl2) + magnum_platform_sdl2 + magnum_trade) if(TARGET ${target}) set(${target}_file $) endif() diff --git a/src/python/magnum/CMakeLists.txt b/src/python/magnum/CMakeLists.txt index 28f3453..444c132 100644 --- a/src/python/magnum/CMakeLists.txt +++ b/src/python/magnum/CMakeLists.txt @@ -24,7 +24,7 @@ # # *Not* REQUIRED -find_package(Magnum COMPONENTS GL Shaders SceneGraph) +find_package(Magnum COMPONENTS GL Shaders SceneGraph Trade) set(magnum_SRCS magnum.cpp @@ -81,6 +81,19 @@ if(Magnum_Shaders_FOUND) LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum) endif() +if(Magnum_Trade_FOUND) + set(magnum_trade_SRCS + trade.cpp) + + pybind11_add_module(magnum_trade ${magnum_trade_SRCS}) + target_include_directories(magnum_trade PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + target_link_libraries(magnum_trade PRIVATE Magnum::Trade) + set_target_properties(magnum_trade PROPERTIES + FOLDER "python" + OUTPUT_NAME "trade" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}/magnum) +endif() + file(GENERATE OUTPUT ${output_dir}/magnum/__init__.py INPUT ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py) diff --git a/src/python/magnum/test/test_trade.py b/src/python/magnum/test/test_trade.py new file mode 100644 index 0000000..a70215f --- /dev/null +++ b/src/python/magnum/test/test_trade.py @@ -0,0 +1,34 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +import unittest + +from magnum import * +from magnum import trade + +class MeshData(unittest.TestCase): + def test_init(self): + # Well this doesn't do much but well + a = trade.MeshData2D diff --git a/src/python/magnum/trade.cpp b/src/python/magnum/trade.cpp new file mode 100644 index 0000000..58179c5 --- /dev/null +++ b/src/python/magnum/trade.cpp @@ -0,0 +1,53 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include + +#include "magnum/bootstrap.h" + +namespace magnum { namespace { + +template void meshData(py::class_& c) { + c + .def_property_readonly("primitive", &T::primitive, "Primitive") + .def("is_indexed", &T::isIndexed, "Whether the mesh is indexed"); +} + +void trade(py::module& m) { + py::class_ meshData2D{m, "MeshData2D", "Two-dimensional mesh data"}; + py::class_ meshData3D{m, "MeshData3D", "Three-dimensional mesh data"}; + meshData(meshData2D); + meshData(meshData3D); +} + +}} + +PYBIND11_MODULE(trade, m) { + m.doc() = "Data format exchange"; + + magnum::trade(m); +} diff --git a/src/python/setup.py.cmake b/src/python/setup.py.cmake index ed7ee5e..2769667 100644 --- a/src/python/setup.py.cmake +++ b/src/python/setup.py.cmake @@ -40,6 +40,7 @@ extension_paths = { 'magnum.platform.glx': '${magnum_platform_glx_file}', 'magnum.platform.glfw': '${magnum_platform_glfw_file}', 'magnum.platform.sdl2': '${magnum_platform_sdl2_file}', + 'magnum.trade': '${magnum_trade_file}', } class TheExtensionIsAlreadyBuiltWhyThisHasToBeSoDamnComplicated(build_ext):