Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::DoExport Namespace Reference

Functions

static void update_print_estimated_stats (const GCodeProcessor &processor, const std::vector< Extruder > &extruders, PrintStatistics &print_statistics)
 
static std::vector< std::pair< std::string, std::string > > validate_custom_gcode (const Print &print)
 
static void init_gcode_processor (const PrintConfig &config, GCodeProcessor &processor, bool &silent_time_estimator_enabled)
 
static double autospeed_volumetric_limit (const Print &print)
 
static void init_ooze_prevention (const Print &print, OozePrevention &ooze_prevention)
 
static std::string update_print_stats_and_format_filament_stats (const bool has_wipe_tower, const WipeTowerData &wipe_tower_data, const FullPrintConfig &config, const std::vector< Extruder > &extruders, unsigned int initial_extruder_id, PrintStatistics &print_statistics)
 

Function Documentation

◆ autospeed_volumetric_limit()

static double Slic3r::DoExport::autospeed_volumetric_limit ( const Print print)
static
910 {
911 // get the minimum cross-section used in the print
912 std::vector<double> mm3_per_mm;
913 for (auto object : print.objects()) {
914 for (size_t region_id = 0; region_id < object->num_printing_regions(); ++ region_id) {
915 const PrintRegion &region = object->printing_region(region_id);
916 for (auto layer : object->layers()) {
917 const LayerRegion* layerm = layer->regions()[region_id];
918 if (region.config().get_abs_value("perimeter_speed") == 0 ||
919 region.config().get_abs_value("small_perimeter_speed") == 0 ||
920 region.config().get_abs_value("external_perimeter_speed") == 0 ||
921 region.config().get_abs_value("bridge_speed") == 0)
922 mm3_per_mm.push_back(layerm->perimeters().min_mm3_per_mm());
923 if (region.config().get_abs_value("infill_speed") == 0 ||
924 region.config().get_abs_value("solid_infill_speed") == 0 ||
925 region.config().get_abs_value("top_solid_infill_speed") == 0 ||
926 region.config().get_abs_value("bridge_speed") == 0)
927 {
928 // Minimal volumetric flow should not be calculated over ironing extrusions.
929 // Use following lambda instead of the built-it method.
930 // https://github.com/prusa3d/PrusaSlicer/issues/5082
931 auto min_mm3_per_mm_no_ironing = [](const ExtrusionEntityCollection& eec) -> double {
932 double min = std::numeric_limits<double>::max();
933 for (const ExtrusionEntity* ee : eec.entities)
934 if (ee->role() != ExtrusionRole::Ironing)
935 min = std::min(min, ee->min_mm3_per_mm());
936 return min;
937 };
938
939 mm3_per_mm.push_back(min_mm3_per_mm_no_ironing(layerm->fills()));
940 }
941 }
942 }
943 if (object->config().get_abs_value("support_material_speed") == 0 ||
944 object->config().get_abs_value("support_material_interface_speed") == 0)
945 for (auto layer : object->support_layers())
946 mm3_per_mm.push_back(layer->support_fills.min_mm3_per_mm());
947 }
948 // filter out 0-width segments
949 mm3_per_mm.erase(std::remove_if(mm3_per_mm.begin(), mm3_per_mm.end(), [](double v) { return v < 0.000001; }), mm3_per_mm.end());
950 double volumetric_speed = 0.;
951 if (! mm3_per_mm.empty()) {
952 // In order to honor max_print_speed we need to find a target volumetric
953 // speed that we can use throughout the print. So we define this target
954 // volumetric speed as the volumetric speed produced by printing the
955 // smallest cross-section at the maximum speed: any larger cross-section
956 // will need slower feedrates.
957 volumetric_speed = *std::min_element(mm3_per_mm.begin(), mm3_per_mm.end()) * print.config().max_print_speed.value;
958 // limit such volumetric speed with max_volumetric_speed if set
959 if (print.config().max_volumetric_speed.value > 0)
960 volumetric_speed = std::min(volumetric_speed, print.config().max_volumetric_speed.value);
961 }
962 return volumetric_speed;
963 }
Definition ExtrusionEntityCollection.hpp:26
double min_mm3_per_mm() const override
Definition ExtrusionEntityCollection.cpp:147
Definition ExtrusionEntity.hpp:21
Definition Layer.hpp:95
const ExtrusionEntityCollection & fills() const
Definition Layer.hpp:134
const ExtrusionEntityCollection & perimeters() const
Definition Layer.hpp:130
const PrintConfig & config() const
Definition Print.hpp:597
Definition Print.hpp:76
const PrintRegionConfig & config() const
Definition Print.hpp:87
if(!(yy_init))
Definition lexer.c:1190
STL namespace.
Definition ExtrusionRole.hpp:43

References autospeed_volumetric_limit(), Slic3r::PrintRegion::config(), Slic3r::Print::config(), Slic3r::LayerRegion::fills(), Slic3r::ExtrusionEntityCollection::min_mm3_per_mm(), Slic3r::Print::objects(), and Slic3r::LayerRegion::perimeters().

Referenced by Slic3r::GCode::_do_export(), and autospeed_volumetric_limit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_gcode_processor()

static void Slic3r::DoExport::init_gcode_processor ( const PrintConfig &  config,
GCodeProcessor processor,
bool &  silent_time_estimator_enabled 
)
static
900 {
901 silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware)
902 && config.silent_mode;
903 processor.reset();
904 processor.initialize_result_moves();
905 processor.apply_config(config);
906 processor.enable_stealth_time_estimator(silent_time_estimator_enabled);
907 }
void initialize_result_moves()
Definition GCodeProcessor.hpp:642
void apply_config(const PrintConfig &config)
Definition GCodeProcessor.cpp:553
void reset()
Definition GCodeProcessor.cpp:942
void enable_stealth_time_estimator(bool enabled)
Definition GCodeProcessor.cpp:937
@ gcfMarlinFirmware
Definition PrintConfig.hpp:35
@ gcfMarlinLegacy
Definition PrintConfig.hpp:35

References Slic3r::GCodeProcessor::apply_config(), Slic3r::GCodeProcessor::enable_stealth_time_estimator(), Slic3r::gcfMarlinFirmware, Slic3r::gcfMarlinLegacy, init_gcode_processor(), Slic3r::GCodeProcessor::initialize_result_moves(), and Slic3r::GCodeProcessor::reset().

Referenced by Slic3r::GCode::_do_export(), and init_gcode_processor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_ooze_prevention()

static void Slic3r::DoExport::init_ooze_prevention ( const Print print,
OozePrevention ooze_prevention 
)
static
967 {
968 ooze_prevention.enable = print.config().ooze_prevention.value && ! print.config().single_extruder_multi_material;
969 }
bool enable
Definition GCode.hpp:41

References Slic3r::Print::config(), Slic3r::OozePrevention::enable, and init_ooze_prevention().

Referenced by Slic3r::GCode::_do_export(), and init_ooze_prevention().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_print_estimated_stats()

