Files
OrcaSlicer-bambulab/src/libslic3r/GCode/GCodeProcessor.hpp
T

144 lines
3.9 KiB
C++
Raw Normal View History

2020-02-14 08:31:31 +01:00
#ifndef slic3r_GCodeProcessor_hpp_
#define slic3r_GCodeProcessor_hpp_
#if ENABLE_GCODE_VIEWER
#include "../GCodeReader.hpp"
2020-04-02 12:03:18 +02:00
#include "../Point.hpp"
#include "../ExtrusionEntity.hpp"
2020-02-14 08:31:31 +01:00
namespace Slic3r {
class GCodeProcessor
{
2020-04-02 12:03:18 +02:00
public:
static const std::string Extrusion_Role_Tag;
static const std::string Width_Tag;
static const std::string Height_Tag;
private:
2020-02-14 08:31:31 +01:00
using AxisCoords = std::array<float, 4>;
enum class EUnits : unsigned char
{
Millimeters,
Inches
};
enum class EPositioningType : unsigned char
{
Absolute,
Relative
};
enum class EMoveType : unsigned char
{
Noop,
Retract,
Unretract,
Tool_change,
Travel,
Extrude,
Num_Types
};
2020-04-02 12:03:18 +02:00
public:
struct MoveVertex
2020-02-14 08:31:31 +01:00
{
EMoveType type{ EMoveType::Noop };
2020-04-02 12:03:18 +02:00
ExtrusionRole extrusion_role{ erNone };
Vec3f position{ Vec3f::Zero() }; // mm
float feedrate{ 0.0f }; // mm/s
float width{ 0.0f }; // mm
float height{ 0.0f }; // mm
unsigned int extruder_id{ 0 };
2020-02-14 08:31:31 +01:00
2020-04-02 12:03:18 +02:00
std::string to_string() const
{
std::string str = std::to_string((int)type);
str += ", " + std::to_string((int)extrusion_role);
str += ", " + Slic3r::to_string((Vec3d)position.cast<double>());
str += ", " + std::to_string(extruder_id);
str += ", " + std::to_string(feedrate);
str += ", " + std::to_string(width);
str += ", " + std::to_string(height);
return str;
}
};
2020-02-14 08:31:31 +01:00
struct Result
{
std::vector<MoveVertex> moves;
void reset() { moves = std::vector<MoveVertex>(); }
};
private:
2020-02-14 08:31:31 +01:00
GCodeReader m_parser;
EUnits m_units;
EPositioningType m_global_positioning_type;
EPositioningType m_e_local_positioning_type;
2020-04-02 12:03:18 +02:00
std::vector<Vec3f> m_extruder_offsets;
2020-02-14 08:31:31 +01:00
AxisCoords m_start_position; // mm
AxisCoords m_end_position; // mm
AxisCoords m_origin; // mm
float m_feedrate; // mm/s
2020-04-02 12:03:18 +02:00
float m_width; // mm
float m_height; // mm
ExtrusionRole m_extrusion_role;
unsigned int m_extruder_id;
2020-02-14 08:31:31 +01:00
Result m_result;
2020-02-14 08:31:31 +01:00
public:
GCodeProcessor() { reset(); }
2020-04-02 12:03:18 +02:00
void apply_config(const PrintConfig& config);
2020-02-14 08:31:31 +01:00
void reset();
const Result& get_result() const { return m_result; }
Result&& extract_result() { return std::move(m_result); }
2020-02-14 08:31:31 +01:00
// Process the gcode contained in the file with the given filename
// Return false if any error occourred
void process_file(const std::string& filename);
private:
void process_gcode_line(const GCodeReader::GCodeLine& line);
// Process tags embedded into comments
2020-04-02 12:03:18 +02:00
void process_tags(const std::string& comment);
2020-02-14 08:31:31 +01:00
// Move
void process_G1(const GCodeReader::GCodeLine& line);
2020-04-02 12:03:18 +02:00
// Set to Absolute Positioning
void processG90(const GCodeReader::GCodeLine& line);
// Set to Relative Positioning
void processG91(const GCodeReader::GCodeLine& line);
// Set Position
void processG92(const GCodeReader::GCodeLine& line);
// Set extruder to absolute mode
void processM82(const GCodeReader::GCodeLine& line);
// Set extruder to relative mode
void processM83(const GCodeReader::GCodeLine& line);
// Processes T line (Select Tool)
void processT(const GCodeReader::GCodeLine& line);
void store_move_vertex(EMoveType type);
};
2020-02-14 08:31:31 +01:00
} /* namespace Slic3r */
#endif // ENABLE_GCODE_VIEWER
#endif /* slic3r_GCodeProcessor_hpp_ */