diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 3de77b911..770d02a7c 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -977,14 +977,13 @@ Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &co new_objects = true; if (it_old != old.end()) const_cast(*it_old)->status = PrintObjectStatus::Deleted; - } else if ((*it_old)->print_object->copies() != new_instances.copies) { + } else { // The PrintObject already exists and the copies differ. if ((*it_old)->print_object->copies().size() != new_instances.copies.size()) update_apply_status(this->invalidate_step(psWipeTower)); if ((*it_old)->print_object->set_copies(new_instances.copies)) { // Invalidated - static PrintStep steps[] = { psSkirt, psBrim, psGCodeExport }; - update_apply_status(this->invalidate_multiple_steps(steps, steps + 3)); + update_apply_status(this->invalidate_steps({ psSkirt, psBrim, psGCodeExport })); } print_objects_new.emplace_back((*it_old)->print_object); const_cast(*it_old)->status = PrintObjectStatus::Reused; @@ -1002,10 +1001,8 @@ Print::ApplyStatus Print::apply(const Model &model, const DynamicPrintConfig &co delete pos.print_object; deleted_objects = true; } - if (deleted_objects) { - static PrintStep steps[] = { psSkirt, psBrim, psWipeTower, psGCodeExport }; - update_apply_status(this->invalidate_multiple_steps(steps, steps + 4)); - } + if (new_objects || deleted_objects) + update_apply_status(this->invalidate_steps({ psSkirt, psBrim, psWipeTower, psGCodeExport })); update_apply_status(new_objects); } print_object_status.clear(); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index dfa5cc485..d2dc81755 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -268,8 +268,9 @@ public: bool invalidate_state_by_config_options(const std::vector &opt_keys); bool invalidate_step(PrintObjectStep step); template - bool invalidate_multiple_steps(StepTypeIterator step_begin, StepTypeIterator step_end) { return m_state.invalidate_multiple(step_begin, step_end, m_mutex, m_cancel_callback); } - bool invalidate_all_steps(); + bool invalidate_steps(StepTypeIterator step_begin, StepTypeIterator step_end) { return m_state.invalidate_multiple(step_begin, step_end, this->cancel_mutex(), this->cancel_callback()); } + bool invalidate_steps(std::initializer_list il) { return m_state.invalidate_multiple(il.begin(), il.end(), this->cancel_mutex(), this->cancel_callback()); } + bool invalidate_all_steps() { return m_state.invalidate_all(this->cancel_mutex(), this->cancel_callback()); } bool is_step_done(PrintObjectStep step) const { return m_state.is_done(step); } // To be used over the layer_height_profile of both the PrintObject and ModelObject @@ -318,6 +319,9 @@ private: void _generate_support_material(); bool is_printable() const { return ! m_copies.empty(); } + // Implemented in cpp due to cyclic dependencies between Print and PrintObject. + tbb::mutex& cancel_mutex(); + std::function cancel_callback(); Print *m_print; ModelObject *m_model_object; @@ -534,7 +538,8 @@ protected: void set_done(PrintStep step) { m_state.set_done(step, m_mutex); throw_if_canceled(); } bool invalidate_step(PrintStep step); template - bool invalidate_multiple_steps(StepTypeIterator step_begin, StepTypeIterator step_end) { return m_state.invalidate_multiple(step_begin, step_end, m_mutex, m_cancel_callback); } + bool invalidate_steps(StepTypeIterator step_begin, StepTypeIterator step_end) { return m_state.invalidate_multiple(step_begin, step_end, m_mutex, m_cancel_callback); } + bool invalidate_steps(std::initializer_list il) { return m_state.invalidate_multiple(il.begin(), il.end(), m_mutex, m_cancel_callback); } bool invalidate_all_steps() { return m_state.invalidate_all(m_mutex, m_cancel_callback); } // methods for handling regions diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index b7b33087f..6527a7272 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -99,11 +99,9 @@ bool PrintObject::set_copies(const Points &points) // Invalidate and set copies. bool invalidated = false; if (copies != m_copies) { - invalidated = m_print->invalidate_step(psSkirt); - invalidated |= m_print->invalidate_step(psBrim); + invalidated = m_print->invalidate_steps({ psSkirt, psBrim, psGCodeExport }); if (copies.size() != m_copies.size()) invalidated |= m_print->invalidate_step(psWipeTower); - invalidated |= m_print->invalidate_step(psGCodeExport); m_copies = copies; } return invalidated; @@ -590,21 +588,16 @@ bool PrintObject::invalidate_step(PrintObjectStep step) // propagate to dependent steps if (step == posPerimeters) { invalidated |= this->invalidate_step(posPrepareInfill); - invalidated |= m_print->invalidate_step(psSkirt); - invalidated |= m_print->invalidate_step(psBrim); + invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); } else if (step == posPrepareInfill) { invalidated |= this->invalidate_step(posInfill); } else if (step == posInfill) { - invalidated |= m_print->invalidate_step(psSkirt); - invalidated |= m_print->invalidate_step(psBrim); + invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); } else if (step == posSlice) { - invalidated |= this->invalidate_step(posPerimeters); - invalidated |= this->invalidate_step(posSupportMaterial); + invalidated |= this->invalidate_steps({ posPerimeters, posSupportMaterial }); invalidated |= m_print->invalidate_step(psWipeTower); - } else if (step == posSupportMaterial) { - invalidated |= m_print->invalidate_step(psSkirt); - invalidated |= m_print->invalidate_step(psBrim); - } + } else if (step == posSupportMaterial) + invalidated |= m_print->invalidate_steps({ psSkirt, psBrim }); // Wipe tower depends on the ordering of extruders, which in turn depends on everything. // It also decides about what the wipe_into_infill / wipe_into_object features will do, @@ -613,11 +606,6 @@ bool PrintObject::invalidate_step(PrintObjectStep step) return invalidated; } -bool PrintObject::invalidate_all_steps() -{ - return m_state.invalidate_all(m_print->m_mutex, m_print->m_cancel_callback); -} - bool PrintObject::has_support_material() const { return m_config.support_material @@ -2254,4 +2242,15 @@ void PrintObject::adjust_layer_height_profile(coordf_t z, coordf_t layer_thickne layer_height_profile_valid = false; } +tbb::mutex& PrintObject::cancel_mutex() +{ + return m_print->m_mutex; +} + +std::function PrintObject::cancel_callback() +{ + return m_print->m_cancel_callback; +} + + } // namespace Slic3r