Skip to content

Commit

Permalink
Suppor of "No extrusion" firmware flavor by not emitting the E axis.
Browse files Browse the repository at this point in the history
Fix of #6023
The fix is partial: No extrusions are shown by the final G-code preview.
  • Loading branch information
bubnikv committed Aug 9, 2021
1 parent d6370a1 commit 9f9cbb4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/libslic3r/GCode.cpp
Expand Up @@ -2714,7 +2714,9 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,

// calculate extrusion length per distance unit
double e_per_mm = m_writer.extruder()->e_per_mm3() * path.mm3_per_mm;
if (m_writer.extrusion_axis().empty()) e_per_mm = 0;
if (m_writer.extrusion_axis().empty())
// gcfNoExtrusion
e_per_mm = 0;

// set speed
if (speed == -1) {
Expand Down
21 changes: 16 additions & 5 deletions src/libslic3r/GCodeReader.cpp
Expand Up @@ -12,16 +12,24 @@

namespace Slic3r {

static inline char get_extrusion_axis_char(const GCodeConfig &config)
{
std::string axis = get_extrusion_axis(config);
assert(axis.size() <= 1);
// Return 0 for gcfNoExtrusion
return axis.empty() ? 0 : axis[0];
}

void GCodeReader::apply_config(const GCodeConfig &config)
{
m_config = config;
m_extrusion_axis = get_extrusion_axis(m_config)[0];
m_extrusion_axis = get_extrusion_axis_char(m_config);
}

void GCodeReader::apply_config(const DynamicPrintConfig &config)
{
m_config.apply(config, true);
m_extrusion_axis = get_extrusion_axis(m_config)[0];
m_extrusion_axis = get_extrusion_axis_char(m_config);
}

const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command)
Expand Down Expand Up @@ -52,9 +60,10 @@ const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline,
case 'Z': axis = Z; break;
case 'F': axis = F; break;
default:
if (*c == m_extrusion_axis)
axis = E;
else if (*c >= 'A' && *c <= 'Z')
if (*c == m_extrusion_axis) {
if (m_extrusion_axis != 0)
axis = E;
} else if (*c >= 'A' && *c <= 'Z')
// Unknown axis, but we still want to remember that such a axis was seen.
axis = UNKNOWN_AXIS;
break;
Expand Down Expand Up @@ -190,6 +199,8 @@ void GCodeReader::GCodeLine::set(const GCodeReader &reader, const Axis axis, con
match[1] = 'F';
else {
assert(axis == E);
// Extruder axis is set.
assert(reader.extrusion_axis() != 0);
match[1] = reader.extrusion_axis();
}

Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/GCodeReader.hpp
Expand Up @@ -122,8 +122,9 @@ class GCodeReader {
float& f() { return m_position[F]; }
float f() const { return m_position[F]; }

// Returns 0 for gcfNoExtrusion.
char extrusion_axis() const { return m_extrusion_axis; }
void set_extrusion_axis(char axis) { m_extrusion_axis = axis; }
// void set_extrusion_axis(char axis) { m_extrusion_axis = axis; }

private:
const char* parse_line_internal(const char *ptr, GCodeLine &gline, std::pair<const char*, const char*> &command);
Expand Down
16 changes: 10 additions & 6 deletions src/libslic3r/GCodeWriter.cpp
Expand Up @@ -405,8 +405,10 @@ std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std:

std::ostringstream gcode;
gcode << "G1 X" << XYZF_NUM(point(0))
<< " Y" << XYZF_NUM(point(1))
<< " " << m_extrusion_axis << E_NUM(m_extruder->E());
<< " Y" << XYZF_NUM(point(1));
if (! m_extrusion_axis.empty())
// not gcfNoExtrusion
gcode << " " << m_extrusion_axis << E_NUM(m_extruder->E());
COMMENT(comment);
gcode << "\n";
return gcode.str();
Expand All @@ -421,8 +423,10 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
std::ostringstream gcode;
gcode << "G1 X" << XYZF_NUM(point(0))
<< " Y" << XYZF_NUM(point(1))
<< " Z" << XYZF_NUM(point(2))
<< " " << m_extrusion_axis << E_NUM(m_extruder->E());
<< " Z" << XYZF_NUM(point(2));
if (! m_extrusion_axis.empty())
// not gcfNoExtrusion
gcode << " " << m_extrusion_axis << E_NUM(m_extruder->E());
COMMENT(comment);
gcode << "\n";
return gcode.str();
Expand Down Expand Up @@ -474,7 +478,7 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
gcode << "G22 ; retract\n";
else
gcode << "G10 ; retract\n";
} else {
} else if (! m_extrusion_axis.empty()) {
gcode << "G1 " << m_extrusion_axis << E_NUM(m_extruder->E())
<< " F" << XYZF_NUM(m_extruder->retract_speed() * 60.);
COMMENT(comment);
Expand Down Expand Up @@ -503,7 +507,7 @@ std::string GCodeWriter::unretract()
else
gcode << "G11 ; unretract\n";
gcode << this->reset_e();
} else {
} else if (! m_extrusion_axis.empty()) {
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
gcode << "G1 " << m_extrusion_axis << E_NUM(m_extruder->E())
<< " F" << XYZF_NUM(m_extruder->deretract_speed() * 60.);
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/GCodeWriter.hpp
Expand Up @@ -25,6 +25,7 @@ class GCodeWriter {
Extruder* extruder() { return m_extruder; }
const Extruder* extruder() const { return m_extruder; }

// Returns empty string for gcfNoExtrusion.
std::string extrusion_axis() const { return m_extrusion_axis; }
void apply_print_config(const PrintConfig &print_config);
// Extruders are expected to be sorted in an increasing order.
Expand Down

0 comments on commit 9f9cbb4

Please sign in to comment.