Implemented new placeholders for output file name:

1) "initial_filament_type", "printing_filament_types" - really useful
   for multi-material prints

the two other are not so useful, they may become useful once
the output file name template will support not yet defined
vector variables:
2) "initial_tool", "initial_extruder" - zero based index of first extruder
3) "num_printing_extruders" - number of printing extruders.

Fixes Filename incorrect when exporting G-Code with MMU. Always refers filament type in extruder 1 #5300
Fixes Export Filename nicht richtig #7673
Fixes wrong filename - always Filament in from the first extruder #7684
This commit is contained in:
Vojtech Bubnik 2022-01-10 17:57:03 +01:00
parent 4ebfe58352
commit a591d9e9fe
4 changed files with 36 additions and 2 deletions

View File

@ -758,6 +758,8 @@ public:
ConfigOptionIntsTempl() : ConfigOptionVector<int>() {}
explicit ConfigOptionIntsTempl(size_t n, int value) : ConfigOptionVector<int>(n, value) {}
explicit ConfigOptionIntsTempl(std::initializer_list<int> il) : ConfigOptionVector<int>(std::move(il)) {}
explicit ConfigOptionIntsTempl(const std::vector<int> &v) : ConfigOptionVector<int>(v) {}
explicit ConfigOptionIntsTempl(std::vector<int> &&v) : ConfigOptionVector<int>(std::move(v)) {}
static ConfigOptionType static_type() { return coInts; }
ConfigOptionType type() const override { return static_type(); }

View File

@ -677,7 +677,7 @@ namespace DoExport {
print_statistics.total_weight = total_weight;
print_statistics.total_cost = total_cost;
print_statistics.filament_stats = result.print_statistics.volumes_per_extruder;
print_statistics.filament_stats = result.print_statistics.volumes_per_extruder;
}
// if any reserved keyword is found, returns a std::vector containing the first MAX_COUNT keywords found
@ -984,19 +984,26 @@ namespace DoExport {
static std::string update_print_stats_and_format_filament_stats(
const bool has_wipe_tower,
const WipeTowerData &wipe_tower_data,
const FullPrintConfig &config,
const std::vector<Extruder> &extruders,
unsigned int initial_extruder_id,
PrintStatistics &print_statistics)
{
std::string filament_stats_string_out;
print_statistics.clear();
print_statistics.total_toolchanges = std::max(0, wipe_tower_data.number_of_toolchanges);
print_statistics.initial_extruder_id = initial_extruder_id;
std::vector<std::string> filament_types;
if (! extruders.empty()) {
std::pair<std::string, unsigned int> out_filament_used_mm ("; filament used [mm] = ", 0);
std::pair<std::string, unsigned int> out_filament_used_cm3("; filament used [cm3] = ", 0);
std::pair<std::string, unsigned int> out_filament_used_g ("; filament used [g] = ", 0);
std::pair<std::string, unsigned int> out_filament_cost ("; filament cost = ", 0);
for (const Extruder &extruder : extruders) {
print_statistics.printing_extruders.emplace_back(extruder.id());
filament_types.emplace_back(config.filament_type.get_at(extruder.id()));
double used_filament = extruder.used_filament() + (has_wipe_tower ? wipe_tower_data.used_filament[extruder.id()] : 0.f);
double extruded_volume = extruder.extruded_volume() + (has_wipe_tower ? wipe_tower_data.used_filament[extruder.id()] * 2.4052f : 0.f); // assumes 1.75mm filament diameter
double filament_weight = extruded_volume * extruder.filament_density() * 0.001;
@ -1036,6 +1043,13 @@ namespace DoExport {
filament_stats_string_out += "\n" + out_filament_used_g.first;
if (out_filament_cost.second)
filament_stats_string_out += "\n" + out_filament_cost.first;
print_statistics.initial_filament_type = config.filament_type.values[initial_extruder_id];
std::sort(filament_types.begin(), filament_types.end());
print_statistics.printing_filament_types = filament_types.front();
for (size_t i = 1; i < filament_types.size(); ++ i) {
print_statistics.printing_filament_types += ",";
print_statistics.printing_filament_types += filament_types[i];
}
}
return filament_stats_string_out;
}
@ -1486,7 +1500,9 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write(DoExport::update_print_stats_and_format_filament_stats(
// Const inputs
has_wipe_tower, print.wipe_tower_data(),
this->config(),
m_writer.extruders(),
initial_extruder_id,
// Modifies
print.m_print_statistics));
file.write("\n");

View File

@ -1248,6 +1248,13 @@ DynamicConfig PrintStatistics::config() const
config.set_key_value("total_weight", new ConfigOptionFloat(this->total_weight));
config.set_key_value("total_wipe_tower_cost", new ConfigOptionFloat(this->total_wipe_tower_cost));
config.set_key_value("total_wipe_tower_filament", new ConfigOptionFloat(this->total_wipe_tower_filament));
config.set_key_value("initial_tool", new ConfigOptionInt(int(this->initial_extruder_id)));
config.set_key_value("initial_extruder", new ConfigOptionInt(int(this->initial_extruder_id)));
config.set_key_value("initial_filament_type", new ConfigOptionString(this->initial_filament_type));
config.set_key_value("printing_filament_types", new ConfigOptionString(this->printing_filament_types));
config.set_key_value("num_printing_extruders", new ConfigOptionInt(int(this->printing_extruders.size())));
// config.set_key_value("printing_extruders", new ConfigOptionInts(std::vector<int>(this->printing_extruders.begin(), this->printing_extruders.end())));
return config;
}
@ -1257,7 +1264,8 @@ DynamicConfig PrintStatistics::placeholders()
for (const std::string &key : {
"print_time", "normal_print_time", "silent_print_time",
"used_filament", "extruded_volume", "total_cost", "total_weight",
"total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament"})
"total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament",
"initial_tool", "initial_extruder", "initial_filament_type", "printing_filament_types", "num_printing_extruders" })
config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}"));
return config;
}

View File

@ -455,6 +455,10 @@ struct PrintStatistics
double total_weight;
double total_wipe_tower_cost;
double total_wipe_tower_filament;
std::vector<unsigned int> printing_extruders;
unsigned int initial_extruder_id;
std::string initial_filament_type;
std::string printing_filament_types;
std::map<size_t, double> filament_stats;
// Config with the filled in print statistics.
@ -472,7 +476,11 @@ struct PrintStatistics
total_weight = 0.;
total_wipe_tower_cost = 0.;
total_wipe_tower_filament = 0.;
initial_extruder_id = 0;
initial_filament_type.clear();
printing_filament_types.clear();
filament_stats.clear();
printing_extruders.clear();
}
};