ENH: add cost info when loading GCode file

Add total cost infomation when loading Gcode file

jira:STUDIO-4353

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I930cb141e2a0b3cf328515f6543707c8bd5d620a
This commit is contained in:
xun.zhang 2023-09-13 18:14:17 +08:00 committed by Lane.Wei
parent 81bab138b5
commit 6a5e3b3646
3 changed files with 33 additions and 0 deletions

View File

@ -39,6 +39,7 @@ static const size_t MIN_EXTRUDERS_COUNT = 5;
static const float DEFAULT_FILAMENT_DIAMETER = 1.75f;
static const int DEFAULT_FILAMENT_HRC = 0;
static const float DEFAULT_FILAMENT_DENSITY = 1.245f;
static const float DEFAULT_FILAMENT_COST = 29.99f;
static const int DEFAULT_FILAMENT_VITRIFICATION_TEMPERATURE = 0;
static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero();
@ -840,6 +841,7 @@ void GCodeProcessorResult::reset() {
filament_diameters = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER);
required_nozzle_HRC = std::vector<int>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_HRC);
filament_densities = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY);
filament_costs = std::vector<float>(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_COST);
custom_gcode_per_print_z = std::vector<CustomGCode::Item>();
spiral_vase_layers = std::vector<std::pair<float, std::pair<size_t, size_t>>>();
warnings.clear();
@ -946,6 +948,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
m_result.required_nozzle_HRC.resize(extruders_count);
m_result.filament_densities.resize(extruders_count);
m_result.filament_vitrification_temperature.resize(extruders_count);
m_result.filament_costs.resize(extruders_count);
m_extruder_temps.resize(extruders_count);
m_result.nozzle_type = config.nozzle_type;
for (size_t i = 0; i < extruders_count; ++ i) {
@ -955,6 +958,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
m_result.required_nozzle_HRC[i] = static_cast<int>(config.required_nozzle_HRC.get_at(i));
m_result.filament_densities[i] = static_cast<float>(config.filament_density.get_at(i));
m_result.filament_vitrification_temperature[i] = static_cast<float>(config.temperature_vitrification.get_at(i));
m_result.filament_costs[i] = static_cast<float>(config.filament_cost.get_at(i));
}
if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfKlipper) {
@ -1078,6 +1082,19 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
m_result.filament_densities.emplace_back(DEFAULT_FILAMENT_DENSITY);
}
}
//BBS
const ConfigOptionFloats* filament_costs = config.option<ConfigOptionFloats>("filament_cost");
if (filament_costs != nullptr) {
m_result.filament_costs.clear();
m_result.filament_costs.resize(filament_costs->values.size());
for (size_t i = 0; i < filament_costs->values.size(); ++i)
m_result.filament_costs[i]=static_cast<float>(filament_costs->values[i]);
}
for (size_t i = m_result.filament_costs.size(); i < m_result.extruders_count; ++i) {
m_result.filament_costs.emplace_back(DEFAULT_FILAMENT_COST);
}
//BBS
const ConfigOptionInts* filament_vitrification_temperature = config.option<ConfigOptionInts>("temperature_vitrification");
if (filament_vitrification_temperature != nullptr) {

View File

@ -190,6 +190,7 @@ namespace Slic3r {
std::vector<float> filament_diameters;
std::vector<int> required_nozzle_HRC;
std::vector<float> filament_densities;
std::vector<float> filament_costs;
std::vector<int> filament_vitrification_temperature;
PrintEstimatedStatistics print_statistics;
std::vector<CustomGCode::Item> custom_gcode_per_print_z;
@ -222,6 +223,7 @@ namespace Slic3r {
extruder_colors = other.extruder_colors;
filament_diameters = other.filament_diameters;
filament_densities = other.filament_densities;
filament_costs = other.filament_costs;
print_statistics = other.print_statistics;
custom_gcode_per_print_z = other.custom_gcode_per_print_z;
spiral_vase_layers = other.spiral_vase_layers;

View File

@ -9027,6 +9027,20 @@ void Plater::load_gcode(const wxString& filename)
current_print.apply(this->model(), wxGetApp().preset_bundle->full_config());
//BBS: add cost info when drag in gcode
auto& ps = current_result->print_statistics;
double total_cost = 0.0;
for (auto& volumes_map : { ps.volumes_per_extruder,ps.flush_per_filament ,ps.wipe_tower_volumes_per_extruder }) {
for (auto volume : volumes_map) {
size_t extruder_id = volume.first;
double density = current_result->filament_densities.at(extruder_id);
double cost = current_result->filament_costs.at(extruder_id);
double weight = volume.second * density * 0.001;
total_cost += weight * cost * 0.001;
}
}
current_print.print_statistics().total_cost = total_cost;
current_print.set_gcode_file_ready();
// show results