Fixed ColorPrint current layer identification

This commit is contained in:
YuSanka 2018-11-28 12:32:43 +01:00
parent bac021d516
commit 360133246c
6 changed files with 36 additions and 13 deletions

View file

@ -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. // 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, ...). // (Layers can be close to each other, model could have been resliced with bigger layer height, ...).
bool colorprint_change = false; 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()); m_colorprint_heights.erase(m_colorprint_heights.begin());
colorprint_change = true; colorprint_change = true;
} }

View file

@ -382,7 +382,7 @@ std::string GCodePreviewData::get_legend_title() const
return ""; 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 struct Helper
{ {
@ -465,15 +465,16 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
break; break;
} }
if (i == 0) { 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; break;
} }
if (i == color_print_cnt) { 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; 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; break;
} }

View file

@ -198,7 +198,7 @@ public:
void set_extrusion_paths_colors(const std::vector<std::string>& colors); void set_extrusion_paths_colors(const std::vector<std::string>& colors);
std::string get_legend_title() const; 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); GCodePreviewData::Color operator + (const GCodePreviewData::Color& c1, const GCodePreviewData::Color& c2);

View file

@ -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(); reset();
// collects items to render // collects items to render
auto title = _(preview_data.get_legend_title()); auto title = _(preview_data.get_legend_title());
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 auto& config = wxGetApp().preset_bundle->full_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 GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, color_print_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(); unsigned int items_count = (unsigned int)items.size();
if (items_count == 0) if (items_count == 0)
@ -7414,7 +7436,7 @@ void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data,
return; return;
#endif // !ENABLE_USE_UNIQUE_GLCONTEXT #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) void GLCanvas3D::_generate_warning_texture(const std::string& msg)

View file

@ -710,7 +710,7 @@ private:
public: public:
LegendTexture(); 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; void render(const GLCanvas3D& canvas) const;
}; };

View file

@ -1446,7 +1446,7 @@ void PrusaDoubleSlider::get_size(int *w, int *h)
double PrusaDoubleSlider::get_double_value(const SelectedSlider& selection) double PrusaDoubleSlider::get_double_value(const SelectedSlider& selection)
{ {
if (m_values.empty()) if (m_values.empty() || m_lower_value<0)
return 0.0; return 0.0;
if (m_values.size() <= m_higher_value) { if (m_values.size() <= m_higher_value) {
correct_higher_value(); correct_higher_value();