From 3421a9298a8c0e522310d3d73ca684a763484b99 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 13 Sep 2023 11:56:37 +0200 Subject: [PATCH] Remove depricated variable + read old staff in separate 3mf function --- src/libslic3r/Emboss.cpp | 4 --- src/libslic3r/Emboss.hpp | 5 ++-- src/libslic3r/Format/3mf.cpp | 40 +++++++++++++------------ src/libslic3r/TextConfiguration.hpp | 17 +---------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 34 +++++---------------- src/slic3r/Utils/WxFontUtils.cpp | 3 +- tests/libslic3r/test_emboss.cpp | 5 ++-- 7 files changed, 36 insertions(+), 72 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 4734ded814..0fed283a0c 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -1352,10 +1352,6 @@ unsigned Emboss::get_count_lines(const ExPolygonsWithIds &shapes) { return result; } -void Emboss::apply_transformation(const FontProp &font_prop, Transform3d &transformation){ - apply_transformation(font_prop.angle, font_prop.distance, transformation); -} - void Emboss::apply_transformation(const std::optional& angle, const std::optional& distance, Transform3d &transformation) { if (angle.has_value()) { double angle_z = *angle; diff --git a/src/libslic3r/Emboss.hpp b/src/libslic3r/Emboss.hpp index f606dad936..870fa3183b 100644 --- a/src/libslic3r/Emboss.hpp +++ b/src/libslic3r/Emboss.hpp @@ -198,10 +198,9 @@ namespace Emboss /// /// Use data from font property to modify transformation /// - /// Z-move as surface distance(FontProp::distance) - /// Z-rotation as angle to Y axis(FontProp::angle) + /// Z-rotation as angle to Y axis + /// Z-move as surface distance /// In / Out transformation to modify by property - void apply_transformation(const FontProp &font_prop, Transform3d &transformation); void apply_transformation(const std::optional &angle, const std::optional &distance, Transform3d &transformation); /// diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 311e441e5c..c72256a8fc 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1982,6 +1982,7 @@ namespace Slic3r { static void to_xml(std::stringstream &stream, const TextConfiguration &tc); static std::optional read(const char **attributes, unsigned int num_attributes); + static EmbossShape read_old(const char **attributes, unsigned int num_attributes); }; bool _3MF_Importer::_handle_start_text_configuration(const char **attributes, unsigned int num_attributes) @@ -2005,14 +2006,7 @@ namespace Slic3r { return true; // Back compatibility for 3mf version without shapes - const TextConfiguration &tc = *volume.text_configuration; - EmbossShape es; - es.fix_3mf_tr = tc.fix_3mf_tr; - const FontProp &fp = tc.style.prop; - EmbossProjection& ep = es.projection; - ep.depth = fp.emboss; - ep.use_surface = fp.use_surface; - volume.shape_configuration = es; + volume.shape_configuration = TextConfigurationSerialization::read_old(attributes, num_attributes); return true; } @@ -3655,8 +3649,6 @@ std::optional TextConfigurationSerialization::read(const char float skew = get_attribute_value_float(attributes, num_attributes, SKEW_ATTR); if (std::fabs(skew) > std::numeric_limits::epsilon()) fp.skew = skew; - int use_surface = get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR); - if (use_surface == 1) fp.use_surface = true; int per_glyph = get_attribute_value_int(attributes, num_attributes, PER_GLYPH_ATTR); if (per_glyph == 1) fp.per_glyph = true; @@ -3686,18 +3678,28 @@ std::optional TextConfigurationSerialization::read(const char EmbossStyle::Type type = TextConfigurationSerialization::get_type(type_str); std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR); + EmbossStyle es{style_name, std::move(font_descriptor), type, std::move(fp)}; + return TextConfiguration{std::move(es), std::move(text)}; +} - // Read of old fashion save style for Back compatibility - std::optional fix_tr_mat; +EmbossShape TextConfigurationSerialization::read_old(const char **attributes, unsigned int num_attributes) +{ + EmbossShape es; std::string fix_tr_mat_str = get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR); - if (!fix_tr_mat_str.empty()) - fix_tr_mat = get_transform_from_3mf_specs_string(fix_tr_mat_str); - if (get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR) == 1) - fp.use_surface = true; - fp.emboss = get_attribute_value_float(attributes, num_attributes, DEPTH_ATTR); + if (!fix_tr_mat_str.empty()) + es.fix_3mf_tr = get_transform_from_3mf_specs_string(fix_tr_mat_str); - EmbossStyle fi{style_name, std::move(font_descriptor), type, std::move(fp)}; - return TextConfiguration{std::move(fi), std::move(text), std::move(fix_tr_mat)}; + + if (get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR) == 1) + es.projection.use_surface = true; + + es.projection.depth = get_attribute_value_float(attributes, num_attributes, DEPTH_ATTR); + + int use_surface = get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR); + if (use_surface == 1) + es.projection.use_surface = true; + + return es; } namespace { diff --git a/src/libslic3r/TextConfiguration.hpp b/src/libslic3r/TextConfiguration.hpp index 96ccf68726..8da67cdd0a 100644 --- a/src/libslic3r/TextConfiguration.hpp +++ b/src/libslic3r/TextConfiguration.hpp @@ -54,18 +54,6 @@ struct FontProp // change pivot of text // When not set, center is used and is not stored Align align = Align(HorizontalAlign::center, VerticalAlign::center); - - [[deprecated("Back compatibility only, now it is stored EmbossProjection like depth")]] - float emboss; - - [[deprecated("Back compatibility only, now it is stored EmbossProjection")]] - bool use_surface; - - [[deprecated("it is calculated on the fly")]] - std::optional distance; - - [[deprecated("it is calculated on the fly")]] - std::optional angle; ////// // Duplicit data to wxFontDescriptor @@ -88,7 +76,7 @@ struct FontProp /// /// Y size of text [in mm] /// Z size of text [in mm] - FontProp(float line_height = 10.f, float depth = 2.f) : emboss(depth), size_in_mm(line_height), use_surface(false), per_glyph(false) + FontProp(float line_height = 10.f) : size_in_mm(line_height), per_glyph(false) {} bool operator==(const FontProp& other) const { @@ -194,9 +182,6 @@ struct TextConfiguration // Embossed text value std::string text = "None"; - [[deprecated("only for back compatibility, now it is stored in EmbossShape")]] - std::optional fix_3mf_tr; - // undo / redo stack recovery template void serialize(Archive &ar) { ar(style, text); } }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 022145386c..a5032aa25b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -413,12 +413,14 @@ bool GLGizmoEmboss::do_mirror(size_t axis) return false; const TextConfiguration &tc= *m_volume->text_configuration; - if(tc.style.prop.per_glyph){ + if(tc.style.prop.per_glyph){ // init textlines before mirroring on mirrored text volume transformation Transform3d tr = m_volume->get_matrix(); - const std::optional &fix_tr = tc.fix_3mf_tr; - if (fix_tr.has_value()) - tr = tr * (fix_tr->inverse()); + if (m_volume->emboss_shape.has_value()) { + const std::optional &fix_tr = m_volume->emboss_shape->fix_3mf_tr; + if (fix_tr.has_value()) + tr = tr * (fix_tr->inverse()); + } // mirror Vec3d scale = Vec3d::Ones(); @@ -563,8 +565,7 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event) assert(m_style_manager.is_active_font()); if (gl_volume == nullptr || !m_style_manager.is_active_font()) return res; - - m_style_manager.get_font_prop().angle = calc_up(gl_volume->world_matrix(), Slic3r::GUI::up_limit); + m_style_manager.get_style().angle = calc_up(gl_volume->world_matrix(), Slic3r::GUI::up_limit); } volume_transformation_changing(); @@ -1272,7 +1273,7 @@ void GLGizmoEmboss::set_volume_by_selection() // Calculate current angle of up vector assert(m_style_manager.is_active_font()); if (m_style_manager.is_active_font()) - m_style_manager.get_font_prop().angle = calc_up(gl_volume->world_matrix(), up_limit); + m_style_manager.get_style().angle = calc_up(gl_volume->world_matrix(), up_limit); // calculate scale for height and depth inside of scaled object instance calculate_scale(); @@ -3261,26 +3262,7 @@ void TextDataBase::write(ModelVolume &volume) const { DataBase::write(volume); volume.text_configuration = m_text_configuration; // copy - - // TEMPORARY check until depricated variable will be deleted - FontProp &fp = volume.text_configuration->style.prop; - // Distance and angle are calculated on the fly it should not be stored in volume - assert(!fp.angle.has_value()); - if (fp.angle.has_value()) - fp.angle.reset(); - assert(!fp.distance.has_value()); - if (fp.distance.has_value()) - fp.distance.reset(); - - // use_surface and emboss are stored in projection assert(volume.emboss_shape.has_value()); - if (!volume.emboss_shape.has_value()) - return; - const EmbossProjection &ep = volume.emboss_shape->projection; - if (fp.use_surface != ep.use_surface) - fp.use_surface = ep.use_surface; - if (!is_approx(fp.emboss, static_cast(ep.depth))) - fp.emboss = static_cast(ep.depth); } std::unique_ptr create_emboss_data_base(const std::string &text, diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 7544553785..b34499fb63 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -129,7 +129,7 @@ EmbossStyle WxFontUtils::create_emboss_style(const wxFont &font, const std::stri { std::string name_item = name.empty()? get_human_readable_name(font) : name; std::string fontDesc = store_wxFont(font); - EmbossStyle::Type type = get_current_type(); + EmbossStyle::Type type = get_current_type(); // synchronize font property with actual font FontProp font_prop; @@ -138,7 +138,6 @@ EmbossStyle WxFontUtils::create_emboss_style(const wxFont &font, const std::stri // is approximately 0.0139 inch or 352.8 um. But it is too small, so I // decide use point size as mm for emboss font_prop.size_in_mm = font.GetPointSize(); // *0.3528f; - font_prop.emboss = font_prop.size_in_mm / 2.f; WxFontUtils::update_property(font_prop, font); return { name_item, fontDesc, type, font_prop }; diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index e294e96e9b..b4315ebb7b 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -313,18 +313,19 @@ The other kids at school nicknamed him Ix,\n\ which in the language of Betelgeuse Five translates as\t\n\ \"boy who is not able satisfactorily to explain what a Hrung is,\n\ nor why it should choose to collapse on Betelgeuse Seven\"."; - float line_height = 10.f, depth = 2.f; + float line_height = 10.f; auto font = Emboss::create_font_file(font_path.c_str()); REQUIRE(font != nullptr); Emboss::FontFileWithCache ffwc(std::move(font)); - FontProp fp{line_height, depth}; + FontProp fp{line_height}; auto was_canceled = []() { return false; }; ExPolygons shapes = Emboss::text2shapes(ffwc, text.c_str(), fp, was_canceled); REQUIRE(!shapes.empty()); + float depth = 2.f; Emboss::ProjectZ projection(depth); indexed_triangle_set its = Emboss::polygons2model(shapes, projection); CHECK(!its.indices.empty());