WipeTowerDialog now uses filament_purging_multiplier

This commit is contained in:
Lukas Matena 2024-03-12 15:28:01 +01:00
parent 0988bf2998
commit e1b2bd4155
6 changed files with 95 additions and 22 deletions

View File

@ -1710,6 +1710,8 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_configbundle(
return std::make_pair(std::move(substitutions), presets_loaded + ph_printers_loaded);
}
void PresetBundle::update_multi_material_filament_presets()
{
if (printers.get_edited_preset().printer_technology() != ptFFF)
@ -1733,17 +1735,21 @@ void PresetBundle::update_multi_material_filament_presets()
std::vector<double> old_matrix = this->project_config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values;
size_t old_number_of_extruders = size_t(std::sqrt(old_matrix.size())+EPSILON);
if (num_extruders != old_number_of_extruders) {
const double default_purge = static_cast<const ConfigOptionFloat*>(printers.get_edited_preset().config.option("multimaterial_purging"))->value;
// Extract the relevant config options, even values from possibly modified presets.
const double default_purge = static_cast<const ConfigOptionFloat*>(this->printers.get_edited_preset().config.option("multimaterial_purging"))->value;
const std::vector<double> filament_purging_multipliers = get_config_options_for_current_filaments<ConfigOptionPercents>("filament_purge_multiplier");
std::vector<double> new_matrix;
for (unsigned int i=0;i<num_extruders;++i)
for (unsigned int i=0;i<num_extruders;++i) {
for (unsigned int j=0;j<num_extruders;++j) {
// append the value for this pair from the old matrix (if it's there):
if (i<old_number_of_extruders && j<old_number_of_extruders)
new_matrix.push_back(old_matrix[i*old_number_of_extruders + j]);
else
new_matrix.push_back( i==j ? 0. : default_purge);
new_matrix.push_back( i==j ? 0. : default_purge * filament_purging_multipliers[j] / 100.);
}
}
this->project_config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values = new_matrix;
}
}

View File

@ -63,6 +63,30 @@ public:
void cache_extruder_filaments_names();
void reset_extruder_filaments();
// Another hideous function related to current ExtruderFilaments hack. Returns a vector of values
// of a given config option for all currently used filaments. Modified value is returned for modified preset.
// Must be called with the vector ConfigOption type, e.g. ConfigOptionPercents.
template <class T>
auto get_config_options_for_current_filaments(const t_config_option_key& key)
{
decltype(T::values) out;
const Preset& edited_preset = this->filaments.get_edited_preset();
for (const ExtruderFilaments& extr_filament : this->extruders_filaments) {
const Preset& selected_preset = *extr_filament.get_selected_preset();
const Preset& preset = edited_preset.name == selected_preset.name ? edited_preset : selected_preset;
const T* co = preset.config.opt<T>(key);
if (co) {
assert(co->values.size() == 1);
out.push_back(co->values.back());
} else {
// Key is missing or type mismatch.
}
}
return out;
}
PresetCollection& get_presets(Preset::Type preset_type);
// The project configuration values are kept separated from the print/filament/printer preset,

View File

@ -2149,7 +2149,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("");
def->sidetext = L("mm³");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(70));
def->set_default_value(new ConfigOptionFloat(140.));
def = this->add("perimeter_acceleration", coFloat);
def->label = L("Perimeters");

View File

