Browse Source

Removed print_center option (but left --print-center from CLI)

Alessandro Ranellucci 10 years ago
parent
commit
928335f186

+ 2 - 7
lib/Slic3r/Config.pm

@@ -9,7 +9,7 @@ use List::Util qw(first max);
 our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
 our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
     adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
     adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
     rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
     rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
-    randomize_start seal_position bed_size);
+    randomize_start seal_position bed_size print_center);
 
 
 our $Options = print_config_def();
 our $Options = print_config_def();
 
 
@@ -63,7 +63,7 @@ sub new_from_cli {
         
         
         # we use set_deserialize() for bool options since GetOpt::Long doesn't handle 
         # we use set_deserialize() for bool options since GetOpt::Long doesn't handle 
         # arrays of boolean values
         # arrays of boolean values
-        if ($opt_key =~ /^(?:print_center|bed_size|duplicate_grid|extruder_offset)$/ || $opt_def->{type} eq 'bool') {
+        if ($opt_key =~ /^(?:bed_shape|duplicate_grid|extruder_offset)$/ || $opt_def->{type} eq 'bool') {
             $self->set_deserialize($opt_key, $args{$opt_key});
             $self->set_deserialize($opt_key, $args{$opt_key});
         } elsif (my $shortcut = $opt_def->{shortcut}) {
         } elsif (my $shortcut = $opt_def->{shortcut}) {
             $self->set($_, $args{$opt_key}) for @$shortcut;
             $self->set($_, $args{$opt_key}) for @$shortcut;
@@ -280,11 +280,6 @@ sub validate {
     die "--use-firmware-retraction is not compatible with --wipe\n"
     die "--use-firmware-retraction is not compatible with --wipe\n"
         if $self->use_firmware_retraction && first {$_} @{$self->wipe};
         if $self->use_firmware_retraction && first {$_} @{$self->wipe};
     
     
-    # --print-center
-    die "Invalid value for --print-center\n"
-        if !ref $self->print_center 
-            && (!$self->print_center || $self->print_center !~ /^\d+,\d+$/);
-    
     # --fill-pattern
     # --fill-pattern
     die "Invalid value for --fill-pattern\n"
     die "Invalid value for --fill-pattern\n"
         if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}};
         if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}};

+ 0 - 8
lib/Slic3r/GUI/ConfigWizard.pm

