mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 16:45:55 +08:00
#123 Material weight/length per change for colour changes
This commit is contained in:
parent
fad19b4b1c
commit
605e27b9b5
@ -1152,6 +1152,8 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
|
||||
m_last_width = GCodeAnalyzer::Default_Width;
|
||||
m_last_height = GCodeAnalyzer::Default_Height;
|
||||
print.m_print_statistics.color_extruderid_to_used_filament.clear();
|
||||
print.m_print_statistics.color_extruderid_to_used_weight.clear();
|
||||
|
||||
// How many times will be change_layer() called?
|
||||
// change_layer() in turn increments the progress bar status.
|
||||
@ -1440,7 +1442,7 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||
for (const LayerToPrint <p : layers_to_print) {
|
||||
std::vector<LayerToPrint> lrs;
|
||||
lrs.emplace_back(std::move(ltp));
|
||||
this->process_layer(file, print, lrs, tool_ordering.tools_for_layer(ltp.print_z()), nullptr, *print_object_instance_sequential_active - object.instances().data());
|
||||
this->process_layer(file, print, print.m_print_statistics, lrs, tool_ordering.tools_for_layer(ltp.print_z()), nullptr, *print_object_instance_sequential_active - object.instances().data());
|
||||
print.throw_if_canceled();
|
||||
}
|
||||
#ifdef HAS_PRESSURE_EQUALIZER
|
||||
@ -1493,7 +1495,7 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||
const LayerTools &layer_tools = tool_ordering.tools_for_layer(layer.first);
|
||||
if (m_wipe_tower && layer_tools.has_wipe_tower)
|
||||
m_wipe_tower->next_layer();
|
||||
this->process_layer(file, print, layer.second, layer_tools, &print_object_instances_ordering, size_t(-1));
|
||||
this->process_layer(file, print, print.m_print_statistics, layer.second, layer_tools, &print_object_instances_ordering, size_t(-1));
|
||||
print.throw_if_canceled();
|
||||
}
|
||||
#ifdef HAS_PRESSURE_EQUALIZER
|
||||
@ -1809,15 +1811,14 @@ std::vector<GCode::InstanceToPrint> GCode::sort_print_object_instances(
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace ProcessLayer
|
||||
{
|
||||
|
||||
static std::string emit_custom_gcode_per_print_z(
|
||||
std::string GCode::emit_custom_gcode_per_print_z(
|
||||
const CustomGCode::Item *custom_gcode,
|
||||
// ID of the first extruder printing this layer.
|
||||
unsigned int first_extruder_id,
|
||||
bool single_extruder_printer)
|
||||
{
|
||||
const Print &print,
|
||||
PrintStatistics &stats)
|
||||
{
|
||||
bool single_extruder_printer = print.config().nozzle_diameter.size() == 1;
|
||||
std::string gcode;
|
||||
|
||||
if (custom_gcode != nullptr) {
|
||||
@ -1837,9 +1838,27 @@ namespace ProcessLayer
|
||||
else if (custom_code == PausePrintCode)
|
||||
pause_print_msg = custom_gcode->color;
|
||||
|
||||
if (color_change) {
|
||||
//update stats : weight
|
||||
double previously_extruded = 0;
|
||||
for (const auto& tuple : stats.color_extruderid_to_used_weight)
|
||||
if (tuple.first == this->m_writer.extruder()->id())
|
||||
previously_extruded += tuple.second;
|
||||
double extruded = this->m_writer.extruder()->filament_density() * this->m_writer.extruder()->extruded_volume();
|
||||
stats.color_extruderid_to_used_weight.emplace_back(this->m_writer.extruder()->id(), extruded - previously_extruded);
|
||||
|
||||
//update stats : length
|
||||
previously_extruded = 0;
|
||||
for (const auto& tuple : stats.color_extruderid_to_used_filament)
|
||||
if (tuple.first == this->m_writer.extruder()->id())
|
||||
previously_extruded += tuple.second;
|
||||
stats.color_extruderid_to_used_filament.emplace_back(this->m_writer.extruder()->id(), this->m_writer.extruder()->used_filament() - previously_extruded);
|
||||
}
|
||||
|
||||
// we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count
|
||||
if (color_change || tool_change)
|
||||
{
|
||||
|
||||
// Color Change or Tool Change as Color Change.
|
||||
// add tag for analyzer
|
||||
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
|
||||
@ -1882,8 +1901,7 @@ namespace ProcessLayer
|
||||
}
|
||||
|
||||
return gcode;
|
||||
}
|
||||
} // namespace ProcessLayer
|
||||
}
|
||||
|
||||
namespace Skirt {
|
||||
static void skirt_loops_per_extruder_all_printing(const Print &print, const LayerTools &layer_tools, std::map<unsigned int, std::pair<size_t, size_t>> &skirt_loops_per_extruder_out)
|
||||
@ -1958,6 +1976,7 @@ void GCode::process_layer(
|
||||
// Write into the output file.
|
||||
FILE *file,
|
||||
const Print &print,
|
||||
PrintStatistics &print_stat,
|
||||
// Set of object & print layers of the same PrintObject and with the same print_z.
|
||||
const std::vector<LayerToPrint> &layers,
|
||||
const LayerTools &layer_tools,
|
||||
@ -2054,7 +2073,7 @@ void GCode::process_layer(
|
||||
|
||||
if (single_object_instance_idx == size_t(-1)) {
|
||||
// Normal (non-sequential) print.
|
||||
gcode += ProcessLayer::emit_custom_gcode_per_print_z(layer_tools.custom_gcode, first_extruder_id, print.config().nozzle_diameter.size() == 1);
|
||||
gcode += this->emit_custom_gcode_per_print_z(layer_tools.custom_gcode, first_extruder_id, print, print_stat);
|
||||
}
|
||||
// Extrude skirt at the print_z of the raft layers and normal object layers
|
||||
// not at the print_z of the interlaced support material layers.
|
||||
|
@ -200,6 +200,9 @@ public:
|
||||
// append full config to the given string
|
||||
static void append_full_config(const Print& print, std::string& str);
|
||||
|
||||
// called by porcess_layer, do the color change / custom gcode
|
||||
std::string emit_custom_gcode_per_print_z(const CustomGCode::Item* custom_gcode, unsigned int first_extruder_id, const Print& print, PrintStatistics& stats);
|
||||
|
||||
// Object and support extrusions of the same PrintObject at the same print_z.
|
||||
// public, so that it could be accessed by free helper functions from GCode.cpp
|
||||
struct LayerToPrint
|
||||
@ -225,6 +228,7 @@ private:
|
||||
// Write into the output file.
|
||||
FILE *file,
|
||||
const Print &print,
|
||||
PrintStatistics &print_stat,
|
||||
// Set of object & print layers of the same PrintObject and with the same print_z.
|
||||
const std::vector<LayerToPrint> &layers,
|
||||
const LayerTools &layer_tools,
|
||||
|
@ -772,7 +772,7 @@ namespace Slic3r {
|
||||
std::vector<std::pair<CustomGcodeType, std::string>> ret;
|
||||
|
||||
float total_time = 0.0f;
|
||||
for (auto t : m_custom_gcode_times)
|
||||
for (const std::pair<CustomGcodeType, float> &t : m_custom_gcode_times)
|
||||
{
|
||||
std::string time = _get_time_dhm(t.second);
|
||||
if (include_remaining)
|
||||
|
@ -321,10 +321,12 @@ struct PrintStatistics
|
||||
std::vector<std::pair<CustomGcodeType, std::string>> estimated_normal_custom_gcode_print_times;
|
||||
std::vector<std::pair<CustomGcodeType, std::string>> estimated_silent_custom_gcode_print_times;
|
||||
double total_used_filament;
|
||||
std::vector<std::pair<size_t, double>> color_extruderid_to_used_filament;
|
||||
double total_extruded_volume;
|
||||
double total_cost;
|
||||
int total_toolchanges;
|
||||
double total_weight;
|
||||
std::vector<std::pair<size_t, double>> color_extruderid_to_used_weight;
|
||||
double total_wipe_tower_cost;
|
||||
double total_wipe_tower_filament;
|
||||
std::map<size_t, float> filament_stats;
|
||||
|
@ -1241,10 +1241,36 @@ void Sidebar::update_sliced_info_sizer()
|
||||
(ps.total_used_filament - ps.total_wipe_tower_filament) / 1000,
|
||||
ps.total_wipe_tower_filament / 1000) :
|
||||
wxString::Format("%.2f", ps.total_used_filament / 1000);
|
||||
if (ps.color_extruderid_to_used_filament.size() > 0) {
|
||||
double total_length = 0;
|
||||
for (int i = 0; i < ps.color_extruderid_to_used_filament.size(); i++) {
|
||||
new_label+= from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % i ).str());
|
||||
total_length += ps.color_extruderid_to_used_filament[i].second;
|
||||
info_text += wxString::Format("\n%.2f (%.2f)", ps.color_extruderid_to_used_filament[i].second / 1000, total_length / 1000);
|
||||
}
|
||||
new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % ps.color_extruderid_to_used_filament.size()).str());
|
||||
info_text += wxString::Format("\n%.2f (%.2f)", (ps.total_used_filament - total_length) / 1000, ps.total_used_filament / 1000);
|
||||
}
|
||||
p->sliced_info->SetTextAndShow(siFilament_m, info_text, new_label);
|
||||
|
||||
p->sliced_info->SetTextAndShow(siFilament_mm3, wxString::Format("%.2f", ps.total_extruded_volume));
|
||||
p->sliced_info->SetTextAndShow(siFilament_g, ps.total_weight == 0.0 ? "N/A" : wxString::Format("%.2f", ps.total_weight));
|
||||
|
||||
if (ps.color_extruderid_to_used_weight.size() > 0 && ps.total_weight != 0) {
|
||||
new_label = _(L("Used Filament (g)"));
|
||||
info_text = wxString::Format("%.2f", ps.total_weight);
|
||||
double total_weight = 0;
|
||||
for (int i = 0; i < ps.color_extruderid_to_used_weight.size(); i++) {
|
||||
new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % i).str());
|
||||
total_weight += ps.color_extruderid_to_used_weight[i].second;
|
||||
info_text += (ps.color_extruderid_to_used_weight[i].second == 0 ? "\nN/A": wxString::Format("\n%.2f", ps.color_extruderid_to_used_weight[i].second / 1000))
|
||||
+ (total_weight == 0 ? " (N/A)" : wxString::Format(" (%.2f)", total_weight / 1000));
|
||||
}
|
||||
new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % ps.color_extruderid_to_used_weight.size()).str());
|
||||
info_text += ((ps.total_weight - total_weight / 1000) == 0 ? "\nN/A" : wxString::Format("\n%.2f", (ps.total_weight - total_weight / 1000)))
|
||||
+ wxString::Format(" (%.2f)", ps.total_weight);
|
||||
p->sliced_info->SetTextAndShow(siFilament_g, info_text, new_label);
|
||||
}else
|
||||
p->sliced_info->SetTextAndShow(siFilament_g, ps.total_weight == 0.0 ? "N/A" : wxString::Format("%.2f", ps.total_weight), _(L("Used Filament (g)")));
|
||||
|
||||
new_label = _(L("Cost"));
|
||||
if (is_wipe_tower)
|
||||
|
Loading…
x
Reference in New Issue
Block a user