@ -518,12 +518,16 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) :
sizer->Add(m_wiping_dialog_button, 0, wxALIGN_CENTER_VERTICAL);
m_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e)
{
auto &project_config = wxGetApp().preset_bundle->project_config;
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
DynamicPrintConfig& project_config = preset_bundle->project_config;
const std::vector<double> &init_matrix = (project_config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
WipingDialog dlg(parent, cast<float>(init_matrix), extruder_colours);
// Extract the relevant config options, even values from possibly modified presets.
const double default_purge = static_cast<const ConfigOptionFloat*>(preset_bundle->printers.get_edited_preset().config.option("multimaterial_purging"))->value;
std::vector<double> filament_purging_multipliers = preset_bundle->get_config_options_for_current_filaments<ConfigOptionPercents>("filament_purge_multiplier");
WipingDialog dlg(parent, cast<float>(init_matrix), extruder_colours, default_purge, filament_purging_multipliers);
if (dlg.ShowModal() == wxID_OK) {
std::vector<float> matrix = dlg.get_matrix();

View File

@ -189,8 +189,9 @@ std::string RammingPanel::get_parameters()
// Parent dialog for purging volume adjustments - it fathers WipingPanel widget (that contains all controls) and a button.
WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours)
: wxDialog(parent, wxID_ANY, _(L("Wipe tower - Purging volume adjustment")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE/* | wxRESIZE_BORDER*/)
WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours,
double printer_purging_volume, const std::vector<double>& filament_purging_multipliers)
: wxDialog(parent, wxID_ANY, _(L("Wipe tower - Purging volume adjustment")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE/* | wxRESIZE_BORDER*/)
{
SetFont(wxGetApp().normal_font());
update_ui(this);
@ -202,7 +203,7 @@ WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, c
m_radio_button2 = new wxRadioButton(this, wxID_ANY, _L("Custom project-specific settings"));
auto stb = new wxStaticBox(this, wxID_ANY, wxEmptyString);
m_panel_wiping = new WipingPanel(this,matrix, extruder_colours, m_widget_button);
m_panel_wiping = new WipingPanel(this, matrix, extruder_colours, filament_purging_multipliers, printer_purging_volume, m_widget_button);
update_ui(m_radio_button1);
update_ui(m_radio_button2);
@ -247,12 +248,15 @@ WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, c
EndModal(wxID_OK);
},wxID_OK);
this->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent& evt) {
wxRadioButton* rdb = dynamic_cast<wxRadioButton*>(FindWindowById(evt.GetId()));
m_widget_button->Enable(rdb == m_radio_button2);
m_panel_wiping->Enable(rdb == m_radio_button2);
this->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent&) {
enable_or_disable_panel();
});
const bool start_default = should_start_as_default();
m_radio_button1->SetValue(start_default);
m_radio_button2->SetValue(! start_default);
enable_or_disable_panel();
this->Show();
}
@ -267,11 +271,24 @@ void WipingPanel::format_sizer(wxSizer* sizer, wxPanel* page, wxGridSizer* grid_
}
WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours, wxButton* widget_button)
WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours,
const std::vector<double>& filament_purging_multipliers, double printer_purging_volume, wxButton* widget_button)
: wxPanel(parent,wxID_ANY, wxDefaultPosition, wxDefaultSize/*,wxBORDER_RAISED*/)
{
m_filament_purging_multipliers = filament_purging_multipliers;
m_printer_purging_volume = printer_purging_volume;
m_widget_button = widget_button; // pointer to the button in parent dialog
m_widget_button->Bind(wxEVT_BUTTON,[this](wxCommandEvent&){ });
m_widget_button->Bind(wxEVT_BUTTON,[this](wxCommandEvent&){
// Set the matrix to defaults.
for (size_t i = 0; i < m_number_of_extruders; ++i) {
for (size_t j = 0; j < m_number_of_extruders; ++j) {
if (i != j) {
double def_val = m_printer_purging_volume * m_filament_purging_multipliers[j] / 100.;
edit_boxes[j][i]->SetValue(wxString("") << int(def_val));
}
}
}
});
m_number_of_extruders = (int)(sqrt(matrix.size())+0.001);
@ -375,3 +392,18 @@ std::vector<float> WipingPanel::read_matrix_values() {
}
return output;
}
bool WipingDialog::should_start_as_default() const
{
return true;
}
void WipingDialog::enable_or_disable_panel()
{
bool enable = m_radio_button2->GetValue();
m_widget_button->Enable(enable);
m_panel_wiping->Enable(enable);
}

View File

@ -51,7 +51,8 @@ private:
class WipingPanel : public wxPanel {
public:
WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours, wxButton* widget_button);
WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours,
const std::vector<double>& filament_purging_multipliers, double printer_purging_volume, wxButton* widget_button);
std::vector<float> read_matrix_values();
void format_sizer(wxSizer* sizer, wxPanel* page, wxGridSizer* grid_sizer, const wxString& table_title, int table_lshift=0);
@ -64,6 +65,8 @@ private:
wxBoxSizer* m_sizer_advanced = nullptr;
wxGridSizer* m_gridsizer_advanced = nullptr;
wxButton* m_widget_button = nullptr;
double m_printer_purging_volume;
std::vector<double> m_filament_purging_multipliers; // In percents !
};
@ -72,16 +75,20 @@ private:
class WipingDialog : public wxDialog {
public:
WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours);
WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<std::string>& extruder_colours,
double printer_purging_volume, const std::vector<double>& filament_purging_multipliers);
std::vector<float> get_matrix() const { return m_output_matrix; }
private:
WipingPanel* m_panel_wiping = nullptr;
bool should_start_as_default() const;
void enable_or_disable_panel();
WipingPanel* m_panel_wiping = nullptr;
std::vector<float> m_output_matrix;
wxRadioButton* m_radio_button1 = nullptr;
wxRadioButton* m_radio_button2 = nullptr;
wxButton* m_widget_button = nullptr;
wxRadioButton* m_radio_button1 = nullptr;
wxRadioButton* m_radio_button2 = nullptr;
wxButton* m_widget_button = nullptr;
};
#endif // _WIPE_TOWER_DIALOG_H_