Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsupermerill <merill@fr.fr>2022-03-16 20:57:07 +0300
committersupermerill <merill@free.fr>2022-03-17 00:49:59 +0300
commit67352b5dd8859bb79bcb1fbbaa55899eeefcbdf9 (patch)
tree74ad2438ee83a6ac136696ad483bb781a68d62f1 /src
parentf1e486ba500cfd34933532d0103ce3c829baa554 (diff)
Allow to access physical printer variables in custom gcode
Diffstat (limited to 'src')
-rw-r--r--src/libslic3r/GCode.cpp5
-rw-r--r--src/libslic3r/Print.hpp5
-rw-r--r--src/libslic3r/PrintBase.hpp3
-rw-r--r--src/slic3r/GUI/BackgroundSlicingProcess.cpp12
-rw-r--r--src/slic3r/GUI/BackgroundSlicingProcess.hpp2
-rw-r--r--src/slic3r/GUI/Plater.cpp2
6 files changed, 23 insertions, 6 deletions
diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp
index 113801240..18ce362f7 100644
--- a/src/libslic3r/GCode.cpp
+++ b/src/libslic3r/GCode.cpp
@@ -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);
diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp
index 4c9cdfebd..2078fb4f5 100644
--- a/src/libslic3r/Print.hpp
+++ b/src/libslic3r/Print.hpp
@@ -657,10 +657,11 @@ public:
//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);
diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp
index 5ab62a9c9..16a8c2f84 100644
--- a/src/libslic3r/PrintBase.hpp
+++ b/src/libslic3r/PrintBase.hpp
@@ -493,6 +493,8 @@ public:
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).
@@ -525,6 +527,7 @@ protected:
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.
diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp
index 92b792798..3a87335a8 100644
--- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp
+++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp
@@ -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.
diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.hpp b/src/slic3r/GUI/BackgroundSlicingProcess.hpp
index f726ca6e2..b22a6f77e 100644
--- a/src/slic3r/GUI/BackgroundSlicingProcess.hpp
+++ b/src/slic3r/GUI/BackgroundSlicingProcess.hpp
@@ -125,7 +125,7 @@ public:
// 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);
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index f8ef301e4..236b98756 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -3238,7 +3238,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
update_print_volume_state();
// Apply new config to the possibly running background task.
bool was_running = background_process.running();
- Print::ApplyStatus invalidated = background_process.apply(q->model(), wxGetApp().preset_bundle->full_config());
+ Print::ApplyStatus invalidated = background_process.apply(q->model(), wxGetApp().preset_bundle->full_config(), wxGetApp().preset_bundle->physical_printers.get_selected_printer_config());
// Just redraw the 3D canvas without reloading the scene to consume the update of the layer height profile.
if (view3D->is_layers_editing_enabled())