GCode Preview - Legend texture shown only when gcode is available

This commit is contained in:
Enrico Turri 2018-02-06 12:43:25 +01:00
parent 593d794655
commit 6ff9021e04
9 changed files with 61 additions and 30 deletions

View file

@ -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;

View file

@ -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");

View file

@ -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;
}

View file

@ -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(

View file

@ -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,

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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;