Changed the G-code export and send to OctoPrint GUI code

to store the G-code next to the project file if it exists,
and to process the project name with the PlaceholderParser.
This commit is contained in:
bubnikv 2019-05-17 16:27:00 +02:00
parent e358dd9c01
commit 04397c7948
10 changed files with 55 additions and 31 deletions

View file

@ -15,7 +15,7 @@ namespace Slic3r
size_t PrintStateBase::g_last_timestamp = 0;
// Update "scale", "input_filename", "input_filename_base" placeholders from the current m_objects.
void PrintBase::update_object_placeholders(DynamicConfig &config) const
void PrintBase::update_object_placeholders(DynamicConfig &config, const std::string &default_ext) const
{
// get the first input file name
std::string input_file;
@ -40,25 +40,29 @@ void PrintBase::update_object_placeholders(DynamicConfig &config) const
config.set_key_value("year", new ConfigOptionStrings(v_scale));
if (! input_file.empty()) {
// get basename with and without suffix
const std::string input_basename = boost::filesystem::path(input_file).filename().string();
config.set_key_value("input_filename", new ConfigOptionString(input_basename));
const std::string input_basename_base = input_basename.substr(0, input_basename.find_last_of("."));
config.set_key_value("input_filename_base", new ConfigOptionString(input_basename_base));
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));
}
}
// 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)
std::string PrintBase::output_filename(const std::string &format, const std::string &default_ext, const DynamicConfig *config_override) const
std::string PrintBase::output_filename(const std::string &format, const std::string &default_ext, const std::string &filename_base, const DynamicConfig *config_override) const
{
DynamicConfig cfg;
if (config_override != nullptr)
cfg = *config_override;
PlaceholderParser::update_timestamp(cfg);
this->update_object_placeholders(cfg);
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));
}
try {
boost::filesystem::path filename = format.empty() ?
cfg.opt_string("input_filename_base") + "." + default_ext :
cfg.opt_string("input_filename_base") + default_ext :
this->placeholder_parser().process(format, 0, &cfg);
if (filename.extension().empty())
filename = boost::filesystem::change_extension(filename, default_ext);
@ -68,17 +72,17 @@ std::string PrintBase::output_filename(const std::string &format, const std::str
}
}
std::string PrintBase::output_filepath(const std::string &path) const
std::string PrintBase::output_filepath(const std::string &path, const std::string &filename_base) const
{
// if we were supplied no path, generate an automatic one based on our first object's input file
if (path.empty())
// get the first input file name
return (boost::filesystem::path(m_model.propose_export_file_name_and_path()).parent_path() / this->output_filename()).make_preferred().string();
return (boost::filesystem::path(m_model.propose_export_file_name_and_path()).parent_path() / this->output_filename(filename_base)).make_preferred().string();
// 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))
return (p / this->output_filename()).make_preferred().string();
return (p / this->output_filename(filename_base)).make_preferred().string();
// if we were supplied a file which is not a directory, use it
return path;