mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -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(); | ||||
|  |  | |||
|  | @ -1908,7 +1908,7 @@ private: | |||
|     void update_fff_scene(); | ||||
|     void update_sla_scene(); | ||||
|     void undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator it_snapshot); | ||||
|     void update_after_undo_redo(bool temp_snapshot_was_taken = false); | ||||
|     void update_after_undo_redo(const UndoRedo::Snapshot& snapshot, bool temp_snapshot_was_taken = false); | ||||
| 
 | ||||
|     // path to project file stored with no extension
 | ||||
|     wxString 					m_project_filename; | ||||
|  | @ -3823,6 +3823,12 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name) | |||
|     } | ||||
|     else if (this->sidebar->obj_list()->is_selected(itLayerRoot)) | ||||
|         snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR; | ||||
| 
 | ||||
|     // If SLA gizmo is active, ask it if it wants to trigger support generation
 | ||||
|     // on loading this snapshot.
 | ||||
|     if (view3D->get_canvas3d()->get_gizmos_manager().wants_reslice_supports_on_undo()) | ||||
|         snapshot_data.flags |= UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS; | ||||
| 
 | ||||
|     //FIXME updating the Wipe tower config values at the ModelWipeTower from the Print config.
 | ||||
|     // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print config.
 | ||||
|     if (this->printer_technology == ptFFF) { | ||||
|  | @ -3908,9 +3914,14 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator | |||
|     bool         new_selected_layer_on_sidebar     = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYER_ON_SIDEBAR) != 0; | ||||
|     bool         new_selected_layerroot_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR) != 0; | ||||
| 
 | ||||
|     if (this->view3D->get_canvas3d()->get_gizmos_manager().wants_reslice_supports_on_undo()) | ||||
|         top_snapshot_data.flags |= UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS; | ||||
| 
 | ||||
|     // Disable layer editing before the Undo / Redo jump.
 | ||||
|     if (!new_variable_layer_editing_active && view3D->is_layers_editing_enabled()) | ||||
|         view3D->get_canvas3d()->force_main_toolbar_left_action(view3D->get_canvas3d()->get_main_toolbar_item_id("layersediting")); | ||||
|     // Make a copy of the snapshot, undo/redo could invalidate the iterator
 | ||||
|     const UndoRedo::Snapshot snapshot_copy = *it_snapshot; | ||||
|     // Do the jump in time.
 | ||||
|     if (it_snapshot->timestamp < this->undo_redo_stack().active_snapshot_time() ? | ||||
|         this->undo_redo_stack().undo(model, this->view3D->get_canvas3d()->get_selection(), this->view3D->get_canvas3d()->get_gizmos_manager(), top_snapshot_data, it_snapshot->timestamp) : | ||||
|  | @ -3948,14 +3959,14 @@ void Plater::priv::undo_redo_to(std::vector<UndoRedo::Snapshot>::const_iterator | |||
|         if (new_selected_settings_on_sidebar || new_selected_layer_on_sidebar) | ||||
|             this->sidebar->obj_list()->set_selected_layers_range_idx(layer_range_idx); | ||||
| 
 | ||||
|         this->update_after_undo_redo(temp_snapshot_was_taken); | ||||
|         this->update_after_undo_redo(snapshot_copy, temp_snapshot_was_taken); | ||||
|         // Enable layer editing after the Undo / Redo jump.
 | ||||
|         if (! view3D->is_layers_editing_enabled() && this->layers_height_allowed() && new_variable_layer_editing_active) | ||||
|             view3D->get_canvas3d()->force_main_toolbar_left_action(view3D->get_canvas3d()->get_main_toolbar_item_id("layersediting")); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void Plater::priv::update_after_undo_redo(bool /* temp_snapshot_was_taken */) | ||||
| void Plater::priv::update_after_undo_redo(const UndoRedo::Snapshot& snapshot, bool /* temp_snapshot_was_taken */) | ||||
| { | ||||
|     this->view3D->get_canvas3d()->get_selection().clear(); | ||||
|     // Update volumes from the deserializd model, always stop / update the background processing (for both the SLA and FFF technologies).
 | ||||
|  | @ -3967,7 +3978,7 @@ void Plater::priv::update_after_undo_redo(bool /* temp_snapshot_was_taken */) | |||
|         this->undo_redo_stack().release_least_recently_used(); | ||||
|     //YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?) (no selections at this point of time)
 | ||||
|     this->view3D->get_canvas3d()->get_selection().set_deserialized(GUI::Selection::EMode(this->undo_redo_stack().selection_deserialized().mode), this->undo_redo_stack().selection_deserialized().volumes_and_instances); | ||||
|     this->view3D->get_canvas3d()->get_gizmos_manager().update_after_undo_redo(); | ||||
|     this->view3D->get_canvas3d()->get_gizmos_manager().update_after_undo_redo(snapshot); | ||||
| 
 | ||||
|     wxGetApp().obj_list()->update_after_undo_redo(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -45,6 +45,7 @@ struct SnapshotData | |||
| 		SELECTED_SETTINGS_ON_SIDEBAR  = 2, | ||||
| 		SELECTED_LAYERROOT_ON_SIDEBAR = 4, | ||||
| 		SELECTED_LAYER_ON_SIDEBAR     = 8, | ||||
|         RECALCULATE_SLA_SUPPORTS      = 16 | ||||
| 	}; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena