Fixed configuration & validate C++ ports.

This commit is contained in:
bubnikv 2017-10-27 16:11:06 +02:00
parent 5a99e694ce
commit 3bc79e80d5
8 changed files with 36 additions and 37 deletions

View File

@ -94,23 +94,6 @@ sub merge {
return $config; 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, $file) = @_;
# Instead of using the /i modifier for case-insensitive matching, the case insensitivity is expressed
# explicitely to avoid having to bundle the UTF8 Perl library.
if ($file =~ /\.[gG][cC][oO][dD][eE]/ || $file =~ /\.[gG]/) {
my $config = $class->new;
$config->_load_from_gcode($file);
return $config;
} else {
my $config = $class->new;
$config->_load($file);
return $config;
}
}
sub clone { sub clone {
my $self = shift; my $self = shift;
my $new = (ref $self)->new; my $new = (ref $self)->new;

View File

@ -255,13 +255,4 @@ sub make_wipe_tower {
$self->set_step_done(STEP_WIPE_TOWER); $self->set_step_done(STEP_WIPE_TOWER);
} }
# Wrapper around the C++ Slic3r::Print::validate()
# to produce a Perl exception without a hang-up on some Strawberry perls.
sub validate
{
my $self = shift;
my $err = $self->_validate;
die $err . "\n" if (defined($err) && $err ne '');
}
1; 1;

View File

@ -320,6 +320,14 @@ void ConfigBase::setenv_()
} }
void ConfigBase::load(const std::string &file) void ConfigBase::load(const std::string &file)
{
if (boost::iends_with(file, ".gcode") || boost::iends_with(file, ".g"))
this->load_from_gcode(file);
else
this->load_from_ini(file);
}
void ConfigBase::load_from_ini(const std::string &file)
{ {
namespace pt = boost::property_tree; namespace pt = boost::property_tree;
pt::ptree tree; pt::ptree tree;

View File

@ -952,6 +952,7 @@ public:
double get_abs_value(const t_config_option_key &opt_key, double ratio_over) const; double get_abs_value(const t_config_option_key &opt_key, double ratio_over) const;
void setenv_(); void setenv_();
void load(const std::string &file); void load(const std::string &file);
void load_from_ini(const std::string &file);
void load_from_gcode(const std::string &file); void load_from_gcode(const std::string &file);
void save(const std::string &file) const; void save(const std::string &file) const;

View File

@ -1825,7 +1825,7 @@ std::string FullPrintConfig::validate()
// --nozzle-diameter // --nozzle-diameter
for (double nd : this->nozzle_diameter.values) for (double nd : this->nozzle_diameter.values)
if (nd < 1) if (nd < 0.005)
return "Invalid value for --nozzle-diameter"; return "Invalid value for --nozzle-diameter";
// --perimeters // --perimeters

View File

@ -244,9 +244,8 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo
{ {
use Cwd qw(abs_path); use Cwd qw(abs_path);
use File::Basename qw(dirname); use File::Basename qw(dirname);
my $class = Slic3r::Config->new;
my $path = abs_path($0); my $path = abs_path($0);
my $config = $class->_load(dirname($path)."/inc/22_config_bad_config_options.ini"); my $config = Slic3r::Config::load(dirname($path)."/inc/22_config_bad_config_options.ini");
ok 1, 'did not crash on reading invalid items in config'; ok 1, 'did not crash on reading invalid items in config';
} }

View File

@ -38,16 +38,24 @@
void normalize(); void normalize();
%name{setenv} void setenv_(); %name{setenv} void setenv_();
double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %}; double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %};
%name{_load} void load(std::string file); static DynamicPrintConfig* load(char *path)
%name{_load_from_gcode} void load_from_gcode(std::string input_file)
%code%{ %code%{
auto config = new DynamicPrintConfig();
try { try {
THIS->load_from_gcode(input_file); config->load(path);
RETVAL = config;
} catch (std::exception& e) { } catch (std::exception& e) {
croak("Error extracting configuration from a g-code %s:\n%s\n", input_file.c_str(), e.what()); delete config;
croak("Error extracting configuration from %s:\n%s\n", path, e.what());
} }
%}; %};
void save(std::string file); void save(std::string file);
int validate() %code%{
std::string err = THIS->validate();
if (! err.empty())
croak("Configuration is not valid: %s\n", err.c_str());
RETVAL = 1;
%};
}; };
%name{Slic3r::Config::Static} class StaticPrintConfig { %name{Slic3r::Config::Static} class StaticPrintConfig {
@ -94,8 +102,18 @@
%}; %};
%name{setenv} void setenv_(); %name{setenv} void setenv_();
double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %}; double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %};
%name{_load} void load(std::string file); static StaticPrintConfig* load(char *path)
%name{_load_from_gcode} void load_from_gcode(std::string file); %code%{
auto config = new FullPrintConfig();
try {
config->load(path);
RETVAL = static_cast<PrintObjectConfig*>(config);
} catch (std::exception& e) {
delete config;
croak("Error extracting configuration from %s:\n%s\n", path, e.what());
}
%};
void save(std::string file); void save(std::string file);
}; };

View File

@ -215,8 +215,7 @@ _constant()
bool has_infinite_skirt(); bool has_infinite_skirt();
bool has_skirt(); bool has_skirt();
std::vector<unsigned int> extruders() const; std::vector<unsigned int> extruders() const;
std::string _validate() void validate() %code%{ std::string err = THIS->validate(); if (! err.empty()) throw std::exception(err.c_str()); %};
%code%{ RETVAL = THIS->validate(); %};
Clone<BoundingBox> bounding_box(); Clone<BoundingBox> bounding_box();
Clone<BoundingBox> total_bounding_box(); Clone<BoundingBox> total_bounding_box();
double skirt_first_layer_height(); double skirt_first_layer_height();