micro refactor vender type

This commit is contained in:
SoftFever 2023-08-27 11:01:52 +08:00
parent 1f03e4d241
commit aa4c042855
17 changed files with 79 additions and 81 deletions

View file

@ -685,26 +685,6 @@ bool Preset::is_custom_defined()
return false;
}
bool Preset::has_lidar(PresetBundle *preset_bundle)
{
bool has_lidar = false;
if (preset_bundle) {
auto config = &preset_bundle->printers.get_edited_preset().config;
std::string vendor_name;
for (auto vendor_profile : preset_bundle->vendors) {
for (auto vendor_model : vendor_profile.second.models)
if (vendor_model.name == config->opt_string("printer_model"))
{
vendor_name = vendor_profile.first;
break;
}
}
if (!vendor_name.empty())
has_lidar = vendor_name.compare("BBL") == 0 ? true : false;
}
return has_lidar;
}
BedType Preset::get_default_bed_type(PresetBundle* preset_bundle)
{
if (config.has("default_bed_type") && !config.opt_string("default_bed_type").empty()) {

View file

@ -302,7 +302,6 @@ public:
std::string get_current_printer_type(PresetBundle *preset_bundle); // get current preset type
bool is_custom_defined();
bool has_lidar(PresetBundle *preset_bundle);
BedType get_default_bed_type(PresetBundle *preset_bundle);
bool has_cali_lines(PresetBundle* preset_bundle);

View file

@ -321,6 +321,23 @@ Semver PresetBundle::get_vendor_profile_version(std::string vendor_name)
return result_ver;
}
VendorType PresetBundle::get_current_vendor_type()
{
auto t = VendorType::Unknown;
auto config = &printers.get_edited_preset().config;
std::string vendor_name;
for (auto vendor_profile : vendors) {
for (auto vendor_model : vendor_profile.second.models)
if (vendor_model.name == config->opt_string("printer_model")) {
vendor_name = vendor_profile.first;
break;
}
}
if (!vendor_name.empty())
t = vendor_name.compare("BBL") == 0 ? VendorType::Unknown : VendorType::Marlin_BBL;
return t;
}
//BBS: load project embedded presets
PresetsConfigSubstitutions PresetBundle::load_project_embedded_presets(std::vector<Preset*> project_presets, ForwardCompatibilitySubstitutionRule substitution_rule)
{

View file

@ -11,6 +11,13 @@
#define DEFAULT_USER_FOLDER_NAME "default"
// define an enum class of vendor type
enum class VendorType {
Unknown = 0,
Klipper,
Marlin,
Marlin_BBL
};
namespace Slic3r {
// Bundle of Print + Filament + Printer presets.
@ -67,6 +74,11 @@ public:
//BBS: get vendor's current version
Semver get_vendor_profile_version(std::string vendor_name);
// Orca: get vendor type
VendorType get_current_vendor_type();
// Vendor related handy functions
bool is_bbl_vendor() { return get_current_vendor_type() == VendorType::Marlin_BBL; }
//BBS: project embedded preset logic
PresetsConfigSubstitutions load_project_embedded_presets(std::vector<Preset*> project_presets, ForwardCompatibilitySubstitutionRule substitution_rule);
std::vector<Preset*> get_current_project_embedded_presets();

View file

@ -195,8 +195,7 @@ std::string BackgroundSlicingProcess::output_filepath_for_project(const boost::f
void BackgroundSlicingProcess::process_fff()
{
assert(m_print == m_fff_print);
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
m_fff_print->is_BBL_printer() = preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle);
m_fff_print->is_BBL_printer() = wxGetApp().preset_bundle->is_bbl_vendor();
//BBS: add the logic to process from an existed gcode file
if (m_print->finished()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: skip slicing, to process previous gcode file")%__LINE__;

View file

@ -5427,8 +5427,7 @@ bool GLCanvas3D::_render_arrange_menu(float left, float right, float bottom, flo
// only show this option if the printer has micro Lidar and can do first layer scan
DynamicPrintConfig &current_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
const bool has_lidar = preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle);
const bool has_lidar = wxGetApp().preset_bundle->is_bbl_vendor();
auto op = current_config.option("scan_first_layer");
if (has_lidar && op && op->getBool()) {
if (imgui->bbl_checkbox(_L("Avoid extrusion calibration region"), settings.avoid_extrusion_cali_region)) {

View file

@ -2462,6 +2462,7 @@ bool GUI_App::on_init_inner()
#endif // __WXMSW__
preset_updater = new PresetUpdater();
#if orca_todo
Bind(EVT_SLIC3R_VERSION_ONLINE, [this](const wxCommandEvent& evt) {
if (this->plater_ != nullptr) {
// this->plater_->get_notification_manager()->push_notification(NotificationType::NewAppAvailable);
@ -2550,6 +2551,7 @@ bool GUI_App::on_init_inner()
});
dlg.ShowModal();
});
#endif
}
else {
#ifdef __WXMSW__

View file

@ -356,10 +356,8 @@ void ObjectSettings::update_config_values(ModelConfig* config)
//BBS: change local config to DynamicPrintConfig
ConfigManipulation config_manipulation(load_config, toggle_field, nullptr, nullptr, &(config->get()));
// BBS: whether the preset is Bambu Lab printer
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
bool is_BBL_printer = preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle);
config_manipulation.set_is_BBL_Printer(is_BBL_printer);
config_manipulation.set_is_BBL_Printer(wxGetApp().preset_bundle->is_bbl_vendor());
if (!is_object_settings)
{

View file

@ -1874,11 +1874,11 @@ void ObjectGridTable::init_cols(ObjectGrid *object_grid)
col = new ObjectGridCol(coBool, "support_reset", L("Support"), true, true, false, false, wxALIGN_CENTRE);
m_col_data.push_back(col);
// orca merge todo:
//Bed Adhesion
col = new ObjectGridCol(coEnum, "brim_type", L("Support"), true, false, true, true, wxALIGN_LEFT);
col->size = object_grid->GetTextExtent(L("Auto Brim")).x + 8; //add 8 for border
col->choices.Add(_L("Auto"));
col->choices.Add(_L("Mouse ear"));
col->choices.Add(_L("Outer brim only"));
col->choices.Add(_L("Inner brim only"));
col->choices.Add(_L("Outer and inner brim"));

View file

@ -296,10 +296,8 @@ bool ObjectTableSettings::update_settings_list(bool is_object, bool is_multiple_
if (line) line->toggle_visible = toggle;
};
ConfigManipulation config_manipulation(nullptr, toggle_field, toggle_line, nullptr, &m_current_config);
// BBS: whether the preset is Bambu Lab printer
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
bool is_BBL_printer = preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle);
// orca merge todo:
bool is_BBL_printer = wxGetApp().preset_bundle->is_bbl_vendor();
config_manipulation.set_is_BBL_Printer(is_BBL_printer);
printer_technology == ptFFF ? config_manipulation.toggle_print_fff_options(&m_current_config) :
@ -402,10 +400,8 @@ void ObjectTableSettings::update_config_values(bool is_object, ModelObject* obje
};
ConfigManipulation config_manipulation(nullptr, toggle_field, toggle_line, nullptr, &m_current_config);
// BBS: whether the preset is Bambu Lab printer
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
bool is_BBL_printer = preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle);
config_manipulation.set_is_BBL_Printer(is_BBL_printer);
config_manipulation.set_is_BBL_Printer(wxGetApp().preset_bundle->is_bbl_vendor());
printer_technology == ptFFF ? config_manipulation.update_print_fff_config(&main_config) :
config_manipulation.update_print_sla_config(&main_config) ;

View file

@ -499,8 +499,8 @@ void ArrangeJob::process()
const Slic3r::DynamicPrintConfig& global_config = wxGetApp().preset_bundle->full_config();
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
const bool has_lidar = preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle);
if (has_lidar && params.avoid_extrusion_cali_region && global_config.opt_bool("scan_first_layer"))
const bool is_bbl = wxGetApp().preset_bundle->is_bbl_vendor();
if (is_bbl && params.avoid_extrusion_cali_region && global_config.opt_bool("scan_first_layer"))
partplate_list.preprocess_nonprefered_areas(m_unselected, MAX_NUM_PLATES);
update_arrange_params(params, *m_plater, m_selected);

View file

@ -212,8 +212,8 @@ void FillBedJob::process()
auto &print = wxGetApp().plater()->get_partplate_list().get_current_fff_print();
const Slic3r::DynamicPrintConfig& global_config = wxGetApp().preset_bundle->full_config();
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
const bool has_lidar = preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle);
if (has_lidar && params.avoid_extrusion_cali_region && global_config.opt_bool("scan_first_layer"))
const bool is_bbl = wxGetApp().preset_bundle->is_bbl_vendor();
if (is_bbl && params.avoid_extrusion_cali_region && global_config.opt_bool("scan_first_layer"))
partplate_list.preprocess_nonprefered_areas(m_unselected, MAX_NUM_PLATES);
update_selected_items_inflation(m_selected, *m_plater, params);
@ -233,7 +233,7 @@ void FillBedJob::process()
do_stop = ap.bed_idx > 0 && ap.priority == 0;
};
// final align用的是凸包在有fixed item的情况下可能找到的参考点位置是错的这里就不做了。见STUDIO-3265
params.do_final_align = !has_lidar;
params.do_final_align = !is_bbl;
arrangement::arrange(m_selected, m_unselected, m_bedpts, params);

View file

@ -556,8 +556,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
m_print_enable = get_enable_print_status();
m_print_btn->Enable(m_print_enable);
if (m_print_enable) {
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle))
if (wxGetApp().preset_bundle->is_bbl_vendor())
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_PRINT_PLATE));
else
wxPostEvent(m_plater, SimpleEvent(EVT_GLTOOLBAR_SEND_GCODE));
@ -950,28 +949,24 @@ void MainFrame::init_tabpanel() {
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, [this](wxBookCtrlEvent &e) {
int old_sel = e.GetOldSelection();
int new_sel = e.GetSelection();
if (wxGetApp().preset_bundle &&
wxGetApp().preset_bundle->printers.get_edited_preset().has_lidar(wxGetApp().preset_bundle) &&
new_sel == tpMonitor) {
if (!wxGetApp().getAgent()) {
e.Veto();
BOOST_LOG_TRIVIAL(info) << boost::format("skipped tab switch from %1% to %2%, lack of network plugins") %
old_sel % new_sel;
if (m_plater) {
wxCommandEvent *evt = new wxCommandEvent(EVT_INSTALL_PLUGIN_HINT);
wxQueueEvent(m_plater, evt);
if (wxGetApp().preset_bundle && wxGetApp().preset_bundle->is_bbl_vendor() && new_sel == tpMonitor) {
if (!wxGetApp().getAgent()) {
e.Veto();
BOOST_LOG_TRIVIAL(info) << boost::format("skipped tab switch from %1% to %2%, lack of network plugins") % old_sel % new_sel;
if (m_plater) {
wxCommandEvent *evt = new wxCommandEvent(EVT_INSTALL_PLUGIN_HINT);
wxQueueEvent(m_plater, evt);
}
}
}
} else {
if (new_sel == tpMonitor && wxGetApp().preset_bundle != nullptr) {
auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
wxString url = cfg.opt_string("print_host_webui").empty() ? cfg.opt_string("print_host")
: cfg.opt_string("print_host_webui");
if (url.empty()) {
wxString url = wxString::Format("file://%s/web/orca/missing_connection.html", from_u8(resources_dir()));
m_printer_view->load_url(url);
if (new_sel == tpMonitor && wxGetApp().preset_bundle != nullptr) {
auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
wxString url = cfg.opt_string("print_host_webui").empty() ? cfg.opt_string("print_host") : cfg.opt_string("print_host_webui");
if (url.empty()) {
wxString url = wxString::Format("file://%s/web/orca/missing_connection.html", from_u8(resources_dir()));
m_printer_view->load_url(url);
}
}
}
}
});
@ -1575,7 +1570,7 @@ wxBoxSizer* MainFrame::create_side_tools()
SidePopup* p = new SidePopup(this);
if (wxGetApp().preset_bundle
&& !wxGetApp().preset_bundle->printers.get_edited_preset().has_lidar(wxGetApp().preset_bundle)) {
&& !wxGetApp().preset_bundle->is_bbl_vendor()) {
// ThirdParty Buttons
SideButton* export_gcode_btn = new SideButton(p, _L("Export G-code file"), "");
export_gcode_btn->SetCornerRadius(0);
@ -3497,7 +3492,7 @@ void MainFrame::load_printer_url(wxString url)
void MainFrame::load_printer_url()
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle))
if (preset_bundle.is_bbl_vendor())
return;
auto cfg = preset_bundle.printers.get_edited_preset().config;

View file

@ -29,13 +29,15 @@ PlateSettingsDialog::PlateSettingsDialog(wxWindow* parent, wxWindowID id, const
top_sizer->Add(plate_name_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT |wxALL, FromDIP(5));
top_sizer->Add(m_ti_plate_name, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT |wxALL, FromDIP(5));
// bool is_bbl = wxGetApp().preset_bundle->printers.get_edited_preset().has_lidar(wxGetApp().preset_bundle);
m_bed_type_choice = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(240), -1), 0,
NULL, wxCB_READONLY);
for (BedType i = btDefault; i < btCount; i = BedType(int(i) + 1)) {
m_bed_type_choice->Append(to_bed_type_name(i));
}
m_bed_type_choice->Disable();
if (wxGetApp().preset_bundle->is_bbl_vendor())
m_bed_type_choice->Disable();
wxStaticText* m_bed_type_txt = new wxStaticText(this, wxID_ANY, _L("Bed type"));
m_bed_type_txt->SetFont(Label::Body_14);
top_sizer->Add(m_bed_type_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5));

