Skip to content

Commit 118d217

Browse files
committed
Search for active extruders to generate skirt/brim
CURA-12250
1 parent 192680d commit 118d217

File tree

11 files changed

+167
-167
lines changed

11 files changed

+167
-167
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ set(engine_SRCS # Except main.cpp.
9999

100100
src/feature_generation/FeatureGenerator.cpp include/feature_generation/FeatureGenerator.h
101101
src/feature_generation/MeshFeatureGenerator.cpp include/feature_generation/MeshFeatureGenerator.h
102-
src/feature_generation/SkirtBrimGenerator.cpp include/feature_generation/SkirtBrimGenerator.h
102+
src/feature_generation/SkirtBrimAppender.cpp include/feature_generation/SkirtBrimAppender.h
103103

104104
src/infill/ImageBasedDensityProvider.cpp
105105
src/infill/NoZigZagConnectorProcessor.cpp

doc/architecture_paths_graph.puml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ package "operation_transformation" {
6969
}
7070

7171
LayerPlanTravelMovesInserter -up-|> PrintOperationTransformer
72-
AddPrimeTowerTransformer -up-|> PrintOperationTransformer
7372
MinimumLayerTimeTransformer -up-|> PrintOperationTransformer
7473
CoastingTransformer -up-|> PrintOperationTransformer
7574
BackPressureCompensationTransformer -up-|> PrintOperationTransformer
@@ -78,6 +77,8 @@ package "operation_transformation" {
7877
AddBedTemperatureCommandsTransformer -up-|> InsertOperationOnTimeTransformer
7978
AddCoolingFanCommandsTransformer -up-|> InsertOperationOnTimeTransformer
8079
InsertOperationOnTimeTransformer -up-|> PrintOperationTransformer
80+
SkirtBrimAppender -up-|> PrintOperationTransformer
81+
PrimeTowerAppender -up-|> PrintOperationTransformer
8182

8283
LayerPlanTravelMovesInserter *-- "*" TravelMoveGenerator
8384
abstract TravelMoveGenerator
@@ -106,7 +107,6 @@ package "operation_transformation" {
106107
class AddNozzleTemperatureCommandsTransformer #paleturquoise
107108
class AddBedTemperatureCommandsTransformer #paleturquoise
108109
class AddCoolingFanCommandsTransformer #paleturquoise
109-
class AddPrimeTowerTransformer #paleturquoise
110110
class CombingTravelMoveGenerator #paleturquoise
111111
class MinimumLayerTimeTransformer #paleturquoise
112112
class CoastingTransformer #paleturquoise
@@ -116,23 +116,22 @@ package "operation_transformation" {
116116
class GradualFlowSplitter #paleturquoise
117117
class ScarfSeamSplitter #paleturquoise
118118
class SmoothSpeedSplitter #paleturquoise
119+
class PrimeTowerAppender #paleturquoise
119120
}
120121

121122
package "feature_generation" {
122123
abstract FeatureGenerator {
123-
{abstract} vector<FeatureExtrusion> generateFeatures(layer_index, extruder_index)
124+
{abstract} generateFeatures(layer_index, extruder_plans)
124125
}
125126

126127
MeshFeatureGenerator -up-|> FeatureGenerator
127128
NormalSupportGenerator -up-|> FeatureGenerator
128129
TreeSupportGenerator -up-|> FeatureGenerator
129130
OozeShieldGenerator -up-|> FeatureGenerator
130-
SkirtBrimGenerator -up-|> FeatureGenerator
131131

132132
class MeshFeatureGenerator #paleturquoise
133133
class NormalSupportGenerator #paleturquoise
134134
class TreeSupportGenerator #paleturquoise
135135
class OozeShieldGenerator #paleturquoise
136-
class SkirtBrimGenerator #paleturquoise
137136
}
138137
@enduml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2024 UltiMaker
2+
// CuraEngine is released under the terms of the AGPLv3 or higher
3+
4+
#pragma once
5+
6+
#include <settings/EnumSettings.h>
7+
8+
#include "operation_transformation/PrintOperationTransformer.h"
9+
#include "print_operation/PrintPlan.h"
10+
11+
namespace cura
12+
{
13+
14+
enum class EPlatformAdhesion;
15+
16+
class SkirtBrimAppender : public PrintOperationTransformer<PrintPlan>
17+
{
18+
public:
19+
explicit SkirtBrimAppender();
20+
21+
void process(PrintPlan* print_plan) override;
22+
};
23+
24+
} // namespace cura

include/feature_generation/SkirtBrimGenerator.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

include/print_operation/PrintOperationSequence.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ class SliceMeshStorage;
1616
class PlanExporter;
1717
class LayerPlan;
1818

19+
namespace SearchDepth
20+
{
21+
static constexpr std::optional<size_t> Full = std::nullopt;
22+
static constexpr std::optional<size_t> DirectChildren = 0;
23+
}; // namespace SearchDepth
24+
1925
class PrintOperationSequence : public PrintOperation, public std::enable_shared_from_this<PrintOperationSequence>
2026
{
2127
public:
2228
enum class SearchOrder
2329
{
24-
Forward, // Only search in direct children, forwards
25-
Backward, // Only search in direct children, backwards
26-
DepthFirstForward, // Search in children tree, depth-first forwards
27-
DepthFirstBackward, // Search in children tree, depth-first backwards
30+
Forward,
31+
Backward,
2832
};
2933

3034
public:
@@ -43,14 +47,23 @@ class PrintOperationSequence : public PrintOperation, public std::enable_shared_
4347

4448
std::optional<Point3LL> findEndPosition() const override;
4549

46-
std::shared_ptr<PrintOperation>
47-
findOperation(const std::function<bool(const std::shared_ptr<PrintOperation>&)>& search_function, const SearchOrder search_order = SearchOrder::Forward) const;
50+
/*!
51+
* Searches a child operation, recursively or not, forwards of backwards, given a search function
52+
*
53+
* @param search_function The search function that should find the matching operation
54+
* @param search_order Whether we should search forwards or backwards
55+
* @param max_depth The maximum depth of children to look for. 0 means only direct children, nullopt means full tree. You case use SearchDepth defines.
56+
* @return The first found operation, or a null ptr if none was found
57+
* @note This function can also be used to iterate over children by providing a search function that always returns false
58+
*/
59+
std::shared_ptr<PrintOperation> findOperation(
60+
const std::function<bool(const std::shared_ptr<PrintOperation>&)>& search_function,
61+
const SearchOrder search_order = SearchOrder::Forward,
62+
const std::optional<size_t> max_depth = SearchDepth::DirectChildren) const;
4863

4964
template<class OperationType>
50-
std::shared_ptr<OperationType> findOperationByType(const SearchOrder search_order = SearchOrder::Forward) const;
51-
52-
std::shared_ptr<PrintOperation>
53-
findOperation(const std::vector<const PrintOperation*>& parents, const std::function<bool(const std::shared_ptr<PrintOperation>&)>& search_function) const;
65+
std::shared_ptr<OperationType>
66+
findOperationByType(const SearchOrder search_order = SearchOrder::Forward, const std::optional<size_t> max_depth = SearchDepth::DirectChildren) const;
5467

5568
const std::vector<std::shared_ptr<PrintOperation>>& getOperations() const noexcept;
5669

@@ -74,14 +87,15 @@ class PrintOperationSequence : public PrintOperation, public std::enable_shared_
7487
};
7588

7689
template<class OperationType>
77-
std::shared_ptr<OperationType> PrintOperationSequence::findOperationByType(const SearchOrder search_order) const
90+
std::shared_ptr<OperationType> PrintOperationSequence::findOperationByType(const SearchOrder search_order, const std::optional<size_t> max_depth) const
7891
{
7992
std::shared_ptr<PrintOperation> found_operation = findOperation(
8093
[](const std::shared_ptr<PrintOperation>& operation)
8194
{
8295
return static_cast<bool>(std::dynamic_pointer_cast<OperationType>(operation));
8396
},
84-
search_order);
97+
search_order,
98+
max_depth);
8599

86100
if (found_operation)
87101
{

src/FffGcodeWriter.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "communication/Communication.h" //To send layer view data.
3131
#include "feature_generation/FeatureGenerator.h"
3232
#include "feature_generation/MeshFeatureGenerator.h"
33-
#include "feature_generation/SkirtBrimGenerator.h"
3433
#include "geometry/LinesSet.h"
3534
#include "geometry/OpenPolyline.h"
3635
#include "geometry/PointMatrix.h"
@@ -192,7 +191,6 @@ void FffGcodeWriter::writeGCode(SliceDataStorage& storage, TimeKeeper& time_keep
192191
// }
193192

194193
// Add all possible feature generators
195-
feature_generators_.push_back(std::make_shared<SkirtBrimGenerator>());
196194
for (const std::shared_ptr<SliceMeshStorage>& mesh : storage.meshes)
197195
{
198196
feature_generators_.push_back(std::make_shared<MeshFeatureGenerator>(mesh));
@@ -223,20 +221,7 @@ void FffGcodeWriter::writeGCode(SliceDataStorage& storage, TimeKeeper& time_keep
223221
});
224222

225223
// print_plan_.flush(exporter);
226-
// print_plan_.applyProcessors();
227-
228-
#warning this should be done in the PrintPlan, or something like that
229-
LayerPlanTravelMovesInserter layer_plan_travel_moves_inserter;
230-
ExtruderPlanScheduler order_optimizer;
231-
for (const std::shared_ptr<LayerPlan>& layer_plan : print_plan_->getOperationsAs<LayerPlan>())
232-
{
233-
for (const std::shared_ptr<ExtruderPlan>& extruder_plan : layer_plan->getOperationsAs<ExtruderPlan>())
234-
{
235-
order_optimizer.process(extruder_plan.get());
236-
}
237-
238-
layer_plan_travel_moves_inserter.process(layer_plan.get());
239-
}
224+
print_plan_->applyProcessors();
240225

241226
MultiExporter exporter;
242227
// exporter.appendExporter(std::make_shared<ConsoleExporter>());
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2024 UltiMaker
2+
// CuraEngine is released under the terms of the AGPLv3 or higher
3+
4+
#include "feature_generation/SkirtBrimAppender.h"
5+
6+
#include <Application.h>
7+
#include <Slice.h>
8+
#include <settings/EnumSettings.h>
9+
#include <settings/Settings.h>
10+
11+
#include <range/v3/algorithm/contains.hpp>
12+
13+
#include "print_operation/ExtruderPlan.h"
14+
#include "print_operation/PrintOperationPtr.h"
15+
16+
namespace cura
17+
{
18+
19+
SkirtBrimAppender::SkirtBrimAppender()
20+
{
21+
}
22+
23+
void SkirtBrimAppender::process(PrintPlan* print_plan)
24+
{
25+
const Settings& settings = Application::getInstance().current_slice_->scene.settings;
26+
const auto adhesion_type = settings.get<EPlatformAdhesion>("adhesion_type");
27+
const bool support_brim_enable = settings.get<bool>("support_brim_enable");
28+
29+
if (adhesion_type != EPlatformAdhesion::SKIRT && adhesion_type != EPlatformAdhesion::BRIM && ! support_brim_enable)
30+
{
31+
return;
32+
}
33+
34+
// Collect actually used extruders. At this point we assume that all added extruder plans are non-empty.
35+
std::set<size_t> used_extruders;
36+
print_plan->findOperation(
37+
[&used_extruders](const PrintOperationPtr& operation)
38+
{
39+
if (const auto extruder_plan = std::dynamic_pointer_cast<ExtruderPlan>(operation))
40+
{
41+
used_extruders.insert(extruder_plan->getExtruderNr());
42+
}
43+
return false;
44+
},
45+
PrintOperationSequence::SearchOrder::Forward,
46+
1);
47+
}
48+
49+
} // namespace cura

src/feature_generation/SkirtBrimGenerator.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/print_operation/LayerPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void LayerPlan::write(PlanExporter& exporter) const
5353

5454
std::optional<Point3LL> LayerPlan::findExtruderStartPosition() const
5555
{
56-
if (const auto move_sequence = findOperationByType<ContinuousExtruderMoveSequence>(SearchOrder::DepthFirstForward))
56+
if (const auto move_sequence = findOperationByType<ContinuousExtruderMoveSequence>(SearchOrder::Forward, SearchDepth::Full))
5757
{
5858
std::optional<Point3LL> start_position = move_sequence->findStartPosition();
5959
if (start_position.has_value())

0 commit comments

Comments
 (0)