Skip to content

Commit

Permalink
add start_gcode_manual to disable automatic 'start gcode' output
Browse files Browse the repository at this point in the history
  • Loading branch information
remi durand committed Apr 29, 2021
1 parent 20a106f commit b51fbc8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 47 deletions.
2 changes: 2 additions & 0 deletions resources/ui_layout/printer_fff.ui
Expand Up @@ -41,6 +41,8 @@ group:Advanced
setting:variable_layer_height

page:Custom G-code:cog
group:
setting:start_gcode_manual
height:15
group:nolabel:Start G-code
setting:full_width:start_gcode
Expand Down
83 changes: 46 additions & 37 deletions src/libslic3r/GCode.cpp
Expand Up @@ -1323,14 +1323,15 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu

std::string start_gcode = this->placeholder_parser_process("start_gcode", print.config().start_gcode.value, initial_extruder_id);
// Set bed temperature if the start G-code does not contain any bed temp control G-codes.
if(this->config().gcode_flavor != gcfKlipper && print.config().first_layer_bed_temperature.get_at(initial_extruder_id) != 0)
if( !this->config().start_gcode_manual && this->config().gcode_flavor != gcfKlipper && print.config().first_layer_bed_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_bed_temperature(file, print, start_gcode, initial_extruder_id, false);

//init extruders
this->_init_multiextruders(file, print, m_writer, tool_ordering, start_gcode);
if (!this->config().start_gcode_manual)
this->_init_multiextruders(file, print, m_writer, tool_ordering, start_gcode);

// Set extruder(s) temperature before and after start G-code.
if ((this->config().gcode_flavor != gcfKlipper || print.config().start_gcode.value.empty()) && print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
if (!this->config().start_gcode_manual && (this->config().gcode_flavor != gcfKlipper || print.config().start_gcode.value.empty()) && print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, false);

// adds tag for processor
Expand All @@ -1350,7 +1351,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
*/

// Disable fan.
if (print.config().disable_fan_first_layers.get_at(initial_extruder_id))
if (!this->config().start_gcode_manual && print.config().disable_fan_first_layers.get_at(initial_extruder_id))
_write(file, m_writer.set_fan(0, true, initial_extruder_id));
//ensure fan is at the right speed

Expand All @@ -1367,52 +1368,57 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
m_seam_placer.init(print);

//activate first extruder is multi-extruder and not in start-gcode
if (m_writer.multiple_extruders) {
//if not in gcode
bool find = false;
if (!start_gcode.empty()) {
const char *ptr = start_gcode.data();
while (*ptr != 0) {
// Skip whitespaces.
for (; *ptr == ' ' || *ptr == '\t'; ++ptr);
if (*ptr == 'T') {
// TX for most of the firmwares
find = true;
break;
} else if (*ptr == 'A' && print.config().gcode_flavor.value == gcfKlipper) {
// ACTIVATE_EXTRUDER for klipper (if used)
if (std::string::npos != start_gcode.find("ACTIVATE_EXTRUDER", size_t(ptr - start_gcode.data()))) {
if (!this->config().start_gcode_manual) {
if (m_writer.multiple_extruders) {
//if not in gcode
bool find = false;
if (!start_gcode.empty()) {
const char* ptr = start_gcode.data();
while (*ptr != 0) {
// Skip whitespaces.
for (; *ptr == ' ' || *ptr == '\t'; ++ptr);
if (*ptr == 'T') {
// TX for most of the firmwares
find = true;
break;
} else if (*ptr == 'A' && print.config().gcode_flavor.value == gcfKlipper) {
// ACTIVATE_EXTRUDER for klipper (if used)
if (std::string::npos != start_gcode.find("ACTIVATE_EXTRUDER", size_t(ptr - start_gcode.data()))) {
find = true;
break;
}
}
// Skip the rest of the line.
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ptr);
// Skip the end of line indicators.
for (; *ptr == '\r' || *ptr == '\n'; ++ptr);
}
// Skip the rest of the line.
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ptr);
// Skip the end of line indicators.
for (; *ptr == '\r' || *ptr == '\n'; ++ptr);
}
}
if (!find) {
// Set initial extruder only after custom start G-code.
// Ugly hack: Do not set the initial extruder if the extruder is primed using the MMU priming towers at the edge of the print bed.
if (!(has_wipe_tower && print.config().single_extruder_multi_material_priming)) {
_write(file, this->set_extruder(initial_extruder_id, 0.));
if (!find) {
// Set initial extruder only after custom start G-code.
// Ugly hack: Do not set the initial extruder if the extruder is primed using the MMU priming towers at the edge of the print bed.
if (!(has_wipe_tower && print.config().single_extruder_multi_material_priming)) {
_write(file, this->set_extruder(initial_extruder_id, 0.));
} else {
m_writer.toolchange(initial_extruder_id);
}
} else {
m_writer.toolchange(initial_extruder_id);
// set writer to the tool as should be set in the start_gcode.
_write(file, this->set_extruder(initial_extruder_id, 0., true));
}
} else {
// set writer to the tool as should be set in the start_gcode.
_write(file, this->set_extruder(initial_extruder_id, 0., true));
// if we are running a single-extruder setup, just set the extruder and "return nothing"
_write(file, this->set_extruder(initial_extruder_id, 0.));
}
} else {
// if we are running a single-extruder setup, just set the extruder and "return nothing"
_write(file, this->set_extruder(initial_extruder_id, 0.));
// the right tool should have been set by the user.
m_writer.toolchange(initial_extruder_id);
}

//write temps after custom gcodes to ensure the temperature are good. (after tool selection)
if(print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
if (!this->config().start_gcode_manual && print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, true);
if (print.config().first_layer_bed_temperature.get_at(initial_extruder_id) != 0)
if (!this->config().start_gcode_manual && print.config().first_layer_bed_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_bed_temperature(file, print, start_gcode, initial_extruder_id, true);

// Do all objects for each layer.
Expand Down Expand Up @@ -2699,7 +2705,10 @@ void GCode::set_origin(const Vec2d &pointf)

std::string GCode::preamble()
{
std::string gcode = m_writer.preamble();
std::string gcode;

if (!this->config().start_gcode_manual)
gcode = m_writer.preamble();

/* Perform a *silent* move to z_offset: we need this to initialize the Z
position of our writer object so that any initial lift taking place
Expand Down
9 changes: 7 additions & 2 deletions src/libslic3r/Preset.cpp
Expand Up @@ -691,8 +691,13 @@ const std::vector<std::string>& Preset::printer_options()
"min_length",
//FIXME the print host keys are left here just for conversion from the Printer preset to Physical Printer preset.
"host_type", "print_host", "printhost_apikey", "printhost_cafile", "printhost_port",
"single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode",

"single_extruder_multi_material",
"start_gcode",
"start_gcode_manual",
"end_gcode",
"before_layer_gcode",
"layer_gcode",
"toolchange_gcode",
"color_change_gcode", "pause_print_gcode", "template_custom_gcode", "feature_gcode",
"between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction",
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height",
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/Print.cpp
Expand Up @@ -164,6 +164,7 @@ bool Print::invalidate_state_by_config_options(const std::vector<t_config_option
"slowdown_below_layer_time",
"standby_temperature_delta",
"start_gcode",
"start_gcode_manual",
"start_filament_gcode",
"thin_walls_speed",
"time_estimation_compensation",
Expand Down
25 changes: 17 additions & 8 deletions src/libslic3r/PrintConfig.cpp
Expand Up @@ -3462,19 +3462,27 @@ void PrintConfigDef::init_fff_params()
def->label = L("Start G-code");
def->category = OptionCategory::customgcode;
def->tooltip = L("This start procedure is inserted at the beginning, after bed has reached "
"the target temperature and extruder just started heating, and before extruder "
"has finished heating. If Slic3r detects M104 or M190 in your custom codes, "
"such commands will not be prepended automatically so you're free to customize "
"the order of heating commands and other custom actions. Note that you can use "
"placeholder variables for all Slic3r settings, so you can put "
"a \"M109 S[first_layer_temperature]\" command wherever you want."
"\n placeholders: initial_extruder, total_layer_count, has_wipe_tower, has_single_extruder_multi_material_priming, total_toolchanges, bounding_box[minx,miny,maxx,maxy]");
"the target temperature and extruder just started heating, and before extruder "
"has finished heating. If Slic3r detects M104 or M190 in your custom codes, "
"such commands will not be prepended automatically so you're free to customize "
"the order of heating commands and other custom actions. Note that you can use "
"placeholder variables for all Slic3r settings, so you can put "
"a \"M109 S[first_layer_temperature]\" command wherever you want."
"\n placeholders: initial_extruder, total_layer_count, has_wipe_tower, has_single_extruder_multi_material_priming, total_toolchanges, bounding_box[minx,miny,maxx,maxy]");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert;
def->set_default_value(new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"));

def = this->add("start_gcode_manual", coBool);
def->label = L("Only custom Start G-code");
def->category = OptionCategory::customgcode;
def->tooltip = L("Ensure that the slicer won't add heating, fan, extruder... commands before or just after your start-gcode."
"If set to true, you have to write a good and complete start_gcode, as no checks are made anymore.");
def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(false));

def = this->add("start_filament_gcode", coStrings);
def->label = L("Start G-code");
def->full_label = ("Filament start G-code");
Expand Down Expand Up @@ -5416,7 +5424,8 @@ void PrintConfigDef::to_prusa(t_config_option_key& opt_key, std::string& value,
"external_perimeter_extrusion_spacing",
"infill_extrusion_spacing",
"solid_infill_extrusion_spacing",
"top_infill_extrusion_spacing"
"top_infill_extrusion_spacing",
"start_gcode_manual",

};
//looks if it's to be removed, or have to be transformed
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Expand Up @@ -1085,6 +1085,7 @@ class GCodeConfig : public StaticPrintConfig
ConfigOptionFloats retract_speed;
ConfigOptionStrings start_filament_gcode;
ConfigOptionString start_gcode;
ConfigOptionBool start_gcode_manual;
ConfigOptionBool single_extruder_multi_material;
ConfigOptionBool single_extruder_multi_material_priming;
ConfigOptionBool wipe_tower_no_sparse_layers;
Expand Down Expand Up @@ -1198,6 +1199,7 @@ class GCodeConfig : public StaticPrintConfig
OPT_PTR(single_extruder_multi_material_priming);
OPT_PTR(wipe_tower_no_sparse_layers);
OPT_PTR(start_gcode);
OPT_PTR(start_gcode_manual);
OPT_PTR(start_filament_gcode);
OPT_PTR(tool_name);
OPT_PTR(toolchange_gcode);
Expand Down

0 comments on commit b51fbc8

Please sign in to comment.