ENH:meshboolean: fix crash and set a warning notification

1.add warning notification
2.fix a crash while delete volume from object_list

Change-Id: Iafcbe420dfb4c5d1b324365e6c5160745ad0be3b
This commit is contained in:
liz.li 2023-06-20 15:51:04 +08:00 committed by Lane.Wei
parent e2934516ed
commit 85b44fbe1f
2 changed files with 26 additions and 7 deletions

View File

@ -6,6 +6,7 @@
#include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/Camera.hpp"
#include "slic3r/GUI/NotificationManager.hpp"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
@ -13,6 +14,8 @@
namespace Slic3r {
namespace GUI {
static const std::string warning_text = _u8L("Unable to perform boolean operation on selected parts");
GLGizmoMeshBoolean::GLGizmoMeshBoolean(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
: GLGizmoBase(parent, icon_filename, sprite_id)
{
@ -151,6 +154,7 @@ void GLGizmoMeshBoolean::on_set_state()
bool m_inter_delete_input = false;
m_operation_mode = MeshBooleanOperation::Undef;
m_selecting_state = MeshBooleanSelectingState::Undef;
wxGetApp().notification_manager()->close_plater_warning_notification(warning_text);
}
}
@ -315,8 +319,13 @@ void GLGizmoMeshBoolean::on_render_input_window(float x, float y, float bottom_l
temp_tool_mesh.transform(m_tool.trafo);
std::vector<TriangleMesh> temp_mesh_resuls;
Slic3r::MeshBoolean::mcut::make_boolean(temp_src_mesh, temp_tool_mesh, temp_mesh_resuls, "UNION");
if (temp_mesh_resuls.size() != 0)
if (temp_mesh_resuls.size() != 0) {
generate_new_volume(true, *temp_mesh_resuls.begin());
wxGetApp().notification_manager()->close_plater_warning_notification(warning_text);
}
else {
wxGetApp().notification_manager()->push_plater_warning_notification(warning_text);
}
}
}
else if (m_operation_mode == MeshBooleanOperation::Difference) {
@ -328,8 +337,13 @@ void GLGizmoMeshBoolean::on_render_input_window(float x, float y, float bottom_l
temp_tool_mesh.transform(m_tool.trafo);
std::vector<TriangleMesh> temp_mesh_resuls;
Slic3r::MeshBoolean::mcut::make_boolean(temp_src_mesh, temp_tool_mesh, temp_mesh_resuls, "A_NOT_B");
if (temp_mesh_resuls.size() != 0)
if (temp_mesh_resuls.size() != 0) {
generate_new_volume(m_diff_delete_input, *temp_mesh_resuls.begin());
wxGetApp().notification_manager()->close_plater_warning_notification(warning_text);
}
else {
wxGetApp().notification_manager()->push_plater_warning_notification(warning_text);
}
}
}
else if (m_operation_mode == MeshBooleanOperation::Intersection){
@ -341,8 +355,13 @@ void GLGizmoMeshBoolean::on_render_input_window(float x, float y, float bottom_l
temp_tool_mesh.transform(m_tool.trafo);
std::vector<TriangleMesh> temp_mesh_resuls;
Slic3r::MeshBoolean::mcut::make_boolean(temp_src_mesh, temp_tool_mesh, temp_mesh_resuls, "INTERSECTION");
if (temp_mesh_resuls.size() != 0)
if (temp_mesh_resuls.size() != 0) {
generate_new_volume(m_inter_delete_input, *temp_mesh_resuls.begin());
wxGetApp().notification_manager()->close_plater_warning_notification(warning_text);
}
else {
wxGetApp().notification_manager()->push_plater_warning_notification(warning_text);
}
}
}
@ -401,8 +420,8 @@ void GLGizmoMeshBoolean::generate_new_volume(bool delete_input, const TriangleMe
if (delete_input) {
std::vector<ItemForDelete> items;
const Selection& selection = m_parent.get_selection();
items.emplace_back(ItemType::itVolume, selection.get_volume(0)->object_idx(), m_tool.volume_idx);
auto obj_idx = m_parent.get_selection().get_object_idx();
items.emplace_back(ItemType::itVolume, obj_idx, m_tool.volume_idx);
wxGetApp().obj_list()->delete_from_model_and_list(items);
}

View File

@ -43,12 +43,12 @@ public:
void set_src_volume(ModelVolume* mv) {
m_src.mv = mv;
if (m_src.mv == m_tool.mv)
m_tool.mv = nullptr;
m_tool.reset();
}
void set_tool_volume(ModelVolume* mv) {
m_tool.mv = mv;
if (m_tool.mv == m_src.mv)
m_src.mv = nullptr;
m_src.reset();
}
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);