GCodeProcessor -> Human readable extrusion roles in gcode

This commit is contained in:
enricoturri1966 2020-07-28 09:48:55 +02:00
parent 14366800e2
commit d9228ee82c
5 changed files with 46 additions and 22 deletions

View file

@ -331,4 +331,40 @@ std::string ExtrusionEntity::role_to_string(ExtrusionRole role)
return "";
}
ExtrusionRole ExtrusionEntity::string_to_role(const std::string& role)
{
if (role == L("Perimeter"))
return erPerimeter;
else if (role == L("External perimeter"))
return erExternalPerimeter;
else if (role == L("Overhang perimeter"))
return erOverhangPerimeter;
else if (role == L("Internal infill"))
return erInternalInfill;
else if (role == L("Solid infill"))
return erSolidInfill;
else if (role == L("Top solid infill"))
return erTopSolidInfill;
else if (role == L("Ironing"))
return erIroning;
else if (role == L("Bridge infill"))
return erBridgeInfill;
else if (role == L("Gap fill"))
return erGapFill;
else if (role == L("Skirt"))
return erSkirt;
else if (role == L("Support material"))
return erSupportMaterial;
else if (role == L("Support material interface"))
return erSupportMaterialInterface;
else if (role == L("Wipe tower"))
return erWipeTower;
else if (role == L("Custom"))
return erCustom;
else if (role == L("Mixed"))
return erMixed;
else
return erNone;
}
}

View file

@ -106,6 +106,7 @@ public:
virtual double total_volume() const = 0;
static std::string role_to_string(ExtrusionRole role);
static ExtrusionRole string_to_role(const std::string& role);
};
typedef std::vector<ExtrusionEntity*> ExtrusionEntitiesPtr;

View file

@ -1388,7 +1388,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
#if ENABLE_GCODE_VIEWER
// adds tag for processor
_write_format(file, ";%s%d\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), erCustom);
_write_format(file, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#else
if (m_enable_analyzer)
// adds tag for analyzer
@ -1546,7 +1546,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
#if ENABLE_GCODE_VIEWER
// adds tag for processor
_write_format(file, ";%s%d\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), erCustom);
_write_format(file, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#else
if (m_enable_analyzer)
// adds tag for analyzer
@ -3226,7 +3226,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
#if ENABLE_GCODE_VIEWER
if (path.role() != m_last_processor_extrusion_role) {
m_last_processor_extrusion_role = path.role();
sprintf(buf, ";%s%d\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), int(m_last_processor_extrusion_role));
sprintf(buf, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(m_last_processor_extrusion_role).c_str());
gcode += buf;
}
#else

View file

@ -21,13 +21,13 @@ static const float DEFAULT_ACCELERATION = 1500.0f; // Prusa Firmware 1_75mm_MK2
namespace Slic3r {
const std::string GCodeProcessor::Extrusion_Role_Tag = "PrusaSlicer__EXTRUSION_ROLE:";
const std::string GCodeProcessor::Extrusion_Role_Tag = "ExtrType:";
const std::string GCodeProcessor::Width_Tag = "PrusaSlicer__WIDTH:";
const std::string GCodeProcessor::Height_Tag = "PrusaSlicer__HEIGHT:";
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "PrusaSlicer__MM3_PER_MM:";
const std::string GCodeProcessor::Color_Change_Tag = "PrusaSlicer__COLOR_CHANGE";
const std::string GCodeProcessor::Pause_Print_Tag = "PrusaSlicer__PAUSE_PRINT";
const std::string GCodeProcessor::Custom_Code_Tag = "PrusaSlicer__CUSTOM_CODE";
const std::string GCodeProcessor::Color_Change_Tag = "COLOR_CHANGE";
const std::string GCodeProcessor::Pause_Print_Tag = "PAUSE_PRINT";
const std::string GCodeProcessor::Custom_Code_Tag = "CUSTOM_CODE";
static bool is_valid_extrusion_role(int value)
{
@ -560,20 +560,7 @@ void GCodeProcessor::process_tags(const std::string& comment)
// extrusion role tag
size_t pos = comment.find(Extrusion_Role_Tag);
if (pos != comment.npos) {
try
{
int role = std::stoi(comment.substr(pos + Extrusion_Role_Tag.length()));
if (is_valid_extrusion_role(role))
m_extrusion_role = static_cast<ExtrusionRole>(role);
else {
// todo: show some error ?
}
}
catch (...)
{
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Extrusion Role (" << comment << ").";
}
m_extrusion_role = ExtrusionEntity::string_to_role(comment.substr(pos + Extrusion_Role_Tag.length()));
return;
}

View file

@ -64,7 +64,7 @@ public:
#endif // ENABLE_GCODE_VIEWER
m_gcode += buf;
#if ENABLE_GCODE_VIEWER
sprintf(buf, ";%s%d\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), erWipeTower);
sprintf(buf, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erWipeTower).c_str());
#else
sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), erWipeTower);
#endif // ENABLE_GCODE_VIEWER