View file

@ -1028,7 +1028,7 @@ void Sidebar::update_all_preset_comboboxes()
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology();
bool is_bbl_preset = preset_bundle.printers.get_edited_preset().has_lidar(&preset_bundle);
bool is_bbl_preset = preset_bundle.is_bbl_vendor();
auto p_mainframe = wxGetApp().mainframe;
@ -1150,7 +1150,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
printer_tab->update();
}
bool isBBL = wxGetApp().preset_bundle->printers.get_edited_preset().has_lidar(wxGetApp().preset_bundle);
bool isBBL = wxGetApp().preset_bundle->is_bbl_vendor();
wxGetApp().mainframe->show_calibration_button(!isBBL);
break;
}
@ -3408,7 +3408,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
if (bed_type_opt != nullptr) {
BedType bed_type = (BedType)bed_type_opt->getInt();
// update app config for bed type
bool is_bbl_preset = preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle);
bool is_bbl_preset = preset_bundle->is_bbl_vendor();
if (is_bbl_preset) {
AppConfig* app_config = wxGetApp().app_config;
if (app_config)
@ -8399,7 +8399,7 @@ void Plater::_calib_pa_pattern(const Calib_Params& params)
const DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config();
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
const bool is_bbl_machine = preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle);
const bool is_bbl_machine = preset_bundle->is_bbl_vendor();
const Vec3d plate_origin = get_partplate_list().get_current_plate_origin();
CalibPressureAdvancePattern pa_pattern(
params,
@ -10696,7 +10696,7 @@ void Plater::reslice()
model().calib_pa_pattern->generate_custom_gcodes(
wxGetApp().preset_bundle->full_config(),
preset_bundle->printers.get_edited_preset().has_lidar(preset_bundle),
preset_bundle->is_bbl_vendor(),
model(),
get_partplate_list().get_current_plate_origin()
);

View file

@ -371,7 +371,7 @@ void PresetComboBox::update_from_bundle()
void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
{
bool is_bbl_vendor_preset = m_preset_bundle->printers.get_edited_preset().has_lidar(m_preset_bundle);
bool is_bbl_vendor_preset = m_preset_bundle->is_bbl_vendor();
if (is_bbl_vendor_preset && !m_preset_bundle->filament_ams_list.empty()) {
set_label_marker(Append(separator(L("AMS filaments")), wxNullBitmap));
m_first_ams_filament = GetCount();
@ -1017,7 +1017,7 @@ void PlaterPresetComboBox::update()
//if (i + 1 == m_collection->num_default_presets())
// set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
}
if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->printers.get_edited_preset().has_lidar(m_preset_bundle))
if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->is_bbl_vendor())
add_ams_filaments(into_u8(selected_user_preset), true);
//BBS: add project embedded preset logic
@ -1245,7 +1245,7 @@ void TabPresetComboBox::update()
// set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
}
if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->printers.get_edited_preset().has_lidar(m_preset_bundle))
if (m_type == Preset::TYPE_FILAMENT && m_preset_bundle->is_bbl_vendor())
add_ams_filaments(into_u8(selected));
//BBS: add project embedded preset logic

