diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index e6ccdc6429..c7fe287dc4 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -906,6 +906,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu return; BOOST_LOG_TRIVIAL(info) << boost::format("Will export G-code to %1% soon")%path; + GCodeProcessor::s_IsBBLPrinter = print->is_BBL_printer(); print->set_started(psGCodeExport); if (print->is_BBL_printer()) @@ -913,7 +914,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu else gcode_label_objects = true; - GCodeProcessor::s_IsBBLPrinter = print->is_BBL_printer(); // check if any custom gcode contains keywords used by the gcode processor to // produce time estimation and gcode toolpaths diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 6338d45a2c..9897205cd0 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -14,6 +14,7 @@ #include #include +#include #if __has_include() #include @@ -910,7 +911,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_result.filament_vitrification_temperature[i] = static_cast(config.temperature_vitrification.get_at(i)); } - if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) { + if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfKlipper) { m_time_processor.machine_limits = reinterpret_cast(config); if (m_flavor == gcfMarlinLegacy) { // Legacy Marlin does not have separate travel acceleration, it uses the 'extruding' value instead. @@ -1086,7 +1087,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) if (machine_unload_filament_time != nullptr) m_time_processor.filament_unload_times = static_cast(machine_unload_filament_time->value); - if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) { + if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfKlipper) { const ConfigOptionFloats* machine_max_acceleration_x = config.option("machine_max_acceleration_x"); if (machine_max_acceleration_x != nullptr) m_time_processor.machine_limits.machine_max_acceleration_x.values = machine_max_acceleration_x->values; @@ -1598,6 +1599,15 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool m_start_position = m_end_position; const std::string_view cmd = line.cmd(); + if (m_flavor == gcfKlipper) + { + if (boost::iequals(cmd, "SET_VELOCITY_LIMIT")) + { + process_SET_VELOCITY_LIMIT(line); + return; + } + } + if (cmd.length() > 1) { // process command lines switch (cmd[0]) @@ -3524,7 +3534,7 @@ void GCodeProcessor::process_M203(const GCodeReader::GCodeLine& line) // see http://reprap.org/wiki/G-code#M203:_Set_maximum_feedrate // http://smoothieware.org/supported-g-codes - float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; + float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfSmoothie || m_flavor == gcfKlipper) ? 1.0f : MMMIN_TO_MMSEC; for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { if (static_cast(i) == PrintEstimatedStatistics::ETimeMode::Normal || @@ -3603,6 +3613,54 @@ void GCodeProcessor::process_M205(const GCodeReader::GCodeLine& line) } } +void GCodeProcessor::process_SET_VELOCITY_LIMIT(const GCodeReader::GCodeLine& line) +{ + // handle SQUARE_CORNER_VELOCITY + std::regex pattern("\\sSQUARE_CORNER_VELOCITY\\s*=\\s*([0-9]*\\.*[0-9]*)"); + std::smatch matches; + if (std::regex_search(line.raw(), matches, pattern) && matches.size() == 2) { + float _jerk = 0; + try + { + _jerk = std::stof(matches[1]); + } + catch (...){} + for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { + set_option_value(m_time_processor.machine_limits.machine_max_jerk_x, i, _jerk); + set_option_value(m_time_processor.machine_limits.machine_max_jerk_y, i, _jerk); + } + } + + pattern = std::regex("\\sACCEL\\s*=\\s*([0-9]*\\.*[0-9]*)"); + if (std::regex_search(line.raw(), matches, pattern) && matches.size() == 2) { + float _accl = 0; + try + { + _accl = std::stof(matches[1]); + } + catch (...) {} + for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { + set_acceleration(static_cast(i), _accl); + set_travel_acceleration(static_cast(i), _accl); + } + } + + pattern = std::regex("\\sVELOCITY\\s*=\\s*([0-9]*\\.*[0-9]*)"); + if (std::regex_search(line.raw(), matches, pattern) && matches.size() == 2) { + float _speed = 0; + try + { + _speed = std::stof(matches[1]); + } + catch (...) {} + for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { + set_option_value(m_time_processor.machine_limits.machine_max_speed_x, i, _speed); + set_option_value(m_time_processor.machine_limits.machine_max_speed_y, i, _speed); + } + } + +} + void GCodeProcessor::process_M221(const GCodeReader::GCodeLine& line) { float value_s; diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index f677c0970c..8124c5e157 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -794,6 +794,9 @@ namespace Slic3r { // Advanced settings void process_M205(const GCodeReader::GCodeLine& line); + // Klipper SET_VELOCITY_LIMIT + void process_SET_VELOCITY_LIMIT(const GCodeReader::GCodeLine& line); + // Set extrude factor override percentage void process_M221(const GCodeReader::GCodeLine& line);