Alternate fix of #1976

This commit is contained in:
Enrico Turri 2019-03-19 10:48:20 +01:00
parent 262f187699
commit 6eafc97302
2 changed files with 17 additions and 12 deletions

View File

@ -355,11 +355,11 @@ void Preview::set_drop_target(wxDropTarget* target)
SetDropTarget(target);
}
void Preview::load_print()
void Preview::load_print(bool keep_z_range)
{
PrinterTechnology tech = m_process->current_printer_technology();
if (tech == ptFFF)
load_print_as_fff();
load_print_as_fff(keep_z_range);
else if (tech == ptSLA)
load_print_as_sla();
}
@ -390,7 +390,7 @@ void Preview::refresh_print()
if (!IsShown())
return;
load_print();
load_print(true);
}
void Preview::bind_event_handlers()
@ -447,10 +447,10 @@ void Preview::reset_sliders()
m_double_slider_sizer->Hide((size_t)0);
}
void Preview::update_sliders(const std::vector<double>& layers_z)
void Preview::update_sliders(const std::vector<double>& layers_z, bool keep_z_range)
{
m_enabled = true;
update_double_slider(layers_z);
update_double_slider(layers_z, keep_z_range);
m_double_slider_sizer->Show((size_t)0);
Layout();
}
@ -559,13 +559,18 @@ static int find_close_layer_idx(const std::vector<double>& zs, double &z, double
return -1;
}
void Preview::update_double_slider(const std::vector<double>& layers_z)
void Preview::update_double_slider(const std::vector<double>& layers_z, bool keep_z_range)
{
// Save the initial slider span.
double z_low = m_slider->GetLowerValueD();
double z_high = m_slider->GetHigherValueD();
bool was_empty = m_slider->GetMaxValue() == 0;
bool force_sliders_full_range = was_empty;
if (!keep_z_range)
{
bool span_changed = layers_z.empty() || std::abs(layers_z.back() - m_slider->GetMaxValueD()) > 1e-6;
force_sliders_full_range |= span_changed;
}
bool snap_to_min = force_sliders_full_range || m_slider->is_lower_at_min();
bool snap_to_max = force_sliders_full_range || m_slider->is_higher_at_max();
@ -652,7 +657,7 @@ void Preview::update_double_slider_from_canvas(wxKeyEvent& event)
event.Skip();
}
void Preview::load_print_as_fff()
void Preview::load_print_as_fff(bool keep_z_range)
{
if (m_loaded || m_process->current_printer_technology() != ptFFF)
return;
@ -753,7 +758,7 @@ void Preview::load_print_as_fff()
reset_sliders();
m_canvas_widget->Refresh();
} else
update_sliders(zs);
update_sliders(zs, keep_z_range);
}
}

View File

@ -113,7 +113,7 @@ public:
void select_view(const std::string& direction);
void set_drop_target(wxDropTarget* target);
void load_print();
void load_print(bool keep_z_range = false);
void reload_print(bool keep_volumes = false);
void refresh_print();
@ -126,7 +126,7 @@ private:
void show_hide_ui_elements(const std::string& what);
void reset_sliders();
void update_sliders(const std::vector<double>& layers_z);
void update_sliders(const std::vector<double>& layers_z, bool keep_z_range = false);
void on_size(wxSizeEvent& evt);
void on_choice_view_type(wxCommandEvent& evt);
@ -138,14 +138,14 @@ private:
// Create/Update/Reset double slider on 3dPreview
void create_double_slider();
void update_double_slider(const std::vector<double>& layers_z);
void update_double_slider(const std::vector<double>& layers_z, bool keep_z_range = false);
void fill_slider_values(std::vector<std::pair<int, double>> &values,
const std::vector<double> &layers_z);
void reset_double_slider();
// update DoubleSlider after keyDown in canvas
void update_double_slider_from_canvas(wxKeyEvent& event);
void load_print_as_fff();
void load_print_as_fff(bool keep_z_range = false);
void load_print_as_sla();
void on_sliders_scroll_changed(wxEvent& event);