1 #ifndef slic3r_Flow_hpp_ 2 #define slic3r_Flow_hpp_ 3 4 #include "libslic3r.h" 5 #include "Config.hpp" 6 #include "Exception.hpp" 7 #include "ExtrusionEntity.hpp" 8 9 namespace Slic3r { 10 11 class PrintObject; 12 13 // Extra spacing of bridge threads, in mm. 14 #define BRIDGE_EXTRA_SPACING 0.05 15 16 // Overlap factor of perimeter lines. Currently no overlap. 17 #ifdef HAS_PERIMETER_LINE_OVERLAP 18 #define PERIMETER_LINE_OVERLAP_FACTOR 1.0 19 #endif 20 21 enum FlowRole { 22 frExternalPerimeter, 23 frPerimeter, 24 frInfill, 25 frSolidInfill, 26 frTopSolidInfill, 27 frSupportMaterial, 28 frSupportMaterialInterface, 29 }; 30 31 class FlowError : public Slic3r::InvalidArgument 32 { 33 public: FlowError(const std::string & what_arg)34 FlowError(const std::string& what_arg) : Slic3r::InvalidArgument(what_arg) {} FlowError(const char * what_arg)35 FlowError(const char* what_arg) : Slic3r::InvalidArgument(what_arg) {} 36 }; 37 38 class FlowErrorNegativeSpacing : public FlowError 39 { 40 public: 41 FlowErrorNegativeSpacing(); 42 }; 43 44 class FlowErrorNegativeFlow : public FlowError 45 { 46 public: 47 FlowErrorNegativeFlow(); 48 }; 49 50 class FlowErrorMissingVariable : public FlowError 51 { 52 public: FlowErrorMissingVariable(const std::string & what_arg)53 FlowErrorMissingVariable(const std::string& what_arg) : FlowError(what_arg) {} 54 }; 55 56 class Flow 57 { 58 public: 59 // Non bridging flow: Maximum width of an extrusion with semicircles at the ends. 60 // Bridging flow: Bridge thread diameter. 61 float width; 62 // Non bridging flow: Layer height. 63 // Bridging flow: Bridge thread diameter = layer height. 64 float height; 65 // Nozzle diameter. 66 float nozzle_diameter; 67 // Is it a bridge? 68 bool bridge; 69 Flow(float _w,float _h,float _nd,bool _bridge=false)70 Flow(float _w, float _h, float _nd, bool _bridge = false) : 71 width(_w), height(_h), nozzle_diameter(_nd), bridge(_bridge) {} 72 73 float spacing() const; 74 float spacing(const Flow &other) const; 75 double mm3_per_mm() const; scaled_width() const76 coord_t scaled_width() const { return coord_t(scale_(this->width)); } scaled_spacing() const77 coord_t scaled_spacing() const { return coord_t(scale_(this->spacing())); } scaled_spacing(const Flow & other) const78 coord_t scaled_spacing(const Flow &other) const { return coord_t(scale_(this->spacing(other))); } 79 80 // Elephant foot compensation spacing to be used to detect narrow parts, where the elephant foot compensation cannot be applied. 81 // To be used on frExternalPerimeter only. 82 // Enable some perimeter squish (see INSET_OVERLAP_TOLERANCE). 83 // Here an overlap of 0.2x external perimeter spacing is allowed for by the elephant foot compensation. scaled_elephant_foot_spacing() const84 coord_t scaled_elephant_foot_spacing() const { return coord_t(0.5f * float(this->scaled_width() + 0.6f * this->scaled_spacing())); } 85 operator ==(const Flow & rhs) const86 bool operator==(const Flow &rhs) const { return this->width == rhs.width && this->height == rhs.height && this->nozzle_diameter == rhs.nozzle_diameter && this->bridge == rhs.bridge; } 87 88 static Flow new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio); 89 // Create a flow from the spacing of extrusion lines. 90 // This method is used exclusively to calculate new flow of 100% infill, where the extrusion width was allowed to scale 91 // to fit a region with integer number of lines. 92 static Flow new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge); 93 94 // Sane extrusion width defautl based on nozzle diameter. 95 // The defaults were derived from manual Prusa MK3 profiles. 96 static float auto_extrusion_width(FlowRole role, float nozzle_diameter); 97 98 // Extrusion width from full config, taking into account the defaults (when set to zero) and ratios (percentages). 99 // Precise value depends on layer index (1st layer vs. other layers vs. variable layer height), 100 // on active extruder etc. Therefore the value calculated by this function shall be used as a hint only. 101 static double extrusion_width(const std::string &opt_key, const ConfigOptionFloatOrPercent *opt, const ConfigOptionResolver &config, const unsigned int first_printing_extruder = 0); 102 static double extrusion_width(const std::string &opt_key, const ConfigOptionResolver &config, const unsigned int first_printing_extruder = 0); 103 }; 104 105 extern Flow support_material_flow(const PrintObject *object, float layer_height = 0.f); 106 extern Flow support_material_1st_layer_flow(const PrintObject *object, float layer_height = 0.f); 107 extern Flow support_material_interface_flow(const PrintObject *object, float layer_height = 0.f); 108 109 } 110 111 #endif 112