From ca5b310e433013204878f6f78a5d56fd893ebebc Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 15 Mar 2023 11:25:17 +0100 Subject: [PATCH] Fix: moving with text object(not volume) over build plate by canvas dragging --- src/libslic3r/Model.cpp | 19 +++++++++++++++++++ src/libslic3r/Model.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 18 ++++-------------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 9 --------- src/slic3r/GUI/SurfaceDrag.cpp | 4 ++++ 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 5e1574e60..6fdec8b14 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1397,6 +1397,25 @@ void ModelObject::clone_for_cut(ModelObject** obj) (*obj)->input_file.clear(); } +bool ModelVolume::is_the_only_one_part() const +{ + if (m_type != ModelVolumeType::MODEL_PART) + return false; + if (object == nullptr) + return false; + for (const ModelVolume *v : object->volumes) { + if (v == nullptr) + continue; + // is this volume? + if (v->id() == this->id()) + continue; + // exist another model part in object? + if (v->type() == ModelVolumeType::MODEL_PART) + return false; + } + return true; +} + void ModelVolume::reset_extra_facets() { this->supported_facets.reset(); diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 08fa79481..3fd9f21bc 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -835,6 +835,7 @@ public: bool is_support_blocker() const { return m_type == ModelVolumeType::SUPPORT_BLOCKER; } bool is_support_modifier() const { return m_type == ModelVolumeType::SUPPORT_BLOCKER || m_type == ModelVolumeType::SUPPORT_ENFORCER; } bool is_text() const { return text_configuration.has_value(); } + bool is_the_only_one_part() const; // behave like an object t_model_material_id material_id() const { return m_material_id; } void reset_extra_facets(); void apply_tolerance(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 88ccde4bb..bc0b5e811 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1169,7 +1169,8 @@ void GLGizmoEmboss::close() m_volume->text_configuration.has_value() && priv::is_text_empty(m_text)) { Plater &p = *wxGetApp().plater(); - if (is_text_object(m_volume)) { + // is the text object? + if (m_volume->is_the_only_one_part()) { // delete whole object p.remove(m_parent.get_selection().get_object_idx()); } else { @@ -1912,7 +1913,7 @@ void GLGizmoEmboss::draw_font_list() void GLGizmoEmboss::draw_model_type() { - bool is_last_solid_part = is_text_object(m_volume); + bool is_last_solid_part = m_volume->is_the_only_one_part(); std::string title = _u8L("Text is to object"); if (is_last_solid_part) { ImVec4 color{.5f, .5f, .5f, 1.f}; @@ -2945,7 +2946,7 @@ void GLGizmoEmboss::draw_advanced() // input surface distance bool allowe_surface_distance = !m_volume->text_configuration->style.prop.use_surface && - !is_text_object(m_volume); + !m_volume->is_the_only_one_part(); std::optional &distance = font_prop.distance; float prev_distance = distance.has_value() ? *distance : .0f, min_distance = -2 * font_prop.emboss, @@ -3336,17 +3337,6 @@ bool priv::draw_button(const IconManager::VIcons &icons, IconType type, bool dis ); } -bool GLGizmoEmboss::is_text_object(const ModelVolume *text) { - if (text == nullptr) return false; - if (!text->text_configuration.has_value()) return false; - if (text->type() != ModelVolumeType::MODEL_PART) return false; - for (const ModelVolume *v : text->get_object()->volumes) { - if (v == text) continue; - if (v->type() == ModelVolumeType::MODEL_PART) return false; - } - return true; -} - ///////////// // priv namespace implementation /////////////// diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 7e7c2aa16..730b7354c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -328,15 +328,6 @@ private: // only temporary solution static const std::string M_ICON_FILENAME; - -public: - /// - /// Check if text is last solid part of object - /// TODO: move to emboss gui utils - /// - /// Model volume of Text - /// True when object otherwise False - static bool is_text_object(const ModelVolume *text); }; } // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/SurfaceDrag.cpp b/src/slic3r/GUI/SurfaceDrag.cpp index 0f2f1706a..f32113698 100644 --- a/src/slic3r/GUI/SurfaceDrag.cpp +++ b/src/slic3r/GUI/SurfaceDrag.cpp @@ -116,6 +116,10 @@ bool on_mouse_surface_drag(const wxMouseEvent &mouse_event, if (object == nullptr || instance == nullptr || volume == nullptr) return false; + // allowed drag&drop by canvas for object + if (volume->is_the_only_one_part()) + return false; + const ModelVolumePtrs &volumes = object->volumes; std::vector allowed_volumes_id; if (volumes.size() > 1) {