GCodeViewer -> Refactoring and code cleanup

This commit is contained in:
enricoturri1966 2020-04-23 15:12:40 +02:00
parent 6e2307f56d
commit 66964c44c1
8 changed files with 26 additions and 77 deletions

View File

@ -2328,16 +2328,6 @@ void GCode::process_layer(
else if (gcode.find(GCodeAnalyzer::Custom_Code_Tag) != gcode.npos)
gcode += "\n; " + GCodeAnalyzer::End_Pause_Print_Or_Custom_Code_Tag + "\n";
#if ENABLE_GCODE_VIEWER
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
// add tag for processor
if (gcode.find(GCodeProcessor::Pause_Print_Tag) != gcode.npos)
gcode += "\n; " + GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag + "\n";
else if (gcode.find(GCodeProcessor::Custom_Code_Tag) != gcode.npos)
gcode += "\n; " + GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag + "\n";
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
#ifdef HAS_PRESSURE_EQUALIZER
// Apply pressure equalization if enabled;
// printf("G-code before filter:\n%s\n", gcode.c_str());

View File

@ -24,9 +24,6 @@ const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "_PROCESSOR_MM3_PER_MM:";
const std::string GCodeProcessor::Color_Change_Tag = "_PROCESSOR_COLOR_CHANGE";
const std::string GCodeProcessor::Pause_Print_Tag = "_PROCESSOR_PAUSE_PRINT";
const std::string GCodeProcessor::Custom_Code_Tag = "_PROCESSOR_CUSTOM_CODE";
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
const std::string GCodeProcessor::End_Pause_Print_Or_Custom_Code_Tag = "_PROCESSOR_END_PAUSE_PRINT_OR_CUSTOM_CODE";
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
void GCodeProcessor::CachedPosition::reset()
{
@ -248,9 +245,7 @@ void GCodeProcessor::process_tags(const std::string& comment)
if (m_extruder_id == extruder_id)
{
m_cp_color.current = m_extruders_color[extruder_id];
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
store_move_vertex(EMoveType::Color_change);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
}
}
catch (...)
@ -265,11 +260,7 @@ void GCodeProcessor::process_tags(const std::string& comment)
pos = comment.find(Pause_Print_Tag);
if (pos != comment.npos)
{
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
store_move_vertex(EMoveType::Pause_Print);
#else
m_cp_color.current = UCHAR_MAX;
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
return;
}
@ -277,25 +268,9 @@ void GCodeProcessor::process_tags(const std::string& comment)
pos = comment.find(Custom_Code_Tag);
if (pos != comment.npos)
{
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
store_move_vertex(EMoveType::Custom_GCode);
#else
m_cp_color.current = UCHAR_MAX;
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
return;
}
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
// end pause print or custom code tag
pos = comment.find(End_Pause_Print_Or_Custom_Code_Tag);
if (pos != comment.npos)
{
if (m_cp_color.current == UCHAR_MAX)
m_cp_color.current = m_extruders_color[m_extruder_id];
return;
}
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
}
void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
@ -588,10 +563,7 @@ void GCodeProcessor::process_T(const std::string& command)
else
{
m_extruder_id = id;
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
if (m_cp_color.current != UCHAR_MAX)
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
m_cp_color.current = m_extruders_color[id];
m_cp_color.current = m_extruders_color[id];
}
// store tool change move

View File

