Browse Source

Fixed configuration & validate C++ ports.

bubnikv 7 years ago
parent
commit
3bc79e80d5

+ 0 - 17
lib/Slic3r/Config.pm

@@ -94,23 +94,6 @@ 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, $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 {
     my $self = shift;
     my $new = (ref $self)->new;

+ 0 - 9
lib/Slic3r/Print.pm

@@ -255,13 +255,4 @@ sub make_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;

+ 8 - 0
xs/src/libslic3r/Config.cpp

@@ -320,6 +320,14 @@ void ConfigBase::setenv_()
 }
 
 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;
     pt::ptree tree;

+ 1 - 0
xs/src/libslic3r/Config.hpp

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

+ 1 - 1
xs/src/libslic3r/PrintConfig.cpp

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

+ 1 - 2
xs/t/15_config.t

@@ -244,9 +244,8 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo
 {
     use Cwd qw(abs_path);
     use File::Basename qw(dirname);
-    my $class = Slic3r::Config->new;
     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';
 }
 

+ 24 - 6
xs/xsp/Config.xsp

@@ -38,16 +38,24 @@
     void normalize();
     %name{setenv} void setenv_();
     double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %};
-    %name{_load} void load(std::string file);
-    %name{_load_from_gcode} void load_from_gcode(std::string input_file)
+    static DynamicPrintConfig* load(char *path)
         %code%{
+            auto config = new DynamicPrintConfig();
             try {
-                THIS->load_from_gcode(input_file);
+                config->load(path);
+                RETVAL = config;
             } 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);
+    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 {
@@ -94,8 +102,18 @@
         %};
     %name{setenv} void setenv_();
     double min_object_distance() %code{% RETVAL = PrintConfig::min_object_distance(THIS); %};
-    %name{_load} void load(std::string file);
-    %name{_load_from_gcode} void load_from_gcode(std::string file);
+    static StaticPrintConfig* load(char *path)
+        %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);
 };
 

+ 1 - 2
xs/xsp/Print.xsp

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