Merge branch 'dk_filaments' into master

This commit is contained in:
David Kocik 2020-09-01 18:00:54 +02:00
commit 3967a7ac7e
2 changed files with 476 additions and 158 deletions

View File

@ -561,30 +561,37 @@ const std::string PageMaterials::EMPTY;
PageMaterials::PageMaterials(ConfigWizard *parent, Materials *materials, wxString title, wxString shortname, wxString list1name) PageMaterials::PageMaterials(ConfigWizard *parent, Materials *materials, wxString title, wxString shortname, wxString list1name)
: ConfigWizardPage(parent, std::move(title), std::move(shortname)) : ConfigWizardPage(parent, std::move(title), std::move(shortname))
, materials(materials) , materials(materials)
, list_l1(new StringList(this)) , list_printer(new StringList(this, wxLB_MULTIPLE))
, list_l2(new StringList(this)) , list_type(new StringList(this))
, list_l3(new PresetList(this)) , list_vendor(new StringList(this))
, list_profile(new PresetList(this))
, compatible_printers(new wxStaticText(this, wxID_ANY, _(L(""))))
{ {
append_spacer(VERTICAL_SPACING); append_spacer(VERTICAL_SPACING);
const int em = parent->em_unit(); const int em = parent->em_unit();
const int list_h = 30*em; const int list_h = 30*em;
list_l1->SetMinSize(wxSize(8*em, list_h)); list_printer->SetWindowStyle(wxLB_EXTENDED);
list_l2->SetMinSize(wxSize(13*em, list_h));
list_l3->SetMinSize(wxSize(25*em, list_h));
auto *grid = new wxFlexGridSizer(3, em/2, em); list_printer->SetMinSize(wxSize(23*em, list_h));
grid->AddGrowableCol(2, 1); list_type->SetMinSize(wxSize(8*em, list_h));
list_vendor->SetMinSize(wxSize(13*em, list_h));
list_profile->SetMinSize(wxSize(23*em, list_h));
grid = new wxFlexGridSizer(4, em/2, em);
grid->AddGrowableCol(3, 1);
grid->AddGrowableRow(1, 1); grid->AddGrowableRow(1, 1);
grid->Add(new wxStaticText(this, wxID_ANY, _(L("Printer:"))));
grid->Add(new wxStaticText(this, wxID_ANY, list1name)); grid->Add(new wxStaticText(this, wxID_ANY, list1name));
grid->Add(new wxStaticText(this, wxID_ANY, _(L("Vendor:")))); grid->Add(new wxStaticText(this, wxID_ANY, _(L("Vendor:"))));
grid->Add(new wxStaticText(this, wxID_ANY, _(L("Profile:")))); grid->Add(new wxStaticText(this, wxID_ANY, _(L("Profile:"))));
grid->Add(list_l1, 0, wxEXPAND); grid->Add(list_printer, 0, wxEXPAND);
grid->Add(list_l2, 0, wxEXPAND); grid->Add(list_type, 0, wxEXPAND);
grid->Add(list_l3, 1, wxEXPAND); grid->Add(list_vendor, 0, wxEXPAND);
grid->Add(list_profile, 1, wxEXPAND);
auto *btn_sizer = new wxBoxSizer(wxHORIZONTAL); auto *btn_sizer = new wxBoxSizer(wxHORIZONTAL);
auto *sel_all = new wxButton(this, wxID_ANY, _(L("All"))); auto *sel_all = new wxButton(this, wxID_ANY, _(L("All")));
@ -592,121 +599,342 @@ PageMaterials::PageMaterials(ConfigWizard *parent, Materials *materials, wxStrin
btn_sizer->Add(sel_all, 0, wxRIGHT, em / 2); btn_sizer->Add(sel_all, 0, wxRIGHT, em / 2);
btn_sizer->Add(sel_none); btn_sizer->Add(sel_none);
grid->Add(new wxBoxSizer(wxHORIZONTAL)); grid->Add(new wxBoxSizer(wxHORIZONTAL));
grid->Add(new wxBoxSizer(wxHORIZONTAL)); grid->Add(new wxBoxSizer(wxHORIZONTAL));
grid->Add(btn_sizer, 0, wxALIGN_RIGHT); grid->Add(btn_sizer, 0, wxALIGN_RIGHT);
auto* notes_sizer = new wxBoxSizer(wxHORIZONTAL);
notes_sizer->Add(compatible_printers);
grid->Add(notes_sizer);
append(grid, 1, wxEXPAND); append(grid, 1, wxEXPAND);
list_l1->Bind(wxEVT_LISTBOX, [this](wxCommandEvent &) { list_printer->Bind(wxEVT_LISTBOX, [this](wxCommandEvent& evt) {
update_lists(list_l1->GetSelection(), list_l2->GetSelection()); update_lists(evt.GetInt(), list_type->GetSelection(), list_vendor->GetSelection());
});
list_type->Bind(wxEVT_LISTBOX, [this](wxCommandEvent &) {
update_lists(list_printer->GetSelection(), list_type->GetSelection(), list_vendor->GetSelection());
}); });
list_l2->Bind(wxEVT_LISTBOX, [this](wxCommandEvent &) { list_vendor->Bind(wxEVT_LISTBOX, [this](wxCommandEvent &) {
update_lists(list_l1->GetSelection(), list_l2->GetSelection()); update_lists(list_printer->GetSelection(), list_type->GetSelection(), list_vendor->GetSelection());
}); });
list_l3->Bind(wxEVT_CHECKLISTBOX, [this](wxCommandEvent &evt) { select_material(evt.GetInt()); }); list_profile->Bind(wxEVT_CHECKLISTBOX, [this](wxCommandEvent &evt) { select_material(evt.GetInt()); });
list_profile->Bind(wxEVT_LISTBOX, [this](wxCommandEvent& evt) { on_material_highlighted(evt.GetInt()); });
sel_all->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { select_all(true); }); sel_all->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { select_all(true); });
sel_none->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { select_all(false); }); sel_none->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { select_all(false); });
Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) {on_paint();});
list_profile->Bind(wxEVT_MOTION, [this](wxMouseEvent& evt) { on_mouse_move_on_profiles(evt); });
list_profile->Bind(wxEVT_ENTER_WINDOW, [this](wxMouseEvent& evt) { on_mouse_enter_profiles(evt); });
list_profile->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& evt) { on_mouse_leave_profiles(evt); });
reload_presets(); reload_presets();
} }
void PageMaterials::on_paint()
{
if (first_paint) {
first_paint = false;
prepare_compatible_printers_label();
}
}
void PageMaterials::on_mouse_move_on_profiles(wxMouseEvent& evt)
{
const wxClientDC dc(list_profile);
const wxPoint pos = evt.GetLogicalPosition(dc);
int item = list_profile->HitTest(pos);
BOOST_LOG_TRIVIAL(error) << "hit test: " << item;
on_material_hovered(item);
}
void PageMaterials::on_mouse_enter_profiles(wxMouseEvent& evt)
{}
void PageMaterials::on_mouse_leave_profiles(wxMouseEvent& evt)
{
on_material_hovered(-1);
}
void PageMaterials::reload_presets() void PageMaterials::reload_presets()
{ {
clear(); clear();
list_l1->append(_(L("(All)")), &EMPTY); list_printer->append(_(L("(All)")), &EMPTY);
list_printer->SetLabelMarkup("<b>bald</b>");
for (const Preset* printer : materials->printers) {
list_printer->append(printer->name, &printer->name);
}
for (const std::string &type : materials->types) { if (list_printer->GetCount() > 0) {
list_l1->append(type, &type); list_printer->SetSelection(0);
} sel_printer_prev = wxNOT_FOUND;
sel_type_prev = wxNOT_FOUND;
if (list_l1->GetCount() > 0) { sel_vendor_prev = wxNOT_FOUND;
list_l1->SetSelection(0); update_lists(0, 0, 0);
sel1_prev = wxNOT_FOUND;
sel2_prev = wxNOT_FOUND;
update_lists(0, 0);
} }
presets_loaded = true; presets_loaded = true;
} }
void PageMaterials::update_lists(int sel1, int sel2) void PageMaterials::prepare_compatible_printers_label()
{ {
wxWindowUpdateLocker freeze_guard(this); assert(grid->GetColWidths().size() == 4);
(void)freeze_guard; compatible_printers_width = grid->GetColWidths()[3];
empty_printers_label = "Compatible printers:";
if (sel1 != sel1_prev) { for (const Preset* printer : materials->printers) {
// Refresh the second list empty_printers_label += "\n";
// XXX: The vendor list is created with quadratic complexity here,
// but the number of vendors is going to be very small this shouldn't be a problem.
list_l2->Clear();
list_l2->append(_(L("(All)")), &EMPTY);
if (sel1 != wxNOT_FOUND) {
const std::string &type = list_l1->get_data(sel1);
materials->filter_presets(type, EMPTY, [this](const Preset *p) {
const std::string &vendor = this->materials->get_vendor(p);
if (list_l2->find(vendor) == wxNOT_FOUND) {
list_l2->append(vendor, &vendor);
}
});
}
sel1_prev = sel1;
sel2 = 0;
sel2_prev = wxNOT_FOUND;
list_l2->SetSelection(sel2);
list_l3->Clear();
} }
clear_compatible_printers_label();
}
if (sel2 != sel2_prev) { void PageMaterials::clear_compatible_printers_label()
// Refresh the third list {
compatible_printers->SetLabel(boost::nowide::widen(empty_printers_label));
compatible_printers->Wrap(compatible_printers_width);
Layout();
}
list_l3->Clear(); void PageMaterials::on_material_hovered(int sel_material)
if (sel1 != wxNOT_FOUND && sel2 != wxNOT_FOUND) { {
const std::string &type = list_l1->get_data(sel1); if ( sel_material == last_hovered_item)
const std::string &vendor = list_l2->get_data(sel2); return;
if (sel_material == -1) {
materials->filter_presets(type, vendor, [this](const Preset *p) { clear_compatible_printers_label();
bool was_checked = false; return;
}
int cur_i = list_l3->find(p->alias); last_hovered_item = sel_material;
if (cur_i == wxNOT_FOUND) std::string compatible_printers_label = "compatible printers:\n";
cur_i = list_l3->append(p->alias, &p->alias); //selected material string
std::string material_name = list_profile->get_data(sel_material);
// get material preset
const std::vector<const Preset*> matching_materials = materials->get_presets_by_alias(material_name);
if (matching_materials.empty())
{
clear_compatible_printers_label();
return;
}
//find matching printers
bool first = true;
for (const Preset* printer : materials->printers) {
bool compatible = false;
for (const Preset* material : matching_materials) {
if (is_compatible_with_printer(PresetWithVendorProfile(*material, material->vendor), PresetWithVendorProfile(*printer, printer->vendor))) {
if (first)
first = false;
else else
was_checked = list_l3->IsChecked(cur_i); compatible_printers_label += "\n";//", ";
compatible_printers_label += printer->name;
const std::string& section = materials->appconfig_section(); compatible = true;
break;
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;
} }
this->compatible_printers->SetLabel(boost::nowide::widen(compatible_printers_label));
this->compatible_printers->Wrap(compatible_printers_width);
}
void PageMaterials::on_material_highlighted(int sel_material)
{
wxWindowUpdateLocker freeze_guard(this);
(void)freeze_guard;
//std::string compatible_printers_label = "compatible printers:\n";
//std::string empty_suplement = std::string();
//unselect all printers
list_printer->SetSelection(wxNOT_FOUND);
//selected material string
std::string material_name = list_profile->get_data(sel_material);
// get material preset
const std::vector<const Preset*> matching_materials = materials->get_presets_by_alias(material_name);
if (matching_materials.empty())
return;
//find matching printers
//bool first = true;
for (const Preset* printer : materials->printers) {
bool compatible = false;
for (const Preset* material : matching_materials) {
if (is_compatible_with_printer(PresetWithVendorProfile(*material, material->vendor), PresetWithVendorProfile(*printer, printer->vendor))) {
//select printer
int index = list_printer->find(printer->name);
list_printer->SetSelection(index);
/*if (first)
first = false;
else
compatible_printers_label += "\n";//", ";
compatible_printers_label += printer->name;
compatible = true;
break;*/
}
}
//if(!compatible)
// empty_suplement += std::string(printer->name.length() + 2, ' ');
}
// fill rest of label with blanks so it maintains legth
//compatible_printers_label += empty_suplement;
update_lists(0,0,0);
list_profile->SetSelection(list_profile->find(material_name));
//this->compatible_printers->SetLabel(boost::nowide::widen(compatible_printers_label));
//this->compatible_printers->Wrap(compatible_printers_width);
//Refresh();
}
void PageMaterials::update_lists(int sel_printer, int sel_type, int sel_vendor)
{
wxWindowUpdateLocker freeze_guard(this);
(void)freeze_guard;
wxArrayInt sel_printers;
int sel_printers_count = list_printer->GetSelections(sel_printers);
if (sel_printers_count != sel_printer_prev) {
// Refresh type list
list_type->Clear();
list_type->append(_(L("(All)")), &EMPTY);
if (sel_printers_count > 0) {
// If all is selected with other printers
// unselect "all" or all printers depending on last value
if (sel_printers[0] == 0 && sel_printers_count > 1) {
if (sel_printer == 0) {
list_printer->SetSelection(wxNOT_FOUND);
list_printer->SetSelection(0);
} else {
list_printer->SetSelection(0, false);
sel_printers_count = list_printer->GetSelections(sel_printers);
}
}
if (sel_printers[0] != 0) {
for (size_t i = 0; i < sel_printers_count; i++) {
const std::string& printer_name = list_printer->get_data(sel_printers[i]);
const Preset* printer = nullptr;
for (const Preset* it : materials->printers) {
if (it->name == printer_name) {
printer = it;
break;
}
}
materials->filter_presets(printer, EMPTY, EMPTY, [this](const Preset* p) {
const std::string& type = this->materials->get_type(p);
if (list_type->find(type) == wxNOT_FOUND) {
list_type->append(type, &type);
}
});
}
} else {
//clear selection except "ALL"
list_printer->SetSelection(wxNOT_FOUND);
list_printer->SetSelection(0);
materials->filter_presets(nullptr, EMPTY, EMPTY, [this](const Preset* p) {
const std::string& type = this->materials->get_type(p);
if (list_type->find(type) == wxNOT_FOUND) {
list_type->append(type, &type);
}
});
}
}
sel_printer_prev = sel_printers_count;
sel_type = 0;
sel_type_prev = wxNOT_FOUND;
list_type->SetSelection(sel_type);
list_profile->Clear();
}
if (sel_type != sel_type_prev) {
// Refresh vendor list
// XXX: The vendor list is created with quadratic complexity here,
// but the number of vendors is going to be very small this shouldn't be a problem.
list_vendor->Clear();
list_vendor->append(_(L("(All)")), &EMPTY);
if (sel_printers_count != 0 && sel_type != wxNOT_FOUND) {
const std::string& type = list_type->get_data(sel_type);
// find printer preset
for (size_t i = 0; i < sel_printers_count; i++) {
const std::string& printer_name = list_printer->get_data(sel_printers[i]);
const Preset* printer = nullptr;
for (const Preset* it : materials->printers) {
if (it->name == printer_name) {
printer = it;
break;
}
}
materials->filter_presets(printer, type, EMPTY, [this](const Preset* p) {
const std::string& vendor = this->materials->get_vendor(p);
if (list_vendor->find(vendor) == wxNOT_FOUND) {
list_vendor->append(vendor, &vendor);
}
});
}
}
sel_type_prev = sel_type;
sel_vendor = 0;
sel_vendor_prev = wxNOT_FOUND;
list_vendor->SetSelection(sel_vendor);
list_profile->Clear();
}
if (sel_vendor != sel_vendor_prev) {
// Refresh material list
list_profile->Clear();
clear_compatible_printers_label();
if (sel_printers_count != 0 && sel_type != wxNOT_FOUND && sel_vendor != wxNOT_FOUND) {
const std::string& type = list_type->get_data(sel_type);
const std::string& vendor = list_vendor->get_data(sel_vendor);
// finst printer preset
for (size_t i = 0; i < sel_printers_count; i++) {
const std::string& printer_name = list_printer->get_data(sel_printers[i]);
const Preset* printer = nullptr;
for (const Preset* it : materials->printers) {
if (it->name == printer_name) {
printer = it;
break;
}
}
materials->filter_presets(printer, type, vendor, [this](const Preset* p) {
bool was_checked = false;
//size_t printer_counter = materials->get_printer_counter(p);
int cur_i = list_profile->find(p->alias);
if (cur_i == wxNOT_FOUND)
//cur_i = list_profile->append(p->alias + " " + std::to_string(printer_counter)/*+ (omnipresent ? "" : " ONLY SOME PRINTERS")*/, &p->alias);
cur_i = list_profile->append(p->alias + (materials->get_omnipresent(p) ? "" : " *"), &p->alias);
else
was_checked = list_profile->IsChecked(cur_i);
const std::string& section = materials->appconfig_section();
const bool checked = wizard_p()->appconfig_new.has(section, p->name);
list_profile->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");
});
}
}
sel_vendor_prev = sel_vendor;
}
} }
void PageMaterials::select_material(int i) void PageMaterials::select_material(int i)
{ {
const bool checked = list_l3->IsChecked(i); const bool checked = list_profile->IsChecked(i);
const std::string& alias_key = list_l3->get_data(i); const std::string& alias_key = list_profile->get_data(i);
wizard_p()->update_presets_in_config(materials->appconfig_section(), alias_key, checked); wizard_p()->update_presets_in_config(materials->appconfig_section(), alias_key, checked);
} }
@ -715,10 +943,10 @@ void PageMaterials::select_all(bool select)
wxWindowUpdateLocker freeze_guard(this); wxWindowUpdateLocker freeze_guard(this);
(void)freeze_guard; (void)freeze_guard;
for (unsigned i = 0; i < list_l3->GetCount(); i++) { for (unsigned i = 0; i < list_profile->GetCount(); i++) {
const bool current = list_l3->IsChecked(i); const bool current = list_profile->IsChecked(i);
if (current != select) { if (current != select) {
list_l3->Check(i, select); list_profile->Check(i, select);
select_material(i); select_material(i);
} }
} }
@ -726,11 +954,13 @@ void PageMaterials::select_all(bool select)
void PageMaterials::clear() void PageMaterials::clear()
{ {
list_l1->Clear(); list_printer->Clear();
list_l2->Clear(); list_type->Clear();
list_l3->Clear(); list_vendor->Clear();
sel1_prev = wxNOT_FOUND; list_profile->Clear();
sel2_prev = wxNOT_FOUND; sel_printer_prev = wxNOT_FOUND;
sel_type_prev = wxNOT_FOUND;
sel_vendor_prev = wxNOT_FOUND;
presets_loaded = false; presets_loaded = false;
} }
@ -740,6 +970,7 @@ void PageMaterials::on_activate()
wizard_p()->update_materials(materials->technology); wizard_p()->update_materials(materials->technology);
reload_presets(); reload_presets();
} }
first_paint = true;
} }
@ -1314,16 +1545,22 @@ const std::string Materials::UNKNOWN = "(Unknown)";
void Materials::push(const Preset *preset) void Materials::push(const Preset *preset)
{ {
presets.push_back(preset); presets.emplace_back(preset, 0);
types.insert(technology & T_FFF types.insert(technology & T_FFF
? Materials::get_filament_type(preset) ? Materials::get_filament_type(preset)
: Materials::get_material_type(preset)); : Materials::get_material_type(preset));
} }
void Materials::add_printer(const Preset* preset)
{
printers.insert(preset);
}
void Materials::clear() void Materials::clear()
{ {
presets.clear(); presets.clear();
types.clear(); types.clear();
printers.clear();
} }
const std::string& Materials::appconfig_section() const const std::string& Materials::appconfig_section() const
@ -1373,7 +1610,6 @@ const std::string& Materials::get_material_vendor(const Preset *preset)
return opt != nullptr ? opt->value : UNKNOWN; return opt != nullptr ? opt->value : UNKNOWN;
} }
// priv // priv
static const std::unordered_map<std::string, std::pair<std::string, std::string>> legacy_preset_map {{ static const std::unordered_map<std::string, std::pair<std::string, std::string>> legacy_preset_map {{
@ -1601,26 +1837,28 @@ 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_fff.clear(); aliases_fff.clear();
// Iterate filaments in all bundles // Iterate filaments in all bundles
for (const auto &pair : bundles) { for (const auto &pair : bundles) {
for (const auto &filament : pair.second.preset_bundle->filaments) { for (const auto &filament : pair.second.preset_bundle->filaments) {
// Check if filament is already added // Check if filament is already added
if (filaments.containts(&filament)) if (filaments.containts(&filament))
continue; continue;
// Iterate printers in all bundles // Iterate printers in all bundles
// For now, we only allow the profiles to be compatible with another profiles inside the same bundle. for (const auto &printer : pair.second.preset_bundle->printers) {
// for (const auto &pair : bundles) if (!printer.is_visible || printer.printer_technology() != ptFFF)
for (const auto &printer : pair.second.preset_bundle->printers) continue;
// Filter out inapplicable printers // Filter out inapplicable printers
if (printer.is_visible && printer.printer_technology() == ptFFF && if (is_compatible_with_printer(PresetWithVendorProfile(filament, filament.vendor), PresetWithVendorProfile(printer, printer.vendor))) {
is_compatible_with_printer(PresetWithVendorProfile(filament, nullptr), PresetWithVendorProfile(printer, nullptr)) && if (!filaments.containts(&filament)) {
// Check if filament is already added filaments.push(&filament);
! filaments.containts(&filament)) { if (!filament.alias.empty())
filaments.push(&filament); aliases_fff[filament.alias].insert(filament.name);
if (!filament.alias.empty()) }
aliases_fff[filament.alias].insert(filament.name); filaments.add_printer_counter(&filament);
} filaments.add_printer(&printer);
}
}
} }
} }
} }
@ -1637,17 +1875,21 @@ void ConfigWizard::priv::update_materials(Technology technology)
continue; continue;
// Iterate printers in all bundles // Iterate printers in all bundles
// For now, we only allow the profiles to be compatible with another profiles inside the same bundle. // For now, we only allow the profiles to be compatible with another profiles inside the same bundle.
// for (const auto &pair : bundles) for (const auto& printer : pair.second.preset_bundle->printers) {
for (const auto &printer : pair.second.preset_bundle->printers) if(!printer.is_visible || printer.printer_technology() != ptSLA)
// Filter out inapplicable printers continue;
if (printer.is_visible && printer.printer_technology() == ptSLA && // Filter out inapplicable printers
is_compatible_with_printer(PresetWithVendorProfile(material, nullptr), PresetWithVendorProfile(printer, nullptr)) && if (is_compatible_with_printer(PresetWithVendorProfile(material, nullptr), PresetWithVendorProfile(printer, nullptr))) {
// Check if material is already added // Check if material is already added
! sla_materials.containts(&material)) { if(!sla_materials.containts(&material)) {
sla_materials.push(&material); sla_materials.push(&material);
if (!material.alias.empty()) if (!material.alias.empty())
aliases_sla[material.alias].insert(material.name); aliases_sla[material.alias].insert(material.name);
} }
sla_materials.add_printer_counter(&material);
sla_materials.add_printer(&printer);
}
}
} }
} }
} }

