Optimized PressureAdvance

This commit is contained in:
QIDI TECH
2023-09-01 20:05:08 +08:00
parent 07e2346d8d
commit a2b2cf743e
10 changed files with 212 additions and 1459 deletions

View File

@@ -1579,8 +1579,7 @@ void MainFrame::init_menubar_as_editor()
append_menu_item(flowrateMenu, wxID_ANY, _L("Fine"), _L("Flow Rate Fine"),
[this](wxCommandEvent &) {
if (!m_frf_calib_dlg)
m_frf_calib_dlg = new FRF_Calibration_Dlg((wxWindow *) this, wxID_ANY, m_plater);
m_frf_calib_dlg = new FRF_Calibration_Dlg((wxWindow *) this, wxID_ANY, m_plater);
m_frf_calib_dlg->ShowModal();
},
"", nullptr, [this]() { return m_plater->is_view3D_shown(); }, this);
@@ -1590,8 +1589,7 @@ void MainFrame::init_menubar_as_editor()
append_menu_item(calibrationMenu, wxID_ANY, _L("Pressure advance"), _L("Pressure advance"),
[this](wxCommandEvent &) {
if (!m_pa_calib_dlg)
m_pa_calib_dlg = new PA_Calibration_Dlg((wxWindow *) this, wxID_ANY, m_plater);
m_pa_calib_dlg = new PA_Calibration_Dlg((wxWindow *) this, wxID_ANY, m_plater);
m_pa_calib_dlg->ShowModal();
},
"", nullptr, [this]() { return m_plater->is_view3D_shown(); }, this);

View File

