Fixed conflicts after merge with master

This commit is contained in:
enricoturri1966 2021-07-22 11:46:00 +02:00
commit 5c6810d0bc
38 changed files with 31 additions and 782 deletions

View file

@ -155,10 +155,8 @@ void AppConfig::set_defaults()
if (get("seq_top_layer_only").empty())
set("seq_top_layer_only", "1");
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (get("seq_top_gcode_indices").empty())
set("seq_top_gcode_indices", "1");
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (get("use_perspective_camera").empty())
set("use_perspective_camera", "1");
@ -544,6 +542,8 @@ void AppConfig::update_config_dir(const std::string &dir)
void AppConfig::update_skein_dir(const std::string &dir)
{
if (dir == sys_shapes_dir() || dir == custom_shapes_dir())
return; // do not save "shapes gallery" directory
this->set("recent", "skein_directory", dir);
}
/*

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();
@ -794,16 +782,11 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re
m_processor.process_file(path_tmp, true, [print]() { print->throw_if_canceled(); });
// DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics);
DoExport::update_print_estimated_stats(m_processor, m_writer.extruders(), print->m_print_statistics);
#if ENABLE_GCODE_WINDOW
if (result != nullptr) {
*result = std::move(m_processor.extract_result());
// set the filename to the correct value
result->filename = path;
}
#else
if (result != nullptr)
*result = std::move(m_processor.extract_result());
#endif // ENABLE_GCODE_WINDOW
BOOST_LOG_TRIVIAL(debug) << "Finished processing gcode, " << log_memory_info();
if (rename_file(path_tmp, path))
@ -1168,11 +1151,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 +1258,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 +1419,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 +1446,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 +1462,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 +1762,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 +1787,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 +1795,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 +1942,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 +2778,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 +2798,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,15 +5,11 @@
#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>
#if ENABLE_GCODE_WINDOW
#include <boost/filesystem/path.hpp>
#endif // ENABLE_GCODE_WINDOW
#include <float.h>
#include <assert.h>
@ -37,7 +33,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 +47,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;
@ -202,9 +182,7 @@ void GCodeProcessor::TimeMachine::reset()
max_travel_acceleration = 0.0f;
extrude_factor_override_percentage = 1.0f;
time = 0.0f;
#if ENABLE_EXTENDED_M73_LINES
stop_times = std::vector<StopTime>();
#endif // ENABLE_EXTENDED_M73_LINES
curr.reset();
prev.reset();
gcode_time.reset();
@ -332,13 +310,11 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks)
layers_time[block.layer_id - 1] += block_time;
}
g1_times_cache.push_back({ block.g1_line_id, time });
#if ENABLE_EXTENDED_M73_LINES
// update times for remaining time to printer stop placeholders
auto it_stop_time = std::lower_bound(stop_times.begin(), stop_times.end(), block.g1_line_id,
[](const StopTime& t, unsigned int value) { return t.g1_line_id < value; });
if (it_stop_time != stop_times.end() && it_stop_time->g1_line_id == block.g1_line_id)
it_stop_time->elapsed_time = time;
#endif // ENABLE_EXTENDED_M73_LINES
}
if (keep_last_n_blocks)
@ -361,11 +337,7 @@ void GCodeProcessor::TimeProcessor::reset()
machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].enabled = true;
}
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, std::vector<MoveVertex>& moves)
#else
void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
{
boost::nowide::ifstream in(filename);
if (!in.good())
@ -381,16 +353,12 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
return int(::roundf(time_in_seconds / 60.0f));
};
#if ENABLE_EXTENDED_M73_LINES
auto time_in_last_minute = [](float time_in_seconds) {
assert(time_in_seconds <= 60.0f);
return time_in_seconds / 60.0f;
};
auto format_line_M73_main = [](const std::string& mask, int percent, int time) {
#else
auto format_line_M73 = [](const std::string& mask, int percent, int time) {
#endif // ENABLE_EXTENDED_M73_LINES
char line_M73[64];
sprintf(line_M73, mask.c_str(),
std::to_string(percent).c_str(),
@ -398,7 +366,6 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
return std::string(line_M73);
};
#if ENABLE_EXTENDED_M73_LINES
auto format_line_M73_stop_int = [](const std::string& mask, int time) {
char line_M73[64];
sprintf(line_M73, mask.c_str(), std::to_string(time).c_str());
@ -414,13 +381,11 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
sprintf(line_M73, mask.c_str(), format_time_float(time).c_str());
return std::string(line_M73);
};
#endif // ENABLE_EXTENDED_M73_LINES
GCodeReader parser;
std::string gcode_line;
size_t g1_lines_counter = 0;
// keeps track of last exported pair <percent, remaining time>
#if ENABLE_EXTENDED_M73_LINES
std::array<std::pair<int, int>, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> last_exported_main;
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
last_exported_main[i] = { 0, time_in_minutes(machines[i].time) };
@ -431,27 +396,18 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
last_exported_stop[i] = time_in_minutes(machines[i].time);
}
#else
std::array<std::pair<int, int>, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> last_exported;
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
last_exported[i] = { 0, time_in_minutes(machines[i].time) };
}
#endif // ENABLE_EXTENDED_M73_LINES
// buffer line to export only when greater than 64K to reduce writing calls
std::string export_line;
// replace placeholder lines with the proper final value
auto process_placeholders = [&](const std::string& gcode_line) {
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int extra_lines_count = 0;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// remove trailing '\n'
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 &&
@ -459,49 +415,23 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i];
if (machine.enabled) {
#if ENABLE_EXTENDED_M73_LINES
// export pair <percent, remaining time>
ret += format_line_M73_main(machine.line_m73_main_mask.c_str(),
(line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? 0 : 100,
(line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? time_in_minutes(machine.time) : 0);
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++extra_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// export remaining time to next printer stop
if (line == reserved_tag(ETags::First_Line_M73_Placeholder) && !machine.stop_times.empty()) {
int to_export_stop = time_in_minutes(machine.stop_times.front().elapsed_time);
ret += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop);
last_exported_stop[i] = to_export_stop;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++extra_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}
#else
ret += format_line_M73(machine.line_m73_mask.c_str(),
(line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? 0 : 100,
(line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? time_in_minutes(machine.time) : 0);
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++extra_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#endif // ENABLE_EXTENDED_M73_LINES
}
}
}
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);
@ -514,15 +444,9 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
}
}
}
#if ENABLE_VALIDATE_CUSTOM_GCODE
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
return std::tuple(!ret.empty(), ret.empty() ? gcode_line : ret, (extra_lines_count == 0) ? extra_lines_count : extra_lines_count - 1);
#else
return std::make_pair(!ret.empty(), ret.empty() ? gcode_line : ret);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
};
// check for temporary lines
@ -546,9 +470,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
// add lines M73 to exported gcode
auto process_line_G1 = [&]() {
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int exported_lines_count = 0;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (export_remaining_time_enabled) {
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i];
@ -559,30 +481,14 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
while (it != machine.g1_times_cache.end() && it->id < g1_lines_counter)
++it;
if (it != machine.g1_times_cache.end() && it->id == g1_lines_counter) {
#if ENABLE_EXTENDED_M73_LINES
std::pair<int, int> to_export_main = { int(100.0f * it->elapsed_time / machine.time),
time_in_minutes(machine.time - it->elapsed_time) };
if (last_exported_main[i] != to_export_main) {
export_line += format_line_M73_main(machine.line_m73_main_mask.c_str(),
to_export_main.first, to_export_main.second);
last_exported_main[i] = to_export_main;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++exported_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#else
float elapsed_time = it->elapsed_time;
std::pair<int, int> to_export = { int(100.0f * elapsed_time / machine.time),
time_in_minutes(machine.time - elapsed_time) };
if (last_exported[i] != to_export) {
export_line += format_line_M73(machine.line_m73_mask.c_str(),
to_export.first, to_export.second);
last_exported[i] = to_export;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++exported_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#endif // ENABLE_EXTENDED_M73_LINES
}
#if ENABLE_EXTENDED_M73_LINES
// export remaining time to next printer stop
auto it_stop = std::upper_bound(machine.stop_times.begin(), machine.stop_times.end(), it->elapsed_time,
[](float value, const TimeMachine::StopTime& t) { return value < t.elapsed_time; });
@ -593,9 +499,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
if (last_exported_stop[i] != to_export_stop) {
export_line += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop);
last_exported_stop[i] = to_export_stop;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++exported_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}
}
else {
@ -620,21 +524,16 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
export_line += format_line_M73_stop_float(machine.line_m73_stop_mask.c_str(), time_in_last_minute(it_stop->elapsed_time - it->elapsed_time));
last_exported_stop[i] = to_export_stop;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++exported_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}
}
}
}
#endif // ENABLE_EXTENDED_M73_LINES
}
}
}
}
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
return exported_lines_count;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
};
// helper function to write to disk
@ -649,10 +548,8 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
export_line.clear();
};
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int line_id = 0;
std::vector<std::pair<unsigned int, unsigned int>> offsets;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
while (std::getline(in, gcode_line)) {
if (!in.good()) {
@ -660,19 +557,13 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nError while reading from file.\n"));
}
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++line_id;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
gcode_line += "\n";
// replace placeholder lines
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
auto [processed, result, lines_added_count] = process_placeholders(gcode_line);
if (processed && lines_added_count > 0)
offsets.push_back({ line_id, lines_added_count });
#else
auto [processed, result] = process_placeholders(gcode_line);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
gcode_line = result;
if (!processed) {
// remove temporary lines
@ -683,15 +574,10 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
parser.parse_line(gcode_line,
[&](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
if (line.cmd_is("G1")) {
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int extra_lines_count = process_line_G1();
++g1_lines_counter;
if (extra_lines_count > 0)
offsets.push_back({ line_id, extra_lines_count });
#else
process_line_G1();
++g1_lines_counter;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}
});
}
@ -707,7 +593,6 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
fclose(out);
in.close();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// updates moves' gcode ids which have been modified by the insertion of the M73 lines
unsigned int curr_offset_id = 0;
unsigned int total_offset = 0;
@ -718,7 +603,6 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
}
move.gcode_id += total_offset;
}
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (rename_file(out_path, filename))
throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + filename + '\n' +
@ -827,7 +711,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;
@ -879,20 +762,14 @@ bool GCodeProcessor::contains_reserved_tags(const std::string& gcode, unsigned i
return ret;
}
#endif // ENABLE_VALIDATE_CUSTOM_GCODE
GCodeProcessor::GCodeProcessor()
{
reset();
#if ENABLE_EXTENDED_M73_LINES
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].line_m73_main_mask = "M73 P%s R%s\n";
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].line_m73_stop_mask = "M73 C%s\n";
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].line_m73_main_mask = "M73 Q%s S%s\n";
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].line_m73_stop_mask = "M73 D%s\n";
#else
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].line_m73_mask = "M73 P%s R%s\n";
m_time_processor.machines[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].line_m73_mask = "M73 Q%s S%s\n";
#endif // ENABLE_EXTENDED_M73_LINES
}
void GCodeProcessor::apply_config(const PrintConfig& config)
@ -1214,12 +1091,10 @@ void GCodeProcessor::reset()
m_cached_position.reset();
m_wiping = false;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_line_id = 0;
#if ENABLE_SEAMS_VISUALIZATION
m_last_line_id = 0;
#endif // ENABLE_SEAMS_VISUALIZATION
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_feedrate = 0.0f;
m_width = 0.0f;
m_height = 0.0f;
@ -1284,11 +1159,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
}
});
@ -1308,9 +1179,7 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr
}
// process gcode
#if ENABLE_GCODE_WINDOW
m_result.filename = filename;
#endif // ENABLE_GCODE_WINDOW
m_result.id = ++s_result_id;
// 1st move must be a dummy move
m_result.moves.emplace_back(MoveVertex());
@ -1349,11 +1218,7 @@ void GCodeProcessor::process_file(const std::string& filename, bool apply_postpr
// post-process to add M73 lines into the gcode
if (apply_postprocess)
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_time_processor.post_process(filename, m_result.moves);
#else
m_time_processor.post_process(filename);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
std::cout << "\n";
@ -1500,9 +1365,7 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line)
{
/* std::cout << line.raw() << std::endl; */
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
++m_line_id;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// update start position
m_start_position = m_end_position;
@ -1627,7 +1490,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())));
@ -1652,28 +1514,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))
@ -1686,23 +1528,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;
@ -1750,53 +1577,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
@ -3064,13 +2844,11 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
#endif // ENABLE_SEAMS_VISUALIZATION
MoveVertex vertex = {
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#if ENABLE_SEAMS_VISUALIZATION
m_last_line_id,
#else
(type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ? m_line_id + 1 : m_line_id,
#endif // ENABLE_SEAMS_VISUALIZATION
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
type,
m_extrusion_role,
m_extruder_id,
@ -3091,7 +2869,6 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
};
m_result.moves.emplace_back(vertex);
#if ENABLE_EXTENDED_M73_LINES
// stores stop time placeholders for later use
if (type == EMoveType::Color_change || type == EMoveType::Pause_Print) {
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
@ -3102,7 +2879,6 @@ void GCodeProcessor::store_move_vertex(EMoveType type)
machine.stop_times.push_back({ m_g1_line_id, 0.0f });
}
}
#endif // ENABLE_EXTENDED_M73_LINES
}
void GCodeProcessor::set_extrusion_role(ExtrusionRole role)

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;
@ -210,7 +194,6 @@ namespace Slic3r {
float time() const;
};
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
struct MoveVertex
{
unsigned int gcode_id{ 0 };
@ -230,7 +213,6 @@ namespace Slic3r {
float volumetric_rate() const { return feedrate * mm3_per_mm; }
};
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
private:
struct TimeMachine
@ -269,7 +251,6 @@ namespace Slic3r {
float max_travel_acceleration; // mm/s^2
float extrude_factor_override_percentage;
float time; // s
#if ENABLE_EXTENDED_M73_LINES
struct StopTime
{
unsigned int g1_line_id;
@ -278,9 +259,6 @@ namespace Slic3r {
std::vector<StopTime> stop_times;
std::string line_m73_main_mask;
std::string line_m73_stop_mask;
#else
std::string line_m73_mask;
#endif // ENABLE_EXTENDED_M73_LINES
State curr;
State prev;
CustomGCodeTime gcode_time;
@ -326,12 +304,8 @@ namespace Slic3r {
void reset();
// post process the file with the given filename to add remaining time lines M73
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// and updates moves' gcode ids accordingly
void post_process(const std::string& filename, std::vector<MoveVertex>& moves);
#else
void post_process(const std::string& filename);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
};
struct UsedFilaments // filaments per ColorChange
@ -358,27 +332,6 @@ namespace Slic3r {
};
public:
#if !ENABLE_GCODE_LINES_ID_IN_H_SLIDER
struct MoveVertex
{
EMoveType type{ EMoveType::Noop };
ExtrusionRole extrusion_role{ erNone };
unsigned char extruder_id{ 0 };
unsigned char cp_color_id{ 0 };
Vec3f position{ Vec3f::Zero() }; // mm
float delta_extruder{ 0.0f }; // mm
float feedrate{ 0.0f }; // mm/s
float width{ 0.0f }; // mm
float height{ 0.0f }; // mm
float mm3_per_mm{ 0.0f };
float fan_speed{ 0.0f }; // percentage
float temperature{ 0.0f }; // Celsius degrees
float time{ 0.0f }; // s
float volumetric_rate() const { return feedrate * mm3_per_mm; }
};
#endif // !ENABLE_GCODE_LINES_ID_IN_H_SLIDER
struct Result
{
struct SettingsIds
@ -393,9 +346,7 @@ namespace Slic3r {
printer = "";
}
};
#if ENABLE_GCODE_WINDOW
std::string filename;
#endif // ENABLE_GCODE_WINDOW
unsigned int id;
std::vector<MoveVertex> moves;
Pointfs bed_shape;
@ -518,12 +469,10 @@ namespace Slic3r {
CachedPosition m_cached_position;
bool m_wiping;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int m_line_id;
#if ENABLE_SEAMS_VISUALIZATION
unsigned int m_last_line_id;
#endif // ENABLE_SEAMS_VISUALIZATION
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
float m_feedrate; // mm/s
float m_width; // mm
float m_height; // mm

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

@ -918,7 +918,6 @@ BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_
// Calculate 2D convex hull of of a projection of the transformed printable volumes into the XY plane.
// This method is cheap in that it does not make any unnecessary copy of the volume meshes.
// This method is used by the auto arrange function.
#if ENABLE_ALLOW_NEGATIVE_Z
Polygon ModelObject::convex_hull_2d(const Transform3d& trafo_instance) const
{
Points pts;
@ -928,33 +927,6 @@ Polygon ModelObject::convex_hull_2d(const Transform3d& trafo_instance) const
}
return Geometry::convex_hull(std::move(pts));
}
#else
Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const
{
Points pts;
for (const ModelVolume *v : this->volumes)
if (v->is_model_part()) {
Transform3d trafo = trafo_instance * v->get_matrix();
const indexed_triangle_set &its = v->mesh().its;
if (its.vertices.empty()) {
// Using the STL faces.
const stl_file& stl = v->mesh().stl;
for (const stl_facet &facet : stl.facet_start)
for (size_t j = 0; j < 3; ++ j) {
Vec3d p = trafo * facet.vertex[j].cast<double>();
pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y())));
}
} else {
// Using the shared vertices should be a bit quicker than using the STL faces.
for (size_t i = 0; i < its.vertices.size(); ++ i) {
Vec3d p = trafo * its.vertices[i].cast<double>();
pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y())));
}
}
}
return Geometry::convex_hull(std::move(pts));
}
#endif // ENABLE_ALLOW_NEGATIVE_Z
void ModelObject::center_around_origin(bool include_modifiers)
{
@ -969,19 +941,12 @@ void ModelObject::center_around_origin(bool include_modifiers)
this->origin_translation += shift;
}
#if ENABLE_ALLOW_NEGATIVE_Z
void ModelObject::ensure_on_bed(bool allow_negative_z)
{
const double min_z = get_min_z();
if (!allow_negative_z || min_z > SINKING_Z_THRESHOLD)
translate_instances({ 0.0, 0.0, -min_z });
}
#else
void ModelObject::ensure_on_bed()
{
translate_instances({ 0.0, 0.0, -get_min_z() });
}
#endif // ENABLE_ALLOW_NEGATIVE_Z
void ModelObject::translate_instances(const Vec3d& vector)
{
@ -1927,20 +1892,10 @@ arrangement::ArrangePolygon ModelInstance::get_arrange_polygon() const
Vec3d rotation = get_rotation();
rotation.z() = 0.;
Transform3d trafo_instance =
#if ENABLE_ALLOW_NEGATIVE_Z
Geometry::assemble_transform(get_offset().z() * Vec3d::UnitZ(), rotation,
get_scaling_factor(), get_mirror());
#else
Geometry::assemble_transform(Vec3d::Zero(), rotation,
get_scaling_factor(), get_mirror());
#endif // ENABLE_ALLOW_NEGATIVE_Z
Geometry::assemble_transform(get_offset().z() * Vec3d::UnitZ(), rotation, get_scaling_factor(), get_mirror());
Polygon p = get_object()->convex_hull_2d(trafo_instance);
#if !ENABLE_ALLOW_NEGATIVE_Z
assert(!p.points.empty());
#endif // !ENABLE_ALLOW_NEGATIVE_Z
// if (!p.points.empty()) {
// Polygons pp{p};
// pp = p.simplify(scaled<double>(SIMPLIFY_TOLERANCE_MM));

View file

@ -322,12 +322,8 @@ public:
Polygon convex_hull_2d(const Transform3d &trafo_instance) const;
void center_around_origin(bool include_modifiers = true);
#if ENABLE_ALLOW_NEGATIVE_Z
void ensure_on_bed(bool allow_negative_z = false);
#else
void ensure_on_bed();
#endif // ENABLE_ALLOW_NEGATIVE_Z
void translate_instances(const Vec3d& vector);
void translate_instance(size_t instance_idx, const Vec3d& vector);
void translate(const Vec3d &vector) { this->translate(vector(0), vector(1), vector(2)); }
@ -1176,9 +1172,7 @@ void check_model_ids_validity(const Model &model);
void check_model_ids_equal(const Model &model1, const Model &model2);
#endif /* NDEBUG */
#if ENABLE_ALLOW_NEGATIVE_Z
static const float SINKING_Z_THRESHOLD = -0.001f;
#endif // ENABLE_ALLOW_NEGATIVE_Z
} // namespace Slic3r

