Skip to content

Commit e8156c4

Browse files
committed
Clean and simplify code
CURA-12250
1 parent 220a216 commit e8156c4

File tree

6 files changed

+114
-351
lines changed

6 files changed

+114
-351
lines changed

include/Scene.h

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Scene
7171
*/
7272
void processMeshGroup(MeshGroup& mesh_group);
7373

74+
const ExtruderTrain& getExtruder(const ExtruderNumber extruder_nr) const;
75+
7476
private:
7577
/*
7678
* \brief You are not allowed to copy the scene.

include/feature_generation/SkirtBrimAppender.h

+20-68
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <settings/EnumSettings.h>
7+
#include <utils/ExtrudersSet.h>
78

89
#include "ExtruderNumber.h"
910
#include "operation_transformation/PrintOperationTransformer.h"
@@ -27,41 +28,6 @@ class SkirtBrimAppender : public PrintOperationTransformer<PrintPlan>
2728
void process(PrintPlan* print_plan) override;
2829

2930
private:
30-
/*!
31-
* A helper class to store an offset yet to be performed on either an outline polygon, or based on an earlier generated brim line.
32-
*/
33-
struct Offset
34-
{
35-
Offset(
36-
const std::variant<const Shape*, int>& reference_outline_or_index,
37-
const bool outside,
38-
const bool inside,
39-
const coord_t offset_value,
40-
const coord_t total_offset,
41-
const size_t inset_idx,
42-
const size_t extruder_nr,
43-
const bool is_last)
44-
: reference_outline_or_index_(reference_outline_or_index)
45-
, outside_(outside)
46-
, inside_(inside)
47-
, offset_value_(offset_value)
48-
, total_offset_(total_offset)
49-
, inset_idx_(inset_idx)
50-
, extruder_nr_(extruder_nr)
51-
, is_last_(is_last)
52-
{
53-
}
54-
55-
std::variant<const Shape*, int> reference_outline_or_index_;
56-
bool outside_; //!< Wether to offset outward from the reference polygons
57-
bool inside_; //!< Wether to offset inward from the reference polygons
58-
coord_t offset_value_; //!< Distance by which to offset from the reference
59-
coord_t total_offset_; //!< Total distance from the model
60-
int inset_idx_; //!< The outset index of this brimline
61-
ExtruderNumber extruder_nr_; //!< The extruder by which to print this brim line
62-
bool is_last_; //!< Whether this is the last planned offset for this extruder.
63-
};
64-
6531
/*!
6632
* Container to store the pre-extracted settings of an extruder
6733
*/
@@ -74,63 +40,49 @@ class SkirtBrimAppender : public PrintOperationTransformer<PrintPlan>
7440
int line_count_; //!< The (minimal) number of brim lines to generate
7541
coord_t gap_; //!< The gap between the part and the first brim/skirt line
7642
coord_t brim_inside_margin_;
43+
size_t skirt_height_;
7744
};
7845

7946
static constexpr coord_t min_brim_line_length_ = 3000u; //!< open polyline brim lines smaller than this will be removed
80-
std::map<ExtruderNumber, ExtruderConfig> extruders_configs_;
8147
const SliceDataStorage& storage_;
8248

8349
private:
84-
static bool sortOffsets(const Offset& a, const Offset& b)
85-
{
86-
// Use extruder_nr in case both extruders have the same offset settings.
87-
return a.total_offset_ != b.total_offset_ ? a.total_offset_ < b.total_offset_ : a.extruder_nr_ < b.extruder_nr_;
88-
};
50+
static std::tuple<std::vector<ConstExtruderPlanPtr>, ExtrudersSet> generateUsedExtruders(const PrintPlan* print_plan);
51+
52+
static size_t calculateMaxHeight(const std::map<ExtruderNumber, ExtruderConfig>& extruders_configs, const EPlatformAdhesion adhesion_type);
53+
54+
static std::map<ExtruderNumber, ExtruderConfig> generateExtrudersConfigs(const ExtrudersSet& used_extruders, const EPlatformAdhesion adhesion_type);
8955

90-
static std::map<ExtruderNumber, Shape> generateStartingOutlines(const PrintPlan* print_plan,
56+
static std::map<ExtruderNumber, Shape> generateStartingOutlines(
57+
const PrintPlan* print_plan,
9158
const std::optional<ExtruderNumber> skirt_brim_extruder_nr,
9259
const size_t height,
9360
const EPlatformAdhesion adhesion_type,
9461
const ExtrudersSet& used_extruders);
9562

96-
std::vector<Offset> generateBrimOffsetPlan(const std::optional<ExtruderNumber> skirt_brim_extruder_nr,
97-
const EPlatformAdhesion adhesion_type,
63+
std::map<ExtruderNumber, Shape> generateAllowedAreas(
9864
const std::map<ExtruderNumber, Shape>& starting_outlines,
99-
const ExtrudersSet &used_extruders) const;
100-
101-
std::map<ExtruderNumber, Shape> generateAllowedAreas(const std::map<ExtruderNumber, Shape>& starting_outlines,
10265
const EPlatformAdhesion adhesion_type,
103-
const ExtrudersSet &used_extruders,
66+
const ExtrudersSet& used_extruders,
10467
const std::optional<ExtruderNumber> skirt_brim_extruder_nr,
105-
const SliceDataStorage& storage) const;
68+
const std::map<ExtruderNumber, ExtruderConfig>& extruders_configs) const;
10669

107-
void generateSkirtBrim(const SliceDataStorage& storage,
70+
static void generateSkirtBrim(
10871
const EPlatformAdhesion adhesion_type,
109-
const std::map<ExtruderNumber, Shape>& starting_outlines,
110-
std::vector<Offset>& offset_plan,
111-
std::map<ExtruderNumber, Shape>& allowed_areas_per_extruder,
112-
PrintPlan* print_plan) const;
113-
114-
void generateSkirtBrimV2(const SliceDataStorage& storage,
115-
const EPlatformAdhesion adhesion_type,
116-
const ExtrudersSet &used_extruders,
72+
const ExtrudersSet& used_extruders,
11773
const std::vector<ConstExtruderPlanPtr> first_extruder_plans,
118-
const std::map<ExtruderNumber,
119-
Shape>& starting_outlines,
120-
std::map<ExtruderNumber, Shape>& allowed_areas_per_extruder,
121-
PrintPlan* print_plan) const;
122-
123-
FeatureExtrusionPtr generateOffset(const Offset& offset,
12474
const std::map<ExtruderNumber, Shape>& starting_outlines,
125-
Shape& covered_area,
12675
std::map<ExtruderNumber, Shape>& allowed_areas_per_extruder,
127-
const LayerPlanPtr &layer_plan) const;
76+
const std::map<ExtruderNumber, ExtruderConfig>& extruders_configs,
77+
PrintPlan* print_plan);
12878

129-
FeatureExtrusionPtr generateOffsetV2(const ExtruderNumber extruder_nr,
79+
static FeatureExtrusionPtr generateOffset(
80+
const ExtruderNumber extruder_nr,
13081
const coord_t total_offset,
13182
Shape& covered_area,
13283
std::map<ExtruderNumber, Shape>& allowed_areas_per_extruder,
133-
const LayerPlanPtr &layer_plan) const;
84+
const std::map<ExtruderNumber, ExtruderConfig>& extruders_configs,
85+
const LayerPlanPtr& layer_plan);
13486
};
13587

13688
} // namespace cura

include/settings/Settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sstream>
1919
#include <unordered_map>
2020
#include <vector>
21+
#include <cstdint>
2122

2223
namespace cura
2324
{

include/utils/ExtrudersSet.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
#pragma once
55

6+
#include <bit>
7+
#include <optional>
8+
69
#include "settings/Settings.h"
710
#include "ExtruderNumber.h"
8-
#include <bit>
911

1012
namespace cura
1113
{
@@ -57,17 +59,17 @@ class ExtrudersSet
5759
public:
5860
bool contains(const ExtruderNumber extruder_nr) const
5961
{
60-
return extruders_mask_ & (1 << extruder_nr);
62+
return extruders_mask_ & (static_cast<EXTRUDERS_BITMASK_TYPE>(1) << extruder_nr);
6163
}
6264

6365
void set(const ExtruderNumber extruder_nr)
6466
{
65-
extruders_mask_ |= (1 << extruder_nr);
67+
extruders_mask_ |= (static_cast<EXTRUDERS_BITMASK_TYPE>(1) << extruder_nr);
6668
}
6769

6870
void unset(const ExtruderNumber extruder_nr)
6971
{
70-
extruders_mask_ &= ~(1 << extruder_nr);
72+
extruders_mask_ &= ~(static_cast<EXTRUDERS_BITMASK_TYPE>(1) << extruder_nr);
7173
}
7274

7375
bool empty() const

src/Scene.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "Scene.h"
55

6+
#include <range/v3/algorithm/find_if.hpp>
67
#include <spdlog/spdlog.h>
78

89
#include "Application.h"
@@ -100,4 +101,9 @@ void Scene::processMeshGroup(MeshGroup& mesh_group)
100101
spdlog::info("Total time elapsed {:03.3f}s\n", time_keeper_total.restart());
101102
}
102103

104+
const ExtruderTrain& Scene::getExtruder(const ExtruderNumber extruder_nr) const
105+
{
106+
return *ranges::find_if(extruders, [extruder_nr](const ExtruderTrain &extruder){ return extruder.extruder_nr_ == extruder_nr; });
107+
}
108+
103109
} // namespace cura

0 commit comments

Comments
 (0)