update bed exclude area

This commit is contained in:
QIDI TECH
2023-12-30 11:17:23 +08:00
parent bb8113dee9
commit ce07369753
11 changed files with 110 additions and 71 deletions

View File

@@ -529,7 +529,7 @@ static std::vector<std::string> s_Preset_printer_options {
"remaining_times", "silent_mode",
"machine_limits_usage", "thumbnails", "thumbnails_format",
//Y20
"bed_exclude_area",
"bed_exclude_area_0", "bed_exclude_area_1",
//Y16
"chamber_temperature", "auxiliary_fan", "chamber_fan"
};
@@ -1341,7 +1341,8 @@ static const std::set<std::string> independent_from_extruder_number_options = {
"gcode_substitutions",
"post_process",
//Y20
"bed_exclude_area",
"bed_exclude_area_0",
"bed_exclude_area_1",
};
bool PresetCollection::is_independent_from_extruder_number_option(const std::string& opt_key)

View File

@@ -61,7 +61,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"avoid_crossing_perimeters",
"avoid_crossing_perimeters_max_detour",
//Y20
"bed_exclude_area",
"bed_exclude_area_0",
"bed_exclude_area_1",
"bed_shape",
"bed_temperature",
"before_layer_gcode",

View File

@@ -272,8 +272,13 @@ void PrintConfigDef::init_common_params()
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0), Vec2d(200, 0), Vec2d(200, 200), Vec2d(0, 200) });
//Y20
def = this->add("bed_exclude_area", coPoints);
def->label = L("Bed exclude area");
def = this->add("bed_exclude_area_0", coPoints);
def->label = L("Bed exclude area 1");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });
def = this->add("bed_exclude_area_1", coPoints);
def->label = L("Bed exclude area 2");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) });

View File

@@ -789,7 +789,8 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionFloatOrPercent, avoid_crossing_perimeters_max_detour))
((ConfigOptionPoints, bed_shape))
//Y20
((ConfigOptionPoints, bed_exclude_area))
((ConfigOptionPoints, bed_exclude_area_0))
((ConfigOptionPoints, bed_exclude_area_1))
((ConfigOptionInts, bed_temperature))
//Y16
((ConfigOptionBool, chamber_temperature))

View File

@@ -159,13 +159,13 @@ void BedShape::apply_exclude_values(ConfigOptionsGroupShp optgroup)
BedShapeDialog::BedShapeDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _(L("Bed Shape")),
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {}
//Y20
void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model)
void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area_0, const ConfigOptionPoints& exclude_area_1, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model)
{
SetFont(wxGetApp().normal_font());
m_panel = new BedShapePanel(this);
//Y20
m_panel->build_panel(default_pt, exclude_area, custom_texture, custom_model);
m_panel->build_panel(default_pt, exclude_area_0, exclude_area_1, custom_texture, custom_model);
auto main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_panel, 1, wxEXPAND);
@@ -204,12 +204,13 @@ void BedShapeDialog::on_dpi_changed(const wxRect &suggested_rect)
const std::string BedShapePanel::NONE = "None";
const std::string BedShapePanel::EMPTY_STRING = "";
//Y20
void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model)
void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area_0, const ConfigOptionPoints& exclude_area_1, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model)
{
wxGetApp().UpdateDarkUI(this);
m_shape = default_pt.values;
//Y20
m_exclude_area = exclude_area.values;
m_exclude_area_0 = exclude_area_0.values;
m_exclude_area_1 = exclude_area_1.values;
m_custom_texture = custom_texture.value.empty() ? NONE : custom_texture.value;
m_custom_model = custom_model.value.empty() ? NONE : custom_model.value;
@@ -255,7 +256,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
activate_options_page(optgroup);
//Y20
wxPanel* exclude_panel = init_exclude_panel();
wxSizer* exclude_panel = init_exclude_sizer();
wxPanel* texture_panel = init_texture_panel();
wxPanel* model_panel = init_model_panel();
@@ -263,6 +264,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
// right pane with preview canvas
m_canvas = new Bed_2D(this);
m_canvas->SetMinSize({ FromDIP(400), FromDIP(400) });
m_canvas->Bind(wxEVT_PAINT, [this](wxPaintEvent& e) { m_canvas->repaint(m_shape); });
m_canvas->Bind(wxEVT_SIZE, [this](wxSizeEvent& e) { m_canvas->Refresh(); });
@@ -270,8 +272,8 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
left_sizer->Add(sbsizer, 0, wxEXPAND);
//Y20
left_sizer->Add(exclude_panel, 0, wxEXPAND);
left_sizer->Add(texture_panel, 1, wxEXPAND);
left_sizer->Add(model_panel, 1, wxEXPAND);
left_sizer->Add(texture_panel, 0, wxEXPAND);
left_sizer->Add(model_panel, 0, wxEXPAND);
wxSizer* top_sizer = new wxBoxSizer(wxHORIZONTAL);
top_sizer->Add(left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 10);
@@ -281,7 +283,7 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf
set_shape(default_pt);
//Y20
set_exclude_area(exclude_area);
set_exclude_area(exclude_area_0, exclude_area_1);
update_preview();
}
@@ -311,25 +313,38 @@ void BedShapePanel::activate_options_page(ConfigOptionsGroupShp options_group)
}
//Y20
wxPanel* BedShapePanel::init_exclude_panel()
wxSizer* BedShapePanel::init_exclude_sizer()
{
wxPanel* panel = new wxPanel(this);
wxGetApp().UpdateDarkUI(panel, true);
exclude_optgroup = std::make_shared<ConfigOptionsGroup>(panel, _L("Exclude area"));
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
exclude_optgroup->label_width = 10;
exclude_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
wxPanel* panel_0 = new wxPanel(this);
wxGetApp().UpdateDarkUI(panel_0, true);
exclude_optgroup_0 = std::make_shared<ConfigOptionsGroup>(panel_0, _L("Exclude area 1"));
exclude_optgroup_0->label_width = 10;
exclude_optgroup_0->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
update_shape();
};
BedShape::append_option_line(exclude_optgroup_0, BedShape::Parameter::ExcludeMax);
BedShape::append_option_line(exclude_optgroup_0, BedShape::Parameter::ExcludeMin);
exclude_optgroup_0->activate();
panel_0->SetSizerAndFit(exclude_optgroup_0->sizer);
BedShape::append_option_line(exclude_optgroup, BedShape::Parameter::ExcludeMax);
BedShape::append_option_line(exclude_optgroup, BedShape::Parameter::ExcludeMin);
wxPanel* panel_1 = new wxPanel(this);
wxGetApp().UpdateDarkUI(panel_1, true);
exclude_optgroup_1 = std::make_shared<ConfigOptionsGroup>(panel_1, _L("Exclude area 2"));
exclude_optgroup_1->label_width = 10;
exclude_optgroup_1->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
update_shape();
};
BedShape::append_option_line(exclude_optgroup_1, BedShape::Parameter::ExcludeMax);
BedShape::append_option_line(exclude_optgroup_1, BedShape::Parameter::ExcludeMin);
exclude_optgroup_1->activate();
panel_1->SetSizerAndFit(exclude_optgroup_1->sizer);
exclude_optgroup->activate();
sizer->Add(panel_0, 1, wxEXPAND);
sizer->Add(panel_1, 1, wxEXPAND);
panel->SetSizerAndFit(exclude_optgroup->sizer);
return panel;
return sizer;
}
wxPanel* BedShapePanel::init_texture_panel()
@@ -497,10 +512,14 @@ void BedShapePanel::set_shape(const ConfigOptionPoints& points)
update_shape();
}
//Y20
void BedShapePanel::set_exclude_area(const ConfigOptionPoints& points)
void BedShapePanel::set_exclude_area(const ConfigOptionPoints& points_0, const ConfigOptionPoints& points_1)
{
BedShape exclude(points);
exclude.apply_exclude_values(exclude_optgroup);
BedShape exclude_0(points_0);
exclude_0.apply_exclude_values(exclude_optgroup_0);
BedShape exclude_1(points_1);
exclude_1.apply_exclude_values(exclude_optgroup_1);
update_shape();
}
@@ -575,41 +594,37 @@ void BedShapePanel::update_shape()
}
//Y20
m_exclude_area_0 = update_exclude_area(exclude_optgroup_0);
m_exclude_area_1 = update_exclude_area(exclude_optgroup_1);
update_preview();
}
//Y20
const std::vector<Vec2d>& BedShapePanel::update_exclude_area(ConfigOptionsGroupShp options_group)
{
Vec2d exclude_max(Vec2d::Zero());
Vec2d exclude_min(Vec2d::Zero());
std::vector<Vec2d> e_area = {Vec2d(0, 0)};
try { exclude_max = boost::any_cast<Vec2d>(exclude_optgroup->get_value("exclude_area_max")); }
catch (const std::exception& /* e */) { return; }
try { exclude_max = boost::any_cast<Vec2d>(options_group->get_value("exclude_area_max")); }
catch (const std::exception & /* e */) { return e_area; }
try { exclude_min = boost::any_cast<Vec2d>(exclude_optgroup->get_value("exclude_area_min")); }
catch (const std::exception & /* e */) { return; }
try { exclude_min = boost::any_cast<Vec2d>(options_group->get_value("exclude_area_min")); }
catch (const std::exception & /* e */) { return e_area; }
auto e_x = exclude_max(0);
auto e_y = exclude_max(1);
// empty strings or '-' or other things
//if (e_x == 0 || e_y == 0) return;
//double e_x0 = 0.0;
//double e_y0 = 0.0;
//double e_x1 = e_x;
//double e_y1 = e_y;
auto e_dx = exclude_min(0);
auto e_dy = exclude_min(1);
//e_x0 -= e_dx;
//e_x1 -= e_dx;
//e_y0 -= e_dy;
//e_y1 -= e_dy;
//m_exclude_area = { Vec2d(e_x0, e_y0),
// Vec2d(e_x1, e_y0),
// Vec2d(e_x1, e_y1),
// Vec2d(e_x0, e_y1) };
m_exclude_area = { Vec2d(e_dx, e_dy),
Vec2d(e_x, e_dy),
Vec2d(e_x, e_y),
Vec2d(e_dx, e_y) };
e_area = { Vec2d(e_dx, e_dy),
Vec2d(e_x, e_dy),
Vec2d(e_x, e_y),
Vec2d(e_dx, e_y) };
update_preview();
return e_area;
}
// Loads an stl file, projects it to the XY plane and calculates a polygon.

