From 7bb0b7eefc3dc4bc5fdb10da5c3afa469a2843e1 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 20 Oct 2022 16:34:21 +0200 Subject: [PATCH] Cut bug fixing: Fixed a place of connectors after several cutting + Added info about camera direction to a DEBUG window + Code factoring (deleted unused code) + Fixed build warnings --- src/libslic3r/Model.cpp | 6 ++- src/slic3r/GUI/Field.cpp | 2 +- src/slic3r/GUI/GUI_ObjectList.cpp | 11 +++--- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 52 ++++++++++++++++--------- src/slic3r/GUI/SavePresetDialog.cpp | 2 +- src/slic3r/GUI/UnsavedChangesDialog.hpp | 2 +- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index aa21c3ade..3c4e00454 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1232,6 +1232,8 @@ indexed_triangle_set ModelObject::get_connector_mesh(CutConnectorAttributes conn case CutConnectorShape::Hexagon: sectorCount = 6; break; + default: + break; } if (connector_attributes.style == CutConnectorStyle::Prizm) @@ -1395,11 +1397,11 @@ void ModelObject::process_connector_cut(ModelVolume* volume, ModelObjectCutAttri void ModelObject::process_modifier_cut(ModelVolume* volume, const Transform3d& instance_matrix, const Transform3d& inverse_cut_matrix, ModelObjectCutAttributes attributes, ModelObject* upper, ModelObject* lower) { - const auto volume_matrix = volume->get_matrix(); + const auto volume_matrix = instance_matrix * volume->get_matrix(); // Modifiers are not cut, but we still need to add the instance transformation // to the modifier volume transformation to preserve their shape properly. - volume->set_transformation(Geometry::Transformation(instance_matrix * volume_matrix)); + volume->set_transformation(Geometry::Transformation(volume_matrix)); // Some logic for the negative volumes/connectors. Add only needed modifiers auto bb = volume->mesh().transformed_bounding_box(inverse_cut_matrix * volume_matrix); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index e674b52d0..bedb3718e 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -33,7 +33,7 @@ wxString double_to_string(double const value, const int max_precision /*= 4*/) // Style_NoTrailingZeroes does not work on OSX. It also does not work correctly with some locales on Windows. // return wxNumberFormatter::ToString(value, max_precision, wxNumberFormatter::Style_NoTrailingZeroes); - wxString s = wxNumberFormatter::ToString(value, value < 0.0001 ? 10 : max_precision, wxNumberFormatter::Style_None); + wxString s = wxNumberFormatter::ToString(value, std::abs(value) < 0.0001 ? 10 : max_precision, wxNumberFormatter::Style_None); // The following code comes from wxNumberFormatter::RemoveTrailingZeroes(wxString& s) // with the exception that here one sets the decimal separator explicitely to dot. diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index ac9602985..5be1efed1 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2990,9 +2990,9 @@ void ObjectList::delete_instance_from_list(const size_t obj_idx, const size_t in void ObjectList::update_lock_icons_for_model() { - for (int obj_idx = 0; obj_idx < (*m_objects).size(); ++obj_idx) + for (size_t obj_idx = 0; obj_idx < (*m_objects).size(); ++obj_idx) if (!(*m_objects)[obj_idx]->is_cut()) - m_objects_model->UpdateLockIcon(m_objects_model->GetItemById(obj_idx), false); + m_objects_model->UpdateLockIcon(m_objects_model->GetItemById(int(obj_idx)), false); } bool ObjectList::delete_from_model_and_list(const ItemType type, const int obj_idx, const int sub_obj_idx) @@ -4088,15 +4088,16 @@ bool ObjectList::fix_cut_selection(wxDataViewItemArray& sels) bool is_instance_selection = m_objects_model->GetItemType(item) & itInstance; - int obj_idx = m_objects_model->GetObjectIdByItem(item); + int object_idx = m_objects_model->GetObjectIdByItem(item); int inst_idx = is_instance_selection ? m_objects_model->GetInstanceIdByItem(item) : 0; - if (auto obj = object(obj_idx); obj->is_cut()) { + if (auto obj = object(object_idx); obj->is_cut()) { sels.Clear(); auto cut_id = obj->cut_id; - for (int obj_idx = 0; obj_idx < (*m_objects).size(); ++obj_idx) { + int objects_cnt = int((*m_objects).size()); + for (int obj_idx = 0; obj_idx < objects_cnt; ++obj_idx) { auto object = (*m_objects)[obj_idx]; if (object->is_cut() && object->cut_id.has_same_id(cut_id)) sels.Add(is_instance_selection ? m_objects_model->GetItemByInstanceId(obj_idx, inst_idx) : m_objects_model->GetItemById(obj_idx)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 56dd56462..fcb5cc247 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -578,13 +578,9 @@ void GLGizmoCut3D::render_cut_plane_line() const Camera& camera = wxGetApp().plater()->get_camera(); - Vec3d unit_dir = m_rotation_m * Vec3d::UnitZ(); - unit_dir.normalize(); + const Vec3d unit_dir = m_rotation_m * Vec3d::UnitZ(); - Vec3d camera_dir = camera.get_dir_forward(); - camera_dir.normalize(); - - if (std::abs(unit_dir.dot(camera_dir)) <= 0.025) { + if (std::abs(unit_dir.dot(camera.get_dir_forward())) <= 0.025) { GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); if (shader) { m_circle.reset(); @@ -665,7 +661,6 @@ void GLGizmoCut3D::render_line(GLModel& line_model, const ColorRGBA& color, Tran if (shader) { shader->start_using(); - const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", wxGetApp().plater()->get_camera().get_projection_matrix()); shader->set_uniform("width", width); @@ -734,11 +729,11 @@ void GLGizmoCut3D::render_cut_plane_grabbers() // render Z grabber - if ((!m_dragging && m_hover_id < 0)) + if (!m_dragging && m_hover_id < 0) render_grabber_connection(color, view_matrix); render_model(m_sphere.model, color, view_matrix * scale_transform(size)); - if (!m_dragging && m_hover_id < 0 || m_hover_id == Z) + if ((!m_dragging && m_hover_id < 0) || m_hover_id == Z) { const BoundingBoxf3 tbb = transformed_bounding_box(); if (tbb.min.z() <= 0.0) @@ -867,9 +862,9 @@ void GLGizmoCut3D::on_set_state() m_parent.request_extra_frame(); } - else + else { m_c->object_clipper()->release(); - + } force_update_clipper_on_render = m_state == On; } @@ -1398,6 +1393,34 @@ void GLGizmoCut3D::render_debug_input_window() if (auto oc = m_c->object_clipper()) oc->set_behavior(hide_clipped || m_connectors_editing, fill_cut || m_connectors_editing, double(contour_width)); + ImGui::Separator(); + + // Camera editing + + auto get_label = [](Vec3d dir) { + wxString str = "x=" + double_to_string(dir.x(), 2) + + ", y=" + double_to_string(dir.y(), 2) + + ", z=" + double_to_string(dir.z(), 2); + return str; + }; + + const Camera& camera = wxGetApp().plater()->get_camera(); + + Vec3d unit_dir = m_rotation_m * Vec3d::UnitZ(); + m_imgui->text("Unit dir: "); + ImGui::SameLine(m_label_width); + m_imgui->text(get_label(unit_dir)); + + Vec3d camera_dir = camera.get_dir_forward(); + m_imgui->text("Camera dir: "); + ImGui::SameLine(m_label_width); + m_imgui->text(get_label(camera_dir)); + + m_imgui->text("Unit2Camera: "); + double proj = unit_dir.dot(camera_dir); + ImGui::SameLine(m_label_width); + m_imgui->text_colored(std::abs(proj) <= 0.025 ? ImGuiWrapper::COL_ORANGE_LIGHT : ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()), double_to_string(proj, 2)); + m_imgui->end(); } @@ -2021,13 +2044,6 @@ void GLGizmoCut3D::discard_cut_line_processing() bool GLGizmoCut3D::process_cut_line(SLAGizmoEventType action, const Vec2d& mouse_position) { - const float sla_shift = m_c->selection_info()->get_sla_shift(); - const ModelObject* mo = m_c->selection_info()->model_object(); - const ModelInstance* mi = mo->instances[m_c->selection_info()->get_active_instance()]; - Transform3d inst_trafo = sla_shift > 0.f ? - assemble_transform(Vec3d(0.0, 0.0, sla_shift)) * mi->get_transformation().get_matrix() : - mi->get_transformation().get_matrix(); - const Camera& camera = wxGetApp().plater()->get_camera(); Vec3d pt; diff --git a/src/slic3r/GUI/SavePresetDialog.cpp b/src/slic3r/GUI/SavePresetDialog.cpp index 57aa5da98..40f981722 100644 --- a/src/slic3r/GUI/SavePresetDialog.cpp +++ b/src/slic3r/GUI/SavePresetDialog.cpp @@ -163,7 +163,7 @@ void SavePresetDialog::Item::update() if (m_valid_type == ValidationType::Valid && existing) { if (m_preset_name == m_presets->get_selected_preset_name()) { - if (!rename && m_presets->get_edited_preset().is_dirty || + if ((!rename && m_presets->get_edited_preset().is_dirty) || m_parent->get_preset_bundle()) // means that we save modifications from the DiffDialog info_line = _L("Save preset modifications to existing user profile"); else diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index 69f808451..a0b53dadf 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -414,7 +414,7 @@ public: std::string get_left_preset_name(Preset::Type type); std::string get_right_preset_name(Preset::Type type); - std::vector get_selected_options(Preset::Type type) const { return std::move(m_tree->options(type, true)); } + std::vector get_selected_options(Preset::Type type) const { return m_tree->options(type, true); } protected: void on_dpi_changed(const wxRect& suggested_rect) override;