Extract bed size from gcode produced with Simplify3d

This commit is contained in:
enricoturri1966 2021-03-25 09:23:14 +01:00
parent 3a5360651d
commit 68303059a6
2 changed files with 57 additions and 1 deletions

View file

@ -1064,6 +1064,8 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr
config.load_from_gcode_file(filename, false);
apply_config(config);
}
else if (m_producer == EProducer::Simplify3D)
apply_config_simplify3d(filename);
}
// process gcode
@ -1182,6 +1184,59 @@ std::vector<float> GCodeProcessor::get_layers_time(PrintEstimatedTimeStatistics:
std::vector<float>();
}
void GCodeProcessor::apply_config_simplify3d(const std::string& filename)
{
struct BedSize
{
double x{ 0.0 };
double y{ 0.0 };
bool is_defined() const { return x > 0.0 && y > 0.0; }
};
BedSize bed_size;
m_parser.parse_file(filename, [this, &bed_size](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
auto extract_float = [](const std::string& cmt, const std::string& key, double& out) {
size_t pos = cmt.find(key);
if (pos != cmt.npos) {
pos = cmt.find(',', pos);
if (pos != cmt.npos) {
out = std::stod(cmt.substr(pos + 1));
return true;
}
}
return false;
};
const std::string& comment = line.raw();
if (comment.length() > 2 && comment.front() == ';') {
if (bed_size.x == 0.0)
extract_float(comment, "strokeXoverride", bed_size.x);
if (bed_size.y == 0.0)
extract_float(comment, "strokeYoverride", bed_size.y);
// check for early exit
if (bed_size.is_defined()) {
#if ENABLE_VALIDATE_CUSTOM_GCODE
m_parser.quit_parsing();
#else
m_parser.quit_parsing_file();
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
}
}
});
if (bed_size.is_defined()) {
m_result.bed_shape = {
{ 0.0, 0.0 },
{ bed_size.x, 0.0 },
{ bed_size.x, bed_size.y },
{ 0.0, bed_size.y }
};
}
}
void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line)
{
/* std::cout << line.raw() << std::endl; */

View file

@ -524,7 +524,6 @@ namespace Slic3r {
GCodeProcessor();
void apply_config(const PrintConfig& config);
void apply_config(const DynamicPrintConfig& config);
void enable_stealth_time_estimator(bool enabled);
bool is_stealth_time_estimator_enabled() const {
return m_time_processor.machines[static_cast<size_t>(PrintEstimatedTimeStatistics::ETimeMode::Stealth)].enabled;
@ -549,6 +548,8 @@ namespace Slic3r {
std::vector<float> get_layers_time(PrintEstimatedTimeStatistics::ETimeMode mode) const;
private:
void apply_config(const DynamicPrintConfig& config);
void apply_config_simplify3d(const std::string& filename);
void process_gcode_line(const GCodeReader::GCodeLine& line);
// Process tags embedded into comments