diff --git a/example/with_external_libs/CMakeLists.txt b/example/with_external_libs/CMakeLists.txt deleted file mode 100644 index 1d60eb866c..0000000000 --- a/example/with_external_libs/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Boost.Geometry -# Example CMakeLists.txt building the Boost.Geometry with wxWidget example -# -# Copyright (c) 2021-2021 Barend Gehrels, Amsterdam, the Netherlands. - -# Use, modification and distribution is subject to the Boost Software License, -# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -cmake_minimum_required(VERSION 3.10) - -project(with_external_libs) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -# Set BOOST_ROOT in your environment (this is cmake default) -find_package(Boost) - -# Set WX_ROOT, similarly, also in your environment -set(WX_ROOT $ENV{WX_ROOT}) -message(STATUS "Using wxWidgets from this folder: " $ENV{WX_ROOT}) - -# WX Widgets -link_directories(${WX_ROOT}/lib) -add_executable(wx x04_wxwidgets_world_mapper.cpp) -target_include_directories(wx PRIVATE ${Boost_INCLUDE_DIRS}) -target_include_directories(wx PRIVATE ${WX_ROOT}/include) -target_include_directories(wx PRIVATE ${WX_ROOT}/include/wx-3.1) - -# WX configuration (get the values using wx-config --cxxflags and wx-config --libs) -target_compile_definitions(wx PRIVATE WXUSINGDLL __WXGTK2__ __WXGTK__) -target_link_libraries(wx PRIVATE wx_gtk2u_html-3.1 wx_gtk2u_core-3.1 wx_baseu_net-3.1 wx_baseu-3.1) - diff --git a/example/with_external_libs/wxwidgets/CMakeLists.txt b/example/with_external_libs/wxwidgets/CMakeLists.txt new file mode 100644 index 0000000000..ad06d01949 --- /dev/null +++ b/example/with_external_libs/wxwidgets/CMakeLists.txt @@ -0,0 +1,29 @@ +# Boost.Geometry +# Example CMakeLists.txt building the Boost.Geometry with wxWidget example +# +# Copyright (c) 2021-2024 Barend Gehrels, Amsterdam, the Netherlands. + +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +cmake_minimum_required(VERSION 3.8...3.20) + +project(wx_widgets_world_mapper) + +add_executable(${PROJECT_NAME} x04_wxwidgets_world_mapper.cpp) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) + +# Link the wxWidgets libraries to our executable +# Assuming it can be found by CMake in /usr/local +find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG) +target_link_libraries(${PROJECT_NAME} wxWidgets::wxWidgets) + +# Link the Boost.Geometry library to our executable +# By default, it is assumed to be relative to this directory. +target_include_directories(${PROJECT_NAME} PRIVATE ../../../../..) + +# If this does not work, or you build from elsewhere +# First set BOOST_ROOT +# Then use find_package(Boost) +# Then use target_link_libraries(${PROJECT_NAME} Boost::geometry) diff --git a/example/with_external_libs/wxwidgets/README.md b/example/with_external_libs/wxwidgets/README.md new file mode 100644 index 0000000000..036d285984 --- /dev/null +++ b/example/with_external_libs/wxwidgets/README.md @@ -0,0 +1,47 @@ +# ![Boost.Geometry](../../../doc/other/logo/logo_bkg.png) + +# wxWidgets + +## Introduction + +[wxWidgets](https://www.wxwidgets.org/) is a stable and powerful open source framework for developing native cross-platform GUI applications in C++. + +## Building wxWidgets + +There are several possibilities. This documentation uses the CMake approach. + +* Retrieve wxWidgets from github +* Be sure to also retrieve the git submodules +* Build and install with cmake, such that it can be found from anywhere. + +``` +cd ~git +git clone --recurse-submodules git@github.com:wxWidgets/wxWidgets.git +cd wxWidgets +mkdir my_build_folder +cd my_build_folder +cmake .. +cmake --build . +sudo cmake --build . --target install +``` + +It is (on macOs) now installed in `/usr/local/lib/` + +## Building this example + +Assuming you want to build it with CMake + +``` +cd example/with_external_libs/wxwidgets +mkdir my_build_folder +cd my_build_folder +cmake .. +cmake --build . +``` + +## Running this example + +You can pass an Ascii file with WKT polygons as the first command line argument. There are several +packed with Boost.Geometry as examples and as test data. + +For example: `./wx_widgets_world_mapper ../../../data/world.wkt` diff --git a/example/with_external_libs/x04_wxwidgets_world_mapper.cpp b/example/with_external_libs/wxwidgets/x04_wxwidgets_world_mapper.cpp similarity index 87% rename from example/with_external_libs/x04_wxwidgets_world_mapper.cpp rename to example/with_external_libs/wxwidgets/x04_wxwidgets_world_mapper.cpp index ac3f6322e1..40074108bb 100644 --- a/example/with_external_libs/x04_wxwidgets_world_mapper.cpp +++ b/example/with_external_libs/wxwidgets/x04_wxwidgets_world_mapper.cpp @@ -1,6 +1,6 @@ // Boost.Geometry // -// Copyright (c) 2010-2021 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2010-2024 Barend Gehrels, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -11,19 +11,7 @@ // highlighting the country under the mouse, and indicating position // of the mouse in latitude/longitude and in pixels. -// To compile this program: -// Install wxWidgets (if not done before) -// export BOOST_ROOT=..... -// export WX_ROOT=.... (for example /home/myname/mylib/wxWidgets/Linux/x86_64) -// mkdir build -// cd build -// cmake .. -G Ninja -// ninja -// If necessary, CMakeLists.txt should be adapted, the options for wx -// are provided by "wx-config --cxxflags" and "... --libs" -// and might need a change in CMakeLists.txt - -//#define EXAMPLE_WX_USE_GRAPHICS_CONTEXT 1 +// #define EXAMPLE_WX_USE_GRAPHICS_CONTEXT 1 #include #include @@ -36,16 +24,16 @@ #include #include -#include "wx/wx.h" -#include "wx/math.h" -#include "wx/stockitem.h" +#include +#include +#include +#include #ifdef EXAMPLE_WX_USE_GRAPHICS_CONTEXT #include "wx/graphics.h" #include "wx/dcgraph.h" #endif - using point_2d = boost::geometry::model::d2::point_xy; using country_type = boost::geometry::model::multi_polygon < @@ -58,7 +46,7 @@ BOOST_GEOMETRY_REGISTER_POINT_2D(wxPoint, int, cs::cartesian, x, y) BOOST_GEOMETRY_REGISTER_POINT_2D(wxRealPoint, double, cs::cartesian, x, y) // ---------------------------------------------------------------------------- -// Read an ASCII file containing WKT's +// Read an ASCII file containing WKT's of either POLYGON or MULTIPOLYGON // ---------------------------------------------------------------------------- template inline void read_wkt(std::string const& filename, std::vector& geometries, Box& box) @@ -70,13 +58,24 @@ inline void read_wkt(std::string const& filename, std::vector& geometr { std::string line; std::getline(cpp_file, line); - if (! line.empty()) + if (line.empty()) + { + continue; + } + Geometry geometry; + if (line.substr(0, 4) == "POLY") + { + boost::geometry::model::polygon polygon; + boost::geometry::read_wkt(line, polygon); + geometry.push_back(polygon); + } + else { - Geometry geometry; boost::geometry::read_wkt(line, geometry); - geometries.push_back(geometry); - boost::geometry::expand(box, boost::geometry::return_envelope(geometry)); } + + geometries.push_back(geometry); + boost::geometry::expand(box, boost::geometry::return_envelope(geometry)); } } } @@ -99,7 +98,7 @@ class HelloWorldFrame: public wxFrame class HelloWorldCanvas: public wxWindow { public: - HelloWorldCanvas(wxFrame *frame); + HelloWorldCanvas(wxFrame *frame, const std::string& filename); private: void DrawCountries(wxDC& dc); @@ -122,6 +121,7 @@ class HelloWorldCanvas: public wxWindow std::shared_ptr m_map_transformer; std::shared_ptr m_inverse_transformer; + std::string m_filename; boost::geometry::model::box m_box; std::vector m_countries; int m_focus = -1; @@ -132,7 +132,7 @@ class HelloWorldCanvas: public wxWindow wxFrame* m_owner = nullptr; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; @@ -143,8 +143,10 @@ class HelloWorldApp: public wxApp public: bool OnInit() { + const auto filename = wxApp::argc >= 2 ? wxApp::argv[1].ToStdString() : "example/data/world.wkt"; + // Create the main frame window - HelloWorldFrame *frame = new HelloWorldFrame(NULL, _T("Boost.Geometry for wxWidgets - Hello World!"), wxDefaultPosition, wxSize(640, 480)); + HelloWorldFrame *frame = new HelloWorldFrame(NULL, _T("Boost.Geometry for wxWidgets - Hello World!"), wxDefaultPosition, wxSize(1024, 768)); wxMenu *file_menu = new wxMenu; file_menu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT)); @@ -152,10 +154,7 @@ class HelloWorldApp: public wxApp menuBar->Append(file_menu, _T("&File")); frame->SetMenuBar(menuBar); - int width, height; - frame->GetClientSize(&width, &height); - - (void) new HelloWorldCanvas(frame); + (void) new HelloWorldCanvas(frame, filename); // Show the frame frame->Show(true); @@ -191,12 +190,13 @@ void HelloWorldFrame::OnCloseWindow(wxCloseEvent& ) // ---------------------------------------------------------------------------- -HelloWorldCanvas::HelloWorldCanvas(wxFrame *frame) +HelloWorldCanvas::HelloWorldCanvas(wxFrame *frame, const std::string& filename) : wxWindow(frame, wxID_ANY) , m_owner(frame) + , m_filename(filename) { boost::geometry::assign_inverse(m_box); - read_wkt("../data/world.wkt", m_countries, m_box); + read_wkt(m_filename, m_countries, m_box); }