mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 20:51:12 -06:00 
			
		
		
		
	Added validation on all settings. #611
This commit is contained in:
		
							parent
							
								
									1f50d9c7e8
								
							
						
					
					
						commit
						1b6a9c0c3b
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		|  | @ -1340,6 +1340,33 @@ sub validate { | |||
|     # --extrusion-multiplier | ||||
|     die "Invalid value for --extrusion-multiplier\n" | ||||
|         if defined first { $_ <= 0 } @{$self->extrusion_multiplier}; | ||||
|      | ||||
|     # general validation, quick and dirty | ||||
|     foreach my $opt_key (keys %$Options) { | ||||
|         my $opt = $Options->{$opt_key}; | ||||
|         next unless defined $self->$opt_key; | ||||
|         next unless defined $opt->{cli} && $opt->{cli} =~ /=(.+)$/; | ||||
|         my $type = $1; | ||||
|         my @values = (); | ||||
|         if ($type =~ s/\@$//) { | ||||
|             die "Invalid value for $opt_key\n" if ref($self->$opt_key) ne 'ARRAY'; | ||||
|             @values = @{ $self->$opt_key }; | ||||
|         } else { | ||||
|             @values = ($self->$opt_key); | ||||
|         } | ||||
|         foreach my $value (@values) { | ||||
|             if ($type eq 'i' || $type eq 'f') { | ||||
|                 die "Invalid value for $opt_key\n" | ||||
|                     if ($type eq 'i' && $value !~ /^\d+$/) | ||||
|                     || ($type eq 'f' && $value !~ /^(?:\d+|\d*\.\d+)$/) | ||||
|                     || (defined $opt->{min} && $value < $opt->{min}) | ||||
|                     || (defined $opt->{max} && $value > $opt->{max}); | ||||
|             } elsif ($type eq 's' && $opt->{type} eq 'select') { | ||||
|                 die "Invalid value for $opt_key\n" | ||||
|                     unless first { $_ eq $value } @{ $opt->{values} }; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| sub replace_options { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci