Tech ENABLE_PROCESS_G2_G3_LINES - Improved detection of layer zs for gcode produced by other slicers
This commit is contained in:
parent
82fe599cae
commit
93d703518d
3 changed files with 37 additions and 11 deletions
|
@ -37,7 +37,7 @@ static const float DEFAULT_FILAMENT_DENSITY = 1.245f;
|
||||||
static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero();
|
static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero();
|
||||||
|
|
||||||
#if ENABLE_PROCESS_G2_G3_LINES
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
static const std::string INTERNAL_G2G3_TAG = "!#!#! from G2/G3 expansion !#!#!";
|
static const std::string INTERNAL_G2G3_TAG = "!#!#! internal only - from G2/G3 expansion !#!#!";
|
||||||
#endif // ENABLE_PROCESS_G2_G3_LINES
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
@ -2782,7 +2782,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
||||||
m_result.spiral_vase_layers.back().second.second = m_result.moves.size() - 1;
|
m_result.spiral_vase_layers.back().second.second = m_result.moves.size() - 1;
|
||||||
|
|
||||||
// store move
|
// store move
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
store_move_vertex(type, line.comment() == INTERNAL_G2G3_TAG);
|
||||||
|
#else
|
||||||
store_move_vertex(type);
|
store_move_vertex(type);
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_PROCESS_G2_G3_LINES
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
@ -2897,7 +2901,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto fake_g1_line = [](const AxisCoords& target, bool has_z, const std::optional<float>& feedrate, const std::optional<float>& extrusion) {
|
auto internal_only_g1_line = [](const AxisCoords& target, bool has_z, const std::optional<float>& feedrate, const std::optional<float>& extrusion) {
|
||||||
std::string ret = (boost::format("G1 X%1% Y%2%") % target[X] % target[Y]).str();
|
std::string ret = (boost::format("G1 X%1% Y%2%") % target[X] % target[Y]).str();
|
||||||
if (has_z)
|
if (has_z)
|
||||||
ret += (boost::format(" Z%1%") % target[Z]).str();
|
ret += (boost::format(" Z%1%") % target[Z]).str();
|
||||||
|
@ -2969,7 +2973,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
||||||
arc_target[Z] += z_per_segment;
|
arc_target[Z] += z_per_segment;
|
||||||
arc_target[E] += extruder_per_segment;
|
arc_target[E] += extruder_per_segment;
|
||||||
|
|
||||||
gcode += fake_g1_line(adjust_target(arc_target, prev_target), z_per_segment != 0.0, feedrate, extrusion);
|
gcode += internal_only_g1_line(adjust_target(arc_target, prev_target), z_per_segment != 0.0, feedrate, extrusion);
|
||||||
prev_target = arc_target;
|
prev_target = arc_target;
|
||||||
|
|
||||||
// feedrate is constant, we do not need to repeat it
|
// feedrate is constant, we do not need to repeat it
|
||||||
|
@ -2977,7 +2981,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure last segment arrives at target location.
|
// Ensure last segment arrives at target location.
|
||||||
gcode += fake_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, feedrate, extrusion);
|
gcode += internal_only_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, feedrate, extrusion);
|
||||||
|
|
||||||
// process fake gcode lines
|
// process fake gcode lines
|
||||||
GCodeReader parser;
|
GCodeReader parser;
|
||||||
|
@ -3489,7 +3493,11 @@ void GCodeProcessor::process_T(const std::string_view command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
void GCodeProcessor::store_move_vertex(EMoveType type, bool internal_only)
|
||||||
|
#else
|
||||||
void GCodeProcessor::store_move_vertex(EMoveType type)
|
void GCodeProcessor::store_move_vertex(EMoveType type)
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
{
|
{
|
||||||
m_last_line_id = (type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ?
|
m_last_line_id = (type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ?
|
||||||
m_line_id + 1 :
|
m_line_id + 1 :
|
||||||
|
@ -3509,7 +3517,12 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
|
||||||
m_mm3_per_mm,
|
m_mm3_per_mm,
|
||||||
m_fan_speed,
|
m_fan_speed,
|
||||||
m_extruder_temps[m_extruder_id],
|
m_extruder_temps[m_extruder_id],
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
static_cast<float>(m_result.moves.size()),
|
||||||
|
internal_only
|
||||||
|
#else
|
||||||
static_cast<float>(m_result.moves.size())
|
static_cast<float>(m_result.moves.size())
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
});
|
});
|
||||||
|
|
||||||
// stores stop time placeholders for later use
|
// stores stop time placeholders for later use
|
||||||
|
|
|
@ -113,6 +113,9 @@ namespace Slic3r {
|
||||||
float fan_speed{ 0.0f }; // percentage
|
float fan_speed{ 0.0f }; // percentage
|
||||||
float temperature{ 0.0f }; // Celsius degrees
|
float temperature{ 0.0f }; // Celsius degrees
|
||||||
float time{ 0.0f }; // s
|
float time{ 0.0f }; // s
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
bool internal_only{ false };
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
|
||||||
float volumetric_rate() const { return feedrate * mm3_per_mm; }
|
float volumetric_rate() const { return feedrate * mm3_per_mm; }
|
||||||
};
|
};
|
||||||
|
@ -751,7 +754,11 @@ namespace Slic3r {
|
||||||
void process_T(const GCodeReader::GCodeLine& line);
|
void process_T(const GCodeReader::GCodeLine& line);
|
||||||
void process_T(const std::string_view command);
|
void process_T(const std::string_view command);
|
||||||
|
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
void store_move_vertex(EMoveType type, bool internal_only = false);
|
||||||
|
#else
|
||||||
void store_move_vertex(EMoveType type);
|
void store_move_vertex(EMoveType type);
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
|
||||||
void set_extrusion_role(ExtrusionRole role);
|
void set_extrusion_role(ExtrusionRole role);
|
||||||
|
|
||||||
|
|
|
@ -2284,13 +2284,19 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
|
||||||
size_t move_id = i - seams_count;
|
size_t move_id = i - seams_count;
|
||||||
|
|
||||||
if (move.type == EMoveType::Extrude) {
|
if (move.type == EMoveType::Extrude) {
|
||||||
// layers zs
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back();
|
if (move.extrusion_role != erNone && !move.internal_only) {
|
||||||
const double z = static_cast<double>(move.position.z());
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z)
|
// layers zs
|
||||||
m_layers.append(z, { last_travel_s_id, move_id });
|
const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back();
|
||||||
else
|
const double z = static_cast<double>(move.position.z());
|
||||||
m_layers.get_ranges().back().last = move_id;
|
if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z)
|
||||||
|
m_layers.append(z, { last_travel_s_id, move_id });
|
||||||
|
else
|
||||||
|
m_layers.get_ranges().back().last = move_id;
|
||||||
|
#if ENABLE_PROCESS_G2_G3_LINES
|
||||||
|
}
|
||||||
|
#endif // ENABLE_PROCESS_G2_G3_LINES
|
||||||
// extruder ids
|
// extruder ids
|
||||||
m_extruder_ids.emplace_back(move.extruder_id);
|
m_extruder_ids.emplace_back(move.extruder_id);
|
||||||
// roles
|
// roles
|
||||||
|
|
Loading…
Add table
Reference in a new issue