mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 15:51:10 -06:00
ENH: refine global bed type config logic
Add default type to plate bed types. Signed-off-by: yifan.wu <yifan.wu@bambulab.com> Change-Id: I26f3a64dba4a19b0d882b828f1ee54c84df1879c (cherry picked from commit 1ebed465d2b3bcd482dd4ba7a5930b721c79fc13)
This commit is contained in:
parent
3b3ad1b390
commit
d152b4d235
11 changed files with 109 additions and 100 deletions
|
@ -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<BedType>(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<BedType>(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<BedType>(bed_type));
|
||||
|
||||
m_config.set_key_value("curr_bed_type", new ConfigOptionEnum<BedType>(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<BedType>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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<std::string, Ams *> 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<BedType>(bed_type));
|
||||
if (new_bed_type != btCount) {
|
||||
BedType old_bed_type = proj_config.opt_enum<BedType>("curr_bed_type");
|
||||
proj_config.set_key_value("curr_bed_type", new ConfigOptionEnum<BedType>(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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<RadioBox*> radio_buttons;
|
||||
std::vector<BedTypeRadioBox*> 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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue