From c0ebcacf1d62d44d247755c9c0d9c681d3579651 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 12 Dec 2018 12:00:45 +0100 Subject: [PATCH] WIP: Time estimate in file names. --- src/libslic3r/Print.cpp | 13 ++++++++ src/libslic3r/Print.hpp | 3 +- src/libslic3r/PrintBase.cpp | 10 +++--- src/libslic3r/PrintBase.hpp | 2 +- src/slic3r/GUI/BackgroundSlicingProcess.cpp | 34 +++++++++++++++++++-- src/slic3r/GUI/GUI.cpp | 2 +- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index e382c7dbc..3bbe00805 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1860,5 +1860,18 @@ int Print::get_extruder(const ExtrusionEntityCollection& fill, const PrintRegion std::max(region.config().perimeter_extruder.value - 1, 0); } +std::string Print::output_filename() const +{ + // Set the placeholders for the data know first after the G-code export is finished. + // These values will be just propagated into the output file name. + DynamicConfig config; + for (const std::string &key : { + "print_time", "normal_print_time", "silent_print_time", + "used_filament", "extruded_volume", "total_cost", "total_weight", + "total_wipe_tower_cost", "total_wipe_tower_filament"}) + config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}")); + return this->PrintBase::output_filename(m_config.output_filename_format.value, "gcode", &config); +} + } // namespace Slic3r diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 04de0f95c..27ee6f3c2 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -345,8 +345,7 @@ public: bool has_wipe_tower() const; const WipeTowerData& wipe_tower_data() const { return m_wipe_tower_data; } - std::string output_filename() const override - { return this->PrintBase::output_filename(m_config.output_filename_format.value, "gcode"); } + std::string output_filename() const override; // Accessed by SupportMaterial const PrintRegion* get_region(size_t idx) const { return m_regions[idx]; } diff --git a/src/libslic3r/PrintBase.cpp b/src/libslic3r/PrintBase.cpp index cf8c5b193..1d078da30 100644 --- a/src/libslic3r/PrintBase.cpp +++ b/src/libslic3r/PrintBase.cpp @@ -48,12 +48,14 @@ void PrintBase::update_object_placeholders() } } -std::string PrintBase::output_filename(const std::string &format, const std::string &default_ext) const +std::string PrintBase::output_filename(const std::string &format, const std::string &default_ext, const DynamicConfig *config_override) const { - DynamicConfig cfg_timestamp; - PlaceholderParser::update_timestamp(cfg_timestamp); + DynamicConfig cfg; + if (config_override != nullptr) + cfg = *config_override; + PlaceholderParser::update_timestamp(cfg); try { - boost::filesystem::path filename = this->placeholder_parser().process(format, 0, &cfg_timestamp); + boost::filesystem::path filename = this->placeholder_parser().process(format, 0, &cfg); if (filename.extension().empty()) filename = boost::filesystem::change_extension(filename, default_ext); return filename.string(); diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp index 401718773..1a61921d6 100644 --- a/src/libslic3r/PrintBase.hpp +++ b/src/libslic3r/PrintBase.hpp @@ -307,7 +307,7 @@ protected: void throw_if_canceled() const { if (m_cancel_status) throw CanceledException(); } // To be called by this->output_filename() with the format string pulled from the configuration layer. - std::string output_filename(const std::string &format, const std::string &default_ext) const; + std::string output_filename(const std::string &format, const std::string &default_ext, const DynamicConfig *config_override = nullptr) const; // Update "scale", "input_filename", "input_filename_base" placeholders from the current printable ModelObjects. void update_object_placeholders(); diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 1e8258d6f..f2249de3d 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -22,6 +22,7 @@ #include #include +#include #include namespace Slic3r { @@ -72,11 +73,38 @@ void BackgroundSlicingProcess::process_fff() if (this->set_step_started(bspsGCodeFinalize)) { if (! m_export_path.empty()) { //FIXME localize the messages - if (copy_file(m_temp_output_path, m_export_path) != 0) + // Perform the final post-processing of the export path by applying the print statistics over the file name. + std::string export_path; + { + const PrintStatistics &stats = m_fff_print->print_statistics(); + PlaceholderParser pp; + std::string normal_print_time = stats.estimated_normal_print_time; + std::string silent_print_time = stats.estimated_silent_print_time; + normal_print_time.erase(std::remove_if(normal_print_time.begin(), normal_print_time.end(), std::isspace), normal_print_time.end()); + silent_print_time.erase(std::remove_if(silent_print_time.begin(), silent_print_time.end(), std::isspace), silent_print_time.end()); + pp.set("print_time", new ConfigOptionString(normal_print_time)); + pp.set("normal_print_time", new ConfigOptionString(normal_print_time)); + pp.set("silent_print_time", new ConfigOptionString(silent_print_time)); + pp.set("used_filament", new ConfigOptionFloat (stats.total_used_filament)); + pp.set("extruded_volume", new ConfigOptionFloat (stats.total_extruded_volume)); + pp.set("total_cost", new ConfigOptionFloat (stats.total_cost)); + pp.set("total_weight", new ConfigOptionFloat (stats.total_weight)); + pp.set("total_wipe_tower_cost", new ConfigOptionFloat (stats.total_wipe_tower_cost)); + pp.set("total_wipe_tower_filament", new ConfigOptionFloat (stats.total_wipe_tower_filament)); + boost::filesystem::path path(m_export_path); + try { + std::string new_stem = pp.process(path.stem().string(), 0); + export_path = (path.parent_path() / (new_stem + path.extension().string())).string(); + } catch (const std::exception &ex) { + BOOST_LOG_TRIVIAL(error) << "Failed to apply the print statistics to the export file name: " << ex.what(); + export_path = m_export_path; + } + } + if (copy_file(m_temp_output_path, export_path) != 0) throw std::runtime_error("Copying of the temporary G-code to the output G-code failed"); m_print->set_status(95, "Running post-processing scripts"); - run_post_process_scripts(m_export_path, m_fff_print->config()); - m_print->set_status(100, "G-code file exported to " + m_export_path); + run_post_process_scripts(export_path, m_fff_print->config()); + m_print->set_status(100, "G-code file exported to " + export_path); } else { m_print->set_status(100, "Slicing complete"); } diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 2423c152f..bc7ea9899 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -147,7 +147,7 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast(value))); break; case coStrings:{ - if (opt_key == "compatible_prints" || opt_key == "compatible_printers") { + if (opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "post_process") { config.option(opt_key)->values = boost::any_cast>(value); }