diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 3220ce07d4..0fd61c883d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -69,6 +69,7 @@ GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent) , m_is_initialized(false) // initialize on first opening gizmo , m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis) , m_font_manager(m_imgui->get_glyph_ranges()) + , m_update_job_cancel(std::make_shared(false)) { m_rotate_gizmo.set_group_id(0); // TODO: add suggestion to use https://fontawesome.com/ @@ -732,12 +733,18 @@ bool GLGizmoEmboss::process() // exist loaded font? Emboss::FontFileWithCache font = m_font_manager.get_font().font_file_with_cache; if (!font.has_value()) return false; - auto data = std::make_unique(font, - create_configuration(), - create_volume_name(), m_volume); - auto &worker = wxGetApp().plater()->get_ui_job_worker(); - replace_job(worker, std::make_unique(std::move(data))); + // cancel must be befor create new data + + *m_update_job_cancel = true; // set old job to cancel + m_update_job_cancel = std::make_shared(false); // create new shared ptr + + // IMPROVE: Cancel only EmbossUpdateJob no others + worker.cancel(); + auto data = std::make_unique( + font, create_configuration(), create_volume_name(), + m_volume->id(), m_update_job_cancel); + queue_job(worker, std::make_unique(std::move(data))); // notification is removed befor object is changed by job remove_notification_not_valid_font(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 512f564af2..f442f789e6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -202,11 +202,11 @@ private: void fill_stored_font_items(); void select_stored_font_item(); - //FontList m_font_list; - //size_t m_font_selected;// index to m_font_list - std::string m_text; + // cancel for previous update of volume to cancel finalize part + std::shared_ptr m_update_job_cancel; + // actual volume ModelVolume *m_volume; diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index b05ca2e4fc..4b49d0e6b2 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -66,7 +66,7 @@ void EmbossUpdateJob::process(Ctl &ctl) void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &) { - if (canceled) return; + if (canceled || *m_input->cancel) return; // for sure that some object is created from shape if (m_result.its.indices.empty()) return; @@ -80,24 +80,21 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &) // Check emboss gizmo is still open if (manager.get_current_type() != GLGizmosManager::Emboss) return; - Plater::TakeSnapshot snapshot(plater, - GUI::format(_L("Text: %1%"), - m_input->text_configuration.text), - UndoRedo::SnapshotType::GizmoAction); + std::string snap_name = GUI::format(_L("Text: %1%"), m_input->text_configuration.text); + Plater::TakeSnapshot snapshot(plater, snap_name, UndoRedo::SnapshotType::GizmoAction); - ModelVolume *volume = m_input->volume; - // find volume by object id - NOT WORK - // -> edit text change volume id so could apper not found volume - // ModelVolume *volume = nullptr; - // Model &model = plater->model(); - // for (auto obj : model.objects) - // for (auto vol : obj->volumes) - // if (vol->id() == volume_id) { - // volume = vol; - // break; - // } - // if (volume == nullptr) return; - assert(volume != nullptr); + ModelVolume *volume = nullptr; + Model &model = plater->model(); + for (auto obj : model.objects) + for (auto vol : obj->volumes) + if (vol->id() == m_input->volume_id) { + volume = vol; + break; + } + + // could appear when user delete edited volume + if (volume == nullptr) + return; // update volume volume->set_mesh(std::move(m_result)); diff --git a/src/slic3r/GUI/Jobs/EmbossJob.hpp b/src/slic3r/GUI/Jobs/EmbossJob.hpp index 1d9543dd90..3e5a80d929 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.hpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.hpp @@ -29,6 +29,14 @@ class EmbossUpdateJob : public Job public: EmbossUpdateJob(std::unique_ptr input); void process(Ctl &ctl) override; + + /// + /// Update volume - change object_id + /// + /// Was process canceled. + /// NOTE: Be carefull it doesn't care about + /// time between finished process and started finalize part. + /// unused void finalize(bool canceled, std::exception_ptr &) override; }; @@ -89,8 +97,11 @@ struct EmbossDataBase struct EmbossDataUpdate : public EmbossDataBase { // unique identifier of volume to change - // I can't proove of alive pointer - ModelVolume *volume; + ObjectID volume_id; + + // flag that job is canceled + // for time after process. + std::shared_ptr cancel; // unique identifier of volume to change // Change of volume change id, last change could disapear @@ -98,9 +109,11 @@ struct EmbossDataUpdate : public EmbossDataBase EmbossDataUpdate(Emboss::FontFileWithCache font_file, TextConfiguration text_configuration, std::string volume_name, - ModelVolume *volume) + ObjectID volume_id, + std::shared_ptr cancel) : EmbossDataBase(font_file, text_configuration, volume_name) - , volume(volume) + , volume_id(volume_id) + , cancel(std::move(cancel)) {} };