Ported GCode::travel_to() to XS
This commit is contained in:
parent
a6f4c8e567
commit
b025efe729
4 changed files with 44 additions and 38 deletions
|
@ -296,42 +296,4 @@ sub _extrude_path {
|
||||||
return $gcode;
|
return $gcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
# This method accepts $point in print coordinates.
|
|
||||||
sub travel_to {
|
|
||||||
my ($self, $point, $role, $comment) = @_;
|
|
||||||
|
|
||||||
# Define the travel move as a line between current position and the taget point.
|
|
||||||
# This is expressed in print coordinates, so it will need to be translated by
|
|
||||||
# $self->origin in order to get G-code coordinates.
|
|
||||||
my $travel = Slic3r::Polyline->new($self->last_pos, $point);
|
|
||||||
|
|
||||||
# check whether a straight travel move would need retraction
|
|
||||||
my $needs_retraction = $self->needs_retraction($travel, $role // EXTR_ROLE_NONE);
|
|
||||||
|
|
||||||
# if a retraction would be needed, try to use avoid_crossing_perimeters to plan a
|
|
||||||
# multi-hop travel path inside the configuration space
|
|
||||||
if ($needs_retraction
|
|
||||||
&& $self->config->avoid_crossing_perimeters
|
|
||||||
&& !$self->avoid_crossing_perimeters->disable_once) {
|
|
||||||
$travel = $self->avoid_crossing_perimeters->travel_to($self, $point);
|
|
||||||
|
|
||||||
# check again whether the new travel path still needs a retraction
|
|
||||||
$needs_retraction = $self->needs_retraction($travel, $role // EXTR_ROLE_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Re-allow avoid_crossing_perimeters for the next travel moves
|
|
||||||
$self->avoid_crossing_perimeters->set_disable_once(0);
|
|
||||||
$self->avoid_crossing_perimeters->set_use_external_mp_once(0);
|
|
||||||
|
|
||||||
# generate G-code for the travel move
|
|
||||||
my $gcode = "";
|
|
||||||
$gcode .= $self->retract if $needs_retraction;
|
|
||||||
|
|
||||||
# use G1 because we rely on paths being straight (G0 may make round paths)
|
|
||||||
$gcode .= $self->writer->travel_to_xy($self->point_to_gcode($_->b), $comment)
|
|
||||||
for @{$travel->lines};
|
|
||||||
|
|
||||||
return $gcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -267,6 +267,47 @@ GCode::preamble()
|
||||||
return gcode;
|
return gcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method accepts &point in print coordinates.
|
||||||
|
std::string
|
||||||
|
GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment)
|
||||||
|
{
|
||||||
|
/* Define the travel move as a line between current position and the taget point.
|
||||||
|
This is expressed in print coordinates, so it will need to be translated by
|
||||||
|
$self->origin in order to get G-code coordinates. */
|
||||||
|
Polyline travel;
|
||||||
|
travel.append(this->last_pos());
|
||||||
|
travel.append(point);
|
||||||
|
|
||||||
|
// check whether a straight travel move would need retraction
|
||||||
|
bool needs_retraction = this->needs_retraction(travel, role);
|
||||||
|
|
||||||
|
// if a retraction would be needed, try to use avoid_crossing_perimeters to plan a
|
||||||
|
// multi-hop travel path inside the configuration space
|
||||||
|
if (needs_retraction
|
||||||
|
&& this->config.avoid_crossing_perimeters
|
||||||
|
&& !this->avoid_crossing_perimeters.disable_once) {
|
||||||
|
travel = this->avoid_crossing_perimeters.travel_to(*this, point);
|
||||||
|
|
||||||
|
// check again whether the new travel path still needs a retraction
|
||||||
|
needs_retraction = this->needs_retraction(travel, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-allow avoid_crossing_perimeters for the next travel moves
|
||||||
|
this->avoid_crossing_perimeters.disable_once = false;
|
||||||
|
this->avoid_crossing_perimeters.use_external_mp_once = false;
|
||||||
|
|
||||||
|
// generate G-code for the travel move
|
||||||
|
std::string gcode;
|
||||||
|
if (needs_retraction) gcode += this->retract();
|
||||||
|
|
||||||
|
// use G1 because we rely on paths being straight (G0 may make round paths)
|
||||||
|
Lines lines = travel.lines();
|
||||||
|
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line)
|
||||||
|
gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment);
|
||||||
|
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GCode::needs_retraction(const Polyline &travel, ExtrusionRole role)
|
GCode::needs_retraction(const Polyline &travel, ExtrusionRole role)
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,6 +92,7 @@ class GCode {
|
||||||
void apply_print_config(const PrintConfig &print_config);
|
void apply_print_config(const PrintConfig &print_config);
|
||||||
void set_origin(const Pointf &pointf);
|
void set_origin(const Pointf &pointf);
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
|
std::string travel_to(const Point &point, ExtrusionRole role, std::string comment);
|
||||||
bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone);
|
bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone);
|
||||||
std::string retract(bool toolchange = false);
|
std::string retract(bool toolchange = false);
|
||||||
std::string unretract();
|
std::string unretract();
|
||||||
|
|
|
@ -157,6 +157,8 @@
|
||||||
void set_origin(Pointf* pointf)
|
void set_origin(Pointf* pointf)
|
||||||
%code{% THIS->set_origin(*pointf); %};
|
%code{% THIS->set_origin(*pointf); %};
|
||||||
std::string preamble();
|
std::string preamble();
|
||||||
|
std::string travel_to(Point* point, ExtrusionRole role, std::string comment)
|
||||||
|
%code{% RETVAL = THIS->travel_to(*point, role, comment); %};
|
||||||
bool needs_retraction(Polyline* travel, ExtrusionRole role = erNone)
|
bool needs_retraction(Polyline* travel, ExtrusionRole role = erNone)
|
||||||
%code{% RETVAL = THIS->needs_retraction(*travel, role); %};
|
%code{% RETVAL = THIS->needs_retraction(*travel, role); %};
|
||||||
std::string retract(bool toolchange = false);
|
std::string retract(bool toolchange = false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue