mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
Fixed crashes caused by pressure eq when support is used (#3407)
Fixed crashed caused by pressure eq when support is used
This commit is contained in:
parent
967dc3d487
commit
2f916f5ee9
5 changed files with 19 additions and 199 deletions
|
@ -81,8 +81,6 @@ set(lisbslic3r_sources
|
|||
ExtrusionEntity.hpp
|
||||
ExtrusionEntityCollection.cpp
|
||||
ExtrusionEntityCollection.hpp
|
||||
ExtrusionRole.cpp
|
||||
ExtrusionRole.hpp
|
||||
ExtrusionSimulator.cpp
|
||||
ExtrusionSimulator.hpp
|
||||
FileParserError.hpp
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
///|/ Copyright (c) Prusa Research 2023 Pavel Mikuš @Godrak, Oleksandra Iushchenko @YuSanka, Vojtěch Bubník @bubnikv
|
||||
///|/
|
||||
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#include "ExtrusionRole.hpp"
|
||||
#include "I18N.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
|
||||
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
|
||||
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role)
|
||||
{
|
||||
if (role == erNone) return GCodeExtrusionRole::None;
|
||||
if (role == erOverhangPerimeter) return GCodeExtrusionRole::OverhangPerimeter;
|
||||
if (role == erExternalPerimeter) return GCodeExtrusionRole::ExternalPerimeter;
|
||||
if (role == erPerimeter) return GCodeExtrusionRole::Perimeter;
|
||||
if (role == erInternalInfill) return GCodeExtrusionRole::InternalInfill;
|
||||
if (role == erSolidInfill) return GCodeExtrusionRole::SolidInfill;
|
||||
if (role == erTopSolidInfill) return GCodeExtrusionRole::TopSolidInfill;
|
||||
if (role == erIroning) return GCodeExtrusionRole::Ironing;
|
||||
if (role == erBridgeInfill) return GCodeExtrusionRole::BridgeInfill;
|
||||
if (role == erGapFill) return GCodeExtrusionRole::GapFill;
|
||||
if (role == erSkirt) return GCodeExtrusionRole::Skirt;
|
||||
if (role == erSupportMaterial) return GCodeExtrusionRole::SupportMaterial;
|
||||
if (role == erSupportMaterialInterface) return GCodeExtrusionRole::SupportMaterialInterface;
|
||||
if (role == erWipeTower) return GCodeExtrusionRole::WipeTower;
|
||||
assert(false);
|
||||
return GCodeExtrusionRole::None;
|
||||
}
|
||||
|
||||
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role)
|
||||
{
|
||||
switch (role) {
|
||||
case GCodeExtrusionRole::None : return L("Unknown");
|
||||
case GCodeExtrusionRole::Perimeter : return L("Perimeter");
|
||||
case GCodeExtrusionRole::ExternalPerimeter : return L("External perimeter");
|
||||
case GCodeExtrusionRole::OverhangPerimeter : return L("Overhang perimeter");
|
||||
case GCodeExtrusionRole::InternalInfill : return L("Internal infill");
|
||||
case GCodeExtrusionRole::SolidInfill : return L("Solid infill");
|
||||
case GCodeExtrusionRole::TopSolidInfill : return L("Top solid infill");
|
||||
case GCodeExtrusionRole::Ironing : return L("Ironing");
|
||||
case GCodeExtrusionRole::BridgeInfill : return L("Bridge infill");
|
||||
case GCodeExtrusionRole::GapFill : return L("Gap fill");
|
||||
case GCodeExtrusionRole::Skirt : return L("Skirt/Brim");
|
||||
case GCodeExtrusionRole::SupportMaterial : return L("Support material");
|
||||
case GCodeExtrusionRole::SupportMaterialInterface : return L("Support material interface");
|
||||
case GCodeExtrusionRole::WipeTower : return L("Wipe tower");
|
||||
case GCodeExtrusionRole::Custom : return L("Custom");
|
||||
default : assert(false);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role)
|
||||
{
|
||||
if (role == L("Perimeter"))
|
||||
return GCodeExtrusionRole::Perimeter;
|
||||
else if (role == L("External perimeter"))
|
||||
return GCodeExtrusionRole::ExternalPerimeter;
|
||||
else if (role == L("Overhang perimeter"))
|
||||
return GCodeExtrusionRole::OverhangPerimeter;
|
||||
else if (role == L("Internal infill"))
|
||||
return GCodeExtrusionRole::InternalInfill;
|
||||
else if (role == L("Solid infill"))
|
||||
return GCodeExtrusionRole::SolidInfill;
|
||||
else if (role == L("Top solid infill"))
|
||||
return GCodeExtrusionRole::TopSolidInfill;
|
||||
else if (role == L("Ironing"))
|
||||
return GCodeExtrusionRole::Ironing;
|
||||
else if (role == L("Bridge infill"))
|
||||
return GCodeExtrusionRole::BridgeInfill;
|
||||
else if (role == L("Gap fill"))
|
||||
return GCodeExtrusionRole::GapFill;
|
||||
else if (role == L("Skirt") || role == L("Skirt/Brim")) // "Skirt" is for backward compatibility with 2.3.1 and earlier
|
||||
return GCodeExtrusionRole::Skirt;
|
||||
else if (role == L("Support material"))
|
||||
return GCodeExtrusionRole::SupportMaterial;
|
||||
else if (role == L("Support material interface"))
|
||||
return GCodeExtrusionRole::SupportMaterialInterface;
|
||||
else if (role == L("Wipe tower"))
|
||||
return GCodeExtrusionRole::WipeTower;
|
||||
else if (role == L("Custom"))
|
||||
return GCodeExtrusionRole::Custom;
|
||||
else
|
||||
return GCodeExtrusionRole::None;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
///|/ Copyright (c) 2023 Robert Schiele @schiele
|
||||
///|/ Copyright (c) Prusa Research 2023 Vojtěch Bubník @bubnikv
|
||||
///|/
|
||||
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#ifndef slic3r_ExtrusionRole_hpp_
|
||||
#define slic3r_ExtrusionRole_hpp_
|
||||
|
||||
#include "enum_bitmask.hpp"
|
||||
#include "ExtrusionEntity.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
enum class ExtrusionRoleModifier : uint16_t {
|
||||
// 1) Extrusion types
|
||||
// Perimeter (external, inner, ...)
|
||||
Perimeter,
|
||||
// Infill (top / bottom / solid inner / sparse inner / bridging inner ...)
|
||||
Infill,
|
||||
// Variable width extrusion
|
||||
Thin,
|
||||
// Support material extrusion
|
||||
Support,
|
||||
Skirt,
|
||||
Wipe,
|
||||
// 2) Extrusion modifiers
|
||||
External,
|
||||
Solid,
|
||||
Ironing,
|
||||
Bridge,
|
||||
// 3) Special types
|
||||
// Indicator that the extrusion role was mixed from multiple differing extrusion roles,
|
||||
// for example from Support and SupportInterface.
|
||||
Mixed,
|
||||
// Stopper, there should be maximum 16 modifiers defined for uint16_t bit mask.
|
||||
Count
|
||||
};
|
||||
// There should be maximum 16 modifiers defined for uint16_t bit mask.
|
||||
static_assert(int(ExtrusionRoleModifier::Count) <= 16, "ExtrusionRoleModifier: there must be maximum 16 modifiers defined to fit a 16 bit bitmask");
|
||||
|
||||
using ExtrusionRoleModifiers = enum_bitmask<ExtrusionRoleModifier>;
|
||||
ENABLE_ENUM_BITMASK_OPERATORS(ExtrusionRoleModifier);
|
||||
|
||||
|
||||
|
||||
// Be careful when editing this list as many parts of the code depend
|
||||
// on the values of these ordinars, for example
|
||||
// GCodeViewer::Extrusion_Role_Colors
|
||||
enum class GCodeExtrusionRole : uint8_t {
|
||||
None,
|
||||
Perimeter,
|
||||
ExternalPerimeter,
|
||||
OverhangPerimeter,
|
||||
InternalInfill,
|
||||
SolidInfill,
|
||||
TopSolidInfill,
|
||||
Ironing,
|
||||
BridgeInfill,
|
||||
GapFill,
|
||||
Skirt,
|
||||
SupportMaterial,
|
||||
SupportMaterialInterface,
|
||||
WipeTower,
|
||||
// Custom (user defined) G-code block, for example start / end G-code.
|
||||
Custom,
|
||||
// Stopper to count number of enums.
|
||||
Count
|
||||
};
|
||||
|
||||
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
|
||||
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
|
||||
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role);
|
||||
|
||||
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role);
|
||||
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role);
|
||||
|
||||
}
|
||||
|
||||
#endif // slic3r_ExtrusionRole_hpp_
|
|
@ -3,6 +3,7 @@
|
|||
///|/
|
||||
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
||||
///|/
|
||||
#include <iostream>
|
||||
#include <memory.h>
|
||||
#include <cstring>
|
||||
#include <cfloat>
|
||||
|
@ -45,7 +46,7 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_
|
|||
m_current_extruder = 0;
|
||||
// Zero the position of the XYZE axes + the current feed
|
||||
memset(m_current_pos, 0, sizeof(float) * 5);
|
||||
m_current_extrusion_role = GCodeExtrusionRole::None;
|
||||
m_current_extrusion_role = ExtrusionRole::erNone;
|
||||
// Expect the first command to fill the nozzle (deretract).
|
||||
m_retracted = true;
|
||||
|
||||
|
@ -74,7 +75,7 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_
|
|||
}
|
||||
|
||||
// Don't regulate the pressure before and after ironing.
|
||||
for (const GCodeExtrusionRole er : {GCodeExtrusionRole::Ironing}) {
|
||||
for (const ExtrusionRole er : {ExtrusionRole::erIroning}) {
|
||||
m_max_volumetric_extrusion_rate_slopes[size_t(er)].negative = 0;
|
||||
m_max_volumetric_extrusion_rate_slopes[size_t(er)].positive = 0;
|
||||
}
|
||||
|
@ -260,7 +261,7 @@ bool PressureEqualizer::process_line(const char *line, const char *line_end, GCo
|
|||
if (strncmp(line, EXTRUSION_ROLE_TAG.data(), EXTRUSION_ROLE_TAG.length()) == 0) {
|
||||
line += EXTRUSION_ROLE_TAG.length();
|
||||
int role = atoi(line);
|
||||
m_current_extrusion_role = GCodeExtrusionRole(role);
|
||||
m_current_extrusion_role = ExtrusionRole(role);
|
||||
#ifdef PRESSURE_EQUALIZER_DEBUG
|
||||
++line_idx;
|
||||
#endif
|
||||
|
@ -589,8 +590,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
if (line_idx == fist_line_idx || !m_gcode_lines[line_idx].extruding())
|
||||
// Nothing to do, the last move is not extruding.
|
||||
return;
|
||||
|
||||
std::array<float, size_t(GCodeExtrusionRole::Count)> feedrate_per_extrusion_role{};
|
||||
std::array<float, size_t(ExtrusionRole::erCount)> feedrate_per_extrusion_role{};
|
||||
feedrate_per_extrusion_role.fill(std::numeric_limits<float>::max());
|
||||
feedrate_per_extrusion_role[int(m_gcode_lines[line_idx].extrusion_role)] = m_gcode_lines[line_idx].volumetric_extrusion_rate_start;
|
||||
|
||||
|
@ -600,7 +600,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
if (!m_gcode_lines[idx_prev].extruding())
|
||||
break;
|
||||
// Don't decelerate before ironing.
|
||||
if (m_gcode_lines[line_idx].extrusion_role == GCodeExtrusionRole::Ironing) { line_idx = idx_prev;
|
||||
if (m_gcode_lines[line_idx].extrusion_role == ExtrusionRole::erIroning) { line_idx = idx_prev;
|
||||
continue;
|
||||
}
|
||||
// Volumetric extrusion rate at the start of the succeding segment.
|
||||
|
@ -609,10 +609,10 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
line_idx = idx_prev;
|
||||
GCodeLine &line = m_gcode_lines[line_idx];
|
||||
|
||||
for (size_t iRole = 1; iRole < size_t(GCodeExtrusionRole::Count); ++ iRole) {
|
||||
for (size_t iRole = 1; iRole < size_t(ExtrusionRole::erCount); ++ iRole) {
|
||||
const float &rate_slope = m_max_volumetric_extrusion_rate_slopes[iRole].negative;
|
||||
if (rate_slope == 0 || feedrate_per_extrusion_role[iRole] == std::numeric_limits<float>::max())
|
||||
continue; // The negative rate is unlimited or the rate for GCodeExtrusionRole iRole is unlimited.
|
||||
continue; // The negative rate is unlimited or the rate for ExtrusionRole iRole is unlimited.
|
||||
|
||||
float rate_end = feedrate_per_extrusion_role[iRole];
|
||||
if (iRole == size_t(line.extrusion_role) && rate_succ < rate_end)
|
||||
|
@ -620,7 +620,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
rate_end = rate_succ;
|
||||
|
||||
// don't alter the flow rate for these extrusion types
|
||||
if (!line.adjustable_flow || line.extrusion_role == GCodeExtrusionRole::BridgeInfill || line.extrusion_role == GCodeExtrusionRole::Ironing) {
|
||||
if (!line.adjustable_flow || line.extrusion_role == ExtrusionRole::erBridgeInfill || line.extrusion_role == ExtrusionRole::erIroning) {
|
||||
rate_end = line.volumetric_extrusion_rate_end;
|
||||
} else if (line.volumetric_extrusion_rate_end > rate_end) {
|
||||
line.volumetric_extrusion_rate_end = rate_end;
|
||||
|
@ -644,7 +644,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
}
|
||||
// feedrate_per_extrusion_role[iRole] = (iRole == line.extrusion_role) ? line.volumetric_extrusion_rate_start : rate_start;
|
||||
// Don't store feed rate for ironing
|
||||
if (line.extrusion_role != GCodeExtrusionRole::Ironing)
|
||||
if (line.extrusion_role != ExtrusionRole::erIroning)
|
||||
feedrate_per_extrusion_role[iRole] = line.volumetric_extrusion_rate_start;
|
||||
}
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
if (!m_gcode_lines[idx_next].extruding())
|
||||
break;
|
||||
// Don't accelerate after ironing.
|
||||
if (m_gcode_lines[line_idx].extrusion_role == GCodeExtrusionRole::Ironing) {
|
||||
if (m_gcode_lines[line_idx].extrusion_role == ExtrusionRole::erIroning) {
|
||||
line_idx = idx_next;
|
||||
continue;
|
||||
}
|
||||
|
@ -668,14 +668,14 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
line_idx = idx_next;
|
||||
GCodeLine &line = m_gcode_lines[line_idx];
|
||||
|
||||
for (size_t iRole = 1; iRole < size_t(GCodeExtrusionRole::Count); ++ iRole) {
|
||||
for (size_t iRole = 1; iRole < size_t(ExtrusionRole::erCount); ++ iRole) {
|
||||
const float &rate_slope = m_max_volumetric_extrusion_rate_slopes[iRole].positive;
|
||||
if (rate_slope == 0 || feedrate_per_extrusion_role[iRole] == std::numeric_limits<float>::max())
|
||||
continue; // The positive rate is unlimited or the rate for GCodeExtrusionRole iRole is unlimited.
|
||||
continue; // The positive rate is unlimited or the rate for ExtrusionRole iRole is unlimited.
|
||||
|
||||
float rate_start = feedrate_per_extrusion_role[iRole];
|
||||
// don't alter the flow rate for these extrusion types
|
||||
if (!line.adjustable_flow || line.extrusion_role == GCodeExtrusionRole::BridgeInfill || line.extrusion_role == GCodeExtrusionRole::Ironing) {
|
||||
if (!line.adjustable_flow || line.extrusion_role == ExtrusionRole::erBridgeInfill || line.extrusion_role == ExtrusionRole::erIroning) {
|
||||
rate_start = line.volumetric_extrusion_rate_start;
|
||||
} else if (iRole == size_t(line.extrusion_role) && rate_prec < rate_start)
|
||||
rate_start = rate_prec;
|
||||
|
@ -701,7 +701,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
|
|||
}
|
||||
// feedrate_per_extrusion_role[iRole] = (iRole == line.extrusion_role) ? line.volumetric_extrusion_rate_end : rate_end;
|
||||
// Don't store feed rate for ironing
|
||||
if (line.extrusion_role != GCodeExtrusionRole::Ironing)
|
||||
if (line.extrusion_role != ExtrusionRole::erIroning)
|
||||
feedrate_per_extrusion_role[iRole] = line.volumetric_extrusion_rate_end;
|
||||
}
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ void PressureEqualizer::push_line_to_output(const size_t line_idx, const float n
|
|||
GCodeG1Formatter feedrate_formatter;
|
||||
feedrate_formatter.emit_f(new_feedrate);
|
||||
feedrate_formatter.emit_string(std::string(EXTRUDE_SET_SPEED_TAG.data(), EXTRUDE_SET_SPEED_TAG.length()));
|
||||
if (line.extrusion_role == GCodeExtrusionRole::ExternalPerimeter)
|
||||
if (line.extrusion_role == ExtrusionRole::erExternalPerimeter)
|
||||
feedrate_formatter.emit_string(std::string(EXTERNAL_PERIMETER_TAG.data(), EXTERNAL_PERIMETER_TAG.length()));
|
||||
push_to_output(feedrate_formatter);
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "../libslic3r.h"
|
||||
#include "../PrintConfig.hpp"
|
||||
#include "../ExtrusionRole.hpp"
|
||||
|
||||
#include <queue>
|
||||
|
||||
|
@ -70,7 +69,7 @@ private:
|
|||
float positive;
|
||||
float negative;
|
||||
};
|
||||
ExtrusionRateSlope m_max_volumetric_extrusion_rate_slopes[size_t(GCodeExtrusionRole::Count)];
|
||||
ExtrusionRateSlope m_max_volumetric_extrusion_rate_slopes[size_t(ExtrusionRole::erCount)];
|
||||
float m_max_volumetric_extrusion_rate_slope_positive;
|
||||
float m_max_volumetric_extrusion_rate_slope_negative;
|
||||
|
||||
|
@ -82,7 +81,7 @@ private:
|
|||
// X,Y,Z,E,F
|
||||
float m_current_pos[5];
|
||||
size_t m_current_extruder;
|
||||
GCodeExtrusionRole m_current_extrusion_role;
|
||||
ExtrusionRole m_current_extrusion_role;
|
||||
bool m_retracted;
|
||||
bool m_use_relative_e_distances;
|
||||
|
||||
|
@ -158,7 +157,7 @@ private:
|
|||
// Index of the active extruder.
|
||||
size_t extruder_id;
|
||||
// Extrusion role of this segment.
|
||||
GCodeExtrusionRole extrusion_role;
|
||||
ExtrusionRole extrusion_role;
|
||||
|
||||
// Current volumetric extrusion rate.
|
||||
float volumetric_extrusion_rate;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue