Tech ENABLE_GCODE_VIEWER -> Refactoring and code cleanup

This commit is contained in:
enricoturri1966 2020-05-15 12:25:38 +02:00
parent e57bc8afc1
commit a68eefbe4a
11 changed files with 152 additions and 288 deletions
src/slic3r/GUI

View file

@ -324,9 +324,6 @@ void GCodeViewer::render() const
m_sequential_view.marker.render();
render_shells();
render_legend();
#if !ENABLE_GCODE_USE_WXWIDGETS_SLIDER
render_sequential_bar();
#endif // !ENABLE_GCODE_USE_WXWIDGETS_SLIDER
#if ENABLE_GCODE_VIEWER_STATISTICS
render_statistics();
#endif // ENABLE_GCODE_VIEWER_STATISTICS
@ -383,15 +380,13 @@ void GCodeViewer::set_options_visibility_from_flags(unsigned int flags)
enable_legend(is_flag_set(9));
}
#if ENABLE_GCODE_USE_WXWIDGETS_SLIDER
void GCodeViewer::set_layers_z_range(const std::array<double, 2>& layers_z_range)
{
bool keep_sequential_current = layers_z_range[1] <= m_layers_z_range[1];
m_layers_z_range = layers_z_range;
refresh_render_paths(keep_sequential_current);
wxGetApp().plater()->update_preview_horz_slider();
wxGetApp().plater()->update_preview_moves_slider();
}
#endif // ENABLE_GCODE_USE_WXWIDGETS_SLIDER
bool GCodeViewer::init_shaders()
{
@ -1159,93 +1154,6 @@ void GCodeViewer::render_legend() const
ImGui::PopStyleVar();
}
#if !ENABLE_GCODE_USE_WXWIDGETS_SLIDER
void GCodeViewer::render_sequential_bar() const
{
static const float MARGIN = 125.0f;
static const float BUTTON_W = 50.0f;
auto apply_button_action = [this](unsigned int value) {
m_sequential_view.current = std::clamp(value, m_sequential_view.first, m_sequential_view.last);
refresh_render_paths(true);
};
if (m_sequential_view.last <= m_sequential_view.first)
return;
ImGuiWrapper& imgui = *wxGetApp().imgui();
const ImGuiStyle& style = ImGui::GetStyle();
Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size();
float left = wxGetApp().plater()->get_view_toolbar().get_width();
float width = static_cast<float>(cnv_size.get_width()) - left;
ImGui::SetNextWindowBgAlpha(0.5f);
imgui.set_next_window_pos(left, static_cast<float>(cnv_size.get_height()), ImGuiCond_Always, 0.0f, 1.0f);
ImGui::SetNextWindowSize({ width, -1.0f }, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
imgui.begin(std::string("Sequential"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove);
ImGui::SetCursorPosX(MARGIN);
imgui.disabled_begin(m_sequential_view.first == m_sequential_view.current);
if (ImGui::Button("< 1", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current - 1);
imgui.disabled_end();
ImGui::SameLine();
imgui.disabled_begin(m_sequential_view.current - m_sequential_view.first < 10);
if (ImGui::Button("< 10", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current - 10);
imgui.disabled_end();
ImGui::SameLine();
imgui.disabled_begin(m_sequential_view.current - m_sequential_view.first < 100);
if (ImGui::Button("< 100", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current - 100);
imgui.disabled_end();
ImGui::SameLine(width - MARGIN - 3 * BUTTON_W - 2 * style.ItemSpacing.x - style.WindowPadding.x);
imgui.disabled_begin(m_sequential_view.last - m_sequential_view.current < 100);
if (ImGui::Button("> 100", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current + 100);
imgui.disabled_end();
ImGui::SameLine();
imgui.disabled_begin(m_sequential_view.last - m_sequential_view.current < 10);
if (ImGui::Button("> 10", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current + 10);
imgui.disabled_end();
ImGui::SameLine();
imgui.disabled_begin(m_sequential_view.last == m_sequential_view.current);
if (ImGui::Button("> 1", { BUTTON_W, 0.0f }))
apply_button_action(m_sequential_view.current + 1);
imgui.disabled_end();
int index = 1 + static_cast<int>(m_sequential_view.current);
int i_min = 1 + static_cast<int>(m_sequential_view.first);
int i_max = 1 + static_cast<int>(m_sequential_view.last);
std::string low_str = std::to_string(i_min);
ImGui::SetCursorPosX(MARGIN - style.ItemSpacing.x - ImGui::CalcTextSize(low_str.c_str()).x);
ImGui::AlignTextToFramePadding();
imgui.text(low_str);
ImGui::SameLine(MARGIN);
ImGui::PushItemWidth(-MARGIN);
if (ImGui::SliderInt("##slider int", &index, i_min, i_max)) {
m_sequential_view.current = static_cast<unsigned int>(index - 1);
refresh_render_paths(true);
}
ImGui::PopItemWidth();
ImGui::SameLine();
imgui.text(std::to_string(i_max));
imgui.end();
ImGui::PopStyleVar();
}
#endif // !ENABLE_GCODE_USE_WXWIDGETS_SLIDER
#if ENABLE_GCODE_VIEWER_STATISTICS
void GCodeViewer::render_statistics() const
{