mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-01 05:01:10 -06:00
Fixes to Config and plater; also refactored the arrange() code
This commit is contained in:
parent
5b9bbe43b2
commit
c5ead0f2a6
9 changed files with 55 additions and 41 deletions
|
|
@ -78,8 +78,7 @@ sub load {
|
|||
my $ini = __PACKAGE__->read_ini($file);
|
||||
my $config = __PACKAGE__->new;
|
||||
foreach my $opt_key (keys %{$ini->{_}}) {
|
||||
print "key: $opt_key\n";
|
||||
($opt_key, my $value) = handle_legacy($opt_key, $ini->{_}{$opt_key});
|
||||
($opt_key, my $value) = _handle_legacy($opt_key, $ini->{_}{$opt_key});
|
||||
next if !defined $opt_key;
|
||||
$config->set_deserialize($opt_key, $value);
|
||||
}
|
||||
|
|
@ -103,8 +102,7 @@ sub get_value {
|
|||
: $self->get($opt_key);
|
||||
}
|
||||
|
||||
sub handle_legacy {
|
||||
my $self = shift;
|
||||
sub _handle_legacy {
|
||||
my ($opt_key, $value) = @_;
|
||||
|
||||
# handle legacy options
|
||||
|
|
|
|||
|
|
@ -591,10 +591,17 @@ sub changescale {
|
|||
sub arrange {
|
||||
my $self = shift;
|
||||
|
||||
# get the bounding box of the model area shown in the viewport
|
||||
my $bb = Slic3r::Geometry::BoundingBox->new_from_points([
|
||||
Slic3r::Point->new(@{ $self->point_to_model_units([0,0]) }),
|
||||
Slic3r::Point->new(@{ $self->point_to_model_units(CANVAS_SIZE) }),
|
||||
]);
|
||||
|
||||
eval {
|
||||
$self->{model}->arrange_objects($self->skeinpanel->config);
|
||||
$self->{model}->arrange_objects($self->skeinpanel->config->min_object_distance, $bb);
|
||||
};
|
||||
# ignore arrange warnings on purpose
|
||||
# ignore arrange failures on purpose: user has visual feedback and we don't need to warn him
|
||||
# when parts don't fit in print bed
|
||||
|
||||
$self->update(1);
|
||||
$self->{canvas}->Refresh;
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ sub quick_slice {
|
|||
foreach my $object (@{$model->objects}) {
|
||||
$object->add_instance(offset => [0,0]) if !defined $object->instances;
|
||||
}
|
||||
$model->arrange_objects($config);
|
||||
$model->arrange_objects($config->min_object_distance);
|
||||
}
|
||||
$model->center_instances_around_point($config->print_center);
|
||||
|
||||
|
|
|
|||
|
|
@ -660,7 +660,7 @@ sub douglas_peucker2 {
|
|||
}
|
||||
|
||||
sub arrange {
|
||||
my ($total_parts, $partx, $party, $areax, $areay, $dist, $Config) = @_;
|
||||
my ($total_parts, $partx, $party, $dist, $bb) = @_;
|
||||
|
||||
my $linint = sub {
|
||||
my ($value, $oldmin, $oldmax, $newmin, $newmax) = @_;
|
||||
|
|
@ -671,22 +671,19 @@ sub arrange {
|
|||
$partx += $dist;
|
||||
$party += $dist;
|
||||
|
||||
# margin needed for the skirt
|
||||
my $skirt_margin;
|
||||
if ($Config->skirts > 0) {
|
||||
my $flow = Slic3r::Flow->new(
|
||||
layer_height => $Config->get_value('first_layer_height'),
|
||||
nozzle_diameter => $Config->nozzle_diameter->[0], # TODO: actually look for the extruder used for skirt
|
||||
width => $Config->get_value('first_layer_extrusion_width'),
|
||||
);
|
||||
$skirt_margin = ($flow->spacing * $Config->skirts + $Config->skirt_distance) * 2;
|
||||
my ($areax, $areay);
|
||||
if (defined $bb) {
|
||||
my $size = $bb->size;
|
||||
($areax, $areay) = @$size[X,Y];
|
||||
} else {
|
||||
$skirt_margin = 0;
|
||||
# bogus area size, large enough not to trigger the error below
|
||||
$areax = $partx * $total_parts;
|
||||
$areay = $party * $total_parts;
|
||||
}
|
||||
|
||||
# this is how many cells we have available into which to put parts
|
||||
my $cellw = int(($areax - $skirt_margin + $dist) / $partx);
|
||||
my $cellh = int(($areay - $skirt_margin + $dist) / $party);
|
||||
my $cellw = int(($areax + $dist) / $partx);
|
||||
my $cellh = int(($areay + $dist) / $party);
|
||||
|
||||
die "$total_parts parts won't fit in your print area!\n" if $total_parts > ($cellw * $cellh);
|
||||
|
||||
|
|
@ -769,6 +766,11 @@ sub arrange {
|
|||
|
||||
push @positions, [$cx * $partx, $cy * $party];
|
||||
}
|
||||
|
||||
if (defined $bb) {
|
||||
$_->[X] += $bb->x_min for @positions;
|
||||
$_->[Y] += $bb->y_min for @positions;
|
||||
}
|
||||
return @positions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ sub duplicate_objects_grid {
|
|||
# this will append more instances to each object
|
||||
# and then automatically rearrange everything
|
||||
sub duplicate_objects {
|
||||
my ($self, $config, $copies_num) = @_;
|
||||
my ($self, $copies_num, $distance, $bb) = @_;
|
||||
|
||||
foreach my $object (@{$self->objects}) {
|
||||
my @instances = @{$object->instances};
|
||||
|
|
@ -133,13 +133,13 @@ sub duplicate_objects {
|
|||
}
|
||||
}
|
||||
|
||||
$self->arrange_objects($config);
|
||||
$self->arrange_objects($distance, $bb);
|
||||
}
|
||||
|
||||
# arrange objects preserving their instance count
|
||||
# but altering their instance positions
|
||||
sub arrange_objects {
|
||||
my ($self, $config) = @_;
|
||||
my ($self, $distance, $bb) = @_;
|
||||
|
||||
# get the (transformed) size of each instance so that we take
|
||||
# into account their different transformations when packing
|
||||
|
|
@ -148,20 +148,20 @@ sub arrange_objects {
|
|||
push @instance_sizes, map $object->instance_bounding_box($_)->size, 0..$#{$object->instances};
|
||||
}
|
||||
|
||||
my @positions = $self->_arrange($config, \@instance_sizes);
|
||||
my @positions = $self->_arrange(\@instance_sizes, $distance, $bb);
|
||||
|
||||
foreach my $object (@{$self->objects}) {
|
||||
$_->offset(shift @positions) for @{$object->instances};
|
||||
$_->offset([ @{shift @positions} ]) for @{$object->instances};
|
||||
$object->update_bounding_box;
|
||||
}
|
||||
}
|
||||
|
||||
# duplicate the entire model preserving instance relative positions
|
||||
sub duplicate {
|
||||
my ($self, $config, $copies_num) = @_;
|
||||
my ($self, $copies_num, $distance, $bb) = @_;
|
||||
|
||||
my $model_size = $self->bounding_box->size;
|
||||
my @positions = $self->_arrange($config, [ map $model_size, 2..$copies_num ]);
|
||||
my @positions = $self->_arrange([ map $model_size, 2..$copies_num ], $distance, $bb);
|
||||
|
||||
# note that this will leave the object count unaltered
|
||||
|
||||
|
|
@ -181,13 +181,15 @@ sub duplicate {
|
|||
}
|
||||
|
||||
sub _arrange {
|
||||
my ($self, $config, $sizes) = @_;
|
||||
my ($self, $sizes, $distance, $bb) = @_;
|
||||
|
||||
my $partx = max(map $_->[X], @$sizes);
|
||||
my $party = max(map $_->[Y], @$sizes);
|
||||
return Slic3r::Geometry::arrange
|
||||
(scalar(@$sizes), $partx, $party, (map $_, @{$config->bed_size}),
|
||||
$config->min_object_distance, $config);
|
||||
return Slic3r::Geometry::arrange(
|
||||
scalar(@$sizes), # number of parts
|
||||
max(map $_->[X], @$sizes), # cell width
|
||||
max(map $_->[Y], @$sizes), # cell height
|
||||
$distance, # distance between cells
|
||||
$bb, # bounding box of the area to fill (can be undef)
|
||||
);
|
||||
}
|
||||
|
||||
sub has_objects_with_no_instances {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ sub init_print {
|
|||
$model_name = [$model_name] if ref($model_name) ne 'ARRAY';
|
||||
for my $model (map model($_, %params), @$model_name) {
|
||||
die "Unknown model in test" if !defined $model;
|
||||
$model->arrange_objects($config);
|
||||
$model->arrange_objects($config->min_object_distance);
|
||||
$model->center_instances_around_point($config->print_center);
|
||||
$print->add_model_object($_) for @{$model->objects};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue