mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 19:28:14 -06:00
Ported the G-code generator from Perl to C++.
Removed GCode.pm Removed the Perl bindigns for AvoidCrossingPerimeters, OozePrevention, SpiralVase, Wipe Changed the std::set of extruder IDs to vector of IDs. Removed some MSVC compiler warnings, removed obnoxious compiler warnings when compiling the Perl bindings.
This commit is contained in:
parent
72ae3585e4
commit
e90279c513
52 changed files with 1362 additions and 1632 deletions
|
@ -1,3 +1,4 @@
|
|||
#include "../GCode.hpp"
|
||||
#include "CoolingBuffer.hpp"
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
@ -5,28 +6,26 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
std::string
|
||||
CoolingBuffer::append(const std::string &gcode, std::string obj_id, size_t layer_id, float print_z)
|
||||
std::string CoolingBuffer::append(const std::string &gcode, size_t object_id, size_t layer_id, bool is_support)
|
||||
{
|
||||
std::string out;
|
||||
if (this->_last_z.find(obj_id) != this->_last_z.end()) {
|
||||
// A layer was finished, Z of the object's layer changed. Process the layer.
|
||||
size_t signature = object_id * 2 + is_support ? 1 : 0;
|
||||
if (m_object_ids_visited.find(signature) != m_object_ids_visited.end())
|
||||
// For a single print_z, a combination of (object_id, is_support) could repeat once only.
|
||||
// If the combination of (object_id, is_support) reappears, this must be for another print_z,
|
||||
// therefore a layer has to be finalized.
|
||||
out = this->flush();
|
||||
}
|
||||
|
||||
this->_layer_id = layer_id;
|
||||
this->_last_z[obj_id] = print_z;
|
||||
this->_gcode += gcode;
|
||||
|
||||
m_object_ids_visited.insert(signature);
|
||||
m_layer_id = layer_id;
|
||||
m_gcode += gcode;
|
||||
// This is a very rough estimate of the print time,
|
||||
// not taking into account the acceleration curves generated by the printer firmware.
|
||||
this->_elapsed_time += this->_gcodegen->elapsed_time;
|
||||
this->_gcodegen->elapsed_time = 0;
|
||||
|
||||
m_elapsed_time += m_gcodegen.get_reset_elapsed_time();
|
||||
return out;
|
||||
}
|
||||
|
||||
void
|
||||
apply_speed_factor(std::string &line, float speed_factor, float min_print_speed)
|
||||
void apply_speed_factor(std::string &line, float speed_factor, float min_print_speed)
|
||||
{
|
||||
// find pos of F
|
||||
size_t pos = line.find_first_of('F');
|
||||
|
@ -51,36 +50,34 @@ apply_speed_factor(std::string &line, float speed_factor, float min_print_speed)
|
|||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
CoolingBuffer::flush()
|
||||
std::string CoolingBuffer::flush()
|
||||
{
|
||||
GCode &gg = *this->_gcodegen;
|
||||
const FullPrintConfig &config = m_gcodegen.config();
|
||||
|
||||
std::string gcode = this->_gcode;
|
||||
float elapsed = this->_elapsed_time;
|
||||
this->_gcode = "";
|
||||
this->_elapsed_time = 0;
|
||||
this->_last_z.clear(); // reset the whole table otherwise we would compute overlapping times
|
||||
|
||||
int fan_speed = gg.config.fan_always_on ? gg.config.min_fan_speed.value : 0;
|
||||
std::string gcode = m_gcode;
|
||||
float elapsed = m_elapsed_time;
|
||||
m_gcode.clear();
|
||||
m_elapsed_time = 0.;
|
||||
|
||||
int fan_speed = config.fan_always_on ? config.min_fan_speed.value : 0;
|
||||
|
||||
float speed_factor = 1.0;
|
||||
|
||||
if (gg.config.cooling) {
|
||||
if (config.cooling) {
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Layer %zu estimated printing time: %f seconds\n", this->_layer_id, elapsed);
|
||||
printf("Layer %zu estimated printing time: %f seconds\n", m_layer_id, elapsed);
|
||||
#endif
|
||||
if (elapsed < (float)gg.config.slowdown_below_layer_time) {
|
||||
if (elapsed < (float)config.slowdown_below_layer_time) {
|
||||
// Layer time very short. Enable the fan to a full throttle and slow down the print
|
||||
// (stretch the layer print time to slowdown_below_layer_time).
|
||||
fan_speed = gg.config.max_fan_speed;
|
||||
speed_factor = elapsed / (float)gg.config.slowdown_below_layer_time;
|
||||
} else if (elapsed < (float)gg.config.fan_below_layer_time) {
|
||||
fan_speed = config.max_fan_speed;
|
||||
speed_factor = elapsed / (float)config.slowdown_below_layer_time;
|
||||
} else if (elapsed < (float)config.fan_below_layer_time) {
|
||||
// Layer time quite short. Enable the fan proportionally according to the current layer time.
|
||||
fan_speed = gg.config.max_fan_speed
|
||||
- (gg.config.max_fan_speed - gg.config.min_fan_speed)
|
||||
* (elapsed - (float)gg.config.slowdown_below_layer_time)
|
||||
/ (gg.config.fan_below_layer_time - gg.config.slowdown_below_layer_time);
|
||||
fan_speed = config.max_fan_speed
|
||||
- (config.max_fan_speed - config.min_fan_speed)
|
||||
* (elapsed - (float)config.slowdown_below_layer_time)
|
||||
/ (config.fan_below_layer_time - config.slowdown_below_layer_time);
|
||||
}
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
|
@ -94,13 +91,14 @@ CoolingBuffer::flush()
|
|||
std::string new_gcode;
|
||||
std::istringstream ss(gcode);
|
||||
std::string line;
|
||||
bool bridge_fan_start = false;
|
||||
bool bridge_fan_start = false;
|
||||
float min_print_speed = float(config.min_print_speed * 60.);
|
||||
while (std::getline(ss, line)) {
|
||||
if (boost::starts_with(line, "G1")
|
||||
&& boost::contains(line, ";_EXTRUDE_SET_SPEED")
|
||||
&& !boost::contains(line, ";_WIPE")
|
||||
&& !bridge_fan_start) {
|
||||
apply_speed_factor(line, speed_factor, this->_min_print_speed);
|
||||
apply_speed_factor(line, speed_factor, min_print_speed);
|
||||
boost::replace_first(line, ";_EXTRUDE_SET_SPEED", "");
|
||||
}
|
||||
bridge_fan_start = boost::contains(line, ";_BRIDGE_FAN_START");
|
||||
|
@ -109,22 +107,23 @@ CoolingBuffer::flush()
|
|||
gcode = new_gcode;
|
||||
}
|
||||
}
|
||||
if (this->_layer_id < gg.config.disable_fan_first_layers)
|
||||
if (m_layer_id < config.disable_fan_first_layers)
|
||||
fan_speed = 0;
|
||||
|
||||
gcode = gg.writer.set_fan(fan_speed) + gcode;
|
||||
gcode = m_gcodegen.writer().set_fan(fan_speed) + gcode;
|
||||
|
||||
// bridge fan speed
|
||||
if (!gg.config.cooling || gg.config.bridge_fan_speed == 0 || this->_layer_id < gg.config.disable_fan_first_layers) {
|
||||
if (!config.cooling || config.bridge_fan_speed == 0 || m_layer_id < config.disable_fan_first_layers) {
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_START", "");
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_END", "");
|
||||
} else {
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_START", gg.writer.set_fan(gg.config.bridge_fan_speed, true));
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_END", gg.writer.set_fan(fan_speed, true));
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_START", m_gcodegen.writer().set_fan(config.bridge_fan_speed, true));
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_END", m_gcodegen.writer().set_fan(fan_speed, true));
|
||||
}
|
||||
boost::replace_all(gcode, ";_WIPE", "");
|
||||
boost::replace_all(gcode, ";_EXTRUDE_SET_SPEED", "");
|
||||
|
||||
m_object_ids_visited.clear();
|
||||
return gcode;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue