NEW: support to edit bed stl and texture for third-party printers

Jira:STUDIO-4209
some codes are referenced form PrusaSlicer,thanks enricoturri1966 for the original commit

commit cf380fb456
Author: enricoturri1966 <enricoturri@seznam.cz>
Date:   Tue Sep 21 13:51:57 2021 +0200
    Tech ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS - Out of bed detection for circular printbeds
...

Change-Id: I1b1e2ff045286566d4fb9f2d8ad4faa1f135f60c
(cherry picked from commit 284bca9f1f4cdb9eb405e8205cd50666a2b0b2a0)
This commit is contained in:
zhou.xu 2023-09-14 10:41:47 +08:00 committed by Lane.Wei
parent 384b0793ff
commit 487c86e915
11 changed files with 319 additions and 228 deletions

View file

@ -363,7 +363,8 @@ void PrintConfigDef::init_common_params()
def = this->add("printable_area", coPoints); def = this->add("printable_area", coPoints);
def->label = L("Printable area"); def->label = L("Printable area");
//BBS //BBS
def->mode = comDevelop; def->mode = comAdvanced;
def->gui_type = ConfigOptionDef::GUIType::one_string;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0), Vec2d(200, 0), Vec2d(200, 200), Vec2d(0, 200) }); def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0), Vec2d(200, 0), Vec2d(200, 200), Vec2d(0, 200) });
//BBS: add "bed_exclude_area" //BBS: add "bed_exclude_area"
@ -378,11 +379,13 @@ void PrintConfigDef::init_common_params()
def = this->add("bed_custom_texture", coString); def = this->add("bed_custom_texture", coString);
def->label = L("Bed custom texture"); def->label = L("Bed custom texture");
def->mode = comAdvanced; def->mode = comAdvanced;
def->gui_type = ConfigOptionDef::GUIType::one_string;
def->set_default_value(new ConfigOptionString("")); def->set_default_value(new ConfigOptionString(""));
def = this->add("bed_custom_model", coString); def = this->add("bed_custom_model", coString);
def->label = L("Bed custom model"); def->label = L("Bed custom model");
def->mode = comAdvanced; def->mode = comAdvanced;
def->gui_type = ConfigOptionDef::GUIType::one_string;
def->set_default_value(new ConfigOptionString("")); def->set_default_value(new ConfigOptionString(""));
def = this->add("elefant_foot_compensation", coFloat); def = this->add("elefant_foot_compensation", coFloat);
@ -2341,7 +2344,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Nozzle volume"); def->label = L("Nozzle volume");
def->tooltip = L("Volume of nozzle between the cutter and the end of nozzle"); def->tooltip = L("Volume of nozzle between the cutter and the end of nozzle");
def->sidetext = L("mm³"); def->sidetext = L("mm³");
def->mode = comDevelop; def->mode = comAdvanced;
def->readonly = true; def->readonly = true;
def->set_default_value(new ConfigOptionFloat { 0.0 }); def->set_default_value(new ConfigOptionFloat { 0.0 });

View file

@ -920,6 +920,8 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
//BBS: add bed_exclude_area //BBS: add bed_exclude_area
((ConfigOptionPoints, bed_exclude_area)) ((ConfigOptionPoints, bed_exclude_area))
// BBS // BBS
((ConfigOptionString, bed_custom_texture))
((ConfigOptionString, bed_custom_model))
((ConfigOptionEnum<BedType>, curr_bed_type)) ((ConfigOptionEnum<BedType>, curr_bed_type))
((ConfigOptionInts, cool_plate_temp)) ((ConfigOptionInts, cool_plate_temp))
((ConfigOptionInts, eng_plate_temp)) ((ConfigOptionInts, eng_plate_temp))

View file

@ -34,11 +34,12 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
// On MacOS the background is erased, on Windows the background is not erased // On MacOS the background is erased, on Windows the background is not erased
// and on Linux / GTK the background is erased to gray color. // and on Linux / GTK the background is erased to gray color.
// Fill DC with the background on Windows & Linux / GTK. // Fill DC with the background on Windows & Linux / GTK.
#ifdef _WIN32 wxColour color;
auto color = wxGetApp().get_highlight_default_clr(); if (wxGetApp().dark_mode()) {// SetBackgroundColour
#else color = wxColour(45, 45, 49);
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour } else {
#endif color = *wxWHITE;
}
dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID)); dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID));
dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID)); dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID));
auto rect = GetUpdateRegion().GetBox(); auto rect = GetUpdateRegion().GetBox();

View file

