Skip to content

Commit

Permalink
Add "Manual filament change" option and logic (#2379)
Browse files Browse the repository at this point in the history
* Add "Manual filament change" option and logic

* make suggested changes

* make suggested changes

* change tag from "CHANGE_TOOL" to "MANUAL_TOOL_CHANGE"

* some tweaks

* More fixes

---------

Co-authored-by: SoftFever <[email protected]>
Co-authored-by: SoftFever <[email protected]>
  • Loading branch information
3 people authored Oct 22, 2023
1 parent 90601c0 commit f84e94f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5431,7 +5431,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()) {
//Orca: Ignore change_filament_gcode if is the first call for a tool change and manual_filament_change is enabled
if (!change_filament_gcode.empty() && !(m_config.manual_filament_change.value && m_toolchange_count == 1)) {
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
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",
" MANUAL_TOOL_CHANGE ",
"_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",
" MANUAL_TOOL_CHANGE "
};


Expand Down Expand Up @@ -1010,7 +1012,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 @@ -2108,6 +2112,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;
}
// Orca: manual tool change tag
if (m_manual_filament_change && boost::starts_with(comment, reserved_tag(ETags::Manual_Tool_Change))) {
std::string_view tool_change_cmd = comment.substr(reserved_tag(ETags::Manual_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 @@ -260,6 +260,7 @@ namespace Slic3r {
Last_Line_M73_Placeholder,
Estimated_Printing_Time_Placeholder,
Total_Layer_Number_Placeholder,
Manual_Tool_Change,
During_Print_Exhaust_Fan
};

Expand Down Expand Up @@ -637,6 +638,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 @@ -312,7 +313,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::Manual_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 @@ -818,7 +818,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
8 changes: 8 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,14 @@ 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("Enable this option to omit the custom Change filament G-code only at the beginning of the print. "
"The tool change command (e.g., T0) will be skipped throughout the entire print. "
"This is useful for manual multi-material printing, where we use M600/PAUSE to trigger the manual filament change action.");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(false));

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 @@ -944,6 +944,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
2 changes: 2 additions & 0 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,8 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
}
});
};
optgroup->append_single_option_line("manual_filament_change");

optgroup = page->new_optgroup(L("Wipe tower"));
optgroup->append_single_option_line("purge_in_prime_tower");
optgroup->append_single_option_line("enable_filament_ramming");
Expand Down

0 comments on commit f84e94f

Please sign in to comment.