#7008 - GCodeViewer - Fixed loading of gcodes generated by SuperSlicer
This commit is contained in:
parent
43470af0c6
commit
7ca9024fca
@ -740,7 +740,11 @@ ConfigSubstitutions ConfigBase::load(const boost::property_tree::ptree &tree, Fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the config keys from the given string.
|
// Load the config keys from the given string.
|
||||||
static inline size_t load_from_gcode_string_legacy(ConfigBase &config, const char *str, ConfigSubstitutionContext &substitutions)
|
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
|
size_t ConfigBase::load_from_gcode_string_legacy(ConfigBase& config, const char* str, ConfigSubstitutionContext& substitutions)
|
||||||
|
#else
|
||||||
|
static inline size_t load_from_gcode_string_legacy(ConfigBase& config, const char* str, ConfigSubstitutionContext& substitutions)
|
||||||
|
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
{
|
{
|
||||||
if (str == nullptr)
|
if (str == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2015,6 +2015,10 @@ public:
|
|||||||
// Set all the nullable values to nils.
|
// Set all the nullable values to nils.
|
||||||
void null_nullables();
|
void null_nullables();
|
||||||
|
|
||||||
|
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
|
static size_t load_from_gcode_string_legacy(ConfigBase& config, const char* str, ConfigSubstitutionContext& substitutions);
|
||||||
|
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Set a configuration value from a string.
|
// Set a configuration value from a string.
|
||||||
bool set_deserialize_raw(const t_config_option_key& opt_key_src, const std::string& value, ConfigSubstitutionContext& substitutions, bool append);
|
bool set_deserialize_raw(const t_config_option_key& opt_key_src, const std::string& value, ConfigSubstitutionContext& substitutions, bool append);
|
||||||
|
@ -746,6 +746,9 @@ const std::vector<std::pair<GCodeProcessor::EProducer, std::string>> GCodeProces
|
|||||||
{ EProducer::PrusaSlicer, "generated by PrusaSlicer" },
|
{ EProducer::PrusaSlicer, "generated by PrusaSlicer" },
|
||||||
{ EProducer::Slic3rPE, "generated by Slic3r Prusa Edition" },
|
{ EProducer::Slic3rPE, "generated by Slic3r Prusa Edition" },
|
||||||
{ EProducer::Slic3r, "generated by Slic3r" },
|
{ 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::Cura, "Cura_SteamEngine" },
|
||||||
{ EProducer::Simplify3D, "G-Code generated by Simplify3D(R)" },
|
{ EProducer::Simplify3D, "G-Code generated by Simplify3D(R)" },
|
||||||
{ EProducer::CraftWare, "CraftWare" },
|
{ EProducer::CraftWare, "CraftWare" },
|
||||||
@ -1227,6 +1230,10 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
|
|||||||
}
|
}
|
||||||
else if (m_producer == EProducer::Simplify3D)
|
else if (m_producer == EProducer::Simplify3D)
|
||||||
apply_config_simplify3d(filename);
|
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
|
// process gcode
|
||||||
@ -1360,6 +1367,41 @@ std::vector<std::pair<ExtrusionRole, float>> GCodeProcessor::get_roles_time(Prin
|
|||||||
return ret;
|
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
|
std::vector<float> GCodeProcessor::get_layers_time(PrintEstimatedStatistics::ETimeMode mode) const
|
||||||
{
|
{
|
||||||
return (mode < PrintEstimatedStatistics::ETimeMode::Count) ?
|
return (mode < PrintEstimatedStatistics::ETimeMode::Count) ?
|
||||||
@ -1849,6 +1891,9 @@ bool GCodeProcessor::process_producers_tags(const std::string_view comment)
|
|||||||
{
|
{
|
||||||
case EProducer::Slic3rPE:
|
case EProducer::Slic3rPE:
|
||||||
case EProducer::Slic3r:
|
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::PrusaSlicer: { return process_prusaslicer_tags(comment); }
|
||||||
case EProducer::Cura: { return process_cura_tags(comment); }
|
case EProducer::Cura: { return process_cura_tags(comment); }
|
||||||
case EProducer::Simplify3D: { return process_simplify3d_tags(comment); }
|
case EProducer::Simplify3D: { return process_simplify3d_tags(comment); }
|
||||||
|
@ -543,6 +543,9 @@ namespace Slic3r {
|
|||||||
PrusaSlicer,
|
PrusaSlicer,
|
||||||
Slic3rPE,
|
Slic3rPE,
|
||||||
Slic3r,
|
Slic3r,
|
||||||
|
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
|
SuperSlicer,
|
||||||
|
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
Cura,
|
Cura,
|
||||||
Simplify3D,
|
Simplify3D,
|
||||||
CraftWare,
|
CraftWare,
|
||||||
@ -599,6 +602,9 @@ namespace Slic3r {
|
|||||||
private:
|
private:
|
||||||
void apply_config(const DynamicPrintConfig& config);
|
void apply_config(const DynamicPrintConfig& config);
|
||||||
void apply_config_simplify3d(const std::string& filename);
|
void apply_config_simplify3d(const std::string& filename);
|
||||||
|
#if ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
|
void apply_config_superslicer(const std::string& filename);
|
||||||
|
#endif // ENABLE_FIX_SUPERSLICER_GCODE_IMPORT
|
||||||
void process_gcode_line(const GCodeReader::GCodeLine& line, bool producers_enabled);
|
void process_gcode_line(const GCodeReader::GCodeLine& line, bool producers_enabled);
|
||||||
|
|
||||||
// Process tags embedded into comments
|
// Process tags embedded into comments
|
||||||
|
@ -64,4 +64,13 @@
|
|||||||
#define ENABLE_FIX_SEAMS_SYNCH (1 && ENABLE_2_4_0_ALPHA2)
|
#define ENABLE_FIX_SEAMS_SYNCH (1 && ENABLE_2_4_0_ALPHA2)
|
||||||
|
|
||||||
|
|
||||||
|
//====================
|
||||||
|
// 2.4.0.alpha3 techs
|
||||||
|
//====================
|
||||||
|
#define ENABLE_2_4_0_ALPHA3 1
|
||||||
|
|
||||||
|
// Enable fixing loading of gcode files generated with SuperSlicer in GCodeViewer
|
||||||
|
#define ENABLE_FIX_SUPERSLICER_GCODE_IMPORT (1 && ENABLE_2_4_0_ALPHA3)
|
||||||
|
|
||||||
|
|
||||||
#endif // _prusaslicer_technologies_h_
|
#endif // _prusaslicer_technologies_h_
|
||||||
|
Loading…
Reference in New Issue
Block a user