Implemented aliase for sla_materials
This commit is contained in:
parent
cb395460c4
commit
5bf1c02303
4 changed files with 85 additions and 52 deletions
|
@ -628,7 +628,23 @@ void PageMaterials::update_lists(int sel1, int sel2)
|
||||||
const std::string &vendor = list_l2->get_data(sel2);
|
const std::string &vendor = list_l2->get_data(sel2);
|
||||||
|
|
||||||
materials->filter_presets(type, vendor, [this](const Preset *p) {
|
materials->filter_presets(type, vendor, [this](const Preset *p) {
|
||||||
const int i = list_l3->append(p->name, p);
|
// #ys_FIXME_alias
|
||||||
|
// const int i = list_l3->append(p->name, p);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
if (materials->technology == T_FFF) {
|
||||||
|
if (!p->alias.empty())
|
||||||
|
return;
|
||||||
|
i = list_l3->append(p->name, &p->name);
|
||||||
|
}
|
||||||
|
else if (materials->technology == T_SLA) {
|
||||||
|
if (list_l3->find(p->alias) != wxNOT_FOUND)
|
||||||
|
return;
|
||||||
|
i = list_l3->append(p->alias, &p->alias);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
const bool checked = wizard_p()->appconfig_new.has(materials->appconfig_section(), p->name);
|
const bool checked = wizard_p()->appconfig_new.has(materials->appconfig_section(), p->name);
|
||||||
list_l3->Check(i, checked);
|
list_l3->Check(i, checked);
|
||||||
});
|
});
|
||||||
|
@ -641,19 +657,16 @@ void PageMaterials::update_lists(int sel1, int sel2)
|
||||||
void PageMaterials::select_material(int i)
|
void PageMaterials::select_material(int i)
|
||||||
{
|
{
|
||||||
const bool checked = list_l3->IsChecked(i);
|
const bool checked = list_l3->IsChecked(i);
|
||||||
const Preset &preset = list_l3->get_data(i);
|
|
||||||
// #ys_FIXME_aliases
|
// #ys_FIXME_aliases
|
||||||
|
// const Preset &preset = list_l3->get_data(i);
|
||||||
// if (checked) {
|
// if (checked) {
|
||||||
// wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
|
// wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
|
||||||
// } else {
|
// } else {
|
||||||
// wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
|
// wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (checked) {
|
const std::string& alias_key = list_l3->get_data(i);
|
||||||
wizard_p()->add_presets(materials->appconfig_section(), preset.name);
|
wizard_p()->update_presets_in_config(materials->appconfig_section(), alias_key, checked);
|
||||||
} else {
|
|
||||||
wizard_p()->del_presets(materials->appconfig_section(), preset.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageMaterials::select_all(bool select)
|
void PageMaterials::select_all(bool select)
|
||||||
|
@ -1450,7 +1463,7 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
{
|
{
|
||||||
if (any_fff_selected && (technology & T_FFF)) {
|
if (any_fff_selected && (technology & T_FFF)) {
|
||||||
filaments.clear();
|
filaments.clear();
|
||||||
aliases.clear();
|
aliases_fff.clear();
|
||||||
|
|
||||||
// Iterate filaments in all bundles
|
// Iterate filaments in all bundles
|
||||||
for (const auto &pair : bundles) {
|
for (const auto &pair : bundles) {
|
||||||
|
@ -1469,7 +1482,7 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
if (filament.is_compatible_with_printer(printer)) {
|
if (filament.is_compatible_with_printer(printer)) {
|
||||||
filaments.push(&filament);
|
filaments.push(&filament);
|
||||||
if (!filament.alias.empty())
|
if (!filament.alias.empty())
|
||||||
aliases[filament.alias].insert(filament.name);
|
aliases_fff[filament.alias].insert(filament.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1479,6 +1492,7 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
|
|
||||||
if (any_sla_selected && (technology & T_SLA)) {
|
if (any_sla_selected && (technology & T_SLA)) {
|
||||||
sla_materials.clear();
|
sla_materials.clear();
|
||||||
|
aliases_sla.clear();
|
||||||
|
|
||||||
// Iterate SLA materials in all bundles
|
// Iterate SLA materials in all bundles
|
||||||
for (const auto &pair : bundles) {
|
for (const auto &pair : bundles) {
|
||||||
|
@ -1496,6 +1510,8 @@ void ConfigWizard::priv::update_materials(Technology technology)
|
||||||
|
|
||||||
if (material.is_compatible_with_printer(printer)) {
|
if (material.is_compatible_with_printer(printer)) {
|
||||||
sla_materials.push(&material);
|
sla_materials.push(&material);
|
||||||
|
if (!material.alias.empty())
|
||||||
|
aliases_sla[material.alias].insert(material.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1678,28 +1694,28 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
||||||
preset_bundle->export_selections(*app_config);
|
preset_bundle->export_selections(*app_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigWizard::priv::add_presets(const std::string& section, const std::string& alias_key)
|
void ConfigWizard::priv::update_presets_in_config(const std::string& section, const std::string& alias_key, bool add)
|
||||||
{
|
{
|
||||||
// add preset to config
|
const PresetAliases& aliases = section == AppConfig::SECTION_FILAMENTS ? aliases_fff : aliases_sla;
|
||||||
appconfig_new.set(section, alias_key, "1");
|
|
||||||
|
|
||||||
// add presets had a same alias
|
auto update = [this, add](const std::string& s, const std::string& key) {
|
||||||
|
if (add)
|
||||||
|
appconfig_new.set(s, key, "1");
|
||||||
|
else
|
||||||
|
appconfig_new.erase(s, key);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Not all of the filament preset have aliases.
|
||||||
|
// Thus, we should to delete preset with a same as an alias_key name
|
||||||
|
// add or delete preset from config
|
||||||
|
if (section == AppConfig::SECTION_FILAMENTS)
|
||||||
|
update(section, alias_key);
|
||||||
|
|
||||||
|
// add or delete presets had a same alias
|
||||||
auto it = aliases.find(alias_key);
|
auto it = aliases.find(alias_key);
|
||||||
if (it != aliases.end())
|
if (it != aliases.end())
|
||||||
for (const std::string& name : it->second)
|
for (const std::string& name : it->second)
|
||||||
appconfig_new.set(section, name, "1");
|
update(section, name);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1758,6 +1774,9 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
|
||||||
p->page_msla = new PagePrinters(this, _(L("Prusa MSLA Technology Printers")), "Prusa MSLA", *vendor_prusa, 0, T_SLA);
|
p->page_msla = new PagePrinters(this, _(L("Prusa MSLA Technology Printers")), "Prusa MSLA", *vendor_prusa, 0, T_SLA);
|
||||||
p->add_page(p->page_msla);
|
p->add_page(p->page_msla);
|
||||||
|
|
||||||
|
p->any_sla_selected = p->page_msla->any_selected();
|
||||||
|
p->any_fff_selected = p->page_fff->any_selected();
|
||||||
|
|
||||||
p->add_page(p->page_filaments = new PageMaterials(this, &p->filaments,
|
p->add_page(p->page_filaments = new PageMaterials(this, &p->filaments,
|
||||||
_(L("Filament Profiles Selection")), _(L("Filaments")), _(L("Type:")) ));
|
_(L("Filament Profiles Selection")), _(L("Filaments")), _(L("Type:")) ));
|
||||||
p->add_page(p->page_sla_materials = new PageMaterials(this, &p->sla_materials,
|
p->add_page(p->page_sla_materials = new PageMaterials(this, &p->sla_materials,
|
||||||
|
@ -1775,9 +1794,6 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
|
||||||
p->create_3rdparty_pages(); // Needs to ne done _before_ creating PageVendors
|
p->create_3rdparty_pages(); // Needs to ne done _before_ creating PageVendors
|
||||||
p->add_page(p->page_vendors = new PageVendors(this));
|
p->add_page(p->page_vendors = new PageVendors(this));
|
||||||
|
|
||||||
p->any_sla_selected = p->page_msla->any_selected();
|
|
||||||
p->any_fff_selected = p->page_fff->any_selected();
|
|
||||||
|
|
||||||
p->load_pages();
|
p->load_pages();
|
||||||
p->index->go_to(size_t{0});
|
p->index->go_to(size_t{0});
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,7 @@ struct Materials
|
||||||
|
|
||||||
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) {
|
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) {
|
||||||
for (const Preset *preset : presets) {
|
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);
|
cb(preset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +243,9 @@ template<class T, class D> struct DataList : public T
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef DataList<wxListBox, std::string> StringList;
|
typedef DataList<wxListBox, std::string> StringList;
|
||||||
typedef DataList<wxCheckListBox, Preset> PresetList;
|
// #ys_FIXME_alias
|
||||||
|
//typedef DataList<wxCheckListBox, Preset> PresetList;
|
||||||
|
typedef DataList<wxCheckListBox, std::string> PresetList;
|
||||||
|
|
||||||
struct PageMaterials: ConfigWizardPage
|
struct PageMaterials: ConfigWizardPage
|
||||||
{
|
{
|
||||||
|
@ -418,7 +419,8 @@ struct ConfigWizard::priv
|
||||||
// PrinterPickers state.
|
// PrinterPickers state.
|
||||||
Materials filaments; // Holds available filament presets and their types & vendors
|
Materials filaments; // Holds available filament presets and their types & vendors
|
||||||
Materials sla_materials; // Ditto for SLA materials
|
Materials sla_materials; // Ditto for SLA materials
|
||||||
PresetAliases aliases; // Map of aliase to preset names
|
PresetAliases aliases_fff; // Map of aliase to preset names
|
||||||
|
PresetAliases aliases_sla; // Map of aliase to preset names
|
||||||
std::unique_ptr<DynamicPrintConfig> custom_config; // Backing for custom printer definition
|
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_fff_selected; // Used to decide whether to display Filaments page
|
||||||
bool any_sla_selected; // Used to decide whether to display SLA Materials page
|
bool any_sla_selected; // Used to decide whether to display SLA Materials page
|
||||||
|
@ -458,7 +460,6 @@ struct ConfigWizard::priv
|
||||||
: q(q)
|
: q(q)
|
||||||
, filaments(T_FFF)
|
, filaments(T_FFF)
|
||||||
, sla_materials(T_SLA)
|
, sla_materials(T_SLA)
|
||||||
, any_sla_selected(false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void load_pages();
|
void load_pages();
|
||||||
|
@ -478,14 +479,11 @@ struct ConfigWizard::priv
|
||||||
|
|
||||||
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
|
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
|
||||||
// #ys_FIXME_alise
|
// #ys_FIXME_alise
|
||||||
void add_presets(const std::string& section, const std::string& alias_key);
|
void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add);
|
||||||
void del_presets(const std::string& section, const std::string& alias_key);
|
|
||||||
|
|
||||||
int em() const { return index->em(); }
|
int em() const { return index->em(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -978,7 +978,7 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
|
||||||
// Otherwise fill in the list from scratch.
|
// Otherwise fill in the list from scratch.
|
||||||
ui->Freeze();
|
ui->Freeze();
|
||||||
ui->Clear();
|
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->get_selected_preset();
|
const Preset &selected_preset = this->get_selected_preset();
|
||||||
// Show wide icons if the currently selected preset is not compatible with the current printer,
|
// Show wide icons if the currently selected preset is not compatible with the current printer,
|
||||||
|
@ -1028,7 +1028,9 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
|
||||||
if (preset.is_default || preset.is_system) {
|
if (preset.is_default || preset.is_system) {
|
||||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
||||||
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
||||||
if (i == m_idx_selected)
|
if (i == m_idx_selected ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX)
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1045,7 +1047,9 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
|
||||||
ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap));
|
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) {
|
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||||
ui->Append(it->first, *it->second);
|
ui->Append(it->first, *it->second);
|
||||||
if (it->first == selected)
|
if (it->first == selected ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX)
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1076,6 +1080,13 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui)
|
||||||
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove materials")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_MATERIALS);
|
ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove materials")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_MATERIALS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 preset")
|
||||||
|
*/
|
||||||
|
if (selected_preset_item == INT_MAX)
|
||||||
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
|
|
||||||
ui->SetSelection(selected_preset_item);
|
ui->SetSelection(selected_preset_item);
|
||||||
ui->SetToolTip(ui->GetString(selected_preset_item));
|
ui->SetToolTip(ui->GetString(selected_preset_item));
|
||||||
ui->check_selection();
|
ui->check_selection();
|
||||||
|
@ -1092,7 +1103,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
|
||||||
return 0;
|
return 0;
|
||||||
ui->Freeze();
|
ui->Freeze();
|
||||||
ui->Clear();
|
ui->Clear();
|
||||||
size_t selected_preset_item = 0;
|
size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected
|
||||||
|
|
||||||
/* It's supposed that standard size of an icon is 16px*16px for 100% scaled display.
|
/* It's supposed that standard size of an icon is 16px*16px for 100% scaled display.
|
||||||
* So set sizes for solid_colored(empty) icons used for preset
|
* So set sizes for solid_colored(empty) icons used for preset
|
||||||
|
@ -1127,7 +1138,9 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
|
||||||
if (preset.is_default || preset.is_system) {
|
if (preset.is_default || preset.is_system) {
|
||||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()),
|
||||||
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
(bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp);
|
||||||
if (i == m_idx_selected)
|
if (i == m_idx_selected ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX)
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1144,7 +1157,9 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
|
||||||
ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap);
|
ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap);
|
||||||
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||||
ui->Append(it->first, *it->second);
|
ui->Append(it->first, *it->second);
|
||||||
if (it->first == selected)
|
if (it->first == selected ||
|
||||||
|
// just in case: mark selected_preset_item as a first added element
|
||||||
|
selected_preset_item == INT_MAX)
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1159,6 +1174,14 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
|
||||||
}
|
}
|
||||||
ui->Append(PresetCollection::separator("Add a new printer"), *bmp);
|
ui->Append(PresetCollection::separator("Add a new printer"), *bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 preset")
|
||||||
|
*/
|
||||||
|
if (selected_preset_item == INT_MAX)
|
||||||
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
|
|
||||||
ui->SetSelection(selected_preset_item);
|
ui->SetSelection(selected_preset_item);
|
||||||
ui->SetToolTip(ui->GetString(selected_preset_item));
|
ui->SetToolTip(ui->GetString(selected_preset_item));
|
||||||
ui->Thaw();
|
ui->Thaw();
|
||||||
|
|
|
@ -1148,13 +1148,8 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
|
||||||
loaded = &loaded_sla_materials;
|
loaded = &loaded_sla_materials;
|
||||||
preset_name = section.first.substr(13);
|
preset_name = section.first.substr(13);
|
||||||
|
|
||||||
for (const auto& item : section.second)
|
int end_pos = preset_name.find_first_of("0.");
|
||||||
{
|
alias_name = preset_name.substr(0, end_pos-1);
|
||||||
if (boost::starts_with(item.first, "alias")) {
|
|
||||||
alias_name = item.second.data();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (boost::starts_with(section.first, "printer:")) {
|
} else if (boost::starts_with(section.first, "printer:")) {
|
||||||
presets = &this->printers;
|
presets = &this->printers;
|
||||||
loaded = &loaded_printers;
|
loaded = &loaded_printers;
|
||||||
|
@ -1664,7 +1659,8 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr
|
||||||
|
|
||||||
/* But, if selected_preset_item is still equal to INT_MAX, it means that
|
/* But, if selected_preset_item is still equal to INT_MAX, it means that
|
||||||
* there is no presets added to the list.
|
* there is no presets added to the list.
|
||||||
* */ So, select last combobox item ("Add/Remove filaments")
|
* So, select last combobox item ("Add/Remove filaments")
|
||||||
|
*/
|
||||||
if (selected_preset_item == INT_MAX)
|
if (selected_preset_item == INT_MAX)
|
||||||
selected_preset_item = ui->GetCount() - 1;
|
selected_preset_item = ui->GetCount() - 1;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue