mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-06 01:16:05 +08:00
Method GCodeProcessor::process_G2_G3() modified to process lines G2/G3 R
This commit is contained in:
parent
bde6fb2528
commit
9fe42ecbdc
@ -6,6 +6,7 @@
|
|||||||
#include "libslic3r/I18N.hpp"
|
#include "libslic3r/I18N.hpp"
|
||||||
#include "libslic3r/GCode/GCodeWriter.hpp"
|
#include "libslic3r/GCode/GCodeWriter.hpp"
|
||||||
#include "libslic3r/I18N.hpp"
|
#include "libslic3r/I18N.hpp"
|
||||||
|
#include "libslic3r/Geometry/ArcWelder.hpp"
|
||||||
#include "GCodeProcessor.hpp"
|
#include "GCodeProcessor.hpp"
|
||||||
|
|
||||||
#include <boost/algorithm/string/case_conv.hpp>
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
@ -2698,13 +2699,39 @@ void GCodeProcessor::process_G1(const std::array<std::optional<double>, 4>& axes
|
|||||||
|
|
||||||
void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise)
|
void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise)
|
||||||
{
|
{
|
||||||
if (!line.has('I') || !line.has('J'))
|
enum class EFitting { None, IJ, R };
|
||||||
|
const EFitting fitting = line.has('R') ? EFitting::R : (line.has('I') && line.has('J')) ? EFitting::IJ : EFitting::None;
|
||||||
|
|
||||||
|
if (fitting == EFitting::None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const float filament_diameter = (static_cast<size_t>(m_extruder_id) < m_result.filament_diameters.size()) ? m_result.filament_diameters[m_extruder_id] : m_result.filament_diameters.back();
|
||||||
|
const float filament_radius = 0.5f * filament_diameter;
|
||||||
|
const float area_filament_cross_section = static_cast<float>(M_PI) * sqr(filament_radius);
|
||||||
|
|
||||||
|
AxisCoords end_position = m_start_position;
|
||||||
|
for (unsigned char a = X; a <= E; ++a) {
|
||||||
|
end_position[a] = extract_absolute_position_on_axis((Axis)a, line, double(area_filament_cross_section));
|
||||||
|
}
|
||||||
|
|
||||||
// relative center
|
// relative center
|
||||||
Vec3f rel_center = Vec3f::Zero();
|
Vec3f rel_center = Vec3f::Zero();
|
||||||
|
double radius = 0.0;
|
||||||
|
if (fitting == EFitting::R) {
|
||||||
|
float r;
|
||||||
|
if (!line.has_value('R', r) || r == 0.0f)
|
||||||
|
return;
|
||||||
|
radius = (double)std::abs(r);
|
||||||
|
const Vec2f start_pos((float)m_start_position[X], (float)m_start_position[Y]);
|
||||||
|
const Vec2f end_pos((float)end_position[X], (float)end_position[Y]);
|
||||||
|
const Vec2f c = Geometry::ArcWelder::arc_center(start_pos, end_pos, r, !clockwise);
|
||||||
|
rel_center.x() = c.x() - m_start_position[X];
|
||||||
|
rel_center.y() = c.y() - m_start_position[Y];
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (!line.has_value('I', rel_center.x()) || !line.has_value('J', rel_center.y()))
|
if (!line.has_value('I', rel_center.x()) || !line.has_value('J', rel_center.y()))
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// scale center, if needed
|
// scale center, if needed
|
||||||
if (m_units == EUnits::Inches)
|
if (m_units == EUnits::Inches)
|
||||||
@ -2740,15 +2767,6 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
|||||||
// arc center
|
// arc center
|
||||||
arc.center = arc.start + rel_center.cast<double>();
|
arc.center = arc.start + rel_center.cast<double>();
|
||||||
|
|
||||||
const float filament_diameter = (static_cast<size_t>(m_extruder_id) < m_result.filament_diameters.size()) ? m_result.filament_diameters[m_extruder_id] : m_result.filament_diameters.back();
|
|
||||||
const float filament_radius = 0.5f * filament_diameter;
|
|
||||||
const float area_filament_cross_section = static_cast<float>(M_PI) * sqr(filament_radius);
|
|
||||||
|
|
||||||
AxisCoords end_position = m_start_position;
|
|
||||||
for (unsigned char a = X; a <= E; ++a) {
|
|
||||||
end_position[a] = extract_absolute_position_on_axis((Axis)a, line, double(area_filament_cross_section));
|
|
||||||
}
|
|
||||||
|
|
||||||
// arc end endpoint
|
// arc end endpoint
|
||||||
arc.end = Vec3d(end_position[X], end_position[Y], end_position[Z]);
|
arc.end = Vec3d(end_position[X], end_position[Y], end_position[Z]);
|
||||||
|
|
||||||
@ -2757,6 +2775,8 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc
|
|||||||
// what to do ???
|
// what to do ???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(fitting != EFitting::R || std::abs(radius - arc.start_radius()) < EPSILON);
|
||||||
|
|
||||||
// updates feedrate from line
|
// updates feedrate from line
|
||||||
std::optional<float> feedrate;
|
std::optional<float> feedrate;
|
||||||
if (line.has_f())
|
if (line.has_f())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user