View File

@ -57,32 +57,98 @@ enum Technology {
T_ANY = ~0, T_ANY = ~0,
}; };
struct Bundle
{
std::unique_ptr<PresetBundle> preset_bundle;
VendorProfile* vendor_profile{ nullptr };
bool is_in_resources{ false };
bool is_prusa_bundle{ false };
Bundle() = default;
Bundle(Bundle&& other);
// Returns false if not loaded. Reason for that is logged as boost::log error.
bool load(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
const std::string& vendor_id() const { return vendor_profile->id; }
};
struct BundleMap : std::unordered_map<std::string /* = vendor ID */, Bundle>
{
static BundleMap load();
Bundle& prusa_bundle();
const Bundle& prusa_bundle() const;
};
struct Materials struct Materials
{ {
Technology technology; Technology technology;
// use vector for the presets to purpose of save of presets sorting in the bundle // use vector for the presets to purpose of save of presets sorting in the bundle
std::vector<const Preset*> presets; // bool is true if material is present in all printers (omnipresent)
// size_t is counter of printers compatible with material
std::vector<std::pair<const Preset*, size_t>> presets;
std::set<std::string> types; std::set<std::string> types;
std::set<const Preset*> printers;
Materials(Technology technology) : technology(technology) {} Materials(Technology technology) : technology(technology) {}
void push(const Preset *preset); void push(const Preset *preset);
void add_printer(const Preset* preset);
void clear(); void clear();
bool containts(const Preset *preset) const { bool containts(const Preset *preset) const {
return std::find(presets.begin(), presets.end(), preset) != presets.end(); //return std::find(presets.begin(), presets.end(), preset) != presets.end();
return std::find_if(presets.begin(), presets.end(),
[preset](const std::pair<const Preset*, bool>& element) { return element.first == preset; }) != presets.end();
} }
bool get_omnipresent(const Preset* preset) {
return get_printer_counter(preset) == printers.size();
}
const std::vector<const Preset*> get_presets_by_alias(const std::string name) {
std::vector<const Preset*> ret_vec;
for (auto it = presets.begin(); it != presets.end(); ++it) {
if ((*it).first->alias == name)
ret_vec.push_back((*it).first);
}
return ret_vec;
}
void add_printer_counter(const Preset* preset) {
for (auto it = presets.begin(); it != presets.end(); ++it) {
if ((*it).first->alias == preset->alias)
(*it).second += 1;
}
}
size_t get_printer_counter(const Preset* preset) {
size_t highest = 0;
for (auto it : presets) {
if (it.first->alias == preset->alias && it.second > highest)
highest = it.second;
}
return highest;
}
const std::string& appconfig_section() const; const std::string& appconfig_section() const;
const std::string& get_type(const Preset *preset) const; const std::string& get_type(const Preset *preset) const;
const std::string& get_vendor(const Preset *preset) const; const std::string& get_vendor(const Preset *preset) const;
template<class F> void filter_presets(const std::string &type, const std::string &vendor, F cb) { template<class F> void filter_presets(const Preset* printer, const std::string& type, const std::string& vendor, F cb) {
for (const Preset *preset : presets) { for (auto preset : presets) {
if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)) { const Preset& prst = *(preset.first);
cb(preset); const Preset& prntr = *printer;
} if ((printer == nullptr || is_compatible_with_printer(PresetWithVendorProfile(prst, prst.vendor), PresetWithVendorProfile(prntr, prntr.vendor))) &&
} (type.empty() || get_type(preset.first) == type) &&
} (vendor.empty() || get_vendor(preset.first) == vendor)) {
cb(preset.first);
}
}
}
static const std::string UNKNOWN; static const std::string UNKNOWN;
static const std::string& get_filament_type(const Preset *preset); static const std::string& get_filament_type(const Preset *preset);
@ -91,33 +157,9 @@ struct Materials
static const std::string& get_material_vendor(const Preset *preset); static const std::string& get_material_vendor(const Preset *preset);
}; };
struct Bundle
{
std::unique_ptr<PresetBundle> preset_bundle;
VendorProfile *vendor_profile { nullptr };
bool is_in_resources { false };
bool is_prusa_bundle { false };
Bundle() = default;
Bundle(Bundle &&other);
// Returns false if not loaded. Reason for that is logged as boost::log error.
bool load(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
const std::string& vendor_id() const { return vendor_profile->id; }
};
struct BundleMap: std::unordered_map<std::string /* = vendor ID */, Bundle>
{
static BundleMap load();
Bundle& prusa_bundle();
const Bundle& prusa_bundle() const;
};
struct PrinterPickerEvent; struct PrinterPickerEvent;
// GUI elements // GUI elements
typedef std::function<bool(const VendorProfile::PrinterModel&)> ModelFilter; typedef std::function<bool(const VendorProfile::PrinterModel&)> ModelFilter;
@ -225,6 +267,7 @@ struct PagePrinters: ConfigWizardPage
template<class T, class D> struct DataList : public T template<class T, class D> struct DataList : public T
{ {
DataList(wxWindow *parent) : T(parent, wxID_ANY) {} DataList(wxWindow *parent) : T(parent, wxID_ANY) {}
DataList(wxWindow* parent, int style) : T(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, style) {}
// Note: We're _not_ using wxLB_SORT here because it doesn't do the right thing, // Note: We're _not_ using wxLB_SORT here because it doesn't do the right thing,
// eg. "ABS" is sorted before "(All)" // eg. "ABS" is sorted before "(All)"
@ -252,6 +295,25 @@ template<class T, class D> struct DataList : public T
} }
int size() { return this->GetCount(); } int size() { return this->GetCount(); }
void on_mouse_move(const wxPoint& position) {
int item = T::HitTest(position);
if(item == wxHitTest::wxHT_WINDOW_INSIDE)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_WINDOW_INSIDE";
else if (item == wxHitTest::wxHT_WINDOW_OUTSIDE)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_WINDOW_OUTSIDE";
else if(item == wxHitTest::wxHT_WINDOW_CORNER)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_WINDOW_CORNER";
else if (item == wxHitTest::wxHT_WINDOW_VERT_SCROLLBAR)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_WINDOW_VERT_SCROLLBAR";
else if (item == wxHitTest::wxHT_NOWHERE)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_NOWHERE";
else if (item == wxHitTest::wxHT_MAX)
BOOST_LOG_TRIVIAL(error) << "hit test wxHT_MAX";
else
BOOST_LOG_TRIVIAL(error) << "hit test: " << item;
}
}; };
typedef DataList<wxListBox, std::string> StringList; typedef DataList<wxListBox, std::string> StringList;
@ -260,21 +322,35 @@ typedef DataList<wxCheckListBox, std::string> PresetList;
struct PageMaterials: ConfigWizardPage struct PageMaterials: ConfigWizardPage
{ {
Materials *materials; Materials *materials;
StringList *list_l1, *list_l2; StringList *list_printer, *list_type, *list_vendor;
PresetList *list_l3; PresetList *list_profile;
int sel1_prev, sel2_prev; int sel_printer_prev, sel_type_prev, sel_vendor_prev;
bool presets_loaded; bool presets_loaded;
wxFlexGridSizer *grid;
wxStaticText *compatible_printers;
int compatible_printers_width = { 100 };
std::string empty_printers_label;
bool first_paint = { false };
static const std::string EMPTY; static const std::string EMPTY;
int last_hovered_item = { -1 } ;
PageMaterials(ConfigWizard *parent, Materials *materials, wxString title, wxString shortname, wxString list1name); PageMaterials(ConfigWizard *parent, Materials *materials, wxString title, wxString shortname, wxString list1name);
void reload_presets(); void reload_presets();
void update_lists(int sel1, int sel2); void update_lists(int sel1, int sel2, int sel3);
void on_material_highlighted(int sel_material);
void on_material_hovered(int sel_material);
void select_material(int i); void select_material(int i);
void select_all(bool select); void select_all(bool select);
void clear(); void clear();
void prepare_compatible_printers_label();
void clear_compatible_printers_label();
void on_paint();
void on_mouse_move_on_profiles(wxMouseEvent& evt);
void on_mouse_enter_profiles(wxMouseEvent& evt);
void on_mouse_leave_profiles(wxMouseEvent& evt);
virtual void on_activate() override; virtual void on_activate() override;
}; };