mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-10 04:01:46 +08:00
Update volume identified by ObjectID
(NOT VolumePtr which could invalidate by deleting volume)
This commit is contained in:
parent
d9249024ba
commit
ffab47dac7
@ -69,6 +69,7 @@ GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent)
|
|||||||
, m_is_initialized(false) // initialize on first opening gizmo
|
, m_is_initialized(false) // initialize on first opening gizmo
|
||||||
, m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis)
|
, m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis)
|
||||||
, m_font_manager(m_imgui->get_glyph_ranges())
|
, m_font_manager(m_imgui->get_glyph_ranges())
|
||||||
|
, m_update_job_cancel(std::make_shared<bool>(false))
|
||||||
{
|
{
|
||||||
m_rotate_gizmo.set_group_id(0);
|
m_rotate_gizmo.set_group_id(0);
|
||||||
// TODO: add suggestion to use https://fontawesome.com/
|
// TODO: add suggestion to use https://fontawesome.com/
|
||||||
@ -732,12 +733,18 @@ bool GLGizmoEmboss::process()
|
|||||||
// exist loaded font?
|
// exist loaded font?
|
||||||
Emboss::FontFileWithCache font = m_font_manager.get_font().font_file_with_cache;
|
Emboss::FontFileWithCache font = m_font_manager.get_font().font_file_with_cache;
|
||||||
if (!font.has_value()) return false;
|
if (!font.has_value()) return false;
|
||||||
auto data = std::make_unique<EmbossDataUpdate>(font,
|
|
||||||
create_configuration(),
|
|
||||||
create_volume_name(), m_volume);
|
|
||||||
|
|
||||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||||
replace_job(worker, std::make_unique<EmbossUpdateJob>(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<bool>(false); // create new shared ptr
|
||||||
|
|
||||||
|
// IMPROVE: Cancel only EmbossUpdateJob no others
|
||||||
|
worker.cancel();
|
||||||
|
auto data = std::make_unique<EmbossDataUpdate>(
|
||||||
|
font, create_configuration(), create_volume_name(),
|
||||||
|
m_volume->id(), m_update_job_cancel);
|
||||||
|
queue_job(worker, std::make_unique<EmbossUpdateJob>(std::move(data)));
|
||||||
|
|
||||||
// notification is removed befor object is changed by job
|
// notification is removed befor object is changed by job
|
||||||
remove_notification_not_valid_font();
|
remove_notification_not_valid_font();
|
||||||
|
@ -202,11 +202,11 @@ private:
|
|||||||
void fill_stored_font_items();
|
void fill_stored_font_items();
|
||||||
void select_stored_font_item();
|
void select_stored_font_item();
|
||||||
|
|
||||||
//FontList m_font_list;
|
|
||||||
//size_t m_font_selected;// index to m_font_list
|
|
||||||
|
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
|
||||||
|
// cancel for previous update of volume to cancel finalize part
|
||||||
|
std::shared_ptr<bool> m_update_job_cancel;
|
||||||
|
|
||||||
// actual volume
|
// actual volume
|
||||||
ModelVolume *m_volume;
|
ModelVolume *m_volume;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ void EmbossUpdateJob::process(Ctl &ctl)
|
|||||||
|
|
||||||
void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &)
|
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
|
// for sure that some object is created from shape
|
||||||
if (m_result.its.indices.empty()) return;
|
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
|
// Check emboss gizmo is still open
|
||||||
if (manager.get_current_type() != GLGizmosManager::Emboss) return;
|
if (manager.get_current_type() != GLGizmosManager::Emboss) return;
|
||||||
|
|
||||||
Plater::TakeSnapshot snapshot(plater,
|
std::string snap_name = GUI::format(_L("Text: %1%"), m_input->text_configuration.text);
|
||||||
GUI::format(_L("Text: %1%"),
|
Plater::TakeSnapshot snapshot(plater, snap_name, UndoRedo::SnapshotType::GizmoAction);
|
||||||
m_input->text_configuration.text),
|
|
||||||
UndoRedo::SnapshotType::GizmoAction);
|
|
||||||
|
|
||||||
ModelVolume *volume = m_input->volume;
|
ModelVolume *volume = nullptr;
|
||||||
// find volume by object id - NOT WORK
|
Model &model = plater->model();
|
||||||
// -> edit text change volume id so could apper not found volume
|
for (auto obj : model.objects)
|
||||||
// ModelVolume *volume = nullptr;
|
for (auto vol : obj->volumes)
|
||||||
// Model &model = plater->model();
|
if (vol->id() == m_input->volume_id) {
|
||||||
// for (auto obj : model.objects)
|
volume = vol;
|
||||||
// for (auto vol : obj->volumes)
|
break;
|
||||||
// if (vol->id() == volume_id) {
|
}
|
||||||
// volume = vol;
|
|
||||||
// break;
|
// could appear when user delete edited volume
|
||||||
// }
|
if (volume == nullptr)
|
||||||
// if (volume == nullptr) return;
|
return;
|
||||||
assert(volume != nullptr);
|
|
||||||
|
|
||||||
// update volume
|
// update volume
|
||||||
volume->set_mesh(std::move(m_result));
|
volume->set_mesh(std::move(m_result));
|
||||||
|
@ -29,6 +29,14 @@ class EmbossUpdateJob : public Job
|
|||||||
public:
|
public:
|
||||||
EmbossUpdateJob(std::unique_ptr<EmbossDataUpdate> input);
|
EmbossUpdateJob(std::unique_ptr<EmbossDataUpdate> input);
|
||||||
void process(Ctl &ctl) override;
|
void process(Ctl &ctl) override;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update volume - change object_id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="canceled">Was process canceled.
|
||||||
|
/// NOTE: Be carefull it doesn't care about
|
||||||
|
/// time between finished process and started finalize part.</param>
|
||||||
|
/// <param name="">unused</param>
|
||||||
void finalize(bool canceled, std::exception_ptr &) override;
|
void finalize(bool canceled, std::exception_ptr &) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,8 +97,11 @@ struct EmbossDataBase
|
|||||||
struct EmbossDataUpdate : public EmbossDataBase
|
struct EmbossDataUpdate : public EmbossDataBase
|
||||||
{
|
{
|
||||||
// unique identifier of volume to change
|
// unique identifier of volume to change
|
||||||
// I can't proove of alive pointer
|
ObjectID volume_id;
|
||||||
ModelVolume *volume;
|
|
||||||
|
// flag that job is canceled
|
||||||
|
// for time after process.
|
||||||
|
std::shared_ptr<bool> cancel;
|
||||||
|
|
||||||
// unique identifier of volume to change
|
// unique identifier of volume to change
|
||||||
// Change of volume change id, last change could disapear
|
// Change of volume change id, last change could disapear
|
||||||
@ -98,9 +109,11 @@ struct EmbossDataUpdate : public EmbossDataBase
|
|||||||
EmbossDataUpdate(Emboss::FontFileWithCache font_file,
|
EmbossDataUpdate(Emboss::FontFileWithCache font_file,
|
||||||
TextConfiguration text_configuration,
|
TextConfiguration text_configuration,
|
||||||
std::string volume_name,
|
std::string volume_name,
|
||||||
ModelVolume *volume)
|
ObjectID volume_id,
|
||||||
|
std::shared_ptr<bool> cancel)
|
||||||
: EmbossDataBase(font_file, text_configuration, volume_name)
|
: EmbossDataBase(font_file, text_configuration, volume_name)
|
||||||
, volume(volume)
|
, volume_id(volume_id)
|
||||||
|
, cancel(std::move(cancel))
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user