mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-17 11:47:54 -06:00
Documented perl modules.
This commit is contained in:
parent
6dfe4c0b96
commit
b2a6f43923
13 changed files with 107 additions and 10 deletions
|
@ -1,3 +1,6 @@
|
|||
# Extends C++ class Slic3r::DynamicPrintConfig
|
||||
# This perl class does not keep any perl class variables,
|
||||
# all the storage is handled by the underlying C++ code.
|
||||
package Slic3r::Config;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
@ -11,6 +14,8 @@ our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_
|
|||
rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
|
||||
randomize_start seal_position bed_size print_center g0);
|
||||
|
||||
# C++ Slic3r::PrintConfigDef exported as a Perl hash of hashes.
|
||||
# The C++ counterpart is a constant singleton.
|
||||
our $Options = print_config_def();
|
||||
|
||||
# overwrite the hard-coded readonly value (this information is not available in XS)
|
||||
|
@ -24,6 +29,8 @@ $Options->{threads}{readonly} = !$Slic3r::have_threads;
|
|||
}
|
||||
}
|
||||
|
||||
# Fill in the underlying C++ Slic3r::DynamicPrintConfig with the content of the defaults
|
||||
# provided by the C++ class Slic3r::FullPrintConfig.
|
||||
sub new_from_defaults {
|
||||
my $class = shift;
|
||||
my (@opt_keys) = @_;
|
||||
|
@ -39,12 +46,16 @@ sub new_from_defaults {
|
|||
return $self;
|
||||
}
|
||||
|
||||
# From command line parameters
|
||||
sub new_from_cli {
|
||||
my $class = shift;
|
||||
my %args = @_;
|
||||
|
||||
# Delete hash keys with undefined value.
|
||||
delete $args{$_} for grep !defined $args{$_}, keys %args;
|
||||
|
||||
# Replace the start_gcode, end_gcode ... hash values
|
||||
# with the content of the files they reference.
|
||||
for (qw(start end layer toolchange)) {
|
||||
my $opt_key = "${_}_gcode";
|
||||
if ($args{$opt_key}) {
|
||||
|
@ -57,7 +68,7 @@ sub new_from_cli {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
my $self = $class->new;
|
||||
foreach my $opt_key (keys %args) {
|
||||
my $opt_def = $Options->{$opt_key};
|
||||
|
@ -83,6 +94,8 @@ sub merge {
|
|||
return $config;
|
||||
}
|
||||
|
||||
# Load a flat ini file without a category into the underlying C++ Slic3r::DynamicConfig class,
|
||||
# convert legacy configuration names.
|
||||
sub load {
|
||||
my $class = shift;
|
||||
my ($file) = @_;
|
||||
|
@ -91,6 +104,8 @@ sub load {
|
|||
return $class->load_ini_hash($ini->{_});
|
||||
}
|
||||
|
||||
# Deserialize a perl hash into the underlying C++ Slic3r::DynamicConfig class,
|
||||
# convert legacy configuration names.
|
||||
sub load_ini_hash {
|
||||
my $class = shift;
|
||||
my ($ini_hash) = @_;
|
||||
|
@ -175,6 +190,8 @@ sub _handle_legacy {
|
|||
return ($opt_key, $value);
|
||||
}
|
||||
|
||||
# Create a hash of hashes from the underlying C++ Slic3r::DynamicPrintConfig.
|
||||
# The first hash key is '_' meaning no category.
|
||||
sub as_ini {
|
||||
my ($self) = @_;
|
||||
|
||||
|
@ -186,6 +203,7 @@ sub as_ini {
|
|||
return $ini;
|
||||
}
|
||||
|
||||
# Save the content of the underlying C++ Slic3r::DynamicPrintConfig as a flat ini file without any category.
|
||||
sub save {
|
||||
my $self = shift;
|
||||
my ($file) = @_;
|
||||
|
@ -343,6 +361,7 @@ sub validate {
|
|||
|
||||
# CLASS METHODS:
|
||||
|
||||
# Write a "Windows" style ini file with categories enclosed in squre brackets.
|
||||
sub write_ini {
|
||||
my $class = shift;
|
||||
my ($file, $ini) = @_;
|
||||
|
@ -361,6 +380,10 @@ sub write_ini {
|
|||
close $fh;
|
||||
}
|
||||
|
||||
# Parse a "Windows" style ini file with categories enclosed in squre brackets.
|
||||
# Returns a hash of hashes over strings.
|
||||
# {category}{name}=value
|
||||
# Non-categorized entries are stored under a category '_'.
|
||||
sub read_ini {
|
||||
my $class = shift;
|
||||
my ($file) = @_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue