ENH: refine retraction before cut

1. Add filament retraction before cut control

jira:NEW

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ifcb087c9791c0461b793ef811b21ebd4c007d880
This commit is contained in:
xun.zhang 2024-03-29 20:08:43 +08:00 committed by Lane.Wei
parent f02af9d59c
commit 5b834000f6
13 changed files with 182 additions and 85 deletions

View File

@ -57,6 +57,9 @@
"filament_is_support": [
"0"
],
"filament_long_retractions_when_cut": [
"nil"
],
"filament_max_volumetric_speed": [
"0"
],
@ -72,6 +75,9 @@
"filament_retract_when_changing_layer": [
"nil"
],
"filament_retraction_distances_when_cut": [
"nil"
],
"filament_retraction_length": [
"nil"
],

View File

@ -80,6 +80,7 @@ using namespace nlohmann;
#include "slic3r/GUI/OpenGLManager.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/Camera.hpp"
#include "slic3r/GUI/Plater.hpp"
#include <GLFW/glfw3.h>
#ifdef __WXGTK__
@ -2646,12 +2647,8 @@ int CLI::run(int argc, char **argv)
//flush_vol_vector.resize(project_filament_count);
//set multiplier to 1?
m_print_config.option<ConfigOptionFloat>("flush_multiplier", true)->set(new ConfigOptionFloat(1.f));
ConfigOption* extra_flush_volume_opt = m_print_config.option("nozzle_volume");
int extra_flush_volume = extra_flush_volume_opt ? (int)extra_flush_volume_opt->getFloat() : 0;
bool activate = m_print_config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value && m_print_config.option<ConfigOptionBool>("long_retraction_when_cut")->value;
float extra_retract_length = activate && m_print_config.option<ConfigOptionBool>("long_retraction_when_cut")->value ? m_print_config.option<ConfigOptionFloat>("retraction_distance_when_cut")->value : 0;
float extra_retract_volume = PI * 1.75 * 1.75 / 4 * extra_retract_length;
extra_flush_volume = (int)std::max(0.f, extra_flush_volume - extra_retract_volume);
const std::vector<int>& min_flush_volumes = Slic3r::GUI::get_min_flush_volumes();
if (filament_is_support->size() != project_filament_count)
{
@ -2660,9 +2657,13 @@ int CLI::run(int argc, char **argv)
flush_and_exit(CLI_CONFIG_FILE_ERROR);
}
BOOST_LOG_TRIVIAL(info) << boost::format("extra_flush_volume: %1%")%extra_flush_volume;
BOOST_LOG_TRIVIAL(info) << boost::format("filament_is_support: %1%")%filament_is_support->serialize();
BOOST_LOG_TRIVIAL(info) << boost::format("flush_volumes_matrix before computing: %1%")%m_print_config.option<ConfigOptionFloats>("flush_volumes_matrix")->serialize();
{
std::ostringstream volumes_str;
std::copy(min_flush_volumes.begin(), min_flush_volumes.end(), std::ostream_iterator<int>(volumes_str, ","));
BOOST_LOG_TRIVIAL(info) << boost::format("extra_flush_volume: %1%") % volumes_str.str();
BOOST_LOG_TRIVIAL(info) << boost::format("filament_is_support: %1%") % filament_is_support->serialize();
BOOST_LOG_TRIVIAL(info) << boost::format("flush_volumes_matrix before computing: %1%") % m_print_config.option<ConfigOptionFloats>("flush_volumes_matrix")->serialize();
}
for (int from_idx = 0; from_idx < project_filament_count; from_idx++) {
const std::string& from_color = project_filament_colors[from_idx];
unsigned char from_rgb[4] = {};
@ -2686,7 +2687,7 @@ int CLI::run(int argc, char **argv)
//BOOST_LOG_TRIVIAL(info) << boost::format("src_rgba {%1%,%2%,%3%,%4%} dst_rgba {%5%,%6%,%7%,%8%}")%(unsigned int)(from_rgb[0]) %(unsigned int)(from_rgb[1]) %(unsigned int)(from_rgb[2]) %(unsigned int)(from_rgb[3])
// %(unsigned int)(to_rgb[0]) %(unsigned int)(to_rgb[1]) %(unsigned int)(to_rgb[2]) %(unsigned int)(to_rgb[3]);
Slic3r::FlushVolCalculator calculator(extra_flush_volume, Slic3r::g_max_flush_volume);
Slic3r::FlushVolCalculator calculator(min_flush_volumes[from_idx], Slic3r::g_max_flush_volume);
flushing_volume = calculator.calc_flush_vol(from_rgb[3], from_rgb[0], from_rgb[1], from_rgb[2], to_rgb[3], to_rgb[0], to_rgb[1], to_rgb[2]);
if (is_from_support) {

View File

@ -88,11 +88,7 @@ int FlushVolCalculator::calc_flush_vol(unsigned char src_a, unsigned char src_r,
float hs_flush = 230.f * hs_dist;
float flush_volume = calc_triangle_3rd_edge(hs_flush, lumi_flush, 120.f);
constexpr int standard_nozzle_volume = 107;
auto formula = [](float rate) {
return 1.13 / (1 + 5.24*exp(-4 * rate)) - 0.031;
};
flush_volume = std::max(flush_volume, 60.f) *formula(float( m_min_flush_vol) / standard_nozzle_volume);
flush_volume = std::max(flush_volume, 60.f);
//float flush_multiplier = std::atof(m_flush_multiplier_ebox->GetValue().c_str());
flush_volume += m_min_flush_vol;

View File

@ -561,6 +561,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
}
gcodegen.placeholder_parser().set("current_extruder", new_extruder_id);
gcodegen.placeholder_parser().set("retraction_distance_when_cut", gcodegen.m_config.retraction_distances_when_cut.get_at(new_extruder_id));
gcodegen.placeholder_parser().set("long_retraction_when_cut", gcodegen.m_config.long_retractions_when_cut.get_at(new_extruder_id));
// Process the start filament gcode.
std::string start_filament_gcode_str;
@ -1262,7 +1264,14 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
m_processor.result().timelapse_warning_code = m_timelapse_warning_code;
m_processor.result().support_traditional_timelapse = m_support_traditional_timelapse;
m_processor.result().long_retraction_when_cut = m_config.long_retraction_when_cut;
bool activate_long_retraction_when_cut = false;
for (const auto& extruder : m_writer.extruders())
activate_long_retraction_when_cut |= (
m_config.long_retractions_when_cut.get_at(extruder.id())
&& m_config.retraction_distances_when_cut.get_at(extruder.id()) > 0
);
m_processor.result().long_retraction_when_cut = activate_long_retraction_when_cut;
{ //BBS:check bed and filament compatible
const ConfigOptionDef *bed_type_def = print_config_def.get("curr_bed_type");
@ -1918,6 +1927,12 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
m_placeholder_parser.set("initial_no_support_tool", initial_non_support_extruder_id);
m_placeholder_parser.set("initial_no_support_extruder", initial_non_support_extruder_id);
m_placeholder_parser.set("current_extruder", initial_extruder_id);
//set the key for compatibilty
m_placeholder_parser.set("retraction_distance_when_cut", m_config.retraction_distances_when_cut.get_at(initial_extruder_id));
m_placeholder_parser.set("long_retraction_when_cut", m_config.long_retractions_when_cut.get_at(initial_extruder_id));
m_placeholder_parser.set("retraction_distances_when_cut", new ConfigOptionFloats(m_config.retraction_distances_when_cut));
m_placeholder_parser.set("long_retractions_when_cut",new ConfigOptionBools(m_config.long_retractions_when_cut));
//Set variable for total layer count so it can be used in custom gcode.
m_placeholder_parser.set("total_layer_count", m_layer_count);
// Useful for sequential prints.
@ -5055,6 +5070,8 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool b
// if we are running a single-extruder setup, just set the extruder and return nothing
if (!m_writer.multiple_extruders) {
m_placeholder_parser.set("current_extruder", extruder_id);
m_placeholder_parser.set("retraction_distance_when_cut", m_config.retraction_distances_when_cut.get_at(extruder_id));
m_placeholder_parser.set("long_retraction_when_cut", m_config.long_retractions_when_cut.get_at(extruder_id));
std::string gcode;
// Append the filament start G-code.
@ -5241,6 +5258,8 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool b
}
m_placeholder_parser.set("current_extruder", extruder_id);
m_placeholder_parser.set("retraction_distance_when_cut", m_config.retraction_distances_when_cut.get_at(extruder_id));
m_placeholder_parser.set("long_retraction_when_cut", m_config.long_retractions_when_cut.get_at(extruder_id));
// Append the filament start G-code.
const std::string &filament_start_gcode = m_config.filament_start_gcode.get_at(extruder_id);

View File

@ -22,7 +22,7 @@ namespace Slic3r {
#define BED_TEMP_TOO_HIGH_THAN_FILAMENT "bed_temperature_too_high_than_filament"
#define NOT_SUPPORT_TRADITIONAL_TIMELAPSE "not_support_traditional_timelapse"
#define NOT_GENERATE_TIMELAPSE "not_generate_timelapse"
#define LONG_RETRACTION_WHEN_CUT "activate_long_retration_when_cut"
#define LONG_RETRACTION_WHEN_CUT "activate_long_retraction_when_cut"
enum class EMoveType : unsigned char
{

View File

@ -871,7 +871,8 @@ static std::vector<std::string> s_Preset_filament_options {
"filament_wipe_distance", "additional_cooling_fan_speed",
"nozzle_temperature_range_low", "nozzle_temperature_range_high",
//OrcaSlicer
"enable_pressure_advance", "pressure_advance", "chamber_temperatures","filament_notes"
"enable_pressure_advance", "pressure_advance", "chamber_temperatures","filament_notes",
"filament_long_retractions_when_cut","filament_retraction_distances_when_cut"
};
static std::vector<std::string> s_Preset_machine_limits_options {
@ -894,13 +895,13 @@ static std::vector<std::string> s_Preset_printer_options {
"scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode",
"nozzle_type","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types","support_chamber_temp_control","support_air_filtration","printer_structure","thumbnail_size",
"best_object_pos","head_wrap_detect_zone","printer_notes",
"enable_long_retraction_when_cut","long_retractions_when_cut","retraction_distances_when_cut",
//OrcaSlicer
"host_type", "print_host", "printhost_apikey",
"print_host_webui",
"printhost_cafile","printhost_port","printhost_authorization_type",
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke",
"use_relative_e_distances", "extruder_type","use_firmware_retraction",
"long_retraction_when_cut","retraction_distance_when_cut","enable_long_retraction_when_cut"
"use_relative_e_distances", "extruder_type","use_firmware_retraction"
};
static std::vector<std::string> s_Preset_sla_print_options {

View File

@ -2695,21 +2695,20 @@ void PrintConfigDef::init_fff_params()
def->mode = comDevelop;
def->set_default_value(new ConfigOptionBool {false});
def = this->add("long_retraction_when_cut", coBool);
def = this->add("long_retractions_when_cut", coBools);
def->label = L("Long retraction when cut(experimental)");
def->tooltip = L("Experimental feature.Retracting and cutting off the filament at a longer distance during changes to minimize purge."
"While this reduces flush significantly, it may also raise the risk of nozzle clogs or other printing problems.");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionBool {false});
def->set_default_value(new ConfigOptionBools {false});
def = this->add("retraction_distance_when_cut",coFloat);
def = this->add("retraction_distances_when_cut",coFloats);
def->label = L("Retraction distance when cut");
def->tooltip = L("Experimental feature.Retraction length before cutting off during filament change");
def->mode = comDevelop;
def->min = 10;
def->max = 20;
def->set_default_value(new ConfigOptionFloat {20});
def->max = 18;
def->set_default_value(new ConfigOptionFloats {18});
def = this->add("retract_length_toolchange", coFloats);
def->label = L("Length");
@ -3847,7 +3846,10 @@ void PrintConfigDef::init_fff_params()
// bools
"retract_when_changing_layer", "wipe",
// percents
"retract_before_wipe"}) {
"retract_before_wipe",
"long_retractions_when_cut",
"retraction_distances_when_cut"
}) {
auto it_opt = options.find(opt_key);
assert(it_opt != options.end());
def = this->add_nullable(std::string("filament_") + opt_key, it_opt->second.type);
@ -3858,6 +3860,8 @@ void PrintConfigDef::init_fff_params()
def->enum_keys_map = it_opt->second.enum_keys_map;
def->enum_labels = it_opt->second.enum_labels;
def->enum_values = it_opt->second.enum_values;
def->min = it_opt->second.min;
def->max = it_opt->second.max;
//BBS: shown specific filament retract config because we hide the machine retract into comDevelop mode
if ((strcmp(opt_key, "retraction_length") == 0) ||
(strcmp(opt_key, "z_hop") == 0))
@ -3891,16 +3895,18 @@ void PrintConfigDef::init_extruder_option_keys()
"retraction_length", "z_hop", "z_hop_types", "retraction_speed", "retract_lift_above", "retract_lift_below","deretraction_speed",
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour",
"default_filament_profile"
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
};
m_extruder_retract_keys = {
"deretraction_speed",
"long_retractions_when_cut",
"retract_before_wipe",
"retract_lift_above",
"retract_lift_below",
"retract_restart_extra",
"retract_when_changing_layer",
"retraction_distances_when_cut",
"retraction_length",
"retraction_minimum_travel",
"retraction_speed",
@ -3919,14 +3925,16 @@ void PrintConfigDef::init_filament_option_keys()
"retraction_length", "z_hop", "z_hop_types", "retraction_speed", "deretraction_speed",
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
"default_filament_profile"
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
};
m_filament_retract_keys = {
"deretraction_speed",
"long_retractions_when_cut",
"retract_before_wipe",
"retract_restart_extra",
"retract_when_changing_layer",
"retraction_distances_when_cut",
"retraction_length",
"retraction_minimum_travel",
"retraction_speed",
@ -4681,7 +4689,8 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
"remove_freq_sweep", "remove_bed_leveling", "remove_extrusion_calibration",
"support_transition_line_width", "support_transition_speed", "bed_temperature", "bed_temperature_initial_layer",
"can_switch_nozzle_type", "can_add_auxiliary_fan", "extra_flush_volume", "spaghetti_detector", "adaptive_layer_height",
"z_hop_type","nozzle_hrc","chamber_temperature","only_one_wall_top","bed_temperature_difference"
"z_hop_type","nozzle_hrc","chamber_temperature","only_one_wall_top","bed_temperature_difference","long_retraction_when_cut",
"retraction_distance_when_cut"
};
if (ignore.find(opt_key) != ignore.end()) {

View File

@ -916,8 +916,8 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloats, retraction_length))
((ConfigOptionFloats, retract_length_toolchange))
((ConfigOptionBool, enable_long_retraction_when_cut))
((ConfigOptionBool, long_retraction_when_cut))
((ConfigOptionFloat, retraction_distance_when_cut))
((ConfigOptionFloats, retraction_distances_when_cut))
((ConfigOptionBools, long_retractions_when_cut))
((ConfigOptionFloats, z_hop))
// BBS
((ConfigOptionEnumsGeneric, z_hop_types))

View File

@ -463,6 +463,45 @@ void Sidebar::priv::hide_rich_tip(wxButton* btn)
}
#endif
std::vector<int> get_min_flush_volumes()
{
std::vector<int>extra_flush_volumes;
const auto& full_config = wxGetApp().preset_bundle->full_config();
auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
ConfigOption* nozzle_volume_opt = printer_config.option("nozzle_volume");
int nozzle_volume_val = nozzle_volume_opt ? (int)nozzle_volume_opt->getFloat() : 0;
bool machine_enabled = printer_config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value;
bool machine_activated = printer_config.option<ConfigOptionBools>("long_retractions_when_cut")->values[0] == 1;
auto filament_retraction_distance_when_cut = full_config.option<ConfigOptionFloats>("filament_retraction_distances_when_cut");
auto printer_retraction_distance_when_cut = full_config.option<ConfigOptionFloats>("retraction_distances_when_cut");
auto filament_long_retractions_when_cut = full_config.option<ConfigOptionBools>("filament_long_retractions_when_cut");
size_t filament_size = filament_retraction_distance_when_cut->values.size();
for (size_t idx = 0; idx < filament_size; ++idx) {
int extra_flush_volume = nozzle_volume_val;
int retract_length = machine_enabled && machine_activated ? printer_retraction_distance_when_cut->values[0] : 0;
char filament_activated = filament_long_retractions_when_cut->values[idx];
double filament_retract_length = filament_retraction_distance_when_cut->values[idx];
if(filament_activated == 0)
retract_length = 0;
else if (filament_activated == 1 && machine_enabled) {
if (!std::isnan(filament_retract_length))
retract_length = (int)filament_retraction_distance_when_cut->values[idx];
else
retract_length = printer_retraction_distance_when_cut->values[0];
}
extra_flush_volume -= PI * 1.75 * 1.75 / 4 * retract_length;
extra_flush_volumes.emplace_back(extra_flush_volume);
}
return extra_flush_volumes;
}
// Sidebar / public
static struct DynamicFilamentList : DynamicList
@ -778,22 +817,14 @@ Sidebar::Sidebar(Plater *parent)
p->m_flushing_volume_btn->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent &e)
{
auto& project_config = wxGetApp().preset_bundle->project_config;
auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
const std::vector<double>& init_extruders = (project_config.option<ConfigOptionFloats>("flush_volumes_vector"))->values;
ConfigOption* extra_flush_volume_opt = printer_config.option("nozzle_volume");
int extra_flush_volume = extra_flush_volume_opt ? (int)extra_flush_volume_opt->getFloat() : 0;
bool activate = printer_config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value && printer_config.option<ConfigOptionBool>("long_retraction_when_cut")->value;
float extra_retract_length = activate && printer_config.option<ConfigOptionBool>("long_retraction_when_cut")->value ? printer_config.option<ConfigOptionFloat>("retraction_distance_when_cut")->value : 0;
float extra_retract_volume = PI * 1.75 * 1.75 / 4 * extra_retract_length;
extra_flush_volume = (int)std::max(0.f, extra_flush_volume - extra_retract_volume);
ConfigOptionFloat* flush_multi_opt = project_config.option<ConfigOptionFloat>("flush_multiplier");
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
const std::vector<std::string> extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config();
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours, extra_flush_volume, flush_multiplier);
const auto& extra_flush_volumes = get_min_flush_volumes();
WipingDialog dlg(parent, cast<float>(init_matrix), cast<float>(init_extruders), extruder_colours, extra_flush_volumes, flush_multiplier);
if (dlg.ShowModal() == wxID_OK) {
std::vector<float> matrix = dlg.get_matrix();
std::vector<float> extruders = dlg.get_extruders();
@ -1937,17 +1968,12 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
const std::vector<double>& init_extruders = (project_config.option<ConfigOptionFloats>("flush_volumes_vector"))->values;
ConfigOption* extra_flush_volume_opt = printer_config.option("nozzle_volume");
int extra_flush_volume = extra_flush_volume_opt ? (int)extra_flush_volume_opt->getFloat() : 0;
bool activate = printer_config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value && printer_config.option<ConfigOptionBool>("long_retraction_when_cut")->value;
float extra_retract_length = activate && printer_config.option<ConfigOptionBool>("long_retraction_when_cut")->value ? printer_config.option<ConfigOptionFloat>("retraction_distance_when_cut")->value : 0;
float extra_retract_volume = PI * 1.75 * 1.75 / 4 * extra_retract_length;
extra_flush_volume = (int)std::max(0.f, extra_flush_volume - extra_retract_volume);
const std::vector<int>& min_flush_volumes= get_min_flush_volumes();
ConfigOptionFloat* flush_multi_opt = project_config.option<ConfigOptionFloat>("flush_multiplier");
float flush_multiplier = flush_multi_opt ? flush_multi_opt->getFloat() : 1.f;
std::vector<double> matrix = init_matrix;
int m_min_flush_volume = extra_flush_volume;
int m_max_flush_volume = Slic3r::g_max_flush_volume;
unsigned int m_number_of_extruders = (int)(sqrt(init_matrix.size()) + 0.001);
@ -1974,12 +2000,10 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
if (modify_id >= 0 && modify_id < multi_colours.size()) {
for (int i = 0; i < multi_colours.size(); ++i) {
Slic3r::FlushVolCalculator calculator(m_min_flush_volume, m_max_flush_volume);
// from to modify
int from_idx = i;
if (from_idx != modify_id) {
Slic3r::FlushVolCalculator calculator(min_flush_volumes[from_idx], m_max_flush_volume);
int flushing_volume = 0;
bool is_from_support = is_support_filament(from_idx);
bool is_to_support = is_support_filament(modify_id);
@ -2004,6 +2028,7 @@ void Sidebar::auto_calc_flushing_volumes(const int modify_id)
// modify to to
int to_idx = i;
if (to_idx != modify_id) {
Slic3r::FlushVolCalculator calculator(min_flush_volumes[modify_id], m_max_flush_volume);
bool is_from_support = is_support_filament(modify_id);
bool is_to_support = is_support_filament(to_idx);
int flushing_volume = 0;
@ -6330,11 +6355,9 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
view3D->deselect_all();
}
// update flush matrix
auto& project_config = wxGetApp().preset_bundle->project_config;
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
for (size_t idx = 0; idx < init_matrix.size(); ++idx)
size_t filament_size = wxGetApp().plater()->get_extruder_colors_from_plater_config().size();
for (size_t idx = 0; idx < filament_size; ++idx)
wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(idx);
}
#ifdef __WXMSW__

View File

@ -776,6 +776,7 @@ private:
bool m_was_scheduled;
};
std::vector<int> get_min_flush_volumes();
} // namespace GUI
} // namespace Slic3r

