From 6ff9021e040e9cc4ed7d20e5772600122f2af7de Mon Sep 17 00:00:00 2001 From: Enrico Turri <enricoturri@seznam.cz> Date: Tue, 6 Feb 2018 12:43:25 +0100 Subject: [PATCH] GCode Preview - Legend texture shown only when gcode is available --- lib/Slic3r/GUI/3DScene.pm | 32 ++++++++++++++++++------------ lib/Slic3r/GUI/Plater.pm | 2 ++ lib/Slic3r/GUI/Plater/3DPreview.pm | 3 +++ xs/src/slic3r/GUI/3DScene.cpp | 17 +++++++++++++++- xs/src/slic3r/GUI/3DScene.hpp | 6 ++++++ xs/src/slic3r/GUI/GUI.cpp | 9 ++++++--- xs/src/slic3r/GUI/wxExtensions.cpp | 12 +++-------- xs/src/slic3r/GUI/wxExtensions.hpp | 3 --- xs/xsp/GUI_3DScene.xsp | 7 ++++++- 9 files changed, 61 insertions(+), 30 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index daceb8c49..f567c2f72 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1605,23 +1605,25 @@ sub draw_legend { my $tex_id = Slic3r::GUI::_3DScene::get_legend_texture_id; if ($tex_id > 0) { - glDisable(GL_DEPTH_TEST); - glPushMatrix(); - glLoadIdentity(); - my $tex_w = Slic3r::GUI::_3DScene::get_legend_texture_width; my $tex_h = Slic3r::GUI::_3DScene::get_legend_texture_height; - - my ($cw, $ch) = $self->GetSizeWH; + if (($tex_w > 0) && ($tex_h > 0)) + { + glDisable(GL_DEPTH_TEST); + glPushMatrix(); + glLoadIdentity(); + + my ($cw, $ch) = $self->GetSizeWH; - my $l = (-0.5 * $cw) / $self->_zoom; - my $t = (0.5 * $ch) / $self->_zoom; - my $r = $l + $tex_w / $self->_zoom; - my $b = $t - $tex_h / $self->_zoom; - $self->_render_texture($tex_id, $l, $r, $b, $t); + my $l = (-0.5 * $cw) / $self->_zoom; + my $t = (0.5 * $ch) / $self->_zoom; + my $r = $l + $tex_w / $self->_zoom; + my $b = $t - $tex_h / $self->_zoom; + $self->_render_texture($tex_id, $l, $r, $b, $t); - glPopMatrix(); - glEnable(GL_DEPTH_TEST); + glPopMatrix(); + glEnable(GL_DEPTH_TEST); + } } } } @@ -2038,4 +2040,8 @@ sub set_toolpaths_range { $self->volumes->set_range($min_z, $max_z); } +sub reset_legend_texture { + Slic3r::GUI::_3DScene::reset_legend_texture(); +} + 1; diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 321bb7112..014aee53c 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1261,6 +1261,8 @@ sub reslice { $self->stop_background_process; # Rather perform one additional unnecessary update of the print object instead of skipping a pending async update. $self->async_apply_config; + # Reset gcode data + $self->{print}->clear_gcode_preview_data; $self->statusbar->SetCancelCallback(sub { $self->stop_background_process; $self->statusbar->SetStatusText("Slicing cancelled"); diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index af0cb16c8..9c3c95d1a 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -290,6 +290,9 @@ sub load_print { $self->set_z_range(0,0); $self->slider_low->Hide; $self->slider_high->Hide; + $self->{z_label_low}->SetLabel(""); + $self->{z_label_high}->SetLabel(""); + $self->canvas->reset_legend_texture(); $self->canvas->Refresh; # clears canvas return; } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 589a23e86..15e905ee4 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1229,6 +1229,11 @@ unsigned int _3DScene::LegendTexture::get_texture_height() const return m_tex_height; } +void _3DScene::LegendTexture::reset_texture() +{ + _destroy_texture(); +} + bool _3DScene::LegendTexture::_create_texture(const Print& print, const wxBitmap& bitmap) { if ((m_tex_width == 0) || (m_tex_height == 0)) @@ -1270,6 +1275,8 @@ void _3DScene::LegendTexture::_destroy_texture() { ::glDeleteTextures(1, &m_tex_id); m_tex_id = 0; + m_tex_height = 0; + m_tex_width = 0; } } @@ -1316,7 +1323,10 @@ void _3DScene::load_gcode_preview(const Print* print, GLVolumeCollection* volume _load_gcode_retractions(*print, *volumes, use_VBOs); _load_gcode_unretractions(*print, *volumes, use_VBOs); - _generate_legend_texture(*print); + if (volumes->empty()) + reset_legend_texture(); + else + _generate_legend_texture(*print); } _update_gcode_volumes_visibility(*print, *volumes); @@ -1337,6 +1347,11 @@ unsigned int _3DScene::get_legend_texture_height() return s_legend_texture.get_texture_height(); } +void _3DScene::reset_legend_texture() +{ + s_legend_texture.reset_texture(); +} + // Create 3D thick extrusion lines for a skirt and brim. // Adds a new Slic3r::GUI::3DScene::Volume to volumes. void _3DScene::_load_print_toolpaths( diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index ba1a9af71..4c73bdb7d 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -403,20 +403,26 @@ class _3DScene unsigned int get_texture_width() const; unsigned int get_texture_height() const; + void reset_texture(); + private: bool _create_texture(const Print& print, const wxBitmap& bitmap); void _destroy_texture(); }; static LegendTexture s_legend_texture; + public: static void _glew_init(); static void load_gcode_preview(const Print* print, GLVolumeCollection* volumes, bool use_VBOs); + static unsigned int get_legend_texture_id(); static unsigned int get_legend_texture_width(); static unsigned int get_legend_texture_height(); + static void reset_legend_texture(); + static void _load_print_toolpaths( const Print *print, GLVolumeCollection *volumes, diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 749ed0c69..775cfdcf6 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -191,13 +191,16 @@ void create_preset_tab(const char *name) void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value) { - wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup(-1); + if (comboCtrl == nullptr) + return; + + wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup; if (popup != nullptr) { comboCtrl->SetPopupControl(popup); popup->SetStringValue(text); - popup->Connect(-1, wxEVT_CHECKLISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnCheckListBox), nullptr, popup); - popup->Connect(-1, wxEVT_LISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnListBoxSelection), nullptr, popup); + popup->Connect(wxID_ANY, wxEVT_CHECKLISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnCheckListBox), nullptr, popup); + popup->Connect(wxID_ANY, wxEVT_LISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnListBoxSelection), nullptr, popup); std::vector<std::string> items_str; boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off); diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 7fe799019..b5f0595f8 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -1,16 +1,10 @@ #include "wxExtensions.hpp" -const unsigned int wxCheckListBoxComboPopup::Height = 200; - -wxCheckListBoxComboPopup::wxCheckListBoxComboPopup(wxWindowID id) - : m_id(id) - , m_text(wxEmptyString) -{ -} +const unsigned int wxCheckListBoxComboPopup::Height = 210; bool wxCheckListBoxComboPopup::Create(wxWindow* parent) { - return wxCheckListBox::Create(parent, m_id, wxPoint(0, 0)); + return wxCheckListBox::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0)); } wxWindow* wxCheckListBoxComboPopup::GetControl() @@ -51,6 +45,7 @@ void wxCheckListBoxComboPopup::OnCheckListBox(wxCommandEvent& evt) if (cmb != nullptr) { wxCommandEvent event(wxEVT_CHECKLISTBOX, cmb->GetId()); + event.SetEventObject(cmb); cmb->ProcessWindowEvent(event); } } @@ -68,7 +63,6 @@ void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt) wxCommandEvent event(wxEVT_CHECKLISTBOX, GetId()); event.SetInt(selId); event.SetEventObject(this); - event.SetString(GetString(selId)); ProcessEvent(event); } } diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 96d59069d..8e62f766c 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -8,12 +8,9 @@ class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { static const unsigned int Height; - wxWindowID m_id; wxString m_text; public: - explicit wxCheckListBoxComboPopup(wxWindowID id); - virtual bool Create(wxWindow* parent); virtual wxWindow* GetControl(); virtual void SetStringValue(const wxString& value); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index f6d729f98..6c56a06d9 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -161,7 +161,12 @@ get_legend_texture_height() RETVAL = _3DScene::get_legend_texture_height(); OUTPUT: RETVAL - + +void +reset_legend_texture() + CODE: + _3DScene::reset_legend_texture(); + void _load_print_toolpaths(print, volumes, tool_colors, use_VBOs) Print *print;