@@ -3,6 +3,7 @@
#include <cstddef>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <string>
@@ -5369,14 +5370,11 @@ void Plater::calib_flowrate_coarse()
{
new_project();
wxGetApp().mainframe->select_tab(size_t(0));
Tab *tab_print = wxGetApp().get_tab(Preset::TYPE_PRINT);
Tab *tab_filament = wxGetApp().get_tab(Preset::TYPE_FILAMENT);
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
DynamicPrintConfig new_config;
DynamicPrintConfig new_config;
new_config.set_key_value("complete_objects", new ConfigOptionBool(true));
new_config.set_key_value("extruder_clearance_radius", new ConfigOptionFloat(1));
new_config.set_key_value("extrusion_multiplier", new ConfigOptionFloats{1.});
new_config.set_key_value("extrusion_multiplier", new ConfigOptionFloats{1});
new_config.set_key_value("between_objects_gcode",
new ConfigOptionString("{if current_object_idx==1}M221 S105{endif}"
"{if current_object_idx==2}M221 S110{endif}"
@@ -5386,6 +5384,10 @@ void Plater::calib_flowrate_coarse()
"{if current_object_idx==6}M221 S90{endif}"
"{if current_object_idx==7}M221 S85{endif}"
"{if current_object_idx==8}M221 S80{endif}"));
Tab *tab_print = wxGetApp().get_tab(Preset::TYPE_PRINT);
Tab *tab_filament = wxGetApp().get_tab(Preset::TYPE_FILAMENT);
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
tab_print->load_config(new_config);
tab_filament->load_config(new_config);
tab_printer->load_config(new_config);
@@ -5398,33 +5400,33 @@ void Plater::calib_flowrate_coarse()
get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message);
}
void Plater::calib_flowrate_fine(const Calib_Params &params)
void Plater::calib_flowrate_fine(const double target_extrusion_multiplier)
{
new_project();
wxGetApp().mainframe->select_tab(size_t(0));
if (params.mode != CalibMode::Calib_FRF)
return;
auto printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
int em = target_extrusion_multiplier * 100;
auto start_gcode = printerConfig->opt_string("start_gcode");
DynamicPrintConfig new_config;
new_config.set_key_value("complete_objects", new ConfigOptionBool(true));
new_config.set_key_value("extruder_clearance_radius", new ConfigOptionFloat(1));
new_config.set_key_value("extrusion_multiplier", new ConfigOptionFloats{1});
new_config.set_key_value("start_gcode", new ConfigOptionString(start_gcode + "\nM221 S"+std::to_string(em)));
new_config.set_key_value("between_objects_gcode",
new ConfigOptionString("{if current_object_idx==1}M221 S"+std::to_string(em+1)+"{endif}"
"{if current_object_idx==2}M221 S"+std::to_string(em+2)+"{endif}"
"{if current_object_idx==3}M221 S"+std::to_string(em+3)+"{endif}"
"{if current_object_idx==4}M221 S"+std::to_string(em+4)+"{endif}"
"{if current_object_idx==5}M221 S"+std::to_string(em-1)+"{endif}"
"{if current_object_idx==6}M221 S"+std::to_string(em-2)+"{endif}"
"{if current_object_idx==7}M221 S"+std::to_string(em-3)+"{endif}"
"{if current_object_idx==8}M221 S"+std::to_string(em-4)+"{endif}"));
Tab *tab_print = wxGetApp().get_tab(Preset::TYPE_PRINT);
Tab *tab_filament = wxGetApp().get_tab(Preset::TYPE_FILAMENT);
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
DynamicPrintConfig new_config;
auto printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
int extru_multip = params.start * 100;
auto start_gcode = printerConfig->opt_string("start_gcode");
new_config.set_key_value("complete_objects", new ConfigOptionBool(true));
new_config.set_key_value("extruder_clearance_radius", new ConfigOptionFloat(1));
new_config.set_key_value("extrusion_multiplier", new ConfigOptionFloats{1.});
new_config.set_key_value("start_gcode", new ConfigOptionString(start_gcode + "\nM221 S"+std::to_string(extru_multip)));
new_config.set_key_value("between_objects_gcode",
new ConfigOptionString("{if current_object_idx==1}M221 S"+std::to_string(extru_multip+1)+"{endif}"
"{if current_object_idx==2}M221 S"+std::to_string(extru_multip+2)+"{endif}"
"{if current_object_idx==3}M221 S"+std::to_string(extru_multip+3)+"{endif}"
"{if current_object_idx==4}M221 S"+std::to_string(extru_multip+4)+"{endif}"
"{if current_object_idx==5}M221 S"+std::to_string(extru_multip-1)+"{endif}"
"{if current_object_idx==6}M221 S"+std::to_string(extru_multip-2)+"{endif}"
"{if current_object_idx==7}M221 S"+std::to_string(extru_multip-3)+"{endif}"
"{if current_object_idx==8}M221 S"+std::to_string(extru_multip-4)+"{endif}"));
tab_print->load_config(new_config);
tab_filament->load_config(new_config);
tab_printer->load_config(new_config);
@@ -5438,46 +5440,95 @@ void Plater::calib_flowrate_fine(const Calib_Params &params)
}
//B34
void Plater::calib_pa(const int pa_method, wxString StartPA, wxString EndPA, wxString PAStep)
void Plater::calib_pa_line(const double StartPA, double EndPA, double PAStep)
{
new_project();
wxGetApp().mainframe->select_tab(size_t(0));
//Load model
std::vector<fs::path> model_path;
//double pa = StartPA;
switch (pa_method) {
case 0:
{
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
DynamicPrintConfig new_config;
auto printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
auto end_gcode = printerConfig->opt_string("end_gcode");
std::string set_pa_gcode = "M900 K";
end_gcode = set_pa_gcode + end_gcode;
new_config.set_key_value("end_gcode", new ConfigOptionString(end_gcode));
tab_printer->load_config(new_config);
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_line.stl");
load_files(model_path, true, false, false);
break;
}
case 1:
{
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_pattern.stl");
load_files(model_path, true, false, false);
break;
}
case 2:
{
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_tower.stl");
load_files(model_path, true, false, false);
break;
}
default: break;
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_line.stl");
load_files(model_path, true, false, false);
//Check step count
const Vec2d plate_center = build_volume().bed_center();
double count = floor((EndPA - StartPA) / PAStep);
double max_count = floor(plate_center.y() / 2.5) - 2;
if (count > max_count)
{
count = max_count;
}
auto printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
//Position aided model
sidebar().obj_manipul()->on_change("position", 0, plate_center.x() - 50);
sidebar().obj_manipul()->set_uniform_scaling(false);
sidebar().obj_manipul()->on_change("size", 1, count * 5);
auto first_layer_height = printerConfig->opt_float("first_layer_height");
sidebar().obj_manipul()->on_change("size", 2, first_layer_height);
sidebar().obj_manipul()->set_uniform_scaling(true);
//Generate line gcode
double start_x = plate_center.x() - 40;
double end_x = plate_center.x() + 40;
double start_y = plate_center.y() - count *2.5;
double end_y = plate_center.y() + count *2.5;
std::string pa_line_gcode = "M900 K";
//Generate number gcode
std::string pa_number_gcode = "M900 K";
//Set and load end gcode
auto end_gcode = printerConfig->opt_string("end_gcode");
end_gcode = pa_line_gcode + pa_number_gcode + end_gcode;
DynamicPrintConfig new_config;
new_config.set_key_value("end_gcode", new ConfigOptionString(end_gcode));
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
tab_printer->load_config(new_config);
std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters.");
get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message);
}
void Plater::calib_pa_pattern(const double StartPA, double EndPA, double PAStep)
{
new_project();
wxGetApp().mainframe->select_tab(size_t(0));
std::vector<fs::path> model_path;
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_pattern.stl");
load_files(model_path, true, false, false);
const Vec2d plate_center = build_volume().bed_center();
sidebar().obj_manipul()->on_change("position", 0, plate_center.x() - 50);
Tab *tab_printer = wxGetApp().get_tab(Preset::TYPE_PRINTER);
DynamicPrintConfig new_config;
auto printerConfig = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
auto end_gcode = printerConfig->opt_string("end_gcode");
std::string set_pa_gcode = "M900 K";
end_gcode = set_pa_gcode + end_gcode;
new_config.set_key_value("end_gcode", new ConfigOptionString(end_gcode));
tab_printer->load_config(new_config);
std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters.");
get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message);
}
void Plater::calib_pa_tower(const double StartPA, double EndPA, double PAStep)
{
new_project();
wxGetApp().mainframe->select_tab(size_t(0));
std::vector<fs::path> model_path;
model_path.emplace_back(Slic3r::resources_dir() + "/calib/PressureAdvance/pa_tower.stl");
load_files(model_path, true, false, false);
std::string message = _u8L("NOTICE: The calibration function modifies some parameters. After calibration, record the best value and restore the other parameters.");
get_notification_manager()->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::PrintInfoNotificationLevel, message);
}
void Plater::import_zip_archive()

