FIX: negtive value in grouping stats

jira:STUDIO-10772

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I90b88c7d96f6aeb31df36233efab5b9059ad2622
This commit is contained in:
xun.zhang 2025-03-12 19:34:07 +08:00 committed by lane.wei
parent d61d0c7231
commit f6a46d9b95
2 changed files with 47 additions and 10 deletions

View File

@ -1009,7 +1009,8 @@ std::vector<int> ToolOrdering::get_recommended_filament_maps(const std::vector<s
return false;
};
std::vector<int>ret(filament_nums, 0);
int master_extruder_id = print_config.master_extruder_id.value -1; // switch to 0 based idx
std::vector<int>ret(filament_nums, master_extruder_id);
bool ignore_ext_filament = false; // TODO: read from config
// if mutli_extruder, calc group,otherwise set to 0
if (extruder_nums == 2) {
@ -1048,7 +1049,7 @@ std::vector<int> ToolOrdering::get_recommended_filament_maps(const std::vector<s
context.machine_info.machine_filament_info = machine_filament_info;
context.machine_info.max_group_size = std::move(group_size);
context.machine_info.master_extruder_id = print_config.master_extruder_id.value - 1; // switch to 0 based idx
context.machine_info.master_extruder_id = master_extruder_id;
context.group_info.total_filament_num = (int)(filament_nums);
context.group_info.max_gap_threshold = 0.01;

View File

@ -4759,8 +4759,10 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
int delta_change_to_single_ext = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count;
int delta_change_to_best = stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count - stats_by_extruder.stats_by_multi_extruder_best.filament_change_count;
bool less_to_single_ext = delta_weight_to_single_ext > EPSILON || delta_change_to_single_ext > 0;
bool more_to_best = delta_weight_to_best > EPSILON || delta_change_to_best > 0;
bool any_less_to_single_ext = delta_weight_to_single_ext > EPSILON || delta_change_to_single_ext > 0;
bool any_more_to_best = delta_weight_to_best > EPSILON || delta_change_to_best > 0;
bool all_less_to_single_ext = delta_weight_to_single_ext > EPSILON && delta_change_to_single_ext > 0;
bool all_more_to_best = delta_weight_to_best > EPSILON && delta_change_to_best > 0;
auto get_filament_display_type = [](const ExtruderFilament& filament) {
if (filament.is_support_filament && (filament.type == "PLA" || filament.type == "PA" || filament.type == "ABS"))
@ -4796,10 +4798,16 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
}
int tips_count = 8;
if (more_to_best)
if (any_more_to_best) {
tips_count = 8;
else if (less_to_single_ext)
if (!all_more_to_best)
tips_count += 1;
}
else if (any_less_to_single_ext) {
tips_count = 6;
if (!all_less_to_single_ext)
tips_count += 1;
}
else
tips_count = 5;
@ -4883,17 +4891,45 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding)
return static_cast<int>(num);
};
if (more_to_best) {
if (any_more_to_best) {
is_optimal_group = false;
ImVec4 orangeColor = ImVec4(1.0f, 0.5f, 0.0f, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Text, orangeColor);
imgui.text(_u8L("Tips:"));
imgui.text(_u8L("Current grouping of slice result is not optimal."));
imgui.text_wrapped(from_u8((boost::format(_u8L("Cost %1%g filament and %2% changes more than optimal grouping.")) % number_format(delta_weight_to_best) % delta_change_to_best).str()), parent_width);
wxString tip;
if (delta_weight_to_best >= 0 && delta_change_to_best >= 0)
tip = from_u8((boost::format(_u8L("Cost %1%g filament and %2% changes more than optimal grouping."))
% number_format(delta_weight_to_best)
% delta_change_to_best).str());
else if (delta_weight_to_best >= 0 && delta_change_to_best < 0)
tip = from_u8((boost::format(_u8L("Increase %1%g filament and reduce %2% changes compared to optimal grouping."))
% number_format(delta_weight_to_best)
% std::abs(delta_change_to_best)).str());
else if (delta_weight_to_best < 0 && delta_change_to_best >= 0)
tip = from_u8((boost::format(_u8L("Reduce %1%g filament and increase %2% changes compared to optimal grouping."))
% number_format(std::abs(delta_weight_to_best))
% delta_change_to_best).str());
imgui.text_wrapped(tip, parent_width);
ImGui::PopStyleColor(1);
}
else if (less_to_single_ext) {
imgui.text_wrapped(from_u8((boost::format(_u8L("Save %1%g filament and %2% changes than one-nozzle printer.")) % number_format(delta_weight_to_single_ext) % delta_change_to_single_ext).str()), parent_width);
else if (any_less_to_single_ext) {
wxString tip;
if (delta_weight_to_single_ext >= 0 && delta_change_to_single_ext >= 0)
tip = from_u8((boost::format(_u8L("Save %1%g filament and %2% changes than one-nozzle printer."))
% number_format(delta_weight_to_single_ext)
% delta_change_to_single_ext).str());
else if (delta_weight_to_single_ext >= 0 && delta_change_to_single_ext < 0)
tip = from_u8((boost::format(_u8L("Reduce %1%g filament and increase %2% changes compared to one-nozzle printer."))
% number_format(delta_weight_to_single_ext)
% std::abs(delta_change_to_single_ext)).str());
else if (delta_weight_to_single_ext < 0 && delta_change_to_single_ext >= 0)
tip = from_u8((boost::format(_u8L("Increase %1%g filament and reduce %2% changes compared to one-nozzle printer."))
% number_format(std::abs(delta_weight_to_single_ext))
% delta_change_to_single_ext).str());
imgui.text_wrapped(tip, parent_width);
}
ImGui::Dummy({window_padding, window_padding});