Implemented aliases for filaments

This commit is contained in:
YuSanka 2019-11-21 13:12:06 +01:00
parent 15251397b8
commit cb395460c4
5 changed files with 81 additions and 6 deletions

View file

@ -2268,6 +2268,7 @@ temperature = 265
[filament:ColorFabb nGen MINI]
inherits = ColorFabb nGen; *PETMINI*
filament_type = NGEN
alias = ColorFabb nGen
[filament:ColorFabb nGen flex MINI]

View file

@ -642,11 +642,17 @@ void PageMaterials::select_material(int i)
{
const bool checked = list_l3->IsChecked(i);
const Preset &preset = list_l3->get_data(i);
// #ys_FIXME_aliases
// if (checked) {
// wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
// } else {
// wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
// }
if (checked) {
wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
wizard_p()->add_presets(materials->appconfig_section(), preset.name);
} else {
wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
wizard_p()->del_presets(materials->appconfig_section(), preset.name);
}
}
@ -1444,6 +1450,7 @@ void ConfigWizard::priv::update_materials(Technology technology)
{
if (any_fff_selected && (technology & T_FFF)) {
filaments.clear();
aliases.clear();
// Iterate filaments in all bundles
for (const auto &pair : bundles) {
@ -1461,6 +1468,8 @@ void ConfigWizard::priv::update_materials(Technology technology)
if (filament.is_compatible_with_printer(printer)) {
filaments.push(&filament);
if (!filament.alias.empty())
aliases[filament.alias].insert(filament.name);
}
}
}
@ -1669,6 +1678,30 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
preset_bundle->export_selections(*app_config);
}
void ConfigWizard::priv::add_presets(const std::string& section, const std::string& alias_key)
{
// add preset to config
appconfig_new.set(section, alias_key, "1");
// add presets had a same alias
auto it = aliases.find(alias_key);
if (it != aliases.end())
for (const std::string& name : it->second)
appconfig_new.set(section, name, "1");
}
void ConfigWizard::priv::del_presets(const std::string& section, const std::string& alias_key)
{
// delete preset from config
appconfig_new.erase(section, alias_key);
// delete presets had a same alias
auto it = aliases.find(alias_key);
if (it != aliases.end())
for (const std::string& name : it->second)
appconfig_new.erase(section, name);
}
// Public

View file

@ -75,7 +75,8 @@ struct Materials
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) {
for (const Preset *preset : presets) {
if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)) {
if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)//) {
&& preset->alias.empty()) {
cb(preset);
}
}
@ -404,6 +405,8 @@ wxDEFINE_EVENT(EVT_INDEX_PAGE, wxCommandEvent);
// ConfigWizard private data
typedef std::map<std::string, std::set<std::string>> PresetAliases;
struct ConfigWizard::priv
{
ConfigWizard *q;
@ -415,6 +418,7 @@ struct ConfigWizard::priv
// PrinterPickers state.
Materials filaments; // Holds available filament presets and their types & vendors
Materials sla_materials; // Ditto for SLA materials
PresetAliases aliases; // Map of aliase to preset names
std::unique_ptr<DynamicPrintConfig> custom_config; // Backing for custom printer definition
bool any_fff_selected; // Used to decide whether to display Filaments page
bool any_sla_selected; // Used to decide whether to display SLA Materials page
@ -473,6 +477,9 @@ struct ConfigWizard::priv
void on_3rdparty_install(const VendorProfile *vendor, bool install);
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
// #ys_FIXME_alise
void add_presets(const std::string& section, const std::string& alias_key);
void del_presets(const std::string& section, const std::string& alias_key);
int em() const { return index->em(); }
};

View file

@ -148,6 +148,9 @@ public:
// Configuration data, loaded from a file, or set from the defaults.
DynamicPrintConfig config;
// Alias of the preset
std::string alias = "";
void save();
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.

View file

@ -1122,6 +1122,7 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
PresetCollection *presets = nullptr;
std::vector<std::string> *loaded = nullptr;
std::string preset_name;
std::string alias_name;
if (boost::starts_with(section.first, "print:")) {
presets = &this->prints;
loaded = &loaded_prints;
@ -1130,6 +1131,14 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
presets = &this->filaments;
loaded = &loaded_filaments;
preset_name = section.first.substr(9);
for (const auto& item : section.second)
{
if (boost::starts_with(item.first, "alias")) {
alias_name = item.second.data();
break;
}
}
} else if (boost::starts_with(section.first, "sla_print:")) {
presets = &this->sla_prints;
loaded = &loaded_sla_prints;
@ -1138,6 +1147,14 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
presets = &this->sla_materials;
loaded = &loaded_sla_materials;
preset_name = section.first.substr(13);
for (const auto& item : section.second)
{
if (boost::starts_with(item.first, "alias")) {
alias_name = item.second.data();
break;
}
}
} else if (boost::starts_with(section.first, "printer:")) {
presets = &this->printers;
loaded = &loaded_printers;
@ -1283,6 +1300,8 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
loaded.is_system = true;
loaded.vendor = vendor_profile;
}
if (!alias_name.empty())
loaded.alias = alias_name;
++ presets_loaded;
}
}
@ -1538,7 +1557,8 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
// Fill in the list from scratch.
ui->Freeze();
ui->Clear();
size_t selected_preset_item = 0;
size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected
const Preset *selected_preset = this->filaments.find_preset(this->filament_presets[idx_extruder]);
// Show wide icons if the currently selected preset is not compatible with the current printer,
// and draw a red flag in front of the selected preset.
@ -1611,7 +1631,9 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
if (preset.is_default || preset.is_system) {
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()),
(bitmap == 0) ? wxNullBitmap : *bitmap);
if (selected)
if (selected ||
// just in case: mark selected_preset_item as a first added element
selected_preset_item == INT_MAX )
selected_preset_item = ui->GetCount() - 1;
}
else
@ -1630,13 +1652,22 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap));
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
ui->Append(it->first, *it->second);
if (it->first == selected_str)
if (it->first == selected_str ||
// just in case: mark selected_preset_item as a first added element
selected_preset_item == INT_MAX) {
selected_preset_item = ui->GetCount() - 1;
}
}
}
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove filaments")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_FILAMENTS);
/* But, if selected_preset_item is still equal to INT_MAX, it means that
* there is no presets added to the list.
* */ So, select last combobox item ("Add/Remove filaments")
if (selected_preset_item == INT_MAX)
selected_preset_item = ui->GetCount() - 1;
ui->SetSelection(selected_preset_item);
ui->SetToolTip(ui->GetString(selected_preset_item));
ui->check_selection();