Merge branch 'lm_total_toolchanges'

This commit is contained in:
Lukas Matena 2023-11-02 14:00:27 +01:00
commit 9ca4017a8d
6 changed files with 31 additions and 7 deletions

View File

@ -720,6 +720,7 @@ namespace DoExport {
const FullPrintConfig &config, const FullPrintConfig &config,
const std::vector<Extruder> &extruders, const std::vector<Extruder> &extruders,
unsigned int initial_extruder_id, unsigned int initial_extruder_id,
int total_toolchanges,
PrintStatistics &print_statistics, PrintStatistics &print_statistics,
bool export_binary_data, bool export_binary_data,
bgcode::binarize::BinaryData &binary_data) bgcode::binarize::BinaryData &binary_data)
@ -727,7 +728,7 @@ namespace DoExport {
std::string filament_stats_string_out; std::string filament_stats_string_out;
print_statistics.clear(); print_statistics.clear();
print_statistics.total_toolchanges = std::max(0, wipe_tower_data.number_of_toolchanges); print_statistics.total_toolchanges = total_toolchanges;
print_statistics.initial_extruder_id = initial_extruder_id; print_statistics.initial_extruder_id = initial_extruder_id;
std::vector<std::string> filament_types; std::vector<std::string> filament_types;
if (! extruders.empty()) { if (! extruders.empty()) {
@ -1161,7 +1162,7 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail
// For the start / end G-code to do the priming and final filament pull in case there is no wipe tower provided. // For the start / end G-code to do the priming and final filament pull in case there is no wipe tower provided.
this->placeholder_parser().set("has_wipe_tower", has_wipe_tower); this->placeholder_parser().set("has_wipe_tower", has_wipe_tower);
this->placeholder_parser().set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming); this->placeholder_parser().set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming);
this->placeholder_parser().set("total_toolchanges", std::max(0, print.wipe_tower_data().number_of_toolchanges)); // Check for negative toolchanges (single extruder mode) and set to 0 (no tool change). this->placeholder_parser().set("total_toolchanges", tool_ordering.toolchanges_count());
{ {
BoundingBoxf bbox(print.config().bed_shape.values); BoundingBoxf bbox(print.config().bed_shape.values);
assert(bbox.defined); assert(bbox.defined);
@ -1389,6 +1390,7 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail
this->config(), this->config(),
m_writer.extruders(), m_writer.extruders(),
initial_extruder_id, initial_extruder_id,
tool_ordering.toolchanges_count(),
// Modifies // Modifies
print.m_print_statistics, print.m_print_statistics,
export_to_binary_gcode, export_to_binary_gcode,

View File

@ -479,6 +479,9 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_
bool ToolOrdering::insert_wipe_tower_extruder() bool ToolOrdering::insert_wipe_tower_extruder()
{ {
if (!m_print_config_ptr->wipe_tower)
return false;
// In case that wipe_tower_extruder is set to non-zero, we must make sure that the extruder will be in the list. // In case that wipe_tower_extruder is set to non-zero, we must make sure that the extruder will be in the list.
bool changed = false; bool changed = false;
if (m_print_config_ptr->wipe_tower_extruder != 0) { if (m_print_config_ptr->wipe_tower_extruder != 0) {
@ -836,4 +839,20 @@ void WipingExtrusions::ensure_perimeters_infills_order(const Print& print, const
} }
} }
int ToolOrdering::toolchanges_count() const
{
std::vector<unsigned int> tools_in_order;
for (const LayerTools& lt : m_layer_tools)
tools_in_order.insert(tools_in_order.end(), lt.extruders.begin(), lt.extruders.end());
assert(std::find(tools_in_order.begin(), tools_in_order.end(), (unsigned int)(-1)) == tools_in_order.end());
for (size_t i=1; i<tools_in_order.size(); ++i)
if (tools_in_order[i] == tools_in_order[i-1])
tools_in_order[i-1] = (unsigned int)(-1);
tools_in_order.erase(std::remove(tools_in_order.begin(), tools_in_order.end(), (unsigned int)(-1)), tools_in_order.end());
if (tools_in_order.size() > 1 && tools_in_order.back() == tools_in_order[tools_in_order.size()-2])
tools_in_order.pop_back();
return std::max(0, int(tools_in_order.size())-1); // 5 tools = 4 toolchanges
}
} // namespace Slic3r } // namespace Slic3r

View File

@ -165,6 +165,7 @@ public:
bool empty() const { return m_layer_tools.empty(); } bool empty() const { return m_layer_tools.empty(); }
std::vector<LayerTools>& layer_tools() { return m_layer_tools; } std::vector<LayerTools>& layer_tools() { return m_layer_tools; }
bool has_wipe_tower() const { return ! m_layer_tools.empty() && m_first_printing_extruder != (unsigned int)-1 && m_layer_tools.front().wipe_tower_partitions > 0; } bool has_wipe_tower() const { return ! m_layer_tools.empty() && m_first_printing_extruder != (unsigned int)-1 && m_layer_tools.front().wipe_tower_partitions > 0; }
int toolchanges_count() const;
private: private:
void initialize_layers(std::vector<coordf_t> &zs); void initialize_layers(std::vector<coordf_t> &zs);

View File

@ -793,12 +793,13 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool)
.set_initial_tool(m_current_tool) .set_initial_tool(m_current_tool)
.set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f))
.append(";--------------------\n" .append(";--------------------\n"
"; CP TOOLCHANGE START\n") "; CP TOOLCHANGE START\n");
.comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based
if (tool != (unsigned)(-1)) if (tool != (unsigned)(-1)) {
writer.comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based
writer.append(std::string("; material : " + (m_current_tool < m_filpar.size() ? m_filpar[m_current_tool].material : "(NONE)") + " -> " + m_filpar[tool].material + "\n").c_str()) writer.append(std::string("; material : " + (m_current_tool < m_filpar.size() ? m_filpar[m_current_tool].material : "(NONE)") + " -> " + m_filpar[tool].material + "\n").c_str())
.append(";--------------------\n"); .append(";--------------------\n");
}
writer.speed_override_backup(); writer.speed_override_backup();
writer.speed_override(100); writer.speed_override(100);

View File

@ -474,7 +474,9 @@ struct WipeTowerData
used_filament.clear(); used_filament.clear();
number_of_toolchanges = -1; number_of_toolchanges = -1;
depth = 0.f; depth = 0.f;
z_and_depth_pairs.clear();
brim_width = 0.f; brim_width = 0.f;
height = 0.f;
width = 0.f; width = 0.f;
first_layer_height = 0.f; first_layer_height = 0.f;
cone_angle = 0.f; cone_angle = 0.f;

View File

@ -1502,8 +1502,7 @@ void Sidebar::update_sliced_info_sizer()
p->sliced_info->SetTextAndShow(siEstimatedTime, info_text, new_label); p->sliced_info->SetTextAndShow(siEstimatedTime, info_text, new_label);
} }
// if there is a wipe tower, insert number of toolchanges info into the array: p->sliced_info->SetTextAndShow(siWTNumbetOfToolchanges, ps.total_toolchanges > 0 ? wxString::Format("%.d", ps.total_toolchanges) : "N/A");
p->sliced_info->SetTextAndShow(siWTNumbetOfToolchanges, is_wipe_tower ? wxString::Format("%.d", ps.total_toolchanges) : "N/A");
// Hide non-FFF sliced info parameters // Hide non-FFF sliced info parameters
p->sliced_info->SetTextAndShow(siMateril_unit, "N/A"); p->sliced_info->SetTextAndShow(siMateril_unit, "N/A");