- GCodeViewer - Fixed loading of gcodes generated by SuperSlicer

This commit is contained in:
enricoturri1966 2021-09-27 11:22:36 +02:00
parent 43470af0c6
commit 7ca9024fca
5 changed files with 69 additions and 1 deletions
src/libslic3r/GCode

View file

@ -746,6 +746,9 @@ const std::vector<std::pair<GCodeProcessor::EProducer, std::string>> GCodeProces
{ EProducer::PrusaSlicer, "generated by PrusaSlicer" },
{ EProducer::Slic3rPE, "generated by Slic3r Prusa Edition" },
{ EProducer::Slic3r, "generated by Slic3r" },
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
{ EProducer::SuperSlicer, "generated by SuperSlicer" },
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
{ EProducer::Cura, "Cura_SteamEngine" },
{ EProducer::Simplify3D, "G-Code generated by Simplify3D(R)" },
{ EProducer::CraftWare, "CraftWare" },
@ -1227,6 +1230,10 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
}
else if (m_producer == EProducer::Simplify3D)
apply_config_simplify3d(filename);
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
else if (m_producer == EProducer::SuperSlicer)
apply_config_superslicer(filename);
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
}
// process gcode
@ -1360,6 +1367,41 @@ std::vector<std::pair<ExtrusionRole, float>> GCodeProcessor::get_roles_time(Prin
return ret;
}
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
ConfigSubstitutions load_from_superslicer_gcode_file(const std::string& filename, DynamicPrintConfig& config, ForwardCompatibilitySubstitutionRule compatibility_rule)
{
// for reference, see: ConfigBase::load_from_gcode_file()
boost::nowide::ifstream ifs(filename);
auto header_end_pos = ifs.tellg();
ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
size_t key_value_pairs = 0;
ifs.seekg(0, ifs.end);
auto file_length = ifs.tellg();
auto data_length = std::min<std::fstream::pos_type>(65535, file_length - header_end_pos);
ifs.seekg(file_length - data_length, ifs.beg);
std::vector<char> data(size_t(data_length) + 1, 0);
ifs.read(data.data(), data_length);
ifs.close();
key_value_pairs = ConfigBase::load_from_gcode_string_legacy(config, data.data(), substitutions_ctxt);
if (key_value_pairs < 80)
throw Slic3r::RuntimeError(format("Suspiciously low number of configuration values extracted from %1%: %2%", filename, key_value_pairs));
return std::move(substitutions_ctxt.substitutions);
}
void GCodeProcessor::apply_config_superslicer(const std::string& filename)
{
DynamicPrintConfig config;
config.apply(FullPrintConfig::defaults());
load_from_superslicer_gcode_file(filename, config, ForwardCompatibilitySubstitutionRule::EnableSilent);
apply_config(config);
}
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
std::vector<float> GCodeProcessor::get_layers_time(PrintEstimatedStatistics::ETimeMode mode) const
{
return (mode < PrintEstimatedStatistics::ETimeMode::Count) ?
@ -1849,6 +1891,9 @@ bool GCodeProcessor::process_producers_tags(const std::string_view comment)
{
case EProducer::Slic3rPE:
case EProducer::Slic3r:
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
case EProducer::SuperSlicer:
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
case EProducer::PrusaSlicer: { return process_prusaslicer_tags(comment); }
case EProducer::Cura: { return process_cura_tags(comment); }
case EProducer::Simplify3D: { return process_simplify3d_tags(comment); }