Completed adapting plater behavior to new Print object API
This commit is contained in:
parent
916a0a0e58
commit
15235699e4
3 changed files with 56 additions and 23 deletions
|
@ -223,7 +223,7 @@ sub new {
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->_update_bed_size;
|
$self->_update_bed_size;
|
||||||
$self->recenter;
|
$self->update;
|
||||||
|
|
||||||
{
|
{
|
||||||
my $presets;
|
my $presets;
|
||||||
|
@ -432,7 +432,7 @@ sub object_loaded {
|
||||||
|
|
||||||
$self->make_thumbnail($obj_idx);
|
$self->make_thumbnail($obj_idx);
|
||||||
$self->arrange unless $params{no_arrange};
|
$self->arrange unless $params{no_arrange};
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{list}->Update;
|
$self->{list}->Update;
|
||||||
$self->{list}->Select($obj_idx, 1);
|
$self->{list}->Select($obj_idx, 1);
|
||||||
$self->object_list_changed;
|
$self->object_list_changed;
|
||||||
|
@ -454,7 +454,7 @@ sub remove {
|
||||||
$self->object_list_changed;
|
$self->object_list_changed;
|
||||||
|
|
||||||
$self->select_object(undef);
|
$self->select_object(undef);
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ sub decrease {
|
||||||
$self->{list}->Select($obj_idx, 0);
|
$self->{list}->Select($obj_idx, 0);
|
||||||
$self->{list}->Select($obj_idx, 1);
|
$self->{list}->Select($obj_idx, 1);
|
||||||
}
|
}
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ sub rotate {
|
||||||
$object->transform_thumbnail($self->{model}, $obj_idx);
|
$object->transform_thumbnail($self->{model}, $obj_idx);
|
||||||
}
|
}
|
||||||
$self->selection_changed; # refresh info (size etc.)
|
$self->selection_changed; # refresh info (size etc.)
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ sub arrange {
|
||||||
};
|
};
|
||||||
# ignore arrange warnings on purpose
|
# ignore arrange warnings on purpose
|
||||||
|
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,8 +733,8 @@ sub export_gcode2 {
|
||||||
} if $Slic3r::have_threads;
|
} if $Slic3r::have_threads;
|
||||||
|
|
||||||
my $print = $self->{print};
|
my $print = $self->{print};
|
||||||
$print->config->apply($config);
|
$print->apply_config($config);
|
||||||
$print->extra_variables($extra_variables);
|
$print->apply_extra_variables($extra_variables);
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
$print->config->validate;
|
$print->config->validate;
|
||||||
|
@ -746,10 +746,10 @@ sub export_gcode2 {
|
||||||
|
|
||||||
$print->status_cb(sub { $params{progressbar}->(@_) });
|
$print->status_cb(sub { $params{progressbar}->(@_) });
|
||||||
if ($params{export_svg}) {
|
if ($params{export_svg}) {
|
||||||
$print->export_svg(%params);
|
$print->export_svg(output_file => $output_file);
|
||||||
} else {
|
} else {
|
||||||
$print->process;
|
$print->process;
|
||||||
$print->export_gcode(%params);
|
$print->export_gcode(output_file => $output_file);
|
||||||
}
|
}
|
||||||
$print->status_cb(undef);
|
$print->status_cb(undef);
|
||||||
Slic3r::GUI::warning_catcher($self, $Slic3r::have_threads ? sub {
|
Slic3r::GUI::warning_catcher($self, $Slic3r::have_threads ? sub {
|
||||||
|
@ -849,7 +849,7 @@ sub on_thumbnail_made {
|
||||||
my ($obj_idx) = @_;
|
my ($obj_idx) = @_;
|
||||||
|
|
||||||
$self->{objects}[$obj_idx]->transform_thumbnail($self->{model}, $obj_idx);
|
$self->{objects}[$obj_idx]->transform_thumbnail($self->{model}, $obj_idx);
|
||||||
$self->recenter;
|
$self->update;
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,10 +863,19 @@ sub clean_instance_thumbnails {
|
||||||
|
|
||||||
# this method gets called whenever print center is changed or the objects' bounding box changes
|
# this method gets called whenever print center is changed or the objects' bounding box changes
|
||||||
# (i.e. when an object is added/removed/moved/rotated/scaled)
|
# (i.e. when an object is added/removed/moved/rotated/scaled)
|
||||||
sub recenter {
|
sub update {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->{model}->center_instances_around_point($self->{config}->print_center);
|
$self->{model}->center_instances_around_point($self->{config}->print_center);
|
||||||
|
|
||||||
|
# sync model and print object instances
|
||||||
|
for my $obj_idx (0..$#{$self->{objects}}) {
|
||||||
|
my $model_object = $self->{model}->objects->[$obj_idx];
|
||||||
|
my $print_object = $self->{print}->objects->[$obj_idx];
|
||||||
|
|
||||||
|
$print_object->delete_all_copies;
|
||||||
|
$print_object->add_copy(@{$_->offset}) for @{$model_object->instances};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub on_config_change {
|
sub on_config_change {
|
||||||
|
@ -892,7 +901,7 @@ sub on_config_change {
|
||||||
} elsif ($self->{config}->has($opt_key)) {
|
} elsif ($self->{config}->has($opt_key)) {
|
||||||
$self->{config}->set($opt_key, $value);
|
$self->{config}->set($opt_key, $value);
|
||||||
$self->_update_bed_size if $opt_key eq 'bed_size';
|
$self->_update_bed_size if $opt_key eq 'bed_size';
|
||||||
$self->recenter if $opt_key eq 'print_center';
|
$self->update if $opt_key eq 'print_center';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +913,7 @@ sub _update_bed_size {
|
||||||
# when the canvas is not rendered yet, its GetSize() method returns 0,0
|
# when the canvas is not rendered yet, its GetSize() method returns 0,0
|
||||||
# scaling_factor is expressed in pixel / mm
|
# scaling_factor is expressed in pixel / mm
|
||||||
$self->{scaling_factor} = CANVAS_SIZE->[X] / max(@{ $self->{config}->bed_size });
|
$self->{scaling_factor} = CANVAS_SIZE->[X] / max(@{ $self->{config}->bed_size });
|
||||||
$self->recenter;
|
$self->update;
|
||||||
}
|
}
|
||||||
|
|
||||||
# this is called on the canvas
|
# this is called on the canvas
|
||||||
|
@ -992,7 +1001,7 @@ sub repaint {
|
||||||
|
|
||||||
# if sequential printing is enabled and we have more than one object, draw clearance area
|
# if sequential printing is enabled and we have more than one object, draw clearance area
|
||||||
if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{model}->objects}) > 1) {
|
if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{model}->objects}) > 1) {
|
||||||
my ($clearance) = @{offset([$thumbnail->convex_hull], (scale($parent->{config}->extruder_clearance_radius) / 2), 0.0001, JT_ROUND)};
|
my ($clearance) = @{offset([$thumbnail->convex_hull], (scale($parent->{config}->extruder_clearance_radius) / 2), 1, JT_ROUND, scale(0.1))};
|
||||||
$dc->SetPen($parent->{clearance_pen});
|
$dc->SetPen($parent->{clearance_pen});
|
||||||
$dc->SetBrush($parent->{transparent_brush});
|
$dc->SetBrush($parent->{transparent_brush});
|
||||||
$dc->DrawPolygon($parent->points_to_pixel($clearance, 1), 0, 0);
|
$dc->DrawPolygon($parent->points_to_pixel($clearance, 1), 0, 0);
|
||||||
|
@ -1004,7 +1013,8 @@ sub repaint {
|
||||||
if (@{$parent->{objects}} && $parent->{config}->skirts) {
|
if (@{$parent->{objects}} && $parent->{config}->skirts) {
|
||||||
my @points = map @{$_->contour}, map @$_, map @{$_->instance_thumbnails}, @{$parent->{objects}};
|
my @points = map @{$_->contour}, map @$_, map @{$_->instance_thumbnails}, @{$parent->{objects}};
|
||||||
if (@points >= 3) {
|
if (@points >= 3) {
|
||||||
my ($convex_hull) = @{offset([convex_hull(\@points)], scale($parent->{config}->skirt_distance), 0.0001, JT_ROUND)};
|
my @o = @{Slic3r::Geometry::Clipper::simplify_polygons([convex_hull(\@points)])};
|
||||||
|
my ($convex_hull) = @{offset([convex_hull(\@points)], scale($parent->{config}->skirt_distance), 1, JT_ROUND, scale(0.1))};
|
||||||
$dc->SetPen($parent->{skirt_pen});
|
$dc->SetPen($parent->{skirt_pen});
|
||||||
$dc->SetBrush($parent->{transparent_brush});
|
$dc->SetBrush($parent->{transparent_brush});
|
||||||
$dc->DrawPolygon($parent->points_to_pixel($convex_hull, 1), 0, 0);
|
$dc->DrawPolygon($parent->points_to_pixel($convex_hull, 1), 0, 0);
|
||||||
|
@ -1041,7 +1051,7 @@ sub mouse_event {
|
||||||
}
|
}
|
||||||
$parent->Refresh;
|
$parent->Refresh;
|
||||||
} elsif ($event->ButtonUp(&Wx::wxMOUSE_BTN_LEFT)) {
|
} elsif ($event->ButtonUp(&Wx::wxMOUSE_BTN_LEFT)) {
|
||||||
$parent->recenter;
|
$parent->update;
|
||||||
$parent->Refresh;
|
$parent->Refresh;
|
||||||
$self->{drag_start_pos} = undef;
|
$self->{drag_start_pos} = undef;
|
||||||
$self->{drag_object} = undef;
|
$self->{drag_object} = undef;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX PI scale unscale move_points c
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex intersection offset
|
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex intersection offset
|
||||||
offset2 union union_pt_chained JT_ROUND JT_SQUARE);
|
offset2 union union_pt_chained JT_ROUND JT_SQUARE);
|
||||||
|
|
||||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
|
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => \&init_config);
|
||||||
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
||||||
has 'objects' => (is => 'rw', default => sub {[]});
|
has 'objects' => (is => 'rw', default => sub {[]});
|
||||||
has 'status_cb' => (is => 'rw');
|
has 'status_cb' => (is => 'rw');
|
||||||
|
@ -30,10 +30,11 @@ sub BUILD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# call this manually because the 'default' coderef doesn't trigger the trigger
|
# call this manually because the 'default' coderef doesn't trigger the trigger
|
||||||
$self->_trigger_config;
|
$self->init_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _trigger_config {
|
# this method needs to be idempotent
|
||||||
|
sub init_config {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# store config in a handy place
|
# store config in a handy place
|
||||||
|
@ -67,6 +68,14 @@ sub _trigger_config {
|
||||||
$self->config->set('retract_lift', [ map $self->config->retract_lift->[0], @{$self->config->retract_lift} ]);
|
$self->config->set('retract_lift', [ map $self->config->retract_lift->[0], @{$self->config->retract_lift} ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub apply_config {
|
||||||
|
my ($self, $config) = @_;
|
||||||
|
|
||||||
|
$self->config->apply($config);
|
||||||
|
$self->init_config;
|
||||||
|
$_->init_config for @{$self->objects};
|
||||||
|
}
|
||||||
|
|
||||||
sub _build_has_support_material {
|
sub _build_has_support_material {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return (first { $_->config->support_material } @{$self->objects})
|
return (first { $_->config->support_material } @{$self->objects})
|
||||||
|
@ -165,7 +174,7 @@ sub validate {
|
||||||
$convex_hull->translate(@{$object->_copies_shift});
|
$convex_hull->translate(@{$object->_copies_shift});
|
||||||
|
|
||||||
# grow convex hull with the clearance margin
|
# grow convex hull with the clearance margin
|
||||||
($convex_hull) = @{offset([$convex_hull], scale $self->config->extruder_clearance_radius / 2, 1, JT_ROUND)};
|
($convex_hull) = @{offset([$convex_hull], scale $self->config->extruder_clearance_radius / 2, 1, JT_ROUND, scale(0.1))};
|
||||||
|
|
||||||
# now we need that no instance of $convex_hull does not intersect any of the previously checked object instances
|
# now we need that no instance of $convex_hull does not intersect any of the previously checked object instances
|
||||||
for my $copy (@{$object->_shifted_copies}) {
|
for my $copy (@{$object->_shifted_copies}) {
|
||||||
|
@ -552,6 +561,8 @@ sub make_skirt {
|
||||||
return unless $Slic3r::Config->skirts > 0
|
return unless $Slic3r::Config->skirts > 0
|
||||||
|| ($Slic3r::Config->ooze_prevention && @{$self->extruders} > 1);
|
|| ($Slic3r::Config->ooze_prevention && @{$self->extruders} > 1);
|
||||||
|
|
||||||
|
$self->skirt->clear; # method must be idempotent
|
||||||
|
|
||||||
# collect points from all layers contained in skirt height
|
# collect points from all layers contained in skirt height
|
||||||
my @points = ();
|
my @points = ();
|
||||||
foreach my $obj_idx (0 .. $#{$self->objects}) {
|
foreach my $obj_idx (0 .. $#{$self->objects}) {
|
||||||
|
@ -587,7 +598,7 @@ sub make_skirt {
|
||||||
my $distance = scale $Slic3r::Config->skirt_distance;
|
my $distance = scale $Slic3r::Config->skirt_distance;
|
||||||
for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) {
|
for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) {
|
||||||
$distance += scale $spacing;
|
$distance += scale $spacing;
|
||||||
my $loop = offset([$convex_hull], $distance, 0.0001, JT_ROUND)->[0];
|
my $loop = offset([$convex_hull], $distance, 1, JT_ROUND, scale(0.1))->[0];
|
||||||
$self->skirt->append(Slic3r::ExtrusionLoop->new(
|
$self->skirt->append(Slic3r::ExtrusionLoop->new(
|
||||||
polygon => Slic3r::Polygon->new(@$loop),
|
polygon => Slic3r::Polygon->new(@$loop),
|
||||||
role => EXTR_ROLE_SKIRT,
|
role => EXTR_ROLE_SKIRT,
|
||||||
|
@ -615,6 +626,8 @@ sub make_brim {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return unless $Slic3r::Config->brim_width > 0;
|
return unless $Slic3r::Config->brim_width > 0;
|
||||||
|
|
||||||
|
$self->brim->clear; # method must be idempotent
|
||||||
|
|
||||||
my $flow = $self->objects->[0]->layers->[0]->regions->[0]->perimeter_flow;
|
my $flow = $self->objects->[0]->layers->[0]->regions->[0]->perimeter_flow;
|
||||||
|
|
||||||
my $grow_distance = $flow->scaled_width / 2;
|
my $grow_distance = $flow->scaled_width / 2;
|
||||||
|
@ -915,7 +928,6 @@ sub expanded_output_filepath {
|
||||||
} else {
|
} else {
|
||||||
# path is a full path to a file so we use it as it is
|
# path is a full path to a file so we use it as it is
|
||||||
}
|
}
|
||||||
|
|
||||||
return $self->config->replace_options($path, { %{$self->extra_variables}, %$extra_variables });
|
return $self->config->replace_options($path, { %{$self->extra_variables}, %$extra_variables });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,4 +940,9 @@ sub parse_filename {
|
||||||
return ($filename, $filename_base);
|
return ($filename, $filename_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub apply_extra_variables {
|
||||||
|
my ($self, $extra) = @_;
|
||||||
|
$self->extra_variables->{$_} = $extra->{$_} for keys %$extra;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -85,6 +85,12 @@ sub delete_last_copy {
|
||||||
$self->_trigger_copies;
|
$self->_trigger_copies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub delete_all_copies {
|
||||||
|
my ($self) = @_;
|
||||||
|
@{$self->copies} = ();
|
||||||
|
$self->_trigger_copies;
|
||||||
|
}
|
||||||
|
|
||||||
sub init_config {
|
sub init_config {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->config(Slic3r::Config->merge($self->print->config, $self->config_overrides));
|
$self->config(Slic3r::Config->merge($self->print->config, $self->config_overrides));
|
||||||
|
|
Loading…
Reference in a new issue