fix annoying check when setting big width with big nozzle

also fix error when setting a width too small
This commit is contained in:
remi durand 2021-06-02 22:20:50 +02:00
parent f6c663cc70
commit 77316cea73
2 changed files with 151 additions and 109 deletions

View File

@ -236,6 +236,7 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Do not use the 'Avoid crossing perimeters' on the first layer.");
def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(true));
def = this->add("avoid_crossing_perimeters_max_detour", coFloatOrPercent);
def->label = L("Avoid crossing perimeters - Max detour length");
def->category = OptionCategory::perimeter;
@ -5945,8 +5946,10 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
double max_nozzle_diameter = 0;
for (double dmr : nozzle_diameter_option->values)
max_nozzle_diameter = std::max(max_nozzle_diameter, dmr);
ConfigOptionFloatOrPercent* spacing_option = nullptr;
try {
if (opt_key == "extrusion_width") {
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("extrusion_spacing");
if (width_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -5957,7 +5960,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
}
if (opt_key == "first_layer_extrusion_width") {
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("first_layer_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("first_layer_extrusion_spacing");
if (width_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -5969,7 +5972,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
if (opt_key == "perimeter_extrusion_width") {
const ConfigOptionPercent* perimeter_overlap_option = find_option<ConfigOptionPercent>("perimeter_overlap", this, config_collection);
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("perimeter_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("perimeter_extrusion_spacing");
if (width_option && perimeter_overlap_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -5982,7 +5985,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
if (opt_key == "external_perimeter_extrusion_width") {
const ConfigOptionPercent* external_perimeter_overlap_option = find_option<ConfigOptionPercent>("external_perimeter_overlap", this, config_collection);
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("external_perimeter_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("external_perimeter_extrusion_spacing");
if (width_option && external_perimeter_overlap_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -5994,7 +5997,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
}
if (opt_key == "infill_extrusion_width") {
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("infill_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("infill_extrusion_spacing");
if (width_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -6005,7 +6008,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
}
if (opt_key == "solid_infill_extrusion_width") {
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("solid_infill_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("solid_infill_extrusion_spacing");
if (width_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -6016,7 +6019,7 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
}
}
if (opt_key == "top_infill_extrusion_width") {
ConfigOptionFloatOrPercent* spacing_option = this->option<ConfigOptionFloatOrPercent>("top_infill_extrusion_spacing");
spacing_option = this->option<ConfigOptionFloatOrPercent>("top_infill_extrusion_spacing");
if (width_option) {
width_option->set_phony(false);
spacing_option->set_phony(true);
@ -6042,6 +6045,27 @@ bool DynamicPrintConfig::value_changed(const t_config_option_key& opt_key, const
// this->set_key_value("skirt_extrusion_spacing", new ConfigOptionFloatOrPercent(std::round(flow.spacing() * 10000) / 10000, false));
// something_changed = true;
//}
} catch (FlowErrorNegativeSpacing) {
if (spacing_option != nullptr) {
width_option->set_phony(true);
spacing_option->set_phony(false);
spacing_option->value = 100;
spacing_option->percent = true;
Flow flow = Flow::new_from_spacing(spacing_option->get_abs_value(max_nozzle_diameter), max_nozzle_diameter, layer_height_option->value, false);
width_option->value = (spacing_option->percent) ? std::round(100 * flow.width / max_nozzle_diameter) : (std::round(flow.width * 10000) / 10000);
width_option->percent = spacing_option->percent;
something_changed = true;
} else {
width_option->value = 100;
width_option->percent = true;
width_option->set_phony(false);
spacing_option->set_phony(true);
Flow flow = Flow::new_from_config_width(FlowRole::frPerimeter, *width_option, max_nozzle_diameter, layer_height_option->value, 0);
spacing_option->value = (width_option->percent) ? std::round(100 * flow.spacing() / max_nozzle_diameter) : (std::round(flow.spacing() * 10000) / 10000);
spacing_option->percent = width_option->percent;
something_changed = true;
}
}
}
}
return something_changed;

View File

@ -7,6 +7,7 @@
#include "MainFrame.hpp"
#include "format.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/PrintConfig.hpp"
#include <regex>
@ -329,6 +330,23 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
(m_opt.sidetext.rfind("mm ") != std::string::npos && val > 1)) &&
(m_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast<std::string>(m_value)))
{
// exceptions
if (std::set<t_config_option_key>{"infill_anchor", "infill_anchor_max", "avoid_crossing_perimeters_max_detour"}.count(m_opt.opt_key) > 0) {
m_value = std::string(str.ToUTF8().data());
break;
}
if (m_opt.opt_key.find("extrusion_width") != std::string::npos || m_opt.opt_key.find("extrusion_spacing") != std::string::npos) {
const DynamicPrintConfig& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
const std::vector<double> &nozzle_diameters = printer_config.option<ConfigOptionFloats>("nozzle_diameter")->values;
double nozzle_diameter = 0;
for(double diameter : nozzle_diameters)
nozzle_diameter = std::max(nozzle_diameter, diameter);
if (val < nozzle_diameter * 10) {
m_value = std::string(str.ToUTF8().data());
break;
}
}
if (!check_value) {
m_value.clear();
break;
@ -353,8 +371,8 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
}
m_value = std::string(str.ToUTF8().data());
break; }
break;
}
case coPoints: {
std::vector<Vec2d> out_values;
str.Replace(" ", wxEmptyString, true);