Update to config wizard to make it generic again.

This commit is contained in:
supermerill 2019-03-13 19:50:15 +01:00
parent cfc96cf561
commit 2f0a2bd579
6 changed files with 66 additions and 62 deletions

View File

@ -2,7 +2,10 @@
[vendor]
# Vendor name will be shown by the Config Wizard.
name = Prusa Research
name = Prusa {technology}
technologies = FFF; SLA
full_name = Prusa {technology} Technology Printers
# Configuration version of this file. Config file will only be installed, if the config_version differs.
# This means, the server may force the Slic3r configuration to be downgraded.
config_version = 0.8.0-alpha7

View File

@ -30,6 +30,8 @@ enum PrinterTechnology
ptFFF,
// Stereolitography
ptSLA,
// laser-sintered powder
ptSLS,
};

View File

@ -3,7 +3,7 @@
#include <algorithm>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <boost/unordered_map.hpp>
#include <boost/format.hpp>
#include <boost/log/trivial.hpp>
#include <boost/algorithm/string/predicate.hpp>
@ -300,7 +300,7 @@ PageWelcome::PageWelcome(ConfigWizard *parent)
}
PagePrinters::PagePrinters(ConfigWizard *parent, wxString title, wxString shortname, const VendorProfile &vendor, unsigned indent, Technology technology)
PagePrinters::PagePrinters(ConfigWizard *parent, wxString title, wxString shortname, const VendorProfile &vendor, unsigned indent, PrinterTechnology technology)
: ConfigWizardPage(parent, std::move(title), std::move(shortname), indent)
{
enum {
@ -314,8 +314,7 @@ PagePrinters::PagePrinters(ConfigWizard *parent, wxString title, wxString shortn
const auto families = vendor.families();
for (const auto &family : families) {
const auto filter = [&](const VendorProfile::PrinterModel &model) {
return (model.technology == ptFFF && technology & T_FFF
|| model.technology == ptSLA && technology & T_SLA)
return (model.technology == technology)
&& model.family == family;
};
@ -801,17 +800,6 @@ void ConfigWizardIndex::on_mouse_move(wxMouseEvent &evt)
// priv
static const std::unordered_map<std::string, std::pair<std::string, std::string>> legacy_preset_map {{
{ "Original Prusa i3 MK2.ini", std::make_pair("MK2S", "0.4") },
{ "Original Prusa i3 MK2 MM Single Mode.ini", std::make_pair("MK2SMM", "0.4") },
{ "Original Prusa i3 MK2 MM Single Mode 0.6 nozzle.ini", std::make_pair("MK2SMM", "0.6") },
{ "Original Prusa i3 MK2 MultiMaterial.ini", std::make_pair("MK2SMM", "0.4") },
{ "Original Prusa i3 MK2 MultiMaterial 0.6 nozzle.ini", std::make_pair("MK2SMM", "0.6") },
{ "Original Prusa i3 MK2 0.25 nozzle.ini", std::make_pair("MK2S", "0.25") },
{ "Original Prusa i3 MK2 0.6 nozzle.ini", std::make_pair("MK2S", "0.6") },
{ "Original Prusa i3 MK3.ini", std::make_pair("MK3", "0.4") },
}};
void ConfigWizard::priv::load_pages(bool custom_setup)
{
const auto former_active = index->active_item();
@ -819,8 +807,9 @@ void ConfigWizard::priv::load_pages(bool custom_setup)
index->clear();
index->add_page(page_welcome);
index->add_page(page_fff);
index->add_page(page_msla);
for (PagePrinters *page : page_vendors) {
index->add_page(page);
}
index->add_page(page_custom);
if (custom_setup) {
@ -861,7 +850,7 @@ void ConfigWizard::priv::load_vendors()
// Additionally load up vendors from the application resources directory, but only those not seen in the datadir
for (auto &dir_entry : boost::filesystem::directory_iterator(rsrc_vendor_dir))
if (Slic3r::is_ini_file(dir_entry)) {
if (Slic3r::is_ini_file(dir_entry)) {
const auto id = dir_entry.path().stem().string();
if (vendors.find(id) == vendors.end()) {
try {
@ -877,21 +866,7 @@ void ConfigWizard::priv::load_vendors()
// Load up the set of vendors / models / variants the user has had enabled up till now
const AppConfig *app_config = GUI::get_app_config();
if (! app_config->legacy_datadir()) {
appconfig_vendors.set_vendors(*app_config);
} else {
// In case of legacy datadir, try to guess the preference based on the printer preset files that are present
const auto printer_dir = fs::path(Slic3r::data_dir()) / "printer";
for (auto &dir_entry : boost::filesystem::directory_iterator(printer_dir))
if (Slic3r::is_ini_file(dir_entry)) {
auto needle = legacy_preset_map.find(dir_entry.path().filename().string());
if (needle == legacy_preset_map.end()) { continue; }
const auto &model = needle->second.first;
const auto &variant = needle->second.second;
appconfig_vendors.set_variant("PrusaResearch", model, variant, true);
}
}
appconfig_vendors.set_vendors(*app_config);
}
void ConfigWizard::priv::add_page(ConfigWizardPage *page)
@ -969,6 +944,12 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
preset_bundle->export_selections(*app_config);
}
static const boost::unordered_map<PrinterTechnology, std::string> tech_to_string{ {
{ PrinterTechnology::ptFFF, "FFF" },
{ PrinterTechnology::ptSLA, "SLA" },
{ PrinterTechnology::ptSLS, "SLS" },
} };
// Public
ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
@ -999,7 +980,7 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
topsizer->AddSpacer(INDEX_MARGIN);
topsizer->Add(p->hscroll, 1, wxEXPAND);
auto *btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers")));
auto *btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers in this page")));
p->btnsizer->Add(btn_sel_all);
p->btn_prev = new wxButton(this, wxID_ANY, _(L("< &Back")));
@ -1012,22 +993,23 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
p->btnsizer->Add(p->btn_finish, 0, wxLEFT, BTN_SPACING);
p->btnsizer->Add(p->btn_cancel, 0, wxLEFT, BTN_SPACING);
const auto &vendors = p->vendors;
const auto vendor_prusa_it = vendors.find("PrusaResearch");
wxCHECK_RET(vendor_prusa_it != vendors.cend(), "Vendor PrusaResearch not found");
const VendorProfile &vendor_prusa = vendor_prusa_it->second;
p->add_page(p->page_welcome = new PageWelcome(this));
p->page_fff = new PagePrinters(this, _(L("Prusa FFF Technology Printers")), "Prusa FFF", vendor_prusa, 0, PagePrinters::T_FFF);
p->add_page(p->page_fff);
p->page_msla = new PagePrinters(this, _(L("Prusa MSLA Technology Printers")), "Prusa MSLA", vendor_prusa, 0, PagePrinters::T_SLA);
p->add_page(p->page_msla);
for (auto vendor : p->vendors) {
bool first = true;
for (const PrinterTechnology &tech : vendor.second.technologies) {
wxString name = _(L(vendor.second.name));
name.Replace("{technology}", tech_to_string.at(tech));
wxString description = _(L(vendor.second.full_name));
description.Replace("{technology}", tech_to_string.at(tech));
p->page_vendors.push_back(new PagePrinters(this, description, name, vendor.second, (vendor.second.technologies.size()>1 && !first ? 1 : 0), tech));
p->add_page(p->page_vendors.back());
first = false;
}
}
p->add_page(p->page_custom = new PageCustom(this));
p->add_page(p->page_update = new PageUpdate(this));
p->add_page(p->page_vendors = new PageVendors(this));
p->add_page(p->page_firmware = new PageFirmware(this));
p->add_page(p->page_bed = new PageBedShape(this));
p->add_page(p->page_diams = new PageDiameters(this));
@ -1057,8 +1039,11 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
disp_rect.y + disp_rect.height / 20,
9*disp_rect.width / 10,
9*disp_rect.height / 10);
const int width_hint = p->index->GetSize().GetWidth() + p->page_fff->get_width() + 300; // XXX: magic constant, I found no better solution
int max_width = 0;
for (auto page : p->page_vendors) {
max_width = std::max(max_width, page->get_width());
}
const int width_hint = p->index->GetSize().GetWidth() + max_width + 300; // XXX: magic constant, I found no better solution
if (width_hint < window_rect.width) {
window_rect.x += (window_rect.width - width_hint) / 2;
window_rect.width = width_hint;
@ -1073,8 +1058,10 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
p->btn_finish->Hide();
btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {
p->page_fff->select_all(true, false);
p->page_msla->select_all(true, false);
ConfigWizardPage *page = p->index->active_page();
PagePrinters *page_printers = dynamic_cast<PagePrinters*>(page);
if (page_printers)
page_printers->select_all(true, false);
p->index->go_to(p->page_update);
});
@ -1095,7 +1082,7 @@ bool ConfigWizard::run(PresetBundle *preset_bundle, const PresetUpdater *updater
if (ShowModal() == wxID_OK) {
auto *app_config = GUI::get_app_config();
p->apply_config(app_config, preset_bundle, updater);
app_config->set_legacy_datadir(false);
app_config->set_legacy_datadir(false);
BOOST_LOG_TRIVIAL(info) << "ConfigWizard applied";
return true;
} else {

View File

@ -108,16 +108,10 @@ struct PageWelcome: ConfigWizardPage
struct PagePrinters: ConfigWizardPage
{
enum Technology {
// Bitflag equivalent of PrinterTechnology
T_FFF = 0x1,
T_SLA = 0x2,
T_Any = ~0,
};
std::vector<PrinterPicker *> printer_pickers;
PagePrinters(ConfigWizard *parent, wxString title, wxString shortname, const VendorProfile &vendor, unsigned indent, Technology technology);
PagePrinters(ConfigWizard *parent, wxString title, wxString shortname, const VendorProfile &vendor, unsigned indent, PrinterTechnology technology);
void select_all(bool select, bool alternates = false);
int get_width() const;
@ -262,11 +256,9 @@ struct ConfigWizard::priv
wxButton *btn_cancel = nullptr;
PageWelcome *page_welcome = nullptr;
PagePrinters *page_fff = nullptr;
PagePrinters *page_msla = nullptr;
std::vector<PagePrinters*> page_vendors;
PageCustom *page_custom = nullptr;
PageUpdate *page_update = nullptr;
PageVendors *page_vendors = nullptr; // XXX: ?
// Custom setup pages
PageFirmware *page_firmware = nullptr;

View File

@ -117,6 +117,25 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
const auto &vendor_section = get_or_throw(tree, "vendor")->second;
res.name = get_or_throw(vendor_section, "name")->second.data();
auto full_name_node = vendor_section.find("full_name");
res.full_name = (full_name_node == vendor_section.not_found()) ? res.name : full_name_node->second.data();
const auto technologies_field = vendor_section.get<std::string>("technologies", "");
std::vector<std::string> technologies;
if (Slic3r::unescape_strings_cstyle(technologies_field, technologies) && !technologies.empty()) {
for (const std::string &technology : technologies) {
if (technology == "FFF")
res.technologies.push_back(PrinterTechnology::ptFFF);
else if (technology == "SLA")
res.technologies.push_back(PrinterTechnology::ptSLA);
else if (technology == "SLS")
res.technologies.push_back(PrinterTechnology::ptSLS);
else
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: Malformed technologies field: `%2%`") % id % technologies_field;
}
} else {
//default to FFF if not present
res.technologies.push_back(PrinterTechnology::ptFFF);
}
auto config_version_str = get_or_throw(vendor_section, "config_version")->second.data();
auto config_version = Semver::parse(config_version_str);
@ -160,7 +179,6 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
if (model.technology == ptSLA)
continue;
#endif
section.second.get<std::string>("variants", "");
const auto variants_field = section.second.get<std::string>("variants", "");
std::vector<std::string> variants;
if (Slic3r::unescape_strings_cstyle(variants_field, variants)) {

View File

@ -39,6 +39,8 @@ class VendorProfile
{
public:
std::string name;
std::string full_name;
std::vector<PrinterTechnology> technologies;
std::string id;
Semver config_version;
std::string config_update_url;