Another approach to fix undo redo:

Do not open gizmo on shortcut key: only create volume
This commit is contained in:
Filip Sykala - NTB T15p 2023-03-30 19:04:29 +02:00
parent 115b230367
commit dd7a19505a
26 changed files with 54 additions and 49 deletions

View File

@ -174,7 +174,7 @@ public:
/// <summary>
/// Is called when data (Selection) is changed
/// </summary>
virtual void data_changed(bool is_serializing){};
virtual void data_changed(){};
/// <summary>
/// Implement when want to process mouse events in gizmo

View File

@ -2510,7 +2510,7 @@ CommonGizmosDataID GLGizmoCut3D::on_get_requirements() const {
| int(CommonGizmosDataID::ObjectClipper));
}
void GLGizmoCut3D::data_changed(bool is_serializing)
void GLGizmoCut3D::data_changed()
{
update_bb();
if (auto oc = m_c->object_clipper())

View File

@ -256,7 +256,7 @@ protected:
std::string get_gizmo_leaving_text() const override { return _u8L("Leaving Cut gizmo"); }
std::string get_action_snapshot_name() const override { return _u8L("Cut gizmo editing"); }
void data_changed(bool is_serializing) override;
void data_changed() override;
private:
void set_center(const Vec3d& center, bool update_tbb = false);

View File

@ -312,6 +312,21 @@ void GLGizmoEmboss::create_volume(ModelVolumeType volume_type)
}
}
void GLGizmoEmboss::on_shortcut_key() {
set_volume_by_selection();
if (m_volume == nullptr) {
// No volume to select from selection so create volume.
// NOTE: After finish job for creation emboss Text volume,
// GLGizmoEmboss will be opened
create_volume(ModelVolumeType::MODEL_PART);
} else {
// shortcut is pressed when text is selected soo start edit it.
auto &mng = m_parent.get_gizmos_manager();
if (mng.get_current_type() != GLGizmosManager::Emboss)
mng.open_gizmo(GLGizmosManager::Emboss);
}
}
bool GLGizmoEmboss::init_create(ModelVolumeType volume_type)
{
// check valid volume type
@ -628,7 +643,6 @@ static void draw_mouse_offset(const std::optional<Vec2d> &offset)
void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
{
m_is_just_opened = false;
assert(m_volume != nullptr);
// Do not render window for not selected text volume
if (m_volume == nullptr ||
@ -767,16 +781,7 @@ void GLGizmoEmboss::on_set_state()
// Immediately after set state On is called function data_changed(),
// where one could distiguish undo/redo serialization from opening by letter 'T'
set_volume_by_selection();
// when open window by "T" and no valid volume is selected, so Create new one
if (m_volume == nullptr) {
// reopen gizmo when new object is created
m_state = GLGizmoBase::Off;
// start creating new object
return;
}
m_is_just_opened = true;
// set_volume_by_selection();
// change position of just opened emboss window
if (m_allow_open_near_volume) {
@ -794,9 +799,7 @@ void GLGizmoEmboss::on_set_state()
}
}
void GLGizmoEmboss::data_changed(bool is_serializing) {
if (is_serializing)
reset_volume();
void GLGizmoEmboss::data_changed() {
set_volume_by_selection();
}
@ -1001,13 +1004,15 @@ void GLGizmoEmboss::set_volume_by_selection()
if (gl_volume == nullptr)
return reset_volume();
const ModelObjectPtrs &objects = selection.get_model()->objects;
ModelVolume *volume =get_model_volume(*gl_volume, objects);
const ModelObjectPtrs &objects = m_parent.get_model()->objects;
ModelVolume *volume = get_model_volume(*gl_volume, objects);
if (volume == nullptr)
return reset_volume();
// is same volume as actual selected?
if (volume->id() == m_volume_id)
if (volume->id() == m_volume_id &&
m_volume != nullptr &&
volume->text_configuration->style == m_volume->text_configuration->style)
return;
// for changed volume notification is NOT valid

View File

@ -47,6 +47,10 @@ public:
/// <param name="volume_type">Object part / Negative volume / Modifier</param>
void create_volume(ModelVolumeType volume_type);
/// <summary>
/// Handle pressing of shortcut
/// </summary>
void on_shortcut_key();
protected:
bool on_init() override;
bool on_is_activable() const override;
@ -57,7 +61,7 @@ protected:
void on_render_input_window(float x, float y, float bottom_limit) override;
bool on_is_selectable() const override { return false; }
void on_set_state() override;
void data_changed(bool is_serializing) override; // selection changed
void data_changed() override; // selection changed
void on_set_hover_id() override{ m_rotate_gizmo.set_hover_id(m_hover_id); }
void on_enable_grabber(unsigned int id) override { m_rotate_gizmo.enable_grabber(); }
void on_disable_grabber(unsigned int id) override { m_rotate_gizmo.disable_grabber(); }
@ -304,10 +308,6 @@ private:
// True when m_text contain character unknown by selected font
bool m_text_contain_unknown_glyph = false;
// True from on_set_state(State::On) to first call of on_render_input_window()
// To know that on data_change when no volume is selected create new one
bool m_is_just_opened = false;
// cancel for previous update of volume to cancel finalize part
std::shared_ptr<std::atomic<bool>> m_job_cancel;

View File

@ -387,9 +387,9 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block)
m_parent.set_as_dirty();
}
void GLGizmoFdmSupports::data_changed(bool is_serializing)
void GLGizmoFdmSupports::data_changed()
{
GLGizmoPainterBase::data_changed(is_serializing);
GLGizmoPainterBase::data_changed();
if (! m_c->selection_info())
return;

View File

@ -28,7 +28,7 @@ protected:
private:
bool on_init() override;
void data_changed(bool is_serializing) override;
void data_changed() override;
void update_model_object() const override;
void update_from_model_object() override;

View File

@ -56,7 +56,7 @@ bool GLGizmoFlatten::on_mouse(const wxMouseEvent &mouse_event)
return false;
}
void GLGizmoFlatten::data_changed(bool is_serializing)
void GLGizmoFlatten::data_changed()
{
const Selection & selection = m_parent.get_selection();
const ModelObject *model_object = nullptr;

View File

@ -55,7 +55,7 @@ public:
/// <returns>Return True when use the information otherwise False.</returns>
bool on_mouse(const wxMouseEvent &mouse_event) override;
void data_changed(bool is_serializing) override;
void data_changed() override;
protected:
bool on_init() override;
std::string on_get_name() const override;

View File

@ -42,7 +42,7 @@ bool GLGizmoHollow::on_init()
return true;
}
void GLGizmoHollow::data_changed(bool is_serializing)
void GLGizmoHollow::data_changed()
{
if (! m_c->selection_info())
return;

View File

@ -24,7 +24,7 @@ class GLGizmoHollow : public GLGizmoSlaBase
{
public:
GLGizmoHollow(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
void data_changed(bool is_serializing) override;
void data_changed() override;
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
void delete_selected_points();
bool is_selection_rectangle_dragging() const override {

View File

@ -454,7 +454,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event)
return false;
}
void GLGizmoMeasure::data_changed(bool is_serializing)
void GLGizmoMeasure::data_changed()
{
m_parent.toggle_sla_auxiliaries_visibility(false, nullptr, -1);

View File

@ -156,7 +156,7 @@ public:
/// <returns>Return True when use the information otherwise False.</returns>
bool on_mouse(const wxMouseEvent &mouse_event) override;
void data_changed(bool is_serializing) override;
void data_changed() override;
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);

View File

@ -147,9 +147,9 @@ void GLGizmoMmuSegmentation::render_painter_gizmo()
glsafe(::glDisable(GL_BLEND));
}
void GLGizmoMmuSegmentation::data_changed(bool is_serializing)
void GLGizmoMmuSegmentation::data_changed()
{
GLGizmoPainterBase::data_changed(is_serializing);
GLGizmoPainterBase::data_changed();
if (m_state != On || wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptFFF || wxGetApp().extruders_edited_cnt() <= 1)
return;

View File

@ -90,7 +90,7 @@ public:
void render_painter_gizmo() override;
void data_changed(bool is_serializing) override;
void data_changed() override;
void render_triangles(const Selection& selection) const override;

View File

@ -51,7 +51,7 @@ bool GLGizmoMove3D::on_mouse(const wxMouseEvent &mouse_event) {
return use_grabbers(mouse_event);
}
void GLGizmoMove3D::data_changed(bool is_serializing) {
void GLGizmoMove3D::data_changed() {
m_grabbers[2].enabled = !m_parent.get_selection().is_wipe_tower();
}

View File

@ -51,7 +51,7 @@ public:
/// <summary>
/// Detect reduction of move for wipetover on selection change
/// </summary>
void data_changed(bool is_serializing) override;
void data_changed() override;
protected:
bool on_init() override;
std::string on_get_name() const override;

View File

@ -31,7 +31,7 @@ GLGizmoPainterBase::~GLGizmoPainterBase()
s_sphere.reset();
}
void GLGizmoPainterBase::data_changed(bool is_serializing)
void GLGizmoPainterBase::data_changed()
{
if (m_state != On)
return;

View File

@ -83,7 +83,7 @@ private:
public:
GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
~GLGizmoPainterBase() override;
void data_changed(bool is_serializing) override;
void data_changed() override;
virtual bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
// Following function renders the triangles and cursor. Having this separated

View File

@ -600,7 +600,7 @@ bool GLGizmoRotate3D::on_mouse(const wxMouseEvent &mouse_event)
return use_grabbers(mouse_event);
}
void GLGizmoRotate3D::data_changed(bool is_serializing) {
void GLGizmoRotate3D::data_changed() {
if (m_parent.get_selection().is_wipe_tower()) {
#if !ENABLE_WORLD_COORDINATE
const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config;

View File

@ -146,7 +146,7 @@ public:
/// <returns>Return True when use the information otherwise False.</returns>
bool on_mouse(const wxMouseEvent &mouse_event) override;
void data_changed(bool is_serializing) override;
void data_changed() override;
protected:
bool on_init() override;
std::string on_get_name() const override;

View File

@ -105,7 +105,7 @@ void GLGizmoScale3D::enable_ununiversal_scale(bool enable)
m_grabbers[i].enabled = enable;
}
void GLGizmoScale3D::data_changed(bool is_serializing)
void GLGizmoScale3D::data_changed()
{
#if ENABLE_WORLD_COORDINATE
set_scale(Vec3d::Ones());

View File

@ -82,7 +82,7 @@ public:
/// <returns>Return True when use the information otherwise False.</returns>
bool on_mouse(const wxMouseEvent &mouse_event) override;
void data_changed(bool is_serializing) override;
void data_changed() override;
void enable_ununiversal_scale(bool enable);
protected:
virtual bool on_init() override;

View File

@ -49,7 +49,7 @@ bool GLGizmoSlaSupports::on_init()
return true;
}
void GLGizmoSlaSupports::data_changed(bool is_serializing)
void GLGizmoSlaSupports::data_changed()
{
if (! m_c->selection_info())
return;

View File

@ -55,7 +55,7 @@ private:
public:
GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);
virtual ~GLGizmoSlaSupports() = default;
void data_changed(bool is_serializing) override;
void data_changed() override;
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
void delete_selected_points(bool force = false);
//ClippingPlane get_sla_clipping_plane() const;

View File

@ -223,7 +223,7 @@ void GLGizmosManager::update_data()
m_common_gizmos_data->update(get_current()
? get_current()->get_requirements()
: CommonGizmosDataID(0));
if (m_current != Undefined) m_gizmos[m_current]->data_changed(m_serializing);
if (m_current != Undefined) m_gizmos[m_current]->data_changed();
}
bool GLGizmosManager::is_running() const
@ -245,7 +245,7 @@ bool GLGizmosManager::handle_shortcut(int key)
// allowe open shortcut even when selection is empty
if (GLGizmoBase* gizmo_emboss = m_gizmos[Emboss].get();
is_key(gizmo_emboss->get_shortcut_key())) {
dynamic_cast<GLGizmoEmboss *>(gizmo_emboss)->create_volume(ModelVolumeType::MODEL_PART);
dynamic_cast<GLGizmoEmboss *>(gizmo_emboss)->on_shortcut_key();
return true;
}