From 2759c87e5b8f95b130089bb31f058c68e3945853 Mon Sep 17 00:00:00 2001 From: Lukas Matena <lukasmatena@seznam.cz> Date: Wed, 20 Feb 2019 12:09:45 +0100 Subject: [PATCH 1/3] WarningTexture class in GLCanvas3D modified so it can be used more universally Added a warning to notify that some objects are not rendered with SLA gizmo active --- src/slic3r/GUI/GLCanvas3D.cpp | 86 ++++++++++++++++++++--------------- src/slic3r/GUI/GLCanvas3D.hpp | 28 ++++++++---- 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 98d7b43a1..799d6d632 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3677,7 +3677,40 @@ GLCanvas3D::WarningTexture::WarningTexture() { } -bool GLCanvas3D::WarningTexture::generate(const std::string& msg, const GLCanvas3D& canvas) +void GLCanvas3D::WarningTexture::activate(WarningTexture::Warning warning, bool state, const GLCanvas3D& canvas) +{ + auto it = std::find(m_warnings.begin(), m_warnings.end(), warning); + + if (state) { + if (it != m_warnings.end()) // this warning is already set to be shown + return; + + m_warnings.push_back(warning); + std::sort(m_warnings.begin(), m_warnings.end()); + } + else { + if (it == m_warnings.end()) // deactivating something that is not active is an easy task + return; + + m_warnings.erase(it); + if (m_warnings.empty()) { // nothing remains to be shown + reset(); + return; + } + } + + // Look at the end of our vector and generate proper texture. + std::string text; + switch (m_warnings.back()) { + case ObjectOutside : text = L("Detected object outside print volume"); break; + case ToolpathOutside : text = L("Detected toolpath outside print volume"); break; + case SomethingNotShown : text = L("Some objects are not visible when editing supports"); break; + } + + _generate(text, canvas); // GUI::GLTexture::reset() is called at the beginning of generate(...) +} + +bool GLCanvas3D::WarningTexture::_generate(const std::string& msg, const GLCanvas3D& canvas) { reset(); @@ -3750,6 +3783,9 @@ bool GLCanvas3D::WarningTexture::generate(const std::string& msg, const GLCanvas void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const { + if (m_warnings.empty()) + return; + if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) { ::glDisable(GL_DEPTH_TEST); @@ -4074,7 +4110,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) , m_apply_zoom_to_volumes_filter(false) , m_hover_volume_id(-1) , m_toolbar_action_running(false) - , m_warning_texture_enabled(false) , m_legend_texture_enabled(false) , m_picking_enabled(false) , m_moving_enabled(false) @@ -4232,8 +4267,7 @@ void GLCanvas3D::reset_volumes() m_dirty = true; } - enable_warning_texture(false); - _reset_warning_texture(); + _set_warning_texture(WarningTexture::ObjectOutside, false); } int GLCanvas3D::check_volumes_outside_state() const @@ -4262,6 +4296,12 @@ void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject } if (visible && !mo) toggle_sla_auxiliaries_visibility(true); + + if (!mo && !visible && !m_model->objects.empty() && (m_model->objects.size() > 1 || m_model->objects.front()->instances.size() > 1)) + _set_warning_texture(WarningTexture::SomethingNotShown, true); + + if (!mo && visible) + _set_warning_texture(WarningTexture::SomethingNotShown, false); } @@ -4375,11 +4415,6 @@ void GLCanvas3D::enable_layers_editing(bool enable) } } -void GLCanvas3D::enable_warning_texture(bool enable) -{ - m_warning_texture_enabled = enable; -} - void GLCanvas3D::enable_legend_texture(bool enable) { m_legend_texture_enabled = enable; @@ -4998,22 +5033,19 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re if (!contained) { - enable_warning_texture(true); - _generate_warning_texture(L("Detected object outside print volume")); + _set_warning_texture(WarningTexture::ObjectOutside, true); post_event(Event<bool>(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, state == ModelInstance::PVS_Fully_Outside)); } else { - enable_warning_texture(false); m_volumes.reset_outside_state(); - _reset_warning_texture(); + _set_warning_texture(WarningTexture::ObjectOutside, false); post_event(Event<bool>(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, !m_model->objects.empty())); } } else { - enable_warning_texture(false); - _reset_warning_texture(); + _set_warning_texture(WarningTexture::ObjectOutside, false); post_event(Event<bool>(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false)); } @@ -6667,9 +6699,6 @@ void GLCanvas3D::_render_selection_center() const void GLCanvas3D::_render_warning_texture() const { - if (!m_warning_texture_enabled) - return; - m_warning_texture.render(*this); } @@ -8204,17 +8233,7 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state() void GLCanvas3D::_show_warning_texture_if_needed() { _set_current(); - - if (_is_any_volume_outside()) - { - enable_warning_texture(true); - _generate_warning_texture(L("Detected toolpath outside print volume")); - } - else - { - enable_warning_texture(false); - _reset_warning_texture(); - } + _set_warning_texture(WarningTexture::ToolpathOutside, _is_any_volume_outside()); } std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors) @@ -8247,14 +8266,9 @@ void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, m_legend_texture.generate(preview_data, tool_colors, *this, m_dynamic_background_enabled && _is_any_volume_outside()); } -void GLCanvas3D::_generate_warning_texture(const std::string& msg) +void GLCanvas3D::_set_warning_texture(WarningTexture::Warning warning, bool state) { - m_warning_texture.generate(msg, *this); -} - -void GLCanvas3D::_reset_warning_texture() -{ - m_warning_texture.reset(); + m_warning_texture.activate(warning, state, *this); } bool GLCanvas3D::_is_any_volume_outside() const diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 6b3839b4f..3317c6378 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -843,18 +843,32 @@ private: class WarningTexture : public GUI::GLTexture { + public: + WarningTexture(); + + enum Warning { + ObjectOutside, + ToolpathOutside, + SomethingNotShown + }; + + // Sets a warning of the given type to be active/inactive. If several warnings are active simultaneously, + // only the last one is shown (decided by the order in the enum above). + void activate(WarningTexture::Warning warning, bool state, const GLCanvas3D& canvas); + void render(const GLCanvas3D& canvas) const; + + private: static const unsigned char Background_Color[3]; static const unsigned char Opacity; int m_original_width; int m_original_height; - public: - WarningTexture(); + // Information about which warnings are currently active. + std::vector<Warning> m_warnings; - bool generate(const std::string& msg, const GLCanvas3D& canvas); - - void render(const GLCanvas3D& canvas) const; + // Generates the texture with given text. + bool _generate(const std::string& msg, const GLCanvas3D& canvas); }; class LegendTexture : public GUI::GLTexture @@ -1003,7 +1017,6 @@ public: bool is_reload_delayed() const; void enable_layers_editing(bool enable); - void enable_warning_texture(bool enable); void enable_legend_texture(bool enable); void enable_picking(bool enable); void enable_moving(bool enable); @@ -1189,8 +1202,7 @@ private: void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors); // generates a warning texture containing the given message - void _generate_warning_texture(const std::string& msg); - void _reset_warning_texture(); + void _set_warning_texture(WarningTexture::Warning warning, bool state); bool _is_any_volume_outside() const; From b7465e935eceace3130e6d806026d6e7e709f002 Mon Sep 17 00:00:00 2001 From: Lukas Matena <lukasmatena@seznam.cz> Date: Wed, 20 Feb 2019 12:28:57 +0100 Subject: [PATCH 2/3] Fixed a missing include problem in SLASupportAuto.hpp --- src/libslic3r/SLA/SLAAutoSupports.cpp | 12 ++++++++++++ src/libslic3r/SLA/SLAAutoSupports.hpp | 10 +--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/SLA/SLAAutoSupports.cpp b/src/libslic3r/SLA/SLAAutoSupports.cpp index 1f6dcc2b7..aca84dbd8 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.cpp +++ b/src/libslic3r/SLA/SLAAutoSupports.cpp @@ -499,6 +499,18 @@ void SLAAutoSupports::uniformly_cover(const ExPolygons& islands, Structure& stru } } +float SLAAutoSupports::Structure::overlap_area(const Structure &rhs) const +{ + double out = 0.; + if (this->bbox.overlap(rhs.bbox)) { + Polygons polys = intersection(to_polygons(*this->polygon), to_polygons(*rhs.polygon), false); + for (const Polygon &poly : polys) + out += poly.area(); + } + + return float(out); +} + #ifdef SLA_AUTOSUPPORTS_DEBUG void SLAAutoSupports::output_structures(const std::vector<Structure>& structures) { diff --git a/src/libslic3r/SLA/SLAAutoSupports.hpp b/src/libslic3r/SLA/SLAAutoSupports.hpp index b552d1c0b..27f595a74 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.hpp +++ b/src/libslic3r/SLA/SLAAutoSupports.hpp @@ -71,15 +71,7 @@ public: bool overlaps(const Structure &rhs) const { return this->bbox.overlap(rhs.bbox) && (this->polygon->overlaps(*rhs.polygon) || rhs.polygon->overlaps(*this->polygon)); } - float overlap_area(const Structure &rhs) const { - double out = 0.; - if (this->bbox.overlap(rhs.bbox)) { - Polygons polys = intersection(to_polygons(*this->polygon), to_polygons(*rhs.polygon), false); - for (const Polygon &poly : polys) - out += poly.area(); - } - return float(out); - } + float overlap_area(const Structure &rhs) const; float area_below() const { float area = 0.f; for (const Link &below : this->islands_below) From 574cb53bff5f69daed9f2e02695e58c335bc85cb Mon Sep 17 00:00:00 2001 From: Lukas Matena <lukasmatena@seznam.cz> Date: Wed, 20 Feb 2019 13:16:09 +0100 Subject: [PATCH 3/3] Revert "Fixed a missing include problem in SLASupportAuto.hpp" This is already solved in master branch by including the header This reverts commit b7465e935eceace3130e6d806026d6e7e709f002. --- src/libslic3r/SLA/SLAAutoSupports.cpp | 12 ------------ src/libslic3r/SLA/SLAAutoSupports.hpp | 10 +++++++++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/SLA/SLAAutoSupports.cpp b/src/libslic3r/SLA/SLAAutoSupports.cpp index aca84dbd8..1f6dcc2b7 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.cpp +++ b/src/libslic3r/SLA/SLAAutoSupports.cpp @@ -499,18 +499,6 @@ void SLAAutoSupports::uniformly_cover(const ExPolygons& islands, Structure& stru } } -float SLAAutoSupports::Structure::overlap_area(const Structure &rhs) const -{ - double out = 0.; - if (this->bbox.overlap(rhs.bbox)) { - Polygons polys = intersection(to_polygons(*this->polygon), to_polygons(*rhs.polygon), false); - for (const Polygon &poly : polys) - out += poly.area(); - } - - return float(out); -} - #ifdef SLA_AUTOSUPPORTS_DEBUG void SLAAutoSupports::output_structures(const std::vector<Structure>& structures) { diff --git a/src/libslic3r/SLA/SLAAutoSupports.hpp b/src/libslic3r/SLA/SLAAutoSupports.hpp index 27f595a74..b552d1c0b 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.hpp +++ b/src/libslic3r/SLA/SLAAutoSupports.hpp @@ -71,7 +71,15 @@ public: bool overlaps(const Structure &rhs) const { return this->bbox.overlap(rhs.bbox) && (this->polygon->overlaps(*rhs.polygon) || rhs.polygon->overlaps(*this->polygon)); } - float overlap_area(const Structure &rhs) const; + float overlap_area(const Structure &rhs) const { + double out = 0.; + if (this->bbox.overlap(rhs.bbox)) { + Polygons polys = intersection(to_polygons(*this->polygon), to_polygons(*rhs.polygon), false); + for (const Polygon &poly : polys) + out += poly.area(); + } + return float(out); + } float area_below() const { float area = 0.f; for (const Link &below : this->islands_below)