View File

@@ -63,19 +63,21 @@ class BedShapePanel : public wxPanel
std::vector<Vec2d> m_shape;
std::vector<Vec2d> m_loaded_shape;
//Y20
std::vector<Vec2d> m_exclude_area;
std::vector<Vec2d> m_exclude_area_0;
std::vector<Vec2d> m_exclude_area_1;
std::string m_custom_texture;
std::string m_custom_model;
public:
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY), m_custom_texture(NONE), m_custom_model(NONE) {}
//Y20
void build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
void build_panel(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area_0, const ConfigOptionPoints& exclude_area_1, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
const std::vector<Vec2d>& get_shape() const { return m_shape; }
//Y20
const std::vector<Vec2d>& get_exclude_area() const { return m_exclude_area; }
const std::vector<Vec2d>& get_exclude_area_0() const { return m_exclude_area_0; }
const std::vector<Vec2d>& get_exclude_area_1() const { return m_exclude_area_1; }
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; }
@@ -83,15 +85,17 @@ private:
ConfigOptionsGroupShp init_shape_options_page(const wxString& title);
void activate_options_page(ConfigOptionsGroupShp options_group);
//Y20
wxPanel* init_exclude_panel();
ConfigOptionsGroupShp exclude_optgroup;
wxSizer* init_exclude_sizer();
ConfigOptionsGroupShp exclude_optgroup_0;
ConfigOptionsGroupShp exclude_optgroup_1;
wxPanel* init_texture_panel();
wxPanel* init_model_panel();
void set_shape(const ConfigOptionPoints& points);
//Y20
void set_exclude_area(const ConfigOptionPoints& points);
void set_exclude_area(const ConfigOptionPoints& points_0, const ConfigOptionPoints& points_1);
void update_preview();
void update_shape();
const std::vector<Vec2d>& update_exclude_area(ConfigOptionsGroupShp options_group);
void load_stl();
void load_texture();
void load_model();
@@ -108,11 +112,12 @@ class BedShapeDialog : public DPIDialog
public:
BedShapeDialog(wxWindow* parent);
//Y20
void build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
void build_dialog(const ConfigOptionPoints& default_pt, const ConfigOptionPoints& exclude_area_0, const ConfigOptionPoints& exclude_area_1, const ConfigOptionString& custom_texture, const ConfigOptionString& custom_model);
const std::vector<Vec2d>& get_shape() const { return m_panel->get_shape(); }
//Y20
const std::vector<Vec2d>& get_exclude_area() const { return m_panel->get_exclude_area(); }
const std::vector<Vec2d>& get_exclude_area_0() const { return m_panel->get_exclude_area_0(); }
const std::vector<Vec2d>& get_exclude_area_1() const { return m_panel->get_exclude_area_1(); }
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(); }

View File

