further simplification
This commit is contained in:
parent
bb3b39016f
commit
695950b2e6
4 changed files with 42 additions and 62 deletions
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(OpenCSG-example)
|
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/ProgressStatusBar.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.cpp)
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
#ifndef CANVAS_HPP
|
|
||||||
#define CANVAS_HPP
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx/wx.h".
|
|
||||||
#include <wx/wxprec.h>
|
|
||||||
#ifndef WX_PRECOMP
|
|
||||||
#include <wx/wx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <wx/glcanvas.h>
|
|
||||||
#include <wx/msgdlg.h>
|
|
||||||
|
|
||||||
#include "GLScene.hpp"
|
|
||||||
|
|
||||||
namespace Slic3r { namespace GL {
|
|
||||||
|
|
||||||
class Canvas: public wxGLCanvas, public Slic3r::GL::Display
|
|
||||||
{
|
|
||||||
std::unique_ptr<wxGLContext> 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<class...Args>
|
|
||||||
Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(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
|
|
|
@ -21,16 +21,16 @@ template<class T> using uqptr = std::unique_ptr<T>;
|
||||||
template<class T> using wkptr = std::weak_ptr<T>;
|
template<class T> using wkptr = std::weak_ptr<T>;
|
||||||
|
|
||||||
template<class T, class A = std::allocator<T>>
|
template<class T, class A = std::allocator<T>>
|
||||||
using Collection = std::vector<T, A>;
|
using vector = std::vector<T, A>;
|
||||||
|
|
||||||
template<class L> void cleanup(Collection<std::weak_ptr<L>> &listeners) {
|
template<class L> void cleanup(vector<std::weak_ptr<L>> &listeners) {
|
||||||
auto it = std::remove_if(listeners.begin(), listeners.end(),
|
auto it = std::remove_if(listeners.begin(), listeners.end(),
|
||||||
[](auto &l) { return !l.lock(); });
|
[](auto &l) { return !l.lock(); });
|
||||||
listeners.erase(it, listeners.end());
|
listeners.erase(it, listeners.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class F, class L, class...Args>
|
template<class F, class L, class...Args>
|
||||||
void call(F &&f, Collection<std::weak_ptr<L>> &listeners, Args&&... args) {
|
void call(F &&f, vector<std::weak_ptr<L>> &listeners, Args&&... args) {
|
||||||
for (auto &l : listeners)
|
for (auto &l : listeners)
|
||||||
if (auto p = l.lock()) ((p.get())->*f)(std::forward<Args>(args)...);
|
if (auto p = l.lock()) ((p.get())->*f)(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Collection<wkptr<Listener>> m_listeners;
|
vector<wkptr<Listener>> m_listeners;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~MouseInput() = default;
|
virtual ~MouseInput() = default;
|
||||||
|
@ -104,9 +104,9 @@ public:
|
||||||
|
|
||||||
// Vertices and their normals, interleaved to be used by void
|
// Vertices and their normals, interleaved to be used by void
|
||||||
// glInterleavedArrays(GL_N3F_V3F, 0, x)
|
// glInterleavedArrays(GL_N3F_V3F, 0, x)
|
||||||
Collection<float> vertices_and_normals_interleaved;
|
vector<float> vertices_and_normals_interleaved;
|
||||||
Collection<int> triangle_indices;
|
vector<int> triangle_indices;
|
||||||
Collection<int> quad_indices;
|
vector<int> quad_indices;
|
||||||
|
|
||||||
// When the geometry data is loaded into the graphics card as Vertex
|
// When the geometry data is loaded into the graphics card as Vertex
|
||||||
// Buffer Objects, the above mentioned std::vectors are cleared and the
|
// Buffer Objects, the above mentioned std::vectors are cleared and the
|
||||||
|
@ -271,7 +271,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Collection<wkptr<Listener>> m_listeners;
|
vector<wkptr<Listener>> m_listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Display : public Scene::Listener
|
class Display : public Scene::Listener
|
||||||
|
@ -283,9 +283,9 @@ protected:
|
||||||
CSGSettings m_csgsettings;
|
CSGSettings m_csgsettings;
|
||||||
|
|
||||||
struct SceneCache {
|
struct SceneCache {
|
||||||
Collection<shptr<Primitive>> primitives;
|
vector<shptr<Primitive>> primitives;
|
||||||
Collection<Primitive *> primitives_free;
|
vector<Primitive *> primitives_free;
|
||||||
Collection<OpenCSG::Primitive *> primitives_csg;
|
vector<OpenCSG::Primitive *> primitives_csg;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
@ -332,8 +332,9 @@ class Controller : public std::enable_shared_from_this<Controller>,
|
||||||
bool m_left_btn = false, m_right_btn = false;
|
bool m_left_btn = false, m_right_btn = false;
|
||||||
|
|
||||||
shptr<Scene> m_scene;
|
shptr<Scene> m_scene;
|
||||||
Collection<wkptr<Display>> m_displays;
|
vector<wkptr<Display>> m_displays;
|
||||||
|
|
||||||
|
// Call a method of Camera on all the cameras of the attached displays
|
||||||
template<class F, class...Args>
|
template<class F, class...Args>
|
||||||
void call_cameras(F &&f, Args&&... args) {
|
void call_cameras(F &&f, Args&&... args) {
|
||||||
for (wkptr<Display> &l : m_displays)
|
for (wkptr<Display> &l : m_displays)
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#include <wx/tglbtn.h>
|
#include <wx/tglbtn.h>
|
||||||
#include <wx/combobox.h>
|
#include <wx/combobox.h>
|
||||||
#include <wx/spinctrl.h>
|
#include <wx/spinctrl.h>
|
||||||
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/glcanvas.h>
|
#include <wx/glcanvas.h>
|
||||||
|
|
||||||
#include "Canvas.hpp"
|
|
||||||
#include "GLScene.hpp"
|
#include "GLScene.hpp"
|
||||||
|
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
@ -29,6 +29,33 @@
|
||||||
|
|
||||||
using namespace Slic3r::GL;
|
using namespace Slic3r::GL;
|
||||||
|
|
||||||
|
class Canvas: public wxGLCanvas, public Slic3r::GL::Display
|
||||||
|
{
|
||||||
|
std::unique_ptr<wxGLContext> 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<class...Args>
|
||||||
|
Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(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
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
shptr<Scene> m_scene; // Model
|
shptr<Scene> m_scene; // Model
|
||||||
|
|
Loading…
Reference in a new issue