print.t 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. use Test::More tests => 6;
  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::Geometry qw(unscale X Y);
  12. use Slic3r::Test;
  13. {
  14. my $config = Slic3r::Config::new_from_defaults;
  15. my $print_center = [100,100];
  16. my $print = Slic3r::Test::init_print('20mm_cube', config => $config, print_center => $print_center);
  17. my @extrusion_points = ();
  18. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  19. my ($self, $cmd, $args, $info) = @_;
  20. if ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
  21. push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
  22. }
  23. });
  24. my $bb = Slic3r::Geometry::BoundingBox->new_from_points(\@extrusion_points);
  25. my $center = $bb->center;
  26. ok abs(unscale($center->[X]) - $print_center->[X]) < 0.005, 'print is centered around print_center (X)';
  27. ok abs(unscale($center->[Y]) - $print_center->[Y]) < 0.005, 'print is centered around print_center (Y)';
  28. }
  29. {
  30. # this represents the aggregate config from presets
  31. my $config = Slic3r::Config::new_from_defaults;
  32. # Define 4 extruders.
  33. $config->set('nozzle_diameter', [0.4, 0.4, 0.4, 0.4]);
  34. # user adds one object to the plater
  35. my $print = Slic3r::Test::init_print(my $model = Slic3r::Test::model('20mm_cube'), config => $config);
  36. # user sets a per-region option
  37. my $model2 = $model->clone;
  38. $model2->get_object(0)->config->set('fill_density', 100);
  39. $print->apply($model2, $config);
  40. is $print->print->regions->[0]->config->fill_density, 100, 'region config inherits model object config';
  41. # user exports G-code, thus the default config is reapplied
  42. $model2->get_object(0)->config->erase('fill_density');
  43. $print->apply($model2, $config);
  44. is $print->print->regions->[0]->config->fill_density, 20, 'region config is resetted';
  45. # user assigns object extruders
  46. $model2->get_object(0)->config->set('extruder', 3);
  47. $model2->get_object(0)->config->set('perimeter_extruder', 2);
  48. $print->apply($model2, $config);
  49. is $print->print->regions->[0]->config->infill_extruder, 3, 'extruder setting is correctly expanded';
  50. is $print->print->regions->[0]->config->perimeter_extruder, 2, 'extruder setting does not override explicitely specified extruders';
  51. }
  52. __END__