diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index ffc6b5cee6..af1ef8e4db 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -232,6 +232,8 @@ set(lisbslic3r_sources GCode/ConflictChecker.hpp GCode/CoolingBuffer.cpp GCode/CoolingBuffer.hpp + GCode/ExclusionVolumePathCheck.cpp + GCode/ExclusionVolumePathCheck.hpp GCode/TimelapsePosPicker.cpp GCode/TimelapsePosPicker.hpp GCode.cpp diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5e93ec7eb0..23f7a47188 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2582,6 +2582,18 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu m_processor.result().nozzle_group_result = m_print->get_layered_nozzle_group_result(); m_processor.finalize(true); + if (m_processor.get_result().exclusion_volume_path_conflict) { + const int extruder_id = m_processor.get_result().exclusion_volume_conflict_extruder_id; + const std::string warning = extruder_id >= 0 ? + Slic3r::format( + _(L("A G-code move intersects an exclusion volume for extruder %1%. This may cause a printer collision.")), + std::to_string(extruder_id + 1)) : + _(L("A G-code move intersects an exclusion volume. This may cause a printer collision.")); + print->active_step_add_warning( + PrintStateBase::WarningLevel::CRITICAL, + warning, + PrintStateBase::SlicingExclusionVolumeToolpath); + } // DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics); DoExport::update_print_estimated_stats(m_processor, m_writer.extruders(), print->m_print_statistics, print->config()); // Printed-mass safety check. Flushed filament leaves the bed, so subtract it @@ -2644,6 +2656,7 @@ namespace DoExport { processor.initialize_from_context(nozzle_group_result); processor.initialize_result_moves(); processor.apply_config(config); + processor.configure_exclusion_volume_path_check(config); processor.enable_stealth_time_estimator(silent_time_estimator_enabled); } diff --git a/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp b/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp new file mode 100644 index 0000000000..f2f3bb9cbe --- /dev/null +++ b/src/libslic3r/GCode/ExclusionVolumePathCheck.cpp @@ -0,0 +1,224 @@ +#include "ExclusionVolumePathCheck.hpp" + +#include "libslic3r/Polygon.hpp" +#include "libslic3r/libslic3r.h" + +#include +#include +#include + +namespace Slic3r { + +namespace { + +constexpr double Z_EPSILON_MM = 1e-6; + +Point scaled_point(const Vec3d &point) +{ + return { scale_(point.x()), scale_(point.y()) }; +} + +BoundingBox line_bbox(const Point &a, const Point &b) +{ + BoundingBox bbox; + bbox.merge(a); + bbox.merge(b); + bbox.offset(SCALED_EPSILON); + return bbox; +} + +bool intervals_overlap(coord_t a_min, coord_t a_max, coord_t b_min, coord_t b_max) +{ + if (a_min > a_max) + std::swap(a_min, a_max); + if (b_min > b_max) + std::swap(b_min, b_max); + return std::max(a_min, b_min) <= std::min(a_max, b_max); +} + +bool collinear_segments_overlap(const Line &a, const Line &b) +{ + const Vec2crd a_dir = a.b - a.a; + if (a_dir == Vec2crd::Zero()) + return a.a == b.a || a.a == b.b; + + if (cross2(a_dir, b.a - a.a) != 0 || cross2(a_dir, b.b - a.a) != 0) + return false; + + return std::abs(a_dir.x()) >= std::abs(a_dir.y()) ? + intervals_overlap(a.a.x(), a.b.x(), b.a.x(), b.b.x()) : + intervals_overlap(a.a.y(), a.b.y(), b.a.y(), b.b.y()); +} + +bool overlaps_collinear_boundary(const Line &line, const Lines &edges) +{ + const BoundingBox line_bounds = line_bbox(line.a, line.b); + for (const Line &edge : edges) { + if (line_bounds.overlap(line_bbox(edge.a, edge.b)) && collinear_segments_overlap(line, edge)) + return true; + } + return false; +} + +bool clip_segment_to_z_range( + const Vec3d &from, + const Vec3d &to, + double z_min, + double z_max, + Vec3d &out_from, + Vec3d &out_to) +{ + const double segment_min_z = std::min(from.z(), to.z()); + const double segment_max_z = std::max(from.z(), to.z()); + if (segment_max_z < z_min - Z_EPSILON_MM || segment_min_z > z_max + Z_EPSILON_MM) + return false; + + double t0 = 0.0; + double t1 = 1.0; + const double dz = to.z() - from.z(); + if (std::abs(dz) < Z_EPSILON_MM) { + if (from.z() < z_min - Z_EPSILON_MM || from.z() > z_max + Z_EPSILON_MM) + return false; + } else { + const double z0 = (z_min - from.z()) / dz; + const double z1 = (z_max - from.z()) / dz; + t0 = std::max(t0, std::min(z0, z1)); + t1 = std::min(t1, std::max(z0, z1)); + if (t0 > t1 + Z_EPSILON_MM) + return false; + } + + t0 = std::clamp(t0, 0.0, 1.0); + t1 = std::clamp(t1, 0.0, 1.0); + const Vec3d delta = to - from; + out_from = from + t0 * delta; + out_to = from + t1 * delta; + return true; +} + +} // namespace + +void ExclusionVolumePathChecker::configure(const PrintConfig &config) +{ + clear(); + m_configured = true; + m_extruder_offsets = config.extruder_offset.values; + + const std::vector> regions = + get_bed_excluded_regions_by_extruder(config); + m_regions_by_extruder.resize(regions.size()); + if (m_extruder_offsets.size() < regions.size()) + m_extruder_offsets.resize(regions.size(), Vec2d::Zero()); + + for (size_t extruder_id = 0; extruder_id < regions.size(); ++extruder_id) { + std::vector &prepared = m_regions_by_extruder[extruder_id]; + prepared.reserve(regions[extruder_id].size()); + for (const BedExcludeRegion ®ion : regions[extruder_id]) { + if (region.polygon.points.size() < 3 || region.z_max < region.z_min) + continue; + + PreparedRegion item; + item.region = region; + item.bbox = BoundingBox(region.polygon.points); + item.bbox.offset(SCALED_EPSILON); + item.edge_tree = AABBTreeLines::LinesDistancer(to_lines(region.polygon)); + prepared.emplace_back(std::move(item)); + } + } +} + +void ExclusionVolumePathChecker::clear() +{ + m_configured = false; + m_extruder_offsets.clear(); + m_regions_by_extruder.clear(); + m_result = {}; +} + +bool ExclusionVolumePathChecker::segment_intersects_region( + const Vec3d &from, + const Vec3d &to, + const bool z_known, + const PreparedRegion ®ion) const +{ + Vec3d clipped_from = from; + Vec3d clipped_to = to; + if (z_known && !clip_segment_to_z_range( + from, to, region.region.z_min, region.region.z_max, clipped_from, clipped_to)) + return false; + + const Point a = scaled_point(clipped_from); + const Point b = scaled_point(clipped_to); + if (!line_bbox(a, b).overlap(region.bbox)) + return false; + + if (region.region.polygon.contains(a) || region.region.polygon.contains(b)) + return true; + if (a == b) + return false; + + const Line line(a, b); + if (!region.edge_tree.intersections_with_line(line).empty()) + return true; + + // The line tree intentionally omits collinear intersections. + return overlaps_collinear_boundary(line, region.edge_tree.get_lines()); +} + +void ExclusionVolumePathChecker::check_motion( + const Vec3d &from, + const Vec3d &to, + const bool start_xy_known, + const bool end_xy_known, + const bool start_z_known, + const bool end_z_known, + const int active_extruder_id, + const ExclusionVolumeMotionType motion_type, + const unsigned char source_move_type, + const unsigned int gcode_id, + const size_t move_id) +{ + if (!m_configured || m_result.has_any_conflict || !start_xy_known || !end_xy_known || + m_regions_by_extruder.empty()) + return; + + const bool z_known = start_z_known && end_z_known; + const bool active_extruder_valid = + active_extruder_id >= 0 && size_t(active_extruder_id) < m_regions_by_extruder.size(); + const size_t first_extruder = active_extruder_valid ? size_t(active_extruder_id) : 0; + const size_t last_extruder = active_extruder_valid ? first_extruder + 1 : m_regions_by_extruder.size(); + + for (size_t extruder_id = first_extruder; extruder_id < last_extruder; ++extruder_id) { + const Vec2d offset = extruder_id < m_extruder_offsets.size() ? + m_extruder_offsets[extruder_id] : Vec2d::Zero(); + Vec3d model_from = from; + Vec3d model_to = to; + model_from.head<2>() += offset; + model_to.head<2>() += offset; + + const std::vector ®ions = m_regions_by_extruder[extruder_id]; + for (size_t region_id = 0; region_id < regions.size(); ++region_id) { + if (!segment_intersects_region(model_from, model_to, z_known, regions[region_id])) + continue; + + m_result.has_any_conflict = true; + m_result.has_travel_conflict = motion_type == ExclusionVolumeMotionType::Travel; + m_result.has_extrusion_conflict = motion_type == ExclusionVolumeMotionType::Extrude; + m_result.has_other_motion_conflict = motion_type == ExclusionVolumeMotionType::Other; + m_result.first_hit = ExclusionVolumePathHit{ + move_id, + gcode_id, + motion_type, + source_move_type, + int(extruder_id), + region_id, + model_from, + model_to, + !z_known + }; + return; + } + } +} + +} // namespace Slic3r diff --git a/src/libslic3r/GCode/ExclusionVolumePathCheck.hpp b/src/libslic3r/GCode/ExclusionVolumePathCheck.hpp new file mode 100644 index 0000000000..b04db406dc --- /dev/null +++ b/src/libslic3r/GCode/ExclusionVolumePathCheck.hpp @@ -0,0 +1,89 @@ +#pragma once + +#include "libslic3r/AABBTreeLines.hpp" +#include "libslic3r/BoundingBox.hpp" +#include "libslic3r/Line.hpp" +#include "libslic3r/PrintConfig.hpp" + +#include +#include +#include + +namespace Slic3r { + +enum class ExclusionVolumeMotionType : unsigned char +{ + Travel, + Extrude, + Other +}; + +struct ExclusionVolumePathHit +{ + size_t move_id { 0 }; + unsigned int gcode_id { 0 }; + ExclusionVolumeMotionType motion_type { ExclusionVolumeMotionType::Other }; + unsigned char source_move_type { 0 }; + int extruder_id { -1 }; + size_t region_id { 0 }; + Vec3d from { Vec3d::Zero() }; + Vec3d to { Vec3d::Zero() }; + bool used_unknown_z { false }; +}; + +struct ExclusionVolumePathCheckResult +{ + bool has_any_conflict { false }; + bool has_travel_conflict { false }; + bool has_extrusion_conflict { false }; + bool has_other_motion_conflict { false }; + std::optional first_hit; +}; + +// Checks G-code coordinates as they are parsed. Exclusion regions are expressed +// in nozzle/model space, so each candidate physical extruder offset is applied +// before testing a motion. This keeps the checker independent of preview +// vertices, whose extruder_id field represents a filament rather than a nozzle. +class ExclusionVolumePathChecker +{ +public: + void configure(const PrintConfig &config); + void clear(); + + bool configured() const { return m_configured; } + const ExclusionVolumePathCheckResult &result() const { return m_result; } + + void check_motion( + const Vec3d &from, + const Vec3d &to, + bool start_xy_known, + bool end_xy_known, + bool start_z_known, + bool end_z_known, + int active_extruder_id, + ExclusionVolumeMotionType motion_type, + unsigned char source_move_type, + unsigned int gcode_id, + size_t move_id); + +private: + struct PreparedRegion + { + BedExcludeRegion region; + BoundingBox bbox; + AABBTreeLines::LinesDistancer edge_tree; + }; + + bool segment_intersects_region( + const Vec3d &from, + const Vec3d &to, + bool z_known, + const PreparedRegion ®ion) const; + + bool m_configured { false }; + std::vector m_extruder_offsets; + std::vector> m_regions_by_extruder; + ExclusionVolumePathCheckResult m_result; +}; + +} // namespace Slic3r diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 0a65508350..eb05146892 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -2528,6 +2528,17 @@ void GCodeProcessorResult::reset() { wrapping_exclude_area = Pointfs(); //BBS: add toolpath_outside toolpath_outside = false; + exclusion_volume_path_checked = false; + exclusion_volume_path_conflict = false; + exclusion_volume_travel_conflict = false; + exclusion_volume_extrusion_conflict = false; + exclusion_volume_other_motion_conflict = false; + exclusion_volume_conflict_gcode_id = 0; + exclusion_volume_conflict_move_id = 0; + exclusion_volume_conflict_move_type = EMoveType::Noop; + exclusion_volume_conflict_extruder_id = -1; + exclusion_volume_conflict_region_id = 0; + exclusion_volume_conflict_used_unknown_z = false; //BBS: add label_object_enabled label_object_enabled = false; long_retraction_when_cut = false; @@ -3485,6 +3496,10 @@ void GCodeProcessor::reset() m_start_position = { 0.0f, 0.0f, 0.0f, 0.0f }; m_end_position = { 0.0f, 0.0f, 0.0f, 0.0f }; m_origin = { 0.0f, 0.0f, 0.0f, 0.0f }; + m_axis_position_known = { false, false, false }; + m_axis_origin_known = { true, true, true }; + m_processing_homing_move = false; + m_exclusion_volume_path_checker.clear(); m_cached_position.reset(); m_wiping = false; m_flushing = false; @@ -3692,6 +3707,40 @@ void GCodeProcessor::process_buffer(const std::string &buffer) }); } +void GCodeProcessor::configure_exclusion_volume_path_check(const PrintConfig &config) +{ + m_exclusion_volume_path_checker.configure(config); +} + +GCodeProcessor::PositionState GCodeProcessor::get_current_position() const +{ + PositionState state; + state.position = Vec3d(m_end_position[X], m_end_position[Y], m_end_position[Z]); + state.axis_known = m_axis_position_known; + return state; +} + +void GCodeProcessor::update_exclusion_volume_path_check_result() +{ + m_result.exclusion_volume_path_checked = m_exclusion_volume_path_checker.configured(); + const ExclusionVolumePathCheckResult &check = m_exclusion_volume_path_checker.result(); + m_result.exclusion_volume_path_conflict = check.has_any_conflict; + m_result.exclusion_volume_travel_conflict = check.has_travel_conflict; + m_result.exclusion_volume_extrusion_conflict = check.has_extrusion_conflict; + m_result.exclusion_volume_other_motion_conflict = check.has_other_motion_conflict; + + if (!check.first_hit) + return; + + const ExclusionVolumePathHit &hit = *check.first_hit; + m_result.exclusion_volume_conflict_gcode_id = hit.gcode_id; + m_result.exclusion_volume_conflict_move_id = hit.move_id; + m_result.exclusion_volume_conflict_move_type = static_cast(hit.source_move_type); + m_result.exclusion_volume_conflict_extruder_id = hit.extruder_id; + m_result.exclusion_volume_conflict_region_id = hit.region_id; + m_result.exclusion_volume_conflict_used_unknown_z = hit.used_unknown_z; +} + void GCodeProcessor::finalize(bool post_process) { m_result.z_offset = m_z_offset; @@ -3731,6 +3780,7 @@ void GCodeProcessor::finalize(bool post_process) if (m_enable_pre_heating) run_second_pass_injection(); } + update_exclusion_volume_path_check_result(); //BBS: update slice warning update_slice_warnings(); } @@ -4857,6 +4907,30 @@ void GCodeProcessor::process_G0(const GCodeReader::GCodeLine& line) process_G1(line); } +void GCodeProcessor::update_position_known_from_move( + const std::array, 4> &axes, + const G1DiscretizationOrigin origin) +{ + if (origin != G1DiscretizationOrigin::G1 || m_global_positioning_type != EPositioningType::Absolute) + return; + + for (unsigned char axis = X; axis <= Z; ++axis) { + if (axes[axis].has_value()) + m_axis_position_known[axis] = m_axis_origin_known[axis]; + } +} + +void GCodeProcessor::update_position_known_from_move(const GCodeReader::GCodeLine &line) +{ + if (m_global_positioning_type != EPositioningType::Absolute) + return; + + for (unsigned char axis = X; axis <= Z; ++axis) { + if (line.has(static_cast(axis))) + m_axis_position_known[axis] = m_axis_origin_known[axis]; + } +} + void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line, const std::optional& remaining_internal_g1_lines) { std::array, 4> g1_axes = { std::nullopt, std::nullopt, std::nullopt, std::nullopt }; @@ -4872,6 +4946,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line, const std::o void GCodeProcessor::process_G1(const std::array, 4>& axes, const std::optional& feedrate, G1DiscretizationOrigin origin, const std::optional& remaining_internal_g1_lines) { + const std::array start_axis_known = m_axis_position_known; int filament_id = get_filament_id(); int last_filament_id = get_last_filament_id(); float filament_diameter = (static_cast(filament_id) < m_result.filament_diameters.size()) ? m_result.filament_diameters[filament_id] : m_result.filament_diameters.back(); @@ -4921,6 +4996,7 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes for (unsigned char a = X; a <= E; ++a) { m_end_position[a] = extract_absolute_position_on_axis((Axis)a, axes[a], double(area_filament_cross_section)); } + update_position_known_from_move(axes, origin); // updates feedrate from line, if present if (feedrate.has_value()) @@ -4942,6 +5018,40 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes const float delta_xyz = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z])); m_travel_dist = delta_xyz; + if (!m_processing_homing_move) { + std::optional exclusion_motion_type; + switch (type) { + case EMoveType::Travel: + exclusion_motion_type = ExclusionVolumeMotionType::Travel; + break; + case EMoveType::Extrude: + case EMoveType::Wipe: + exclusion_motion_type = ExclusionVolumeMotionType::Extrude; + break; + case EMoveType::Retract: + case EMoveType::Unretract: + exclusion_motion_type = ExclusionVolumeMotionType::Other; + break; + default: + break; + } + + if (exclusion_motion_type) { + m_exclusion_volume_path_checker.check_motion( + Vec3d(m_start_position[X], m_start_position[Y], m_start_position[Z]), + Vec3d(m_end_position[X], m_end_position[Y], m_end_position[Z]), + start_axis_known[X] && start_axis_known[Y], + m_axis_position_known[X] && m_axis_position_known[Y], + start_axis_known[Z], + m_axis_position_known[Z], + get_extruder_id(false), + *exclusion_motion_type, + static_cast(type), + m_line_id, + m_result.moves.size()); + } + } + if (type == EMoveType::Extrude) { float volume_extruded_filament = area_filament_cross_section * delta_pos[E]; float area_toolpath_cross_section = volume_extruded_filament / delta_xyz; @@ -5925,6 +6035,10 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line, bool cloc m_start_position = m_end_position; // this is required because we are skipping the call to process_gcode_line() internal_only_g1_line(adjust_target(end_position, prev_target), arc.delta_z() != 0.0, (segments == 1) ? feedrate : std::nullopt, extrusion); } + + // Internal linearized arc segments inherit the arc's starting certainty. + // Only the original absolute command may establish a newly known endpoint. + update_position_known_from_move(line); } //BBS @@ -6024,7 +6138,19 @@ void GCodeProcessor::process_G28(const GCodeReader::GCodeLine& line) GCodeReader::GCodeLine new_gline; GCodeReader reader; reader.parse_line(new_line_raw, [&](GCodeReader& reader, const GCodeReader::GCodeLine& gline) { new_gline = gline; }); + m_processing_homing_move = true; process_G1(new_gline); + m_processing_homing_move = false; + + // G28's physical endpoint is printer-specific even though the preview uses + // zero. Wait for a subsequent explicit absolute coordinate before checking + // a path from any homed axis. + for (unsigned char axis = X; axis <= Z; ++axis) { + if (!found || line.has(static_cast(axis))) { + m_axis_position_known[axis] = false; + m_axis_origin_known[axis] = true; + } + } } void GCodeProcessor::process_G90(const GCodeReader::GCodeLine& line) @@ -6043,16 +6169,19 @@ void GCodeProcessor::process_G92(const GCodeReader::GCodeLine& line) bool any_found = false; if (line.has_x()) { + m_axis_origin_known[X] = m_axis_position_known[X]; m_origin[X] = m_end_position[X] - line.x() * lengths_scale_factor; any_found = true; } if (line.has_y()) { + m_axis_origin_known[Y] = m_axis_position_known[Y]; m_origin[Y] = m_end_position[Y] - line.y() * lengths_scale_factor; any_found = true; } if (line.has_z()) { + m_axis_origin_known[Z] = m_axis_position_known[Z]; m_origin[Z] = m_end_position[Z] - line.z() * lengths_scale_factor; any_found = true; } @@ -6070,6 +6199,8 @@ void GCodeProcessor::process_G92(const GCodeReader::GCodeLine& line) // The G92 may be called for axes that PrusaSlicer does not recognize, for example see GH issue #3510, // where G92 A0 B0 is called although the extruder axis is till E. for (unsigned char a = X; a <= E; ++a) { + if (a <= Z) + m_axis_origin_known[a] = m_axis_position_known[a]; m_origin[a] = m_end_position[a]; } } diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 0f211f133e..b169c976d4 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -7,6 +7,7 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/CustomGCode.hpp" #include "libslic3r/MultiNozzleUtils.hpp" +#include "libslic3r/GCode/ExclusionVolumePathCheck.hpp" #include #include @@ -268,6 +269,17 @@ class Print; std::vector extruder_heights; //BBS: add toolpath_outside bool toolpath_outside; + bool exclusion_volume_path_checked { false }; + bool exclusion_volume_path_conflict { false }; + bool exclusion_volume_travel_conflict { false }; + bool exclusion_volume_extrusion_conflict { false }; + bool exclusion_volume_other_motion_conflict { false }; + unsigned int exclusion_volume_conflict_gcode_id { 0 }; + size_t exclusion_volume_conflict_move_id { 0 }; + EMoveType exclusion_volume_conflict_move_type { EMoveType::Noop }; + int exclusion_volume_conflict_extruder_id { -1 }; + size_t exclusion_volume_conflict_region_id { 0 }; + bool exclusion_volume_conflict_used_unknown_z { false }; //BBS: add object_label_enabled bool label_object_enabled; //BBS : extra retraction when change filament,experiment func @@ -333,6 +345,17 @@ class Print; bed_exclude_area = other.bed_exclude_area; wrapping_exclude_area = other.wrapping_exclude_area; toolpath_outside = other.toolpath_outside; + exclusion_volume_path_checked = other.exclusion_volume_path_checked; + exclusion_volume_path_conflict = other.exclusion_volume_path_conflict; + exclusion_volume_travel_conflict = other.exclusion_volume_travel_conflict; + exclusion_volume_extrusion_conflict = other.exclusion_volume_extrusion_conflict; + exclusion_volume_other_motion_conflict = other.exclusion_volume_other_motion_conflict; + exclusion_volume_conflict_gcode_id = other.exclusion_volume_conflict_gcode_id; + exclusion_volume_conflict_move_id = other.exclusion_volume_conflict_move_id; + exclusion_volume_conflict_move_type = other.exclusion_volume_conflict_move_type; + exclusion_volume_conflict_extruder_id = other.exclusion_volume_conflict_extruder_id; + exclusion_volume_conflict_region_id = other.exclusion_volume_conflict_region_id; + exclusion_volume_conflict_used_unknown_z = other.exclusion_volume_conflict_used_unknown_z; label_object_enabled = other.label_object_enabled; long_retraction_when_cut = other.long_retraction_when_cut; timelapse_warning_code = other.timelapse_warning_code; @@ -1070,6 +1093,10 @@ class Print; AxisCoords m_start_position; // mm AxisCoords m_end_position; // mm AxisCoords m_origin; // mm + std::array m_axis_position_known { false, false, false }; + std::array m_axis_origin_known { true, true, true }; + bool m_processing_homing_move { false }; + ExclusionVolumePathChecker m_exclusion_volume_path_checker; CachedPosition m_cached_position; bool m_wiping; bool m_flushing; // mark a section with real flush @@ -1206,6 +1233,15 @@ class Print; static unsigned int s_result_id; public: + struct PositionState + { + Vec3d position { Vec3d::Zero() }; + std::array axis_known { false, false, false }; + + bool has_known_xy() const { return axis_known[X] && axis_known[Y]; } + bool has_known_z() const { return axis_known[Z]; } + }; + GCodeProcessor(); void init_filament_maps_and_nozzle_type_when_import_only_gcode(); // Reprocessing an already-generated g-code (from-previous / imported g-code) does not rebuild @@ -1223,6 +1259,7 @@ class Print; const std::vector &filament_map, const std::vector>& unprintable_filament_types ); void apply_config(const PrintConfig& config); + void configure_exclusion_volume_path_check(const PrintConfig &config); void set_print(Print* print) { m_print = print; } // Hand the nozzle grouping context to the estimator BEFORE the streaming replay, so the // per-slot machine-limit resolution can follow the active nozzle. Null is fine (slot 0). @@ -1242,6 +1279,7 @@ class Print; const GCodeProcessorResult& get_result() const { return m_result; } GCodeProcessorResult& result() { return m_result; } GCodeProcessorResult&& extract_result() { return std::move(m_result); } + PositionState get_current_position() const; // Load a G-code into a stand-alone G-code viewer. // throws CanceledException through print->throw_if_canceled() (sent by the caller as callback). @@ -1300,6 +1338,9 @@ class Print; void process_G1(const std::array, 4>& axes = { std::nullopt, std::nullopt, std::nullopt, std::nullopt }, const std::optional& feedrate = std::nullopt, G1DiscretizationOrigin origin = G1DiscretizationOrigin::G1, const std::optional& remaining_internal_g1_lines = std::nullopt); + void update_position_known_from_move(const std::array, 4> &axes, G1DiscretizationOrigin origin); + void update_position_known_from_move(const GCodeReader::GCodeLine &line); + void update_exclusion_volume_path_check_result(); // Arc Move void process_G2_G3(const GCodeReader::GCodeLine& line, bool clockwise); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 8d7a8ec225..42021d3090 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -4601,6 +4601,7 @@ void Print::export_gcode_from_previous_file(const std::string& file, GCodeProces // (via ensure_nozzle_group_result), so the multi-nozzle send/monitor mapping survives here. if (result != nullptr && result->nozzle_group_result) processor.initialize_from_context(result->nozzle_group_result); + processor.configure_exclusion_volume_path_check(this->config()); //processor.enable_producers(true); processor.process_file(file); diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp index d4f99c764e..f73626241f 100644 --- a/src/libslic3r/PrintBase.hpp +++ b/src/libslic3r/PrintBase.hpp @@ -62,7 +62,8 @@ public: SlicingReplaceInitEmptyLayers, SlicingNeedSupportOn, SlicingEmptyGcodeLayers, - SlicingGcodeOverlap + SlicingGcodeOverlap, + SlicingExclusionVolumeToolpath }; typedef size_t TimeStamp;