From 93131ab69c7da02aeb8001a56491df587f35a85e Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Mon, 15 Nov 2021 15:38:06 +0100 Subject: [PATCH] clean emboss from add volume --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 108 +++--------------------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 2 - src/slic3r/GUI/Jobs/EmbossJob.cpp | 24 +++--- src/slic3r/GUI/Jobs/EmbossJob.hpp | 4 +- 4 files changed, 23 insertions(+), 115 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 0c7664bc2..fd8f63161 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -475,75 +475,10 @@ bool GLGizmoEmboss::process() data.volume_name = create_volume_name(); data.volume_ptr = m_volume; data.object_idx = m_parent.get_selection().get_object_idx(); - m_job->restart(data); - return true; - ExPolygons shapes = Emboss::text2shapes(*m_font, m_text.c_str(), m_font_prop); - // exist 2d shape made by text ? - // (no shape means that font doesnt have any of text symbols) - if (shapes.empty()) return false; - - // after applied another font notification is no more valid + // notification is removed befor object is changed by job remove_notification_not_valid_font(); - - float scale = m_font_prop.size_in_mm / m_font->ascent; - auto project = std::make_unique( - std::make_unique(m_font_prop.emboss / scale), scale); - indexed_triangle_set its = Emboss::polygons2model(shapes, *project); - return add_volume(create_volume_name(), its); -} - -bool GLGizmoEmboss::add_volume(const std::string & name, - indexed_triangle_set &its) -{ - if (its.indices.empty()) return false; - // add object - TriangleMesh tm(std::move(its)); - // center triangle mesh - Vec3d shift = tm.bounding_box().center(); - tm.translate(-shift.cast()); - - GUI_App &app = wxGetApp(); - Plater * plater = app.plater(); - plater->take_snapshot(_L("Emboss text") + ": " + name); - if (m_volume == nullptr) { - // decide to add as volume or new object - const Selection &selection = m_parent.get_selection(); - if (selection.is_empty() || selection.get_object_idx() < 0) { - TextConfiguration text_configuration = create_configuration(); - // create new object - app.obj_list()->load_mesh_object(tm, name, true, &text_configuration); - app.mainframe->update_title(); - - // load mesh cause close gizmo, on windows but not on linux - // Open gizmo again when it is closed - GLGizmosManager& mng = m_parent.get_gizmos_manager(); - if (mng.get_current_type() != GLGizmosManager::Emboss) - mng.open_gizmo(GLGizmosManager::Emboss); - return true; - } else { - // create new volume inside of object - int object_idx = selection.get_object_idx(); - ModelObject *obj = plater->model().objects[object_idx]; - m_volume = obj->add_volume(std::move(tm)); - // set a default extruder value, since user can't add it manually - m_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - } - } else { - // update volume - m_volume->set_mesh(std::move(tm)); - m_volume->set_new_unique_id(); - m_volume->calculate_convex_hull(); - m_volume->get_object()->invalidate_bounding_box(); - } - m_volume->name = name; - m_volume->text_configuration = create_configuration(); - - // update volume name in object list - refresh_object_list(); - - m_parent.reload_scene(true); return true; } @@ -607,14 +542,16 @@ void GLGizmoEmboss::draw_font_list() } else if (ImGui::IsItemHovered()) ImGui::SetTooltip( _u8L("Choose from installed font inside dialog.").c_str()); - + +#ifdef ALLOW_DEBUG_MODE + ImGui::SameLine(); // select font file by file browser - // if (ImGui::Button(_u8L("Add File").c_str())) { - // choose_true_type_file(); - // store_font_list(); - // ImGui::CloseCurrentPopup(); - //} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file - //with font(.ttf, .ttc)").c_str()); + if (ImGui::Button(_u8L("Add File").c_str())) { + choose_true_type_file(); + store_font_list(); + ImGui::CloseCurrentPopup(); + } else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file with font(.ttf, .ttc)").c_str()); +#endif // ALLOW_DEBUG_MODE ImGui::Separator(); @@ -807,29 +744,6 @@ bool GLGizmoEmboss::create_default_model_object() return false; } -void GLGizmoEmboss::refresh_object_list() -{ - const Selection &selection = m_parent.get_selection(); - if (selection.is_empty() || - selection.get_object_idx() < 0 || - m_volume == nullptr) - return; - - ObjectList * obj_list = wxGetApp().obj_list(); - ModelVolume *volume = m_volume; // copy for lambda - - // select only actual volume - // when new volume is created change selection to this volume - auto add_to_selection = [volume](const ModelVolume *vol) { return vol == volume;}; - wxDataViewItemArray sel = obj_list->reorder_volumes_and_get_selection( - selection.get_object_idx(), add_to_selection); - - if (!sel.IsEmpty()) - obj_list->select_item(sel.front()); - - obj_list->selection_changed(); -} - bool GLGizmoEmboss::load_font(size_t font_index) { std::swap(font_index, m_font_selected); @@ -1070,7 +984,7 @@ bool GLGizmoEmboss::choose_svg_file() // for (auto &poly : polys) poly.scale(1e5); // SVG svg("converted.svg", BoundingBox(polys.front().contour.points)); // svg.draw(polys); - return add_volume(name, its); + //return add_volume(name, its); } TextConfiguration GLGizmoEmboss::create_configuration() diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index ea3c42dca..5de88de68 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -51,7 +51,6 @@ private: static ModelVolume *get_selected_volume(const Selection &selection, const ModelObjectPtrs objects); // create volume from text - main functionality bool process(); - bool add_volume(const std::string& name, indexed_triangle_set& its); void close(); void draw_window(); void draw_font_list(); @@ -59,7 +58,6 @@ private: void draw_advanced(); bool create_default_model_object(); - void refresh_object_list(); bool load_font(); // try to set font_index diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 07baae11c..6b4138ed4 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -3,6 +3,7 @@ #include "libslic3r/Model.hpp" #include "slic3r/GUI/Plater.hpp" +#include "slic3r/GUI/NotificationManager.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/GUI/MainFrame.hpp" @@ -82,11 +83,10 @@ void EmbossJob::finalize() { Vec3d shift = tm.bounding_box().center(); tm.translate(-shift.cast()); - GUI_App &app = wxGetApp(); - Plater * plater = app.plater(); + GUI_App & app = wxGetApp(); + Plater * plater = app.plater(); GLCanvas3D *canvas = plater->canvas3D(); - std::string name = m_data->volume_name; - + const std::string &name = m_data->volume_name; plater->take_snapshot(_L("Emboss text") + ": " + name); ModelVolume *volume = m_data->volume_ptr; @@ -106,12 +106,12 @@ void EmbossJob::finalize() { return; } else { // create new volume inside of object - Model & model = wxGetApp().plater()->model(); + Model &model = plater->model(); + if (model.objects.size() <= m_data->object_idx) return; ModelObject *obj = model.objects[m_data->object_idx]; volume = obj->add_volume(std::move(tm)); - // set a default extruder value, since user can't add it manually - volume->config.set_key_value("extruder", new ConfigOptionInt(0)); + volume->config.set_key_value("extruder", new ConfigOptionInt(0)); } } else { // update volume @@ -125,13 +125,9 @@ void EmbossJob::finalize() { volume->text_configuration = m_data->text_configuration; // update volume name in object list - select_volume(volume); - - //ObjectList *obj_list = wxGetApp().obj_list(); - //obj_list->selection_changed(); - - // after applied another font notification is no more valid - //remove_notification_not_valid_font(); + // updata selection after new volume added + // change name of volume in right panel + select_volume(volume); // Job promiss to refresh is not working canvas->reload_scene(true); diff --git a/src/slic3r/GUI/Jobs/EmbossJob.hpp b/src/slic3r/GUI/Jobs/EmbossJob.hpp index 1a363e8a9..279c4af49 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.hpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.hpp @@ -22,7 +22,7 @@ class EmbossJob : protected Job public: struct Data { - // Pointer on Data of font(glyoh shapes) + // Pointer on Data of font (glyph shapes) std::shared_ptr font; // font item is not used for create object TextConfiguration text_configuration; @@ -31,7 +31,7 @@ public: // when volume_ptr == nullptr than new volume will be created ModelVolume *volume_ptr; // when volume_ptr == nullptr && object_idx < 0 than new object will be created - int object_idx; + int object_idx; }; EmbossJob(); void restart(const Data &data);