Move extrusion path gcode generation to C++ for speed.
This commit is contained in:
parent
f56206cac3
commit
4deeff995a
@ -340,35 +340,14 @@ sub extrude_path {
|
|||||||
|
|
||||||
# extrude arc or line
|
# extrude arc or line
|
||||||
$gcode .= ";_BRIDGE_FAN_START\n" if $path->is_bridge;
|
$gcode .= ";_BRIDGE_FAN_START\n" if $path->is_bridge;
|
||||||
my $gcode_comments = $self->print_config->gcode_comments;
|
my $path_length = unscale $path->length;
|
||||||
my $path_length = 0;
|
|
||||||
{
|
{
|
||||||
my $local_F = $F;
|
$gcode .= $path->gcode($self->extruder, $e, $F,
|
||||||
my $xofs = $self->shift_x - $self->extruder->extruder_offset->[X];
|
$self->shift_x - $self->extruder->extruder_offset->[X],
|
||||||
my $yofs = $self->shift_y - $self->extruder->extruder_offset->[Y];
|
$self->shift_y - $self->extruder->extruder_offset->[Y],
|
||||||
foreach my $line (@{$path->lines}) {
|
$self->_extrusion_axis,
|
||||||
$path_length += my $line_length = unscale $line->length;
|
$self->print_config->gcode_comments ? " ; $description" : "");
|
||||||
|
|
||||||
# calculate extrusion length for this line
|
|
||||||
my $E = 0;
|
|
||||||
$E = $self->extruder->extrude($e * $line_length) if $e;
|
|
||||||
|
|
||||||
# compose G-code line
|
|
||||||
my $point = $line->b;
|
|
||||||
$gcode .= sprintf "G1 X%.3f Y%.3f",
|
|
||||||
($point->x * &Slic3r::SCALING_FACTOR) + $xofs,
|
|
||||||
($point->y * &Slic3r::SCALING_FACTOR) + $yofs; #**
|
|
||||||
$gcode .= sprintf(" %s%.5f", $self->_extrusion_axis, $E)
|
|
||||||
if $E;
|
|
||||||
$gcode .= " F$local_F"
|
|
||||||
if $local_F;
|
|
||||||
$gcode .= " ; $description"
|
|
||||||
if $gcode_comments;
|
|
||||||
$gcode .= "\n";
|
|
||||||
|
|
||||||
# only include F in the first line
|
|
||||||
$local_F = 0;
|
|
||||||
}
|
|
||||||
if ($self->enable_wipe) {
|
if ($self->enable_wipe) {
|
||||||
$self->wipe_path($path->polyline->clone);
|
$self->wipe_path($path->polyline->clone);
|
||||||
$self->wipe_path->reverse;
|
$self->wipe_path->reverse;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <sstream>
|
||||||
#include "ExtrusionEntity.hpp"
|
#include "ExtrusionEntity.hpp"
|
||||||
#include "ExtrusionEntityCollection.hpp"
|
#include "ExtrusionEntityCollection.hpp"
|
||||||
#include "ExPolygonCollection.hpp"
|
#include "ExPolygonCollection.hpp"
|
||||||
@ -100,6 +101,67 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SLIC3RXS
|
||||||
|
std::string
|
||||||
|
ExtrusionPath::gcode(SV* extruder, double e, double F,
|
||||||
|
double xofs, double yofs, std::string extrusion_axis,
|
||||||
|
std::string gcode_line_suffix) const
|
||||||
|
{
|
||||||
|
dSP;
|
||||||
|
|
||||||
|
std::stringstream stream;
|
||||||
|
stream.setf(std::ios::fixed);
|
||||||
|
|
||||||
|
double local_F = F;
|
||||||
|
|
||||||
|
Lines lines = this->polyline.lines();
|
||||||
|
for (Lines::const_iterator line_it = lines.begin();
|
||||||
|
line_it != lines.end(); ++line_it)
|
||||||
|
{
|
||||||
|
const double line_length = line_it->length() * SCALING_FACTOR;
|
||||||
|
|
||||||
|
// calculate extrusion length for this line
|
||||||
|
double E = 0;
|
||||||
|
if (e != 0) {
|
||||||
|
PUSHMARK(SP);
|
||||||
|
XPUSHs(extruder);
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(e * line_length)));
|
||||||
|
PUTBACK;
|
||||||
|
|
||||||
|
const int count = call_method("extrude", G_SCALAR);
|
||||||
|
SPAGAIN;
|
||||||
|
|
||||||
|
// TODO: check that count is 1
|
||||||
|
E = POPn;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compose G-code line
|
||||||
|
|
||||||
|
Point point = line_it->b;
|
||||||
|
const double x = point.x * SCALING_FACTOR + xofs;
|
||||||
|
const double y = point.y * SCALING_FACTOR + yofs;
|
||||||
|
stream.precision(3);
|
||||||
|
stream << "G1 X" << x << " Y" << y;
|
||||||
|
|
||||||
|
if (E != 0) {
|
||||||
|
stream.precision(5);
|
||||||
|
stream << " " << extrusion_axis << E;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local_F != 0) {
|
||||||
|
stream.precision(3);
|
||||||
|
stream << " F" << local_F;
|
||||||
|
local_F = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << gcode_line_suffix;
|
||||||
|
stream << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ExtrusionLoop*
|
ExtrusionLoop*
|
||||||
ExtrusionLoop::clone() const
|
ExtrusionLoop::clone() const
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,13 @@ class ExtrusionPath : public ExtrusionEntity
|
|||||||
void clip_end(double distance);
|
void clip_end(double distance);
|
||||||
void simplify(double tolerance);
|
void simplify(double tolerance);
|
||||||
double length() const;
|
double length() const;
|
||||||
|
|
||||||
|
#ifdef SLIC3RXS
|
||||||
|
std::string gcode(SV* extruder, double e, double F,
|
||||||
|
double xofs, double yofs, std::string extrusion_axis,
|
||||||
|
std::string gcode_line_suffix) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
|
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
bool is_perimeter();
|
bool is_perimeter();
|
||||||
bool is_fill();
|
bool is_fill();
|
||||||
bool is_bridge();
|
bool is_bridge();
|
||||||
|
std::string gcode(SV* extruder, double e, double F,
|
||||||
|
double xofs, double yofs, std::string extrusion_axis,
|
||||||
|
std::string gcode_line_suffix);
|
||||||
%{
|
%{
|
||||||
|
|
||||||
ExtrusionPath*
|
ExtrusionPath*
|
||||||
|
Loading…
Reference in New Issue
Block a user