Tech ENABLE_GCODE_LINES_ID_IN_H_SLIDER set as default

This commit is contained in:
enricoturri1966 2021-07-22 08:35:21 +02:00
parent 232309a879
commit b80fb40fcd
12 changed files with 2 additions and 121 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");

View File

@ -361,11 +361,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())
@ -443,9 +439,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
// 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);
@ -464,26 +458,20 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
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
}
}
@ -518,11 +506,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
}
#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 +530,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];
@ -566,9 +548,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
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),
@ -577,9 +557,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
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
@ -593,9 +571,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,9 +596,7 @@ 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
}
}
}
@ -632,9 +606,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
}
}
}
#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 +621,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 +630,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 +647,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 +666,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 +676,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' +
@ -1214,12 +1171,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;
@ -1349,11 +1304,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 +1451,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;
@ -3064,13 +3013,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,

View File

@ -210,7 +210,6 @@ namespace Slic3r {
float time() const;
};
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
struct MoveVertex
{
unsigned int gcode_id{ 0 };
@ -230,7 +229,6 @@ namespace Slic3r {
float volumetric_rate() const { return feedrate * mm3_per_mm; }
};
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
private:
struct TimeMachine
@ -326,12 +324,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 +352,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
@ -518,12 +491,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

@ -41,8 +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

View File

@ -739,16 +739,11 @@ wxString Control::get_label(int tick, LabelType label_type/* = ltHeightWithLayer
return size_t(it - m_layers_values.begin());
};
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (m_draw_mode == dmSequentialGCodeView) {
return (Slic3r::GUI::get_app_config()->get("seq_top_gcode_indices") == "1") ?
wxString::Format("%lu", static_cast<unsigned long>(m_alternate_values[value])) :
wxString::Format("%lu", static_cast<unsigned long>(m_values[value]));
}
#else
if (m_draw_mode == dmSequentialGCodeView)
return wxString::Format("%lu", static_cast<unsigned long>(m_values[value]));
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
else {
if (label_type == ltEstimatedTime) {
if (m_is_wipe_tower) {

View File

@ -223,9 +223,7 @@ public:
void SetKoefForLabels(const double koef) { m_label_koef = koef; }
void SetSliderValues(const std::vector<double>& values);
void ChangeOneLayerLock();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
void SetSliderAlternateValues(const std::vector<double>& values) { m_alternate_values = values; }
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
Info GetTicksValues() const;
void SetTicksValues(const Info &custom_gcode_per_print_z);
@ -409,9 +407,7 @@ private:
std::vector<std::string> m_extruder_colors;
std::string m_print_obj_idxs;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
std::vector<double> m_alternate_values;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// control's view variables
wxCoord SLIDER_MARGIN; // margin around slider

View File

@ -1443,12 +1443,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
m_max_bounding_box = m_paths_bounding_box;
m_max_bounding_box.merge(m_paths_bounding_box.max + m_sequential_view.marker.get_bounding_box().size()[2] * Vec3d::UnitZ());
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_sequential_view.gcode_ids.clear();
for (const GCodeProcessor::MoveVertex& move : gcode_result.moves) {
m_sequential_view.gcode_ids.push_back(move.gcode_id);
}
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
std::vector<MultiVertexBuffer> vertices(m_buffers.size());
std::vector<MultiIndexBuffer> indices(m_buffers.size());

View File

@ -574,9 +574,7 @@ public:
#if ENABLE_GCODE_WINDOW
GCodeWindow gcode_window;
#endif // ENABLE_GCODE_WINDOW
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
std::vector<unsigned int> gcode_ids;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
#if ENABLE_GCODE_WINDOW
void render(float legend_height) const;

View File

@ -1908,11 +1908,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
PreferencesDialog dlg(mainframe);
dlg.ShowModal();
app_layout_changed = dlg.settings_layout_changed();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
#else
if (dlg.seq_top_layer_only_changed())
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
this->plater_->refresh_print();
if (dlg.recreate_GUI()) {

View File

@ -834,25 +834,17 @@ void Preview::update_moves_slider()
return;
std::vector<double> values(view.endpoints.last - view.endpoints.first + 1);
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
std::vector<double> alternate_values(view.endpoints.last - view.endpoints.first + 1);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
unsigned int count = 0;
for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i) {
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
values[count] = static_cast<double>(i + 1);
if (view.gcode_ids[i] > 0)
alternate_values[count] = static_cast<double>(view.gcode_ids[i]);
++count;
#else
values[count++] = static_cast<double>(i + 1);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
}
m_moves_slider->SetSliderValues(values);
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_moves_slider->SetSliderAlternateValues(alternate_values);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_moves_slider->SetMaxValue(view.endpoints.last - view.endpoints.first);
m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first, view.current.last - view.endpoints.first);
}

View File

@ -292,7 +292,6 @@ void PreferencesDialog::build()
option = Option(def, "seq_top_layer_only");
m_optgroup_gui->append_single_option_line(option);
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
def.label = L("Sequential slider shows gcode line numbers");
def.type = coBool;
def.tooltip = L("If enabled, the sequential slider, in preview, shows the gcode lines numbers."
@ -300,7 +299,6 @@ void PreferencesDialog::build()
def.set_default_value(new ConfigOptionBool{ app_config->get("seq_top_gcode_indices") == "1" });
option = Option(def, "seq_top_gcode_indices");
m_optgroup_gui->append_single_option_line(option);
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
if (is_editor) {
def.label = L("Show sidebar collapse/expand button");
@ -438,11 +436,9 @@ void PreferencesDialog::accept(wxEvent&)
if (auto it = m_values.find("seq_top_layer_only"); it != m_values.end())
m_seq_top_layer_only_changed = app_config->get("seq_top_layer_only") != it->second;
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_seq_top_gcode_indices_changed = false;
if (auto it = m_values.find("seq_top_gcode_indices"); it != m_values.end())
m_seq_top_gcode_indices_changed = app_config->get("seq_top_gcode_indices") != it->second;
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
m_settings_layout_changed = false;
for (const std::string& key : { "old_settings_layout_mode",

View File

@ -29,9 +29,7 @@ class PreferencesDialog : public DPIDialog
bool isOSX {false};
bool m_settings_layout_changed {false};
bool m_seq_top_layer_only_changed{ false };
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
bool m_seq_top_gcode_indices_changed{ false };
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
bool m_recreate_GUI{false};
public:
@ -40,12 +38,10 @@ public:
bool settings_layout_changed() const { return m_settings_layout_changed; }
bool seq_top_layer_only_changed() const { return m_seq_top_layer_only_changed; }
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
bool seq_seq_top_gcode_indices_changed() const { return m_seq_top_gcode_indices_changed; }
#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
bool recreate_GUI() const { return m_recreate_GUI; }
void build();
void accept(wxEvent&);
void build();
void accept(wxEvent&);
protected:
void on_dpi_changed(const wxRect &suggested_rect) override;