2018-05-09 08:47:04 +00:00
|
|
|
#include "GLCanvas3DManager.hpp"
|
|
|
|
#include "../../slic3r/GUI/GUI.hpp"
|
|
|
|
#include "../../slic3r/GUI/AppConfig.hpp"
|
2018-06-11 13:13:13 +00:00
|
|
|
#include "../../slic3r/GUI/GLCanvas3D.hpp"
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
|
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
|
|
|
|
|
|
#include <wx/glcanvas.h>
|
2018-05-30 13:18:45 +00:00
|
|
|
#include <wx/timer.h>
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2018-06-04 08:14:09 +00:00
|
|
|
GLCanvas3DManager::GLInfo::GLInfo()
|
|
|
|
: version("")
|
|
|
|
, glsl_version("")
|
|
|
|
, vendor("")
|
|
|
|
, renderer("")
|
2018-05-09 08:47:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:34:20 +00:00
|
|
|
void GLCanvas3DManager::GLInfo::detect()
|
2018-05-09 08:47:04 +00:00
|
|
|
{
|
2018-06-04 08:14:09 +00:00
|
|
|
const char* data = (const char*)::glGetString(GL_VERSION);
|
2018-06-20 12:34:20 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
version = data;
|
2018-06-04 08:14:09 +00:00
|
|
|
|
|
|
|
data = (const char*)::glGetString(GL_SHADING_LANGUAGE_VERSION);
|
2018-06-20 12:34:20 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
glsl_version = data;
|
2018-06-04 08:14:09 +00:00
|
|
|
|
|
|
|
data = (const char*)::glGetString(GL_VENDOR);
|
2018-06-20 12:34:20 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
vendor = data;
|
2018-06-04 08:14:09 +00:00
|
|
|
|
|
|
|
data = (const char*)::glGetString(GL_RENDERER);
|
2018-06-20 12:34:20 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
renderer = data;
|
2018-06-04 08:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GLCanvas3DManager::GLInfo::is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const
|
|
|
|
{
|
2018-05-09 08:47:04 +00:00
|
|
|
std::vector<std::string> tokens;
|
2018-06-04 08:14:09 +00:00
|
|
|
boost::split(tokens, version, boost::is_any_of(" "), boost::token_compress_on);
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
if (tokens.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> numbers;
|
|
|
|
boost::split(numbers, tokens[0], boost::is_any_of("."), boost::token_compress_on);
|
|
|
|
|
2018-06-04 08:14:09 +00:00
|
|
|
unsigned int gl_major = 0;
|
|
|
|
unsigned int gl_minor = 0;
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
if (numbers.size() > 0)
|
2018-06-04 08:14:09 +00:00
|
|
|
gl_major = ::atoi(numbers[0].c_str());
|
2018-05-09 08:47:04 +00:00
|
|
|
|
|
|
|
if (numbers.size() > 1)
|
2018-06-04 08:14:09 +00:00
|
|
|
gl_minor = ::atoi(numbers[1].c_str());
|
2018-05-09 08:47:04 +00:00
|
|
|
|
2018-06-04 08:14:09 +00:00
|
|
|
if (gl_major < major)
|
2018-05-09 08:47:04 +00:00
|
|
|
return false;
|
2018-06-04 08:14:09 +00:00
|
|
|
else if (gl_major > major)
|
2018-05-09 08:47:04 +00:00
|
|
|
return true;
|
|
|
|
else
|
2018-06-04 08:14:09 +00:00
|
|
|
return gl_minor >= minor;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool extensions) const
|
|
|
|
{
|
|
|
|
std::stringstream out;
|
|
|
|
|
|
|
|
std::string h2_start = format_as_html ? "<b>" : "";
|
2018-07-12 11:34:39 +00:00
|
|
|
std::string h2_end = format_as_html ? "</b>" : "";
|
|
|
|
std::string b_start = format_as_html ? "<b>" : "";
|
|
|
|
std::string b_end = format_as_html ? "</b>" : "";
|
2018-06-04 08:14:09 +00:00
|
|
|
std::string line_end = format_as_html ? "<br>" : "\n";
|
|
|
|
|
|
|
|
out << h2_start << "OpenGL installation" << h2_end << line_end;
|
2018-07-12 11:34:39 +00:00
|
|
|
out << b_start << "GL version: " << b_end << (version.empty() ? "N/A" : version) << line_end;
|
|
|
|
out << b_start << "Vendor: " << b_end << (vendor.empty() ? "N/A" : vendor) << line_end;
|
|
|
|
out << b_start << "Renderer: " << b_end << (renderer.empty() ? "N/A" : renderer) << line_end;
|
|
|
|
out << b_start << "GLSL version: " << b_end << (glsl_version.empty() ? "N/A" : glsl_version) << line_end;
|
2018-07-12 10:15:30 +00:00
|
|
|
|
2018-06-04 08:14:09 +00:00
|
|
|
if (extensions)
|
|
|
|
{
|
|
|
|
std::vector<std::string> extensions_list;
|
2018-07-12 11:10:18 +00:00
|
|
|
std::string extensions_str = (const char*)::glGetString(GL_EXTENSIONS);
|
|
|
|
boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_off);
|
|
|
|
|
2018-07-12 10:15:30 +00:00
|
|
|
if (!extensions_list.empty())
|
2018-06-04 08:14:09 +00:00
|
|
|
{
|
2018-07-12 10:15:30 +00:00
|
|
|
out << h2_start << "Installed extensions:" << h2_end << line_end;
|
|
|
|
|
|
|
|
std::sort(extensions_list.begin(), extensions_list.end());
|
|
|
|
for (const std::string& ext : extensions_list)
|
|
|
|
{
|
|
|
|
out << ext << line_end;
|
|
|
|
}
|
2018-06-04 08:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.str();
|
2018-05-09 08:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLCanvas3DManager::GLCanvas3DManager()
|
2018-06-27 09:31:11 +00:00
|
|
|
: m_current(nullptr)
|
2018-06-11 13:49:04 +00:00
|
|
|
, m_gl_initialized(false)
|
2018-05-09 08:47:04 +00:00
|
|
|
, m_use_legacy_opengl(false)
|
|
|
|
, m_use_VBOs(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-11 13:49:04 +00:00
|
|
|
bool GLCanvas3DManager::add(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
if (canvas == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
if (_get_canvas(canvas) != m_canvases.end())
|
|
|
|
return false;
|
|
|
|
|
2018-06-27 09:31:11 +00:00
|
|
|
GLCanvas3D* canvas3D = new GLCanvas3D(canvas);
|
2018-05-09 08:47:04 +00:00
|
|
|
if (canvas3D == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2018-06-06 12:19:28 +00:00
|
|
|
canvas3D->bind_event_handlers();
|
2018-05-09 08:47:04 +00:00
|
|
|
m_canvases.insert(CanvasesMap::value_type(canvas, canvas3D));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLCanvas3DManager::remove(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it == m_canvases.end())
|
|
|
|
return false;
|
|
|
|
|
2018-06-06 12:19:28 +00:00
|
|
|
it->second->unbind_event_handlers();
|
2018-05-09 08:47:04 +00:00
|
|
|
delete it->second;
|
|
|
|
m_canvases.erase(it);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::remove_all()
|
|
|
|
{
|
|
|
|
for (CanvasesMap::value_type& item : m_canvases)
|
|
|
|
{
|
2018-06-06 12:19:28 +00:00
|
|
|
item.second->unbind_event_handlers();
|
2018-05-09 08:47:04 +00:00
|
|
|
delete item.second;
|
|
|
|
}
|
|
|
|
m_canvases.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GLCanvas3DManager::count() const
|
|
|
|
{
|
|
|
|
return (unsigned int)m_canvases.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::init_gl()
|
|
|
|
{
|
|
|
|
if (!m_gl_initialized)
|
|
|
|
{
|
|
|
|
glewInit();
|
2018-06-20 12:34:20 +00:00
|
|
|
m_gl_info.detect();
|
|
|
|
const AppConfig* config = GUI::get_app_config();
|
|
|
|
m_use_legacy_opengl = (config == nullptr) || (config->get("use_legacy_opengl") == "1");
|
|
|
|
m_use_VBOs = !m_use_legacy_opengl && m_gl_info.is_version_greater_or_equal_to(2, 0);
|
|
|
|
m_gl_initialized = true;
|
2018-05-09 08:47:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 08:14:09 +00:00
|
|
|
std::string GLCanvas3DManager::get_gl_info(bool format_as_html, bool extensions) const
|
|
|
|
{
|
|
|
|
return m_gl_info.to_string(format_as_html, extensions);
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
bool GLCanvas3DManager::use_VBOs() const
|
|
|
|
{
|
|
|
|
return m_use_VBOs;
|
|
|
|
}
|
|
|
|
|
2018-06-04 11:15:28 +00:00
|
|
|
bool GLCanvas3DManager::init(wxGLCanvas* canvas)
|
2018-05-23 07:57:44 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
2018-06-04 11:15:28 +00:00
|
|
|
if (it != m_canvases.end())
|
|
|
|
return (it->second != nullptr) ? _init(*it->second) : false;
|
|
|
|
else
|
|
|
|
return false;
|
2018-05-23 07:57:44 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 14:06:37 +00:00
|
|
|
void GLCanvas3DManager::set_as_dirty(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_as_dirty();
|
|
|
|
}
|
|
|
|
|
2018-06-11 11:48:02 +00:00
|
|
|
unsigned int GLCanvas3DManager::get_volumes_count(wxGLCanvas* canvas) const
|
2018-05-14 12:14:19 +00:00
|
|
|
{
|
2018-06-11 11:48:02 +00:00
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->get_volumes_count() : 0;
|
2018-05-14 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 12:08:59 +00:00
|
|
|
void GLCanvas3DManager::reset_volumes(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->reset_volumes();
|
|
|
|
}
|
|
|
|
|
2018-05-25 07:03:55 +00:00
|
|
|
void GLCanvas3DManager::deselect_volumes(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->deselect_volumes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::select_volume(wxGLCanvas* canvas, unsigned int id)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->select_volume(id);
|
|
|
|
}
|
|
|
|
|
2018-06-08 07:40:00 +00:00
|
|
|
void GLCanvas3DManager::update_volumes_selection(wxGLCanvas* canvas, const std::vector<int>& selections)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->update_volumes_selection(selections);
|
|
|
|
}
|
|
|
|
|
2018-07-23 08:16:56 +00:00
|
|
|
int GLCanvas3DManager::check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config) const
|
2018-06-11 11:48:02 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->check_volumes_outside_state(config) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLCanvas3DManager::move_volume_up(wxGLCanvas* canvas, unsigned int id)
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->move_volume_up(id) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLCanvas3DManager::move_volume_down(wxGLCanvas* canvas, unsigned int id)
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->move_volume_down(id) : false;
|
|
|
|
}
|
|
|
|
|
2018-06-08 07:40:00 +00:00
|
|
|
void GLCanvas3DManager::set_objects_selections(wxGLCanvas* canvas, const std::vector<int>& selections)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_objects_selections(selections);
|
|
|
|
}
|
|
|
|
|
2018-05-28 13:23:01 +00:00
|
|
|
void GLCanvas3DManager::set_config(wxGLCanvas* canvas, DynamicPrintConfig* config)
|
2018-05-23 09:14:49 +00:00
|
|
|
{
|
2018-05-28 13:23:01 +00:00
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_config(config);
|
2018-05-23 09:14:49 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 13:23:01 +00:00
|
|
|
void GLCanvas3DManager::set_print(wxGLCanvas* canvas, Print* print)
|
2018-05-23 09:14:49 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
2018-05-28 13:23:01 +00:00
|
|
|
it->second->set_print(print);
|
2018-05-23 09:14:49 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 09:18:28 +00:00
|
|
|
void GLCanvas3DManager::set_model(wxGLCanvas* canvas, Model* model)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_model(model);
|
|
|
|
}
|
|
|
|
|
2018-05-14 12:14:19 +00:00
|
|
|
void GLCanvas3DManager::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_bed_shape(shape);
|
|
|
|
}
|
|
|
|
|
2018-05-15 13:38:25 +00:00
|
|
|
void GLCanvas3DManager::set_auto_bed_shape(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_auto_bed_shape();
|
|
|
|
}
|
|
|
|
|
2018-05-18 11:02:47 +00:00
|
|
|
BoundingBoxf3 GLCanvas3DManager::get_volumes_bounding_box(wxGLCanvas* canvas)
|
2018-05-15 09:07:32 +00:00
|
|
|
{
|
2018-05-18 11:02:47 +00:00
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->volumes_bounding_box() : BoundingBoxf3();
|
2018-05-15 09:07:32 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 11:02:47 +00:00
|
|
|
void GLCanvas3DManager::set_axes_length(wxGLCanvas* canvas, float length)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_axes_length(length);
|
2018-05-14 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 09:05:48 +00:00
|
|
|
void GLCanvas3DManager::set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_cutting_plane(z, polygons);
|
|
|
|
}
|
|
|
|
|
2018-06-06 10:36:52 +00:00
|
|
|
void GLCanvas3DManager::set_color_by(wxGLCanvas* canvas, const std::string& value)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_color_by(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::set_select_by(wxGLCanvas* canvas, const std::string& value)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_select_by(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::set_drag_by(wxGLCanvas* canvas, const std::string& value)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_drag_by(value);
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:08:59 +00:00
|
|
|
bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->is_layers_editing_enabled() : false;
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:28:24 +00:00
|
|
|
bool GLCanvas3DManager::is_layers_editing_allowed(wxGLCanvas* canvas) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->is_layers_editing_allowed() : false;
|
|
|
|
}
|
|
|
|
|
2018-06-04 12:28:59 +00:00
|
|
|
bool GLCanvas3DManager::is_shader_enabled(wxGLCanvas* canvas) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->is_shader_enabled() : false;
|
|
|
|
}
|
|
|
|
|
2018-06-08 07:40:00 +00:00
|
|
|
bool GLCanvas3DManager::is_reload_delayed(wxGLCanvas* canvas) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->is_reload_delayed() : false;
|
|
|
|
}
|
|
|
|
|
2018-05-25 12:05:08 +00:00
|
|
|
void GLCanvas3DManager::enable_layers_editing(wxGLCanvas* canvas, bool enable)
|
2018-05-23 13:35:11 +00:00
|
|
|
{
|
2018-05-25 12:05:08 +00:00
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_layers_editing(enable);
|
2018-05-23 13:35:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 12:40:09 +00:00
|
|
|
void GLCanvas3DManager::enable_warning_texture(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_warning_texture(enable);
|
|
|
|
}
|
|
|
|
|
2018-05-21 12:57:43 +00:00
|
|
|
void GLCanvas3DManager::enable_legend_texture(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_legend_texture(enable);
|
|
|
|
}
|
|
|
|
|
2018-05-22 07:02:42 +00:00
|
|
|
void GLCanvas3DManager::enable_picking(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_picking(enable);
|
|
|
|
}
|
|
|
|
|
2018-05-31 11:51:50 +00:00
|
|
|
void GLCanvas3DManager::enable_moving(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_moving(enable);
|
|
|
|
}
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
void GLCanvas3DManager::enable_gizmos(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_gizmos(enable);
|
|
|
|
}
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
void GLCanvas3DManager::enable_toolbar(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_toolbar(enable);
|
|
|
|
}
|
|
|
|
|
2018-05-23 07:57:44 +00:00
|
|
|
void GLCanvas3DManager::enable_shader(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_shader(enable);
|
|
|
|
}
|
|
|
|
|
2018-06-05 08:56:55 +00:00
|
|
|
void GLCanvas3DManager::enable_force_zoom_to_bed(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_force_zoom_to_bed(enable);
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:38:39 +00:00
|
|
|
void GLCanvas3DManager::enable_dynamic_background(wxGLCanvas* canvas, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_dynamic_background(enable);
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:35:11 +00:00
|
|
|
void GLCanvas3DManager::allow_multisample(wxGLCanvas* canvas, bool allow)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->allow_multisample(allow);
|
|
|
|
}
|
|
|
|
|
2018-07-23 11:49:48 +00:00
|
|
|
void GLCanvas3DManager::enable_toolbar_item(wxGLCanvas* canvas, const std::string& name, bool enable)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->enable_toolbar_item(name, enable);
|
|
|
|
}
|
2018-07-27 10:08:33 +00:00
|
|
|
|
|
|
|
bool GLCanvas3DManager::is_toolbar_item_pressed(wxGLCanvas* canvas, const std::string& name) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->is_toolbar_item_pressed(name) : false;
|
|
|
|
}
|
2018-07-23 11:49:48 +00:00
|
|
|
|
2018-05-15 08:32:38 +00:00
|
|
|
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->zoom_to_bed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::zoom_to_volumes(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->zoom_to_volumes();
|
|
|
|
}
|
|
|
|
|
2018-05-15 09:30:11 +00:00
|
|
|
void GLCanvas3DManager::select_view(wxGLCanvas* canvas, const std::string& direction)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->select_view(direction);
|
|
|
|
}
|
|
|
|
|
2018-05-29 13:36:09 +00:00
|
|
|
void GLCanvas3DManager::set_viewport_from_scene(wxGLCanvas* canvas, wxGLCanvas* other)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator other_it = _get_canvas(other);
|
|
|
|
if (other_it != m_canvases.end())
|
|
|
|
it->second->set_viewport_from_scene(*other_it->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 13:07:06 +00:00
|
|
|
void GLCanvas3DManager::update_volumes_colors_by_extruder(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->update_volumes_colors_by_extruder();
|
|
|
|
}
|
|
|
|
|
2018-06-19 07:46:26 +00:00
|
|
|
void GLCanvas3DManager::update_gizmos_data(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->update_gizmos_data();
|
|
|
|
}
|
|
|
|
|
2018-05-29 11:54:34 +00:00
|
|
|
void GLCanvas3DManager::render(wxGLCanvas* canvas) const
|
2018-05-23 13:35:11 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
2018-06-04 10:26:39 +00:00
|
|
|
it->second->render();
|
2018-05-18 11:02:47 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 13:42:34 +00:00
|
|
|
std::vector<double> GLCanvas3DManager::get_current_print_zs(wxGLCanvas* canvas, bool active_only) const
|
|
|
|
{
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->get_current_print_zs(active_only) : std::vector<double>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::set_toolpaths_range(wxGLCanvas* canvas, double low, double high)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->set_toolpaths_range(low, high);
|
|
|
|
}
|
|
|
|
|
2018-06-06 08:16:58 +00:00
|
|
|
std::vector<int> GLCanvas3DManager::load_object(wxGLCanvas* canvas, const ModelObject* model_object, int obj_idx, std::vector<int> instance_idxs)
|
|
|
|
{
|
|
|
|
if (model_object == nullptr)
|
|
|
|
return std::vector<int>();
|
|
|
|
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
|
|
|
return (it != m_canvases.end()) ? it->second->load_object(*model_object, obj_idx, instance_idxs) : std::vector<int>();
|
|
|
|
}
|
|
|
|
|
2018-06-07 07:22:19 +00:00
|
|
|
std::vector<int> GLCanvas3DManager::load_object(wxGLCanvas* canvas, const Model* model, int obj_idx)
|
2018-06-06 08:16:58 +00:00
|
|
|
{
|
|
|
|
if (model == nullptr)
|
|
|
|
return std::vector<int>();
|
|
|
|
|
|
|
|
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
2018-06-07 07:22:19 +00:00
|
|
|
return (it != m_canvases.end()) ? it->second->load_object(*model, obj_idx) : std::vector<int>();
|
2018-06-06 08:16:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 07:40:00 +00:00
|
|
|
void GLCanvas3DManager::reload_scene(wxGLCanvas* canvas, bool force)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->reload_scene(force);
|
|
|
|
}
|
|
|
|
|
2018-07-24 11:39:17 +00:00
|
|
|
void GLCanvas3DManager::load_gcode_preview(wxGLCanvas* canvas, const GCodePreviewData* preview_data, const std::vector<std::string>& str_tool_colors)
|
2018-06-05 12:09:36 +00:00
|
|
|
{
|
2018-07-24 11:39:17 +00:00
|
|
|
if (preview_data == nullptr)
|
2018-06-05 12:09:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
2018-07-24 11:39:17 +00:00
|
|
|
it->second->load_gcode_preview(*preview_data, str_tool_colors);
|
2018-06-05 12:09:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 11:39:17 +00:00
|
|
|
void GLCanvas3DManager::load_preview(wxGLCanvas* canvas, const std::vector<std::string>& str_tool_colors)
|
2018-06-05 12:09:36 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
2018-07-24 11:39:17 +00:00
|
|
|
it->second->load_preview(str_tool_colors);
|
2018-06-05 08:56:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 11:18:19 +00:00
|
|
|
void GLCanvas3DManager::reset_legend_texture()
|
|
|
|
{
|
|
|
|
for (CanvasesMap::value_type& canvas : m_canvases)
|
|
|
|
{
|
|
|
|
if (canvas.second != nullptr)
|
|
|
|
canvas.second->reset_legend_texture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 07:50:01 +00:00
|
|
|
void GLCanvas3DManager::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_viewport_changed_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-05-31 11:51:50 +00:00
|
|
|
void GLCanvas3DManager::register_on_double_click_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_double_click_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_right_click_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_right_click_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-08 09:37:07 +00:00
|
|
|
void GLCanvas3DManager::register_on_select_object_callback(wxGLCanvas* canvas, void* callback)
|
2018-05-31 11:51:50 +00:00
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
2018-06-08 09:37:07 +00:00
|
|
|
it->second->register_on_select_object_callback(callback);
|
2018-05-31 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:04:59 +00:00
|
|
|
void GLCanvas3DManager::register_on_model_update_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_model_update_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-07 07:22:19 +00:00
|
|
|
void GLCanvas3DManager::register_on_remove_object_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_remove_object_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_arrange_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_arrange_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_rotate_object_left_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_rotate_object_left_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_rotate_object_right_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_rotate_object_right_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_scale_object_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_scale_object_uniformly_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_increase_objects_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_increase_objects_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_decrease_objects_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_decrease_objects_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-07 09:18:28 +00:00
|
|
|
void GLCanvas3DManager::register_on_instance_moved_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_instance_moved_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_wipe_tower_moved_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_wipe_tower_moved_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_on_enable_action_buttons_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_enable_action_buttons_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:07:17 +00:00
|
|
|
void GLCanvas3DManager::register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_gizmo_scale_uniformly_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-19 07:46:26 +00:00
|
|
|
void GLCanvas3DManager::register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_gizmo_rotate_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-06-22 09:19:38 +00:00
|
|
|
void GLCanvas3DManager::register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_on_update_geometry_info_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-07-27 10:08:33 +00:00
|
|
|
void GLCanvas3DManager::register_action_add_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_add_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_delete_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_delete_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_deleteall_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_deleteall_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_arrange_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_arrange_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_more_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_more_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_fewer_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_fewer_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_split_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_split_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_cut_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_cut_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_settings_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_settings_callback(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLCanvas3DManager::register_action_layersediting_callback(wxGLCanvas* canvas, void* callback)
|
|
|
|
{
|
|
|
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
|
|
|
if (it != m_canvases.end())
|
|
|
|
it->second->register_action_layersediting_callback(callback);
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
|
|
|
|
{
|
|
|
|
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLCanvas3DManager::CanvasesMap::const_iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas) const
|
|
|
|
{
|
|
|
|
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
|
|
|
}
|
|
|
|
|
2018-06-04 11:15:28 +00:00
|
|
|
bool GLCanvas3DManager::_init(GLCanvas3D& canvas)
|
|
|
|
{
|
|
|
|
if (!m_gl_initialized)
|
|
|
|
init_gl();
|
|
|
|
|
|
|
|
return canvas.init(m_use_VBOs, m_use_legacy_opengl);
|
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|