ENABLE_GCODE_VIEWER -> More general drag and drop for .gcode files
This commit is contained in:
parent
5a0e048079
commit
4ca026d4b6
3 changed files with 34 additions and 14 deletions
|
@ -1626,7 +1626,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
|
||||||
_write_format(file, "; estimated printing time (normal mode) = %s\n", m_normal_time_estimator.get_time_dhms().c_str());
|
_write_format(file, "; estimated printing time (normal mode) = %s\n", m_normal_time_estimator.get_time_dhms().c_str());
|
||||||
if (m_silent_time_estimator_enabled)
|
if (m_silent_time_estimator_enabled)
|
||||||
_write_format(file, "; estimated printing time (silent mode) = %s\n", m_silent_time_estimator.get_time_dhms().c_str());
|
_write_format(file, "; estimated printing time (silent mode) = %s\n", m_silent_time_estimator.get_time_dhms().c_str());
|
||||||
#endif // !ENABLE_GCODE_VIEWER
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
|
|
||||||
// Append full config.
|
// Append full config.
|
||||||
_write(file, "\n");
|
_write(file, "\n");
|
||||||
|
|
|
@ -1006,7 +1006,9 @@ void MainFrame::init_menubar()
|
||||||
fileMenu->AppendSeparator();
|
fileMenu->AppendSeparator();
|
||||||
append_menu_item(fileMenu, wxID_ANY, _L("&G-code preview"), _L("Switch to G-code preview mode"),
|
append_menu_item(fileMenu, wxID_ANY, _L("&G-code preview"), _L("Switch to G-code preview mode"),
|
||||||
[this](wxCommandEvent&) {
|
[this](wxCommandEvent&) {
|
||||||
if (m_plater->model().objects.empty() || wxMessageDialog((wxWindow*)this, _L("Switching to G-code preview mode will remove all objects, continue?"), wxString(SLIC3R_APP_NAME) + " - " + _L("Switch to G-code preview mode"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE).ShowModal() == wxID_YES)
|
if (m_plater->model().objects.empty() ||
|
||||||
|
wxMessageDialog((wxWindow*)this, _L("Switching to G-code preview mode will remove all objects, continue?"),
|
||||||
|
wxString(SLIC3R_APP_NAME) + " - " + _L("Switch to G-code preview mode"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION | wxCENTRE).ShowModal() == wxID_YES)
|
||||||
set_mode(EMode::GCodeViewer);
|
set_mode(EMode::GCodeViewer);
|
||||||
}, "", nullptr,
|
}, "", nullptr,
|
||||||
[this]() { return m_plater != nullptr && m_plater->printer_technology() != ptSLA; }, this);
|
[this]() { return m_plater != nullptr && m_plater->printer_technology() != ptSLA; }, this);
|
||||||
|
|
|
@ -1362,8 +1362,9 @@ const std::regex PlaterDropTarget::pattern_gcode_drop(".*[.](gcode)", std::regex
|
||||||
bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames)
|
bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames)
|
||||||
{
|
{
|
||||||
std::vector<fs::path> paths;
|
std::vector<fs::path> paths;
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER
|
#if ENABLE_GCODE_VIEWER
|
||||||
if (wxGetApp().mainframe->get_mode() == MainFrame::EMode::GCodeViewer) {
|
// gcode section
|
||||||
for (const auto& filename : filenames) {
|
for (const auto& filename : filenames) {
|
||||||
fs::path path(into_path(filename));
|
fs::path path(into_path(filename));
|
||||||
if (std::regex_match(path.string(), pattern_gcode_drop))
|
if (std::regex_match(path.string(), pattern_gcode_drop))
|
||||||
|
@ -1371,16 +1372,33 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paths.size() > 1) {
|
if (paths.size() > 1) {
|
||||||
wxMessageDialog((wxWindow*)plater, _L("Only one gcode file at a time can be opened."), wxString(SLIC3R_APP_NAME) + " - " + _L("Open G-code file"), wxCLOSE | wxICON_WARNING | wxCENTRE).ShowModal();
|
wxMessageDialog((wxWindow*)plater, _L("You can open only one .gcode file at a time."),
|
||||||
|
wxString(SLIC3R_APP_NAME) + " - " + _L("Open G-code file"), wxCLOSE | wxICON_WARNING | wxCENTRE).ShowModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (paths.size() == 1) {
|
else if (paths.size() == 1) {
|
||||||
|
if (wxGetApp().mainframe->get_mode() == MainFrame::EMode::GCodeViewer) {
|
||||||
|
plater->load_gcode(from_path(paths.front()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (wxMessageDialog((wxWindow*)plater, _L("Do you want to switch to G-code preview ?"),
|
||||||
|
wxString(SLIC3R_APP_NAME) + " - " + _L("Open G-code file"), wxYES_NO | wxCANCEL | wxICON_QUESTION | wxYES_DEFAULT | wxCENTRE).ShowModal() == wxID_YES) {
|
||||||
|
|
||||||
|
if (plater->model().objects.empty() ||
|
||||||
|
wxMessageDialog((wxWindow*)plater, _L("Switching to G-code preview mode will remove all objects, continue?"),
|
||||||
|
wxString(SLIC3R_APP_NAME) + " - " + _L("Switch to G-code preview mode"), wxYES_NO | wxCANCEL | wxICON_QUESTION | wxYES_DEFAULT | wxCENTRE).ShowModal() == wxID_YES) {
|
||||||
|
wxGetApp().mainframe->set_mode(MainFrame::EMode::GCodeViewer);
|
||||||
plater->load_gcode(from_path(paths.front()));
|
plater->load_gcode(from_path(paths.front()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // ENABLE_GCODE_VIEWER
|
#endif // ENABLE_GCODE_VIEWER
|
||||||
|
|
||||||
|
// model section
|
||||||
for (const auto &filename : filenames) {
|
for (const auto &filename : filenames) {
|
||||||
fs::path path(into_path(filename));
|
fs::path path(into_path(filename));
|
||||||
if (std::regex_match(path.string(), pattern_drop))
|
if (std::regex_match(path.string(), pattern_drop))
|
||||||
|
|
Loading…
Reference in a new issue