Skip to content

Commit

Permalink
default pause & color change
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Nov 16, 2023
2 parents 0836554 + 44fa0ad commit 5252d7f
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 125 deletions.
2 changes: 2 additions & 0 deletions doc/How to build - Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ cmake .. -G "Visual Studio 16 2019" -DDESTDIR="c:\src\REPO_NAME-deps"
msbuild /m ALL_BUILD.vcxproj // This took 13.5 minutes on my machine: core I7-7700K @ 4.2Ghz with 32GB main memory and 20min on a average laptop
```

note: if you have visual studio 2022 installed alongside 2017/2019, you may have to comment/remove the lines 20->31 in `dep_Boost-prefix/src/dep_Boosttools/build/src/engine/vswhere_usability_wrapper.cmd` (after first failing to compile) to force it to ignore vs2022.

### Generate Visual Studio project file for Slic3r, referencing the precompiled dependencies.
Go to the Windows Start Menu and Click on "Visual Studio 2019" folder, then select the ->"x64 Native Tools Command Prompt" to open a command window and run the following:
```
Expand Down
27 changes: 13 additions & 14 deletions resources/ui_layout/default/filament.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,23 @@ group:Fan speed - default
end_line
setting:min_fan_speed
line:Perimeter fan speed
setting:label$:perimeter_fan_speed
setting:label_width$12:label$Internal:perimeter_fan_speed
setting:label_width$12:label$External:external_perimeter_fan_speed
end_line
setting:overhang_perimeter_fan_speed
setting:infill_fan_speed
line:Internal Infill fan speed
setting:label_width$12:label$Sparse:infill_fan_speed
line:Solid Infill fan speed
setting:label$:solid_infill_fan_speed
setting:label_width$12:label$Top:top_fan_speed
end_line
setting:label_width$12:label$Solid:solid_infill_fan_speed
setting:label_width$12:label$Top solid:top_fan_speed
line:Support Material fan speed
setting:label$:support_material_fan_speed
setting:label_width$12:label$Support Interface:support_material_interface_fan_speed
end_line
setting:label_width$12:label$Default:support_material_fan_speed
setting:label_width$12:label$Interface:support_material_interface_fan_speed
line:Bridges fan speed
setting:label$:bridge_fan_speed
setting:label_width$12:label$Infill bridges:bridge_internal_fan_speed
end_line
setting:gap_fill_fan_speed
setting:label_width$12:label$Bridges:bridge_fan_speed
setting:label_width$12:label$Internal bridges:bridge_internal_fan_speed
line:Overhangs Perimeter fan speed
setting:label_width$12:label$Overhangs:overhangs_fan_speed
line:Gap fill fan speed
setting:label_width$12:label$Gap fill:gap_fill_fan_speed
group:Short layer time - began to increase base fan speed
setting:fan_below_layer_time
setting:label$Max fan speed:max_fan_speed
Expand Down
27 changes: 13 additions & 14 deletions resources/ui_layout/example/filament.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,23 @@ group:Fan speed - default
end_line
setting:min_fan_speed
line:Perimeter fan speed
setting:label$:perimeter_fan_speed
setting:label_width$12:label$Internal:perimeter_fan_speed
setting:label_width$12:label$External:external_perimeter_fan_speed
end_line
setting:overhang_perimeter_fan_speed
setting:infill_fan_speed
line:Internal Infill fan speed
setting:label_width$12:label$Sparse:infill_fan_speed
line:Solid Infill fan speed
setting:label$:solid_infill_fan_speed
setting:label_width$12:label$Top:top_fan_speed
end_line
setting:label_width$12:label$Solid:solid_infill_fan_speed
setting:label_width$12:label$Top solid:top_fan_speed
line:Support Material fan speed
setting:label$:support_material_fan_speed
setting:label_width$12:label$Support Interface:support_material_interface_fan_speed
end_line
setting:label_width$12:label$Default:support_material_fan_speed
setting:label_width$12:label$Interface:support_material_interface_fan_speed
line:Bridges fan speed
setting:label$:bridge_fan_speed
setting:label_width$12:label$Infill bridges:bridge_internal_fan_speed
end_line
setting:gap_fill_fan_speed
setting:label_width$12:label$Bridges:bridge_fan_speed
setting:label_width$12:label$Internal bridges:bridge_internal_fan_speed
line:Overhangs Perimeter fan speed
setting:label_width$12:label$Overhangs:overhangs_fan_speed
line:Gap fill fan speed
setting:label_width$12:label$Gap fill:gap_fill_fan_speed
group:Short layer time - began to increase base fan speed
setting:fan_below_layer_time
setting:label$Max fan speed:max_fan_speed
Expand Down
134 changes: 77 additions & 57 deletions src/libslic3r/GCode.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ class GCode : ExtrusionVisitorConst {
};
void _do_export(Print &print, GCodeOutputStream &file, ThumbnailsGeneratorCallback thumbnail_cb);

