@@ -57,6 +57,8 @@ class LayerPlan : public NoCopy
5757#ifdef BUILD_TESTS
5858 friend class AddTravelTest ;
5959 friend class FffGcodeWriterTest_SurfaceGetsExtraInfillLinesUnderIt_Test ;
60+ friend class AntiOozeAmountsTest ;
61+ FRIEND_TEST (AntiOozeAmountsTest, ComputeAntiOozeAmounts);
6062#endif
6163
6264public:
@@ -86,6 +88,36 @@ class LayerPlan : public NoCopy
8688 Point3LL coasting_start_pos;
8789 };
8890
91+ struct TravelDurations
92+ {
93+ Duration z_hop; // !< The duration of the Z hop start and end
94+ Duration travel; // !< The duration of the full travel
95+ };
96+
97+ struct AntiOozeSettings
98+ {
99+ double distance;
100+ Velocity speed;
101+ Ratio during_travel_ratio;
102+ };
103+
104+ struct AntiOozeIntermediateAmounts
105+ {
106+ Ratio actual_during_travel_ratio;
107+ Duration total_expected_duration;
108+ Duration expected_duration_during_travel;
109+ double expected_amount_during_travel;
110+ double actual_amount_during_travel;
111+ };
112+
113+ enum class TravelRetractionState
114+ {
115+ None, // There is no retraction/prime
116+ Retracting, // We are retracting while traveling
117+ Travelling, // We are traveling, but neither retracting nor priming, just moving
118+ Priming, // We are priming while traveling
119+ };
120+
89121 const SliceDataStorage& storage_; // !< The polygon data obtained from FffPolygonProcessor
90122 const LayerIndex layer_nr_; // !< The layer number of this layer plan
91123 const bool is_initial_layer_; // !< Whether this is the first layer (which might be raft)
@@ -858,9 +890,15 @@ class LayerPlan : public NoCopy
858890 * @param position The position to move to. The Z coordinate is an offset to the current layer position
859891 * @param speed The actual used speed
860892 * @param path_z_offset The global path Z offset to be applied
893+ * @param retract_distance The absolute retraction distance to be reached during this travel move, or nullopt to leave it unchanged
861894 * @note This function is to be used when dealing with 3D coordinates. If you have 2D coordinates, just call gcode.writeTravel()
862895 */
863- void writeTravelRelativeZ (GCodeExport& gcode, const Point3LL& position, const Velocity& speed, const coord_t path_z_offset);
896+ void writeTravelRelativeZ (
897+ GCodeExport& gcode,
898+ const Point3LL& position,
899+ const Velocity& speed,
900+ const coord_t path_z_offset,
901+ const std::optional<double > retract_distance = std::nullopt );
864902
865903 /* !
866904 * \brief Write an extrusion move and properly apply the various Z offsets
@@ -1042,6 +1080,72 @@ class LayerPlan : public NoCopy
10421080 * \return The distance from the start of the current wall line to the first bridge segment
10431081 */
10441082 coord_t computeDistanceToBridgeStart (const ExtrusionLine& wall, const size_t current_index, const coord_t min_bridge_line_len) const ;
1083+
1084+ /* !
1085+ * Compute the Z-hop and travel duration for the given travel path
1086+ * @param gcode The gcode exporter, which we need to get the current nozzle position
1087+ * @param extruder The current extruder, for which we need the settings
1088+ * @param path The travel path we want the durations of
1089+ * @param z_hop_height The Z-hop height
1090+ * @return The computed path durations
1091+ */
1092+ static TravelDurations computeTravelDurations (const GCodeExport& gcode, const ExtruderTrain& extruder, const GCodePath& path, const coord_t z_hop_height);
1093+
1094+ /* !
1095+ * Compute the anti-ooze (retraction and priming) amounts to be processed during stationary/Z-hop/travel steps
1096+ * @param gcode The gcode exporter
1097+ * @param extruder The current extruder
1098+ * @param path The raw travel path to be exported
1099+ * @param z_hop_height The Z-hop height
1100+ * @param retraction_config The retraction/priming configuration to be used
1101+ * @param retraction_amounts The retraction amounts to be set
1102+ * @param priming_amounts The priming amounts to be set
1103+ */
1104+ static void computeAntiOozeAmounts (
1105+ const GCodeExport& gcode,
1106+ const ExtruderTrain& extruder,
1107+ const GCodePath& path,
1108+ const coord_t z_hop_height,
1109+ const RetractionAndWipeConfig* retraction_config,
1110+ std::optional<TravelAntiOozing>& retraction_amounts,
1111+ std::optional<TravelAntiOozing>& priming_amounts);
1112+
1113+ /* !
1114+ * Compute the anti-ooze amounts to be processed during stationary/Z-hop/travel steps for either a retraction or a priming
1115+ * @param travel_durations The pre-calculated travel durations
1116+ * @param gcode The gcode exporter
1117+ * @param path The raw travel path to be exported
1118+ * @param settings The anti-ooze settings to be applied
1119+ * @param reversed Indicates if we should process the path forwards (retraction at the beginning) or backwards (prime at the end)
1120+ */
1121+ static void computeAntiOozeTravelSplit (
1122+ const GCodeExport& gcode,
1123+ const GCodePath& path,
1124+ const Velocity& speed,
1125+ const double amount_during_travel,
1126+ const bool reversed,
1127+ TravelAntiOozing& anti_oozing);
1128+
1129+ /* !
1130+ * Write a single travel segment, taking care of the retraction and priming during travel
1131+ * @param travel_retraction_state The current travel retraction state, which may be updated
1132+ * @param gcode The gcode exporter
1133+ * @param path The full travel path being written
1134+ * @param retraction_amounts The pre-calculated retraction amounts to be processed during this travel move
1135+ * @param priming_amounts The pre-calculated priming amounts to be processed during this travel move
1136+ * @param speed The travel speed
1137+ * @param point_index The index of the current point in the path to be written
1138+ * @warning When travel_retraction_state is None, retraction_amounts and priming_amounts may be std::nullopt, however if it is anything different,
1139+ * it is assumed that they both have a value.
1140+ */
1141+ void writeTravelSegment (
1142+ TravelRetractionState& travel_retraction_state,
1143+ GCodeExport& gcode,
1144+ const GCodePath& path,
1145+ const std::optional<TravelAntiOozing>& retraction_amounts,
1146+ const std::optional<TravelAntiOozing>& priming_amounts,
1147+ const Velocity& speed,
1148+ const size_t point_index);
10451149};
10461150
10471151} // namespace cura
0 commit comments