ENABLE_GCODE_VIEWER - Basic framework for new gcode viewer

This commit is contained in:
Enrico Turri 2020-03-02 15:13:23 +01:00
parent ebbebe3727
commit 3b6d334d7b
17 changed files with 173 additions and 48 deletions

View file

@ -8,30 +8,26 @@ static const float MMMIN_TO_MMSEC = 1.0f / 60.0f;
namespace Slic3r {
void GCodeProcessor::apply_config(const PrintConfig& config)
{
m_parser.apply_config(config);
}
void GCodeProcessor::reset()
{
m_units = EUnits::Millimeters;
m_global_positioning_type = EPositioningType::Absolute;
m_e_local_positioning_type = EPositioningType::Absolute;
::memset(m_start_position.data(), 0, sizeof(AxisCoords));
::memset(m_end_position.data(), 0, sizeof(AxisCoords));
::memset(m_origin.data(), 0, sizeof(AxisCoords));
std::fill(m_start_position.begin(), m_start_position.end(), 0.0f);
std::fill(m_end_position.begin(), m_end_position.end(), 0.0f);
std::fill(m_origin.begin(), m_origin.end(), 0.0f);
m_feedrate = 0.0f;
m_extruder_id = 0;
m_moves.clear();
m_result.reset();
}
void GCodeProcessor::process_file(const std::string& filename)
{
MoveStep start_step {};
m_moves.emplace_back(start_step);
MoveVertex start_vertex {};
m_result.moves.emplace_back(start_vertex);
m_parser.parse_file(filename, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { process_gcode_line(line); });
int a = 0;
}
@ -149,9 +145,17 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
else if ((delta_pos[X] != 0.0f) || (delta_pos[Y] != 0.0f) || (delta_pos[Z] != 0.0f))
move_type = EMoveType::Travel;
// correct position by extruder offset
Vec3d extruder_offset = Vec3d::Zero();
auto it = m_extruder_offsets.find(m_extruder_id);
if (it != m_extruder_offsets.end())
extruder_offset = Vec3d(it->second(0), it->second(1), 0.0);
MoveStep move_step { m_end_position, m_feedrate, move_type };
m_moves.emplace_back(move_step);
MoveVertex vertex;
vertex.position = Vec3d(m_end_position[0], m_end_position[1], m_end_position[2]) + extruder_offset;
vertex.feedrate = m_feedrate;
vertex.type = move_type;
m_result.moves.emplace_back(vertex);
/*
std::cout << "start: ";

View file

@ -33,15 +33,24 @@ namespace Slic3r {
Num_Types
};
struct MoveStep
struct MoveVertex
{
AxisCoords position; // mm
float feedrate; // mm/s
EMoveType type;
Vec3d position{ Vec3d::Zero() }; // mm
float feedrate{ 0.0f }; // mm/s
// type of the move terminating at this vertex
EMoveType type{ EMoveType::Noop };
};
using MoveStepsList = std::vector<MoveStep>;
public:
typedef std::map<unsigned int, Vec2d> ExtruderOffsetsMap;
struct Result
{
std::vector<MoveVertex> moves;
void reset() { moves = std::vector<MoveVertex>(); }
};
private:
GCodeReader m_parser;
EUnits m_units;
@ -53,17 +62,22 @@ namespace Slic3r {
AxisCoords m_origin; // mm
float m_feedrate; // mm/s
unsigned int m_extruder_id;
ExtruderOffsetsMap m_extruder_offsets;
MoveStepsList m_moves;
Result m_result;
public:
GCodeProcessor() { reset(); }
void apply_config(const PrintConfig& config);
void apply_config(const PrintConfig& config) { m_parser.apply_config(config); }
void reset();
void set_extruder_offsets(const ExtruderOffsetsMap& extruder_offsets) { m_extruder_offsets = extruder_offsets; }
const Result& get_result() const { return m_result; }
Result&& extract_result() { return std::move(m_result); }
// Process the gcode contained in the file with the given filename
// Return false if any error occourred
void process_file(const std::string& filename);