Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra travel move to outer wall start position #2075

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e167f89
Add extra travel move to outer wall start position
wawanbreton Apr 19, 2024
34b4c19
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
saumyaj3 Apr 29, 2024
7d947d1
Refined travel and wall printing functionalities
saumyaj3 May 1, 2024
a368605
Applied clang-format.
saumyaj3 May 1, 2024
ae6c9e3
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
saumyaj3 May 2, 2024
0fb536f
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
saumyaj3 May 2, 2024
446c073
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
saumyaj3 May 3, 2024
a857c54
Applied clang-format.
saumyaj3 May 3, 2024
a347254
Update InsetOrderOptimizer.cpp
saumyaj3 May 3, 2024
e3f4bb8
Merge branch 'CURA-9830_consolidate_polygon_classes' into CURA-11830_…
saumyaj3 May 6, 2024
6d77384
Refactor first wall travel and add new approach move feature
saumyaj3 May 6, 2024
03e4df1
Applied clang-format.
saumyaj3 May 6, 2024
acebd81
Standardize code
wawanbreton May 16, 2024
52648a6
Polish approach segment generation
wawanbreton May 16, 2024
371ec47
Basically working straight approach move
wawanbreton May 21, 2024
1a2eb17
Make the unretract travel move inside the model
wawanbreton May 23, 2024
c33b29c
Make the unretraction move smoothly approach the start position
wawanbreton May 23, 2024
b5d8f59
Fix wrongly computed remaining unretraction amount
wawanbreton May 23, 2024
20087fe
Move loopOverSegments method to ClosedPolyline
wawanbreton May 23, 2024
799c0f1
Clarify variables names
wawanbreton May 23, 2024
24e3b50
Fix potentially wrong unretraction amount
wawanbreton May 23, 2024
218f527
Add setting for inset value and polish code
wawanbreton May 24, 2024
ac760c9
Merge remote-tracking branch 'origin/main' into CURA-11830_smart_seam…
wawanbreton May 24, 2024
1d215c3
Fix unit tests build
wawanbreton May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ set(engine_SRCS # Except main.cpp.
src/geometry/Polyline.cpp
src/geometry/ClosedPolyline.cpp
src/geometry/MixedLinesSet.cpp
src/geometry/Point2D.cpp
)

add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS})
Expand Down
2 changes: 2 additions & 0 deletions Cura.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ message Polygon {
MoveRetractionType = 9;
SupportInterfaceType = 10;
PrimeTowerType = 11;
MoveUnretractionType = 12;

}
Type type = 1; // Type of move
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)
Expand Down
7 changes: 6 additions & 1 deletion include/GCodePathConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace cura
struct GCodePathConfig
{
coord_t z_offset{}; //<! vertical offset from 'full' layer height
PrintFeatureType type{}; //!< name of the feature type
PrintFeatureType type_{}; //!< name of the feature type
coord_t line_width{}; //!< width of the line extruded
coord_t layer_thickness{}; //!< current layer height in micron
Ratio flow{}; //!< extrusion flow modifier.
Expand All @@ -28,6 +28,7 @@ struct GCodePathConfig
double fan_speed{ FAN_SPEED_DEFAULT }; //!< fan speed override for this path, value should be within range 0-100 (inclusive) and ignored otherwise
double extrusion_mm3_per_mm{ calculateExtrusion() }; //!< current mm^3 filament moved per mm line traversed
static constexpr double FAN_SPEED_DEFAULT = -1;
bool is_unretraction_path{ false }; // whether current config is used for unretraction path

[[nodiscard]] constexpr bool operator==(const GCodePathConfig& other) const noexcept = default;
[[nodiscard]] constexpr auto operator<=>(const GCodePathConfig& other) const = default;
Expand Down Expand Up @@ -56,6 +57,8 @@ struct GCodePathConfig

[[nodiscard]] bool isTravelPath() const noexcept;

[[nodiscard]] bool isUnretractionMove() const noexcept;

[[nodiscard]] bool isBridgePath() const noexcept;

[[nodiscard]] double getFanSpeed() const noexcept;
Expand All @@ -66,6 +69,8 @@ struct GCodePathConfig

[[nodiscard]] PrintFeatureType getPrintFeatureType() const noexcept;

void setPrintFeatureType(PrintFeatureType type);

private:
[[nodiscard]] double calculateExtrusion() const noexcept;
};
Expand Down
4 changes: 4 additions & 0 deletions include/InsetOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class InsetOrderOptimizer
* line widths, flows, speeds, etc to print this mesh with.
* \param part The part from which to read the previously generated insets.
* \param layer_nr The current layer number.
* \param is_outer_shell determines if the element added is the outer wall/shell of the mesh
*/
InsetOrderOptimizer(
const FffGcodeWriter& gcode_writer,
Expand All @@ -56,8 +57,10 @@ class InsetOrderOptimizer
const size_t wall_x_extruder_nr,
const ZSeamConfig& z_seam_config,
const std::vector<VariableWidthLines>& paths,
const bool is_outer_shell = false,
const Shape& disallowed_areas_for_seams = {});


/*!
* Adds the insets to the given layer plan.
*
Expand Down Expand Up @@ -107,6 +110,7 @@ class InsetOrderOptimizer
const ZSeamConfig& z_seam_config_;
const std::vector<VariableWidthLines>& paths_;
const LayerIndex layer_nr_;
const bool is_outer_shell_;
Shape disallowed_areas_for_seams_;

std::vector<std::vector<const Polygon*>> inset_polys_; // vector of vectors holding the inset polygons
Expand Down
31 changes: 28 additions & 3 deletions include/LayerPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ class LayerPlan : public NoCopy
* The first travel move in a layer will result in a bogus travel move with
* no combing and no retraction. This travel move needs to be fixed
* afterwards.
* \param p The point to travel to.
* \param pos The point to travel to.
* \param force_retract Whether to force a retraction to occur.
*/
GCodePath& addTravel(const Point2LL& p, const bool force_retract = false, const coord_t z_offset = 0);
GCodePath& addTravel(const Point2LL& pos, const bool force_retract = false, const coord_t z_offset = 0);

/*!
* Add a travel path to a certain point and retract if needed.
Expand Down Expand Up @@ -502,6 +502,8 @@ class LayerPlan : public NoCopy
* polyline).
* \param is_reversed Whether to print this wall in reverse direction.
* \param is_linked_path Whether the path is a continuation off the previous path
* \param smooth_approach Whether we should make a smoothed approach to the first point,
* or just move straight to it
*/
void addWall(
const ExtrusionLine& wall,
Expand All @@ -515,7 +517,8 @@ class LayerPlan : public NoCopy
bool always_retract,
const bool is_closed,
const bool is_reversed,
const bool is_linked_path);
const bool is_linked_path,
const bool smooth_approach = false);

/*!
* Add an infill wall to the g-code
Expand Down Expand Up @@ -806,6 +809,28 @@ class LayerPlan : public NoCopy
const coord_t wipe_dist,
const Ratio flow_ratio,
const double fan_speed);

void addTravelBeforeSeam(const Point2LL& p, const GCodePathConfig& config);

/*!
* Begin the first wall with a travel move, executing specific procedures to optimize the process.
*
* Special conditions for this function are:
* - If `always_retract` is true, a retraction is always performed regardless of other factors.
* - If there's an optional `next` point provided, the function adds an intermediate position where the nozzle should go to begin printing the segment with optimal nozzle speed
* and extrusion parameters.
* - The focus of this method is the travel move for the first wall or layer in a print action, specifically optimizing retraction, travel speed, and the starting point for
* extrusion, if any.
*
* Note: This function is for handling very specific cases (such as initial layer or wall) in 3D printing G-code generation and should be used appropriately.
*
* \param pos The point to travel to.
* \param always_retract Whether to always enforce a retraction action.
* \param next the subsequent point of the segment moving towards. If provided, an intermediate travel point is added, when feasible, to optimize the start of the actual print
* action with proper nozzle speed and extrusion.
*/

