Port PrintRegion::flow() and LayerRegion.flow() to XS
This commit is contained in:
parent
380dd8adfc
commit
7ff13c063f
11 changed files with 80 additions and 85 deletions
|
@ -68,7 +68,6 @@ use Slic3r::Polygon;
|
||||||
use Slic3r::Polyline;
|
use Slic3r::Polyline;
|
||||||
use Slic3r::Print;
|
use Slic3r::Print;
|
||||||
use Slic3r::Print::Object;
|
use Slic3r::Print::Object;
|
||||||
use Slic3r::Print::Region;
|
|
||||||
use Slic3r::Print::Simple;
|
use Slic3r::Print::Simple;
|
||||||
use Slic3r::Print::SupportMaterial;
|
use Slic3r::Print::SupportMaterial;
|
||||||
use Slic3r::Surface;
|
use Slic3r::Surface;
|
||||||
|
|
|
@ -209,7 +209,7 @@ sub make_fill {
|
||||||
$h,
|
$h,
|
||||||
$is_bridge,
|
$is_bridge,
|
||||||
$layerm->id == 0,
|
$layerm->id == 0,
|
||||||
undef,
|
-1,
|
||||||
$layerm->object,
|
$layerm->object,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -28,18 +28,6 @@ sub print { return $_[0]->layer->print; }
|
||||||
|
|
||||||
sub config { return $_[0]->region->config; }
|
sub config { return $_[0]->region->config; }
|
||||||
|
|
||||||
sub flow {
|
|
||||||
my ($self, $role, $bridge, $width) = @_;
|
|
||||||
return $self->region->flow(
|
|
||||||
$role,
|
|
||||||
$self->layer->height,
|
|
||||||
$bridge // 0,
|
|
||||||
$self->layer->id == 0,
|
|
||||||
$width,
|
|
||||||
$self->object,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub merge_slices {
|
sub merge_slices {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
@ -67,7 +55,7 @@ sub make_perimeters {
|
||||||
my $ext_pspacing = scale($ext_perimeter_flow->spacing_to($perimeter_flow));
|
my $ext_pspacing = scale($ext_perimeter_flow->spacing_to($perimeter_flow));
|
||||||
|
|
||||||
# overhang perimeters
|
# overhang perimeters
|
||||||
my $overhang_flow = $self->region->flow(FLOW_ROLE_PERIMETER, -1, 1, 0, undef, $self->layer->object);
|
my $overhang_flow = $self->region->flow(FLOW_ROLE_PERIMETER, -1, 1, 0, -1, $self->layer->object);
|
||||||
my $mm3_per_mm_overhang = $overhang_flow->mm3_per_mm;
|
my $mm3_per_mm_overhang = $overhang_flow->mm3_per_mm;
|
||||||
|
|
||||||
# solid infill
|
# solid infill
|
||||||
|
|
|
@ -737,20 +737,20 @@ sub write_gcode {
|
||||||
my $layer_height = $first_object->config->layer_height;
|
my $layer_height = $first_object->config->layer_height;
|
||||||
for my $region_id (0..$#{$self->regions}) {
|
for my $region_id (0..$#{$self->regions}) {
|
||||||
printf $fh "; external perimeters extrusion width = %.2fmm\n",
|
printf $fh "; external perimeters extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_EXTERNAL_PERIMETER, $layer_height, 0, 0, undef, $first_object)->width;
|
$self->regions->[$region_id]->flow(FLOW_ROLE_EXTERNAL_PERIMETER, $layer_height, 0, 0, -1, $first_object)->width;
|
||||||
printf $fh "; perimeters extrusion width = %.2fmm\n",
|
printf $fh "; perimeters extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_PERIMETER, $layer_height, 0, 0, undef, $first_object)->width;
|
$self->regions->[$region_id]->flow(FLOW_ROLE_PERIMETER, $layer_height, 0, 0, -1, $first_object)->width;
|
||||||
printf $fh "; infill extrusion width = %.2fmm\n",
|
printf $fh "; infill extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_INFILL, $layer_height, 0, 0, undef, $first_object)->width;
|
$self->regions->[$region_id]->flow(FLOW_ROLE_INFILL, $layer_height, 0, 0, -1, $first_object)->width;
|
||||||
printf $fh "; solid infill extrusion width = %.2fmm\n",
|
printf $fh "; solid infill extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_SOLID_INFILL, $layer_height, 0, 0, undef, $first_object)->width;
|
$self->regions->[$region_id]->flow(FLOW_ROLE_SOLID_INFILL, $layer_height, 0, 0, -1, $first_object)->width;
|
||||||
printf $fh "; top infill extrusion width = %.2fmm\n",
|
printf $fh "; top infill extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_TOP_SOLID_INFILL, $layer_height, 0, 0, undef, $first_object)->width;
|
$self->regions->[$region_id]->flow(FLOW_ROLE_TOP_SOLID_INFILL, $layer_height, 0, 0, -1, $first_object)->width;
|
||||||
printf $fh "; support material extrusion width = %.2fmm\n",
|
printf $fh "; support material extrusion width = %.2fmm\n",
|
||||||
$self->objects->[0]->support_material_flow->width
|
$self->objects->[0]->support_material_flow->width
|
||||||
if $self->has_support_material;
|
if $self->has_support_material;
|
||||||
printf $fh "; first layer extrusion width = %.2fmm\n",
|
printf $fh "; first layer extrusion width = %.2fmm\n",
|
||||||
$self->regions->[$region_id]->flow(FLOW_ROLE_PERIMETER, $layer_height, 0, 1, undef, $self->objects->[0])->width
|
$self->regions->[$region_id]->flow(FLOW_ROLE_PERIMETER, $layer_height, 0, 1, -1, $self->objects->[0])->width
|
||||||
if $self->regions->[$region_id]->config->first_layer_extrusion_width;
|
if $self->regions->[$region_id]->config->first_layer_extrusion_width;
|
||||||
print $fh "\n";
|
print $fh "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
package Slic3r::Print::Region;
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
|
|
||||||
use Slic3r::Extruder ':roles';
|
|
||||||
use Slic3r::Flow ':roles';
|
|
||||||
|
|
||||||
# A Print::Region object represents a group of volumes to print
|
|
||||||
# sharing the same config (including the same assigned extruder(s))
|
|
||||||
|
|
||||||
sub flow {
|
|
||||||
my ($self, $role, $layer_height, $bridge, $first_layer, $width, $object) = @_;
|
|
||||||
|
|
||||||
$bridge //= 0;
|
|
||||||
$first_layer //= 0;
|
|
||||||
|
|
||||||
# use the supplied custom width, if any
|
|
||||||
my $config_width = $width;
|
|
||||||
if (!defined $config_width) {
|
|
||||||
# get extrusion width from configuration
|
|
||||||
# (might be an absolute value, or a percent value, or zero for auto)
|
|
||||||
if ($first_layer && $self->print->config->first_layer_extrusion_width) {
|
|
||||||
$config_width = $self->print->config->first_layer_extrusion_width;
|
|
||||||
} elsif ($role == FLOW_ROLE_EXTERNAL_PERIMETER) {
|
|
||||||
$config_width = $self->config->external_perimeter_extrusion_width;
|
|
||||||
} elsif ($role == FLOW_ROLE_PERIMETER) {
|
|
||||||
$config_width = $self->config->perimeter_extrusion_width;
|
|
||||||
} elsif ($role == FLOW_ROLE_INFILL) {
|
|
||||||
$config_width = $self->config->infill_extrusion_width;
|
|
||||||
} elsif ($role == FLOW_ROLE_SOLID_INFILL) {
|
|
||||||
$config_width = $self->config->solid_infill_extrusion_width;
|
|
||||||
} elsif ($role == FLOW_ROLE_TOP_SOLID_INFILL) {
|
|
||||||
$config_width = $self->config->top_infill_extrusion_width;
|
|
||||||
} else {
|
|
||||||
die "Unknown role $role";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($config_width eq '0') {
|
|
||||||
$config_width = $object->config->extrusion_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
# get the configured nozzle_diameter for the extruder associated
|
|
||||||
# to the flow role requested
|
|
||||||
my $extruder; # 1-based
|
|
||||||
if ($role == FLOW_ROLE_PERIMETER || $role == FLOW_ROLE_EXTERNAL_PERIMETER) {
|
|
||||||
$extruder = $self->config->perimeter_extruder;
|
|
||||||
} elsif ($role == FLOW_ROLE_INFILL || $role == FLOW_ROLE_SOLID_INFILL || $role == FLOW_ROLE_TOP_SOLID_INFILL) {
|
|
||||||
$extruder = $self->config->infill_extruder;
|
|
||||||
} else {
|
|
||||||
die "Unknown role $role";
|
|
||||||
}
|
|
||||||
my $nozzle_diameter = $self->print->config->get_at('nozzle_diameter', $extruder-1);
|
|
||||||
|
|
||||||
return Slic3r::Flow->new_from_width(
|
|
||||||
width => $config_width,
|
|
||||||
role => $role,
|
|
||||||
nozzle_diameter => $nozzle_diameter,
|
|
||||||
layer_height => $layer_height,
|
|
||||||
bridge_flow_ratio => ($bridge ? $self->config->bridge_flow_ratio : 0),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
|
@ -28,6 +28,19 @@ LayerRegion::region()
|
||||||
return this->_region;
|
return this->_region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Flow
|
||||||
|
LayerRegion::flow(FlowRole role, bool bridge, double width) const
|
||||||
|
{
|
||||||
|
return this->_region->flow(
|
||||||
|
role,
|
||||||
|
this->_layer->height,
|
||||||
|
bridge,
|
||||||
|
this->_layer->id() == 0,
|
||||||
|
width,
|
||||||
|
*this->_layer->object()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
REGISTER_CLASS(LayerRegion, "Layer::Region");
|
REGISTER_CLASS(LayerRegion, "Layer::Region");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define slic3r_Layer_hpp_
|
#define slic3r_Layer_hpp_
|
||||||
|
|
||||||
#include <myinit.h>
|
#include <myinit.h>
|
||||||
|
#include "Flow.hpp"
|
||||||
#include "SurfaceCollection.hpp"
|
#include "SurfaceCollection.hpp"
|
||||||
#include "ExtrusionEntityCollection.hpp"
|
#include "ExtrusionEntityCollection.hpp"
|
||||||
#include "ExPolygonCollection.hpp"
|
#include "ExPolygonCollection.hpp"
|
||||||
|
@ -49,7 +50,9 @@ class LayerRegion
|
||||||
|
|
||||||
// ordered collection of extrusion paths to fill surfaces
|
// ordered collection of extrusion paths to fill surfaces
|
||||||
ExtrusionEntityCollection fills;
|
ExtrusionEntityCollection fills;
|
||||||
|
|
||||||
|
Flow flow(FlowRole role, bool bridge = false, double width = -1) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Layer *_layer;
|
Layer *_layer;
|
||||||
PrintRegion *_region;
|
PrintRegion *_region;
|
||||||
|
|
|
@ -60,6 +60,52 @@ PrintRegion::print()
|
||||||
return this->_print;
|
return this->_print;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Flow
|
||||||
|
PrintRegion::flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const
|
||||||
|
{
|
||||||
|
ConfigOptionFloatOrPercent config_width;
|
||||||
|
if (width != -1) {
|
||||||
|
// use the supplied custom width, if any
|
||||||
|
config_width.value = width;
|
||||||
|
config_width.percent = false;
|
||||||
|
} else {
|
||||||
|
// otherwise, get extrusion width from configuration
|
||||||
|
// (might be an absolute value, or a percent value, or zero for auto)
|
||||||
|
if (first_layer && this->_print->config.first_layer_extrusion_width.value > 0) {
|
||||||
|
config_width = this->_print->config.first_layer_extrusion_width;
|
||||||
|
} else if (role == frExternalPerimeter) {
|
||||||
|
config_width = this->config.external_perimeter_extrusion_width;
|
||||||
|
} else if (role == frPerimeter) {
|
||||||
|
config_width = this->config.perimeter_extrusion_width;
|
||||||
|
} else if (role == frInfill) {
|
||||||
|
config_width = this->config.infill_extrusion_width;
|
||||||
|
} else if (role == frSolidInfill) {
|
||||||
|
config_width = this->config.solid_infill_extrusion_width;
|
||||||
|
} else if (role == frTopSolidInfill) {
|
||||||
|
config_width = this->config.top_infill_extrusion_width;
|
||||||
|
} else {
|
||||||
|
CONFESS("Unknown role");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config_width.value == 0) {
|
||||||
|
config_width = object.config.extrusion_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the configured nozzle_diameter for the extruder associated
|
||||||
|
// to the flow role requested
|
||||||
|
size_t extruder; // 1-based
|
||||||
|
if (role == frPerimeter || role == frExternalPerimeter) {
|
||||||
|
extruder = this->config.perimeter_extruder;
|
||||||
|
} else if (role == frInfill || role == frSolidInfill || role == frTopSolidInfill) {
|
||||||
|
extruder = this->config.infill_extruder;
|
||||||
|
} else {
|
||||||
|
CONFESS("Unknown role $role");
|
||||||
|
}
|
||||||
|
double nozzle_diameter = this->_print->config.nozzle_diameter.get_at(extruder-1);
|
||||||
|
|
||||||
|
return Flow::new_from_config_width(role, config_width, nozzle_diameter, layer_height, bridge ? this->config.bridge_flow_ratio : 0);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
REGISTER_CLASS(PrintRegion, "Print::Region");
|
REGISTER_CLASS(PrintRegion, "Print::Region");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <myinit.h>
|
#include <myinit.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Flow.hpp"
|
||||||
#include "PrintConfig.hpp"
|
#include "PrintConfig.hpp"
|
||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
#include "Layer.hpp"
|
#include "Layer.hpp"
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class Print;
|
class Print;
|
||||||
|
class PrintObject;
|
||||||
class ModelObject;
|
class ModelObject;
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +49,7 @@ class PrintRegion
|
||||||
PrintRegionConfig config;
|
PrintRegionConfig config;
|
||||||
|
|
||||||
Print* print();
|
Print* print();
|
||||||
|
Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Print* _print;
|
Print* _print;
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
%code%{ RETVAL = &THIS->perimeters; %};
|
%code%{ RETVAL = &THIS->perimeters; %};
|
||||||
Ref<ExtrusionEntityCollection> fills()
|
Ref<ExtrusionEntityCollection> fills()
|
||||||
%code%{ RETVAL = &THIS->fills; %};
|
%code%{ RETVAL = &THIS->fills; %};
|
||||||
|
|
||||||
|
Flow* flow(FlowRole role, bool bridge = false, double width = -1)
|
||||||
|
%code%{ RETVAL = new Flow(THIS->flow(role, bridge, width)); %};
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Layer} class Layer {
|
%name{Slic3r::Layer} class Layer {
|
||||||
|
|
|
@ -34,6 +34,9 @@ _constant()
|
||||||
Ref<PrintRegionConfig> config()
|
Ref<PrintRegionConfig> config()
|
||||||
%code%{ RETVAL = &THIS->config; %};
|
%code%{ RETVAL = &THIS->config; %};
|
||||||
Ref<Print> print();
|
Ref<Print> print();
|
||||||
|
|
||||||
|
Flow* flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object)
|
||||||
|
%code%{ RETVAL = new Flow(THIS->flow(role, layer_height, bridge, first_layer, width, *object)); %};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue