diff options
author | bubnikv <bubnikv@gmail.com> | 2016-11-05 04:23:46 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2016-11-05 04:23:46 +0300 |
commit | bfb336df0cb1d0f2428bb6158df586733b32a84b (patch) | |
tree | 81b321c8474adfc470e4971f8de07f09420cdd2a /xs/src | |
parent | dfa3f8d597fe294c488b85dfb41c694c73438a38 (diff) |
Refactored Print::validate() method to not throw an exception, but
to return a string with an error message instead. This was necessary
to avoid a hang-up on some Strawberry Perl distributions, when
a perl "croak" function is called after a C++ exception is caught.
Diffstat (limited to 'xs/src')
-rw-r--r-- | xs/src/libslic3r/Print.cpp | 18 | ||||
-rw-r--r-- | xs/src/libslic3r/Print.hpp | 10 |
2 files changed, 13 insertions, 15 deletions
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<size_t> 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<double> nozzle_diameters; for (std::set<size_t>::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 <set> #include <vector> -#include <stdexcept> +#include <string> #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 StepType> 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; |