diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d349eb1a0..187ee84e5 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 b22d16999..3ef964339 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -577,7 +577,7 @@ bool Print::has_skirt() const || this->has_infinite_skirt(); } -void +std::string Print::validate() const { if (this->config.complete_objects) { @@ -619,7 +619,7 @@ Print::validate() const Polygon p = convex_hull; p.translate(*copy); if (intersects(a, p)) - 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."; union_(a, p, &a); } @@ -638,7 +638,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) @@ -646,16 +646,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) @@ -679,13 +679,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 d127b7ce6..7a41af302 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 @@ -203,7 +198,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 db64ef749..f8b541712 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -219,14 +219,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();