Flow.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package Slic3r::Flow;
  2. use Moo;
  3. use Slic3r::Geometry qw(PI);
  4. has 'nozzle_diameter' => (is => 'ro', required => 1);
  5. has 'layer_height' => (is => 'ro', default => sub { $Slic3r::Config->layer_height });
  6. has 'width' => (is => 'rwp', builder => 1);
  7. has 'spacing' => (is => 'lazy');
  8. sub BUILD {
  9. my $self = shift;
  10. if ($self->width =~ /^(\d+(?:\.\d+)?)%$/) {
  11. $self->_set_width($self->layer_height * $1 / 100);
  12. }
  13. $self->_set_width($self->_build_width) if $self->width == 0; # auto
  14. }
  15. sub _build_width {
  16. my $self = shift;
  17. # here we calculate a sane default by matching the flow speed (at the nozzle) and the feed rate
  18. my $volume = ($self->nozzle_diameter**2) * PI/4;
  19. my $shape_threshold = $self->nozzle_diameter * $self->layer_height + ($self->layer_height**2) * PI/4;
  20. my $width;
  21. if ($volume >= $shape_threshold) {
  22. # rectangle with semicircles at the ends
  23. $width = (($self->nozzle_diameter**2) * PI + ($self->layer_height**2) * (4 - PI)) / (4 * $self->layer_height);
  24. } else {
  25. # rectangle with squished semicircles at the ends
  26. $width = $self->nozzle_diameter * ($self->nozzle_diameter/$self->layer_height - 4/PI + 1);
  27. }
  28. my $min = $self->nozzle_diameter * 1.05;
  29. my $max = $self->nozzle_diameter * 1.4;
  30. $width = $max if $width > $max;
  31. $width = $min if $width < $min;
  32. return $width;
  33. }
  34. sub _build_spacing {
  35. my $self = shift;
  36. my $min_flow_spacing;
  37. if ($self->width >= ($self->nozzle_diameter + $self->layer_height)) {
  38. # rectangle with semicircles at the ends
  39. $min_flow_spacing = $self->width - $self->layer_height * (1 - PI/4);
  40. } else {
  41. # rectangle with shrunk semicircles at the ends
  42. $min_flow_spacing = $self->nozzle_diameter * (1 - PI/4) + $self->width * PI/4;
  43. }
  44. return $self->width - &Slic3r::OVERLAP_FACTOR * ($self->width - $min_flow_spacing);
  45. }
  46. 1;