void _init_multiextruders(Print& print, GCodeOutputStream& file, GCodeWriter& writer, ToolOrdering& tool_ordering, const std::string& custom_gcode);
void _init_multiextruders(const Print& print, GCodeOutputStream& file, GCodeWriter& writer, const ToolOrdering& tool_ordering, const std::string& custom_gcode);

static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object);
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print);
static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object, Print::StatusMonitor &status_monitor);
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print, Print::StatusMonitor &status_monitor);

LayerResult process_layer(
const Print &print,
PrintStatistics &print_stat,
Print::StatusMonitor &status_monitor,
// Set of object & print layers of the same PrintObject and with the same print_z.
const std::vector<LayerToPrint> &layers,
const LayerTools &layer_tools,
Expand All @@ -269,7 +269,7 @@ class GCode : ExtrusionVisitorConst {
// and export G-code into file.
void process_layers(
const Print &print,
PrintStatistics &print_stat,
Print::StatusMonitor &status_monitor,
const ToolOrdering &tool_ordering,
const std::vector<const PrintInstance*> &print_object_instances_ordering,
const std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> &layers_to_print,
Expand All @@ -279,7 +279,7 @@ class GCode : ExtrusionVisitorConst {
// and export G-code into file.
void process_layers(
const Print &print,
PrintStatistics &print_stat,
Print::StatusMonitor &status_monitor,
const ToolOrdering &tool_ordering,
std::vector<LayerToPrint> layers_to_print,
const size_t single_object_idx,
Expand Down Expand Up @@ -506,9 +506,9 @@ class GCode : ExtrusionVisitorConst {
std::string _before_extrude(const ExtrusionPath &path, const std::string &description, double speed = -1);
double_t _compute_speed_mm_per_sec(const ExtrusionPath& path, double speed = -1);
std::string _after_extrude(const ExtrusionPath &path);
void print_machine_envelope(GCodeOutputStream &file, Print &print);
void _print_first_layer_bed_temperature(GCodeOutputStream &file, Print &print, const std::string &gcode, uint16_t first_printing_extruder_id, bool wait);
void _print_first_layer_extruder_temperatures(GCodeOutputStream &file, Print &print, const std::string &gcode, uint16_t first_printing_extruder_id, bool wait);
void print_machine_envelope(GCodeOutputStream &file, const Print &print);
void _print_first_layer_bed_temperature(GCodeOutputStream &file, const Print &print, const std::string &gcode, uint16_t first_printing_extruder_id, bool wait);
void _print_first_layer_extruder_temperatures(GCodeOutputStream &file, const Print &print, const std::string &gcode, uint16_t first_printing_extruder_id, bool wait);
// On the first printing layer. This flag triggers first layer speeds.
bool on_first_layer() const { return m_layer != nullptr && m_layer->id() == 0; }
// To control print speed of 1st object layer over raft interface.
Expand Down
30 changes: 29 additions & 1 deletion src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,36 @@
#define E_NUM(val) PRECISION(val, this->config.gcode_precision_e.value)
namespace Slic3r {

std::string GCodeWriter::get_default_pause_gcode(const GCodeConfig &config)
{
if (config.pause_print_gcode.value.empty()) {
if (config.gcode_flavor.value == GCodeFlavor::gcfKlipper) {
return "PAUSE";
} else if (config.gcode_flavor.value == GCodeFlavor::gcfRepRap || config.gcode_flavor.value == GCodeFlavor::gcfMarlinLegacy /*prusa only*/) {
return "M601";
} else {
// no pause command for other firmware, for what i am aware. Please submit a pullrequest or issue if they change.
return "";
}
} else {
return config.pause_print_gcode.value;
}
}

std::string GCodeWriter::PausePrintCode = "M601";
std::string GCodeWriter::get_default_color_change_gcode(const GCodeConfig &config)
{
if (config.color_change_gcode.value.empty()) {
if (config.gcode_flavor.value == GCodeFlavor::gcfRepRap || config.gcode_flavor.value == GCodeFlavor::gcfMarlinLegacy ||
config.gcode_flavor.value == GCodeFlavor::gcfMarlinFirmware || config.gcode_flavor.value == GCodeFlavor::gcfSmoothie) {
return "M600";
} else {
// no pause command for other firmware, for what i am aware. Please submit a pullrequest or issue if they change.
return "";
}
} else {
return config.color_change_gcode.value;
}
}

void GCodeWriter::apply_print_config(const PrintConfig &print_config)
{
Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/GCodeWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Slic3r {

class GCodeWriter {
public:
static std::string PausePrintCode;
GCodeConfig config;
bool multiple_extruders;
// override from region
Expand Down Expand Up @@ -90,6 +89,9 @@ class GCodeWriter {
std::string set_fan(uint8_t speed, uint16_t default_tool = 0);
uint8_t get_fan() { return m_last_fan_speed; }

static std::string get_default_pause_gcode(const GCodeConfig &config);
static std::string get_default_color_change_gcode(const GCodeConfig &config);

private:
// Extruders are sorted by their ID, so that binary search is possible.
std::vector<Extruder> m_extruders;
Expand Down
24 changes: 22 additions & 2 deletions src/libslic3r/Print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,28 @@ class Print : public PrintBaseWithState<PrintStep, psCount>
// 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);

// just a little wrapper to let the user know that this print can only be modified to emit warnings & update advancement status, change stats.
// TODO: have the status out of the printbase class and into another one, so we can have a const print & a mutable statusmonitor
class StatusMonitor
{
private:
Print& print;

public:
StatusMonitor(Print &print_mutable) : print(print_mutable) {}

// need this extra method because active_step_add_warning is protected and so need the friend status, and Gcode has it.
void active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id = 0)
{
print.active_step_add_warning(warning_level, message, message_id);
}
PrintStatistics &stats() { return print.m_print_statistics; }
bool set_started(PrintStep step) { return print.set_started(step); }
PrintStateBase::TimeStamp set_done(PrintStep step) { return print.set_done(step); }

};

protected:
private:

Expand Down Expand Up @@ -708,8 +730,6 @@ class Print : public PrintBaseWithState<PrintStep, psCount>
// tiem of last change, to see if the gui need to be updated
std::time_t m_timestamp_last_change;

// To allow GCode to set the Print's GCodeExport step status.
friend class GCode;
// Allow PrintObject to access m_mutex and m_cancel_callback.
friend class PrintObject;
};
Expand Down
6 changes: 4 additions & 2 deletions src/libslic3r/PrintBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ class PrintBase : public ObjectBase
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
//public to ebablet ot call it from brim code.
void throw_if_canceled() const { if (m_cancel_status.load(std::memory_order_acquire)) throw CanceledException(); }

// Update "scale", "input_filename", "input_filename_base" placeholders from the current printable ModelObjects.
void update_object_placeholders(DynamicConfig &config, const std::string &default_ext) const;

protected:
friend class PrintObjectBase;
friend class BackgroundSlicingProcess;
Expand All @@ -522,8 +526,6 @@ class PrintBase : public ObjectBase

// To be called by this->output_filename() with the format string pulled from the configuration layer.
std::string output_filename(const std::string &format, const std::string &default_ext, const std::string &filename_base, const DynamicConfig *config_override = nullptr) const;
// Update "scale", "input_filename", "input_filename_base" placeholders from the current printable ModelObjects.
void update_object_placeholders(DynamicConfig &config, const std::string &default_ext) const;

Model m_model;
DynamicPrintConfig m_full_print_config;
Expand Down
28 changes: 15 additions & 13 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ void PrintConfigDef::init_fff_params()

def = this->add("gap_fill_extension", coFloatOrPercent);
def->label = L("Extension");
def->full_label = L("Gapfill: extra extension");
def->full_label = L("Gap fill: extra extension");
def->category = OptionCategory::perimeter;
def->tooltip = L("Increase the length of all gapfills by this amount (may overextrude a little bit)\nCan be a % of the perimeter width");
def->ratio_over = "perimeter_width";
Expand All @@ -2675,7 +2675,7 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionFloatOrPercent{ 0, false });

def = this->add("gap_fill_fan_speed", coInts);
def->label = L("Gap Fill fan speed");
def->label = L("Gap fill fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all gap fill Perimeter moves"
"\nSet to 1 to disable fan."
Expand All @@ -2684,7 +2684,7 @@ void PrintConfigDef::init_fff_params()
def->sidetext = L("%");
def->min = -1;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });

Expand Down Expand Up @@ -3133,7 +3133,7 @@ void PrintConfigDef::init_fff_params()
def->sidetext = L("%");
def->min = -1;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });

Expand Down Expand Up @@ -3879,7 +3879,7 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionFloatOrPercent(0,false));

def = this->add("overhangs_fan_speed", coInts);
def->label = L("Overhang Perimeter fan speed");
def->label = L("Overhangs Perimeter fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all Overhang Perimeter moves"
"\nSet to 1 to disable fan."
Expand Down Expand Up @@ -4107,7 +4107,7 @@ void PrintConfigDef::init_fff_params()
def->sidetext = L("%");
def->min = -1;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });

Expand Down Expand Up @@ -4938,7 +4938,7 @@ void PrintConfigDef::init_fff_params()
def->sidetext = L("%");
def->min = -1;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });

Expand Down Expand Up @@ -5044,21 +5044,23 @@ void PrintConfigDef::init_fff_params()

def = this->add("color_change_gcode", coString);
def->label = L("Color change G-code");
def->tooltip = L("This G-code will be used as a code for the color change");
def->tooltip = L("This G-code will be used as a code for the color change"
" If empty, the default color change print command for the selected G-code flavor will be used (if any).");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert | comPrusa;
def->set_default_value(new ConfigOptionString("M600"));
def->set_default_value(new ConfigOptionString(""));

def = this->add("pause_print_gcode", coString);
def->label = L("Pause Print G-code");
def->tooltip = L("This G-code will be used as a code for the pause print");
def->tooltip = L("This G-code will be used as a code for the pause print."
" If empty, the default pause print command for the selected G-code flavor will be used (if any).");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert | comPrusa;
def->set_default_value(new ConfigOptionString("M601"));
def->set_default_value(new ConfigOptionString(""));

def = this->add("template_custom_gcode", coString);
def->label = L("Custom G-code");
Expand Down Expand Up @@ -5315,7 +5317,7 @@ void PrintConfigDef::init_fff_params()
def->sidetext = L("%");
def->min = -1;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });

