From b3c09a9254a7b05ea03c2bcd4fbcf78ee5ec8766 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 3 Oct 2018 16:18:23 +0200 Subject: [PATCH 1/3] Fixed object position after loading --- src/slic3r/GUI/GLCanvas3D.cpp | 1 + src/slic3r/GUI/Plater.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 328d5af39..2414e8c9b 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -315,6 +315,7 @@ bool GLCanvas3D::Bed::set_shape(const Pointfs& shape) if (m_shape == shape && m_type == new_type) // No change, no need to update the UI. return false; + m_shape = shape; m_type = new_type; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9778df45c..5ac4b2d84 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -420,7 +420,8 @@ struct Plater::priv void update_ui_from_settings(); ProgressStatusBar* statusbar(); std::string get_config(const std::string &key) const; - BoundingBox bed_shape_bb() const; + BoundingBoxf bed_shape_bb() const; + BoundingBox scaled_bed_shape_bb() const; std::vector load_files(const std::vector &input_files); std::vector load_model_objects(const ModelObjectPtrs &model_objects); @@ -569,7 +570,7 @@ void Plater::priv::update(bool force_autocenter) // auto *bed_shape_opt = config->opt("bed_shape"); // const auto bed_shape = Slic3r::Polygon::new_scale(bed_shape_opt->values); // const BoundingBox bed_shape_bb = bed_shape.bounding_box(); - const Vec2d bed_center = bed_shape_bb().center().cast(); + const Vec2d& bed_center = bed_shape_bb().center(); model.center_instances_around_point(bed_center); } @@ -605,7 +606,13 @@ std::string Plater::priv::get_config(const std::string &key) const return wxGetApp().app_config->get(key); } -BoundingBox Plater::priv::bed_shape_bb() const +BoundingBoxf Plater::priv::bed_shape_bb() const +{ + BoundingBox bb = scaled_bed_shape_bb(); + return BoundingBoxf(unscale(bb.min), unscale(bb.max)); +} + +BoundingBox Plater::priv::scaled_bed_shape_bb() const { const auto *bed_shape_opt = config->opt("bed_shape"); const auto bed_shape = Slic3r::Polygon::new_scale(bed_shape_opt->values); @@ -732,7 +739,7 @@ Vec3crd to_3d(const Point &p, coord_t z) { return Vec3crd(p(0), p(1), z); } std::vector Plater::priv::load_model_objects(const ModelObjectPtrs &model_objects) { - const BoundingBox bed_shape = bed_shape_bb(); + const BoundingBoxf bed_shape = bed_shape_bb(); const Vec3d bed_center = to_3d(bed_shape.center().cast(), 0.0); const Vec3d bed_size = to_3d(bed_shape.size().cast(), 1.0); From f31cf684cb8ca19ec723218753fc346490ce0701 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 3 Oct 2018 16:27:02 +0200 Subject: [PATCH 2/3] Tab preset & value change events --- src/slic3r/GUI/Event.hpp | 3 ++ src/slic3r/GUI/MainFrame.cpp | 87 ++++++++++++++++++++++-------------- src/slic3r/GUI/MainFrame.hpp | 3 ++ src/slic3r/GUI/Plater.cpp | 21 +++++---- src/slic3r/GUI/Tab.cpp | 52 ++++++++++----------- src/slic3r/GUI/Tab.hpp | 16 +++---- 6 files changed, 102 insertions(+), 80 deletions(-) diff --git a/src/slic3r/GUI/Event.hpp b/src/slic3r/GUI/Event.hpp index 63800fa00..2ae9fd154 100644 --- a/src/slic3r/GUI/Event.hpp +++ b/src/slic3r/GUI/Event.hpp @@ -14,6 +14,7 @@ struct SimpleEvent : public wxEvent { SimpleEvent(wxEventType type, wxObject* origin = nullptr) : wxEvent(0, type) { + m_propagationLevel = wxEVENT_PROPAGATE_MAX; SetEventObject(origin); } @@ -30,6 +31,7 @@ template struct ArrayEvent : public wxEvent ArrayEvent(wxEventType type, std::array data, wxObject* origin = nullptr) : wxEvent(0, type), data(std::move(data)) { + m_propagationLevel = wxEVENT_PROPAGATE_MAX; SetEventObject(origin); } @@ -45,6 +47,7 @@ template struct ArrayEvent : public wxEvent ArrayEvent(wxEventType type, T data, wxObject* origin = nullptr) : wxEvent(0, type), data(std::move(data)) { + m_propagationLevel = wxEVENT_PROPAGATE_MAX; SetEventObject(origin); } diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 1aba0f7c7..d24a2d5df 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Tab.hpp" #include "PresetBundle.hpp" @@ -168,40 +169,10 @@ void MainFrame::init_tabpanel() // m_config->save(Slic3r::GUI::autosave) ; // }); - // The following event is emited by the C++ Tab implementation on preset selection, + // The following event is emited by Tab on preset selection, // or when the preset's "modified" status changes. -// EVT_COMMAND($self, -1, $PRESETS_CHANGED_EVENT, sub { -// my($self, $event) = @_; -// auto tab_name = event->GetString; -// -// Tab* tab = Slic3r::GUI::get_preset_tab(tab_name); -// if (m_plater) { -// // Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs. -// auto presets = tab->get_presets(); -// if (presets){ -// auto reload_dependent_tabs = tab->get_dependent_tabs(); -// m_plater->update_presets(tab_name, reload_dependent_tabs, presets); -// m_plater->{"selected_item_$tab_name"} = tab->get_selected_preset_item(); -// if (tab_name == "printer") { -// // Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors. -// std::vector tab_names_other = { "print", "filament", "sla_materialprinter" }; -// for (const auto tab_name_other : tab_names_other) { -// Tab* cur_tab = m_options_tabs[tab_name_other]; -// // If the printer tells us that the print or filament preset has been switched or invalidated, -// // refresh the print or filament tab page.Otherwise just refresh the combo box. -// if (reload_dependent_tabs.empty() || -// find(reload_dependent_tabs.begin(), reload_dependent_tabs.end(), tab_name_other) == -// reload_dependent_tabs.end() ) -// cur_tab->update_tab_ui(); -// else -// cur_tab->load_current_preset(); -// -// } -// } -// m_plater->on_config_change(tab->get_config()); -// } -// } -// }); + Bind(EVT_TAB_PRESETS_CHANGED, &MainFrame::on_presets_changed, this); + // The following event is emited by the C++ Tab implementation on object selection change. // EVT_COMMAND($self, -1, $OBJECT_SELECTION_CHANGED_EVENT, sub { @@ -791,6 +762,56 @@ wxMenuItem* MainFrame::append_menu_item(wxMenu* menu, return item; } +void MainFrame::on_presets_changed(SimpleEvent &event) +{ + auto *tab = dynamic_cast(event.GetEventObject()); + wxASSERT(tab != nullptr); + if (tab == nullptr) { + return; + } + + // Update preset combo boxes(Print settings, Filament, Material, Printer) from their respective tabs. + auto presets = tab->get_presets(); + if (presets) { + auto reload_dependent_tabs = tab->get_dependent_tabs(); + + // FIXME: The preset type really should be a property of Tab instead + Slic3r::Preset::Type preset_type; + if (tab == m_options_tabs["print"]) { preset_type = Slic3r::Preset::TYPE_PRINT; } + else if (tab == m_options_tabs["filament"]) { preset_type = Slic3r::Preset::TYPE_FILAMENT; } + else if (tab == m_options_tabs["sla_material"]) { preset_type = Slic3r::Preset::TYPE_SLA_MATERIAL; } + else if (tab == m_options_tabs["printer"]) { preset_type = Slic3r::Preset::TYPE_PRINTER; } + else { + wxASSERT(false); + return; + } + + m_plater->sidebar().update_presets(preset_type); + + // XXX: ??? + // m_plater->{"selected_item_$tab_name"} = tab->get_selected_preset_item(); + + if (preset_type == Slic3r::Preset::TYPE_PRINTER) { + // Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors. + // XXX: Do this in a more C++ way + std::vector tab_names_other = { "print", "filament", "sla_material" }; + for (const auto tab_name_other : tab_names_other) { + Tab* cur_tab = m_options_tabs[tab_name_other]; + // If the printer tells us that the print or filament preset has been switched or invalidated, + // refresh the print or filament tab page.Otherwise just refresh the combo box. + if (reload_dependent_tabs.empty() || + find(reload_dependent_tabs.begin(), reload_dependent_tabs.end(), tab_name_other) == + reload_dependent_tabs.end() ) + cur_tab->update_tab_ui(); + else + cur_tab->load_current_preset(); + } + } + // XXX: ? + // m_plater->on_config_change(tab->get_config()); + } +} + // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. void MainFrame::update_ui_from_settings() diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index f4c75de65..638c122e8 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -9,6 +9,7 @@ #include #include "Plater.hpp" +#include "Event.hpp" class wxMenuBar; class wxNotebook; @@ -64,6 +65,8 @@ class MainFrame : public wxFrame std::string get_base_name(const wxString full_name) const ; std::string get_dir_name(const wxString full_name) const ; + + void on_presets_changed(SimpleEvent&); public: MainFrame() {} MainFrame(const bool no_plater, const bool loaded); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5ac4b2d84..bbbdba084 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -310,38 +310,37 @@ Sidebar::~Sidebar() {} void Sidebar::update_presets(Preset::Type preset_type) { - // TODO: wxApp access - switch (preset_type) { case Preset::TYPE_FILAMENT: - // my $choice_idx = 0; if (p->combos_filament.size() == 1) { // Single filament printer, synchronize the filament presets. - // wxTheApp->{preset_bundle}->set_filament_preset(0, wxTheApp->{preset_bundle}->filament->get_selected_preset->name); + const std::string &name = wxGetApp().preset_bundle->filaments.get_selected_preset().name; + wxGetApp().preset_bundle->set_filament_preset(0, name); } for (size_t i = 0; i < p->combos_filament.size(); i++) { - // wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice); + wxGetApp().preset_bundle->update_platter_filament_ui(i, p->combos_filament[i]); } + break; case Preset::TYPE_PRINT: - // wxTheApp->{preset_bundle}->print->update_platter_ui($choosers[0]); + wxGetApp().preset_bundle->prints.update_platter_ui(p->combo_print); break; case Preset::TYPE_SLA_MATERIAL: - // wxTheApp->{preset_bundle}->sla_material->update_platter_ui($choosers[0]); + wxGetApp().preset_bundle->sla_materials.update_platter_ui(p->combo_sla_material); break; case Preset::TYPE_PRINTER: // Update the print choosers to only contain the compatible presets, update the dirty flags. - // wxTheApp->{preset_bundle}->print->update_platter_ui($self->{preset_choosers}{print}->[0]); + wxGetApp().preset_bundle->prints.update_platter_ui(p->combo_print); // Update the printer choosers, update the dirty flags. - // wxTheApp->{preset_bundle}->printer->update_platter_ui($choosers[0]); + wxGetApp().preset_bundle->printers.update_platter_ui(p->combo_printer); // Update the filament choosers to only contain the compatible presets, update the color preview, // update the dirty flags. for (size_t i = 0; i < p->combos_filament.size(); i++) { - // wxTheApp->{preset_bundle}->update_platter_filament_ui($choice_idx, $choice); + wxGetApp().preset_bundle->update_platter_filament_ui(i, p->combos_filament[i]); } break; @@ -349,7 +348,7 @@ void Sidebar::update_presets(Preset::Type preset_type) } // Synchronize config.ini with the current selections. - // wxTheApp->{preset_bundle}->export_selections(wxTheApp->{app_config}); + wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e4a1f5933..1f29fb5bb 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -35,6 +35,11 @@ namespace GUI { static wxString dots("…", wxConvUTF8); + +wxDEFINE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent); +wxDEFINE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent); + + // sub new void Tab::create_preset_tab(PresetBundle *preset_bundle) { @@ -662,30 +667,27 @@ void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bo update(); } -extern wxFrame *g_wxMainFrame; - void Tab::on_value_change(const std::string& opt_key, const boost::any& value) { - if (m_event_value_change > 0) { - wxCommandEvent event(m_event_value_change); - std::string str_out = opt_key + " " + m_name; - event.SetString(str_out); - if (opt_key == "extruders_count") - { - int val = boost::any_cast(value); - event.SetInt(val); - } - - if (opt_key == "printer_technology") - { - int val = boost::any_cast(value); - event.SetInt(val); - g_wxMainFrame->ProcessWindowEvent(event); - return; - } - - g_wxMainFrame->ProcessWindowEvent(event); + wxCommandEvent event(EVT_TAB_VALUE_CHANGED); + event.SetEventObject(this); + event.SetString(opt_key); + if (opt_key == "extruders_count") + { + int val = boost::any_cast(value); + event.SetInt(val); } + + if (opt_key == "printer_technology") + { + int val = boost::any_cast(value); + event.SetInt(val); + wxPostEvent(this, event); + return; + } + + wxPostEvent(this, event); + if (opt_key == "fill_density") { boost::any val = get_optgroup(ogFrequentlyChangingParameters)->get_config_value(*m_config, opt_key); @@ -734,11 +736,9 @@ void Tab::update_wiping_button_visibility() { // to uddate number of "filament" selection boxes when the number of extruders change. void Tab::on_presets_changed() { - if (m_event_presets_changed > 0) { - wxCommandEvent event(m_event_presets_changed); - event.SetString(m_name); - g_wxMainFrame->ProcessWindowEvent(event); - } + wxCommandEvent event(EVT_TAB_PRESETS_CHANGED); + event.SetEventObject(this); + wxPostEvent(this, event); update_preset_description_line(); } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index afdf2008b..f105cc950 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -25,14 +25,15 @@ #include #include #include +#include #include #include #include #include "BedShapeDialog.hpp" +#include "Event.hpp" -//!enum { ID_TAB_TREE = wxID_HIGHEST + 1 }; namespace Slic3r { namespace GUI { @@ -96,7 +97,10 @@ protected: const wxColour* m_item_color; }; -// Slic3r::GUI::Tab; + +wxDECLARE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent); +wxDECLARE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent); + using PageShp = std::shared_ptr; class Tab: public wxPanel @@ -178,10 +182,6 @@ protected: t_icon_descriptions m_icon_descriptions = {}; - // The two following two event IDs are generated at Plater.pm by calling Wx::NewEventType. - wxEventType m_event_value_change = 0; - wxEventType m_event_presets_changed = 0; - bool m_is_modified_values{ false }; bool m_is_nonsys_values{ true }; bool m_postpone_update_ui {false}; @@ -211,10 +211,6 @@ public: wxString title() const { return m_title; } std::string name() const { return m_name; } - // Set the events to the callbacks posted to the main frame window (currently implemented in Perl). - void set_event_value_change(wxEventType evt) { m_event_value_change = evt; } - void set_event_presets_changed(wxEventType evt) { m_event_presets_changed = evt; } - void create_preset_tab(PresetBundle *preset_bundle); void load_current_preset(); void rebuild_page_tree(bool tree_sel_change_event = false); From 96745e12d764f957884032ddf24f64dcd3303d89 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 4 Oct 2018 10:41:11 +0200 Subject: [PATCH 3/3] Use an unique opengl context --- src/libslic3r/Technologies.hpp | 2 ++ src/slic3r/GUI/GLCanvas3D.cpp | 41 +++++++++++++++++++++++++++- src/slic3r/GUI/GLCanvas3D.hpp | 11 +++++++- src/slic3r/GUI/GLCanvas3DManager.cpp | 28 +++++++++++++++++++ src/slic3r/GUI/GLCanvas3DManager.hpp | 6 ++++ src/slic3r/GUI/GLToolbar.cpp | 4 +-- src/slic3r/GUI/GUI_Preview.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 4 +-- 8 files changed, 91 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 14e2a8bde..9b9067af3 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -10,6 +10,8 @@ #define ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM (1 && ENABLE_1_42_0) // Add double click on gizmo grabbers to reset transformation components to their default value #define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0) +// Uses a unique opengl context +#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 2414e8c9b..d78fb9c1f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1956,7 +1956,6 @@ wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); - GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) , m_context(nullptr) @@ -1986,7 +1985,9 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) { if (m_canvas != nullptr) { +#if !ENABLE_USE_UNIQUE_GLCONTEXT m_context = new wxGLContext(m_canvas); +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_timer = new wxTimer(m_canvas); } } @@ -2001,11 +2002,13 @@ GLCanvas3D::~GLCanvas3D() m_timer = nullptr; } +#if !ENABLE_USE_UNIQUE_GLCONTEXT if (m_context != nullptr) { delete m_context; m_context = nullptr; } +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT } void GLCanvas3D::post_event(wxEvent &&event) @@ -2095,6 +2098,7 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) return true; } +#if !ENABLE_USE_UNIQUE_GLCONTEXT bool GLCanvas3D::set_current() { if ((m_canvas != nullptr) && (m_context != nullptr)) @@ -2102,6 +2106,7 @@ bool GLCanvas3D::set_current() return false; } +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT void GLCanvas3D::set_as_dirty() { @@ -2117,9 +2122,11 @@ void GLCanvas3D::reset_volumes() { if (!m_volumes.empty()) { +#if !ENABLE_USE_UNIQUE_GLCONTEXT // ensures this canvas is current if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_volumes.release_geometry(); m_volumes.clear(); @@ -2514,7 +2521,11 @@ void GLCanvas3D::render() return; // ensures this canvas is current and initialized +#if ENABLE_USE_UNIQUE_GLCONTEXT + if (!_set_current() || !_3DScene::init(m_canvas)) +#else if (!set_current() || !_3DScene::init(m_canvas)) +#endif // ENABLE_USE_UNIQUE_GLCONTEXT return; if (m_force_zoom_to_bed_enabled) @@ -2619,9 +2630,11 @@ void GLCanvas3D::reload_scene(bool force) reset_volumes(); +#if !ENABLE_USE_UNIQUE_GLCONTEXT // ensures this canvas is current if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT set_bed_shape(dynamic_cast(m_config->option("bed_shape"))->values); @@ -2709,9 +2722,11 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const { if ((m_canvas != nullptr) && (m_print != nullptr)) { +#if !ENABLE_USE_UNIQUE_GLCONTEXT // ensures that this canvas is current if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT if (m_volumes.empty()) { @@ -3503,8 +3518,10 @@ Point GLCanvas3D::get_local_mouse_position() const void GLCanvas3D::reset_legend_texture() { +#if !ENABLE_USE_UNIQUE_GLCONTEXT if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_legend_texture.reset(); } @@ -3650,13 +3667,27 @@ bool GLCanvas3D::_init_toolbar() return true; } +#if ENABLE_USE_UNIQUE_GLCONTEXT +bool GLCanvas3D::_set_current() +{ + if ((m_canvas != nullptr) && (m_context != nullptr)) + return m_canvas->SetCurrent(*m_context); + + return false; +} +#endif ENABLE_USE_UNIQUE_GLCONTEXT + void GLCanvas3D::_resize(unsigned int w, unsigned int h) { if ((m_canvas == nullptr) && (m_context == nullptr)) return; // ensures that this canvas is current +#if ENABLE_USE_UNIQUE_GLCONTEXT + _set_current(); +#else set_current(); +#endif // ENABLE_USE_UNIQUE_GLCONTEXT ::glViewport(0, 0, w, h); ::glMatrixMode(GL_PROJECTION); @@ -4315,9 +4346,11 @@ int GLCanvas3D::_get_first_selected_volume_id(int object_id) const void GLCanvas3D::_load_print_toolpaths() { +#if !ENABLE_USE_UNIQUE_GLCONTEXT // ensures this canvas is current if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT if (m_print == nullptr) return; @@ -5427,24 +5460,30 @@ std::vector GLCanvas3D::_parse_colors(const std::vector& col void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors) { +#if !ENABLE_USE_UNIQUE_GLCONTEXT if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_legend_texture.generate(preview_data, tool_colors); } void GLCanvas3D::_generate_warning_texture(const std::string& msg) { +#if !ENABLE_USE_UNIQUE_GLCONTEXT if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_warning_texture.generate(msg); } void GLCanvas3D::_reset_warning_texture() { +#if !ENABLE_USE_UNIQUE_GLCONTEXT if (!set_current()) return; +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT m_warning_texture.reset(); } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 04da72995..59893368e 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -552,11 +552,17 @@ public: GLCanvas3D(wxGLCanvas* canvas); ~GLCanvas3D(); - wxGLCanvas* widget() { return m_canvas; } +#if ENABLE_USE_UNIQUE_GLCONTEXT + void set_context(wxGLContext* context) { m_context = context; } +#endif // ENABLE_USE_UNIQUE_GLCONTEXT + + wxGLCanvas* get_wxglcanvas() { return m_canvas; } bool init(bool useVBOs, bool use_legacy_opengl); +#if !ENABLE_USE_UNIQUE_GLCONTEXT bool set_current(); +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT void set_as_dirty(); @@ -668,6 +674,9 @@ private: bool _init_toolbar(); +#if ENABLE_USE_UNIQUE_GLCONTEXT + bool _set_current(); +#endif // ENABLE_USE_UNIQUE_GLCONTEXT void _resize(unsigned int w, unsigned int h); BoundingBoxf3 _max_bounding_box() const; diff --git a/src/slic3r/GUI/GLCanvas3DManager.cpp b/src/slic3r/GUI/GLCanvas3DManager.cpp index 41f5ef22a..8720caba5 100644 --- a/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -113,13 +113,29 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten GLCanvas3DManager::EMultisampleState GLCanvas3DManager::s_multisample = GLCanvas3DManager::MS_Unknown; GLCanvas3DManager::GLCanvas3DManager() +#if ENABLE_USE_UNIQUE_GLCONTEXT + : m_context(nullptr) + , m_current(nullptr) +#else : m_current(nullptr) +#endif // ENABLE_USE_UNIQUE_GLCONTEXT , m_gl_initialized(false) , m_use_legacy_opengl(false) , m_use_VBOs(false) { } +#if ENABLE_USE_UNIQUE_GLCONTEXT +GLCanvas3DManager::~GLCanvas3DManager() +{ + if (m_context != nullptr) + { + delete m_context; + m_context = nullptr; + } +} +#endif // ENABLE_USE_UNIQUE_GLCONTEXT + bool GLCanvas3DManager::add(wxGLCanvas* canvas) { if (canvas == nullptr) @@ -133,6 +149,18 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas) return false; canvas3D->bind_event_handlers(); + +#if ENABLE_USE_UNIQUE_GLCONTEXT + if (m_context == nullptr) + { + m_context = new wxGLContext(canvas); + if (m_context == nullptr) + return false; + } + + canvas3D->set_context(m_context); +#endif // ENABLE_USE_UNIQUE_GLCONTEXT + m_canvases.insert(CanvasesMap::value_type(canvas, canvas3D)); return true; diff --git a/src/slic3r/GUI/GLCanvas3DManager.hpp b/src/slic3r/GUI/GLCanvas3DManager.hpp index 1a3036f9f..960bb6d2a 100644 --- a/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -52,6 +52,9 @@ class GLCanvas3DManager typedef std::map CanvasesMap; CanvasesMap m_canvases; +#if ENABLE_USE_UNIQUE_GLCONTEXT + wxGLContext* m_context; +#endif // ENABLE_USE_UNIQUE_GLCONTEXT wxGLCanvas* m_current; GLInfo m_gl_info; bool m_gl_initialized; @@ -61,6 +64,9 @@ class GLCanvas3DManager public: GLCanvas3DManager(); +#if ENABLE_USE_UNIQUE_GLCONTEXT + ~GLCanvas3DManager(); +#endif // ENABLE_USE_UNIQUE_GLCONTEXT bool add(wxGLCanvas* canvas); bool remove(wxGLCanvas* canvas); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index e1566e944..f2d882e22 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -339,13 +339,13 @@ void GLToolbar::do_action(unsigned int item_id) item->set_state(GLToolbarItem::Hover); m_parent.render(); - item->do_action(m_parent.widget()); + item->do_action(m_parent.get_wxglcanvas()); } else { item->set_state(GLToolbarItem::HoverPressed); m_parent.render(); - item->do_action(m_parent.widget()); + item->do_action(m_parent.get_wxglcanvas()); if (item->get_state() != GLToolbarItem::Disabled) { // the item may get disabled during the action, if not, set it back to hover state diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index e7b7f4c94..9c2898558 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -50,7 +50,7 @@ public: Preview(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data); virtual ~Preview(); - wxGLCanvas* get_canvas() { return m_canvas; } + wxGLCanvas* get_wxglcanvas() { return m_canvas; } void set_number_extruders(unsigned int number_extruders); void reset_gcode_preview_data(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index bbbdba084..c510258ab 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -520,7 +520,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : canvas3D->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this); canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); - preview->get_canvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); + preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); q->Bind(EVT_SLICING_COMPLETED, &priv::on_update_print_preview, this); q->Bind(EVT_PROCESS_COMPLETED, &priv::on_process_completed, this); @@ -893,7 +893,7 @@ void Plater::priv::on_action_add(SimpleEvent&) void Plater::priv::on_viewport_changed(SimpleEvent& evt) { wxObject* o = evt.GetEventObject(); - if (o == preview->get_canvas()) + if (o == preview->get_wxglcanvas()) preview->set_viewport_into_scene(canvas3D); else if (o == canvas3D) preview->set_viewport_from_scene(canvas3D);