PrintRegion refactoring: Getting rid of the Print pointer.
This commit is contained in:
parent
9537c4e8d0
commit
72ce8cb28d
@ -29,11 +29,12 @@ Flow LayerRegion::bridging_flow(FlowRole role) const
|
||||
{
|
||||
const PrintRegion ®ion = *this->region();
|
||||
const PrintRegionConfig ®ion_config = region.config();
|
||||
if (this->layer()->object()->config().thick_bridges) {
|
||||
const PrintObject &print_object = *this->layer()->object();
|
||||
if (print_object.config().thick_bridges) {
|
||||
// The old Slic3r way (different from all other slicers): Use rounded extrusions.
|
||||
// Get the configured nozzle_diameter for the extruder associated to the flow role requested.
|
||||
// Here this->extruder(role) - 1 may underflow to MAX_INT, but then the get_at() will follback to zero'th element, so everything is all right.
|
||||
auto nozzle_diameter = float(region.print()->config().nozzle_diameter.get_at(region.extruder(role) - 1));
|
||||
auto nozzle_diameter = float(print_object.print()->config().nozzle_diameter.get_at(region.extruder(role) - 1));
|
||||
// Applies default bridge spacing.
|
||||
return Flow::bridging_flow(float(sqrt(region_config.bridge_flow_ratio)) * nozzle_diameter, nozzle_diameter);
|
||||
} else {
|
||||
|
@ -47,13 +47,13 @@ void Print::clear()
|
||||
|
||||
PrintRegion* Print::add_region()
|
||||
{
|
||||
m_regions.emplace_back(new PrintRegion(this));
|
||||
m_regions.emplace_back(new PrintRegion());
|
||||
return m_regions.back();
|
||||
}
|
||||
|
||||
PrintRegion* Print::add_region(const PrintRegionConfig &config)
|
||||
{
|
||||
m_regions.emplace_back(new PrintRegion(this, config));
|
||||
m_regions.emplace_back(new PrintRegion(config));
|
||||
return m_regions.back();
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ std::vector<unsigned int> Print::object_extruders() const
|
||||
region_used[&volumes_per_region - &object->region_volumes.front()] = true;
|
||||
for (size_t idx_region = 0; idx_region < m_regions.size(); ++ idx_region)
|
||||
if (region_used[idx_region])
|
||||
m_regions[idx_region]->collect_object_printing_extruders(extruders);
|
||||
m_regions[idx_region]->collect_object_printing_extruders(*this, extruders);
|
||||
sort_remove_duplicates(extruders);
|
||||
return extruders;
|
||||
}
|
||||
|
@ -57,11 +57,13 @@ enum PrintObjectStep {
|
||||
// sharing the same config (including the same assigned extruder(s))
|
||||
class PrintRegion
|
||||
{
|
||||
friend class Print;
|
||||
public:
|
||||
PrintRegion() : m_refcnt(0) {}
|
||||
PrintRegion(const PrintRegionConfig &config) : m_refcnt(0), m_config(config) {}
|
||||
~PrintRegion() = default;
|
||||
|
||||
// Methods NOT modifying the PrintRegion's state:
|
||||
public:
|
||||
const Print* print() const { return m_print; }
|
||||
const PrintRegionConfig& config() const { return m_config; }
|
||||
// 1-based extruder identifier for this region and role.
|
||||
unsigned int extruder(FlowRole role) const;
|
||||
@ -72,27 +74,22 @@ public:
|
||||
coordf_t bridging_height_avg(const PrintConfig &print_config) const;
|
||||
|
||||
// Collect 0-based extruder indices used to print this region's object.
|
||||
void collect_object_printing_extruders(std::vector<unsigned int> &object_extruders) const;
|
||||
void collect_object_printing_extruders(const Print &print, std::vector<unsigned int> &object_extruders) const;
|
||||
static void collect_object_printing_extruders(const PrintConfig &print_config, const PrintRegionConfig ®ion_config, const bool has_brim, std::vector<unsigned int> &object_extruders);
|
||||
|
||||
// Methods modifying the PrintRegion's state:
|
||||
public:
|
||||
Print* print() { return m_print; }
|
||||
void set_config(const PrintRegionConfig &config) { m_config = config; }
|
||||
void set_config(PrintRegionConfig &&config) { m_config = std::move(config); }
|
||||
void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false)
|
||||
{ this->m_config.apply_only(other, keys, ignore_nonexistent); }
|
||||
|
||||
protected:
|
||||
friend Print;
|
||||
size_t m_refcnt;
|
||||
|
||||
private:
|
||||
Print *m_print;
|
||||
PrintRegionConfig m_config;
|
||||
|
||||
PrintRegion(Print* print) : m_refcnt(0), m_print(print) {}
|
||||
PrintRegion(Print* print, const PrintRegionConfig &config) : m_refcnt(0), m_print(print), m_config(config) {}
|
||||
~PrintRegion() = default;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -1675,7 +1675,7 @@ std::vector<unsigned int> PrintObject::object_extruders() const
|
||||
extruders.reserve(this->region_volumes.size() * 3);
|
||||
for (size_t idx_region = 0; idx_region < this->region_volumes.size(); ++ idx_region)
|
||||
if (! this->region_volumes[idx_region].empty())
|
||||
m_print->get_region(idx_region)->collect_object_printing_extruders(extruders);
|
||||
m_print->get_region(idx_region)->collect_object_printing_extruders(*this->print(), extruders);
|
||||
sort_remove_duplicates(extruders);
|
||||
return extruders;
|
||||
}
|
||||
|
@ -20,11 +20,12 @@ unsigned int PrintRegion::extruder(FlowRole role) const
|
||||
|
||||
Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_height, bool first_layer) const
|
||||
{
|
||||
ConfigOptionFloatOrPercent config_width;
|
||||
const PrintConfig &print_config = object.print()->config();
|
||||
ConfigOptionFloatOrPercent config_width;
|
||||
// Get extrusion width from configuration.
|
||||
// (might be an absolute value, or a percent value, or zero for auto)
|
||||
if (first_layer && m_print->config().first_layer_extrusion_width.value > 0) {
|
||||
config_width = m_print->config().first_layer_extrusion_width;
|
||||
if (first_layer && print_config.first_layer_extrusion_width.value > 0) {
|
||||
config_width = print_config.first_layer_extrusion_width;
|
||||
} else if (role == frExternalPerimeter) {
|
||||
config_width = m_config.external_perimeter_extrusion_width;
|
||||
} else if (role == frPerimeter) {
|
||||
@ -44,7 +45,7 @@ Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_he
|
||||
|
||||
// Get the configured nozzle_diameter for the extruder associated to the flow role requested.
|
||||
// Here this->extruder(role) - 1 may underflow to MAX_INT, but then the get_at() will follback to zero'th element, so everything is all right.
|
||||
auto nozzle_diameter = float(m_print->config().nozzle_diameter.get_at(this->extruder(role) - 1));
|
||||
auto nozzle_diameter = float(print_config.nozzle_diameter.get_at(this->extruder(role) - 1));
|
||||
return Flow::new_from_config_width(role, config_width, nozzle_diameter, float(layer_height));
|
||||
}
|
||||
|
||||
@ -76,17 +77,17 @@ void PrintRegion::collect_object_printing_extruders(const PrintConfig &print_con
|
||||
emplace_extruder(region_config.solid_infill_extruder);
|
||||
}
|
||||
|
||||
void PrintRegion::collect_object_printing_extruders(std::vector<unsigned int> &object_extruders) const
|
||||
void PrintRegion::collect_object_printing_extruders(const Print &print, std::vector<unsigned int> &object_extruders) const
|
||||
{
|
||||
// PrintRegion, if used by some PrintObject, shall have all the extruders set to an existing printer extruder.
|
||||
// If not, then there must be something wrong with the Print::apply() function.
|
||||
#ifndef NDEBUG
|
||||
auto num_extruders = (int)print()->config().nozzle_diameter.size();
|
||||
auto num_extruders = int(print.config().nozzle_diameter.size());
|
||||
assert(this->config().perimeter_extruder <= num_extruders);
|
||||
assert(this->config().infill_extruder <= num_extruders);
|
||||
assert(this->config().solid_infill_extruder <= num_extruders);
|
||||
#endif
|
||||
collect_object_printing_extruders(print()->config(), this->config(), print()->has_brim(), object_extruders);
|
||||
collect_object_printing_extruders(print.config(), this->config(), print.has_brim(), object_extruders);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user