GCodeProcessor -> Load config data from gcode files generated by PrusaSlicer
This commit is contained in:
parent
11cf9a87f1
commit
16e282110d
4 changed files with 52 additions and 5 deletions
|
@ -346,6 +346,18 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
|
||||||
|
{
|
||||||
|
m_parser.apply_config(config);
|
||||||
|
|
||||||
|
const ConfigOptionFloats* filament_diameters = config.option<ConfigOptionFloats>("filament_diameter");
|
||||||
|
if (filament_diameters != nullptr) {
|
||||||
|
for (double diam : filament_diameters->values) {
|
||||||
|
m_filament_diameters.push_back(static_cast<float>(diam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeProcessor::enable_stealth_time_estimator(bool enabled)
|
void GCodeProcessor::enable_stealth_time_estimator(bool enabled)
|
||||||
{
|
{
|
||||||
m_time_processor.machines[static_cast<size_t>(ETimeMode::Stealth)].enabled = enabled;
|
m_time_processor.machines[static_cast<size_t>(ETimeMode::Stealth)].enabled = enabled;
|
||||||
|
@ -391,6 +403,28 @@ void GCodeProcessor::process_file(const std::string& filename)
|
||||||
auto start_time = std::chrono::high_resolution_clock::now();
|
auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
||||||
|
// pre-processing
|
||||||
|
// parse the gcode file to detect its producer
|
||||||
|
if (m_producers_enabled) {
|
||||||
|
m_parser.parse_file(filename, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
|
||||||
|
std::string cmd = line.cmd();
|
||||||
|
if (cmd.length() == 0) {
|
||||||
|
std::string comment = line.comment();
|
||||||
|
if (comment.length() > 1 && detect_producer(comment))
|
||||||
|
m_parser.quit_parsing_file();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// if the gcode was produced by PrusaSlicer,
|
||||||
|
// extract the config from it
|
||||||
|
if (m_producer == EProducer::PrusaSlicer) {
|
||||||
|
DynamicPrintConfig config;
|
||||||
|
config.apply(FullPrintConfig::defaults());
|
||||||
|
config.load_from_gcode_file(filename);
|
||||||
|
apply_config(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_result.id = ++s_result_id;
|
m_result.id = ++s_result_id;
|
||||||
m_result.moves.emplace_back(MoveVertex());
|
m_result.moves.emplace_back(MoveVertex());
|
||||||
m_parser.parse_file(filename, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { process_gcode_line(line); });
|
m_parser.parse_file(filename, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { process_gcode_line(line); });
|
||||||
|
@ -554,12 +588,13 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line)
|
||||||
|
|
||||||
void GCodeProcessor::process_tags(const std::string& comment)
|
void GCodeProcessor::process_tags(const std::string& comment)
|
||||||
{
|
{
|
||||||
if (m_producers_enabled && m_producer == EProducer::Unknown && detect_producer(comment))
|
// producers tags
|
||||||
return;
|
if (m_producers_enabled) {
|
||||||
else if (m_producers_enabled && m_producer != EProducer::Unknown) {
|
if (m_producer != EProducer::Unknown) {
|
||||||
if (process_producers_tags(comment))
|
if (process_producers_tags(comment))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// extrusion role tag
|
// extrusion role tag
|
||||||
size_t pos = comment.find(Extrusion_Role_Tag);
|
size_t pos = comment.find(Extrusion_Role_Tag);
|
||||||
|
|
|
@ -266,6 +266,7 @@ namespace Slic3r {
|
||||||
GCodeProcessor() { reset(); }
|
GCodeProcessor() { reset(); }
|
||||||
|
|
||||||
void apply_config(const PrintConfig& config);
|
void apply_config(const PrintConfig& config);
|
||||||
|
void apply_config(const DynamicPrintConfig& config);
|
||||||
void enable_stealth_time_estimator(bool enabled);
|
void enable_stealth_time_estimator(bool enabled);
|
||||||
void enable_producers(bool enabled) { m_producers_enabled = enabled; }
|
void enable_producers(bool enabled) { m_producers_enabled = enabled; }
|
||||||
void reset();
|
void reset();
|
||||||
|
|
|
@ -115,7 +115,12 @@ void GCodeReader::parse_file(const std::string &file, callback_t callback)
|
||||||
{
|
{
|
||||||
std::ifstream f(file);
|
std::ifstream f(file);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
m_parsing_file = true;
|
||||||
|
while (m_parsing_file && std::getline(f, line))
|
||||||
|
#else
|
||||||
while (std::getline(f, line))
|
while (std::getline(f, line))
|
||||||
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
this->parse_line(line, callback);
|
this->parse_line(line, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,9 @@ public:
|
||||||
{ GCodeLine gline; this->parse_line(line.c_str(), gline, callback); }
|
{ GCodeLine gline; this->parse_line(line.c_str(), gline, callback); }
|
||||||
|
|
||||||
void parse_file(const std::string &file, callback_t callback);
|
void parse_file(const std::string &file, callback_t callback);
|
||||||
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
void quit_parsing_file() { m_parsing_file = false; }
|
||||||
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
|
|
||||||
float& x() { return m_position[X]; }
|
float& x() { return m_position[X]; }
|
||||||
float x() const { return m_position[X]; }
|
float x() const { return m_position[X]; }
|
||||||
|
@ -145,6 +148,9 @@ private:
|
||||||
char m_extrusion_axis;
|
char m_extrusion_axis;
|
||||||
float m_position[NUM_AXES];
|
float m_position[NUM_AXES];
|
||||||
bool m_verbose;
|
bool m_verbose;
|
||||||
|
#if ENABLE_GCODE_VIEWER
|
||||||
|
bool m_parsing_file{ false };
|
||||||
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace Slic3r */
|
} /* namespace Slic3r */
|
||||||
|
|
Loading…
Reference in a new issue