From a6834a1a826efc4a87fbdc0b039d3f61608b0c07 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Tue, 8 Mar 2022 09:22:56 +0100 Subject: [PATCH] WxUtils are using imap Remove unused map utils --- src/libslic3r/CMakeLists.txt | 1 - src/libslic3r/MapUtils.hpp | 30 --------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 1 - src/slic3r/Utils/WxFontUtils.cpp | 87 ++++++++++++------------- src/slic3r/Utils/WxFontUtils.hpp | 15 ++--- tests/libslic3r/libslic3r_tests.cpp | 1 - 6 files changed, 48 insertions(+), 87 deletions(-) delete mode 100644 src/libslic3r/MapUtils.hpp diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 672e638c4f..628f08e68e 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -163,7 +163,6 @@ set(SLIC3R_SOURCES BlacklistedLibraryCheck.hpp LocalesUtils.cpp LocalesUtils.hpp - MapUtils.hpp Model.cpp Model.hpp ModelArrange.hpp diff --git a/src/libslic3r/MapUtils.hpp b/src/libslic3r/MapUtils.hpp deleted file mode 100644 index 44869bacf2..0000000000 --- a/src/libslic3r/MapUtils.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef slic3r_MapUtils_hpp_ -#define slic3r_MapUtils_hpp_ - -#include -namespace Slic3r { - -/// -/// Utility for easier work with standart map -/// -class MapUtils -{ -public: - MapUtils() = delete; // only static functions - - /// - /// Create map with swaped key-value - /// - /// Input map - /// Map with changed key to value and vice versa - template - static std::map create_oposit(const std::map &map) - { - std::map result; - for (const auto &it : map) result[it.second] = it.first; - return result; - } -}; - -} // namespace Slic3r -#endif // slic3r_MapUtils_hpp_ \ No newline at end of file diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index a17f28a3ea..424f897f50 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -23,7 +23,6 @@ #include "libslic3r/Model.hpp" #include "libslic3r/ClipperUtils.hpp" // union_ex #include "libslic3r/AppConfig.hpp" // store/load font list -#include "libslic3r/MapUtils.hpp" #include "libslic3r/Format/OBJ.hpp" // load obj file for default object #include "libslic3r/BuildVolume.hpp" diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 7bb99cd039..3e36b45f4b 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -1,6 +1,5 @@ #include "WxFontUtils.hpp" -#include "libslic3r/MapUtils.hpp" -#include +#include #if defined(__APPLE__) #include @@ -164,39 +163,37 @@ std::optional WxFontUtils::load_wxFont( return wx_font; } -const std::map WxFontUtils::from_family( - {{wxFONTFAMILY_DEFAULT, "default"}, - {wxFONTFAMILY_DECORATIVE, "decorative"}, - {wxFONTFAMILY_ROMAN, "roman"}, - {wxFONTFAMILY_SCRIPT, "script"}, - {wxFONTFAMILY_SWISS, "swiss"}, - {wxFONTFAMILY_MODERN, "modern"}, - {wxFONTFAMILY_TELETYPE, "teletype"}, - {wxFONTFAMILY_MAX, "max"}, - {wxFONTFAMILY_UNKNOWN, "unknown"}}); -const std::map WxFontUtils::to_family = - MapUtils::create_oposit(WxFontUtils::from_family); +using TypeToFamily = boost::bimap; +const TypeToFamily WxFontUtils::type_to_family = + boost::assign::list_of + (wxFONTFAMILY_DEFAULT, "default") + (wxFONTFAMILY_DECORATIVE, "decorative") + (wxFONTFAMILY_ROMAN, "roman") + (wxFONTFAMILY_SCRIPT, "script") + (wxFONTFAMILY_SWISS, "swiss") + (wxFONTFAMILY_MODERN, "modern") + (wxFONTFAMILY_TELETYPE, "teletype"); -const std::map WxFontUtils::from_style( - {{wxFONTSTYLE_ITALIC, "italic"}, - {wxFONTSTYLE_SLANT, "slant"}, - {wxFONTSTYLE_NORMAL, "normal"}}); -const std::map WxFontUtils::to_style = - MapUtils::create_oposit(WxFontUtils::from_style); +using TypeToStyle = boost::bimap; +const TypeToStyle WxFontUtils::type_to_style = + boost::assign::list_of + (wxFONTSTYLE_ITALIC, "italic") + (wxFONTSTYLE_SLANT, "slant") + (wxFONTSTYLE_NORMAL, "normal"); -const std::map WxFontUtils::from_weight( - {{wxFONTWEIGHT_THIN, "thin"}, - {wxFONTWEIGHT_EXTRALIGHT, "extraLight"}, - {wxFONTWEIGHT_LIGHT, "light"}, - {wxFONTWEIGHT_NORMAL, "normal"}, - {wxFONTWEIGHT_MEDIUM, "medium"}, - {wxFONTWEIGHT_SEMIBOLD, "semibold"}, - {wxFONTWEIGHT_BOLD, "bold"}, - {wxFONTWEIGHT_EXTRABOLD, "extraBold"}, - {wxFONTWEIGHT_HEAVY, "heavy"}, - {wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy"}}); -const std::map WxFontUtils::to_weight = - MapUtils::create_oposit(WxFontUtils::from_weight); +using TypeToWeight = boost::bimap; +const TypeToWeight WxFontUtils::type_to_weight = + boost::assign::list_of + (wxFONTWEIGHT_THIN, "thin") + (wxFONTWEIGHT_EXTRALIGHT, "extraLight") + (wxFONTWEIGHT_LIGHT, "light") + (wxFONTWEIGHT_NORMAL, "normal") + (wxFONTWEIGHT_MEDIUM, "medium") + (wxFONTWEIGHT_SEMIBOLD, "semibold") + (wxFONTWEIGHT_BOLD, "bold") + (wxFONTWEIGHT_EXTRABOLD, "extraBold") + (wxFONTWEIGHT_HEAVY, "heavy") + (wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy"); std::optional WxFontUtils::create_wxFont(const FontItem &fi, const FontProp &fp) @@ -204,20 +201,20 @@ std::optional WxFontUtils::create_wxFont(const FontItem &fi, double point_size = static_cast(fp.size_in_mm); wxFontInfo info(point_size); if (fp.family.has_value()) { - auto it = to_family.find(*fp.style); - if (it != to_family.end()) info.Family(it->second); + auto it = type_to_family.right.find(*fp.style); + if (it != type_to_family.right.end()) info.Family(it->second); } if (fp.face_name.has_value()) { wxString face_name(*fp.face_name); info.FaceName(face_name); } if (fp.style.has_value()) { - auto it = to_style.find(*fp.style); - if (it != to_style.end()) info.Style(it->second); + auto it = type_to_style.right.find(*fp.style); + if (it != type_to_style.right.end()) info.Style(it->second); } if (fp.weight.has_value()) { - auto it = to_weight.find(*fp.weight); - if (it != to_weight.end()) info.Weight(it->second); + auto it = type_to_weight.right.find(*fp.weight); + if (it != type_to_weight.right.end()) info.Weight(it->second); } // Improve: load descriptor instead of store to font property to 3mf @@ -249,20 +246,20 @@ void WxFontUtils::update_property(FontProp &font_prop, const wxFont &font) wxFontFamily wx_family = font.GetFamily(); if (wx_family != wxFONTFAMILY_DEFAULT) { - auto it = from_family.find(wx_family); - if (it != from_family.end()) font_prop.family = it->second; + auto it = type_to_family.left.find(wx_family); + if (it != type_to_family.left.end()) font_prop.family = it->second; } wxFontStyle wx_style = font.GetStyle(); if (wx_style != wxFONTSTYLE_NORMAL) { - auto it = from_style.find(wx_style); - if (it != from_style.end()) font_prop.style = it->second; + auto it = type_to_style.left.find(wx_style); + if (it != type_to_style.left.end()) font_prop.style = it->second; } wxFontWeight wx_weight = font.GetWeight(); if (wx_weight != wxFONTWEIGHT_NORMAL) { - auto it = from_weight.find(wx_weight); - if (it != from_weight.end()) font_prop.weight = it->second; + auto it = type_to_weight.left.find(wx_weight); + if (it != type_to_weight.left.end()) font_prop.weight = it->second; } } diff --git a/src/slic3r/Utils/WxFontUtils.hpp b/src/slic3r/Utils/WxFontUtils.hpp index f2c5901b6b..d06d10c07f 100644 --- a/src/slic3r/Utils/WxFontUtils.hpp +++ b/src/slic3r/Utils/WxFontUtils.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include "libslic3r/Emboss.hpp" @@ -62,15 +64,10 @@ public: /// New created font fileon success otherwise nullptr static std::unique_ptr set_bold(wxFont &font, const Emboss::FontFile& font_file); - // map to convert wxFont type to string and vice versa - static const std::map from_family; - static const std::map to_family; - - static const std::map from_style; - static const std::map to_style; - - static const std::map from_weight; - static const std::map to_weight; + // convert wxFont types to string and vice versa + static const boost::bimap type_to_family; + static const boost::bimap type_to_style; + static const boost::bimap type_to_weight; }; } // namespace Slic3r::GUI diff --git a/tests/libslic3r/libslic3r_tests.cpp b/tests/libslic3r/libslic3r_tests.cpp index a97667dcca..bfd012680b 100644 --- a/tests/libslic3r/libslic3r_tests.cpp +++ b/tests/libslic3r/libslic3r_tests.cpp @@ -7,7 +7,6 @@ #include #include - namespace { TEST_CASE("sort_remove_duplicates", "[utils]") {