Skip to content

Commit

Permalink
fix & change for 2.4: variables, flow, gui refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Mar 16, 2022
2 parents d989d6a + 67352b5 commit 225a855
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 81 deletions.
6 changes: 5 additions & 1 deletion src/libslic3r/Brim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,11 @@ void make_brim(const Print& print, const Flow& flow, const PrintObjectPtrs& obje
if (!object->support_layers().empty()) {
Polygons polys = object->support_layers().front()->support_fills.polygons_covered_by_spacing(flow.spacing_ratio(), float(SCALED_EPSILON));
for (Polygon poly : polys) {
object_islands.emplace_back(brim_offset == 0 ? ExPolygon{ poly } : offset_ex(Polygons{ poly }, brim_offset)[0]);
if (brim_offset == 0) {
object_islands.emplace_back(poly);
} else {
append(object_islands, offset_ex(Polygons{ poly }, brim_offset));
}
}
}
islands.reserve(islands.size() + object_islands.size() * object->instances().size());
Expand Down
10 changes: 9 additions & 1 deletion src/libslic3r/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,11 +933,19 @@ ConfigSubstitutions ConfigBase::load(const boost::property_tree::ptree &tree, Fo
{
ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
for (const boost::property_tree::ptree::value_type &v : tree) {
t_config_option_key opt_key = v.first;
try {
t_config_option_key opt_key = v.first;
this->set_deserialize(opt_key, v.second.get_value<std::string>(), substitutions_ctxt);
} catch (UnknownOptionException & /* e */) {
// ignore
} catch (BadOptionValueException & e) {
if (compatibility_rule == ForwardCompatibilitySubstitutionRule::Disable)
throw e;
// log the error
const ConfigDef* def = this->def();
if (def == nullptr) throw e;
const ConfigOptionDef* optdef = def->get(opt_key);
substitutions_ctxt.substitutions.emplace_back(optdef, v.second.get_value<std::string>(), ConfigOptionUniquePtr(optdef->default_value->clone()));
}
}
return std::move(substitutions_ctxt.substitutions);
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ struct ConfigSubstitution {
const ConfigOptionDef *opt_def { nullptr };
std::string old_value;
ConfigOptionUniquePtr new_value;
ConfigSubstitution() = default;
ConfigSubstitution(const ConfigOptionDef* def, std::string old, ConfigOptionUniquePtr&& new_v) : opt_def(def), old_value(old), new_value(std::move(new_v)) {}
};

using ConfigSubstitutions = std::vector<ConfigSubstitution>;
Expand Down
5 changes: 4 additions & 1 deletion src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,14 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
// Emit machine envelope limits for the Marlin firmware.
this->print_machine_envelope(file, print);

//add variables from filament_custom_variables
// Add variables from filament_custom_variables
m_placeholder_parser.parse_custom_variables(m_config.print_custom_variables);
m_placeholder_parser.parse_custom_variables(m_config.printer_custom_variables);
m_placeholder_parser.parse_custom_variables(m_config.filament_custom_variables);

// Add physical printer variables
m_placeholder_parser.apply_config(print.physical_printer_config());

// Let the start-up script prime the 1st printing tool.
m_placeholder_parser.set("initial_tool", initial_extruder_id);
m_placeholder_parser.set("initial_extruder", initial_extruder_id);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/LayerRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
BridgeDetector bd(
initial,
lower_layer->lslices,
this->flow(frInfill, true).scaled_width()
this->flow(frInfill).scaled_width()
);
#ifdef SLIC3R_DEBUG
printf("Processing bridge at layer %zu:\n", this->layer()->id());
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PlaceholderParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ void PlaceholderParser::append_custom_variables(std::map<std::string, std::vecto

bool is_array = nb_extruders > 0;
if (!is_array) nb_extruders = 1;
SLIC3R_REGEX_NAMESPACE::regex is_a_name("[a-zA-Z_]+");
SLIC3R_REGEX_NAMESPACE::regex is_a_name("[a-zA-Z_0-9]+");
for (const auto& entry : name2var_array) {
if (entry.first.empty())
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
&& (ignore_phony || !(this_opt->is_phony() && other_opt->is_phony()))
&& ((*this_opt != *other_opt) || (this_opt->is_phony() != other_opt->is_phony())))
{
if (opt_key == "bed_shape" || opt_key == "compatible_prints" || opt_key == "compatible_printers" || "filament_ramming_parameters" || "gcode_substitutions") {
if (opt_key == "bed_shape" || opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "filament_ramming_parameters" || opt_key == "gcode_substitutions") {
// Scalar variable, or a vector variable, which is independent from number of extruders,
// thus the vector is presented to the user as a single input.
// Merill: these are 'button' special settings.
Expand Down
5 changes: 3 additions & 2 deletions src/libslic3r/Print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,11 @@ class Print : public PrintBaseWithState<PrintStep, psCount>

//put this in public to be accessible for tests, it was in private before.
bool invalidate_state_by_config_options(const ConfigOptionResolver& new_config, const std::vector<t_config_option_key> &opt_keys);
protected:

// Invalidates the step, and its depending steps in Print.
//in public to invalidate gcode when the physical printer change. It's needed if we allow the gcode macro to read these values.
bool invalidate_step(PrintStep step);

protected:
private:

void _make_skirt(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out, std::optional<ExtrusionEntityCollection> &out_first_layer);
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/PrintBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ class PrintBase : public ObjectBase

const PlaceholderParser& placeholder_parser() const { return m_placeholder_parser; }
const DynamicPrintConfig& full_print_config() const { return m_full_print_config; }
const DynamicPrintConfig& physical_printer_config() const { return m_physical_printer_config; }
DynamicPrintConfig& physical_printer_config() { return m_physical_printer_config; }

virtual std::string output_filename(const std::string &filename_base = std::string()) const = 0;
// If the filename_base is set, it is used as the input for the template processing. In that case the path is expected to be the directory (may be empty).
Expand Down Expand Up @@ -525,6 +527,7 @@ class PrintBase : public ObjectBase

Model m_model;
DynamicPrintConfig m_full_print_config;
DynamicPrintConfig m_physical_printer_config;
PlaceholderParser m_placeholder_parser;

// Callback to be evoked regularly to update state of the UI thread.
Expand Down
20 changes: 13 additions & 7 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,13 +1743,15 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::filament;
def->tooltip = L("You can add data accessible to custom-gcode macros."
"\nEach line can define one variable."
"\nThe format is 'variable_name=value'. the variabel name should only have [a-zA-Z] characters or '_'."
"\nThe format is 'variable_name=value'. The variable name should only have [a-zA-Z0-9] characters or '_'."
"\nA value that can be parsed as a int or float will be avaible as a numeric value."
"\nA value that is enclosed by double-quotes will be available as a string (without the quotes)"
"\nA value that only takes values as 'true' or 'false' will be a boolean)"
"\nEvery other value will be parsed as a string as-is."
"\nThese varibles will be available as an array in the custom gcode (one item per extruder), don't forget to use them with the {current_extruder} index to get the current value."
" If a filament has a typo on the variable that change its type, then the parser will convert evrything to strings.");
"\nThese variables will be available as an array in the custom gcode (one item per extruder), don't forget to use them with the {current_extruder} index to get the current value."
" If a filament has a typo on the variable that change its type, then the parser will convert evrything to strings."
"\nAdvice: before using a variable, it's safer to use the function 'default_XXX(variable_name, default_value)'"
" (enclosed in bracket as it's a script) in case it's not set. You can replace XXX by 'int' 'bool' 'double' 'string'.");
def->multiline = true;
def->full_width = true;
def->height = 13;
Expand Down Expand Up @@ -3567,11 +3569,13 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::filament;
def->tooltip = L("You can add data accessible to custom-gcode macros."
"\nEach line can define one variable."
"\nThe format is 'variable_name=value'. the variabel name should only have [a-zA-Z] characters or '_'."
"\nThe format is 'variable_name=value'. the variable name should only have [a-zA-Z0-9] characters or '_'."
"\nA value that can be parsed as a int or float will be avaible as a numeric value."
"\nA value that is enclosed by double-quotes will be available as a string (without the quotes)"
"\nA value that only takes values as 'true' or 'false' will be a boolean)"
"\nEvery other value will be parsed as a string as-is.");
"\nEvery other value will be parsed as a string as-is."
"\nAdvice: before using a variable, it's safer to use the function 'default_XXX(variable_name, default_value)'"
" (enclosed in bracket as it's a script) in case it's not set. You can replace XXX by 'int' 'bool' 'double' 'string'.");
def->multiline = true;
def->full_width = true;
def->height = 13;
Expand Down Expand Up @@ -3913,11 +3917,13 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::filament;
def->tooltip = L("You can add data accessible to custom-gcode macros."
"\nEach line can define one variable."
"\nThe format is 'variable_name=value'. the variabel name should only have [a-zA-Z] characters or '_'."
"\nThe format is 'variable_name=value'. the variable name should only have [a-zA-Z0-9] characters or '_'."
"\nA value that can be parsed as a int or float will be avaible as a numeric value."
"\nA value that is enclosed by double-quotes will be available as a string (without the quotes)"
"\nA value that only takes values as 'true' or 'false' will be a boolean)"
"\nEvery other value will be parsed as a string as-is.");
"\nEvery other value will be parsed as a string as-is."
"\nAdvice: before using a variable, it's safer to use the function 'default_XXX(variable_name, default_value)'"
" (enclosed in bracket as it's a script) in case it's not set. You can replace XXX by 'int' 'bool' 'double' 'string'.");
def->multiline = true;
def->full_width = true;
def->height = 13;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ bool PrintObject::invalidate_state_by_config_options(
std::vector<uint16_t> dense_priority;
const ExPolygons surfs_with_overlap = { surface.expolygon };
// create a surface with overlap to allow the dense thing to bond to the infill
coord_t scaled_width = layerm->flow(frInfill, true).scaled_width();
coord_t scaled_width = layerm->flow(frInfill).scaled_width();
coord_t overlap = scaled_width / 4;
for (const ExPolygon& surf_with_overlap : surfs_with_overlap) {
ExPolygons sparse_polys = { surf_with_overlap };
Expand Down
64 changes: 43 additions & 21 deletions src/libslic3r/SupportMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

namespace Slic3r {

// how much we extend support around the actual contact area
//FIXME this should be dependent on the nozzle diameter!
// how much we extend support around the actual contact area
//FIXME this should be dependent on the nozzle diameter!
#define SUPPORT_MATERIAL_MARGIN 1.5

// Increment used to reach MARGIN in steps to avoid trespassing thin objects
Expand All @@ -64,6 +64,25 @@ namespace Slic3r {
//#define SUPPORT_SURFACES_OFFSET_PARAMETERS ClipperLib::jtMiter, 1.5
#define SUPPORT_SURFACES_OFFSET_PARAMETERS ClipperLib::jtSquare, 0.

#ifndef NDEBUG
class verify_nonempty : public ExtrusionVisitorRecursiveConst {
public:
virtual void use(const ExtrusionPath& path) override { assert(!path.empty()); }
virtual void use(const ExtrusionPath3D& path3D) override { assert(!path3D.empty()); }
virtual void use(const ExtrusionMultiPath& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
virtual void use(const ExtrusionMultiPath3D& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
virtual void use(const ExtrusionLoop& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.paths.empty());
}
virtual void use(const ExtrusionEntityCollection& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
} verifier;
#endif
#ifdef SLIC3R_DEBUG
const char* support_surface_type_to_color_name(const PrintObjectSupportMaterial::SupporLayerType surface_type)
{
Expand Down Expand Up @@ -4044,6 +4063,9 @@ void PrintObjectSupportMaterial::generate_toolpaths(
// Extrusion parameters
erSupportMaterial, flow, m_support_params.support_material_flow.spacing(),
m_object->print()->default_region_config());
#ifndef NDEBUG
support_layer.support_fills.visit(verifier);
#endif // NDEBUG
}
}

Expand Down Expand Up @@ -4081,6 +4103,9 @@ void PrintObjectSupportMaterial::generate_toolpaths(
// Extrusion parameters
(support_layer_id < m_slicing_params.base_raft_layers) ? erSupportMaterial : erSupportMaterialInterface, flow, spacing,
m_object->print()->default_region_config());
#ifndef NDEBUG
support_layer.support_fills.visit(verifier);
#endif // NDEBUG
}
});

Expand Down Expand Up @@ -4374,33 +4399,30 @@ void PrintObjectSupportMaterial::generate_toolpaths(
LayerCache &layer_cache = layer_caches[support_layer_id];
// For all extrusion types at this print_z, ordered by decreasing layer height:
for (LayerCacheItem &layer_cache_item : layer_cache.nonempty) {
if (layer_cache_item.layer_extruded->extrusions.empty()) continue;
// Trim the extrusion height from the bottom by the overlapping layers.
modulate_extrusion_by_overlapping_layers(layer_cache_item.layer_extruded->extrusions, *layer_cache_item.layer_extruded->layer, layer_cache_item.overlapping);
if (layer_cache_item.layer_extruded->extrusions.empty()) continue;
#ifndef NDEBUG
layer_cache_item.layer_extruded->extrusions.visit(verifier);
#endif // NDEBUG
support_layer.support_fills.append(std::move(layer_cache_item.layer_extruded->extrusions));
#ifndef NDEBUG
support_layer.support_fills.visit(verifier);
#endif // NDEBUG
}
}
});

#ifndef NDEBUG
class verify_nonempty : public ExtrusionVisitorRecursiveConst {
public:
virtual void use(const ExtrusionPath& path) override { assert(!path.empty()); }
virtual void use(const ExtrusionPath3D& path3D) override { assert(!path3D.empty()); }
virtual void use(const ExtrusionMultiPath& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
virtual void use(const ExtrusionMultiPath3D& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
virtual void use(const ExtrusionLoop& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.paths.empty());
}
virtual void use(const ExtrusionEntityCollection& truc) override {
ExtrusionVisitorRecursiveConst::use(truc); assert(!truc.empty());
}
} verifier;
for (const SupportLayer* support_layer : support_layers)
support_layer->support_fills.visit(verifier);
const SupportLayer* support_layer_current = nullptr;
int idx = 0;
for (const SupportLayer* support_layer : support_layers) {
support_layer_current = support_layer;
if(!support_layer->support_fills.empty())
support_layer->support_fills.visit(verifier);
idx++;
}
#endif // NDEBUG
}

Expand Down
12 changes: 11 additions & 1 deletion src/slic3r/GUI/BackgroundSlicingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,21 @@ std::pair<PrintBase::PrintValidationError, std::string> BackgroundSlicingProcess

// Apply config over the print. Returns false, if the new config values caused any of the already
// processed steps to be invalidated, therefore the task will need to be restarted.
Print::ApplyStatus BackgroundSlicingProcess::apply(const Model &model, const DynamicPrintConfig &config)
Print::ApplyStatus BackgroundSlicingProcess::apply(const Model &model, const DynamicPrintConfig &config, const DynamicPrintConfig *physical_printer_config)
{
assert(m_print != nullptr);
assert(config.opt_enum<PrinterTechnology>("printer_technology") == m_print->technology());
Print::ApplyStatus invalidated = m_print->apply(model, config);
if (physical_printer_config &&
(m_print->physical_printer_config().diff(*physical_printer_config).size() != 0 || m_print->physical_printer_config().keys() != physical_printer_config->keys()) ) {
m_print->physical_printer_config().clear();
m_print->physical_printer_config().apply(*physical_printer_config);
if (!invalidated)
invalidated = PrintBase::APPLY_STATUS_INVALIDATED;
if (m_print->technology() == ptFFF && this->m_fff_print->is_step_done(psGCodeExport)) {
this->m_fff_print->invalidate_step(psGCodeExport);
}
}
if ((invalidated & PrintBase::APPLY_STATUS_INVALIDATED) != 0 && m_print->technology() == ptFFF &&
!m_fff_print->is_step_done(psGCodeExport)) {
// Some FFF status was invalidated, and the G-code was not exported yet.
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/BackgroundSlicingProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class BackgroundSlicingProcess

// Apply config over the print. Returns false, if the new config values caused any of the already
// processed steps to be invalidated, therefore the task will need to be restarted.
PrintBase::ApplyStatus apply(const Model &model, const DynamicPrintConfig &config);
PrintBase::ApplyStatus apply(const Model &model, const DynamicPrintConfig &config, const DynamicPrintConfig *physical_printer_config);
// After calling the apply() function, set_task() may be called to limit the task to be processed by process().
// This is useful for calculating SLA supports for a single object only.
void set_task(const PrintBase::TaskParams &params);
Expand Down
Loading

0 comments on commit 225a855

Please sign in to comment.