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/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/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5a28ee5c0..b147ce989 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -317,6 +317,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; @@ -1957,7 +1958,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) @@ -1987,7 +1987,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); } } @@ -2002,11 +2004,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) @@ -2096,6 +2100,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)) @@ -2103,6 +2108,7 @@ bool GLCanvas3D::set_current() return false; } +#endif // !ENABLE_USE_UNIQUE_GLCONTEXT void GLCanvas3D::set_as_dirty() { @@ -2118,9 +2124,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(); @@ -2515,7 +2523,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) @@ -2620,9 +2632,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); @@ -2710,9 +2724,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()) { @@ -3504,8 +3520,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(); } @@ -3651,13 +3669,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); @@ -4316,9 +4348,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; @@ -5428,24 +5462,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 7c7430c7c..ab7544ed8 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -53,7 +53,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/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 1c52d2155..e2a4f9d54 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" @@ -154,40 +155,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 { @@ -793,6 +764,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 4063bd0c4..03b27a98b 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; @@ -71,6 +72,7 @@ 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&); Tab* get_tab(const std::string& name); public: diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 522dfb471..d76a0ca1b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -463,38 +463,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; @@ -502,7 +501,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); } ObjectManipulation* Sidebar::obj_manipul() @@ -623,7 +622,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); @@ -723,7 +723,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); @@ -751,7 +751,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); } @@ -787,7 +787,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); @@ -914,7 +920,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); @@ -1069,7 +1075,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); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 1e39e2a70..6b0b89eee 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -33,6 +33,12 @@ namespace Slic3r { namespace GUI { + +wxDEFINE_EVENT(EVT_TAB_VALUE_CHANGED, wxCommandEvent); +wxDEFINE_EVENT(EVT_TAB_PRESETS_CHANGED, SimpleEvent); + + +// sub new void Tab::create_preset_tab() { m_preset_bundle = wxGetApp().preset_bundle; @@ -659,31 +665,28 @@ void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bo update(); } -// extern wxFrame *g_wxMainFrame; // #ys_FIXME - 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);// #ys_FIXME - return; - } - -// g_wxMainFrame->ProcessWindowEvent(event);// #ys_FIXME + 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); + + auto og_freq_chng_params = wxGetApp().sidebar().og_freq_chng_params(); if (opt_key == "fill_density") { @@ -736,11 +739,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); // #ys_FIXME - } + 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 c9fb1764c..4c7f32e7e 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(); void load_current_preset(); void rebuild_page_tree(bool tree_sel_change_event = false);