diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 79a5f7636..9cfd0e1b4 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -12,7 +12,7 @@ PrintGCode::output() time_t rawtime; tm * timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); - + fh << "; generated by Slic3r " << SLIC3R_VERSION << " on "; fh << asctime(timeinfo) << "\n"; fh << "; Git Commit: " << BUILD_COMMIT << "\n\n"; @@ -107,7 +107,7 @@ PrintGCode::output() if (config.has_heatbed && temp > 0 && std::regex_search(config.start_gcode.getString(), bed_temp_regex)) { fh << _gcodegen.writer.set_bed_temperature(temp, 1); } - + // Set extruder(s) temperature before and after start gcode. auto include_start_extruder_temp = !std::regex_search(config.start_gcode.getString(), ex_temp_regex); for(const auto& start_gcode : config.start_filament_gcode.values) { @@ -130,7 +130,7 @@ PrintGCode::output() fh << apply_math(_gcodegen.placeholder_parser->process(start_gcode)); } } - + if (include_start_extruder_temp) this->_print_first_layer_temperature(1); @@ -149,7 +149,7 @@ PrintGCode::output() const ExPolygons& slice { layer->slices }; std::for_each(slice.cbegin(), slice.cend(), [&polygons] (const ExPolygon& a) { polygons.emplace_back(a.contour); }); } - + if (polygons.size() == 0) continue; for (auto copy : object->_shifted_copies) { @@ -158,10 +158,10 @@ PrintGCode::output() islands_p.insert(islands_p.cend(), copy_islands_p.begin(), copy_islands_p.end()); } } - + _gcodegen.avoid_crossing_perimeters.init_external_mp(union_ex(islands_p)); } - + const auto extruders = _print.extruders(); // Calculate wiping points if needed. @@ -178,12 +178,12 @@ PrintGCode::output() $s->translate(-scale($extruder_offset->x), -scale($extruder_offset->y)); #) } my $convex_hull = convex_hull([ map @$_, @skirts ]); - + $gcodegen->ooze_prevention->set_enable(1); $gcodegen->ooze_prevention->set_standby_points( [ map @{$_->equally_spaced_points(scale 10)}, @{offset([$convex_hull], scale 3)} ] ); - + if (0) { require "Slic3r/SVG.pm"; Slic3r::SVG::output( @@ -209,7 +209,7 @@ PrintGCode::output() return (a->config.sequential_print_priority < a->config.sequential_print_priority) || (a->size.z < b->size.z); }); size_t finished_objects {0}; - + for (size_t obj_idx {0}; obj_idx < _print.objects.size(); ++obj_idx) { PrintObject& object {*(this->objects.at(obj_idx))}; for (const Point& copy : object._shifted_copies) { @@ -240,7 +240,7 @@ PrintGCode::output() if (layer->id() == 0 && finished_objects > 0) { if (config.first_layer_bed_temperature > 0 && config.has_heatbed && - std::regex_search(config.between_objects_gcode.getString(), bed_temp_regex)) + std::regex_search(config.between_objects_gcode.getString(), bed_temp_regex)) { fh << _gcodegen.writer.set_bed_temperature(config.first_layer_bed_temperature); } @@ -259,7 +259,7 @@ PrintGCode::output() // order objects using a nearest neighbor search std::vector obj_idx {}; Points p; - for (const auto obj : this->objects ) + for (const auto obj : this->objects ) p.emplace_back(obj->_shifted_copies.at(0)); Geometry::chained_path(p, obj_idx); @@ -271,7 +271,7 @@ PrintGCode::output() // sort layers by Z into buckets for (Layer* layer : object.layers) { if (layers.count(scale_(layer->print_z)) == 0) { // initialize bucket if empty - + layers[scale_(layer->print_z)] = std::map(); layers[scale_(layer->print_z)][idx] = LayerPtrs(); z.emplace_back(scale_(layer->print_z)); @@ -299,7 +299,7 @@ PrintGCode::output() _gcodegen.placeholder_parser->set("layer_z", unscale(print_z)); _gcodegen.placeholder_parser->set("layer_num", _gcodegen.layer_index); } - + this->flush_filters(); } @@ -328,7 +328,7 @@ PrintGCode::output() _print.total_weight = 0.0; _print.total_cost = 0.0; - + for (auto extruder_pair : _gcodegen.writer.extruders) { const Extruder& extruder { extruder_pair.second }; const auto used_material = extruder.used_filament(); @@ -340,24 +340,24 @@ PrintGCode::output() fh << "; material used = "; fh << std::fixed << std::setprecision(2) << used_material << "mm "; - fh << "(" << std::fixed << std::setprecision(2) - << extruded_volume / 1000.0 + fh << "(" << std::fixed << std::setprecision(2) + << extruded_volume / 1000.0 << used_material << "cm3)\n"; if (material_weight > 0) { _print.total_weight += material_weight; - fh << "; material used = " + fh << "; material used = " << std::fixed << std::setprecision(2) << material_weight << "g\n"; if (material_cost > 0) { _print.total_cost += material_cost; - fh << "; material cost = " + fh << "; material cost = " << std::fixed << std::setprecision(2) << material_weight << "g\n"; } } _print.total_used_filament += used_material; _print.total_extruded_volume += extruded_volume; } - fh << "; total filament cost = " + fh << "; total filament cost = " << std::fixed << std::setprecision(2) << _print.total_cost << "\n"; // Append full config @@ -369,8 +369,8 @@ PrintGCode::output() _print_config(_print.default_region_config); } -std::string -PrintGCode::filter(const std::string& in, bool wait) +std::string +PrintGCode::filter(const std::string& in, bool wait) { return in; } @@ -385,12 +385,12 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) // check for usage of spiralvase logic. this->_spiral_vase.enable = ( - layer->id() > 0 + layer->id() > 0 && (_print.config.skirts == 0 || (layer->id() >= _print.config.skirt_height && !_print.has_infinite_skirt())) - && std::find_if(layer->regions.cbegin(), layer->regions.cend(), [layer] (const LayerRegion* l) - { return l->region()->config.bottom_solid_layers > layer->id() - || l->perimeters.items_count() > 1 - || l->fills.items_count() > 0; + && std::find_if(layer->regions.cbegin(), layer->regions.cend(), [layer] (const LayerRegion* l) + { return l->region()->config.bottom_solid_layers > layer->id() + || l->perimeters.items_count() > 1 + || l->fills.items_count() > 0; }) == layer->regions.cend() ); this->_gcodegen.enable_loop_clipping = this->_spiral_vase.enable; @@ -410,7 +410,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) if (!(region->config.get_abs_value("perimeter_speed") > 0 && region->config.get_abs_value("small_perimeter_speed") > 0 && region->config.get_abs_value("external_perimeter_speed") > 0 && - region->config.get_abs_value("bridge_speed") > 0)) + region->config.get_abs_value("bridge_speed") > 0)) { mm3_per_mm.emplace_back(layerm->perimeters.min_mm3_per_mm()); } @@ -418,14 +418,14 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) region->config.get_abs_value("solid_infill_speed") > 0 && region->config.get_abs_value("top_solid_infill_speed") > 0 && region->config.get_abs_value("bridge_speed") > 0 && - region->config.get_abs_value("gap_fill_speed") > 0)) // TODO: make this configurable? + region->config.get_abs_value("gap_fill_speed") > 0)) // TODO: make this configurable? { mm3_per_mm.emplace_back(layerm->fills.min_mm3_per_mm()); } } if (typeid(layer) == typeid(SupportLayer*)) { const SupportLayer* slayer = dynamic_cast(layer); - if (!(obj.config.get_abs_value("support_material_speed") > 0 && + if (!(obj.config.get_abs_value("support_material_speed") > 0 && obj.config.get_abs_value("support_material_interface_speed") > 0)) { mm3_per_mm.emplace_back(slayer->support_fills.min_mm3_per_mm()); @@ -440,8 +440,8 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) if (mm3_per_mm.size() > 0) { const double min_mm3_per_mm { *(std::min_element(mm3_per_mm.begin(), mm3_per_mm.end())) }; // In order to honor max_print_speed we need to find a target volumetric - // speed that we can use throughout the _print. So we define this target - // volumetric speed as the volumetric speed produced by printing the + // speed that we can use throughout the _print. So we define this target + // volumetric speed as the volumetric speed produced by printing the // smallest cross-section at the maximum speed: any larger cross-section // will need slower feedrates. double volumetric_speed { min_mm3_per_mm * config.max_print_speed }; @@ -488,7 +488,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) gcode += "\n"; } - + // extrude skirt along raft layers and normal obj layers // (not along interlaced support material layers) if (layer->id() < static_cast(obj.config.raft_layers) @@ -499,11 +499,11 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) _gcodegen.set_origin(Pointf(0,0)); _gcodegen.avoid_crossing_perimeters.use_external_mp = true; - - /// data load + + /// data load std::vector extruder_ids; extruder_ids.reserve(_gcodegen.writer.extruders.size()); - std::transform(_gcodegen.writer.extruders.cbegin(), _gcodegen.writer.extruders.cend(), std::back_inserter(extruder_ids), + std::transform(_gcodegen.writer.extruders.cbegin(), _gcodegen.writer.extruders.cend(), std::back_inserter(extruder_ids), [] (const std::pair& z) -> std::size_t { return z.second.id; } ); gcode += _gcodegen.set_extruder(extruder_ids.at(0)); @@ -514,10 +514,10 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) // distribute skirt loops across all extruders in layer 0 const auto skirt_loops = _print.skirt.flatten().entities; for (size_t i = 0; i < skirt_loops.size(); ++i) { - - // when printing layers > 0 ignore 'min_skirt_length' and + + // when printing layers > 0 ignore 'min_skirt_length' and // just use the 'skirts' setting; also just use the current extruder - if (layer->id() > 0 && i >= static_cast(_print.config.skirts)) break; + if (layer->id() > 0 && i >= static_cast(_print.config.skirts)) break; const size_t extruder_id { extruder_ids.at((i / extruder_ids.size()) % extruder_ids.size()) }; if (layer->id() == 0) gcode += _gcodegen.set_extruder(extruder_id); @@ -540,7 +540,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } - this->_skirt_done[scale_(layer->print_z)] = true; + this->_skirt_done[scale_(layer->print_z)] = true; _gcodegen.avoid_crossing_perimeters.use_external_mp = false; if (layer->id() == 0) _gcodegen.avoid_crossing_perimeters.disable_once = true; @@ -556,7 +556,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } this->_brim_done = true; _gcodegen.avoid_crossing_perimeters.use_external_mp = false; - + // allow a straight travel move to the first object point _gcodegen.avoid_crossing_perimeters.disable_once = true; } @@ -564,7 +564,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) auto copy_idx = 0U; for (const auto& copy : copies) { if (config.label_printed_objects) { - gcode += "; printing object " + obj.model_object().name + " id:" + std::to_string(idx) + " copy " + std::to_string(copy_idx) + "\n"; + gcode += "; printing object " + obj.model_object().name + " id:" + std::to_string(idx) + " copy " + std::to_string(copy_idx) + "\n"; } // when starting a new object, use the external motion planner for the first travel move @@ -578,7 +578,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) // and also because we avoid travelling on other things when printing it if(layer->is_support()) { const SupportLayer* slayer = dynamic_cast(layer); - ExtrusionEntityCollection paths; + ExtrusionEntityCollection paths; if (slayer->support_interface_fills.size() > 0) { gcode += _gcodegen.set_extruder(obj.config.support_material_interface_extruder - 1); slayer->support_interface_fills.chained_path_from(_gcodegen.last_pos(), &paths, false); @@ -594,8 +594,8 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } } } - // We now define a strategy for building perimeters and fills. The separation - // between regions doesn't matter in terms of printing order, as we follow + // We now define a strategy for building perimeters and fills. The separation + // between regions doesn't matter in terms of printing order, as we follow // another logic instead: // - we group all extrusions by extruder so that we minimize toolchanges // - we start from the last used extruder @@ -636,7 +636,7 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) for(const auto* perimeter_coll : layerm->perimeters.flatten().entities) { if(perimeter_coll->length() == 0) continue; // this shouldn't happen but first_point() would fail - + // perimeter_coll is an ExtrusionPath::Collection object representing a single slice for(auto i = 0U; i < n_slices; i++){ if (// perimeter_coll->first_point does not fit inside any slice @@ -649,19 +649,19 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } } } - + // process infill // $layerm->fills is a collection of ExtrusionPath::Collection objects, each one containing // the ExtrusionPath objects of a certain infill "group" (also called "surface" - // throughout the code). We can redefine the order of such Collections but we have to + // throughout the code). We can redefine the order of such Collections but we have to // do each one completely at once. for(auto* fill : layerm->fills.flatten().entities) { if(fill->length() == 0) continue; // this shouldn't happen but first_point() would fail - + auto extruder_id = fill->is_solid_infill() ? region->config.solid_infill_extruder-1 : region->config.infill_extruder-1; - + // $fill is an ExtrusionPath::Collection object for(auto i = 0U; i < n_slices; i++){ if (i == n_slices - 1 @@ -672,9 +672,9 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } } } - + // tweak extruder ordering to save toolchanges - + auto last_extruder = _gcodegen.writer.extruder()->id; if (by_extruder.count(last_extruder)) { for(auto &island : by_extruder[last_extruder]) { @@ -707,14 +707,14 @@ PrintGCode::process_layer(size_t idx, const Layer* layer, const Points& copies) } // Apply spiral vase post-processing if this layer contains suitable geometry - // (we must feed all the G-code into the post-processor, including the first + // (we must feed all the G-code into the post-processor, including the first // bottom non-spiral layers otherwise it will mess with positions) // we apply spiral vase at this stage because it requires a full layer gcode = this->_spiral_vase.process_layer(gcode); // Apply the cooling logic. - gcode = this->_cooling_buffer.append(gcode, std::to_string(reinterpret_cast(layer->object())) + std::string(typeid(layer).name()), + gcode = this->_cooling_buffer.append(gcode, std::to_string(reinterpret_cast(layer->object())) + std::string(typeid(layer).name()), layer->id(), layer->print_z); - + // write the resulting gcode fh << this->filter(gcode); } @@ -752,7 +752,7 @@ PrintGCode::_extrude_infill(std::map &by_regio void -PrintGCode::_print_first_layer_temperature(bool wait) +PrintGCode::_print_first_layer_temperature(bool wait) { for (auto& t : _print.extruders()) { auto temp = config.first_layer_temperature.get_at(t); @@ -761,7 +761,7 @@ PrintGCode::_print_first_layer_temperature(bool wait) } } -void +void PrintGCode::_print_config(const ConfigBase& config) { for (const auto& key : config.keys()) { @@ -771,26 +771,26 @@ PrintGCode::_print_config(const ConfigBase& config) } } -PrintGCode::PrintGCode(Slic3r::Print& print, std::ostream& _fh) : - _print(print), - config(_print.config), +PrintGCode::PrintGCode(Slic3r::Print& print, std::ostream& _fh) : + _print(print), + config(_print.config), _gcodegen(Slic3r::GCode()), objects(_print.objects), fh(_fh), _cooling_buffer(Slic3r::CoolingBuffer(this->_gcodegen)), _spiral_vase(Slic3r::SpiralVase(this->config)) -{ +{ size_t layer_count {0}; if (config.complete_objects) { layer_count = std::accumulate(objects.cbegin(), objects.cend(), layer_count, [](const size_t& ret, const PrintObject* obj){ return ret + (obj->copies().size() * obj->total_layer_count()); }); } else { layer_count = std::accumulate(objects.cbegin(), objects.cend(), layer_count, [](const size_t& ret, const PrintObject* obj){ return ret + obj->total_layer_count(); }); } - _gcodegen.placeholder_parser = &(_print.placeholder_parser); // initialize + _gcodegen.placeholder_parser = &(_print.placeholder_parser); // initialize _gcodegen.layer_count = layer_count; _gcodegen.enable_cooling_markers = true; _gcodegen.apply_print_config(config); - + if (config.spiral_vase) _spiral_vase.enable = true; const auto extruders = _print.extruders(); diff --git a/xs/src/libslic3r/PrintGCode.hpp b/xs/src/libslic3r/PrintGCode.hpp index 9f0b4006f..a82c8dcda 100644 --- a/xs/src/libslic3r/PrintGCode.hpp +++ b/xs/src/libslic3r/PrintGCode.hpp @@ -32,7 +32,7 @@ public: std::string filter(const std::string& in, bool wait = false); private: - + Slic3r::Print& _print; const Slic3r::PrintConfig& config; @@ -48,7 +48,7 @@ private: // Slic3r::ArcFitting _arc_fitting; // Slic3r::PressureRegulator _pressure_regulator; - /// presence in the array indicates that the + /// presence in the array indicates that the std::map _skirt_done {}; bool _brim_done {false}; bool _second_layer_things_done {false};