diff --git a/resources/ui_layout/printer_fff.ui b/resources/ui_layout/printer_fff.ui index 9621af511..34ce66ad4 100644 --- a/resources/ui_layout/printer_fff.ui +++ b/resources/ui_layout/printer_fff.ui @@ -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 diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 44027acf2..3d725dc9d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index aa392ad80..b3c3b3156 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -692,8 +692,13 @@ const std::vector& 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", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 6dec9589d..1245fed6c 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -164,6 +164,7 @@ bool Print::invalidate_state_by_config_options(const std::vectorlabel = 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"); @@ -5437,7 +5445,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 diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 4d268002f..483175417 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1089,6 +1089,7 @@ public: 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; @@ -1202,6 +1203,7 @@ protected: 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);