@ -35,7 +35,7 @@ static std::string get_option_label(BedShape::Parameter param)
} }
} }
void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter param) void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter param, bool can_edit)
{ {
ConfigOptionDef def; ConfigOptionDef def;
t_config_option_key key; t_config_option_key key;
@ -47,6 +47,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para
def.max = 1200; def.max = 1200;
def.label = get_option_label(param); def.label = get_option_label(param);
def.tooltip = L("Size in X and Y of the rectangular plate."); def.tooltip = L("Size in X and Y of the rectangular plate.");
def.readonly = !can_edit;
key = "rect_size"; key = "rect_size";
break; break;
case Parameter::RectOrigin: case Parameter::RectOrigin:
@ -56,6 +57,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para
def.max = 600; def.max = 600;
def.label = get_option_label(param); def.label = get_option_label(param);
def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
def.readonly = !can_edit;
key = "rect_origin"; key = "rect_origin";
break; break;
case Parameter::Diameter: case Parameter::Diameter:
@ -64,6 +66,7 @@ void BedShape::append_option_line(ConfigOptionsGroupShp optgroup, Parameter para
def.sidetext = L("mm"); def.sidetext = L("mm");
def.label = get_option_label(param); def.label = get_option_label(param);
def.tooltip = L("Diameter of the print bed. It is assumed that origin (0,0) is located in the center."); def.tooltip = L("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
def.readonly = !can_edit;
key = "diameter"; key = "diameter";
break; break;
default: default:
@ -128,22 +131,23 @@ void BedShape::apply_optgroup_values(ConfigOptionsGroupShp optgroup)
} }
} }
void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model) void BedShapeDialog::build_dialog(const ConfigOptionPoints &default_pt, const ConfigOptionString &custom_texture, const ConfigOptionString &custom_model, bool can_edit)
{ {
SetFont(wxGetApp().normal_font()); SetFont(wxGetApp().normal_font());
this->SetBackgroundColour(*wxWHITE);
m_panel = new BedShapePanel(this); m_panel = new BedShapePanel(this);
m_panel->set_edit_state(can_edit);
m_panel->build_panel(default_pt, custom_texture, custom_model); m_panel->build_panel(default_pt, custom_texture, custom_model);
auto main_sizer = new wxBoxSizer(wxVERTICAL); auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_panel, 1, wxEXPAND); main_sizer->Add(m_panel, 1, wxEXPAND);
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
wxGetApp().UpdateDlgDarkUI(this); wxGetApp().UpdateDlgDarkUI(this);
SetSizer(main_sizer); SetSizer(main_sizer);
SetMinSize(GetSize()); SetMinSize(GetSize());
main_sizer->SetSizeHints(this); main_sizer->SetSizeHints(this);
this->Bind(wxEVT_CLOSE_WINDOW, ([this](wxCloseEvent& evt) { this->Bind(wxEVT_CLOSE_WINDOW, ([this](wxCloseEvent& evt) {
EndModal(wxID_CANCEL); EndModal(wxID_CANCEL);
@ -178,6 +182,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape")); auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Shape"));
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font()); sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());
sbsizer->GetStaticBox()->Enable(m_can_edit);
wxGetApp().UpdateDarkUI(sbsizer->GetStaticBox()); wxGetApp().UpdateDarkUI(sbsizer->GetStaticBox());
// shape options // shape options
@ -187,13 +192,12 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
sbsizer->Add(m_shape_options_book); sbsizer->Add(m_shape_options_book);
auto optgroup = init_shape_options_page(BedShape::get_name(BedShape::PageType::Rectangle)); auto optgroup = init_shape_options_page(BedShape::get_name(BedShape::PageType::Rectangle));
BedShape::append_option_line(optgroup, BedShape::Parameter::RectSize); BedShape::append_option_line(optgroup, BedShape::Parameter::RectSize,m_can_edit);
// BBS hide // BBS hide
//BedShape::append_option_line(optgroup, BedShape::Parameter::RectOrigin); BedShape::append_option_line(optgroup, BedShape::Parameter::RectOrigin, m_can_edit);
activate_options_page(optgroup); activate_options_page(optgroup);
// BBS hide // BBS hide
/* optgroup = init_shape_options_page(BedShape::get_name(BedShape::PageType::Circle)); /* optgroup = init_shape_options_page(BedShape::get_name(BedShape::PageType::Circle));
BedShape::append_option_line(optgroup, BedShape::Parameter::Diameter); BedShape::append_option_line(optgroup, BedShape::Parameter::Diameter);
activate_options_page(optgroup); activate_options_page(optgroup);
@ -219,9 +223,6 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
wxPanel* texture_panel = init_texture_panel(); wxPanel* texture_panel = init_texture_panel();
wxPanel* model_panel = init_model_panel(); wxPanel* model_panel = init_model_panel();
// BBS hide
texture_panel->Hide();
model_panel->Hide();
Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent& e) { update_shape(); })); Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent& e) { update_shape(); }));
@ -251,6 +252,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& title) ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& title)
{ {
wxPanel* panel = new wxPanel(m_shape_options_book); wxPanel* panel = new wxPanel(m_shape_options_book);
panel->SetBackgroundColour(*wxWHITE);
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Settings")); ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Settings"));
optgroup->label_width = 10; optgroup->label_width = 10;
@ -271,83 +273,64 @@ void BedShapePanel::activate_options_page(ConfigOptionsGroupShp options_group)
options_group->parent()->SetSizerAndFit(options_group->sizer); options_group->parent()->SetSizerAndFit(options_group->sizer);
} }
wxPanel* BedShapePanel::init_texture_panel() wxPanel *BedShapePanel::init_texture_panel()
{ {
wxPanel* panel = new wxPanel(this); wxPanel *panel = new wxPanel(this);
panel->SetBackgroundColour(*wxWHITE); wxGetApp().UpdateDarkUI(panel, true);
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Texture")); ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Texture"));
optgroup->label_width = 10; optgroup->label_width = 10;
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); };
update_shape();
};
Line line{ "", "" }; Line line{"", ""};
line.full_width = 1; line.full_width = 1;
line.widget = [this](wxWindow* parent) { line.widget = [this](wxWindow *parent) {
wxButton *load_btn = new wxButton(parent, wxID_ANY, _L("Load..."));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Disabled), std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), load_btn->Enable(m_can_edit);
std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Hovered), wxSizer * load_sizer = new wxBoxSizer(wxHORIZONTAL);
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
StateColor btn_bd_white(std::pair<wxColour, int>(*wxWHITE, StateColor::Disabled), std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Enabled));
Button* load_btn = new Button(parent, _L("Load..."));
load_btn->SetBackgroundColor(btn_bg_white);
load_btn->SetBorderColor(btn_bd_white);
load_btn->SetBackgroundColour(*wxWHITE);
wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL);
load_sizer->Add(load_btn, 1, wxEXPAND); load_sizer->Add(load_btn, 1, wxEXPAND);
wxStaticText* filename_lbl = new wxStaticText(parent, wxID_ANY, _(NONE)); wxStaticText *filename_lbl = new wxStaticText(parent, wxID_ANY, _(NONE));
wxSizer* filename_sizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *filename_sizer = new wxBoxSizer(wxHORIZONTAL);
filename_sizer->Add(filename_lbl, 1, wxEXPAND); filename_sizer->Add(filename_lbl, 1, wxEXPAND);
Button* remove_btn = new Button(parent, _L("Remove")); wxButton *remove_btn = new wxButton(parent, wxID_ANY, _L("Remove"));
remove_btn->SetBackgroundColor(btn_bg_white); wxSizer * remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_btn->SetBorderColor(btn_bd_white);
remove_btn->SetBackgroundColour(*wxWHITE);
wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_sizer->Add(remove_btn, 1, wxEXPAND); remove_sizer->Add(remove_btn, 1, wxEXPAND);
wxGetApp().UpdateDarkUI(load_btn); wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxGetApp().UpdateDarkUI(remove_btn);
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(filename_sizer, 1, wxEXPAND); sizer->Add(filename_sizer, 1, wxEXPAND);
sizer->Add(load_sizer, 1, wxEXPAND); sizer->Add(load_sizer, 1, wxEXPAND);
sizer->Add(remove_sizer, 1, wxEXPAND | wxTOP, 2); sizer->Add(remove_sizer, 1, wxEXPAND | wxTOP, 2);
load_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e) { load_texture(); })); load_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_texture(); }));
remove_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e) { remove_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) {
m_custom_texture = NONE; m_custom_texture = NONE;
update_shape(); update_shape();
})); }));
filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent& e) { filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) {
e.SetText(_(boost::filesystem::path(m_custom_texture).filename().string())); e.SetText(_(boost::filesystem::path(m_custom_texture).filename().string()));
wxStaticText* lbl = dynamic_cast<wxStaticText*>(e.GetEventObject()); wxStaticText *lbl = dynamic_cast<wxStaticText *>(e.GetEventObject());
if (lbl != nullptr) { if (lbl != nullptr) {
bool exists = (m_custom_texture == NONE) || boost::filesystem::exists(m_custom_texture); bool exists = (m_custom_texture == NONE) || boost::filesystem::exists(m_custom_texture);
lbl->SetForegroundColour(exists ? /*wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)*/wxGetApp().get_label_clr_default() : wxColor(*wxRED)); lbl->SetForegroundColour(exists ? wxGetApp().get_label_clr_default() : wxColor(*wxRED));
wxString tooltip_text = ""; wxString tooltip_text = "";
if (m_custom_texture != NONE) { if (m_custom_texture != NONE) {
if (!exists) if (!exists) tooltip_text += _L("Not found:") + " ";
tooltip_text += _L("Not found:") + " ";
tooltip_text += _(m_custom_texture); tooltip_text += _(m_custom_texture);
} }
wxToolTip* tooltip = lbl->GetToolTip(); wxToolTip *tooltip = lbl->GetToolTip();
if ((tooltip == nullptr) || (tooltip->GetTip() != tooltip_text)) if ((tooltip == nullptr) || (tooltip->GetTip() != tooltip_text)) lbl->SetToolTip(tooltip_text);
lbl->SetToolTip(tooltip_text); }
} }));
}));
remove_btn->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent& e) { e.Enable(m_custom_texture != NONE); }));
remove_btn->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) { e.Enable(m_custom_texture != NONE); }));
parent->SetBackgroundColour(*wxWHITE);
return sizer; return sizer;
}; };
optgroup->append_line(line); optgroup->append_line(line);
@ -358,84 +341,64 @@ wxPanel* BedShapePanel::init_texture_panel()
return panel; return panel;
} }
wxPanel* BedShapePanel::init_model_panel() wxPanel *BedShapePanel::init_model_panel()
{ {
wxPanel* panel = new wxPanel(this); wxPanel *panel = new wxPanel(this);
panel->SetBackgroundColour(*wxWHITE); wxGetApp().UpdateDarkUI(panel, true);
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Model")); ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Model"));
optgroup->label_width = 10; optgroup->label_width = 10;
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { update_shape(); };
update_shape();
};
Line line{"", ""};
Line line{ "", "" };
line.full_width = 1; line.full_width = 1;
line.widget = [this](wxWindow* parent) { line.widget = [this](wxWindow *parent) {
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Disabled), std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), wxButton *load_btn = new wxButton(parent, wxID_ANY, _L("Load..."));
std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Hovered), load_btn->Enable(m_can_edit);
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal)); wxSizer * load_sizer = new wxBoxSizer(wxHORIZONTAL);
StateColor btn_bd_white(std::pair<wxColour, int>(*wxWHITE, StateColor::Disabled), std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Enabled));
Button* load_btn = new Button(parent, _L("Load..."));
load_btn->SetBackgroundColor(btn_bg_white);
load_btn->SetBorderColor(btn_bd_white);
load_btn->SetBackgroundColour(*wxWHITE);
wxSizer* load_sizer = new wxBoxSizer(wxHORIZONTAL);
load_sizer->Add(load_btn, 1, wxEXPAND); load_sizer->Add(load_btn, 1, wxEXPAND);
wxStaticText* filename_lbl = new wxStaticText(parent, wxID_ANY, _(NONE)); wxStaticText *filename_lbl = new wxStaticText(parent, wxID_ANY, _(NONE));
wxSizer* filename_sizer = new wxBoxSizer(wxHORIZONTAL); wxSizer * filename_sizer = new wxBoxSizer(wxHORIZONTAL);
filename_sizer->Add(filename_lbl, 1, wxEXPAND); filename_sizer->Add(filename_lbl, 1, wxEXPAND);
Button* remove_btn = new Button(parent, _L("Remove")); wxButton *remove_btn = new wxButton(parent, wxID_ANY, _L("Remove"));
remove_btn->SetBackgroundColor(btn_bg_white); wxSizer * remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_btn->SetBorderColor(btn_bd_white);
remove_btn->SetBackgroundColour(*wxWHITE);
wxSizer* remove_sizer = new wxBoxSizer(wxHORIZONTAL);
remove_sizer->Add(remove_btn, 1, wxEXPAND); remove_sizer->Add(remove_btn, 1, wxEXPAND);
wxGetApp().UpdateDarkUI(load_btn); wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxGetApp().UpdateDarkUI(remove_btn);
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(filename_sizer, 1, wxEXPAND); sizer->Add(filename_sizer, 1, wxEXPAND);
sizer->Add(load_sizer, 1, wxEXPAND); sizer->Add(load_sizer, 1, wxEXPAND);
sizer->Add(remove_sizer, 1, wxEXPAND | wxTOP, 2); sizer->Add(remove_sizer, 1, wxEXPAND | wxTOP, 2);
load_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e) { load_model(); })); load_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_model(); }));
remove_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e) { remove_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) {
m_custom_model = NONE; m_custom_model = NONE;
update_shape(); update_shape();
})); }));
filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent& e) { filename_lbl->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) {
e.SetText(_(boost::filesystem::path(m_custom_model).filename().string())); e.SetText(_(boost::filesystem::path(m_custom_model).filename().string()));
wxStaticText* lbl = dynamic_cast<wxStaticText*>(e.GetEventObject()); wxStaticText *lbl = dynamic_cast<wxStaticText *>(e.GetEventObject());
if (lbl != nullptr) { if (lbl != nullptr) {
bool exists = (m_custom_model == NONE) || boost::filesystem::exists(m_custom_model); bool exists = (m_custom_model == NONE) || boost::filesystem::exists(m_custom_model);
lbl->SetForegroundColour(exists ? /*wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)*/wxGetApp().get_label_clr_default() : wxColor(*wxRED)); lbl->SetForegroundColour(exists ? wxGetApp().get_label_clr_default() : wxColor(*wxRED));
wxString tooltip_text = ""; wxString tooltip_text = "";
if (m_custom_model != NONE) { if (m_custom_model != NONE) {
if (!exists) if (!exists) tooltip_text += _L("Not found:") + " ";
tooltip_text += _L("Not found:") + " ";
tooltip_text += _(m_custom_model); tooltip_text += _(m_custom_model);
} }
wxToolTip* tooltip = lbl->GetToolTip(); wxToolTip *tooltip = lbl->GetToolTip();
if ((tooltip == nullptr) || (tooltip->GetTip() != tooltip_text)) if ((tooltip == nullptr) || (tooltip->GetTip() != tooltip_text)) lbl->SetToolTip(tooltip_text);
lbl->SetToolTip(tooltip_text); }
} }));
}));
remove_btn->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent& e) { e.Enable(m_custom_model != NONE); }));
remove_btn->Bind(wxEVT_UPDATE_UI, ([this](wxUpdateUIEvent &e) { e.Enable(m_custom_model != NONE); }));
parent->SetBackgroundColour(*wxWHITE);
return sizer; return sizer;
}; };
optgroup->append_line(line); optgroup->append_line(line);
@ -480,34 +443,46 @@ void BedShapePanel::update_shape()
auto opt_group = m_optgroups[page_idx]; auto opt_group = m_optgroups[page_idx];
switch (static_cast<BedShape::PageType>(page_idx)) { switch (static_cast<BedShape::PageType>(page_idx)) {
case BedShape::PageType::Rectangle: case BedShape::PageType::Rectangle: {
{ m_is_valid = true;
Vec2d rect_size(Vec2d::Zero()); Vec2d rect_size(Vec2d::Zero());
Vec2d rect_origin(Vec2d::Zero()); Vec2d rect_origin(Vec2d::Zero());
try { rect_size = boost::any_cast<Vec2d>(opt_group->get_value("rect_size")); } try {
catch (const std::exception& /* e */) { return; } rect_size = boost::any_cast<Vec2d>(opt_group->get_value("rect_size"));
} catch (const std::exception & /* e */) {
return;
}
// BBS // BBS
//try { rect_origin = boost::any_cast<Vec2d>(opt_group->get_value("rect_origin")); } try {
//catch (const std::exception & /* e */) { return; } rect_origin = boost::any_cast<Vec2d>(opt_group->get_value("rect_origin"));
} catch (const std::exception & /* e */) {
return;
}
auto x = rect_size(0); auto x = rect_size(0);
auto y = rect_size(1); auto y = rect_size(1);
// empty strings or '-' or other things // empty strings or '-' or other things
if (x == 0 || y == 0) return; if (x == 0 || y == 0) {
double x0 = 0.0; m_is_valid = false;
double y0 = 0.0; return;
double x1 = x; }
double y1 = y; double x0 = 0.0;
double y0 = 0.0;
double x1 = x;
double y1 = y;
auto dx = rect_origin(0); auto dx = rect_origin(0);
auto dy = rect_origin(1); auto dy = rect_origin(1);
if (dx >= x || dy >= y) {
x0 -= dx; m_is_valid = false;
x1 -= dx; return;
y0 -= dy; }
y1 -= dy; x0 -= dx;
x1 -= dx;
y0 -= dy;
y1 -= dy;
m_shape = { Vec2d(x0, y0), m_shape = { Vec2d(x0, y0),
Vec2d(x1, y0), Vec2d(x1, y0),
Vec2d(x1, y1), Vec2d(x1, y1),

View file

@ -37,7 +37,7 @@ struct BedShape
bool is_custom() { return m_build_volume.type() == BuildVolume::Type::Convex || m_build_volume.type() == BuildVolume::Type::Custom; } bool is_custom() { return m_build_volume.type() == BuildVolume::Type::Convex || m_build_volume.type() == BuildVolume::Type::Custom; }
static void append_option_line(ConfigOptionsGroupShp optgroup, Parameter param); static void append_option_line(ConfigOptionsGroupShp optgroup, Parameter param,bool can_edit);
static wxString get_name(PageType type); static wxString get_name(PageType type);
PageType get_page_type(); PageType get_page_type();
@ -59,6 +59,8 @@ class BedShapePanel : public wxPanel
std::vector<Vec2d> m_loaded_shape; std::vector<Vec2d> m_loaded_shape;
std::string m_custom_texture; std::string m_custom_texture;
std::string m_custom_model; std::string m_custom_model;
bool m_is_valid{true};
bool m_can_edit{true};
public: public:
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {} BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {}
@ -69,6 +71,8 @@ public:
const std::vector<Vec2d>& get_shape() const { return m_shape; } const std::vector<Vec2d>& get_shape() const { return m_shape; }
const std::string& get_custom_texture() const { return (m_custom_texture != NONE) ? m_custom_texture : EMPTY_STRING; } const std::string& get_custom_texture() const { return (m_custom_texture != NONE) ? m_custom_texture : EMPTY_STRING; }
const std::string& get_custom_model() const { return (m_custom_model != NONE) ? m_custom_model : EMPTY_STRING; } const std::string& get_custom_model() const { return (m_custom_model != NONE) ? m_custom_model : EMPTY_STRING; }
bool get_valid() { return m_is_valid; }
void set_edit_state(bool flag) { m_can_edit = flag; }
private: private:
ConfigOptionsGroupShp init_shape_options_page(const wxString& title); ConfigOptionsGroupShp init_shape_options_page(const wxString& title);
@ -91,16 +95,18 @@ private:
class BedShapeDialog : public DPIDialog class BedShapeDialog : public DPIDialog
{ {
BedShapePanel* m_panel; BedShapePanel* m_panel;
public: public:
BedShapeDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _(L("Bed Shape")), BedShapeDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _(L("Bed Shape")),
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {} wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {}
void build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model); void build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model,bool can_edit);
const std::vector<Vec2d>& get_shape() const { return m_panel->get_shape(); } const std::vector<Vec2d>& get_shape() const { return m_panel->get_shape(); }
const std::string& get_custom_texture() const { return m_panel->get_custom_texture(); } const std::string& get_custom_texture() const { return m_panel->get_custom_texture(); }
const std::string& get_custom_model() const { return m_panel->get_custom_model(); } const std::string& get_custom_model() const { return m_panel->get_custom_model(); }
bool get_valid() { return m_panel->get_valid(); }
protected: protected:
void on_dpi_changed(const wxRect &suggested_rect) override; void on_dpi_changed(const wxRect &suggested_rect) override;
}; };

View file

@ -1,5 +1,5 @@
#include "CreatePresetsDialog.hpp" #include "CreatePresetsDialog.hpp"
#include <regex>
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
@ -1237,7 +1237,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_bed_size_item(wxWindow *parent)
length_sizer->Add(static_length_text, 0, wxEXPAND | wxALL, 0); length_sizer->Add(static_length_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_size_x_input = new TextInput(parent, wxEmptyString, "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER); m_bed_size_x_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS); wxTextValidator validator(wxFILTER_DIGITS);
m_bed_size_x_input->GetTextCtrl()->SetValidator(validator); m_bed_size_x_input->GetTextCtrl()->SetValidator(validator);
length_input_sizer->Add(m_bed_size_x_input, 0, wxEXPAND | wxALL, 0); length_input_sizer->Add(m_bed_size_x_input, 0, wxEXPAND | wxALL, 0);
@ -1250,7 +1250,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_bed_size_item(wxWindow *parent)
width_sizer->Add(static_width_text, 0, wxEXPAND | wxALL, 0); width_sizer->Add(static_width_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_size_y_input = new TextInput(parent, wxEmptyString, "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER); m_bed_size_y_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_bed_size_y_input->GetTextCtrl()->SetValidator(validator); m_bed_size_y_input->GetTextCtrl()->SetValidator(validator);
width_input_sizer->Add(m_bed_size_y_input, 0, wxEXPAND | wxALL, 0); width_input_sizer->Add(m_bed_size_y_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5)); horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
@ -1276,7 +1276,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_origin_item(wxWindow *parent)
length_sizer->Add(static_origin_x_text, 0, wxEXPAND | wxALL, 0); length_sizer->Add(static_origin_x_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_origin_x_input = new TextInput(parent, wxEmptyString, "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER); m_bed_origin_x_input = new TextInput(parent, "0", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS); wxTextValidator validator(wxFILTER_DIGITS);
m_bed_origin_x_input->GetTextCtrl()->SetValidator(validator); m_bed_origin_x_input->GetTextCtrl()->SetValidator(validator);
length_input_sizer->Add(m_bed_origin_x_input, 0, wxEXPAND | wxALL, 0); length_input_sizer->Add(m_bed_origin_x_input, 0, wxEXPAND | wxALL, 0);
@ -1289,7 +1289,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_origin_item(wxWindow *parent)
width_sizer->Add(static_origin_y_text, 0, wxEXPAND | wxALL, 0); width_sizer->Add(static_origin_y_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_origin_y_input = new TextInput(parent, wxEmptyString, "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER); m_bed_origin_y_input = new TextInput(parent, "0", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_bed_origin_y_input->GetTextCtrl()->SetValidator(validator); m_bed_origin_y_input->GetTextCtrl()->SetValidator(validator);
width_input_sizer->Add(m_bed_origin_y_input, 0, wxEXPAND | wxALL, 0); width_input_sizer->Add(m_bed_origin_y_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5)); horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
@ -1316,6 +1316,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_hot_bed_stl_item(wxWindow *parent)
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal)); std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
m_button_bed_stl = new Button(parent, _L("Upload")); m_button_bed_stl = new Button(parent, _L("Upload"));
m_button_bed_stl->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_model_stl(); }));
m_button_bed_stl->SetFont(Label::Body_10); m_button_bed_stl->SetFont(Label::Body_10);
m_button_bed_stl->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8))); m_button_bed_stl->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8)));
@ -1349,6 +1350,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_hot_bed_svg_item(wxWindow *parent)
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal)); std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
m_button_bed_svg = new Button(parent, _L("Upload")); m_button_bed_svg = new Button(parent, _L("Upload"));
m_button_bed_svg->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_texture(); }));
m_button_bed_svg->SetFont(Label::Body_10); m_button_bed_svg->SetFont(Label::Body_10);
m_button_bed_svg->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8))); m_button_bed_svg->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8)));
@ -1374,7 +1376,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_max_print_height_item(wxWindow *pa
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *hight_input_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hight_input_sizer = new wxBoxSizer(wxVERTICAL);
m_print_height_input = new TextInput(parent, wxEmptyString, "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER); m_print_height_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS); wxTextValidator validator(wxFILTER_DIGITS);
m_print_height_input->GetTextCtrl()->SetValidator(validator); m_print_height_input->GetTextCtrl()->SetValidator(validator);
hight_input_sizer->Add(m_print_height_input, 0, wxEXPAND | wxLEFT, FromDIP(5)); hight_input_sizer->Add(m_print_height_input, 0, wxEXPAND | wxLEFT, FromDIP(5));
@ -1402,6 +1404,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page1_btns_item(wxWindow *parent)
bSizer_button->Add(m_button_OK, 0, wxRIGHT, FromDIP(10)); bSizer_button->Add(m_button_OK, 0, wxRIGHT, FromDIP(10));
m_button_OK->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { m_button_OK->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
if (!validate_input_valid()) return;
data_init(); data_init();
show_page2(); show_page2();
}); });
@ -1422,6 +1425,39 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page1_btns_item(wxWindow *parent)
return bSizer_button; return bSizer_button;
} }
static std::string last_directory = "";
void CreatePrinterPresetDialog::load_texture() {
wxFileDialog dialog(this, _L("Choose a file to import bed texture from (PNG/SVG):"), last_directory, "", file_wildcards(FT_TEX), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_OK)
return;
m_custom_texture = "";
last_directory = dialog.GetDirectory().ToUTF8().data();
std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::algorithm::iends_with(file_name, ".png") && !boost::algorithm::iends_with(file_name, ".svg")) {
show_error(this, _L("Invalid file format."));
return;
}
m_custom_texture = file_name;
}
void CreatePrinterPresetDialog::load_model_stl()
{
wxFileDialog dialog(this, _L("Choose an STL file to import bed model from:"), last_directory, "", file_wildcards(FT_STL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_OK)
return;
m_custom_model = "";
last_directory = dialog.GetDirectory().ToUTF8().data();
std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::algorithm::iends_with(file_name, ".stl")) {
show_error(this, _L("Invalid file format."));
return;
}
m_custom_model = file_name;
}
wxBoxSizer *CreatePrinterPresetDialog::create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list) wxBoxSizer *CreatePrinterPresetDialog::create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list)
{ {
@ -1676,7 +1712,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
bSizer_button->Add(m_button_create, 0, wxRIGHT, FromDIP(10)); bSizer_button->Add(m_button_create, 0, wxRIGHT, FromDIP(10));
m_button_create->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { m_button_create->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
if (!validate_input_valid()) return;
PresetBundle *preset_bundle = wxGetApp().preset_bundle; PresetBundle *preset_bundle = wxGetApp().preset_bundle;
wxString curr_selected_printer_type = curr_create_printer_type(); wxString curr_selected_printer_type = curr_create_printer_type();
wxString curr_selected_preset_type = curr_create_preset_type(); wxString curr_selected_preset_type = curr_create_preset_type();
@ -1700,16 +1736,8 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
} else { } else {
std::string vender_name = into_u8(m_select_vendor->GetStringSelection()); std::string vender_name = into_u8(m_select_vendor->GetStringSelection());
std::string model_name = into_u8(m_select_model->GetStringSelection()); std::string model_name = into_u8(m_select_model->GetStringSelection());
if (vender_name.empty() || model_name.empty()) {
MessageDialog dlg(this, _L("The printer and model are not selected, place return page 1 to select."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
show_page1();
return;
}
printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter; printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter;
} }
//Confirm if the printer preset exists //Confirm if the printer preset exists
if (!m_printer_preset) { if (!m_printer_preset) {
MessageDialog dlg(this, _L("You have not yet chosen which printer preset to create based on. Please choose the vendor and model of the printer"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), MessageDialog dlg(this, _L("You have not yet chosen which printer preset to create based on. Please choose the vendor and model of the printer"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
@ -1797,7 +1825,6 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
dlg.ShowModal(); dlg.ShowModal();
} }
} }
save_preset_config(m_printer_preset);
preset_bundle->printers.save_current_preset(printer_preset_name, true, false, m_printer_preset); preset_bundle->printers.save_current_preset(printer_preset_name, true, false, m_printer_preset);
preset_bundle->update_compatible(PresetSelectCompatibleType::Always); preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
} }
@ -2071,40 +2098,91 @@ void CreatePrinterPresetDialog::clear_preset_combobox()
m_process_preset_template_sizer->Clear(true); m_process_preset_template_sizer->Clear(true);
} }
void CreatePrinterPresetDialog::save_preset_config(Preset* preset) bool CreatePrinterPresetDialog::save_printable_area_config(Preset *preset)
{ {
DynamicPrintConfig &config = preset->config; DynamicPrintConfig &config = preset->config;
double prnite_area_x = 0; double x = 0;
m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&prnite_area_x); m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x);
double prnite_area_y = 0; double y = 0;
m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&prnite_area_y); m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y);
std::vector<Vec2d> points = {{0, 0}, {prnite_area_x, 0}, {prnite_area_x, prnite_area_y}, {0, prnite_area_y}}; double dx = 0;
m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx);
double dy = 0;
m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy);
//range check begin
if (x == 0 || y == 0) {
return false;
}
double x0 = 0.0;
double y0 = 0.0;
double x1 = x;
double y1 = y;
if (dx >= x || dy >= y) {
return false;
}
x0 -= dx;
x1 -= dx;
y0 -= dy;
y1 -= dy;
// range check end
std::vector<Vec2d> points = {Vec2d(x0, y0),
Vec2d(x1, y0),
Vec2d(x1, y1),
Vec2d(x0, y1)};
config.set_key_value("printable_area", new ConfigOptionPoints(points)); config.set_key_value("printable_area", new ConfigOptionPoints(points));
double max_print_height = 0; double max_print_height = 0;
m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height); m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height);
config.set("printable_height", max_print_height); config.set("printable_height", max_print_height);
std::regex regex("\\\\");
m_custom_model = std::regex_replace(m_custom_model, regex, "/");
m_custom_texture = std::regex_replace(m_custom_texture, regex, "/");
config.set("bed_custom_model", m_custom_model);
config.set("bed_custom_texture", m_custom_texture);
return true;
} }
bool CreatePrinterPresetDialog::validate_input_valid() bool CreatePrinterPresetDialog::validate_input_valid()
{ {
if (m_bed_size_x_input->GetTextCtrl()->GetValue().empty() || m_bed_size_y_input->GetTextCtrl()->GetValue().empty()) { if (m_bed_size_x_input->GetTextCtrl()->GetValue().empty() || m_bed_size_y_input->GetTextCtrl()->GetValue().empty()) {
MessageDialog dlg(this, _L("You did not entered in the printable area of the printer. Please return to page 1 to input."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), MessageDialog dlg(this, _L("You did not entered in the printable area of the printer."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE); wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal(); dlg.ShowModal();
show_page1();
return false; return false;
} }
if (m_print_height_input->GetTextCtrl()->GetValue().empty()) { if (m_print_height_input->GetTextCtrl()->GetValue().empty()) {
MessageDialog dlg(this, _L("You have not entered the maximum printing height of the printer. Please return to page 1 for input."), MessageDialog dlg(this, _L("You have not entered the maximum printing height of the printer."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE); wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal(); dlg.ShowModal();
show_page1();
return false; return false;
} }
std::string vender_name = into_u8(m_select_vendor->GetStringSelection());
std::string model_name = into_u8(m_select_model->GetStringSelection());
if (vender_name.empty() || model_name.empty()) {
MessageDialog dlg(this, _L("You have not selected the printer and model."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (m_custom_texture.empty()) {
MessageDialog dlg(this, _L("You have not upload bed texture."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (m_custom_model.empty()) {
MessageDialog dlg(this, _L("You have not upload bed model."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (save_printable_area_config(m_printer_preset) == false) {
MessageDialog dlg(this, _L("Please check bed shape input."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
return true; return true;
} }

View file

@ -100,8 +100,8 @@ protected:
wxBoxSizer *create_hot_bed_svg_item(wxWindow *parent); wxBoxSizer *create_hot_bed_svg_item(wxWindow *parent);
wxBoxSizer *create_max_print_height_item(wxWindow *parent); wxBoxSizer *create_max_print_height_item(wxWindow *parent);
wxBoxSizer *create_page1_btns_item(wxWindow *parent); wxBoxSizer *create_page1_btns_item(wxWindow *parent);
void load_texture();
void load_model_stl();
//Improt Presets Page2 //Improt Presets Page2
void create_printer_page2(wxWindow *parent); void create_printer_page2(wxWindow *parent);
wxBoxSizer *create_printer_preset_item(wxWindow *parent); wxBoxSizer *create_printer_preset_item(wxWindow *parent);
@ -120,7 +120,7 @@ protected:
void update_presets_list(); void update_presets_list();
void on_preset_model_value_change(wxCommandEvent &e); void on_preset_model_value_change(wxCommandEvent &e);
void clear_preset_combobox(); void clear_preset_combobox();
void save_preset_config(Preset *preset); bool save_printable_area_config(Preset *preset);
bool validate_input_valid(); bool validate_input_valid();
wxArrayString printer_preset_sort_with_nozzle_diameter(const VendorProfile &vendor_profile, float nozzle_diameter); wxArrayString printer_preset_sort_with_nozzle_diameter(const VendorProfile &vendor_profile, float nozzle_diameter);
@ -170,7 +170,8 @@ private:
wxPanel * m_filament_preset_panel = nullptr; wxPanel * m_filament_preset_panel = nullptr;
wxPanel * m_process_preset_panel = nullptr; wxPanel * m_process_preset_panel = nullptr;
wxPanel * m_preset_template_panel = nullptr; wxPanel * m_preset_template_panel = nullptr;
std::string m_custom_texture;
std::string m_custom_model;
}; };
enum SuccessType { enum SuccessType {

View file

@ -131,7 +131,9 @@ void Field::PostInitialize()
// For the mode, when settings are in non-modal dialog, neither dialog nor tabpanel doesn't receive wxEVT_KEY_UP event, when some field is selected. // For the mode, when settings are in non-modal dialog, neither dialog nor tabpanel doesn't receive wxEVT_KEY_UP event, when some field is selected.
// So, like a workaround check wxEVT_KEY_UP event for the Filed and switch between tabs if Ctrl+(1-4) was pressed // So, like a workaround check wxEVT_KEY_UP event for the Filed and switch between tabs if Ctrl+(1-4) was pressed
if (getWindow()) { if (getWindow()) {
if (m_opt.readonly) getWindow()->Disable(); if (m_opt.readonly) {
this->disable();
}
getWindow()->Bind(wxEVT_KEY_UP, [](wxKeyEvent& evt) { getWindow()->Bind(wxEVT_KEY_UP, [](wxKeyEvent& evt) {
if ((evt.GetModifiers() & wxMOD_CONTROL) != 0) { if ((evt.GetModifiers() & wxMOD_CONTROL) != 0) {
int tab_id = -1; int tab_id = -1;
@ -424,6 +426,12 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
continue; continue;
} }
} }
else if (m_opt_id == "printable_area") {
if (0 <= x && x <= 1000 && 0 <= y && y <= 1000) {
out_values.push_back(Vec2d(x, y));
continue;
}
}
else { else {
if (0 < x && x < 1000 && 0 < y && y < 1000) { if (0 < x && x < 1000 && 0 < y && y < 1000) {
out_values.push_back(Vec2d(x, y)); out_values.push_back(Vec2d(x, y));

View file

@ -233,26 +233,26 @@ void OptionsGroup::activate_line(Line& line)
m_use_custom_ctrl_as_parent = false; m_use_custom_ctrl_as_parent = false;
if (line.full_width && ( if (line.full_width && (
line.widget != nullptr || line.widget != nullptr ||
!line.get_extra_widgets().empty()) !line.get_extra_widgets().empty())
) { ) {
// BBS: new layout // BBS: new layout
const auto h_sizer = new wxBoxSizer(wxHORIZONTAL); const auto h_sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(h_sizer, 1, wxEXPAND | wxALL, wxOSX ? 0 : 15); sizer->Add(h_sizer, 1, wxEXPAND | wxALL, wxOSX ? 0 : 15);
if (line.widget != nullptr) { if (line.widget != nullptr) {
// description lines // description lines
h_sizer->Add(line.widget(this->ctrl_parent()), 0, wxEXPAND | wxLEFT, titleWidth * wxGetApp().em_unit()); sizer->Add(line.widget(this->ctrl_parent()), 0, wxEXPAND | wxALL, wxOSX ? 0 : 15);
return; return;
} }
if (!line.get_extra_widgets().empty()) { if (!line.get_extra_widgets().empty()) {
bool is_first_item = true; bool is_first_item = true;
for (auto extra_widget : line.get_extra_widgets()) { for (auto extra_widget : line.get_extra_widgets()) {
h_sizer->Add(extra_widget(this->ctrl_parent()), is_first_item ? 1 : 0, wxLEFT, titleWidth * wxGetApp().em_unit()); h_sizer->Add(extra_widget(this->ctrl_parent()), is_first_item ? 1 : 0, wxLEFT, titleWidth * wxGetApp().em_unit());
is_first_item = false; is_first_item = false;
} }
return; return;
} }
} }
auto option_set = line.get_options(); auto option_set = line.get_options();
@ -1038,7 +1038,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
break; break;
case coPoints: case coPoints:
if (opt_key == "printable_area") if (opt_key == "printable_area")
ret = config.option<ConfigOptionPoints>(opt_key)->values; ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values);
else if (opt_key == "bed_exclude_area") else if (opt_key == "bed_exclude_area")
ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values); ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values);
else if (opt_key == "thumbnail_size") else if (opt_key == "thumbnail_size")
@ -1153,7 +1153,7 @@ boost::any ConfigOptionsGroup::get_config_value2(const DynamicPrintConfig& confi
break; break;
case coPoints: case coPoints:
if (opt_key == "printable_area") if (opt_key == "printable_area")
ret = config.option<ConfigOptionPoints>(opt_key)->values; ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values);
else if (opt_key == "bed_exclude_area") else if (opt_key == "bed_exclude_area")
ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values); ret = get_thumbnails_string(config.option<ConfigOptionPoints>(opt_key)->values);
else if (opt_key == "thumbnail_size") else if (opt_key == "thumbnail_size")

View file

@ -588,6 +588,11 @@ Sidebar::Sidebar(Plater *parent)
if (wxID_OK == res) { if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui(); wxGetApp().mainframe->update_side_preset_ui();
update_all_preset_comboboxes(); update_all_preset_comboboxes();
Tab *printer_tab = wxGetApp().get_tab(Preset::TYPE_PRINTER);
if (printer_tab) {
printer_tab->load_current_preset();
printer_tab->update();
}
CreatePresetSuccessfulDialog success_dlg(p->m_panel_filament_title, SuccessType::PRINTER); CreatePresetSuccessfulDialog success_dlg(p->m_panel_filament_title, SuccessType::PRINTER);
int res = success_dlg.ShowModal(); int res = success_dlg.ShowModal();
if (res == wxID_OK) { if (res == wxID_OK) {

View file

@ -3692,7 +3692,7 @@ void TabPrinter::toggle_options()
// toggle_option("change_filament_gcode", have_multiple_extruders); // toggle_option("change_filament_gcode", have_multiple_extruders);
//} //}
if (m_active_page->title() == "Basic information") { if (m_active_page->title() == "Basic information") {
toggle_line("printable_area", !is_BBL_printer); //toggle_line("printable_area", !is_configed_by_BBL);//all printer can entry and view data
toggle_option("single_extruder_multi_material", have_multiple_extruders); toggle_option("single_extruder_multi_material", have_multiple_extruders);
//BBS: gcode_flavore of BBL printer can't be edited and changed //BBS: gcode_flavore of BBL printer can't be edited and changed
toggle_option("gcode_flavor", !is_BBL_printer); toggle_option("gcode_flavor", !is_BBL_printer);
@ -4945,16 +4945,26 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL); sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL);
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) {
{ bool is_configed_by_BBL = PresetUtils::system_printer_bed_model(m_preset_bundle->printers.get_edited_preset()).size() > 0;
BedShapeDialog dlg(this); BedShapeDialog dlg(this);
dlg.build_dialog(*m_config->option<ConfigOptionPoints>("printable_area"), {}, {}); dlg.build_dialog(*m_config->option<ConfigOptionPoints>("printable_area"),
if (dlg.ShowModal() == wxID_OK) { *m_config->option<ConfigOptionString>("bed_custom_texture"),
const std::vector<Vec2d>& shape = dlg.get_shape(); *m_config->option<ConfigOptionString>("bed_custom_model") , !is_configed_by_BBL);
if (!shape.empty()) if (dlg.ShowModal() == wxID_OK && !is_configed_by_BBL) {
{ if (dlg.get_valid()) {
load_key_value("printable_area", shape); const std::vector<Vec2d> &shape = dlg.get_shape();
update_changed_ui(); const std::string & custom_texture = dlg.get_custom_texture();
const std::string & custom_model = dlg.get_custom_model();
if (!shape.empty()) {
load_key_value("printable_area", shape);
load_key_value("bed_custom_texture", custom_texture);
load_key_value("bed_custom_model", custom_model);
update_changed_ui();
}
} else {
show_error(m_parent, _L("Invalid input."));
} }
} }
})); }));
@ -4962,6 +4972,8 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
{ {
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher(); Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
const Search::GroupAndCategory& gc = searcher.get_group_and_category("printable_area"); const Search::GroupAndCategory& gc = searcher.get_group_and_category("printable_area");
searcher.add_key("bed_custom_texture", m_type, gc.group, gc.category);
searcher.add_key("bed_custom_model", m_type, gc.group, gc.category);
} }
return sizer; return sizer;