mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-17 02:22:17 +00:00
Orca filament profile revamp - done (#8287)
* Update Qidi profiles * restructure orca filament lib folder * update profiles * add more global filaments * check missing instantiation errors * fix missing instantiation attribute * delete voron generic filaments * remove Mellow filaments * clean profiles * QoL: select only visible filament when select all filaments
This commit is contained in:
@@ -43,14 +43,18 @@ void generate_custom_presets(PresetBundle* preset_bundle, AppConfig& app_config)
|
||||
for (auto p : custom_preset) {
|
||||
// Creating a new preset.
|
||||
auto parent = collection->find_preset(p.parent_name);
|
||||
if (type == Preset::TYPE_FILAMENT)
|
||||
auto vendor = collection->get_preset_with_vendor_profile(*parent);
|
||||
if (type == Preset::TYPE_FILAMENT) {
|
||||
parent->config.set_key_value("filament_start_gcode",
|
||||
new ConfigOptionStrings({"this_is_orca_test_filament_start_gcode_mock"}));
|
||||
else if (type == Preset::TYPE_PRINT)
|
||||
new ConfigOptionStrings({"this_is_orca_test_filament_start_gcode_mock"}));
|
||||
parent->config.set_key_value("filament_notes", new ConfigOptionString(vendor.vendor->name));
|
||||
} else if (type == Preset::TYPE_PRINT) {
|
||||
parent->config.set_key_value("filename_format", new ConfigOptionString("this_is_orca_test_filename_format_mock"));
|
||||
else if (type == Preset::TYPE_PRINTER)
|
||||
parent->config.set_key_value("machine_start_gcode",
|
||||
new ConfigOptionString("this_is_orca_test_machine_start_gcode_mock"));
|
||||
parent->config.set_key_value("notes", new ConfigOptionString(vendor.vendor->name));
|
||||
} else if (type == Preset::TYPE_PRINTER) {
|
||||
parent->config.set_key_value("machine_start_gcode", new ConfigOptionString("this_is_orca_test_machine_start_gcode_mock"));
|
||||
parent->config.set_key_value("printer_notes", new ConfigOptionString(vendor.vendor->name));
|
||||
}
|
||||
|
||||
collection->save_current_preset(p.name, false, false, parent);
|
||||
|
||||
@@ -83,7 +87,11 @@ int main(int argc, char* argv[])
|
||||
po::options_description desc("Orca Profile Validator\nUsage");
|
||||
// clang-format off
|
||||
desc.add_options()("help,h", "help")
|
||||
#ifdef __APPLE__
|
||||
("path,p", po::value<std::string>()->default_value("../../../../../../resources/profiles"), "profile folder")
|
||||
#else
|
||||
("path,p", po::value<std::string>()->default_value("../../../resources/profiles"), "profile folder")
|
||||
#endif
|
||||
("vendor,v", po::value<std::string>()->default_value(""), "Vendor name. Optional, all profiles present in the folder will be validated if not specified")
|
||||
("generate_presets,g", po::value<bool>()->default_value(false), "Generate user presets for mock test")
|
||||
("log_level,l", po::value<int>()->default_value(2), "Log level. Optional, default is 2 (warning). Higher values produce more detailed logs.");
|
||||
|
||||
@@ -1163,13 +1163,9 @@ void PresetCollection::load_presets(
|
||||
if (inherits_config) {
|
||||
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
|
||||
std::string inherits_value = option_str->value;
|
||||
inherit_preset = this->find_preset(inherits_value, false, true);
|
||||
// Orca: try to find if the parent preset has been renamed
|
||||
if (inherit_preset == nullptr) {
|
||||
auto it = this->find_preset_renamed(inherits_value);
|
||||
if (it != m_presets.end())
|
||||
inherit_preset = &(*it);
|
||||
}
|
||||
inherit_preset = this->find_preset2(inherits_value);
|
||||
|
||||
} else {
|
||||
;
|
||||
}
|
||||
@@ -2535,23 +2531,38 @@ const std::string& PresetCollection::get_suffix_modified() {
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found, bool real)
|
||||
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found, bool real, bool only_from_library)
|
||||
{
|
||||
Preset key(m_type, name, false);
|
||||
auto it = this->find_preset_internal(name);
|
||||
auto it = this->find_preset_internal(name, only_from_library);
|
||||
// Ensure that a temporary copy is returned if the preset found is currently selected.
|
||||
return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin(), real) :
|
||||
first_visible_if_not_found ? &this->first_visible() : nullptr;
|
||||
}
|
||||
|
||||
const Preset* PresetCollection::find_preset2(const std::string& name) const
|
||||
Preset* PresetCollection::find_preset2(const std::string& name, bool auto_match)
|
||||
{
|
||||
auto preset = const_cast<PresetCollection*>(this)->find_preset(name, false, true);
|
||||
auto preset = find_preset(name,false,true);
|
||||
if (preset == nullptr) {
|
||||
auto _name = get_preset_name_renamed(name);
|
||||
if(_name != nullptr)
|
||||
preset = const_cast<PresetCollection*>(this)->find_preset(*_name, false, true);
|
||||
if (_name != nullptr)
|
||||
preset = find_preset(*_name,false,true);
|
||||
if (auto_match && preset == nullptr) {
|
||||
//Orca: one more try, find the most likely preset in OrcaFilamentLibrary
|
||||
if (name.find("Generic") != std::string::npos) {
|
||||
// The regex pattern matches an optional prefix ending in '_' then "Generic" followed by the material name.
|
||||
std::regex re(R"(^(?:.*?\b(?:\w+_)?)(Generic)\b\s+([^@]+?)\s*(?:@.*)?$)");
|
||||
auto alter_name = std::regex_replace(name, re, "Generic $2 @System");
|
||||
preset = find_preset2(alter_name, false);
|
||||
// print preset file name
|
||||
if (preset != nullptr) {
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << "Failed to find: " << name
|
||||
<< ". fallback to library preset: " << preset->file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return preset;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,6 +239,9 @@ public:
|
||||
// certain printer models defined in the vendor profile as well, in this case we want to hide this generic preset for these printer models.
|
||||
std::set<std::string> m_excluded_from;
|
||||
|
||||
// Orca: flag to indicate if this preset is from Orca Filament Library
|
||||
bool m_from_orca_filament_lib = false;
|
||||
|
||||
//BBS
|
||||
Semver version; // version of preset
|
||||
std::string ini_str; // ini string of preset
|
||||
@@ -598,24 +601,26 @@ public:
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
// BBS return real pointer if set real = true
|
||||
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<PresetCollection*>(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;
|
||||
// return real pointer if set real = true
|
||||
Preset* find_preset(const std::string& name, bool first_visible_if_not_found = false, bool real = false, bool only_from_library = false);
|
||||
const Preset* find_preset(const std::string& name, bool first_visible_if_not_found = false) const
|
||||
{
|
||||
return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found);
|
||||
}
|
||||
// Orca: find preset, if not found, keep searching in the renamed history. This is function should only be used when find
|
||||
// system(parent) presets for custom preset.
|
||||
Preset* find_preset2(const std::string& name, bool auto_match = true);
|
||||
|
||||
size_t first_visible_idx() const;
|
||||
size_t first_visible_idx() const;
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
// If one of the prefered_alternates is compatible, select it.
|
||||
template<typename PreferedCondition>
|
||||
size_t first_compatible_idx(PreferedCondition prefered_condition) const
|
||||
template<typename PreferedCondition> size_t first_compatible_idx(PreferedCondition prefered_condition) const
|
||||
{
|
||||
size_t i = m_default_suppressed ? m_num_default_presets : 0;
|
||||
size_t n = this->m_presets.size();
|
||||
size_t i_compatible = n;
|
||||
size_t i = m_default_suppressed ? m_num_default_presets : 0;
|
||||
size_t n = this->m_presets.size();
|
||||
size_t i_compatible = n;
|
||||
int match_quality = -1;
|
||||
for (; i < n; ++ i)
|
||||
for (; i < n; ++i)
|
||||
// Since we use the filament selection from Wizard, it's needed to control the preset visibility too
|
||||
if (m_presets[i].is_compatible && m_presets[i].is_visible) {
|
||||
int this_match_quality = prefered_condition(m_presets[i]);
|
||||
@@ -624,16 +629,16 @@ public:
|
||||
// Better match will not be found.
|
||||
return i;
|
||||
// Store the first compatible profile with highest match quality into i_compatible.
|
||||
i_compatible = i;
|
||||
i_compatible = i;
|
||||
match_quality = this_match_quality;
|
||||
}
|
||||
}
|
||||
return (i_compatible == n) ?
|
||||
// No compatible preset found, return the default preset.
|
||||
0 :
|
||||
// Compatible preset found.
|
||||
i_compatible;
|
||||
}
|
||||
// No compatible preset found, return the default preset.
|
||||
0 :
|
||||
// Compatible preset found.
|
||||
i_compatible;
|
||||
}
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
size_t first_compatible_idx() const { return this->first_compatible_idx([](const Preset&) -> int { return 0; }); }
|
||||
|
||||
@@ -738,13 +743,13 @@ private:
|
||||
// The "-- default -- " preset is always the first, so it needs
|
||||
// to be handled differently.
|
||||
// If a preset does not exist, an iterator is returned indicating where to insert a preset with the same name.
|
||||
std::deque<Preset>::iterator find_preset_internal(const std::string &name)
|
||||
std::deque<Preset>::iterator find_preset_internal(const std::string &name, bool from_orca_lib_only = false)
|
||||
{
|
||||
auto it = Slic3r::lower_bound_by_predicate(m_presets.begin() + m_num_default_presets, m_presets.end(), [&name](const auto& l) { return l.name < name; });
|
||||
if (it == m_presets.end() || it->name != name) {
|
||||
// Preset has not been not found in the sorted list of non-default presets. Try the defaults.
|
||||
for (size_t i = 0; i < m_num_default_presets; ++ i)
|
||||
if (m_presets[i].name == name) {
|
||||
if (m_presets[i].name == name && (!from_orca_lib_only || m_presets[i].m_from_orca_filament_lib)) {
|
||||
it = m_presets.begin() + i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1209,7 +1209,7 @@ std::pair<PresetsConfigSubstitutions, std::string> PresetBundle::load_system_pre
|
||||
|
||||
for (auto &vendor_name : vendor_names)
|
||||
{
|
||||
if (validation_mode && !vendor_to_validate.empty() && vendor_name != vendor_to_validate)
|
||||
if (validation_mode && !vendor_to_validate.empty() && vendor_name != vendor_to_validate && vendor_name != ORCA_FILAMENT_LIBRARY)
|
||||
continue;
|
||||
|
||||
try {
|
||||
@@ -2852,7 +2852,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
|
||||
std::map<std::string, DynamicPrintConfig>& config_maps,
|
||||
std::map<std::string, std::string>& filament_id_maps,
|
||||
PresetCollection* presets_collection,
|
||||
size_t& count) -> std::string {
|
||||
size_t& count, bool is_from_lib = false) -> std::string {
|
||||
|
||||
std::string subfile = path + "/" + vendor_name + "/" + subfile_iter.second;
|
||||
// Load the print, filament or printer preset.
|
||||
@@ -2877,7 +2877,16 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
|
||||
}
|
||||
preset_name = key_values[BBL_JSON_KEY_NAME];
|
||||
description = key_values[BBL_JSON_KEY_DESCRIPTION];
|
||||
if(key_values.find(BBL_JSON_KEY_INSTANTIATION) == key_values.end())
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Missing instantiation attribute for " << preset_name;
|
||||
++m_errors;
|
||||
}
|
||||
instantiation = key_values[BBL_JSON_KEY_INSTANTIATION];
|
||||
if(instantiation != "false" && instantiation != "true"){
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Missing instantiation attribute for " << preset_name;
|
||||
++m_errors;
|
||||
}
|
||||
auto setting_it = key_values.find(BBL_JSON_KEY_SETTING_ID);
|
||||
if (setting_it != key_values.end())
|
||||
setting_id = setting_it->second;
|
||||
@@ -3019,6 +3028,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
|
||||
loaded.description = description;
|
||||
loaded.setting_id = setting_id;
|
||||
loaded.filament_id = filament_id;
|
||||
loaded.m_from_orca_filament_lib = is_from_lib;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << loaded.name << " load filament_id: " << filament_id;
|
||||
if (presets_collection->type() == Preset::TYPE_FILAMENT) {
|
||||
if (filament_id.empty() && "Template" != vendor_name) {
|
||||
@@ -3085,9 +3095,11 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
|
||||
presets = &this->filaments;
|
||||
configs.clear();
|
||||
filament_id_maps.clear();
|
||||
const auto is_orca_lib = vendor_name == ORCA_FILAMENT_LIBRARY;
|
||||
for (auto& subfile : filament_subfiles)
|
||||
{
|
||||
std::string reason = parse_subfile(substitution_context, substitutions, flags, subfile, configs, filament_id_maps, presets, presets_loaded);
|
||||
std::string reason = parse_subfile(substitution_context, substitutions, flags, subfile, configs, filament_id_maps, presets,
|
||||
presets_loaded, is_orca_lib);
|
||||
if (!reason.empty()) {
|
||||
++m_errors;
|
||||
//parse error
|
||||
@@ -3096,7 +3108,7 @@ std::pair<PresetsConfigSubstitutions, size_t> 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) {
|
||||
if (is_orca_lib) {
|
||||
m_config_maps = configs;
|
||||
m_filament_id_maps = filament_id_maps;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,11 @@ GuideFrame::GuideFrame(GUI_App *pGUI, long style)
|
||||
// Bind(wxEVT_IDLE, &GuideFrame::OnIdle, this);
|
||||
// Bind(wxEVT_CLOSE_WINDOW, &GuideFrame::OnClose, this);
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
LoadProfile();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": LoadProfile() took " << duration.count() << " milliseconds";
|
||||
|
||||
// UI
|
||||
SetStartPage(BBL_REGION);
|
||||
@@ -1112,13 +1116,10 @@ int GuideFrame::LoadProfile()
|
||||
m_ProfileJson["stealth_mode"] = StealthMode;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
//wxLogMessage("GUIDE: load_profile_error %s ", e.what());
|
||||
// wxMessageBox(e.what(), "", MB_OK);
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ", error: "<< e.what() <<std::endl;
|
||||
}
|
||||
|
||||
std::string strAll = m_ProfileJson.dump(-1, ' ', false, json::error_handler_t::ignore);
|
||||
//wxLogMessage("GUIDE: profile_json_s2 %s ", m_ProfileJson.dump(-1, ' ', false, json::error_handler_t::ignore));
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished, json contents: "<< std::endl<<strAll;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user