diff --git a/sandboxes/opencsg/CMakeLists.txt b/sandboxes/opencsg/CMakeLists.txt index 9a216a7dc..651fbe82f 100644 --- a/sandboxes/opencsg/CMakeLists.txt +++ b/sandboxes/opencsg/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(OpenCSG-example) -add_executable(opencsg_example main.cpp GLScene.hpp GLScene.cpp Canvas.hpp +add_executable(opencsg_example main.cpp GLScene.hpp GLScene.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/ProgressStatusBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.hpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.cpp) diff --git a/sandboxes/opencsg/Canvas.hpp b/sandboxes/opencsg/Canvas.hpp deleted file mode 100644 index 424579945..000000000 --- a/sandboxes/opencsg/Canvas.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef CANVAS_HPP -#define CANVAS_HPP - -#include - -// For compilers that support precompilation, includes "wx/wx.h". -#include -#ifndef WX_PRECOMP -#include -#endif - -#include -#include - -#include "GLScene.hpp" - -namespace Slic3r { namespace GL { - -class Canvas: public wxGLCanvas, public Slic3r::GL::Display -{ - std::unique_ptr m_context; -public: - - void set_active(long w, long h) override - { - SetCurrent(*m_context); - Slic3r::GL::Display::set_active(w, h); - } - - void swap_buffers() override { SwapBuffers(); } - - template - Canvas(Args &&...args): wxGLCanvas(std::forward(args)...) - { - auto ctx = new wxGLContext(this); - if (!ctx || !ctx->IsOK()) { - wxMessageBox("Could not create OpenGL context.", "Error", - wxOK | wxICON_ERROR); - return; - } - - m_context.reset(ctx); - } -}; - -}} // namespace Slic3r::GL - -#endif // CANVAS_HPP diff --git a/sandboxes/opencsg/GLScene.hpp b/sandboxes/opencsg/GLScene.hpp index 5a4afb396..68cc59b01 100644 --- a/sandboxes/opencsg/GLScene.hpp +++ b/sandboxes/opencsg/GLScene.hpp @@ -21,16 +21,16 @@ template using uqptr = std::unique_ptr; template using wkptr = std::weak_ptr; template> -using Collection = std::vector; +using vector = std::vector; -template void cleanup(Collection> &listeners) { +template void cleanup(vector> &listeners) { auto it = std::remove_if(listeners.begin(), listeners.end(), [](auto &l) { return !l.lock(); }); listeners.erase(it, listeners.end()); } template -void call(F &&f, Collection> &listeners, Args&&... args) { +void call(F &&f, vector> &listeners, Args&&... args) { for (auto &l : listeners) if (auto p = l.lock()) ((p.get())->*f)(std::forward(args)...); } @@ -57,7 +57,7 @@ public: }; private: - Collection> m_listeners; + vector> m_listeners; public: virtual ~MouseInput() = default; @@ -104,9 +104,9 @@ public: // Vertices and their normals, interleaved to be used by void // glInterleavedArrays(GL_N3F_V3F, 0, x) - Collection vertices_and_normals_interleaved; - Collection triangle_indices; - Collection quad_indices; + vector vertices_and_normals_interleaved; + vector triangle_indices; + vector quad_indices; // When the geometry data is loaded into the graphics card as Vertex // Buffer Objects, the above mentioned std::vectors are cleared and the @@ -271,7 +271,7 @@ public: } private: - Collection> m_listeners; + vector> m_listeners; }; class Display : public Scene::Listener @@ -283,9 +283,9 @@ protected: CSGSettings m_csgsettings; struct SceneCache { - Collection> primitives; - Collection primitives_free; - Collection primitives_csg; + vector> primitives; + vector primitives_free; + vector primitives_csg; void clear(); @@ -332,8 +332,9 @@ class Controller : public std::enable_shared_from_this, bool m_left_btn = false, m_right_btn = false; shptr m_scene; - Collection> m_displays; + vector> m_displays; + // Call a method of Camera on all the cameras of the attached displays template void call_cameras(F &&f, Args&&... args) { for (wkptr &l : m_displays) diff --git a/sandboxes/opencsg/main.cpp b/sandboxes/opencsg/main.cpp index d01687428..c2f8a74aa 100644 --- a/sandboxes/opencsg/main.cpp +++ b/sandboxes/opencsg/main.cpp @@ -15,9 +15,9 @@ #include #include #include +#include #include -#include "Canvas.hpp" #include "GLScene.hpp" #include "libslic3r/Model.hpp" @@ -29,6 +29,33 @@ using namespace Slic3r::GL; +class Canvas: public wxGLCanvas, public Slic3r::GL::Display +{ + std::unique_ptr m_context; +public: + + void set_active(long w, long h) override + { + SetCurrent(*m_context); + Slic3r::GL::Display::set_active(w, h); + } + + void swap_buffers() override { SwapBuffers(); } + + template + Canvas(Args &&...args): wxGLCanvas(std::forward(args)...) + { + auto ctx = new wxGLContext(this); + if (!ctx || !ctx->IsOK()) { + wxMessageBox("Could not create OpenGL context.", "Error", + wxOK | wxICON_ERROR); + return; + } + + m_context.reset(ctx); + } +}; + class MyFrame: public wxFrame { shptr m_scene; // Model