mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-28 22:52:03 +08:00
follow-up to eba6a81e38f2183c524584127c4ddef9ef5c9c04
This commit is contained in:
parent
852f10bbe7
commit
a693adbeab
@ -2887,15 +2887,15 @@ void GCodeProcessor::process_G1(const std::array<std::optional<double>, 4>& axes
|
||||
void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise)
|
||||
{
|
||||
enum class EFitting { None, IJ, R };
|
||||
const char *axis_pos_I = nullptr;
|
||||
const char *axis_pos_J = nullptr;
|
||||
std::string_view axis_pos_I;
|
||||
std::string_view axis_pos_J;
|
||||
EFitting fitting = EFitting::None;
|
||||
if (line.has('R')) {
|
||||
fitting = EFitting::R;
|
||||
} else {
|
||||
axis_pos_I = line.axis_pos('I');
|
||||
axis_pos_J = line.axis_pos('J');
|
||||
if (axis_pos_I || axis_pos_J)
|
||||
if (! axis_pos_I.empty() || ! axis_pos_J.empty())
|
||||
fitting = EFitting::IJ;
|
||||
}
|
||||
|
||||
@ -2931,9 +2931,9 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
||||
}
|
||||
else {
|
||||
assert(fitting == EFitting::IJ);
|
||||
if (axis_pos_I && ! line.has_value(axis_pos_I, rel_center.x()))
|
||||
if (! axis_pos_I.empty() && ! line.has_value(axis_pos_I, rel_center.x()))
|
||||
return;
|
||||
if (axis_pos_J && ! line.has_value(axis_pos_J, rel_center.y()))
|
||||
if (! axis_pos_J.empty() && ! line.has_value(axis_pos_J, rel_center.y()))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -237,20 +237,22 @@ const char* GCodeReader::axis_pos(const char *raw_str, char axis)
|
||||
|
||||
bool GCodeReader::GCodeLine::has(char axis) const
|
||||
{
|
||||
return this->axis_pos(axis);
|
||||
}
|
||||
|
||||
const char* GCodeReader::GCodeLine::axis_pos(char axis) const
|
||||
{
|
||||
return GCodeReader::axis_pos(this->raw().c_str(), axis);
|
||||
}
|
||||
|
||||
static bool GCodeReader::GCodeLine::has_value(const char *axis_pos, float &value)
|
||||
std::string_view GCodeReader::GCodeLine::axis_pos(char axis) const
|
||||
{
|
||||
const std::string &s = this->raw();
|
||||
const char *c = GCodeReader::axis_pos(this->raw().c_str(), axis);
|
||||
return c ? std::string_view{ c, s.size() - (c - s.data()) } : std::string_view();
|
||||
}
|
||||
|
||||
bool GCodeReader::GCodeLine::has_value(std::string_view axis_pos, float &value)
|
||||
{
|
||||
if (const char *c = axis_pos; c) {
|
||||
if (const char *c = axis_pos.data(); c) {
|
||||
// Try to parse the numeric value.
|
||||
double v = 0.;
|
||||
const char *end = m_raw.c_str() + m_raw.size();
|
||||
const char *end = axis_pos.data() + axis_pos.size();
|
||||
auto [pend, ec] = fast_float::from_chars(++ c, end, v);
|
||||
if (pend != c && is_end_of_word(*pend)) {
|
||||
// The axis value has been parsed correctly.
|
||||
@ -267,9 +269,9 @@ bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
|
||||
return this->has_value(this->axis_pos(axis), value);
|
||||
}
|
||||
|
||||
static bool GCodeReader::GCodeLine::has_value(const char *axis_pos, int &value)
|
||||
bool GCodeReader::GCodeLine::has_value(std::string_view axis_pos, int &value)
|
||||
{
|
||||
if (const char *c = axis_pos; c) {
|
||||
if (const char *c = axis_pos.data(); c) {
|
||||
// Try to parse the numeric value.
|
||||
char *pend = nullptr;
|
||||
long v = strtol(++ c, &pend, 10);
|
||||
|
@ -31,15 +31,15 @@ public:
|
||||
{ size_t pos = m_raw.find(';'); return (pos == std::string::npos) ? std::string_view() : std::string_view(m_raw).substr(pos + 1); }
|
||||
|
||||
// Return position in this->raw() string starting with the "axis" character.
|
||||
const char* axis_pos(char axis) const;
|
||||
std::string_view axis_pos(char axis) const;
|
||||
bool has(Axis axis) const { return (m_mask & (1 << int(axis))) != 0; }
|
||||
float value(Axis axis) const { return m_axis[axis]; }
|
||||
bool has(char axis) const;
|
||||
bool has_value(char axis, float &value) const;
|
||||
bool has_value(char axis, int &value) const;
|
||||
// Parse value of an axis from raw string starting at axis_pos.
|
||||
static bool has_value(const char *axis_pos, float &value);
|
||||
static bool has_value(const char *axis_pos, int &value);
|
||||
static bool has_value(std::string_view axis_pos, float &value);
|
||||
static bool has_value(std::string_view axis_pos, int &value);
|
||||
float new_X(const GCodeReader &reader) const { return this->has(X) ? this->x() : reader.x(); }
|
||||
float new_Y(const GCodeReader &reader) const { return this->has(Y) ? this->y() : reader.y(); }
|
||||
float new_Z(const GCodeReader &reader) const { return this->has(Z) ? this->z() : reader.z(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user