diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 26f04868a4..fad0762a18 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2037,17 +2037,11 @@ void GCode::print_machine_envelope(GCodeOutputStream &file, Print &print) } // BBS -void GCode::get_bed_temperature(const int extruder_id, const bool is_first_layer, std::vector& temps_per_bed, int& default_temp) const +int GCode::get_bed_temperature(const int extruder_id, const bool is_first_layer, const BedType bed_type) const { - temps_per_bed.resize((int)BedType::btCount, 0); - for (int bed_type = 0; bed_type < BedType::btCount; bed_type++) { - std::string bed_temp_key = is_first_layer ? get_bed_temp_1st_layer_key((BedType)bed_type) : get_bed_temp_key((BedType)bed_type); - const ConfigOptionInts* bed_temp_opt = m_config.option(bed_temp_key); - - temps_per_bed[bed_type] = bed_temp_opt->get_at(extruder_id); - if (bed_type == m_config.curr_bed_type) - default_temp = temps_per_bed[bed_type]; - } + std::string bed_temp_key = is_first_layer ? get_bed_temp_1st_layer_key(bed_type) : get_bed_temp_key(bed_type); + const ConfigOptionInts* bed_temp_opt = m_config.option(bed_temp_key); + return bed_temp_opt->get_at(extruder_id); } // Write 1st layer bed temperatures into the G-code. @@ -2059,8 +2053,7 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p // Initial bed temperature based on the first extruder. // BBS std::vector temps_per_bed; - int default_temp = 0; - get_bed_temperature(first_printing_extruder_id, true, temps_per_bed, default_temp); + int bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type); // Is the bed temperature set by the provided custom G-code? int temp_by_gcode = -1; @@ -2073,7 +2066,7 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p // Always call m_writer.set_bed_temperature() so it will set the internal "current" state of the bed temp as if // the custom start G-code emited these. - std::string set_temp_gcode = m_writer.set_bed_temperature(temps_per_bed, default_temp, wait); + std::string set_temp_gcode = m_writer.set_bed_temperature(bed_temp, wait); if (! temp_set_by_gcode) file.write(set_temp_gcode); } @@ -2528,10 +2521,8 @@ GCode::LayerResult GCode::process_layer( } // BBS - std::vector temps_per_bed; - int default_temp = 0; - get_bed_temperature(first_extruder_id, false, temps_per_bed, default_temp); - gcode += m_writer.set_bed_temperature(temps_per_bed, default_temp); + int bed_temp = get_bed_temperature(first_extruder_id, false, print.config().curr_bed_type); + gcode += m_writer.set_bed_temperature(bed_temp); // Mark the temperature transition from 1st to 2nd layer to be finished. m_second_layer_things_done = true; } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index e3c1aec259..ccf254c571 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -492,7 +492,7 @@ private: static bool gcode_label_objects; // BBS - void get_bed_temperature(const int extruder_id, const bool is_first_layer, std::vector& temps_per_bed, int& default_temp) const; + int get_bed_temperature(const int extruder_id, const bool is_first_layer, const BedType bed_type) const; std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1); void print_machine_envelope(GCodeOutputStream &file, Print &print); diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 4b0739b9c8..ae4b84e8e5 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -120,13 +120,12 @@ std::string GCodeWriter::set_temperature(unsigned int temperature, bool wait, in } // BBS -std::string GCodeWriter::set_bed_temperature(std::vector temps_per_bed, int default_temp, bool wait) +std::string GCodeWriter::set_bed_temperature(int temperature, bool wait) { - if (temps_per_bed == m_last_bed_temperature && (! wait || m_last_bed_temperature_reached)) + if (temperature == m_last_bed_temperature && (! wait || m_last_bed_temperature_reached)) return std::string(); - bool target_temp_changed = (temps_per_bed != m_last_bed_temperature); - m_last_bed_temperature = temps_per_bed; + m_last_bed_temperature = temperature; m_last_bed_temperature_reached = wait; std::string code, comment; @@ -141,7 +140,7 @@ std::string GCodeWriter::set_bed_temperature(std::vector temps_per_bed, int comment = "set bed temperature"; } - gcode << code << " S" << default_temp << " ; " << comment << "\n"; + gcode << code << " S" << temperature << " ; " << comment << "\n"; return gcode.str(); } diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 23d3b5ec72..1a92abfbb6 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -48,8 +48,7 @@ public: std::string preamble(); std::string postamble() const; std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const; - // BBS - std::string set_bed_temperature(std::vector temps_per_bed, int default_temp, bool wait = false); + std::string set_bed_temperature(int temperature, bool wait = false); std::string set_acceleration(unsigned int acceleration); std::string reset_e(bool force = false); std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const; @@ -106,8 +105,7 @@ private: unsigned int m_max_acceleration; //BBS unsigned int m_last_additional_fan_speed; - // BBS - std::vector m_last_bed_temperature; + int m_last_bed_temperature; bool m_last_bed_temperature_reached; double m_lifted; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 3e95e36afc..47d10284f2 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -269,10 +269,11 @@ CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(OverhangFanThreshold) // BBS static const t_config_enum_values s_keys_map_BedType = { + { "Default Plate", btDefault }, { "Cool Plate", btPC }, { "Engineering Plate", btEP }, { "High Temp Plate", btPEI }, - { "Textured PEI Plate", btPTE } + { "Textured PEI Plate", btPTE } }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedType) diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index a772ac6864..22360c9024 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -166,7 +166,8 @@ enum OverhangFanThreshold { // BBS enum BedType { - btPC = 0, + btDefault = 0, + btPC, btEP, btPEI, btPTE, diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 0e00716ec3..65bd69066c 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -133,12 +133,20 @@ void PartPlate::init() m_print = nullptr; } -BedType PartPlate::get_bed_type() const +BedType PartPlate::get_bed_type(bool check_global/*= true*/) const { std::string bed_type_key = "curr_bed_type"; - if (m_config.has(bed_type_key)) - return m_config.opt_enum(bed_type_key); + // should be called in GUI context + assert(m_plater != nullptr); + if (m_config.has(bed_type_key)) { + BedType bed_type = m_config.opt_enum(bed_type_key); + if (bed_type != btDefault) + return bed_type; + } + + if (!check_global) + return btDefault; if (m_plater) { // In GUI mode @@ -150,30 +158,20 @@ BedType PartPlate::get_bed_type() const return BedType::btPC; } -void PartPlate::set_bed_type(BedType bed_type, bool& same_as_global) +void PartPlate::set_bed_type(BedType bed_type) { - is_same_bedtype_with_global = true; + std::string bed_type_key = "curr_bed_type"; + // should be called in GUI context assert(m_plater != nullptr); - std::string bed_type_key = "curr_bed_type"; + if (bed_type == BedType::btDefault) + m_config.erase(bed_type_key); + else + m_config.set_key_value("curr_bed_type", new ConfigOptionEnum(bed_type)); - m_config.set_key_value("curr_bed_type", new ConfigOptionEnum(bed_type)); - if (m_plater) { + if (m_plater) m_plater->update_project_dirty_from_presets(); - //m_plater->schedule_background_process(); - DynamicConfig& proj_cfg = wxGetApp().preset_bundle->project_config; - if (proj_cfg.has(bed_type_key)) { - //std::string bed_type_key = "curr_bed_type"; - BedType global_bed_type = proj_cfg.opt_enum(bed_type_key); - same_as_global = bed_type == global_bed_type; - is_same_bedtype_with_global = same_as_global; - return; - } - } - - same_as_global = false; - is_same_bedtype_with_global = same_as_global; } void PartPlate::reset_bed_type() @@ -551,7 +549,8 @@ void PartPlate::render_logo(bool bottom) const PartPlateList::load_bedtype_textures(); - int bed_type_idx = (int)get_bed_type(); + // btDefault should be skipped + int bed_type_idx = (int)get_bed_type() - 1; render_logo_texture(PartPlateList::bed_textures[bed_type_idx], bottom); } @@ -717,16 +716,16 @@ void PartPlate::render_icons(bool bottom, int hover_id) const if (m_partplate_list->render_bedtype_setting) { if (hover_id == 5) { - if (is_same_bedtype_with_global) - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_hovered_texture, m_bedtype_vbo_id); + if (get_bed_type(false) == BedType::btDefault) + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_hovered_texture, m_bedtype_vbo_id); else - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_hovered_texture, m_bedtype_vbo_id); + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_hovered_texture, m_bedtype_vbo_id); } else { - if (is_same_bedtype_with_global) - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_texture, m_bedtype_vbo_id); + if (get_bed_type(false) == BedType::btDefault) + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_texture, m_bedtype_vbo_id); else - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_texture, m_bedtype_vbo_id); + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_texture, m_bedtype_vbo_id); } } diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index e15c4c55e6..9bbffd8ce5 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -213,8 +213,8 @@ public: //clear alll the instances in plate void clear(bool clear_sliced_result = true); - BedType get_bed_type() const; - void set_bed_type(BedType, bool& same_as_global); + BedType get_bed_type(bool check_global = true) const; + void set_bed_type(BedType bed_type); void reset_bed_type(); DynamicPrintConfig* config() { return &m_config; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 90ec0718d0..a6b6c25226 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -542,8 +542,12 @@ Sidebar::Sidebar(Plater *parent) m_bed_type_list = new ComboBox(p->m_panel_printer_content, wxID_ANY, wxString(""), wxDefaultPosition, {-1, FromDIP(24)}, 0, nullptr, wxCB_READONLY); const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type"); if (bed_type_def && bed_type_def->enum_keys_map) { - for (auto item : *bed_type_def->enum_keys_map) + for (auto item : *bed_type_def->enum_keys_map) { + if (item.first == "Default Plate") + continue; + m_bed_type_list->AppendString(_L(item.first)); + } } bed_type_title->Bind(wxEVT_ENTER_WINDOW, [bed_type_title, this](wxMouseEvent &e) { @@ -1253,8 +1257,10 @@ void Sidebar::on_filaments_change(size_t num_filaments) void Sidebar::on_bed_type_change(BedType bed_type) { + // btDefault option is not included in global bed type setting + int sel_idx = (int)bed_type - 1; if (m_bed_type_list != nullptr) - m_bed_type_list->SetSelection(bed_type); + m_bed_type_list->SetSelection(sel_idx); } void Sidebar::load_ams_list(std::map const &list) @@ -5231,38 +5237,32 @@ void Plater::priv::on_select_bed_type(wxCommandEvent &evt) int selection = combo->GetSelection(); wxString bed_type_name = combo->GetString(selection); - DynamicPrintConfig& 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; if (keys_map) { - BedType bed_type = btCount; + BedType new_bed_type = btCount; for (auto item : *keys_map) { - if (_L(item.first) == bed_type_name) - bed_type = (BedType)item.second; + if (_L(item.first) == bed_type_name) { + new_bed_type = (BedType)item.second; + break; + } } - if (bed_type != btCount) { - config.set_key_value("curr_bed_type", new ConfigOptionEnum(bed_type)); + if (new_bed_type != btCount) { + BedType old_bed_type = proj_config.opt_enum("curr_bed_type"); + proj_config.set_key_value("curr_bed_type", new ConfigOptionEnum(new_bed_type)); wxGetApp().plater()->update_project_dirty_from_presets(); - // clear all plates' bed type config - for (int i = 0; i < partplate_list.get_plate_count(); i++) - partplate_list.get_plate(i)->reset_bed_type(); // update plater with new config q->on_config_change(wxGetApp().preset_bundle->full_config()); // update app_config AppConfig *app_config = wxGetApp().app_config; - app_config->set("curr_bed_type", std::to_string(int(bed_type))); + app_config->set("curr_bed_type", std::to_string(int(new_bed_type))); // update render - auto plate_list = partplate_list.get_plate_list(); - for (auto plate : plate_list) { - bool same_as_global = false; - auto type = plate->get_bed_type(); - plate->set_bed_type(type, same_as_global); - } view3D->get_canvas3d()->render(); preview->msw_rescale(); } @@ -10645,11 +10645,11 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click) ret = select_plate(plate_index); if (!ret) { SetBedTypeDialog dlg(this, wxID_ANY, _L("Select Bed Type")); - dlg.sync_bed_type(p->partplate_list.get_curr_plate()->get_bed_type()); + PartPlate* curr_plate = p->partplate_list.get_curr_plate(); + dlg.sync_bed_type(curr_plate->get_bed_type(false)); dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index](wxCommandEvent& e) { - bool same_as_global = false; auto type = (BedType)(e.GetInt()); - p->partplate_list.get_curr_plate()->set_bed_type(type, same_as_global); + p->partplate_list.get_curr_plate()->set_bed_type(type); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select bed type %1% for plate %2% at plate side")%type %plate_index; }); dlg.ShowModal(); diff --git a/src/slic3r/GUI/SetBedTypeDialog.cpp b/src/slic3r/GUI/SetBedTypeDialog.cpp index 76c9ce7354..b44f78b460 100644 --- a/src/slic3r/GUI/SetBedTypeDialog.cpp +++ b/src/slic3r/GUI/SetBedTypeDialog.cpp @@ -19,14 +19,17 @@ SetBedTypeDialog::SetBedTypeDialog(wxWindow* parent, wxWindowID id, const wxStri m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); wxBoxSizer* m_sizer_radiobutton = new wxBoxSizer(wxVERTICAL); - m_cool_btn = create_item_radiobox(_L("Cool Plate"), this, wxEmptyString, FromDIP(5), 0, "btPC"); - m_sizer_radiobutton->Add( m_cool_btn, 1, wxALL, FromDIP(5) ); - m_engineering_btn = create_item_radiobox(_L("Engineering Plate"), this, wxEmptyString, FromDIP(5), 1, "btEP"); - m_sizer_radiobutton->Add( m_engineering_btn, 1, wxALL, FromDIP(5) ); - m_high_temp_btn = create_item_radiobox(_L("High Temp Plate"), this, wxEmptyString, FromDIP(5), 2, "btPEI"); - m_sizer_radiobutton->Add( m_high_temp_btn, 1, wxALL, FromDIP(5) ); - m_texture_pei_btn = create_item_radiobox(_L("Textured PEI Plate"), this, wxEmptyString, FromDIP(5), 3, "btPTE"); - m_sizer_radiobutton->Add( m_texture_pei_btn, 1, wxALL, FromDIP(5) ); + + m_rb_default_plate = create_item_radiobox(_L("Default"), this, wxEmptyString, FromDIP(5), btDefault); + m_sizer_radiobutton->Add(m_rb_default_plate->GetParent(), 1, wxALL, FromDIP(5)); + m_rb_cool_plate = create_item_radiobox(_L("Cool Plate"), this, wxEmptyString, FromDIP(5), btPC); + m_sizer_radiobutton->Add(m_rb_cool_plate->GetParent(), 1, wxALL, FromDIP(5)); + m_rb_eng_plate = create_item_radiobox(_L("Engineering Plate"), this, wxEmptyString, FromDIP(5), btEP); + m_sizer_radiobutton->Add(m_rb_eng_plate->GetParent(), 1, wxALL, FromDIP(5) ); + m_rb_high_temp_plate = create_item_radiobox(_L("High Temp Plate"), this, wxEmptyString, FromDIP(5), btPEI); + m_sizer_radiobutton->Add(m_rb_high_temp_plate->GetParent(), 1, wxALL, FromDIP(5)); + m_rb_texture_pei_plate = create_item_radiobox(_L("Textured PEI Plate"), this, wxEmptyString, FromDIP(5), btPTE); + m_sizer_radiobutton->Add(m_rb_texture_pei_plate->GetParent(), 1, wxALL, FromDIP(5)); m_sizer_main->Add(m_sizer_radiobutton, 0, wxEXPAND | wxALL, FromDIP(10)); @@ -50,7 +53,7 @@ SetBedTypeDialog::SetBedTypeDialog(wxWindow* parent, wxWindowID id, const wxStri for (int i = 0; i < len; ++i) { if (radio_buttons[i]->GetValue()) { wxCommandEvent evt(EVT_SET_BED_TYPE_CONFIRM, GetId()); - evt.SetInt(i); + evt.SetInt(radio_buttons[i]->GetBedType()); e.SetEventObject(this); GetEventHandler()->ProcessEvent(evt); break; @@ -94,12 +97,12 @@ SetBedTypeDialog::~SetBedTypeDialog() } -wxWindow* SetBedTypeDialog::create_item_radiobox(wxString title, wxWindow* parent, wxString tooltip, int padding_left, int groupid, std::string param) +BedTypeRadioBox* SetBedTypeDialog::create_item_radiobox(wxString title, wxWindow* parent, wxString tooltip, int padding_left, BedType bed_type) { wxWindow *item = new wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(28))); item->SetBackgroundColour(*wxWHITE); - RadioBox *radiobox = new RadioBox(item); + BedTypeRadioBox* radiobox = new BedTypeRadioBox(item, bed_type); radiobox->SetPosition(wxPoint(padding_left, (item->GetSize().GetHeight() - radiobox->GetSize().GetHeight()) / 2)); radio_buttons.push_back(radiobox); int btn_idx = radio_buttons.size() - 1; @@ -117,7 +120,7 @@ wxWindow* SetBedTypeDialog::create_item_radiobox(wxString title, wxWindow* paren radiobox->SetToolTip(tooltip); text->SetToolTip(tooltip); - return item; + return radiobox; } void SetBedTypeDialog::select_curr_radiobox(int btn_idx) @@ -133,8 +136,12 @@ void SetBedTypeDialog::select_curr_radiobox(int btn_idx) void SetBedTypeDialog::sync_bed_type(BedType type) { - int select_type = (int)(type); - select_curr_radiobox(select_type); + for (auto radio_box : radio_buttons) { + if (radio_box->GetBedType() == type) + radio_box->SetValue(true); + else + radio_box->SetValue(false); + } } void SetBedTypeDialog::on_dpi_changed(const wxRect& suggested_rect) diff --git a/src/slic3r/GUI/SetBedTypeDialog.hpp b/src/slic3r/GUI/SetBedTypeDialog.hpp index 1fc9f60292..f54e5700e7 100644 --- a/src/slic3r/GUI/SetBedTypeDialog.hpp +++ b/src/slic3r/GUI/SetBedTypeDialog.hpp @@ -10,6 +10,18 @@ namespace Slic3r { namespace GUI { wxDECLARE_EVENT(EVT_SET_BED_TYPE_CONFIRM, wxCommandEvent); +class BedTypeRadioBox : public RadioBox +{ +public: + BedTypeRadioBox(wxWindow* parent, BedType bed_type) : RadioBox(parent), m_bed_type(bed_type) {} + + void SetBedType(BedType bed_type) { m_bed_type = bed_type; } + BedType GetBedType() { return m_bed_type; } + +private: + BedType m_bed_type{ BedType::btCount }; +}; + class SetBedTypeDialog : public DPIDialog { public: @@ -32,15 +44,16 @@ public: void on_dpi_changed(const wxRect& suggested_rect) override; protected: - wxWindow* m_cool_btn; - wxWindow* m_engineering_btn; - wxWindow* m_high_temp_btn; - wxWindow* m_texture_pei_btn; + BedTypeRadioBox* m_rb_default_plate{ nullptr }; + BedTypeRadioBox* m_rb_cool_plate{ nullptr }; + BedTypeRadioBox* m_rb_eng_plate{ nullptr }; + BedTypeRadioBox* m_rb_high_temp_plate{ nullptr }; + BedTypeRadioBox* m_rb_texture_pei_plate{ nullptr }; Button* m_button_ok; Button* m_button_cancel; - std::vector radio_buttons; + std::vector radio_buttons; - wxWindow * create_item_radiobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, int groupid, std::string param); + BedTypeRadioBox* create_item_radiobox(wxString title, wxWindow* parent, wxString tooltip, int padding_left, BedType bed_type); void select_curr_radiobox(int btn_idx); };