mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-29 16:36:01 -05:00
97 lines
5.0 KiB
C++
97 lines
5.0 KiB
C++
#ifndef slic3r_CoolingBuffer_hpp_
|
|
#define slic3r_CoolingBuffer_hpp_
|
|
|
|
#include "../Point.hpp"
|
|
#include "../PrintConfig.hpp"
|
|
#include "GCodeProcessor.hpp"
|
|
#include <cstddef>
|
|
#include <map>
|
|
#include <string>
|
|
#include <cfloat>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace Slic3r {
|
|
|
|
class GCode;
|
|
class Layer;
|
|
struct PerExtruderAdjustments;
|
|
|
|
// A standalone G-code filter, to control cooling of the print.
|
|
// The G-code is processed per layer. Once a layer is collected, fan start / stop commands are edited
|
|
// and the print is modified to stretch over a minimum layer time.
|
|
//
|
|
// The simple it sounds, the actual implementation is significantly more complex.
|
|
// Namely, for a multi-extruder print, each material may require a different cooling logic.
|
|
// For example, some materials may not like to print too slowly, while with some materials
|
|
// we may slow down significantly.
|
|
//
|
|
class CoolingBuffer {
|
|
public:
|
|
CoolingBuffer(GCode &gcodegen);
|
|
void reset(const Vec3d &position);
|
|
void set_current_extruder(unsigned int extruder_id, unsigned int nozzle_id) { m_current_extruder = extruder_id; m_current_nozzle = nozzle_id; }
|
|
std::string process_layer(std::string &&gcode, size_t layer_id, bool flush);
|
|
// ORCA: Remembers the motion limits that G-code outside the layers sets, such as the start G-code, to time the layers.
|
|
void remember_motion_settings(const std::string &gcode);
|
|
|
|
private:
|
|
CoolingBuffer& operator=(const CoolingBuffer&) = delete;
|
|
std::vector<PerExtruderAdjustments> parse_layer_gcode(const std::string &gcode, std::vector<float> ¤t_pos);
|
|
// The slowdown aims at time_scale times each minimum layer time, in the time at the feed rates.
|
|
float calculate_layer_slowdown(std::vector<PerExtruderAdjustments> &per_extruder_adjustments, float time_scale);
|
|
// ORCA: Slows the layer down to the minimum layer time as the time estimate gives it, and returns that time.
|
|
float slow_down_layer(const std::string &gcode, std::vector<PerExtruderAdjustments> &per_extruder_adjustments);
|
|
// ORCA: The time of the layer's timed part, with acceleration, as the preview estimates it.
|
|
float estimate_layer_time(const std::string &gcode, const std::vector<PerExtruderAdjustments> &per_extruder_adjustments);
|
|
void remember_motion_setting(const std::string &line);
|
|
// ORCA: The G-code that puts the layer timer in the machine state with this extruder at this position.
|
|
std::string timer_setup(unsigned int extruder, const std::vector<float> &position) const;
|
|
// Apply slow down over G-code lines stored in per_extruder_adjustments, enable fan if needed.
|
|
// Returns the adjusted G-code.
|
|
std::string apply_layer_cooldown(const std::string &gcode, size_t layer_id, float layer_time, std::vector<PerExtruderAdjustments> &per_extruder_adjustments);
|
|
|
|
// G-code snippet cached for the support layers preceding an object layer.
|
|
std::string m_gcode;
|
|
// Internal data.
|
|
// BBS: X,Y,Z,E,F,I,J
|
|
std::vector<char> m_axis;
|
|
std::vector<float> m_current_pos;
|
|
// Current known fan speed or -1 if not known yet.
|
|
int m_fan_speed;
|
|
int m_additional_fan_speed;
|
|
// Cached from GCodeWriter.
|
|
// Printing extruder IDs, zero based.
|
|
std::vector<unsigned int> m_extruder_ids;
|
|
// Highest of m_extruder_ids plus 1.
|
|
unsigned int m_num_extruders { 0 };
|
|
const std::string m_toolchange_prefix;
|
|
// Referencs GCode::m_config, which is FullPrintConfig. While the PrintObjectConfig slice of FullPrintConfig is being modified,
|
|
// the PrintConfig slice of FullPrintConfig is constant, thus no thread synchronization is required.
|
|
const PrintConfig &m_config;
|
|
// Resolves the filament config index of the per-variant options.
|
|
const GCode &m_gcodegen;
|
|
unsigned int m_current_extruder;
|
|
unsigned int m_current_nozzle;
|
|
//BBS: current fan speed
|
|
int m_current_fan_speed;
|
|
// Belt printers: the extrusion being processed lies in the first-layer band above the
|
|
// belt (between a ";_BELT_BAND_START" and a ";_BELT_BAND_END"). Kept across layers.
|
|
bool m_belt_band_active = false;
|
|
|
|
// ORCA: Times the layers. Its config leaves out filament changes, which the layer time does not count.
|
|
GCodeProcessor m_layer_timer;
|
|
PrintConfig m_layer_timer_config;
|
|
// The last line of each kind that sets an acceleration or another motion limit, and its order.
|
|
std::map<std::string, std::pair<size_t, std::string>> m_motion_settings;
|
|
size_t m_motion_settings_count { 0 };
|
|
// Where the layer's timed part starts in its G-code, and the G-code that sets the timer up for it. The whole layer is
|
|
// timed, unless a filament change comes before its first extrusion: then it is timed from that extrusion.
|
|
size_t m_timed_from { std::string::npos };
|
|
std::string m_timer_setup;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|