ENH: add alias for custom Filament preset
Jira: XXXX Change-Id: I2fecc8b2bdb63618155e3d21f9db374a6119e416
This commit is contained in:
parent
cafc1c7148
commit
e21a808d73
|
@ -1200,6 +1200,8 @@ void PresetCollection::load_presets(
|
|||
preset.setting_id.clear();
|
||||
//BBS: add config related logs
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", preset type %1%, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_visible;
|
||||
// add alias for custom filament preset
|
||||
set_custom_preset_alias(preset);
|
||||
} catch (const std::ifstream::failure &err) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("The user-config cannot be loaded: %1%. Reason: %2%")%preset.file %err.what();
|
||||
fs::path file_path(preset.file);
|
||||
|
@ -2147,6 +2149,7 @@ bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets,
|
|||
auto old_name = this->get_edited_preset().name;
|
||||
for (auto preset : new_presets) {
|
||||
preset.alias.clear();
|
||||
set_custom_preset_alias(preset);
|
||||
preset.base_id.clear();
|
||||
auto it = this->find_preset_internal(preset.name);
|
||||
assert((it == m_presets.end() || it->name != preset.name) || force_rewritten);
|
||||
|
@ -2467,10 +2470,13 @@ const std::string& PresetCollection::get_preset_name_by_alias(const std::string&
|
|||
auto it = Slic3r::lower_bound_by_predicate(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [&alias](auto &l){ return l.first < alias; });
|
||||
// Continue over all profile names with the same alias.
|
||||
it != m_map_alias_to_profile_name.end() && it->first == alias; ++ it)
|
||||
if (auto it_preset = this->find_preset_internal(it->second);
|
||||
it_preset != m_presets.end() && it_preset->name == it->second &&
|
||||
for (const std::string &preset_name : it->second) {
|
||||
if (auto it_preset = this->find_preset_internal(preset_name);
|
||||
it_preset != m_presets.end() && it_preset->name == preset_name &&
|
||||
it_preset->is_visible && (it_preset->is_compatible || size_t(it_preset - m_presets.begin()) == m_idx_selected))
|
||||
return it_preset->name;
|
||||
}
|
||||
|
||||
return alias;
|
||||
}
|
||||
|
||||
|
@ -2482,6 +2488,12 @@ const std::string* PresetCollection::get_preset_name_renamed(const std::string &
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool PresetCollection::is_alias_exist(const std::string &alias)
|
||||
{
|
||||
if (m_map_alias_to_profile_name.end() == m_map_alias_to_profile_name.find(alias)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string& PresetCollection::get_suffix_modified() {
|
||||
return g_suffix_modified;
|
||||
}
|
||||
|
@ -2808,9 +2820,11 @@ void PresetCollection::update_vendor_ptrs_after_copy(const VendorMap &new_vendor
|
|||
void PresetCollection::update_map_alias_to_profile_name()
|
||||
{
|
||||
m_map_alias_to_profile_name.clear();
|
||||
for (const Preset &preset : m_presets)
|
||||
m_map_alias_to_profile_name.emplace_back(preset.alias, preset.name);
|
||||
std::sort(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [](auto &l, auto &r) { return l.first < r.first; });
|
||||
for (const Preset &preset : m_presets) {
|
||||
m_map_alias_to_profile_name[preset.alias].push_back(preset.name);
|
||||
}
|
||||
// now m_map_alias_to_profile_name is map, not need sort
|
||||
//std::sort(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [](auto &l, auto &r) { return l.first < r.first; });
|
||||
}
|
||||
|
||||
void PresetCollection::update_map_system_profile_renamed()
|
||||
|
@ -2824,6 +2838,27 @@ void PresetCollection::update_map_system_profile_renamed()
|
|||
}
|
||||
}
|
||||
|
||||
void PresetCollection::set_custom_preset_alias(Preset &preset)
|
||||
{
|
||||
if (m_type == Preset::Type::TYPE_FILAMENT && preset.config.has(BBL_JSON_KEY_INHERITS) && preset.config.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS)->value.empty()) {
|
||||
std::string alias_name;
|
||||
std::string preset_name = preset.name;
|
||||
if (alias_name.empty()) {
|
||||
size_t end_pos = preset_name.find_first_of("@");
|
||||
if (end_pos != std::string::npos) {
|
||||
alias_name = preset_name.substr(0, end_pos);
|
||||
boost::trim_right(alias_name);
|
||||
}
|
||||
}
|
||||
if (alias_name.empty() || is_alias_exist(alias_name))
|
||||
preset.alias = "";
|
||||
else {
|
||||
preset.alias = std::move(alias_name);
|
||||
m_map_alias_to_profile_name[preset.alias].push_back(preset.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string PresetCollection::name() const
|
||||
{
|
||||
switch (this->type()) {
|
||||
|
|
|
@ -557,6 +557,7 @@ public:
|
|||
|
||||
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;
|
||||
bool is_alias_exist(const std::string &alias);
|
||||
|
||||
// used to update preset_choice from Tab
|
||||
const std::deque<Preset>& get_presets() const { return m_presets; }
|
||||
|
@ -707,6 +708,8 @@ protected:
|
|||
// Update m_map_system_profile_renamed from loaded system profiles.
|
||||
void update_map_system_profile_renamed();
|
||||
|
||||
void set_custom_preset_alias(Preset &preset);
|
||||
|
||||
private:
|
||||
// Find a preset position in the sorted list of presets.
|
||||
// The "-- default -- " preset is always the first, so it needs
|
||||
|
@ -750,7 +753,7 @@ private:
|
|||
// so that the addresses of the presets don't change during resizing of the container.
|
||||
std::deque<Preset> m_presets;
|
||||
// System profiles may have aliases. Map to the full profile name.
|
||||
std::vector<std::pair<std::string, std::string>> m_map_alias_to_profile_name;
|
||||
std::map<std::string, std::vector<std::string>> m_map_alias_to_profile_name;
|
||||
// Map from old system profile name to a current system profile name.
|
||||
std::map<std::string, std::string> m_map_system_profile_renamed;
|
||||
// Initially this preset contains a copy of the selected preset. Later on, this copy may be modified by the user.
|
||||
|
|
|
@ -1004,10 +1004,20 @@ wxBoxSizer *CreateFilamentPresetDialog::create_button_item()
|
|||
}
|
||||
|
||||
std::string filament_preset_name = vendor_name + " " + type_name + " " + serial_name;
|
||||
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
||||
if (preset_bundle->filaments.is_alias_exist(filament_preset_name)) {
|
||||
MessageDialog dlg(this,
|
||||
wxString::Format(_L("The Filament name %s you created already exists. \nIf you continue creating, the preset created will be displayed with its "
|
||||
"full name. Do you want to continue?"),
|
||||
from_u8(filament_preset_name)),
|
||||
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
|
||||
if (wxID_YES != dlg.ShowModal()) { return; }
|
||||
}
|
||||
|
||||
std::string user_filament_id = get_filament_id(filament_preset_name);
|
||||
|
||||
const wxString &curr_create_type = curr_create_filament_type();
|
||||
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
|
||||
|
||||
if (curr_create_type == m_create_type.base_filament) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":clone filament create type filament ";
|
||||
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_filament_preset) {
|
||||
|
|
Loading…
Reference in New Issue