diff --git a/src/slic3r/GUI/AmsMappingPopup.cpp b/src/slic3r/GUI/AmsMappingPopup.cpp index c0a2c918c6..9663c1df4c 100644 --- a/src/slic3r/GUI/AmsMappingPopup.cpp +++ b/src/slic3r/GUI/AmsMappingPopup.cpp @@ -1257,12 +1257,10 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& Refresh(); } -std::vector AmsMapingPopup::parse_ams_mapping(std::map amsList) +std::vector AmsMapingPopup::parse_ams_mapping(const std::map& amsList) { std::vector m_tray_data; - std::map::iterator ams_iter; - - for (ams_iter = amsList.begin(); ams_iter != amsList.end(); ams_iter++) { + for (auto ams_iter = amsList.begin(); ams_iter != amsList.end(); ams_iter++) { BOOST_LOG_TRIVIAL(trace) << "ams_mapping ams id " << ams_iter->first.c_str(); diff --git a/src/slic3r/GUI/AmsMappingPopup.hpp b/src/slic3r/GUI/AmsMappingPopup.hpp index 92e72218d9..bbfb967822 100644 --- a/src/slic3r/GUI/AmsMappingPopup.hpp +++ b/src/slic3r/GUI/AmsMappingPopup.hpp @@ -39,6 +39,8 @@ #include #include +#include "slic3r/GUI/DeviceCore/DevUtil.h" + #define MAPPING_ITEM_INVALID_REMAIN -1 namespace Slic3r { namespace GUI { @@ -277,7 +279,7 @@ public: void paintEvent(wxPaintEvent &evt); void set_parent_item(MaterialItem* item) {m_parent_item = item;}; void set_show_type(ShowType type) { m_show_type = type; }; - std::vector parse_ams_mapping(std::map amsList); + std::vector parse_ams_mapping(const std::map& amsList); using ResetCallback = std::function; void reset_ams_info(); diff --git a/src/slic3r/GUI/DeviceCore/DevFilaSystem.h b/src/slic3r/GUI/DeviceCore/DevFilaSystem.h index b1929bc05c..910eaf1558 100644 --- a/src/slic3r/GUI/DeviceCore/DevFilaSystem.h +++ b/src/slic3r/GUI/DeviceCore/DevFilaSystem.h @@ -4,6 +4,7 @@ #include "DevDefs.h" #include "DevFilaAmsSetting.h" +#include "DevUtil.h" #include #include @@ -158,7 +159,7 @@ public: /* ams */ DevAms* GetAmsById(const std::string& ams_id) const; - std::map& GetAmsList() { return amsList; } + std::map& GetAmsList() { return amsList; } int GetAmsCount() const { return amsList.size(); } /* tray*/ @@ -190,7 +191,7 @@ private: /* ams properties */ int m_ams_cali_stat = 0; - std::map amsList; // key: ams[id], start with 0 + std::map amsList;// key: ams[id], start with 0 DevAmsSystemSetting m_ams_system_setting{ this }; std::shared_ptr m_ams_firmware_switch = DevAmsSystemFirmwareSwitch::Create(this); diff --git a/src/slic3r/GUI/DeviceCore/DevUtil.h b/src/slic3r/GUI/DeviceCore/DevUtil.h index 252e69558d..4ba309b18c 100644 --- a/src/slic3r/GUI/DeviceCore/DevUtil.h +++ b/src/slic3r/GUI/DeviceCore/DevUtil.h @@ -85,4 +85,23 @@ public: static std::string get_longlong_val(const nlohmann::json& j); }; + +struct NumericStrCompare +{ + bool operator()(const std::string& a, const std::string& b) const noexcept + { + int ai = -1; + try { + ai = std::stoi(a); + } catch (...) { }; + + int bi = -1; + try { + bi = std::stoi(b); + } catch (...) { }; + + return ai < bi; + } +}; + }; // namespace Slic3r \ No newline at end of file