@ -21,9 +21,6 @@ namespace Slic3r {
static const std::string Color_Change_Tag;
static const std::string Pause_Print_Tag;
static const std::string Custom_Code_Tag;
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
static const std::string End_Pause_Print_Or_Custom_Code_Tag;
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
private:
using AxisCoords = std::array<float, 4>;
@ -64,11 +61,9 @@ namespace Slic3r {
Retract,
Unretract,
Tool_change,
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
Color_change,
Pause_Print,
Custom_GCode,
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
Travel,
Extrude,
Count

View File

@ -400,7 +400,9 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_
// and maybe other problems. We will therefore go through layer_tools and detect and fix this.
// So, if there is a non-object layer starting with different extruder than the last one ended with (or containing more than one extruder),
// we'll mark it with has_wipe tower.
assert(! m_layer_tools.empty() && m_layer_tools.front().has_wipe_tower);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// assert(! m_layer_tools.empty() && m_layer_tools.front().has_wipe_tower);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
if (! m_layer_tools.empty() && m_layer_tools.front().has_wipe_tower) {
for (size_t i = 0; i + 1 < m_layer_tools.size();) {
const LayerTools &lt = m_layer_tools[i];

View File

@ -59,7 +59,6 @@
// Enable G-Code viewer
#define ENABLE_GCODE_VIEWER (1 && ENABLE_2_3_0_ALPHA1)
#define ENABLE_GCODE_VIEWER_DEBUG_OUTPUT (0 && ENABLE_GCODE_VIEWER)
#define ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT (1 && ENABLE_GCODE_VIEWER)
#endif // _prusaslicer_technologies_h_

View File

@ -254,11 +254,9 @@ bool GCodeViewer::init_shaders()
switch (buffer_type(i))
{
case GCodeProcessor::EMoveType::Tool_change: { vertex_shader = "toolchanges.vs"; fragment_shader = "toolchanges.fs"; break; }
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Color_change: { vertex_shader = "colorchanges.vs"; fragment_shader = "colorchanges.fs"; break; }
case GCodeProcessor::EMoveType::Pause_Print: { vertex_shader = "pauses.vs"; fragment_shader = "pauses.fs"; break; }
case GCodeProcessor::EMoveType::Custom_GCode: { vertex_shader = "customs.vs"; fragment_shader = "customs.fs"; break; }
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Retract: { vertex_shader = "retractions.vs"; fragment_shader = "retractions.fs"; break; }
case GCodeProcessor::EMoveType::Unretract: { vertex_shader = "unretractions.vs"; fragment_shader = "unretractions.fs"; break; }
case GCodeProcessor::EMoveType::Extrude: { vertex_shader = "extrusions.vs"; fragment_shader = "extrusions.fs"; break; }
@ -320,11 +318,9 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
switch (curr.type)
{
case GCodeProcessor::EMoveType::Tool_change:
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Color_change:
case GCodeProcessor::EMoveType::Pause_Print:
case GCodeProcessor::EMoveType::Custom_GCode:
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Retract:
case GCodeProcessor::EMoveType::Unretract:
{
@ -523,7 +519,6 @@ void GCodeViewer::render_toolpaths() const
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
break;
}
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Color_change:
{
std::array<float, 3> color = { 1.0f, 0.0f, 0.0f };
@ -551,7 +546,6 @@ void GCodeViewer::render_toolpaths() const
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
break;
}
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
case GCodeProcessor::EMoveType::Retract:
{
std::array<float, 3> color = { 1.0f, 0.0f, 1.0f };
@ -746,9 +740,6 @@ void GCodeViewer::render_legend() const
const int items_cnt = static_cast<int>(cp_values.size());
if (items_cnt == 0) { // There is no one color change, but there are some pause print or custom Gcode
add_item(m_tool_colors.front(), I18N::translate_utf8(L("Default print color")));
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
add_item(m_tool_colors.back(), I18N::translate_utf8(L("Pause print or custom G-code")));
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
}
else {
for (int i = items_cnt; i >= 0; --i) {

View File

@ -229,12 +229,12 @@ Preview::Preview(
, m_checkbox_travel(nullptr)
, m_checkbox_retractions(nullptr)
, m_checkbox_unretractions(nullptr)
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
, m_checkbox_tool_changes(nullptr)
, m_checkbox_color_changes(nullptr)
, m_checkbox_pause_prints(nullptr)
, m_checkbox_custom_gcodes(nullptr)
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
, m_checkbox_shells(nullptr)
, m_checkbox_legend(nullptr)
, m_config(config)
@ -336,12 +336,12 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
m_checkbox_travel = new wxCheckBox(this, wxID_ANY, _(L("Travel")));
m_checkbox_retractions = new wxCheckBox(this, wxID_ANY, _(L("Retractions")));
m_checkbox_unretractions = new wxCheckBox(this, wxID_ANY, _(L("Unretractions")));
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
m_checkbox_tool_changes = new wxCheckBox(this, wxID_ANY, _(L("Tool changes")));
m_checkbox_color_changes = new wxCheckBox(this, wxID_ANY, _(L("Color changes")));
m_checkbox_pause_prints = new wxCheckBox(this, wxID_ANY, _(L("Pause prints")));
m_checkbox_custom_gcodes = new wxCheckBox(this, wxID_ANY, _(L("Custom GCodes")));
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
m_checkbox_shells = new wxCheckBox(this, wxID_ANY, _(L("Shells")));
m_checkbox_legend = new wxCheckBox(this, wxID_ANY, _(L("Legend")));
m_checkbox_legend->SetValue(true);
@ -363,7 +363,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_unretractions, 0, wxEXPAND | wxALL, 5);
bottom_sizer->AddSpacer(10);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
bottom_sizer->Add(m_checkbox_tool_changes, 0, wxEXPAND | wxALL, 5);
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_color_changes, 0, wxEXPAND | wxALL, 5);
@ -372,7 +372,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
bottom_sizer->AddSpacer(10);
bottom_sizer->Add(m_checkbox_custom_gcodes, 0, wxEXPAND | wxALL, 5);
bottom_sizer->AddSpacer(10);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
bottom_sizer->Add(m_checkbox_shells, 0, wxEXPAND | wxALL, 5);
bottom_sizer->AddSpacer(20);
bottom_sizer->Add(m_checkbox_legend, 0, wxEXPAND | wxALL, 5);
@ -555,12 +555,12 @@ void Preview::bind_event_handlers()
m_checkbox_travel->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this);
m_checkbox_retractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this);
m_checkbox_unretractions->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
m_checkbox_tool_changes->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_tool_changes, this);
m_checkbox_color_changes->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_color_changes, this);
m_checkbox_pause_prints->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_pause_prints, this);
m_checkbox_custom_gcodes->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_custom_gcodes, this);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
m_checkbox_shells->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this);
m_checkbox_legend->Bind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this);
}
@ -573,12 +573,12 @@ void Preview::unbind_event_handlers()
m_checkbox_travel->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_travel, this);
m_checkbox_retractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_retractions, this);
m_checkbox_unretractions->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_unretractions, this);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
m_checkbox_tool_changes->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_tool_changes, this);
m_checkbox_color_changes->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_color_changes, this);
m_checkbox_pause_prints->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_pause_prints, this);
m_checkbox_custom_gcodes->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_custom_gcodes, this);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
m_checkbox_shells->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_shells, this);
m_checkbox_legend->Unbind(wxEVT_CHECKBOX, &Preview::on_checkbox_legend, this);
}
@ -591,12 +591,12 @@ void Preview::show_hide_ui_elements(const std::string& what)
m_checkbox_travel->Enable(enable);
m_checkbox_retractions->Enable(enable);
m_checkbox_unretractions->Enable(enable);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
m_checkbox_tool_changes->Enable(enable);
m_checkbox_color_changes->Enable(enable);
m_checkbox_pause_prints->Enable(enable);
m_checkbox_custom_gcodes->Enable(enable);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
m_checkbox_shells->Enable(enable);
m_checkbox_legend->Enable(enable);
@ -610,12 +610,12 @@ void Preview::show_hide_ui_elements(const std::string& what)
m_checkbox_travel->Show(visible);
m_checkbox_retractions->Show(visible);
m_checkbox_unretractions->Show(visible);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
m_checkbox_tool_changes->Show(visible);
m_checkbox_color_changes->Show(visible);
m_checkbox_pause_prints->Show(visible);
m_checkbox_custom_gcodes->Show(visible);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
m_checkbox_shells->Show(visible);
m_checkbox_legend->Show(visible);
m_label_view_type->Show(visible);
@ -709,7 +709,7 @@ void Preview::on_checkbox_unretractions(wxCommandEvent& evt)
refresh_print();
}
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
void Preview::on_checkbox_tool_changes(wxCommandEvent& evt)
{
m_canvas->set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Tool_change, m_checkbox_tool_changes->IsChecked());
@ -733,7 +733,7 @@ void Preview::on_checkbox_custom_gcodes(wxCommandEvent& evt)
m_canvas->set_toolpath_move_type_visible(GCodeProcessor::EMoveType::Custom_GCode, m_checkbox_custom_gcodes->IsChecked());
refresh_print();
}
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
void Preview::on_checkbox_shells(wxCommandEvent& evt)
{
@ -1053,9 +1053,9 @@ void Preview::load_print_as_fff(bool keep_z_range)
#endif // ENABLE_GCODE_VIEWER
{
colors = wxGetApp().plater()->get_colors_for_color_print();
#if !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if !ENABLE_GCODE_VIEWER
colors.push_back("#808080"); // gray color for pause print or custom G-code
#endif // !ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // !ENABLE_GCODE_VIEWER
if (!gcode_preview_data_valid)
color_print_values = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;

View File

@ -98,12 +98,12 @@ class Preview : public wxPanel
wxCheckBox* m_checkbox_travel;
wxCheckBox* m_checkbox_retractions;
wxCheckBox* m_checkbox_unretractions;
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
wxCheckBox* m_checkbox_tool_changes;
wxCheckBox* m_checkbox_color_changes;
wxCheckBox* m_checkbox_pause_prints;
wxCheckBox* m_checkbox_custom_gcodes;
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
wxCheckBox* m_checkbox_shells;
wxCheckBox* m_checkbox_legend;
@ -195,12 +195,12 @@ private:
void on_checkbox_travel(wxCommandEvent& evt);
void on_checkbox_retractions(wxCommandEvent& evt);
void on_checkbox_unretractions(wxCommandEvent& evt);
#if ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#if ENABLE_GCODE_VIEWER
void on_checkbox_tool_changes(wxCommandEvent& evt);
void on_checkbox_color_changes(wxCommandEvent& evt);
void on_checkbox_pause_prints(wxCommandEvent& evt);
void on_checkbox_custom_gcodes(wxCommandEvent& evt);
#endif // ENABLE_GCODE_VIEWER_SEPARATE_PAUSE_PRINT
#endif // ENABLE_GCODE_VIEWER
void on_checkbox_shells(wxCommandEvent& evt);
void on_checkbox_legend(wxCommandEvent& evt);