Skip to content

Commit

Permalink
Show used filament length and weight per line type (#3246)
Browse files Browse the repository at this point in the history
Show used filament length and weight per feature

Co-authored-by: SoftFever <[email protected]>
  • Loading branch information
Noisyfox and SoftFever authored Dec 24, 2023
1 parent 7db0ad3 commit 35d5b62
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/slic3r/GUI/GCodeViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4485,11 +4485,14 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
}
};

auto append_headers = [&imgui](const std::vector<std::pair<std::string, float>>& title_offsets) {
auto append_headers = [&imgui, window_padding](const std::vector<std::pair<std::string, float>>& title_offsets) {
for (size_t i = 0; i < title_offsets.size(); i++) {
ImGui::SameLine(title_offsets[i].second);
imgui.bold_text(title_offsets[i].first);
}
// Ensure right padding
ImGui::SameLine();
ImGui::Dummy({window_padding, 1});
ImGui::Separator();
};

Expand All @@ -4507,8 +4510,12 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
offsets.push_back(max_width(title_columns[0].second, title_columns[0].first, extra_size) + 3.0f * style.ItemSpacing.x);
for (size_t i = 1; i < title_columns.size() - 1; i++)
offsets.push_back(offsets.back() + max_width(title_columns[i].second, title_columns[i].first) + style.ItemSpacing.x);
if (title_columns.back().first == _u8L("Display"))
offsets.back() = ImGui::GetWindowWidth() - ImGui::CalcTextSize(_u8L("Display").c_str()).x - ImGui::GetFrameHeight() / 2 - 2 * window_padding;
if (title_columns.back().first == _u8L("Display")) {
const auto preferred_offset = ImGui::GetWindowWidth() - ImGui::CalcTextSize(_u8L("Display").c_str()).x - ImGui::GetFrameHeight() / 2 - 2 * window_padding;
if (preferred_offset > offsets.back()) {
offsets.back() = preferred_offset;
}
}

float average_col_width = ImGui::GetWindowWidth() / static_cast<float>(title_columns.size());
std::vector<float> ret;
Expand Down Expand Up @@ -4586,8 +4593,9 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
if (it == m_print_statistics.used_filaments_per_role.end())
return std::make_pair(0.0, 0.0);

double koef = imperial_units ? 1000.0 / GizmoObjectManipulation::in_to_mm : 1.0;
return std::make_pair(it->second.first * koef, it->second.second);
double koef = imperial_units ? GizmoObjectManipulation::in_to_mm / 1000.0 : 1.0;
double unit_conver = imperial_units ? GizmoObjectManipulation::oz_to_g : 1;
return std::make_pair(it->second.first / koef, it->second.second / unit_conver);
};

// get used filament (meters and grams) from used volume in respect to the active extruder
Expand Down Expand Up @@ -4664,6 +4672,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
std::vector<std::string> times;
std::string travel_time;
std::vector<std::string> percents;
std::vector<std::string> used_filaments_length;
std::vector<std::string> used_filaments_weight;
std::string travel_percent;
std::vector<double> model_used_filaments_m;
std::vector<double> model_used_filaments_g;
Expand Down Expand Up @@ -4707,9 +4717,12 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
else
percent > 0.001 ? ::sprintf(buffer, "%.1f%%", percent * 100) : ::sprintf(buffer, "<0.1%%");
percents.push_back(buffer);
//auto [model_used_filament_m, model_used_filament_g] = used_filament_per_role(role);
//model_used_filaments_m.push_back(model_used_filament_m);
//model_used_filaments_g.push_back(model_used_filament_g);

auto [model_used_filament_m, model_used_filament_g] = used_filament_per_role(role);
::sprintf(buffer, imperial_units ? "%.2f in" : "%.2f m", model_used_filament_m);
used_filaments_length.push_back(buffer);
::sprintf(buffer, imperial_units ? "%.2f oz" : "%.2f g", model_used_filament_g);
used_filaments_weight.push_back(buffer);
}
}

Expand All @@ -4724,8 +4737,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
travel_percent = buffer;
}

offsets = calculate_offsets({ {_u8L("Line Type"), labels}, {_u8L("Time"), times}, {_u8L("Percent"), percents}, {_u8L("Display"), {""}}}, icon_size);
append_headers({{_u8L("Line Type"), offsets[0]}, {_u8L("Time"), offsets[1]}, {_u8L("Percent"), offsets[2]}, {_u8L("Display"), offsets[3]}});
offsets = calculate_offsets({ {_u8L("Line Type"), labels}, {_u8L("Time"), times}, {_u8L("Percent"), percents}, {"", used_filaments_length}, {"", used_filaments_weight}, {_u8L("Display"), {""}}}, icon_size);
append_headers({{_u8L("Line Type"), offsets[0]}, {_u8L("Time"), offsets[1]}, {_u8L("Percent"), offsets[2]}, {_u8L("Used filament"), offsets[3]}, {_u8L("Display"), offsets[5]}});
break;
}
case EViewType::Height: { imgui.title(_u8L("Layer Height (mm)")); break; }
Expand Down Expand Up @@ -4877,7 +4890,9 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
std::vector<std::pair<std::string, float>> columns_offsets;
columns_offsets.push_back({ labels[i], offsets[0] });
columns_offsets.push_back({ times[i], offsets[1] });
columns_offsets.push_back({ percents[i], offsets[2] });
columns_offsets.push_back({percents[i], offsets[2]});
columns_offsets.push_back({used_filaments_length[i], offsets[3]});
columns_offsets.push_back({used_filaments_weight[i], offsets[4]});
append_item(EItemType::Rect, Extrusion_Role_Colors[static_cast<unsigned int>(role)], columns_offsets,
true, visible, [this, role, visible]() {
m_extrusions.role_visibility_flags = visible ? m_extrusions.role_visibility_flags & ~(1 << role) : m_extrusions.role_visibility_flags | (1 << role);
Expand Down

0 comments on commit 35d5b62

Please sign in to comment.