support.t 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. use Test::More tests => 13;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. }
  8. use List::Util qw(first);
  9. use Slic3r;
  10. use Slic3r::Geometry qw(epsilon);
  11. use Slic3r::Test;
  12. {
  13. my $config = Slic3r::Config->new_from_defaults;
  14. $config->set('support_material', 1);
  15. my @contact_z = my @top_z = ();
  16. my $test = sub {
  17. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  18. $print->init_extruders;
  19. my $flow = $print->support_material_flow;
  20. my $support_z = Slic3r::Print::SupportMaterial
  21. ->new(config => $config, flow => $flow)
  22. ->support_layers_z(\@contact_z, \@top_z, $config->layer_height);
  23. is $support_z->[0], $config->first_layer_height,
  24. 'first layer height is honored';
  25. is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
  26. 'no null or negative support layers';
  27. is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $flow->nozzle_diameter + epsilon } 1..$#$support_z), 0,
  28. 'no layers thicker than nozzle diameter';
  29. my $wrong_top_spacing = 0;
  30. foreach my $top_z (@top_z) {
  31. # find layer index of this top surface
  32. my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
  33. # check that first support layer above this top surface is spaced with nozzle diameter
  34. $wrong_top_spacing = 1
  35. if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $flow->nozzle_diameter;
  36. }
  37. ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
  38. };
  39. $config->set('layer_height', 0.2);
  40. $config->set('first_layer_height', 0.3);
  41. @contact_z = (1.9);
  42. @top_z = (1.1);
  43. $test->();
  44. $config->set('first_layer_height', 0.4);
  45. $test->();
  46. $config->set('layer_height', $config->nozzle_diameter->[0]);
  47. $test->();
  48. }
  49. {
  50. my $config = Slic3r::Config->new_from_defaults;
  51. $config->set('raft_layers', 3);
  52. $config->set('brim_width', 6);
  53. $config->set('skirts', 0);
  54. $config->set('support_material_extruder', 2);
  55. $config->set('support_material_interface_extruder', 2);
  56. $config->set('layer_height', 0.4);
  57. $config->set('first_layer_height', '100%');
  58. my $print = Slic3r::Test::init_print('overhang', config => $config);
  59. ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
  60. my $tool = 0;
  61. Slic3r::GCode::Reader->new->parse($gcode, sub {
  62. my ($self, $cmd, $args, $info) = @_;
  63. if ($cmd =~ /^T(\d+)/) {
  64. $tool = $1;
  65. } elsif ($info->{extruding}) {
  66. if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
  67. fail 'not extruding raft/brim with support material extruder'
  68. if $tool != ($config->support_material_extruder-1);
  69. } else {
  70. fail 'support material exceeds raft layers'
  71. if $tool == $config->support_material_extruder-1;
  72. # TODO: we should test that full support is generated when we use raft too
  73. }
  74. }
  75. });
  76. }
  77. __END__