void addFirstWallTravel(const Point2LL& pos, const bool force_retract, const Point2LL* next, const GCodePathConfig& config, const Ratio& flow, const Ratio& width_factor);
};

} // namespace cura
Expand Down
7 changes: 3 additions & 4 deletions include/PrintFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace cura
{

enum class PrintFeatureType: unsigned char
enum class PrintFeatureType : unsigned char
{
NoneType = 0, // used to mark unspecified jumps in polygons. libArcus depends on it
OuterWall = 1,
Expand All @@ -18,14 +18,13 @@ enum class PrintFeatureType: unsigned char
MoveRetraction = 9,
SupportInterface = 10,
PrimeTower = 11,
NumPrintFeatureTypes = 12 // this number MUST be the last one because other modules will
MoveUnretraction = 12,
NumPrintFeatureTypes = 13 // this number MUST be the last one because other modules will
// use this symbol to get the total number of types, which can
// be used to create an array or so
};




} // namespace cura

#endif // PRINT_FEATURE
32 changes: 29 additions & 3 deletions include/gcodeExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifdef BUILD_TESTS
#include <gtest/gtest_prod.h> //To allow tests to use protected members.
#endif
#include <optional>
#include <sstream> // for stream.str()
#include <stdio.h>

Expand All @@ -26,6 +27,7 @@ namespace cura

class RetractionConfig;
class SliceDataStorage;
class SliceLayerPart;
struct WipeScriptConfig;

// The GCodeExport class writes the actual GCode. This is the only class that knows how GCode looks and feels.
Expand Down Expand Up @@ -192,6 +194,8 @@ class GCodeExport : public NoCopy
*/
double mm3ToE(double mm3);

double mm3ToMm(double mm3);

/*!
* Convert a distance value to an E value (which might be linear/distance based as well) for the current extruder.
*
Expand Down Expand Up @@ -250,7 +254,7 @@ class GCodeExport : public NoCopy

bool getExtruderIsUsed(const int extruder_nr) const; //!< return whether the extruder has been used throughout printing all meshgroup up till now

Point2LL getGcodePos(const coord_t x, const coord_t y, const int extruder_train) const;
Point2LL getGcodePos(const coord_t x, const coord_t y, const size_t extruder_train) const;

void setFlavor(EGCodeFlavor flavor);
EGCodeFlavor getFlavor() const;
Expand Down Expand Up @@ -446,13 +450,26 @@ class GCodeExport : public NoCopy
* Write the F, X, Y, Z and E value (if they are not different from the last)
*
* convenience function called from writeExtrusion and writeTravel
*/
// void writeFXYZE(const Velocity& speed, const coord_t x, const coord_t y, const coord_t z, const double e, const PrintFeatureType& feature);

/*!
* \brief Write a G0/G1 command
*
* This function also applies the gcode offset by calling \ref GCodeExport::getGcodePos
* This function updates the \ref GCodeExport::total_bounding_box
* It estimates the time in \ref GCodeExport::estimateCalculator for the correct feature
* It updates \ref GCodeExport::currentPosition, \ref GCodeExport::current_e_value and \ref GCodeExport::currentSpeed
*
* \param command_name The actual command name, which should be "G0" or "G1" (but no check is performed)
* \param Tpeed movement speed
* \param x Target X position
* \param y Target Y position
* \param z Target Z position
* \param e_delta Extrusion amount to be performed while moving
* \param feature The type of feature being printed
*/
void writeFXYZE(const Velocity& speed, const coord_t x, const coord_t y, const coord_t z, const double e, const PrintFeatureType& feature);
void writeGCommand(const char* command_name, const Velocity& speed, const coord_t x, const coord_t y, const coord_t z, const double e_delta, const PrintFeatureType feature);

/*!
* The writeTravel and/or writeExtrusion when flavor == BFB
Expand All @@ -470,6 +487,8 @@ class GCodeExport : public NoCopy
*/
void processInitialLayerBedTemperature();

void sendTravelLine(const Point2LL& pos, PrintFeatureType line_type, const Velocity& speed);

public:
/*!
* Get ready for extrusion moves:
Expand All @@ -479,7 +498,7 @@ class GCodeExport : public NoCopy
* It estimates the time in \ref GCodeExport::estimateCalculator
* It updates \ref GCodeExport::current_e_value and \ref GCodeExport::currentSpeed
*/
void writeUnretractionAndPrime();
void writeUnretractionAndPrime(const std::optional<Point2LL>& pos = {}, const std::optional<Velocity>& override_speed = {}, const std::optional<double>& override_amount = {});
void writeRetraction(const RetractionConfig& config, bool force = false, bool extruder_switch = false);

