From 69549af9ac0b6dddaf7f35f60820730e443be17f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 28 Jan 2020 11:11:45 +0100 Subject: [PATCH 1/7] Invalidate object bounding box after arrange --- src/libslic3r/Model.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index e0859e81d..2fbd58461 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -674,6 +674,7 @@ public: set_rotation(Z, rotation); set_offset(X, unscale(offs(X))); set_offset(Y, unscale(offs(Y))); + this->object->invalidate_bounding_box(); } protected: From 04a58e41c437f39d95d52aef0ef161a7c76fbd87 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 28 Jan 2020 14:49:07 +0100 Subject: [PATCH 2/7] Fix cgal when used from distro package fix CMake -frounding-math propagation from CGAL. --- src/libslic3r/CMakeLists.txt | 31 +++++++++++++++++++------------ src/libslic3r/MeshBoolean.cpp | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 0bad50abe..0f8f5b2c2 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -238,15 +238,24 @@ if (MSVC AND "${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") # 32 bit MSVC workaround set(_cgal_defines CGAL_DO_NOT_USE_MPZF) endif () -add_library(libslic3r_cgal OBJECT MeshBoolean.cpp MeshBoolean.hpp) -target_include_directories(libslic3r_cgal PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - $ - $) -target_compile_definitions(libslic3r_cgal PRIVATE ${_cgal_defines} - $) -target_compile_options(libslic3r_cgal PRIVATE - $) +add_library(libslic3r_cgal STATIC MeshBoolean.cpp MeshBoolean.hpp) +target_include_directories(libslic3r_cgal PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +# Reset compile options of libslic3r_cgal. Despite it being linked privately, CGAL options +# (-frounding-math) still propagate to dependent libs which is not desired. +get_target_property(_cgal_tgt CGAL::CGAL ALIASED_TARGET) +if (NOT TARGET ${_cgal_tgt}) + set (_cgal_tgt CGAL::CGAL) +endif () +get_target_property(_opts ${_cgal_tgt} INTERFACE_COMPILE_OPTIONS) +set(_opts_bad "${_opts}") +set(_opts_good "${_opts}") +list(FILTER _opts_bad INCLUDE REGEX frounding-math) +list(FILTER _opts_good EXCLUDE REGEX frounding-math) +set_target_properties(${_cgal_tgt} PROPERTIES INTERFACE_COMPILE_OPTIONS "${_opts_good}") + +target_link_libraries(libslic3r_cgal PRIVATE ${_cgal_tgt} libigl) +target_compile_options(libslic3r_cgal PRIVATE "${_opts_bad}") encoding_check(libslic3r) @@ -268,7 +277,7 @@ target_link_libraries(libslic3r qhull semver TBB::tbb - $ + libslic3r_cgal ${CMAKE_DL_LIBS} ) @@ -287,5 +296,3 @@ endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) endif () - -target_sources(libslic3r PRIVATE $) diff --git a/src/libslic3r/MeshBoolean.cpp b/src/libslic3r/MeshBoolean.cpp index 69db96d3f..025f2f97d 100644 --- a/src/libslic3r/MeshBoolean.cpp +++ b/src/libslic3r/MeshBoolean.cpp @@ -111,7 +111,7 @@ static TriangleMesh cgal_to_triangle_mesh(const _CGALMesh &cgalmesh) auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face)); int i = 0; Vec3crd trface; - for (auto v : vtc) trface(i++) = int(v.idx()); + for (auto v : vtc) trface(i++) = static_cast(v); facets.emplace_back(trface); } From 9d0d0cde21bc078dee4195e7b85c9d8ae2f844ac Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 28 Jan 2020 15:08:07 +0100 Subject: [PATCH 3/7] Fix broken build on non-linux platforms --- src/libslic3r/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 0f8f5b2c2..c145eded0 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -248,14 +248,16 @@ if (NOT TARGET ${_cgal_tgt}) set (_cgal_tgt CGAL::CGAL) endif () get_target_property(_opts ${_cgal_tgt} INTERFACE_COMPILE_OPTIONS) -set(_opts_bad "${_opts}") -set(_opts_good "${_opts}") -list(FILTER _opts_bad INCLUDE REGEX frounding-math) -list(FILTER _opts_good EXCLUDE REGEX frounding-math) -set_target_properties(${_cgal_tgt} PROPERTIES INTERFACE_COMPILE_OPTIONS "${_opts_good}") +if (_opts) + set(_opts_bad "${_opts}") + set(_opts_good "${_opts}") + list(FILTER _opts_bad INCLUDE REGEX frounding-math) + list(FILTER _opts_good EXCLUDE REGEX frounding-math) + set_target_properties(${_cgal_tgt} PROPERTIES INTERFACE_COMPILE_OPTIONS "${_opts_good}") + target_compile_options(libslic3r_cgal PRIVATE "${_opts_bad}") +endif() target_link_libraries(libslic3r_cgal PRIVATE ${_cgal_tgt} libigl) -target_compile_options(libslic3r_cgal PRIVATE "${_opts_bad}") encoding_check(libslic3r) From 6988752d05fad29a6d158a5c2d20eb09875ce075 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 28 Jan 2020 15:24:23 +0100 Subject: [PATCH 4/7] Re-apply fix for Win32 --- src/libslic3r/CMakeLists.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index c145eded0..73b7df5bc 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -233,11 +233,6 @@ cmake_policy(SET CMP0011 NEW) find_package(CGAL REQUIRED) cmake_policy(POP) -set(_cgal_defines "") -if (MSVC AND "${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") # 32 bit MSVC workaround - set(_cgal_defines CGAL_DO_NOT_USE_MPZF) -endif () - add_library(libslic3r_cgal STATIC MeshBoolean.cpp MeshBoolean.hpp) target_include_directories(libslic3r_cgal PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) @@ -259,6 +254,10 @@ endif() target_link_libraries(libslic3r_cgal PRIVATE ${_cgal_tgt} libigl) +if (MSVC AND "${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") # 32 bit MSVC workaround + target_compile_definitions(libslic3r_cgal PRIVATE CGAL_DO_NOT_USE_MPZF) +endif () + encoding_check(libslic3r) target_compile_definitions(libslic3r PUBLIC -DUSE_TBB -DTBB_USE_CAPTURED_EXCEPTION=0) From a38735b4ae78611fe10f3422ccfd54e690ce1a88 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 28 Jan 2020 16:15:43 +0100 Subject: [PATCH 5/7] More fix of svg icons scaling under OSX (to avoid icon's blurring) + some code cleaning from unused text --- src/slic3r/GUI/BitmapCache.cpp | 21 ++++++++++++--- src/slic3r/GUI/BitmapCache.hpp | 6 ++--- src/slic3r/GUI/wxExtensions.cpp | 46 ++++++++++----------------------- src/slic3r/GUI/wxExtensions.hpp | 8 ++---- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index 7322a88d1..b80ac1726 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -49,12 +49,20 @@ static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image, float scale = 1. #endif } -wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_t height) +wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_t height, float scale/* = 1.0f*/) { wxBitmap *bitmap = nullptr; auto it = m_map.find(bitmap_key); if (it == m_map.end()) { bitmap = new wxBitmap(width, height); +#ifdef __APPLE__ + // Contrary to intuition, the `scale` argument isn't "please scale this to such and such" + // but rather "the wxImage is sized for backing scale such and such". + // So, We need to let the Mac OS wxBitmap implementation + // know that the image may already be scaled appropriately for Retina, + // and thereby that it's not supposed to upscale it. + return bitmap->CreateScaled(width, height, scale); +#endif m_map[bitmap_key] = bitmap; } else { bitmap = it->second; @@ -95,7 +103,7 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap &bmp return this->insert(bitmap_key, bmps, bmps + 3); } -wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *begin, const wxBitmap *end) +wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *begin, const wxBitmap *end, float scale/* = 1.0f*/) { size_t width = 0; size_t height = 0; @@ -158,6 +166,12 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg #else +#ifdef __APPLE__ + // Note, for this moment width and height are scaled, so divide them by scale to avoid one more multiplication inside CreateScaled() + width *= 1.0 / scale; + height *= 1.0 / scale; +#endif + wxBitmap *bitmap = this->insert(bitmap_key, width, height); wxMemoryDC memDC; memDC.SelectObject(*bitmap); @@ -167,7 +181,8 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg for (const wxBitmap *bmp = begin; bmp != end; ++ bmp) { if (bmp->GetWidth() > 0) memDC.DrawBitmap(*bmp, x, 0, true); - x += bmp->GetWidth(); + // we should "move" with step equal to non-scaled width + x += bmp->GetWidth()/scale; } memDC.SelectObject(wxNullBitmap); return bitmap; diff --git a/src/slic3r/GUI/BitmapCache.hpp b/src/slic3r/GUI/BitmapCache.hpp index 041e7d892..49d45c66a 100644 --- a/src/slic3r/GUI/BitmapCache.hpp +++ b/src/slic3r/GUI/BitmapCache.hpp @@ -23,12 +23,12 @@ public: wxBitmap* find(const std::string &name) { auto it = m_map.find(name); return (it == m_map.end()) ? nullptr : it->second; } const wxBitmap* find(const std::string &name) const { return const_cast(this)->find(name); } - wxBitmap* insert(const std::string &name, size_t width, size_t height); + wxBitmap* insert(const std::string &name, size_t width, size_t height, float scale = 1.0f); wxBitmap* insert(const std::string &name, const wxBitmap &bmp); wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2); wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3); - wxBitmap* insert(const std::string &name, const std::vector &bmps) { return this->insert(name, &bmps.front(), &bmps.front() + bmps.size()); } - wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end); + wxBitmap* insert(const std::string &name, const std::vector &bmps, float scale = 1.0f) { return this->insert(name, &bmps.front(), &bmps.front() + bmps.size(), scale); } + wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end, float scale = 1.0f); wxBitmap* insert_raw_rgba(const std::string &bitmap_key, unsigned width, unsigned height, const unsigned char *raw_data, float scale = 1.0f, const bool grayscale = false); // Load png from resources/icons. bitmap_key is given without the .png suffix. Bitmap will be rescaled to provided height/width if nonzero. diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 8e2bc1d97..b710d2cd7 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -66,7 +66,7 @@ void enable_menu_item(wxUpdateUIEvent& evt, std::function const cb_condi const auto it = msw_menuitem_bitmaps.find(item->GetId()); if (it != msw_menuitem_bitmaps.end()) { - const wxBitmap& item_icon = create_scaled_bitmap(win, it->second, 16, false, !enable); + const wxBitmap& item_icon = create_scaled_bitmap(win, it->second, 16, !enable); if (item_icon.IsOk()) item->SetBitmap(item_icon); } @@ -420,41 +420,25 @@ float get_svg_scale_factor(wxWindow *win) } return win != nullptr ? max_scaling_factor : 1.0f; #else + (void)(win); return 1.0f; #endif } // If an icon has horizontal orientation (width > height) call this function with is_horizontal = true wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, - const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/, const bool grayscale/* = false*/) + const int px_cnt/* = 16*/, const bool grayscale/* = false*/) { static Slic3r::GUI::BitmapCache cache; -#ifdef __APPLE__ - // Note: win->GetContentScaleFactor() is not used anymore here because it tends to - // return bogus results quite often (such as 1.0 on Retina or even 0.0). - // We're using the max scaling factor across all screens because it's very likely to be good enough. + const float scale_factor = get_svg_scale_factor(win); - static float max_scaling_factor = NAN; - if (std::isnan(max_scaling_factor)) { - max_scaling_factor = Slic3r::GUI::mac_max_scaling_factor(); - } - const float scale_factor = win != nullptr ? max_scaling_factor : 1.0f; -#else - (void)(win); - const float scale_factor = 1.0f; -#endif - - unsigned int height, width = height = 0; - unsigned int& scale_base = is_horizontal ? width : height; - - scale_base = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f); + unsigned int width = 0; + unsigned int height = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f); std::string bmp_name = bmp_name_in; boost::replace_last(bmp_name, ".png", ""); -// std::string bmp_name = icon_name_respected_to_mode(bmp_name_in); - // Try loading an SVG first, then PNG if SVG is not found: wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor, grayscale, Slic3r::GUI::wxGetApp().dark_mode()); if (bmp == nullptr) { @@ -682,7 +666,7 @@ void ObjectDataViewModelNode::update_settings_digest_bitmaps() for (auto& cat : m_opt_categories) bmps.emplace_back( categories_icon.find(cat) == categories_icon.end() ? wxNullBitmap : categories_icon.at(cat)); - bmp = m_bitmap_cache->insert(scaled_bitmap_name, bmps); + bmp = m_bitmap_cache->insert(scaled_bitmap_name, bmps, get_svg_scale_factor(m_ctrl)); } m_bmp = *bmp; @@ -2470,18 +2454,17 @@ void MenuWithSeparators::SetSecondSeparator() // ---------------------------------------------------------------------------- ScalableBitmap::ScalableBitmap( wxWindow *parent, const std::string& icon_name/* = ""*/, - const int px_cnt/* = 16*/, - const bool is_horizontal/* = false*/): + const int px_cnt/* = 16*/): m_parent(parent), m_icon_name(icon_name), - m_px_cnt(px_cnt), m_is_horizontal(is_horizontal) + m_px_cnt(px_cnt) { - m_bmp = create_scaled_bitmap(parent, icon_name, px_cnt, is_horizontal); + m_bmp = create_scaled_bitmap(parent, icon_name, px_cnt); } void ScalableBitmap::msw_rescale() { - m_bmp = create_scaled_bitmap(m_parent, m_icon_name, m_px_cnt, m_is_horizontal); + m_bmp = create_scaled_bitmap(m_parent, m_icon_name, m_px_cnt); } // ---------------------------------------------------------------------------- @@ -2522,8 +2505,7 @@ ScalableButton::ScalableButton( wxWindow * parent, long style /*= wxBU_EXACTFIT | wxNO_BORDER*/) : m_parent(parent), m_current_icon_name(bitmap.name()), - m_px_cnt(bitmap.px_cnt()), - m_is_horizontal(bitmap.is_horizontal()) + m_px_cnt(bitmap.px_cnt()) { Create(parent, id, label, wxDefaultPosition, wxDefaultSize, style); #ifdef __WXMSW__ @@ -2554,9 +2536,9 @@ int ScalableButton::GetBitmapHeight() void ScalableButton::msw_rescale() { - SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name, m_px_cnt, m_is_horizontal)); + SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name, m_px_cnt)); if (!m_disabled_icon_name.empty()) - SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name, m_px_cnt, m_is_horizontal)); + SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name, m_px_cnt)); if (m_width > 0 || m_height>0) { diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 1ee42dc29..c3d26c8be 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -56,7 +56,7 @@ int em_unit(wxWindow* win); float get_svg_scale_factor(wxWindow* win); wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, - const int px_cnt = 16, const bool is_horizontal = false, const bool grayscale = false); + const int px_cnt = 16, const bool grayscale = false); std::vector get_extruder_color_icons(bool thin_icon = false); void apply_extruder_selector(wxBitmapComboBox** ctrl, @@ -729,8 +729,7 @@ public: ScalableBitmap() {}; ScalableBitmap( wxWindow *parent, const std::string& icon_name = "", - const int px_cnt = 16, - const bool is_horizontal = false); + const int px_cnt = 16); ~ScalableBitmap() {} @@ -741,14 +740,12 @@ public: const std::string& name() const{ return m_icon_name; } int px_cnt()const {return m_px_cnt;} - bool is_horizontal()const {return m_is_horizontal;} private: wxWindow* m_parent{ nullptr }; wxBitmap m_bmp = wxBitmap(); std::string m_icon_name = ""; int m_px_cnt {16}; - bool m_is_horizontal {false}; }; @@ -832,7 +829,6 @@ private: // bitmap dimensions int m_px_cnt{ 16 }; - bool m_is_horizontal{ false }; }; From cd2973fad361a8dd392ac4342c08a464f2b8fce5 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 28 Jan 2020 16:23:05 +0100 Subject: [PATCH 6/7] Typo fix for https://github.com/prusa3d/PrusaSlicer/commit/a38735b4ae78611fe10f3422ccfd54e690ce1a88 --- src/slic3r/GUI/BitmapCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index b80ac1726..60efcc429 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -61,7 +61,7 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_ // So, We need to let the Mac OS wxBitmap implementation // know that the image may already be scaled appropriately for Retina, // and thereby that it's not supposed to upscale it. - return bitmap->CreateScaled(width, height, scale); + bitmap->CreateScaled(width, height, -1, scale); #endif m_map[bitmap_key] = bitmap; } else { From d45744b7bb95c8990a248dcf9d1419f3b5a42aa6 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 28 Jan 2020 16:23:05 +0100 Subject: [PATCH 7/7] Typo fix for https://github.com/prusa3d/PrusaSlicer/commit/a38735b4ae78611fe10f3422ccfd54e690ce1a88 --- src/slic3r/GUI/BitmapCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index 60efcc429..8d65ae90b 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -172,7 +172,7 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *beg height *= 1.0 / scale; #endif - wxBitmap *bitmap = this->insert(bitmap_key, width, height); + wxBitmap *bitmap = this->insert(bitmap_key, width, height, scale); wxMemoryDC memDC; memDC.SelectObject(*bitmap); memDC.SetBackground(*wxTRANSPARENT_BRUSH);