Skip to content

Commit

Permalink
Perl unit tests for perimeters and multi-material were rewritten to C++.
Browse files Browse the repository at this point in the history
Perl binding was slimmed down, namely Clipper is no more linked by Perl.
  • Loading branch information
bubnikv committed May 4, 2022
1 parent 7380787 commit a627614
Show file tree
Hide file tree
Showing 48 changed files with 1,194 additions and 2,310 deletions.
83 changes: 0 additions & 83 deletions lib/Slic3r.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ BEGIN {

use FindBin;

# Let the XS module know where the GUI resources reside.
set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources'));
set_var_dir(resources_dir() . "/icons");
set_local_dir(resources_dir() . "/localization/");

use Moo 1.003001;

use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
Expand Down Expand Up @@ -60,82 +55,4 @@ use constant SCALING_FACTOR => 0.000001;
$Slic3r::loglevel = (defined($ENV{'SLIC3R_LOGLEVEL'}) && $ENV{'SLIC3R_LOGLEVEL'} =~ /^[1-9]/) ? $ENV{'SLIC3R_LOGLEVEL'} : 0;
set_logging_level($Slic3r::loglevel);

# Let the palceholder parser evaluate one expression to initialize its local static macro_processor
# class instance in a thread safe manner.
Slic3r::GCode::PlaceholderParser->new->evaluate_boolean_expression('1==1');

# Open a file by converting $filename to local file system locales.
sub open {
my ($fh, $mode, $filename) = @_;
return CORE::open $$fh, $mode, encode_path($filename);
}

sub tags {
my ($format) = @_;
$format //= '';
my %tags;
# End of line
$tags{eol} = ($format eq 'html') ? '<br>' : "\n";
# Heading
$tags{h2start} = ($format eq 'html') ? '<b>' : '';
$tags{h2end} = ($format eq 'html') ? '</b>' : '';
# Bold font
$tags{bstart} = ($format eq 'html') ? '<b>' : '';
$tags{bend} = ($format eq 'html') ? '</b>' : '';
# Verbatim
$tags{vstart} = ($format eq 'html') ? '<pre>' : '';
$tags{vend} = ($format eq 'html') ? '</pre>' : '';
return %tags;
}

sub slic3r_info
{
my (%params) = @_;
my %tag = Slic3r::tags($params{format});
my $out = '';
$out .= "$tag{bstart}$Slic3r::FORK_NAME$tag{bend}$tag{eol}";
$out .= "$tag{bstart}Version: $tag{bend}$Slic3r::VERSION$tag{eol}";
$out .= "$tag{bstart}Build: $tag{bend}$Slic3r::BUILD$tag{eol}";
return $out;
}

sub copyright_info
{
my (%params) = @_;
my %tag = Slic3r::tags($params{format});
my $out =
'Copyright &copy; 2016 Vojtech Bubnik, Prusa Research. <br />' .
'Copyright &copy; 2011-2016 Alessandro Ranellucci. <br />' .
'<a href="http://slic3r.org/">Slic3r</a> is licensed under the ' .
'<a href="http://www.gnu.org/licenses/agpl-3.0.html">GNU Affero General Public License, version 3</a>.' .
'<br /><br /><br />' .
'Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Y. Sapir, Mike Sheldrake and numerous others. ' .
'Manual by Gary Hodgson. Inspired by the RepRap community. <br />' .
'Slic3r logo designed by Corey Daniels, <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon Set</a> designed by Mark James. ';
return $out;
}

sub system_info
{
my (%params) = @_;
my %tag = Slic3r::tags($params{format});

my $out = '';
$out .= "$tag{bstart}Operating System: $tag{bend}$Config{osname}$tag{eol}";
$out .= "$tag{bstart}System Architecture: $tag{bend}$Config{archname}$tag{eol}";
if ($^O eq 'MSWin32') {
$out .= "$tag{bstart}Windows Version: $tag{bend}" . `ver` . $tag{eol};
} else {
# Hopefully some kind of unix / linux.
$out .= "$tag{bstart}System Version: $tag{bend}" . `uname -a` . $tag{eol};
}
$out .= $tag{vstart} . Config::myconfig . $tag{vend};
$out .= " $tag{bstart}\@INC:$tag{bend}$tag{eol}$tag{vstart}";
foreach my $i (@INC) {
$out .= " $i\n";
}
$out .= "$tag{vend}";
return $out;
}

1;
41 changes: 0 additions & 41 deletions lib/Slic3r/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,6 @@ our $Options = print_config_def();
}
}

