WxUtils are using imap

Remove unused map utils
This commit is contained in:
Filip Sykala 2022-03-08 09:22:56 +01:00
parent 41a506688a
commit a6834a1a82
6 changed files with 48 additions and 87 deletions

View File

@ -163,7 +163,6 @@ set(SLIC3R_SOURCES
BlacklistedLibraryCheck.hpp BlacklistedLibraryCheck.hpp
LocalesUtils.cpp LocalesUtils.cpp
LocalesUtils.hpp LocalesUtils.hpp
MapUtils.hpp
Model.cpp Model.cpp
Model.hpp Model.hpp
ModelArrange.hpp ModelArrange.hpp

View File

@ -1,30 +0,0 @@
#ifndef slic3r_MapUtils_hpp_
#define slic3r_MapUtils_hpp_
#include <map>
namespace Slic3r {
/// <summary>
/// Utility for easier work with standart map
/// </summary>
class MapUtils
{
public:
MapUtils() = delete; // only static functions
/// <summary>
/// Create map with swaped key-value
/// </summary>
/// <param name="map">Input map</param>
/// <returns>Map with changed key to value and vice versa</returns>
template<typename Key, typename Value>
static std::map<Value, Key> create_oposit(const std::map<Key, Value> &map)
{
std::map<Value, Key> result;
for (const auto &it : map) result[it.second] = it.first;
return result;
}
};
} // namespace Slic3r
#endif // slic3r_MapUtils_hpp_

View File

@ -23,7 +23,6 @@
#include "libslic3r/Model.hpp" #include "libslic3r/Model.hpp"
#include "libslic3r/ClipperUtils.hpp" // union_ex #include "libslic3r/ClipperUtils.hpp" // union_ex
#include "libslic3r/AppConfig.hpp" // store/load font list #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/Format/OBJ.hpp" // load obj file for default object
#include "libslic3r/BuildVolume.hpp" #include "libslic3r/BuildVolume.hpp"

View File

@ -1,6 +1,5 @@
#include "WxFontUtils.hpp" #include "WxFontUtils.hpp"
#include "libslic3r/MapUtils.hpp" #include <boost/assign.hpp>
#include <string_view>
#if defined(__APPLE__) #if defined(__APPLE__)
#include <CoreText/CTFont.h> #include <CoreText/CTFont.h>
@ -164,39 +163,37 @@ std::optional<wxFont> WxFontUtils::load_wxFont(
return wx_font; return wx_font;
} }
const std::map<wxFontFamily, std::string> WxFontUtils::from_family( using TypeToFamily = boost::bimap<wxFontFamily, std::string_view>;
{{wxFONTFAMILY_DEFAULT, "default"}, const TypeToFamily WxFontUtils::type_to_family =
{wxFONTFAMILY_DECORATIVE, "decorative"}, boost::assign::list_of<TypeToFamily::relation>
{wxFONTFAMILY_ROMAN, "roman"}, (wxFONTFAMILY_DEFAULT, "default")
{wxFONTFAMILY_SCRIPT, "script"}, (wxFONTFAMILY_DECORATIVE, "decorative")
{wxFONTFAMILY_SWISS, "swiss"}, (wxFONTFAMILY_ROMAN, "roman")
{wxFONTFAMILY_MODERN, "modern"}, (wxFONTFAMILY_SCRIPT, "script")
{wxFONTFAMILY_TELETYPE, "teletype"}, (wxFONTFAMILY_SWISS, "swiss")
{wxFONTFAMILY_MAX, "max"}, (wxFONTFAMILY_MODERN, "modern")
{wxFONTFAMILY_UNKNOWN, "unknown"}}); (wxFONTFAMILY_TELETYPE, "teletype");
const std::map<std::string, wxFontFamily> WxFontUtils::to_family =
MapUtils::create_oposit(WxFontUtils::from_family);
const std::map<wxFontStyle, std::string> WxFontUtils::from_style( using TypeToStyle = boost::bimap<wxFontStyle, std::string_view>;
{{wxFONTSTYLE_ITALIC, "italic"}, const TypeToStyle WxFontUtils::type_to_style =
{wxFONTSTYLE_SLANT, "slant"}, boost::assign::list_of<TypeToStyle::relation>
{wxFONTSTYLE_NORMAL, "normal"}}); (wxFONTSTYLE_ITALIC, "italic")
const std::map<std::string, wxFontStyle> WxFontUtils::to_style = (wxFONTSTYLE_SLANT, "slant")
MapUtils::create_oposit(WxFontUtils::from_style); (wxFONTSTYLE_NORMAL, "normal");
const std::map<wxFontWeight, std::string> WxFontUtils::from_weight( using TypeToWeight = boost::bimap<wxFontWeight, std::string_view>;
{{wxFONTWEIGHT_THIN, "thin"}, const TypeToWeight WxFontUtils::type_to_weight =
{wxFONTWEIGHT_EXTRALIGHT, "extraLight"}, boost::assign::list_of<TypeToWeight::relation>
{wxFONTWEIGHT_LIGHT, "light"}, (wxFONTWEIGHT_THIN, "thin")
{wxFONTWEIGHT_NORMAL, "normal"}, (wxFONTWEIGHT_EXTRALIGHT, "extraLight")
{wxFONTWEIGHT_MEDIUM, "medium"}, (wxFONTWEIGHT_LIGHT, "light")
{wxFONTWEIGHT_SEMIBOLD, "semibold"}, (wxFONTWEIGHT_NORMAL, "normal")
{wxFONTWEIGHT_BOLD, "bold"}, (wxFONTWEIGHT_MEDIUM, "medium")
{wxFONTWEIGHT_EXTRABOLD, "extraBold"}, (wxFONTWEIGHT_SEMIBOLD, "semibold")
{wxFONTWEIGHT_HEAVY, "heavy"}, (wxFONTWEIGHT_BOLD, "bold")
{wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy"}}); (wxFONTWEIGHT_EXTRABOLD, "extraBold")
const std::map<std::string, wxFontWeight> WxFontUtils::to_weight = (wxFONTWEIGHT_HEAVY, "heavy")
MapUtils::create_oposit(WxFontUtils::from_weight); (wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy");
std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi, std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi,
const FontProp &fp) const FontProp &fp)
@ -204,20 +201,20 @@ std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi,
double point_size = static_cast<double>(fp.size_in_mm); double point_size = static_cast<double>(fp.size_in_mm);
wxFontInfo info(point_size); wxFontInfo info(point_size);
if (fp.family.has_value()) { if (fp.family.has_value()) {
auto it = to_family.find(*fp.style); auto it = type_to_family.right.find(*fp.style);
if (it != to_family.end()) info.Family(it->second); if (it != type_to_family.right.end()) info.Family(it->second);
} }
if (fp.face_name.has_value()) { if (fp.face_name.has_value()) {
wxString face_name(*fp.face_name); wxString face_name(*fp.face_name);
info.FaceName(face_name); info.FaceName(face_name);
} }
if (fp.style.has_value()) { if (fp.style.has_value()) {
auto it = to_style.find(*fp.style); auto it = type_to_style.right.find(*fp.style);
if (it != to_style.end()) info.Style(it->second); if (it != type_to_style.right.end()) info.Style(it->second);
} }
if (fp.weight.has_value()) { if (fp.weight.has_value()) {
auto it = to_weight.find(*fp.weight); auto it = type_to_weight.right.find(*fp.weight);
if (it != to_weight.end()) info.Weight(it->second); if (it != type_to_weight.right.end()) info.Weight(it->second);
} }
// Improve: load descriptor instead of store to font property to 3mf // 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(); wxFontFamily wx_family = font.GetFamily();
if (wx_family != wxFONTFAMILY_DEFAULT) { if (wx_family != wxFONTFAMILY_DEFAULT) {
auto it = from_family.find(wx_family); auto it = type_to_family.left.find(wx_family);
if (it != from_family.end()) font_prop.family = it->second; if (it != type_to_family.left.end()) font_prop.family = it->second;
} }
wxFontStyle wx_style = font.GetStyle(); wxFontStyle wx_style = font.GetStyle();
if (wx_style != wxFONTSTYLE_NORMAL) { if (wx_style != wxFONTSTYLE_NORMAL) {
auto it = from_style.find(wx_style); auto it = type_to_style.left.find(wx_style);
if (it != from_style.end()) font_prop.style = it->second; if (it != type_to_style.left.end()) font_prop.style = it->second;
} }
wxFontWeight wx_weight = font.GetWeight(); wxFontWeight wx_weight = font.GetWeight();
if (wx_weight != wxFONTWEIGHT_NORMAL) { if (wx_weight != wxFONTWEIGHT_NORMAL) {
auto it = from_weight.find(wx_weight); auto it = type_to_weight.left.find(wx_weight);
if (it != from_weight.end()) font_prop.weight = it->second; if (it != type_to_weight.left.end()) font_prop.weight = it->second;
} }
} }

