Skip to content

Commit

Permalink
Implemented new placeholders for output file name:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bubnikv committed Jan 10, 2022
1 parent 4ebfe58 commit a591d9e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/libslic3r/Config.hpp
Expand Up @@ -758,6 +758,8 @@ class ConfigOptionIntsTempl : public ConfigOptionVector<int>
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(); }
Expand Down
18 changes: 17 additions & 1 deletion src/libslic3r/GCode.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 9 additions & 1 deletion src/libslic3r/Print.cpp
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/libslic3r/Print.hpp
Expand Up @@ -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.
Expand All @@ -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();
}
};

Expand Down

0 comments on commit a591d9e

Please sign in to comment.