Merge branch 'dev_native' of https://github.com/Prusa3d/Slic3r into dev_native

This commit is contained in:
bubnikv 2018-11-13 18:44:45 +01:00
commit fedc78dc91
12 changed files with 430 additions and 182 deletions

View file

@ -6,6 +6,11 @@
#include <wx/panel.h>
#include <wx/stdpaths.h>
// For zipped archive creation
#include <wx/stdstream.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
// Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx.
#include "libslic3r/Print.hpp"
#include "libslic3r/SLAPrint.hpp"
@ -75,6 +80,59 @@ void BackgroundSlicingProcess::process_fff()
}
}
// Pseudo type for specializing LayerWriter trait class
struct SLAZipFmt {};
// The implementation of creating zipped archives with wxWidgets
template<> class LayerWriter<SLAZipFmt> {
wxFileName fpath;
wxFFileOutputStream zipfile;
wxZipOutputStream zipstream;
wxStdOutputStream pngstream;
public:
inline LayerWriter(const std::string& zipfile_path):
fpath(zipfile_path),
zipfile(zipfile_path),
zipstream(zipfile),
pngstream(zipstream)
{
if(!zipfile.IsOk())
throw std::runtime_error("Cannot create zip file.");
}
inline void next_entry(const std::string& fname) {
zipstream.PutNextEntry(fname);
}
inline std::string get_name() const {
return fpath.GetName().ToStdString();
}
template<class T> inline LayerWriter& operator<<(const T& arg) {
pngstream << arg; return *this;
}
inline void close() {
zipstream.Close();
zipfile.Close();
}
};
void BackgroundSlicingProcess::process_sla() {
assert(m_print == m_sla_print);
m_print->process();
if(!m_print->canceled() && ! this->is_step_done(bspsGCodeFinalize)) {
this->set_step_started(bspsGCodeFinalize);
if (! m_export_path.empty()) {
m_sla_print->export_raster<SLAZipFmt>(m_export_path);
m_print->set_status(100, "Zip file exported to " + m_export_path);
}
this->set_step_done(bspsGCodeFinalize);
}
}
void BackgroundSlicingProcess::thread_proc()
{
assert(m_print != nullptr);
@ -100,6 +158,7 @@ void BackgroundSlicingProcess::thread_proc()
assert(m_print != nullptr);
switch(m_print->technology()) {
case ptFFF: this->process_fff(); break;
case ptSLA: this->process_sla(); break;
default: m_print->process(); break;
}
} catch (CanceledException & /* ex */) {

View file

@ -100,6 +100,9 @@ private:
// Helper to wrap the FFF slicing & G-code generation.
void process_fff();
// Temporary: for mimicking the fff file export behavior with the raster output
void process_sla();
// Currently active print. It is one of m_fff_print and m_sla_print.
PrintBase *m_print = nullptr;
// Non-owned pointers to Print instances.

View file

@ -1683,7 +1683,7 @@ void GLGizmoSlaSupports::clicked_on_object(const Vec2d& mouse_position)
m_model_object->sla_support_points.push_back(new_pos);
// This should trigger the support generation
wxGetApp().plater()->reslice();
// wxGetApp().plater()->reslice();
}
catch (...) {}
}
@ -1695,7 +1695,7 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all)
m_model_object->sla_support_points.clear();
// This should trigger the support generation
wxGetApp().plater()->reslice();
// wxGetApp().plater()->reslice();
}
else
if (m_hover_id != -1) {
@ -1704,7 +1704,7 @@ void GLGizmoSlaSupports::delete_current_grabber(bool delete_all)
m_hover_id = -1;
// This should trigger the support generation
wxGetApp().plater()->reslice();
// wxGetApp().plater()->reslice();
}
}

View file

@ -48,6 +48,7 @@ const wxString file_wildcards[FT_SIZE] = {
/* FT_INI */ "INI files *.ini|*.ini;*.INI",
/* FT_SVG */ "SVG files *.svg|*.svg;*.SVG",
/* FT_PNGZIP */"Zipped PNG files *.zip|*.zip;*.ZIP", // This is lame, but that's what we use for SLA
};
@ -713,4 +714,4 @@ wxNotebook* GUI_App::tab_panel() const
} // GUI
} //Slic3r
} //Slic3r

View file

@ -38,6 +38,7 @@ enum FileType
FT_INI,
FT_SVG,
FT_PNGZIP,
FT_SIZE,
};
@ -152,4 +153,4 @@ DECLARE_APP(GUI_App)
} // GUI
} //Slic3r
#endif // slic3r_GUI_App_hpp_
#endif // slic3r_GUI_App_hpp_

View file

