Fix of #1812 (GCode Anayzer take in account extruder offsets for multiextruder printers)

This commit is contained in:
Enrico Turri 2019-03-06 10:22:10 +01:00
parent de23725a1e
commit 219ea04c23
4 changed files with 12 additions and 33 deletions

View file

@ -574,17 +574,16 @@ void GCode::_do_export(Print &print, FILE *file)
// resets analyzer
m_analyzer.reset();
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
// send extruder offset data to analyzer
std::vector<Vec2d> extruder_offsets;
GCodeAnalyzer::ExtruderOffsetsMap extruder_offsets;
for (unsigned int extruder_id : print.extruders())
{
extruder_offsets.push_back(print.config().extruder_offset.get_at(extruder_id));
Vec2d offset = print.config().extruder_offset.get_at(extruder_id);
if (!offset.isApprox(Vec2d::Zero()))
extruder_offsets[extruder_id] = offset;
}
m_analyzer.set_extruder_offsets(extruder_offsets);
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
// resets analyzer's tracking data
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
@ -855,9 +854,7 @@ void GCode::_do_export(Print &print, FILE *file)
for (unsigned int extruder_id : print.extruders()) {
const Vec2d &extruder_offset = print.config().extruder_offset.get_at(extruder_id);
Polygon s(outer_skirt);
#if !ENABLE_ANALYZER_EXTRUDER_OFFSET
s.translate(Point::new_scale(-extruder_offset(0), -extruder_offset(1)));
#endif // !ENABLE_ANALYZER_EXTRUDER_OFFSET
skirts.emplace_back(std::move(s));
}
m_ooze_prevention.enable = true;

View file

@ -101,12 +101,10 @@ GCodeAnalyzer::GCodeAnalyzer()
reset();
}
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
void GCodeAnalyzer::set_extruder_offsets(const std::vector<Vec2d>& extruder_offsets)
void GCodeAnalyzer::set_extruder_offsets(const GCodeAnalyzer::ExtruderOffsetsMap& extruder_offsets)
{
m_extruder_offsets = extruder_offsets;
}
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
void GCodeAnalyzer::reset()
{
@ -125,9 +123,7 @@ void GCodeAnalyzer::reset()
_reset_axes_position();
m_moves_map.clear();
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
m_extruder_offsets.clear();
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
}
const std::string& GCodeAnalyzer::process_gcode(const std::string& gcode)
@ -664,24 +660,15 @@ void GCodeAnalyzer::_store_move(GCodeAnalyzer::GCodeMove::EType type)
it = m_moves_map.insert(TypeToMovesMap::value_type(type, GCodeMovesList())).first;
// store move
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
Vec3d extruder_offset = Vec3d::Zero();
unsigned int extruder_id = _get_extruder_id();
std::cout << extruder_id << std::endl;
if (extruder_id < m_extruder_offsets.size())
{
Vec2d offset = m_extruder_offsets[extruder_id];
extruder_offset = Vec3d(offset(0), offset(1), 0.0);
}
ExtruderOffsetsMap::iterator extr_it = m_extruder_offsets.find(extruder_id);
if (extr_it != m_extruder_offsets.end())
extruder_offset = Vec3d(extr_it->second(0), extr_it->second(1), 0.0);
Vec3d start_position = _get_start_position() + extruder_offset;
Vec3d end_position = _get_end_position() + extruder_offset;
it->second.emplace_back(type, _get_extrusion_role(), extruder_id, _get_mm3_per_mm(), _get_width(), _get_height(), _get_feedrate(), start_position, end_position, _get_delta_extrusion(), _get_cp_color_id());
#else
it->second.emplace_back(type, _get_extrusion_role(), _get_extruder_id(), _get_mm3_per_mm(), _get_width(), _get_height(), _get_feedrate(), _get_start_position(), _get_end_position(), _get_delta_extrusion(), _get_cp_color_id());
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
}
bool GCodeAnalyzer::_is_valid_extrusion_role(int value) const

View file

@ -86,6 +86,7 @@ public:
typedef std::vector<GCodeMove> GCodeMovesList;
typedef std::map<GCodeMove::EType, GCodeMovesList> TypeToMovesMap;
typedef std::map<unsigned int, Vec2d> ExtruderOffsetsMap;
private:
struct State
@ -104,9 +105,7 @@ private:
State m_state;
GCodeReader m_parser;
TypeToMovesMap m_moves_map;
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
std::vector<Vec2d> m_extruder_offsets;
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
ExtruderOffsetsMap m_extruder_offsets;
// The output of process_layer()
std::string m_process_output;
@ -114,9 +113,7 @@ private:
public:
GCodeAnalyzer();
#if ENABLE_ANALYZER_EXTRUDER_OFFSET
void set_extruder_offsets(const std::vector<Vec2d>& extruder_offsets);
#endif // ENABLE_ANALYZER_EXTRUDER_OFFSET
void set_extruder_offsets(const ExtruderOffsetsMap& extruder_offsets);
// Reinitialize the analyzer
void reset();

View file

@ -58,7 +58,5 @@
// Toolbars and Gizmos use icons imported from svg files
#define ENABLE_SVG_ICONS (1 && ENABLE_1_42_0_ALPHA8 && ENABLE_TEXTURES_FROM_SVG)
// G-Code Analyzer takes in account for extruder offsets
#define ENABLE_ANALYZER_EXTRUDER_OFFSET (0 && ENABLE_1_42_0_ALPHA8)
#endif // _technologies_h_