From 727e7cc4f16b9ad6a04dfa77429698a374ae9395 Mon Sep 17 00:00:00 2001 From: PavelMikus Date: Tue, 10 Jan 2023 16:12:32 +0100 Subject: [PATCH] add throw if canceled calls into support spot generating algorithm --- src/libslic3r/PrintBase.cpp | 2 +- src/libslic3r/PrintBase.hpp | 2 +- src/libslic3r/PrintObject.cpp | 9 +++++---- src/libslic3r/SupportSpotsGenerator.cpp | 12 +++++++----- src/libslic3r/SupportSpotsGenerator.hpp | 5 ++++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/PrintBase.cpp b/src/libslic3r/PrintBase.cpp index b0aa7bd1e..d9b3e9cda 100644 --- a/src/libslic3r/PrintBase.cpp +++ b/src/libslic3r/PrintBase.cpp @@ -13,7 +13,7 @@ namespace Slic3r { -void PrintTryCancel::operator()() +void PrintTryCancel::operator()() const { m_print->throw_if_canceled(); } diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp index 6aac560a3..d218146ac 100644 --- a/src/libslic3r/PrintBase.hpp +++ b/src/libslic3r/PrintBase.hpp @@ -340,7 +340,7 @@ class PrintTryCancel { public: // calls print.throw_if_canceled(). - void operator()(); + void operator()() const; private: friend PrintBase; PrintTryCancel() = delete; diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 177540192..5423a3ad1 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -7,6 +7,7 @@ #include "I18N.hpp" #include "Layer.hpp" #include "MutablePolygon.hpp" +#include "PrintBase.hpp" #include "SupportMaterial.hpp" #include "TreeSupport.hpp" #include "Surface.hpp" @@ -420,8 +421,9 @@ void PrintObject::generate_support_spots() BOOST_LOG_TRIVIAL(debug) << "Searching support spots - start"; m_print->set_status(75, L("Searching support spots")); if (!this->shared_regions()->generated_support_points.has_value()) { + PrintTryCancel cancel_func = m_print->make_try_cancel(); SupportSpotsGenerator::Params params{this->print()->m_config.filament_type.values}; - SupportSpotsGenerator::SupportPoints supp_points = SupportSpotsGenerator::full_search(this, params); + SupportSpotsGenerator::SupportPoints supp_points = SupportSpotsGenerator::full_search(this, cancel_func, params); this->m_shared_regions->generated_support_points = {this->trafo_centered(), supp_points}; m_print->throw_if_canceled(); } @@ -463,7 +465,6 @@ void PrintObject::estimate_curled_extrusions() SupportSpotsGenerator::Params params{this->print()->m_config.filament_type.values}; SupportSpotsGenerator::estimate_supports_malformations(this->support_layers(), support_flow_width, params); SupportSpotsGenerator::estimate_malformations(this->layers(), params); - m_print->throw_if_canceled(); BOOST_LOG_TRIVIAL(debug) << "Estimating areas with curled extrusions - end"; } @@ -787,10 +788,10 @@ bool PrintObject::invalidate_step(PrintObjectStep step) } else if (step == posPrepareInfill) { invalidated |= this->invalidate_steps({ posInfill, posIroning }); } else if (step == posInfill) { - invalidated |= this->invalidate_steps({ posIroning }); + invalidated |= this->invalidate_steps({ posIroning, posSupportSpotsSearch }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); } else if (step == posSlice) { - invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportMaterial, posEstimateCurledExtrusions }); + invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportSpotsSearch, posSupportMaterial, posEstimateCurledExtrusions }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); m_slicing_params.valid = false; } else if (step == posSupportMaterial) { diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index 38f0876d2..f20583f9b 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -8,6 +8,7 @@ #include "Point.hpp" #include "Polygon.hpp" #include "Print.hpp" +#include "PrintBase.hpp" #include "Tesselate.hpp" #include "libslic3r.h" #include "tbb/parallel_for.h" @@ -32,8 +33,8 @@ #include "libslic3r/ClipperUtils.hpp" #include "Geometry/ConvexHull.hpp" -// #define DETAILED_DEBUG_LOGS -// #define DEBUG_FILES +#define DETAILED_DEBUG_LOGS +#define DEBUG_FILES #ifdef DEBUG_FILES #include @@ -661,7 +662,7 @@ public: } }; -SupportPoints check_stability(const PrintObject *po, const Params ¶ms) +SupportPoints check_stability(const PrintObject *po, const PrintTryCancel& cancel_func, const Params ¶ms) { SupportPoints supp_points{}; SupportGridFilter supports_presence_grid(po, params.min_distance_between_support_points); @@ -674,6 +675,7 @@ SupportPoints check_stability(const PrintObject *po, const Params ¶ms) std::unordered_map next_slice_idx_to_weakest_connection; for (size_t layer_idx = 0; layer_idx < po->layer_count(); ++layer_idx) { + cancel_func(); const Layer *layer = po->get_layer(layer_idx); float bottom_z = layer->bottom_z(); auto create_support_point_position = [bottom_z](const Vec2f &layer_pos) { return Vec3f{layer_pos.x(), layer_pos.y(), bottom_z}; }; @@ -873,9 +875,9 @@ void debug_export(SupportPoints support_points, std::string file_name) // std::vector quick_search(const PrintObject *po, const Params ¶ms) { // return {}; // } -SupportPoints full_search(const PrintObject *po, const Params ¶ms) +SupportPoints full_search(const PrintObject *po, const PrintTryCancel& cancel_func, const Params ¶ms) { - SupportPoints supp_points = check_stability(po, params); + SupportPoints supp_points = check_stability(po, cancel_func, params); #ifdef DEBUG_FILES debug_export(supp_points, "issues"); #endif diff --git a/src/libslic3r/SupportSpotsGenerator.hpp b/src/libslic3r/SupportSpotsGenerator.hpp index e1b0c8cd0..ca62061ff 100644 --- a/src/libslic3r/SupportSpotsGenerator.hpp +++ b/src/libslic3r/SupportSpotsGenerator.hpp @@ -3,6 +3,7 @@ #include "Layer.hpp" #include "Line.hpp" +#include "PrintBase.hpp" #include #include @@ -22,6 +23,8 @@ struct Params { filament_type = std::string("PLA"); } else { filament_type = filament_types[0]; + BOOST_LOG_TRIVIAL(debug) + << "SupportSpotsGenerator: applying filament type: " << filament_type; } } @@ -76,7 +79,7 @@ struct Malformations { }; // std::vector quick_search(const PrintObject *po, const Params ¶ms); -SupportPoints full_search(const PrintObject *po, const Params ¶ms); +SupportPoints full_search(const PrintObject *po, const PrintTryCancel& cancel_func, const Params ¶ms); void estimate_supports_malformations(std::vector &layers, float supports_flow_width, const Params ¶ms); void estimate_malformations(std::vector &layers, const Params ¶ms);