Tech ENABLE_VALIDATE_CUSTOM_GCODE set as default

This commit is contained in:
enricoturri1966 2021-07-22 09:13:12 +02:00
parent b80fb40fcd
commit 5faac3c105
11 changed files with 3 additions and 277 deletions

View File

@ -172,11 +172,7 @@ namespace Slic3r {
// subdivide the retraction in segments
if (!wipe_path.empty()) {
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_Start) + "\n";
#else
gcode += ";" + GCodeProcessor::Wipe_Start_Tag + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
for (const Line& line : wipe_path.lines()) {
double segment_length = line.length();
/* Reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one
@ -192,11 +188,7 @@ namespace Slic3r {
);
}
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Wipe_End) + "\n";
#else
gcode += ";" + GCodeProcessor::Wipe_End_Tag + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gcodegen.set_last_pos(wipe_path.points.back());
}
@ -655,7 +647,6 @@ namespace DoExport {
print_statistics.filament_stats = result.print_statistics.volumes_per_extruder;
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
// if any reserved keyword is found, returns a std::vector containing the first MAX_COUNT keywords found
// into pairs containing:
// first: source
@ -714,7 +705,6 @@ namespace DoExport {
return ret;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
} // namespace DoExport
void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* result, ThumbnailsGeneratorCallback thumbnail_cb)
@ -729,7 +719,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
print->set_started(psGCodeExport);
#if ENABLE_VALIDATE_CUSTOM_GCODE
// check if any custom gcode contains keywords used by the gcode processor to
// produce time estimation and gcode toolpaths
std::vector<std::pair<std::string, std::string>> validation_res = DoExport::validate_custom_gcode(*print);
@ -743,7 +732,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
reports +
_(L("This may cause problems in g-code visualization and printing time estimation.")));
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
BOOST_LOG_TRIVIAL(info) << "Exporting G-code..." << log_memory_info();
@ -1168,11 +1156,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
// adds tags for time estimators
if (print.config().remaining_times.value)
#if ENABLE_VALIDATE_CUSTOM_GCODE
_write_format(file, ";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::First_Line_M73_Placeholder).c_str());
#else
_writeln(file, GCodeProcessor::First_Line_M73_Placeholder_Tag);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
// Prepare the helper object for replacing placeholders in custom G-code and output filename.
m_placeholder_parser = print.placeholder_parser();
@ -1279,11 +1263,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, false);
// adds tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
_write_format(file, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#else
_write_format(file, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
// Write the custom start G-code
_writeln(file, start_gcode);
@ -1444,11 +1424,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
_write(file, m_writer.set_fan(false));
// adds tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
_write_format(file, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#else
_write_format(file, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(erCustom).c_str());
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
// Process filament-specific gcode in extruder order.
{
@ -1475,11 +1451,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
// adds tags for time estimators
if (print.config().remaining_times.value)
#if ENABLE_VALIDATE_CUSTOM_GCODE
_write_format(file, ";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Last_Line_M73_Placeholder).c_str());
#else
_writeln(file, GCodeProcessor::Last_Line_M73_Placeholder_Tag);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
print.throw_if_canceled();
@ -1495,11 +1467,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
_write_format(file, "; total filament cost = %.2lf\n", print.m_print_statistics.total_cost);
if (print.m_print_statistics.total_toolchanges > 0)
_write_format(file, "; total toolchanges = %i\n", print.m_print_statistics.total_toolchanges);
#if ENABLE_VALIDATE_CUSTOM_GCODE
_write_format(file, ";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str());
#else
_writeln(file, GCodeProcessor::Estimated_Printing_Time_Placeholder_Tag);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
// Append full config.
_write(file, "\n");
@ -1799,11 +1767,7 @@ namespace ProcessLayer
assert(m600_extruder_before_layer >= 0);
// Color Change or Tool Change as Color Change.
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Color_Change) + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
#else
gcode += ";" + GCodeProcessor::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != (unsigned)m600_extruder_before_layer
// && !MMU1
@ -1828,11 +1792,7 @@ namespace ProcessLayer
if (gcode_type == CustomGCode::PausePrint) // Pause print
{
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Pause_Print) + "\n";
#else
gcode += ";" + GCodeProcessor::Pause_Print_Tag + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
//! FIXME_in_fw show message during print pause
if (!pause_print_msg.empty())
gcode += "M117 " + pause_print_msg + "\n";
@ -1840,11 +1800,7 @@ namespace ProcessLayer
}
else {
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Custom_Code) + "\n";
#else
gcode += ";" + GCodeProcessor::Custom_Code_Tag + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
if (gcode_type == CustomGCode::Template) // Template Custom Gcode
gcode += gcodegen.placeholder_parser_process("template_custom_gcode", config.template_custom_gcode, current_extruder_id);
else // custom Gcode
@ -1991,22 +1947,14 @@ void GCode::process_layer(
assert(is_decimal_separator_point()); // for the sprintfs
// add tag for processor
#if ENABLE_VALIDATE_CUSTOM_GCODE
gcode += ";" + GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Layer_Change) + "\n";
#else
gcode += ";" + GCodeProcessor::Layer_Change_Tag + "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
// export layer z
char buf[64];
sprintf(buf, ";Z:%g\n", print_z);
gcode += buf;
// export layer height
float height = first_layer ? static_cast<float>(print_z) : static_cast<float>(print_z) - m_last_layer_z;
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height).c_str(), height);
#else
sprintf(buf, ";%s%g\n", GCodeProcessor::Height_Tag.c_str(), height);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gcode += buf;
// update caches
m_last_layer_z = static_cast<float>(print_z);
@ -2835,21 +2783,13 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
if (path.role() != m_last_processor_extrusion_role) {
m_last_processor_extrusion_role = path.role();
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role).c_str(), ExtrusionEntity::role_to_string(m_last_processor_extrusion_role).c_str());
#else
sprintf(buf, ";%s%s\n", GCodeProcessor::Extrusion_Role_Tag.c_str(), ExtrusionEntity::role_to_string(m_last_processor_extrusion_role).c_str());
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gcode += buf;
}
if (last_was_wipe_tower || m_last_width != path.width) {
m_last_width = path.width;
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width).c_str(), m_last_width);
#else
sprintf(buf, ";%s%g\n", GCodeProcessor::Width_Tag.c_str(), m_last_width);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gcode += buf;
}
@ -2863,11 +2803,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
if (last_was_wipe_tower || std::abs(m_last_height - path.height) > EPSILON) {
m_last_height = path.height;
#if ENABLE_VALIDATE_CUSTOM_GCODE
sprintf(buf, ";%s%g\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height).c_str(), m_last_height);
#else
sprintf(buf, ";%s%g\n", GCodeProcessor::Height_Tag.c_str(), m_last_height);
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gcode += buf;
}

View File

@ -5,9 +5,7 @@
#include "GCodeProcessor.hpp"
#include <boost/log/trivial.hpp>
#if ENABLE_VALIDATE_CUSTOM_GCODE
#include <boost/algorithm/string/predicate.hpp>
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
#include <boost/algorithm/string/split.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/nowide/cstdio.hpp>
@ -37,7 +35,6 @@ static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero();
namespace Slic3r {
#if ENABLE_VALIDATE_CUSTOM_GCODE
const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
"TYPE:",
"WIPE_START",
@ -52,21 +49,6 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
"_GP_LAST_LINE_M73_PLACEHOLDER",
"_GP_ESTIMATED_PRINTING_TIME_PLACEHOLDER"
};
#else
const std::string GCodeProcessor::Extrusion_Role_Tag = "TYPE:";
const std::string GCodeProcessor::Wipe_Start_Tag = "WIPE_START";
const std::string GCodeProcessor::Wipe_End_Tag = "WIPE_END";
const std::string GCodeProcessor::Height_Tag = "HEIGHT:";
const std::string GCodeProcessor::Width_Tag = "WIDTH:";
const std::string GCodeProcessor::Layer_Change_Tag = "LAYER_CHANGE";
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_GCODE";
const std::string GCodeProcessor::First_Line_M73_Placeholder_Tag = "; _GP_FIRST_LINE_M73_PLACEHOLDER";
const std::string GCodeProcessor::Last_Line_M73_Placeholder_Tag = "; _GP_LAST_LINE_M73_PLACEHOLDER";
const std::string GCodeProcessor::Estimated_Printing_Time_Placeholder_Tag = "; _GP_ESTIMATED_PRINTING_TIME_PLACEHOLDER";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
const float GCodeProcessor::Wipe_Width = 0.05f;
const float GCodeProcessor::Wipe_Height = 0.05f;
@ -445,7 +427,6 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
std::string line = gcode_line.substr(0, gcode_line.length() - 1);
std::string ret;
#if ENABLE_VALIDATE_CUSTOM_GCODE
if (line.length() > 1) {
line = line.substr(1);
if (export_remaining_time_enabled &&
@ -477,19 +458,6 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
}
}
else if (line == reserved_tag(ETags::Estimated_Printing_Time_Placeholder)) {
#else
if (export_remaining_time_enabled && (line == First_Line_M73_Placeholder_Tag || line == Last_Line_M73_Placeholder_Tag)) {
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i];
if (machine.enabled) {
ret += format_line_M73(machine.line_m73_mask.c_str(),
(line == First_Line_M73_Placeholder_Tag) ? 0 : 100,
(line == First_Line_M73_Placeholder_Tag) ? time_in_minutes(machines[i].time) : 0);
}
}
}
else if (line == Estimated_Printing_Time_Placeholder_Tag) {
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i];
PrintEstimatedStatistics::ETimeMode mode = static_cast<PrintEstimatedStatistics::ETimeMode>(i);
@ -502,9 +470,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
}
}
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
return std::tuple(!ret.empty(), ret.empty() ? gcode_line : ret, (extra_lines_count == 0) ? extra_lines_count : extra_lines_count - 1);
};
@ -784,7 +750,6 @@ const std::vector<std::pair<GCodeProcessor::EProducer, std::string>> GCodeProces
unsigned int GCodeProcessor::s_result_id = 0;
#if ENABLE_VALIDATE_CUSTOM_GCODE
bool GCodeProcessor::contains_reserved_tag(const std::string& gcode, std::string& found_tag)
{
bool ret = false;
@ -836,7 +801,6 @@ bool GCodeProcessor::contains_reserved_tags(const std::string& gcode, unsigned i
return ret;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
GCodeProcessor::GCodeProcessor()
{
@ -1239,11 +1203,7 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr
if (cmd.length() == 0) {
const std::string_view comment = line.comment();
if (comment.length() > 1 && detect_producer(comment))
#if ENABLE_VALIDATE_CUSTOM_GCODE
m_parser.quit_parsing();
#else
m_parser.quit_parsing_file();
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
}
});
@ -1576,7 +1536,6 @@ void GCodeProcessor::process_tags(const std::string_view comment)
if (m_producers_enabled && process_producers_tags(comment))
return;
#if ENABLE_VALIDATE_CUSTOM_GCODE
// extrusion role tag
if (boost::starts_with(comment, reserved_tag(ETags::Role))) {
set_extrusion_role(ExtrusionEntity::string_to_role(comment.substr(reserved_tag(ETags::Role).length())));
@ -1601,28 +1560,8 @@ void GCodeProcessor::process_tags(const std::string_view comment)
m_wiping = false;
return;
}
#else
// extrusion role tag
if (boost::starts_with(comment, Extrusion_Role_Tag)) {
set_extrusion_role(ExtrusionEntity::string_to_role(comment.substr(Extrusion_Role_Tag.length())));
return;
}
// wipe start tag
if (boost::starts_with(comment, Wipe_Start_Tag)) {
m_wiping = true;
return;
}
// wipe end tag
if (boost::starts_with(comment, Wipe_End_Tag)) {
m_wiping = false;
return;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
if (!m_producers_enabled || m_producer == EProducer::PrusaSlicer) {
#if ENABLE_VALIDATE_CUSTOM_GCODE
// height tag
if (boost::starts_with(comment, reserved_tag(ETags::Height))) {
if (!parse_number(comment.substr(reserved_tag(ETags::Height).size()), m_forced_height))
@ -1635,23 +1574,8 @@ void GCodeProcessor::process_tags(const std::string_view comment)
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Width (" << comment << ").";
return;
}
#else
// height tag
if (boost::starts_with(comment, Height_Tag)) {
if (!parse_number(comment.substr(Height_Tag.size()), m_forced_height))
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Height (" << comment << ").";
return;
}
// width tag
if (boost::starts_with(comment, Width_Tag)) {
if (!parse_number(comment.substr(Width_Tag.size()), m_forced_width))
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Width (" << comment << ").";
return;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
// color change tag
if (boost::starts_with(comment, reserved_tag(ETags::Color_Change))) {
unsigned char extruder_id = 0;
@ -1699,53 +1623,6 @@ void GCodeProcessor::process_tags(const std::string_view comment)
++m_layer_id;
return;
}
#else
// color change tag
if (boost::starts_with(comment, Color_Change_Tag)) {
unsigned char extruder_id = 0;
if (boost::starts_with(comment.substr(Color_Change_Tag.size()), ",T")) {
int eid;
if (! parse_number(comment.substr(Color_Change_Tag.size() + 2), eid) || eid < 0 || eid > 255) {
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Color_Change (" << comment << ").";
return;
}
extruder_id = static_cast<unsigned char>(eid);
}
m_extruder_colors[extruder_id] = static_cast<unsigned char>(m_extruder_offsets.size()) + m_cp_color.counter; // color_change position in list of color for preview
++m_cp_color.counter;
if (m_cp_color.counter == UCHAR_MAX)
m_cp_color.counter = 0;
if (m_extruder_id == extruder_id) {
m_cp_color.current = m_extruder_colors[extruder_id];
store_move_vertex(EMoveType::Color_change);
}
process_custom_gcode_time(CustomGCode::ColorChange);
return;
}
// pause print tag
if (comment == Pause_Print_Tag) {
store_move_vertex(EMoveType::Pause_Print);
process_custom_gcode_time(CustomGCode::PausePrint);
return;
}
// custom code tag
if (comment == Custom_Code_Tag) {
store_move_vertex(EMoveType::Custom_GCode);
return;
}
// layer change tag
if (comment == Layer_Change_Tag) {
++m_layer_id;
return;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
// mm3_per_mm print tag

View File

@ -82,11 +82,9 @@ namespace Slic3r {
class GCodeProcessor
{
#if ENABLE_VALIDATE_CUSTOM_GCODE
static const std::vector<std::string> Reserved_Tags;
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
public:
#if ENABLE_VALIDATE_CUSTOM_GCODE
enum class ETags : unsigned char
{
Role,
@ -109,20 +107,6 @@ namespace Slic3r {
// checks the given gcode for reserved tags and returns true when finding any
// (the first max_count found tags are returned into found_tag)
static bool contains_reserved_tags(const std::string& gcode, unsigned int max_count, std::vector<std::string>& found_tag);
#else
static const std::string Extrusion_Role_Tag;
static const std::string Wipe_Start_Tag;
static const std::string Wipe_End_Tag;
static const std::string Height_Tag;
static const std::string Layer_Change_Tag;
static const std::string Color_Change_Tag;
static const std::string Pause_Print_Tag;
static const std::string Custom_Code_Tag;
static const std::string First_Line_M73_Placeholder_Tag;
static const std::string Last_Line_M73_Placeholder_Tag;
static const std::string Estimated_Printing_Time_Placeholder_Tag;
static const std::string Width_Tag;
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
static const float Wipe_Width;
static const float Wipe_Height;

View File

@ -34,13 +34,8 @@ public:
{
// adds tag for analyzer:
std::ostringstream str;
#if ENABLE_VALIDATE_CUSTOM_GCODE
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Height) << m_layer_height << "\n"; // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Role) << ExtrusionEntity::role_to_string(erWipeTower) << "\n";
#else
str << ";" << GCodeProcessor::Height_Tag << m_layer_height << "\n"; // don't rely on GCodeAnalyzer knowing the layer height - it knows nothing at priming
str << ";" << GCodeProcessor::Extrusion_Role_Tag << ExtrusionEntity::role_to_string(erWipeTower) << "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
m_gcode += str.str();
change_analyzer_line_width(line_width);
}
@ -48,11 +43,7 @@ public:
WipeTowerWriter& change_analyzer_line_width(float line_width) {
// adds tag for analyzer:
std::stringstream str;
#if ENABLE_VALIDATE_CUSTOM_GCODE
str << ";" << GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Width) << line_width << "\n";
#else
str << ";" << GCodeProcessor::Width_Tag << line_width << "\n";
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
m_gcode += str.str();
return *this;
}

View File

@ -120,13 +120,8 @@ void GCodeReader::parse_file(const std::string &file, callback_t callback)
{
boost::nowide::ifstream f(file);
std::string line;
#if ENABLE_VALIDATE_CUSTOM_GCODE
m_parsing = true;
while (m_parsing && std::getline(f, line))
#else
m_parsing_file = true;
while (m_parsing_file && std::getline(f, line))
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
this->parse_line(line, callback);
}

View File

@ -84,12 +84,8 @@ public:
{
const char *ptr = buffer.c_str();
GCodeLine gline;
#if ENABLE_VALIDATE_CUSTOM_GCODE
m_parsing = true;
while (m_parsing && *ptr != 0) {
#else
while (*ptr != 0) {
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
gline.reset();
ptr = this->parse_line(ptr, gline, callback);
}
@ -113,11 +109,7 @@ public:
{ GCodeLine gline; this->parse_line(line.c_str(), gline, callback); }
void parse_file(const std::string &file, callback_t callback);
#if ENABLE_VALIDATE_CUSTOM_GCODE
void quit_parsing() { m_parsing = false; }
#else
void quit_parsing_file() { m_parsing_file = false; }
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
float& x() { return m_position[X]; }
float x() const { return m_position[X]; }
@ -156,11 +148,7 @@ private:
char m_extrusion_axis;
float m_position[NUM_AXES];
bool m_verbose;
#if ENABLE_VALIDATE_CUSTOM_GCODE
bool m_parsing{ false };
#else
bool m_parsing_file{ false };
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
};
} /* namespace Slic3r */

View File

@ -41,12 +41,10 @@
//====================
#define ENABLE_2_4_0_ALPHA0 1
// Enable validation of custom gcode against gcode processor reserved keywords
#define ENABLE_VALIDATE_CUSTOM_GCODE (1 && ENABLE_2_4_0_ALPHA0)
// Enable showing a imgui window containing gcode in preview
#define ENABLE_GCODE_WINDOW (1 && ENABLE_2_4_0_ALPHA0)
// Enable exporting lines M73 for remaining time to next printer stop to gcode
#define ENABLE_EXTENDED_M73_LINES (1 && ENABLE_VALIDATE_CUSTOM_GCODE)
#define ENABLE_EXTENDED_M73_LINES (1 && ENABLE_2_4_0_ALPHA0)
// Enable a modified version of automatic downscale on load of objects too big
#define ENABLE_MODIFIED_DOWNSCALE_ON_LOAD_OBJECTS_TOO_BIG (1 && ENABLE_2_4_0_ALPHA0)
// Enable scrollable legend in preview

View File

@ -2175,7 +2175,6 @@ static std::string get_custom_code(const std::string& code_in, double height)
wxTextEntryDialogStyle | wxTE_MULTILINE);
upgrade_text_entry_dialog(&dlg);
#if ENABLE_VALIDATE_CUSTOM_GCODE
bool valid = true;
std::string value;
do {
@ -2186,12 +2185,6 @@ static std::string get_custom_code(const std::string& code_in, double height)
valid = GUI::Tab::validate_custom_gcode("Custom G-code", value);
} while (!valid);
return value;
#else
if (dlg.ShowModal() != wxID_OK)
return "";
return into_u8(dlg.GetValue());
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
}
static std::string get_pause_print_msg(const std::string& msg_in, double height)

View File

@ -675,14 +675,12 @@ void MainFrame::init_tabpanel()
#else
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxBookCtrlEvent& e) {
#endif
#if ENABLE_VALIDATE_CUSTOM_GCODE
if (int old_selection = e.GetOldSelection();
old_selection != wxNOT_FOUND && old_selection < static_cast<int>(m_tabpanel->GetPageCount())) {
Tab* old_tab = dynamic_cast<Tab*>(m_tabpanel->GetPage(old_selection));
if (old_tab)
old_tab->validate_custom_gcodes();
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
wxWindow* panel = m_tabpanel->GetCurrentPage();
Tab* tab = dynamic_cast<Tab*>(panel);

View File

@ -5,9 +5,7 @@
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp"
#if ENABLE_VALIDATE_CUSTOM_GCODE
#include "libslic3r/GCode/GCodeProcessor.hpp"
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
#include "slic3r/Utils/Http.hpp"
#include "slic3r/Utils/PrintHost.hpp"
@ -1744,7 +1742,6 @@ void TabPrint::clear_pages()
m_top_bottom_shell_thickness_explanation = nullptr;
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
bool Tab::validate_custom_gcode(const wxString& title, const std::string& gcode)
{
std::vector<std::string> tags;
@ -1770,7 +1767,6 @@ static void validate_custom_gcode_cb(Tab* tab, ConfigOptionsGroupShp opt_group,
tab->update_dirty();
tab->on_value_change(opt_key, value);
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
void TabFilament::add_filament_overrides_page()
{
@ -1996,11 +1992,9 @@ void TabFilament::build()
page = add_options_page(L("Custom G-code"), "cog");
optgroup = page->new_optgroup(L("Start G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("start_filament_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2008,11 +2002,9 @@ void TabFilament::build()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("End G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("end_filament_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2323,11 +2315,9 @@ void TabPrinter::build_fff()
const int notes_field_height = 25; // 250
page = add_options_page(L("Custom G-code"), "cog");
optgroup = page->new_optgroup(L("Start G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("start_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2335,11 +2325,9 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("End G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("end_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2347,11 +2335,9 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Before layer change G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("before_layer_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2359,11 +2345,9 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("After layer change G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("layer_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2371,11 +2355,9 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Tool change G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("toolchange_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2383,11 +2365,9 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Between objects G-code (for sequential printing)"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("between_objects_gcode");
option.opt.full_width = true;
option.opt.is_code = true;
@ -2395,33 +2375,27 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Color Change G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("color_change_gcode");
option.opt.is_code = true;
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Pause Print G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("pause_print_gcode");
option.opt.is_code = true;
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Template Custom G-code"), 0);
#if ENABLE_VALIDATE_CUSTOM_GCODE
optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) {
validate_custom_gcode_cb(this, optgroup, opt_key, value);
};
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
option = optgroup->get_option("template_custom_gcode");
option.opt.is_code = true;
option.opt.height = gcode_field_height;//150;
@ -3904,7 +3878,6 @@ void TabPrinter::apply_extruder_cnt_from_cache()
}
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
bool Tab::validate_custom_gcodes()
{
if (m_type != Preset::TYPE_FILAMENT &&
@ -3930,7 +3903,6 @@ bool Tab::validate_custom_gcodes()
}
return valid;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
void TabPrinter::update_machine_limits_description(const MachineLimitsUsage usage)
{
@ -4157,7 +4129,6 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la
return optgroup;
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
const ConfigOptionsGroupShp Page::get_optgroup(const wxString& title) const
{
for (ConfigOptionsGroupShp optgroup : m_optgroups) {
@ -4167,7 +4138,6 @@ const ConfigOptionsGroupShp Page::get_optgroup(const wxString& title) const
return nullptr;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
void TabSLAMaterial::build()
{

View File

@ -79,9 +79,7 @@ public:
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1);
#if ENABLE_VALIDATE_CUSTOM_GCODE
const ConfigOptionsGroupShp get_optgroup(const wxString& title) const;
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
bool set_item_colour(const wxColour *clr) {
if (m_item_color != clr) {
@ -357,11 +355,9 @@ public:
const std::map<wxString, std::string>& get_category_icon_map() { return m_category_icon; }
#if ENABLE_VALIDATE_CUSTOM_GCODE
static bool validate_custom_gcode(const wxString& title, const std::string& gcode);
bool validate_custom_gcodes();
bool validate_custom_gcodes_was_shown { false };
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
bool validate_custom_gcodes_was_shown{ false };
protected:
void create_line_with_widget(ConfigOptionsGroup* optgroup, const std::string& opt_key, const wxString& path, widget_t widget);