GCode Viewer -> Fixed used filament for gcode files produced by other slicers

This commit is contained in:
enricoturri1966 2021-06-15 09:39:33 +02:00
parent 2f8190e6d0
commit a2788f3a73
2 changed files with 97 additions and 71 deletions

View file

@ -8,6 +8,7 @@
#if ENABLE_VALIDATE_CUSTOM_GCODE #if ENABLE_VALIDATE_CUSTOM_GCODE
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#endif // ENABLE_VALIDATE_CUSTOM_GCODE #endif // ENABLE_VALIDATE_CUSTOM_GCODE
#include <boost/algorithm/string/split.hpp>
#include <boost/nowide/fstream.hpp> #include <boost/nowide/fstream.hpp>
#include <boost/nowide/cstdio.hpp> #include <boost/nowide/cstdio.hpp>
#if ENABLE_GCODE_WINDOW #if ENABLE_GCODE_WINDOW
@ -1422,7 +1423,7 @@ void GCodeProcessor::apply_config_simplify3d(const std::string& filename)
BedSize bed_size; BedSize bed_size;
m_parser.parse_file(filename, [this, &bed_size](GCodeReader& reader, const GCodeReader::GCodeLine& line) { m_parser.parse_file(filename, [this, &bed_size](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
auto extract_float = [](const std::string& cmt, const std::string& key, double& out) { auto extract_double = [](const std::string& cmt, const std::string& key, double& out) {
size_t pos = cmt.find(key); size_t pos = cmt.find(key);
if (pos != cmt.npos) { if (pos != cmt.npos) {
pos = cmt.find(',', pos); pos = cmt.find(',', pos);
@ -1434,24 +1435,42 @@ void GCodeProcessor::apply_config_simplify3d(const std::string& filename)
return false; return false;
}; };
auto extract_floats = [](const std::string& cmt, const std::string& key, std::vector<float>& out) {
size_t pos = cmt.find(key);
if (pos != cmt.npos) {
pos = cmt.find(',', pos);
if (pos != cmt.npos) {
std::string data_str = cmt.substr(pos + 1);
std::vector<std::string> values_str;
boost::split(values_str, data_str, boost::is_any_of("|"), boost::token_compress_on);
for (const std::string& s : values_str) {
out.emplace_back(static_cast<float>(string_to_double_decimal_point(s)));
}
return true;
}
}
return false;
};
const std::string& comment = line.raw(); const std::string& comment = line.raw();
if (comment.length() > 2 && comment.front() == ';') { if (comment.length() > 2 && comment.front() == ';') {
if (bed_size.x == 0.0) if (bed_size.x == 0.0 && comment.find("strokeXoverride") != comment.npos)
extract_float(comment, "strokeXoverride", bed_size.x); extract_double(comment, "strokeXoverride", bed_size.x);
if (bed_size.y == 0.0) else if (bed_size.y == 0.0 && comment.find("strokeYoverride") != comment.npos)
extract_float(comment, "strokeYoverride", bed_size.y); extract_double(comment, "strokeYoverride", bed_size.y);
else if (comment.find("filamentDiameters") != comment.npos) {
// check for early exit m_result.filament_diameters.clear();
if (bed_size.is_defined()) { extract_floats(comment, "filamentDiameters", m_result.filament_diameters);
#if ENABLE_VALIDATE_CUSTOM_GCODE }
m_parser.quit_parsing(); else if (comment.find("filamentDensities") != comment.npos) {
#else m_result.filament_densities.clear();
m_parser.quit_parsing_file(); extract_floats(comment, "filamentDensities", m_result.filament_densities);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
} }
} }
}); });
m_result.extruders_count = std::max<size_t>(1, std::min(m_result.filament_diameters.size(), m_result.filament_densities.size()));
if (bed_size.is_defined()) { if (bed_size.is_defined()) {
m_result.bed_shape = { m_result.bed_shape = {
{ 0.0, 0.0 }, { 0.0, 0.0 },
@ -1596,8 +1615,7 @@ void GCodeProcessor::process_tags(const std::string_view comment)
#if ENABLE_VALIDATE_CUSTOM_GCODE #if ENABLE_VALIDATE_CUSTOM_GCODE
// extrusion role tag // extrusion role tag
if (boost::starts_with(comment, reserved_tag(ETags::Role))) { if (boost::starts_with(comment, reserved_tag(ETags::Role))) {
m_used_filaments.process_role_cache(this); set_extrusion_role(ExtrusionEntity::string_to_role(comment.substr(reserved_tag(ETags::Role).length())));
m_extrusion_role = ExtrusionEntity::string_to_role(comment.substr(reserved_tag(ETags::Role).length()));
#if ENABLE_SEAMS_VISUALIZATION #if ENABLE_SEAMS_VISUALIZATION
if (m_extrusion_role == erExternalPerimeter) if (m_extrusion_role == erExternalPerimeter)
m_seams_detector.activate(true); m_seams_detector.activate(true);
@ -1622,7 +1640,7 @@ void GCodeProcessor::process_tags(const std::string_view comment)
#else #else
// extrusion role tag // extrusion role tag
if (boost::starts_with(comment, Extrusion_Role_Tag)) { if (boost::starts_with(comment, Extrusion_Role_Tag)) {
m_extrusion_role = ExtrusionEntity::string_to_role(comment.substr(Extrusion_Role_Tag.length())); set_extrusion_role(ExtrusionEntity::string_to_role(comment.substr(Extrusion_Role_Tag.length())));
return; return;
} }
@ -1804,23 +1822,23 @@ bool GCodeProcessor::process_cura_tags(const std::string_view comment)
if (pos != comment.npos) { if (pos != comment.npos) {
const std::string_view type = comment.substr(pos + tag.length()); const std::string_view type = comment.substr(pos + tag.length());
if (type == "SKIRT") if (type == "SKIRT")
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
else if (type == "WALL-OUTER") else if (type == "WALL-OUTER")
m_extrusion_role = erExternalPerimeter; set_extrusion_role(erExternalPerimeter);
else if (type == "WALL-INNER") else if (type == "WALL-INNER")
m_extrusion_role = erPerimeter; set_extrusion_role(erPerimeter);
else if (type == "SKIN") else if (type == "SKIN")
m_extrusion_role = erSolidInfill; set_extrusion_role(erSolidInfill);
else if (type == "FILL") else if (type == "FILL")
m_extrusion_role = erInternalInfill; set_extrusion_role(erInternalInfill);
else if (type == "SUPPORT") else if (type == "SUPPORT")
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
else if (type == "SUPPORT-INTERFACE") else if (type == "SUPPORT-INTERFACE")
m_extrusion_role = erSupportMaterialInterface; set_extrusion_role(erSupportMaterialInterface);
else if (type == "PRIME-TOWER") else if (type == "PRIME-TOWER")
m_extrusion_role = erWipeTower; set_extrusion_role(erWipeTower);
else { else {
m_extrusion_role = erNone; set_extrusion_role(erNone);
BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type; BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type;
} }
@ -1884,14 +1902,14 @@ bool GCodeProcessor::process_simplify3d_tags(const std::string_view comment)
// ; skirt // ; skirt
pos = cmt.find(" skirt"); pos = cmt.find(" skirt");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
return true; return true;
} }
// ; outer perimeter // ; outer perimeter
pos = cmt.find(" outer perimeter"); pos = cmt.find(" outer perimeter");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erExternalPerimeter; set_extrusion_role(erExternalPerimeter);
#if ENABLE_SEAMS_VISUALIZATION #if ENABLE_SEAMS_VISUALIZATION
m_seams_detector.activate(true); m_seams_detector.activate(true);
#endif // ENABLE_SEAMS_VISUALIZATION #endif // ENABLE_SEAMS_VISUALIZATION
@ -1901,77 +1919,77 @@ bool GCodeProcessor::process_simplify3d_tags(const std::string_view comment)
// ; inner perimeter // ; inner perimeter
pos = cmt.find(" inner perimeter"); pos = cmt.find(" inner perimeter");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erPerimeter; set_extrusion_role(erPerimeter);
return true; return true;
} }
// ; gap fill // ; gap fill
pos = cmt.find(" gap fill"); pos = cmt.find(" gap fill");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erGapFill; set_extrusion_role(erGapFill);
return true; return true;
} }
// ; infill // ; infill
pos = cmt.find(" infill"); pos = cmt.find(" infill");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erInternalInfill; set_extrusion_role(erInternalInfill);
return true; return true;
} }
// ; solid layer // ; solid layer
pos = cmt.find(" solid layer"); pos = cmt.find(" solid layer");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSolidInfill; set_extrusion_role(erSolidInfill);
return true; return true;
} }
// ; bridge // ; bridge
pos = cmt.find(" bridge"); pos = cmt.find(" bridge");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erBridgeInfill; set_extrusion_role(erBridgeInfill);
return true; return true;
} }
// ; support // ; support
pos = cmt.find(" support"); pos = cmt.find(" support");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
return true; return true;
} }
// ; dense support // ; dense support
pos = cmt.find(" dense support"); pos = cmt.find(" dense support");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSupportMaterialInterface; set_extrusion_role(erSupportMaterialInterface);
return true; return true;
} }
// ; prime pillar // ; prime pillar
pos = cmt.find(" prime pillar"); pos = cmt.find(" prime pillar");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erWipeTower; set_extrusion_role(erWipeTower);
return true; return true;
} }
// ; ooze shield // ; ooze shield
pos = cmt.find(" ooze shield"); pos = cmt.find(" ooze shield");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // Missing mapping set_extrusion_role(erNone); // Missing mapping
return true; return true;
} }
// ; raft // ; raft
pos = cmt.find(" raft"); pos = cmt.find(" raft");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
return true; return true;
} }
// ; internal single extrusion // ; internal single extrusion
pos = cmt.find(" internal single extrusion"); pos = cmt.find(" internal single extrusion");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // Missing mapping set_extrusion_role(erNone); // Missing mapping
return true; return true;
} }
@ -2023,29 +2041,29 @@ bool GCodeProcessor::process_craftware_tags(const std::string_view comment)
if (pos != comment.npos) { if (pos != comment.npos) {
const std::string_view type = comment.substr(pos + tag.length()); const std::string_view type = comment.substr(pos + tag.length());
if (type == "Skirt") if (type == "Skirt")
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
else if (type == "Perimeter") else if (type == "Perimeter")
m_extrusion_role = erExternalPerimeter; set_extrusion_role(erExternalPerimeter);
else if (type == "HShell") else if (type == "HShell")
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
else if (type == "InnerHair") else if (type == "InnerHair")
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
else if (type == "Loop") else if (type == "Loop")
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
else if (type == "Infill") else if (type == "Infill")
m_extrusion_role = erInternalInfill; set_extrusion_role(erInternalInfill);
else if (type == "Raft") else if (type == "Raft")
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
else if (type == "Support") else if (type == "Support")
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
else if (type == "SupportTouch") else if (type == "SupportTouch")
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
else if (type == "SoftSupport") else if (type == "SoftSupport")
m_extrusion_role = erSupportMaterialInterface; set_extrusion_role(erSupportMaterialInterface);
else if (type == "Pillar") else if (type == "Pillar")
m_extrusion_role = erWipeTower; set_extrusion_role(erWipeTower);
else { else {
m_extrusion_role = erNone; set_extrusion_role(erNone);
BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type; BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type;
} }
@ -2075,21 +2093,21 @@ bool GCodeProcessor::process_ideamaker_tags(const std::string_view comment)
if (pos != comment.npos) { if (pos != comment.npos) {
const std::string_view type = comment.substr(pos + tag.length()); const std::string_view type = comment.substr(pos + tag.length());
if (type == "RAFT") if (type == "RAFT")
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
else if (type == "WALL-OUTER") else if (type == "WALL-OUTER")
m_extrusion_role = erExternalPerimeter; set_extrusion_role(erExternalPerimeter);
else if (type == "WALL-INNER") else if (type == "WALL-INNER")
m_extrusion_role = erPerimeter; set_extrusion_role(erPerimeter);
else if (type == "SOLID-FILL") else if (type == "SOLID-FILL")
m_extrusion_role = erSolidInfill; set_extrusion_role(erSolidInfill);
else if (type == "FILL") else if (type == "FILL")
m_extrusion_role = erInternalInfill; set_extrusion_role(erInternalInfill);
else if (type == "BRIDGE") else if (type == "BRIDGE")
m_extrusion_role = erBridgeInfill; set_extrusion_role(erBridgeInfill);
else if (type == "SUPPORT") else if (type == "SUPPORT")
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
else { else {
m_extrusion_role = erNone; set_extrusion_role(erNone);
BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type; BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown extrusion role: " << type;
} }
@ -2136,35 +2154,35 @@ bool GCodeProcessor::process_kissslicer_tags(const std::string_view comment)
// ; 'Raft Path' // ; 'Raft Path'
size_t pos = comment.find(" 'Raft Path'"); size_t pos = comment.find(" 'Raft Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSkirt; set_extrusion_role(erSkirt);
return true; return true;
} }
// ; 'Support Interface Path' // ; 'Support Interface Path'
pos = comment.find(" 'Support Interface Path'"); pos = comment.find(" 'Support Interface Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSupportMaterialInterface; set_extrusion_role(erSupportMaterialInterface);
return true; return true;
} }
// ; 'Travel/Ironing Path' // ; 'Travel/Ironing Path'
pos = comment.find(" 'Travel/Ironing Path'"); pos = comment.find(" 'Travel/Ironing Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erIroning; set_extrusion_role(erIroning);
return true; return true;
} }
// ; 'Support (may Stack) Path' // ; 'Support (may Stack) Path'
pos = comment.find(" 'Support (may Stack) Path'"); pos = comment.find(" 'Support (may Stack) Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSupportMaterial; set_extrusion_role(erSupportMaterial);
return true; return true;
} }
// ; 'Perimeter Path' // ; 'Perimeter Path'
pos = comment.find(" 'Perimeter Path'"); pos = comment.find(" 'Perimeter Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erExternalPerimeter; set_extrusion_role(erExternalPerimeter);
#if ENABLE_SEAMS_VISUALIZATION #if ENABLE_SEAMS_VISUALIZATION
m_seams_detector.activate(true); m_seams_detector.activate(true);
#endif // ENABLE_SEAMS_VISUALIZATION #endif // ENABLE_SEAMS_VISUALIZATION
@ -2174,56 +2192,56 @@ bool GCodeProcessor::process_kissslicer_tags(const std::string_view comment)
// ; 'Pillar Path' // ; 'Pillar Path'
pos = comment.find(" 'Pillar Path'"); pos = comment.find(" 'Pillar Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
return true; return true;
} }
// ; 'Destring/Wipe/Jump Path' // ; 'Destring/Wipe/Jump Path'
pos = comment.find(" 'Destring/Wipe/Jump Path'"); pos = comment.find(" 'Destring/Wipe/Jump Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
return true; return true;
} }
// ; 'Prime Pillar Path' // ; 'Prime Pillar Path'
pos = comment.find(" 'Prime Pillar Path'"); pos = comment.find(" 'Prime Pillar Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
return true; return true;
} }
// ; 'Loop Path' // ; 'Loop Path'
pos = comment.find(" 'Loop Path'"); pos = comment.find(" 'Loop Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
return true; return true;
} }
// ; 'Crown Path' // ; 'Crown Path'
pos = comment.find(" 'Crown Path'"); pos = comment.find(" 'Crown Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set_extrusion_role(erNone); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
return true; return true;
} }
// ; 'Solid Path' // ; 'Solid Path'
pos = comment.find(" 'Solid Path'"); pos = comment.find(" 'Solid Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erNone; set_extrusion_role(erNone);
return true; return true;
} }
// ; 'Stacked Sparse Infill Path' // ; 'Stacked Sparse Infill Path'
pos = comment.find(" 'Stacked Sparse Infill Path'"); pos = comment.find(" 'Stacked Sparse Infill Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erInternalInfill; set_extrusion_role(erInternalInfill);
return true; return true;
} }
// ; 'Sparse Infill Path' // ; 'Sparse Infill Path'
pos = comment.find(" 'Sparse Infill Path'"); pos = comment.find(" 'Sparse Infill Path'");
if (pos == 0) { if (pos == 0) {
m_extrusion_role = erSolidInfill; set_extrusion_role(erSolidInfill);
return true; return true;
} }
@ -3072,6 +3090,12 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
#endif // ENABLE_EXTENDED_M73_LINES #endif // ENABLE_EXTENDED_M73_LINES
} }
void GCodeProcessor::set_extrusion_role(ExtrusionRole role)
{
m_used_filaments.process_role_cache(this);
m_extrusion_role = role;
}
float GCodeProcessor::minimum_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const float GCodeProcessor::minimum_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const
{ {
if (m_time_processor.machine_limits.machine_min_extruding_rate.empty()) if (m_time_processor.machine_limits.machine_min_extruding_rate.empty())

View file

@ -718,6 +718,8 @@ namespace Slic3r {
void store_move_vertex(EMoveType type); void store_move_vertex(EMoveType type);
void set_extrusion_role(ExtrusionRole role);
float minimum_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const; float minimum_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const;
float minimum_travel_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const; float minimum_travel_feedrate(PrintEstimatedStatistics::ETimeMode mode, float feedrate) const;
float get_axis_max_feedrate(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const; float get_axis_max_feedrate(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const;