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.
This commit is contained in:
parent
dfa3f8d597
commit
bfb336df0c
@ -450,4 +450,13 @@ sub expanded_output_filepath {
|
|||||||
return $self->placeholder_parser->process($path);
|
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;
|
1;
|
||||||
|
@ -577,7 +577,7 @@ bool Print::has_skirt() const
|
|||||||
|| this->has_infinite_skirt();
|
|| this->has_infinite_skirt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
std::string
|
||||||
Print::validate() const
|
Print::validate() const
|
||||||
{
|
{
|
||||||
if (this->config.complete_objects) {
|
if (this->config.complete_objects) {
|
||||||
@ -619,7 +619,7 @@ Print::validate() const
|
|||||||
Polygon p = convex_hull;
|
Polygon p = convex_hull;
|
||||||
p.translate(*copy);
|
p.translate(*copy);
|
||||||
if (intersects(a, p))
|
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);
|
union_(a, p, &a);
|
||||||
}
|
}
|
||||||
@ -638,7 +638,7 @@ Print::validate() const
|
|||||||
// it will be printed as last one so its height doesn't matter
|
// it will be printed as last one so its height doesn't matter
|
||||||
object_height.pop_back();
|
object_height.pop_back();
|
||||||
if (!object_height.empty() && object_height.back() > scale_(this->config.extruder_clearance_height.value))
|
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)
|
} // end if (this->config.complete_objects)
|
||||||
|
|
||||||
@ -646,16 +646,16 @@ Print::validate() const
|
|||||||
size_t total_copies_count = 0;
|
size_t total_copies_count = 0;
|
||||||
FOREACH_OBJECT(this, i_object) total_copies_count += (*i_object)->copies().size();
|
FOREACH_OBJECT(this, i_object) total_copies_count += (*i_object)->copies().size();
|
||||||
if (total_copies_count > 1)
|
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)
|
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
|
// find the smallest nozzle diameter
|
||||||
std::set<size_t> extruders = this->extruders();
|
std::set<size_t> extruders = this->extruders();
|
||||||
if (extruders.empty())
|
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;
|
std::set<double> nozzle_diameters;
|
||||||
for (std::set<size_t>::iterator it = extruders.begin(); it != extruders.end(); ++it)
|
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;
|
first_layer_min_nozzle_diameter = min_nozzle_diameter;
|
||||||
}
|
}
|
||||||
if (first_layer_height > first_layer_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
|
// validate layer_height
|
||||||
if (object->config.layer_height.value > min_nozzle_diameter)
|
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
|
// the bounding box of objects placed in copies position
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "libslic3r.h"
|
#include "libslic3r.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <string>
|
||||||
#include "BoundingBox.hpp"
|
#include "BoundingBox.hpp"
|
||||||
#include "Flow.hpp"
|
#include "Flow.hpp"
|
||||||
#include "PrintConfig.hpp"
|
#include "PrintConfig.hpp"
|
||||||
@ -29,11 +29,6 @@ enum PrintObjectStep {
|
|||||||
posInfill, posSupportMaterial,
|
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.
|
// To be instantiated over PrintStep or PrintObjectStep enums.
|
||||||
template <class StepType>
|
template <class StepType>
|
||||||
class PrintState
|
class PrintState
|
||||||
@ -203,7 +198,8 @@ class Print
|
|||||||
bool apply_config(DynamicPrintConfig config);
|
bool apply_config(DynamicPrintConfig config);
|
||||||
bool has_infinite_skirt() const;
|
bool has_infinite_skirt() const;
|
||||||
bool has_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 bounding_box() const;
|
||||||
BoundingBox total_bounding_box() const;
|
BoundingBox total_bounding_box() const;
|
||||||
double skirt_first_layer_height() const;
|
double skirt_first_layer_height() const;
|
||||||
|
@ -219,14 +219,8 @@ _constant()
|
|||||||
%code%{ RETVAL = THIS->apply_config(*config); %};
|
%code%{ RETVAL = THIS->apply_config(*config); %};
|
||||||
bool has_infinite_skirt();
|
bool has_infinite_skirt();
|
||||||
bool has_skirt();
|
bool has_skirt();
|
||||||
void validate()
|
std::string _validate()
|
||||||
%code%{
|
%code%{ RETVAL = THIS->validate(); %};
|
||||||
try {
|
|
||||||
THIS->validate();
|
|
||||||
} catch (PrintValidationException &e) {
|
|
||||||
croak("%s\n", e.what());
|
|
||||||
}
|
|
||||||
%};
|
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user