mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 06:11:02 +00:00
Co-authored-by: Rodrigo Faselli <162915171+RF47@users.noreply.github.com>
99 lines
4.1 KiB
C++
99 lines
4.1 KiB
C++
// AdaptivePAProcessor.hpp
|
|
// OrcaSlicer
|
|
//
|
|
// Header file for the AdaptivePAProcessor class, responsible for processing G-code layers for the purposes of applying adaptive pressure advance.
|
|
|
|
#ifndef ADAPTIVEPAPROCESSOR_H
|
|
#define ADAPTIVEPAPROCESSOR_H
|
|
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <regex>
|
|
#include <memory>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
#include "AdaptivePAInterpolator.hpp"
|
|
|
|
namespace Slic3r {
|
|
|
|
// Forward declaration of GCode class
|
|
class GCode;
|
|
class PrintConfig;
|
|
|
|
/**
|
|
* @brief Class for processing G-code layers with adaptive pressure advance.
|
|
*/
|
|
class AdaptivePAProcessor {
|
|
public:
|
|
/**
|
|
* @brief Constructor for AdaptivePAProcessor.
|
|
*
|
|
* This constructor initializes the AdaptivePAProcessor with a reference to a GCode object.
|
|
* It also initializes the configuration reference, pressure advance interpolation object,
|
|
* and regular expression patterns used for processing the G-code.
|
|
*
|
|
* @param gcodegen A reference to the GCode object that generates the G-code.
|
|
*/
|
|
AdaptivePAProcessor(GCode &gcodegen);
|
|
|
|
/**
|
|
* @brief Processes a layer of G-code and applies adaptive pressure advance.
|
|
*
|
|
* This method processes the G-code for a single layer, identifying the appropriate
|
|
* pressure advance settings and applying them based on the current state and configurations.
|
|
*
|
|
* @param gcode A string containing the G-code for the layer.
|
|
* @return A string containing the processed G-code with adaptive pressure advance applied.
|
|
*/
|
|
std::string process_layer(std::string &&gcode);
|
|
|
|
/**
|
|
* @brief Manually sets adaptive PA internal value.
|
|
*
|
|
* This method manually sets the adaptive PA internally held value.
|
|
* Call this when changing tools or in any other case where the internally assumed last PA value may be incorrect
|
|
*/
|
|
void resetPreviousPA(double PA){ m_last_predicted_pa = PA; };
|
|
|
|
/**
|
|
* @brief Validates an adaptive pressure advance model string.
|
|
*
|
|
* Checks that:
|
|
* - Each non-empty line has exactly 3 comma-separated values (PA, flow, accel)
|
|
* - PA value is less than 2
|
|
* - Flow value is greater than PA value
|
|
* - Accel value is greater than flow value
|
|
*
|
|
* @param model_str The model string to validate (typically from config)
|
|
* @return Empty string if valid, or an error message describing the first issue found
|
|
*/
|
|
static std::string validate_adaptive_pa_model(const std::string& model_str);
|
|
|
|
private:
|
|
GCode &m_gcodegen; ///< Reference to the GCode object.
|
|
std::unordered_map<unsigned int, std::unique_ptr<AdaptivePAInterpolator>> m_AdaptivePAInterpolators; ///< Map between Interpolator objects and filament config indices (null when adaptive PA is off)
|
|
const PrintConfig &m_config; ///< Reference to the print configuration.
|
|
double m_last_predicted_pa; ///< Last predicted pressure advance value.
|
|
double m_max_next_feedrate; ///< Maximum feed rate (speed) for the upcomming island. If no speed is found, the previous island speed is used.
|
|
double m_next_feedrate; ///< First feed rate (speed) for the upcomming island.
|
|
double m_current_feedrate; ///< Current, latest feedrate.
|
|
int m_last_config_index; ///< Filament config index of the last PA_CHANGE tag.
|
|
bool m_enabled{false}; ///< Whether any filament config index has both PA and adaptive PA on, the only ones that emit PA_CHANGE tags.
|
|
|
|
std::regex m_pa_change_pattern; ///< Regular expression to detect PA_CHANGE pattern.
|
|
std::regex m_g1_f_pattern; ///< Regular expression to detect G1 F pattern.
|
|
std::smatch m_match; ///< Match results for regular expressions.
|
|
|
|
/**
|
|
* @brief Get the PA interpolator attached to the specified filament config index.
|
|
*
|
|
* @param config_index The filament config index (one per filament and extruder variant) for which the PA interpolation model is to be returned.
|
|
* @return The Adaptive PA Interpolator object corresponding to that index, or nullptr when adaptive PA is off for it.
|
|
*/
|
|
AdaptivePAInterpolator* getInterpolator(unsigned int config_index);
|
|
};
|
|
|
|
} // namespace Slic3r
|
|
|
|
#endif // ADAPTIVEPAPROCESSOR_H
|