Further refactoring of the cooling logic to collect per extruder data.
This commit is contained in:
bubnikv 2017-06-23 10:13:09 +02:00
parent 39b9341359
commit 32fa84c5a5
9 changed files with 123 additions and 132 deletions

View file

@ -7,10 +7,45 @@
namespace Slic3r {
struct ElapsedTime;
class GCode;
class Layer;
struct ElapsedTime
{
ElapsedTime(unsigned int extruder_id = 0) : extruder_id(extruder_id) { this->reset(); }
void reset() { total = bridges = external_perimeters = travel = other = 0.f; }
ElapsedTime& operator+=(const ElapsedTime &rhs) {
this->total += rhs.total;
this->bridges += rhs.bridges;
this->external_perimeters += rhs.external_perimeters;
this->travel += rhs.travel;
this->other += rhs.other;
return *this;
}
// Potion of the total time, which cannot be stretched to heed the minimum layer print time.
float non_stretchable() const { return this->bridges + this->travel + this->other; }
// Potion of the total time, which could be stretched to heed the minimum layer print time.
float stretchable() const { return this->total - this->non_stretchable(); }
// For which extruder ID has this statistics been collected?
unsigned int extruder_id;
// Total time.
float total;
// Per feature time slices.
float bridges;
float external_perimeters;
float travel;
float other;
};
// Sort ElapsedTime objects by the extruder id by default.
inline bool operator==(const ElapsedTime &e1, const ElapsedTime &e2) { return e1.extruder_id == e2.extruder_id; }
inline bool operator!=(const ElapsedTime &e1, const ElapsedTime &e2) { return e1.extruder_id != e2.extruder_id; }
inline bool operator< (const ElapsedTime &e1, const ElapsedTime &e2) { return e1.extruder_id < e2.extruder_id; }
inline bool operator> (const ElapsedTime &e1, const ElapsedTime &e2) { return e1.extruder_id > e2.extruder_id; }
/*
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
@ -19,19 +54,17 @@ and the print is modified to stretch over a minimum layer time.
class CoolingBuffer {
public:
CoolingBuffer(GCode &gcodegen);
~CoolingBuffer();
std::string append(const std::string &gcode, size_t object_id, size_t layer_id, bool is_support);
std::string flush();
GCode* gcodegen() { return &m_gcodegen; };
CoolingBuffer(GCode &gcodegen) : m_gcodegen(gcodegen) {}
void set_current_extruder(unsigned int extruder_id) { m_current_extruder = extruder_id; }
std::string process_layer(const std::string &gcode, size_t layer_id);
GCode* gcodegen() { return &m_gcodegen; }
private:
CoolingBuffer& operator=(const CoolingBuffer&);
GCode& m_gcodegen;
std::string m_gcode;
ElapsedTime *m_elapsed_time;
size_t m_layer_id;
unsigned int m_current_extruder;
std::set<size_t> m_object_ids_visited;
};