WIP: Time estimate in file names.

This commit is contained in:
bubnikv 2018-12-12 12:00:45 +01:00
parent 2b9f52c33c
commit c0ebcacf1d
6 changed files with 53 additions and 11 deletions

View file

@ -22,6 +22,7 @@
#include <boost/format.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
#include <boost/nowide/cstdio.hpp>
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");
}