From 8bd0f8ada9e571ece441857a9f1a37ff90030688 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 10 Sep 2021 08:27:03 +0200 Subject: [PATCH] Removed duplicated method GLVolumeCollection::check_outside_state() --- src/slic3r/GUI/3DScene.cpp | 68 ++++++---------------------------- src/slic3r/GUI/3DScene.hpp | 1 - src/slic3r/GUI/GLCanvas3D.cpp | 13 ++++--- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- src/slic3r/GUI/GUI_Preview.cpp | 5 --- src/slic3r/GUI/GUI_Preview.hpp | 2 - src/slic3r/GUI/Plater.cpp | 4 +- 7 files changed, 22 insertions(+), 73 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 7a9fdc3886..2d49a8bf38 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -827,6 +827,12 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func) const { +#if ENABLE_SINKING_CONTOURS + GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); + if (to_render.empty()) + return; +#endif // ENABLE_SINKING_CONTOURS + GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; @@ -841,7 +847,6 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glDisable(GL_CULL_FACE)); #if ENABLE_SINKING_CONTOURS - GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); for (GLVolumeWithIdAndZ& volume : to_render) { volume.first->set_render_color(); @@ -961,8 +966,10 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M if (opt == nullptr) return false; - BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - BoundingBoxf3 print_volume({ unscale(bed_box_2D.min(0)), unscale(bed_box_2D.min(1)), 0.0 }, { unscale(bed_box_2D.max(0)), unscale(bed_box_2D.max(1)), config->opt_float("max_print_height") }); + const BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); + BoundingBoxf3 print_volume({ unscale(bed_box_2D.min.x()), unscale(bed_box_2D.min.y()), 0.0 }, + { unscale(bed_box_2D.max.x()), unscale(bed_box_2D.max.y()), + config->opt_float("max_print_height") }); // Allow the objects to protrude below the print bed print_volume.min(2) = -1e10; print_volume.min(0) -= BedEpsilon; @@ -975,7 +982,7 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M bool contained_min_one = false; for (GLVolume* volume : this->volumes) { - if (volume == nullptr || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || (volume->composite_id.volume_id < 0 && !volume->shader_outside_printer_detection_enabled)) + if (volume->is_modifier || (!volume->shader_outside_printer_detection_enabled && (volume->is_wipe_tower || volume->composite_id.volume_id < 0))) continue; const BoundingBoxf3& bb = volume->transformed_convex_hull_bounding_box(); @@ -985,8 +992,7 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M if (!volume->printable) continue; - if (contained) - contained_min_one = true; + contained_min_one |= contained; if (state == ModelInstancePVS_Inside && volume->is_outside) state = ModelInstancePVS_Fully_Outside; @@ -1001,56 +1007,6 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M return contained_min_one; } -bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut) const -{ - if (config == nullptr) - return false; - - const ConfigOptionPoints* opt = dynamic_cast(config->option("bed_shape")); - if (opt == nullptr) - return false; - - const BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - BoundingBoxf3 print_volume(Vec3d(unscale(bed_box_2D.min.x()), unscale(bed_box_2D.min.y()), 0.0), Vec3d(unscale(bed_box_2D.max.x()), unscale(bed_box_2D.max.y()), config->opt_float("max_print_height"))); - // Allow the objects to protrude below the print bed - print_volume.min(2) = -1e10; - print_volume.min(0) -= BedEpsilon; - print_volume.min(1) -= BedEpsilon; - print_volume.max(0) += BedEpsilon; - print_volume.max(1) += BedEpsilon; - - bool contained_min_one = false; - - partlyOut = false; - fullyOut = false; - for (GLVolume* volume : this->volumes) { - if (volume == nullptr || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || (volume->composite_id.volume_id < 0 && !volume->shader_outside_printer_detection_enabled)) - continue; - - const BoundingBoxf3& bb = volume->transformed_convex_hull_bounding_box(); - bool contained = print_volume.contains(bb); - - volume->is_outside = !contained; - if (!volume->printable) - continue; - - if (contained) - contained_min_one = true; - - if (volume->is_outside) { - if (print_volume.intersects(bb)) - partlyOut = true; - else - fullyOut = true; - } - } - /* - if (out_state != nullptr) - *out_state = state; - */ - return contained_min_one; -} - void GLVolumeCollection::reset_outside_state() { for (GLVolume* volume : this->volumes) diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index e5298ca931..35abe8bd4d 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -614,7 +614,6 @@ public: // returns true if all the volumes are completely contained in the print volume // returns the containment state in the given out_state, if non-null bool check_outside_state(const DynamicPrintConfig* config, ModelInstanceEPrintVolumeState* out_state) const; - bool check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut) const; void reset_outside_state(); void update_colors_by_extruder(const DynamicPrintConfig* config); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f50c7fe25b..37493e754c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1107,11 +1107,11 @@ void GLCanvas3D::reset_volumes() _set_warning_notification(EWarning::ObjectOutside, false); } -int GLCanvas3D::check_volumes_outside_state() const +ModelInstanceEPrintVolumeState GLCanvas3D::check_volumes_outside_state() const { ModelInstanceEPrintVolumeState state; m_volumes.check_outside_state(m_config, &state); - return (int)state; + return state; } void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo, int instance_idx) @@ -2039,9 +2039,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re // checks for geometry outside the print volume to render it accordingly if (!m_volumes.empty()) { - bool partlyOut = false; - bool fullyOut = false; - const bool contained_min_one = m_volumes.check_outside_state(m_config, partlyOut, fullyOut); + ModelInstanceEPrintVolumeState state; + const bool contained_min_one = m_volumes.check_outside_state(m_config, &state); + const bool partlyOut = (state == ModelInstanceEPrintVolumeState::ModelInstancePVS_Partly_Outside); + const bool fullyOut = (state == ModelInstanceEPrintVolumeState::ModelInstancePVS_Fully_Outside); _set_warning_notification(EWarning::ObjectClashed, partlyOut); _set_warning_notification(EWarning::ObjectOutside, fullyOut); @@ -2121,7 +2122,7 @@ void GLCanvas3D::load_sla_preview() if (m_canvas != nullptr && print != nullptr) { _set_current(); // Release OpenGL data before generating new data. - this->reset_volumes(); + reset_volumes(); _load_sla_shells(); _update_sla_shells_outside_state(); _set_warning_notification_if_needed(EWarning::SlaSupportsOutside); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 799fa11c79..eb0220cd47 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -615,7 +615,7 @@ public: unsigned int get_volumes_count() const; const GLVolumeCollection& get_volumes() const { return m_volumes; } void reset_volumes(); - int check_volumes_outside_state() const; + ModelInstanceEPrintVolumeState check_volumes_outside_state() const; void reset_gcode_toolpaths() { m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 8c10fb1576..45da928f57 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -128,11 +128,6 @@ void View3D::mirror_selection(Axis axis) m_canvas->mirror_selection(axis); } -int View3D::check_volumes_outside_state() const -{ - return (m_canvas != nullptr) ? m_canvas->check_volumes_outside_state() : false; -} - bool View3D::is_layers_editing_enabled() const { return (m_canvas != nullptr) ? m_canvas->is_layers_editing_enabled() : false; diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index f8a41fd926..97ced0a1e0 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -59,8 +59,6 @@ public: void delete_selected(); void mirror_selection(Axis axis); - int check_volumes_outside_state() const; - bool is_layers_editing_enabled() const; bool is_layers_editing_allowed() const; void enable_layers_editing(bool enable); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 76612a718c..656b879722 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2724,7 +2724,7 @@ void Plater::priv::object_list_changed() { const bool export_in_progress = this->background_process.is_export_scheduled(); // || ! send_gcode_file.empty()); // XXX: is this right? - const bool model_fits = view3D->check_volumes_outside_state() == ModelInstancePVS_Inside; + const bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state() == ModelInstancePVS_Inside; sidebar->enable_buttons(!model.objects.empty() && !export_in_progress && model_fits); } @@ -3664,7 +3664,7 @@ void Plater::priv::set_current_panel(wxPanel* panel) // see: Plater::priv::object_list_changed() // FIXME: it may be better to have a single function making this check and let it be called wherever needed bool export_in_progress = this->background_process.is_export_scheduled(); - bool model_fits = view3D->check_volumes_outside_state() != ModelInstancePVS_Partly_Outside; + bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state() != ModelInstancePVS_Partly_Outside; if (!model.objects.empty() && !export_in_progress && model_fits) this->q->reslice(); // keeps current gcode preview, if any