@@ -1829,7 +1829,8 @@ PageBedShape::PageBedShape(ConfigWizard *parent)
shape_panel->build_panel(*wizard_p()->custom_config->option<ConfigOptionPoints>("bed_shape"),
//Y20
*wizard_p()->custom_config->option<ConfigOptionPoints>("bed_exclude_area"),
*wizard_p()->custom_config->option<ConfigOptionPoints>("bed_exclude_area_0"),
*wizard_p()->custom_config->option<ConfigOptionPoints>("bed_exclude_area_1"),
*wizard_p()->custom_config->option<ConfigOptionString>("bed_custom_texture"),
*wizard_p()->custom_config->option<ConfigOptionString>("bed_custom_model"));
@@ -1840,12 +1841,14 @@ void PageBedShape::apply_custom_config(DynamicPrintConfig &config)
{
const std::vector<Vec2d>& points = shape_panel->get_shape();
//Y20
const std::vector<Vec2d>& exclude_area = shape_panel->get_exclude_area();
const std::vector<Vec2d>& exclude_area_0 = shape_panel->get_exclude_area_0();
const std::vector<Vec2d>& exclude_area_1 = shape_panel->get_exclude_area_1();
const std::string& custom_texture = shape_panel->get_custom_texture();
const std::string& custom_model = shape_panel->get_custom_model();
config.set_key_value("bed_shape", new ConfigOptionPoints(points));
//Y20
config.set_key_value("bed_exclude_area", new ConfigOptionPoints(exclude_area));
config.set_key_value("bed_exclude_area_0", new ConfigOptionPoints(exclude_area_0));
config.set_key_value("bed_exclude_area_1", new ConfigOptionPoints(exclude_area_1));
config.set_key_value("bed_custom_texture", new ConfigOptionString(custom_texture));
config.set_key_value("bed_custom_model", new ConfigOptionString(custom_model));
}
@@ -3317,7 +3320,7 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
p->load_vendors();
p->custom_config.reset(DynamicPrintConfig::new_from_defaults_keys({
//Y20
"gcode_flavor", "bed_shape", "bed_exclude_area", "bed_custom_texture", "bed_custom_model", "nozzle_diameter", "filament_diameter", "temperature", "bed_temperature",
"gcode_flavor", "bed_shape", "bed_exclude_area_0", "bed_exclude_area_1", "bed_custom_texture", "bed_custom_model", "nozzle_diameter", "filament_diameter", "temperature", "bed_temperature",
}));
p->index = new ConfigWizardIndex(this);

View File

@@ -204,7 +204,7 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break;
case coPoints:{
//Y20
if (opt_key == "bed_shape" || opt_key == "bed_exclude_area") {
if (opt_key == "bed_shape" || opt_key == "bed_exclude_area_0" || opt_key == "bed_exclude_area_1") {
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
break;
}

View File

@@ -954,7 +954,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
break;
case coPoints:
//Y20
if (opt_key == "bed_shape" || opt_key == "bed_exclude_area")
if (opt_key == "bed_shape" || opt_key == "bed_exclude_area_0" || opt_key == "bed_exclude_area_1")
ret = config.option<ConfigOptionPoints>(opt_key)->values;
else
ret = config.option<ConfigOptionPoints>(opt_key)->get_at(idx);

View File

@@ -4956,20 +4956,23 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
BedShapeDialog dlg(this);
dlg.build_dialog(*m_config->option<ConfigOptionPoints>("bed_shape"),
//Y20
*m_config->option<ConfigOptionPoints>("bed_exclude_area"),
*m_config->option<ConfigOptionPoints>("bed_exclude_area_0"),
*m_config->option<ConfigOptionPoints>("bed_exclude_area_1"),
*m_config->option<ConfigOptionString>("bed_custom_texture"),
*m_config->option<ConfigOptionString>("bed_custom_model"));
if (dlg.ShowModal() == wxID_OK) {
const std::vector<Vec2d>& shape = dlg.get_shape();
//Y20
const std::vector<Vec2d>& exclude_area = dlg.get_exclude_area();
const std::vector<Vec2d>& exclude_area_0 = dlg.get_exclude_area_0();
const std::vector<Vec2d>& exclude_area_1 = dlg.get_exclude_area_1();
const std::string& custom_texture = dlg.get_custom_texture();
const std::string& custom_model = dlg.get_custom_model();
if (!shape.empty())
{
load_key_value("bed_shape", shape);
//Y20
load_key_value("bed_exclude_area", exclude_area);
load_key_value("bed_exclude_area_0", exclude_area_0);
load_key_value("bed_exclude_area_1", exclude_area_1);
load_key_value("bed_custom_texture", custom_texture);
load_key_value("bed_custom_model", custom_model);
update_changed_ui();
@@ -4983,7 +4986,8 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
const Search::GroupAndCategory& gc = searcher.get_group_and_category("bed_shape");
//Y20
searcher.add_key("bed_exclude_area", m_type, gc.group, gc.category);
searcher.add_key("bed_exclude_area_0", m_type, gc.group, gc.category);
searcher.add_key("bed_exclude_area_1", m_type, gc.group, gc.category);
searcher.add_key("bed_custom_texture", m_type, gc.group, gc.category);
searcher.add_key("bed_custom_model", m_type, gc.group, gc.category);
}

View File

@@ -1204,7 +1204,11 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig&
return shape.get_full_name_with_params();
}
//Y20
if (opt_key == "bed_exclude_area") {
if (opt_key == "bed_exclude_area_0") {
BedShape shape(*config.option<ConfigOptionPoints>(opt_key));
return shape.get_full_name_with_params();
}
if (opt_key == "bed_exclude_area_1") {
BedShape shape(*config.option<ConfigOptionPoints>(opt_key));
return shape.get_full_name_with_params();
}