# From command line parameters, used by slic3r.pl
sub new_from_cli {
my $class = shift;
my %args = @_;

# Delete hash keys with undefined value.
delete $args{$_} for grep !defined $args{$_}, keys %args;

# Replace the start_gcode, end_gcode ... hash values
# with the content of the files they reference.
for (qw(start end layer toolchange)) {
my $opt_key = "${_}_gcode";
if ($args{$opt_key}) {
if (-e $args{$opt_key}) {
Slic3r::open(\my $fh, "<", $args{$opt_key})
or die "Failed to open $args{$opt_key}\n";
binmode $fh, ':utf8';
$args{$opt_key} = do { local $/; <$fh> };
close $fh;
}
}
}

my $self = $class->new;
foreach my $opt_key (keys %args) {
my $opt_def = $Options->{$opt_key};

# we use set_deserialize() for bool options since GetOpt::Long doesn't handle
# arrays of boolean values
if ($opt_key =~ /^(?:bed_shape|duplicate_grid|extruder_offset)$/ || $opt_def->{type} eq 'bool') {
$self->set_deserialize($opt_key, $args{$opt_key});
} elsif (my $shortcut = $opt_def->{shortcut}) {
$self->set($_, $args{$opt_key}) for @$shortcut;
} else {
$self->set($opt_key, $args{$opt_key});
}
}

return $self;
}

package Slic3r::Config::Static;
use parent 'Slic3r::Config';

Expand Down
7 changes: 0 additions & 7 deletions lib/Slic3r/ExPolygon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ use warnings;

# an ExPolygon is a polygon with holes

sub noncollapsing_offset_ex {
my $self = shift;
my ($distance, @params) = @_;

return $self->offset_ex($distance + 1, @params);
}

sub bounding_box {
my $self = shift;
return $self->contour->bounding_box;
Expand Down
13 changes: 0 additions & 13 deletions lib/Slic3r/Geometry/Clipper.pm

This file was deleted.

3 changes: 0 additions & 3 deletions lib/Slic3r/Layer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ sub regions {
return [ map $self->get_region($_), 0..($self->region_count-1) ];
}

package Slic3r::Layer::Support;
our @ISA = qw(Slic3r::Layer);

1;
5 changes: 0 additions & 5 deletions lib/Slic3r/Line.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ use warnings;
# a line is a two-points line
use parent 'Slic3r::Polyline';

sub grow {
my $self = shift;
return Slic3r::Polyline->new(@$self)->grow(@_);
}

1;
7 changes: 0 additions & 7 deletions lib/Slic3r/Model.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,4 @@ sub add_instance {
}
}

sub mesh_stats {
my $self = shift;

# TODO: sum values from all volumes
return $self->volumes->[0]->mesh->stats;
}

1;
7 changes: 1 addition & 6 deletions lib/Slic3r/Polygon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ use warnings;
# a polygon is a closed polyline.
use parent 'Slic3r::Polyline';

sub grow {
my $self = shift;
return $self->split_at_first_point->grow(@_);
}

1;
1;
6 changes: 0 additions & 6 deletions lib/Slic3r/Print/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ use warnings;

use List::Util qw(min max sum first);
use Slic3r::Flow ':roles';
use Slic3r::Print::State ':steps';
use Slic3r::Surface ':types';

sub layers {
my $self = shift;
return [ map $self->get_layer($_), 0..($self->layer_count - 1) ];
}

sub support_layers {
my $self = shift;
return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ];
}

1;
12 changes: 0 additions & 12 deletions lib/Slic3r/Print/State.pm

This file was deleted.

64 changes: 36 additions & 28 deletions src/libslic3r/GCodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ bool GCodeReader::parse_file_raw(const std::string &filename, raw_line_callback_
[](size_t){});
}

bool GCodeReader::GCodeLine::has(char axis) const
const char* GCodeReader::axis_pos(const char *raw_str, char axis)
{
const char *c = m_raw.c_str();
const char *c = raw_str;
// Skip the whitespaces.
c = skip_whitespaces(c);
// Skip the command.
Expand All @@ -230,40 +230,48 @@ bool GCodeReader::GCodeLine::has(char axis) const
break;
// Check the name of the axis.
if (*c == axis)
return true;
return c;
// Skip the rest of the word.
c = skip_word(c);
}
return false;
return nullptr;
}

