Wiping into infill should respect infill_first setting, marking moved to separate function

This commit is contained in:
Lukas Matena 2018-05-30 11:56:30 +02:00
parent 549351bbb4
commit 8bdbe41505
5 changed files with 64 additions and 45 deletions

View file

@ -1136,43 +1136,12 @@ void Print::_make_wipe_tower()
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, current_extruder_id,false);
for (const auto extruder_id : layer_tools.extruders) {
if ((first_layer && extruder_id == m_tool_ordering.all_extruders().back()) || extruder_id != current_extruder_id) {
float volume_to_wipe = wipe_volumes[current_extruder_id][extruder_id]; // total volume to wipe after this toolchange
// Toolchange from old_extruder to new_extruder.
// Check how much volume needs to be wiped and keep marking infills until
// we run out of the volume (or infills)
const float min_infill_volume = 0.f;
if (config.wipe_into_infill && !first_layer)
volume_to_wipe = mark_wiping_infill(layer_tools, extruder_id, wipe_volumes[current_extruder_id][extruder_id]);
float volume_to_wipe = wipe_volumes[current_extruder_id][extruder_id];
float saved_material = 0.f;
if (!first_layer && !config.filament_soluble.get_at(extruder_id)) { // soluble filament cannot be wiped in a random infill, first layer is potentionally visible too
for (size_t i = 0; i < objects.size(); ++ i) { // Let's iterate through all objects...
for (Layer* lay : objects[i]->layers) { // Find this layer
if (std::abs(layer_tools.print_z - lay->print_z) > EPSILON)
continue;
for (size_t region_id = 0; region_id < objects[i]->print()->regions.size(); ++ region_id) {
unsigned int region_extruder = objects[i]->print()->regions[region_id]->config.infill_extruder - 1; // config value is 1-based
if (config.filament_soluble.get_at(region_extruder)) // if this infill is meant to be soluble, keep it that way
continue;
ExtrusionEntityCollection& eec = lay->regions[region_id]->fills;
for (ExtrusionEntity* ee : eec.entities) { // and all infill Collections
auto* fill = dynamic_cast<ExtrusionEntityCollection*>(ee);
if (fill->role() == erTopSolidInfill) continue; // color of TopSolidInfill cannot be changed - it is visible
if (volume_to_wipe > 0.f && !fill->is_extruder_overridden() && fill->total_volume() > min_infill_volume) { // this infill will be used to wipe this extruder
fill->set_extruder_override(extruder_id);
volume_to_wipe -= fill->total_volume();
}
}
}
}
}
}
saved_material = wipe_volumes[current_extruder_id][extruder_id] - std::max(0.f, volume_to_wipe);
std::cout << layer_tools.print_z << "\t" << extruder_id << "\t" << wipe_volumes[current_extruder_id][extruder_id] - volume_to_wipe << "\n";
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, first_layer && extruder_id == m_tool_ordering.all_extruders().back(), saved_material);
wipe_tower.plan_toolchange(layer_tools.print_z, layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, first_layer && extruder_id == m_tool_ordering.all_extruders().back(), volume_to_wipe);
current_extruder_id = extruder_id;
}
}
@ -1205,6 +1174,52 @@ void Print::_make_wipe_tower()
wipe_tower.tool_change((unsigned int)-1, false));
}
float Print::mark_wiping_infill(const ToolOrdering::LayerTools& layer_tools, unsigned int new_extruder, float volume_to_wipe)
{
const float min_infill_volume = 0.f; // ignore infill with smaller volume than this
if (!config.filament_soluble.get_at(new_extruder)) { // Soluble filament cannot be wiped in a random infill
for (size_t i = 0; i < objects.size(); ++ i) { // Let's iterate through all objects...
Layer* this_layer = nullptr;
for (unsigned int a = 0; a < objects[i]->layers.size(); this_layer = objects[i]->layers[++a]) // Finds this layer
if (std::abs(layer_tools.print_z - objects[i]->layers[a]->print_z) < EPSILON)
break;
for (size_t region_id = 0; region_id < objects[i]->print()->regions.size(); ++ region_id) {
unsigned int region_extruder = objects[i]->print()->regions[region_id]->config.infill_extruder - 1; // config value is 1-based
if (config.filament_soluble.get_at(region_extruder)) // if this infill is meant to be soluble, keep it that way
continue;
if (!config.infill_first) { // in this case we must verify that region_extruder was already used at this layer (and perimeters of the infill are therefore extruded)
bool unused_yet = false;
for (unsigned i = 0; i < layer_tools.extruders.size(); ++i) {
if (layer_tools.extruders[i] == new_extruder)
unused_yet = true;
if (layer_tools.extruders[i] == region_extruder)
break;
}
if (unused_yet)
continue;
}
ExtrusionEntityCollection& eec = this_layer->regions[region_id]->fills;
for (ExtrusionEntity* ee : eec.entities) { // iterate through all infill Collections
auto* fill = dynamic_cast<ExtrusionEntityCollection*>(ee);
if (fill->role() == erTopSolidInfill) continue; // color of TopSolidInfill cannot be changed - it is visible
if (volume_to_wipe > 0.f && !fill->is_extruder_overridden() && fill->total_volume() > min_infill_volume) { // this infill will be used to wipe this extruder
fill->set_extruder_override(new_extruder);
volume_to_wipe -= fill->total_volume();
}
}
}
}
}
return std::max(0.f, volume_to_wipe);
}
std::string Print::output_filename()
{
this->placeholder_parser.update_timestamp();