mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-25 03:42:05 +00:00
ENH: Add gcode check for multi_extruder
jira: none Change-Id: Iebc43e608c4509eb62b280af2d401fa9e0e089ba (cherry picked from commit c75c10e312b8d0bd5404d92db88c95a9e6186bc1)
This commit is contained in:
@@ -698,6 +698,59 @@ GCodeProcessor::GCodeProcessor()
|
||||
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].line_m73_stop_mask = "M73 D%s\n";
|
||||
}
|
||||
|
||||
bool GCodeProcessor::check_multi_extruder_gcode_valid(const std::vector<Polygons> &unprintable_areas, const std::vector<int> &filament_map)
|
||||
{
|
||||
m_result.gcode_check_result.reset();
|
||||
|
||||
auto to_2d = [](const Vec3d &pos) -> Point {
|
||||
Point ps(scale_(pos.x()), scale_(pos.y()));
|
||||
return ps;
|
||||
};
|
||||
|
||||
std::map<int, Points> gcode_path_pos;
|
||||
for (const GCodeProcessorResult::MoveVertex &move : m_result.moves) {
|
||||
if (move.type == EMoveType::Extrude/* || move.type == EMoveType::Travel*/) {
|
||||
if (move.is_arc_move_with_interpolation_points()) {
|
||||
for (int i = 0; i < move.interpolation_points.size(); i++) {
|
||||
gcode_path_pos[int(move.extruder_id)].emplace_back(to_2d(move.interpolation_points[i].cast<double>()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
gcode_path_pos[int(move.extruder_id)].emplace_back(to_2d(move.position.cast<double>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
for (auto iter = gcode_path_pos.begin(); iter != gcode_path_pos.end(); ++iter) {
|
||||
int extruder_id = filament_map[iter->first] - 1;
|
||||
Polygon path_poly(iter->second);
|
||||
BoundingBox bbox = path_poly.bounding_box();
|
||||
|
||||
// Simplified use bounding_box, Accurate calculation is not efficient
|
||||
for (const Polygon &poly : unprintable_areas[extruder_id]) {
|
||||
if (poly.bounding_box().overlap(bbox)) {
|
||||
m_result.gcode_check_result.error_code = 1;
|
||||
m_result.gcode_check_result.error_infos[extruder_id].push_back(iter->first);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Accurate calculation is not efficient
|
||||
for (const Polygon& poly : unprintable_areas[extruder_id]) {
|
||||
if (poly.overlaps({path_poly})) {
|
||||
m_result.gcode_check_result.error_code = 1;
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
void GCodeProcessor::apply_config(const PrintConfig& config)
|
||||
{
|
||||
m_parser.apply_config(config);
|
||||
|
||||
@@ -133,9 +133,21 @@ class Print;
|
||||
|
||||
using ConflictResultOpt = std::optional<ConflictResult>;
|
||||
|
||||
struct GCodeCheckResult
|
||||
{
|
||||
int error_code = 0; // 0 means succeed
|
||||
std::map<int, std::vector<int>> error_infos; // extruder_id to filament_ids
|
||||
|
||||
void reset() {
|
||||
error_code = 0;
|
||||
error_infos.clear();
|
||||
}
|
||||
};
|
||||
|
||||
struct GCodeProcessorResult
|
||||
{
|
||||
ConflictResultOpt conflict_result;
|
||||
GCodeCheckResult gcode_check_result;
|
||||
BedMatchResult bed_match_result;
|
||||
|
||||
struct SettingsIds
|
||||
@@ -260,6 +272,7 @@ class Print;
|
||||
spiral_vase_layers = other.spiral_vase_layers;
|
||||
warnings = other.warnings;
|
||||
bed_type = other.bed_type;
|
||||
gcode_check_result = other.gcode_check_result;
|
||||
bed_match_result = other.bed_match_result;
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
time = other.time;
|
||||
@@ -776,6 +789,8 @@ class Print;
|
||||
public:
|
||||
GCodeProcessor();
|
||||
|
||||
// check whether the gcode path meets the filament_map grouping requirements
|
||||
bool check_multi_extruder_gcode_valid(const std::vector<Polygons> &unprintable_areas, const std::vector<int>& filament_map);
|
||||
void apply_config(const PrintConfig& config);
|
||||
void set_print(Print* print) { m_print = print; }
|
||||
void enable_stealth_time_estimator(bool enabled);
|
||||
|
||||
Reference in New Issue
Block a user