Tech ENABLE_FIX_PREVIEW_OPTIONS_Z - Enable fixing the z position of seams (and other options) in preview

This commit is contained in:
enricoturri1966 2021-09-08 14:30:40 +02:00
parent 0da0a7b2a0
commit 6f678c09d1
4 changed files with 78 additions and 0 deletions

View file

@ -390,6 +390,45 @@ namespace Slic3r {
bool has_first_vertex() const { return m_first_vertex.has_value(); }
};
#if ENABLE_FIX_PREVIEW_OPTIONS_Z
// Helper class used to fix the z for color change, pause print and
// custom gcode markes
class OptionsZCorrector
{
Result& m_result;
std::optional<size_t> m_move_id;
std::optional<size_t> m_custom_gcode_per_print_z_id;
public:
explicit OptionsZCorrector(Result& result) : m_result(result) {
}
void set() {
m_move_id = m_result.moves.size() - 1;
m_custom_gcode_per_print_z_id = m_result.custom_gcode_per_print_z.size() - 1;
}
void update(float height) {
if (!m_move_id.has_value() || !m_custom_gcode_per_print_z_id.has_value())
return;
const Vec3f position = m_result.moves.back().position;
MoveVertex& move = m_result.moves.emplace_back(m_result.moves[m_move_id.value()]);
move.position = position;
move.height = height;
m_result.moves.erase(m_result.moves.begin() + m_move_id.value());
m_result.custom_gcode_per_print_z[m_custom_gcode_per_print_z_id.value()].print_z = position.z();
reset();
}
void reset() {
m_move_id.reset();
m_custom_gcode_per_print_z_id.reset();
}
};
#endif // ENABLE_FIX_PREVIEW_OPTIONS_Z
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
struct DataChecker
{
@ -494,6 +533,9 @@ namespace Slic3r {
CpColor m_cp_color;
bool m_use_volumetric_e;
SeamsDetector m_seams_detector;
#if ENABLE_FIX_PREVIEW_OPTIONS_Z
OptionsZCorrector m_options_z_corrector;
#endif // ENABLE_FIX_PREVIEW_OPTIONS_Z
#if ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER
size_t m_last_default_color_id;
#endif // ENABLE_FIX_IMPORTING_COLOR_PRINT_VIEW_INTO_GCODEVIEWER