From 2848ae9c4d530c21d949e88507311512cfb5f624 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 19 Jul 2021 11:11:49 +0200 Subject: [PATCH 1/8] Colors in GLVolume defined as std::array --- src/slic3r/GUI/3DScene.cpp | 99 +++++++++++++++-------------------- src/slic3r/GUI/3DScene.hpp | 35 +++++++------ src/slic3r/GUI/GLCanvas3D.cpp | 58 ++++++++++---------- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- 4 files changed, 88 insertions(+), 106 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index b98f2bbe7..4e0db4e02 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -286,21 +286,21 @@ void GLIndexedVertexArray::render( glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } -const float GLVolume::SELECTED_COLOR[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; -const float GLVolume::HOVER_SELECT_COLOR[4] = { 0.4f, 0.9f, 0.1f, 1.0f }; -const float GLVolume::HOVER_DESELECT_COLOR[4] = { 1.0f, 0.75f, 0.75f, 1.0f }; -const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f }; -const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; -const float GLVolume::DISABLED_COLOR[4] = { 0.25f, 0.25f, 0.25f, 1.0f }; -const float GLVolume::MODEL_COLOR[4][4] = { +const std::array GLVolume::SELECTED_COLOR = { 0.0f, 1.0f, 0.0f, 1.0f }; +const std::array GLVolume::HOVER_SELECT_COLOR = { 0.4f, 0.9f, 0.1f, 1.0f }; +const std::array GLVolume::HOVER_DESELECT_COLOR = { 1.0f, 0.75f, 0.75f, 1.0f }; +const std::array GLVolume::OUTSIDE_COLOR = { 0.0f, 0.38f, 0.8f, 1.0f }; +const std::array GLVolume::SELECTED_OUTSIDE_COLOR = { 0.19f, 0.58f, 1.0f, 1.0f }; +const std::array GLVolume::DISABLED_COLOR = { 0.25f, 0.25f, 0.25f, 1.0f }; +const std::array GLVolume::SLA_SUPPORT_COLOR = { 0.75f, 0.75f, 0.75f, 1.0f }; +const std::array GLVolume::SLA_PAD_COLOR = { 0.0f, 0.2f, 0.0f, 1.0f }; +const std::array GLVolume::NEUTRAL_COLOR = { 0.9f, 0.9f, 0.9f, 1.0f }; +const std::array, 4> GLVolume::MODEL_COLOR = { { { 1.0f, 1.0f, 0.0f, 1.f }, { 1.0f, 0.5f, 0.5f, 1.f }, { 0.5f, 1.0f, 0.5f, 1.f }, { 0.5f, 0.5f, 1.0f, 1.f } -}; -const float GLVolume::SLA_SUPPORT_COLOR[4] = { 0.75f, 0.75f, 0.75f, 1.0f }; -const float GLVolume::SLA_PAD_COLOR[4] = { 0.0f, 0.2f, 0.0f, 1.0f }; -const float GLVolume::NEUTRAL_COLOR[4] = { 0.9f, 0.9f, 0.9f, 1.0f }; +} }; GLVolume::GLVolume(float r, float g, float b, float a) : m_transformed_bounding_box_dirty(true) @@ -326,24 +326,18 @@ GLVolume::GLVolume(float r, float g, float b, float a) , tverts_range(0, size_t(-1)) , qverts_range(0, size_t(-1)) { - color[0] = r; - color[1] = g; - color[2] = b; - color[3] = a; - set_render_color(r, g, b, a); + color = { r, g, b, a }; + set_render_color(color); } void GLVolume::set_render_color(float r, float g, float b, float a) { - render_color[0] = r; - render_color[1] = g; - render_color[2] = b; - render_color[3] = a; + render_color = { r, g, b, a }; } -void GLVolume::set_render_color(const float* rgba, unsigned int size) +void GLVolume::set_render_color(const std::array& rgba) { - ::memcpy((void*)render_color, (const void*)rgba, (size_t)(std::min((unsigned int)4, size) * sizeof(float))); + render_color = rgba; } void GLVolume::set_render_color() @@ -358,35 +352,35 @@ void GLVolume::set_render_color() #else if (is_outside && shader_outside_printer_detection_enabled) #endif // ENABLE_ALLOW_NEGATIVE_Z - set_render_color(OUTSIDE_COLOR, 4); + set_render_color(OUTSIDE_COLOR); else { if (force_native_color) - set_render_color(color, 4); + set_render_color(color); else - set_render_color(NEUTRAL_COLOR, 4); + set_render_color(NEUTRAL_COLOR); } } else { if (hover == HS_Select) - set_render_color(HOVER_SELECT_COLOR, 4); + set_render_color(HOVER_SELECT_COLOR); else if (hover == HS_Deselect) - set_render_color(HOVER_DESELECT_COLOR, 4); + set_render_color(HOVER_DESELECT_COLOR); else if (selected) #if ENABLE_ALLOW_NEGATIVE_Z - set_render_color(outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR, 4); + set_render_color(outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR); #else - set_render_color(is_outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR, 4); + set_render_color(is_outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR); #endif // ENABLE_ALLOW_NEGATIVE_Z else if (disabled) - set_render_color(DISABLED_COLOR, 4); + set_render_color(DISABLED_COLOR); #if ENABLE_ALLOW_NEGATIVE_Z else if (outside && shader_outside_printer_detection_enabled) #else else if (is_outside && shader_outside_printer_detection_enabled) #endif // ENABLE_ALLOW_NEGATIVE_Z - set_render_color(OUTSIDE_COLOR, 4); + set_render_color(OUTSIDE_COLOR); else - set_render_color(color, 4); + set_render_color(color); } if (!printable) { @@ -399,29 +393,29 @@ void GLVolume::set_render_color() render_color[3] = color[3]; } -void GLVolume::set_color_from_model_volume(const ModelVolume *model_volume) +void GLVolume::set_color_from_model_volume(const ModelVolume& model_volume) { - if (model_volume->is_negative_volume()) { + if (model_volume.is_negative_volume()) { color[0] = 0.2f; color[1] = 0.2f; color[2] = 0.2f; } - else if (model_volume->is_modifier()) { + else if (model_volume.is_modifier()) { color[0] = 0.2f; color[1] = 1.0f; color[2] = 0.2f; } - else if (model_volume->is_support_blocker()) { + else if (model_volume.is_support_blocker()) { color[0] = 1.0f; color[1] = 0.2f; color[2] = 0.2f; } - else if (model_volume->is_support_enforcer()) { + else if (model_volume.is_support_enforcer()) { color[0] = 0.2f; color[1] = 0.2f; color[2] = 1.0f; } - color[3] = model_volume->is_model_part() ? 1.f : 0.5f; + color[3] = model_volume.is_model_part() ? 1.f : 0.5f; } Transform3d GLVolume::world_matrix() const @@ -571,22 +565,11 @@ int GLVolumeCollection::load_object_volume( const int extruder_id = model_volume->extruder_id(); const ModelInstance *instance = model_object->instances[instance_idx]; const TriangleMesh &mesh = model_volume->mesh(); - float color[4]; - memcpy(color, GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4], sizeof(float) * 3); - /* if (model_volume->is_support_blocker()) { - color[0] = 1.0f; - color[1] = 0.2f; - color[2] = 0.2f; - } else if (model_volume->is_support_enforcer()) { - color[0] = 0.2f; - color[1] = 0.2f; - color[2] = 1.0f; - } - color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */ + std::array color = GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4]; color[3] = model_volume->is_model_part() ? 1.f : 0.5f; this->volumes.emplace_back(new GLVolume(color)); GLVolume& v = *this->volumes.back(); - v.set_color_from_model_volume(model_volume); + v.set_color_from_model_volume(*model_volume); #if ENABLE_SMOOTH_NORMALS v.indexed_vertex_array.load_mesh(mesh, true); #else @@ -664,7 +647,7 @@ int GLVolumeCollection::load_wipe_tower_preview( height = 0.1f; TriangleMesh mesh; - float color[4] = { 0.5f, 0.5f, 0.0f, 1.f }; + std::array color = { 0.5f, 0.5f, 0.0f, 1.0f }; // In case we don't know precise dimensions of the wipe tower yet, we'll draw // the box with different color with one side jagged: @@ -712,8 +695,8 @@ int GLVolumeCollection::load_wipe_tower_preview( brim_mesh.translate(-brim_width, -brim_width, 0.f); mesh.merge(brim_mesh); - this->volumes.emplace_back(new GLVolume(color)); - GLVolume& v = *this->volumes.back(); + volumes.emplace_back(new GLVolume(color)); + GLVolume& v = *volumes.back(); v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.finalize_geometry(opengl_initialized); v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); @@ -723,17 +706,17 @@ int GLVolumeCollection::load_wipe_tower_preview( v.geometry_id.second = wipe_tower_instance_id().id; v.is_wipe_tower = true; v.shader_outside_printer_detection_enabled = !size_unknown; - return int(this->volumes.size() - 1); + return int(volumes.size() - 1); } -GLVolume* GLVolumeCollection::new_toolpath_volume(const float *rgba, size_t reserve_vbo_floats) +GLVolume* GLVolumeCollection::new_toolpath_volume(const std::array& rgba, size_t reserve_vbo_floats) { GLVolume *out = new_nontoolpath_volume(rgba, reserve_vbo_floats); out->is_extrusion_path = true; return out; } -GLVolume* GLVolumeCollection::new_nontoolpath_volume(const float *rgba, size_t reserve_vbo_floats) +GLVolume* GLVolumeCollection::new_nontoolpath_volume(const std::array& rgba, size_t reserve_vbo_floats) { GLVolume *out = new GLVolume(rgba); out->is_extrusion_path = false; @@ -812,7 +795,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func); for (GLVolumeWithIdAndZ& volume : to_render) { volume.first->set_render_color(); - shader->set_uniform("uniform_color", volume.first->render_color, 4); + shader->set_uniform("uniform_color", volume.first->render_color); shader->set_uniform("print_box.actived", volume.first->shader_outside_printer_detection_enabled); shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index c7984fc61..217d39746 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -236,16 +236,16 @@ private: class GLVolume { public: - static const float SELECTED_COLOR[4]; - static const float HOVER_SELECT_COLOR[4]; - static const float HOVER_DESELECT_COLOR[4]; - static const float OUTSIDE_COLOR[4]; - static const float SELECTED_OUTSIDE_COLOR[4]; - static const float DISABLED_COLOR[4]; - static const float MODEL_COLOR[4][4]; - static const float SLA_SUPPORT_COLOR[4]; - static const float SLA_PAD_COLOR[4]; - static const float NEUTRAL_COLOR[4]; + static const std::array SELECTED_COLOR; + static const std::array HOVER_SELECT_COLOR; + static const std::array HOVER_DESELECT_COLOR; + static const std::array OUTSIDE_COLOR; + static const std::array SELECTED_OUTSIDE_COLOR; + static const std::array DISABLED_COLOR; + static const std::array SLA_SUPPORT_COLOR; + static const std::array SLA_PAD_COLOR; + static const std::array NEUTRAL_COLOR; + static const std::array, 4> MODEL_COLOR; enum EHoverState : unsigned char { @@ -255,7 +255,7 @@ public: }; GLVolume(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f); - GLVolume(const float *rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {} + GLVolume(const std::array& rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {} private: Geometry::Transformation m_instance_transformation; @@ -276,9 +276,10 @@ private: public: // Color of the triangles / quads held by this volume. - float color[4]; + std::array color; // Color used to render this volume. - float render_color[4]; + std::array render_color; + struct CompositeID { CompositeID(int object_id, int volume_id, int instance_id) : object_id(object_id), volume_id(volume_id), instance_id(instance_id) {} CompositeID() : object_id(-1), volume_id(-1), instance_id(-1) {} @@ -362,11 +363,11 @@ public: } void set_render_color(float r, float g, float b, float a); - void set_render_color(const float* rgba, unsigned int size); + void set_render_color(const std::array& rgba); // Sets render color in dependence of current state void set_render_color(); // set color according to model volume - void set_color_from_model_volume(const ModelVolume *model_volume); + void set_color_from_model_volume(const ModelVolume& model_volume); const Geometry::Transformation& get_instance_transformation() const { return m_instance_transformation; } void set_instance_transformation(const Geometry::Transformation& transformation) { m_instance_transformation = transformation; set_bounding_boxes_as_dirty(); } @@ -542,8 +543,8 @@ public: int load_wipe_tower_preview( int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized); - GLVolume* new_toolpath_volume(const float *rgba, size_t reserve_vbo_floats = 0); - GLVolume* new_nontoolpath_volume(const float *rgba, size_t reserve_vbo_floats = 0); + GLVolume* new_toolpath_volume(const std::array& rgba, size_t reserve_vbo_floats = 0); + GLVolume* new_nontoolpath_volume(const std::array& rgba, size_t reserve_vbo_floats = 0); // Render the volumes by OpenGL. void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func = std::function()) const; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d40acb68b..c064a48f7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1881,7 +1881,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re volume->extruder_id = extruder_id; volume->is_modifier = !mvs->model_volume->is_model_part(); - volume->set_color_from_model_volume(mvs->model_volume); + volume->set_color_from_model_volume(*mvs->model_volume); // updates volumes transformations volume->set_instance_transformation(mvs->model_volume->get_object()->instances[mvs->composite_id.instance_id]->get_transformation()); @@ -5710,7 +5710,7 @@ void GLCanvas3D::_load_print_toolpaths() if (!print->has_skirt() && !print->has_brim()) return; - const float color[] = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish + const std::array color = { 0.5f, 1.0f, 0.5f, 1.0f }; // greenish // number of skirt layers size_t total_layer_count = 0; @@ -5756,7 +5756,7 @@ void GLCanvas3D::_load_print_toolpaths() void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector& str_tool_colors, const std::vector& color_print_values) { - std::vector tool_colors = _parse_colors(str_tool_colors); + std::vector> tool_colors = _parse_colors(str_tool_colors); struct Ctxt { @@ -5765,20 +5765,20 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c bool has_perimeters; bool has_infill; bool has_support; - const std::vector* tool_colors; + const std::vector>* tool_colors; bool is_single_material_print; int extruders_cnt; const std::vector* color_print_values; - static const float* color_perimeters() { static float color[4] = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow - static const float* color_infill() { static float color[4] = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish - static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish - static const float* color_pause_or_custom_code() { static float color[4] = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray + static const std::array& color_perimeters() { static std::array color = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow + static const std::array& color_infill() { static std::array color = { 1.0f, 0.5f, 0.5f, 1.f }; return color; } // redish + static const std::array& color_support() { static std::array color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish + static const std::array& color_pause_or_custom_code() { static std::array color = { 0.5f, 0.5f, 0.5f, 1.f }; return color; } // gray // For cloring by a tool, return a parsed color. bool color_by_tool() const { return tool_colors != nullptr; } - size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } - const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } + size_t number_tools() const { return color_by_tool() ? tool_colors->size() : 0; } + const std::array& color_tool(size_t tool) const { return (*tool_colors)[tool]; } // For coloring by a color_print(M600), return a parsed color. bool color_by_color_print() const { return color_print_values!=nullptr; } @@ -5918,8 +5918,8 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c //FIXME Improve the heuristics for a grain size. size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1)); tbb::spin_mutex new_volume_mutex; - auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* { - // Allocate the volume before locking. + auto new_volume = [this, &new_volume_mutex](const std::array& color) { + // Allocate the volume before locking. GLVolume *volume = new GLVolume(color); volume->is_extrusion_path = true; tbb::spin_mutex::scoped_lock lock; @@ -6056,23 +6056,22 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector& str_ if (!print->is_step_done(psWipeTower)) return; - std::vector tool_colors = _parse_colors(str_tool_colors); + std::vector> tool_colors = _parse_colors(str_tool_colors); struct Ctxt { const Print *print; - const std::vector *tool_colors; + const std::vector>* tool_colors; Vec2f wipe_tower_pos; float wipe_tower_angle; - static const float* color_support() { static float color[4] = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish + static const std::array& color_support() { static std::array color = { 0.5f, 1.0f, 0.5f, 1.f }; return color; } // greenish // For cloring by a tool, return a parsed color. bool color_by_tool() const { return tool_colors != nullptr; } - size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() / 4 : 0; } - const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; } - int volume_idx(int tool, int feature) const - { + size_t number_tools() const { return this->color_by_tool() ? tool_colors->size() : 0; } + const std::array& color_tool(size_t tool) const { return (*tool_colors)[tool]; } + int volume_idx(int tool, int feature) const { return this->color_by_tool() ? std::min(this->number_tools() - 1, std::max(tool, 0)) : feature; } @@ -6103,7 +6102,7 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector& str_ size_t n_items = print->wipe_tower_data().tool_changes.size() + (ctxt.priming.empty() ? 0 : 1); size_t grain_size = std::max(n_items / 128, size_t(1)); tbb::spin_mutex new_volume_mutex; - auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* { + auto new_volume = [this, &new_volume_mutex](const std::array& color) { auto *volume = new GLVolume(color); volume->is_extrusion_path = true; tbb::spin_mutex::scoped_lock lock; @@ -6219,7 +6218,7 @@ void GLCanvas3D::_load_sla_shells() return; auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance, - const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) { + const TriangleMesh& mesh, const std::array& color, bool outside_printer_detection_enabled) { m_volumes.volumes.emplace_back(new GLVolume(color)); GLVolume& v = *m_volumes.volumes.back(); #if ENABLE_SMOOTH_NORMALS @@ -6230,8 +6229,8 @@ void GLCanvas3D::_load_sla_shells() v.indexed_vertex_array.finalize_geometry(m_initialized); v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled; v.composite_id.volume_id = volume_id; - v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0)); - v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation)); + v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0.0)); + v.set_instance_rotation({ 0.0, 0.0, (double)instance.rotation }); v.set_instance_mirror(X, object.is_left_handed() ? -1. : 1.); v.set_convex_hull(mesh.convex_hull_3d()); }; @@ -6252,9 +6251,8 @@ void GLCanvas3D::_load_sla_shells() } double shift_z = obj->get_current_elevation(); for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) { - GLVolume& v = *m_volumes.volumes[i]; // apply shift z - v.set_sla_shift_z(shift_z); + m_volumes.volumes[i]->set_sla_shift_z(shift_z); } } @@ -6265,7 +6263,7 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state() { BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); for (GLVolume* volume : m_volumes.volumes) { - volume->is_outside = ((test_volume.radius() > 0.0) && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false; + volume->is_outside = (test_volume.radius() > 0.0 && volume->is_extrusion_path) ? !test_volume.contains(volume->bounding_box()) : false; } } @@ -6273,7 +6271,7 @@ void GLCanvas3D::_update_sla_shells_outside_state() { BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); for (GLVolume* volume : m_volumes.volumes) { - volume->is_outside = ((test_volume.radius() > 0.0) && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false; + volume->is_outside = (test_volume.radius() > 0.0 && volume->shader_outside_printer_detection_enabled) ? !test_volume.contains(volume->transformed_convex_hull_bounding_box()) : false; } } @@ -6294,11 +6292,11 @@ void GLCanvas3D::_set_warning_notification_if_needed(EWarning warning) _set_warning_notification(warning, show); } -std::vector GLCanvas3D::_parse_colors(const std::vector& colors) +std::vector> GLCanvas3D::_parse_colors(const std::vector& colors) { static const float INV_255 = 1.0f / 255.0f; - std::vector output(colors.size() * 4, 1.0f); + std::vector> output(colors.size(), { 1.0f, 1.0f, 1.0f, 1.0f }); for (size_t i = 0; i < colors.size(); ++i) { const std::string& color = colors[i]; const char* c = color.data() + 1; @@ -6309,7 +6307,7 @@ std::vector GLCanvas3D::_parse_colors(const std::vector& col if (digit1 == -1 || digit2 == -1) break; - output[i * 4 + j] = float(digit1 * 16 + digit2) * INV_255; + output[i][j] = float(digit1 * 16 + digit2) * INV_255; } } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index aa999a409..2c85ca52f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -907,7 +907,7 @@ private: float get_overlay_window_width() { return LayersEditing::get_overlay_window_width(); } - static std::vector _parse_colors(const std::vector& colors); + static std::vector> GLCanvas3D::_parse_colors(const std::vector& colors); }; } // namespace GUI From ccf67793bdf4f6ff356423d6dbd96aaa073a0a8d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 19 Jul 2021 11:21:26 +0200 Subject: [PATCH 2/8] Fixed typo introduced with 2848ae9c4d530c21d949e88507311512cfb5f624 --- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 2c85ca52f..413719721 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -907,7 +907,7 @@ private: float get_overlay_window_width() { return LayersEditing::get_overlay_window_width(); } - static std::vector> GLCanvas3D::_parse_colors(const std::vector& colors); + static std::vector> _parse_colors(const std::vector& colors); }; } // namespace GUI From 5b67fafb75f6cc20c9e3b738756bb032ba0c1b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Mon, 19 Jul 2021 10:24:38 +0200 Subject: [PATCH 3/8] Fixed a crash in the multi-material gizmo when bucket fill is selected. --- src/libslic3r/TriangleSelector.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libslic3r/TriangleSelector.cpp b/src/libslic3r/TriangleSelector.cpp index b64bef17a..e7be260f6 100644 --- a/src/libslic3r/TriangleSelector.cpp +++ b/src/libslic3r/TriangleSelector.cpp @@ -333,6 +333,9 @@ void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_ if (!visited[current_facet]) { m_triangles[current_facet].select_by_seed_fill(); for(int neighbor_idx : all_level_neighbors[current_facet]) { + if(neighbor_idx < 0 || visited[neighbor_idx]) + continue; + if(!m_triangles[neighbor_idx].is_split()) { if(m_triangles[neighbor_idx].get_state() == start_facet_state) facet_queue.push(neighbor_idx); From 5405ab19866114c7159fb7c47033af48b44cc357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Mon, 19 Jul 2021 11:15:04 +0200 Subject: [PATCH 4/8] Optimized seed fill and bucket fill selection to recompute selection only in case the cursor is pointing on a non-selected triangle. --- src/libslic3r/TriangleSelector.cpp | 63 ++++++++++++++++-------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/libslic3r/TriangleSelector.cpp b/src/libslic3r/TriangleSelector.cpp index e7be260f6..a349fe35a 100644 --- a/src/libslic3r/TriangleSelector.cpp +++ b/src/libslic3r/TriangleSelector.cpp @@ -65,8 +65,8 @@ void TriangleSelector::Triangle::set_division(int sides_to_split, int special_si assert(sides_to_split >= 0 && sides_to_split <= 3); assert(special_side_idx >= 0 && special_side_idx < 3); assert(sides_to_split == 1 || sides_to_split == 2 || special_side_idx == 0); - this->number_of_splits = sides_to_split; - this->special_side_idx = special_side_idx; + this->number_of_splits = char(sides_to_split); + this->special_side_idx = char(special_side_idx); } inline bool is_point_inside_triangle(const Vec3f &pt, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3) @@ -167,8 +167,7 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start, if (! visited[facet]) { if (select_triangle(facet, new_state, triangle_splitting)) { // add neighboring facets to list to be proccessed later - for (int n=0; n<3; ++n) { - int neighbor_idx = m_mesh->stl.neighbors_start[facet].neighbor[n]; + for (int neighbor_idx : m_mesh->stl.neighbors_start[facet].neighbor) { if (neighbor_idx >=0 && (m_cursor.type == SPHERE || faces_camera(neighbor_idx))) facets_to_check.push_back(neighbor_idx); } @@ -182,6 +181,11 @@ void TriangleSelector::select_patch(const Vec3f& hit, int facet_start, void TriangleSelector::seed_fill_select_triangles(const Vec3f &hit, int facet_start, float seed_fill_angle) { assert(facet_start < m_orig_size_indices); + + // Recompute seed fill only if the cursor is pointing on facet unselected by seed fill. + if (int start_facet_idx = select_unsplit_triangle(hit, facet_start); start_facet_idx >= 0 && m_triangles[start_facet_idx].is_selected_by_seed_fill()) + return; + this->seed_fill_unselect_all_triangles(); std::vector visited(m_triangles.size(), false); @@ -308,13 +312,15 @@ std::vector TriangleSelector::neighboring_triangles(const int first_facet_i void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_start, bool propagate) { - this->seed_fill_unselect_all_triangles(); - - int start_facet_idx = select_unsplit_triangle(hit, facet_start); - EnforcerBlockerType start_facet_state = m_triangles[start_facet_idx].get_state(); - if (start_facet_idx == -1) + int start_facet_idx = select_unsplit_triangle(hit, facet_start); + // Recompute bucket fill only if the cursor is pointing on facet unselected by bucket fill. + if (start_facet_idx == -1 || m_triangles[start_facet_idx].is_selected_by_seed_fill()) return; + assert(!m_triangles[start_facet_idx].is_split()); + EnforcerBlockerType start_facet_state = m_triangles[start_facet_idx].get_state(); + this->seed_fill_unselect_all_triangles(); + if (!propagate) { m_triangles[start_facet_idx].select_by_seed_fill(); return; @@ -332,15 +338,15 @@ void TriangleSelector::bucket_fill_select_triangles(const Vec3f& hit, int facet_ if (!visited[current_facet]) { m_triangles[current_facet].select_by_seed_fill(); - for(int neighbor_idx : all_level_neighbors[current_facet]) { - if(neighbor_idx < 0 || visited[neighbor_idx]) + for (int neighbor_idx : all_level_neighbors[current_facet]) { + if (neighbor_idx < 0 || visited[neighbor_idx]) continue; - if(!m_triangles[neighbor_idx].is_split()) { - if(m_triangles[neighbor_idx].get_state() == start_facet_state) + if (!m_triangles[neighbor_idx].is_split()) { + if (m_triangles[neighbor_idx].get_state() == start_facet_state) facet_queue.push(neighbor_idx); } else { - for(int neighbor_facet_idx : neighboring_triangles(neighbor_idx, current_facet, start_facet_state)) + for (int neighbor_facet_idx : neighboring_triangles(neighbor_idx, current_facet, start_facet_state)) facet_queue.push(neighbor_facet_idx); } } @@ -478,7 +484,7 @@ int TriangleSelector::triangle_midpoint_or_allocate(int itriangle, int vertexi, Vec3f c = 0.5f * (m_vertices[vertexi].v + m_vertices[vertexj].v); #ifdef EXPENSIVE_DEBUG_CHECKS // Verify that the vertex is really a new one. - auto it = std::find_if(m_vertices.begin(), m_vertices.end(), [this, c](const Vertex &v) { + auto it = std::find_if(m_vertices.begin(), m_vertices.end(), [c](const Vertex &v) { return v.ref_cnt > 0 && (v.v - c).norm() < EPSILON; }); assert(it == m_vertices.end()); #endif // EXPENSIVE_DEBUG_CHECKS @@ -777,10 +783,9 @@ void TriangleSelector::split_triangle(int facet_idx, const Vec3i &neighbors) } } - std::array sides; - sides = { (*pts[2]-*pts[1]).squaredNorm(), - (*pts[0]-*pts[2]).squaredNorm(), - (*pts[1]-*pts[0]).squaredNorm() }; + std::array sides = {(*pts[2] - *pts[1]).squaredNorm(), + (*pts[0] - *pts[2]).squaredNorm(), + (*pts[1] - *pts[0]).squaredNorm()}; boost::container::small_vector sides_to_split; int side_to_keep = -1; @@ -798,7 +803,7 @@ void TriangleSelector::split_triangle(int facet_idx, const Vec3i &neighbors) // Save how the triangle will be split. Second argument makes sense only for one // or two split sides, otherwise the value is ignored. - tr->set_division(sides_to_split.size(), + tr->set_division(int(sides_to_split.size()), sides_to_split.size() == 2 ? side_to_keep : sides_to_split[0]); perform_split(facet_idx, neighbors, old_type); @@ -1026,12 +1031,12 @@ void TriangleSelector::reset() for (const stl_vertex& vert : m_mesh->its.vertices) m_vertices.emplace_back(vert); m_triangles.reserve(m_mesh->its.indices.size()); - for (size_t i=0; iits.indices.size(); ++i) { - const stl_triangle_vertex_indices& ind = m_mesh->its.indices[i]; - push_triangle(ind[0], ind[1], ind[2], i); + for (size_t i = 0; i < m_mesh->its.indices.size(); ++i) { + const stl_triangle_vertex_indices &ind = m_mesh->its.indices[i]; + push_triangle(ind[0], ind[1], ind[2], int(i)); } - m_orig_size_vertices = m_vertices.size(); - m_orig_size_indices = m_triangles.size(); + m_orig_size_vertices = int(m_vertices.size()); + m_orig_size_indices = int(m_triangles.size()); } @@ -1412,7 +1417,7 @@ void TriangleSelector::deserialize(const std::pair &triangle_id_and_ibit : data.first) { int ibit = triangle_id_and_ibit.second; - assert(ibit < data.second.size()); + assert(ibit < int(data.second.size())); auto next_nibble = [&data, &ibit = ibit]() { int n = 0; for (int i = 0; i < 4; ++ i) @@ -1556,7 +1561,7 @@ void TriangleSelector::seed_fill_apply_on_triangles(EnforcerBlockerType new_stat for (Triangle &triangle : m_triangles) if (triangle.is_split() && triangle.valid()) { size_t facet_idx = &triangle - &m_triangles.front(); - remove_useless_children(facet_idx); + remove_useless_children(int(facet_idx)); } } @@ -1570,7 +1575,7 @@ TriangleSelector::Cursor::Cursor( { Vec3d sf = Geometry::Transformation(trafo_).get_scaling_factor(); if (is_approx(sf(0), sf(1)) && is_approx(sf(1), sf(2))) { - radius_sqr = std::pow(radius_world / sf(0), 2); + radius_sqr = float(std::pow(radius_world / sf(0), 2)); uniform_scaling = true; } else { From 75a2d7620be013d786625a8cde228f666787dfc8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 19 Jul 2021 11:37:18 +0200 Subject: [PATCH 5/8] Removed striped shading for sinking objects --- resources/shaders/gouraud.fs | 9 --------- src/slic3r/GUI/3DScene.cpp | 4 ---- 2 files changed, 13 deletions(-) diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index dbbebf7d6..572b37c7f 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -31,7 +31,6 @@ struct SlopeDetection uniform vec4 uniform_color; uniform SlopeDetection slope; -uniform bool sinking; #ifdef ENABLE_ENVIRONMENT_MAP uniform sampler2D environment_tex; @@ -51,11 +50,6 @@ varying float world_pos_z; varying float world_normal_z; varying vec3 eye_normal; -vec3 sinking_color(vec3 color) -{ - return (mod(model_pos.x + model_pos.y + model_pos.z, BANDS_WIDTH) < (0.5 * BANDS_WIDTH)) ? mix(color, ZERO, 0.6666) : color; -} - uniform bool compute_triangle_normals_in_fs; void main() @@ -97,9 +91,6 @@ void main() } // if the fragment is outside the print volume -> use darker color color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; - // if the object is sinking, shade it with inclined bands or white around world z = 0 - if (sinking) - color = (abs(world_pos_z) < 0.05) ? WHITE : sinking_color(color); #ifdef ENABLE_ENVIRONMENT_MAP if (use_environment_tex) gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal_fs).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity_fs.x, alpha); diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 4e0db4e02..fb464ce02 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -800,10 +800,6 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab shader->set_uniform("print_box.volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); shader->set_uniform("slope.volume_world_normal_matrix", static_cast(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast())); -#if ENABLE_ALLOW_NEGATIVE_Z - shader->set_uniform("sinking", volume.first->is_sinking()); -#endif // ENABLE_ALLOW_NEGATIVE_Z - volume.first->render(); } From 4b5cf004bd528ff7b04d8a6cbd56157bf98bb204 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 19 Jul 2021 12:35:48 +0200 Subject: [PATCH 6/8] MSW specific: Fixed rescaling for the BitmapComboBox control and Notebook tab buttons --- src/slic3r/GUI/BitmapComboBox.cpp | 17 +++++++++++++- src/slic3r/GUI/BitmapComboBox.hpp | 2 ++ src/slic3r/GUI/Field.cpp | 3 +++ src/slic3r/GUI/GUI_ObjectManipulation.cpp | 3 +++ src/slic3r/GUI/GUI_Preview.cpp | 4 ++++ src/slic3r/GUI/Notebook.cpp | 27 ++++++++++++++++++----- src/slic3r/GUI/Notebook.hpp | 3 +++ src/slic3r/GUI/wxExtensions.cpp | 5 ++++- src/slic3r/GUI/wxExtensions.hpp | 2 ++ 9 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/BitmapComboBox.cpp b/src/slic3r/GUI/BitmapComboBox.cpp index f27c1b671..1864a3545 100644 --- a/src/slic3r/GUI/BitmapComboBox.cpp +++ b/src/slic3r/GUI/BitmapComboBox.cpp @@ -166,7 +166,7 @@ int BitmapComboBox::Append(const wxString& item) //2. But then set width to 0 value for no using of bitmap left and right spacing //3. Set this empty bitmap to the at list one item and BitmapCombobox will be recreated correct - wxBitmap bitmap(1, this->GetFont().GetPixelSize().y + 2); + wxBitmap bitmap(1, int(1.6 * wxGetApp().em_unit() + 1)); bitmap.SetWidth(0); OnAddBitmap(bitmap); @@ -260,6 +260,21 @@ void BitmapComboBox::DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED( dc.DrawRectangle(rect); } } + +void BitmapComboBox::Rescale() +{ + // Next workaround: To correct scaling of a BitmapCombobox + // we need to refill control with new bitmaps + const wxString selection = this->GetValue(); + std::vector items; + for (int i = 0; i < GetCount(); i++) + items.push_back(GetString(i)); + + this->Clear(); + for (const wxString& item : items) + Append(item); + this->SetValue(selection); +} #endif }} diff --git a/src/slic3r/GUI/BitmapComboBox.hpp b/src/slic3r/GUI/BitmapComboBox.hpp index c46edfd50..a77bf401d 100644 --- a/src/slic3r/GUI/BitmapComboBox.hpp +++ b/src/slic3r/GUI/BitmapComboBox.hpp @@ -54,6 +54,8 @@ void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const overrid #ifdef _WIN32 bool MSWOnDraw(WXDRAWITEMSTRUCT* item) override; void DrawBackground_(wxDC& dc, const wxRect& rect, int WXUNUSED(item), int flags) const; +public: +void Rescale(); #endif }; diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index e194898ee..49771081d 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1296,6 +1296,9 @@ void Choice::msw_rescale() field->SetValue(selection) : field->SetSelection(idx); #else +#ifdef _WIN32 + field->Rescale(); +#endif auto size = wxSize(def_width_wider() * m_em_unit, wxDefaultCoord); if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index f12adc9d1..d55acf054 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -106,6 +106,9 @@ void msw_rescale_word_local_combo(choice_ctrl* combo) combo->SetValue(selection); #else +#ifdef _WIN32 + combo->Rescale(); +#endif combo->SetMinSize(wxSize(15 * wxGetApp().em_unit(), -1)); #endif } diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 4a95eaedb..336ff8f51 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -402,6 +402,10 @@ void Preview::refresh_print() void Preview::msw_rescale() { +#ifdef _WIN32 + m_choice_view_type->Rescale(); + m_choice_view_type->SetMinSize(m_choice_view_type->GetSize()); +#endif // rescale slider if (m_layers_slider != nullptr) m_layers_slider->msw_rescale(); if (m_moves_slider != nullptr) m_moves_slider->msw_rescale(); diff --git a/src/slic3r/GUI/Notebook.cpp b/src/slic3r/GUI/Notebook.cpp index 25a0b565f..afc0241d8 100644 --- a/src/slic3r/GUI/Notebook.cpp +++ b/src/slic3r/GUI/Notebook.cpp @@ -17,13 +17,20 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = fal SetDoubleBuffered(true); #endif //__WINDOWS__ + int em = em_unit(this);// Slic3r::GUI::wxGetApp().em_unit(); + m_btn_margin = std::lround(0.3 * em); + m_line_margin = std::lround(0.1 * em); + m_sizer = new wxBoxSizer(wxHORIZONTAL); this->SetSizer(m_sizer); + m_buttons_sizer = new wxFlexGridSizer(4, m_btn_margin, m_btn_margin); + m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin); + if (add_mode_buttons) { - m_mode_sizer = new ModeSizer(this, int(0.5 * em_unit(this))); + m_mode_sizer = new ModeSizer(this, m_btn_margin); m_sizer->AddStretchSpacer(20); - m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5); + m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin); } this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this); @@ -53,12 +60,12 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&) const wxColour& clr = idx == m_selection ? btn_marker_color : default_btn_bg; dc.SetPen(clr); dc.SetBrush(clr); - dc.DrawRectangle(pos.x, sz.y - 3, size.x, 3); + dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y); } dc.SetPen(btn_marker_color); dc.SetBrush(btn_marker_color); - dc.DrawRectangle(1, sz.y - 1, sz.x, 1); + dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin); } void ButtonsListCtrl::UpdateMode() @@ -71,6 +78,14 @@ void ButtonsListCtrl::Rescale() m_mode_sizer->msw_rescale(); for (ScalableButton* btn : m_pageButtons) btn->msw_rescale(); + + int em = em_unit(this); + m_btn_margin = std::lround(0.3 * em); + m_line_margin = std::lround(0.1 * em); + m_buttons_sizer->SetVGap(m_btn_margin); + m_buttons_sizer->SetHGap(m_btn_margin); + + m_sizer->Layout(); } void ButtonsListCtrl::SetSelection(int sel) @@ -95,7 +110,7 @@ bool ButtonsListCtrl::InsertPage(size_t n, const wxString& text, bool bSelect/* }); Slic3r::GUI::wxGetApp().UpdateDarkUI(btn); m_pageButtons.insert(m_pageButtons.begin() + n, btn); - m_sizer->Insert(n, new wxSizerItem(btn, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3)); + m_buttons_sizer->Insert(n, new wxSizerItem(btn)); m_sizer->Layout(); return true; } @@ -104,7 +119,7 @@ void ButtonsListCtrl::RemovePage(size_t n) { ScalableButton* btn = m_pageButtons[n]; m_pageButtons.erase(m_pageButtons.begin() + n); - m_sizer->Remove(n); + m_buttons_sizer->Remove(n); btn->Reparent(nullptr); btn->Destroy(); m_sizer->Layout(); diff --git a/src/slic3r/GUI/Notebook.hpp b/src/slic3r/GUI/Notebook.hpp index ef42679e9..56e6ddf6c 100644 --- a/src/slic3r/GUI/Notebook.hpp +++ b/src/slic3r/GUI/Notebook.hpp @@ -29,9 +29,12 @@ public: private: wxWindow* m_parent; + wxFlexGridSizer* m_buttons_sizer; wxBoxSizer* m_sizer; std::vector m_pageButtons; int m_selection {-1}; + int m_btn_margin; + int m_line_margin; ModeSizer* m_mode_sizer {nullptr}; }; diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index f3be89ef9..819c91c62 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -694,7 +694,9 @@ void ModeButton::focus_button(const bool focus) // ---------------------------------------------------------------------------- ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) : - wxFlexGridSizer(3, 0, hgap) + wxFlexGridSizer(3, 0, hgap), + m_parent(parent), + m_hgap_unscaled((double)(hgap)/em_unit(parent)) { SetFlexibleDirection(wxHORIZONTAL); @@ -739,6 +741,7 @@ void ModeSizer::set_items_border(int border) void ModeSizer::msw_rescale() { + this->SetHGap(std::lround(m_hgap_unscaled * em_unit(m_parent))); for (size_t m = 0; m < m_mode_btns.size(); m++) m_mode_btns[m]->msw_rescale(); } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 2b8965ba2..1462e8aa0 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -315,6 +315,8 @@ public: private: std::vector m_mode_btns; + wxWindow* m_parent {nullptr}; + double m_hgap_unscaled; }; From d3ddb1cfa8fb3a8d3ad742e0ffeeccc9ad2b8849 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 19 Jul 2021 13:30:49 +0200 Subject: [PATCH 7/8] Fixed a bug with update of the warning icon for object after a deleting of the broken volume --- src/slic3r/GUI/GUI_ObjectList.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 9e2149a0e..5103e18bb 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2670,11 +2670,16 @@ void ObjectList::delete_from_model_and_list(const std::vector& it if (item->type&itVolume) { m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx)); - if ((*m_objects)[item->obj_idx]->volumes.size() == 1 && - (*m_objects)[item->obj_idx]->config.has("extruder")) - { - const wxString extruder = wxString::Format("%d", (*m_objects)[item->obj_idx]->config.extruder()); - m_objects_model->SetExtruder(extruder, m_objects_model->GetItemById(item->obj_idx)); + ModelObject* obj = object(item->obj_idx); + if (obj->volumes.size() == 1) { + wxDataViewItem parent = m_objects_model->GetItemById(item->obj_idx); + if (obj->config.has("extruder")) { + const wxString extruder = wxString::Format("%d", obj->config.extruder()); + m_objects_model->SetExtruder(extruder, parent); + } + // If last volume item with warning was deleted, unmark object item + if (obj->get_mesh_errors_count() == 0) + m_objects_model->DeleteWarningIcon(parent); } wxGetApp().plater()->canvas3D()->ensure_on_bed(item->obj_idx); } From 888a5e3084a406a96235ffe974d81367963b1f87 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 19 Jul 2021 15:46:50 +0200 Subject: [PATCH 8/8] Fixed of the warnings. + Some small bug-fixing related to the system colors change on MacOS ("Set..." buttons didn't respect to the system color change) --- src/slic3r/GUI/2DBed.cpp | 3 ++- src/slic3r/GUI/BitmapComboBox.cpp | 2 +- src/slic3r/GUI/GalleryDialog.cpp | 4 ++-- src/slic3r/GUI/OptionsGroup.cpp | 8 ++++---- src/slic3r/GUI/Tab.cpp | 17 ----------------- src/slic3r/GUI/Tab.hpp | 1 - src/slic3r/GUI/wxExtensions.cpp | 8 +++++++- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/slic3r/GUI/2DBed.cpp b/src/slic3r/GUI/2DBed.cpp index c4eec0b03..e184b43fc 100644 --- a/src/slic3r/GUI/2DBed.cpp +++ b/src/slic3r/GUI/2DBed.cpp @@ -14,9 +14,10 @@ namespace GUI { Bed_2D::Bed_2D(wxWindow* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTAB_TRAVERSAL) { - SetBackgroundStyle(wxBG_STYLE_PAINT); // to avoid assert message after wxAutoBufferedPaintDC #ifdef __APPLE__ m_user_drawn_background = false; +#else + SetBackgroundStyle(wxBG_STYLE_PAINT); // to avoid assert message after wxAutoBufferedPaintDC #endif /*__APPLE__*/ } diff --git a/src/slic3r/GUI/BitmapComboBox.cpp b/src/slic3r/GUI/BitmapComboBox.cpp index 1864a3545..fcbc4b666 100644 --- a/src/slic3r/GUI/BitmapComboBox.cpp +++ b/src/slic3r/GUI/BitmapComboBox.cpp @@ -267,7 +267,7 @@ void BitmapComboBox::Rescale() // we need to refill control with new bitmaps const wxString selection = this->GetValue(); std::vector items; - for (int i = 0; i < GetCount(); i++) + for (size_t i = 0; i < GetCount(); i++) items.push_back(GetString(i)); this->Clear(); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index d124eda69..163e33527 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -179,8 +179,8 @@ static void add_lock(wxImage& image) size_t beg_x = width - lock_width; size_t beg_y = height - lock_height; - for (size_t x = 0; x < lock_width; ++x) { - for (size_t y = 0; y < lock_height; ++y) { + for (size_t x = 0; x < (size_t)lock_width; ++x) { + for (size_t y = 0; y < (size_t)lock_height; ++y) { const size_t lock_idx = (x + y * lock_width); if (lock_a_data && lock_a_data[lock_idx] == 0) continue; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 7ebe71ef8..6624982dd 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -747,6 +747,10 @@ void ConfigOptionsGroup::sys_color_changed() wxGetApp().UpdateDarkUI(extra_col); } + if (custom_ctrl) + wxGetApp().UpdateDarkUI(custom_ctrl); +#endif + auto update = [](wxSizer* sizer) { for (wxSizerItem* item : sizer->GetChildren()) if (item->IsWindow()) { @@ -768,10 +772,6 @@ void ConfigOptionsGroup::sys_color_changed() update(line.extra_widget_sizer); } - if (custom_ctrl) - wxGetApp().UpdateDarkUI(custom_ctrl); -#endif - // update undo buttons : rescale bitmaps for (const auto& field : m_fields) field.second->sys_color_changed(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 3cda9e3e4..b642610d8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -709,29 +709,12 @@ void TabPrinter::msw_rescale() { Tab::msw_rescale(); - // rescale missed options_groups - const std::vector& pages = m_printer_technology == ptFFF ? m_pages_sla : m_pages_fff; - for (auto page : pages) - page->msw_rescale(); - if (m_reset_to_filament_color) m_reset_to_filament_color->msw_rescale(); Layout(); } -void TabPrinter::sys_color_changed() -{ - Tab::sys_color_changed(); - - // update missed options_groups - const std::vector& pages = m_printer_technology == ptFFF ? m_pages_sla : m_pages_fff; - for (auto page : pages) - page->sys_color_changed(); - - Layout(); -} - void TabSLAMaterial::init_options_list() { if (!m_options_list.empty()) diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 65c817cb6..80b9cd873 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -485,7 +485,6 @@ public: void on_preset_loaded() override; void init_options_list() override; void msw_rescale() override; - void sys_color_changed() override; #if ENABLE_PROJECT_DIRTY_STATE bool supports_printer_technology(const PrinterTechnology /* tech */) const override { return true; } #else diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 819c91c62..8903f3b30 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -889,6 +889,8 @@ bool ScalableButton::SetBitmap_(const std::string& bmp_name) wxBitmap bmp = create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt); SetBitmap(bmp); SetBitmapCurrent(bmp); + SetBitmapPressed(bmp); + SetBitmapFocus(bmp); if (m_use_default_disabled_bitmap) SetBitmapDisabled(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt, true)); return true; @@ -920,7 +922,11 @@ void ScalableButton::msw_rescale() Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border); if (!m_current_icon_name.empty()) { - SetBitmap(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt)); + wxBitmap bmp = create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt); + SetBitmap(bmp); + SetBitmapCurrent(bmp); + SetBitmapPressed(bmp); + SetBitmapFocus(bmp); if (!m_disabled_icon_name.empty()) SetBitmapDisabled(create_scaled_bitmap(m_disabled_icon_name, m_parent, m_px_cnt)); else if (m_use_default_disabled_bitmap)