Improved handling of loading invalid .gcode files

This commit is contained in:
enricoturri1966 2020-11-02 11:59:37 +01:00
parent 38e883a66e
commit 516db43b20
3 changed files with 17 additions and 4 deletions

View file

@ -302,6 +302,9 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print&
reset(); reset();
load_toolpaths(gcode_result); load_toolpaths(gcode_result);
if (m_layers_zs.empty())
return;
if (wxGetApp().is_editor()) if (wxGetApp().is_editor())
load_shells(print, initialized); load_shells(print, initialized);
else { else {
@ -1477,6 +1480,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
} }
} }
if (progress_dialog != nullptr) {
progress_dialog->Update(100, "");
progress_dialog->Fit();
}
log_memory_usage("Loaded G-code generated indices buffers, ", vertices, indices); log_memory_usage("Loaded G-code generated indices buffers, ", vertices, indices);
// toolpaths data -> send indices data to gpu // toolpaths data -> send indices data to gpu
@ -1550,7 +1558,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
} }
// set layers z range // set layers z range
m_layers_z_range = { m_layers_zs.front(), m_layers_zs.back() }; if (!m_layers_zs.empty())
m_layers_z_range = { m_layers_zs.front(), m_layers_zs.back() };
// roles -> remove duplicates // roles -> remove duplicates
std::sort(m_roles.begin(), m_roles.end()); std::sort(m_roles.begin(), m_roles.end());

View file

@ -1256,7 +1256,7 @@ void Preview::load_print_as_fff(bool keep_z_range)
// It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature. // It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
// Color by feature if it is a single extruder print. // Color by feature if it is a single extruder print.
unsigned int number_extruders = (unsigned int)print->extruders().size(); unsigned int number_extruders = (unsigned int)print->extruders().size();
int tool_idx = m_choice_view_type->FindString(_(L("Tool"))); int tool_idx = m_choice_view_type->FindString(_L("Tool"));
int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type
m_choice_view_type->SetSelection(type); m_choice_view_type->SetSelection(type);
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER

View file

@ -1407,8 +1407,8 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &fi
return false; return false;
} }
else if (paths.size() == 1) { else if (paths.size() == 1) {
plater->load_gcode(from_path(paths.front())); plater->load_gcode(from_path(paths.front()));
return true; return true;
} }
return false; return false;
} }
@ -4728,6 +4728,10 @@ void Plater::load_gcode(const wxString& filename)
// show results // show results
p->preview->reload_print(false); p->preview->reload_print(false);
p->preview->get_canvas3d()->zoom_to_gcode(); p->preview->get_canvas3d()->zoom_to_gcode();
if (p->preview->get_canvas3d()->get_gcode_layers_zs().empty())
wxMessageDialog(this, _L("The selected file") + ":\n" + filename + "\n" + _L("does not contain valid gcode."),
wxString(GCODEVIEWER_APP_NAME) + " - " + _L("Error while loading .gcode file"), wxCLOSE | wxICON_WARNING | wxCENTRE).ShowModal();
} }
void Plater::refresh_print() void Plater::refresh_print()