OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{GCode.cpp} Namespace Reference

Classes

struct  PrecomputedLayer

Functions

std::optional< Vec2d > emitted_xy_after_gcode (const std::string &gcode, const Vec2d &initial_xy)

Class Documentation

◆ Slic3r::anonymous_namespace{GCode.cpp}::PrecomputedLayer

struct Slic3r::anonymous_namespace{GCode.cpp}::PrecomputedLayer
Collaboration diagram for Slic3r::anonymous_namespace{GCode.cpp}::PrecomputedLayer:
Class Members
size_t index {size_t(-1)}
vector< PrecomputedOverhangLayer > overhang_layers

Function Documentation

◆ emitted_xy_after_gcode()

std::optional< Vec2d > Slic3r::anonymous_namespace{GCode.cpp}::emitted_xy_after_gcode ( const std::string & gcode,
const Vec2d & initial_xy )
162{
163 Vec2d position = initial_xy;
164 bool absolute = true;
165 bool coordinate_frame_known = true;
166
167 GCodeReader reader;
168 reader.parse_buffer(gcode, [&position, &absolute, &coordinate_frame_known](GCodeReader &, const GCodeReader::GCodeLine &line) {
169 if (line.cmd_is("G90")) {
170 absolute = true;
171 return;
172 }
173 if (line.cmd_is("G91")) {
174 absolute = false;
175 return;
176 }
177
178 const bool is_motion = line.cmd_is("G0") || line.cmd_is("G1") || line.cmd_is("G2") || line.cmd_is("G3");
179 if (is_motion) {
180 if (line.has_x())
181 position.x() = absolute ? line.x() : position.x() + line.x();
182 if (line.has_y())
183 position.y() = absolute ? line.y() : position.y() + line.y();
184 return;
185 }
186
187 // G92 changes the coordinate system without moving the machine, and
188 // G28 moves to a firmware-defined position. Do not invent a position
189 // if either command affects XY.
190 if (line.cmd_is("G92")) {
191 coordinate_frame_known = coordinate_frame_known && !line.has_x() && !line.has_y();
192 } else if (line.cmd_is("G28")) {
193 const bool homes_all = !line.has_x() && !line.has_y() && !line.has_z();
194 coordinate_frame_known = coordinate_frame_known && !homes_all && !line.has_x() && !line.has_y();
195 }
196 });
197
198 return coordinate_frame_known ? std::optional<Vec2d>(position) : std::nullopt;
199}
Definition GCodeReader.hpp:21
float x() const
Definition GCodeReader.hpp:76
bool has_z() const
Definition GCodeReader.hpp:67
float y() const
Definition GCodeReader.hpp:77
bool has_y() const
Definition GCodeReader.hpp:66
bool has_x() const
Definition GCodeReader.hpp:65
bool cmd_is(const char *cmd_test) const
Definition GCodeReader.hpp:58
Definition GCodeReader.hpp:19
void parse_buffer(const std::string &buffer, Callback callback)
Definition GCodeReader.hpp:119
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References Slic3r::GCodeReader::GCodeLine::cmd_is(), emitted_xy_after_gcode(), Slic3r::GCodeReader::GCodeLine::has_x(), Slic3r::GCodeReader::GCodeLine::has_y(), Slic3r::GCodeReader::GCodeLine::has_z(), Slic3r::GCodeReader::parse_buffer(), Slic3r::GCodeReader::GCodeLine::x(), and Slic3r::GCodeReader::GCodeLine::y().

Referenced by emitted_xy_after_gcode().

Here is the call graph for this function:
Here is the caller graph for this function: