layers.t 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. use Test::More tests => 5;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use local::lib "$FindBin::Bin/../local-lib";
  8. }
  9. use List::Util qw(first);
  10. use Slic3r;
  11. use Slic3r::Test qw(_eq);
  12. {
  13. my $config = Slic3r::Config::new_from_defaults;
  14. my $test = sub {
  15. my ($conf) = @_;
  16. $conf ||= $config;
  17. my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
  18. my @z = ();
  19. my @increments = ();
  20. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  21. my ($self, $cmd, $args, $info) = @_;
  22. if ($info->{dist_Z}) {
  23. push @z, 1*$args->{Z};
  24. push @increments, $info->{dist_Z};
  25. }
  26. });
  27. fail 'wrong first layer height'
  28. if $z[0] ne $config->get_value('first_layer_height') + $config->z_offset;
  29. fail 'wrong second layer height'
  30. if $z[1] ne $config->get_value('first_layer_height') + $config->get_value('layer_height') + $config->z_offset;
  31. fail 'wrong layer height'
  32. if first { !_eq($_, $config->layer_height) } @increments[1..$#increments];
  33. 1;
  34. };
  35. $config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
  36. $config->set('layer_height', 0.3);
  37. $config->set('first_layer_height', 0.2);
  38. ok $test->(), "absolute first layer height";
  39. $config->set('first_layer_height', 0.6 * $config->layer_height);
  40. ok $test->(), "relative first layer height";
  41. $config->set('z_offset', 0.9);
  42. ok $test->(), "positive Z offset";
  43. $config->set('z_offset', -0.8);
  44. ok $test->(), "negative Z offset";
  45. }
  46. {
  47. my $config = Slic3r::Config->new;
  48. $config->set('fill_density', 0); # just for making the test faster
  49. my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2);
  50. my @z = ();
  51. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  52. my ($self, $cmd, $args, $info) = @_;
  53. if ($info->{dist_Z}) {
  54. push @z, 1*$args->{Z};
  55. }
  56. });
  57. ok $z[-1] > 20*1.8 && $z[-1] < 20*2.2, 'resulting G-code has reasonable height';
  58. }
  59. __END__