From df5312d3b279cbcf64568b484706cfeabd10110d Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 28 Nov 2022 17:06:32 +0100 Subject: [PATCH 001/244] Fix to valid file name --- src/slic3r/GUI/Jobs/EmbossJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 56d8c7e45..a5fa47672 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -483,7 +483,7 @@ TriangleMesh priv::create_mesh(DataBase &input, Fnc was_canceled, Job::Ctl& ctl) TriangleMesh priv::create_default_mesh() { // When cant load any font use default object loaded from file - std::string path = Slic3r::resources_dir() + "/data/embossed_text.stl"; + std::string path = Slic3r::resources_dir() + "/data/embossed_text.obj"; TriangleMesh triangle_mesh; if (!load_obj(path.c_str(), &triangle_mesh)) { // when can't load mesh use cube From 7bb80a84aba778c51578182f391b08a1cb25dc49 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 28 Nov 2022 17:16:25 +0100 Subject: [PATCH 002/244] Fix UTF8 coding for filename --- src/admesh/shared.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/admesh/shared.cpp b/src/admesh/shared.cpp index 807d9ef4c..8ead78d08 100644 --- a/src/admesh/shared.cpp +++ b/src/admesh/shared.cpp @@ -210,8 +210,9 @@ bool its_write_obj(const indexed_triangle_set &its, const char *file) bool its_write_obj(const indexed_triangle_set& its, const std::vector &color, const char* file) { Slic3r::CNumericLocalesSetter locales_setter; - FILE* fp = fopen(file, "w"); + FILE* fp = boost::nowide::fopen(file, "w"); if (fp == nullptr) { + BOOST_LOG_TRIVIAL(error) << "stl_write_obj: Couldn't open " << file << " for writing"; return false; } From f022402963b52b79889c0e733e775fde17db899a Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 08:42:29 +0100 Subject: [PATCH 003/244] Revert ModelVolumeType separation --- src/libslic3r/CMakeLists.txt | 1 - src/libslic3r/Model.hpp | 1 - src/libslic3r/ModelVolumeType.hpp | 16 ---------------- src/slic3r/GUI/Jobs/EmbossJob.hpp | 1 - 4 files changed, 19 deletions(-) delete mode 100644 src/libslic3r/ModelVolumeType.hpp diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index bee7ceb62..fd641b916 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -183,7 +183,6 @@ set(SLIC3R_SOURCES Model.hpp ModelArrange.hpp ModelArrange.cpp - #ModelVolumeType.hpp MultiMaterialSegmentation.cpp MultiMaterialSegmentation.hpp MeshNormals.hpp diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index d514171f1..b280ebcee 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -14,7 +14,6 @@ #include "Arrange.hpp" #include "CustomGCode.hpp" #include "enum_bitmask.hpp" -//#include "ModelVolumeType.hpp" #include "TextConfiguration.hpp" #include diff --git a/src/libslic3r/ModelVolumeType.hpp b/src/libslic3r/ModelVolumeType.hpp deleted file mode 100644 index 5ae1c6440..000000000 --- a/src/libslic3r/ModelVolumeType.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef slic3r_ModelVolumeType_hpp_ -#define slic3r_ModelVolumeType_hpp_ - -namespace Slic3r { - -enum class ModelVolumeType : int { - INVALID = -1, - MODEL_PART = 0, - NEGATIVE_VOLUME, - PARAMETER_MODIFIER, - SUPPORT_BLOCKER, - SUPPORT_ENFORCER, -}; - -} // namespace Slic3r -#endif /* slic3r_ModelVolumeType_hpp_ */ diff --git a/src/slic3r/GUI/Jobs/EmbossJob.hpp b/src/slic3r/GUI/Jobs/EmbossJob.hpp index c8ef7fee6..0081024a0 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.hpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.hpp @@ -5,7 +5,6 @@ #include #include #include -//#include #include "slic3r/Utils/RaycastManager.hpp" #include "slic3r/GUI/Camera.hpp" #include "Job.hpp" From 676a77fbf93a5132e04523f0655f2a2b9a4e0ec1 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 11:16:50 +0100 Subject: [PATCH 004/244] Remove ambigous function --- src/libslic3r/BoundingBox.hpp | 1 - src/libslic3r/IntersectionPoints.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libslic3r/BoundingBox.hpp b/src/libslic3r/BoundingBox.hpp index 92c12d4e9..4818ff9ee 100644 --- a/src/libslic3r/BoundingBox.hpp +++ b/src/libslic3r/BoundingBox.hpp @@ -174,7 +174,6 @@ public: BoundingBox rotated(double angle, const Point ¢er) const; void rotate(double angle) { (*this) = this->rotated(angle); } void rotate(double angle, const Point ¢er) { (*this) = this->rotated(angle, center); } - bool intersects(const BoundingBox &other) const { return this->min(0) <= other.max(0) && this->max(0) >= other.min(0) && this->min(1) <= other.max(1) && this->max(1) >= other.min(1); } // Align the min corner to a grid of cell_size x cell_size cells, // to encompass the original bounding box. void align_to_grid(const coord_t cell_size); diff --git a/src/libslic3r/IntersectionPoints.cpp b/src/libslic3r/IntersectionPoints.cpp index f2c63a53b..3537e74ab 100644 --- a/src/libslic3r/IntersectionPoints.cpp +++ b/src/libslic3r/IntersectionPoints.cpp @@ -133,7 +133,7 @@ Slic3r::Pointfs compute_intersections(const Slic3r::Lines &lines) Point max_(std::max(a_.x(), b_.x()), std::max(a_.y(), b_.y())); BoundingBox bb_(min_, max_); // intersect of BB compare min max - if (bb.intersects(bb_) && + if (bb.overlap(bb_) && l.intersection(l_, &i)) pts.push_back(i.cast()); } From d330bbc54b73b2f98ddd4636b1914451e7ce75a7 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 13:39:28 +0100 Subject: [PATCH 005/244] comment source of idea --- src/libslic3r/NSVGUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libslic3r/NSVGUtils.cpp b/src/libslic3r/NSVGUtils.cpp index a8f23e2e9..2844fc55e 100644 --- a/src/libslic3r/NSVGUtils.cpp +++ b/src/libslic3r/NSVGUtils.cpp @@ -3,6 +3,8 @@ using namespace Slic3r; +// inspired by nanosvgrast.h function nsvgRasterize -> nsvg__flattenShape -> nsvg__flattenCubicBez +// https://github.com/memononen/nanosvg/blob/f0a3e1034dd22e2e87e5db22401e44998383124e/src/nanosvgrast.h#L335 void NSVGUtils::flatten_cubic_bez(Polygon &polygon, float tessTol, Vec2f p1, From b1f9d50aad249aaa5500c47caf79eae5b9a8c3d9 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 13:52:47 +0100 Subject: [PATCH 006/244] Rename function: collect_duplications -> collect_duplicates more english correct name --- src/libslic3r/Emboss.cpp | 10 +++++----- src/libslic3r/Point.cpp | 2 +- src/libslic3r/Point.hpp | 2 +- src/libslic3r/Triangulation.cpp | 4 ++-- tests/libslic3r/test_emboss.cpp | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index d7a3ac1f6..440903757 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -283,7 +283,7 @@ ExPolygons Emboss::heal_shape(const Polygons &shape) { // Do not remove all duplicits but do it better way // Overlap all duplicit points by rectangle 3x3 - Points duplicits = collect_duplications(to_points(polygons)); + Points duplicits = collect_duplicates(to_points(polygons)); if (!duplicits.empty()) { polygons.reserve(polygons.size() + duplicits.size()); for (const Point &p : duplicits) { @@ -310,7 +310,7 @@ bool Emboss::heal_shape(ExPolygons &shape, unsigned max_iteration) priv::remove_same_neighbor(shape); Pointfs intersections = intersection_points(shape); - Points duplicits = collect_duplications(to_points(shape)); + Points duplicits = collect_duplicates(to_points(shape)); //Points close = priv::collect_close_points(shape, 1.); if (intersections.empty() && duplicits.empty() /* && close.empty() */) break; @@ -353,7 +353,7 @@ bool Emboss::heal_shape(ExPolygons &shape, unsigned max_iteration) svg.draw(shape, "green"); svg.draw(duplicits, "lightgray", 13 / Emboss::SHAPE_SCALE); - Points duplicits3 = collect_duplications(to_points(shape)); + Points duplicits3 = collect_duplicates(to_points(shape)); svg.draw(duplicits3, "black", 7 / Emboss::SHAPE_SCALE); Pointfs pts2 = intersection_points(shape); @@ -387,7 +387,7 @@ bool Emboss::heal_shape(ExPolygons &shape, unsigned max_iteration) } assert(intersection_points(shape).empty()); - assert(collect_duplications(to_points(shape)).empty()); + assert(collect_duplicates(to_points(shape)).empty()); return true; } @@ -1186,7 +1186,7 @@ indexed_triangle_set Emboss::polygons2model(const ExPolygons &shape2d, const IProjection &projection) { Points points = to_points(shape2d); - Points duplicits = collect_duplications(points); + Points duplicits = collect_duplicates(points); return (duplicits.empty()) ? priv::polygons2model_unique(shape2d, projection, points) : priv::polygons2model_duplicit(shape2d, projection, points, duplicits); diff --git a/src/libslic3r/Point.cpp b/src/libslic3r/Point.cpp index 2e282b400..ade8a5621 100644 --- a/src/libslic3r/Point.cpp +++ b/src/libslic3r/Point.cpp @@ -158,7 +158,7 @@ bool has_duplicate_points(std::vector &&pts) return false; } -Points collect_duplications(Points pts /* Copy */) +Points collect_duplicates(Points pts /* Copy */) { std::stable_sort(pts.begin(), pts.end()); Points duplicits; diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index c4504c211..ae1e88276 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -269,7 +269,7 @@ inline bool has_duplicate_successive_points_closed(const std::vector &pts } // Collect adjecent(duplicit points) -Points collect_duplications(Points pts /* Copy */); +Points collect_duplicates(Points pts /* Copy */); inline bool shorter_then(const Point& p0, const coord_t len) { diff --git a/src/libslic3r/Triangulation.cpp b/src/libslic3r/Triangulation.cpp index a355d725d..f5978d3e9 100644 --- a/src/libslic3r/Triangulation.cpp +++ b/src/libslic3r/Triangulation.cpp @@ -241,7 +241,7 @@ Triangulation::Indices Triangulation::triangulate(const ExPolygon &expolygon){ Triangulation::Indices Triangulation::triangulate(const ExPolygons &expolygons){ Points pts = to_points(expolygons); - Points d_pts = collect_duplications(pts); + Points d_pts = collect_duplicates(pts); if (d_pts.empty()) return triangulate(expolygons, pts); Changes changes = create_changes(pts, d_pts); @@ -262,7 +262,7 @@ Triangulation::Indices Triangulation::triangulate(const ExPolygons &expolygons, { assert(count_points(expolygons) == points.size()); // when contain duplicit coordinate in points will not work properly - assert(collect_duplications(points).empty()); + assert(collect_duplicates(points).empty()); HalfEdges edges; edges.reserve(points.size()); diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 6a523ed31..ebb1a1792 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -201,7 +201,7 @@ ExPolygons heal_and_check(const Polygons &polygons) { Pointfs intersections_prev = intersection_points(polygons); Points polygons_points = to_points(polygons); - Points duplicits_prev = collect_duplications(polygons_points); + Points duplicits_prev = collect_duplicates(polygons_points); ExPolygons shape = Emboss::heal_shape(polygons); @@ -215,7 +215,7 @@ ExPolygons heal_and_check(const Polygons &polygons) Pointfs intersections = intersection_points(shape); Points shape_points = to_points(shape); - Points duplicits = collect_duplications(shape_points); + Points duplicits = collect_duplicates(shape_points); //{ // BoundingBox bb(polygons_points); // // bb.scale(svg_scale); From fe736291c795cea5b4e0ab623f51590e89c72c22 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 13:54:38 +0100 Subject: [PATCH 007/244] rename function which change m_volume value to set_volume() --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 180 ++++++++++++------------ src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 8 +- 2 files changed, 96 insertions(+), 92 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 7a853e718..766cb04ef 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -329,6 +329,15 @@ bool GLGizmoEmboss::on_mouse_for_rotation(const wxMouseEvent &mouse_event) namespace priv { +/// +/// Access to model from gl_volume +/// TODO: it is more general function --> move to utils +/// +/// Volume to model belongs to +/// Object containing gl_volume +/// Model for volume +static ModelVolume *get_model_volume(const GLVolume *gl_volume, const ModelObject *object); + /// /// Access to model from gl_volume /// TODO: it is more general function --> move to utils @@ -343,9 +352,8 @@ static ModelVolume *get_model_volume(const GLVolume *gl_volume, const ModelObjec /// TODO: it is more general function --> move to select utils /// /// Actual selection -/// All objects /// Model from selection -static ModelVolume *get_selected_volume(const Selection &selection, const ModelObjectPtrs &objects); +static ModelVolume *get_selected_volume(const Selection &selection); /// /// Calculate offset from mouse position to center of text @@ -671,7 +679,7 @@ static void draw_mouse_offset(const std::optional &offset) void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit) { if (!m_gui_cfg.has_value()) initialize(); - check_selection(); + set_volume_by_selection(); // Do not render window for not selected text volume if (m_volume == nullptr || !m_volume->text_configuration.has_value()) { @@ -741,8 +749,8 @@ void GLGizmoEmboss::on_set_state() // to reload fonts from system, when install new one wxFontEnumerator::InvalidateCache(); - // Try(when exist) set text configuration by volume - load_configuration(get_selected_volume()); + // Try(when exist) set text configuration by volume + set_volume(priv::get_selected_volume(m_parent.get_selection())); // change position of just opened emboss window set_fine_position(); @@ -900,9 +908,9 @@ EmbossStyles GLGizmoEmboss::create_default_styles() void GLGizmoEmboss::set_default_text(){ m_text = _u8L("Embossed text"); } #include "imgui/imgui_internal.h" // to unfocus input --> ClearActiveID -void GLGizmoEmboss::check_selection() +void GLGizmoEmboss::set_volume_by_selection() { - ModelVolume *vol = get_selected_volume(); + ModelVolume *vol = priv::get_selected_volume(m_parent.get_selection()); // is same volume selected? if (vol != nullptr && m_volume == vol) return; @@ -913,27 +921,88 @@ void GLGizmoEmboss::check_selection() if (m_volume != nullptr) ImGui::ClearActiveID(); // is select embossed volume? - if (load_configuration(vol)) - // successfull load volume for editing - return; - - // behave like adding new text - m_volume = nullptr; - set_default_text(); + if (!set_volume(vol)) { + // Can't load so behave like adding new text + m_volume = nullptr; + set_default_text(); + } +} + +bool GLGizmoEmboss::set_volume(ModelVolume *volume) +{ + if (volume == nullptr) return false; + const std::optional tc_opt = volume->text_configuration; + if (!tc_opt.has_value()) return false; + const TextConfiguration &tc = *tc_opt; + const EmbossStyle &style = tc.style; + + auto has_same_name = [&style](const StyleManager::Item &style_item) -> bool { + const EmbossStyle &es = style_item.style; + return es.name == style.name; + }; + + wxFont wx_font; + bool is_path_changed = false; + if (style.type == WxFontUtils::get_actual_type()) + wx_font = WxFontUtils::load_wxFont(style.path); + if (!wx_font.IsOk()) { + create_notification_not_valid_font(tc); + // Try create similar wx font + wx_font = WxFontUtils::create_wxFont(style); + is_path_changed = wx_font.IsOk(); + } + + const auto& styles = m_style_manager.get_styles(); + auto it = std::find_if(styles.begin(), styles.end(), has_same_name); + if (it == styles.end()) { + // style was not found + if (wx_font.IsOk()) + m_style_manager.load_style(style, wx_font); + } else { + size_t style_index = it - styles.begin(); + if (!m_style_manager.load_style(style_index)) { + // can`t load stored style + m_style_manager.erase(style_index); + if (wx_font.IsOk()) + m_style_manager.load_style(style, wx_font); + + } else { + // stored style is loaded, now set modification of style + m_style_manager.get_style() = style; + m_style_manager.set_wx_font(wx_font); + } + } + + if (is_path_changed) { + std::string path = WxFontUtils::store_wxFont(wx_font); + m_style_manager.get_style().path = path; + } + + m_text = tc.text; + m_volume = volume; + + // store volume state before edit + m_unmodified_volume = {*volume->get_mesh_shared_ptr(), // copy + tc, volume->get_matrix(), volume->name}; + + return true; +} + +ModelVolume *priv::get_model_volume(const GLVolume *gl_volume, const ModelObject *object) +{ + int volume_id = gl_volume->volume_idx(); + if (volume_id < 0 || static_cast(volume_id) >= object->volumes.size()) return nullptr; + return object->volumes[volume_id]; } ModelVolume *priv::get_model_volume(const GLVolume *gl_volume, const ModelObjectPtrs &objects) { - const GLVolume::CompositeID &id = gl_volume->composite_id; - - if (id.object_id < 0 || static_cast(id.object_id) >= objects.size()) return nullptr; - ModelObject *object = objects[id.object_id]; - - if (id.volume_id < 0 || static_cast(id.volume_id) >= object->volumes.size()) return nullptr; - return object->volumes[id.volume_id]; + int object_id = gl_volume->object_idx(); + if (object_id < 0 || static_cast(object_id) >= objects.size()) return nullptr; + return get_model_volume(gl_volume, objects[object_id]); } -ModelVolume *priv::get_selected_volume(const Selection &selection, const ModelObjectPtrs &objects) +ModelVolume *priv::get_selected_volume(const Selection &selection) { int object_idx = selection.get_object_idx(); // is more object selected? @@ -944,15 +1013,10 @@ ModelVolume *priv::get_selected_volume(const Selection &selection, const ModelOb if (volume_idxs.size() != 1) return nullptr; unsigned int vol_id_gl = *volume_idxs.begin(); const GLVolume *vol_gl = selection.get_volume(vol_id_gl); + const ModelObjectPtrs &objects = selection.get_model()->objects; return get_model_volume(vol_gl, objects); } -ModelVolume *GLGizmoEmboss::get_selected_volume() -{ - return priv::get_selected_volume(m_parent.get_selection(), - wxGetApp().plater()->model().objects); -} - // Run Job on main thread (blocking) - ONLY DEBUG static inline void execute_job(std::shared_ptr j) { @@ -2985,66 +3049,6 @@ bool GLGizmoEmboss::choose_svg_file() //return add_volume(name, its); } -bool GLGizmoEmboss::load_configuration(ModelVolume *volume) -{ - if (volume == nullptr) return false; - const std::optional tc_opt = volume->text_configuration; - if (!tc_opt.has_value()) return false; - const TextConfiguration &tc = *tc_opt; - const EmbossStyle &style = tc.style; - - auto has_same_name = [&style](const StyleManager::Item &style_item) -> bool { - const EmbossStyle &es = style_item.style; - return es.name == style.name; - }; - - wxFont wx_font; - bool is_path_changed = false; - if (style.type == WxFontUtils::get_actual_type()) - wx_font = WxFontUtils::load_wxFont(style.path); - if (!wx_font.IsOk()) { - create_notification_not_valid_font(tc); - // Try create similar wx font - wx_font = WxFontUtils::create_wxFont(style); - is_path_changed = wx_font.IsOk(); - } - - const auto& styles = m_style_manager.get_styles(); - auto it = std::find_if(styles.begin(), styles.end(), has_same_name); - if (it == styles.end()) { - // style was not found - if (wx_font.IsOk()) - m_style_manager.load_style(style, wx_font); - } else { - size_t style_index = it - styles.begin(); - if (!m_style_manager.load_style(style_index)) { - // can`t load stored style - m_style_manager.erase(style_index); - if (wx_font.IsOk()) - m_style_manager.load_style(style, wx_font); - - } else { - // stored style is loaded, now set modification of style - m_style_manager.get_style() = style; - m_style_manager.set_wx_font(wx_font); - } - } - - if (is_path_changed) { - std::string path = WxFontUtils::store_wxFont(wx_font); - m_style_manager.get_style().path = path; - } - - m_text = tc.text; - m_volume = volume; - - // store volume state before edit - m_unmodified_volume = {*volume->get_mesh_shared_ptr(), // copy - tc, volume->get_matrix(), volume->name}; - - return true; -} - void GLGizmoEmboss::create_notification_not_valid_font( const TextConfiguration &tc) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 092041e96..1df32150f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -91,8 +91,10 @@ private: // localized default text void set_default_text(); - void check_selection(); - ModelVolume *get_selected_volume(); + void set_volume_by_selection(); + // load text configuration from volume into gizmo + bool set_volume(ModelVolume *volume); + // create volume from text - main functionality bool process(); void close(); @@ -158,8 +160,6 @@ private: bool choose_true_type_file(); bool choose_svg_file(); - bool load_configuration(ModelVolume *volume); - // When open text loaded from .3mf it could be written with unknown font bool m_is_unknown_font; void create_notification_not_valid_font(const TextConfiguration& tc); From 1fa532c624e26c22b114c3531425b7b2ba259b8d Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 13:58:41 +0100 Subject: [PATCH 008/244] change stable_sort to sort(in this place it is better) --- src/libslic3r/Point.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Point.cpp b/src/libslic3r/Point.cpp index ade8a5621..8c2861674 100644 --- a/src/libslic3r/Point.cpp +++ b/src/libslic3r/Point.cpp @@ -160,7 +160,7 @@ bool has_duplicate_points(std::vector &&pts) Points collect_duplicates(Points pts /* Copy */) { - std::stable_sort(pts.begin(), pts.end()); + std::sort(pts.begin(), pts.end()); Points duplicits; const Point *prev = &pts.front(); for (size_t i = 1; i < pts.size(); ++i) { From b71b42b9f32e2f61f4caf2ba8cee98f13b7e3922 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 14:26:10 +0100 Subject: [PATCH 009/244] add Note why escape white character in XML --- src/libslic3r/utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 2cca334d9..2615937eb 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -956,7 +956,8 @@ std::string xml_escape(std::string text, bool is_marked/* = false*/) } // Definition of escape symbols https://www.w3.org/TR/REC-xml/#AVNormalize - +// During the read of xml attribute normalization of white spaces is applied +// Soo for not lose white space character it is escaped before store std::string xml_escape_double_quotes_attribute_value(std::string text) { std::string::size_type pos = 0; From b8503ed9048978d3a12dd9c1f295ec51b6702300 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 14:33:47 +0100 Subject: [PATCH 010/244] Remove comment iritating @vojta --- src/libslic3r/libslic3r.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index 83608aa72..0de638ac8 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -112,7 +112,6 @@ inline void append(std::vector& dest, const std::vector& src) dest = src; // copy else dest.insert(dest.end(), src.begin(), src.end()); - // NOTE: insert reserve space when needed } template From d9cc6ecad96d8e4e94d48912a4e6ed23b07c87b4 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 29 Nov 2022 18:42:11 +0100 Subject: [PATCH 011/244] Show imgui demo window --- src/slic3r/GUI/GLCanvas3D.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 11d1bb80c..11d8f1668 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1697,6 +1697,8 @@ void GLCanvas3D::render() #endif // ENABLE_RAYCAST_PICKING_DEBUG } + ImGui::ShowDemoWindow(); + const bool is_looking_downward = camera.is_looking_downward(); // draw scene From 9a40e63a11575c16a66e9bc7e77b619f2cce9004 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 30 Nov 2022 10:49:53 +0100 Subject: [PATCH 012/244] Disable background fadeout animation for modal imgui windows --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 766cb04ef..bacc1b151 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1908,6 +1908,7 @@ void GLGizmoEmboss::draw_style_rename_button() else ImGui::SetTooltip("%s", _u8L("Can't rename temporary style.").c_str()); } if (ImGui::BeginPopupModal(popup_id, 0, ImGuiWindowFlags_AlwaysAutoResize)) { + m_imgui->disable_background_fadeout_animation(); draw_style_rename_popup(); ImGui::EndPopup(); } @@ -2002,6 +2003,7 @@ void GLGizmoEmboss::draw_style_add_button() } if (ImGui::BeginPopupModal(popup_id, 0, ImGuiWindowFlags_AlwaysAutoResize)) { + m_imgui->disable_background_fadeout_animation(); draw_style_save_as_popup(); ImGui::EndPopup(); } @@ -2050,6 +2052,7 @@ void GLGizmoEmboss::draw_delete_style_button() { } if (ImGui::BeginPopupModal(popup_id)) { + m_imgui->disable_background_fadeout_animation(); const std::string &style_name = m_style_manager.get_style().name; std::string text_in_popup = GUI::format(_L("Are you sure,\nthat you want permanently and unrecoverable \nremove style \"%1%\"?"), style_name); ImGui::Text("%s", text_in_popup.c_str()); From 1309dab7e708448189e821dcddd1c2b5ed1033d0 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 30 Nov 2022 11:35:48 +0100 Subject: [PATCH 013/244] Do not inform user about disable cut surface functionality --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index bacc1b151..514c207e8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -205,10 +205,6 @@ static void find_closest_volume(const Selection &selection, /// Screen coordinat, where to create new object laying on bed static void start_create_object_job(DataBase &emboss_data, const Vec2d &coor); -static void message_disable_cut_surface(){ - wxMessageBox(_L("Can NOT cut surface from nothing. Function 'use surface' was disabled for this text."), - _L("Disable 'use surface' from style"), wxOK | wxICON_WARNING);} - /// /// Create transformation for new created emboss object by mouse position /// @@ -1063,12 +1059,9 @@ bool GLGizmoEmboss::process() // check cutting from source mesh bool &use_surface = data.text_configuration.style.prop.use_surface; bool is_object = m_volume->get_object()->volumes.size() == 1; - if (use_surface && is_object) { - priv::message_disable_cut_surface(); + if (use_surface && is_object) use_surface = false; - } - - + if (use_surface) { // Model to cut surface from. SurfaceVolumeData::ModelSources sources = create_volume_sources(m_volume); @@ -3317,10 +3310,8 @@ void priv::start_create_object_job(DataBase &emboss_data, const Vec2d &coor) if (prop.distance.has_value()) prop.distance.reset(); // can't create new object with using surface - if (prop.use_surface) { - priv::message_disable_cut_surface(); + if (prop.use_surface) prop.use_surface = false; - } // Transform3d volume_tr = priv::create_transformation_on_bed(mouse_pos, camera, bed_shape, prop.emboss / 2); DataCreateObject data{std::move(emboss_data), coor, camera, bed_shape}; @@ -3340,7 +3331,6 @@ void priv::start_create_volume_job(const ModelObject *object, // Model to cut surface from. SurfaceVolumeData::ModelSources sources = create_sources(object->volumes); if (sources.empty()) { - priv::message_disable_cut_surface(); use_surface = false; } else { bool is_outside = volume_type == ModelVolumeType::MODEL_PART; From 8d54798231b3eb07e659ee18a6ba7a39d1ddcb11 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 30 Nov 2022 12:07:46 +0100 Subject: [PATCH 014/244] Extend Hot fix by description --- src/imgui/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/imgui/README.md b/src/imgui/README.md index 58008bded..9413811ae 100644 --- a/src/imgui/README.md +++ b/src/imgui/README.md @@ -17,6 +17,12 @@ imstb_truetype.h modification: Hot fix for open symbolic fonts on windows 62bdfe6f8d04b88e8bd511cd613be80c0baa7f55 +Add case STBTT_MS_EID_SYMBOL to swith in file imstb_truetype.h on line 1440. Hot fix for open curved fonts mainly on MAC 2148e49f75d82cb19dc6ec409fb7825296ed005c +viz. https://github.com/nothings/stb/issues/1296 +In file imstb_truetype.h line 1667 change malloc size from: +vertices = (stbtt_vertex *) STBTT_malloc((m + 1) * sizeof(vertices[0]), info->userdata); +to: +vertices = (stbtt_vertex *) STBTT_malloc(m * sizeof(vertices[0]), info->userdata); \ No newline at end of file From 36f6c8bf655a6638d2babd8d60639deb9cb17284 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 30 Nov 2022 15:46:27 +0100 Subject: [PATCH 015/244] temporary add scope guard test for MacOs --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 514c207e8..09fba9212 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1138,6 +1138,23 @@ void GLGizmoEmboss::discard_and_close() { // * Volume containing 3mf fix transformation - needs work around } +void scopeguard_test() { + bool v = false; + { + ScopeGuard sg; + if (!v) { + v = true; + sg = ScopeGuard([&v]() { + if(!v) wxMessageBox("Guard is called twice."); + v = false; + }); + if (!v) wxMessageBox("v should be true in condition."); + } + if (!v) wxMessageBox("v should be true in scope."); + } + if (v) wxMessageBox("v should NOT be true."); +} + void GLGizmoEmboss::draw_window() { #ifdef ALLOW_DEBUG_MODE @@ -1155,6 +1172,8 @@ void GLGizmoEmboss::draw_window() m_imgui->disabled_end(); }); + scopeguard_test(); + draw_text_input(); draw_model_type(); draw_style_list(); From a4af4bb0b332ab0a6100e16bcb5cf910b70d5d8e Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 1 Dec 2022 09:45:49 +0100 Subject: [PATCH 016/244] Sychronize imgui keys state into ImGuiWrapper::new_frame() to prevent misalignment when the key up event happens after the application loses focus --- src/slic3r/GUI/ImGuiWrapper.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 17709788d..7b8227642 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -294,6 +294,42 @@ void ImGuiWrapper::new_frame() ImGui::NewFrame(); m_new_frame_open = true; + + // synchronize key states + // when the application loses the focus it may happen that the key up event is not processed + + // modifier keys + auto synchronize_mod_key = [](const std::pair& key) { + ImGuiIO& io = ImGui::GetIO(); + if ((io.KeyMods & key.first) != 0 && !wxGetKeyState(key.second)) + io.KeyMods &= ~key.first; + }; + + std::vector> imgui_mod_keys = { + { ImGuiKeyModFlags_Ctrl, WXK_CONTROL }, + { ImGuiKeyModFlags_Shift, WXK_SHIFT }, + { ImGuiKeyModFlags_Alt, WXK_ALT } + }; + + for (const std::pair& key : imgui_mod_keys) { + synchronize_mod_key(key); + } + + // regular keys + ImGuiIO& io = ImGui::GetIO(); + for (size_t i = 0; i < IM_ARRAYSIZE(io.KeysDown); ++i) { + wxKeyCode keycode = WXK_NONE; + if (33 <= i && i <= 126) + keycode = (wxKeyCode)i; + else { + auto it = std::find(std::begin(io.KeyMap), std::end(io.KeyMap), i); + if (it != std::end(io.KeyMap)) + keycode = (wxKeyCode)i; + } + + if (io.KeysDown[i] && keycode != WXK_NONE && !wxGetKeyState(keycode)) + io.KeysDown[i] = false; + } } void ImGuiWrapper::render() From 58a825dd91c2853aac12829a19f5ca77cfc299df Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 1 Dec 2022 17:20:10 +0100 Subject: [PATCH 017/244] Fix Release ghost pressing of key backspace, del, ... Add debug log for imgui update key data - aka key events --- src/slic3r/GUI/ImGuiWrapper.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 17709788d..233e102a6 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -257,20 +257,37 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) return false; } - ImGuiIO& io = ImGui::GetIO(); + auto to_string = [](wxEventType type) -> std::string { + if (type == wxEVT_CHAR) return "Char"; + if (type == wxEVT_KEY_DOWN) return "KeyDown"; + if (type == wxEVT_KEY_UP) return "KeyUp"; + return "Other"; + }; - if (evt.GetEventType() == wxEVT_CHAR) { + wxEventType type = evt.GetEventType(); + ImGuiIO& io = ImGui::GetIO(); + BOOST_LOG_TRIVIAL(debug) << "ImGui - key event(" << to_string(type) << "):" + //<< " Unicode(" << evt.GetUnicodeKey() << ")" + << " KeyCode(" << evt.GetKeyCode() << ")"; + + if (type == wxEVT_CHAR) { // Char event - const auto key = evt.GetUnicodeKey(); + const auto key = evt.GetUnicodeKey(); + unsigned int key_u = static_cast(key); + // Release BackSpace, Delete, ... when miss wxEVT_KEY_UP event + if (key_u >= 0 && key_u < IM_ARRAYSIZE(io.KeysDown) && io.KeysDown[key_u]) { + io.KeysDown[key_u] = false; + } + if (key != 0) { io.AddInputCharacter(key); } - } else { + } else if (type == wxEVT_KEY_DOWN || type == wxEVT_KEY_UP) { // Key up/down event int key = evt.GetKeyCode(); wxCHECK_MSG(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown), false, "Received invalid key code"); - io.KeysDown[key] = evt.GetEventType() == wxEVT_KEY_DOWN; + io.KeysDown[key] = (type == wxEVT_KEY_DOWN); io.KeyShift = evt.ShiftDown(); io.KeyCtrl = evt.ControlDown(); io.KeyAlt = evt.AltDown(); From 9f395a26a3925f615063d7424362ab194b915160 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 1 Dec 2022 17:20:23 +0100 Subject: [PATCH 018/244] Remove test --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 09fba9212..514c207e8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1138,23 +1138,6 @@ void GLGizmoEmboss::discard_and_close() { // * Volume containing 3mf fix transformation - needs work around } -void scopeguard_test() { - bool v = false; - { - ScopeGuard sg; - if (!v) { - v = true; - sg = ScopeGuard([&v]() { - if(!v) wxMessageBox("Guard is called twice."); - v = false; - }); - if (!v) wxMessageBox("v should be true in condition."); - } - if (!v) wxMessageBox("v should be true in scope."); - } - if (v) wxMessageBox("v should NOT be true."); -} - void GLGizmoEmboss::draw_window() { #ifdef ALLOW_DEBUG_MODE @@ -1172,8 +1155,6 @@ void GLGizmoEmboss::draw_window() m_imgui->disabled_end(); }); - scopeguard_test(); - draw_text_input(); draw_model_type(); draw_style_list(); From d6add813192ccb3e2653da8acdbed67038cc07b2 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 1 Dec 2022 17:35:17 +0100 Subject: [PATCH 019/244] Show imgui demo window after type "demo" --- src/slic3r/GUI/GLCanvas3D.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 8493f38dc..13ea764d0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -94,6 +94,11 @@ static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE = 131072 * 2; // 1.05MB //static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE_SUM_MAX = 1024 * 1024 * 128 / 4; // 128MB #endif // !ENABLE_LEGACY_OPENGL_REMOVAL +#define SHOW_IMGUI_DEMO_WINDOW +#ifdef SHOW_IMGUI_DEMO_WINDOW +static bool show_imgui_demo_window = false; +#endif // SHOW_IMGUI_DEMO_WINDOW + namespace Slic3r { namespace GUI { @@ -1694,8 +1699,10 @@ void GLCanvas3D::render() } #endif // ENABLE_RAYCAST_PICKING_DEBUG } - - ImGui::ShowDemoWindow(); + +#ifdef SHOW_IMGUI_DEMO_WINDOW + if (show_imgui_demo_window) ImGui::ShowDemoWindow(); +#endif // SHOW_IMGUI_DEMO_WINDOW const bool is_looking_downward = camera.is_looking_downward(); @@ -2642,10 +2649,11 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) if (!m_initialized) return; - // see include/wx/defs.h enum wxKeyCode - int keyCode = evt.GetKeyCode(); - int ctrlMask = wxMOD_CONTROL; - int shiftMask = wxMOD_SHIFT; +#ifdef SHOW_IMGUI_DEMO_WINDOW + static int cur = 0; + if (wxString("demo")[cur] = evt.GetUnicodeKey()) ++cur; else cur = 0; + if (cur == 4) { show_imgui_demo_window = !show_imgui_demo_window; cur = 0;} +#endif // SHOW_IMGUI_DEMO_WINDOW auto imgui = wxGetApp().imgui(); if (imgui->update_key_data(evt)) { @@ -2653,6 +2661,10 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) return; } + // see include/wx/defs.h enum wxKeyCode + int keyCode = evt.GetKeyCode(); + int ctrlMask = wxMOD_CONTROL; + int shiftMask = wxMOD_SHIFT; if (keyCode == WXK_ESCAPE && (_deactivate_undo_redo_toolbar_items() || _deactivate_search_toolbar_item() || _deactivate_arrange_menu())) return; From 0e01e6af72764f844894bbe58f0982bd6f156bc0 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 1 Dec 2022 21:14:55 +0100 Subject: [PATCH 020/244] Fix crash when double click on wipe tower Add option to open embos gizmo by doubleclick when move scale rotate or emboss + fix demo opening --- src/slic3r/GUI/GLCanvas3D.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 13ea764d0..13ed57c7b 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2651,7 +2651,7 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) #ifdef SHOW_IMGUI_DEMO_WINDOW static int cur = 0; - if (wxString("demo")[cur] = evt.GetUnicodeKey()) ++cur; else cur = 0; + if (wxString("demo")[cur] == evt.GetUnicodeKey()) ++cur; else cur = 0; if (cur == 4) { show_imgui_demo_window = !show_imgui_demo_window; cur = 0;} #endif // SHOW_IMGUI_DEMO_WINDOW @@ -3740,20 +3740,27 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) evt.Skip(); // Detection of doubleclick on text to open emboss edit window - if (evt.LeftDClick() && m_gizmos.get_current() == nullptr && !m_hover_volume_idxs.empty()) { + auto type = m_gizmos.get_current_type(); + if (evt.LeftDClick() && !m_hover_volume_idxs.empty() && + (type == GLGizmosManager::EType::Undefined || + type == GLGizmosManager::EType::Move || + type == GLGizmosManager::EType::Rotate || + type == GLGizmosManager::EType::Scale || + type == GLGizmosManager::EType::Emboss) ) { for (int hover_volume_id : m_hover_volume_idxs) { const GLVolume &hover_gl_volume = *m_volumes.volumes[hover_volume_id]; - const ModelObject* hover_object = m_model->objects[hover_gl_volume.object_idx()]; + int object_idx = hover_gl_volume.object_idx(); + if (object_idx < 0 || object_idx >= m_model->objects.size()) continue; + const ModelObject* hover_object = m_model->objects[object_idx]; int hover_volume_idx = hover_gl_volume.volume_idx(); + if (hover_volume_idx < 0 || hover_volume_idx >= hover_object->volumes.size()) continue; const ModelVolume* hover_volume = hover_object->volumes[hover_volume_idx]; - if (hover_volume->text_configuration.has_value()) { - //m_selection.set_mode(Selection::EMode::Volume); - //m_selection.add(hover_volume_id); // add whole instance - m_selection.add_volumes(Selection::EMode::Volume, {(unsigned) hover_volume_id}); + if (!hover_volume->text_configuration.has_value()) continue; + m_selection.add_volumes(Selection::EMode::Volume, {(unsigned) hover_volume_id}); + if (type != GLGizmosManager::EType::Emboss) m_gizmos.open_gizmo(GLGizmosManager::EType::Emboss); - wxGetApp().obj_list()->update_selections(); - return; - } + wxGetApp().obj_list()->update_selections(); + return; } } From 910c87baec17b06ce2690def5ce6373ee27df4a8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 2 Dec 2022 09:16:37 +0100 Subject: [PATCH 021/244] Tech ENABLE_WORLD_COORDINATE - Fix of Selection::mirror() --- src/slic3r/GUI/GLCanvas3D.cpp | 13 +++++++++++++ src/slic3r/GUI/Selection.cpp | 8 ++++++++ src/slic3r/GUI/Selection.hpp | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 991bbead2..5cbff5c05 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1954,7 +1954,20 @@ std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) void GLCanvas3D::mirror_selection(Axis axis) { +#if ENABLE_WORLD_COORDINATE + TransformationType transformation_type; + if (wxGetApp().obj_manipul()->is_local_coordinates()) + transformation_type.set_local(); + else if (wxGetApp().obj_manipul()->is_instance_coordinates()) + transformation_type.set_instance(); + + transformation_type.set_relative(); + + m_selection.setup_cache(); + m_selection.mirror(axis, transformation_type); +#else m_selection.mirror(axis); +#endif // ENABLE_WORLD_COORDINATE do_mirror(L("Mirror Object")); wxGetApp().obj_manipul()->set_dirty(); } diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index b27f7a738..d317b1887 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1268,6 +1268,13 @@ void Selection::scale_to_fit_print_volume(const BuildVolume& volume) } } +#if ENABLE_WORLD_COORDINATE +void Selection::mirror(Axis axis, TransformationType transformation_type) +{ + const Vec3d mirror((axis == X) ? -1.0 : 1.0, (axis == Y) ? -1.0 : 1.0, (axis == Z) ? -1.0 : 1.0); + scale_and_translate(mirror, Vec3d::Zero(), transformation_type); +} +#else void Selection::mirror(Axis axis) { if (!m_valid) @@ -1290,6 +1297,7 @@ void Selection::mirror(Axis axis) set_bounding_boxes_dirty(); } +#endif // ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE void Selection::scale_and_translate(const Vec3d& scale, const Vec3d& translation, TransformationType transformation_type) diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 34b88f160..b95ac3e78 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -302,7 +302,7 @@ public: void set_deserialized(EMode mode, const std::vector> &volumes_and_instances); // Update the selection based on the new instance IDs. - void instances_changed(const std::vector &instance_ids_selected); + void instances_changed(const std::vector &instance_ids_selected); // Update the selection based on the map from old indices to new indices after m_volumes changed. // If the current selection is by instance, this call may select newly added volumes, if they belong to already selected instances. void volumes_changed(const std::vector &map_volume_old_to_new); @@ -402,11 +402,12 @@ public: void flattening_rotate(const Vec3d& normal); void scale(const Vec3d& scale, TransformationType transformation_type); void scale_to_fit_print_volume(const BuildVolume& volume); - void mirror(Axis axis); #if ENABLE_WORLD_COORDINATE void scale_and_translate(const Vec3d& scale, const Vec3d& translation, TransformationType transformation_type); + void mirror(Axis axis, TransformationType transformation_type); void reset_skew(); #else + void mirror(Axis axis); void translate(unsigned int object_idx, const Vec3d& displacement); #endif // ENABLE_WORLD_COORDINATE void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement); From 5f26b8c601cb804c078c4e1e9d19cd5ff68f3fb8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 2 Dec 2022 14:15:04 +0100 Subject: [PATCH 022/244] Tech ENABLE_WORLD_COORDINATE - Modified behavior of mirror buttons in sidebar panel. Trigger transformation but do not show state. --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 39 ++++++++++++++++++----- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 8 +++-- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index bbcad2919..19a9368f2 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -268,25 +268,39 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : btn->SetToolTip(wxString::Format(_L("Toggle %c axis mirroring"), (int)label)); btn->SetBitmapDisabled_(m_mirror_bitmap_hidden); +#if ENABLE_WORLD_COORDINATE + m_mirror_buttons[axis_idx] = btn; +#else m_mirror_buttons[axis_idx].first = btn; m_mirror_buttons[axis_idx].second = mbShown; +#endif // ENABLE_WORLD_COORDINATE sizer->AddStretchSpacer(2); sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL); btn->Bind(wxEVT_BUTTON, [this, axis_idx](wxCommandEvent&) { +#if !ENABLE_WORLD_COORDINATE Axis axis = (Axis)(axis_idx + X); if (m_mirror_buttons[axis_idx].second == mbHidden) - return; + return; +#endif // !ENABLE_WORLD_COORDINATE GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); Selection& selection = canvas->get_selection(); #if ENABLE_WORLD_COORDINATE - if (selection.is_single_volume_or_modifier()) { + TransformationType transformation_type; + if (is_local_coordinates()) + transformation_type.set_local(); + else if (is_instance_coordinates()) + transformation_type.set_instance(); + + transformation_type.set_relative(); + + selection.setup_cache(); + selection.mirror((Axis)axis_idx, transformation_type); #else if (selection.is_single_volume() || selection.is_single_modifier()) { -#endif // ENABLE_WORLD_COORDINATE GLVolume* volume = const_cast(selection.get_first_volume()); volume->set_volume_mirror(axis, -volume->get_volume_mirror(axis)); } @@ -302,6 +316,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : // Update mirroring at the GLVolumes. selection.synchronize_unselected_instances(Selection::SyncRotationType::GENERAL); selection.synchronize_unselected_volumes(); +#endif // ENABLE_WORLD_COORDINATE // Copy mirroring values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. canvas->do_mirror(L("Set Mirror")); UpdateAndShow(true); @@ -977,16 +992,14 @@ void ObjectManipulation::update_mirror_buttons_visibility() { GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); Selection& selection = canvas->get_selection(); - std::array new_states = {mbHidden, mbHidden, mbHidden}; #if ENABLE_WORLD_COORDINATE if (is_local_coordinates()) { -#else - if (!m_world_coordinates) { -#endif // ENABLE_WORLD_COORDINATE -#if ENABLE_WORLD_COORDINATE if (selection.is_single_full_instance() || selection.is_single_volume_or_modifier()) { #else + std::array new_states = { mbHidden, mbHidden, mbHidden }; + + if (!m_world_coordinates) { if (selection.is_single_full_instance() || selection.is_single_modifier() || selection.is_single_volume()) { #endif // ENABLE_WORLD_COORDINATE const GLVolume* volume = selection.get_first_volume(); @@ -997,10 +1010,13 @@ void ObjectManipulation::update_mirror_buttons_visibility() else mirror = volume->get_volume_mirror(); +#if !ENABLE_WORLD_COORDINATE for (unsigned char i=0; i<3; ++i) new_states[i] = (mirror[i] < 0. ? mbActive : mbShown); +#endif // !ENABLE_WORLD_COORDINATE } } +#if !ENABLE_WORLD_COORDINATE else { // the mirroring buttons should be hidden in world coordinates, // unless we make it actually mirror in world coords. @@ -1022,6 +1038,7 @@ void ObjectManipulation::update_mirror_buttons_visibility() } } }); +#endif // !ENABLE_WORLD_COORDINATE } @@ -1432,8 +1449,14 @@ void ObjectManipulation::sys_color_changed() m_drop_to_bed_button->sys_color_changed(); m_lock_bnt->sys_color_changed(); +#if ENABLE_WORLD_COORDINATE + for (int id = 0; id < 3; ++id) { + m_mirror_buttons[id]->sys_color_changed(); + } +#else for (int id = 0; id < 3; ++id) m_mirror_buttons[id].first->sys_color_changed(); +#endif // ENABLE_WORLD_COORDINATE } #if ENABLE_WORLD_COORDINATE diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 9995b3e6f..4085d91ce 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -132,6 +132,9 @@ private: wxCheckBox* m_check_inch {nullptr}; +#if ENABLE_WORLD_COORDINATE + std::array m_mirror_buttons; +#else // Mirroring buttons and their current state enum MirrorButtonState { mbHidden, @@ -139,6 +142,7 @@ private: mbActive }; std::array, 3> m_mirror_buttons; +#endif // ENABLE_WORLD_COORDINATE // Bitmaps for the mirroring buttons. ScalableBitmap m_mirror_bitmap_on; @@ -149,8 +153,8 @@ private: bool m_dirty = false; // Cached labels for the delayed update, not localized! std::string m_new_move_label_string; - std::string m_new_rotate_label_string; - std::string m_new_scale_label_string; + std::string m_new_rotate_label_string; + std::string m_new_scale_label_string; Vec3d m_new_position; Vec3d m_new_rotation; Vec3d m_new_scale; From cb7705ddbd67a750a7eb2b1291ff98d6a7f215f9 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 2 Dec 2022 17:57:34 +0100 Subject: [PATCH 023/244] optimize for each frame --- src/slic3r/GUI/ImGuiWrapper.cpp | 54 +++++++++++++++------------------ 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index e63dab146..7d68565e9 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -274,10 +274,12 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) // Char event const auto key = evt.GetUnicodeKey(); unsigned int key_u = static_cast(key); + // Release BackSpace, Delete, ... when miss wxEVT_KEY_UP event - if (key_u >= 0 && key_u < IM_ARRAYSIZE(io.KeysDown) && io.KeysDown[key_u]) { - io.KeysDown[key_u] = false; - } + // Already Fixed at begining of new frame + //if (key_u >= 0 && key_u < IM_ARRAYSIZE(io.KeysDown) && io.KeysDown[key_u]) { + // io.KeysDown[key_u] = false; + //} if (key != 0) { io.AddInputCharacter(key); @@ -299,6 +301,7 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt) return ret; } +#include void ImGuiWrapper::new_frame() { if (m_new_frame_open) { @@ -312,40 +315,33 @@ void ImGuiWrapper::new_frame() ImGui::NewFrame(); m_new_frame_open = true; + ImGuiIO& io = ImGui::GetIO(); // synchronize key states // when the application loses the focus it may happen that the key up event is not processed - // modifier keys - auto synchronize_mod_key = [](const std::pair& key) { - ImGuiIO& io = ImGui::GetIO(); + // synchronize modifier keys + constexpr std::array, 3> imgui_mod_keys{ + std::make_pair(ImGuiKeyModFlags_Ctrl, WXK_CONTROL), + std::make_pair(ImGuiKeyModFlags_Shift, WXK_SHIFT), + std::make_pair(ImGuiKeyModFlags_Alt, WXK_ALT)}; + for (const std::pair& key : imgui_mod_keys) { if ((io.KeyMods & key.first) != 0 && !wxGetKeyState(key.second)) io.KeyMods &= ~key.first; - }; - - std::vector> imgui_mod_keys = { - { ImGuiKeyModFlags_Ctrl, WXK_CONTROL }, - { ImGuiKeyModFlags_Shift, WXK_SHIFT }, - { ImGuiKeyModFlags_Alt, WXK_ALT } - }; - - for (const std::pair& key : imgui_mod_keys) { - synchronize_mod_key(key); } - // regular keys - ImGuiIO& io = ImGui::GetIO(); - for (size_t i = 0; i < IM_ARRAYSIZE(io.KeysDown); ++i) { - wxKeyCode keycode = WXK_NONE; - if (33 <= i && i <= 126) - keycode = (wxKeyCode)i; - else { - auto it = std::find(std::begin(io.KeyMap), std::end(io.KeyMap), i); - if (it != std::end(io.KeyMap)) - keycode = (wxKeyCode)i; - } - + // Not sure if it is neccessary + // values from 33 to 126 are reserved for the standard ASCII characters + for (size_t i = 33; i <= 126; ++i) { + wxKeyCode keycode = static_cast(i); if (io.KeysDown[i] && keycode != WXK_NONE && !wxGetKeyState(keycode)) - io.KeysDown[i] = false; + io.KeysDown[i] = false; + } + + // special keys: delete, backspace, ... + for (int key: io.KeyMap) { + wxKeyCode keycode = static_cast(key); + if (io.KeysDown[key] && keycode != WXK_NONE && !wxGetKeyState(keycode)) + io.KeysDown[key] = false; } } From 3c961f38168f8faab9d13ad4d96e202a3fa2df9f Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 2 Dec 2022 18:47:11 +0100 Subject: [PATCH 024/244] Move 3mf tag into Slic3r namespace - Break back compatibility with loading text volume Use surface retype as int --- src/libslic3r/Format/3mf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index bc379814e..8997df192 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -148,7 +148,7 @@ static constexpr const char* MESH_STAT_FACETS_RESERVED = "facets_reversed"; static constexpr const char* MESH_STAT_BACKWARDS_EDGES = "backwards_edges"; // Store / load of TextConfiguration -static constexpr const char *TEXT_TAG = "emboss"; +static constexpr const char *TEXT_TAG = "slic3rpe:text"; static constexpr const char *TEXT_DATA_ATTR = "text"; // TextConfiguration::EmbossStyle static constexpr const char *STYLE_NAME_ATTR = "style_name"; @@ -3628,8 +3628,8 @@ std::optional TextConfigurationSerialization::read(const char float distance = get_attribute_value_float(attributes, num_attributes, DISTANCE_ATTR); if (std::fabs(distance) > std::numeric_limits::epsilon()) fp.distance = distance; - std::string use_surface = get_attribute_value_string(attributes, num_attributes, USE_SURFACE_ATTR); - if (!use_surface.empty()) fp.use_surface = true; + int use_surface = get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR); + if (use_surface == 1) fp.use_surface = true; float angle = get_attribute_value_float(attributes, num_attributes, ANGLE_ATTR); if (std::fabs(angle) > std::numeric_limits::epsilon()) fp.angle = angle; From 9d1204d6f5618e62bd7535b611c3dbea3985b9c0 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 2 Dec 2022 19:00:44 +0100 Subject: [PATCH 025/244] Fix typo 'activ_font' to 'active_font' --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 20 +++++++++---------- src/slic3r/Utils/EmbossStyleManager.cpp | 4 ++-- src/slic3r/Utils/EmbossStyleManager.hpp | 2 +- src/slic3r/Utils/EmbossStylesSerializable.cpp | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 514c207e8..d1a920b5b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -315,8 +315,8 @@ bool GLGizmoEmboss::on_mouse_for_rotation(const wxMouseEvent &mouse_event) angle_opt.reset(); // set into activ style - assert(m_style_manager.is_activ_font()); - if (m_style_manager.is_activ_font()) + assert(m_style_manager.is_active_font()); + if (m_style_manager.is_active_font()) m_style_manager.get_font_prop().angle = angle_opt; } @@ -1042,7 +1042,7 @@ bool GLGizmoEmboss::process() if (m_text.empty()) return false; // exist loaded font file? - if (!m_style_manager.is_activ_font()) return false; + if (!m_style_manager.is_active_font()) return false; // Cancel previous Job, when it is in process // Can't use cancel, because I want cancel only previous EmbossUpdateJob no other jobs @@ -1145,8 +1145,8 @@ void GLGizmoEmboss::draw_window() if (ImGui::Button("add svg")) choose_svg_file(); #endif // ALLOW_DEBUG_MODE - bool is_activ_font = m_style_manager.is_activ_font(); - if (!is_activ_font) + bool is_active_font = m_style_manager.is_active_font(); + if (!is_active_font) m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _L("Warning: No font is selected. Select correct one.")); // Disable all except selection of font, when open text from 3mf with unknown font @@ -1158,7 +1158,7 @@ void GLGizmoEmboss::draw_window() draw_text_input(); draw_model_type(); draw_style_list(); - m_imgui->disabled_begin(!is_activ_font); + m_imgui->disabled_begin(!is_active_font); ImGui::TreePush(); draw_style_edit(); ImGui::TreePop(); @@ -1176,7 +1176,7 @@ void GLGizmoEmboss::draw_window() ImGui::TreePop(); } else if (m_is_advanced_edit_style) set_minimal_window_size(false); - m_imgui->disabled_end(); // !is_activ_font + m_imgui->disabled_end(); // !is_active_font #ifdef SHOW_WX_FONT_DESCRIPTOR if (is_selected_style) @@ -1655,7 +1655,7 @@ void GLGizmoEmboss::draw_font_list() { // Set partial wxString actual_face_name; - if (m_style_manager.is_activ_font()) { + if (m_style_manager.is_active_font()) { const std::optional &wx_font_opt = m_style_manager.get_wx_font(); if (wx_font_opt.has_value()) actual_face_name = wx_font_opt->GetFaceName(); @@ -2088,7 +2088,7 @@ void GLGizmoEmboss::fix_transformation(const FontProp &from, } void GLGizmoEmboss::draw_style_list() { - if (!m_style_manager.is_activ_font()) return; + if (!m_style_manager.is_active_font()) return; const EmbossStyle *stored_style = nullptr; bool is_stored = m_style_manager.exist_stored_style(); @@ -3255,7 +3255,7 @@ DataBase priv::create_emboss_data_base(const std::string &text, StyleManager& st }; auto create_configuration = [&]() -> TextConfiguration { - if (!style_manager.is_activ_font()) { + if (!style_manager.is_active_font()) { std::string default_text_for_emboss = _u8L("Embossed text"); EmbossStyle es = style_manager.get_style(); TextConfiguration tc{es, default_text_for_emboss}; diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index 256b1160b..77df3e217 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -200,7 +200,7 @@ bool StyleManager::load_style(const EmbossStyle &style, const wxFont &font) return true; } -bool StyleManager::is_activ_font() { return m_style_cache.font_file.has_value(); } +bool StyleManager::is_active_font() { return m_style_cache.font_file.has_value(); } bool StyleManager::load_first_valid_font() { while (!m_style_items.empty()) { @@ -228,7 +228,7 @@ void StyleManager::clear_imgui_font() { m_style_cache.atlas.Clear(); } ImFont *StyleManager::get_imgui_font() { - if (!is_activ_font()) return nullptr; + if (!is_active_font()) return nullptr; ImVector &fonts = m_style_cache.atlas.Fonts; if (fonts.empty()) return nullptr; diff --git a/src/slic3r/Utils/EmbossStyleManager.hpp b/src/slic3r/Utils/EmbossStyleManager.hpp index 502ba84bd..bc04ede32 100644 --- a/src/slic3r/Utils/EmbossStyleManager.hpp +++ b/src/slic3r/Utils/EmbossStyleManager.hpp @@ -185,7 +185,7 @@ public: }; // check if exist selected font style in manager - bool is_activ_font(); + bool is_active_font(); // Limits for imgui loaded font size // Value out of limits is crop diff --git a/src/slic3r/Utils/EmbossStylesSerializable.cpp b/src/slic3r/Utils/EmbossStylesSerializable.cpp index 483f147b1..a1c3c599a 100644 --- a/src/slic3r/Utils/EmbossStylesSerializable.cpp +++ b/src/slic3r/Utils/EmbossStylesSerializable.cpp @@ -19,7 +19,7 @@ const std::string EmbossStylesSerializable::APP_CONFIG_FONT_COLLECTION = "colle const std::string EmbossStylesSerializable::APP_CONFIG_FONT_CHAR_GAP = "char_gap"; const std::string EmbossStylesSerializable::APP_CONFIG_FONT_LINE_GAP = "line_gap"; -const std::string EmbossStylesSerializable::APP_CONFIG_ACTIVE_FONT = "activ_font"; +const std::string EmbossStylesSerializable::APP_CONFIG_ACTIVE_FONT = "active_font"; std::string EmbossStylesSerializable::create_section_name(unsigned index) { @@ -150,8 +150,8 @@ void EmbossStylesSerializable::store_style_index(AppConfig &cfg, unsigned index) // store actual font index cfg.clear_section(AppConfig::SECTION_EMBOSS_STYLE); // activ font first index is +1 to correspond with section name - std::string activ_font = std::to_string(index); - cfg.set(AppConfig::SECTION_EMBOSS_STYLE, APP_CONFIG_ACTIVE_FONT, activ_font); + std::string active_font = std::to_string(index); + cfg.set(AppConfig::SECTION_EMBOSS_STYLE, APP_CONFIG_ACTIVE_FONT, active_font); } std::optional EmbossStylesSerializable::load_style_index(const AppConfig &cfg) From 5266c6be8e7ecbdf127e7d329900a1f9579b7753 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 2 Dec 2022 19:03:26 +0100 Subject: [PATCH 026/244] Fix typo 'activ_' to 'active_' --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 12 ++++++------ src/slic3r/Utils/EmbossStyleManager.cpp | 22 +++++++++++----------- src/slic3r/Utils/EmbossStyleManager.hpp | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index d1a920b5b..8a9a51c98 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2013,9 +2013,9 @@ void GLGizmoEmboss::draw_delete_style_button() { if (draw_button(IconType::erase, !can_delete)) { while (true) { // NOTE: can't use previous loaded activ index -> erase could change index - size_t activ_index = m_style_manager.get_style_index(); - next_style_index = (activ_index > 0) ? activ_index - 1 : - activ_index + 1; + size_t active_index = m_style_manager.get_style_index(); + next_style_index = (active_index > 0) ? active_index - 1 : + active_index + 1; if (next_style_index >= m_style_manager.get_styles().size()) { // can't remove last font style // TODO: inform user @@ -2029,7 +2029,7 @@ void GLGizmoEmboss::draw_delete_style_button() { } // load back - m_style_manager.load_style(activ_index); + m_style_manager.load_style(active_index); ImGui::OpenPopup(popup_id); break; } @@ -2050,9 +2050,9 @@ void GLGizmoEmboss::draw_delete_style_button() { std::string text_in_popup = GUI::format(_L("Are you sure,\nthat you want permanently and unrecoverable \nremove style \"%1%\"?"), style_name); ImGui::Text("%s", text_in_popup.c_str()); if (ImGui::Button(_u8L("Yes").c_str())) { - size_t activ_index = m_style_manager.get_style_index(); + size_t active_index = m_style_manager.get_style_index(); m_style_manager.load_style(next_style_index); - m_style_manager.erase(activ_index); + m_style_manager.erase(active_index); m_style_manager.store_styles_to_app_config(wxGetApp().app_config); ImGui::CloseCurrentPopup(); process(); diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index 77df3e217..22ad0827e 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -39,19 +39,19 @@ void StyleManager::init(AppConfig *app_config, const EmbossStyles &default_style m_style_items.push_back({style}); } - std::optional activ_index_opt = (app_config != nullptr) ? + std::optional active_index_opt = (app_config != nullptr) ? EmbossStylesSerializable::load_style_index(*app_config) : std::optional{}; - size_t activ_index = 0; - if (activ_index_opt.has_value()) activ_index = *activ_index_opt; - if (activ_index >= m_style_items.size()) activ_index = 0; + size_t active_index = 0; + if (active_index_opt.has_value()) active_index = *active_index_opt; + if (active_index >= m_style_items.size()) active_index = 0; // find valid font item - if (!load_style(activ_index)) { - m_style_items.erase(m_style_items.begin() + activ_index); - activ_index = 0; - while (m_style_items.empty() || !load_style(activ_index)) + if (!load_style(active_index)) { + m_style_items.erase(m_style_items.begin() + active_index); + active_index = 0; + while (m_style_items.empty() || !load_style(active_index)) m_style_items.erase(m_style_items.begin()); // no one style from config is loadable if (m_style_items.empty()) { @@ -61,14 +61,14 @@ void StyleManager::init(AppConfig *app_config, const EmbossStyles &default_style m_style_items.push_back({std::move(style)}); } // try to load first default font - [[maybe_unused]] bool loaded = load_style(activ_index); + [[maybe_unused]] bool loaded = load_style(active_index); assert(loaded); } } } bool StyleManager::store_styles_to_app_config(bool use_modification, - bool store_activ_index) + bool store_active_index) { assert(m_app_config != nullptr); if (m_app_config == nullptr) return false; @@ -87,7 +87,7 @@ bool StyleManager::store_styles_to_app_config(bool use_modification, m_style_cache.stored_wx_font = m_style_cache.wx_font; } - if (store_activ_index) + if (store_active_index) { size_t style_index = exist_stored_style() ? m_style_cache.style_index : diff --git a/src/slic3r/Utils/EmbossStyleManager.hpp b/src/slic3r/Utils/EmbossStyleManager.hpp index bc04ede32..3851a1051 100644 --- a/src/slic3r/Utils/EmbossStyleManager.hpp +++ b/src/slic3r/Utils/EmbossStyleManager.hpp @@ -46,7 +46,7 @@ public: /// When true cache state will be used for store /// When true store activ index into configuration /// True on succes otherwise False. - bool store_styles_to_app_config(bool use_modification = true, bool store_activ_index = true); + bool store_styles_to_app_config(bool use_modification = true, bool store_active_index = true); /// /// Append actual style to style list From 22891acc07a45d558c9a9cb76965d96a8658af0c Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 5 Dec 2022 15:20:56 +0100 Subject: [PATCH 027/244] Lock emboss text window position --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 83 ++++++++++++++----------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 11 ++-- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 8a9a51c98..6d89132b0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -54,7 +54,7 @@ #define SHOW_ICONS_TEXTURE #define SHOW_FINE_POSITION // draw convex hull around volume #define SHOW_WX_WEIGHT_INPUT -#define DRAW_PLACE_TO_ADD_TEXT +#define DRAW_PLACE_TO_ADD_TEXT // Interactive draw of window position #endif // ALLOW_DEBUG_MODE using namespace Slic3r; @@ -681,7 +681,7 @@ void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit) if (m_volume == nullptr || !m_volume->text_configuration.has_value()) { close(); return; - } + } // TODO: fix width - showing scroll in first draw of advanced. const ImVec2 &min_window_size = get_minimal_window_size(); @@ -697,13 +697,19 @@ void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit) draw_mouse_offset(m_dragging_mouse_offset); #endif // SHOW_OFFSET_DURING_DRAGGING - // check if is set window offset - if (m_set_window_offset.has_value()) { - ImGui::SetNextWindowPos(*m_set_window_offset, ImGuiCond_Always); - m_set_window_offset.reset(); + ImGuiWindowFlags flag = ImGuiWindowFlags_NoCollapse; + if (m_allow_float_window){ + // check if is set window offset + if (m_set_window_offset.has_value()) { + ImGui::SetNextWindowPos(*m_set_window_offset, ImGuiCond_Always); + m_set_window_offset.reset(); + } + } else { + flag |= ImGuiWindowFlags_NoMove; + y = std::min(y, bottom_limit - min_window_size.y); + ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_Always); } - ImGuiWindowFlags flag = ImGuiWindowFlags_NoCollapse; if (ImGui::Begin(on_get_name().c_str(), nullptr, flag)) { // Need to pop var before draw window ImGui::PopStyleVar(); // WindowMinSize @@ -714,6 +720,29 @@ void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit) ImGui::End(); } +namespace priv { +/// +/// Move window for edit emboss text near to embossed object +/// NOTE: embossed object must be selected +/// +ImVec2 calc_fine_position(const Selection &selection, const ImVec2 &windows_size, const Size &canvas_size) +{ + const Selection::IndicesList indices = selection.get_volume_idxs(); + // no selected volume + if (indices.empty()) return {}; + const GLVolume *volume = selection.get_volume(*indices.begin()); + // bad volume selected (e.g. deleted one) + if (volume == nullptr) return {}; + + const Camera &camera = wxGetApp().plater()->get_camera(); + Slic3r::Polygon hull = CameraUtils::create_hull2d(camera, *volume); + + ImVec2 c_size(canvas_size.get_width(), canvas_size.get_height()); + ImVec2 offset = ImGuiWrapper::suggest_location(windows_size, hull, c_size); + return offset; +} +} // namespace priv + void GLGizmoEmboss::on_set_state() { // enable / disable bed from picking @@ -749,7 +778,8 @@ void GLGizmoEmboss::on_set_state() set_volume(priv::get_selected_volume(m_parent.get_selection())); // change position of just opened emboss window - set_fine_position(); + if (m_allow_float_window) + m_set_window_offset = priv::calc_fine_position(m_parent.get_selection(), get_minimal_window_size(), m_parent.get_canvas_size()); // when open by hyperlink it needs to show up // or after key 'T' windows doesn't appear @@ -1228,6 +1258,15 @@ void GLGizmoEmboss::draw_window() const auto &atlas = m_style_manager.get_atlas(); ImGui::Image(atlas.TexID, ImVec2(atlas.TexWidth, atlas.TexHeight)); #endif // SHOW_IMGUI_ATLAS + ImGui::SameLine(); + if (ImGui::Checkbox("##allow_float_window", &m_allow_float_window)) { + if (m_allow_float_window) + m_set_window_offset = priv::calc_fine_position(m_parent.get_selection(), get_minimal_window_size(), m_parent.get_canvas_size()); + } else if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("%s", ((m_allow_float_window) ? + _u8L("Fix settings possition"): + _u8L("Allow floating window near text")).c_str()); + } } void GLGizmoEmboss::draw_text_input() @@ -2648,34 +2687,6 @@ void GLGizmoEmboss::do_rotate(float relative_z_angle) m_parent.do_rotate(snapshot_name); } -void GLGizmoEmboss::set_fine_position() -{ - const Selection &selection = m_parent.get_selection(); - const Selection::IndicesList indices = selection.get_volume_idxs(); - // no selected volume - if (indices.empty()) return; - const GLVolume *volume = selection.get_volume(*indices.begin()); - // bad volume selected (e.g. deleted one) - if (volume == nullptr) return; - - const Camera &camera = wxGetApp().plater()->get_camera(); - Polygon hull = CameraUtils::create_hull2d(camera, *volume); - - const ImVec2 &windows_size = get_minimal_window_size(); - Size c_size = m_parent.get_canvas_size(); - ImVec2 canvas_size(c_size.get_width(), c_size.get_height()); - ImVec2 offset = ImGuiWrapper::suggest_location(windows_size, hull, canvas_size); - m_set_window_offset = offset; - return; - - Polygon rect({Point(offset.x, offset.y), - Point(offset.x + windows_size.x, offset.y), - Point(offset.x + windows_size.x, offset.y + windows_size.y), - Point(offset.x, offset.y + windows_size.y)}); - ImGuiWrapper::draw(hull); - ImGuiWrapper::draw(rect); -} - void GLGizmoEmboss::draw_advanced() { const auto &ff = m_style_manager.get_font_file_with_cache(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 1df32150f..cf2ebfd44 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -125,12 +125,6 @@ private: void do_translate(const Vec3d& relative_move); void do_rotate(float relative_z_angle); - /// - /// Move window for edit emboss text near to embossed object - /// NOTE: embossed object must be selected - /// - void set_fine_position(); - /// /// Reversible input float with option to restor default value /// TODO: make more general, static and move to ImGuiWrapper @@ -220,9 +214,12 @@ private: GuiCfg() = default; }; std::optional m_gui_cfg; + bool m_is_advanced_edit_style = false; + + // when true window will appear near to text + bool m_allow_float_window = false; // setted only when wanted to use - not all the time std::optional m_set_window_offset; - bool m_is_advanced_edit_style = false; Emboss::StyleManager m_style_manager; From 2168d0935a5c9d36390eeac5e3508495a70dc0d5 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 5 Dec 2022 16:52:35 +0100 Subject: [PATCH 028/244] Allow letter "T" for open text gizmo --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 9 +++++++++ src/slic3r/GUI/KBShortcutsDialog.cpp | 1 + 2 files changed, 10 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 194c34ce2..ae5de7be0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -526,6 +526,7 @@ bool GLGizmoEmboss::on_init() m_rotate_gizmo.init(); ColorRGBA gray_color(.6f, .6f, .6f, .3f); m_rotate_gizmo.set_highlight_color(gray_color); + m_shortcut_key = WXK_CONTROL_T; return true; } @@ -771,6 +772,14 @@ void GLGizmoEmboss::on_set_state() // Try(when exist) set text configuration by volume set_volume(priv::get_selected_volume(m_parent.get_selection())); + // when open window by "T" and no valid volume is selected, so Create new one + if (m_volume == nullptr) { + // reopen gizmo when new object is created + GLGizmoBase::m_state = GLGizmoBase::Off; + // start creating new object + create_volume(ModelVolumeType::MODEL_PART); + } + // change position of just opened emboss window if (m_allow_float_window) m_set_window_offset = priv::calc_fine_position(m_parent.get_selection(), get_minimal_window_size(), m_parent.get_canvas_size()); diff --git a/src/slic3r/GUI/KBShortcutsDialog.cpp b/src/slic3r/GUI/KBShortcutsDialog.cpp index 04668b593..cf23c85d3 100644 --- a/src/slic3r/GUI/KBShortcutsDialog.cpp +++ b/src/slic3r/GUI/KBShortcutsDialog.cpp @@ -154,6 +154,7 @@ void KBShortcutsDialog::fill_shortcuts() { "L", L("Gizmo FDM paint-on supports") }, { "P", L("Gizmo FDM paint-on seam") }, { "N", L("Gizmo Multi Material painting") }, + { "T", L("Gizmo Text emboss / engrave")}, { "Esc", L("Unselect gizmo or clear selection") }, { "K", L("Change camera type (perspective, orthographic)") }, { "B", L("Zoom to Bed") }, From 12e6948feff840c1d30a6af64c9b319f38e538b1 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 6 Dec 2022 14:33:34 +0100 Subject: [PATCH 029/244] Fix imgui want to have persistant io key during new window imgui assert - [link]{https://github.com/Prusa-Development/PrusaSlicerPrivate/blob/b1bfef44ba6bb72d925fc6c9f3133956be60e6ac/src/imgui/imgui.cpp#L7180} --- src/slic3r/GUI/ImGuiWrapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 7d68565e9..d7106173c 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -312,9 +312,6 @@ void ImGuiWrapper::new_frame() init_font(true); } - ImGui::NewFrame(); - m_new_frame_open = true; - ImGuiIO& io = ImGui::GetIO(); // synchronize key states // when the application loses the focus it may happen that the key up event is not processed @@ -343,6 +340,9 @@ void ImGuiWrapper::new_frame() if (io.KeysDown[key] && keycode != WXK_NONE && !wxGetKeyState(keycode)) io.KeysDown[key] = false; } + + ImGui::NewFrame(); + m_new_frame_open = true; } void ImGuiWrapper::render() From 307d541eafa9119136bdcd7b033bb5cc241a52c1 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 6 Dec 2022 14:34:16 +0100 Subject: [PATCH 030/244] Add option to use camera orientation for text. --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 53 ++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index ae5de7be0..78547fee2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1171,6 +1171,48 @@ void GLGizmoEmboss::discard_and_close() { // * Volume containing 3mf fix transformation - needs work around } +void use_camera_dir(const Camera &camera, GLCanvas3D &canvas) { + const Vec3d &cam_dir = camera.get_dir_forward(); + + Selection &sel = canvas.get_selection(); + if (sel.is_empty()) return; + assert(sel.get_volume_idxs().size() == 1); + GLVolume *vol = sel.get_volume(*sel.get_volume_idxs().begin()); + + // camera direction transformed into volume coordinate system + Vec3d cam_dir_tr = vol->world_matrix().inverse().linear() * cam_dir; + cam_dir_tr.normalize(); + + Vec3d emboss_dir(0., 0., -1.); + + // check wether cam_dir is already used + if (is_approx(cam_dir_tr, emboss_dir)) return; + + Transform3d vol_rot; + Transform3d vol_tr = vol->get_volume_transformation().get_matrix(); + // check whether cam_dir is opposit to emboss dir + if (is_approx(cam_dir_tr, -emboss_dir)) { + // rotate 180 DEG by y + vol_rot = Eigen::AngleAxis(M_PI_2, Vec3d(0., 1., 0.)); + } else { + // calc params for rotation + Vec3d axe = emboss_dir.cross(cam_dir_tr); + axe.normalize(); + double angle = std::acos(emboss_dir.dot(cam_dir_tr)); + vol_rot = Eigen::AngleAxis(angle, axe); + } + + Vec3d offset = vol_tr * Vec3d::Zero(); + Vec3d offset_inv = vol_rot.inverse() * offset; + Transform3d res = vol_tr * + Eigen::Translation(-offset) * + vol_rot * + Eigen::Translation(offset_inv); + //Transform3d res = vol_tr * vol_rot; + vol->set_volume_transformation(res); + priv::get_model_volume(vol, sel.get_model()->objects)->set_transformation(res); +} + void GLGizmoEmboss::draw_window() { #ifdef ALLOW_DEBUG_MODE @@ -1261,6 +1303,7 @@ void GLGizmoEmboss::draw_window() const auto &atlas = m_style_manager.get_atlas(); ImGui::Image(atlas.TexID, ImVec2(atlas.TexWidth, atlas.TexHeight)); #endif // SHOW_IMGUI_ATLAS + ImGui::SameLine(); if (ImGui::Checkbox("##allow_float_window", &m_allow_float_window)) { if (m_allow_float_window) @@ -1270,7 +1313,15 @@ void GLGizmoEmboss::draw_window() _u8L("Fix settings possition"): _u8L("Allow floating window near text")).c_str()); } -} + + ImGui::SameLine(); + if (ImGui::Button("use")) { + assert(priv::get_selected_volume(m_parent.get_selection()) == m_volume); + use_camera_dir(wxGetApp().plater()->get_camera(), m_parent); + } else if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("%s", _u8L("Use camera direction for text orientation").c_str()); + } + } void GLGizmoEmboss::draw_text_input() { From c8503d583597afc8fd0bb76c101d0c4755079f78 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 6 Dec 2022 14:45:25 +0100 Subject: [PATCH 031/244] Add using camera direction together with use surface --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 78547fee2..648122082 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1171,11 +1171,11 @@ void GLGizmoEmboss::discard_and_close() { // * Volume containing 3mf fix transformation - needs work around } -void use_camera_dir(const Camera &camera, GLCanvas3D &canvas) { +bool use_camera_dir(const Camera &camera, GLCanvas3D &canvas) { const Vec3d &cam_dir = camera.get_dir_forward(); Selection &sel = canvas.get_selection(); - if (sel.is_empty()) return; + if (sel.is_empty()) return false; assert(sel.get_volume_idxs().size() == 1); GLVolume *vol = sel.get_volume(*sel.get_volume_idxs().begin()); @@ -1186,7 +1186,7 @@ void use_camera_dir(const Camera &camera, GLCanvas3D &canvas) { Vec3d emboss_dir(0., 0., -1.); // check wether cam_dir is already used - if (is_approx(cam_dir_tr, emboss_dir)) return; + if (is_approx(cam_dir_tr, emboss_dir)) return false; Transform3d vol_rot; Transform3d vol_tr = vol->get_volume_transformation().get_matrix(); @@ -1211,6 +1211,7 @@ void use_camera_dir(const Camera &camera, GLCanvas3D &canvas) { //Transform3d res = vol_tr * vol_rot; vol->set_volume_transformation(res); priv::get_model_volume(vol, sel.get_model()->objects)->set_transformation(res); + return true; } void GLGizmoEmboss::draw_window() @@ -1317,7 +1318,10 @@ void GLGizmoEmboss::draw_window() ImGui::SameLine(); if (ImGui::Button("use")) { assert(priv::get_selected_volume(m_parent.get_selection()) == m_volume); - use_camera_dir(wxGetApp().plater()->get_camera(), m_parent); + const Camera& cam = wxGetApp().plater()->get_camera(); + bool use_surface = m_style_manager.get_style().prop.use_surface; + if (use_camera_dir(cam, m_parent) && use_surface) + process(); } else if (ImGui::IsItemHovered()) { ImGui::SetTooltip("%s", _u8L("Use camera direction for text orientation").c_str()); } From 05ee2a06ff2836fb1fe687696832a633191ca4e7 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 7 Dec 2022 13:27:03 +0100 Subject: [PATCH 032/244] Don't allow short if and for statements on one line Make debugging harder --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 6ec205af8..42ac9f1a0 100644 --- a/.clang-format +++ b/.clang-format @@ -13,8 +13,8 @@ AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false From d214159fc99f25588456245d932afe670cb8d842 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 7 Dec 2022 13:33:22 +0100 Subject: [PATCH 033/244] Bigger surface offset to be able see negative volume alligned with surface(constant used by @enrico ) --- src/slic3r/GUI/Jobs/EmbossJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index a5fa47672..0e7db94e8 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -679,7 +679,7 @@ OrthoProject3d priv::create_emboss_projection( bool is_outside, float emboss, Transform3d tr, SurfaceCut &cut) { // Offset of clossed side to model - const float surface_offset = 1e-3f; // [in mm] + const float surface_offset = 0.015f; // [in mm] float front_move = (is_outside) ? emboss : surface_offset, back_move = -((is_outside) ? surface_offset : emboss); From c0a60d4637b8d2de96618735af6ba17306195dac Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 7 Dec 2022 13:34:36 +0100 Subject: [PATCH 034/244] scale for text height information showed to user --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 68 ++++++++++++++++++++----- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 648122082..cbd9524a3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2563,23 +2563,60 @@ void GLGizmoEmboss::draw_style_edit() { bool use_inch = wxGetApp().app_config->get("use_inches") == "1"; const std::string revert_text_size = _u8L("Revert text size."); FontProp &font_prop = style.prop; - const float * def_size = exist_stored_style? - &m_style_manager.get_stored_style()->prop.size_in_mm : nullptr; - bool is_size_changed = false; + + const GLVolume* gl_vol = m_parent.get_selection().get_first_volume(); + Transform3d to_world = gl_vol->world_matrix(); + // Use fix of .3mf loaded tranformation when exist + if (m_volume->text_configuration->fix_3mf_tr.has_value()) + to_world = to_world * (*m_volume->text_configuration->fix_3mf_tr); + + Vec3d up_world = to_world.linear() * Vec3d(0., 1., 0.); + double norm_sq = up_world.squaredNorm(); + std::optional height_scale; + if (!is_approx(norm_sq, 1.)) + height_scale = sqrt(norm_sq); + + bool use_correction = use_inch || height_scale.has_value(); + const char *format = ((use_inch) ? "%.2f in" : "%.1f mm"); + float *size_ptr = nullptr; + float size_value; + const float * def_size_ptr = nullptr; + float def_value; if (use_inch) { - float size_in_inch = ObjectManipulation::mm_to_in * font_prop.size_in_mm; - float def_size_inch = exist_stored_style ? ObjectManipulation::mm_to_in * (*def_size) : 0.f; - if (def_size != nullptr) def_size = &def_size_inch; - if (rev_input(tr.size, size_in_inch, def_size, revert_text_size, 0.1f, 1.f, "%.2f in")) { - font_prop.size_in_mm = ObjectManipulation::in_to_mm * size_in_inch; - is_size_changed = true; + // calc value in inch + size_value = ObjectManipulation::mm_to_in * font_prop.size_in_mm; + if (exist_stored_style) { + def_value = ObjectManipulation::mm_to_in * (*def_size_ptr); + def_size_ptr = &def_value; + } + size_ptr = &size_value; + } + if (height_scale.has_value()) { + // use inch + if (size_ptr == nullptr) { + size_value = font_prop.size_in_mm; + size_ptr = &size_value; + } + size_value *= *height_scale; + if (def_size_ptr == nullptr) { + def_size_ptr = &m_style_manager.get_stored_style()->prop.size_in_mm; } - } else { - if (rev_input(tr.size, font_prop.size_in_mm, def_size, revert_text_size, 0.1f, 1.f, "%.1f mm")) - is_size_changed = true; } - if (is_size_changed) { + if (!use_correction){ + size_ptr = &font_prop.size_in_mm; + if (exist_stored_style) + def_size_ptr = &m_style_manager.get_stored_style()->prop.size_in_mm; + } + + assert(size_ptr != nullptr); + assert(exist_stored_style == (def_size_ptr != nullptr)); + if (rev_input(tr.size, *size_ptr, def_size_ptr, revert_text_size, 0.1f, 1.f, format)) { + if (use_correction) { + font_prop.size_in_mm = *size_ptr; + if (use_inch) font_prop.size_in_mm *= ObjectManipulation::in_to_mm; + if (height_scale.has_value()) font_prop.size_in_mm /= *height_scale; + } // size can't be zero or negative Limits::apply(font_prop.size_in_mm, limits.size_in_mm); @@ -2623,6 +2660,11 @@ void GLGizmoEmboss::draw_style_edit() { } #endif // SHOW_WX_WEIGHT_INPUT + Vec3d depth_world = to_world.linear() * Vec3d(0., 0., 1.); + double depth_sq = depth_world.squaredNorm(); + std::optional depth_scale; + if (!is_approx(depth_sq, 1.)) depth_scale = sqrt(depth_sq); + const std::string revert_emboss_depth = _u8L("Revert embossed depth."); const float *def_depth = exist_stored_style ? &m_style_manager.get_stored_style()->prop.emboss : nullptr; From b037e5f024d1c6e7dea90daf4f8e31b95117d5ae Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Dec 2022 22:10:33 +0100 Subject: [PATCH 035/244] Optimization: do not regenerate toolbar texture in each frame --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 79370022b..b7988ea7c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5653,9 +5653,9 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() collapse_toolbar.set_scale(sc); size *= m_retina_helper->get_scale_factor(); #else - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); - collapse_toolbar.set_icons_size(size); + m_main_toolbar.set_icons_size(int(size)); + m_undoredo_toolbar.set_icons_size(int(size)); + collapse_toolbar.set_icons_size(int(size)); #endif // ENABLE_RETINA_GL float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); @@ -5687,24 +5687,12 @@ void GLCanvas3D::_render_overlays() { glsafe(::glDisable(GL_DEPTH_TEST)); + // main toolbar and undoredo toolbar need to be both updated before rendering because both their sizes are needed + // to correctly place them _check_and_update_toolbar_icon_scale(); _render_gizmos_overlay(); - // main toolbar and undoredo toolbar need to be both updated before rendering because both their sizes are needed - // to correctly place them -#if ENABLE_RETINA_GL - const float scale = m_retina_helper->get_scale_factor() * wxGetApp().toolbar_icon_scale(/*true*/); - m_main_toolbar.set_scale(scale); - m_undoredo_toolbar.set_scale(scale); - wxGetApp().plater()->get_collapse_toolbar().set_scale(scale); -#else - const float size = int(GLToolbar::Default_Icons_Size * wxGetApp().toolbar_icon_scale(/*true*/)); - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); - wxGetApp().plater()->get_collapse_toolbar().set_icons_size(size); -#endif // ENABLE_RETINA_GL - _render_main_toolbar(); _render_undoredo_toolbar(); _render_collapse_toolbar(); From fe3a15942bae16e7d8bf70ac66a7625c983f5963 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 7 Dec 2022 14:50:20 +0100 Subject: [PATCH 036/244] Follow-up of 6d737f7081883071a547e0c9960813342e8388e3 - Ensure icon size is a whole number wherever is used --- src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b7988ea7c..d93a76cc1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5639,10 +5639,10 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() if (wxGetApp().plater()->is_preview_shown()) return; - float scale = wxGetApp().toolbar_icon_scale(); - Size cnv_size = get_canvas_size(); + const float scale = wxGetApp().toolbar_icon_scale(); + const Size cnv_size = get_canvas_size(); - float size = GLToolbar::Default_Icons_Size * scale; + int size = int(GLToolbar::Default_Icons_Size * scale); // Set current size for all top toolbars. It will be used for next calculations GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); @@ -5651,28 +5651,28 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() m_main_toolbar.set_scale(sc); m_undoredo_toolbar.set_scale(sc); collapse_toolbar.set_scale(sc); - size *= m_retina_helper->get_scale_factor(); + size *= int(m_retina_helper->get_scale_factor()); #else - m_main_toolbar.set_icons_size(int(size)); - m_undoredo_toolbar.set_icons_size(int(size)); - collapse_toolbar.set_icons_size(int(size)); + m_main_toolbar.set_icons_size(size); + m_undoredo_toolbar.set_icons_size(size); + collapse_toolbar.set_icons_size(size); #endif // ENABLE_RETINA_GL - float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); + const float top_tb_width = m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar.get_width(); int items_cnt = m_main_toolbar.get_visible_items_cnt() + m_undoredo_toolbar.get_visible_items_cnt() + collapse_toolbar.get_visible_items_cnt(); - float noitems_width = top_tb_width - size * items_cnt; // width of separators and borders in top toolbars + const float noitems_width = top_tb_width - float(size) * items_cnt; // width of separators and borders in top toolbars // calculate scale needed for items in all top toolbars // the std::max() is there because on some Linux dialects/virtual machines this code is called when the canvas has not been properly initialized yet, // leading to negative values for the scale. // See: https://github.com/prusa3d/PrusaSlicer/issues/8563 // https://github.com/supermerill/SuperSlicer/issues/854 - float new_h_scale = std::max((cnv_size.get_width() - noitems_width), 1.0f) / (items_cnt * GLToolbar::Default_Icons_Size); + const float new_h_scale = std::max((cnv_size.get_width() - noitems_width), 1.0f) / (items_cnt * GLToolbar::Default_Icons_Size); items_cnt = m_gizmos.get_selectable_icons_cnt() + 3; // +3 means a place for top and view toolbars and separators in gizmos toolbar // calculate scale needed for items in the gizmos toolbar - float new_v_scale = cnv_size.get_height() / (items_cnt * GLGizmosManager::Default_Icons_Size); + const float new_v_scale = cnv_size.get_height() / (items_cnt * GLGizmosManager::Default_Icons_Size); // set minimum scale as a auto scale for the toolbars float new_scale = std::min(new_h_scale, new_v_scale); From 85ad56b43bedf882097255e643b8ab974943f7b0 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 6 Dec 2022 12:18:05 +0100 Subject: [PATCH 037/244] Optimization: std::vector can be quite slow to access --- src/libslic3r/TriangleMesh.cpp | 2 +- src/libslic3r/TriangleMesh.hpp | 2 +- src/libslic3r/TriangleMeshSlicer.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 6e17daa56..d5fe83c26 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -622,7 +622,7 @@ std::vector its_face_edge_ids(const indexed_triangle_set &its, std::funct return its_face_edge_ids_impl(its, [](const uint32_t){ return true; }, throw_on_cancel_callback); } -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask) { return its_face_edge_ids_impl(its, [&face_mask](const uint32_t idx){ return face_mask[idx]; }, [](){}); } diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index d8096eae2..26701bdf5 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -188,7 +188,7 @@ private: // Used for chaining slice lines into polygons. std::vector its_face_edge_ids(const indexed_triangle_set &its); std::vector its_face_edge_ids(const indexed_triangle_set &its, std::function throw_on_cancel_callback); -std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); +std::vector its_face_edge_ids(const indexed_triangle_set &its, const std::vector &face_mask); // Having the face neighbors available, assign unique edge IDs to face edges for chaining of polygons over slices. std::vector its_face_edge_ids(const indexed_triangle_set &its, std::vector &face_neighbors, bool assign_unbound_edges = false, int *num_edges = nullptr); diff --git a/src/libslic3r/TriangleMeshSlicer.cpp b/src/libslic3r/TriangleMeshSlicer.cpp index 63802961b..461d8c22e 100644 --- a/src/libslic3r/TriangleMeshSlicer.cpp +++ b/src/libslic3r/TriangleMeshSlicer.cpp @@ -1805,7 +1805,7 @@ Polygons slice_mesh( { bool trafo_identity = is_identity(params.trafo); Transform3f tf; - std::vector face_mask(mesh.indices.size(), false); + std::vector face_mask(mesh.indices.size(), 0); { // 1) Mark vertices as below or above the slicing plane. From 595ef873ad0fb3c52ce3705bc80569326c089ec3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 7 Dec 2022 15:23:38 +0100 Subject: [PATCH 038/244] Change the way how cut gizmo detects hits on cut plane: it did not work well on meshes with overlapping surfaces --- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 73 +++++++++++++--------------- src/slic3r/GUI/Gizmos/GLGizmoCut.hpp | 2 +- src/slic3r/GUI/MeshUtils.cpp | 45 ++--------------- src/slic3r/GUI/MeshUtils.hpp | 8 +-- 4 files changed, 40 insertions(+), 88 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 29d578fba..3cd661ba3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -1144,11 +1144,11 @@ void GLGizmoCut3D::dragging_grabber_xy(const GLGizmoBase::UpdateData &data) void GLGizmoCut3D::dragging_connector(const GLGizmoBase::UpdateData &data) { CutConnectors& connectors = m_c->selection_info()->model_object()->cut_connectors; - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(data.mouse_pos.cast(), pos_and_normal, pos_world)) { - connectors[m_hover_id - m_connectors_group_id].pos = pos_and_normal.first; + if (unproject_on_cut_plane(data.mouse_pos.cast(), pos, pos_world)) { + connectors[m_hover_id - m_connectors_group_id].pos = pos; update_raycasters_for_picking_transform(); } } @@ -2006,44 +2006,41 @@ void GLGizmoCut3D::perform_cut(const Selection& selection) // Unprojects the mouse position on the mesh and saves hit point and normal of the facet into pos_and_normal // Return false if no intersection was found, true otherwise. -bool GLGizmoCut3D::unproject_on_cut_plane(const Vec2d& mouse_position, std::pair& pos_and_normal, Vec3d& pos_world) +bool GLGizmoCut3D::unproject_on_cut_plane(const Vec2d& mouse_position, Vec3d& pos, Vec3d& pos_world) { 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()]; - const Transform3d instance_trafo = sla_shift > 0.f ? - translation_transform(sla_shift * Vec3d::UnitZ()) * mi->get_transformation().get_matrix() : mi->get_transformation().get_matrix(); const Camera& camera = wxGetApp().plater()->get_camera(); - int mesh_id = -1; - for (const ModelVolume* mv : mo->volumes) { - ++mesh_id; - if (!mv->is_model_part()) - continue; - Vec3f normal; - Vec3f hit; - bool clipping_plane_was_hit = false; + // Calculate intersection with the clipping plane. + const ClippingPlane* cp = m_c->object_clipper()->get_clipping_plane(true); + Vec3d point; + Vec3d direction; + Vec3d hit; + MeshRaycaster::line_from_mouse_pos(mouse_position, Transform3d::Identity(), camera, point, direction); + Vec3d normal = -cp->get_normal().cast(); + double den = normal.dot(direction); + if (den != 0.) { + double t = (-cp->get_offset() - normal.dot(point))/den; + hit = (point + t * direction); + } else + return false; + + if (! m_c->object_clipper()->is_projection_inside_cut(hit)) + return false; -// const Transform3d volume_trafo = get_volume_transformation(mv); - const Transform3d volume_trafo = mv->get_transformation().get_matrix(); + // recalculate hit to object's local position + Vec3d hit_d = hit; + hit_d -= mi->get_offset(); + hit_d[Z] -= sla_shift; - m_c->raycaster()->raycasters()[mesh_id]->unproject_on_mesh(mouse_position, instance_trafo * volume_trafo, - camera, hit, normal, m_c->object_clipper()->get_clipping_plane(true), - nullptr, &clipping_plane_was_hit); - if (clipping_plane_was_hit) { - // recalculate hit to object's local position - Vec3d hit_d = hit.cast(); - hit_d -= mi->get_offset(); - hit_d[Z] -= sla_shift; + // Return both the point and the facet normal. + pos = hit_d; + pos_world = hit; - // Return both the point and the facet normal. - pos_and_normal = std::make_pair(hit_d, normal.cast()); - pos_world = hit.cast(); - return true; - } - } - return false; + return true; } void GLGizmoCut3D::clear_selection() @@ -2139,17 +2136,13 @@ bool GLGizmoCut3D::add_connector(CutConnectors& connectors, const Vec2d& mouse_p if (!m_connectors_editing) return false; - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(mouse_position.cast(), pos_and_normal, pos_world)) { - // check if pos is out of enabled clipping plane - if (m_c->object_clipper() && !m_c->object_clipper()->is_projection_inside_cut(pos_world)) - return true; - + if (unproject_on_cut_plane(mouse_position.cast(), pos, pos_world)) { Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Add connector"), UndoRedo::SnapshotType::GizmoAction); unselect_all_connectors(); - connectors.emplace_back(pos_and_normal.first, m_rotation_m, + connectors.emplace_back(pos, m_rotation_m, m_connector_size * 0.5f, m_connector_depth_ratio, m_connector_size_tolerance, m_connector_depth_ratio_tolerance, CutConnectorAttributes( CutConnectorType(m_connector_type), @@ -2247,9 +2240,9 @@ bool GLGizmoCut3D::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_posi if (!m_connectors_editing) { if (0 && action == SLAGizmoEventType::LeftDown) { // disable / enable current contour - std::pair pos_and_normal; + Vec3d pos; Vec3d pos_world; - if (unproject_on_cut_plane(mouse_position.cast(), pos_and_normal, pos_world)) { + if (unproject_on_cut_plane(mouse_position.cast(), pos, pos_world)) { // Following would inform the clipper about the mouse click, so it can // toggle the respective contour as disabled. m_c->object_clipper()->pass_mouse_click(pos_world); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index 8a3ee6d07..e9412357d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -155,7 +155,7 @@ public: GLGizmoCut3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); std::string get_tooltip() const override; - bool unproject_on_cut_plane(const Vec2d& mouse_pos, std::pair& pos_and_normal, Vec3d& pos_world); + bool unproject_on_cut_plane(const Vec2d& mouse_pos, Vec3d& pos, Vec3d& pos_world); bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); bool is_in_editing_mode() const override { return m_connectors_editing; } diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 39e463a19..a58191528 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -365,11 +365,8 @@ void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3 bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3f& position, Vec3f& normal, const ClippingPlane* clipping_plane, - size_t* facet_idx, bool* was_clipping_plane_hit) const + size_t* facet_idx) const { - if (was_clipping_plane_hit) - *was_clipping_plane_hit = false; - Vec3d point; Vec3d direction; line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); @@ -390,26 +387,9 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& break; } - if (i==hits.size()) { - // All hits are clipped. - return false; - } - if (clipping_plane && (hits.size()-i) % 2 != 0) { - // There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh. - // In that case, calculate intersection with the clipping place. - if (was_clipping_plane_hit) { - direction = direction + point; - point = trafo * point; // transform to world coords - direction = trafo * direction - point; - - Vec3d normal = -clipping_plane->get_normal().cast(); - double den = normal.dot(direction); - if (den != 0.) { - double t = (-clipping_plane->get_offset() - normal.dot(point))/den; - position = (point + t * direction).cast(); - *was_clipping_plane_hit = true; - } - } + if (i==hits.size() || (hits.size()-i) % 2 != 0) { + // All hits are either clipped, or there is an odd number of unclipped + // hits - meaning the nearest must be from inside the mesh. return false; } @@ -423,24 +403,7 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& return true; } -bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, - Vec3d& position, Vec3d& normal) const -{ - Vec3d point; - Vec3d direction; - line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); - std::vector hits = m_emesh.query_ray_hits(point, direction); - - if (hits.empty()) - return false; // no intersection found - - // Now stuff the points in the provided vector and calculate normals if asked about them: - position = hits[0].position(); - normal = hits[0].normal(); - - return true; -} bool MeshRaycaster::is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const { diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index 441532fdb..401ba22f1 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -153,16 +153,12 @@ public: const Vec2d& mouse_pos, const Transform3d& trafo, // how to get the mesh into world coords const Camera& camera, // current camera position - Vec3f& position, // where to save the positibon of the hit (mesh coords if mesh, world coords if clipping plane) + Vec3f& position, // where to save the positibon of the hit (mesh coords) Vec3f& normal, // normal of the triangle that was hit const ClippingPlane* clipping_plane = nullptr, // clipping plane (if active) - size_t* facet_idx = nullptr, // index of the facet hit - bool* was_clipping_plane_hit = nullptr // is the hit on the clipping place cross section? + size_t* facet_idx = nullptr // index of the facet hit ) const; - // Given a mouse position, this returns true in case it is on the mesh. - bool unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, Vec3d& position, Vec3d& normal) const; - bool is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const; // Given a vector of points in woorld coordinates, this returns vector From d2c8d628b96f8e3e0b4fe8ac6a9879c33521c037 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 7 Dec 2022 16:06:43 +0100 Subject: [PATCH 039/244] Fixed a bug in Cut gizmo - contour width was not updating correctly --- src/slic3r/GUI/MeshUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index a58191528..9246c4cdf 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -22,7 +22,7 @@ namespace GUI { void MeshClipper::set_behaviour(bool fill_cut, double contour_width) { - if (fill_cut != m_fill_cut || is_approx(contour_width, m_contour_width)) + if (fill_cut != m_fill_cut || ! is_approx(contour_width, m_contour_width)) m_result.reset(); m_fill_cut = fill_cut; m_contour_width = contour_width; From 71a0b626a9d15a61dbd9a87f25c28001cb631292 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 7 Dec 2022 16:52:52 +0100 Subject: [PATCH 040/244] Fixed memory leaks on switch between parameter pages --- src/slic3r/GUI/Field.cpp | 9 +++ src/slic3r/GUI/Field.hpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 130 ++++++++++++++++---------------- src/slic3r/GUI/OptionsGroup.hpp | 1 + src/slic3r/GUI/Tab.cpp | 2 + 5 files changed, 78 insertions(+), 66 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index d3fef44d3..40cd7f889 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1416,6 +1416,15 @@ void ColourPicker::sys_color_changed() #endif } +PointCtrl::~PointCtrl() +{ + if (sizer) { + sizer->Clear(); + delete sizer; + sizer = nullptr; + } +} + void PointCtrl::BUILD() { auto temp = new wxBoxSizer(wxHORIZONTAL); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 60a06427d..eaa4fe481 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -425,7 +425,7 @@ class PointCtrl : public Field { public: PointCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} PointCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} - ~PointCtrl() {} + ~PointCtrl(); wxSizer* sizer{ nullptr }; wxTextCtrl* x_textctrl{ nullptr }; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index cfa2ef15a..0534446f0 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -118,6 +118,24 @@ OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title, { } +void Line::clear() +{ + if (near_label_widget_win) + near_label_widget_win = nullptr; + + if (widget_sizer) { + widget_sizer->Clear(true); + delete widget_sizer; + widget_sizer = nullptr; + } + + if (extra_widget_sizer) { + extra_widget_sizer->Clear(true); + delete extra_widget_sizer; + extra_widget_sizer = nullptr; + } +} + wxWindow* OptionsGroup::ctrl_parent() const { return this->custom_ctrl && m_use_custom_ctrl_as_parent ? static_cast(this->custom_ctrl) : (this->stb ? static_cast(this->stb) : this->parent()); @@ -231,7 +249,7 @@ void OptionsGroup::activate_line(Line& line) } } - auto option_set = line.get_options(); + const std::vector