View File

@ -3,6 +3,8 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string_view>
#include <boost/bimap.hpp>
#include <wx/font.h> #include <wx/font.h>
#include "libslic3r/Emboss.hpp" #include "libslic3r/Emboss.hpp"
@ -62,15 +64,10 @@ public:
/// <returns>New created font fileon success otherwise nullptr</returns> /// <returns>New created font fileon success otherwise nullptr</returns>
static std::unique_ptr<Emboss::FontFile> set_bold(wxFont &font, const Emboss::FontFile& font_file); static std::unique_ptr<Emboss::FontFile> set_bold(wxFont &font, const Emboss::FontFile& font_file);
// map to convert wxFont type to string and vice versa // convert wxFont types to string and vice versa
static const std::map<wxFontFamily, std::string> from_family; static const boost::bimap<wxFontFamily, std::string_view> type_to_family;
static const std::map<std::string, wxFontFamily> to_family; static const boost::bimap<wxFontStyle, std::string_view> type_to_style;
static const boost::bimap<wxFontWeight, std::string_view> type_to_weight;
static const std::map<wxFontStyle, std::string> from_style;
static const std::map<std::string, wxFontStyle> to_style;
static const std::map<wxFontWeight, std::string> from_weight;
static const std::map<std::string, wxFontWeight> to_weight;
}; };
} // namespace Slic3r::GUI } // namespace Slic3r::GUI

View File

@ -7,7 +7,6 @@
#include <boost/bimap.hpp> #include <boost/bimap.hpp>
#include <boost/assign.hpp> #include <boost/assign.hpp>
namespace { namespace {
TEST_CASE("sort_remove_duplicates", "[utils]") { TEST_CASE("sort_remove_duplicates", "[utils]") {