GCodeProcessor additions:
process color change comment tag process pause print comment tag process custom code comment tag process end pause print or custom code comment tag
This commit is contained in:
parent
1caac17b02
commit
57dad5dfd2
4 changed files with 130 additions and 17 deletions
|
@ -1823,7 +1823,11 @@ namespace ProcessLayer
|
|||
// Color Change or Tool Change as Color Change.
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
|
||||
// add tag for time estimator
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
// add tag for processor
|
||||
gcode += "; " + GCodeProcessor::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
// add tag for time estimator
|
||||
gcode += "; " + GCodeTimeEstimator::Color_Change_Tag + "\n";
|
||||
|
||||
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != (unsigned)m600_extruder_before_layer
|
||||
|
@ -1844,7 +1848,11 @@ namespace ProcessLayer
|
|||
{
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Pause_Print_Tag + "\n";
|
||||
//! FIXME_in_fw show message during print pause
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
// add tag for processor
|
||||
gcode += "; " + GCodeProcessor::Pause_Print_Tag + "\n";
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
//! FIXME_in_fw show message during print pause
|
||||
if (!pause_print_msg.empty())
|
||||
gcode += "M117 " + pause_print_msg + "\n";
|
||||
// add tag for time estimator
|
||||
|
@ -1854,7 +1862,11 @@ namespace ProcessLayer
|
|||
{
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Custom_Code_Tag + "\n";
|
||||
// add tag for time estimator
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
// add tag for processor
|
||||
gcode += "; " + GCodeProcessor::Custom_Code_Tag + "\n";
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
// add tag for time estimator
|
||||
//gcode += "; " + GCodeTimeEstimator::Custom_Code_Tag + "\n";
|
||||
}
|
||||
gcode += custom_code + "\n";
|
||||
|
@ -2316,6 +2328,14 @@ void GCode::process_layer(
|
|||
else if (gcode.find(GCodeAnalyzer::Custom_Code_Tag) != gcode.npos)
|
||||
gcode += "\n; " + GCodeAnalyzer::End_Pause_Print_Or_Custom_Code_Tag + "\n";
|
||||
|
||||
#if ENABLE_GCODE_VIEWER
|
||||
// add tag for processor
|
||||
if (gcode.find(GCodeProcessor::Pause_Print_Tag) != gcode.npos)
|
||||
gcode += "\n; " + GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag + "\n";
|
||||
else if (gcode.find(GCodeProcessor::Custom_Code_Tag) != gcode.npos)
|
||||
gcode += "\n; " + GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag + "\n";
|
||||
#endif // ENABLE_GCODE_VIEWER
|
||||
|
||||
#ifdef HAS_PRESSURE_EQUALIZER
|
||||
// Apply pressure equalization if enabled;
|
||||
// printf("G-code before filter:\n%s\n", gcode.c_str());
|
||||
|
|
|
@ -674,7 +674,7 @@ bool GCodeAnalyzer::_process_tags(const GCodeReader::GCodeLine& line)
|
|||
return true;
|
||||
}
|
||||
|
||||
// color change tag
|
||||
// pause print tag
|
||||
pos = comment.find(Pause_Print_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
|
@ -682,7 +682,7 @@ bool GCodeAnalyzer::_process_tags(const GCodeReader::GCodeLine& line)
|
|||
return true;
|
||||
}
|
||||
|
||||
// color change tag
|
||||
// custom code tag
|
||||
pos = comment.find(Custom_Code_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
|
@ -690,7 +690,7 @@ bool GCodeAnalyzer::_process_tags(const GCodeReader::GCodeLine& line)
|
|||
return true;
|
||||
}
|
||||
|
||||
// color change tag
|
||||
// end pause print or custom code tag
|
||||
pos = comment.find(End_Pause_Print_Or_Custom_Code_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
|
@ -949,10 +949,11 @@ void GCodeAnalyzer::_store_move(GCodeAnalyzer::GCodeMove::EType type)
|
|||
#if ENABLE_GCODE_VIEWER_DEBUG_OUTPUT
|
||||
if (g_debug_output.good())
|
||||
{
|
||||
g_debug_output << std::to_string((int)type);
|
||||
g_debug_output << ", " << std::to_string((int)_get_extrusion_role());
|
||||
g_debug_output << ", " << Slic3r::to_string((Vec3d)end_position.cast<double>());
|
||||
g_debug_output << std::to_string(static_cast<int>(type));
|
||||
g_debug_output << ", " << std::to_string(static_cast<int>(_get_extrusion_role()));
|
||||
g_debug_output << ", " << Slic3r::to_string(static_cast<Vec3d>(end_position.cast<double>()));
|
||||
g_debug_output << ", " << std::to_string(extruder_id);
|
||||
g_debug_output << ", " << std::to_string(_get_cp_color_id());
|
||||
g_debug_output << ", " << std::to_string(_get_feedrate());
|
||||
g_debug_output << ", " << std::to_string(_get_width());
|
||||
g_debug_output << ", " << std::to_string(_get_height());
|
||||
|
|
|
@ -19,6 +19,22 @@ const std::string GCodeProcessor::Extrusion_Role_Tag = "_PROCESSOR_EXTRUSION_ROL
|
|||
const std::string GCodeProcessor::Width_Tag = "_PROCESSOR_WIDTH:";
|
||||
const std::string GCodeProcessor::Height_Tag = "_PROCESSOR_HEIGHT:";
|
||||
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "_PROCESSOR_MM3_PER_MM:";
|
||||
const std::string GCodeProcessor::Color_Change_Tag = "_PROCESSOR_COLOR_CHANGE";
|
||||
const std::string GCodeProcessor::Pause_Print_Tag = "_PROCESSOR_PAUSE_PRINT";
|
||||
const std::string GCodeProcessor::Custom_Code_Tag = "_PROCESSOR_CUSTOM_CODE";
|
||||
const std::string GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag = "_PROCESSOR_END_PAUSE_PRINT_OR_CUSTOM_CODE";
|
||||
|
||||
void GCodeProcessor::CachedPosition::reset()
|
||||
{
|
||||
std::fill(position.begin(), position.end(), FLT_MAX);
|
||||
feedrate = FLT_MAX;
|
||||
}
|
||||
|
||||
void GCodeProcessor::CpColor::reset()
|
||||
{
|
||||
counter = 0;
|
||||
current = 0;
|
||||
}
|
||||
|
||||
void GCodeProcessor::apply_config(const PrintConfig& config)
|
||||
{
|
||||
|
@ -27,14 +43,19 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
|
|||
m_flavor = config.gcode_flavor;
|
||||
|
||||
size_t extruders_count = config.nozzle_diameter.values.size();
|
||||
if (m_extruder_offsets.size() != extruders_count)
|
||||
m_extruder_offsets.resize(extruders_count);
|
||||
|
||||
m_extruder_offsets.resize(extruders_count);
|
||||
for (size_t id = 0; id < extruders_count; ++id)
|
||||
{
|
||||
Vec2f offset = config.extruder_offset.get_at(id).cast<float>();
|
||||
m_extruder_offsets[id] = Vec3f(offset(0), offset(1), 0.0f);
|
||||
}
|
||||
|
||||
m_extruders_color.resize(extruders_count);
|
||||
for (size_t id = 0; id < extruders_count; ++id)
|
||||
{
|
||||
m_extruders_color[id] = static_cast<unsigned int>(id);
|
||||
}
|
||||
}
|
||||
|
||||
void GCodeProcessor::reset()
|
||||
|
@ -48,8 +69,7 @@ void GCodeProcessor::reset()
|
|||
std::fill(m_start_position.begin(), m_start_position.end(), 0.0f);
|
||||
std::fill(m_end_position.begin(), m_end_position.end(), 0.0f);
|
||||
std::fill(m_origin.begin(), m_origin.end(), 0.0f);
|
||||
std::fill(m_cached_position.position.begin(), m_cached_position.position.end(), FLT_MAX);
|
||||
m_cached_position.feedrate = FLT_MAX;
|
||||
m_cached_position.reset();
|
||||
|
||||
m_feedrate = 0.0f;
|
||||
m_width = 0.0f;
|
||||
|
@ -59,6 +79,8 @@ void GCodeProcessor::reset()
|
|||
|
||||
m_extrusion_role = erNone;
|
||||
m_extruder_id = 0;
|
||||
m_extruders_color = ExtrudersColor();
|
||||
m_cp_color.reset();
|
||||
|
||||
m_result.reset();
|
||||
}
|
||||
|
@ -202,6 +224,55 @@ void GCodeProcessor::process_tags(const std::string& comment)
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// color change tag
|
||||
pos = comment.find(Color_Change_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
pos = comment.find_last_of(",T");
|
||||
try
|
||||
{
|
||||
unsigned int extruder_id = (pos == comment.npos) ? 0 : static_cast<unsigned int>(std::stoi(comment.substr(pos + 1, comment.npos)));
|
||||
|
||||
m_extruders_color[extruder_id] = static_cast<unsigned int>(m_extruder_offsets.size()) + m_cp_color.counter; // color_change position in list of color for preview
|
||||
++m_cp_color.counter;
|
||||
|
||||
if (m_extruder_id == extruder_id)
|
||||
m_cp_color.current = m_extruders_color[extruder_id];
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Color_Change (" << comment << ").";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// pause print tag
|
||||
pos = comment.find(Pause_Print_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
m_cp_color.current = INT_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
// custom code tag
|
||||
pos = comment.find(Custom_Code_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
m_cp_color.current = INT_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
// end pause print or custom code tag
|
||||
pos = comment.find(End_Pause_Print_Or_Custom_Code_Tag);
|
||||
if (pos != comment.npos)
|
||||
{
|
||||
if (m_cp_color.current == INT_MAX)
|
||||
m_cp_color.current = m_extruders_color[m_extruder_id];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
|
||||
|
@ -485,17 +556,17 @@ void GCodeProcessor::process_T(const std::string& command)
|
|||
{
|
||||
try
|
||||
{
|
||||
unsigned int id = (unsigned int)std::stoi(command.substr(1));
|
||||
unsigned int id = static_cast<unsigned int>(std::stoi(command.substr(1)));
|
||||
if (m_extruder_id != id)
|
||||
{
|
||||
unsigned int extruders_count = (unsigned int)m_extruder_offsets.size();
|
||||
unsigned int extruders_count = static_cast<unsigned int>(m_extruder_offsets.size());
|
||||
if (id >= extruders_count)
|
||||
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid toolchange, maybe from a custom gcode.";
|
||||
else
|
||||
{
|
||||
m_extruder_id = id;
|
||||
// if (_get_cp_color_id() != INT_MAX) <<<<<<<<<<<<<<<<<<< TODO
|
||||
// _set_cp_color_id(m_extruder_color[id]);
|
||||
if (m_cp_color.current != INT_MAX)
|
||||
m_cp_color.current = m_extruders_color[id];
|
||||
}
|
||||
|
||||
// store tool change move
|
||||
|
@ -521,6 +592,7 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
|
|||
vertex.mm3_per_mm = m_mm3_per_mm;
|
||||
vertex.fan_speed = m_fan_speed;
|
||||
vertex.extruder_id = m_extruder_id;
|
||||
vertex.cp_color_id = m_cp_color.current;
|
||||
m_result.moves.emplace_back(vertex);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../ExtrusionEntity.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -17,9 +18,14 @@ namespace Slic3r {
|
|||
static const std::string Width_Tag;
|
||||
static const std::string Height_Tag;
|
||||
static const std::string Mm3_Per_Mm_Tag;
|
||||
static const std::string Color_Change_Tag;
|
||||
static const std::string Pause_Print_Tag;
|
||||
static const std::string Custom_Code_Tag;
|
||||
static const std::string End_Pause_Print_Or_Custom_Code_Tag;
|
||||
|
||||
private:
|
||||
using AxisCoords = std::array<float, 4>;
|
||||
using ExtrudersColor = std::vector<unsigned int>;
|
||||
|
||||
enum class EUnits : unsigned char
|
||||
{
|
||||
|
@ -48,6 +54,16 @@ namespace Slic3r {
|
|||
{
|
||||
AxisCoords position; // mm
|
||||
float feedrate; // mm/s
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
struct CpColor
|
||||
{
|
||||
unsigned int counter;
|
||||
unsigned int current;
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -62,6 +78,7 @@ namespace Slic3r {
|
|||
float mm3_per_mm{ 0.0f };
|
||||
float fan_speed{ 0.0f }; // percentage
|
||||
unsigned int extruder_id{ 0 };
|
||||
unsigned int cp_color_id{ 0 };
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
|
@ -69,6 +86,7 @@ namespace Slic3r {
|
|||
str += ", " + std::to_string((int)extrusion_role);
|
||||
str += ", " + Slic3r::to_string((Vec3d)position.cast<double>());
|
||||
str += ", " + std::to_string(extruder_id);
|
||||
str += ", " + std::to_string(cp_color_id);
|
||||
str += ", " + std::to_string(feedrate);
|
||||
str += ", " + std::to_string(width);
|
||||
str += ", " + std::to_string(height);
|
||||
|
@ -105,6 +123,8 @@ namespace Slic3r {
|
|||
float m_fan_speed; // percentage
|
||||
ExtrusionRole m_extrusion_role;
|
||||
unsigned int m_extruder_id;
|
||||
ExtrudersColor m_extruders_color;
|
||||
CpColor m_cp_color;
|
||||
|
||||
Result m_result;
|
||||
|
||||
|
|
Loading…
Reference in a new issue