View file

@ -373,7 +373,6 @@ bool Print::sequential_print_horizontal_clearance_valid(const Print& print, Poly
// FIXME: Arrangement has different parameters for offsetting (jtMiter, limit 2)
// which causes that the warning will be showed after arrangement with the
// appropriate object distance. Even if I set this to jtMiter the warning still shows up.
#if ENABLE_ALLOW_NEGATIVE_Z
it_convex_hull = map_model_object_to_convex_hull.emplace_hint(it_convex_hull, model_object_id,
offset(print_object->model_object()->convex_hull_2d(
Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())),
@ -381,15 +380,6 @@ bool Print::sequential_print_horizontal_clearance_valid(const Print& print, Poly
// exactly by satisfying the extruder_clearance_radius, this test will not trigger collision.
float(scale_(0.5 * print.config().extruder_clearance_radius.value - EPSILON)),
jtRound, scale_(0.1)).front());
#else
it_convex_hull = map_model_object_to_convex_hull.emplace_hint(it_convex_hull, model_object_id,
offset(print_object->model_object()->convex_hull_2d(
Geometry::assemble_transform(Vec3d::Zero(), model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())),
// Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects
// exactly by satisfying the extruder_clearance_radius, this test will not trigger collision.
float(scale_(0.5 * print.config().extruder_clearance_radius.value - EPSILON)),
jtRound, float(scale_(0.1))).front());
#endif // ENABLE_ALLOW_NEGATIVE_Z
}
// Make a copy, so it may be rotated for instances.
Polygon convex_hull0 = it_convex_hull->second;

View file

@ -1600,15 +1600,9 @@ PrintRegionConfig region_config_from_model_volume(const PrintRegionConfig &defau
void PrintObject::update_slicing_parameters()
{
#if ENABLE_ALLOW_NEGATIVE_Z
if (!m_slicing_params.valid)
m_slicing_params = SlicingParameters::create_from_config(
this->print()->config(), m_config, this->model_object()->bounding_box().max.z(), this->object_extruders());
#else
if (! m_slicing_params.valid)
m_slicing_params = SlicingParameters::create_from_config(
this->print()->config(), m_config, unscale<double>(this->height()), this->object_extruders());
#endif // ENABLE_ALLOW_NEGATIVE_Z
}
SlicingParameters PrintObject::slicing_parameters(const DynamicPrintConfig& full_config, const ModelObject& model_object, float object_max_z)
@ -1670,7 +1664,6 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
updated = true;
}
#if ENABLE_ALLOW_NEGATIVE_Z
// Verify the layer_height_profile.
if (!layer_height_profile.empty() &&
// Must not be of even length.
@ -1678,15 +1671,6 @@ bool PrintObject::update_layer_height_profile(const ModelObject &model_object, c
// Last entry must be at the top of the object.
std::abs(layer_height_profile[layer_height_profile.size() - 2] - slicing_parameters.object_print_z_max) > 1e-3))
layer_height_profile.clear();
#else
// Verify the layer_height_profile.
if (! layer_height_profile.empty() &&
// Must not be of even length.
((layer_height_profile.size() & 1) != 0 ||
// Last entry must be at the top of the object.
std::abs(layer_height_profile[layer_height_profile.size() - 2] - slicing_parameters.object_print_z_height()) > 1e-3))
layer_height_profile.clear();
#endif // ENABLE_ALLOW_NEGATIVE_Z
if (layer_height_profile.empty()) {
//layer_height_profile = layer_height_profile_adaptive(slicing_parameters, model_object.layer_config_ranges, model_object.volumes);

View file

@ -41,14 +41,6 @@
//====================
#define ENABLE_2_4_0_ALPHA0 1
// Enable showing gcode line numbers in preview horizontal slider
#define ENABLE_GCODE_LINES_ID_IN_H_SLIDER (1 && ENABLE_2_4_0_ALPHA0)
// 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)
// 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
@ -61,13 +53,10 @@
#define ENABLE_PROJECT_DIRTY_STATE (1 && ENABLE_2_4_0_ALPHA0)
// Enable project dirty state manager debug window
#define ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW (0 && ENABLE_PROJECT_DIRTY_STATE)
// Enable to push object instances under the bed
#define ENABLE_ALLOW_NEGATIVE_Z (1 && ENABLE_2_4_0_ALPHA0)
#define DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA (1 && ENABLE_ALLOW_NEGATIVE_Z)
// Enable drawing contours, at cut level, for sinking volumes
#define ENABLE_SINKING_CONTOURS (1 && ENABLE_ALLOW_NEGATIVE_Z)
// Enable delayed rendering of transparent volumes
#define ENABLE_DELAYED_TRANSPARENT_VOLUMES_RENDERING (1 && ENABLE_2_4_0_ALPHA0)
// Enable drawing contours, at cut level, for sinking volumes
#define ENABLE_SINKING_CONTOURS (1 && ENABLE_2_4_0_ALPHA0)
#endif // _prusaslicer_technologies_h_

View file

@ -50,6 +50,9 @@ void set_sys_shapes_dir(const std::string &path);
// Return a full path to the system shapes gallery directory.
const std::string& sys_shapes_dir();
// Return a full path to the custom shapes gallery directory.
std::string custom_shapes_dir();
// Set a path with preset files.
void set_data_dir(const std::string &path);
// Return a full path to the GUI resource files.

View file

@ -202,6 +202,11 @@ const std::string& data_dir()
return g_data_dir;
}
std::string custom_shapes_dir()
{
return (boost::filesystem::path(g_data_dir) / "shapes").string();
}
#ifdef _WIN32
// The following helpers are borrowed from the LLVM project https://github.com/llvm
namespace WindowsSupport