View File

@ -1537,16 +1537,40 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
}
}
auto update_flush_volume = []() {
auto& project_config = wxGetApp().preset_bundle->project_config;
const std::vector<double>& init_matrix = (project_config.option<ConfigOptionFloats>("flush_volumes_matrix"))->values;
for (size_t idx = 0; idx < init_matrix.size(); ++idx)
// -1 means caculate all
auto update_flush_volume = [](int idx = -1) {
if (idx < 0) {
size_t filament_size = wxGetApp().plater()->get_extruder_colors_from_plater_config().size();
for (size_t i = 0; i < filament_size; ++i)
wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(i);
}
else
wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(idx);
};
if(opt_key == "long_retraction_when_cut"){
bool activate = boost::any_cast<bool>(value);
if (activate) {
string opt_key_without_idx = opt_key.substr(0, opt_key.find('#'));
if (opt_key_without_idx == "long_retractions_when_cut") {
unsigned char activate = boost::any_cast<unsigned char>(value);
if (activate == 1) {
MessageDialog dialog(wxGetApp().plater(),
_L("Experimental feature: Retracting and cutting off the filament at a greater distance during filament changes to minimize flush."
"Although it can notably reduce flush, it may also elevate the risk of nozzle clogs or other printing complications."), "", wxICON_WARNING | wxOK);
dialog.ShowModal();
}
update_flush_volume();
}
if (opt_key_without_idx == "retraction_distances_when_cut")
update_flush_volume();
if (opt_key == "filament_long_retractions_when_cut"){
unsigned char activate = boost::any_cast<unsigned char>(value);
if (activate == 1) {
MessageDialog dialog(wxGetApp().plater(),
_L("Experimental feature: Retracting and cutting off the filament at a greater distance during filament changes to minimize flush."
"Although it can notably reduce flush, it may also elevate the risk of nozzle clogs or other printing complications."), "", wxICON_WARNING | wxOK);
@ -1555,9 +1579,10 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
update_flush_volume();
}
if (opt_key == "retraction_distance_when_cut") {
if (opt_key == "filament_retraction_distances_when_cut")
update_flush_volume();
}
// BBS
#if 0
if (opt_key == "extruders_count")
@ -2895,7 +2920,9 @@ void TabFilament::add_filament_overrides_page()
"filament_wipe",
//BBS
"filament_wipe_distance",
"filament_retract_before_wipe"
"filament_retract_before_wipe",
"filament_long_retractions_when_cut",
"filament_retraction_distances_when_cut"
})
append_single_option_line(opt_key, extruder_idx);
}
@ -2927,7 +2954,9 @@ void TabFilament::update_filament_overrides_page()
"filament_wipe",
//BBS
"filament_wipe_distance",
"filament_retract_before_wipe"
"filament_retract_before_wipe",
"filament_long_retractions_when_cut",
"filament_retraction_distances_when_cut"
};
const int extruder_idx = 0; // #ys_FIXME
@ -2944,8 +2973,19 @@ void TabFilament::update_filament_overrides_page()
m_overrides_options[opt_key]->SetValue(is_checked);
Field* field = optgroup->get_fieldc(opt_key, extruder_idx);
if (field != nullptr)
field->toggle(is_checked);
if (field != nullptr) {
if (opt_key == "filament_long_retractions_when_cut") {
bool machine_enabled = wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value;
field->toggle(is_checked&&machine_enabled);
}
else if (opt_key == "filament_retraction_distances_when_cut") {
bool machine_enabled = wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionBool>("enable_long_retraction_when_cut")->value;
bool filament_enabled = m_config->option<ConfigOptionBools>("filament_long_retractions_when_cut")->values[extruder_idx]==1;
field->toggle(is_checked && filament_enabled && machine_enabled);
}
else
field->toggle(is_checked);
}
}
}
@ -3907,8 +3947,9 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
optgroup = page->new_optgroup(L("Retraction when switching material"), L"param_retraction", -1, true);
optgroup->append_single_option_line("retract_length_toolchange", "", extruder_idx);
optgroup->append_single_option_line("retract_restart_extra_toolchange", "", extruder_idx);
optgroup->append_single_option_line("long_retraction_when_cut", "");
optgroup->append_single_option_line("retraction_distance_when_cut", "");
// do not display this params now
optgroup->append_single_option_line("long_retractions_when_cut", "", extruder_idx);
optgroup->append_single_option_line("retraction_distances_when_cut", "", extruder_idx);
#if 0
//optgroup = page->new_optgroup(L("Preview"), -1, true);
@ -4148,9 +4189,9 @@ void TabPrinter::toggle_options()
bool toolchange_retraction = m_config->opt_float("retract_length_toolchange", i) > 0;
toggle_option("retract_restart_extra_toolchange", have_multiple_extruders && toolchange_retraction, i);
toggle_option("long_retraction_when_cut", !use_firmware_retraction && m_config->opt_bool("enable_long_retraction_when_cut"));
toggle_line("retraction_distance_when_cut", m_config->opt_bool("long_retraction_when_cut"));
// do not display this extruder param now
toggle_option("long_retractions_when_cut", !use_firmware_retraction && m_config->opt_bool("enable_long_retraction_when_cut"),i);
toggle_option("retraction_distances_when_cut", m_config->opt_bool("long_retractions_when_cut",i),i);
}
if (m_active_page->title() == "Motion ability") {

View File

@ -194,7 +194,7 @@ void WipingDialog::on_dpi_changed(const wxRect &suggested_rect)
// Parent dialog for purging volume adjustments - it fathers WipingPanel widget (that contains all controls) and a button to toggle simple/advanced mode:
WipingDialog::WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<float>& extruders, const std::vector<std::string>& extruder_colours,
int extra_flush_volume, float flush_multiplier)
const std::vector<int>&extra_flush_volume, float flush_multiplier)
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe),
wxID_ANY,
_(L("Flushing volumes for filament change")),
@ -294,7 +294,7 @@ void WipingPanel::create_panels(wxWindow* parent, const int num) {
// This panel contains all control widgets for both simple and advanced mode (these reside in separate sizers)
WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<float>& extruders, const std::vector<std::string>& extruder_colours, Button* calc_button,
int extra_flush_volume, float flush_multiplier)
const std::vector<int>& extra_flush_volume, float flush_multiplier)
: wxPanel(parent,wxID_ANY, wxDefaultPosition, wxDefaultSize/*,wxBORDER_RAISED*/)
,m_matrix(matrix), m_min_flush_volume(extra_flush_volume), m_max_flush_volume(Slic3r::g_max_flush_volume)
{
@ -423,7 +423,7 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
multi_desc_label->SetForegroundColour(g_text_color);
m_sizer_advanced->Add(multi_desc_label, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING);
wxString min_flush_str = wxString::Format(_L("Suggestion: Flushing Volume in range [%d, %d]"), m_min_flush_volume, m_max_flush_volume);
wxString min_flush_str = wxString::Format(_L("Suggestion: Flushing Volume in range [%d, %d]"),*std::min_element(m_min_flush_volume.begin(), m_min_flush_volume.end()), m_max_flush_volume);
m_min_flush_label = new wxStaticText(m_page_advanced, wxID_ANY, min_flush_str, wxDefaultPosition, wxDefaultSize, 0);
m_min_flush_label->SetForegroundColour(g_text_color);
m_sizer_advanced->Add(m_min_flush_label, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING);
@ -598,9 +598,9 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector<float>& matrix, con
});
}
int WipingPanel::calc_flushing_volume(const wxColour& from_, const wxColour& to_)
int WipingPanel::calc_flushing_volume(const wxColour& from_, const wxColour& to_ ,int min_flush_volume)
{
Slic3r::FlushVolCalculator calculator(m_min_flush_volume, m_max_flush_volume);
Slic3r::FlushVolCalculator calculator(min_flush_volume, m_max_flush_volume);
return calculator.calc_flush_vol(from_.Alpha(), from_.Red(), from_.Green(), from_.Blue(), to_.Alpha(), to_.Red(), to_.Green(), to_.Blue());
}
@ -623,7 +623,7 @@ void WipingPanel::update_warning_texts()
auto text_box = box_vec[j];
wxString str = text_box->GetValue();
int actual_volume = wxAtoi(str);
if (actual_volume < m_min_flush_volume || actual_volume > m_max_flush_volume) {
if (actual_volume < m_min_flush_volume[i] || actual_volume > m_max_flush_volume) {
if (text_box->GetForegroundColour() != g_warning_color) {
text_box->SetForegroundColour(g_warning_color);
text_box->Refresh();
@ -688,7 +688,7 @@ void WipingPanel::calc_flushing_volumes()
const wxColour& from = multi_colors[from_idx][i];
for (int j = 0; j < multi_colors[to_idx].size(); ++j) {
const wxColour& to = multi_colors[to_idx][j];
int volume = calc_flushing_volume(from, to);
int volume = calc_flushing_volume(from, to, m_min_flush_volume[from_idx]);
flushing_volume = std::max(flushing_volume, volume);
}
}

View File

@ -16,7 +16,7 @@ class WipingPanel : public wxPanel {
public:
// BBS
WipingPanel(wxWindow* parent, const std::vector<float>& matrix, const std::vector<float>& extruders, const std::vector<std::string>& extruder_colours, Button* calc_button,
int extra_flush_volume, float flush_multiplier);
const std::vector<int>& extra_flush_volume, float flush_multiplier);
std::vector<float> read_matrix_values();
std::vector<float> read_extruders_values();
void toggle_advanced(bool user_action = false);
@ -36,7 +36,7 @@ public:
private:
void fill_in_matrix();
bool advanced_matches_simple();
int calc_flushing_volume(const wxColour& from, const wxColour& to);
int calc_flushing_volume(const wxColour& from, const wxColour& to,int min_flush_volume);
void update_warning_texts();
std::vector<wxSpinCtrl*> m_old;
@ -58,7 +58,7 @@ private:
std::vector<wxButton *> icon_list1;
std::vector<wxButton *> icon_list2;
const int m_min_flush_volume;
const std::vector<int> m_min_flush_volume;
const int m_max_flush_volume;
wxTextCtrl* m_flush_multiplier_ebox = nullptr;
@ -75,7 +75,7 @@ class WipingDialog : public Slic3r::GUI::DPIDialog
{
public:
WipingDialog(wxWindow* parent, const std::vector<float>& matrix, const std::vector<float>& extruders, const std::vector<std::string>& extruder_colours,
int extra_flush_volume, float flush_multiplier);
const std::vector<int>&extra_flush_volume,float flush_multiplier);
std::vector<float> get_matrix() const { return m_output_matrix; }
std::vector<float> get_extruders() const { return m_output_extruders; }
wxBoxSizer* create_btn_sizer(long flags);