NEW:add "bed type to follow machine preset" function

Jira: STUDIO-5535
Change-Id: I2ef99a0a783a074d9379685adde11fddfd6f8cec
This commit is contained in:
zhou.xu 2023-12-09 16:26:24 +08:00 committed by Lane.Wei
parent ece83b13c8
commit 4b8f9a4cc6
10 changed files with 150 additions and 24 deletions

View File

@ -172,7 +172,8 @@ void AppConfig::set_defaults()
if (get("zoom_to_mouse").empty()) if (get("zoom_to_mouse").empty())
set_bool("zoom_to_mouse", false); set_bool("zoom_to_mouse", false);
if (get("user_bed_type").empty())
set_bool("user_bed_type", true);
//#ifdef SUPPORT_SHOW_HINTS //#ifdef SUPPORT_SHOW_HINTS
if (get("show_hints").empty()) if (get("show_hints").empty())
set_bool("show_hints", true); set_bool("show_hints", true);

View File

@ -57,6 +57,7 @@
#define BBL_JSON_KEY_FAMILY "family" #define BBL_JSON_KEY_FAMILY "family"
#define BBL_JSON_KEY_BED_MODEL "bed_model" #define BBL_JSON_KEY_BED_MODEL "bed_model"
#define BBL_JSON_KEY_BED_TEXTURE "bed_texture" #define BBL_JSON_KEY_BED_TEXTURE "bed_texture"
#define BBL_JSON_KEY_DEFAULT_BED_TYPE "default_bed_type"
#define BBL_JSON_KEY_HOTEND_MODEL "hotend_model" #define BBL_JSON_KEY_HOTEND_MODEL "hotend_model"
#define BBL_JSON_KEY_DEFAULT_MATERIALS "default_materials" #define BBL_JSON_KEY_DEFAULT_MATERIALS "default_materials"
#define BBL_JSON_KEY_MODEL_ID "model_id" #define BBL_JSON_KEY_MODEL_ID "model_id"
@ -112,6 +113,7 @@ public:
// Vendor & Printer Model specific print bed model & texture. // Vendor & Printer Model specific print bed model & texture.
std::string bed_model; std::string bed_model;
std::string bed_texture; std::string bed_texture;
std::string default_bed_type;
std::string hotend_model; std::string hotend_model;
PrinterVariant* variant(const std::string &name) { PrinterVariant* variant(const std::string &name) {

View File

@ -3170,6 +3170,9 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_MODEL)) { else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_MODEL)) {
//get bed model //get bed model
model.bed_model = it.value(); model.bed_model = it.value();
} else if (boost::iequals(it.key(), BBL_JSON_KEY_DEFAULT_BED_TYPE)) {
// get bed type
model.default_bed_type = it.value();
} }
else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_TEXTURE)) { else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_TEXTURE)) {
//get bed texture //get bed texture

View File

@ -2900,6 +2900,10 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
m_dirty |= m_assemble_view_toolbar.update_items_state(); m_dirty |= m_assemble_view_toolbar.update_items_state();
// BBS // BBS
//m_dirty |= wxGetApp().plater()->get_view_toolbar().update_items_state(); //m_dirty |= wxGetApp().plater()->get_view_toolbar().update_items_state();
m_dirty |= wxGetApp().plater()->sidebar().get_update_3d_state();
if (wxGetApp().plater()->sidebar().get_update_3d_state()) {
wxGetApp().plater()->sidebar().cancel_update_3d_state();
}
m_dirty |= wxGetApp().plater()->get_collapse_toolbar().update_items_state(); m_dirty |= wxGetApp().plater()->get_collapse_toolbar().update_items_state();
_update_imgui_select_plate_toolbar(); _update_imgui_select_plate_toolbar();
bool mouse3d_controller_applied = wxGetApp().plater()->get_mouse3d_controller().apply(wxGetApp().plater()->get_camera()); bool mouse3d_controller_applied = wxGetApp().plater()->get_mouse3d_controller().apply(wxGetApp().plater()->get_camera());

View File

@ -314,7 +314,7 @@ public:
//explicit GUI_App(EAppMode mode = EAppMode::Editor); //explicit GUI_App(EAppMode mode = EAppMode::Editor);
~GUI_App() override; ~GUI_App() override;
bool get_app_conf_exists() { return m_app_conf_exists; }
void show_message_box(std::string msg) { wxMessageBox(msg); } void show_message_box(std::string msg) { wxMessageBox(msg); }
EAppMode get_app_mode() const { return m_app_mode; } EAppMode get_app_mode() const { return m_app_mode; }
Slic3r::DeviceManager* getDeviceManager() { return m_device_manager; } Slic3r::DeviceManager* getDeviceManager() { return m_device_manager; }

View File

@ -573,6 +573,7 @@ Sidebar::Sidebar(Plater *parent)
// p->editing_filament = -1; // p->editing_filament = -1;
// wxGetApp().params_dialog()->Popup(); // wxGetApp().params_dialog()->Popup();
// wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item(); // wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item();
m_soft_first_start = false;
wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS);
}); });
@ -618,6 +619,7 @@ Sidebar::Sidebar(Plater *parent)
edit_btn->SetToolTip(_L("Click to edit preset")); edit_btn->SetToolTip(_L("Click to edit preset"));
edit_btn->Bind(wxEVT_BUTTON, [this, combo_printer](wxCommandEvent) edit_btn->Bind(wxEVT_BUTTON, [this, combo_printer](wxCommandEvent)
{ {
m_soft_first_start = false;
p->editing_filament = -1; p->editing_filament = -1;
if (combo_printer->switch_to_tab()) if (combo_printer->switch_to_tab())
p->editing_filament = 0; p->editing_filament = 0;
@ -1097,13 +1099,29 @@ void Sidebar::remove_unused_filament_combos(const size_t current_extruder_count)
} }
} }
void Sidebar::set_bed_by_curr_bed_type(AppConfig *config) {
if (config && !config->get("curr_bed_type").empty()) {
int bed_type_idx = 0;
std::string str_bed_type = config->get("curr_bed_type");
int bed_type_value = (int) btPC;
try {
bed_type_value = atoi(str_bed_type.c_str());
} catch (...) {
}
bed_type_idx = bed_type_value - 1;
m_bed_type_list->SelectAndNotify(bed_type_idx);
} else {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":error:curr_bed_type is empty";
}
}
void Sidebar::update_all_preset_comboboxes() void Sidebar::update_all_preset_comboboxes()
{ {
PresetBundle &preset_bundle = *wxGetApp().preset_bundle; PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology();
bool is_bbl_preset = preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle); bool is_bbl_preset = preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle);
auto cur_preset_name = preset_bundle.printers.get_edited_preset().name;
auto p_mainframe = wxGetApp().mainframe; auto p_mainframe = wxGetApp().mainframe;
p_mainframe->show_device(is_bbl_preset); p_mainframe->show_device(is_bbl_preset);
@ -1115,18 +1133,38 @@ void Sidebar::update_all_preset_comboboxes()
//update print button default value for bbl or third-party printer //update print button default value for bbl or third-party printer
p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate); p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate);
AppConfig* config = wxGetApp().app_config; AppConfig* config = wxGetApp().app_config;
if (config && !config->get("curr_bed_type").empty()) { if (config) {
int bed_type_idx = 0; m_update_3d_state = true;
std::string str_bed_type = config->get("curr_bed_type"); if (m_soft_first_start && !wxGetApp().get_app_conf_exists()) {
int bed_type_value = (int)btPC; use_default_bed_type();
try { } else {
bed_type_value = atoi(str_bed_type.c_str()); auto user_bed_type_flag = config->get("user_bed_type") == "true";
} catch(...) {} if (!user_bed_type_flag) { //bed_type not follow machine
bed_type_idx = bed_type_value - 1; set_bed_by_curr_bed_type(config);
m_bed_type_list->SelectAndNotify(bed_type_idx); } else {//bed_type follow machine
if (m_soft_first_start || m_is_gcode_file) {
if (m_is_gcode_file) {
m_is_gcode_file = false;
}
// should include soft close then open ,.gcode.3mf case
set_bed_by_curr_bed_type(config);
}
else if (user_bed_type_flag) {
if (config->has_section("user_bed_type_list")) {
auto user_bed_type_list = config->get_section("user_bed_type_list");
if (user_bed_type_list.size() > 0 && user_bed_type_list[cur_preset_name].size() > 0) {
set_bed_type(user_bed_type_list[cur_preset_name]);
} else {
use_default_bed_type();
}
} else {
use_default_bed_type();
}
}
}
}
} else { } else {
BedType bed_type = preset_bundle.printers.get_edited_preset().get_default_bed_type(&preset_bundle); BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":error:AppConfig is nullptr";
m_bed_type_list->SelectAndNotify((int)bed_type - 1);
} }
m_bed_type_list->Enable(); m_bed_type_list->Enable();
} else { } else {
@ -1290,6 +1328,50 @@ void Sidebar::update_presets_from_to(Slic3r::Preset::Type preset_type, std::stri
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": exit!"); BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": exit!");
} }
bool Sidebar::set_bed_type(const std::string &bed_type_name)
{
auto bed_type_keys = print_config_def.get("curr_bed_type")->enum_values;
for (size_t i = 0; i < bed_type_keys.size(); i++) {
if (bed_type_name == bed_type_keys[i]) {
m_bed_type_list->SelectAndNotify(i);
return true;
}
}
return false;
}
void Sidebar::save_bed_type_to_config(const std::string &bed_type_name)
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
auto cur_preset_name = preset_bundle.printers.get_edited_preset().name;
if (cur_preset_name.size() > 0) {
if (!wxGetApp().app_config->has_section("user_bed_type_list")) {
std::map<std::string, std::string> data;
data[cur_preset_name] = bed_type_name;
wxGetApp().app_config->set_section("user_bed_type_list", data);
} else {
auto data = wxGetApp().app_config->get_section("user_bed_type_list");
auto data_modify = const_cast<std::map<std::string, std::string> *>(&data);
(*data_modify)[cur_preset_name] = bed_type_name;
wxGetApp().app_config->set_section("user_bed_type_list", *data_modify);
}
}
}
bool Sidebar::use_default_bed_type(bool is_bbl_preset)
{
auto bundle = wxGetApp().preset_bundle;
const Preset *curr = &bundle->printers.get_selected_preset();
const VendorProfile::PrinterModel *pm = PresetUtils::system_printer_model(*curr);
if (is_bbl_preset && pm && pm->default_bed_type.size() > 0) {
return set_bed_type(pm->default_bed_type);
}
int selection = m_bed_type_list->GetSelection();
std::string bed_type_name = print_config_def.get("curr_bed_type")->enum_values[selection];
save_bed_type_to_config(bed_type_name);
return false;
}
void Sidebar::change_top_border_for_mode_sizer(bool increase_border) void Sidebar::change_top_border_for_mode_sizer(bool increase_border)
{ {
// BBS // BBS
@ -3599,7 +3681,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
if (app_config) if (app_config)
app_config->set("curr_bed_type", std::to_string(int(bed_type))); app_config->set("curr_bed_type", std::to_string(int(bed_type)));
} }
q->on_bed_type_change(bed_type); q->on_bed_type_change(bed_type, (boost::algorithm::ends_with(filename.string(), ".gcode.3mf") ||
boost::algorithm::ends_with(filename.string(), ".gcode")) ?
true :
false);
} }
// BBS: moved this logic to presetcollection // BBS: moved this logic to presetcollection
@ -5874,6 +5959,10 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice)
// BBS // BBS
void Plater::priv::on_combobox_select(wxCommandEvent &evt) void Plater::priv::on_combobox_select(wxCommandEvent &evt)
{ {
ComboBox *combo = static_cast<ComboBox *>(evt.GetEventObject());
if (combo && combo->is_drop_down()) {
sidebar->update_soft_first_start_state();
}
PlaterPresetComboBox* preset_combo_box = dynamic_cast<PlaterPresetComboBox*>(evt.GetEventObject()); PlaterPresetComboBox* preset_combo_box = dynamic_cast<PlaterPresetComboBox*>(evt.GetEventObject());
if (preset_combo_box) { if (preset_combo_box) {
this->on_select_preset(evt); this->on_select_preset(evt);
@ -5892,7 +5981,10 @@ void Plater::priv::on_select_bed_type(wxCommandEvent &evt)
PresetBundle& preset_bundle = *wxGetApp().preset_bundle; PresetBundle& preset_bundle = *wxGetApp().preset_bundle;
DynamicPrintConfig& proj_config = wxGetApp().preset_bundle->project_config; DynamicPrintConfig& proj_config = wxGetApp().preset_bundle->project_config;
const t_config_enum_values* keys_map = print_config_def.get("curr_bed_type")->enum_keys_map; const t_config_enum_values* keys_map = print_config_def.get("curr_bed_type")->enum_keys_map;
auto user_bed_type_flag = wxGetApp().app_config->get("user_bed_type") == "true";
if (combo && combo->is_drop_down() && user_bed_type_flag) { // save user behavior
sidebar->save_bed_type_to_config(bed_type_name);
}
if (keys_map) { if (keys_map) {
BedType new_bed_type = btCount; BedType new_bed_type = btCount;
for (auto item : *keys_map) { for (auto item : *keys_map) {
@ -11616,8 +11708,8 @@ void Plater::on_filaments_change(size_t num_filaments)
} }
} }
void Plater::on_bed_type_change(BedType bed_type) void Plater::on_bed_type_change(BedType bed_type, bool is_gcode_file) {
{ sidebar().set_is_gcode_file(is_gcode_file);
sidebar().on_bed_type_change(bed_type); sidebar().on_bed_type_change(bed_type);
} }

View File

@ -115,12 +115,15 @@ public:
void create_printer_preset(); void create_printer_preset();
void init_filament_combo(PlaterPresetComboBox **combo, const int filament_idx); void init_filament_combo(PlaterPresetComboBox **combo, const int filament_idx);
void remove_unused_filament_combos(const size_t current_extruder_count); void remove_unused_filament_combos(const size_t current_extruder_count);
void set_bed_by_curr_bed_type(AppConfig *config);
void update_all_preset_comboboxes(); void update_all_preset_comboboxes();
//void update_partplate(PartPlateList& list); //void update_partplate(PartPlateList& list);
void update_presets(Slic3r::Preset::Type preset_type); void update_presets(Slic3r::Preset::Type preset_type);
//BBS //BBS
void update_presets_from_to(Slic3r::Preset::Type preset_type, std::string from, std::string to); void update_presets_from_to(Slic3r::Preset::Type preset_type, std::string from, std::string to);
bool set_bed_type(const std::string& bed_type_name);
void save_bed_type_to_config(const std::string &bed_type_name);
bool use_default_bed_type(bool is_bbl_preset = true);
void change_top_border_for_mode_sizer(bool increase_border); void change_top_border_for_mode_sizer(bool increase_border);
void msw_rescale(); void msw_rescale();
void sys_color_changed(); void sys_color_changed();
@ -172,7 +175,10 @@ public:
std::vector<PlaterPresetComboBox*>& combos_filament(); std::vector<PlaterPresetComboBox*>& combos_filament();
Search::OptionsSearcher& get_searcher(); Search::OptionsSearcher& get_searcher();
std::string& get_search_line(); std::string& get_search_line();
void set_is_gcode_file(bool flag) { m_is_gcode_file = flag; }
void update_soft_first_start_state() { m_soft_first_start = false; }
void cancel_update_3d_state() { m_update_3d_state = false; }
bool get_update_3d_state() { return m_update_3d_state; }
private: private:
struct priv; struct priv;
std::unique_ptr<priv> p; std::unique_ptr<priv> p;
@ -181,6 +187,9 @@ private:
ComboBox* m_bed_type_list = nullptr; ComboBox* m_bed_type_list = nullptr;
ScalableButton* connection_btn = nullptr; ScalableButton* connection_btn = nullptr;
ScalableButton* ams_btn = nullptr; ScalableButton* ams_btn = nullptr;
bool m_soft_first_start {true };
bool m_is_gcode_file{ false };
bool m_update_3d_state{false};
}; };
class Plater: public wxPanel class Plater: public wxPanel
@ -406,7 +415,7 @@ public:
void on_filaments_change(size_t extruders_count); void on_filaments_change(size_t extruders_count);
// BBS // BBS
void on_bed_type_change(BedType bed_type); void on_bed_type_change(BedType bed_type,bool is_gcode_file = false);
bool update_filament_colors_in_full_config(); bool update_filament_colors_in_full_config();
void config_change_notification(const DynamicPrintConfig &config, const std::string& key); void config_change_notification(const DynamicPrintConfig &config, const std::string& key);
void on_config_change(const DynamicPrintConfig &config); void on_config_change(const DynamicPrintConfig &config);

View File

@ -995,7 +995,9 @@ wxWindow* PreferencesDialog::create_general_page()
auto item_currency = create_item_combobox(_L("Units"), page, _L("Units"), "use_inches", Units); auto item_currency = create_item_combobox(_L("Units"), page, _L("Units"), "use_inches", Units);
auto item_mouse_zoom_settings = create_item_checkbox(_L("Zoom to mouse position"), page, _L("Zoom in towards the mouse pointer's position in the 3D view, rather than the 2D window center."), 50, "zoom_to_mouse"); auto item_mouse_zoom_settings = create_item_checkbox(_L("Zoom to mouse position"), page, _L("Zoom in towards the mouse pointer's position in the 3D view, rather than the 2D window center."), 50, "zoom_to_mouse");
auto item_bed_type_follow_preset = create_item_checkbox(_L("Auto Bed Type"), page,
_L("Studio will remember build plate selected last time for certain printer model."), 50,
"user_bed_type");
//auto item_hints = create_item_checkbox(_L("Show \"Tip of the day\" notification after start"), page, _L("If enabled, useful hints are displayed at startup."), 50, "show_hints"); //auto item_hints = create_item_checkbox(_L("Show \"Tip of the day\" notification after start"), page, _L("If enabled, useful hints are displayed at startup."), 50, "show_hints");
auto item_calc_mode = create_item_checkbox(_L("Flushing volumes: Auto-calculate everytime the color changed."), page, _L("If enabled, auto-calculate everytime the color changed."), 50, "auto_calculate"); auto item_calc_mode = create_item_checkbox(_L("Flushing volumes: Auto-calculate everytime the color changed."), page, _L("If enabled, auto-calculate everytime the color changed."), 50, "auto_calculate");
auto title_presets = create_item_title(_L("Presets"), page, _L("Presets")); auto title_presets = create_item_title(_L("Presets"), page, _L("Presets"));
@ -1054,6 +1056,7 @@ wxWindow* PreferencesDialog::create_general_page()
sizer_page->Add(item_region, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_region, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_currency, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_currency, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_mouse_zoom_settings, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_mouse_zoom_settings, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_bed_type_follow_preset, 0, wxTOP, FromDIP(3));
//sizer_page->Add(item_hints, 0, wxTOP, FromDIP(3)); //sizer_page->Add(item_hints, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_calc_mode, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_calc_mode, 0, wxTOP, FromDIP(3));
sizer_page->Add(title_presets, 0, wxTOP | wxEXPAND, FromDIP(20)); sizer_page->Add(title_presets, 0, wxTOP | wxEXPAND, FromDIP(20));

View File

@ -5135,7 +5135,19 @@ void Tab::delete_preset()
//wxID_YES != wxMessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal()) //wxID_YES != wxMessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal())
wxID_YES == MessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal())) wxID_YES == MessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal()))
return; return;
auto delete_cur_bed_type_to_config = [this]() {
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
auto cur_preset_name = preset_bundle.printers.get_edited_preset().name;
if (cur_preset_name.size() > 0 && wxGetApp().app_config->has_section("user_bed_type_list")) {
auto data = wxGetApp().app_config->get_section("user_bed_type_list");
auto data_modify = const_cast<std::map<std::string, std::string> *>(&data);
if ((*data_modify).find(cur_preset_name) != data_modify->end()) {
data_modify->erase(cur_preset_name);
wxGetApp().app_config->set_section("user_bed_type_list", *data_modify);
}
}
};
delete_cur_bed_type_to_config();
// if we just delete preset from the physical printer // if we just delete preset from the physical printer
if (m_presets_choice->is_selected_physical_printer()) { if (m_presets_choice->is_selected_physical_printer()) {
PhysicalPrinter& printer = physical_printers.get_selected_printer(); PhysicalPrinter& printer = physical_printers.get_selected_printer();

View File

@ -61,7 +61,7 @@ public:
wxBitmap GetItemBitmap(unsigned int n); wxBitmap GetItemBitmap(unsigned int n);
void SetItemBitmap(unsigned int n, wxBitmap const &bitmap); void SetItemBitmap(unsigned int n, wxBitmap const &bitmap);
bool is_drop_down(){return drop_down;}
protected: protected:
virtual int DoInsertItems(const wxArrayStringsAdapter &items, virtual int DoInsertItems(const wxArrayStringsAdapter &items,
unsigned int pos, unsigned int pos,