mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 23:23:59 -06:00
Recalculate SLA supports after undo/redo in case SLA gizmo was active and had supports when the snapshot was taken
This commit is contained in:
parent
b55a140ad4
commit
52933d1bab
6 changed files with 72 additions and 18 deletions
|
@ -528,7 +528,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
|
|||
if (m_selection_empty) {
|
||||
std::pair<Vec3f, Vec3f> pos_and_normal;
|
||||
if (unproject_on_mesh(mouse_position, pos_and_normal)) { // we got an intersection
|
||||
wxGetApp().plater()->take_snapshot(_(L("Add support point")));
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Add support point")));
|
||||
m_editing_cache.emplace_back(sla::SupportPoint(pos_and_normal.first, m_new_point_head_diameter/2.f, false), false, pos_and_normal.second);
|
||||
m_parent.set_as_dirty();
|
||||
m_wait_for_up_event = true;
|
||||
|
@ -716,14 +716,12 @@ void GLGizmoSlaSupports::delete_selected_points(bool force)
|
|||
std::abort();
|
||||
}
|
||||
|
||||
wxGetApp().plater()->take_snapshot(_(L("Delete support point")));
|
||||
Plater::TakeSnapshot(wxGetApp().plater(), _(L("Delete support point")));
|
||||
|
||||
for (unsigned int idx=0; idx<m_editing_cache.size(); ++idx) {
|
||||
if (m_editing_cache[idx].selected && (!m_editing_cache[idx].support_point.is_new_island || !m_lock_unique_islands || force)) {
|
||||
m_editing_cache.erase(m_editing_cache.begin() + (idx--));
|
||||
}
|
||||
// This should trigger the support generation
|
||||
// wxGetApp().plater()->reslice_SLA_supports(*m_model_object);
|
||||
}
|
||||
|
||||
select_point(NoPoints);
|
||||
|
@ -919,7 +917,7 @@ RENDER_AGAIN:
|
|||
cache_entry.support_point.head_front_radius = m_old_point_head_diameter / 2.f;
|
||||
float backup = m_new_point_head_diameter;
|
||||
m_new_point_head_diameter = m_old_point_head_diameter;
|
||||
wxGetApp().plater()->take_snapshot(_(L("Change point head diameter")));
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Change point head diameter")));
|
||||
m_new_point_head_diameter = backup;
|
||||
for (auto& cache_entry : m_editing_cache)
|
||||
if (cache_entry.selected)
|
||||
|
@ -985,7 +983,7 @@ RENDER_AGAIN:
|
|||
if (slider_released) {
|
||||
m_model_object->config.opt<ConfigOptionFloat>("support_points_minimal_distance", true)->value = m_minimal_point_distance_stash;
|
||||
m_model_object->config.opt<ConfigOptionInt>("support_points_density_relative", true)->value = (int)m_density_stash;
|
||||
wxGetApp().plater()->take_snapshot(_(L("Support parameter change")));
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Support parameter change")));
|
||||
m_model_object->config.opt<ConfigOptionFloat>("support_points_minimal_distance", true)->value = minimal_point_distance;
|
||||
m_model_object->config.opt<ConfigOptionInt>("support_points_density_relative", true)->value = (int)density;
|
||||
wxGetApp().obj_list()->update_and_show_object_settings_item();
|
||||
|
@ -1186,7 +1184,7 @@ void GLGizmoSlaSupports::on_stop_dragging()
|
|||
&& backup.support_point.pos != m_point_before_drag.support_point.pos) // and it was moved, not just selected
|
||||
{
|
||||
m_editing_cache[m_hover_id] = m_point_before_drag;
|
||||
wxGetApp().plater()->take_snapshot(_(L("Move support point")));
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Move support point")));
|
||||
m_editing_cache[m_hover_id] = backup;
|
||||
}
|
||||
}
|
||||
|
@ -1285,7 +1283,7 @@ void GLGizmoSlaSupports::editing_mode_apply_changes()
|
|||
disable_editing_mode(); // this leaves the editing mode undo/redo stack and must be done before the snapshot is taken
|
||||
|
||||
if (unsaved_changes()) {
|
||||
wxGetApp().plater()->take_snapshot(_(L("Support points edit")));
|
||||
take_snapshot_internal(_(L("Support points edit")));
|
||||
|
||||
m_normal_cache.clear();
|
||||
for (const CacheEntry& ce : m_editing_cache)
|
||||
|
@ -1295,7 +1293,7 @@ void GLGizmoSlaSupports::editing_mode_apply_changes()
|
|||
m_model_object->sla_support_points.clear();
|
||||
m_model_object->sla_support_points = m_normal_cache;
|
||||
|
||||
wxGetApp().CallAfter([this]() { wxGetApp().plater()->reslice_SLA_supports(*m_model_object); });
|
||||
reslice_SLA_supports();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1312,11 +1310,29 @@ void GLGizmoSlaSupports::reload_cache()
|
|||
}
|
||||
|
||||
|
||||
bool GLGizmoSlaSupports::has_backend_supports() const
|
||||
{
|
||||
// find SlaPrintObject with this ID
|
||||
for (const SLAPrintObject* po : m_parent.sla_print()->objects()) {
|
||||
if (po->model_object()->id() == m_model_object->id() && po->is_step_done(slaposSupportPoints))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GLGizmoSlaSupports::reslice_SLA_supports() const
|
||||
{
|
||||
wxGetApp().CallAfter([this]() { wxGetApp().plater()->reslice_SLA_supports(*m_model_object); });
|
||||
}
|
||||
|
||||
void GLGizmoSlaSupports::get_data_from_backend()
|
||||
{
|
||||
if (! has_backend_supports())
|
||||
return;
|
||||
|
||||
// find the respective SLAPrintObject, we need a pointer to it
|
||||
for (const SLAPrintObject* po : m_parent.sla_print()->objects()) {
|
||||
if (po->model_object()->id() == m_model_object->id() && po->is_step_done(slaposSupportPoints)) {
|
||||
if (po->model_object()->id() == m_model_object->id()) {
|
||||
m_normal_cache.clear();
|
||||
const std::vector<sla::SupportPoint>& points = po->get_support_points();
|
||||
auto mat = po->trafo().inverse().cast<float>();
|
||||
|
@ -1331,6 +1347,13 @@ void GLGizmoSlaSupports::get_data_from_backend()
|
|||
// We don't copy the data into ModelObject, as this would stop the background processing.
|
||||
}
|
||||
|
||||
void GLGizmoSlaSupports::take_snapshot_internal(const wxString& desc)
|
||||
{
|
||||
m_internal_snapshot = true;
|
||||
Plater::TakeSnapshot snapshot(wxGetApp().plater(), desc);
|
||||
m_internal_snapshot = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GLGizmoSlaSupports::auto_generate()
|
||||
|
@ -1341,8 +1364,8 @@ void GLGizmoSlaSupports::auto_generate()
|
|||
)), _(L("Warning")), wxICON_WARNING | wxYES | wxNO);
|
||||
|
||||
if (m_model_object->sla_points_status != sla::PointsStatus::UserModified || m_normal_cache.empty() || dlg.ShowModal() == wxID_YES) {
|
||||
wxGetApp().plater()->take_snapshot(_(L("Autogenerate support points")));
|
||||
wxGetApp().CallAfter([this]() { wxGetApp().plater()->reslice_SLA_supports(*m_model_object); });
|
||||
take_snapshot_internal(_(L("Autogenerate support points")));
|
||||
wxGetApp().CallAfter([this]() { reslice_SLA_supports(); });
|
||||
m_model_object->sla_points_status = sla::PointsStatus::Generating;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ public:
|
|||
|
||||
bool is_in_editing_mode() const { return m_editing_mode; }
|
||||
bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); }
|
||||
bool has_backend_supports() const;
|
||||
void reslice_SLA_supports() const;
|
||||
|
||||
private:
|
||||
bool on_init();
|
||||
|
@ -100,6 +102,7 @@ private:
|
|||
void update_mesh();
|
||||
void update_cache_entry_normal(unsigned int i) const;
|
||||
bool unsaved_changes() const;
|
||||
void take_snapshot_internal(const wxString& desc);
|
||||
|
||||
EState m_no_hover_state = Off;
|
||||
EState m_no_hover_old_state = Off;
|
||||
|
@ -128,6 +131,7 @@ private:
|
|||
bool m_wait_for_up_event = false;
|
||||
bool m_selection_empty = true;
|
||||
EState m_old_state = Off; // to be able to see that the gizmo has just been closed (see on_set_state)
|
||||
bool m_internal_snapshot = false;
|
||||
|
||||
mutable std::unique_ptr<TriangleMeshSlicer> m_tms;
|
||||
mutable std::unique_ptr<TriangleMeshSlicer> m_supports_tms;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/GUI_ObjectManipulation.hpp"
|
||||
#include "slic3r/GUI/PresetBundle.hpp"
|
||||
#include "slic3r/Utils/UndoRedo.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <wx/glcanvas.h>
|
||||
|
@ -464,6 +465,11 @@ ClippingPlane GLGizmosManager::get_sla_clipping_plane() const
|
|||
return ClippingPlane::ClipsNothing();
|
||||
}
|
||||
|
||||
bool GLGizmosManager::wants_reslice_supports_on_undo() const
|
||||
{
|
||||
return (m_current == SlaSupports
|
||||
&& dynamic_cast<const GLGizmoSlaSupports*>(m_gizmos.at(SlaSupports))->has_backend_supports());
|
||||
}
|
||||
|
||||
void GLGizmosManager::render_current_gizmo() const
|
||||
{
|
||||
|
@ -870,10 +876,13 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt)
|
|||
return processed;
|
||||
}
|
||||
|
||||
void GLGizmosManager::update_after_undo_redo()
|
||||
void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot)
|
||||
{
|
||||
update_data();
|
||||
m_serializing = false;
|
||||
if (m_current == SlaSupports
|
||||
&& snapshot.snapshot_data.flags & UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS)
|
||||
dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports])->reslice_SLA_supports();
|
||||
}
|
||||
|
||||
void GLGizmosManager::reset()
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
#include <map>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace UndoRedo {
|
||||
class Snapshot;
|
||||
}
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class GLCanvas3D;
|
||||
|
@ -173,6 +178,7 @@ public:
|
|||
void set_sla_support_data(ModelObject* model_object);
|
||||
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position = Vec2d::Zero(), bool shift_down = false, bool alt_down = false, bool control_down = false);
|
||||
ClippingPlane get_sla_clipping_plane() const;
|
||||
bool wants_reslice_supports_on_undo() const;
|
||||
|
||||
void render_current_gizmo() const;
|
||||
void render_current_gizmo_for_picking_pass() const;
|
||||
|
@ -186,7 +192,7 @@ public:
|
|||
bool on_char(wxKeyEvent& evt);
|
||||
bool on_key(wxKeyEvent& evt);
|
||||
|
||||
void update_after_undo_redo();
|
||||
void update_after_undo_redo(const UndoRedo::Snapshot& snapshot);
|
||||
|
||||
private:
|
||||
void reset();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue