mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 11:23:42 +00:00
FIX: Update the alias of imported presets
Jira: STUDIO-12801 Change-Id: I7583a2022a0f565103953ee0ca742593769da81f (cherry picked from commit cb470ae21279a555c7f4718673d83e3818b46bf0)
This commit is contained in:
@@ -2564,6 +2564,7 @@ bool PresetCollection::delete_preset(const std::string& name)
|
|||||||
}
|
}
|
||||||
//BBS: add lock logic for sync preset in background
|
//BBS: add lock logic for sync preset in background
|
||||||
lock();
|
lock();
|
||||||
|
set_printer_hold_alias(it->alias, *it, true);
|
||||||
m_presets.erase(it);
|
m_presets.erase(it);
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
@@ -3217,22 +3218,43 @@ void PresetCollection::set_custom_preset_alias(Preset &preset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetCollection::set_printer_hold_alias(const std::string &alias, Preset &preset)
|
void PresetCollection::set_printer_hold_alias(const std::string &alias, Preset &preset, bool remove)
|
||||||
{
|
{
|
||||||
auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
|
auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
|
||||||
if (compatible_printers == nullptr) return;
|
if (compatible_printers == nullptr) return;
|
||||||
for (const std::string &printer_name : compatible_printers->values) {
|
for (const std::string &printer_name : compatible_printers->values) {
|
||||||
auto printer_iter = m_printer_hold_alias.find(printer_name);
|
auto printer_iter = m_printer_hold_alias.find(printer_name);
|
||||||
|
bool insert_success = false, remove_success = false;
|
||||||
if (m_printer_hold_alias.end() == printer_iter) {
|
if (m_printer_hold_alias.end() == printer_iter) {
|
||||||
m_printer_hold_alias[printer_name].insert(alias);
|
if (!remove) {
|
||||||
} else {
|
insert_success = true;
|
||||||
auto alias_iter = m_printer_hold_alias[printer_name].find(alias);
|
|
||||||
if (m_printer_hold_alias[printer_name].end() == alias_iter) {
|
|
||||||
m_printer_hold_alias[printer_name].insert(alias);
|
m_printer_hold_alias[printer_name].insert(alias);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto &printer_filament_alias = m_printer_hold_alias[printer_name];
|
||||||
|
auto alias_iter = printer_filament_alias.find(alias);
|
||||||
|
if (printer_filament_alias.end() == alias_iter) {
|
||||||
|
if (!remove) {
|
||||||
|
insert_success = true;
|
||||||
|
printer_filament_alias.insert(alias);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << printer_name << "already has alias: " << alias << " and the preset name: " << preset.name;
|
if (remove) {
|
||||||
|
if (preset.inherits() == "") {
|
||||||
|
remove_success = true;
|
||||||
|
printer_filament_alias.erase(alias);
|
||||||
|
}
|
||||||
|
if (auto alias_iter = m_map_alias_to_profile_name.find(alias); alias_iter != m_map_alias_to_profile_name.end()) {
|
||||||
|
auto& presets = alias_iter->second;
|
||||||
|
auto new_end = std::remove(presets.begin(), presets.end(), preset.name);
|
||||||
|
presets.erase(new_end, presets.end());
|
||||||
|
if (presets.empty()) { m_map_alias_to_profile_name.erase(alias); }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << " preset name : " << preset.name << " remove action: " << remove << " insert success: "
|
||||||
|
<< insert_success << " remove success: " << remove_success << " alias: " << alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -592,7 +592,7 @@ public:
|
|||||||
const std::string& get_preset_name_by_alias(const std::string& alias) const;
|
const std::string& get_preset_name_by_alias(const std::string& alias) const;
|
||||||
const std::string* get_preset_name_renamed(const std::string &old_name) const;
|
const std::string* get_preset_name_renamed(const std::string &old_name) const;
|
||||||
bool is_alias_exist(const std::string &alias, Preset* preset = nullptr);
|
bool is_alias_exist(const std::string &alias, Preset* preset = nullptr);
|
||||||
void set_printer_hold_alias(const std::string &alias, Preset &preset);
|
void set_printer_hold_alias(const std::string &alias, Preset &preset, bool remove = false);
|
||||||
|
|
||||||
// used to update preset_choice from Tab
|
// used to update preset_choice from Tab
|
||||||
const std::deque<Preset>& get_presets() const { return m_presets; }
|
const std::deque<Preset>& get_presets() const { return m_presets; }
|
||||||
|
|||||||
@@ -948,7 +948,7 @@ bool PresetBundle::import_json_presets(PresetsConfigSubstitutions & s
|
|||||||
}
|
}
|
||||||
if (!config_substitutions.empty())
|
if (!config_substitutions.empty())
|
||||||
substitutions.push_back({name, collection->type(), PresetConfigSubstitutions::Source::UserFile, file, std::move(config_substitutions)});
|
substitutions.push_back({name, collection->type(), PresetConfigSubstitutions::Source::UserFile, file, std::move(config_substitutions)});
|
||||||
|
collection->set_custom_preset_alias(preset);
|
||||||
preset.save(inherit_preset ? &inherit_preset->config : nullptr);
|
preset.save(inherit_preset ? &inherit_preset->config : nullptr);
|
||||||
result.push_back(file);
|
result.push_back(file);
|
||||||
} catch (const std::ifstream::failure &err) {
|
} catch (const std::ifstream::failure &err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user