View file

@ -1644,7 +1644,7 @@ void Tab::on_presets_changed()
// Instead of PostEvent (EVT_TAB_PRESETS_CHANGED) just call update_presets
wxGetApp().plater()->sidebar().update_presets(m_type);
bool is_bbl_vendor_preset = wxGetApp().preset_bundle->printers.get_edited_preset().has_lidar(wxGetApp().preset_bundle);
bool is_bbl_vendor_preset = wxGetApp().preset_bundle->is_bbl_vendor();
if (is_bbl_vendor_preset) {
wxGetApp().plater()->get_partplate_list().set_render_option(true, true);
if (wxGetApp().preset_bundle->printers.get_edited_preset().has_cali_lines(wxGetApp().preset_bundle)) {
@ -2146,7 +2146,7 @@ void TabPrint::toggle_options()
if (!m_active_page) return;
// BBS: whether the preset is Bambu Lab printer
if (m_preset_bundle) {
bool is_BBL_printer = m_preset_bundle->printers.get_edited_preset().has_lidar(m_preset_bundle);
bool is_BBL_printer = wxGetApp().preset_bundle->is_bbl_vendor();
m_config_manipulation.set_is_BBL_Printer(is_BBL_printer);
}
@ -2891,8 +2891,7 @@ void TabFilament::toggle_options()
bool is_BBL_printer = false;
if (m_preset_bundle) {
is_BBL_printer =
m_preset_bundle->printers.get_edited_preset().has_lidar(
m_preset_bundle);
wxGetApp().preset_bundle->is_bbl_vendor();
}
if (m_active_page->title() == "Cooling") {
@ -3686,7 +3685,7 @@ void TabPrinter::toggle_options()
//BBS: whether the preset is Bambu Lab printer
bool is_BBL_printer = false;
if (m_preset_bundle) {
is_BBL_printer = m_preset_bundle->printers.get_edited_preset().has_lidar(m_preset_bundle);
is_BBL_printer = wxGetApp().preset_bundle->is_bbl_vendor();
}
bool have_multiple_extruders = true;