From 203a965b3db492c941be9ee2b8d864c2d559e95a Mon Sep 17 00:00:00 2001 From: Joseph Lenox <lenox.joseph@gmail.com> Date: Mon, 16 Jan 2017 01:00:05 -0600 Subject: [PATCH] added total cost/weight to Extruder statistics, mocked up addendum to status bar change. --- lib/Slic3r/GUI/Plater.pm | 1 + lib/Slic3r/Print/GCode.pm | 10 +++++----- lib/Slic3r/Print/Object.pm | 2 ++ xs/src/libslic3r/Print.hpp | 2 +- xs/xsp/Print.xsp | 21 +++++++++++++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 841b33d42..48b0c50e3 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1343,6 +1343,7 @@ sub on_export_completed { } else { $message = "G-code file exported to " . $self->{export_gcode_output_file}; } + $message .= sprintf(" Cost: %.2f" , $self->{print}->total_cost); } else { $message = "Export failed"; } diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 512ce05b7..45d529e4b 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -321,8 +321,8 @@ sub export { $self->print->clear_filament_stats; $self->print->total_used_filament(0); $self->print->total_extruded_volume(0); - my $total_filament_weight = 0.0; - my $total_filament_cost = 0.0; + $self->print->total_weight(0); + $self->print->total_cost(0); foreach my $extruder (@{$gcodegen->writer->extruders}) { my $used_filament = $extruder->used_filament; my $extruded_volume = $extruder->extruded_volume; @@ -333,11 +333,11 @@ sub export { printf $fh "; filament used = %.1fmm (%.1fcm3)\n", $used_filament, $extruded_volume/1000; if ($filament_weight > 0) { - $total_filament_weight += $filament_weight; + $self->print->total_weight($self->print->total_weight + $filament_weight); printf $fh "; filament used = %.1fg\n", $filament_weight; if ($filament_cost > 0) { - $total_filament_cost += $filament_cost; + $self->print->total_cost($self->print->total_cost + $filament_cost); printf $fh "; filament cost = %.1f\n", $filament_cost; } @@ -347,7 +347,7 @@ sub export { $self->print->total_extruded_volume($self->print->total_extruded_volume + $extruded_volume); } printf $fh "; total filament cost = %.1f\n", - $total_filament_cost; + $self->print->total_cost; # append full config print $fh "\n"; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 3e79a3857..eab68309a 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -268,6 +268,8 @@ sub generate_support_material { } $self->set_step_done(STEP_SUPPORTMATERIAL); + my $stats = "Weight: %.1fg, Cost: %.1f" , $self->print->total_weight, $self->print->total_cost; + $self->print->status_cb->(85, $stats); } # Idempotence of this method is guaranteed by the fact that we don't remove things from diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 99582d65d..02b2ea363 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -192,7 +192,7 @@ class Print PrintRegionPtrs regions; PlaceholderParser placeholder_parser; // TODO: status_cb - double total_used_filament, total_extruded_volume; + double total_used_filament, total_extruded_volume, total_cost, total_weight; std::map<size_t,float> filament_stats; PrintState<PrintStep> state; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index f7a3fa118..5166aa96b 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -276,5 +276,26 @@ Print::total_extruded_volume(...) OUTPUT: RETVAL + +double +Print::total_weight(...) + CODE: + if (items > 1) { + THIS->total_weight = (double)SvNV(ST(1)); + } + RETVAL = THIS->total_weight; + OUTPUT: + RETVAL + +double +Print::total_cost(...) + CODE: + if (items > 1) { + THIS->total_cost = (double)SvNV(ST(1)); + } + RETVAL = THIS->total_cost; + OUTPUT: + RETVAL + %} };