From 95419370e132ba81f145b5e2ddd83c1ffd633b55 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 13 Nov 2018 11:53:54 +0100 Subject: [PATCH] zip file output dialog and status indication for sla in the statusbar. --- src/libslic3r/SLAPrint.cpp | 40 ++++++++++++- src/libslic3r/SLAPrint.hpp | 5 +- src/slic3r/GUI/BackgroundSlicingProcess.cpp | 14 +++++ src/slic3r/GUI/BackgroundSlicingProcess.hpp | 3 + src/slic3r/GUI/GLGizmo.cpp | 6 +- src/slic3r/GUI/Plater.cpp | 65 ++++++++++++++------- 6 files changed, 104 insertions(+), 29 deletions(-) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 5e908e31f..27b4d25ed 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -154,6 +154,7 @@ void SLAPrint::process() }; using slaposFn = std::function; + using slapsFn = std::function; std::array objectsteps = { slaposObjectSlice, @@ -164,7 +165,7 @@ void SLAPrint::process() slaposSliceSupports }; - std::array fullprogram = + std::array pobj_program = { slice_model, [](const SLAPrintObject&){}, // slaposSupportIslands now empty @@ -174,8 +175,14 @@ void SLAPrint::process() slice_supports }; + std::array print_program = + { + rasterize, + [](){} // validate + }; + for(SLAPrintObject * po : m_objects) { - for(size_t s = 0; s < fullprogram.size(); ++s) { + for(size_t s = 0; s < pobj_program.size(); ++s) { auto currentstep = objectsteps[s]; // Cancellation checking. Each step will check for cancellation @@ -188,11 +195,33 @@ void SLAPrint::process() OBJ_STEP_LABELS[currentstep]); po->set_started(currentstep); - fullprogram[s](*po); + pobj_program[s](*po); po->set_done(currentstep); } } } + + std::array printsteps = { + slapsRasterize, slapsValidate + }; + + for(size_t s = 0; s < print_program.size(); ++s) { + auto currentstep = printsteps[s]; + + throw_if_canceled(); + + if(m_stepmask[s]) { + set_status(PRINT_STEP_LEVELS[currentstep], + PRINT_STEP_LABELS[currentstep]); + + set_started(currentstep); + print_program[s](); + set_done(currentstep); + } + } + + // If everything vent well + set_status(100, L("Slicing done")); } void SLAPrint::render_supports(SLASupportRenderer &renderer) @@ -200,6 +229,11 @@ void SLAPrint::render_supports(SLASupportRenderer &renderer) std::cout << "Would show the SLA supports" << std::endl; } +void SLAPrint::export_raster(const std::string &fname) +{ + std::cout << "Would export the SLA raster" << std::endl; +} + SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object): Inherited(print), m_model_object(model_object), diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 4e6627eec..3a6e73ff3 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -131,7 +131,7 @@ private: // Prevents erroneous use by other classes. typedef PrintBaseWithState Inherited; public: - SLAPrint() {} + SLAPrint(): m_stepmask(slapsCount, true) {} virtual ~SLAPrint() { this->clear(); } PrinterTechnology technology() const noexcept { return ptSLA; } @@ -143,11 +143,14 @@ public: void render_supports(SLASupportRenderer& renderer); + void export_raster(const std::string& fname); + private: Model m_model; SLAPrinterConfig m_printer_config; SLAMaterialConfig m_material_config; PrintObjects m_objects; + std::vector m_stepmask; friend SLAPrintObject; }; diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index d9a60caa9..7e1908b64 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -75,6 +75,19 @@ void BackgroundSlicingProcess::process_fff() } } +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(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 +113,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 */) { diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.hpp b/src/slic3r/GUI/BackgroundSlicingProcess.hpp index b008437c0..28f8e67ab 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.hpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.hpp @@ -96,6 +96,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. diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index e1f9ff221..920e79913 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -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(); } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8bfa50804..08b368031 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -991,12 +991,15 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : // Default printer technology for default config. background_process.select_technology(q->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); @@ -2171,28 +2174,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()); + // select output file + if (output_path.empty()) { + // XXX: take output path from CLI opts? Ancient Slic3r versions used to do that... - auto fileType = printer_technology() == ptFFF ? FT_GCODE : FT_PNGZIP; - std::string dtitle = printer_technology() == ptFFF ? L("Save G-code file as:") - : L("Save Zip file as:"); - wxFileDialog dlg(this, _(dtitle), - start_dir, - default_output_file.filename().string(), - GUI::file_wildcards[fileType], + // 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 ); @@ -2201,10 +2220,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(); } }