Merge branch 'master' of https://github.com/Prusa3d/PrusaSlicer
This commit is contained in:
commit
7a47784ddf
4 changed files with 99 additions and 53 deletions
|
@ -141,6 +141,7 @@ void GCodeAnalyzer::reset()
|
||||||
_set_start_extrusion(DEFAULT_START_EXTRUSION);
|
_set_start_extrusion(DEFAULT_START_EXTRUSION);
|
||||||
_set_fan_speed(DEFAULT_FAN_SPEED);
|
_set_fan_speed(DEFAULT_FAN_SPEED);
|
||||||
_reset_axes_position();
|
_reset_axes_position();
|
||||||
|
_reset_axes_origin();
|
||||||
_reset_cached_position();
|
_reset_cached_position();
|
||||||
|
|
||||||
m_moves_map.clear();
|
m_moves_map.clear();
|
||||||
|
@ -310,31 +311,32 @@ void GCodeAnalyzer::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLi
|
||||||
m_process_output += line.raw() + "\n";
|
m_process_output += line.raw() + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the new absolute position on the given axis in dependence of the given parameters
|
|
||||||
float axis_absolute_position_from_G1_line(GCodeAnalyzer::EAxis axis, const GCodeReader::GCodeLine& lineG1, GCodeAnalyzer::EUnits units, bool is_relative, float current_absolute_position)
|
|
||||||
{
|
|
||||||
float lengthsScaleFactor = (units == GCodeAnalyzer::Inches) ? INCHES_TO_MM : 1.0f;
|
|
||||||
if (lineG1.has(Slic3r::Axis(axis)))
|
|
||||||
{
|
|
||||||
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
|
|
||||||
return is_relative ? current_absolute_position + ret : ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return current_absolute_position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GCodeAnalyzer::_processG1(const GCodeReader::GCodeLine& line)
|
void GCodeAnalyzer::_processG1(const GCodeReader::GCodeLine& line)
|
||||||
{
|
{
|
||||||
|
auto axis_absolute_position = [this](GCodeAnalyzer::EAxis axis, const GCodeReader::GCodeLine& lineG1) -> float
|
||||||
|
{
|
||||||
|
float current_absolute_position = _get_axis_position(axis);
|
||||||
|
float current_origin = _get_axis_origin(axis);
|
||||||
|
float lengthsScaleFactor = (_get_units() == GCodeAnalyzer::Inches) ? INCHES_TO_MM : 1.0f;
|
||||||
|
|
||||||
|
bool is_relative = (_get_global_positioning_type() == Relative);
|
||||||
|
if (axis == E)
|
||||||
|
is_relative |= (_get_e_local_positioning_type() == Relative);
|
||||||
|
|
||||||
|
if (lineG1.has(Slic3r::Axis(axis)))
|
||||||
|
{
|
||||||
|
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
|
||||||
|
return is_relative ? current_absolute_position + ret : ret + current_origin;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return current_absolute_position;
|
||||||
|
};
|
||||||
|
|
||||||
// updates axes positions from line
|
// updates axes positions from line
|
||||||
EUnits units = _get_units();
|
|
||||||
float new_pos[Num_Axis];
|
float new_pos[Num_Axis];
|
||||||
for (unsigned char a = X; a < Num_Axis; ++a)
|
for (unsigned char a = X; a < Num_Axis; ++a)
|
||||||
{
|
{
|
||||||
bool is_relative = (_get_global_positioning_type() == Relative);
|
new_pos[a] = axis_absolute_position((EAxis)a, line);
|
||||||
if (a == E)
|
|
||||||
is_relative |= (_get_e_local_positioning_type() == Relative);
|
|
||||||
|
|
||||||
new_pos[a] = axis_absolute_position_from_G1_line((EAxis)a, line, units, is_relative, _get_axis_position((EAxis)a));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates feedrate from line, if present
|
// updates feedrate from line, if present
|
||||||
|
@ -424,25 +426,25 @@ void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line)
|
||||||
|
|
||||||
if (line.has_x())
|
if (line.has_x())
|
||||||
{
|
{
|
||||||
_set_axis_position(X, line.x() * lengthsScaleFactor);
|
_set_axis_origin(X, _get_axis_position(X) - line.x() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_y())
|
if (line.has_y())
|
||||||
{
|
{
|
||||||
_set_axis_position(Y, line.y() * lengthsScaleFactor);
|
_set_axis_origin(Y, _get_axis_position(Y) - line.y() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_z())
|
if (line.has_z())
|
||||||
{
|
{
|
||||||
_set_axis_position(Z, line.z() * lengthsScaleFactor);
|
_set_axis_origin(Z, _get_axis_position(Z) - line.z() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_e())
|
if (line.has_e())
|
||||||
{
|
{
|
||||||
_set_axis_position(E, line.e() * lengthsScaleFactor);
|
_set_axis_origin(E, _get_axis_position(E) - line.e() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +452,7 @@ void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line)
|
||||||
{
|
{
|
||||||
for (unsigned char a = X; a < Num_Axis; ++a)
|
for (unsigned char a = X; a < Num_Axis; ++a)
|
||||||
{
|
{
|
||||||
_set_axis_position((EAxis)a, 0.0f);
|
_set_axis_origin((EAxis)a, _get_axis_position((EAxis)a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,11 +783,26 @@ float GCodeAnalyzer::_get_axis_position(EAxis axis) const
|
||||||
return m_state.position[axis];
|
return m_state.position[axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCodeAnalyzer::_set_axis_origin(EAxis axis, float position)
|
||||||
|
{
|
||||||
|
m_state.origin[axis] = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GCodeAnalyzer::_get_axis_origin(EAxis axis) const
|
||||||
|
{
|
||||||
|
return m_state.origin[axis];
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeAnalyzer::_reset_axes_position()
|
void GCodeAnalyzer::_reset_axes_position()
|
||||||
{
|
{
|
||||||
::memset((void*)m_state.position, 0, Num_Axis * sizeof(float));
|
::memset((void*)m_state.position, 0, Num_Axis * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCodeAnalyzer::_reset_axes_origin()
|
||||||
|
{
|
||||||
|
::memset((void*)m_state.origin, 0, Num_Axis * sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeAnalyzer::_set_start_position(const Vec3d& position)
|
void GCodeAnalyzer::_set_start_position(const Vec3d& position)
|
||||||
{
|
{
|
||||||
m_state.start_position = position;
|
m_state.start_position = position;
|
||||||
|
|
|
@ -101,6 +101,7 @@ private:
|
||||||
float cached_position[5];
|
float cached_position[5];
|
||||||
float start_extrusion;
|
float start_extrusion;
|
||||||
float position[Num_Axis];
|
float position[Num_Axis];
|
||||||
|
float origin[Num_Axis];
|
||||||
unsigned int cur_cp_color_id = 0;
|
unsigned int cur_cp_color_id = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,8 +247,13 @@ private:
|
||||||
void _set_axis_position(EAxis axis, float position);
|
void _set_axis_position(EAxis axis, float position);
|
||||||
float _get_axis_position(EAxis axis) const;
|
float _get_axis_position(EAxis axis) const;
|
||||||
|
|
||||||
|
void _set_axis_origin(EAxis axis, float position);
|
||||||
|
float _get_axis_origin(EAxis axis) const;
|
||||||
|
|
||||||
// Sets axes position to zero
|
// Sets axes position to zero
|
||||||
void _reset_axes_position();
|
void _reset_axes_position();
|
||||||
|
// Sets origin position to zero
|
||||||
|
void _reset_axes_origin();
|
||||||
|
|
||||||
void _set_start_position(const Vec3d& position);
|
void _set_start_position(const Vec3d& position);
|
||||||
const Vec3d& _get_start_position() const;
|
const Vec3d& _get_start_position() const;
|
||||||
|
|
|
@ -318,12 +318,15 @@ namespace Slic3r {
|
||||||
|
|
||||||
assert((g1_line_id >= (int)data->g1_line_ids.size()) || (data->g1_line_ids[g1_line_id].first >= g1_lines_count));
|
assert((g1_line_id >= (int)data->g1_line_ids.size()) || (data->g1_line_ids[g1_line_id].first >= g1_lines_count));
|
||||||
const Block* block = nullptr;
|
const Block* block = nullptr;
|
||||||
const G1LineIdToBlockId& map_item = data->g1_line_ids[g1_line_id];
|
if (g1_line_id < (int)data->g1_line_ids.size())
|
||||||
if ((g1_line_id < (int)data->g1_line_ids.size()) && (map_item.first == g1_lines_count))
|
|
||||||
{
|
{
|
||||||
if (line.has_e() && (map_item.second < (unsigned int)data->blocks.size()))
|
const G1LineIdToBlockId& map_item = data->g1_line_ids[g1_line_id];
|
||||||
block = &data->blocks[map_item.second];
|
if (map_item.first == g1_lines_count)
|
||||||
++g1_line_id;
|
{
|
||||||
|
if (line.has_e() && (map_item.second < (unsigned int)data->blocks.size()))
|
||||||
|
block = &data->blocks[map_item.second];
|
||||||
|
++g1_line_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((block != nullptr) && (block->elapsed_time != -1.0f))
|
if ((block != nullptr) && (block->elapsed_time != -1.0f))
|
||||||
|
@ -412,6 +415,11 @@ namespace Slic3r {
|
||||||
m_state.axis[axis].position = position;
|
m_state.axis[axis].position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCodeTimeEstimator::set_axis_origin(EAxis axis, float position)
|
||||||
|
{
|
||||||
|
m_state.axis[axis].origin = position;
|
||||||
|
}
|
||||||
|
|
||||||
void GCodeTimeEstimator::set_axis_max_feedrate(EAxis axis, float feedrate_mm_sec)
|
void GCodeTimeEstimator::set_axis_max_feedrate(EAxis axis, float feedrate_mm_sec)
|
||||||
{
|
{
|
||||||
m_state.axis[axis].max_feedrate = feedrate_mm_sec;
|
m_state.axis[axis].max_feedrate = feedrate_mm_sec;
|
||||||
|
@ -432,6 +440,11 @@ namespace Slic3r {
|
||||||
return m_state.axis[axis].position;
|
return m_state.axis[axis].position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GCodeTimeEstimator::get_axis_origin(EAxis axis) const
|
||||||
|
{
|
||||||
|
return m_state.axis[axis].origin;
|
||||||
|
}
|
||||||
|
|
||||||
float GCodeTimeEstimator::get_axis_max_feedrate(EAxis axis) const
|
float GCodeTimeEstimator::get_axis_max_feedrate(EAxis axis) const
|
||||||
{
|
{
|
||||||
return m_state.axis[axis].max_feedrate;
|
return m_state.axis[axis].max_feedrate;
|
||||||
|
@ -758,6 +771,10 @@ namespace Slic3r {
|
||||||
set_axis_position(X, 0.0f);
|
set_axis_position(X, 0.0f);
|
||||||
set_axis_position(Y, 0.0f);
|
set_axis_position(Y, 0.0f);
|
||||||
set_axis_position(Z, 0.0f);
|
set_axis_position(Z, 0.0f);
|
||||||
|
set_axis_origin(X, 0.0f);
|
||||||
|
set_axis_origin(Y, 0.0f);
|
||||||
|
set_axis_origin(Z, 0.0f);
|
||||||
|
|
||||||
if (get_e_local_positioning_type() == Absolute)
|
if (get_e_local_positioning_type() == Absolute)
|
||||||
set_axis_position(E, 0.0f);
|
set_axis_position(E, 0.0f);
|
||||||
|
|
||||||
|
@ -954,34 +971,35 @@ namespace Slic3r {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the new absolute position on the given axis in dependence of the given parameters
|
|
||||||
float axis_absolute_position_from_G1_line(GCodeTimeEstimator::EAxis axis, const GCodeReader::GCodeLine& lineG1, GCodeTimeEstimator::EUnits units, bool is_relative, float current_absolute_position)
|
|
||||||
{
|
|
||||||
float lengthsScaleFactor = (units == GCodeTimeEstimator::Inches) ? INCHES_TO_MM : 1.0f;
|
|
||||||
if (lineG1.has(Slic3r::Axis(axis)))
|
|
||||||
{
|
|
||||||
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
|
|
||||||
return is_relative ? current_absolute_position + ret : ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return current_absolute_position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GCodeTimeEstimator::_processG1(const GCodeReader::GCodeLine& line)
|
void GCodeTimeEstimator::_processG1(const GCodeReader::GCodeLine& line)
|
||||||
{
|
{
|
||||||
|
auto axis_absolute_position = [this](GCodeTimeEstimator::EAxis axis, const GCodeReader::GCodeLine& lineG1) -> float
|
||||||
|
{
|
||||||
|
float current_absolute_position = get_axis_position(axis);
|
||||||
|
float current_origin = get_axis_origin(axis);
|
||||||
|
float lengthsScaleFactor = (get_units() == GCodeTimeEstimator::Inches) ? INCHES_TO_MM : 1.0f;
|
||||||
|
|
||||||
|
bool is_relative = (get_global_positioning_type() == Relative);
|
||||||
|
if (axis == E)
|
||||||
|
is_relative |= (get_e_local_positioning_type() == Relative);
|
||||||
|
|
||||||
|
if (lineG1.has(Slic3r::Axis(axis)))
|
||||||
|
{
|
||||||
|
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
|
||||||
|
return is_relative ? current_absolute_position + ret : ret + current_origin;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return current_absolute_position;
|
||||||
|
};
|
||||||
|
|
||||||
PROFILE_FUNC();
|
PROFILE_FUNC();
|
||||||
increment_g1_line_id();
|
increment_g1_line_id();
|
||||||
|
|
||||||
// updates axes positions from line
|
// updates axes positions from line
|
||||||
EUnits units = get_units();
|
|
||||||
float new_pos[Num_Axis];
|
float new_pos[Num_Axis];
|
||||||
for (unsigned char a = X; a < Num_Axis; ++a)
|
for (unsigned char a = X; a < Num_Axis; ++a)
|
||||||
{
|
{
|
||||||
bool is_relative = (get_global_positioning_type() == Relative);
|
new_pos[a] = axis_absolute_position((EAxis)a, line);
|
||||||
if (a == E)
|
|
||||||
is_relative |= (get_e_local_positioning_type() == Relative);
|
|
||||||
|
|
||||||
new_pos[a] = axis_absolute_position_from_G1_line((EAxis)a, line, units, is_relative, get_axis_position((EAxis)a));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updates feedrate from line, if present
|
// updates feedrate from line, if present
|
||||||
|
@ -1225,25 +1243,25 @@ namespace Slic3r {
|
||||||
|
|
||||||
if (line.has_x())
|
if (line.has_x())
|
||||||
{
|
{
|
||||||
set_axis_position(X, line.x() * lengthsScaleFactor);
|
set_axis_origin(X, get_axis_position(X) - line.x() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_y())
|
if (line.has_y())
|
||||||
{
|
{
|
||||||
set_axis_position(Y, line.y() * lengthsScaleFactor);
|
set_axis_origin(Y, get_axis_position(Y) - line.y() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_z())
|
if (line.has_z())
|
||||||
{
|
{
|
||||||
set_axis_position(Z, line.z() * lengthsScaleFactor);
|
set_axis_origin(Z, get_axis_position(Z) - line.z() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.has_e())
|
if (line.has_e())
|
||||||
{
|
{
|
||||||
set_axis_position(E, line.e() * lengthsScaleFactor);
|
set_axis_origin(E, get_axis_position(E) - line.e() * lengthsScaleFactor);
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1253,7 +1271,7 @@ namespace Slic3r {
|
||||||
{
|
{
|
||||||
for (unsigned char a = X; a < Num_Axis; ++a)
|
for (unsigned char a = X; a < Num_Axis; ++a)
|
||||||
{
|
{
|
||||||
set_axis_position((EAxis)a, 0.0f);
|
set_axis_origin((EAxis)a, get_axis_position((EAxis)a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ namespace Slic3r {
|
||||||
struct Axis
|
struct Axis
|
||||||
{
|
{
|
||||||
float position; // mm
|
float position; // mm
|
||||||
|
float origin; // mm
|
||||||
float max_feedrate; // mm/s
|
float max_feedrate; // mm/s
|
||||||
float max_acceleration; // mm/s^2
|
float max_acceleration; // mm/s^2
|
||||||
float max_jerk; // mm/s
|
float max_jerk; // mm/s
|
||||||
|
@ -282,6 +283,8 @@ namespace Slic3r {
|
||||||
|
|
||||||
// Set current position on the given axis with the given value
|
// Set current position on the given axis with the given value
|
||||||
void set_axis_position(EAxis axis, float position);
|
void set_axis_position(EAxis axis, float position);
|
||||||
|
// Set current origin on the given axis with the given value
|
||||||
|
void set_axis_origin(EAxis axis, float position);
|
||||||
|
|
||||||
void set_axis_max_feedrate(EAxis axis, float feedrate_mm_sec);
|
void set_axis_max_feedrate(EAxis axis, float feedrate_mm_sec);
|
||||||
void set_axis_max_acceleration(EAxis axis, float acceleration);
|
void set_axis_max_acceleration(EAxis axis, float acceleration);
|
||||||
|
@ -289,6 +292,8 @@ namespace Slic3r {
|
||||||
|
|
||||||
// Returns current position on the given axis
|
// Returns current position on the given axis
|
||||||
float get_axis_position(EAxis axis) const;
|
float get_axis_position(EAxis axis) const;
|
||||||
|
// Returns current origin on the given axis
|
||||||
|
float get_axis_origin(EAxis axis) const;
|
||||||
|
|
||||||
float get_axis_max_feedrate(EAxis axis) const;
|
float get_axis_max_feedrate(EAxis axis) const;
|
||||||
float get_axis_max_acceleration(EAxis axis) const;
|
float get_axis_max_acceleration(EAxis axis) const;
|
||||||
|
|
Loading…
Reference in a new issue