Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Manual filament change" option and logic #2379

Merged
merged 10 commits into from
Oct 22, 2023
7 changes: 4 additions & 3 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
{
// 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.
file.write(this->set_extruder(initial_extruder_id, 0.));
file.write(this->set_extruder(initial_extruder_id, 0., true)); // Orca: add param to indicate it is the first time extruder is initialized
}
// BBS: set that indicates objs with brim
for (auto iter = print.m_brimMap.begin(); iter != print.m_brimMap.end(); ++iter) {
Expand Down Expand Up @@ -5306,7 +5306,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
return gcode;
}

std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool is_init_extruder)
Ocraftyone marked this conversation as resolved.
Show resolved Hide resolved
{
if (!m_writer.need_toolchange(extruder_id))
return "";
Expand Down Expand Up @@ -5450,7 +5450,8 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
// Process the custom change_filament_gcode.
const std::string& change_filament_gcode = m_config.change_filament_gcode.value;
std::string toolchange_gcode_parsed;
if (!change_filament_gcode.empty()) {
if (! ((m_config.manual_filament_change.value && is_init_extruder) //Orca: Ignore change_filament_gcode if is the initial setup for the extruder and manual_filament_change is enabled
|| change_filament_gcode.empty())) {
toolchange_gcode_parsed = placeholder_parser_process("change_filament_gcode", change_filament_gcode, extruder_id, &dyn_config);
check_add_eol(toolchange_gcode_parsed);
gcode += toolchange_gcode_parsed;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class GCode {
bool needs_retraction(const Polyline& travel, ExtrusionRole role, LiftType& lift_type);
std::string retract(bool toolchange = false, bool is_last_retraction = false, LiftType lift_type = LiftType::SpiralLift);
std::string unretract() { return m_writer.unlift() + m_writer.unretract(); }
std::string set_extruder(unsigned int extruder_id, double print_z);
std::string set_extruder(unsigned int extruder_id, double print_z, bool is_init_extruder = false);
bool is_BBL_Printer();

// SoftFever
Expand Down
15 changes: 13 additions & 2 deletions src/libslic3r/GCode/GCodeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
"_GP_LAST_LINE_M73_PLACEHOLDER",
"_GP_ESTIMATED_PRINTING_TIME_PLACEHOLDER",
"_GP_TOTAL_LAYER_NUMBER_PLACEHOLDER",
" CHANGE_TOOL ",
Ocraftyone marked this conversation as resolved.
Show resolved Hide resolved
"_DURING_PRINT_EXHAUST_FAN"
};

Expand All @@ -76,7 +77,8 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags_compatible = {
"_GP_FIRST_LINE_M73_PLACEHOLDER",
"_GP_LAST_LINE_M73_PLACEHOLDER",
"_GP_ESTIMATED_PRINTING_TIME_PLACEHOLDER",
"_GP_TOTAL_LAYER_NUMBER_PLACEHOLDER"
"_GP_TOTAL_LAYER_NUMBER_PLACEHOLDER",
" CHANGE_TOOL "
};


Expand Down Expand Up @@ -1013,7 +1015,9 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
if (spiral_vase != nullptr)
m_spiral_vase_active = spiral_vase->value;


const ConfigOptionBool* manual_filament_change = config.option<ConfigOptionBool>("manual_filament_change");
if (manual_filament_change != nullptr)
m_manual_filament_change = manual_filament_change->value;
}

void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
Expand Down Expand Up @@ -2111,6 +2115,13 @@ void GCodeProcessor::process_tags(const std::string_view comment, bool producers
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Width (" << comment << ").";
return;
}
// tool change tag
if (m_manual_filament_change && boost::starts_with(comment, reserved_tag(ETags::Tool_Change))) {
std::string_view tool_change_cmd = comment.substr(reserved_tag(ETags::Tool_Change).length());
if (boost::starts_with(tool_change_cmd, "T")) {
process_T(tool_change_cmd);
}
}
}

// color change tag
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/GCode/GCodeProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace Slic3r {
Last_Line_M73_Placeholder,
Estimated_Printing_Time_Placeholder,
Total_Layer_Number_Placeholder,
Tool_Change,
During_Print_Exhaust_Fan
};

Expand Down Expand Up @@ -638,6 +639,7 @@ namespace Slic3r {
bool m_wiping;
bool m_flushing;
float m_remaining_volume;
bool m_manual_filament_change;

//BBS: x, y offset for gcode generated
double m_x_offset{ 0 };
Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <map>
#include <assert.h>
#include <GCode/GCodeProcessor.hpp>

#ifdef __APPLE__
#include <boost/spirit/include/karma.hpp>
Expand Down Expand Up @@ -308,7 +309,8 @@ std::string GCodeWriter::update_progress(unsigned int num, unsigned int tot, boo

std::string GCodeWriter::toolchange_prefix() const
{
return FLAVOR_IS(gcfMakerWare) ? "M135 T" :
return config.manual_filament_change ? ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Tool_Change) + "T" :
FLAVOR_IS(gcfMakerWare) ? "M135 T" :
FLAVOR_IS(gcfSailfish) ? "M108 T" : "T";
}

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ static std::vector<std::string> s_Preset_printer_options {
"printer_technology",
"printable_area", "bed_exclude_area","bed_custom_texture", "bed_custom_model", "gcode_flavor",
"fan_kickstart", "fan_speedup_time", "fan_speedup_overhangs",
"single_extruder_multi_material", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode",
"single_extruder_multi_material", "manual_filament_change", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode",
"printer_model", "printer_variant", "printable_height", "extruder_clearance_radius", "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod",
"default_print_profile", "inherits",
"silent_mode",
Expand Down
7 changes: 7 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,13 @@ def = this->add("filament_loading_speed", coFloats);
def->readonly = true;
def->set_default_value(new ConfigOptionBool(true));

def = this->add("manual_filament_change", coBool);
def->label = L("Manual Filament Change");
def->tooltip = L("Perform filament changes by pausing print (must be set in custom g-code) for the manual swap of the filament. "
Ocraftyone marked this conversation as resolved.
Show resolved Hide resolved
"The tool change command is no longer emitted at all and custom g-code is not called during the pre-print phase.");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(true));

def = this->add("purge_in_prime_tower", coBool);
def->label = L("Purge in prime tower");
def->tooltip = L("Purge remaining filament into prime tower");
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionString, machine_start_gcode))
((ConfigOptionStrings, filament_start_gcode))
((ConfigOptionBool, single_extruder_multi_material))
((ConfigOptionBool, manual_filament_change))
((ConfigOptionBool, single_extruder_multi_material_priming))
((ConfigOptionBool, wipe_tower_no_sparse_layers))
((ConfigOptionString, change_filament_gcode))
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3488,6 +3488,7 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
optgroup->append_single_option_line("parking_pos_retraction");
optgroup->append_single_option_line("extra_loading_move");
optgroup->append_single_option_line("high_current_on_filament_swap");
optgroup->append_single_option_line("manual_filament_change");
m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
}

Expand Down