DoubleSlider: Code refactoring for auto color change
This commit is contained in:
parent
94843bb6bf
commit
cedfc5e3fb
@ -38,6 +38,25 @@ using GUI::format_wxstr;
|
|||||||
|
|
||||||
namespace DoubleSlider {
|
namespace DoubleSlider {
|
||||||
|
|
||||||
|
bool possible_threshold(const double& bottom_area, const double& top_area)
|
||||||
|
{
|
||||||
|
// Check percent of the area decrease.
|
||||||
|
// This value have to be more than 25 mm2
|
||||||
|
return (bottom_area - top_area > min_delta_area()) &&
|
||||||
|
// and more 10%
|
||||||
|
(top_area / bottom_area < 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool equivalent_areas(const double& bottom_area, const double& top_area)
|
||||||
|
{
|
||||||
|
return fabs(bottom_area - top_area <= min_threshold());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool overhang(const double& bottom_area, const double& top_area)
|
||||||
|
{
|
||||||
|
return top_area > bottom_area && !equivalent_areas(bottom_area, top_area);
|
||||||
|
}
|
||||||
|
|
||||||
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
|
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
|
||||||
|
|
||||||
static std::string gcode(Type type)
|
static std::string gcode(Type type)
|
||||||
@ -2049,8 +2068,6 @@ void Control::auto_color_change()
|
|||||||
int extruder = 2;
|
int extruder = 2;
|
||||||
|
|
||||||
const Print& print = GUI::wxGetApp().plater()->fff_print();
|
const Print& print = GUI::wxGetApp().plater()->fff_print();
|
||||||
double delta_area = scale_(scale_(25)); // equal to 25 mm2
|
|
||||||
|
|
||||||
for (auto object : print.objects()) {
|
for (auto object : print.objects()) {
|
||||||
if (object->layer_count() == 0)
|
if (object->layer_count() == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -2060,14 +2077,10 @@ void Control::auto_color_change()
|
|||||||
Layer* layer = object->get_layer(i);
|
Layer* layer = object->get_layer(i);
|
||||||
double cur_area = area(layer->lslices);
|
double cur_area = area(layer->lslices);
|
||||||
|
|
||||||
if (cur_area > prev_area && prev_area - cur_area > scale_(scale_(1)))
|
if (overhang(prev_area, cur_area))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (prev_area - cur_area > delta_area) {
|
if (possible_threshold(prev_area, cur_area)) {
|
||||||
// Check percent of the area decrease.
|
|
||||||
// Ignore it, if this value is less than 10%
|
|
||||||
if (cur_area / prev_area > 0.9)
|
|
||||||
continue;
|
|
||||||
int tick = get_tick_from_value(layer->print_z);
|
int tick = get_tick_from_value(layer->print_z);
|
||||||
if (tick >= 0 && !m_ticks.has_tick(tick)) {
|
if (tick >= 0 && !m_ticks.has_tick(tick)) {
|
||||||
if (m_mode == SingleExtruder) {
|
if (m_mode == SingleExtruder) {
|
||||||
|
@ -25,6 +25,13 @@ namespace DoubleSlider {
|
|||||||
*/
|
*/
|
||||||
constexpr double epsilon() { return 0.0011; }
|
constexpr double epsilon() { return 0.0011; }
|
||||||
|
|
||||||
|
constexpr double min_delta_area() { return scale_(scale_(25)); } // equal to 25 mm2
|
||||||
|
constexpr double min_threshold() { return scale_(scale_(1)); } // equal to 1 mm2
|
||||||
|
|
||||||
|
bool possible_threshold(const double& bottom_area, const double& top_area);
|
||||||
|
bool equivalent_areas(const double& bottom_area, const double& top_area);
|
||||||
|
bool overhang(const double& bottom_area, const double& top_area);
|
||||||
|
|
||||||
// custom message the slider sends to its parent to notify a tick-change:
|
// custom message the slider sends to its parent to notify a tick-change:
|
||||||
wxDECLARE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
|
wxDECLARE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
|
||||||
|
|
||||||
|
@ -687,7 +687,6 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
|||||||
if (m_layers_slider->IsNewPrint())
|
if (m_layers_slider->IsNewPrint())
|
||||||
{
|
{
|
||||||
const Print& print = wxGetApp().plater()->fff_print();
|
const Print& print = wxGetApp().plater()->fff_print();
|
||||||
double delta_area = scale_(scale_(25)); // equal to 25 mm2
|
|
||||||
|
|
||||||
//bool is_possible_auto_color_change = false;
|
//bool is_possible_auto_color_change = false;
|
||||||
for (auto object : print.objects()) {
|
for (auto object : print.objects()) {
|
||||||
@ -708,7 +707,7 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
|||||||
int i, min_solid_height = int(0.25 * num_layers);
|
int i, min_solid_height = int(0.25 * num_layers);
|
||||||
for (i = 1; i <= min_solid_height; ++ i) {
|
for (i = 1; i <= min_solid_height; ++ i) {
|
||||||
double cur_area = area(object->get_layer(i)->lslices);
|
double cur_area = area(object->get_layer(i)->lslices);
|
||||||
if (cur_area != bottom_area && fabs(cur_area - bottom_area) > scale_(scale_(1))) {
|
if (!DoubleSlider::equivalent_areas(bottom_area, cur_area)) {
|
||||||
// but due to the elephant foot compensation, the first layer may be slightly smaller than the others
|
// but due to the elephant foot compensation, the first layer may be slightly smaller than the others
|
||||||
if (i == 1 && fabs(cur_area - bottom_area) / bottom_area < 0.1) {
|
if (i == 1 && fabs(cur_area - bottom_area) / bottom_area < 0.1) {
|
||||||
// So, let process this case and use second layer as a bottom
|
// So, let process this case and use second layer as a bottom
|
||||||
@ -725,7 +724,7 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
|||||||
double prev_area = area(object->get_layer(i)->lslices);
|
double prev_area = area(object->get_layer(i)->lslices);
|
||||||
for ( i++; i < num_layers; i++) {
|
for ( i++; i < num_layers; i++) {
|
||||||
double cur_area = area(object->get_layer(i)->lslices);
|
double cur_area = area(object->get_layer(i)->lslices);
|
||||||
if (cur_area > prev_area && prev_area - cur_area > scale_(scale_(1)))
|
if (DoubleSlider::overhang(prev_area, cur_area))
|
||||||
break;
|
break;
|
||||||
prev_area = cur_area;
|
prev_area = cur_area;
|
||||||
}
|
}
|
||||||
@ -733,7 +732,7 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
double top_area = area(object->get_layer(int(object->layers().size()) - 1)->lslices);
|
double top_area = area(object->get_layer(int(object->layers().size()) - 1)->lslices);
|
||||||
if( bottom_area - top_area > delta_area) {
|
if (DoubleSlider::possible_threshold(bottom_area, top_area)) {
|
||||||
NotificationManager *notif_mngr = wxGetApp().plater()->get_notification_manager();
|
NotificationManager *notif_mngr = wxGetApp().plater()->get_notification_manager();
|
||||||
notif_mngr->push_notification(
|
notif_mngr->push_notification(
|
||||||
NotificationType::SignDetected, NotificationManager::NotificationLevel::PrintInfoNotificationLevel,
|
NotificationType::SignDetected, NotificationManager::NotificationLevel::PrintInfoNotificationLevel,
|
||||||
|
Loading…
Reference in New Issue
Block a user