ConfigWizard improvements - added check for printers and filaments/matelials selection

This commit is contained in:
YuSanka 2019-12-03 18:31:07 +01:00
parent a00ff7b06f
commit 7aea0ceff3
2 changed files with 154 additions and 43 deletions

View File

@ -504,7 +504,8 @@ void PagePrinters::set_run_reason(ConfigWizard::RunReason run_reason)
{
if (technology == T_FFF
&& (run_reason == ConfigWizard::RR_DATA_EMPTY || run_reason == ConfigWizard::RR_DATA_LEGACY)
&& printer_pickers.size() > 0) {
&& printer_pickers.size() > 0
&& printer_pickers[0]->vendor_id == PresetBundle::PRUSA_BUNDLE) {
printer_pickers[0]->select_one(0, true);
}
}
@ -628,32 +629,45 @@ void PageMaterials::update_lists(int sel1, int sel2)
const std::string &vendor = list_l2->get_data(sel2);
materials->filter_presets(type, vendor, [this](const Preset *p) {
// #ys_FIXME_alias
// const int i = list_l3->append(p->name, p);
bool was_checked = false;
if (list_l3->find(p->alias) != wxNOT_FOUND)
return;
const int i = list_l3->append(p->alias, &p->alias);
int cur_i = list_l3->find(p->alias);
if (cur_i == wxNOT_FOUND)
cur_i = list_l3->append(p->alias, &p->alias);
else
was_checked = list_l3->IsChecked(cur_i);
const bool checked = wizard_p()->appconfig_new.has(materials->appconfig_section(), p->name);
list_l3->Check(i, checked);
});
const std::string& section = materials->appconfig_section();
const bool checked = wizard_p()->appconfig_new.has(section, p->name);
list_l3->Check(cur_i, checked | was_checked);
/* Update preset selection in config.
* If one preset from aliases bundle is selected,
* than mark all presets with this aliases as selected
* */
if (checked && !was_checked)
wizard_p()->update_presets_in_config(section, p->alias, true);
else if (!checked && was_checked)
wizard_p()->appconfig_new.set(section, p->name, "1");
} );
}
sel2_prev = sel2;
}
// for the very begining
if ((wizard_p()->run_reason == ConfigWizard::RR_DATA_EMPTY || wizard_p()->run_reason == ConfigWizard::RR_DATA_LEGACY)
&& list_l3->size() > 0 )
{
list_l3->Check(0, true);
wizard_p()->update_presets_in_config(materials->appconfig_section(), list_l3->get_data(0), true);
}
}
void PageMaterials::select_material(int i)
{
const bool checked = list_l3->IsChecked(i);
// #ys_FIXME_aliases
// const Preset &preset = list_l3->get_data(i);
// if (checked) {
// wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1");
// } else {
// wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name);
// }
const std::string& alias_key = list_l3->get_data(i);
wizard_p()->update_presets_in_config(materials->appconfig_section(), alias_key, checked);
@ -826,9 +840,11 @@ PageVendors::PageVendors(ConfigWizard *parent)
if (enabled) {
cbox->SetValue(true);
auto pair = wizard_p()->pages_3rdparty.find(vendor->id);
wxCHECK_RET(pair != wizard_p()->pages_3rdparty.end(), "Internal error: 3rd party vendor printers page not created");
pair->second->install = true;
auto pages = wizard_p()->pages_3rdparty.find(vendor->id);
wxCHECK_RET(pages != wizard_p()->pages_3rdparty.end(), "Internal error: 3rd party vendor printers page not created");
for (PagePrinters* page : { pages->second.first, pages->second.second })
if (page) page->install = true;
}
append(cbox);
@ -1326,9 +1342,10 @@ void ConfigWizard::priv::load_pages()
index->add_page(page_fff);
index->add_page(page_msla);
index->add_page(page_vendors);
for (const auto &pair : pages_3rdparty) {
PagePrinters *page = pair.second;
if (page->install) { index->add_page(page); }
for (const auto &pages : pages_3rdparty) {
for ( PagePrinters* page : { pages.second.first, pages.second.second })
if (page && page->install)
index->add_page(page);
}
index->add_page(page_custom);
@ -1343,6 +1360,9 @@ void ConfigWizard::priv::load_pages()
if (any_fff_selected) { index->add_page(page_filaments); }
if (any_sla_selected) { index->add_page(page_sla_materials); }
// there should to be selected at least one printer
btn_finish->Enable(any_fff_selected || any_sla_selected);
index->add_page(page_update);
index->add_page(page_mode);
@ -1450,10 +1470,31 @@ void ConfigWizard::priv::create_3rdparty_pages()
const VendorProfile *vendor = pair.second.vendor_profile;
if (vendor->id == PresetBundle::PRUSA_BUNDLE) { continue; }
auto *page = new PagePrinters(q, vendor->name, vendor->name, *vendor, 1, T_ANY);
add_page(page);
bool is_fff_technology = false;
bool is_sla_technology = false;
pages_3rdparty.insert({vendor->id, page});
for (auto& model: vendor->models)
{
if (!is_fff_technology && model.technology == ptFFF)
is_fff_technology = true;
if (!is_sla_technology && model.technology == ptSLA)
is_sla_technology = true;
}
PagePrinters* pageFFF = nullptr;
PagePrinters* pageSLA = nullptr;
if (is_fff_technology) {
pageFFF = new PagePrinters(q, vendor->name + " " +_(L("FFF Technology Printers")), vendor->name+" FFF", *vendor, 1, T_FFF);
add_page(pageFFF);
}
if (is_sla_technology) {
pageSLA = new PagePrinters(q, vendor->name + " " + _(L("SLA Technology Printers")), vendor->name+" MSLA", *vendor, 1, T_SLA);
add_page(pageSLA);
}
pages_3rdparty.insert({vendor->id, {pageFFF, pageSLA}});
}
}
@ -1533,10 +1574,10 @@ void ConfigWizard::priv::on_custom_setup()
void ConfigWizard::priv::on_printer_pick(PagePrinters *page, const PrinterPickerEvent &evt)
{
if (page_msla->any_selected() != any_sla_selected ||
page_fff->any_selected() != any_fff_selected) {
any_fff_selected = page_fff->any_selected();
any_sla_selected = page_msla->any_selected();
if (check_sla_selected() != any_sla_selected ||
check_fff_selected() != any_fff_selected) {
any_fff_selected = check_fff_selected();
any_sla_selected = check_sla_selected();
load_pages();
}
@ -1553,9 +1594,9 @@ void ConfigWizard::priv::on_printer_pick(PagePrinters *page, const PrinterPicker
}
}
if (page == page_fff) {
if (page->technology & T_FFF) {
page_filaments->clear();
} else if (page == page_msla) {
} else if (page->technology & T_SLA) {
page_sla_materials->clear();
}
}
@ -1564,17 +1605,48 @@ void ConfigWizard::priv::on_3rdparty_install(const VendorProfile *vendor, bool i
{
auto it = pages_3rdparty.find(vendor->id);
wxCHECK_RET(it != pages_3rdparty.end(), "Internal error: GUI page not found for 3rd party vendor profile");
PagePrinters *page = it->second;
if (page->install && !install) {
page->select_all(false);
}
page->install = install;
page->Layout();
for (PagePrinters* page : { it->second.first, it->second.second })
if (page) {
if (page->install && !install)
page->select_all(false);
page->install = install;
page->Layout();
}
load_pages();
}
bool ConfigWizard::priv::check_material_config()
{
const auto exist_preset = [this](const std::string& section, const Materials& materials)
{
if (appconfig_new.has_section(section) &&
!appconfig_new.get_section(section).empty())
{
const std::map<std::string, std::string>& appconfig_presets = appconfig_new.get_section(section);
for (const auto& preset : appconfig_presets)
if (materials.exist_preset(preset.first))
return true;
}
return false;
};
if (any_fff_selected && !exist_preset(AppConfig::SECTION_FILAMENTS, filaments))
{
show_info(q, _(L("You have to select at least one filament for selected printers")), "");
return false;
}
if (any_sla_selected && !exist_preset(AppConfig::SECTION_MATERIALS, sla_materials))
{
show_info(q, _(L("You have to select at least one material for selected printers")), "");
return false;
}
return true;
}
void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater)
{
const auto enabled_vendors = appconfig_new.vendors();
@ -1718,6 +1790,25 @@ void ConfigWizard::priv::update_presets_in_config(const std::string& section, co
update(section, name);
}
bool ConfigWizard::priv::check_fff_selected()
{
bool ret = page_fff->any_selected();
for (const auto& printer: pages_3rdparty)
if (printer.second.first) // FFF page
ret |= printer.second.first->any_selected();
return ret;
}
bool ConfigWizard::priv::check_sla_selected()
{
bool ret = page_msla->any_selected();
for (const auto& printer: pages_3rdparty)
if (printer.second.second) // SLA page
ret |= printer.second.second->any_selected();
return ret;
}
// Public
@ -1774,8 +1865,8 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
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->any_sla_selected = p->page_msla->any_selected();
p->any_fff_selected = p->page_fff->any_selected();
p->any_sla_selected = p->check_sla_selected();
p->any_fff_selected = p->check_fff_selected();
p->update_materials(T_ANY);
@ -1815,7 +1906,12 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
p->btn_prev->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { this->p->index->go_prev(); });
p->btn_next->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { this->p->index->go_next(); });
p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { this->EndModal(wxID_OK); });
p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &)
{
if (!p->check_material_config())
return;
this->EndModal(wxID_OK);
});
// p->btn_finish->Hide();
p->btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {

View File

@ -81,6 +81,14 @@ struct Materials
}
}
bool exist_preset(const std::string& preset_name) const
{
for (const Preset* preset : presets)
if (preset->name == preset_name)
return true;
return false;
}
static const std::string UNKNOWN;
static const std::string& get_filament_type(const Preset *preset);
static const std::string& get_filament_vendor(const Preset *preset);
@ -240,11 +248,11 @@ template<class T, class D> struct DataList : public T
return wxNOT_FOUND;
}
int size() { return this->GetCount(); }
};
typedef DataList<wxListBox, std::string> StringList;
// #ys_FIXME_alias
//typedef DataList<wxCheckListBox, Preset> PresetList;
typedef DataList<wxCheckListBox, std::string> PresetList;
struct PageMaterials: ConfigWizardPage
@ -345,7 +353,10 @@ struct PageTemperatures: ConfigWizardPage
virtual void apply_custom_config(DynamicPrintConfig &config);
};
typedef std::map<std::string /* = vendor ID */, PagePrinters*> Pages3rdparty;
// hypothetically, each vendor can has printers both of technologies (FFF and SLA)
typedef std::map<std::string /* = vendor ID */,
std::pair<PagePrinters* /* = FFF page */,
PagePrinters* /* = SLA page */>> Pages3rdparty;
class ConfigWizardIndex: public wxPanel
@ -477,10 +488,14 @@ struct ConfigWizard::priv
void on_printer_pick(PagePrinters *page, const PrinterPickerEvent &evt);
void on_3rdparty_install(const VendorProfile *vendor, bool install);
bool check_material_config();
void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
// #ys_FIXME_alise
void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add);
bool check_fff_selected(); // Used to decide whether to display Filaments page
bool check_sla_selected(); // Used to decide whether to display SLA Materials page
int em() const { return index->em(); }
};