mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-05 14:51: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.
245 lines
7.0 KiB
C++
245 lines
7.0 KiB
C++
#include "Extruder.hpp"
|
|
#include "Exception.hpp"
|
|
#include "PrintConfig.hpp"
|
|
#include <vector>
|
|
#include "libslic3r.h"
|
|
#include <cassert>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
namespace Slic3r {
|
|
|
|
std::vector<double> Extruder::m_share_E = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0);
|
|
std::vector<double> Extruder::m_share_retracted = std::vector<double>(MAXIMUM_EXTRUDER_NUMBER, 0);
|
|
|
|
Extruder::Extruder(unsigned int id, GCodeConfig *config, bool share_extruder) :
|
|
m_id(id),
|
|
m_config(config),
|
|
m_share_extruder(share_extruder)
|
|
{
|
|
reset();
|
|
|
|
m_config_index = int(m_id);
|
|
// cache values that are going to be called often
|
|
m_e_per_mm3 = this->filament_flow_ratio();
|
|
m_e_per_mm3 /= this->filament_crossection();
|
|
}
|
|
|
|
void Extruder::set_config_index(int idx)
|
|
{
|
|
m_config_index = idx < 0 ? int(m_id) : idx;
|
|
// keep the cached flow term reading the same column as the getters
|
|
m_e_per_mm3 = this->filament_flow_ratio();
|
|
m_e_per_mm3 /= this->filament_crossection();
|
|
}
|
|
|
|
unsigned int Extruder::extruder_id() const
|
|
{
|
|
assert(m_config);
|
|
if (m_id < m_config->filament_map.size()) {
|
|
return m_config->filament_map.get_at(m_id) - 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
double Extruder::extrude(double dE)
|
|
{
|
|
// BBS
|
|
if (m_share_extruder) {
|
|
if (m_config->use_relative_e_distances)
|
|
m_share_E[extruder_id()] = 0.;
|
|
m_share_E[extruder_id()] += dE;
|
|
m_absolute_E += dE;
|
|
if (dE < 0.)
|
|
m_share_retracted[extruder_id()] -= dE;
|
|
} else {
|
|
// in case of relative E distances we always reset to 0 before any output
|
|
if (m_config->use_relative_e_distances)
|
|
m_E = 0.;
|
|
m_E += dE;
|
|
m_absolute_E += dE;
|
|
if (dE < 0.)
|
|
m_retracted -= dE;
|
|
}
|
|
return dE;
|
|
}
|
|
|
|
/* This method makes sure the extruder is retracted by the specified amount
|
|
of filament and returns the amount of filament retracted.
|
|
If the extruder is already retracted by the same or a greater amount,
|
|
this method is a no-op.
|
|
The restart_extra argument sets the extra length to be used for
|
|
unretraction. If we're actually performing a retraction, any restart_extra
|
|
value supplied will overwrite the previous one if any. */
|
|
double Extruder::retract(double length, double restart_extra)
|
|
{
|
|
// BBS
|
|
if (m_share_extruder) {
|
|
if (m_config->use_relative_e_distances)
|
|
m_share_E[extruder_id()] = 0.;
|
|
double to_retract = std::max(0., length - m_share_retracted[extruder_id()]);
|
|
m_restart_extra = restart_extra;
|
|
if (to_retract > 0.) {
|
|
m_share_E[extruder_id()] -= to_retract;
|
|
m_absolute_E -= to_retract;
|
|
m_share_retracted[extruder_id()] += to_retract;
|
|
}
|
|
return to_retract;
|
|
} else {
|
|
// in case of relative E distances we always reset to 0 before any output
|
|
if (m_config->use_relative_e_distances)
|
|
m_E = 0.;
|
|
double to_retract = std::max(0., length - m_retracted);
|
|
m_restart_extra = restart_extra;
|
|
if (to_retract > 0.) {
|
|
m_E -= to_retract;
|
|
m_absolute_E -= to_retract;
|
|
m_retracted += to_retract;
|
|
}
|
|
return to_retract;
|
|
}
|
|
}
|
|
|
|
double Extruder::unretract()
|
|
{
|
|
// BBS
|
|
if (m_share_extruder) {
|
|
double dE = m_share_retracted[extruder_id()] + m_restart_extra;
|
|
this->extrude(dE);
|
|
m_share_retracted[extruder_id()] = 0.;
|
|
m_restart_extra = 0.;
|
|
return dE;
|
|
} else {
|
|
double dE = m_retracted + m_restart_extra;
|
|
this->extrude(dE);
|
|
m_retracted = 0.;
|
|
m_restart_extra = 0.;
|
|
return dE;
|
|
}
|
|
}
|
|
|
|
// Setting the retract state from the script.
|
|
// Sets current retraction value & restart extra filament amount if retracted > 0.
|
|
void Extruder::set_retracted(double retracted, double restart_extra)
|
|
{
|
|
if (retracted < - EPSILON)
|
|
throw Slic3r::RuntimeError("Custom G-code reports negative z_retracted.");
|
|
if (restart_extra < - EPSILON)
|
|
throw Slic3r::RuntimeError("Custom G-code reports negative z_restart_extra.");
|
|
|
|
if (retracted > EPSILON) {
|
|
m_retracted = retracted;
|
|
m_restart_extra = restart_extra < EPSILON ? 0 : restart_extra;
|
|
} else {
|
|
m_retracted = 0;
|
|
m_restart_extra = 0;
|
|
}
|
|
}
|
|
|
|
// Used filament volume in mm^3.
|
|
double Extruder::extruded_volume() const
|
|
{
|
|
// BBS
|
|
if (m_share_extruder) {
|
|
// FIXME: need to count m_retracted for share extruder machine
|
|
return this->used_filament() * this->filament_crossection();
|
|
} else {
|
|
return this->used_filament() * this->filament_crossection();
|
|
}
|
|
}
|
|
|
|
// Used filament length in mm.
|
|
double Extruder::used_filament() const
|
|
{
|
|
// BBS
|
|
if (m_share_extruder) {
|
|
// FIXME: need to count retracted length for share-extruder machine
|
|
return m_absolute_E;
|
|
} else {
|
|
return m_absolute_E + m_retracted;
|
|
}
|
|
}
|
|
|
|
double Extruder::filament_diameter() const
|
|
{
|
|
return m_config->filament_diameter.get_at(m_id);
|
|
}
|
|
|
|
double Extruder::filament_density() const
|
|
{
|
|
return m_config->filament_density.get_at(m_id);
|
|
}
|
|
|
|
double Extruder::filament_cost() const
|
|
{
|
|
return m_config->filament_cost.get_at(m_id);
|
|
}
|
|
|
|
double Extruder::filament_flow_ratio() const
|
|
{
|
|
return m_config->filament_flow_ratio.get_at(m_config_index);
|
|
}
|
|
|
|
// Return a "retract_before_wipe" percentage as a factor clamped to <0, 1>
|
|
double Extruder::retract_before_wipe() const
|
|
{
|
|
return std::clamp(m_config->retract_before_wipe.get_at(m_config_index) * 0.01, 0., 1.);
|
|
}
|
|
|
|
// Orca:
|
|
// Return a "retract_after_wipe" percentage as a factor clamped to <0, 1>
|
|
double Extruder::retract_after_wipe() const
|
|
{
|
|
return std::min(std::clamp(m_config->retract_after_wipe.get_at(m_config_index) * 0.01, 0., 1.), 1. - retract_before_wipe());
|
|
}
|
|
|
|
double Extruder::retraction_length() const
|
|
{
|
|
return m_config->retraction_length.get_at(m_config_index);
|
|
}
|
|
|
|
double Extruder::retract_lift() const
|
|
{
|
|
return m_config->z_hop.get_at(m_config_index);
|
|
}
|
|
|
|
int Extruder::retract_speed() const
|
|
{
|
|
return int(floor(m_config->retraction_speed.get_at(m_config_index)+0.5));
|
|
}
|
|
|
|
bool Extruder::use_firmware_retraction() const
|
|
{
|
|
return m_config->use_firmware_retraction;
|
|
}
|
|
|
|
int Extruder::deretract_speed() const
|
|
{
|
|
int speed = int(floor(m_config->deretraction_speed.get_at(m_config_index)+0.5));
|
|
return (speed > 0) ? speed : this->retract_speed();
|
|
}
|
|
|
|
double Extruder::retract_restart_extra() const
|
|
{
|
|
return m_config->retract_restart_extra.get_at(m_config_index);
|
|
}
|
|
|
|
double Extruder::retract_length_toolchange() const
|
|
{
|
|
return m_config->retract_length_toolchange.get_at(m_config_index);
|
|
}
|
|
|
|
double Extruder::retract_restart_extra_toolchange() const
|
|
{
|
|
return m_config->retract_restart_extra_toolchange.get_at(m_config_index);
|
|
}
|
|
|
|
double Extruder::travel_slope() const
|
|
{
|
|
// Orca: deliberately keyed by the physical extruder, not the filament column — this read
|
|
// predates the per-variant merge and switching it would change existing multi-extruder output.
|
|
return m_config->travel_slope.get_at(extruder_id()) * PI / 180;
|
|
}
|
|
|
|
}
|