Updated draw_colored_band() according to the new colors.

+ some code refactoring
This commit is contained in:
YuSanka 2019-01-30 14:45:18 +01:00
parent 7957675a97
commit 5a28693ff4
5 changed files with 14 additions and 23 deletions

View file

@ -3753,7 +3753,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePrevie
{ {
if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
{ {
const auto& config = wxGetApp().preset_bundle->full_config(); auto& config = wxGetApp().preset_bundle->project_config;
const std::vector<double>& color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values; const std::vector<double>& color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
const int values_cnt = color_print_values.size(); const int values_cnt = color_print_values.size();
if (values_cnt > 0) { if (values_cnt > 0) {
@ -7295,7 +7295,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
bool color_by_color_print() const { return color_print_values!=nullptr; } bool color_by_color_print() const { return color_print_values!=nullptr; }
const float* color_print_by_layer_idx(const size_t layer_idx) const const float* color_print_by_layer_idx(const size_t layer_idx) const
{ {
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z - EPSILON); auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z + EPSILON);
return color_tool((it - color_print_values->begin()) % number_tools()); return color_tool((it - color_print_values->begin()) % number_tools());
} }
} ctxt; } ctxt;

View file

@ -100,8 +100,6 @@ ObjectList::ObjectList(wxWindow* parent) :
ObjectList::~ObjectList() ObjectList::~ObjectList()
{ {
if (m_default_config)
delete m_default_config;
} }
void ObjectList::create_objects_ctrl() void ObjectList::create_objects_ctrl()
@ -749,10 +747,8 @@ void ObjectList::get_settings_choice(const wxString& category_name)
const ConfigOption* option = from_config.option(opt_key); const ConfigOption* option = from_config.option(opt_key);
if (!option) { if (!option) {
// if current option doesn't exist in prints.get_edited_preset(), // if current option doesn't exist in prints.get_edited_preset(),
// get it from m_default_config // get it from default config values
if (m_default_config) delete m_default_config; option = DynamicPrintConfig::new_from_defaults_keys({ opt_key })->option(opt_key);
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false));
option = m_default_config->option(opt_key);
} }
m_config->set_key_value(opt_key, option->clone()); m_config->set_key_value(opt_key, option->clone());
} }
@ -776,10 +772,8 @@ void ObjectList::get_freq_settings_choice(const wxString& bundle_name)
const ConfigOption* option = from_config.option(opt_key); const ConfigOption* option = from_config.option(opt_key);
if (!option) { if (!option) {
// if current option doesn't exist in prints.get_edited_preset(), // if current option doesn't exist in prints.get_edited_preset(),
// get it from m_default_config // get it from default config values
if (m_default_config) delete m_default_config; option = DynamicPrintConfig::new_from_defaults_keys({ opt_key })->option(opt_key);
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false));
option = m_default_config->option(opt_key);
} }
m_config->set_key_value(opt_key, option->clone()); m_config->set_key_value(opt_key, option->clone());
} }

View file

@ -97,9 +97,6 @@ class ObjectList : public wxDataViewCtrl
} m_dragged_data; } m_dragged_data;
wxBoxSizer *m_sizer {nullptr}; wxBoxSizer *m_sizer {nullptr};
DynamicPrintConfig *m_default_config {nullptr};
wxWindow *m_parent {nullptr}; wxWindow *m_parent {nullptr};
wxBitmap m_bmp_modifiermesh; wxBitmap m_bmp_modifiermesh;

View file

@ -740,7 +740,7 @@ void Preview::load_print_as_fff()
if (! gcode_preview_data_valid) { if (! gcode_preview_data_valid) {
//FIXME accessing full_config() is pretty expensive. //FIXME accessing full_config() is pretty expensive.
// Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code. // Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code.
const auto& config = wxGetApp().preset_bundle->full_config(); const auto& config = wxGetApp().preset_bundle->project_config;
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values; color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
} }
} }

View file

@ -1668,7 +1668,7 @@ void PrusaDoubleSlider::render()
// draw colored band on the background of a scroll line // draw colored band on the background of a scroll line
// and only in a case of no-empty m_values // and only in a case of no-empty m_values
// draw_colored_band(dc); draw_colored_band(dc);
// draw line // draw line
draw_scroll_line(dc, lower_pos, higher_pos); draw_scroll_line(dc, lower_pos, higher_pos);
@ -1867,8 +1867,10 @@ void PrusaDoubleSlider::draw_colored_band(wxDC& dc)
return; return;
} }
const std::vector<unsigned char>& clr_bytes = Slic3r::GCodePreviewData::Range::Default_Colors[0].as_bytes(); const std::vector<std::string>& colors = Slic3r::GCodePreviewData::ColorPrintColors();
wxColour clr = wxColour(clr_bytes[0], clr_bytes[1], clr_bytes[2], clr_bytes[3]); const size_t colors_cnt = colors.size();
wxColour clr(colors[0]);
dc.SetPen(clr); dc.SetPen(clr);
dc.SetBrush(clr); dc.SetBrush(clr);
dc.DrawRectangle(main_band); dc.DrawRectangle(main_band);
@ -1876,15 +1878,13 @@ void PrusaDoubleSlider::draw_colored_band(wxDC& dc)
int i = 1; int i = 1;
for (auto tick : m_ticks) for (auto tick : m_ticks)
{ {
if (i == Slic3r::GCodePreviewData::Range::Colors_Count) if (i == colors_cnt)
i = 0; i = 0;
const wxCoord pos = get_position_from_value(tick); const wxCoord pos = get_position_from_value(tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) : is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos-1); main_band.SetBottom(pos-1);
const std::vector<unsigned char>& clr_b = Slic3r::GCodePreviewData::Range::Default_Colors[i].as_bytes(); clr = wxColour(colors[i]);
clr = wxColour(clr_b[0], clr_b[1], clr_b[2], clr_b[3]);
dc.SetPen(clr); dc.SetPen(clr);
dc.SetBrush(clr); dc.SetBrush(clr);
dc.DrawRectangle(main_band); dc.DrawRectangle(main_band);