diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 445a1f1866..2568982464 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -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 GCodeProcessor::get_layers_time(PrintEstimatedTimeStatistics: std::vector(); } +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; */ diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index b263c13e5f..96e2160205 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -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(PrintEstimatedTimeStatistics::ETimeMode::Stealth)].enabled; @@ -549,6 +548,8 @@ namespace Slic3r { std::vector 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