2018-11-08 13:23:17 +00:00
|
|
|
#include "PrintBase.hpp"
|
|
|
|
|
2018-12-03 14:28:54 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2018-12-03 13:58:50 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
2018-12-03 12:14:28 +00:00
|
|
|
#include "I18N.hpp"
|
|
|
|
|
|
|
|
//! macro used to mark string used at localization,
|
|
|
|
//! return same string
|
|
|
|
#define L(s) Slic3r::I18N::translate(s)
|
|
|
|
|
2018-11-08 13:23:17 +00:00
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
|
2018-11-16 17:28:50 +00:00
|
|
|
size_t PrintStateBase::g_last_timestamp = 0;
|
|
|
|
|
2018-12-03 12:14:28 +00:00
|
|
|
// Update "scale", "input_filename", "input_filename_base" placeholders from the current m_objects.
|
2019-05-17 14:27:00 +00:00
|
|
|
void PrintBase::update_object_placeholders(DynamicConfig &config, const std::string &default_ext) const
|
2018-12-03 12:14:28 +00:00
|
|
|
{
|
|
|
|
// get the first input file name
|
|
|
|
std::string input_file;
|
|
|
|
std::vector<std::string> v_scale;
|
|
|
|
for (const ModelObject *model_object : m_model.objects) {
|
|
|
|
ModelInstance *printable = nullptr;
|
|
|
|
for (ModelInstance *model_instance : model_object->instances)
|
|
|
|
if (model_instance->is_printable()) {
|
|
|
|
printable = model_instance;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (printable) {
|
|
|
|
// CHECK_ME -> Is the following correct ?
|
|
|
|
v_scale.push_back("x:" + boost::lexical_cast<std::string>(printable->get_scaling_factor(X) * 100) +
|
|
|
|
"% y:" + boost::lexical_cast<std::string>(printable->get_scaling_factor(Y) * 100) +
|
|
|
|
"% z:" + boost::lexical_cast<std::string>(printable->get_scaling_factor(Z) * 100) + "%");
|
|
|
|
if (input_file.empty())
|
2019-02-03 09:41:14 +00:00
|
|
|
input_file = model_object->name.empty() ? model_object->input_file : model_object->name;
|
2018-12-03 12:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 20:48:55 +00:00
|
|
|
config.set_key_value("scale", new ConfigOptionStrings(v_scale));
|
2018-12-03 12:14:28 +00:00
|
|
|
if (! input_file.empty()) {
|
|
|
|
// get basename with and without suffix
|
2019-05-17 14:27:00 +00:00
|
|
|
const std::string input_filename = boost::filesystem::path(input_file).filename().string();
|
|
|
|
const std::string input_filename_base = input_filename.substr(0, input_filename.find_last_of("."));
|
|
|
|
config.set_key_value("input_filename", new ConfigOptionString(input_filename_base + default_ext));
|
|
|
|
config.set_key_value("input_filename_base", new ConfigOptionString(input_filename_base));
|
2018-12-03 12:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 09:41:14 +00:00
|
|
|
// Generate an output file name based on the format template, default extension, and template parameters
|
|
|
|
// (timestamps, object placeholders derived from the model, current placeholder prameters, print statistics - config_override)
|
2019-05-17 14:27:00 +00:00
|
|
|
std::string PrintBase::output_filename(const std::string &format, const std::string &default_ext, const std::string &filename_base, const DynamicConfig *config_override) const
|
2018-12-03 12:14:28 +00:00
|
|
|
{
|
2018-12-12 11:00:45 +00:00
|
|
|
DynamicConfig cfg;
|
|
|
|
if (config_override != nullptr)
|
|
|
|
cfg = *config_override;
|
|
|
|
PlaceholderParser::update_timestamp(cfg);
|
2019-05-17 14:27:00 +00:00
|
|
|
this->update_object_placeholders(cfg, default_ext);
|
|
|
|
if (! filename_base.empty()) {
|
|
|
|
cfg.set_key_value("input_filename", new ConfigOptionString(filename_base + default_ext));
|
|
|
|
cfg.set_key_value("input_filename_base", new ConfigOptionString(filename_base));
|
|
|
|
}
|
2018-12-03 12:14:28 +00:00
|
|
|
try {
|
2019-05-16 13:55:26 +00:00
|
|
|
boost::filesystem::path filename = format.empty() ?
|
2019-05-17 14:27:00 +00:00
|
|
|
cfg.opt_string("input_filename_base") + default_ext :
|
2019-05-16 13:55:26 +00:00
|
|
|
this->placeholder_parser().process(format, 0, &cfg);
|
2020-02-12 14:39:04 +00:00
|
|
|
if (filename.extension().empty())
|
2020-02-12 13:23:54 +00:00
|
|
|
filename = boost::filesystem::change_extension(filename, default_ext);
|
2018-12-03 12:14:28 +00:00
|
|
|
return filename.string();
|
|
|
|
} catch (std::runtime_error &err) {
|
|
|
|
throw std::runtime_error(L("Failed processing of the output_filename_format template.") + "\n" + err.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 14:27:00 +00:00
|
|
|
std::string PrintBase::output_filepath(const std::string &path, const std::string &filename_base) const
|
2018-12-03 12:14:28 +00:00
|
|
|
{
|
|
|
|
// if we were supplied no path, generate an automatic one based on our first object's input file
|
2019-02-01 10:44:08 +00:00
|
|
|
if (path.empty())
|
2018-12-03 12:14:28 +00:00
|
|
|
// get the first input file name
|
2019-05-17 14:27:00 +00:00
|
|
|
return (boost::filesystem::path(m_model.propose_export_file_name_and_path()).parent_path() / this->output_filename(filename_base)).make_preferred().string();
|
2018-12-03 12:14:28 +00:00
|
|
|
|
|
|
|
// if we were supplied a directory, use it and append our automatically generated filename
|
|
|
|
boost::filesystem::path p(path);
|
|
|
|
if (boost::filesystem::is_directory(p))
|
2019-05-17 14:27:00 +00:00
|
|
|
return (p / this->output_filename(filename_base)).make_preferred().string();
|
2018-12-03 12:14:28 +00:00
|
|
|
|
|
|
|
// if we were supplied a file which is not a directory, use it
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-11-16 17:28:50 +00:00
|
|
|
tbb::mutex& PrintObjectBase::state_mutex(PrintBase *print)
|
2018-11-08 13:23:17 +00:00
|
|
|
{
|
2018-11-16 17:28:50 +00:00
|
|
|
return print->state_mutex();
|
2018-11-08 13:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> PrintObjectBase::cancel_callback(PrintBase *print)
|
|
|
|
{
|
|
|
|
return print->cancel_callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Slic3r
|