mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Enable/disable duplication controls
This commit is contained in:
		
							parent
							
								
									e58ed195fd
								
							
						
					
					
						commit
						e5abb0b9df
					
				
					 4 changed files with 30 additions and 3 deletions
				
			
		|  | @ -395,6 +395,13 @@ our $Options = { | |||
|         cli     => 'rotate=i', | ||||
|         type    => 'i', | ||||
|     }, | ||||
|     'duplicate_mode' => { | ||||
|         label   => 'Duplicate', | ||||
|         gui_only => 1, | ||||
|         type    => 'select', | ||||
|         values  => [qw(no autoarrange grid)], | ||||
|         labels  => ['No', 'Autoarrange', 'Grid'], | ||||
|     }, | ||||
|     'duplicate' => { | ||||
|         label    => 'Copies (autoarrange)', | ||||
|         cli      => 'duplicate=i', | ||||
|  | @ -459,6 +466,7 @@ sub save { | |||
|     open my $fh, '>', $file; | ||||
|     binmode $fh, ':utf8'; | ||||
|     foreach my $opt (sort keys %$Options) { | ||||
|         next if $Options->{$opt}{gui_only}; | ||||
|         my $value = get($opt); | ||||
|         $value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize}; | ||||
|         printf $fh "%s = %s\n", $opt, $value; | ||||
|  | @ -624,6 +632,8 @@ sub validate { | |||
|             || (grep !$_, @$Slic3r::duplicate_grid); | ||||
|     die "Use either --duplicate or --duplicate-grid (using both doesn't make sense)\n" | ||||
|         if $Slic3r::duplicate > 1 && $Slic3r::duplicate_grid && (grep $_ && $_ > 1, @$Slic3r::duplicate_grid); | ||||
|     $Slic3r::duplicate_mode = 'autoarrange' if $Slic3r::duplicate > 1; | ||||
|     $Slic3r::duplicate_mode = 'grid' if grep $_ && $_ > 1, @$Slic3r::duplicate_grid; | ||||
|      | ||||
|     # --duplicate-distance | ||||
|     die "Invalid value for --duplicate-distance\n" | ||||
|  |  | |||
|  | @ -8,7 +8,8 @@ use base 'Wx::StaticBoxSizer'; | |||
| 
 | ||||
| 
 | ||||
| # not very elegant, but this solution is temporary waiting for a better GUI | ||||
| our @reload_callbacks = (); | ||||
| our @reload_callbacks = (\&update_duplicate_controls); | ||||
| our %fields = ();  # $key => [$control] | ||||
| 
 | ||||
| sub new { | ||||
|     my $class = shift; | ||||
|  | @ -77,9 +78,13 @@ sub new { | |||
|                 $x_field->SetValue($value->[0]); | ||||
|                 $y_field->SetValue($value->[1]); | ||||
|             }; | ||||
|             $fields{$opt_key} = [$x_field, $y_field]; | ||||
|         } elsif ($opt->{type} eq 'select') { | ||||
|             $field = Wx::Choice->new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, $opt->{labels} || $opt->{values}); | ||||
|             EVT_CHOICE($parent, $field, sub { Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]) }); | ||||
|             EVT_CHOICE($parent, $field, sub { | ||||
|                 Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]); | ||||
|                 update_duplicate_controls() if $opt_key eq 'duplicate_mode'; | ||||
|             }); | ||||
|             push @reload_callbacks, sub { | ||||
|                 my $value = Slic3r::Config->get($opt_key); | ||||
|                 $field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}}); | ||||
|  | @ -89,6 +94,7 @@ sub new { | |||
|             die "Unsupported option type: " . $opt->{type}; | ||||
|         } | ||||
|         $grid_sizer->Add($_) for $label, $field; | ||||
|         $fields{$opt_key} ||= [$field]; | ||||
|     } | ||||
|      | ||||
|     $self->Add($grid_sizer, 0, wxEXPAND); | ||||
|  | @ -96,4 +102,12 @@ sub new { | |||
|     return $self; | ||||
| } | ||||
| 
 | ||||
| sub update_duplicate_controls { | ||||
|     my $value = Slic3r::Config->get('duplicate_mode'); | ||||
|     $_->Enable($value eq 'autoarrange') for @{$fields{duplicate}}; | ||||
|     $_->Enable($value eq 'autoarrange') for @{$fields{bed_size}}; | ||||
|     $_->Enable($value eq 'grid') for @{$fields{duplicate_grid}}; | ||||
|     $_->Enable($value ne 'no') for @{$fields{duplicate_distance}}; | ||||
| } | ||||
| 
 | ||||
| 1; | ||||
|  |  | |||
|  | @ -61,7 +61,7 @@ sub new { | |||
|         }, | ||||
|         transform => { | ||||
|             title => 'Transform', | ||||
|             options => [qw(scale rotate duplicate bed_size duplicate_grid duplicate_distance)], | ||||
|             options => [qw(scale rotate duplicate_mode duplicate bed_size duplicate_grid duplicate_distance)], | ||||
|         }, | ||||
|         gcode => { | ||||
|             title => 'Custom G-code', | ||||
|  | @ -156,6 +156,8 @@ sub new { | |||
|     $self->SetSizer($sizer); | ||||
|     $self->Layout; | ||||
|      | ||||
|     $_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks; | ||||
|      | ||||
|     return $self; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci