2013-12-20 01:36:42 +01:00
|
|
|
#ifndef slic3r_Print_hpp_
|
|
|
|
#define slic3r_Print_hpp_
|
|
|
|
|
2015-12-08 00:39:54 +01:00
|
|
|
#include "libslic3r.h"
|
2013-12-20 01:36:42 +01:00
|
|
|
#include <set>
|
2016-11-26 12:28:39 +01:00
|
|
|
#include <vector>
|
2016-12-12 17:53:38 +01:00
|
|
|
#include <string>
|
2014-11-30 21:58:41 +01:00
|
|
|
#include "BoundingBox.hpp"
|
2014-08-03 19:17:23 +02:00
|
|
|
#include "Flow.hpp"
|
2014-05-06 11:07:18 +03:00
|
|
|
#include "PrintConfig.hpp"
|
|
|
|
#include "Point.hpp"
|
|
|
|
#include "Layer.hpp"
|
2014-11-09 12:25:59 +01:00
|
|
|
#include "Model.hpp"
|
2014-05-06 11:07:18 +03:00
|
|
|
#include "PlaceholderParser.hpp"
|
2016-12-12 17:53:38 +01:00
|
|
|
#include "Slicing.hpp"
|
2017-05-25 22:27:53 +02:00
|
|
|
#include "GCode/ToolOrdering.hpp"
|
|
|
|
#include "GCode/WipeTower.hpp"
|
2013-12-20 01:36:42 +01:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-05-06 11:07:18 +03:00
|
|
|
class Print;
|
2014-08-03 19:17:23 +02:00
|
|
|
class PrintObject;
|
2014-05-06 11:07:18 +03:00
|
|
|
class ModelObject;
|
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
// Print step IDs for keeping track of the print state.
|
2013-12-20 01:36:42 +01:00
|
|
|
enum PrintStep {
|
2017-05-30 17:17:26 +02:00
|
|
|
psSkirt, psBrim, psWipeTower, psCount,
|
2014-06-11 00:15:02 +02:00
|
|
|
};
|
|
|
|
enum PrintObjectStep {
|
|
|
|
posSlice, posPerimeters, posPrepareInfill,
|
2017-05-30 17:17:26 +02:00
|
|
|
posInfill, posSupportMaterial, posCount,
|
2013-12-20 01:36:42 +01:00
|
|
|
};
|
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
// To be instantiated over PrintStep or PrintObjectStep enums.
|
2017-05-30 17:17:26 +02:00
|
|
|
template <class StepType, size_t COUNT>
|
2013-12-20 01:36:42 +01:00
|
|
|
class PrintState
|
|
|
|
{
|
2017-02-07 18:17:12 +01:00
|
|
|
public:
|
2017-05-30 17:17:26 +02:00
|
|
|
PrintState() { memset(state, 0, sizeof(state)); }
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
INVALID,
|
|
|
|
STARTED,
|
|
|
|
DONE,
|
|
|
|
};
|
|
|
|
State state[COUNT];
|
2014-06-13 11:19:53 +02:00
|
|
|
|
2017-05-30 17:17:26 +02:00
|
|
|
bool is_started(StepType step) const { return this->state[step] == STARTED; }
|
|
|
|
bool is_done(StepType step) const { return this->state[step] == DONE; }
|
|
|
|
void set_started(StepType step) { this->state[step] = STARTED; }
|
|
|
|
void set_done(StepType step) { this->state[step] = DONE; }
|
2017-02-07 18:17:12 +01:00
|
|
|
bool invalidate(StepType step) {
|
2017-05-30 17:17:26 +02:00
|
|
|
bool invalidated = this->state[step] != INVALID;
|
|
|
|
this->state[step] = INVALID;
|
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
bool invalidate_all() {
|
|
|
|
bool invalidated = false;
|
|
|
|
for (size_t i = 0; i < COUNT; ++ i)
|
|
|
|
if (this->state[i] != INVALID) {
|
|
|
|
invalidated = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(state, 0, sizeof(state));
|
2017-02-07 18:17:12 +01:00
|
|
|
return invalidated;
|
|
|
|
}
|
2013-12-20 01:36:42 +01:00
|
|
|
};
|
|
|
|
|
2014-05-06 11:07:18 +03: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;
|
|
|
|
|
2017-03-28 13:25:10 +02:00
|
|
|
public:
|
2014-05-06 11:07:18 +03:00
|
|
|
PrintRegionConfig config;
|
|
|
|
|
2017-03-28 13:25:10 +02:00
|
|
|
Print* print() { return this->_print; }
|
2014-08-03 19:17:23 +02:00
|
|
|
Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject &object) const;
|
2017-03-28 13:25:10 +02:00
|
|
|
coordf_t nozzle_dmr_avg(const PrintConfig &print_config) const;
|
2014-05-06 11:07:18 +03:00
|
|
|
|
2017-03-28 13:25:10 +02:00
|
|
|
private:
|
2014-05-19 23:38:10 +03:00
|
|
|
Print* _print;
|
2015-05-31 22:04:32 +02:00
|
|
|
|
2017-03-28 13:25:10 +02:00
|
|
|
PrintRegion(Print* print) : _print(print) {}
|
|
|
|
~PrintRegion() {}
|
2014-05-06 11:07:18 +03: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 16:00:22 +02:00
|
|
|
public:
|
2017-05-31 12:55:59 +02:00
|
|
|
// vector of (vectors of volume ids), indexed by region_id
|
|
|
|
std::vector<std::vector<int>> region_volumes;
|
2014-05-06 11:07:18 +03:00
|
|
|
PrintObjectConfig config;
|
|
|
|
t_layer_height_ranges layer_height_ranges;
|
2016-12-12 17:53:38 +01: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 14:56:13 +01:00
|
|
|
// layer_height_profile must not be set by the background thread.
|
2016-12-12 17:53:38 +01:00
|
|
|
std::vector<coordf_t> layer_height_profile;
|
2017-02-09 14:56:13 +01: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.
|
|
|
|
bool layer_height_profile_valid;
|
2014-07-15 19:07:38 +02: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
|
|
|
|
bool typed_slices;
|
2014-05-06 11:07:18 +03:00
|
|
|
|
|
|
|
Point3 size; // XYZ in scaled coordinates
|
|
|
|
|
|
|
|
// 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 _copies_shift;
|
|
|
|
|
|
|
|
// Slic3r::Point objects in scaled G-code coordinates in our coordinates
|
|
|
|
Points _shifted_copies;
|
|
|
|
|
|
|
|
LayerPtrs layers;
|
|
|
|
SupportLayerPtrs support_layers;
|
2017-05-30 17:17:26 +02:00
|
|
|
PrintState<PrintObjectStep, posCount> state;
|
2014-06-10 16:01:57 +02:00
|
|
|
|
2016-10-20 13:04:23 +02:00
|
|
|
Print* print() { return this->_print; }
|
|
|
|
const Print* print() const { return this->_print; }
|
|
|
|
ModelObject* model_object() { return this->_model_object; }
|
|
|
|
const ModelObject* model_object() const { return this->_model_object; }
|
|
|
|
|
2017-05-03 18:28:22 +02:00
|
|
|
const Points& copies() const { return this->_copies; }
|
2014-11-13 00:34:56 +01:00
|
|
|
bool add_copy(const Pointf &point);
|
|
|
|
bool delete_last_copy();
|
2017-05-30 17:24:50 +02:00
|
|
|
bool delete_all_copies() { return this->set_copies(Points()); }
|
2014-11-12 23:28:42 +01:00
|
|
|
bool set_copies(const Points &points);
|
|
|
|
bool reload_model_instances();
|
2017-05-30 17:24:50 +02:00
|
|
|
// since the object is aligned to origin, bounding box coincides with size
|
|
|
|
BoundingBox bounding_box() const { return BoundingBox(Point(0,0), this->size); }
|
2014-05-06 11:07:18 +03:00
|
|
|
|
2017-05-30 17:24:50 +02:00
|
|
|
// adds region_id, too, if necessary
|
2017-05-31 12:55:59 +02:00
|
|
|
void add_region_volume(int region_id, int volume_id) {
|
|
|
|
if (region_id >= region_volumes.size())
|
|
|
|
region_volumes.resize(region_id + 1);
|
|
|
|
region_volumes[region_id].push_back(volume_id);
|
|
|
|
}
|
2017-05-30 17:24:50 +02: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(); }
|
|
|
|
size_t layer_count() const { return this->layers.size(); }
|
2014-05-06 11:07:18 +03:00
|
|
|
void clear_layers();
|
2016-10-16 16:30:56 +02:00
|
|
|
Layer* get_layer(int idx) { return this->layers.at(idx); }
|
|
|
|
const Layer* get_layer(int idx) const { return this->layers.at(idx); }
|
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
// print_z: top of the layer; slice_z: center of the layer.
|
2014-06-10 16:01:57 +02:00
|
|
|
Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
|
2014-05-06 11:07:18 +03:00
|
|
|
|
2017-05-30 17:24:50 +02:00
|
|
|
size_t support_layer_count() const { return this->support_layers.size(); }
|
2014-05-06 11:07:18 +03:00
|
|
|
void clear_support_layers();
|
2017-05-30 17:24:50 +02:00
|
|
|
SupportLayer* get_support_layer(int idx) { return this->support_layers.at(idx); }
|
2015-01-30 18:45:30 +01:00
|
|
|
SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z);
|
2014-05-06 11:07:18 +03:00
|
|
|
void delete_support_layer(int idx);
|
2014-06-11 00:15:02 +02:00
|
|
|
|
|
|
|
// methods for handling state
|
|
|
|
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
2014-06-13 11:19:53 +02:00
|
|
|
bool invalidate_step(PrintObjectStep step);
|
2017-05-30 17:17:26 +02:00
|
|
|
bool invalidate_all_steps() { return this->state.invalidate_all(); }
|
2016-12-12 17:53:38 +01:00
|
|
|
|
2017-02-09 14:56:13 +01: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 17:53:38 +01: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 18:17:12 +01:00
|
|
|
bool update_layer_height_profile();
|
2017-02-09 14:56:13 +01:00
|
|
|
|
|
|
|
void reset_layer_height_profile();
|
2016-12-12 17:53:38 +01: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;
|
|
|
|
|
|
|
|
void _slice();
|
2017-03-08 11:56:42 +01:00
|
|
|
std::string _fix_slicing_errors();
|
2017-03-08 13:43:49 +01:00
|
|
|
void _simplify_slices(double distance);
|
2015-03-06 09:56:58 +01:00
|
|
|
bool has_support_material() const;
|
2016-11-10 19:23:01 +01:00
|
|
|
void detect_surfaces_type();
|
2015-10-26 23:23:03 +01:00
|
|
|
void process_external_surfaces();
|
2016-09-26 13:56:24 +02:00
|
|
|
void discover_vertical_shells();
|
2014-12-24 10:20:55 +01:00
|
|
|
void bridge_over_infill();
|
2016-11-26 12:28:39 +01:00
|
|
|
void _make_perimeters();
|
|
|
|
void _infill();
|
2016-12-20 12:19:13 +01:00
|
|
|
void _generate_support_material();
|
2016-12-12 17:53:38 +01:00
|
|
|
|
2016-10-13 16:00:22 +02:00
|
|
|
private:
|
2014-05-19 23:38:10 +03:00
|
|
|
Print* _print;
|
|
|
|
ModelObject* _model_object;
|
2014-11-09 12:25:59 +01:00
|
|
|
Points _copies; // Slic3r::Point objects in scaled G-code coordinates
|
2014-05-19 23:38:10 +03:00
|
|
|
|
2014-05-06 11:07:18 +03:00
|
|
|
// TODO: call model_object->get_bounding_box() instead of accepting
|
|
|
|
// parameter
|
2014-06-10 16:01:57 +02:00
|
|
|
PrintObject(Print* print, ModelObject* model_object, const BoundingBoxf3 &modobj_bbox);
|
2016-12-08 19:02:16 +01:00
|
|
|
~PrintObject() {}
|
2016-12-12 17:53:38 +01:00
|
|
|
|
|
|
|
std::vector<ExPolygons> _slice_region(size_t region_id, const std::vector<float> &z, bool modifier);
|
2014-05-06 11:07:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<PrintObject*> PrintObjectPtrs;
|
|
|
|
typedef std::vector<PrintRegion*> PrintRegionPtrs;
|
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
// The complete print tray with possibly multiple objects.
|
2014-05-06 11:07:18 +03:00
|
|
|
class Print
|
|
|
|
{
|
2017-03-13 16:03:11 +01:00
|
|
|
public:
|
2014-05-06 11:07:18 +03:00
|
|
|
PrintConfig config;
|
|
|
|
PrintObjectConfig default_object_config;
|
|
|
|
PrintRegionConfig default_region_config;
|
|
|
|
PrintObjectPtrs objects;
|
|
|
|
PrintRegionPtrs regions;
|
|
|
|
PlaceholderParser placeholder_parser;
|
|
|
|
// TODO: status_cb
|
2017-01-16 01:00:05 -06:00
|
|
|
double total_used_filament, total_extruded_volume, total_cost, total_weight;
|
2015-01-03 23:25:55 +01:00
|
|
|
std::map<size_t,float> filament_stats;
|
2017-05-30 17:17:26 +02:00
|
|
|
PrintState<PrintStep, psCount> state;
|
2014-05-06 11:07:18 +03:00
|
|
|
|
2014-06-10 16:01:57 +02:00
|
|
|
// ordered collections of extrusion paths to build skirt loops and brim
|
|
|
|
ExtrusionEntityCollection skirt, brim;
|
2014-05-06 11:07:18 +03:00
|
|
|
|
2017-05-30 20:09:34 +02:00
|
|
|
Print() : total_used_filament(0), total_extruded_volume(0) {}
|
|
|
|
~Print() { clear_objects(); }
|
2014-06-10 16:01:57 +02:00
|
|
|
|
|
|
|
// methods for handling objects
|
2014-05-06 11:07:18 +03:00
|
|
|
void clear_objects();
|
2017-03-13 16:03:11 +01:00
|
|
|
PrintObject* get_object(size_t idx) { return objects.at(idx); }
|
|
|
|
const PrintObject* get_object(size_t idx) const { return objects.at(idx); }
|
|
|
|
|
2014-06-10 16:01:57 +02:00
|
|
|
void delete_object(size_t idx);
|
2014-11-07 20:25:05 +01:00
|
|
|
void reload_object(size_t idx);
|
2014-12-29 22:29:24 +01:00
|
|
|
bool reload_model_instances();
|
2014-06-10 16:01:57 +02:00
|
|
|
|
|
|
|
// methods for handling regions
|
2017-01-05 09:11:36 +01:00
|
|
|
PrintRegion* get_region(size_t idx) { return regions.at(idx); }
|
|
|
|
const PrintRegion* get_region(size_t idx) const { return regions.at(idx); }
|
2014-05-06 11:07:18 +03:00
|
|
|
PrintRegion* add_region();
|
2014-06-11 00:15:02 +02:00
|
|
|
|
|
|
|
// methods for handling state
|
2014-06-13 11:19:53 +02:00
|
|
|
bool invalidate_step(PrintStep step);
|
2017-05-30 17:17:26 +02:00
|
|
|
bool invalidate_all_steps() { return this->state.invalidate_all(); }
|
2014-11-30 20:18:09 +01:00
|
|
|
bool step_done(PrintObjectStep step) const;
|
2014-08-03 18:41:09 +02:00
|
|
|
|
2014-11-09 12:25:59 +01:00
|
|
|
void add_model_object(ModelObject* model_object, int idx = -1);
|
|
|
|
bool apply_config(DynamicPrintConfig config);
|
2015-03-06 09:56:58 +01:00
|
|
|
bool has_infinite_skirt() const;
|
|
|
|
bool has_skirt() const;
|
2016-11-05 02:23:46 +01:00
|
|
|
// Returns an empty string if valid, otherwise returns an error message.
|
|
|
|
std::string validate() const;
|
2014-12-12 19:14:52 +01:00
|
|
|
BoundingBox bounding_box() const;
|
|
|
|
BoundingBox total_bounding_box() const;
|
|
|
|
double skirt_first_layer_height() const;
|
2014-12-17 00:45:05 +01:00
|
|
|
Flow brim_flow() const;
|
2014-12-12 19:14:52 +01:00
|
|
|
Flow skirt_flow() const;
|
2014-08-03 18:41:09 +02:00
|
|
|
|
2017-05-03 18:28:22 +02:00
|
|
|
std::vector<unsigned int> object_extruders() const;
|
|
|
|
std::vector<unsigned int> support_material_extruders() const;
|
|
|
|
std::vector<unsigned int> extruders() const;
|
2014-08-03 18:41:09 +02:00
|
|
|
void _simplify_slices(double distance);
|
|
|
|
double max_allowed_layer_height() const;
|
|
|
|
bool has_support_material() const;
|
2015-12-02 18:29:33 +01:00
|
|
|
void auto_assign_extruders(ModelObject* model_object) const;
|
2017-02-15 11:05:52 +01:00
|
|
|
|
|
|
|
void _make_skirt();
|
2017-05-25 22:27:53 +02:00
|
|
|
|
|
|
|
// Wipe tower support.
|
|
|
|
bool has_wipe_tower();
|
|
|
|
void _clear_wipe_tower();
|
|
|
|
void _make_wipe_tower();
|
|
|
|
// 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 m_tool_ordering;
|
|
|
|
// Cache of tool changes per print layer.
|
|
|
|
std::vector<std::vector<WipeTower::ToolChangeResult>> m_wipe_tower_tool_changes;
|
|
|
|
std::unique_ptr<WipeTower::ToolChangeResult> m_wipe_tower_final_purge;
|
|
|
|
|
2016-12-20 19:01:51 +01:00
|
|
|
std::string output_filename();
|
|
|
|
std::string output_filepath(const std::string &path);
|
2014-08-03 18:41:09 +02:00
|
|
|
|
2017-03-13 16:03:11 +01:00
|
|
|
private:
|
2017-05-31 17:02:23 +02:00
|
|
|
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
|
2014-11-09 12:25:59 +01:00
|
|
|
PrintRegionConfig _region_config_from_model_volume(const ModelVolume &volume);
|
2014-05-06 11:07:18 +03:00
|
|
|
};
|
|
|
|
|
2014-08-03 18:41:09 +02:00
|
|
|
#define FOREACH_BASE(type, container, iterator) for (type::const_iterator iterator = (container).begin(); iterator != (container).end(); ++iterator)
|
|
|
|
#define FOREACH_REGION(print, region) FOREACH_BASE(PrintRegionPtrs, (print)->regions, region)
|
|
|
|
#define FOREACH_OBJECT(print, object) FOREACH_BASE(PrintObjectPtrs, (print)->objects, object)
|
|
|
|
#define FOREACH_LAYER(object, layer) FOREACH_BASE(LayerPtrs, (object)->layers, layer)
|
|
|
|
#define FOREACH_LAYERREGION(layer, layerm) FOREACH_BASE(LayerRegionPtrs, (layer)->regions, layerm)
|
|
|
|
|
2013-12-20 01:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|