diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 102f02d0f..a4394f624 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2523,6 +2523,17 @@ Preset* PresetCollection::find_preset(const std::string &name, bool first_visibl first_visible_if_not_found ? &this->first_visible() : nullptr; } +const Preset* PresetCollection::find_preset2(const std::string& name) const +{ + auto preset = const_cast(this)->find_preset(name, false, true); + if (preset == nullptr) { + auto _name = get_preset_name_renamed(name); + if(_name != nullptr) + preset = const_cast(this)->find_preset(*_name, false, true); + } + return preset; +} + // Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible. size_t PresetCollection::first_visible_idx() const { diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index cf8807174..359abf6d6 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -596,6 +596,8 @@ public: Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false, bool real = false); const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false) const { return const_cast(this)->find_preset(name, first_visible_if_not_found); } + // Orca: find preset, if not found, keep searching in the renamed history + const Preset* find_preset2(const std::string &name) const; size_t first_visible_idx() const; // Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible. diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index bb5a39271..f8103ff4f 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1,6 +1,7 @@ #include #include "PresetBundle.hpp" +#include "PrintConfig.hpp" #include "libslic3r.h" #include "Utils.hpp" #include "Model.hpp" @@ -1281,7 +1282,7 @@ std::pair PresetBundle::load_system_pre // Load the other vendor configs, merge them with this PresetBundle. // Report duplicate profiles. PresetBundle other; - append(substitutions, other.load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem, compatibility_rule).first); + append(substitutions, other.load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem, compatibility_rule, this).first); std::vector duplicates = this->merge_presets(std::move(other)); if (! duplicates.empty()) { errors_cummulative += "Found duplicated settings in vendor " + vendor_name + "'s json file lists: "; @@ -3300,7 +3301,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool //BBS: Load a config bundle file from json std::pair PresetBundle::load_vendor_configs_from_json( - const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule) + const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle* base_bundle) { // Enable substitutions for user config bundle, throw an exception when loading a system profile. ConfigSubstitutionContext substitution_context { compatibility_rule }; @@ -3509,7 +3510,7 @@ std::pair PresetBundle::load_vendor_configs_ PresetCollection *presets = nullptr; size_t presets_loaded = 0; - auto parse_subfile = [this, path, vendor_name, presets_loaded, current_vendor_profile]( + auto parse_subfile = [this, path, vendor_name, presets_loaded, current_vendor_profile, base_bundle]( ConfigSubstitutionContext& substitution_context, PresetsConfigSubstitutions& substitutions, LoadConfigBundleAttributes& flags, @@ -3554,19 +3555,32 @@ std::pair PresetBundle::load_vendor_configs_ if (it1 != key_values.end()) { inherits = it1->second; auto it2 = config_maps.find(inherits); - if (it2 != config_maps.end()) { + default_config = nullptr; + if (it2 != config_maps.end()) default_config = &(it2->second); + if(default_config == nullptr && base_bundle != nullptr) { + auto base_it2 = base_bundle->m_config_maps.find(inherits); + if (base_it2 != base_bundle->m_config_maps.end()) + default_config = &(base_it2->second); + } + if (default_config != nullptr) { if (filament_id.empty() && (presets_collection->type() == Preset::TYPE_FILAMENT)) { auto filament_id_map_iter = filament_id_maps.find(inherits); if (filament_id_map_iter != filament_id_maps.end()) { filament_id = filament_id_map_iter->second; } + if (filament_id.empty() && base_bundle != nullptr) { + auto filament_id_map_iter = base_bundle->m_filament_id_maps.find(inherits); + if (filament_id_map_iter != base_bundle->m_filament_id_maps.end()) { + filament_id = filament_id_map_iter->second; + } + } } } else { ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find inherits "< PresetBundle::load_vendor_configs_ throw ConfigurationError((boost::format("Failed loading configuration file %1%\nSuggest cleaning the directory %2% firstly") % subfile_path % path).str()); } } + if (vendor_name == ORCA_FILAMENT_LIBRARY) { + m_config_maps = configs; + m_filament_id_maps = filament_id_maps; + } //3.3) paste the printers presets = &this->printers; diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 50592876e..58b594116 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -160,7 +160,12 @@ public: // and the system profiles will point to the VendorProfile instances owned by PresetBundle::vendors. VendorMap vendors; - struct ObsoletePresets { + // Orca: for OrcaFilamentLibrary + std::map m_config_maps; + std::map m_filament_id_maps; + + struct ObsoletePresets + { std::vector prints; std::vector sla_prints; std::vector filaments; @@ -212,9 +217,9 @@ public: // Don't do any config substitutions when loading a system profile, perform and report substitutions otherwise. /*std::pair load_configbundle( const std::string &path, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule);*/ - //BBS: add json related logic + //Orca: load config bundle from json, pass the base bundle to support cross vendor inheritance std::pair load_vendor_configs_from_json( - const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule); + const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle* base_bundle = nullptr); // Export a config bundle file containing all the presets and the names of the active presets. //void export_configbundle(const std::string &path, bool export_system_settings = false, bool export_physical_printers = false); diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 48315505b..db0451c47 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -1,9 +1,13 @@ #include "WebGuideDialog.hpp" #include "ConfigWizard.hpp" +#include +#include +#include #include #include "I18N.hpp" #include "libslic3r/AppConfig.hpp" +#include "libslic3r/PresetBundle.hpp" #include "slic3r/GUI/wxExtensions.hpp" #include "slic3r/GUI/GUI_App.hpp" #include "libslic3r_version.h" @@ -1066,31 +1070,7 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, int GuideFrame::LoadProfile() { try { - //wxString ExePath = boost::dll::program_location().parent_path().string(); - //wxString TargetFolder = ExePath + "\\resources\\profiles\\"; - //wxString TargetFolderSearch = ExePath + "\\resources\\profiles\\*.json"; - - //intptr_t handle; - //_finddata_t findData; - - //handle = _findfirst(TargetFolderSearch.mb_str(), &findData); // ??????????? - //if (handle == -1) { return -1; } - - //do { - // if (findData.attrib & _A_SUBDIR && strcmp(findData.name, ".") == 0 && strcmp(findData.name, "..") == 0) // ??????????"."?".." - // { - // // cout << findData.name << "\t\n"; - // } else { - // wxString strVendor = wxString(findData.name).BeforeLast('.'); - // LoadProfileFamily(strVendor, TargetFolder + findData.name); - // } - - //} while (_findnext(handle, &findData) == 0); // ??????????? - - // BBS: change directories by design - //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", will load config from %1%.") % bbl_bundle_path; m_ProfileJson = json::parse("{}"); - //m_ProfileJson["configpath"] = Slic3r::data_dir(); m_ProfileJson["model"] = json::array(); m_ProfileJson["machine"] = json::object(); m_ProfileJson["filament"] = json::object(); @@ -1101,74 +1081,58 @@ int GuideFrame::LoadProfile() // Orca: add custom as default // Orca: add json logic for vendor bundle - auto orca_custom_bundle_path = vendor_dir; - orca_bundle_rsrc = false; - if (!boost::filesystem::exists((vendor_dir / PresetBundle::ORCA_DEFAULT_BUNDLE).replace_extension(".json"))) { - orca_custom_bundle_path = rsrc_vendor_dir; - orca_bundle_rsrc = true; + orca_bundle_rsrc = true; + + // search if there exists a .json file in vendor_dir folder, if exists, set orca_bundle_rsrc to false + for (const auto& entry : boost::filesystem::directory_iterator(vendor_dir)) { + if (!boost::filesystem::is_directory(entry) && boost::iequals(entry.path().extension().string(), ".json") && !boost::iequals(entry.path().stem().string(), PresetBundle::ORCA_FILAMENT_LIBRARY)) { + orca_bundle_rsrc = false; + break; + } } - // intptr_t handle; - //_finddata_t findData; - - //handle = _findfirst((bbl_bundle_path / "*.json").make_preferred().string().c_str(), &findData); // ??????????? - // if (handle == -1) { return -1; } - - // do { - // if (findData.attrib & _A_SUBDIR && strcmp(findData.name, ".") == 0 && strcmp(findData.name, "..") == 0) // ??????????"."?".." - // { - // // cout << findData.name << "\t\n"; - // } else { - // wxString strVendor = wxString(findData.name).BeforeLast('.'); - // LoadProfileFamily(w2s(strVendor), vendor_dir.make_preferred().string() + "\\"+ findData.name); - // } - - //} while (_findnext(handle, &findData) == 0); // ??????????? - + // load the default filament library first + std::set loaded_vendors; + auto filament_library_name = boost::filesystem::path(PresetBundle::ORCA_FILAMENT_LIBRARY).replace_extension(".json"); + if (boost::filesystem::exists(vendor_dir / filament_library_name)) { + LoadProfileFamily(PresetBundle::ORCA_FILAMENT_LIBRARY, (vendor_dir / filament_library_name).string()); + } else { + LoadProfileFamily(PresetBundle::ORCA_FILAMENT_LIBRARY, (rsrc_vendor_dir / filament_library_name).string()); + } + loaded_vendors.insert(PresetBundle::ORCA_FILAMENT_LIBRARY); //load custom bundle from user data path - string targetPath = orca_custom_bundle_path.make_preferred().string(); - boost::filesystem::path myPath(targetPath); boost::filesystem::directory_iterator endIter; - for (boost::filesystem::directory_iterator iter(myPath); iter != endIter; iter++) { - if (boost::filesystem::is_directory(*iter)) { - //cout << "is dir" << endl; - //cout << iter->path().string() << endl; - } else { - //cout << "is a file" << endl; - //cout << iter->path().string() << endl; - + for (boost::filesystem::directory_iterator iter(vendor_dir); iter != endIter; iter++) { + if (!boost::filesystem::is_directory(*iter)) { wxString strVendor = from_u8(iter->path().string()).BeforeLast('.'); strVendor = strVendor.AfterLast('\\'); strVendor = strVendor.AfterLast('/'); - wxString strExtension = from_u8(iter->path().string()).AfterLast('.').Lower(); - if ((w2s(strVendor) == PresetBundle::ORCA_DEFAULT_BUNDLE || w2s(strVendor) == PresetBundle::ORCA_FILAMENT_LIBRARY) && strExtension.CmpNoCase("json") == 0) - LoadProfileFamily(w2s(strVendor), iter->path().string()); + wxString strExtension = from_u8(iter->path().string()).AfterLast('.').Lower(); + if(strExtension.CmpNoCase("json") != 0 || loaded_vendors.find(w2s(strVendor)) != loaded_vendors.end()) + continue; + + LoadProfileFamily(w2s(strVendor), iter->path().string()); + loaded_vendors.insert(w2s(strVendor)); } } - //string others_targetPath = rsrc_vendor_dir.string(); boost::filesystem::directory_iterator others_endIter; for (boost::filesystem::directory_iterator iter(rsrc_vendor_dir); iter != others_endIter; iter++) { - if (boost::filesystem::is_directory(*iter)) { - //cout << "is dir" << endl; - //cout << iter->path().string() << endl; - } else { - //cout << "is a file" << endl; - //cout << iter->path().string() << endl; + if (!boost::filesystem::is_directory(*iter)) { wxString strVendor = from_u8(iter->path().string()).BeforeLast('.'); strVendor = strVendor.AfterLast('\\'); strVendor = strVendor.AfterLast('/'); wxString strExtension = from_u8(iter->path().string()).AfterLast('.').Lower(); + if (strExtension.CmpNoCase("json") != 0 || loaded_vendors.find(w2s(strVendor)) != loaded_vendors.end()) + continue; - if (w2s(strVendor) != PresetBundle::ORCA_DEFAULT_BUNDLE && w2s(strVendor) != PresetBundle::ORCA_FILAMENT_LIBRARY && strExtension.CmpNoCase("json")==0) - LoadProfileFamily(w2s(strVendor), iter->path().string()); + LoadProfileFamily(w2s(strVendor), iter->path().string()); } } - //LoadProfileFamily(PresetBundle::ORCA_DEFAULT_BUNDLE, bbl_bundle_path.string()); const auto enabled_filaments = wxGetApp().app_config->has_section(AppConfig::SECTION_FILAMENTS) ? wxGetApp().app_config->get_section(AppConfig::SECTION_FILAMENTS) : std::map(); m_appconfig_new.set_vendors(*wxGetApp().app_config); @@ -1531,7 +1495,7 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath // BBS:Filament json pFilament = jLocal["filament_list"]; - json tFilaList = json::object(); + json tFilaList = m_OrcaFilaList; nsize = pFilament.size(); for (int n = 0; n < nsize; n++) { @@ -1604,6 +1568,8 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath } } + if(strVendor == PresetBundle::ORCA_FILAMENT_LIBRARY) + m_OrcaFilaList = tFilaList; // process json pProcess = jLocal["process_list"]; diff --git a/src/slic3r/GUI/WebGuideDialog.hpp b/src/slic3r/GUI/WebGuideDialog.hpp index 98ce915f5..03f2e752b 100644 --- a/src/slic3r/GUI/WebGuideDialog.hpp +++ b/src/slic3r/GUI/WebGuideDialog.hpp @@ -115,6 +115,8 @@ private: bool InstallNetplugin; bool network_plugin_ready {false}; + json m_OrcaFilaList; + #if wxUSE_WEBVIEW_IE wxMenuItem *m_script_object_el; wxMenuItem *m_script_date_el;