mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 17:27:52 -06:00
Refactoring: removed _islands members in Slic3r::GCode
This commit is contained in:
parent
4925b056c2
commit
5deadc8f12
6 changed files with 44 additions and 36 deletions
|
@ -25,8 +25,6 @@ has 'enable_cooling_markers' => (is =>'rw', default => sub {0});
|
||||||
has 'layer_count' => (is => 'ro');
|
has 'layer_count' => (is => 'ro');
|
||||||
has '_layer_index' => (is => 'rw', default => sub {-1}); # just a counter
|
has '_layer_index' => (is => 'rw', default => sub {-1}); # just a counter
|
||||||
has 'layer' => (is => 'rw');
|
has 'layer' => (is => 'rw');
|
||||||
has '_layer_islands' => (is => 'rw');
|
|
||||||
has '_upper_layer_islands' => (is => 'rw');
|
|
||||||
has '_seam_position' => (is => 'ro', default => sub { {} }); # $object => pos
|
has '_seam_position' => (is => 'ro', default => sub { {} }); # $object => pos
|
||||||
has 'first_layer' => (is => 'rw', default => sub {0}); # this flag triggers first layer speeds
|
has 'first_layer' => (is => 'rw', default => sub {0}); # this flag triggers first layer speeds
|
||||||
has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds
|
has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds
|
||||||
|
@ -84,8 +82,6 @@ sub change_layer {
|
||||||
$self->first_layer($layer->id == 0);
|
$self->first_layer($layer->id == 0);
|
||||||
|
|
||||||
# avoid computing islands and overhangs if they're not needed
|
# avoid computing islands and overhangs if they're not needed
|
||||||
$self->_layer_islands($layer->islands);
|
|
||||||
$self->_upper_layer_islands($layer->upper_layer ? $layer->upper_layer->islands : []);
|
|
||||||
if ($self->config->avoid_crossing_perimeters) {
|
if ($self->config->avoid_crossing_perimeters) {
|
||||||
$self->avoid_crossing_perimeters->init_layer_mp(
|
$self->avoid_crossing_perimeters->init_layer_mp(
|
||||||
union_ex([ map @$_, @{$layer->slices} ], 1),
|
union_ex([ map @$_, @{$layer->slices} ], 1),
|
||||||
|
@ -351,9 +347,9 @@ sub travel_to {
|
||||||
if ($travel->length < scale $self->config->get_at('retract_before_travel', $self->writer->extruder->id)
|
if ($travel->length < scale $self->config->get_at('retract_before_travel', $self->writer->extruder->id)
|
||||||
|| ($self->config->only_retract_when_crossing_perimeters
|
|| ($self->config->only_retract_when_crossing_perimeters
|
||||||
&& $self->config->fill_density > 0
|
&& $self->config->fill_density > 0
|
||||||
&& (first { $_->contains_line($travel) } @{$self->_upper_layer_islands})
|
&& $self->layer->slices->contains_line($travel)
|
||||||
&& (first { $_->contains_line($travel) } @{$self->_layer_islands}))
|
&& (!$self->layer->has_upper_layer || $self->layer->upper_layer->slices->contains_line($travel)))
|
||||||
|| (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->contains_line($travel) } @{$self->layer->support_islands}))
|
|| (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && $self->layer->support_islands->contains_line($travel))
|
||||||
) {
|
) {
|
||||||
# Just perform a straight travel move without any retraction.
|
# Just perform a straight travel move without any retraction.
|
||||||
$gcode .= $self->writer->travel_to_xy($self->point_to_gcode($point), $comment);
|
$gcode .= $self->writer->travel_to_xy($self->point_to_gcode($point), $comment);
|
||||||
|
@ -608,29 +604,19 @@ sub _plan {
|
||||||
my ($self, $gcodegen, $mp, $point, $comment) = @_;
|
my ($self, $gcodegen, $mp, $point, $comment) = @_;
|
||||||
|
|
||||||
my $gcode = "";
|
my $gcode = "";
|
||||||
my @travel = @{$mp->shortest_path($gcodegen->last_pos, $point)->lines};
|
my $travel = $mp->shortest_path($gcodegen->last_pos, $point);
|
||||||
|
|
||||||
# if the path is not contained in a single island we need to retract
|
# if the path is not contained in a single island we need to retract
|
||||||
my $need_retract = !$gcodegen->config->only_retract_when_crossing_perimeters;
|
$gcode .= $gcodegen->retract
|
||||||
if (!$need_retract) {
|
if !$gcodegen->config->only_retract_when_crossing_perimeters
|
||||||
$need_retract = 1;
|
|| !$gcodegen->layer->slices->contains_polyline($travel)
|
||||||
foreach my $island (@{$gcodegen->_upper_layer_islands}) {
|
|| ($gcodegen->layer->has_upper_layer && !$gcodegen->layer->upper_layer->slices->contains_polyline($travel));
|
||||||
# discard the island if at any line is not enclosed in it
|
|
||||||
next if first { !$island->contains_line($_) } @travel;
|
|
||||||
# okay, this island encloses the full travel path
|
|
||||||
$need_retract = 0;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# perform the retraction
|
|
||||||
$gcode .= $gcodegen->retract if $need_retract;
|
|
||||||
|
|
||||||
# append the actual path and return
|
# append the actual path and return
|
||||||
# use G1 because we rely on paths being straight (G0 may make round paths)
|
# use G1 because we rely on paths being straight (G0 may make round paths)
|
||||||
$gcode .= join '',
|
$gcode .= join '',
|
||||||
map $gcodegen->writer->travel_to_xy($self->point_to_gcode($_->b), $comment),
|
map $gcodegen->writer->travel_to_xy($self->point_to_gcode($_->b), $comment),
|
||||||
@travel;
|
@{$travel->lines};
|
||||||
|
|
||||||
return $gcode;
|
return $gcode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,6 @@ sub config {
|
||||||
return $self->object->config;
|
return $self->object->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
# the purpose of this method is to be overridden for ::Support layers
|
|
||||||
sub islands {
|
|
||||||
my $self = shift;
|
|
||||||
return $self->slices;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub region {
|
sub region {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($region_id) = @_;
|
my ($region_id) = @_;
|
||||||
|
@ -120,12 +114,6 @@ sub make_perimeters {
|
||||||
}
|
}
|
||||||
|
|
||||||
package Slic3r::Layer::Support;
|
package Slic3r::Layer::Support;
|
||||||
|
|
||||||
our @ISA = qw(Slic3r::Layer);
|
our @ISA = qw(Slic3r::Layer);
|
||||||
|
|
||||||
sub islands {
|
|
||||||
my $self = shift;
|
|
||||||
return [ @{$self->slices}, @{$self->support_islands} ];
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -64,6 +64,24 @@ ExPolygonCollection::contains_point(const Point &point) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExPolygonCollection::contains_line(const Line &line) const
|
||||||
|
{
|
||||||
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
||||||
|
if (it->contains_line(line)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ExPolygonCollection::contains_polyline(const Polyline &polyline) const
|
||||||
|
{
|
||||||
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
||||||
|
if (it->contains_polyline(polyline)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ExPolygonCollection::simplify(double tolerance)
|
ExPolygonCollection::simplify(double tolerance)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <myinit.h>
|
#include <myinit.h>
|
||||||
#include "ExPolygon.hpp"
|
#include "ExPolygon.hpp"
|
||||||
|
#include "Line.hpp"
|
||||||
|
#include "Polyline.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
@ -23,6 +25,8 @@ class ExPolygonCollection
|
||||||
void translate(double x, double y);
|
void translate(double x, double y);
|
||||||
void rotate(double angle, const Point ¢er);
|
void rotate(double angle, const Point ¢er);
|
||||||
bool contains_point(const Point &point) const;
|
bool contains_point(const Point &point) const;
|
||||||
|
bool contains_line(const Line &line) const;
|
||||||
|
bool contains_polyline(const Polyline &polyline) const;
|
||||||
void simplify(double tolerance);
|
void simplify(double tolerance);
|
||||||
void convex_hull(Polygon* hull) const;
|
void convex_hull(Polygon* hull) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
%code{% RETVAL = THIS->expolygons.size(); %};
|
%code{% RETVAL = THIS->expolygons.size(); %};
|
||||||
bool contains_point(Point* point)
|
bool contains_point(Point* point)
|
||||||
%code{% RETVAL = THIS->contains_point(*point); %};
|
%code{% RETVAL = THIS->contains_point(*point); %};
|
||||||
|
bool contains_line(Line* line)
|
||||||
|
%code{% RETVAL = THIS->contains_line(*line); %};
|
||||||
|
bool contains_polyline(Polyline* polyline)
|
||||||
|
%code{% RETVAL = THIS->contains_polyline(*polyline); %};
|
||||||
void simplify(double tolerance);
|
void simplify(double tolerance);
|
||||||
Polygons polygons()
|
Polygons polygons()
|
||||||
%code{% RETVAL = *THIS; %};
|
%code{% RETVAL = *THIS; %};
|
||||||
|
|
|
@ -53,6 +53,10 @@
|
||||||
%code%{ THIS->upper_layer = layer; %};
|
%code%{ THIS->upper_layer = layer; %};
|
||||||
void set_lower_layer(Layer *layer)
|
void set_lower_layer(Layer *layer)
|
||||||
%code%{ THIS->lower_layer = layer; %};
|
%code%{ THIS->lower_layer = layer; %};
|
||||||
|
bool has_upper_layer()
|
||||||
|
%code%{ RETVAL = (THIS->upper_layer != NULL); %};
|
||||||
|
bool has_lower_layer()
|
||||||
|
%code%{ RETVAL = (THIS->lower_layer != NULL); %};
|
||||||
|
|
||||||
size_t region_count();
|
size_t region_count();
|
||||||
Ref<LayerRegion> get_region(int idx);
|
Ref<LayerRegion> get_region(int idx);
|
||||||
|
@ -99,6 +103,10 @@
|
||||||
%code%{ THIS->upper_layer = layer; %};
|
%code%{ THIS->upper_layer = layer; %};
|
||||||
void set_lower_layer(SupportLayer *layer)
|
void set_lower_layer(SupportLayer *layer)
|
||||||
%code%{ THIS->lower_layer = layer; %};
|
%code%{ THIS->lower_layer = layer; %};
|
||||||
|
bool has_upper_layer()
|
||||||
|
%code%{ RETVAL = (THIS->upper_layer != NULL); %};
|
||||||
|
bool has_lower_layer()
|
||||||
|
%code%{ RETVAL = (THIS->lower_layer != NULL); %};
|
||||||
|
|
||||||
size_t region_count();
|
size_t region_count();
|
||||||
Ref<LayerRegion> get_region(int idx);
|
Ref<LayerRegion> get_region(int idx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue