SLA slices preview - wip 2

This commit is contained in:
Enrico Turri 2018-11-26 16:17:59 +01:00
parent a4e204012d
commit b153c8cb20
4 changed files with 49 additions and 14 deletions

View file

@ -93,7 +93,7 @@ public:
// to the z coordinate of the object coordinate system. // to the z coordinate of the object coordinate system.
struct SliceRecord { struct SliceRecord {
using Key = long long; using Key = long long;
inline static float scale_back(Key h) { return float(scale_(h)); } inline static float scale_back(Key h) { return float(h * SCALING_FACTOR); }
using Idx = size_t; using Idx = size_t;
static const Idx NONE = Idx(-1); // this will be the max limit of size_t static const Idx NONE = Idx(-1); // this will be the max limit of size_t

View file

@ -7003,7 +7003,7 @@ void GLCanvas3D::_load_shells_sla()
unsigned int partial_volumes_count = (unsigned int)m_volumes.volumes.size(); unsigned int partial_volumes_count = (unsigned int)m_volumes.volumes.size();
// add supports // add supports
if (obj->is_step_done(slaposSupportTree)) if (obj->is_step_done(slaposSupportTree) && obj->has_mesh(slaposSupportTree))
{ {
const TriangleMesh& mesh = obj->support_mesh(); const TriangleMesh& mesh = obj->support_mesh();
m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_SUPPORT_COLOR)); m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_SUPPORT_COLOR));
@ -7021,7 +7021,7 @@ void GLCanvas3D::_load_shells_sla()
} }
// add pad // add pad
if (obj->is_step_done(slaposBasePool)) if (obj->is_step_done(slaposBasePool) && obj->has_mesh(slaposBasePool))
{ {
const TriangleMesh& mesh = obj->pad_mesh(); const TriangleMesh& mesh = obj->pad_mesh();
m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_PAD_COLOR)); m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_PAD_COLOR));

View file

@ -22,6 +22,7 @@
// this include must follow the wxWidgets ones or it won't compile on Windows -> see http://trac.wxwidgets.org/ticket/2421 // this include must follow the wxWidgets ones or it won't compile on Windows -> see http://trac.wxwidgets.org/ticket/2421
#include "libslic3r/Print.hpp" #include "libslic3r/Print.hpp"
#include "libslic3r/SLAPrint.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -326,10 +327,10 @@ void Preview::reset_sliders()
m_double_slider_sizer->Hide((size_t)0); m_double_slider_sizer->Hide((size_t)0);
} }
void Preview::update_sliders() void Preview::update_sliders(const std::vector<double>& layers_z)
{ {
m_enabled = true; m_enabled = true;
update_double_slider(m_force_sliders_full_range); update_double_slider(layers_z, m_force_sliders_full_range);
m_double_slider_sizer->Show((size_t)0); m_double_slider_sizer->Show((size_t)0);
Layout(); Layout();
} }
@ -402,10 +403,9 @@ void Preview::create_double_slider()
}); });
} }
void Preview::update_double_slider(bool force_sliders_full_range) void Preview::update_double_slider(const std::vector<double>& layers_z, bool force_sliders_full_range)
{ {
std::vector<std::pair<int, double>> values; std::vector<std::pair<int, double>> values;
std::vector<double> layers_z = m_canvas->get_current_print_zs(true);
fill_slider_values(values, layers_z); fill_slider_values(values, layers_z);
const double z_low = m_slider->GetLowerValueD(); const double z_low = m_slider->GetLowerValueD();
@ -606,7 +606,7 @@ void Preview::load_print_as_fff()
} }
if (n_layers > 0) if (n_layers > 0)
update_sliders(); update_sliders(m_canvas->get_current_print_zs(true));
m_loaded = true; m_loaded = true;
} }
@ -617,9 +617,44 @@ void Preview::load_print_as_sla()
if (m_loaded || (m_process->current_printer_technology() != ptSLA)) if (m_loaded || (m_process->current_printer_technology() != ptSLA))
return; return;
unsigned int n_layers = 0;
const SLAPrint* print = m_process->sla_print();
std::set<float> zs;
for (const SLAPrintObject* obj : print->objects())
{
if (obj->is_step_done(slaposIndexSlices))
{
const SLAPrintObject::SliceIndex& index = obj->get_slice_index();
for (const SLAPrintObject::SliceIndex::value_type& id : index)
{
zs.insert(id.second.scale_back(id.first));
}
}
}
n_layers = (unsigned int)zs.size();
if (n_layers == 0)
{
reset_sliders();
m_canvas_widget->Refresh();
}
if (IsShown())
{
std::cout << "Preview::load_print_as_sla()" << std::endl; std::cout << "Preview::load_print_as_sla()" << std::endl;
m_canvas->load_sla_preview(); m_canvas->load_sla_preview();
show_hide_ui_elements("none"); show_hide_ui_elements("none");
if (n_layers > 0)
{
std::vector<double> layer_zs;
std::copy(zs.begin(), zs.end(), std::back_inserter(layer_zs));
update_sliders(layer_zs);
}
m_loaded = true;
}
} }
} // namespace GUI } // namespace GUI

View file

@ -85,7 +85,7 @@ private:
void show_hide_ui_elements(const std::string& what); void show_hide_ui_elements(const std::string& what);
void reset_sliders(); void reset_sliders();
void update_sliders(); void update_sliders(const std::vector<double>& layers_z);
void on_size(wxSizeEvent& evt); void on_size(wxSizeEvent& evt);
void on_choice_view_type(wxCommandEvent& evt); void on_choice_view_type(wxCommandEvent& evt);
@ -97,7 +97,7 @@ private:
// Create/Update/Reset double slider on 3dPreview // Create/Update/Reset double slider on 3dPreview
void create_double_slider(); void create_double_slider();
void update_double_slider(bool force_sliders_full_range); void update_double_slider(const std::vector<double>& layers_z, bool force_sliders_full_range);
void fill_slider_values(std::vector<std::pair<int, double>> &values, void fill_slider_values(std::vector<std::pair<int, double>> &values,
const std::vector<double> &layers_z); const std::vector<double> &layers_z);
void set_double_slider_thumbs( const bool force_sliders_full_range, void set_double_slider_thumbs( const bool force_sliders_full_range,