From a4ad4ff4a9367bc411b01104f58d339c35d15527 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 12 Oct 2021 15:23:50 +0200 Subject: [PATCH] Auto color change: check overhangs lust from Preview when detecting auto color changes + fixed typo in equivalent_areas() + Added missed include --- src/slic3r/GUI/DoubleSlider.cpp | 8 ++++---- src/slic3r/GUI/DoubleSlider.hpp | 2 +- src/slic3r/GUI/GUI_Preview.cpp | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index d8ad08037..d0b29165c 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -43,7 +43,7 @@ constexpr double miscalculation = scale_(scale_(1)); // equal to 1 mm2 bool equivalent_areas(const double& bottom_area, const double& top_area) { - return fabs(bottom_area - top_area <= miscalculation); + return fabs(bottom_area - top_area) <= miscalculation; } wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent); @@ -2042,7 +2042,7 @@ void Control::show_cog_icon_context_menu() GUI::wxGetApp().plater()->PopupMenu(&menu); } -bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers_cnt, std::function break_condition) +bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers_cnt, bool check_overhangs, std::function break_condition) { double prev_area = area(object->get_layer(frst_layer_id)->lslices); @@ -2052,7 +2052,7 @@ bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers double cur_area = area(layer->lslices); // check for overhangs - if (cur_area > prev_area && !equivalent_areas(prev_area, cur_area)) + if (check_overhangs && cur_area > prev_area && !equivalent_areas(prev_area, cur_area)) break; // Check percent of the area decrease. @@ -2087,7 +2087,7 @@ void Control::auto_color_change() if (object->layer_count() == 0) continue; - check_color_change(object, 1, object->layers().size(), [this, extruders_cnt](Layer* layer) + check_color_change(object, 1, object->layers().size(), false, [this, extruders_cnt](Layer* layer) { int tick = get_tick_from_value(layer->print_z); if (tick >= 0 && !m_ticks.has_tick(tick)) { diff --git a/src/slic3r/GUI/DoubleSlider.hpp b/src/slic3r/GUI/DoubleSlider.hpp index 5c95d8052..8f88de472 100644 --- a/src/slic3r/GUI/DoubleSlider.hpp +++ b/src/slic3r/GUI/DoubleSlider.hpp @@ -31,7 +31,7 @@ constexpr double epsilon() { return 0.0011; } bool equivalent_areas(const double& bottom_area, const double& top_area); // return true if color change was detected -bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers_cnt, +bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers_cnt, bool check_overhangs, // what to do with detected color change // and return true when detection have to be desturbed std::function break_condition); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 8654bed89..8ca2a39c5 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -13,6 +13,7 @@ #include "DoubleSlider.hpp" #include "Plater.hpp" #include "MainFrame.hpp" +#include "format.hpp" #include #include @@ -720,7 +721,7 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee if (i < min_solid_height) continue; - if (DoubleSlider::check_color_change(object, i, num_layers, [this, object](Layer*) { + if (DoubleSlider::check_color_change(object, i, num_layers, true, [this, object](Layer*) { NotificationManager* notif_mngr = wxGetApp().plater()->get_notification_manager(); notif_mngr->push_notification( NotificationType::SignDetected, NotificationManager::NotificationLevel::PrintInfoNotificationLevel,