@ -255,8 +255,6 @@ void MainFrame::init_menubar()
fileMenu->AppendSeparator();
append_menu_item(fileMenu, wxID_ANY, _(L("Slice to SV&G…\tCtrl+G")), _(L("Slice file to a multi-layer SVG")),
[this](wxCommandEvent&) { quick_slice(qsSaveAs | qsExportSVG); }, "shape_handles.png");
append_menu_item(fileMenu, wxID_ANY, _(L("Slice to PNG…")), _(L("Slice file to a set of PNG files")),
[this](wxCommandEvent&) { slice_to_png(); /*$self->quick_slice(save_as = > 0, export_png = > 1);*/ }, "shape_handles.png");
m_menu_item_reslice_now = append_menu_item(fileMenu, wxID_ANY, _(L("(&Re)Slice Now\tCtrl+S")), _(L("Start new slicing process")),
[this](wxCommandEvent&) { reslice_now(); }, "shape_handles.png");
fileMenu->AppendSeparator();
@ -358,13 +356,6 @@ void MainFrame::init_menubar()
}
}
void MainFrame::slice_to_png()
{
// m_plater->stop_background_process();
// m_plater->async_apply_config();
// m_appController->print_ctl()->slice_to_png();
}
// To perform the "Quck Slice", "Quick Slice and Save As", "Repeat last Quick Slice" and "Slice to SVG".
void MainFrame::quick_slice(const int qs)
{

View file

@ -83,7 +83,6 @@ public:
bool is_loaded() const { return m_loaded; }
bool is_last_input_file() const { return !m_qs_last_input_file.IsEmpty(); }
void slice_to_png();
void quick_slice(const int qs = qsUndef);
void reslice_now();
void repair_stl();

View file

@ -1003,12 +1003,15 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
// Default printer technology for default config.
background_process.select_technology(this->printer_technology);
// Register progress callback from the Print class to the Platter.
print.set_status_callback([this](int percent, const std::string &message) {
auto statuscb = [this](int percent, const std::string &message) {
wxCommandEvent event(EVT_PROGRESS_BAR);
event.SetInt(percent);
event.SetString(message);
wxQueueEvent(this->q, event.Clone());
});
};
print.set_status_callback(statuscb);
sla_print.set_status_callback(statuscb);
this->q->Bind(EVT_PROGRESS_BAR, &priv::on_progress_event, this);
_3DScene::add_canvas(canvas3D);
@ -2220,24 +2223,44 @@ void Plater::export_gcode(fs::path output_path)
return;
}
// Copy the names of active presets into the placeholder parser.
wxGetApp().preset_bundle->export_selections(p->print.placeholder_parser());
std::string final_path;
if(printer_technology() == ptFFF) { // TODO: custom button for SLA export
// select output file
if (output_path.empty()) {
// XXX: take output path from CLI opts? Ancient Slic3r versions used to do that...
// Copy the names of active presets into the placeholder parser.
wxGetApp().preset_bundle->export_selections(p->print.placeholder_parser());
// If possible, remove accents from accented latin characters.
// This function is useful for generating file names to be processed by legacy firmwares.
auto default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(
p->print.output_filepath(output_path.string())
// FIXME: ^ errors to handle?
));
auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string());
wxFileDialog dlg(this, _(L("Save G-code file as:")),
start_dir,
default_output_file.filename().string(),
GUI::file_wildcards[FT_GCODE],
// select output file
if (output_path.empty()) {
// XXX: take output path from CLI opts? Ancient Slic3r versions used to do that...
// If possible, remove accents from accented latin characters.
// This function is useful for generating file names to be processed by legacy firmwares.
auto default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(
p->print.output_filepath(output_path.string())
// FIXME: ^ errors to handle?
));
auto start_dir = wxGetApp().app_config->get_last_output_dir(default_output_file.parent_path().string());
wxFileDialog dlg(this, _(L("Save G-code file as:")),
start_dir,
default_output_file.filename().string(),
GUI::file_wildcards[FT_GCODE],
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
if (dlg.ShowModal() == wxID_OK) {
fs::path path(dlg.GetPath());
wxGetApp().app_config->update_last_output_dir(path.parent_path().string());
output_path = path;
}
}
final_path = p->print.output_filepath(output_path.string());
} else {
wxFileDialog dlg(this, _(L("Save Zip file as:")),
wxGetApp().app_config->get_last_output_dir(""),
"out.zip",
GUI::file_wildcards[FT_PNGZIP],
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
@ -2246,10 +2269,12 @@ void Plater::export_gcode(fs::path output_path)
wxGetApp().app_config->update_last_output_dir(path.parent_path().string());
output_path = path;
}
final_path = output_path.string();
}
if (! output_path.empty()) {
this->p->background_process.schedule_export(p->print.output_filepath(output_path.string()));
this->p->background_process.schedule_export(final_path);
this->p->background_process.start();
}
}