mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
GCodeTimeEstimator - simulate firmware st_synchronize() for commands G4, G92, M1
This commit is contained in:
parent
3f57e20235
commit
69e3ea6581
2 changed files with 1266 additions and 1230 deletions
|
@ -142,28 +142,36 @@ namespace Slic3r {
|
|||
|
||||
void GCodeTimeEstimator::calculate_time_from_text(const std::string& gcode)
|
||||
{
|
||||
reset();
|
||||
|
||||
_parser.parse_buffer(gcode,
|
||||
[this](GCodeReader &reader, const GCodeReader::GCodeLine &line)
|
||||
{ this->_process_gcode_line(reader, line); });
|
||||
_calculate_time();
|
||||
reset();
|
||||
|
||||
_reset();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::calculate_time_from_file(const std::string& file)
|
||||
{
|
||||
reset();
|
||||
|
||||
_parser.parse_file(file, boost::bind(&GCodeTimeEstimator::_process_gcode_line, this, _1, _2));
|
||||
_calculate_time();
|
||||
reset();
|
||||
|
||||
_reset();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::calculate_time_from_lines(const std::vector<std::string>& gcode_lines)
|
||||
{
|
||||
reset();
|
||||
|
||||
auto action = [this](GCodeReader &reader, const GCodeReader::GCodeLine &line)
|
||||
{ this->_process_gcode_line(reader, line); };
|
||||
for (const std::string& line : gcode_lines)
|
||||
_parser.parse_line(line, action);
|
||||
_calculate_time();
|
||||
reset();
|
||||
|
||||
_reset();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::add_gcode_line(const std::string& gcode_line)
|
||||
|
@ -362,7 +370,7 @@ namespace Slic3r {
|
|||
|
||||
void GCodeTimeEstimator::reset()
|
||||
{
|
||||
_blocks.clear();
|
||||
_time = 0.0f;
|
||||
_reset();
|
||||
}
|
||||
|
||||
|
@ -392,6 +400,8 @@ namespace Slic3r {
|
|||
|
||||
void GCodeTimeEstimator::_reset()
|
||||
{
|
||||
_blocks.clear();
|
||||
|
||||
_curr.reset();
|
||||
_prev.reset();
|
||||
|
||||
|
@ -408,7 +418,7 @@ namespace Slic3r {
|
|||
_reverse_pass();
|
||||
_recalculate_trapezoids();
|
||||
|
||||
_time = get_additional_time();
|
||||
_time += get_additional_time();
|
||||
|
||||
for (const Block& block : _blocks)
|
||||
{
|
||||
|
@ -478,6 +488,11 @@ namespace Slic3r {
|
|||
{
|
||||
switch (::atoi(&cmd[1]))
|
||||
{
|
||||
case 1: // Sleep or Conditional stop
|
||||
{
|
||||
_processM1(line);
|
||||
break;
|
||||
}
|
||||
case 82: // Set extruder to absolute mode
|
||||
{
|
||||
_processM82(line);
|
||||
|
@ -718,6 +733,8 @@ namespace Slic3r {
|
|||
if (line.has_value('S', value))
|
||||
add_additional_time(value);
|
||||
}
|
||||
|
||||
_simulate_st_synchronize();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processG20(const GCodeReader::GCodeLine& line)
|
||||
|
@ -747,16 +764,6 @@ namespace Slic3r {
|
|||
set_positioning_xyz_type(Relative);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
set_positioning_e_type(Absolute);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM83(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
set_positioning_e_type(Relative);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processG92(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
float lengthsScaleFactor = (get_units() == Inches) ? INCHES_TO_MM : 1.0f;
|
||||
|
@ -785,6 +792,8 @@ namespace Slic3r {
|
|||
set_axis_position(E, line.e() * lengthsScaleFactor);
|
||||
anyFound = true;
|
||||
}
|
||||
else
|
||||
_simulate_st_synchronize();
|
||||
|
||||
if (!anyFound)
|
||||
{
|
||||
|
@ -795,6 +804,21 @@ namespace Slic3r {
|
|||
}
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM1(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
_simulate_st_synchronize();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
set_positioning_e_type(Absolute);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM83(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
set_positioning_e_type(Relative);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processM109(const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
// TODO
|
||||
|
@ -895,6 +919,12 @@ namespace Slic3r {
|
|||
set_axis_max_jerk(E, line.e() * MMMIN_TO_MMSEC);
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_simulate_st_synchronize()
|
||||
{
|
||||
_calculate_time();
|
||||
_reset();
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_forward_pass()
|
||||
{
|
||||
if (_blocks.size() > 1)
|
||||
|
|
|
@ -278,6 +278,9 @@ namespace Slic3r {
|
|||
// Set Position
|
||||
void _processG92(const GCodeReader::GCodeLine& line);
|
||||
|
||||
// Sleep or Conditional stop
|
||||
void _processM1(const GCodeReader::GCodeLine& line);
|
||||
|
||||
// Set extruder to absolute mode
|
||||
void _processM82(const GCodeReader::GCodeLine& line);
|
||||
|
||||
|
@ -302,6 +305,9 @@ namespace Slic3r {
|
|||
// Set allowable instantaneous speed change
|
||||
void _processM566(const GCodeReader::GCodeLine& line);
|
||||
|
||||
// Simulates firmware st_synchronize() call
|
||||
void _simulate_st_synchronize();
|
||||
|
||||
void _forward_pass();
|
||||
void _reverse_pass();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue