mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 07:41:06 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
121 lines
5.6 KiB
C++
121 lines
5.6 KiB
C++
#include "Config.hpp"
|
|
#include "Exception.hpp"
|
|
#include "Flow.hpp"
|
|
#include "Print.hpp"
|
|
#include <cstddef>
|
|
#include "PrintConfig.hpp"
|
|
#include "libslic3r.h"
|
|
#include <cmath>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
namespace Slic3r {
|
|
|
|
// 1-based extruder identifier for this region and role.
|
|
unsigned int PrintRegion::extruder(FlowRole role) const
|
|
{
|
|
size_t extruder = 0;
|
|
if (role == frPerimeter)
|
|
extruder = m_config.inner_wall_filament_id;
|
|
else if (role == frExternalPerimeter)
|
|
extruder = m_config.outer_wall_filament_id;
|
|
else if (role == frInfill)
|
|
extruder = m_config.sparse_infill_filament_id;
|
|
else if (role == frSolidInfill)
|
|
extruder = m_config.internal_solid_filament_id;
|
|
else if (role == frTopSolidInfill)
|
|
extruder = m_config.top_surface_filament_id;
|
|
else
|
|
throw Slic3r::InvalidArgument("Unknown role");
|
|
return extruder;
|
|
}
|
|
|
|
Flow PrintRegion::flow(const PrintObject &object, FlowRole role, double layer_height, bool first_layer) const
|
|
{
|
|
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 && print_config.initial_layer_line_width.value > 0) {
|
|
config_width = print_config.initial_layer_line_width;
|
|
} else if (role == frExternalPerimeter) {
|
|
config_width = m_config.outer_wall_line_width;
|
|
} else if (role == frPerimeter) {
|
|
config_width = m_config.inner_wall_line_width;
|
|
} else if (role == frInfill) {
|
|
config_width = m_config.sparse_infill_line_width;
|
|
} else if (role == frSolidInfill) {
|
|
config_width = m_config.internal_solid_infill_line_width;
|
|
} else if (role == frTopSolidInfill) {
|
|
config_width = m_config.top_surface_line_width;
|
|
} else {
|
|
throw Slic3r::InvalidArgument("Unknown role");
|
|
}
|
|
|
|
if (config_width.value == 0)
|
|
config_width = object.config().line_width;
|
|
|
|
// 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(print_config.nozzle_diameter.get_at(this->extruder(role) - 1));
|
|
return Flow::new_from_config_width(role, config_width, nozzle_diameter, float(layer_height));
|
|
}
|
|
|
|
coordf_t PrintRegion::nozzle_dmr_avg(const PrintConfig &print_config) const
|
|
{
|
|
return (print_config.nozzle_diameter.get_at(m_config.outer_wall_filament_id.value - 1) +
|
|
print_config.nozzle_diameter.get_at(m_config.inner_wall_filament_id.value - 1) +
|
|
print_config.nozzle_diameter.get_at(m_config.sparse_infill_filament_id.value - 1) +
|
|
print_config.nozzle_diameter.get_at(m_config.internal_solid_filament_id.value - 1) +
|
|
print_config.nozzle_diameter.get_at(m_config.top_surface_filament_id.value - 1) +
|
|
print_config.nozzle_diameter.get_at(m_config.bottom_surface_filament_id.value - 1)) / 6.;
|
|
}
|
|
|
|
coordf_t PrintRegion::bridging_height_avg(const PrintConfig &print_config) const
|
|
{
|
|
return this->nozzle_dmr_avg(print_config) * sqrt(m_config.bridge_flow.value);
|
|
}
|
|
|
|
void PrintRegion::collect_object_printing_extruders(const PrintConfig &print_config, const PrintRegionConfig ®ion_config, const bool has_brim, std::vector<unsigned int> &object_extruders)
|
|
{
|
|
// These checks reflect the same logic used in the GUI for enabling/disabling extruder selection fields.
|
|
// BBS
|
|
auto num_extruders = (int)print_config.filament_diameter.size();
|
|
auto emplace_extruder = [num_extruders, &object_extruders](int extruder_id) {
|
|
int i = std::max(0, extruder_id - 1);
|
|
object_extruders.emplace_back((i >= num_extruders) ? 0 : i);
|
|
};
|
|
if (region_config.wall_loops.value > 0 || has_brim) {
|
|
emplace_extruder(region_config.outer_wall_filament_id);
|
|
if (region_config.wall_loops.value > 1)
|
|
emplace_extruder(region_config.inner_wall_filament_id);
|
|
}
|
|
if (region_config.sparse_infill_density.value > 0)
|
|
emplace_extruder(region_config.sparse_infill_filament_id);
|
|
if (region_config.sparse_infill_density.value > 0 || region_config.top_shell_layers.value > 0 || region_config.bottom_shell_layers.value > 0)
|
|
emplace_extruder(region_config.internal_solid_filament_id);
|
|
if (region_config.top_shell_layers.value > 0)
|
|
emplace_extruder(region_config.top_surface_filament_id);
|
|
if (region_config.bottom_shell_layers.value > 0)
|
|
emplace_extruder(region_config.bottom_surface_filament_id);
|
|
}
|
|
|
|
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
|
|
// BBS
|
|
auto num_extruders = int(print.config().filament_diameter.size());
|
|
assert(this->config().outer_wall_filament_id <= num_extruders);
|
|
assert(this->config().inner_wall_filament_id <= num_extruders);
|
|
assert(this->config().sparse_infill_filament_id <= num_extruders);
|
|
assert(this->config().internal_solid_filament_id <= num_extruders);
|
|
assert(this->config().top_surface_filament_id <= num_extruders);
|
|
assert(this->config().bottom_surface_filament_id <= num_extruders);
|
|
#endif
|
|
collect_object_printing_extruders(print.config(), this->config(), print.has_brim(), object_extruders);
|
|
}
|
|
|
|
}
|