Skip to content

Commit d7d1f71

Browse files
committed
Implement functionality to select whether cradle lines should be printed towards the model, or away from it.
1 parent 340e70f commit d7d1f71

File tree

9 files changed

+83
-31
lines changed

9 files changed

+83
-31
lines changed

include/PathOrderOptimizer.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class PathOrderOptimizer
205205

206206
// For some Z seam types the start position can be pre-computed.
207207
// This is faster since we don't need to re-compute the start position at each step then.
208-
precompute_start &= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
208+
precompute_start &= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
209209
if (precompute_start)
210210
{
211211
for (auto& path : paths_)
@@ -584,7 +584,7 @@ class PathOrderOptimizer
584584
}
585585

586586
const bool precompute_start
587-
= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
587+
= seam_config_.type_ == EZSeamType::RANDOM || seam_config_.type_ == EZSeamType::USER_SPECIFIED || seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED ||seam_config_.type_ == EZSeamType::SHARPEST_CORNER;
588588
if (! path->is_closed_ || ! precompute_start) // Find the start location unless we've already precomputed it.
589589
{
590590
path->start_vertex_ = findStartLocation(*path, start_position);
@@ -676,6 +676,14 @@ class PathOrderOptimizer
676676
{
677677
if (! path.is_closed_)
678678
{
679+
if (seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED)
680+
{
681+
if(getDirectDistance(path.converted_->back(), seam_config_.pos_) < getDirectDistance(path.converted_->front(), seam_config_.pos_))
682+
{
683+
return path.converted_->size() - 1; // Back end is closer.
684+
}
685+
return 0;
686+
}
679687
// For polylines, the seam settings are not applicable. Simply choose the position closest to target_pos then.
680688
const coord_t back_distance
681689
= (combing_boundary_ == nullptr) ? getDirectDistance(path.converted_->back(), target_pos) : getCombingDistance(path.converted_->back(), target_pos);

include/SupportInfillPart.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef SUPPORT_INFILL_PART_H
55
#define SUPPORT_INFILL_PART_H
66

7+
#include <optional>
78
#include <vector>
89

910
#include "geometry/Polygon.h"
@@ -38,8 +39,16 @@ class SupportInfillPart
3839
coord_t custom_line_distance_; //!< The distance between support infill lines. 0 means use the default line distance instead.
3940
bool use_fractional_config_; //!< Request to use the configuration used to fill a partial layer height here, instead of the normal full layer height configuration.
4041
EFillMethod custom_line_pattern_;
42+
std::optional<Point2LL> start_near_location;
4143

42-
SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate = 0, coord_t custom_line_distance = 0, EFillMethod custom_line_pattern = EFillMethod::NONE );
44+
SupportInfillPart(const SingleShape& outline,
45+
coord_t support_line_width,
46+
bool use_fractional_config,
47+
int inset_count_to_generate = 0,
48+
coord_t custom_line_distance = 0,
49+
EFillMethod custom_line_pattern = EFillMethod::NONE,
50+
std::optional<Point2LL> start_near_location = std::optional<Point2LL>()
51+
);
4352

4453
const Shape& getInfillArea() const;
4554
};

include/TreeSupport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class TreeSupport
332332
* \param support_roof_extra_wall_storage_fractional[in] Areas of roof that were projected one layer up, but roofs need to have a wall to print correctly.
333333
* \param fake_roof_areas_combined[out] All areas that contain the fake roofs.
334334
* \param cradle_base_areas[out] Copy of all cradle base areas. Already added to correct storage.
335-
* \param cradle_support_line_areas[out] All cradle lines consisting of regular support. Will still have to be added as support (Done in generateSupportSkin)
335+
* \param cradle_support_line_areas[out] All cradle lines consisting of regular support. Already added as support.
336336
* \param storage[in,out] The storage where the support should be stored.
337337
* \param cradle_data[in] All currently existing cradles, with its corresponding cradle lines.
338338
*/
@@ -371,7 +371,7 @@ class TreeSupport
371371
* \param support_skin_storage[out] Areas where high density support should be generated.
372372
* \param fake_roof_areas_combined[in] All areas that contain the fake roofs.
373373
* \param cradle_base_areas[in] Copy of all cradle base areas. Already added to correct storage.
374-
* \param cradle_support_line_areas[in] All cradle lines consisting of regular support. Will be to be added as support.
374+
* \param cradle_support_line_areas[in] All cradle lines consisting of regular support. Already added as support.
375375
* \param hole_parts[in] Parts of holes, ordered by layer.
376376
* \param valid_holes[in] Indices of holes that rest on outer wall, by layer.
377377
* \param non_removable_holes[in] Indices of holes that can not be removed, by layer.

include/settings/EnumSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum class EZSeamType
7070
SHORTEST,
7171
USER_SPECIFIED,
7272
SHARPEST_CORNER,
73+
INTERNAL_SPECIFIED,
7374

7475
/* The 'Skirt/brim' type behaves like shortest, except it doesn't try to do tie-breaking for similar locations to
7576
* the last attempt, as that gives a different result when the seams are next to each other instead of on top.

src/FffGcodeWriter.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,8 +3425,10 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
34253425
constexpr bool retract_before_outer_wall = false;
34263426
constexpr coord_t wipe_dist = 0;
34273427
const LayerIndex layer_nr = gcode_layer.getLayerNr();
3428-
ZSeamConfig z_seam_config
3429-
= ZSeamConfig(EZSeamType::SHORTEST, gcode_layer.getLastPlannedPositionOrStartingPosition(), EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE, false);
3428+
const ZSeamConfig z_seam_config(part.start_near_location.has_value() ? EZSeamType::INTERNAL_SPECIFIED : EZSeamType::SHORTEST,
3429+
part.start_near_location.has_value() ? part.start_near_location.value() : gcode_layer.getLastPlannedPositionOrStartingPosition(),
3430+
EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE,
3431+
false);
34303432
Shape disallowed_area_for_seams{};
34313433
if (infill_extruder.settings_.get<bool>("support_z_seam_away_from_model") && (layer_nr >= 0))
34323434
{
@@ -3580,7 +3582,6 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
35803582
constexpr bool spiralize = false;
35813583
constexpr Ratio flow_ratio = 1.0_r;
35823584
constexpr bool always_retract = false;
3583-
const std::optional<Point2LL> start_near_location = std::optional<Point2LL>();
35843585

35853586
gcode_layer.addPolygonsByOptimizer(
35863587
support_polygons,
@@ -3591,7 +3592,7 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
35913592
flow_ratio,
35923593
always_retract,
35933594
alternate_layer_print_direction,
3594-
start_near_location);
3595+
part.start_near_location);
35953596
added_something = true;
35963597
}
35973598

@@ -3600,7 +3601,6 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
36003601
constexpr bool enable_travel_optimization = false;
36013602
constexpr coord_t wipe_dist = 0;
36023603
constexpr Ratio flow_ratio = 1.0;
3603-
const std::optional<Point2LL> near_start_location = std::optional<Point2LL>();
36043604
constexpr double fan_speed = GCodePathConfig::FAN_SPEED_DEFAULT;
36053605

36063606
gcode_layer.addLinesByOptimizer(
@@ -3610,7 +3610,7 @@ bool FffGcodeWriter::processSupportInfill(const SliceDataStorage& storage, Layer
36103610
enable_travel_optimization,
36113611
wipe_dist,
36123612
flow_ratio,
3613-
near_start_location,
3613+
part.start_near_location,
36143614
fan_speed,
36153615
alternate_layer_print_direction);
36163616

@@ -3715,6 +3715,10 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
37153715
constexpr coord_t pocket_size = 0;
37163716
const coord_t max_resolution = roof_extruder.settings_.get<coord_t>("meshfix_maximum_resolution");
37173717
const coord_t max_deviation = roof_extruder.settings_.get<coord_t>("meshfix_maximum_deviation");
3718+
const ZSeamConfig z_seam_config(roof_part.start_near_location.has_value() ? EZSeamType::INTERNAL_SPECIFIED : EZSeamType::SHORTEST,
3719+
roof_part.start_near_location.has_value() ? roof_part.start_near_location.value() : gcode_layer.getLastPlannedPositionOrStartingPosition(),
3720+
EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE,
3721+
false);
37183722

37193723
coord_t support_roof_line_distance = roof_part.custom_line_distance_ == 0 ? roof_extruder.settings_.get<coord_t>("support_roof_line_distance") : roof_part.custom_line_distance_;
37203724
const coord_t support_roof_line_width = roof_extruder.settings_.get<coord_t>("support_roof_line_width");
@@ -3772,20 +3776,19 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
37723776
gcode_layer.setIsInside(false); // going to print stuff outside print object, i.e. support
37733777
if (gcode_layer.getLayerNr() == 0)
37743778
{
3775-
gcode_layer.addPolygonsByOptimizer(wall, current_roof_config);
3779+
gcode_layer.addPolygonsByOptimizer(wall, current_roof_config, z_seam_config);
37763780
}
37773781
if (! roof_polygons.empty())
37783782
{
37793783
constexpr bool force_comb_retract = false;
37803784
gcode_layer.addTravel(roof_polygons[0][0], force_comb_retract);
3781-
gcode_layer.addPolygonsByOptimizer(roof_polygons, current_roof_config);
3785+
gcode_layer.addPolygonsByOptimizer(roof_polygons, current_roof_config, z_seam_config);
37823786
}
37833787
if (! roof_paths.empty())
37843788
{
37853789
const GCodePathConfig& config = current_roof_config;
37863790
constexpr bool retract_before_outer_wall = false;
37873791
constexpr coord_t wipe_dist = 0;
3788-
const ZSeamConfig z_seam_config(EZSeamType::SHORTEST, gcode_layer.getLastPlannedPositionOrStartingPosition(), EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_NONE, false);
37893792

37903793
InsetOrderOptimizer wall_orderer(
37913794
*this,
@@ -3808,7 +3811,10 @@ bool FffGcodeWriter::addSupportRoofsToGCode(
38083811
roof_paths,
38093812
storage.getModelBoundingBox().flatten().getMiddle());wall_orderer.addToLayer();
38103813
}
3811-
gcode_layer.addLinesByOptimizer(roof_lines, current_roof_config, (pattern == EFillMethod::ZIG_ZAG) ? SpaceFillType::PolyLines : SpaceFillType::Lines);
3814+
constexpr bool enable_travel_optimization = false;
3815+
constexpr coord_t wipe_dist = 0;
3816+
constexpr Ratio flow_ratio = 1.0;
3817+
gcode_layer.addLinesByOptimizer(roof_lines, current_roof_config, (pattern == EFillMethod::ZIG_ZAG) ? SpaceFillType::PolyLines : SpaceFillType::Lines, enable_travel_optimization, wipe_dist, flow_ratio, roof_part.start_near_location);
38123818
}
38133819
}
38143820
return added_support;

src/InsetOrderOptimizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ std::optional<size_t> InsetOrderOptimizer::insertSeamPoint(ExtrusionLine& closed
183183
case EZSeamType::USER_SPECIFIED:
184184
request_point = z_seam_config_.pos_;
185185
break;
186+
case EZSeamType::INTERNAL_SPECIFIED:
187+
request_point = z_seam_config_.pos_;
188+
break;
186189
case EZSeamType::SHORTEST:
187190
request_point = gcode_layer_.getLastPlannedPositionOrStartingPosition();
188191
break;
@@ -195,7 +198,7 @@ std::optional<size_t> InsetOrderOptimizer::insertSeamPoint(ExtrusionLine& closed
195198
size_t closest_junction_idx = 0;
196199
coord_t closest_distance_sqd = std::numeric_limits<coord_t>::max();
197200
bool should_reclaculate_closest = false;
198-
if (z_seam_config_.type_ == EZSeamType::USER_SPECIFIED)
201+
if (z_seam_config_.type_ == EZSeamType::USER_SPECIFIED || z_seam_config_.type_ == EZSeamType::INTERNAL_SPECIFIED)
199202
{
200203
// For user-defined seams you usually don't _actually_ want the _closest_ point, per-se,
201204
// since you want the seam-line to be continuous in 3D space.

src/SupportInfillPart.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
using namespace cura;
99

1010

11-
SupportInfillPart::SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate, coord_t custom_line_distance, EFillMethod custom_line_pattern)
11+
SupportInfillPart::SupportInfillPart(const SingleShape& outline, coord_t support_line_width, bool use_fractional_config, int inset_count_to_generate, coord_t custom_line_distance, EFillMethod custom_line_pattern, std::optional<Point2LL> start_near_location)
1212
: outline_(outline)
1313
, outline_boundary_box_(outline)
1414
, support_line_width_(support_line_width)
1515
, inset_count_to_generate_(inset_count_to_generate)
1616
, custom_line_distance_(custom_line_distance)
1717
, custom_line_pattern_(custom_line_pattern)
1818
, use_fractional_config_(use_fractional_config)
19-
19+
, start_near_location(start_near_location)
2020

2121
{
2222
infill_area_per_combine_per_density_.clear();

0 commit comments

Comments
 (0)