View File

@@ -16,8 +16,6 @@
#include "Jobs/Job.hpp"
#include "Jobs/Worker.hpp"
#include "Search.hpp"
//B34
#include "libslic3r/Calib.hpp"
class wxButton;
class ScalableButton;
@@ -167,9 +165,11 @@ public:
SLAPrint& sla_print();
//B34
void calib_pa(const int pa_method, wxString StartPA, wxString EndPA, wxString PAStep);
void calib_pa_line(const double StartPA, double EndPA, double PAStep);
void calib_pa_pattern(const double StartPA, double EndPA, double PAStep);
void calib_pa_tower(const double StartPA, double EndPA, double PAStep);
void calib_flowrate_coarse();
void calib_flowrate_fine(const Calib_Params &params);
void calib_flowrate_fine(const double target_extrusion_multiplier);
void new_project();

View File

@@ -5,91 +5,45 @@
#include <wx/dcgraph.h>
#include "MainFrame.hpp"
#include <string>
#include <sstream>
#include <iomanip>
namespace Slic3r {
namespace GUI {
wxBoxSizer *create_item_checkbox(wxString title, wxWindow *parent, bool *value, CheckBoxInWT *&checkbox)
{
wxBoxSizer* m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 5);
checkbox = new ::CheckBoxInWT(parent);
m_sizer_checkbox->Add(checkbox, 0, wxALIGN_CENTER, 0);
m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 8);
auto checkbox_title = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxSize(-1, -1), 0);
checkbox_title->SetForegroundColour(wxColour(144, 144, 144));
checkbox_title->SetFont(::Label::Body_13);
checkbox_title->Wrap(-1);
m_sizer_checkbox->Add(checkbox_title, 0, wxALIGN_CENTER | wxALL, 3);
checkbox->SetValue(true);
checkbox->Bind(wxEVT_TOGGLEBUTTON, [parent, checkbox, value](wxCommandEvent& e) {
(*value) = (*value) ? false : true;
e.Skip();
});
return m_sizer_checkbox;
}
FRF_Calibration_Dlg::FRF_Calibration_Dlg(wxWindow* parent, wxWindowID id, Plater* plater)
: DPIDialog(parent, id, _L("Flowrate Fine Calibration"), wxDefaultPosition, parent->FromDIP(wxSize(-1, 280)), wxDEFAULT_DIALOG_STYLE | wxNO_BORDER), m_plater(plater)
: DPIDialog(parent, id, _L("Flowrate Fine Calibration"), wxDefaultPosition, wxSize(-1, 280), wxDEFAULT_DIALOG_STYLE | wxNO_BORDER), m_plater(plater)
{
wxBoxSizer* v_sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(v_sizer);
// Settings
auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config;
wxString start_length_str = _L("Extrusion Multiplier: ");
auto text_size = wxWindow::GetTextExtent(start_length_str);
text_size.x = text_size.x * 1.5;
wxStaticBoxSizer *settings_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Settings"));
// desc
std::string setting_desc_message = _u8L("Please input the best value from the coarse calibration to further determine a more accurate extrusion multiplier.");
auto setting_desc = new wxStaticText(this, wxID_ANY, setting_desc_message, wxDefaultPosition, wxSize(340, -1), wxALIGN_LEFT);
setting_desc->Wrap(setting_desc->GetClientSize().x);
v_sizer->Add(setting_desc, 0, wxTOP | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 15);
auto st_size = FromDIP(wxSize(text_size.x, -1));
auto ti_size = FromDIP(wxSize(90, -1));
auto desc_size = FromDIP(wxSize(307, -1));
// Settings
wxStaticBoxSizer *settings_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _L("Settings"));
auto extrusion_multiplier_text = new wxStaticText(this, wxID_ANY, _L("Extrusion Multiplier: "), wxDefaultPosition, wxSize(230, -1), wxALIGN_LEFT);
settings_sizer->Add(extrusion_multiplier_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
// extru
auto multip = filament_config->opt_float("extrusion_multiplier",0);
std::string multip_str = std::to_string(multip);
if (multip_str.find(".") > 0) {
size_t fp = multip_str.rfind(".");
size_t f = multip_str.rfind("0");
while (f > fp) {
if (f != -1) {
multip_str = multip_str.erase(f);
}
f = multip_str.rfind("0");
}
fp = multip_str.rfind(".");
if (fp == multip_str.size() - 1) {
multip_str = multip_str.erase(fp);
}
}
auto start_length_sizer = new wxBoxSizer(wxHORIZONTAL);
auto start_length_text = new wxStaticText(this, wxID_ANY, start_length_str, wxDefaultPosition, st_size, wxALIGN_LEFT);
m_tiExtru = new wxTextCtrl(this, wxID_ANY, multip_str, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE);
m_tiExtru->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config;
auto read_extrusion_multiplier = filament_config->opt_float("extrusion_multiplier", 0);
std::stringstream ss;
ss << std::setprecision(2) << read_extrusion_multiplier;
m_tc_extrusion_multiplier = new wxTextCtrl(this, wxID_ANY, ss.str(), wxDefaultPosition, wxSize(100, -1), wxBORDER_SIMPLE);
m_tc_extrusion_multiplier->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
settings_sizer->Add(m_tc_extrusion_multiplier, 0, wxRIGHT | wxALIGN_RIGHT, 0);
// desc
auto setting_desc = new wxStaticText(this, wxID_ANY, _u8L("Please input the best value from the coarse calibration to further determine a more accurate extrusion multiplier."),
wxDefaultPosition, desc_size, wxALIGN_LEFT);
setting_desc->Wrap(setting_desc->GetClientSize().x);
// delay
start_length_sizer->Add(start_length_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
start_length_sizer->Add(m_tiExtru, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
settings_sizer->Add(start_length_sizer);
v_sizer->Add(setting_desc, 0, wxTOP | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 15);
//v_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 5);
v_sizer->Add(settings_sizer, 0, wxTOP | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 15);
v_sizer->Add(0, FromDIP(5), 0, wxEXPAND, 5);
m_btnStart = new wxButton(this, wxID_OK, _L("OK"));
v_sizer->Add(0, 5, 0, wxEXPAND, 5);
m_btnStart = new wxButton(this, wxID_ANY, _L("OK"));
m_btnStart->Bind(wxEVT_BUTTON, &FRF_Calibration_Dlg::on_start, this);
v_sizer->Add(m_btnStart, 0, wxRIGHT | wxALIGN_RIGHT, 15);
v_sizer->Add(0, FromDIP(8), 0, wxEXPAND, 5);
v_sizer->Add(0, 8, 0, wxEXPAND, 5);
m_btnStart->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(FRF_Calibration_Dlg::on_start), NULL, this);
@@ -106,22 +60,22 @@ FRF_Calibration_Dlg::~FRF_Calibration_Dlg() {
void FRF_Calibration_Dlg::on_start(wxCommandEvent& event) {
bool read_double = false;
read_double = m_tiExtru->GetValue().ToDouble(&m_params.start);
double target_extrusion_multiplier;
read_double = m_tc_extrusion_multiplier->GetValue().ToDouble(&target_extrusion_multiplier);
if (!read_double || m_params.start < 0.9) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\n 0.9 <= Extrusion Multiplier <= 1.1\n"), wxEmptyString, wxICON_WARNING | wxOK);
if (!read_double || target_extrusion_multiplier < 0.5) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\n 0.5 <= Extrusion Multiplier <= 1.5\n"), wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
m_tiExtru->SetValue("0.9");
m_tc_extrusion_multiplier->SetValue("0.5");
return;
} else if (!read_double || m_params.start > 1.1) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\n 0.9 <= Extrusion Multiplier <= 1.1\n"), wxEmptyString, wxICON_WARNING | wxOK);
} else if (!read_double || target_extrusion_multiplier > 1.5) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\n 0.5 <= Extrusion Multiplier <= 1.5\n"), wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
m_tiExtru->SetValue("1.1");
m_tc_extrusion_multiplier->SetValue("1.5");
return;
}
m_params.mode = CalibMode::Calib_FRF;
m_plater->calib_flowrate_fine(m_params);
m_plater->calib_flowrate_fine(target_extrusion_multiplier);
EndModal(wxID_OK);
}
@@ -131,83 +85,62 @@ void FRF_Calibration_Dlg::on_dpi_changed(const wxRect& suggested_rect) {
}
PA_Calibration_Dlg::PA_Calibration_Dlg(wxWindow* parent, wxWindowID id, Plater* plater)
: DPIDialog(parent, id, _L("Pressure Advance Calibration"), wxDefaultPosition, parent->FromDIP(wxSize(-1, 280)), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), m_plater(plater)
: DPIDialog(parent, id, _L("Pressure Advance Calibration"), wxDefaultPosition, wxSize(-1, 280), wxDEFAULT_DIALOG_STYLE | wxNO_BORDER), m_plater(plater)
{
wxBoxSizer* v_sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(v_sizer);
wxBoxSizer* choice_sizer = new wxBoxSizer(wxHORIZONTAL);
choice_sizer->Add(FromDIP(5), 0, 0, wxEXPAND, 5);
wxString m_rbMethodChoices[] = { _L("PA Line"), _L("PA Pattern"), _L("PA Tower") };
int m_rbMethodNChoices = sizeof(m_rbMethodChoices) / sizeof(wxString);
m_rbMethod = new wxRadioBox(this, wxID_ANY, _L("Method"), wxDefaultPosition, wxDefaultSize, m_rbMethodNChoices, m_rbMethodChoices, 1, wxRA_SPECIFY_COLS);
m_rbMethod->SetSelection(0);
choice_sizer->Add(m_rbMethod, 0, wxALL, 5);
v_sizer->Add(choice_sizer);
wxString m_rbMethodChoices[] = { _L("PA Line"), _L("PA Pattern"), _L("PA Tower") };
int m_rbMethodNChoices = sizeof(m_rbMethodChoices) / sizeof(wxString);
m_rbMethod = new wxRadioBox(this, wxID_ANY, _L("Method"), wxDefaultPosition, wxDefaultSize, m_rbMethodNChoices, m_rbMethodChoices, 1, wxRA_SPECIFY_COLS);
m_rbMethod->SetSelection(0);
v_sizer->Add(m_rbMethod, 0, wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 15);
// Settings
//
wxString start_pa_str = _L("Start PA: ");
wxString end_pa_str = _L("End PA: ");
wxString PA_step_str = _L("PA step: ");
auto text_size = wxWindow::GetTextExtent(start_pa_str);
text_size.IncTo(wxWindow::GetTextExtent(end_pa_str));
text_size.IncTo(wxWindow::GetTextExtent(PA_step_str));
text_size.x = text_size.x * 1.5;
wxStaticBoxSizer* settings_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Settings"));
wxStaticBoxSizer* settings_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _L("Settings"));
auto st_size = FromDIP(wxSize(text_size.x, -1));
auto ti_size = FromDIP(wxSize(90, -1));
// start PA
auto start_PA_sizer = new wxBoxSizer(wxHORIZONTAL);
auto start_pa_text = new wxStaticText(this, wxID_ANY, start_pa_str, wxDefaultPosition, st_size, wxALIGN_LEFT);
m_tiStartPA = new TextInput(this, "", "", "", wxDefaultPosition, ti_size, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_tiStartPA->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
auto start_pa_text = new wxStaticText(this, wxID_ANY, _L("Start PA: "), wxDefaultPosition, wxSize(80, -1), wxALIGN_LEFT);
start_PA_sizer->Add(start_pa_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
start_PA_sizer->Add(start_pa_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
start_PA_sizer->Add(m_tiStartPA, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_tcStartPA = new wxTextCtrl(this, wxID_ANY, "0", wxDefaultPosition, wxSize(100, -1), wxBORDER_SIMPLE);
m_tcStartPA->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
start_PA_sizer->Add(m_tcStartPA, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
settings_sizer->Add(start_PA_sizer);
// end PA
auto end_PA_sizer = new wxBoxSizer(wxHORIZONTAL);
auto end_pa_text = new wxStaticText(this, wxID_ANY, end_pa_str, wxDefaultPosition, st_size, wxALIGN_LEFT);
m_tiEndPA = new TextInput(this, "", "", "", wxDefaultPosition, ti_size, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_tiStartPA->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
auto end_pa_text = new wxStaticText(this, wxID_ANY, _L("End PA: "), wxDefaultPosition, wxSize(80, -1), wxALIGN_LEFT);
end_PA_sizer->Add(end_pa_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
end_PA_sizer->Add(m_tiEndPA, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_tcEndPA = new wxTextCtrl(this, wxID_ANY, "0.04", wxDefaultPosition, wxSize(100, -1), wxBORDER_SIMPLE);
m_tcStartPA->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
end_PA_sizer->Add(m_tcEndPA, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
settings_sizer->Add(end_PA_sizer);
// PA step
auto PA_step_sizer = new wxBoxSizer(wxHORIZONTAL);
auto PA_step_text = new wxStaticText(this, wxID_ANY, PA_step_str, wxDefaultPosition, st_size, wxALIGN_LEFT);
m_tiPAStep = new TextInput(this, "", "", "", wxDefaultPosition, ti_size, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_tiStartPA->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
auto PA_step_text = new wxStaticText(this, wxID_ANY, _L("PA step: "), wxDefaultPosition, wxSize(80, -1), wxALIGN_LEFT);
PA_step_sizer->Add(PA_step_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
PA_step_sizer->Add(m_tiPAStep, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
m_tcPAStep = new wxTextCtrl(this, wxID_ANY, "0.002", wxDefaultPosition, wxSize(100, -1), wxBORDER_SIMPLE);
m_tcStartPA->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
PA_step_sizer->Add(m_tcPAStep, 0, wxALL | wxALIGN_CENTER_VERTICAL, 2);
settings_sizer->Add(PA_step_sizer);
v_sizer->Add(settings_sizer);
v_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 5);
m_btnStart = new Button(this, _L("OK"));
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(51, 91, 188), StateColor::Pressed),
std::pair<wxColour, int>(wxColour(51, 109, 251), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(68, 121, 251), StateColor::Normal));
v_sizer->Add(0, 5, 0, wxEXPAND, 5);
v_sizer->Add(settings_sizer, 0, wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 15);
v_sizer->Add(0, 5, 0, wxEXPAND, 5);
m_btnStart->SetBackgroundColor(btn_bg_green);
m_btnStart->SetBorderColor(wxColour(0, 150, 136));
m_btnStart->SetTextColor(wxColour("#FFFFFE"));
m_btnStart->SetSize(wxSize(FromDIP(48), FromDIP(24)));
m_btnStart->SetMinSize(wxSize(FromDIP(48), FromDIP(24)));
m_btnStart->SetCornerRadius(FromDIP(3));
m_btnStart->Bind(wxEVT_BUTTON, &PA_Calibration_Dlg::on_start, this);
v_sizer->Add(m_btnStart, 0, wxALL | wxALIGN_RIGHT, FromDIP(5));
m_btnStart = new wxButton(this, wxID_ANY, _L("OK"));
m_btnStart->Bind(wxEVT_BUTTON, &PA_Calibration_Dlg::on_start, this);
v_sizer->Add(m_btnStart, 0, wxRIGHT | wxALIGN_RIGHT, 15);
v_sizer->Add(0, 8, 0, wxEXPAND, 5);
PA_Calibration_Dlg::reset_params();
// Connect Events
m_rbMethod->Connect(wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler(PA_Calibration_Dlg::on_method_changed), NULL, this);
this->Connect(wxEVT_SHOW, wxShowEventHandler(PA_Calibration_Dlg::on_show));
m_btnStart->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PA_Calibration_Dlg::on_start), NULL, this);
wxGetApp().UpdateDlgDarkUI(this);
Layout();
Fit();
@@ -219,58 +152,40 @@ PA_Calibration_Dlg::~PA_Calibration_Dlg() {
m_btnStart->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PA_Calibration_Dlg::on_start), NULL, this);
}
void PA_Calibration_Dlg::reset_params() {
int method = m_rbMethod->GetSelection();
m_tiStartPA->GetTextCtrl()->SetValue(wxString::FromDouble(0.0));
switch (method) {
case 1:
m_params.mode = CalibMode::Calib_PA_Pattern;
m_tiEndPA->GetTextCtrl()->SetValue(wxString::FromDouble(0.08));
m_tiPAStep->GetTextCtrl()->SetValue(wxString::FromDouble(0.005));
break;
case 2:
m_params.mode = CalibMode::Calib_PA_Tower;
m_tiEndPA->GetTextCtrl()->SetValue(wxString::FromDouble(0.1));
m_tiPAStep->GetTextCtrl()->SetValue(wxString::FromDouble(0.002));
break;
default:
m_params.mode = CalibMode::Calib_PA_Line;
m_tiEndPA->GetTextCtrl()->SetValue(wxString::FromDouble(0.1));
m_tiPAStep->GetTextCtrl()->SetValue(wxString::FromDouble(0.002));
break;
}
}
void PA_Calibration_Dlg::on_start(wxCommandEvent& event) {
bool read_double = false;
read_double = m_tiStartPA->GetTextCtrl()->GetValue().ToDouble(&m_params.start);
read_double = read_double && m_tiEndPA->GetTextCtrl()->GetValue().ToDouble(&m_params.end);
read_double = read_double && m_tiPAStep->GetTextCtrl()->GetValue().ToDouble(&m_params.step);
if (!read_double || m_params.start < 0 || m_params.step < EPSILON || m_params.end < m_params.start + m_params.step) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\nStart PA: >= 0.0\nEnd PA: > Start PA\nPA step: >= 0.001)"), wxEmptyString, wxICON_WARNING | wxOK);
double start_pa;
double end_pa;
double pa_step;
read_double = m_tcStartPA->GetValue().ToDouble(&start_pa);
read_double = read_double && m_tcEndPA->GetValue().ToDouble(&end_pa);
read_double = read_double && m_tcPAStep->GetValue().ToDouble(&pa_step);
if (!read_double || start_pa < 0 || pa_step < EPSILON || end_pa < start_pa + pa_step) {
MessageDialog msg_dlg(nullptr, _L("Please input valid values:\nStart PA: >= 0.0\nEnd PA: > Start PA + PA step\nPA step: >= 0.001)"), wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
return;
}
switch (m_rbMethod->GetSelection()) {
case 1:
m_params.mode = CalibMode::Calib_PA_Pattern;
case 0:{
m_plater->calib_pa_line( start_pa, end_pa, pa_step);
break;
case 2:
m_params.mode = CalibMode::Calib_PA_Tower;
}
case 1:{
m_plater->calib_pa_pattern( start_pa, end_pa, pa_step);
break;
default:
m_params.mode = CalibMode::Calib_PA_Line;
}
case 2:{
m_plater->calib_pa_tower( start_pa, end_pa, pa_step);
break;
}
default: break;
}
m_plater->calib_pa(m_rbMethod->GetSelection(), m_tiStartPA->GetTextCtrl()->GetValue(), m_tiEndPA->GetTextCtrl()->GetValue(), m_tiPAStep->GetTextCtrl()->GetValue());
EndModal(wxID_OK);
}
void PA_Calibration_Dlg::on_method_changed(wxCommandEvent& event) {
PA_Calibration_Dlg::reset_params();
event.Skip();
}
@@ -279,8 +194,4 @@ void PA_Calibration_Dlg::on_dpi_changed(const wxRect& suggested_rect) {
Fit();
}
void PA_Calibration_Dlg::on_show(wxShowEvent& event) {
PA_Calibration_Dlg::reset_params();
}
}} // namespace Slic3r::GUI

View File

@@ -13,7 +13,6 @@
#include "GUI_App.hpp"
#include "wx/hyperlink.h"
#include <wx/radiobox.h>
#include "libslic3r/calib.hpp"
#include "Plater.hpp"
namespace Slic3r { namespace GUI {
@@ -27,11 +26,10 @@ public:
protected:
virtual void on_start(wxCommandEvent &event);
Calib_Params m_params;
wxTextCtrl *m_tiExtru;
wxButton * m_btnStart;
Plater * m_plater;
wxTextCtrl* m_tc_extrusion_multiplier;
wxButton* m_btnStart;
Plater* m_plater;
};
class PA_Calibration_Dlg : public DPIDialog
@@ -40,20 +38,17 @@ public:
PA_Calibration_Dlg(wxWindow* parent, wxWindowID id, Plater* plater);
~PA_Calibration_Dlg();
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_show(wxShowEvent& event);
protected:
void reset_params();
virtual void on_start(wxCommandEvent& event);
virtual void on_method_changed(wxCommandEvent& event);
protected:
Calib_Params m_params;
wxRadioBox* m_rbMethod;
TextInput* m_tiStartPA;
TextInput* m_tiEndPA;
TextInput* m_tiPAStep;
Button* m_btnStart;
Plater* m_plater;
virtual void on_start(wxCommandEvent& event);
virtual void on_method_changed(wxCommandEvent& event);
wxRadioBox* m_rbMethod;
wxTextCtrl* m_tcStartPA;
wxTextCtrl* m_tcEndPA;
wxTextCtrl* m_tcPAStep;
wxButton* m_btnStart;
Plater* m_plater;
};
}} // namespace Slic3r::GUI