Merge branch lm_colorprint_integration into dev_native + deleting ticks outside slider range

This commit is contained in:
Lukas Matena 2018-11-07 14:44:47 +01:00
parent 69208c4f43
commit 9ca9e2a545
9 changed files with 89 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "../../libslic3r/libslic3r.h"
#include "GUI_Preview.hpp"
#include "GUI_App.hpp"
#include "GUI.hpp"
#include "AppConfig.hpp"
#include "3DScene.hpp"
@ -22,6 +23,7 @@
namespace Slic3r {
namespace GUI {
Preview::Preview(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data)
: m_canvas(nullptr)
, m_double_slider_sizer(nullptr)
@ -482,6 +484,11 @@ void Preview::create_double_slider()
if (IsShown())
m_canvas->Refresh();
});
Bind(wxCUSTOMEVT_TICKSCHANGED, [this](wxEvent&) {
auto& config = wxGetApp().preset_bundle->project_config;
((config.option<ConfigOptionFloats>("colorprint_heights"))->values) = (m_slider->GetTicksValues());
});
}
void Preview::update_double_slider(bool force_sliders_full_range)
@ -495,6 +502,11 @@ void Preview::update_double_slider(bool force_sliders_full_range)
m_slider->SetMaxValue(layers_z.size() - 1);
m_slider->SetSliderValues(values);
const auto& config = wxGetApp().preset_bundle->project_config;
const std::vector<double> &ticks_from_config = (config.option<ConfigOptionFloats>("colorprint_heights"))->values;
m_slider->SetTicksValues(ticks_from_config);
set_double_slider_thumbs(force_sliders_full_range, layers_z, z_low, z_high);
}
@ -515,6 +527,15 @@ void Preview::fill_slider_values(std::vector<std::pair<int, double>> &values,
break;
}
}
// All ticks that would end up outside the slider range should be erased.
// TODO: this should probably be placed into more appropriate part of code,
// this way it relies on the Preview tab being active.
auto& config = wxGetApp().preset_bundle->project_config;
std::vector<double> &ticks_from_config = (config.option<ConfigOptionFloats>("colorprint_heights"))->values;
ticks_from_config.erase(std::remove_if(ticks_from_config.begin(), ticks_from_config.end(),
[values](double val) { return values.back().second < val; }),
ticks_from_config.end());
}
void Preview::set_double_slider_thumbs(const bool force_sliders_full_range,

View file

@ -36,6 +36,7 @@
namespace Slic3r {
static std::vector<std::string> s_project_options {
"colorprint_heights",
"wiping_volumes_extruders",
"wiping_volumes_matrix"
};

View file

@ -11,6 +11,8 @@
#include "GUI_ObjectList.hpp"
#include "Model.hpp"
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
std::function<void(wxCommandEvent& event)> cb, const std::string& icon, wxEvtHandler* event_handler)
{
@ -1189,7 +1191,6 @@ wxSize PrusaBitmapTextRenderer::GetSize() const
// ----------------------------------------------------------------------------
// PrusaDoubleSlider
// ----------------------------------------------------------------------------
PrusaDoubleSlider::PrusaDoubleSlider(wxWindow *parent,
wxWindowID id,
int lowerValue,
@ -1371,6 +1372,34 @@ double PrusaDoubleSlider::get_double_value(const SelectedSlider& selection) cons
return m_values[selection == ssLower ? m_lower_value : m_higher_value].second;
}
std::vector<double> PrusaDoubleSlider::GetTicksValues() const
{
std::vector<double> values;
if (!m_values.empty())
for (auto tick : m_ticks)
values.push_back(m_values[tick].second);
return values;
}
void PrusaDoubleSlider::SetTicksValues(const std::vector<double>& heights)
{
if (m_values.empty())
return;
m_ticks.clear();
unsigned int i = 0;
for (auto h : heights) {
while (i < m_values.size() && m_values[i].second - 1e-6 < h)
++i;
if (i == m_values.size())
return;
m_ticks.insert(i);
}
}
void PrusaDoubleSlider::get_lower_and_higher_position(int& lower_pos, int& higher_pos)
{
const double step = get_scroll_step();
@ -1795,10 +1824,13 @@ void PrusaDoubleSlider::action_tick(const TicksAction action)
m_ticks.insert(tick);
else if (it != m_ticks.end() && action == taDel)
m_ticks.erase(tick);
else
else {
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
return;
}
}
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
Refresh();
Update();
}

View file

@ -622,6 +622,9 @@ private:
// PrusaDoubleSlider
// ----------------------------------------------------------------------------
// custom message the slider sends to its parent to notify a tick-change:
wxDECLARE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
enum SelectedSlider {
ssUndef,
ssLower,
@ -632,6 +635,7 @@ enum TicksAction{
taAdd,
taDel
};
class PrusaDoubleSlider : public wxControl
{
public:
@ -669,6 +673,8 @@ public:
m_values = values;
}
void ChangeOneLayerLock();
std::vector<double> GetTicksValues() const;
void SetTicksValues(const std::vector<double>& heights);
void OnPaint(wxPaintEvent& ) { render();}
void OnLeftDown(wxMouseEvent& event);