Print.hpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. #ifndef slic3r_Print_hpp_
  2. #define slic3r_Print_hpp_
  3. #include "PrintBase.hpp"
  4. #include "BoundingBox.hpp"
  5. #include "ExtrusionEntityCollection.hpp"
  6. #include "Flow.hpp"
  7. #include "Point.hpp"
  8. #include "Slicing.hpp"
  9. #include "Surface.hpp"
  10. #include "GCode/ToolOrdering.hpp"
  11. #include "GCode/WipeTower.hpp"
  12. #include "GCode/ThumbnailData.hpp"
  13. #include "GCode/GCodeProcessor.hpp"
  14. #include "libslic3r.h"
  15. #include <ctime>
  16. namespace Slic3r {
  17. class Print;
  18. class PrintObject;
  19. class ModelObject;
  20. class GCode;
  21. enum class SlicingMode : uint32_t;
  22. class Layer;
  23. class SupportLayer;
  24. namespace FillAdaptive {
  25. struct Octree;
  26. struct OctreeDeleter;
  27. using OctreePtr = std::unique_ptr<Octree, OctreeDeleter>;
  28. };
  29. // Print step IDs for keeping track of the print state.
  30. // The Print steps are applied in this order.
  31. enum PrintStep {
  32. psWipeTower,
  33. // Ordering of the tools on PrintObjects for a multi-material print.
  34. // psToolOrdering is a synonym to psWipeTower, as the Wipe Tower calculates and modifies the ToolOrdering,
  35. // while if printing without the Wipe Tower, the ToolOrdering is calculated as well.
  36. psToolOrdering = psWipeTower,
  37. psSkirt,
  38. psBrim,
  39. // Last step before G-code export, after this step is finished, the initial extrusion path preview
  40. // should be refreshed.
  41. psSlicingFinished = psBrim,
  42. psGCodeExport,
  43. psCount,
  44. };
  45. enum PrintObjectStep {
  46. posSlice, posPerimeters, posPrepareInfill,
  47. posInfill, posIroning, posSupportMaterial, posCount,
  48. };
  49. // A PrintRegion object represents a group of volumes to print
  50. // sharing the same config (including the same assigned extruder(s))
  51. class PrintRegion
  52. {
  53. friend class Print;
  54. // Methods NOT modifying the PrintRegion's state:
  55. public:
  56. const Print* print() const { return m_print; }
  57. const PrintRegionConfig& config() const { return m_config; }
  58. // 1-based extruder identifier for this region and role.
  59. uint16_t extruder(FlowRole role, const PrintObject& object) const;
  60. Flow flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, const PrintObject& object) const;
  61. float width(FlowRole role, bool first_layer, const PrintObject& object) const;
  62. // Average diameter of nozzles participating on extruding this region.
  63. coordf_t nozzle_dmr_avg(const PrintConfig &print_config) const;
  64. // Average diameter of nozzles participating on extruding this region.
  65. coordf_t bridging_height_avg(const PrintConfig &print_config) const;
  66. // Collect 0-based extruder indices used to print this region's object.
  67. void collect_object_printing_extruders(std::set<uint16_t> &object_extruders) const;
  68. static void collect_object_printing_extruders(const PrintConfig &print_config, const PrintObjectConfig &object_config, const PrintRegionConfig &region_config, std::set<uint16_t> &object_extruders);
  69. // Methods modifying the PrintRegion's state:
  70. public:
  71. Print* print() { return m_print; }
  72. void set_config(const PrintRegionConfig &config) { m_config = config; }
  73. void set_config(PrintRegionConfig &&config) { m_config = std::move(config); }
  74. void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false)
  75. { this->m_config.apply_only(other, keys, ignore_nonexistent); }
  76. protected:
  77. size_t m_refcnt;
  78. private:
  79. Print *m_print;
  80. PrintRegionConfig m_config;
  81. //PrintRegion(Print* print) : m_refcnt(0), m_print(print) {}
  82. PrintRegion(Print* print, const PrintRegionConfig& config) : m_refcnt(0), m_print(print), m_config(config) {}
  83. ~PrintRegion() = default;
  84. };
  85. typedef std::vector<Layer*> LayerPtrs;
  86. typedef std::vector<SupportLayer*> SupportLayerPtrs;
  87. class BoundingBoxf3; // TODO: for temporary constructor parameter
  88. // Single instance of a PrintObject.
  89. // As multiple PrintObjects may be generated for a single ModelObject (their instances differ in rotation around Z),
  90. // ModelObject's instancess will be distributed among these multiple PrintObjects.
  91. struct PrintInstance
  92. {
  93. // Parent PrintObject
  94. PrintObject *print_object;
  95. // Source ModelInstance of a ModelObject, for which this print_object was created.
  96. const ModelInstance *model_instance;
  97. // Shift of this instance's center into the world coordinates.
  98. Point shift;
  99. };
  100. typedef std::vector<PrintInstance> PrintInstances;
  101. class PrintObject : public PrintObjectBaseWithState<Print, PrintObjectStep, posCount>
  102. {
  103. private: // Prevents erroneous use by other classes.
  104. typedef PrintObjectBaseWithState<Print, PrintObjectStep, posCount> Inherited;
  105. public:
  106. // vector of (layer height ranges and vectors of volume ids), indexed by region_id
  107. std::vector<std::vector<std::pair<t_layer_height_range, int>>> region_volumes;
  108. // Size of an object: XYZ in scaled coordinates. The size might not be quite snug in XY plane.
  109. const Vec3crd& size() const { return m_size; }
  110. const PrintObjectConfig& config() const { return m_config; }
  111. const LayerPtrs& layers() const { return m_layers; }
  112. const SupportLayerPtrs& support_layers() const { return m_support_layers; }
  113. const Transform3d& trafo() const { return m_trafo; }
  114. const PrintInstances& instances() const { return m_instances; }
  115. // Bounding box is used to align the object infill patterns, and to calculate attractor for the rear seam.
  116. // The bounding box may not be quite snug.
  117. BoundingBox bounding_box() const { return BoundingBox(Point(- m_size.x() / 2, - m_size.y() / 2), Point(m_size.x() / 2, m_size.y() / 2)); }
  118. // Height is used for slicing, for sorting the objects by height for sequential printing and for checking vertical clearence in sequential print mode.
  119. // The height is snug.
  120. coord_t height() const { return m_size.z(); }
  121. // Centering offset of the sliced mesh from the scaled and rotated mesh of the model.
  122. const Point& center_offset() const { return m_center_offset; }
  123. // adds region_id, too, if necessary
  124. void add_region_volume(unsigned int region_id, int volume_id, const t_layer_height_range &layer_range) {
  125. if (region_id >= region_volumes.size())
  126. region_volumes.resize(region_id + 1);
  127. region_volumes[region_id].emplace_back(layer_range, volume_id);
  128. }
  129. // This is the *total* layer count (including support layers)
  130. // this value is not supposed to be compared with Layer::id
  131. // since they have different semantics.
  132. size_t total_layer_count() const { return this->layer_count() + this->support_layer_count(); }
  133. size_t layer_count() const { return m_layers.size(); }
  134. void clear_layers();
  135. const Layer* get_layer(int idx) const { return m_layers[idx]; }
  136. Layer* get_layer(int idx) { return m_layers[idx]; }
  137. // Get a layer exactly at print_z.
  138. const Layer* get_layer_at_printz(coordf_t print_z) const;
  139. Layer* get_layer_at_printz(coordf_t print_z);
  140. // Get a layer approximately at print_z.
  141. const Layer* get_layer_at_printz(coordf_t print_z, coordf_t epsilon) const;
  142. Layer* get_layer_at_printz(coordf_t print_z, coordf_t epsilon);
  143. // Get the first layer approximately bellow print_z.
  144. const Layer* get_first_layer_bellow_printz(coordf_t print_z, coordf_t epsilon) const;
  145. // print_z: top of the layer; slice_z: center of the layer.
  146. Layer* add_layer(int id, coordf_t height, coordf_t print_z, coordf_t slice_z);
  147. size_t support_layer_count() const { return m_support_layers.size(); }
  148. void clear_support_layers();
  149. SupportLayer* get_support_layer(int idx) { return m_support_layers[idx]; }
  150. SupportLayer* add_support_layer(int id, coordf_t height, coordf_t print_z);
  151. SupportLayerPtrs::const_iterator insert_support_layer(SupportLayerPtrs::const_iterator pos, size_t id, coordf_t height, coordf_t print_z, coordf_t slice_z);
  152. void delete_support_layer(int idx);
  153. // Initialize the layer_height_profile from the model_object's layer_height_profile, from model_object's layer height table, or from slicing parameters.
  154. // Returns true, if the layer_height_profile was changed.
  155. static bool update_layer_height_profile(const ModelObject &model_object, const SlicingParameters &slicing_parameters, std::vector<coordf_t> &layer_height_profile);
  156. // Collect the slicing parameters, to be used by variable layer thickness algorithm,
  157. // by the interactive layer height editor and by the printing process itself.
  158. // The slicing parameters are dependent on various configuration values
  159. // (layer height, first layer height, raft settings, print nozzle diameter etc).
  160. const SlicingParameters& slicing_parameters() const { return m_slicing_params; }
  161. static SlicingParameters slicing_parameters(const DynamicPrintConfig &full_config, const ModelObject &model_object, float object_max_z);
  162. // returns 0-based indices of extruders used to print the object (without brim, support and other helper extrusions)
  163. std::set<uint16_t> object_extruders() const;
  164. double get_first_layer_height() const;
  165. // Called by make_perimeters()
  166. void slice();
  167. // Helpers to slice support enforcer / blocker meshes by the support generator.
  168. std::vector<ExPolygons> slice_support_volumes(const ModelVolumeType &model_volume_type) const;
  169. std::vector<ExPolygons> slice_support_blockers() const { return this->slice_support_volumes(ModelVolumeType::SUPPORT_BLOCKER); }
  170. std::vector<ExPolygons> slice_support_enforcers() const { return this->slice_support_volumes(ModelVolumeType::SUPPORT_ENFORCER); }
  171. // Helpers to project custom facets on slices
  172. void project_and_append_custom_facets(bool seam, EnforcerBlockerType type, std::vector<ExPolygons>& expolys) const;
  173. /// skirts if done per copy and not per platter
  174. const std::optional<ExtrusionEntityCollection>& skirt_first_layer() const { return m_skirt_first_layer; }
  175. const ExtrusionEntityCollection& skirt() const { return m_skirt; }
  176. const ExtrusionEntityCollection& brim() const { return m_brim; }
  177. protected:
  178. // to be called from Print only.
  179. friend class Print;
  180. PrintObject(Print* print, ModelObject* model_object, const Transform3d& trafo, PrintInstances&& instances);
  181. ~PrintObject() = default;
  182. void config_apply(const ConfigBase &other, bool ignore_nonexistent = false) { this->m_config.apply(other, ignore_nonexistent); }
  183. 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); }
  184. PrintBase::ApplyStatus set_instances(PrintInstances &&instances);
  185. // Invalidates the step, and its depending steps in PrintObject and Print.
  186. bool invalidate_step(PrintObjectStep step);
  187. // Invalidates all PrintObject and Print steps.
  188. bool invalidate_all_steps();
  189. // Invalidate steps based on a set of parameters changed.
  190. bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
  191. // If ! m_slicing_params.valid, recalculate.
  192. void update_slicing_parameters();
  193. static PrintObjectConfig object_config_from_model_object(const PrintObjectConfig &default_object_config, const ModelObject &object, size_t num_extruders);
  194. static PrintRegionConfig region_config_from_model_volume(const PrintRegionConfig &default_region_config, const DynamicPrintConfig *layer_range_config, const ModelVolume &volume, size_t num_extruders);
  195. private:
  196. void make_perimeters();
  197. void prepare_infill();
  198. void infill();
  199. void ironing();
  200. void generate_support_material();
  201. void _slice(const std::vector<coordf_t> &layer_height_profile);
  202. ExPolygons _shrink_contour_holes(double contour_delta, double default_delta, double convex_delta, const ExPolygons& input) const;
  203. ExPolygons _grow_contour_holes(double contour_delta, double default_delta, double convex_delta, const ExPolygons& input) const;
  204. void _transform_hole_to_polyholes();
  205. ExPolygons _smooth_curves(const ExPolygons &input, const PrintRegionConfig &conf) const;
  206. std::string _fix_slicing_errors();
  207. void simplify_slices(coord_t distance);
  208. bool has_support_material() const;
  209. void detect_surfaces_type();
  210. void process_external_surfaces();
  211. void discover_vertical_shells();
  212. void bridge_over_infill();
  213. void replaceSurfaceType(SurfaceType st_to_replace, SurfaceType st_replacement, SurfaceType st_under_it);
  214. void clip_fill_surfaces();
  215. void tag_under_bridge();
  216. void discover_horizontal_shells();
  217. void clean_surfaces();
  218. void combine_infill();
  219. void _generate_support_material();
  220. std::pair<FillAdaptive::OctreePtr, FillAdaptive::OctreePtr> prepare_adaptive_infill_data();
  221. // XYZ in scaled coordinates
  222. Vec3crd m_size;
  223. PrintObjectConfig m_config;
  224. // Translation in Z + Rotation + Scaling / Mirroring.
  225. Transform3d m_trafo = Transform3d::Identity();
  226. // Slic3r::Point objects in scaled G-code coordinates
  227. std::vector<PrintInstance> m_instances;
  228. // The mesh is being centered before thrown to Clipper, so that the Clipper's fixed coordinates require less bits.
  229. // This is the adjustment of the the Object's coordinate system towards PrintObject's coordinate system.
  230. Point m_center_offset;
  231. SlicingParameters m_slicing_params;
  232. LayerPtrs m_layers;
  233. SupportLayerPtrs m_support_layers;
  234. // Ordered collections of extrusion paths to build skirt loops and brim.
  235. // have to be duplicated per copy
  236. std::optional<ExtrusionEntityCollection> m_skirt_first_layer;
  237. ExtrusionEntityCollection m_skirt;
  238. ExtrusionEntityCollection m_brim;
  239. // this is set to true when LayerRegion->slices is split in top/internal/bottom
  240. // so that next call to make_perimeters() performs a union() before computing loops
  241. bool m_typed_slices = false;
  242. std::vector<ExPolygons> slice_region(size_t region_id, const std::vector<float> &z, SlicingMode mode, size_t slicing_mode_normal_below_layer, SlicingMode mode_below) const;
  243. std::vector<ExPolygons> slice_region(size_t region_id, const std::vector<float> &z, SlicingMode mode) const
  244. { return this->slice_region(region_id, z, mode, 0, mode); }
  245. std::vector<ExPolygons> slice_modifiers(size_t region_id, const std::vector<float> &z) const;
  246. std::vector<ExPolygons> slice_volumes(
  247. const std::vector<float> &z,
  248. SlicingMode mode, size_t slicing_mode_normal_below_layer, SlicingMode mode_below,
  249. const std::vector<const ModelVolume*> &volumes) const;
  250. std::vector<ExPolygons> slice_volumes(const std::vector<float> &z, SlicingMode mode, const std::vector<const ModelVolume*> &volumes) const
  251. { return this->slice_volumes(z, mode, 0, mode, volumes); }
  252. std::vector<ExPolygons> slice_volume(const std::vector<float> &z, SlicingMode mode, const ModelVolume &volume) const;
  253. std::vector<ExPolygons> slice_volume(const std::vector<float> &z, const std::vector<t_layer_height_range> &ranges, SlicingMode mode, const ModelVolume &volume) const;
  254. };
  255. struct WipeTowerData
  256. {
  257. // Following section will be consumed by the GCodeGenerator.
  258. // Tool ordering of a non-sequential print has to be known to calculate the wipe tower.
  259. // Cache it here, so it does not need to be recalculated during the G-code generation.
  260. ToolOrdering &tool_ordering;
  261. // Cache of tool changes per print layer.
  262. std::unique_ptr<std::vector<WipeTower::ToolChangeResult>> priming;
  263. std::vector<std::vector<WipeTower::ToolChangeResult>> tool_changes;
  264. std::unique_ptr<WipeTower::ToolChangeResult> final_purge;
  265. std::vector<float> used_filament;
  266. int number_of_toolchanges;
  267. // Depth of the wipe tower to pass to GLCanvas3D for exact bounding box:
  268. float depth;
  269. float brim_width;
  270. void clear() {
  271. priming.reset(nullptr);
  272. tool_changes.clear();
  273. final_purge.reset(nullptr);
  274. used_filament.clear();
  275. number_of_toolchanges = -1;
  276. depth = 0.f;
  277. brim_width = 0.f;
  278. }
  279. private:
  280. // Only allow the WipeTowerData to be instantiated internally by Print,
  281. // as this WipeTowerData shares reference to Print::m_tool_ordering.
  282. friend class Print;
  283. WipeTowerData(ToolOrdering &tool_ordering) : tool_ordering(tool_ordering) { clear(); }
  284. WipeTowerData(const WipeTowerData & /* rhs */) = delete;
  285. WipeTowerData &operator=(const WipeTowerData & /* rhs */) = delete;
  286. };
  287. struct PrintStatistics
  288. {
  289. PrintStatistics() { clear(); }
  290. std::string estimated_normal_print_time;
  291. std::string estimated_silent_print_time;
  292. double total_used_filament;
  293. std::vector<std::pair<size_t, double>> color_extruderid_to_used_filament;
  294. double total_extruded_volume;
  295. double total_cost;
  296. int total_toolchanges;
  297. double total_weight;
  298. std::vector<std::pair<size_t, double>> color_extruderid_to_used_weight;
  299. double total_wipe_tower_cost;
  300. double total_wipe_tower_filament;
  301. std::map<size_t, float> filament_stats;
  302. // Config with the filled in print statistics.
  303. DynamicConfig config() const;
  304. // Config with the statistics keys populated with placeholder strings.
  305. static DynamicConfig placeholders();
  306. // Replace the print statistics placeholders in the path.
  307. std::string finalize_output_path(const std::string &path_in) const;
  308. void clear() {
  309. total_used_filament = 0.;
  310. total_extruded_volume = 0.;
  311. total_cost = 0.;
  312. total_toolchanges = 0;
  313. total_weight = 0.;
  314. total_wipe_tower_cost = 0.;
  315. total_wipe_tower_filament = 0.;
  316. filament_stats.clear();
  317. }
  318. };
  319. class BrimLoop {
  320. public:
  321. BrimLoop(const Polygon& p) : lines(Polylines{ p.split_at_first_point() }), is_loop(true) {}
  322. BrimLoop(const Polyline& l) : lines(Polylines{l}), is_loop(false) {}
  323. Polylines lines;
  324. std::vector<BrimLoop> children;
  325. bool is_loop; // has only one polyline stored and front == back
  326. Polygon polygon() const{
  327. assert(is_loop);
  328. Polygon poly = Polygon(lines.front().points);
  329. if (poly.points.front() == poly.points.back())
  330. poly.points.resize(poly.points.size() - 1);
  331. return poly;
  332. }
  333. };
  334. typedef std::vector<PrintObject*> PrintObjectPtrs;
  335. typedef std::vector<PrintRegion*> PrintRegionPtrs;
  336. // The complete print tray with possibly multiple objects.
  337. class Print : public PrintBaseWithState<PrintStep, psCount>
  338. {
  339. private: // Prevents erroneous use by other classes.
  340. typedef PrintBaseWithState<PrintStep, psCount> Inherited;
  341. public:
  342. //Print() = default;
  343. Print() {
  344. //create config hierachy
  345. m_default_object_config.parent = &m_config;
  346. m_default_region_config.parent = &m_default_object_config;
  347. };
  348. virtual ~Print() { this->clear(); }
  349. PrinterTechnology technology() const noexcept override { return ptFFF; }
  350. // Methods, which change the state of Print / PrintObject / PrintRegion.
  351. // The following methods are synchronized with process() and export_gcode(),
  352. // so that process() and export_gcode() may be called from a background thread.
  353. // In case the following methods need to modify data processed by process() or export_gcode(),
  354. // a cancellation callback is executed to stop the background processing before the operation.
  355. void clear() override;
  356. bool empty() const override { return m_objects.empty(); }
  357. // List of existing PrintObject IDs, to remove notifications for non-existent IDs.
  358. std::vector<ObjectID> print_object_ids() const override;
  359. ApplyStatus apply(const Model &model, DynamicPrintConfig config) override;
  360. void process() override;
  361. // Exports G-code into a file name based on the path_template, returns the file path of the generated G-code file.
  362. // If preview_data is not null, the preview_data is filled in for the G-code visualization (not used by the command line Slic3r).
  363. std::string export_gcode(const std::string& path_template, GCodeProcessor::Result* result, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
  364. // methods for handling state
  365. bool is_step_done(PrintStep step) const { return Inherited::is_step_done(step); }
  366. // Returns true if an object step is done on all objects and there's at least one object.
  367. bool is_step_done(PrintObjectStep step) const;
  368. // Returns true if the last step was finished with success.
  369. bool finished() const override { return this->is_step_done(psGCodeExport); }
  370. bool has_infinite_skirt() const;
  371. bool has_skirt() const;
  372. // Returns an empty string if valid, otherwise returns an error message.
  373. std::pair<PrintValidationError, std::string> validate() const override;
  374. Flow brim_flow(size_t extruder_id, const PrintObjectConfig &brim_config) const;
  375. Flow skirt_flow(size_t extruder_id, bool first_layer=false) const;
  376. double get_first_layer_height() const;
  377. double get_object_first_layer_height(const PrintObject& object) const;
  378. std::set<uint16_t> object_extruders(const PrintObjectPtrs &objects) const;
  379. std::set<uint16_t> support_material_extruders() const;
  380. std::set<uint16_t> extruders() const;
  381. double max_allowed_layer_height() const;
  382. bool has_support_material() const;
  383. // Make sure the background processing has no access to this model_object during this call!
  384. void auto_assign_extruders(ModelObject* model_object) const;
  385. const PrintConfig& config() const { return m_config; }
  386. const PrintObjectConfig& default_object_config() const { return m_default_object_config; }
  387. const PrintRegionConfig& default_region_config() const { return m_default_region_config; }
  388. //FIXME returning const vector to non-const PrintObject*, caller could modify PrintObjects!
  389. const PrintObjectPtrs& objects() const { return m_objects; }
  390. PrintObject* get_object(size_t idx) { return m_objects[idx]; }
  391. const PrintObject* get_object(size_t idx) const { return m_objects[idx]; }
  392. // PrintObject by its ObjectID, to be used to uniquely bind slicing warnings to their source PrintObjects
  393. // in the notification center.
  394. const PrintObject* get_object(ObjectID object_id) const {
  395. auto it = std::find_if(m_objects.begin(), m_objects.end(),
  396. [object_id](const PrintObject *obj) { return obj->id() == object_id; });
  397. return (it == m_objects.end()) ? nullptr : *it;
  398. }
  399. const PrintRegionPtrs& regions() const { return m_regions; }
  400. // How many of PrintObject::copies() over all print objects are there?
  401. // If zero, then the print is empty and the print shall not be executed.
  402. uint16_t num_object_instances() const;
  403. const std::optional<ExtrusionEntityCollection>& skirt_first_layer() const { return m_skirt_first_layer; }
  404. const ExtrusionEntityCollection& skirt() const { return m_skirt; }
  405. const ExtrusionEntityCollection& brim() const { return m_brim; }
  406. // Convex hull of the 1st layer extrusions, for bed leveling and placing the initial purge line.
  407. // It encompasses the object extrusions, support extrusions, skirt, brim, wipe tower.
  408. // It does NOT encompass user extrusions generated by custom G-code,
  409. // therefore it does NOT encompass the initial purge line.
  410. // It does NOT encompass MMU/MMU2 starting (wipe) areas.
  411. const Polygon& first_layer_convex_hull() const { return m_first_layer_convex_hull; }
  412. const PrintStatistics& print_statistics() const { return m_print_statistics; }
  413. PrintStatistics& print_statistics() { return m_print_statistics; }
  414. std::time_t timestamp_last_change() const { return m_timestamp_last_change; }
  415. // Wipe tower support.
  416. bool has_wipe_tower() const;
  417. const WipeTowerData& wipe_tower_data(size_t extruders_cnt = 0, double first_layer_height = 0., double nozzle_diameter = 0.) const;
  418. const ToolOrdering& tool_ordering() const { return m_tool_ordering; }
  419. std::string output_filename(const std::string &filename_base = std::string()) const override;
  420. // Accessed by SupportMaterial
  421. const PrintRegion* get_region(size_t idx) const { return m_regions[idx]; }
  422. const ToolOrdering& get_tool_ordering() const { return m_wipe_tower_data.tool_ordering; } // #ys_FIXME just for testing
  423. //put this in public to be accessible for tests, it was in private before.
  424. bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
  425. // Invalidates the step, and its depending steps in Print.
  426. //in public to invalidate gcode when the physical printer change. It's needed if we allow the gcode macro to read these values.
  427. bool invalidate_step(PrintStep step);
  428. protected:
  429. // methods for handling regions
  430. PrintRegion* get_region(size_t idx) { return m_regions[idx]; }
  431. //PrintRegion* add_region();
  432. PrintRegion* add_region(const PrintRegionConfig &config);
  433. private:
  434. void config_diffs(
  435. const DynamicPrintConfig &new_full_config,
  436. t_config_option_keys &print_diff, t_config_option_keys &object_diff, t_config_option_keys &region_diff,
  437. t_config_option_keys &full_config_diff,
  438. DynamicPrintConfig &filament_overrides) const;
  439. void _make_skirt(const PrintObjectPtrs &objects, ExtrusionEntityCollection &out, std::optional<ExtrusionEntityCollection> &out_first_layer);
  440. void _make_brim(const Flow &flow, const PrintObjectPtrs &objects, ExPolygons &unbrimmable, ExtrusionEntityCollection &out);
  441. void _make_brim_ears(const Flow &flow, const PrintObjectPtrs &objects, ExPolygons &unbrimmable, ExtrusionEntityCollection &out);
  442. void _make_brim_interior(const Flow &flow, const PrintObjectPtrs &objects, ExPolygons &unbrimmable, ExtrusionEntityCollection &out);
  443. void _extrude_brim_from_tree(std::vector<std::vector<BrimLoop>> &loops, const Polygons &frontiers, const Flow &flow, ExtrusionEntityCollection &out, bool reversed = false);
  444. Polylines _reorder_brim_polyline(Polylines lines, ExtrusionEntityCollection &out, const Flow &flow);
  445. void _make_wipe_tower();
  446. void finalize_first_layer_convex_hull();
  447. // Islands of objects and their supports extruded at the 1st layer.
  448. Polygons first_layer_islands() const;
  449. // Return 4 wipe tower corners in the world coordinates (shifted and rotated), including the wipe tower brim.
  450. std::vector<Point> first_layer_wipe_tower_corners() const;
  451. // Declared here to have access to Model / ModelObject / ModelInstance
  452. static void model_volume_list_update_supports_seams(ModelObject &model_object_dst, const ModelObject &model_object_src);
  453. PrintConfig m_config;
  454. PrintObjectConfig m_default_object_config;
  455. PrintRegionConfig m_default_region_config;
  456. PrintObjectPtrs m_objects;
  457. PrintRegionPtrs m_regions;
  458. // Ordered collections of extrusion paths to build skirt loops and brim.
  459. std::optional<ExtrusionEntityCollection> m_skirt_first_layer;
  460. ExtrusionEntityCollection m_skirt;
  461. ExtrusionEntityCollection m_brim;
  462. // Convex hull of the 1st layer extrusions.
  463. // It encompasses the object extrusions, support extrusions, skirt, brim, wipe tower.
  464. // It does NOT encompass user extrusions generated by custom G-code,
  465. // therefore it does NOT encompass the initial purge line.
  466. // It does NOT encompass MMU/MMU2 starting (wipe) areas.
  467. Polygon m_first_layer_convex_hull;
  468. Points m_skirt_convex_hull;
  469. // Following section will be consumed by the GCodeGenerator.
  470. ToolOrdering m_tool_ordering;
  471. WipeTowerData m_wipe_tower_data {m_tool_ordering};
  472. // Estimated print time, filament consumed.
  473. PrintStatistics m_print_statistics;
  474. // tiem of last change, to see if the gui need to be updated
  475. std::time_t m_timestamp_last_change;
  476. // To allow GCode to set the Print's GCodeExport step status.
  477. friend class GCode;
  478. // Allow PrintObject to access m_mutex and m_cancel_callback.
  479. friend class PrintObject;
  480. };
  481. //for testing purpose
  482. ExPolygons dense_fill_fit_to_size(const ExPolygon &polygon_to_cover, const ExPolygons& allowedPoints,
  483. const ExPolygon& growing_area, const coord_t offset, float coverage);
  484. } /* slic3r_Print_hpp_ */
  485. #endif