Expand Down Expand Up @@ -5967,7 +5969,7 @@ void PrintConfigDef::init_fff_params()
def->category = OptionCategory::extruders;
def->tooltip = L("This flag will wipe the nozzle a bit inward after extruding an external perimeter."
" The wipe_extra_perimeter is executed first, then this move inward before the retraction wipe."
" Note that the retraction wipe will follow the exact external perimeter (center) line if this parameter is disabled, and will follow the inner side of the external periemter line if enabled");
" Note that the retraction wipe will follow the exact external perimeter (center) line if this parameter is disabled, and will follow the inner side of the external perimeter line if enabled");
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionBools{ true });
Expand Down
14 changes: 8 additions & 6 deletions src/slic3r/GUI/DoubleSlider.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "libslic3r/libslic3r.h"
#include "DoubleSlider.hpp"
#include "libslic3r/GCode.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "Plater.hpp"
#include "I18N.hpp"
#include "ExtruderSequenceDialog.hpp"
#include "libslic3r/Print.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/GCode.hpp"
#include "libslic3r/GCodeWriter.hpp"
#include "libslic3r/Print.hpp"
#include "GUI_Utils.hpp"
#include "MsgDialog.hpp"
#include "Tab.hpp"
Expand Down Expand Up @@ -51,10 +52,11 @@ wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);

static std::string gcode(Type type)
{
const PrintConfig& config = GUI::wxGetApp().plater()->fff_print().config();
const Print& print = GUI::wxGetApp().plater()->fff_print();
const PrintConfig &config = print.config();
switch (type) {
case ColorChange: return config.color_change_gcode;
case PausePrint: return config.pause_print_gcode;
case ColorChange: return Slic3r::GCodeWriter::get_default_color_change_gcode(config);
case PausePrint: return Slic3r::GCodeWriter::get_default_pause_gcode(config);
case Template: return config.template_custom_gcode;
default: return "";
}
Expand Down Expand Up @@ -2014,7 +2016,7 @@ void Control::show_add_context_menu()
{
wxMenu menu;

if (m_mode == SingleExtruder) {
if (m_mode == SingleExtruder && !gcode(ColorChange).empty()) {
append_menu_item(&menu, wxID_ANY, _L("Add color change") + " (" + gcode(ColorChange) + ")", "",
[this](wxCommandEvent&) { add_code_as_tick(ColorChange); }, "colorchange_add_m", &menu);

Expand Down
Loading

0 comments on commit 5252d7f

Please sign in to comment.