1 //Copyright (c) 2018 Ultimaker B.V. 2 //CuraEngine is released under the terms of the AGPLv3 or higher. 3 4 #ifndef INSET_ORDER_OPTIMIZER_H 5 #define INSET_ORDER_OPTIMIZER_H 6 7 #include "pathOrderOptimizer.h" 8 #include "sliceDataStorage.h" //For SliceMeshStorage, which is used here at implementation in the header. 9 10 namespace cura 11 { 12 13 class FffGcodeWriter; 14 class LayerPlan; 15 class WallOverlapComputation; 16 17 class InsetOrderOptimizer 18 { 19 public: 20 /*! 21 * Constructor for inset ordering optimizer 22 * \param gcode_writer The gcode_writer on whose behalf the inset order is being optimized 23 * \param storage where the slice data is stored 24 * \param gcode_layer The initial planning of the gcode of the layer 25 * \param mesh The mesh to be added to the layer plan 26 * \param extruder_nr The extruder for which to print all features of the mesh which should be printed with this extruder 27 * \param mesh_config the line config with which to print a print feature 28 * \param part The part for which to create gcode 29 * \param layer_nr The current layer number 30 */ InsetOrderOptimizer(const FffGcodeWriter & gcode_writer,const SliceDataStorage & storage,LayerPlan & gcode_layer,const SliceMeshStorage & mesh,const int extruder_nr,const PathConfigStorage::MeshPathConfigs & mesh_config,const SliceLayerPart & part,unsigned int layer_nr)31 InsetOrderOptimizer(const FffGcodeWriter& gcode_writer, const SliceDataStorage& storage, LayerPlan& gcode_layer, const SliceMeshStorage& mesh, const int extruder_nr, const PathConfigStorage::MeshPathConfigs& mesh_config, const SliceLayerPart& part, unsigned int layer_nr) : 32 gcode_writer(gcode_writer), 33 storage(storage), 34 gcode_layer(gcode_layer), 35 mesh(mesh), 36 extruder_nr(extruder_nr), 37 mesh_config(mesh_config), 38 part(part), 39 layer_nr(layer_nr), 40 z_seam_config(mesh.settings.get<EZSeamType>("z_seam_type"), mesh.getZSeamHint(), mesh.settings.get<EZSeamCornerPrefType>("z_seam_corner")), 41 added_something(false), 42 retraction_region_calculated(false), 43 wall_overlapper_0(nullptr), 44 wall_overlapper_x(nullptr) 45 { 46 } 47 private: 48 49 const FffGcodeWriter& gcode_writer; 50 const SliceDataStorage& storage; 51 LayerPlan& gcode_layer; 52 const SliceMeshStorage& mesh; 53 const size_t extruder_nr; 54 const PathConfigStorage::MeshPathConfigs& mesh_config; 55 const SliceLayerPart& part; 56 const unsigned int layer_nr; 57 const ZSeamConfig z_seam_config; 58 bool added_something; 59 bool retraction_region_calculated; //Whether the retraction_region field has been calculated or not. 60 WallOverlapComputation* wall_overlapper_0; 61 WallOverlapComputation* wall_overlapper_x; 62 std::vector<std::vector<ConstPolygonPointer>> inset_polys; // vector of vectors holding the inset polygons 63 Polygons retraction_region; //After printing an outer wall, move into this region so that retractions do not leave visible blobs. Calculated lazily if needed (see retraction_region_calculated). 64 65 /*! 66 * Generate the insets for the holes of a given layer part after optimizing the ordering. 67 */ 68 void processHoleInsets(); 69 70 /*! 71 * Generate the insets for the outer walls of a given layer part after optimizing the ordering. 72 * \param include_outer true if the outermost inset is to be output 73 * \param include_inners true if the innermost insets are to be output 74 */ 75 void processOuterWallInsets(const bool include_outer, const bool include_inners); 76 77 /*! 78 * Generate a travel move from the current position to inside the part. 79 * This is used after generating an outer wall so that if a retraction occurs immediately afterwards, 80 * the extruder won't be on the outer wall. 81 */ 82 void moveInside(); 83 84 public: 85 /*! 86 * Generate the insets for all of the walls of a given layer part after optimizing the ordering. 87 * \return Whether this function added anything to the layer plan 88 */ 89 bool processInsetsWithOptimizedOrdering(); 90 91 /*! 92 * Test whether it looks to be worthwhile to optimize the inset order of a given layer part. 93 * \param mesh The mesh to be added to the layer plan. 94 * \param part The part for which to create gcode 95 * \return true if it is worth optimizing the inset order, false if not 96 */ 97 static bool optimizingInsetsIsWorthwhile(const SliceMeshStorage& mesh, const SliceLayerPart& part); 98 }; 99 100 } //namespace cura 101 102 #endif // INSET_ORDER_OPTIMIZER_H 103