2013-12-20 00:36:42 +00:00
|
|
|
#ifndef slic3r_Print_hpp_
|
|
|
|
#define slic3r_Print_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2018-09-17 15:17:38 +00:00
|
|
|
#include <atomic>
|
2013-12-20 00:36:42 +00:00
|
|
|
#include <set>
|
2016-11-26 11:28:39 +00:00
|
|
|
#include <vector>
|
2016-12-12 16:53:38 +00:00
|
|
|
#include <string>
|
2018-03-23 10:41:20 +00:00
|
|
|
#include <functional>
|
2014-11-30 20:58:41 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2014-08-03 17:17:23 +00:00
|
|
|
#include "Flow.hpp"
|
2014-05-06 08:07:18 +00:00
|
|
|
#include "PrintConfig.hpp"
|
|
|
|
#include "Point.hpp"
|
|
|
|
#include "Layer.hpp"
|
2014-11-09 11:25:59 +00:00
|
|
|
#include "Model.hpp"
|
2014-05-06 08:07:18 +00:00
|
|
|
#include "PlaceholderParser.hpp"
|
2016-12-12 16:53:38 +00:00
|
|
|
#include "Slicing.hpp"
|
2017-05-25 20:27:53 +00:00
|
|
|
#include "GCode/ToolOrdering.hpp"
|
|
|
|
#include "GCode/WipeTower.hpp"
|
2013-12-20 00:36:42 +00:00
|
|
|
|
2017-09-01 15:30:18 +00:00
|
|
|
#include "tbb/atomic.h"
|
2018-03-28 15:05:31 +00:00
|
|
|
// tbb/mutex.h includes Windows, which in turn defines min/max macros. Convince Windows.h to not define these min/max macros.
|
|
|
|
#ifndef NOMINMAX
|
|
|
|
#define NOMINMAX
|
|
|
|
#endif
|
|
|
|
#include "tbb/mutex.h"
|
2017-09-01 15:30:18 +00:00
|
|
|
|
2013-12-20 00:36:42 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
class Print;
|
2014-08-03 17:17:23 +00:00
|
|
|
class PrintObject;
|
2014-05-06 08:07:18 +00:00
|
|
|
class ModelObject;
|
2018-03-28 15:05:31 +00:00
|
|
|
class GCode;
|
2018-03-23 10:41:20 +00:00
|
|
|
class GCodePreviewData;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
// Print step IDs for keeping track of the print state.
|
2013-12-20 00:36:42 +00:00
|
|
|
enum PrintStep {
|
2018-03-28 15:05:31 +00:00
|
|
|
psSkirt, psBrim, psWipeTower, psGCodeExport, psCount,
|
2014-06-10 22:15:02 +00:00
|
|
|
};
|
|
|
|
enum PrintObjectStep {
|
|
|
|
posSlice, posPerimeters, posPrepareInfill,
|
2017-05-30 15:17:26 +00:00
|
|
|
posInfill, posSupportMaterial, posCount,
|
2013-12-20 00:36:42 +00:00
|
|
|
};
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
class CanceledException : public std::exception {
|
|
|
|
public:
|
|
|
|
const char* what() const throw() { return "Background processing has been canceled"; }
|
|
|
|
};
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
// To be instantiated over PrintStep or PrintObjectStep enums.
|
2017-05-30 15:17:26 +00:00
|
|
|
template <class StepType, size_t COUNT>
|
2013-12-20 00:36:42 +00:00
|
|
|
class PrintState
|
|
|
|
{
|
2017-02-07 17:17:12 +00:00
|
|
|
public:
|
2018-09-11 12:04:47 +00:00
|
|
|
PrintState() { for (size_t i = 0; i < COUNT; ++ i) m_state[i].store(INVALID, std::memory_order_relaxed); }
|
2017-05-30 15:17:26 +00:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
INVALID,
|
|
|
|
STARTED,
|
|
|
|
DONE,
|
|
|
|
};
|
2014-06-13 09:19:53 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// With full memory barrier.
|
2018-03-28 15:05:31 +00:00
|
|
|
bool is_done(StepType step) const { return m_state[step] == DONE; }
|
2018-09-11 12:04:47 +00:00
|
|
|
|
|
|
|
// Set the step as started. Block on mutex while the Print / PrintObject / PrintRegion objects are being
|
|
|
|
// modified by the UI thread.
|
2018-03-28 15:05:31 +00:00
|
|
|
// This is necessary to block until the Print::apply_config() updates its state, which may
|
|
|
|
// influence the processing step being entered.
|
2018-09-11 12:04:47 +00:00
|
|
|
void set_started(StepType step, tbb::mutex &mtx) {
|
|
|
|
mtx.lock();
|
|
|
|
m_state[step].store(STARTED, std::memory_order_relaxed);
|
|
|
|
mtx.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the step as done. Block on mutex while the Print / PrintObject / PrintRegion objects are being
|
|
|
|
// modified by the UI thread.
|
|
|
|
void set_done(StepType step, tbb::mutex &mtx) {
|
|
|
|
mtx.lock();
|
|
|
|
m_state[step].store(DONE, std::memory_order_relaxed);
|
|
|
|
mtx.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the step invalid.
|
|
|
|
// The provided mutex should be locked at this point, guarding access to m_state.
|
|
|
|
// In case the step has already been entered or finished, cancel the background
|
|
|
|
// processing by calling the cancel callback.
|
|
|
|
template<typename CancelationCallback>
|
2018-10-24 09:05:19 +00:00
|
|
|
bool invalidate(StepType step, tbb::mutex &mtx, CancelationCallback cancel) {
|
2018-09-11 12:04:47 +00:00
|
|
|
bool invalidated = m_state[step].load(std::memory_order_relaxed) != INVALID;
|
|
|
|
if (invalidated) {
|
2018-09-14 07:28:00 +00:00
|
|
|
#if 0
|
|
|
|
if (mtx.state != mtx.HELD) {
|
|
|
|
printf("Not held!\n");
|
|
|
|
}
|
|
|
|
#endif
|
2018-10-23 20:53:43 +00:00
|
|
|
// Raise the mutex, so that the following cancel() callback could cancel
|
|
|
|
// the background processing.
|
2018-09-11 12:04:47 +00:00
|
|
|
mtx.unlock();
|
|
|
|
cancel();
|
2018-10-23 13:27:31 +00:00
|
|
|
m_state[step] = INVALID;
|
2018-09-11 12:04:47 +00:00
|
|
|
mtx.lock();
|
|
|
|
}
|
2017-05-30 15:17:26 +00:00
|
|
|
return invalidated;
|
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
|
|
|
|
// Make all steps invalid.
|
|
|
|
// The provided mutex should be locked at this point, guarding access to m_state.
|
|
|
|
// In case any step has already been entered or finished, cancel the background
|
|
|
|
// processing by calling the cancel callback.
|
|
|
|
template<typename CancelationCallback>
|
2018-10-24 09:05:19 +00:00
|
|
|
bool invalidate_all(tbb::mutex &mtx, CancelationCallback cancel) {
|
2017-05-30 15:17:26 +00:00
|
|
|
bool invalidated = false;
|
|
|
|
for (size_t i = 0; i < COUNT; ++ i)
|
2018-09-11 12:04:47 +00:00
|
|
|
if (m_state[i].load(std::memory_order_relaxed) != INVALID) {
|
|
|
|
if (! invalidated) {
|
|
|
|
mtx.unlock();
|
|
|
|
cancel();
|
|
|
|
mtx.lock();
|
|
|
|
invalidated = true;
|
|
|
|
}
|
|
|
|
m_state[i].store(INVALID, std::memory_order_relaxed);
|
2017-05-30 15:17:26 +00:00
|
|
|
}
|
2017-02-07 17:17:12 +00:00
|
|
|
return invalidated;
|
|
|
|
}
|
2018-03-28 15:05:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::atomic<State> m_state[COUNT];
|
2013-12-20 00:36:42 +00:00
|
|
|
};
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
// A PrintRegion object represents a group of volumes to print
|
|
|
|
// sharing the same config (including the same assigned extruder(s))
|
|
|
|
class PrintRegion
|
|
|
|
{
|
|
|
|
friend class Print;
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// Methods NOT modifying the PrintRegion's state:
|
2017-03-28 11:25:10 +00:00
|
|
|
public:
|
2018-09-11 12:04:47 +00:00
|
|
|
const Print* print() const { return m_print; }
|
|
|
|
const PrintRegionConfig& config() const { return m_config; }
|
|
|
|
Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const;
|
2018-09-17 13:12:13 +00:00
|
|
|
// Average diameter of nozzles participating on extruding this region.
|
2018-09-11 12:04:47 +00:00
|
|
|
coordf_t nozzle_dmr_avg(const PrintConfig &print_config) const;
|
2018-09-17 13:12:13 +00:00
|
|
|
// Average diameter of nozzles participating on extruding this region.
|
2018-10-18 12:36:46 +00:00
|
|
|
coordf_t bridging_height_avg(const PrintConfig &print_config) const;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// Methods modifying the PrintRegion's state:
|
|
|
|
public:
|
|
|
|
Print* print() { return m_print; }
|
2018-10-18 12:36:46 +00:00
|
|
|
void set_config(const PrintRegionConfig &config) { m_config = config; }
|
|
|
|
void set_config(PrintRegionConfig &&config) { m_config = std::move(config); }
|
|
|
|
void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false)
|
|
|
|
{ this->m_config.apply_only(other, keys, ignore_nonexistent); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t m_refcnt;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2017-03-28 11:25:10 +00:00
|
|
|
private:
|
2018-09-11 12:04:47 +00:00
|
|
|
Print *m_print;
|
|
|
|
PrintRegionConfig m_config;
|
2015-05-31 20:04:32 +00:00
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
PrintRegion(Print* print) : m_refcnt(0), m_print(print) {}
|
|
|
|
PrintRegion(Print* print, const PrintRegionConfig &config) : m_refcnt(0), m_print(print), m_config(config) {}
|
2017-03-28 11:25:10 +00:00
|
|
|
~PrintRegion() {}
|
2014-05-06 08:07:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<Layer*> LayerPtrs;
|
|
|
|
typedef std::vector<SupportLayer*> SupportLayerPtrs;
|
|
|
|
class BoundingBoxf3; // TODO: for temporary constructor parameter
|
|
|
|
|
|
|
|
class PrintObject
|
|
|
|
{
|
|
|
|
friend class Print;
|
|
|
|
|
2016-10-13 14:00:22 +00:00
|
|
|
public:
|
2017-05-31 10:55:59 +00:00
|
|
|
// vector of (vectors of volume ids), indexed by region_id
|
|
|
|
std::vector<std::vector<int>> region_volumes;
|
2018-09-12 09:59:02 +00:00
|
|
|
t_layer_height_ranges layer_height_ranges;
|
2016-12-12 16:53:38 +00:00
|
|
|
|
|
|
|
// Profile of increasing z to a layer height, to be linearly interpolated when calculating the layers.
|
|
|
|
// The pairs of <z, layer_height> are packed into a 1D array to simplify handling by the Perl XS.
|
2017-02-09 13:56:13 +00:00
|
|
|
// layer_height_profile must not be set by the background thread.
|
2018-09-12 09:59:02 +00:00
|
|
|
std::vector<coordf_t> layer_height_profile;
|
2017-02-09 13:56:13 +00:00
|
|
|
// There is a layer_height_profile at both PrintObject and ModelObject. The layer_height_profile at the ModelObject
|
|
|
|
// is used for interactive editing and for loading / storing into a project file (AMF file as of today).
|
|
|
|
// This flag indicates that the layer_height_profile at the UI has been updated, therefore the backend needs to get it.
|
|
|
|
// This flag is necessary as we cannot safely clear the layer_height_profile if the background calculation is running.
|
2018-09-12 09:59:02 +00:00
|
|
|
bool layer_height_profile_valid;
|
2014-07-15 17:07:38 +00:00
|
|
|
|
|
|
|
// this is set to true when LayerRegion->slices is split in top/internal/bottom
|
|
|
|
// so that next call to make_perimeters() performs a union() before computing loops
|
2018-09-12 09:59:02 +00:00
|
|
|
bool typed_slices;
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
Vec3crd size; // XYZ in scaled coordinates
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
Print* print() { return m_print; }
|
|
|
|
const Print* print() const { return m_print; }
|
|
|
|
ModelObject* model_object() { return m_model_object; }
|
|
|
|
const ModelObject* model_object() const { return m_model_object; }
|
|
|
|
const PrintObjectConfig& config() const { return m_config; }
|
|
|
|
void config_apply(const ConfigBase &other, bool ignore_nonexistent = false) { this->m_config.apply(other, ignore_nonexistent); }
|
|
|
|
void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false) { this->m_config.apply_only(other, keys, ignore_nonexistent); }
|
|
|
|
const LayerPtrs& layers() const { return m_layers; }
|
|
|
|
const SupportLayerPtrs& support_layers() const { return m_support_layers; }
|
2018-10-24 09:48:39 +00:00
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
const Transform3d& trafo() const { return m_trafo; }
|
2018-10-24 09:48:39 +00:00
|
|
|
void set_trafo(const Transform3d& trafo) { m_trafo = trafo; }
|
2018-09-11 12:04:47 +00:00
|
|
|
|
2018-10-18 12:36:46 +00:00
|
|
|
const Points& copies() const { return m_copies; }
|
|
|
|
bool add_copy(const Vec2d &point);
|
|
|
|
bool delete_last_copy();
|
|
|
|
bool delete_all_copies() { return this->set_copies(Points()); }
|
|
|
|
bool set_copies(const Points &points);
|
|
|
|
bool reload_model_instances();
|
|
|
|
|
2017-05-30 15:24:50 +00:00
|
|
|
// since the object is aligned to origin, bounding box coincides with size
|
2018-08-21 15:43:05 +00:00
|
|
|
BoundingBox bounding_box() const { return BoundingBox(Point(0,0), to_2d(this->size)); }
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2017-05-30 15:24:50 +00:00
|
|
|
// adds region_id, too, if necessary
|
2017-09-11 07:49:59 +00:00
|
|
|
void add_region_volume(unsigned int region_id, int volume_id) {
|
2017-05-31 10:55:59 +00:00
|
|
|
if (region_id >= region_volumes.size())
|
|
|
|
region_volumes.resize(region_id + 1);
|
|
|
|
region_volumes[region_id].push_back(volume_id);
|
|
|
|
}
|
2017-05-30 15:24:50 +00:00
|
|
|
// This is the *total* layer count (including support layers)
|
|
|
|
// this value is not supposed to be compared with Layer::id
|
|
|
|
// since they have different semantics.
|
|
|
|
size_t total_layer_count() const { return this->layer_count() + this->support_layer_count(); }
|
2018-09-11 12:04:47 +00:00
|
|
|
size_t layer_count() const { return m_layers.size(); }
|
2014-05-06 08:07:18 +00:00
|
|
|
void clear_layers();
|
2018-09-11 12:04:47 +00:00
|
|
|
Layer* get_layer(int idx) { return m_layers[idx]; }
|
|
|
|
const Layer* get_layer(int idx) const { return m_layers[idx]; }
|
2016-10-16 14:30:56 +00:00
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
// print_z: top of the layer; slice_z: center of the layer.
|
2014-06-10 14:01:57 +00:00
|
|
|
Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
|
2014-05-06 08:07:18 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
size_t support_layer_count() const { return m_support_layers.size(); }
|
2014-05-06 08:07:18 +00:00
|
|
|
void clear_support_layers();
|
2018-09-11 12:04:47 +00:00
|
|
|
SupportLayer* get_support_layer(int idx) { return m_support_layers[idx]; }
|
2015-01-30 17:45:30 +00:00
|
|
|
SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z);
|
2018-09-11 12:04:47 +00:00
|
|
|
SupportLayerPtrs::const_iterator insert_support_layer(SupportLayerPtrs::const_iterator pos, int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
|
2014-05-06 08:07:18 +00:00
|
|
|
void delete_support_layer(int idx);
|
2014-06-10 22:15:02 +00:00
|
|
|
|
|
|
|
// methods for handling state
|
|
|
|
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
2014-06-13 09:19:53 +00:00
|
|
|
bool invalidate_step(PrintObjectStep step);
|
2018-09-11 12:04:47 +00:00
|
|
|
bool invalidate_all_steps();
|
2018-03-28 15:05:31 +00:00
|
|
|
bool is_step_done(PrintObjectStep step) const { return m_state.is_done(step); }
|
2016-12-12 16:53:38 +00:00
|
|
|
|
2017-02-09 13:56:13 +00:00
|
|
|
// To be used over the layer_height_profile of both the PrintObject and ModelObject
|
|
|
|
// to initialize the height profile with the height ranges.
|
|
|
|
bool update_layer_height_profile(std::vector<coordf_t> &layer_height_profile) const;
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
// Process layer_height_ranges, the raft layers and first layer thickness into layer_height_profile.
|
|
|
|
// The layer_height_profile may be later modified interactively by the user to refine layers at sloping surfaces.
|
2017-02-07 17:17:12 +00:00
|
|
|
bool update_layer_height_profile();
|
2017-02-09 13:56:13 +00:00
|
|
|
|
|
|
|
void reset_layer_height_profile();
|
2016-12-12 16:53:38 +00:00
|
|
|
|
2018-05-30 13:18:45 +00:00
|
|
|
void adjust_layer_height_profile(coordf_t z, coordf_t layer_thickness_delta, coordf_t band_width, int action);
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
// Collect the slicing parameters, to be used by variable layer thickness algorithm,
|
|
|
|
// by the interactive layer height editor and by the printing process itself.
|
|
|
|
// The slicing parameters are dependent on various configuration values
|
|
|
|
// (layer height, first layer height, raft settings, print nozzle diameter etc).
|
|
|
|
SlicingParameters slicing_parameters() const;
|
|
|
|
|
2018-03-23 15:00:00 +00:00
|
|
|
// Called when slicing to SVG (see Print.pm sub export_svg), and used by perimeters.t
|
2018-03-23 10:41:20 +00:00
|
|
|
void slice();
|
2018-03-23 15:00:00 +00:00
|
|
|
|
2018-09-17 13:12:13 +00:00
|
|
|
// Helpers to slice support enforcer / blocker meshes by the support generator.
|
|
|
|
std::vector<ExPolygons> slice_support_enforcers() const;
|
|
|
|
std::vector<ExPolygons> slice_support_blockers() const;
|
|
|
|
|
2018-03-23 15:00:00 +00:00
|
|
|
private:
|
2018-03-23 10:41:20 +00:00
|
|
|
void make_perimeters();
|
|
|
|
void prepare_infill();
|
|
|
|
void infill();
|
|
|
|
void generate_support_material();
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
void _slice();
|
2017-03-08 10:56:42 +00:00
|
|
|
std::string _fix_slicing_errors();
|
2017-03-08 12:43:49 +00:00
|
|
|
void _simplify_slices(double distance);
|
2018-09-12 09:59:02 +00:00
|
|
|
void _make_perimeters();
|
2015-03-06 08:56:58 +00:00
|
|
|
bool has_support_material() const;
|
2016-11-10 18:23:01 +00:00
|
|
|
void detect_surfaces_type();
|
2015-10-26 22:23:03 +00:00
|
|
|
void process_external_surfaces();
|
2016-09-26 11:56:24 +00:00
|
|
|
void discover_vertical_shells();
|
2014-12-24 09:20:55 +00:00
|
|
|
void bridge_over_infill();
|
2017-08-02 12:24:32 +00:00
|
|
|
void clip_fill_surfaces();
|
|
|
|
void discover_horizontal_shells();
|
|
|
|
void combine_infill();
|
2016-12-20 11:19:13 +00:00
|
|
|
void _generate_support_material();
|
2016-12-12 16:53:38 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
bool is_printable() const { return ! m_copies.empty(); }
|
2018-07-18 07:37:25 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
Print *m_print;
|
|
|
|
ModelObject *m_model_object;
|
|
|
|
PrintObjectConfig m_config;
|
2018-10-17 09:12:38 +00:00
|
|
|
// Translation in Z + Rotation + Scaling / Mirroring.
|
|
|
|
Transform3d m_trafo = Transform3d::Identity();
|
2018-09-11 12:04:47 +00:00
|
|
|
// Slic3r::Point objects in scaled G-code coordinates
|
|
|
|
Points m_copies;
|
2018-09-12 09:59:02 +00:00
|
|
|
// scaled coordinates to add to copies (to compensate for the alignment
|
|
|
|
// operated when creating the object but still preserving a coherent API
|
|
|
|
// for external callers)
|
|
|
|
Point m_copies_shift;
|
2018-09-11 12:04:47 +00:00
|
|
|
|
|
|
|
LayerPtrs m_layers;
|
|
|
|
SupportLayerPtrs m_support_layers;
|
2014-05-19 20:38:10 +00:00
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
PrintState<PrintObjectStep, posCount> m_state;
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
// TODO: call model_object->get_bounding_box() instead of accepting
|
|
|
|
// parameter
|
2014-06-10 14:01:57 +00:00
|
|
|
PrintObject(Print* print, ModelObject* model_object, const BoundingBoxf3 &modobj_bbox);
|
2016-12-08 18:02:16 +00:00
|
|
|
~PrintObject() {}
|
2016-12-12 16:53:38 +00:00
|
|
|
|
2018-09-14 07:28:00 +00:00
|
|
|
void set_started(PrintObjectStep step);
|
|
|
|
void set_done(PrintObjectStep step);
|
2016-12-12 16:53:38 +00:00
|
|
|
std::vector<ExPolygons> _slice_region(size_t region_id, const std::vector<float> &z, bool modifier);
|
2018-09-17 13:12:13 +00:00
|
|
|
std::vector<ExPolygons> _slice_volumes(const std::vector<float> &z, const std::vector<const ModelVolume*> &volumes) const;
|
2014-05-06 08:07:18 +00:00
|
|
|
};
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
struct WipeTowerData
|
|
|
|
{
|
|
|
|
// Following section will be consumed by the GCodeGenerator.
|
|
|
|
// Tool ordering of a non-sequential print has to be known to calculate the wipe tower.
|
|
|
|
// Cache it here, so it does not need to be recalculated during the G-code generation.
|
|
|
|
ToolOrdering tool_ordering;
|
|
|
|
// Cache of tool changes per print layer.
|
|
|
|
std::unique_ptr<WipeTower::ToolChangeResult> priming;
|
|
|
|
std::vector<std::vector<WipeTower::ToolChangeResult>> tool_changes;
|
|
|
|
std::unique_ptr<WipeTower::ToolChangeResult> final_purge;
|
2018-09-17 13:12:13 +00:00
|
|
|
std::vector<float> used_filament;
|
|
|
|
int number_of_toolchanges;
|
2018-09-11 12:04:47 +00:00
|
|
|
|
2018-09-12 09:59:02 +00:00
|
|
|
// Depth of the wipe tower to pass to GLCanvas3D for exact bounding box:
|
|
|
|
float depth;
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
void clear() {
|
|
|
|
tool_ordering.clear();
|
|
|
|
priming.reset(nullptr);
|
|
|
|
tool_changes.clear();
|
|
|
|
final_purge.reset(nullptr);
|
2018-09-17 13:12:13 +00:00
|
|
|
used_filament.clear();
|
|
|
|
number_of_toolchanges = -1;
|
2018-09-12 09:59:02 +00:00
|
|
|
depth = 0.f;
|
2018-09-11 12:04:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PrintStatistics
|
|
|
|
{
|
|
|
|
PrintStatistics() { clear(); }
|
2018-06-27 13:35:47 +00:00
|
|
|
std::string estimated_normal_print_time;
|
2018-05-30 10:08:03 +00:00
|
|
|
std::string estimated_silent_print_time;
|
2018-09-11 12:04:47 +00:00
|
|
|
double total_used_filament;
|
|
|
|
double total_extruded_volume;
|
|
|
|
double total_cost;
|
|
|
|
double total_weight;
|
2018-09-17 13:12:13 +00:00
|
|
|
double total_wipe_tower_cost;
|
|
|
|
double total_wipe_tower_filament;
|
2018-09-11 12:04:47 +00:00
|
|
|
std::map<size_t, float> filament_stats;
|
|
|
|
|
|
|
|
void clear() {
|
2018-09-12 09:59:02 +00:00
|
|
|
estimated_normal_print_time.clear();
|
|
|
|
estimated_silent_print_time.clear();
|
2018-09-11 12:04:47 +00:00
|
|
|
total_used_filament = 0.;
|
|
|
|
total_extruded_volume = 0.;
|
|
|
|
total_cost = 0.;
|
2018-09-12 09:59:02 +00:00
|
|
|
total_weight = 0.;
|
2018-09-17 13:12:13 +00:00
|
|
|
total_wipe_tower_cost = 0.;
|
|
|
|
total_wipe_tower_filament = 0.;
|
2018-09-11 12:04:47 +00:00
|
|
|
filament_stats.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-06 08:07:18 +00:00
|
|
|
typedef std::vector<PrintObject*> PrintObjectPtrs;
|
|
|
|
typedef std::vector<PrintRegion*> PrintRegionPtrs;
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
// The complete print tray with possibly multiple objects.
|
2014-05-06 08:07:18 +00:00
|
|
|
class Print
|
|
|
|
{
|
2017-03-13 15:03:11 +00:00
|
|
|
public:
|
2018-09-11 12:04:47 +00:00
|
|
|
Print() { restart(); }
|
2017-05-30 18:09:34 +00:00
|
|
|
~Print() { clear_objects(); }
|
2014-06-10 14:01:57 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// Methods, which change the state of Print / PrintObject / PrintRegion.
|
|
|
|
// The following methods are synchronized with process() and export_gcode(),
|
|
|
|
// so that process() and export_gcode() may be called from a background thread.
|
|
|
|
// In case the following methods need to modify data processed by process() or export_gcode(),
|
|
|
|
// a cancellation callback is executed to stop the background processing before the operation.
|
|
|
|
void clear_objects();
|
|
|
|
void delete_object(size_t idx);
|
|
|
|
void reload_object(size_t idx);
|
|
|
|
bool reload_model_instances();
|
|
|
|
void add_model_object(ModelObject* model_object, int idx = -1);
|
|
|
|
bool apply_config(DynamicPrintConfig config);
|
2018-10-23 20:53:43 +00:00
|
|
|
enum ApplyStatus {
|
|
|
|
// No change after the Print::apply() call.
|
|
|
|
APPLY_STATUS_UNCHANGED,
|
|
|
|
// Some of the Print / PrintObject / PrintObjectInstance data was changed,
|
|
|
|
// but no result was invalidated (only data influencing not yet calculated results were changed).
|
|
|
|
APPLY_STATUS_CHANGED,
|
|
|
|
// Some data was changed, which in turn invalidated already calculated steps.
|
|
|
|
APPLY_STATUS_INVALIDATED,
|
|
|
|
};
|
|
|
|
ApplyStatus apply(const Model &model, const DynamicPrintConfig &config);
|
2018-10-17 09:12:38 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
void process();
|
|
|
|
void export_gcode(const std::string &path_template, GCodePreviewData *preview_data);
|
2018-09-12 09:59:02 +00:00
|
|
|
// SLA export, temporary.
|
2018-09-17 10:01:02 +00:00
|
|
|
void export_png(const std::string &dirpath);
|
2014-06-10 14:01:57 +00:00
|
|
|
|
2014-06-10 22:15:02 +00:00
|
|
|
// methods for handling state
|
2018-09-11 12:04:47 +00:00
|
|
|
bool is_step_done(PrintStep step) const { return m_state.is_done(step); }
|
|
|
|
bool is_step_done(PrintObjectStep step) const;
|
|
|
|
|
|
|
|
bool has_infinite_skirt() const;
|
|
|
|
bool has_skirt() const;
|
2018-09-12 09:59:02 +00:00
|
|
|
PrintObjectPtrs get_printable_objects() const;
|
|
|
|
float get_wipe_tower_depth() const { return m_wipe_tower_data.depth; }
|
|
|
|
|
2016-11-05 01:23:46 +00:00
|
|
|
// Returns an empty string if valid, otherwise returns an error message.
|
2018-09-11 12:04:47 +00:00
|
|
|
std::string validate() const;
|
|
|
|
BoundingBox bounding_box() const;
|
|
|
|
BoundingBox total_bounding_box() const;
|
|
|
|
double skirt_first_layer_height() const;
|
|
|
|
Flow brim_flow() const;
|
|
|
|
Flow skirt_flow() const;
|
2014-08-03 16:41:09 +00:00
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
std::vector<unsigned int> object_extruders() const;
|
|
|
|
std::vector<unsigned int> support_material_extruders() const;
|
|
|
|
std::vector<unsigned int> extruders() const;
|
2018-09-11 12:04:47 +00:00
|
|
|
double max_allowed_layer_height() const;
|
|
|
|
bool has_support_material() const;
|
|
|
|
// Make sure the background processing has no access to this model_object during this call!
|
|
|
|
void auto_assign_extruders(ModelObject* model_object) const;
|
|
|
|
|
|
|
|
const PrintConfig& config() const { return m_config; }
|
|
|
|
const PrintObjectConfig& default_object_config() const { return m_default_object_config; }
|
|
|
|
const PrintRegionConfig& default_region_config() const { return m_default_region_config; }
|
|
|
|
const PrintObjectPtrs& objects() const { return m_objects; }
|
2018-10-11 08:03:38 +00:00
|
|
|
PrintObject* get_object(size_t idx) { return m_objects[idx]; }
|
|
|
|
const PrintObject* get_object(size_t idx) const { return m_objects[idx]; }
|
2018-09-11 12:04:47 +00:00
|
|
|
const PrintRegionPtrs& regions() const { return m_regions; }
|
|
|
|
const PlaceholderParser& placeholder_parser() const { return m_placeholder_parser; }
|
2018-10-04 09:12:55 +00:00
|
|
|
PlaceholderParser& placeholder_parser() { return m_placeholder_parser; }
|
2018-10-23 20:53:43 +00:00
|
|
|
// How many of PrintObject::copies() over all print objects are there?
|
|
|
|
// If zero, then the print is empty and the print shall not be executed.
|
|
|
|
unsigned int num_object_instances() const;
|
2018-09-11 12:04:47 +00:00
|
|
|
|
2018-07-11 12:46:13 +00:00
|
|
|
// Returns extruder this eec should be printed with, according to PrintRegion config:
|
|
|
|
static int get_extruder(const ExtrusionEntityCollection& fill, const PrintRegion ®ion);
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
const ExtrusionEntityCollection& skirt() const { return m_skirt; }
|
|
|
|
const ExtrusionEntityCollection& brim() const { return m_brim; }
|
2017-02-15 10:05:52 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
const PrintStatistics& print_statistics() const { return m_print_statistics; }
|
2017-05-25 20:27:53 +00:00
|
|
|
|
|
|
|
// Wipe tower support.
|
2018-09-11 12:04:47 +00:00
|
|
|
bool has_wipe_tower() const;
|
|
|
|
const WipeTowerData& wipe_tower_data() const { return m_wipe_tower_data; }
|
2017-05-25 20:27:53 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
std::string output_filename() const;
|
|
|
|
std::string output_filepath(const std::string &path) const;
|
2017-09-01 15:30:18 +00:00
|
|
|
|
2018-03-23 10:41:20 +00:00
|
|
|
typedef std::function<void(int, const std::string&)> status_callback_type;
|
2018-03-23 15:00:00 +00:00
|
|
|
// Default status console print out in the form of percent => message.
|
2018-09-11 12:04:47 +00:00
|
|
|
void set_status_default() { m_status_callback = nullptr; }
|
2018-03-28 15:05:31 +00:00
|
|
|
// No status output or callback whatsoever, useful mostly for automatic tests.
|
2018-09-11 12:04:47 +00:00
|
|
|
void set_status_silent() { m_status_callback = [](int, const std::string&){}; }
|
2018-03-23 15:00:00 +00:00
|
|
|
// Register a custom status callback.
|
2018-09-11 12:04:47 +00:00
|
|
|
void set_status_callback(status_callback_type cb) { m_status_callback = cb; }
|
2018-03-23 15:00:00 +00:00
|
|
|
// Calls a registered callback to update the status, or print out the default message.
|
2018-09-11 12:04:47 +00:00
|
|
|
void set_status(int percent, const std::string &message) {
|
2018-03-23 10:41:20 +00:00
|
|
|
if (m_status_callback) m_status_callback(percent, message);
|
|
|
|
else printf("%d => %s\n", percent, message.c_str());
|
|
|
|
}
|
2018-09-11 12:04:47 +00:00
|
|
|
|
|
|
|
typedef std::function<void()> cancel_callback_type;
|
|
|
|
// Various methods will call this callback to stop the background processing (the Print::process() call)
|
|
|
|
// in case a successive change of the Print / PrintObject / PrintRegion instances changed
|
|
|
|
// the state of the finished or running calculations.
|
|
|
|
void set_cancel_callback(cancel_callback_type cancel_callback) { m_cancel_callback = cancel_callback; }
|
|
|
|
// Has the calculation been canceled?
|
|
|
|
bool canceled() const { return m_canceled; }
|
2017-09-01 15:30:18 +00:00
|
|
|
// Cancel the running computation. Stop execution of all the background threads.
|
2018-09-11 12:04:47 +00:00
|
|
|
void cancel() { m_canceled = true; }
|
2017-09-01 15:30:18 +00:00
|
|
|
// Cancel the running computation. Stop execution of all the background threads.
|
2018-09-11 12:04:47 +00:00
|
|
|
void restart() { m_canceled = false; }
|
|
|
|
|
|
|
|
// Accessed by SupportMaterial
|
|
|
|
const PrintRegion* get_region(size_t idx) const { return m_regions[idx]; }
|
2018-03-28 15:05:31 +00:00
|
|
|
|
|
|
|
protected:
|
2018-09-14 07:28:00 +00:00
|
|
|
void set_started(PrintStep step) { m_state.set_started(step, m_mutex); throw_if_canceled(); }
|
|
|
|
void set_done(PrintStep step) { m_state.set_done(step, m_mutex); throw_if_canceled(); }
|
2018-09-11 12:04:47 +00:00
|
|
|
bool invalidate_step(PrintStep step);
|
|
|
|
bool invalidate_all_steps() { return m_state.invalidate_all(m_mutex, m_cancel_callback); }
|
|
|
|
|
|
|
|
// methods for handling regions
|
|
|
|
PrintRegion* get_region(size_t idx) { return m_regions[idx]; }
|
|
|
|
PrintRegion* add_region();
|
|
|
|
PrintRegion* add_region(const PrintRegionConfig &config);
|
2018-03-28 15:05:31 +00:00
|
|
|
|
2017-03-13 15:03:11 +00:00
|
|
|
private:
|
2018-10-17 09:12:38 +00:00
|
|
|
// Update "scale", "input_filename", "input_filename_base" placeholders from the current m_objects.
|
|
|
|
void update_object_placeholders();
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
2017-09-01 15:30:18 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// If the background processing stop was requested, throw CanceledException.
|
|
|
|
// To be called by the worker thread and its sub-threads (mostly launched on the TBB thread pool) regularly.
|
2018-09-17 13:12:13 +00:00
|
|
|
void throw_if_canceled() const { if (m_canceled) throw CanceledException(); }
|
2018-09-11 12:04:47 +00:00
|
|
|
|
|
|
|
void _make_skirt();
|
|
|
|
void _make_brim();
|
|
|
|
void _make_wipe_tower();
|
|
|
|
void _simplify_slices(double distance);
|
2018-03-23 10:41:20 +00:00
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
PrintState<PrintStep, psCount> m_state;
|
|
|
|
// Mutex used for synchronization of the worker thread with the UI thread:
|
|
|
|
// The mutex will be used to guard the worker thread against entering a stage
|
|
|
|
// while the data influencing the stage is modified.
|
2018-09-14 07:28:00 +00:00
|
|
|
mutable tbb::mutex m_mutex;
|
2018-07-27 13:56:27 +00:00
|
|
|
|
2017-09-01 15:30:18 +00:00
|
|
|
// Has the calculation been canceled?
|
2018-03-28 15:05:31 +00:00
|
|
|
tbb::atomic<bool> m_canceled;
|
|
|
|
// Callback to be evoked regularly to update state of the UI thread.
|
|
|
|
status_callback_type m_status_callback;
|
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// Callback to be evoked to stop the background processing before a state is updated.
|
|
|
|
cancel_callback_type m_cancel_callback = [](){};
|
|
|
|
|
2018-10-17 09:12:38 +00:00
|
|
|
Model m_model;
|
2018-09-11 12:04:47 +00:00
|
|
|
PrintConfig m_config;
|
|
|
|
PrintObjectConfig m_default_object_config;
|
|
|
|
PrintRegionConfig m_default_region_config;
|
|
|
|
PrintObjectPtrs m_objects;
|
|
|
|
PrintRegionPtrs m_regions;
|
|
|
|
PlaceholderParser m_placeholder_parser;
|
|
|
|
|
|
|
|
// Ordered collections of extrusion paths to build skirt loops and brim.
|
|
|
|
ExtrusionEntityCollection m_skirt;
|
|
|
|
ExtrusionEntityCollection m_brim;
|
|
|
|
|
|
|
|
// Following section will be consumed by the GCodeGenerator.
|
|
|
|
WipeTowerData m_wipe_tower_data;
|
|
|
|
|
|
|
|
// Estimated print time, filament consumed.
|
|
|
|
PrintStatistics m_print_statistics;
|
|
|
|
|
2018-03-28 15:05:31 +00:00
|
|
|
// To allow GCode to set the Print's GCodeExport step status.
|
|
|
|
friend class GCode;
|
2018-09-11 12:04:47 +00:00
|
|
|
// Allow PrintObject to access m_mutex and m_cancel_callback.
|
|
|
|
friend class PrintObject;
|
2014-05-06 08:07:18 +00:00
|
|
|
};
|
|
|
|
|
2018-06-21 08:16:52 +00:00
|
|
|
|
2014-08-03 16:41:09 +00:00
|
|
|
#define FOREACH_BASE(type, container, iterator) for (type::const_iterator iterator = (container).begin(); iterator != (container).end(); ++iterator)
|
2018-09-11 12:04:47 +00:00
|
|
|
#define FOREACH_OBJECT(print, object) FOREACH_BASE(PrintObjectPtrs, (print)->m_objects, object)
|
|
|
|
#define FOREACH_LAYER(object, layer) FOREACH_BASE(LayerPtrs, (object)->m_layers, layer)
|
|
|
|
#define FOREACH_LAYERREGION(layer, layerm) FOREACH_BASE(LayerRegionPtrs, (layer)->m_regions, layerm)
|
2014-08-03 16:41:09 +00:00
|
|
|
|
2013-12-20 00:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|