Merge remote-tracking branch 'origin/time_estimate'

This commit is contained in:
bubnikv 2018-04-04 11:04:31 +02:00
commit 40bbabb6d0
4 changed files with 54 additions and 48 deletions

View file

@ -97,8 +97,8 @@ GCodeAnalyzer::GCodeAnalyzer()
void GCodeAnalyzer::reset() void GCodeAnalyzer::reset()
{ {
_set_units(Millimeters); _set_units(Millimeters);
_set_positioning_xyz_type(Absolute); _set_global_positioning_type(Absolute);
_set_positioning_e_type(Relative); _set_e_local_positioning_type(Absolute);
_set_extrusion_role(erNone); _set_extrusion_role(erNone);
_set_extruder_id(DEFAULT_EXTRUDER_ID); _set_extruder_id(DEFAULT_EXTRUDER_ID);
_set_mm3_per_mm(Default_mm3_per_mm); _set_mm3_per_mm(Default_mm3_per_mm);
@ -247,13 +247,13 @@ void GCodeAnalyzer::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLi
} }
// Returns the new absolute position on the given axis in dependence of the given parameters // 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, GCodeAnalyzer::EPositioningType type, float current_absolute_position) 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; float lengthsScaleFactor = (units == GCodeAnalyzer::Inches) ? INCHES_TO_MM : 1.0f;
if (lineG1.has(Slic3r::Axis(axis))) if (lineG1.has(Slic3r::Axis(axis)))
{ {
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor; float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
return (type == GCodeAnalyzer::Absolute) ? ret : current_absolute_position + ret; return is_relative ? current_absolute_position + ret : ret;
} }
else else
return current_absolute_position; return current_absolute_position;
@ -266,7 +266,11 @@ void GCodeAnalyzer::_processG1(const GCodeReader::GCodeLine& line)
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)
{ {
new_pos[a] = axis_absolute_position_from_G1_line((EAxis)a, line, units, (a == E) ? _get_positioning_e_type() : _get_positioning_xyz_type(), _get_axis_position((EAxis)a)); bool is_relative = (_get_global_positioning_type() == Relative);
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
@ -341,12 +345,12 @@ void GCodeAnalyzer::_processG23(const GCodeReader::GCodeLine& line)
void GCodeAnalyzer::_processG90(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processG90(const GCodeReader::GCodeLine& line)
{ {
_set_positioning_xyz_type(Absolute); _set_global_positioning_type(Absolute);
} }
void GCodeAnalyzer::_processG91(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processG91(const GCodeReader::GCodeLine& line)
{ {
_set_positioning_xyz_type(Relative); _set_global_positioning_type(Relative);
} }
void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line)
@ -389,12 +393,12 @@ void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line)
void GCodeAnalyzer::_processM82(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processM82(const GCodeReader::GCodeLine& line)
{ {
_set_positioning_e_type(Absolute); _set_e_local_positioning_type(Absolute);
} }
void GCodeAnalyzer::_processM83(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processM83(const GCodeReader::GCodeLine& line)
{ {
_set_positioning_e_type(Relative); _set_e_local_positioning_type(Relative);
} }
void GCodeAnalyzer::_processT(const GCodeReader::GCodeLine& line) void GCodeAnalyzer::_processT(const GCodeReader::GCodeLine& line)
@ -488,24 +492,24 @@ GCodeAnalyzer::EUnits GCodeAnalyzer::_get_units() const
return m_state.units; return m_state.units;
} }
void GCodeAnalyzer::_set_positioning_xyz_type(GCodeAnalyzer::EPositioningType type) void GCodeAnalyzer::_set_global_positioning_type(GCodeAnalyzer::EPositioningType type)
{ {
m_state.positioning_xyz_type = type; m_state.global_positioning_type = type;
} }
GCodeAnalyzer::EPositioningType GCodeAnalyzer::_get_positioning_xyz_type() const GCodeAnalyzer::EPositioningType GCodeAnalyzer::_get_global_positioning_type() const
{ {
return m_state.positioning_xyz_type; return m_state.global_positioning_type;
} }
void GCodeAnalyzer::_set_positioning_e_type(GCodeAnalyzer::EPositioningType type) void GCodeAnalyzer::_set_e_local_positioning_type(GCodeAnalyzer::EPositioningType type)
{ {
m_state.positioning_e_type = type; m_state.e_local_positioning_type = type;
} }
GCodeAnalyzer::EPositioningType GCodeAnalyzer::_get_positioning_e_type() const GCodeAnalyzer::EPositioningType GCodeAnalyzer::_get_e_local_positioning_type() const
{ {
return m_state.positioning_e_type; return m_state.e_local_positioning_type;
} }
void GCodeAnalyzer::_set_extrusion_role(ExtrusionRole extrusion_role) void GCodeAnalyzer::_set_extrusion_role(ExtrusionRole extrusion_role)

View file

@ -90,8 +90,8 @@ private:
struct State struct State
{ {
EUnits units; EUnits units;
EPositioningType positioning_xyz_type; EPositioningType global_positioning_type;
EPositioningType positioning_e_type; EPositioningType e_local_positioning_type;
Metadata data; Metadata data;
Pointf3 start_position; Pointf3 start_position;
float start_extrusion; float start_extrusion;
@ -176,11 +176,11 @@ private:
void _set_units(EUnits units); void _set_units(EUnits units);
EUnits _get_units() const; EUnits _get_units() const;
void _set_positioning_xyz_type(EPositioningType type); void _set_global_positioning_type(EPositioningType type);
EPositioningType _get_positioning_xyz_type() const; EPositioningType _get_global_positioning_type() const;
void _set_positioning_e_type(EPositioningType type); void _set_e_local_positioning_type(EPositioningType type);
EPositioningType _get_positioning_e_type() const; EPositioningType _get_e_local_positioning_type() const;
void _set_extrusion_role(ExtrusionRole extrusion_role); void _set_extrusion_role(ExtrusionRole extrusion_role);
ExtrusionRole _get_extrusion_role() const; ExtrusionRole _get_extrusion_role() const;

View file

@ -369,24 +369,24 @@ namespace Slic3r {
return _state.units; return _state.units;
} }
void GCodeTimeEstimator::set_positioning_xyz_type(GCodeTimeEstimator::EPositioningType type) void GCodeTimeEstimator::set_global_positioning_type(GCodeTimeEstimator::EPositioningType type)
{ {
_state.positioning_xyz_type = type; _state.global_positioning_type = type;
} }
GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_positioning_xyz_type() const GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_global_positioning_type() const
{ {
return _state.positioning_xyz_type; return _state.global_positioning_type;
} }
void GCodeTimeEstimator::set_positioning_e_type(GCodeTimeEstimator::EPositioningType type) void GCodeTimeEstimator::set_e_local_positioning_type(GCodeTimeEstimator::EPositioningType type)
{ {
_state.positioning_e_type = type; _state.e_local_positioning_type = type;
} }
GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_positioning_e_type() const GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_e_local_positioning_type() const
{ {
return _state.positioning_e_type; return _state.e_local_positioning_type;
} }
void GCodeTimeEstimator::add_additional_time(float timeSec) void GCodeTimeEstimator::add_additional_time(float timeSec)
@ -408,8 +408,8 @@ namespace Slic3r {
{ {
set_units(Millimeters); set_units(Millimeters);
set_dialect(gcfRepRap); set_dialect(gcfRepRap);
set_positioning_xyz_type(Absolute); set_global_positioning_type(Absolute);
set_positioning_e_type(Relative); set_e_local_positioning_type(Absolute);
set_feedrate(DEFAULT_FEEDRATE); set_feedrate(DEFAULT_FEEDRATE);
set_acceleration(DEFAULT_ACCELERATION); set_acceleration(DEFAULT_ACCELERATION);
@ -628,13 +628,13 @@ namespace Slic3r {
} }
// Returns the new absolute position on the given axis in dependence of the given parameters // 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, GCodeTimeEstimator::EPositioningType type, float current_absolute_position) 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; float lengthsScaleFactor = (units == GCodeTimeEstimator::Inches) ? INCHES_TO_MM : 1.0f;
if (lineG1.has(Slic3r::Axis(axis))) if (lineG1.has(Slic3r::Axis(axis)))
{ {
float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor; float ret = lineG1.value(Slic3r::Axis(axis)) * lengthsScaleFactor;
return (type == GCodeTimeEstimator::Absolute) ? ret : current_absolute_position + ret; return is_relative ? current_absolute_position + ret : ret;
} }
else else
return current_absolute_position; return current_absolute_position;
@ -647,7 +647,11 @@ namespace Slic3r {
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)
{ {
new_pos[a] = axis_absolute_position_from_G1_line((EAxis)a, line, units, (a == E) ? get_positioning_e_type() : get_positioning_xyz_type(), get_axis_position((EAxis)a)); bool is_relative = (get_global_positioning_type() == Relative);
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
@ -865,14 +869,12 @@ namespace Slic3r {
void GCodeTimeEstimator::_processG90(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processG90(const GCodeReader::GCodeLine& line)
{ {
set_positioning_xyz_type(Absolute); set_global_positioning_type(Absolute);
} }
void GCodeTimeEstimator::_processG91(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processG91(const GCodeReader::GCodeLine& line)
{ {
// TODO: THERE ARE DIALECT VARIANTS set_global_positioning_type(Relative);
set_positioning_xyz_type(Relative);
} }
void GCodeTimeEstimator::_processG92(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processG92(const GCodeReader::GCodeLine& line)
@ -922,12 +924,12 @@ namespace Slic3r {
void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line)
{ {
set_positioning_e_type(Absolute); set_e_local_positioning_type(Absolute);
} }
void GCodeTimeEstimator::_processM83(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processM83(const GCodeReader::GCodeLine& line)
{ {
set_positioning_e_type(Relative); set_e_local_positioning_type(Relative);
} }
void GCodeTimeEstimator::_processM109(const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_processM109(const GCodeReader::GCodeLine& line)

View file

@ -61,8 +61,8 @@ namespace Slic3r {
{ {
GCodeFlavor dialect; GCodeFlavor dialect;
EUnits units; EUnits units;
EPositioningType positioning_xyz_type; EPositioningType global_positioning_type;
EPositioningType positioning_e_type; EPositioningType e_local_positioning_type;
Axis axis[Num_Axis]; Axis axis[Num_Axis];
float feedrate; // mm/s float feedrate; // mm/s
float acceleration; // mm/s^2 float acceleration; // mm/s^2
@ -257,11 +257,11 @@ namespace Slic3r {
void set_units(EUnits units); void set_units(EUnits units);
EUnits get_units() const; EUnits get_units() const;
void set_positioning_xyz_type(EPositioningType type); void set_global_positioning_type(EPositioningType type);
EPositioningType get_positioning_xyz_type() const; EPositioningType get_global_positioning_type() const;
void set_positioning_e_type(EPositioningType type); void set_e_local_positioning_type(EPositioningType type);
EPositioningType get_positioning_e_type() const; EPositioningType get_e_local_positioning_type() const;
void add_additional_time(float timeSec); void add_additional_time(float timeSec);
void set_additional_time(float timeSec); void set_additional_time(float timeSec);