Tech ENABLE_SCROLLABLE_LEGEND set as default

This commit is contained in:
enricoturri1966 2021-07-22 12:18:38 +02:00
parent 2dd7091cc3
commit d5ad47d0ca
5 changed files with 0 additions and 47 deletions

View file

@ -41,8 +41,6 @@
//==================== //====================
#define ENABLE_2_4_0_ALPHA0 1 #define ENABLE_2_4_0_ALPHA0 1
// Enable scrollable legend in preview
#define ENABLE_SCROLLABLE_LEGEND (1 && ENABLE_2_4_0_ALPHA0)
// Enable visualization of start gcode as regular toolpaths // Enable visualization of start gcode as regular toolpaths
#define ENABLE_START_GCODE_VISUALIZATION (1 && ENABLE_2_4_0_ALPHA0) #define ENABLE_START_GCODE_VISUALIZATION (1 && ENABLE_2_4_0_ALPHA0)
// Enable visualization of seams in preview // Enable visualization of seams in preview

View file

@ -2579,25 +2579,17 @@ void GCodeViewer::render_legend(float& legend_height) const
if (!m_legend_enabled) if (!m_legend_enabled)
return; return;
#if ENABLE_SCROLLABLE_LEGEND
const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size(); const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size();
#endif // ENABLE_SCROLLABLE_LEGEND
ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGuiWrapper& imgui = *wxGetApp().imgui();
imgui.set_next_window_pos(0.0f, 0.0f, ImGuiCond_Always); imgui.set_next_window_pos(0.0f, 0.0f, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::SetNextWindowBgAlpha(0.6f); ImGui::SetNextWindowBgAlpha(0.6f);
#if ENABLE_SCROLLABLE_LEGEND
const float max_height = 0.75f * static_cast<float>(cnv_size.get_height()); const float max_height = 0.75f * static_cast<float>(cnv_size.get_height());
const float child_height = 0.3333f * max_height; const float child_height = 0.3333f * max_height;
ImGui::SetNextWindowSizeConstraints({ 0.0f, 0.0f }, { -1.0f, max_height }); ImGui::SetNextWindowSizeConstraints({ 0.0f, 0.0f }, { -1.0f, max_height });
imgui.begin(std::string("Legend"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove); imgui.begin(std::string("Legend"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove);
#else
imgui.begin(std::string("Legend"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove);
ImDrawList* draw_list = ImGui::GetWindowDrawList();
#endif // ENABLE_SCROLLABLE_LEGEND
enum class EItemType : unsigned char enum class EItemType : unsigned char
{ {
@ -2608,30 +2600,22 @@ void GCodeViewer::render_legend(float& legend_height) const
}; };
const PrintEstimatedStatistics::Mode& time_mode = m_print_statistics.modes[static_cast<size_t>(m_time_estimate_mode)]; const PrintEstimatedStatistics::Mode& time_mode = m_print_statistics.modes[static_cast<size_t>(m_time_estimate_mode)];
#if ENABLE_SCROLLABLE_LEGEND
bool show_estimated_time = time_mode.time > 0.0f && (m_view_type == EViewType::FeatureType || bool show_estimated_time = time_mode.time > 0.0f && (m_view_type == EViewType::FeatureType ||
(m_view_type == EViewType::ColorPrint && !time_mode.custom_gcode_times.empty())); (m_view_type == EViewType::ColorPrint && !time_mode.custom_gcode_times.empty()));
#endif // ENABLE_SCROLLABLE_LEGEND
const float icon_size = ImGui::GetTextLineHeight(); const float icon_size = ImGui::GetTextLineHeight();
const float percent_bar_size = 2.0f * ImGui::GetTextLineHeight(); const float percent_bar_size = 2.0f * ImGui::GetTextLineHeight();
bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; bool imperial_units = wxGetApp().app_config->get("use_inches") == "1";
#if ENABLE_SCROLLABLE_LEGEND
auto append_item = [this, icon_size, percent_bar_size, &imgui, imperial_units](EItemType type, const Color& color, const std::string& label, auto append_item = [this, icon_size, percent_bar_size, &imgui, imperial_units](EItemType type, const Color& color, const std::string& label,
#else
auto append_item = [this, draw_list, icon_size, percent_bar_size, &imgui, imperial_units](EItemType type, const Color& color, const std::string& label,
#endif // ENABLE_SCROLLABLE_LEGEND
bool visible = true, const std::string& time = "", float percent = 0.0f, float max_percent = 0.0f, const std::array<float, 4>& offsets = { 0.0f, 0.0f, 0.0f, 0.0f }, bool visible = true, const std::string& time = "", float percent = 0.0f, float max_percent = 0.0f, const std::array<float, 4>& offsets = { 0.0f, 0.0f, 0.0f, 0.0f },
double used_filament_m = 0.0, double used_filament_g = 0.0, double used_filament_m = 0.0, double used_filament_g = 0.0,
std::function<void()> callback = nullptr) { std::function<void()> callback = nullptr) {
if (!visible) if (!visible)
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.3333f); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.3333f);
#if ENABLE_SCROLLABLE_LEGEND
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
#endif // ENABLE_SCROLLABLE_LEGEND
ImVec2 pos = ImGui::GetCursorScreenPos(); ImVec2 pos = ImGui::GetCursorScreenPos();
switch (type) { switch (type) {
default: default:
@ -2984,7 +2968,6 @@ void GCodeViewer::render_legend(float& legend_height) const
} }
case EViewType::ColorPrint: case EViewType::ColorPrint:
{ {
#if ENABLE_SCROLLABLE_LEGEND
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes; const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
size_t total_items = 1; size_t total_items = 1;
for (unsigned char i : m_extruder_ids) { for (unsigned char i : m_extruder_ids) {
@ -2996,9 +2979,6 @@ void GCodeViewer::render_legend(float& legend_height) const
// add scrollable region, if needed // add scrollable region, if needed
if (need_scrollable) if (need_scrollable)
ImGui::BeginChild("color_prints", { -1.0f, child_height }, false); ImGui::BeginChild("color_prints", { -1.0f, child_height }, false);
#else
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes;
#endif // ENABLE_SCROLLABLE_LEGEND
if (m_extruders_count == 1) { // single extruder use case if (m_extruders_count == 1) { // single extruder use case
const std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(0, custom_gcode_per_print_z); const std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(0, custom_gcode_per_print_z);
const int items_cnt = static_cast<int>(cp_values.size()); const int items_cnt = static_cast<int>(cp_values.size());
@ -3049,10 +3029,8 @@ void GCodeViewer::render_legend(float& legend_height) const
} }
} }
} }
#if ENABLE_SCROLLABLE_LEGEND
if (need_scrollable) if (need_scrollable)
ImGui::EndChild(); ImGui::EndChild();
#endif // ENABLE_SCROLLABLE_LEGEND
break; break;
} }
@ -3203,12 +3181,10 @@ void GCodeViewer::render_legend(float& legend_height) const
ImGui::Spacing(); ImGui::Spacing();
append_headers({ _u8L("Event"), _u8L("Remaining time"), _u8L("Duration"), _u8L("Used filament") }, offsets); append_headers({ _u8L("Event"), _u8L("Remaining time"), _u8L("Duration"), _u8L("Used filament") }, offsets);
#if ENABLE_SCROLLABLE_LEGEND
const bool need_scrollable = static_cast<float>(partial_times.size()) * (icon_size + ImGui::GetStyle().ItemSpacing.y) > child_height; const bool need_scrollable = static_cast<float>(partial_times.size()) * (icon_size + ImGui::GetStyle().ItemSpacing.y) > child_height;
if (need_scrollable) if (need_scrollable)
// add scrollable region // add scrollable region
ImGui::BeginChild("events", { -1.0f, child_height }, false); ImGui::BeginChild("events", { -1.0f, child_height }, false);
#endif // ENABLE_SCROLLABLE_LEGEND
for (const PartialTime& item : partial_times) { for (const PartialTime& item : partial_times) {
switch (item.type) switch (item.type)
@ -3230,10 +3206,8 @@ void GCodeViewer::render_legend(float& legend_height) const
} }
} }
#if ENABLE_SCROLLABLE_LEGEND
if (need_scrollable) if (need_scrollable)
ImGui::EndChild(); ImGui::EndChild();
#endif // ENABLE_SCROLLABLE_LEGEND
} }
} }
@ -3383,14 +3357,7 @@ void GCodeViewer::render_legend(float& legend_height) const
} }
// total estimated printing time section // total estimated printing time section
#if ENABLE_SCROLLABLE_LEGEND
if (show_estimated_time) { if (show_estimated_time) {
#else
if (time_mode.time > 0.0f && (m_view_type == EViewType::FeatureType ||
(m_view_type == EViewType::ColorPrint && !time_mode.custom_gcode_times.empty()))) {
ImGui::Spacing();
#endif // ENABLE_SCROLLABLE_LEGEND
ImGui::Spacing(); ImGui::Spacing();
std::string time_title = _u8L("Estimated printing times"); std::string time_title = _u8L("Estimated printing times");
switch (m_time_estimate_mode) switch (m_time_estimate_mode)

View file

@ -4701,13 +4701,11 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
if (m_canvas == nullptr && m_context == nullptr) if (m_canvas == nullptr && m_context == nullptr)
return; return;
#if ENABLE_SCROLLABLE_LEGEND
const std::array<unsigned int, 2> new_size = { w, h }; const std::array<unsigned int, 2> new_size = { w, h };
if (m_old_size == new_size) if (m_old_size == new_size)
return; return;
m_old_size = new_size; m_old_size = new_size;
#endif // ENABLE_SCROLLABLE_LEGEND
auto *imgui = wxGetApp().imgui(); auto *imgui = wxGetApp().imgui();
imgui->set_display_size(static_cast<float>(w), static_cast<float>(h)); imgui->set_display_size(static_cast<float>(w), static_cast<float>(h));
@ -4718,9 +4716,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
imgui->set_scaling(font_size, m_canvas->GetContentScaleFactor(), 1.0f); imgui->set_scaling(font_size, m_canvas->GetContentScaleFactor(), 1.0f);
#endif #endif
#if ENABLE_SCROLLABLE_LEGEND
this->request_extra_frame(); this->request_extra_frame();
#endif // ENABLE_SCROLLABLE_LEGEND
// ensures that this canvas is current // ensures that this canvas is current
_set_current(); _set_current();

View file

@ -427,9 +427,7 @@ private:
Model* m_model; Model* m_model;
BackgroundSlicingProcess *m_process; BackgroundSlicingProcess *m_process;
#if ENABLE_SCROLLABLE_LEGEND
std::array<unsigned int, 2> m_old_size{ 0, 0 }; std::array<unsigned int, 2> m_old_size{ 0, 0 };
#endif // ENABLE_SCROLLABLE_LEGEND
// Screen is only refreshed from the OnIdle handler if it is dirty. // Screen is only refreshed from the OnIdle handler if it is dirty.
bool m_dirty; bool m_dirty;
@ -787,9 +785,7 @@ public:
const Print* fff_print() const; const Print* fff_print() const;
const SLAPrint* sla_print() const; const SLAPrint* sla_print() const;
#if ENABLE_SCROLLABLE_LEGEND
void reset_old_size() { m_old_size = { 0, 0 }; } void reset_old_size() { m_old_size = { 0, 0 }; }
#endif // ENABLE_SCROLLABLE_LEGEND
private: private:
bool _is_shown_on_screen() const; bool _is_shown_on_screen() const;

View file

@ -3595,10 +3595,8 @@ void Plater::priv::set_current_panel(wxPanel* panel)
// sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably) // sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
view3D->set_as_dirty(); view3D->set_as_dirty();
#if ENABLE_SCROLLABLE_LEGEND
// reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size
view3D->get_canvas3d()->reset_old_size(); view3D->get_canvas3d()->reset_old_size();
#endif // ENABLE_SCROLLABLE_LEGEND
view_toolbar.select_item("3D"); view_toolbar.select_item("3D");
if (notification_manager != nullptr) if (notification_manager != nullptr)
notification_manager->set_in_preview(false); notification_manager->set_in_preview(false);
@ -3619,10 +3617,8 @@ void Plater::priv::set_current_panel(wxPanel* panel)
preview->reload_print(true); preview->reload_print(true);
preview->set_as_dirty(); preview->set_as_dirty();
#if ENABLE_SCROLLABLE_LEGEND
// reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size
preview->get_canvas3d()->reset_old_size(); preview->get_canvas3d()->reset_old_size();
#endif // ENABLE_SCROLLABLE_LEGEND
view_toolbar.select_item("Preview"); view_toolbar.select_item("Preview");
if (notification_manager != nullptr) if (notification_manager != nullptr)
notification_manager->set_in_preview(true); notification_manager->set_in_preview(true);