bool GCodeReader::GCodeLine::has(char axis) const
{
const char *c = axis_pos(m_raw.c_str(), axis);
return c != nullptr;
}

bool GCodeReader::GCodeLine::has_value(char axis, float &value) const
{
assert(is_decimal_separator_point());
const char *c = m_raw.c_str();
// Skip the whitespaces.
c = skip_whitespaces(c);
// Skip the command.
c = skip_word(c);
// Up to the end of line or comment.
while (! is_end_of_gcode_line(*c)) {
// Skip whitespaces.
c = skip_whitespaces(c);
if (is_end_of_gcode_line(*c))
break;
// Check the name of the axis.
if (*c == axis) {
// Try to parse the numeric value.
char *pend = nullptr;
double v = strtod(++ c, &pend);
if (pend != nullptr && is_end_of_word(*pend)) {
// The axis value has been parsed correctly.
value = float(v);
return true;
}
}
// Skip the rest of the word.
c = skip_word(c);
const char *c = axis_pos(m_raw.c_str(), axis);
if (c == nullptr)
return false;
// Try to parse the numeric value.
char *pend = nullptr;
double v = strtod(++ c, &pend);
if (pend != nullptr && is_end_of_word(*pend)) {
// The axis value has been parsed correctly.
value = float(v);
return true;
}
return false;
}

bool GCodeReader::GCodeLine::has_value(char axis, int &value) const
{
const char *c = axis_pos(m_raw.c_str(), axis);
if (c == nullptr)
return false;
// Try to parse the numeric value.
char *pend = nullptr;
long v = strtol(++ c, &pend, 10);
if (pend != nullptr && is_end_of_word(*pend)) {
// The axis value has been parsed correctly.
value = int(v);
return true;
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/GCodeReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GCodeReader {
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;
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(); }
Expand Down Expand Up @@ -166,6 +167,7 @@ class GCodeReader {
; // silence -Wempty-body
return c;
}
static const char* axis_pos(const char *raw_str, char axis);

GCodeConfig m_config;
char m_extrusion_axis;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Polyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ BoundingBox get_extents(const Polylines &polylines)
const Point& leftmost_point(const Polylines &polylines)
{
if (polylines.empty())
throw Slic3r::InvalidArgument("leftmost_point() called on empty PolylineCollection");
throw Slic3r::InvalidArgument("leftmost_point() called on empty Polylines");
Polylines::const_iterator it = polylines.begin();
const Point *p = &it->leftmost_point();
for (++ it; it != polylines.end(); ++it) {
Expand Down
9 changes: 0 additions & 9 deletions src/libslic3r/Polyline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ class Polyline : public MultiPoint {
inline bool operator==(const Polyline &lhs, const Polyline &rhs) { return lhs.points == rhs.points; }
inline bool operator!=(const Polyline &lhs, const Polyline &rhs) { return lhs.points != rhs.points; }

// Don't use this class in production code, it is used exclusively by the Perl binding for unit tests!
#ifdef PERL_UCHAR_MIN
class PolylineCollection
{
public:
Polylines polylines;
};
#endif /* PERL_UCHAR_MIN */

extern BoundingBox get_extents(const Polyline &polyline);
extern BoundingBox get_extents(const Polylines &polylines);

Expand Down
10 changes: 10 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ class DynamicPrintConfig : public DynamicConfig
DynamicPrintConfig& operator=(DynamicPrintConfig &&rhs) noexcept { DynamicConfig::operator=(std::move(rhs)); return *this; }

static DynamicPrintConfig full_print_config();
static DynamicPrintConfig full_print_config_with(const t_config_option_key &opt_key, const std::string &str, bool append = false) {
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict(opt_key, str, append);
return config;
}
static DynamicPrintConfig full_print_config_with(std::initializer_list<SetDeserializeItem> items) {
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict(items);
return config;
}
static DynamicPrintConfig* new_from_defaults_keys(const std::vector<std::string> &keys);

// Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here.
Expand Down
Loading

0 comments on commit a627614

Please sign in to comment.