@@ -53,14 +53,6 @@ sub run {
         # it would be cleaner to have these defined inside each page class,
         # it would be cleaner to have these defined inside each page class,
         # in some event getting called before leaving the page
         # in some event getting called before leaving the page
         {
         {
-            # set print_center to center of bed_shape
-            {
-                my $bed_shape = $self->{config}->bed_shape;
-                my $polygon = Slic3r::Polygon->new_scale(@$bed_shape);
-                my $center = $polygon->centroid;
-                $self->{config}->set('print_center', [ map unscale($_), @$center ]);
-            }
-            
             # set first_layer_height + layer_height based on nozzle_diameter
             # set first_layer_height + layer_height based on nozzle_diameter
             my $nozzle = $self->{config}->nozzle_diameter;
             my $nozzle = $self->{config}->nozzle_diameter;
             $self->{config}->set('first_layer_height', $nozzle->[0]);
             $self->{config}->set('first_layer_height', $nozzle->[0]);

+ 13 - 4
lib/Slic3r/GUI/Plater.pm

@@ -50,7 +50,7 @@ sub new {
     my ($parent) = @_;
     my ($parent) = @_;
     my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
     my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
     $self->{config} = Slic3r::Config->new_from_defaults(qw(
     $self->{config} = Slic3r::Config->new_from_defaults(qw(
-        bed_shape print_center complete_objects extruder_clearance_radius skirts skirt_distance
+        bed_shape complete_objects extruder_clearance_radius skirts skirt_distance
     ));
     ));
     $self->{model} = Slic3r::Model->new;
     $self->{model} = Slic3r::Model->new;
     $self->{print} = Slic3r::Print->new;
     $self->{print} = Slic3r::Print->new;
@@ -420,6 +420,8 @@ sub load_file {
 sub load_model_objects {
 sub load_model_objects {
     my ($self, @model_objects) = @_;
     my ($self, @model_objects) = @_;
     
     
+    my $bed_centerf = $self->bed_centerf;
+    
     my $need_arrange = 0;
     my $need_arrange = 0;
     my @obj_idx = ();
     my @obj_idx = ();
     foreach my $model_object (@model_objects) {
     foreach my $model_object (@model_objects) {
@@ -436,7 +438,7 @@ sub load_model_objects {
         
         
             # add a default instance and center object around origin
             # add a default instance and center object around origin
             $o->center_around_origin;
             $o->center_around_origin;
-            $o->add_instance(offset => Slic3r::Pointf->new(@{$self->{config}->print_center}));
+            $o->add_instance(offset => $bed_centerf);
         }
         }
     
     
         $self->{print}->auto_assign_extruders($o);
         $self->{print}->auto_assign_extruders($o);
@@ -476,6 +478,14 @@ sub objects_loaded {
     $self->schedule_background_process;
     $self->schedule_background_process;
 }
 }
 
 
+sub bed_centerf {
+    my ($self) = @_;
+    
+    my $bed_shape = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape});
+    my $bed_center = $bed_shape->bounding_box->center;
+    return Slic3r::Pointf->new(unscale($bed_center->x), unscale($bed_center->y)); #)
+}
+
 sub remove {
 sub remove {
     my $self = shift;
     my $self = shift;
     my ($obj_idx) = @_;
     my ($obj_idx) = @_;
@@ -1105,7 +1115,7 @@ sub update {
     my ($self, $force_autocenter) = @_;
     my ($self, $force_autocenter) = @_;
     
     
     if ($Slic3r::GUI::Settings->{_}{autocenter} || $force_autocenter) {
     if ($Slic3r::GUI::Settings->{_}{autocenter} || $force_autocenter) {
-        $self->{model}->center_instances_around_point($self->{config}->print_center);
+        $self->{model}->center_instances_around_point($self->bed_centerf);
     }
     }
     
     
     # sync model and print object instances
     # sync model and print object instances
@@ -1147,7 +1157,6 @@ sub on_config_change {
             $self->{canvas}->update_bed_size;
             $self->{canvas}->update_bed_size;
             $self->update;
             $self->update;
         }
         }
-        $self->update if $opt_key eq 'print_center';
     }
     }
     
     
     return if !$self->GetFrame->is_loaded;
     return if !$self->GetFrame->is_loaded;

+ 7 - 3
lib/Slic3r/GUI/Plater/2D.pm

@@ -87,14 +87,14 @@ sub repaint {
     
     
     # draw print center
     # draw print center
     if (@{$self->{objects}} && $Slic3r::GUI::Settings->{_}{autocenter}) {
     if (@{$self->{objects}} && $Slic3r::GUI::Settings->{_}{autocenter}) {
-        my $center = $self->unscaled_point_to_pixel($self->{config}->print_center);
+        my $center = $self->unscaled_point_to_pixel($self->{print_center});
         $dc->SetPen($self->{print_center_pen});
         $dc->SetPen($self->{print_center_pen});
         $dc->DrawLine($center->[X], 0, $center->[X], $size[Y]);
         $dc->DrawLine($center->[X], 0, $center->[X], $size[Y]);
         $dc->DrawLine(0, $center->[Y], $size[X], $center->[Y]);
         $dc->DrawLine(0, $center->[Y], $size[X], $center->[Y]);
         $dc->SetTextForeground(Wx::Colour->new(0,0,0));
         $dc->SetTextForeground(Wx::Colour->new(0,0,0));
         $dc->SetFont(Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL));
         $dc->SetFont(Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL));
-        $dc->DrawLabel("X = " . $self->{config}->print_center->[X], Wx::Rect->new(0, 0, $center->[X]*2, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
-        $dc->DrawRotatedText("Y = " . $self->{config}->print_center->[Y], 0, $center->[Y]+15, 90);
+        $dc->DrawLabel("X = " . $self->{print_center}->[X], Wx::Rect->new(0, 0, $center->[X]*2, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
+        $dc->DrawRotatedText("Y = " . $self->{print_center}->[Y], 0, $center->[Y]+15, 90);
     }
     }
     
     
     # draw frame
     # draw frame
@@ -258,6 +258,10 @@ sub update_bed_size {
         $canvas_h - ($self->GetSize->GetHeight/2 - (unscale($bb->y_max + $bb->y_min)/2 * $self->{scaling_factor})),
         $canvas_h - ($self->GetSize->GetHeight/2 - (unscale($bb->y_max + $bb->y_min)/2 * $self->{scaling_factor})),
     ];
     ];
     
     
+    # calculate print center
+    my $center = $bb->center;
+    $self->{print_center} = [ unscale($center->x), unscale($center->y) ]; #))
+    
     # cache bed contours and grid
     # cache bed contours and grid
     {
     {
         my $step = scale 10;  # 1cm grid
         my $step = scale 10;  # 1cm grid

+ 1 - 1
lib/Slic3r/GUI/SimpleTab.pm

@@ -196,7 +196,7 @@ sub build {
     
     
     $self->append_optgroup(
     $self->append_optgroup(
         title => 'Size and coordinates',
         title => 'Size and coordinates',
-        options => [qw(bed_size print_center z_offset)],
+        options => [qw(bed_size z_offset)],
     );
     );
     
     
     $self->append_optgroup(
     $self->append_optgroup(

+ 1 - 2
lib/Slic3r/GUI/Tab.pm

@@ -704,14 +704,13 @@ sub build {
     $self->add_options_page('General', 'printer_empty.png', optgroups => [
     $self->add_options_page('General', 'printer_empty.png', optgroups => [
         {
         {
             title => 'Size and coordinates',
             title => 'Size and coordinates',
-            options => [qw(bed_shape print_center z_offset)],
+            options => [qw(bed_shape z_offset)],
             lines => [
             lines => [
                 {
                 {
                     label => 'Bed shape',
                     label => 'Bed shape',
                     widget => $bed_shape_widget,
                     widget => $bed_shape_widget,
                     options => ['bed_shape'],
                     options => ['bed_shape'],
                 },
                 },
-                Slic3r::GUI::OptionsGroup->single_option_line('print_center'),
                 Slic3r::GUI::OptionsGroup->single_option_line('z_offset'),
                 Slic3r::GUI::OptionsGroup->single_option_line('z_offset'),
             ],
             ],
         },
         },

+ 6 - 1
lib/Slic3r/Print/Simple.pm

@@ -36,6 +36,11 @@ has 'status_cb' => (
     default => sub { sub {} },
     default => sub { sub {} },
 );
 );
 
 
+has 'print_center' => (
+    is      => 'rw',
+    default => sub { [100,100] },
+);
+
 has 'output_file' => (
 has 'output_file' => (
     is      => 'rw',
     is      => 'rw',
 );
 );
@@ -63,7 +68,7 @@ sub set_model {
         # if all input objects have defined position(s) apply duplication to the whole model
         # if all input objects have defined position(s) apply duplication to the whole model
         $model->duplicate($self->duplicate, $self->_print->config->min_object_distance);
         $model->duplicate($self->duplicate, $self->_print->config->min_object_distance);
     }
     }
-    $model->center_instances_around_point($self->_print->config->print_center);
+    $model->center_instances_around_point($self->print_center);
     
     
     foreach my $model_object (@{$model->objects}) {
     foreach my $model_object (@{$model->objects}) {
         $self->_print->auto_assign_extruders($model_object);
         $self->_print->auto_assign_extruders($model_object);

+ 1 - 1
lib/Slic3r/Test.pm

@@ -156,7 +156,7 @@ sub init_print {
             $model->duplicate($params{duplicate} // 1, $print->config->min_object_distance);
             $model->duplicate($params{duplicate} // 1, $print->config->min_object_distance);
         }
         }
         $model->arrange_objects($print->config->min_object_distance);
         $model->arrange_objects($print->config->min_object_distance);
-        $model->center_instances_around_point($print->config->print_center);
+        $model->center_instances_around_point($params{print_center} // [100,100]);
         foreach my $model_object (@{$model->objects}) {
         foreach my $model_object (@{$model->objects}) {
             $print->auto_assign_extruders($model_object);
             $print->auto_assign_extruders($model_object);
             $print->add_model_object($model_object);
             $print->add_model_object($model_object);

+ 7 - 2
slic3r.pl

@@ -43,6 +43,7 @@ my %cli_options = ();
         'rotate=i'              => \$opt{rotate},
         'rotate=i'              => \$opt{rotate},
         'duplicate=i'           => \$opt{duplicate},
         'duplicate=i'           => \$opt{duplicate},
         'duplicate-grid=s'      => \$opt{duplicate_grid},
         'duplicate-grid=s'      => \$opt{duplicate_grid},
+        'print-center=s'        => \$opt{print_center},
     );
     );
     foreach my $opt_key (keys %{$Slic3r::Config::Options}) {
     foreach my $opt_key (keys %{$Slic3r::Config::Options}) {
         my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next;
         my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next;
@@ -157,12 +158,16 @@ if (@ARGV) {  # slicing from command line
         if (defined $opt{duplicate_grid}) {
         if (defined $opt{duplicate_grid}) {
             $opt{duplicate_grid} = [ split /[,x]/, $opt{duplicate_grid}, 2 ];
             $opt{duplicate_grid} = [ split /[,x]/, $opt{duplicate_grid}, 2 ];
         }
         }
+        if (defined $opt{print_center}) {
+            $opt{print_center} = [ split /[,x]/, $opt{print_center}, 2 ];
+        }
         
         
         my $sprint = Slic3r::Print::Simple->new(
         my $sprint = Slic3r::Print::Simple->new(
             scale           => $opt{scale}          // 1,
             scale           => $opt{scale}          // 1,
             rotate          => $opt{rotate}         // 0,
             rotate          => $opt{rotate}         // 0,
             duplicate       => $opt{duplicate}      // 1,
             duplicate       => $opt{duplicate}      // 1,
             duplicate_grid  => $opt{duplicate_grid} // [1,1],
             duplicate_grid  => $opt{duplicate_grid} // [1,1],
+            print_center    => $opt{print_center}   // [100,100],
             status_cb       => sub {
             status_cb       => sub {
                 my ($percent, $message) = @_;
                 my ($percent, $message) = @_;
                 printf "=> %s\n", $message;
                 printf "=> %s\n", $message;
@@ -248,8 +253,8 @@ $j
   
   
   Printer options:
   Printer options:
     --nozzle-diameter   Diameter of nozzle in mm (default: $config->{nozzle_diameter}->[0])
     --nozzle-diameter   Diameter of nozzle in mm (default: $config->{nozzle_diameter}->[0])
-    --print-center      Coordinates in mm of the point to center the print around 
-                        (default: $config->{print_center}->[0],$config->{print_center}->[1])
+    --print-center      Coordinates in mm of the point to center the print around
+                        (default: 100,100)
     --z-offset          Additional height in mm to add to vertical coordinates
     --z-offset          Additional height in mm to add to vertical coordinates
                         (+/-, default: $config->{z_offset})
                         (+/-, default: $config->{z_offset})
     --gcode-flavor      The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/no-extrusion,
     --gcode-flavor      The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/no-extrusion,

+ 4 - 4
t/print.t

@@ -14,8 +14,8 @@ use Slic3r::Test;
 
 
 {
 {
     my $config = Slic3r::Config->new_from_defaults;
     my $config = Slic3r::Config->new_from_defaults;
-    $config->set('print_center', [100,100]);
-    my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
+    my $print_center = [100,100];
+    my $print = Slic3r::Test::init_print('20mm_cube', config => $config, print_center => $print_center);
     my @extrusion_points = ();
     my @extrusion_points = ();
     Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
     Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
         my ($self, $cmd, $args, $info) = @_;
         my ($self, $cmd, $args, $info) = @_;
@@ -26,8 +26,8 @@ use Slic3r::Test;
     });
     });
     my $bb = Slic3r::Geometry::BoundingBox->new_from_points(\@extrusion_points);
     my $bb = Slic3r::Geometry::BoundingBox->new_from_points(\@extrusion_points);
     my $center = $bb->center;
     my $center = $bb->center;
-    ok abs(unscale($center->[X]) - $config->print_center->[X]) < epsilon, 'print is centered around print_center (X)';
-    ok abs(unscale($center->[Y]) - $config->print_center->[Y]) < epsilon, 'print is centered around print_center (Y)';
+    ok abs(unscale($center->[X]) - $print_center->[X]) < epsilon, 'print is centered around print_center (X)';
+    ok abs(unscale($center->[Y]) - $print_center->[Y]) < epsilon, 'print is centered around print_center (Y)';
 }
 }
 
 
 {
 {

Some files were not shown because too many files changed in this diff