/*!
Expand Down Expand Up @@ -613,6 +632,13 @@ class GCodeExport : public NoCopy
* \param wipe_config Config with wipe script settings.
*/
void insertWipeScript(const WipeScriptConfig& wipe_config);

void writeApproachToSeam(
const Point2LL& pos,
const Velocity& speed,
const std::vector<SliceLayerPart>& current_mesh_parts,
const coord_t wall_line_width,
const coord_t z_seam_approach_inset);
};

} // namespace cura
Expand Down
2 changes: 2 additions & 0 deletions include/geometry/ClosedPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class ClosedPolyline : public Polyline
* \return An open polyline instance, with the end point at the same position of the start point
*/
[[nodiscard]] OpenPolyline toPseudoOpenPolyline() const;

[[nodiscard]] const_segments_iterator loopOverSegments(const const_segments_iterator& start, const_segments_iterator::difference_type diff) const;
};

} // namespace cura
Expand Down
52 changes: 52 additions & 0 deletions include/geometry/Point2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef UTILS_POINT2D_H
#define UTILS_POINT2D_H

#include "geometry/Point2LL.h"

namespace cura
{

class Point2D
{
private:
double x_{ 0.0 };
double y_{ 0.0 };

public:
Point2D(double x, double y);

Point2D(const Point2LL& other);

[[nodiscard]] Point2D operator*(const coord_t scale) const;

[[nodiscard]] Point2D operator*(const double scale) const;

[[nodiscard]] Point2D operator/(const double scale) const;

[[nodiscard]] double getX() const
{
return x_;
}

[[nodiscard]] double getY() const
{
return y_;
}

[[nodiscard]] double size() const;

[[nodiscard]] double size2() const;

[[nodiscard]] Point2D normalized() const;

void normalize();

Point2LL toPoint2LL() const;
};

} // namespace cura

#endif // UTILS_POINT2D_H
6 changes: 6 additions & 0 deletions include/geometry/Point2LL.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ INLINE double vSizeMM(const Point2LL& p0)
return std::sqrt(fx * fx + fy * fy);
}

INLINE Point2LL vResize(const Point2LL& point, coord_t size)
{
double size_factor = static_cast<double>(size) / static_cast<double>(vSize(point));
return point * size_factor;
}

INLINE Point2LL normal(const Point2LL& p0, coord_t length)
{
const coord_t len{ vSize(p0) };
Expand Down
5 changes: 5 additions & 0 deletions include/geometry/Polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class Polygon : public ClosedPolyline
return ClipperLib::Area(getPoints());
}

[[nodiscard]] bool isHole() const
{
return area() < 0.0;
}

[[nodiscard]] Point2LL centerOfMass() const;

[[nodiscard]] Shape offset(int distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const;
Expand Down
4 changes: 2 additions & 2 deletions include/geometry/Polyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class Polyline : public PointsSet
[[nodiscard]] const_segments_iterator endSegments() const;

/*! \brief Provides a begin iterator to iterate over all the segments of the line */
segments_iterator beginSegments();
[[nodiscard]] segments_iterator beginSegments();

/*! \brief Provides an end iterator to iterate over all the segments of the line */
segments_iterator endSegments();
[[nodiscard]] segments_iterator endSegments();

/*!
* Split these poly line objects into several line segment objects consisting of only two verts
Expand Down
16 changes: 16 additions & 0 deletions include/geometry/SegmentIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ struct SegmentIterator
source_iterator_type before_end_;

public:
SegmentIterator()
{
}

SegmentIterator(source_iterator_type pos, source_iterator_type begin, source_iterator_type end)
: current_pos_(pos)
, begin_(begin)
Expand All @@ -58,12 +62,24 @@ struct SegmentIterator
return Segment{ *current_pos_, *std::next(current_pos_) };
}

SegmentIterator& operator--()
{
current_pos_--;
return *this;
}

SegmentIterator& operator++()
{
current_pos_++;
return *this;
}

SegmentIterator& operator+=(difference_type diff)
{
current_pos_ += (diff);
return *this;
}

bool operator==(const SegmentIterator& other) const
{
return current_pos_ == other.current_pos_;
Expand Down
Loading
Loading