From 360133246cde02d09010fc21e5ef685af020da95 Mon Sep 17 00:00:00 2001 From: YuSanka <yusanka@gmail.com> Date: Wed, 28 Nov 2018 12:32:43 +0100 Subject: [PATCH] Fixed ColorPrint current layer identification --- src/libslic3r/GCode.cpp | 2 +- src/libslic3r/GCode/PreviewData.cpp | 9 ++++---- src/libslic3r/GCode/PreviewData.hpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 32 ++++++++++++++++++++++++----- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- src/slic3r/GUI/wxExtensions.cpp | 2 +- 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index bcfb8faec..b9625523d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1322,7 +1322,7 @@ void GCode::process_layer( // In case there are more toolchange requests that weren't done yet and should happen simultaneously, erase them all. // (Layers can be close to each other, model could have been resliced with bigger layer height, ...). bool colorprint_change = false; - while (!m_colorprint_heights.empty() && m_colorprint_heights.front()/*-EPSILON*/ < layer.print_z-EPSILON) { + while (!m_colorprint_heights.empty() && m_colorprint_heights.front()-EPSILON < layer.print_z) { m_colorprint_heights.erase(m_colorprint_heights.begin()); colorprint_change = true; } diff --git a/src/libslic3r/GCode/PreviewData.cpp b/src/libslic3r/GCode/PreviewData.cpp index 1d14c36e6..3f2df9532 100644 --- a/src/libslic3r/GCode/PreviewData.cpp +++ b/src/libslic3r/GCode/PreviewData.cpp @@ -382,7 +382,7 @@ std::string GCodePreviewData::get_legend_title() const return ""; } -GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::vector<float>& tool_colors, const std::vector<double>& cp_values) const +GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::vector<float>& tool_colors, const std::vector</*double*/std::pair<double, double>>& cp_values) const { struct Helper { @@ -465,15 +465,16 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: break; } if (i == 0) { - items.emplace_back((boost::format(Slic3r::I18N::translate(L("up to %.2f mm"))) % cp_values[0]).str(), color); + items.emplace_back((boost::format(Slic3r::I18N::translate(L("up to %.2f mm"))) % cp_values[0].first).str(), color); break; } if (i == color_print_cnt) { - items.emplace_back((boost::format(Slic3r::I18N::translate(L("above %.2f mm"))) % cp_values[i-1]).str(), color); + items.emplace_back((boost::format(Slic3r::I18N::translate(L("above %.2f mm"))) % cp_values[i-1].second).str(), color); continue; } - items.emplace_back((boost::format(Slic3r::I18N::translate(L("%.2f - %.2f mm"))) % cp_values[i-1] % cp_values[i]).str(), color); +// items.emplace_back((boost::format(Slic3r::I18N::translate(L("%.2f - %.2f mm"))) % cp_values[i-1] % cp_values[i]).str(), color); + items.emplace_back((boost::format(Slic3r::I18N::translate(L("%.2f - %.2f mm"))) % cp_values[i-1].second % cp_values[i].first).str(), color); } break; } diff --git a/src/libslic3r/GCode/PreviewData.hpp b/src/libslic3r/GCode/PreviewData.hpp index 6feefd149..9f882788d 100644 --- a/src/libslic3r/GCode/PreviewData.hpp +++ b/src/libslic3r/GCode/PreviewData.hpp @@ -198,7 +198,7 @@ public: void set_extrusion_paths_colors(const std::vector<std::string>& colors); std::string get_legend_title() const; - LegendItemsList get_legend_items(const std::vector<float>& tool_colors, const std::vector<double>& cp_values) const; + LegendItemsList get_legend_items(const std::vector<float>& tool_colors, const std::vector</*double*/std::pair<double, double>>& cp_values) const; }; GCodePreviewData::Color operator + (const GCodePreviewData::Color& c1, const GCodePreviewData::Color& c2); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5cf178c6b..63a79b6d7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3115,16 +3115,38 @@ GLCanvas3D::LegendTexture::LegendTexture() { } -bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors) +bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas) { reset(); // collects items to render auto title = _(preview_data.get_legend_title()); - const auto& config = wxGetApp().preset_bundle->full_config(); - const std::vector<double>& color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values; - const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, color_print_values); + std::vector<std::pair<double, double>> cp_legend_values; + if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) + { + const auto& config = wxGetApp().preset_bundle->full_config(); + const std::vector<double>& color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values; + const int values_cnt = color_print_values.size(); + if (values_cnt > 0) { + auto print_zs = canvas.get_current_print_zs(true); + auto z = 0; + for (auto i = 0; i < values_cnt; ++i) + { + double prev_z = -1.0; + for (z; z < print_zs.size(); ++z) + if (fabs(color_print_values[i] - print_zs[z]) < EPSILON) { + prev_z = print_zs[z - 1]; + break; + } + if (prev_z < 0) + continue; + + cp_legend_values.push_back(std::pair<double, double>(prev_z, color_print_values[i])); + } + } + } + const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, /*color_print_values*/cp_legend_values); unsigned int items_count = (unsigned int)items.size(); if (items_count == 0) @@ -7414,7 +7436,7 @@ void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, return; #endif // !ENABLE_USE_UNIQUE_GLCONTEXT - m_legend_texture.generate(preview_data, tool_colors); + m_legend_texture.generate(preview_data, tool_colors, *this); } void GLCanvas3D::_generate_warning_texture(const std::string& msg) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 0a824ac2c..8d3f2de6c 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -710,7 +710,7 @@ private: public: LegendTexture(); - bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors); + bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas); void render(const GLCanvas3D& canvas) const; }; diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 398825a7d..0aea5dc04 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1446,7 +1446,7 @@ void PrusaDoubleSlider::get_size(int *w, int *h) double PrusaDoubleSlider::get_double_value(const SelectedSlider& selection) { - if (m_values.empty()) + if (m_values.empty() || m_lower_value<0) return 0.0; if (m_values.size() <= m_higher_value) { correct_higher_value();