Skip to content

Commit 1dd4a5f

Browse files
committed
feat: use filename format for print job names
(cherry picked from commit b470edc)
1 parent f3ed674 commit 1dd4a5f

1 file changed

Lines changed: 56 additions & 6 deletions

File tree

src/slic3r/GUI/Plater.cpp

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15508,17 +15508,67 @@ wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool
1550815508
{
1550915509
wxString curr_project_name = m_project_name;
1551015510

15511-
std::string plate_index_str = "";
15511+
std::string plate_index_str;
1551215512
std::string plate_name = partplate_list.get_curr_plate()->get_plate_name();
1551315513

15514-
// remove unsupported characters in filename
15514+
// Remove unsupported characters before using the project name as the
15515+
// input_filename_base placeholder.
1551515516
curr_project_name = from_u8(filter_characters(curr_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
1551615517
plate_name = filter_characters(plate_name, "<>[]:/\\|?*\"");
1551715518

15518-
if (!plate_name.empty())
15519-
plate_index_str = (boost::format("_%1%") % plate_name).str();
15520-
else if (partplate_list.get_plate_count() > 1)
15521-
plate_index_str = (boost::format("_plate_%1%") % std::to_string(partplate_list.get_curr_plate_index() + 1)).str();
15519+
bool filename_format_has_plate_name = false;
15520+
15521+
// Use filename_format as the default print-job name. For an all-plates
15522+
// operation, retain the project name because the active Print represents
15523+
// only the currently selected plate.
15524+
if (!export_all) {
15525+
try {
15526+
const Print& print = partplate_list.get_current_fff_print();
15527+
15528+
const std::string filename_format = print.config().filename_format.value;
15529+
const std::string formatted_output =
15530+
print.output_filename(curr_project_name.utf8_string());
15531+
15532+
wxString formatted_name = from_u8(
15533+
boost::filesystem::path(formatted_output).filename().string());
15534+
15535+
const wxString lower_name = formatted_name.Lower();
15536+
15537+
if (lower_name.EndsWith(".gcode.3mf"))
15538+
formatted_name.RemoveLast(10);
15539+
else if (lower_name.EndsWith(".gcode"))
15540+
formatted_name.RemoveLast(6);
15541+
else if (lower_name.EndsWith(".3mf"))
15542+
formatted_name.RemoveLast(4);
15543+
15544+
if (!formatted_name.empty())
15545+
curr_project_name = formatted_name;
15546+
15547+
filename_format_has_plate_name =
15548+
!plate_name.empty() &&
15549+
filename_format.find("[plate_name]") != std::string::npos;
15550+
}
15551+
catch (const Slic3r::PlaceholderParserError& ex) {
15552+
BOOST_LOG_TRIVIAL(warning)
15553+
<< "Failed to apply filename_format to print-job name; "
15554+
"using the legacy project name instead: "
15555+
<< ex.what();
15556+
}
15557+
}
15558+
15559+
// Placeholder expansion may introduce characters unsupported by the
15560+
// printer or the local filesystem.
15561+
curr_project_name = from_u8(
15562+
filter_characters(curr_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
15563+
15564+
if (!filename_format_has_plate_name) {
15565+
if (!plate_name.empty())
15566+
plate_index_str = (boost::format("_%1%") % plate_name).str();
15567+
else if (partplate_list.get_plate_count() > 1)
15568+
plate_index_str =
15569+
(boost::format("_plate_%1%") %
15570+
std::to_string(partplate_list.get_curr_plate_index() + 1)).str();
15571+
}
1552215572

1552315573
if (!m_project_folder.empty()) {
1552415574
if (!only_filename) {

0 commit comments

Comments
 (0)