FIX: wrong flush logic
1.Fix flush calc logic 2.Rename m_extruder in GCodeWriter jira:NEW Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I38f023fbad983305632ca62cbfb3909759013c25
This commit is contained in:
parent
9ec276d3d7
commit
f1b0805ed1
|
@ -36,7 +36,7 @@ namespace Slic3r
|
||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t max_group_num = (1 << m_filament_num);
|
uint64_t max_group_num = static_cast<uint64_t>(1 << m_filament_num);
|
||||||
int best_cost = std::numeric_limits<int>::max();
|
int best_cost = std::numeric_limits<int>::max();
|
||||||
std::vector<int>best_label;
|
std::vector<int>best_label;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ namespace Slic3r
|
||||||
continue;
|
continue;
|
||||||
std::set<int>group_0, group_1;
|
std::set<int>group_0, group_1;
|
||||||
for (int j = 0; j < m_filament_num; ++j) {
|
for (int j = 0; j < m_filament_num; ++j) {
|
||||||
if (i & (1 << j))
|
if (i & static_cast<uint64_t>(1 << j))
|
||||||
group_1.insert(m_used_filaments[j]);
|
group_1.insert(m_used_filaments[j]);
|
||||||
else
|
else
|
||||||
group_0.insert(m_used_filaments[j]);
|
group_0.insert(m_used_filaments[j]);
|
||||||
|
|
|
@ -267,7 +267,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
if (gcodegen.config().standby_temperature_delta.value != 0) {
|
if (gcodegen.config().standby_temperature_delta.value != 0) {
|
||||||
// we assume that heating is always slower than cooling, so no need to block
|
// we assume that heating is always slower than cooling, so no need to block
|
||||||
gcode += gcodegen.writer().set_temperature
|
gcode += gcodegen.writer().set_temperature
|
||||||
(this->_get_temp(gcodegen) + gcodegen.config().standby_temperature_delta.value, false, gcodegen.writer().extruder()->id());
|
(this->_get_temp(gcodegen) + gcodegen.config().standby_temperature_delta.value, false, gcodegen.writer().filament()->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
return gcode;
|
return gcode;
|
||||||
|
@ -276,7 +276,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
std::string OozePrevention::post_toolchange(GCode& gcodegen)
|
std::string OozePrevention::post_toolchange(GCode& gcodegen)
|
||||||
{
|
{
|
||||||
return (gcodegen.config().standby_temperature_delta.value != 0) ?
|
return (gcodegen.config().standby_temperature_delta.value != 0) ?
|
||||||
gcodegen.writer().set_temperature(this->_get_temp(gcodegen), true, gcodegen.writer().extruder()->id()) :
|
gcodegen.writer().set_temperature(this->_get_temp(gcodegen), true, gcodegen.writer().filament()->id()) :
|
||||||
std::string();
|
std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +284,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
OozePrevention::_get_temp(GCode& gcodegen)
|
OozePrevention::_get_temp(GCode& gcodegen)
|
||||||
{
|
{
|
||||||
return (gcodegen.layer() != NULL && gcodegen.layer()->id() == 0)
|
return (gcodegen.layer() != NULL && gcodegen.layer()->id() == 0)
|
||||||
? gcodegen.config().nozzle_temperature_initial_layer.get_at(gcodegen.writer().extruder()->id())
|
? gcodegen.config().nozzle_temperature_initial_layer.get_at(gcodegen.writer().filament()->id())
|
||||||
: gcodegen.config().nozzle_temperature.get_at(gcodegen.writer().extruder()->id());
|
: gcodegen.config().nozzle_temperature.get_at(gcodegen.writer().filament()->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Wipe::wipe(GCode& gcodegen, bool toolchange, bool is_last)
|
std::string Wipe::wipe(GCode& gcodegen, bool toolchange, bool is_last)
|
||||||
|
@ -297,22 +297,22 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
//OrcaSlicer
|
//OrcaSlicer
|
||||||
double cur_speed = gcodegen.writer().get_current_speed();
|
double cur_speed = gcodegen.writer().get_current_speed();
|
||||||
double wipe_speed = gcodegen.config().role_base_wipe_speed && cur_speed > EPSILON ? cur_speed / 60 :
|
double wipe_speed = gcodegen.config().role_base_wipe_speed && cur_speed > EPSILON ? cur_speed / 60 :
|
||||||
gcodegen.writer().config.travel_speed.get_at(get_extruder_index(gcodegen.writer().config, gcodegen.writer().extruder()->id())) * gcodegen.config().wipe_speed.value / 100;
|
gcodegen.writer().config.travel_speed.get_at(get_extruder_index(gcodegen.writer().config, gcodegen.writer().filament()->id())) * gcodegen.config().wipe_speed.value / 100;
|
||||||
|
|
||||||
|
|
||||||
// get the retraction length
|
// get the retraction length
|
||||||
double length = toolchange
|
double length = toolchange
|
||||||
? gcodegen.writer().extruder()->retract_length_toolchange()
|
? gcodegen.writer().filament()->retract_length_toolchange()
|
||||||
: gcodegen.writer().extruder()->retraction_length();
|
: gcodegen.writer().filament()->retraction_length();
|
||||||
// Shorten the retraction length by the amount already retracted before wipe.
|
// Shorten the retraction length by the amount already retracted before wipe.
|
||||||
length *= (1. - gcodegen.writer().extruder()->retract_before_wipe());
|
length *= (1. - gcodegen.writer().filament()->retract_before_wipe());
|
||||||
|
|
||||||
if (length >= 0) {
|
if (length >= 0) {
|
||||||
/* Calculate how long we need to travel in order to consume the required
|
/* Calculate how long we need to travel in order to consume the required
|
||||||
amount of retraction. In other words, how far do we move in XY at wipe_speed
|
amount of retraction. In other words, how far do we move in XY at wipe_speed
|
||||||
for the time needed to consume retraction_length at retraction_speed? */
|
for the time needed to consume retraction_length at retraction_speed? */
|
||||||
// BBS
|
// BBS
|
||||||
double wipe_dist = scale_(gcodegen.config().wipe_distance.get_at(gcodegen.writer().extruder() ->extruder_id()));
|
double wipe_dist = scale_(gcodegen.config().wipe_distance.get_at(gcodegen.writer().filament() ->extruder_id()));
|
||||||
|
|
||||||
/* Take the stored wipe path and replace first point with the current actual position
|
/* Take the stored wipe path and replace first point with the current actual position
|
||||||
(they might be different, for example, in case of loop clipping). */
|
(they might be different, for example, in case of loop clipping). */
|
||||||
|
@ -432,12 +432,12 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
|
|
||||||
// Process the end filament gcode.
|
// Process the end filament gcode.
|
||||||
std::string end_filament_gcode_str;
|
std::string end_filament_gcode_str;
|
||||||
if (gcodegen.writer().extruder() != nullptr) {
|
if (gcodegen.writer().filament() != nullptr) {
|
||||||
// Process the custom filament_end_gcode in case of single_extruder_multi_material.
|
// Process the custom filament_end_gcode in case of single_extruder_multi_material.
|
||||||
unsigned int old_extruder_id = gcodegen.writer().extruder()->id();
|
unsigned int old_filament_id = gcodegen.writer().filament()->id();
|
||||||
const std::string& filament_end_gcode = gcodegen.config().filament_end_gcode.get_at(old_extruder_id);
|
const std::string& filament_end_gcode = gcodegen.config().filament_end_gcode.get_at(old_filament_id);
|
||||||
if (gcodegen.writer().extruder() != nullptr && !filament_end_gcode.empty()) {
|
if (gcodegen.writer().filament() != nullptr && !filament_end_gcode.empty()) {
|
||||||
end_filament_gcode_str = gcodegen.placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_extruder_id);
|
end_filament_gcode_str = gcodegen.placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id);
|
||||||
check_add_eol(end_filament_gcode_str);
|
check_add_eol(end_filament_gcode_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -455,8 +455,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
// m_max_layer_z = std::max(m_max_layer_z, tcr.print_z);
|
// m_max_layer_z = std::max(m_max_layer_z, tcr.print_z);
|
||||||
if (! change_filament_gcode.empty()) {
|
if (! change_filament_gcode.empty()) {
|
||||||
DynamicConfig config;
|
DynamicConfig config;
|
||||||
int previous_filament_id = gcodegen.writer().extruder() ? (int)gcodegen.writer().extruder()->id() : -1;
|
int previous_filament_id = gcodegen.writer().filament(new_extruder_id) ? (int)gcodegen.writer().filament(new_extruder_id)->id() : -1;
|
||||||
int previous_extruder_id = gcodegen.writer().extruder() ? (int)gcodegen.writer().extruder()->extruder_id() : -1;
|
int previous_extruder_id = gcodegen.writer().filament(new_extruder_id) ? (int)gcodegen.writer().filament(new_extruder_id)->extruder_id() : -1;
|
||||||
|
|
||||||
config.set_key_value("previous_extruder", new ConfigOptionInt(previous_filament_id));
|
config.set_key_value("previous_extruder", new ConfigOptionInt(previous_filament_id));
|
||||||
config.set_key_value("next_extruder", new ConfigOptionInt((int)new_filament_id));
|
config.set_key_value("next_extruder", new ConfigOptionInt((int)new_filament_id));
|
||||||
|
@ -468,11 +468,11 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
{
|
{
|
||||||
GCodeWriter& gcode_writer = gcodegen.m_writer;
|
GCodeWriter& gcode_writer = gcodegen.m_writer;
|
||||||
FullPrintConfig& full_config = gcodegen.m_config;
|
FullPrintConfig& full_config = gcodegen.m_config;
|
||||||
float old_retract_length = gcode_writer.extruder() != nullptr ? full_config.retraction_length.get_at(previous_extruder_id) : 0;
|
float old_retract_length = gcode_writer.filament(new_extruder_id) != nullptr ? full_config.retraction_length.get_at(previous_filament_id) : 0;
|
||||||
float new_retract_length = full_config.retraction_length.get_at(new_extruder_id);
|
float new_retract_length = full_config.retraction_length.get_at(new_extruder_id);
|
||||||
float old_retract_length_toolchange = gcode_writer.extruder() != nullptr ? full_config.retract_length_toolchange.get_at(previous_extruder_id) : 0;
|
float old_retract_length_toolchange = gcode_writer.filament(new_extruder_id) != nullptr ? full_config.retract_length_toolchange.get_at(previous_filament_id) : 0;
|
||||||
float new_retract_length_toolchange = full_config.retract_length_toolchange.get_at(new_extruder_id);
|
float new_retract_length_toolchange = full_config.retract_length_toolchange.get_at(new_extruder_id);
|
||||||
int old_filament_temp = gcode_writer.extruder() != nullptr ? (gcodegen.on_first_layer()? full_config.nozzle_temperature_initial_layer.get_at(previous_filament_id) : full_config.nozzle_temperature.get_at(previous_filament_id)) : 210;
|
int old_filament_temp = gcode_writer.filament(new_extruder_id) != nullptr ? (gcodegen.on_first_layer()? full_config.nozzle_temperature_initial_layer.get_at(previous_filament_id) : full_config.nozzle_temperature.get_at(previous_filament_id)) : 210;
|
||||||
int new_filament_temp = gcodegen.on_first_layer() ? full_config.nozzle_temperature_initial_layer.get_at(new_filament_id) : full_config.nozzle_temperature.get_at(new_filament_id);
|
int new_filament_temp = gcodegen.on_first_layer() ? full_config.nozzle_temperature_initial_layer.get_at(new_filament_id) : full_config.nozzle_temperature.get_at(new_filament_id);
|
||||||
Vec3d nozzle_pos = gcode_writer.get_position();
|
Vec3d nozzle_pos = gcode_writer.get_position();
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
float filament_area = float((M_PI / 4.f) * pow(full_config.filament_diameter.get_at(new_filament_id), 2));
|
float filament_area = float((M_PI / 4.f) * pow(full_config.filament_diameter.get_at(new_filament_id), 2));
|
||||||
float purge_length = purge_volume / filament_area;
|
float purge_length = purge_volume / filament_area;
|
||||||
|
|
||||||
int old_filament_e_feedrate = gcode_writer.extruder() != nullptr ? (int)(60.0 * full_config.filament_max_volumetric_speed.get_at(previous_filament_id) / filament_area) : 200;
|
int old_filament_e_feedrate = gcode_writer.filament(new_extruder_id) != nullptr ? (int)(60.0 * full_config.filament_max_volumetric_speed.get_at(previous_filament_id) / filament_area) : 200;
|
||||||
old_filament_e_feedrate = old_filament_e_feedrate == 0 ? 100 : old_filament_e_feedrate;
|
old_filament_e_feedrate = old_filament_e_feedrate == 0 ? 100 : old_filament_e_feedrate;
|
||||||
int new_filament_e_feedrate = (int)(60.0 * full_config.filament_max_volumetric_speed.get_at(new_filament_id) / filament_area);
|
int new_filament_e_feedrate = (int)(60.0 * full_config.filament_max_volumetric_speed.get_at(new_filament_id) / filament_area);
|
||||||
new_filament_e_feedrate = new_filament_e_feedrate == 0 ? 100 : new_filament_e_feedrate;
|
new_filament_e_feedrate = new_filament_e_feedrate == 0 ? 100 : new_filament_e_feedrate;
|
||||||
|
@ -793,8 +793,8 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
|
||||||
|
|
||||||
const std::vector<std::string> ColorPrintColors::Colors = { "#C0392B", "#E67E22", "#F1C40F", "#27AE60", "#1ABC9C", "#2980B9", "#9B59B6" };
|
const std::vector<std::string> ColorPrintColors::Colors = { "#C0392B", "#E67E22", "#F1C40F", "#27AE60", "#1ABC9C", "#2980B9", "#9B59B6" };
|
||||||
|
|
||||||
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_writer.extruder()->extruder_id())
|
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_writer.filament()->extruder_id())
|
||||||
#define FILAMENT_CONFIG(OPT) m_config.OPT.get_at(m_writer.extruder()->id())
|
#define FILAMENT_CONFIG(OPT) m_config.OPT.get_at(m_writer.filament()->id())
|
||||||
// Collect pairs of object_layer + support_layer sorted by print_z.
|
// Collect pairs of object_layer + support_layer sorted by print_z.
|
||||||
// object_layer & support_layer are considered to be on the same print_z, if they are not further than EPSILON.
|
// object_layer & support_layer are considered to be on the same print_z, if they are not further than EPSILON.
|
||||||
std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObject& object)
|
std::vector<GCode::LayerToPrint> GCode::collect_layers_to_print(const PrintObject& object)
|
||||||
|
@ -2304,7 +2304,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
||||||
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
||||||
if (print.config().single_extruder_multi_material) {
|
if (print.config().single_extruder_multi_material) {
|
||||||
// Process the filament_end_gcode for the active filament only.
|
// Process the filament_end_gcode for the active filament only.
|
||||||
int extruder_id = m_writer.extruder()->id();
|
int extruder_id = m_writer.filament()->id();
|
||||||
config.set_key_value("filament_extruder_id", new ConfigOptionInt(extruder_id));
|
config.set_key_value("filament_extruder_id", new ConfigOptionInt(extruder_id));
|
||||||
file.writeln(this->placeholder_parser_process("filament_end_gcode", print.config().filament_end_gcode.get_at(extruder_id), extruder_id, &config));
|
file.writeln(this->placeholder_parser_process("filament_end_gcode", print.config().filament_end_gcode.get_at(extruder_id), extruder_id, &config));
|
||||||
} else {
|
} else {
|
||||||
|
@ -2314,7 +2314,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
||||||
file.writeln(this->placeholder_parser_process("filament_end_gcode", end_gcode, extruder_id, &config));
|
file.writeln(this->placeholder_parser_process("filament_end_gcode", end_gcode, extruder_id, &config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.writeln(this->placeholder_parser_process("machine_end_gcode", print.config().machine_end_gcode, m_writer.extruder()->id(), &config));
|
file.writeln(this->placeholder_parser_process("machine_end_gcode", print.config().machine_end_gcode, m_writer.filament()->id(), &config));
|
||||||
}
|
}
|
||||||
file.write(m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
|
file.write(m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
|
||||||
file.write(m_writer.postamble());
|
file.write(m_writer.postamble());
|
||||||
|
@ -2384,7 +2384,9 @@ void GCode::check_placeholder_parser_failed()
|
||||||
|
|
||||||
size_t GCode::cur_extruder_index() const
|
size_t GCode::cur_extruder_index() const
|
||||||
{
|
{
|
||||||
return get_extruder_id(m_writer.extruder()->id());
|
//TODO: check if the function is duplicated
|
||||||
|
//just return m_writer.filament()->extruder_id()
|
||||||
|
return get_extruder_id(m_writer.filament()->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GCode::get_extruder_id(unsigned int filament_id) const
|
size_t GCode::get_extruder_id(unsigned int filament_id) const
|
||||||
|
@ -2504,10 +2506,10 @@ void GCode::process_layers(
|
||||||
tbb::parallel_pipeline(12, generator & cooling & output);
|
tbb::parallel_pipeline(12, generator & cooling & output);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
|
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_filament_id, const DynamicConfig *config_override)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return m_placeholder_parser.process(templ, current_extruder_id, config_override, &m_placeholder_parser_context);
|
return m_placeholder_parser.process(templ, current_filament_id, config_override, &m_placeholder_parser_context);
|
||||||
} catch (std::runtime_error &err) {
|
} catch (std::runtime_error &err) {
|
||||||
// Collect the names of failed template substitutions for error reporting.
|
// Collect the names of failed template substitutions for error reporting.
|
||||||
auto it = m_placeholder_parser_failed_templates.find(name);
|
auto it = m_placeholder_parser_failed_templates.find(name);
|
||||||
|
@ -3055,7 +3057,7 @@ GCode::LayerResult GCode::process_layer(
|
||||||
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
||||||
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
||||||
gcode += this->placeholder_parser_process("before_layer_change_gcode",
|
gcode += this->placeholder_parser_process("before_layer_change_gcode",
|
||||||
print.config().before_layer_change_gcode.value, m_writer.extruder()->id(), &config)
|
print.config().before_layer_change_gcode.value, m_writer.filament()->id(), &config)
|
||||||
+ "\n";
|
+ "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3077,7 +3079,7 @@ GCode::LayerResult GCode::process_layer(
|
||||||
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
|
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
|
||||||
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
||||||
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
||||||
gcode_res = this->placeholder_parser_process("timelapse_gcode", print.config().time_lapse_gcode.value, m_writer.extruder()->id(), &config) + "\n";
|
gcode_res = this->placeholder_parser_process("timelapse_gcode", print.config().time_lapse_gcode.value, m_writer.filament()->id(), &config) + "\n";
|
||||||
}
|
}
|
||||||
return gcode_res;
|
return gcode_res;
|
||||||
};
|
};
|
||||||
|
@ -3103,7 +3105,7 @@ GCode::LayerResult GCode::process_layer(
|
||||||
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
|
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
|
||||||
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
|
||||||
gcode += this->placeholder_parser_process("layer_change_gcode",
|
gcode += this->placeholder_parser_process("layer_change_gcode",
|
||||||
print.config().layer_change_gcode.value, m_writer.extruder()->id(), &config)
|
print.config().layer_change_gcode.value, m_writer.filament()->id(), &config)
|
||||||
+ "\n";
|
+ "\n";
|
||||||
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
|
||||||
}
|
}
|
||||||
|
@ -3175,7 +3177,7 @@ GCode::LayerResult GCode::process_layer(
|
||||||
// Transition from 1st to 2nd layer. Adjust nozzle temperatures as prescribed by the nozzle dependent
|
// Transition from 1st to 2nd layer. Adjust nozzle temperatures as prescribed by the nozzle dependent
|
||||||
// nozzle_temperature_initial_layer vs. temperature settings.
|
// nozzle_temperature_initial_layer vs. temperature settings.
|
||||||
for (const Extruder &extruder : m_writer.extruders()) {
|
for (const Extruder &extruder : m_writer.extruders()) {
|
||||||
if (print.config().single_extruder_multi_material.value && extruder.id() != m_writer.extruder()->id())
|
if (print.config().single_extruder_multi_material.value && extruder.id() != m_writer.filament()->id())
|
||||||
// In single extruder multi material mode, set the temperature for the current extruder only.
|
// In single extruder multi material mode, set the temperature for the current extruder only.
|
||||||
continue;
|
continue;
|
||||||
int temperature = print.config().nozzle_temperature.get_at(extruder.id());
|
int temperature = print.config().nozzle_temperature.get_at(extruder.id());
|
||||||
|
@ -3195,7 +3197,7 @@ GCode::LayerResult GCode::process_layer(
|
||||||
|
|
||||||
if (single_object_instance_idx == size_t(-1)) {
|
if (single_object_instance_idx == size_t(-1)) {
|
||||||
// Normal (non-sequential) print.
|
// Normal (non-sequential) print.
|
||||||
gcode += ProcessLayer::emit_custom_gcode_per_print_z(*this, layer_tools.custom_gcode, m_writer.extruder()->id(), first_extruder_id, print.config());
|
gcode += ProcessLayer::emit_custom_gcode_per_print_z(*this, layer_tools.custom_gcode, m_writer.filament()->id(), first_extruder_id, print.config());
|
||||||
}
|
}
|
||||||
// Extrude skirt at the print_z of the raft layers and normal object layers
|
// Extrude skirt at the print_z of the raft layers and normal object layers
|
||||||
// not at the print_z of the interlaced support material layers.
|
// not at the print_z of the interlaced support material layers.
|
||||||
|
@ -3960,7 +3962,7 @@ static std::map<int, std::string> overhang_speed_key_map =
|
||||||
|
|
||||||
double GCode::get_path_speed(const ExtrusionPath &path)
|
double GCode::get_path_speed(const ExtrusionPath &path)
|
||||||
{
|
{
|
||||||
double min_speed = double(m_config.slow_down_min_speed.get_at(m_writer.extruder()->id()));
|
double min_speed = double(m_config.slow_down_min_speed.get_at(m_writer.filament()->id()));
|
||||||
// set speed
|
// set speed
|
||||||
double speed = 0;
|
double speed = 0;
|
||||||
if (path.role() == erPerimeter) {
|
if (path.role() == erPerimeter) {
|
||||||
|
@ -4743,9 +4745,9 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
||||||
else if (this->on_first_layer())
|
else if (this->on_first_layer())
|
||||||
_mm3_per_mm *= m_config.initial_layer_flow_ratio.value;
|
_mm3_per_mm *= m_config.initial_layer_flow_ratio.value;
|
||||||
|
|
||||||
double e_per_mm = m_writer.extruder()->e_per_mm3() * _mm3_per_mm;
|
double e_per_mm = m_writer.filament()->e_per_mm3() * _mm3_per_mm;
|
||||||
|
|
||||||
double min_speed = double(m_config.slow_down_min_speed.get_at(m_writer.extruder()->id()));
|
double min_speed = double(m_config.slow_down_min_speed.get_at(m_writer.filament()->id()));
|
||||||
// set speed
|
// set speed
|
||||||
if (speed == -1) {
|
if (speed == -1) {
|
||||||
if (path.role() == erPerimeter) {
|
if (path.role() == erPerimeter) {
|
||||||
|
@ -5279,7 +5281,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
|
||||||
{
|
{
|
||||||
std::string gcode;
|
std::string gcode;
|
||||||
|
|
||||||
if (m_writer.extruder() == nullptr)
|
if (m_writer.filament() == nullptr)
|
||||||
return gcode;
|
return gcode;
|
||||||
|
|
||||||
// wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
|
// wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
|
||||||
|
@ -5296,7 +5298,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
|
||||||
|
|
||||||
gcode += m_writer.reset_e();
|
gcode += m_writer.reset_e();
|
||||||
//BBS
|
//BBS
|
||||||
if (m_writer.extruder()->retraction_length() > 0||m_config.use_firmware_retraction) {
|
if (m_writer.filament()->retraction_length() > 0||m_config.use_firmware_retraction) {
|
||||||
// BBS: force to use normal lift for spiral vase mode
|
// BBS: force to use normal lift for spiral vase mode
|
||||||
gcode += m_writer.lift(lift_type, m_spiral_vase != nullptr);
|
gcode += m_writer.lift(lift_type, m_spiral_vase != nullptr);
|
||||||
}
|
}
|
||||||
|
@ -5347,13 +5349,13 @@ std::string GCode::set_extruder(unsigned int filament_id, double print_z, bool b
|
||||||
else
|
else
|
||||||
m_writer.add_object_end_labels(gcode);
|
m_writer.add_object_end_labels(gcode);
|
||||||
|
|
||||||
if (m_writer.extruder() != nullptr) {
|
if (m_writer.filament() != nullptr) {
|
||||||
// Process the custom filament_end_gcode. set_extruder() is only called if there is no wipe tower
|
// Process the custom filament_end_gcode. set_extruder() is only called if there is no wipe tower
|
||||||
// so it should not be injected twice.
|
// so it should not be injected twice.
|
||||||
unsigned int old_extruder_id = m_writer.extruder()->id();
|
unsigned int old_filament_id = m_writer.filament()->id();
|
||||||
const std::string &filament_end_gcode = m_config.filament_end_gcode.get_at(old_extruder_id);
|
const std::string &filament_end_gcode = m_config.filament_end_gcode.get_at(old_filament_id);
|
||||||
if (! filament_end_gcode.empty()) {
|
if (! filament_end_gcode.empty()) {
|
||||||
gcode += placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_extruder_id);
|
gcode += placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id);
|
||||||
check_add_eol(gcode);
|
check_add_eol(gcode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5361,7 +5363,7 @@ std::string GCode::set_extruder(unsigned int filament_id, double print_z, bool b
|
||||||
|
|
||||||
// If ooze prevention is enabled, park current extruder in the nearest
|
// If ooze prevention is enabled, park current extruder in the nearest
|
||||||
// standby point and set it to the standby temperature.
|
// standby point and set it to the standby temperature.
|
||||||
if (m_ooze_prevention.enable && m_writer.extruder() != nullptr)
|
if (m_ooze_prevention.enable && m_writer.filament() != nullptr)
|
||||||
gcode += m_ooze_prevention.pre_toolchange(*this);
|
gcode += m_ooze_prevention.pre_toolchange(*this);
|
||||||
|
|
||||||
// BBS
|
// BBS
|
||||||
|
@ -5379,22 +5381,36 @@ std::string GCode::set_extruder(unsigned int filament_id, double print_z, bool b
|
||||||
float filament_area = float((M_PI / 4.f) * pow(m_config.filament_diameter.get_at(filament_id), 2));
|
float filament_area = float((M_PI / 4.f) * pow(m_config.filament_diameter.get_at(filament_id), 2));
|
||||||
//BBS: add handling for filament change in start gcode
|
//BBS: add handling for filament change in start gcode
|
||||||
int previous_filament_id = -1;
|
int previous_filament_id = -1;
|
||||||
if (m_writer.extruder() != nullptr || m_start_gcode_filament != -1) {
|
if (m_writer.filament() != nullptr || m_start_gcode_filament != -1) {
|
||||||
std::vector<float> flush_matrix(cast<float>(get_flush_volumes_matrix(m_config.flush_volumes_matrix.values, 0, m_config.nozzle_diameter.values.size())));
|
std::vector<float> flush_matrix(cast<float>(get_flush_volumes_matrix(m_config.flush_volumes_matrix.values, extruder_id, m_config.nozzle_diameter.values.size())));
|
||||||
const unsigned int number_of_extruders = (unsigned int) (m_config.filament_colour.values.size()); // if is multi_extruder only use the fist extruder matrix
|
const unsigned int number_of_extruders = (unsigned int) (m_config.filament_colour.values.size()); // if is multi_extruder only use the fist extruder matrix
|
||||||
if (m_writer.extruder() != nullptr)
|
if (m_writer.filament() != nullptr)
|
||||||
assert(m_writer.extruder()->id() < number_of_extruders);
|
assert(m_writer.filament()->id() < number_of_extruders);
|
||||||
else
|
else
|
||||||
assert(m_start_gcode_filament < number_of_extruders);
|
assert(m_start_gcode_filament < number_of_extruders);
|
||||||
|
|
||||||
previous_filament_id = m_writer.extruder() != nullptr ? m_writer.extruder()->id() : m_start_gcode_filament;
|
previous_filament_id = m_writer.filament() != nullptr ? m_writer.filament()->id() : m_start_gcode_filament;
|
||||||
int previous_extruder_id = m_writer.extruder() != nullptr ? m_writer.extruder()->extruder_id() : m_start_gcode_filament;
|
int previous_extruder_id = m_writer.filament() != nullptr ? m_writer.filament()->extruder_id() : get_extruder_id(m_start_gcode_filament);
|
||||||
|
|
||||||
old_retract_length = m_config.retraction_length.get_at(previous_extruder_id);
|
old_retract_length = m_config.retraction_length.get_at(previous_extruder_id);
|
||||||
old_retract_length_toolchange = m_config.retract_length_toolchange.get_at(previous_extruder_id);
|
old_retract_length_toolchange = m_config.retract_length_toolchange.get_at(previous_extruder_id);
|
||||||
old_filament_temp = this->on_first_layer()? m_config.nozzle_temperature_initial_layer.get_at(previous_filament_id) : m_config.nozzle_temperature.get_at(previous_filament_id);
|
old_filament_temp = this->on_first_layer()? m_config.nozzle_temperature_initial_layer.get_at(previous_filament_id) : m_config.nozzle_temperature.get_at(previous_filament_id);
|
||||||
wipe_volume = flush_matrix[previous_filament_id * number_of_extruders + filament_id];
|
|
||||||
wipe_volume *= m_config.flush_multiplier.get_at(0); // if is multi_extruder only use the fist extruder matrix
|
if (previous_extruder_id != extruder_id) {
|
||||||
|
//calc flush volume between the same extruder id
|
||||||
|
int previous_filament_id_in_new_extruder = m_writer.filament(extruder_id) != nullptr ? m_writer.filament(extruder_id)->id() : -1;
|
||||||
|
if (previous_filament_id_in_new_extruder == -1)
|
||||||
|
wipe_volume = 0;
|
||||||
|
else {
|
||||||
|
wipe_volume = flush_matrix[previous_filament_id_in_new_extruder * number_of_extruders + filament_id];
|
||||||
|
wipe_volume *= m_config.flush_multiplier.get_at(extruder_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wipe_volume = flush_matrix[previous_filament_id * number_of_extruders + filament_id];
|
||||||
|
wipe_volume *= m_config.flush_multiplier.get_at(extruder_id); // if is multi_extruder only use the fist extruder matrix
|
||||||
|
}
|
||||||
|
|
||||||
old_filament_e_feedrate = (int) (60.0 * m_config.filament_max_volumetric_speed.get_at(previous_filament_id) / filament_area);
|
old_filament_e_feedrate = (int) (60.0 * m_config.filament_max_volumetric_speed.get_at(previous_filament_id) / filament_area);
|
||||||
old_filament_e_feedrate = old_filament_e_feedrate == 0 ? 100 : old_filament_e_feedrate;
|
old_filament_e_feedrate = old_filament_e_feedrate == 0 ? 100 : old_filament_e_feedrate;
|
||||||
//BBS: must clean m_start_gcode_filament
|
//BBS: must clean m_start_gcode_filament
|
||||||
|
|
|
@ -705,7 +705,7 @@ static bool need_wipe(const GCode &gcodegen,
|
||||||
{
|
{
|
||||||
const ExPolygons &lslices = gcodegen.layer()->lslices;
|
const ExPolygons &lslices = gcodegen.layer()->lslices;
|
||||||
const std::vector<BoundingBox> &lslices_bboxes = gcodegen.layer()->lslices_bboxes;
|
const std::vector<BoundingBox> &lslices_bboxes = gcodegen.layer()->lslices_bboxes;
|
||||||
bool z_lift_enabled = gcodegen.config().z_hop.get_at(gcodegen.writer().extruder()->extruder_id()) > 0.;
|
bool z_lift_enabled = gcodegen.config().z_hop.get_at(gcodegen.writer().filament()->id()) > 0.;
|
||||||
bool wipe_needed = false;
|
bool wipe_needed = false;
|
||||||
|
|
||||||
// If the original unmodified path doesn't have any intersection with boundary, then it is entirely inside the object otherwise is entirely
|
// If the original unmodified path doesn't have any intersection with boundary, then it is entirely inside the object otherwise is entirely
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
#include "FilamentGroup.hpp"
|
#include "../FilamentGroup.hpp"
|
||||||
#include "ExtrusionEntity.hpp"
|
#include "ExtrusionEntity.hpp"
|
||||||
#include "PrintConfig.hpp"
|
#include "PrintConfig.hpp"
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,10 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config)
|
||||||
void GCodeWriter::set_extruders(std::vector<unsigned int> extruder_ids)
|
void GCodeWriter::set_extruders(std::vector<unsigned int> extruder_ids)
|
||||||
{
|
{
|
||||||
std::sort(extruder_ids.begin(), extruder_ids.end());
|
std::sort(extruder_ids.begin(), extruder_ids.end());
|
||||||
m_extruders.clear();
|
m_filament_extruders.clear();
|
||||||
m_extruders.reserve(extruder_ids.size());
|
m_filament_extruders.reserve(extruder_ids.size());
|
||||||
for (unsigned int extruder_id : extruder_ids)
|
for (unsigned int extruder_id : extruder_ids)
|
||||||
m_extruders.emplace_back(Extruder(extruder_id, &this->config, config.single_extruder_multi_material.value));
|
m_filament_extruders.emplace_back(Extruder(extruder_id, &this->config, config.single_extruder_multi_material.value));
|
||||||
|
|
||||||
/* we enable support for multiple extruder if any extruder greater than 0 is used
|
/* we enable support for multiple extruder if any extruder greater than 0 is used
|
||||||
(even if prints only uses that one) since we need to output Tx commands
|
(even if prints only uses that one) since we need to output Tx commands
|
||||||
|
@ -254,10 +254,10 @@ std::string GCodeWriter::reset_e(bool force)
|
||||||
|| FLAVOR_IS(gcfSailfish))
|
|| FLAVOR_IS(gcfSailfish))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if (m_extruder != nullptr) {
|
if (m_curr_extruder_id!=-1 && m_curr_filament_extruder[m_curr_extruder_id] != nullptr) {
|
||||||
if (m_extruder->E() == 0. && ! force)
|
if (m_curr_filament_extruder[m_curr_extruder_id]->E() == 0. && !force)
|
||||||
return "";
|
return "";
|
||||||
m_extruder->reset_E();
|
m_curr_filament_extruder[m_curr_extruder_id]->reset_E();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->config.use_relative_e_distances) {
|
if (!this->config.use_relative_e_distances) {
|
||||||
|
@ -294,12 +294,13 @@ std::string GCodeWriter::toolchange_prefix() const
|
||||||
FLAVOR_IS(gcfSailfish) ? "M108 T" : "T";
|
FLAVOR_IS(gcfSailfish) ? "M108 T" : "T";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GCodeWriter::toolchange(unsigned int extruder_id)
|
std::string GCodeWriter::toolchange(unsigned int filament_id)
|
||||||
{
|
{
|
||||||
// set the new extruder
|
// set the new extruder
|
||||||
auto it_extruder = Slic3r::lower_bound_by_predicate(m_extruders.begin(), m_extruders.end(), [extruder_id](const Extruder &e) { return e.id() < extruder_id; });
|
auto filament_extruder_iter = Slic3r::lower_bound_by_predicate(m_filament_extruders.begin(), m_filament_extruders.end(), [filament_id](const Extruder &e) { return e.id() < filament_id; });
|
||||||
assert(it_extruder != m_extruders.end() && it_extruder->id() == extruder_id);
|
assert(filament_extruder_iter != m_filament_extruders.end() && filament_extruder_iter->id() == filament_id);
|
||||||
m_extruder = &*it_extruder;
|
m_curr_extruder_id = filament_extruder_iter->extruder_id();
|
||||||
|
m_curr_filament_extruder[m_curr_extruder_id] = &*filament_extruder_iter;
|
||||||
|
|
||||||
// return the toolchange command
|
// return the toolchange command
|
||||||
// if we are running a single-extruder setup, just set the extruder and return nothing
|
// if we are running a single-extruder setup, just set the extruder and return nothing
|
||||||
|
@ -307,9 +308,9 @@ std::string GCodeWriter::toolchange(unsigned int extruder_id)
|
||||||
if (this->multiple_extruders) {
|
if (this->multiple_extruders) {
|
||||||
// BBS
|
// BBS
|
||||||
if (this->m_is_bbl_printer)
|
if (this->m_is_bbl_printer)
|
||||||
gcode << "M1020 S" << extruder_id;
|
gcode << "M1020 S" << filament_id;
|
||||||
else
|
else
|
||||||
gcode << this->toolchange_prefix() << extruder_id;
|
gcode << this->toolchange_prefix() << filament_id;
|
||||||
//BBS
|
//BBS
|
||||||
if (GCodeWriter::full_gcode_comment)
|
if (GCodeWriter::full_gcode_comment)
|
||||||
gcode << " ; change extruder";
|
gcode << " ; change extruder";
|
||||||
|
@ -343,7 +344,7 @@ std::string GCodeWriter::travel_to_xy(const Vec2d &point, const std::string &com
|
||||||
|
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_xy(point_on_plate);
|
w.emit_xy(point_on_plate);
|
||||||
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
return w.string();
|
return w.string();
|
||||||
|
@ -403,7 +404,7 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co
|
||||||
Vec3d slope_top_point = Vec3d(temp(0), temp(1), delta(2)) + source;
|
Vec3d slope_top_point = Vec3d(temp(0), temp(1), delta(2)) + source;
|
||||||
GCodeG1Formatter w0;
|
GCodeG1Formatter w0;
|
||||||
w0.emit_xyz(slope_top_point);
|
w0.emit_xyz(slope_top_point);
|
||||||
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
//BBS
|
//BBS
|
||||||
w0.emit_comment(GCodeWriter::full_gcode_comment, "slope lift Z");
|
w0.emit_comment(GCodeWriter::full_gcode_comment, "slope lift Z");
|
||||||
slop_move = w0.string();
|
slop_move = w0.string();
|
||||||
|
@ -418,13 +419,13 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co
|
||||||
GCodeG1Formatter w0;
|
GCodeG1Formatter w0;
|
||||||
if (this->is_current_position_clear()) {
|
if (this->is_current_position_clear()) {
|
||||||
w0.emit_xyz(target);
|
w0.emit_xyz(target);
|
||||||
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
w0.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w0.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
xy_z_move = w0.string();
|
xy_z_move = w0.string();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
w0.emit_xy(Vec2d(target.x(), target.y()));
|
w0.emit_xy(Vec2d(target.x(), target.y()));
|
||||||
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w0.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
w0.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w0.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
xy_z_move = w0.string() + _travel_to_z(target.z(), comment);
|
xy_z_move = w0.string() + _travel_to_z(target.z(), comment);
|
||||||
}
|
}
|
||||||
|
@ -458,13 +459,13 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co
|
||||||
{
|
{
|
||||||
//force to move xy first then z after filament change
|
//force to move xy first then z after filament change
|
||||||
w.emit_xy(Vec2d(point_on_plate.x(), point_on_plate.y()));
|
w.emit_xy(Vec2d(point_on_plate.x(), point_on_plate.y()));
|
||||||
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
out_string = w.string() + _travel_to_z(point_on_plate.z(), comment);
|
out_string = w.string() + _travel_to_z(point_on_plate.z(), comment);
|
||||||
} else {
|
} else {
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_xyz(point_on_plate);
|
w.emit_xyz(point_on_plate);
|
||||||
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id())) * 60.0);
|
w.emit_f(this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id())) * 60.0);
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
out_string = w.string();
|
out_string = w.string();
|
||||||
}
|
}
|
||||||
|
@ -497,9 +498,9 @@ std::string GCodeWriter::_travel_to_z(double z, const std::string &comment)
|
||||||
{
|
{
|
||||||
m_pos(2) = z;
|
m_pos(2) = z;
|
||||||
|
|
||||||
double speed = this->config.travel_speed_z.get_at(get_extruder_index(this->config, extruder()->id()));
|
double speed = this->config.travel_speed_z.get_at(get_extruder_index(this->config, filament()->id()));
|
||||||
if (speed == 0.)
|
if (speed == 0.)
|
||||||
speed = this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id()));
|
speed = this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id()));
|
||||||
|
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_z(z);
|
w.emit_z(z);
|
||||||
|
@ -513,9 +514,9 @@ std::string GCodeWriter::_spiral_travel_to_z(double z, const Vec2d &ij_offset, c
|
||||||
{
|
{
|
||||||
m_pos(2) = z;
|
m_pos(2) = z;
|
||||||
|
|
||||||
double speed = this->config.travel_speed_z.get_at(get_extruder_index(this->config, extruder()->id()));
|
double speed = this->config.travel_speed_z.get_at(get_extruder_index(this->config, filament()->id()));
|
||||||
if (speed == 0.)
|
if (speed == 0.)
|
||||||
speed = this->config.travel_speed.get_at(get_extruder_index(this->config, extruder()->id()));
|
speed = this->config.travel_speed.get_at(get_extruder_index(this->config, filament()->id()));
|
||||||
|
|
||||||
std::string output = "G17\n";
|
std::string output = "G17\n";
|
||||||
GCodeG2G3Formatter w(true);
|
GCodeG2G3Formatter w(true);
|
||||||
|
@ -550,7 +551,7 @@ std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std:
|
||||||
m_pos(1) = point(1);
|
m_pos(1) = point(1);
|
||||||
|
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
m_extruder->extrude(dE);
|
filament()->extrude(dE);
|
||||||
|
|
||||||
//BBS: take plate offset into consider
|
//BBS: take plate offset into consider
|
||||||
Vec2d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset };
|
Vec2d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset };
|
||||||
|
@ -558,7 +559,7 @@ std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std:
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_xy(point_on_plate);
|
w.emit_xy(point_on_plate);
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
w.emit_e(m_extruder->E());
|
w.emit_e(filament()->E());
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
return w.string();
|
return w.string();
|
||||||
|
@ -572,7 +573,7 @@ std::string GCodeWriter::extrude_arc_to_xy(const Vec2d& point, const Vec2d& cent
|
||||||
m_pos(0) = point(0);
|
m_pos(0) = point(0);
|
||||||
m_pos(1) = point(1);
|
m_pos(1) = point(1);
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
m_extruder->extrude(dE);
|
filament()->extrude(dE);
|
||||||
|
|
||||||
Vec2d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset };
|
Vec2d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset };
|
||||||
|
|
||||||
|
@ -580,7 +581,7 @@ std::string GCodeWriter::extrude_arc_to_xy(const Vec2d& point, const Vec2d& cent
|
||||||
w.emit_xy(point_on_plate);
|
w.emit_xy(point_on_plate);
|
||||||
w.emit_ij(center_offset);
|
w.emit_ij(center_offset);
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
w.emit_e(m_extruder->E());
|
w.emit_e(filament()->E());
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
return w.string();
|
return w.string();
|
||||||
|
@ -591,7 +592,7 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
|
||||||
m_pos = point;
|
m_pos = point;
|
||||||
m_lifted = 0;
|
m_lifted = 0;
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
m_extruder->extrude(dE);
|
filament()->extrude(dE);
|
||||||
|
|
||||||
//BBS: take plate offset into consider
|
//BBS: take plate offset into consider
|
||||||
Vec3d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset, point(2) };
|
Vec3d point_on_plate = { point(0) - m_x_offset, point(1) - m_y_offset, point(2) };
|
||||||
|
@ -599,7 +600,7 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_xyz(point_on_plate);
|
w.emit_xyz(point_on_plate);
|
||||||
if (!force_no_extrusion)
|
if (!force_no_extrusion)
|
||||||
w.emit_e(m_extruder->E());
|
w.emit_e(filament()->E());
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
return w.string();
|
return w.string();
|
||||||
|
@ -607,22 +608,22 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
|
||||||
|
|
||||||
std::string GCodeWriter::retract(bool before_wipe)
|
std::string GCodeWriter::retract(bool before_wipe)
|
||||||
{
|
{
|
||||||
double factor = before_wipe ? m_extruder->retract_before_wipe() : 1.;
|
double factor = before_wipe ? filament()->retract_before_wipe() : 1.;
|
||||||
assert(factor >= 0. && factor <= 1. + EPSILON);
|
assert(factor >= 0. && factor <= 1. + EPSILON);
|
||||||
return this->_retract(
|
return this->_retract(
|
||||||
factor * m_extruder->retraction_length(),
|
factor * filament()->retraction_length(),
|
||||||
factor * m_extruder->retract_restart_extra(),
|
factor * filament()->retract_restart_extra(),
|
||||||
"retract"
|
"retract"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GCodeWriter::retract_for_toolchange(bool before_wipe)
|
std::string GCodeWriter::retract_for_toolchange(bool before_wipe)
|
||||||
{
|
{
|
||||||
double factor = before_wipe ? m_extruder->retract_before_wipe() : 1.;
|
double factor = before_wipe ? filament()->retract_before_wipe() : 1.;
|
||||||
assert(factor >= 0. && factor <= 1. + EPSILON);
|
assert(factor >= 0. && factor <= 1. + EPSILON);
|
||||||
return this->_retract(
|
return this->_retract(
|
||||||
factor * m_extruder->retract_length_toolchange(),
|
factor * filament()->retract_length_toolchange(),
|
||||||
factor * m_extruder->retract_restart_extra_toolchange(),
|
factor * filament()->retract_restart_extra_toolchange(),
|
||||||
"retract for toolchange"
|
"retract for toolchange"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -632,7 +633,7 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
|
||||||
std::string gcode;
|
std::string gcode;
|
||||||
if (config.use_firmware_retraction)
|
if (config.use_firmware_retraction)
|
||||||
length = 1;
|
length = 1;
|
||||||
if (double dE = m_extruder->retract(length, restart_extra); dE != 0) {
|
if (double dE = filament()->retract(length, restart_extra); dE != 0) {
|
||||||
//add firmware retraction
|
//add firmware retraction
|
||||||
if (config.use_firmware_retraction) {
|
if (config.use_firmware_retraction) {
|
||||||
gcode = FLAVOR_IS(gcfMachinekit) ? "G22 ;retract" : "G10 ;retract \n";
|
gcode = FLAVOR_IS(gcfMachinekit) ? "G22 ;retract" : "G10 ;retract \n";
|
||||||
|
@ -640,8 +641,8 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
|
||||||
else {
|
else {
|
||||||
//BBS
|
//BBS
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_e(m_extruder->E());
|
w.emit_e(filament()->E());
|
||||||
w.emit_f(m_extruder->retract_speed() * 60.);
|
w.emit_f(filament()->retract_speed() * 60.);
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
|
||||||
gcode = w.string();
|
gcode = w.string();
|
||||||
|
@ -661,7 +662,7 @@ std::string GCodeWriter::unretract()
|
||||||
if (FLAVOR_IS(gcfMakerWare))
|
if (FLAVOR_IS(gcfMakerWare))
|
||||||
gcode = "M101 ; extruder on\n";
|
gcode = "M101 ; extruder on\n";
|
||||||
|
|
||||||
if (double dE = m_extruder->unretract(); dE != 0) {
|
if (double dE = filament()->unretract(); dE != 0) {
|
||||||
if (config.use_firmware_retraction) {
|
if (config.use_firmware_retraction) {
|
||||||
gcode += FLAVOR_IS(gcfMachinekit) ? "G23 ;unretract \n" : "G11 ;unretract \n";
|
gcode += FLAVOR_IS(gcfMachinekit) ? "G23 ;unretract \n" : "G11 ;unretract \n";
|
||||||
gcode += reset_e();
|
gcode += reset_e();
|
||||||
|
@ -670,8 +671,8 @@ std::string GCodeWriter::unretract()
|
||||||
//BBS
|
//BBS
|
||||||
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
|
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
|
||||||
GCodeG1Formatter w;
|
GCodeG1Formatter w;
|
||||||
w.emit_e(m_extruder->E());
|
w.emit_e(filament()->E());
|
||||||
w.emit_f(m_extruder->deretract_speed() * 60.);
|
w.emit_f(filament()->deretract_speed() * 60.);
|
||||||
//BBS
|
//BBS
|
||||||
w.emit_comment(GCodeWriter::full_gcode_comment, " ; unretract");
|
w.emit_comment(GCodeWriter::full_gcode_comment, " ; unretract");
|
||||||
gcode += w.string();
|
gcode += w.string();
|
||||||
|
@ -690,7 +691,7 @@ std::string GCodeWriter::lift(LiftType lift_type, bool spiral_vase)
|
||||||
double target_lift = 0;
|
double target_lift = 0;
|
||||||
{
|
{
|
||||||
//BBS
|
//BBS
|
||||||
int extruder_id = m_extruder->extruder_id();
|
int extruder_id = filament()->extruder_id();
|
||||||
double above = this->config.retract_lift_above.get_at(extruder_id);
|
double above = this->config.retract_lift_above.get_at(extruder_id);
|
||||||
double below = this->config.retract_lift_below.get_at(extruder_id);
|
double below = this->config.retract_lift_below.get_at(extruder_id);
|
||||||
if (m_pos.z() >= above && m_pos.z() <= below)
|
if (m_pos.z() >= above && m_pos.z() <= below)
|
||||||
|
@ -809,6 +810,21 @@ void GCodeWriter::add_object_change_labels(std::string& gcode)
|
||||||
add_object_start_labels(gcode);
|
add_object_start_labels(gcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GCodeWriter::set_extruder(unsigned int filament_id)
|
||||||
|
{
|
||||||
|
auto filament_ext_it = Slic3r::lower_bound_by_predicate(m_filament_extruders.begin(), m_filament_extruders.end(), [filament_id](const Extruder &e) { return e.id() < filament_id; });
|
||||||
|
unsigned int extruder_id = filament_ext_it->extruder_id();
|
||||||
|
assert(filament_ext_it != m_filament_extruders.end() && filament_ext_it->id() == filament_id);
|
||||||
|
//TODO: optmize here, pass extruder_id to toolchange
|
||||||
|
return this->need_toolchange(filament_id) ? this->toolchange(filament_id) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GCodeWriter::need_toolchange(unsigned int filament_id)const
|
||||||
|
{
|
||||||
|
return filament()==nullptr || filament()->id()!=filament_id;
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeFormatter::emit_axis(const char axis, const double v, size_t digits) {
|
void GCodeFormatter::emit_axis(const char axis, const double v, size_t digits) {
|
||||||
assert(digits <= 9);
|
assert(digits <= 9);
|
||||||
static constexpr const std::array<int, 10> pow_10{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
|
static constexpr const std::array<int, 10> pow_10{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
|
||||||
|
|
|
@ -21,9 +21,10 @@ class GCodeWriter {
|
||||||
public:
|
public:
|
||||||
GCodeConfig config;
|
GCodeConfig config;
|
||||||
bool multiple_extruders;
|
bool multiple_extruders;
|
||||||
|
|
||||||
GCodeWriter() :
|
GCodeWriter() :
|
||||||
multiple_extruders(false), m_extruder(nullptr),
|
multiple_extruders(false), m_curr_filament_extruder{ nullptr,nullptr },
|
||||||
|
m_curr_extruder_id (-1),
|
||||||
m_single_extruder_multi_material(false),
|
m_single_extruder_multi_material(false),
|
||||||
m_last_acceleration(0), m_max_acceleration(0),
|
m_last_acceleration(0), m_max_acceleration(0),
|
||||||
m_last_jerk(0), m_max_jerk(0),
|
m_last_jerk(0), m_max_jerk(0),
|
||||||
|
@ -32,18 +33,20 @@ public:
|
||||||
m_to_lift(0),
|
m_to_lift(0),
|
||||||
m_to_lift_type(LiftType::NormalLift)
|
m_to_lift_type(LiftType::NormalLift)
|
||||||
{}
|
{}
|
||||||
Extruder* extruder() { return m_extruder; }
|
Extruder* filament(size_t extruder_id) { assert(extruder_id < m_curr_filament_extruder.size()); return m_curr_filament_extruder[extruder_id]; }
|
||||||
const Extruder* extruder() const { return m_extruder; }
|
const Extruder* filament(size_t extruder_id) const { assert(extruder_id < m_curr_filament_extruder.size()); return m_curr_filament_extruder[extruder_id]; }
|
||||||
|
Extruder* filament() { if (m_curr_extruder_id == -1) return nullptr; return m_curr_filament_extruder[m_curr_extruder_id]; }
|
||||||
|
const Extruder* filament() const { if(m_curr_extruder_id==-1) return nullptr; return m_curr_filament_extruder[m_curr_extruder_id]; }
|
||||||
|
|
||||||
void apply_print_config(const PrintConfig &print_config);
|
void apply_print_config(const PrintConfig &print_config);
|
||||||
// Extruders are expected to be sorted in an increasing order.
|
// Extruders are expected to be sorted in an increasing order.
|
||||||
void set_extruders(std::vector<unsigned int> extruder_ids);
|
void set_extruders(std::vector<unsigned int> extruder_ids);
|
||||||
const std::vector<Extruder>& extruders() const { return m_extruders; }
|
const std::vector<Extruder>& extruders() const { return m_filament_extruders; }
|
||||||
std::vector<unsigned int> extruder_ids() const {
|
std::vector<unsigned int> extruder_ids() const {
|
||||||
std::vector<unsigned int> out;
|
std::vector<unsigned int> out;
|
||||||
out.reserve(m_extruders.size());
|
out.reserve(m_filament_extruders.size());
|
||||||
for (const Extruder &e : m_extruders)
|
for (const Extruder &e : m_filament_extruders)
|
||||||
out.push_back(e.id());
|
out.push_back(e.id());
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
|
@ -57,14 +60,12 @@ public:
|
||||||
std::string reset_e(bool force = false);
|
std::string reset_e(bool force = false);
|
||||||
std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const;
|
std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const;
|
||||||
// return false if this extruder was already selected
|
// return false if this extruder was already selected
|
||||||
bool need_toolchange(unsigned int extruder_id) const
|
bool need_toolchange(unsigned int filament_id) const;
|
||||||
{ return m_extruder == nullptr || m_extruder->id() != extruder_id; }
|
std::string set_extruder(unsigned int filament_id);
|
||||||
std::string set_extruder(unsigned int extruder_id)
|
|
||||||
{ return this->need_toolchange(extruder_id) ? this->toolchange(extruder_id) : ""; }
|
|
||||||
// Prefix of the toolchange G-code line, to be used by the CoolingBuffer to separate sections of the G-code
|
// Prefix of the toolchange G-code line, to be used by the CoolingBuffer to separate sections of the G-code
|
||||||
// printed with the same extruder.
|
// printed with the same extruder.
|
||||||
std::string toolchange_prefix() const;
|
std::string toolchange_prefix() const;
|
||||||
std::string toolchange(unsigned int extruder_id);
|
std::string toolchange(unsigned int filament_id);
|
||||||
std::string set_speed(double F, const std::string &comment = std::string(), const std::string &cooling_marker = std::string());
|
std::string set_speed(double F, const std::string &comment = std::string(), const std::string &cooling_marker = std::string());
|
||||||
double get_current_speed() { return m_current_speed; };
|
double get_current_speed() { return m_current_speed; };
|
||||||
std::string travel_to_xy(const Vec2d &point, const std::string &comment = std::string());
|
std::string travel_to_xy(const Vec2d &point, const std::string &comment = std::string());
|
||||||
|
@ -114,9 +115,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Extruders are sorted by their ID, so that binary search is possible.
|
// Extruders are sorted by their ID, so that binary search is possible.
|
||||||
std::vector<Extruder> m_extruders;
|
std::vector<Extruder> m_filament_extruders;
|
||||||
bool m_single_extruder_multi_material;
|
bool m_single_extruder_multi_material;
|
||||||
Extruder* m_extruder;
|
std::vector<Extruder*> m_curr_filament_extruder;
|
||||||
|
int m_curr_extruder_id;
|
||||||
unsigned int m_last_acceleration;
|
unsigned int m_last_acceleration;
|
||||||
// Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware.
|
// Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware.
|
||||||
// If set to zero, the limit is not in action.
|
// If set to zero, the limit is not in action.
|
||||||
|
|
|
@ -2473,14 +2473,7 @@ void Print::_make_wipe_tower()
|
||||||
multi_extruder_flush.emplace_back(wipe_volumes);
|
multi_extruder_flush.emplace_back(wipe_volumes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo multi_extruders: get filament_maps
|
std::vector<int>filament_maps = get_filament_maps();
|
||||||
std::vector<int> filament_maps;
|
|
||||||
for (int i = 0; i <= number_of_extruders / 2; ++i) {
|
|
||||||
filament_maps.push_back(1);
|
|
||||||
}
|
|
||||||
for (int i = number_of_extruders / 2 + 1; i < number_of_extruders; ++i) {
|
|
||||||
filament_maps.push_back(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned int> nozzle_cur_filament_ids(nozzle_nums, -1);
|
std::vector<unsigned int> nozzle_cur_filament_ids(nozzle_nums, -1);
|
||||||
unsigned int current_filament_id = m_wipe_tower_data.tool_ordering.first_extruder();
|
unsigned int current_filament_id = m_wipe_tower_data.tool_ordering.first_extruder();
|
||||||
|
@ -2510,6 +2503,7 @@ void Print::_make_wipe_tower()
|
||||||
wipe_tower.plan_toolchange((float) layer_tools.print_z, (float) layer_tools.wipe_tower_layer_height, current_filament_id, filament_id,
|
wipe_tower.plan_toolchange((float) layer_tools.print_z, (float) layer_tools.wipe_tower_layer_height, current_filament_id, filament_id,
|
||||||
m_config.prime_volume, volume_to_purge);
|
m_config.prime_volume, volume_to_purge);
|
||||||
current_filament_id = filament_id;
|
current_filament_id = filament_id;
|
||||||
|
nozzle_cur_filament_ids[nozzle_id] = filament_id;
|
||||||
}
|
}
|
||||||
layer_tools.wiping_extrusions().ensure_perimeters_infills_order(*this);
|
layer_tools.wiping_extrusions().ensure_perimeters_infills_order(*this);
|
||||||
|
|
||||||
|
|
|
@ -807,6 +807,7 @@ public:
|
||||||
|
|
||||||
void update_filament_maps_to_config(std::vector<int> f_maps);
|
void update_filament_maps_to_config(std::vector<int> f_maps);
|
||||||
std::vector<int> get_filament_maps() const;
|
std::vector<int> get_filament_maps() const;
|
||||||
|
// get the group label of filament
|
||||||
size_t get_extruder_id(unsigned int filament_id) const;
|
size_t get_extruder_id(unsigned int filament_id) const;
|
||||||
|
|
||||||
bool enable_timelapse_print() const;
|
bool enable_timelapse_print() const;
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Slic3r {
|
||||||
size_t get_extruder_index(const GCodeConfig& config, unsigned int filament_id)
|
size_t get_extruder_index(const GCodeConfig& config, unsigned int filament_id)
|
||||||
{
|
{
|
||||||
if (filament_id < config.filament_map.size()) {
|
if (filament_id < config.filament_map.size()) {
|
||||||
return config.filament_map.get_at(filament_id);
|
return config.filament_map.get_at(filament_id)-1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue