diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d349eb1a05..187ee84e50 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -450,4 +450,13 @@ sub expanded_output_filepath { return $self->placeholder_parser->process($path); } +# 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; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 42827e6e99..c97ca30f0e 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -576,7 +576,7 @@ bool Print::has_skirt() const || this->has_infinite_skirt(); } -void +std::string Print::validate() const { if (this->config.complete_objects) { @@ -614,7 +614,7 @@ Print::validate() const Polygon p = convex_hull; p.translate(*copy); if (!intersection(a, p).empty()) - throw PrintValidationException("Some objects are too close; your extruder will collide with them."); + return "Some objects are too close; your extruder will collide with them."; a = union_(a, p); } @@ -633,7 +633,7 @@ Print::validate() const // it will be printed as last one so its height doesn't matter object_height.pop_back(); if (!object_height.empty() && object_height.back() > scale_(this->config.extruder_clearance_height.value)) - throw PrintValidationException("Some objects are too tall and cannot be printed without extruder collisions."); + return "Some objects are too tall and cannot be printed without extruder collisions."; } } // end if (this->config.complete_objects) @@ -641,16 +641,16 @@ Print::validate() const size_t total_copies_count = 0; FOREACH_OBJECT(this, i_object) total_copies_count += (*i_object)->copies().size(); if (total_copies_count > 1) - throw PrintValidationException("The Spiral Vase option can only be used when printing a single object."); + return "The Spiral Vase option can only be used when printing a single object."; if (this->regions.size() > 1) - throw PrintValidationException("The Spiral Vase option can only be used when printing single material objects."); + return "The Spiral Vase option can only be used when printing single material objects."; } { // find the smallest nozzle diameter std::set extruders = this->extruders(); if (extruders.empty()) - throw PrintValidationException("The supplied settings will cause an empty print."); + return "The supplied settings will cause an empty print."; std::set nozzle_diameters; for (std::set::iterator it = extruders.begin(); it != extruders.end(); ++it) @@ -674,13 +674,15 @@ Print::validate() const first_layer_min_nozzle_diameter = min_nozzle_diameter; } if (first_layer_height > first_layer_min_nozzle_diameter) - throw PrintValidationException("First layer height can't be greater than nozzle diameter"); + return "First layer height can't be greater than nozzle diameter"; // validate layer_height if (object->config.layer_height.value > min_nozzle_diameter) - throw PrintValidationException("Layer height can't be greater than nozzle diameter"); + return "Layer height can't be greater than nozzle diameter"; } } + + return std::string(); } // the bounding box of objects placed in copies position diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index a2a5ba7b4c..56ff11fe5b 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -4,7 +4,7 @@ #include "libslic3r.h" #include #include -#include +#include #include "BoundingBox.hpp" #include "Flow.hpp" #include "PrintConfig.hpp" @@ -29,11 +29,6 @@ enum PrintObjectStep { posInfill, posSupportMaterial, }; -class PrintValidationException : public std::runtime_error { - public: - PrintValidationException(const std::string &error) : std::runtime_error(error) {}; -}; - // To be instantiated over PrintStep or PrintObjectStep enums. template class PrintState @@ -196,7 +191,8 @@ class Print bool apply_config(DynamicPrintConfig config); bool has_infinite_skirt() const; bool has_skirt() const; - void validate() const; + // Returns an empty string if valid, otherwise returns an error message. + std::string validate() const; BoundingBox bounding_box() const; BoundingBox total_bounding_box() const; double skirt_first_layer_height() const; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 27d970a5b4..9168e9d854 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -218,14 +218,8 @@ _constant() %code%{ RETVAL = THIS->apply_config(*config); %}; bool has_infinite_skirt(); bool has_skirt(); - void validate() - %code%{ - try { - THIS->validate(); - } catch (PrintValidationException &e) { - croak("%s\n", e.what()); - } - %}; + std::string _validate() + %code%{ RETVAL = THIS->validate(); %}; Clone bounding_box(); Clone total_bounding_box(); double skirt_first_layer_height();