From 107ff6fd3618e8a468aacb90903f4cc09ca65f49 Mon Sep 17 00:00:00 2001 From: Vojtech Kral <vojtech@kral.hk> Date: Tue, 17 Sep 2019 16:59:52 +0200 Subject: [PATCH] Materials: Cleanup --- src/slic3r/GUI/ConfigWizard.cpp | 20 +++--------- src/slic3r/GUI/ConfigWizard_private.hpp | 3 +- src/slic3r/GUI/PresetBundle.cpp | 42 ------------------------- src/slic3r/GUI/PresetBundle.hpp | 3 -- 4 files changed, 6 insertions(+), 62 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index d77812e3a..cbbaa32b6 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -26,7 +26,6 @@ #include <wx/debug.h> #include "libslic3r/Utils.hpp" -// #include "PresetBundle.hpp" #include "GUI.hpp" #include "GUI_Utils.hpp" #include "slic3r/Config/Snapshot.hpp" @@ -44,22 +43,19 @@ using Config::SnapshotDB; // Configuration data structures extensions needed for the wizard Bundle::Bundle(fs::path source_path, bool is_in_resources, bool is_prusa_bundle) - : source_path(std::move(source_path)) - , preset_bundle(new PresetBundle) + : preset_bundle(new PresetBundle) , vendor_profile(nullptr) , is_in_resources(is_in_resources) , is_prusa_bundle(is_prusa_bundle) { - // XXX: consider removing path <-> string juggling - preset_bundle->load_configbundle(this->source_path.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM); + preset_bundle->load_configbundle(source_path.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM); auto first_vendor = preset_bundle->vendors.begin(); wxCHECK_RET(first_vendor != preset_bundle->vendors.end(), "Failed to load preset bundle"); vendor_profile = &first_vendor->second; } Bundle::Bundle(Bundle &&other) - : source_path(std::move(source_path)) - , preset_bundle(std::move(other.preset_bundle)) + : preset_bundle(std::move(other.preset_bundle)) , vendor_profile(other.vendor_profile) , is_in_resources(other.is_in_resources) , is_prusa_bundle(other.is_prusa_bundle) @@ -71,15 +67,9 @@ BundleMap BundleMap::load() { BundleMap res; - // XXX: Keep Prusa bundle separate? (Probably no - keep same codepaths) - const auto vendor_dir = (boost::filesystem::path(Slic3r::data_dir()) / "vendor").make_preferred(); const auto rsrc_vendor_dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); - // XXX - // const auto prusa_bundle_vendor = (vendor_dir / PRUSA_BUNDLE).replace_extension(".ini"); - // const auto prusa_bundle = boost::filesystem::exists(prusa_bundle_vendor) ? prusa_bundle_vendor - // : (rsrc_vendor_dir / PRUSA_BUNDLE).replace_extension(".ini"); auto prusa_bundle_path = (vendor_dir / PresetBundle::PRUSA_BUNDLE).replace_extension(".ini"); auto prusa_bundle_rsrc = false; if (! boost::filesystem::exists(prusa_bundle_path)) { @@ -663,7 +653,7 @@ void PageMaterials::select_all(bool select) wxWindowUpdateLocker freeze_guard(this); (void)freeze_guard; - for (int i = 0; i < list_l3->GetCount(); i++) { + for (unsigned i = 0; i < list_l3->GetCount(); i++) { const bool current = list_l3->IsChecked(i); if (current != select) { list_l3->Check(i, select); @@ -1646,7 +1636,7 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese // } // } - preset_bundle->load_presets(*app_config, preferred_model); + // preset_bundle->load_presets(*app_config, preferred_model); if (page_custom->custom_wanted()) { page_firmware->apply_custom_config(*custom_config); diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index 6c94d3700..3f688adff 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -90,7 +90,6 @@ struct Materials struct Bundle { - fs::path source_path; // XXX: not needed? std::unique_ptr<PresetBundle> preset_bundle; VendorProfile *vendor_profile; const bool is_in_resources; @@ -235,7 +234,7 @@ template<class T, class D> struct DataList : public T } int find(const D &data) { - for (int i = 0; i < this->GetCount(); i++) { + for (unsigned i = 0; i < this->GetCount(); i++) { if (get_data(i) == data) { return i; } } diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index e3ee84e87..54dd92a71 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -243,48 +243,6 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_ this->load_selections(config, preferred_model_id); } -// FIXME: Comment -// XXX: rm -void PresetBundle::load_available_system_presets() -{ - const auto vendor_dir = (boost::filesystem::path(Slic3r::data_dir()) / "vendor").make_preferred(); - const auto rsrc_vendor_dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); - - const auto prusa_bundle_vendor = (vendor_dir / PRUSA_BUNDLE).replace_extension(".ini"); - const auto prusa_bundle = boost::filesystem::exists(prusa_bundle_vendor) ? prusa_bundle_vendor - : (rsrc_vendor_dir / PRUSA_BUNDLE).replace_extension(".ini"); - - // Reset this PresetBundle and load the Prusa bundle first. - this->load_configbundle(prusa_bundle.string(), LOAD_CFGBNDLE_SYSTEM); - - // Load the other bundles in the datadir/vendor directory - // and then additionally from resources/profiles. - for (auto dir : { &vendor_dir, &rsrc_vendor_dir }) { - for (const auto &dir_entry : boost::filesystem::directory_iterator(*dir)) { - if (Slic3r::is_ini_file(dir_entry)) { - std::string id = dir_entry.path().stem().string(); // stem() = filename() without the trailing ".ini" part - - // Don't load this bundle if we've already loaded it. - // Note that this takes care of not loading the PRUSA_BUNDLE which was loaded upfront - // as well as bundles with the same name (id) in rsrc_vendor_dir as in vendor_dir. - if (vendors.find(id) != vendors.end()) { continue; } - - PresetBundle other; - other.load_configbundle(dir_entry.path().string(), LOAD_CFGBNDLE_SYSTEM); - - std::vector<std::string> duplicates = this->merge_presets(std::move(other)); - if (! duplicates.empty()) { - std::string msg = "Vendor configuration file " + id + " contains the following presets with names used by other vendors: "; - for (size_t i = 0; i < duplicates.size(); ++ i) { - if (i > 0) { msg += ", "; } - msg += duplicates[i]; - } - } - } - } - } -} - // Load system presets into this PresetBundle. // For each vendor, there will be a single PresetBundle loaded. std::string PresetBundle::load_system_presets() diff --git a/src/slic3r/GUI/PresetBundle.hpp b/src/slic3r/GUI/PresetBundle.hpp index 79519071b..b1010e07b 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/slic3r/GUI/PresetBundle.hpp @@ -134,9 +134,6 @@ public: void load_default_preset_bitmaps(wxWindow *window); - // FIXME: rm - void load_available_system_presets(); // XXX: name XXX: retval (VendorMap stored internally) - // Set the is_visible flag for printer vendors, printer models and printer variants // based on the user configuration. // If the "vendor" section is missing, enable all models and variants of the particular vendor.