static void Slic3r::DoExport::update_print_estimated_stats ( const GCodeProcessor processor,
const std::vector< Extruder > &  extruders,
PrintStatistics print_statistics 
)
static
708 {
709 const GCodeProcessorResult& result = processor.get_result();
710 print_statistics.estimated_normal_print_time = get_time_dhms(result.print_statistics.modes[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].time);
712 get_time_dhms(result.print_statistics.modes[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Stealth)].time) : "N/A";
713
714 // update filament statictics
715 double total_extruded_volume = 0.0;
716 double total_used_filament = 0.0;
717 double total_weight = 0.0;
718 double total_cost = 0.0;
719 for (auto volume : result.print_statistics.volumes_per_extruder) {
720 total_extruded_volume += volume.second;
721
722 size_t extruder_id = volume.first;
723 auto extruder = std::find_if(extruders.begin(), extruders.end(), [extruder_id](const Extruder& extr) { return extr.id() == extruder_id; });
724 if (extruder == extruders.end())
725 continue;
726
727 double s = PI * sqr(0.5* extruder->filament_diameter());
728 double weight = volume.second * extruder->filament_density() * 0.001;
729 total_used_filament += volume.second/s;
730 total_weight += weight;
731 total_cost += weight * extruder->filament_cost() * 0.001;
732 }
733
734 print_statistics.total_extruded_volume = total_extruded_volume;
735 print_statistics.total_used_filament = total_used_filament;
736 print_statistics.total_weight = total_weight;
737 print_statistics.total_cost = total_cost;
738
739 print_statistics.filament_stats = result.print_statistics.volumes_per_extruder;
740 }
Definition Extruder.hpp:12
const GCodeProcessorResult & get_result() const
Definition GCodeProcessor.hpp:633
bool is_stealth_time_estimator_enabled() const
Definition GCodeProcessor.hpp:627
static constexpr double PI
Definition libslic3r.h:58
constexpr T sqr(T x)
Definition libslic3r.h:258
std::string get_time_dhms(float time_in_secs)
Definition Utils.hpp:315
Definition GCodeProcessor.hpp:102
PrintEstimatedStatistics print_statistics
Definition GCodeProcessor.hpp:152
std::map< size_t, double > volumes_per_extruder
Definition GCodeProcessor.hpp:66
std::array< Mode, static_cast< size_t >(ETimeMode::Count)> modes
Definition GCodeProcessor.hpp:70
std::string estimated_normal_print_time
Definition Print.hpp:495
std::map< size_t, double > filament_stats
Definition Print.hpp:508
double total_used_filament
Definition Print.hpp:497
std::string estimated_silent_print_time
Definition Print.hpp:496
double total_extruded_volume
Definition Print.hpp:498
double total_cost
Definition Print.hpp:499
double total_weight
Definition Print.hpp:501

References Slic3r::PrintStatistics::estimated_normal_print_time, Slic3r::PrintStatistics::estimated_silent_print_time, Slic3r::PrintStatistics::filament_stats, Slic3r::GCodeProcessor::get_result(), Slic3r::get_time_dhms(), Slic3r::GCodeProcessor::is_stealth_time_estimator_enabled(), Slic3r::PrintEstimatedStatistics::modes, PI, Slic3r::GCodeProcessorResult::print_statistics, Slic3r::sqr(), Slic3r::PrintStatistics::total_cost, Slic3r::PrintStatistics::total_extruded_volume, Slic3r::PrintStatistics::total_used_filament, Slic3r::PrintStatistics::total_weight, update_print_estimated_stats(), and Slic3r::PrintEstimatedStatistics::volumes_per_extruder.

Referenced by Slic3r::GCode::do_export(), and update_print_estimated_stats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_print_stats_and_format_filament_stats()

static std::string Slic3r::DoExport::update_print_stats_and_format_filament_stats ( const bool  has_wipe_tower,
const WipeTowerData wipe_tower_data,
const FullPrintConfig &  config,
const std::vector< Extruder > &  extruders,
unsigned int  initial_extruder_id,
PrintStatistics print_statistics 
)
static
979 {
980 std::string filament_stats_string_out;
981
982 print_statistics.clear();
983 print_statistics.total_toolchanges = std::max(0, wipe_tower_data.number_of_toolchanges);
984 print_statistics.initial_extruder_id = initial_extruder_id;
985 std::vector<std::string> filament_types;
986 if (! extruders.empty()) {
987 std::pair<std::string, unsigned int> out_filament_used_mm ("; filament used [mm] = ", 0);
988 std::pair<std::string, unsigned int> out_filament_used_cm3("; filament used [cm3] = ", 0);
989 std::pair<std::string, unsigned int> out_filament_used_g ("; filament used [g] = ", 0);
990 std::pair<std::string, unsigned int> out_filament_cost ("; filament cost = ", 0);
991 for (const Extruder &extruder : extruders) {
992 print_statistics.printing_extruders.emplace_back(extruder.id());
993 filament_types.emplace_back(config.filament_type.get_at(extruder.id()));
994
995 double used_filament = extruder.used_filament() + (has_wipe_tower ? wipe_tower_data.used_filament[extruder.id()] : 0.f);
996 double extruded_volume = extruder.extruded_volume() + (has_wipe_tower ? wipe_tower_data.used_filament[extruder.id()] * 2.4052f : 0.f); // assumes 1.75mm filament diameter
997 double filament_weight = extruded_volume * extruder.filament_density() * 0.001;
998 double filament_cost = filament_weight * extruder.filament_cost() * 0.001;
999 auto append = [&extruder](std::pair<std::string, unsigned int> &dst, const char *tmpl, double value) {
1001 while (dst.second < extruder.id()) {
1002 // Fill in the non-printing extruders with zeros.
1003 dst.first += (dst.second > 0) ? ", 0" : "0";
1004 ++ dst.second;
1005 }
1006 if (dst.second > 0)
1007 dst.first += ", ";
1008 char buf[64];
1009 sprintf(buf, tmpl, value);
1010 dst.first += buf;
1011 ++ dst.second;
1012 };
1013 append(out_filament_used_mm, "%.2lf", used_filament);
1014 append(out_filament_used_cm3, "%.2lf", extruded_volume * 0.001);
1015 if (filament_weight > 0.) {
1016 print_statistics.total_weight = print_statistics.total_weight + filament_weight;
1017 append(out_filament_used_g, "%.2lf", filament_weight);
1018 if (filament_cost > 0.) {
1019 print_statistics.total_cost = print_statistics.total_cost + filament_cost;
1020 append(out_filament_cost, "%.2lf", filament_cost);
1021 }
1022 }
1023 print_statistics.total_used_filament += used_filament;
1024 print_statistics.total_extruded_volume += extruded_volume;
1025 print_statistics.total_wipe_tower_filament += has_wipe_tower ? used_filament - extruder.used_filament() : 0.;
1026 print_statistics.total_wipe_tower_cost += has_wipe_tower ? (extruded_volume - extruder.extruded_volume())* extruder.filament_density() * 0.001 * extruder.filament_cost() * 0.001 : 0.;
1027 }
1028 filament_stats_string_out += out_filament_used_mm.first;
1029 filament_stats_string_out += "\n" + out_filament_used_cm3.first;
1030 if (out_filament_used_g.second)
1031 filament_stats_string_out += "\n" + out_filament_used_g.first;
1032 if (out_filament_cost.second)
1033 filament_stats_string_out += "\n" + out_filament_cost.first;
1034 print_statistics.initial_filament_type = config.filament_type.get_at(initial_extruder_id);
1035 std::sort(filament_types.begin(), filament_types.end());
1036 print_statistics.printing_filament_types = filament_types.front();
1037 for (size_t i = 1; i < filament_types.size(); ++ i) {
1038 print_statistics.printing_filament_types += ",";
1039 print_statistics.printing_filament_types += filament_types[i];
1040 }
1041 }
1042 return filament_stats_string_out;
1043 }
filament_cost((ConfigOptionFloats, filament_spool_weight))((ConfigOptionFloats
bool is_decimal_separator_point()
Definition LocalesUtils.cpp:47
std::vector< unsigned int > printing_extruders
Definition Print.hpp:504
double total_wipe_tower_cost
Definition Print.hpp:502
unsigned int initial_extruder_id
Definition Print.hpp:505
double total_wipe_tower_filament
Definition Print.hpp:503
int total_toolchanges
Definition Print.hpp:500
std::string initial_filament_type
Definition Print.hpp:506
void clear()
Definition Print.hpp:517
std::string printing_filament_types
Definition Print.hpp:507
std::vector< float > used_filament
Definition Print.hpp:464
int number_of_toolchanges
Definition Print.hpp:465

References Slic3r::PrintStatistics::clear(), Slic3r::filament_cost(), Slic3r::PrintStatistics::initial_extruder_id, Slic3r::PrintStatistics::initial_filament_type, Slic3r::is_decimal_separator_point(), Slic3r::WipeTowerData::number_of_toolchanges, Slic3r::PrintStatistics::printing_extruders, Slic3r::PrintStatistics::printing_filament_types, Slic3r::PrintStatistics::total_cost, Slic3r::PrintStatistics::total_extruded_volume, Slic3r::PrintStatistics::total_toolchanges, Slic3r::PrintStatistics::total_used_filament, Slic3r::PrintStatistics::total_weight, Slic3r::PrintStatistics::total_wipe_tower_cost, Slic3r::PrintStatistics::total_wipe_tower_filament, update_print_stats_and_format_filament_stats(), and Slic3r::WipeTowerData::used_filament.

Referenced by Slic3r::GCode::_do_export(), and update_print_stats_and_format_filament_stats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_custom_gcode()

static std::vector< std::pair< std::string, std::string > > Slic3r::DoExport::validate_custom_gcode ( const Print print)
static
748 {
749 static const unsigned int MAX_TAGS_COUNT = 5;
750 std::vector<std::pair<std::string, std::string>> ret;
751
752 auto check = [&ret](const std::string& source, const std::string& gcode) {
753 std::vector<std::string> tags;
754 if (GCodeProcessor::contains_reserved_tags(gcode, MAX_TAGS_COUNT, tags)) {
755 if (!tags.empty()) {
756 size_t i = 0;
757 while (ret.size() < MAX_TAGS_COUNT && i < tags.size()) {
758 ret.push_back({ source, tags[i] });
759 ++i;
760 }
761 }
762 }
763 };
764
765 const GCodeConfig& config = print.config();
766 check(_u8L("Start G-code"), config.start_gcode.value);
767 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("End G-code"), config.end_gcode.value);
768 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Before layer change G-code"), config.before_layer_gcode.value);
769 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("After layer change G-code"), config.layer_gcode.value);
770 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Tool change G-code"), config.toolchange_gcode.value);
771 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Between objects G-code (for sequential printing)"), config.between_objects_gcode.value);
772 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Color Change G-code"), config.color_change_gcode.value);
773 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Pause Print G-code"), config.pause_print_gcode.value);
774 if (ret.size() < MAX_TAGS_COUNT) check(_u8L("Template Custom G-code"), config.template_custom_gcode.value);
775 if (ret.size() < MAX_TAGS_COUNT) {
776 for (const std::string& value : config.start_filament_gcode.values) {
777 check(_u8L("Filament Start G-code"), value);
778 if (ret.size() == MAX_TAGS_COUNT)
779 break;
780 }
781 }
782 if (ret.size() < MAX_TAGS_COUNT) {
783 for (const std::string& value : config.end_filament_gcode.values) {
784 check(_u8L("Filament End G-code"), value);
785 if (ret.size() == MAX_TAGS_COUNT)
786 break;
787 }
788 }
789 if (ret.size() < MAX_TAGS_COUNT) {
790 const CustomGCode::Info& custom_gcode_per_print_z = print.model().custom_gcode_per_print_z;
791 for (const auto& gcode : custom_gcode_per_print_z.gcodes) {
792 check(_u8L("Custom G-code"), gcode.extra);
793 if (ret.size() == MAX_TAGS_COUNT)
794 break;
795 }
796 }
797
798 return ret;
799 }
#define _u8L(s)
macro used to mark string used at localization, return same string
Definition SLAPrint.cpp:29
CustomGCode::Info custom_gcode_per_print_z
Definition Model.hpp:1259
const Model & model() const
Definition PrintBase.hpp:433
start_filament_gcode((ConfigOptionBool, single_extruder_multi_material))((ConfigOptionBool
bool check(const DataBase &input, bool check_fontfile=true, bool use_surface=false)
Assert check of inputs data.
Definition EmbossJob.cpp:348

References _u8L, Slic3r::Print::config(), Slic3r::Model::custom_gcode_per_print_z, Slic3r::CustomGCode::Info::gcodes, Slic3r::PrintBase::model(), and validate_custom_gcode().

Referenced by Slic3r::GCode::do_export(), and validate_custom_gcode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: