mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 16:05: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_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
|
||||||
m_last_width = GCodeAnalyzer::Default_Width;
|
m_last_width = GCodeAnalyzer::Default_Width;
|
||||||
m_last_height = GCodeAnalyzer::Default_Height;
|
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?
|
// How many times will be change_layer() called?
|
||||||
// change_layer() in turn increments the progress bar status.
|
// 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) {
|
for (const LayerToPrint <p : layers_to_print) {
|
||||||
std::vector<LayerToPrint> lrs;
|
std::vector<LayerToPrint> lrs;
|
||||||
lrs.emplace_back(std::move(ltp));
|
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();
|
print.throw_if_canceled();
|
||||||
}
|
}
|
||||||
#ifdef HAS_PRESSURE_EQUALIZER
|
#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);
|
const LayerTools &layer_tools = tool_ordering.tools_for_layer(layer.first);
|
||||||
if (m_wipe_tower && layer_tools.has_wipe_tower)
|
if (m_wipe_tower && layer_tools.has_wipe_tower)
|
||||||
m_wipe_tower->next_layer();
|
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();
|
print.throw_if_canceled();
|
||||||
}
|
}
|
||||||
#ifdef HAS_PRESSURE_EQUALIZER
|
#ifdef HAS_PRESSURE_EQUALIZER
|
||||||
@ -1809,81 +1811,97 @@ std::vector<GCode::InstanceToPrint> GCode::sort_print_object_instances(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ProcessLayer
|
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,
|
||||||
|
const Print &print,
|
||||||
|
PrintStatistics &stats)
|
||||||
{
|
{
|
||||||
|
bool single_extruder_printer = print.config().nozzle_diameter.size() == 1;
|
||||||
|
std::string gcode;
|
||||||
|
|
||||||
static std::string emit_custom_gcode_per_print_z(
|
if (custom_gcode != nullptr) {
|
||||||
const CustomGCode::Item *custom_gcode,
|
// Extruder switches are processed by LayerTools, they should be filtered out.
|
||||||
// ID of the first extruder printing this layer.
|
assert(custom_gcode->gcode != ToolChangeCode);
|
||||||
unsigned int first_extruder_id,
|
|
||||||
bool single_extruder_printer)
|
|
||||||
{
|
|
||||||
std::string gcode;
|
|
||||||
|
|
||||||
if (custom_gcode != nullptr) {
|
const std::string &custom_code = custom_gcode->gcode;
|
||||||
// Extruder switches are processed by LayerTools, they should be filtered out.
|
bool color_change = custom_code == ColorChangeCode;
|
||||||
assert(custom_gcode->gcode != ToolChangeCode);
|
bool tool_change = custom_code == ToolChangeCode;
|
||||||
|
// Tool Change is applied as Color Change for a single extruder printer only.
|
||||||
|
assert(! tool_change || single_extruder_printer);
|
||||||
|
|
||||||
const std::string &custom_code = custom_gcode->gcode;
|
std::string pause_print_msg;
|
||||||
bool color_change = custom_code == ColorChangeCode;
|
int m600_extruder_before_layer = -1;
|
||||||
bool tool_change = custom_code == ToolChangeCode;
|
if (color_change && custom_gcode->extruder > 0)
|
||||||
// Tool Change is applied as Color Change for a single extruder printer only.
|
m600_extruder_before_layer = custom_gcode->extruder - 1;
|
||||||
assert(! tool_change || single_extruder_printer);
|
else if (custom_code == PausePrintCode)
|
||||||
|
pause_print_msg = custom_gcode->color;
|
||||||
|
|
||||||
std::string pause_print_msg;
|
if (color_change) {
|
||||||
int m600_extruder_before_layer = -1;
|
//update stats : weight
|
||||||
if (color_change && custom_gcode->extruder > 0)
|
double previously_extruded = 0;
|
||||||
m600_extruder_before_layer = custom_gcode->extruder - 1;
|
for (const auto& tuple : stats.color_extruderid_to_used_weight)
|
||||||
else if (custom_code == PausePrintCode)
|
if (tuple.first == this->m_writer.extruder()->id())
|
||||||
pause_print_msg = custom_gcode->color;
|
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);
|
||||||
|
|
||||||
// we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count
|
//update stats : length
|
||||||
if (color_change || tool_change)
|
previously_extruded = 0;
|
||||||
{
|
for (const auto& tuple : stats.color_extruderid_to_used_filament)
|
||||||
// Color Change or Tool Change as Color Change.
|
if (tuple.first == this->m_writer.extruder()->id())
|
||||||
// add tag for analyzer
|
previously_extruded += tuple.second;
|
||||||
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
|
stats.color_extruderid_to_used_filament.emplace_back(this->m_writer.extruder()->id(), this->m_writer.extruder()->used_filament() - previously_extruded);
|
||||||
// add tag for time estimator
|
}
|
||||||
gcode += "; " + GCodeTimeEstimator::Color_Change_Tag + "\n";
|
|
||||||
|
|
||||||
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != m600_extruder_before_layer
|
// we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count
|
||||||
// && !MMU1
|
if (color_change || tool_change)
|
||||||
) {
|
{
|
||||||
//! FIXME_in_fw show message during print pause
|
|
||||||
gcode += "M601\n"; // pause print
|
|
||||||
gcode += "M117 Change filament for Extruder " + std::to_string(m600_extruder_before_layer) + "\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gcode += ColorChangeCode;
|
|
||||||
gcode += "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (custom_code == PausePrintCode) // Pause print
|
|
||||||
{
|
|
||||||
// add tag for analyzer
|
|
||||||
gcode += "; " + GCodeAnalyzer::Pause_Print_Tag + "\n";
|
|
||||||
//! FIXME_in_fw show message during print pause
|
|
||||||
if (!pause_print_msg.empty())
|
|
||||||
gcode += "M117 " + pause_print_msg + "\n";
|
|
||||||
// add tag for time estimator
|
|
||||||
gcode += "; " + GCodeTimeEstimator::Pause_Print_Tag + "\n";
|
|
||||||
}
|
|
||||||
else // custom Gcode
|
|
||||||
{
|
|
||||||
// add tag for analyzer
|
|
||||||
gcode += "; " + GCodeAnalyzer::Custom_Code_Tag + "\n";
|
|
||||||
// add tag for time estimator
|
|
||||||
//gcode += "; " + GCodeTimeEstimator::Custom_Code_Tag + "\n";
|
|
||||||
}
|
|
||||||
gcode += custom_code + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return gcode;
|
// Color Change or Tool Change as Color Change.
|
||||||
}
|
// add tag for analyzer
|
||||||
} // namespace ProcessLayer
|
gcode += "; " + GCodeAnalyzer::Color_Change_Tag + ",T" + std::to_string(m600_extruder_before_layer) + "\n";
|
||||||
|
// add tag for time estimator
|
||||||
|
gcode += "; " + GCodeTimeEstimator::Color_Change_Tag + "\n";
|
||||||
|
|
||||||
|
if (!single_extruder_printer && m600_extruder_before_layer >= 0 && first_extruder_id != m600_extruder_before_layer
|
||||||
|
// && !MMU1
|
||||||
|
) {
|
||||||
|
//! FIXME_in_fw show message during print pause
|
||||||
|
gcode += "M601\n"; // pause print
|
||||||
|
gcode += "M117 Change filament for Extruder " + std::to_string(m600_extruder_before_layer) + "\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gcode += ColorChangeCode;
|
||||||
|
gcode += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (custom_code == PausePrintCode) // Pause print
|
||||||
|
{
|
||||||
|
// add tag for analyzer
|
||||||
|
gcode += "; " + GCodeAnalyzer::Pause_Print_Tag + "\n";
|
||||||
|
//! FIXME_in_fw show message during print pause
|
||||||
|
if (!pause_print_msg.empty())
|
||||||
|
gcode += "M117 " + pause_print_msg + "\n";
|
||||||
|
// add tag for time estimator
|
||||||
|
gcode += "; " + GCodeTimeEstimator::Pause_Print_Tag + "\n";
|
||||||
|
}
|
||||||
|
else // custom Gcode
|
||||||
|
{
|
||||||
|
// add tag for analyzer
|
||||||
|
gcode += "; " + GCodeAnalyzer::Custom_Code_Tag + "\n";
|
||||||
|
// add tag for time estimator
|
||||||
|
//gcode += "; " + GCodeTimeEstimator::Custom_Code_Tag + "\n";
|
||||||
|
}
|
||||||
|
gcode += custom_code + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Skirt {
|
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)
|
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)
|
||||||
@ -1956,11 +1974,12 @@ namespace Skirt {
|
|||||||
// and performing the extruder specific extrusions together.
|
// and performing the extruder specific extrusions together.
|
||||||
void GCode::process_layer(
|
void GCode::process_layer(
|
||||||
// Write into the output file.
|
// Write into the output file.
|
||||||
FILE *file,
|
FILE *file,
|
||||||
const Print &print,
|
const Print &print,
|
||||||
|
PrintStatistics &print_stat,
|
||||||
// Set of object & print layers of the same PrintObject and with the same print_z.
|
// Set of object & print layers of the same PrintObject and with the same print_z.
|
||||||
const std::vector<LayerToPrint> &layers,
|
const std::vector<LayerToPrint> &layers,
|
||||||
const LayerTools &layer_tools,
|
const LayerTools &layer_tools,
|
||||||
// Pairs of PrintObject index and its instance index.
|
// Pairs of PrintObject index and its instance index.
|
||||||
const std::vector<const PrintInstance*> *ordering,
|
const std::vector<const PrintInstance*> *ordering,
|
||||||
// If set to size_t(-1), then print all copies of all objects.
|
// If set to size_t(-1), then print all copies of all objects.
|
||||||
@ -2054,7 +2073,7 @@ void GCode::process_layer(
|
|||||||
|
|
||||||
if (single_object_instance_idx == size_t(-1)) {
|
if (single_object_instance_idx == size_t(-1)) {
|
||||||
// Normal (non-sequential) print.
|
// 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
|
// 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.
|
// not at the print_z of the interlaced support material layers.
|
||||||
|
@ -200,6 +200,9 @@ public:
|
|||||||
// append full config to the given string
|
// append full config to the given string
|
||||||
static void append_full_config(const Print& print, std::string& str);
|
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.
|
// 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
|
// public, so that it could be accessed by free helper functions from GCode.cpp
|
||||||
struct LayerToPrint
|
struct LayerToPrint
|
||||||
@ -225,6 +228,7 @@ private:
|
|||||||
// Write into the output file.
|
// Write into the output file.
|
||||||
FILE *file,
|
FILE *file,
|
||||||
const Print &print,
|
const Print &print,
|
||||||
|
PrintStatistics &print_stat,
|
||||||
// Set of object & print layers of the same PrintObject and with the same print_z.
|
// Set of object & print layers of the same PrintObject and with the same print_z.
|
||||||
const std::vector<LayerToPrint> &layers,
|
const std::vector<LayerToPrint> &layers,
|
||||||
const LayerTools &layer_tools,
|
const LayerTools &layer_tools,
|
||||||
|
@ -772,7 +772,7 @@ namespace Slic3r {
|
|||||||
std::vector<std::pair<CustomGcodeType, std::string>> ret;
|
std::vector<std::pair<CustomGcodeType, std::string>> ret;
|
||||||
|
|
||||||
float total_time = 0.0f;
|
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);
|
std::string time = _get_time_dhm(t.second);
|
||||||
if (include_remaining)
|
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_normal_custom_gcode_print_times;
|
||||||
std::vector<std::pair<CustomGcodeType, std::string>> estimated_silent_custom_gcode_print_times;
|
std::vector<std::pair<CustomGcodeType, std::string>> estimated_silent_custom_gcode_print_times;
|
||||||
double total_used_filament;
|
double total_used_filament;
|
||||||
|
std::vector<std::pair<size_t, double>> color_extruderid_to_used_filament;
|
||||||
double total_extruded_volume;
|
double total_extruded_volume;
|
||||||
double total_cost;
|
double total_cost;
|
||||||
int total_toolchanges;
|
int total_toolchanges;
|
||||||
double total_weight;
|
double total_weight;
|
||||||
|
std::vector<std::pair<size_t, double>> color_extruderid_to_used_weight;
|
||||||
double total_wipe_tower_cost;
|
double total_wipe_tower_cost;
|
||||||
double total_wipe_tower_filament;
|
double total_wipe_tower_filament;
|
||||||
std::map<size_t, float> filament_stats;
|
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_used_filament - ps.total_wipe_tower_filament) / 1000,
|
||||||
ps.total_wipe_tower_filament / 1000) :
|
ps.total_wipe_tower_filament / 1000) :
|
||||||
wxString::Format("%.2f", ps.total_used_filament / 1000);
|
wxString::Format("%.2f", ps.total_used_filament / 1000);
|
||||||
p->sliced_info->SetTextAndShow(siFilament_m, info_text, new_label);
|
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_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"));
|
new_label = _(L("Cost"));
|
||||||
if (is_wipe_tower)
|
if (is_wipe_tower)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user