From adf739cd454bb905715ec83718b9b7074f84138a Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 15 Oct 2018 15:21:37 +0200 Subject: [PATCH 01/24] Simplified algorithm for update of gizmo move and scale --- src/libslic3r/Technologies.hpp | 2 +- src/slic3r/GUI/GLGizmo.cpp | 82 +++++++++++++++++++++++++++++++--- src/slic3r/GUI/GLGizmo.hpp | 8 ++++ 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 77802d811..0b918d7c9 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -13,7 +13,7 @@ // Uses a unique opengl context #define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0) // New selections -#define ENABLE_EXTENDED_SELECTION (0 && ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM) +#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 415a92822..b1e7473aa 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -23,6 +23,7 @@ static const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f namespace Slic3r { namespace GUI { +#if !ENABLE_EXTENDED_SELECTION // returns the intersection of the given ray with the plane parallel to plane XY and passing through the given center // coordinates are local to the plane Vec3d intersection_on_plane_xy(const Linef3& ray, const Vec3d& center) @@ -105,7 +106,8 @@ unsigned int select_best_plane(const Vec3d& unit_vector, unsigned int preferred_ return ret; } - +#endif // !ENABLE_EXTENDED_SELECTION + const float GLGizmoBase::Grabber::SizeFactor = 0.025f; const float GLGizmoBase::Grabber::MinHalfSize = 1.5f; const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; @@ -1065,7 +1067,11 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray) { +#if ENABLE_EXTENDED_SELECTION + double ratio = calc_ratio(mouse_ray); +#else double ratio = calc_ratio(1, mouse_ray, m_starting_box.center()); +#endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) m_scale(0) = m_starting_scale(0) * ratio; @@ -1073,7 +1079,11 @@ void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray) void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray) { +#if ENABLE_EXTENDED_SELECTION + double ratio = calc_ratio(mouse_ray); +#else double ratio = calc_ratio(2, mouse_ray, m_starting_box.center()); +#endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM @@ -1085,7 +1095,11 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray) void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray) { +#if ENABLE_EXTENDED_SELECTION + double ratio = calc_ratio(mouse_ray); +#else double ratio = calc_ratio(1, mouse_ray, m_starting_box.center()); +#endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM @@ -1097,16 +1111,46 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray) void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray) { +#if ENABLE_EXTENDED_SELECTION + double ratio = calc_ratio(mouse_ray); +#else Vec3d center = m_starting_box.center(); -#if !ENABLE_EXTENDED_SELECTION center(2) = m_box.min(2); -#endif // !ENABLE_EXTENDED_SELECTION double ratio = calc_ratio(0, mouse_ray, center); +#endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) m_scale = m_starting_scale * ratio; } +#if ENABLE_EXTENDED_SELECTION +double GLGizmoScale3D::calc_ratio(const Linef3& mouse_ray) const +{ + double ratio = 0.0; + + // vector from the center to the starting position + Vec3d starting_vec = m_starting_drag_position - m_starting_box.center(); + double len_starting_vec = starting_vec.norm(); + if (len_starting_vec != 0.0) + { + Vec3d mouse_dir = mouse_ray.unit_vector(); + // finds the intersection of the mouse ray with the plane parallel to the camera viewport and passing throught the starting position + // use ray-plane intersection see i.e. https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection algebric form + // in our case plane normal and ray direction are the same (orthogonal view) + // when moving to perspective camera the negative z unit axis of the camera needs to be transformed in world space and used as plane normal + Vec3d inters = mouse_ray.a + (m_starting_drag_position - mouse_ray.a).dot(mouse_dir) / mouse_dir.squaredNorm() * mouse_dir; + // vector from the starting position to the found intersection + Vec3d inters_vec = inters - m_starting_drag_position; + + // finds projection of the vector along the staring direction + double proj = inters_vec.dot(starting_vec.normalized()); + + return (len_starting_vec + proj) / len_starting_vec; + } + + return ratio; +} +#else double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const { double ratio = 0.0; @@ -1142,6 +1186,7 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& return ratio; } +#endif // ENABLE_EXTENDED_SELECTION const double GLGizmoMove3D::Offset = 10.0; @@ -1209,11 +1254,11 @@ void GLGizmoMove3D::on_update(const Linef3& mouse_ray) { #if ENABLE_EXTENDED_SELECTION if (m_hover_id == 0) - m_displacement(0) = calc_projection(X, 1, mouse_ray) - (m_starting_drag_position(0) - m_starting_box_center(0)); + m_displacement(0) = calc_projection(mouse_ray); else if (m_hover_id == 1) - m_displacement(1) = calc_projection(Y, 2, mouse_ray) - (m_starting_drag_position(1) - m_starting_box_center(1)); + m_displacement(1) = calc_projection(mouse_ray); else if (m_hover_id == 2) - m_displacement(2) = calc_projection(Z, 1, mouse_ray) - (m_starting_drag_position(2) - m_starting_box_bottom_center(2)); + m_displacement(2) = calc_projection(mouse_ray); #else if (m_hover_id == 0) m_position(0) = 2.0 * m_starting_box_center(0) + calc_projection(X, 1, mouse_ray) - m_starting_drag_position(0); @@ -1315,6 +1360,30 @@ void GLGizmoMove3D::on_render_for_picking(const BoundingBoxf3& box) const } #endif // ENABLE_EXTENDED_SELECTION +#if ENABLE_EXTENDED_SELECTION +double GLGizmoMove3D::calc_projection(const Linef3& mouse_ray) const +{ + double projection = 0.0; + + Vec3d starting_vec = m_starting_drag_position - m_starting_box_center; + double len_starting_vec = starting_vec.norm(); + if (len_starting_vec != 0.0) + { + Vec3d mouse_dir = mouse_ray.unit_vector(); + // finds the intersection of the mouse ray with the plane parallel to the camera viewport and passing throught the starting position + // use ray-plane intersection see i.e. https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection algebric form + // in our case plane normal and ray direction are the same (orthogonal view) + // when moving to perspective camera the negative z unit axis of the camera needs to be transformed in world space and used as plane normal + Vec3d inters = mouse_ray.a + (m_starting_drag_position - mouse_ray.a).dot(mouse_dir) / mouse_dir.squaredNorm() * mouse_dir; + // vector from the starting position to the found intersection + Vec3d inters_vec = inters - m_starting_drag_position; + + // finds projection of the vector along the staring direction + projection = inters_vec.dot(starting_vec.normalized()); + } + return projection; +} +#else double GLGizmoMove3D::calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const { double projection = 0.0; @@ -1350,6 +1419,7 @@ double GLGizmoMove3D::calc_projection(Axis axis, unsigned int preferred_plane_id return projection; } +#endif // ENABLE_EXTENDED_SELECTION GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent) : GLGizmoBase(parent) diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 3f0599ff0..8babd21e5 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -376,7 +376,11 @@ private: void do_scale_z(const Linef3& mouse_ray); void do_scale_uniform(const Linef3& mouse_ray); +#if ENABLE_EXTENDED_SELECTION + double calc_ratio(const Linef3& mouse_ray) const; +#else double calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const; +#endif // ENABLE_EXTENDED_SELECTION }; class GLGizmoMove3D : public GLGizmoBase @@ -419,7 +423,11 @@ protected: #endif // ENABLE_EXTENDED_SELECTION private: +#if ENABLE_EXTENDED_SELECTION + double calc_projection(const Linef3& mouse_ray) const; +#else double calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const; +#endif // ENABLE_EXTENDED_SELECTION }; class GLGizmoFlatten : public GLGizmoBase From 0b0e65636fc696bcf9416ccccbec5f86eefae987 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Fri, 12 Oct 2018 14:19:08 +0200 Subject: [PATCH 02/24] Build improvements: symlink resources properly with Visual Studio Convert dependencies into a CMake build script in the `deps` dir --- CMakeLists.txt | 15 +--- deps/CMakeLists.txt | 31 +++++++ deps/deps-unix-static.cmake | 133 ++++++++++++++++++++++++++++ deps/deps-windows.cmake | 93 ++++++++++++++++++++ deps/wxwidgets-pngprefix.h | 168 ++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 33 +++++++ xs/CMakeLists.txt | 5 -- 7 files changed, 459 insertions(+), 19 deletions(-) create mode 100644 deps/CMakeLists.txt create mode 100644 deps/deps-unix-static.cmake create mode 100644 deps/deps-windows.cmake create mode 100644 deps/wxwidgets-pngprefix.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b0f908e90..62c545fe1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,7 +215,7 @@ if (NOT GLEW_FOUND) endif () include_directories(${GLEW_INCLUDE_DIRS}) -# Resources and l10n +# l10n set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization") add_custom_target(pot # FIXME: file list stale @@ -225,19 +225,6 @@ add_custom_target(pot WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Generate pot file from strings in the source tree" ) -if (MSVC) - file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/src/resources" WIN_RESOURCES_SYMLINK) - add_custom_target(resources_symlink ALL - COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" ( mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ) - VERBATIM - ) -else () - add_custom_target(resources_symlink ALL - COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_BINARY_DIR}/resources" - VERBATIM - ) -endif() - # libslic3r, Slic3r GUI and the slic3r executable. add_subdirectory(src) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt new file mode 100644 index 000000000..22d3f7236 --- /dev/null +++ b/deps/CMakeLists.txt @@ -0,0 +1,31 @@ +project(Slic3r-deps) +cmake_minimum_required(VERSION 3.2) + +include(ExternalProject) + +include(ProcessorCount) +ProcessorCount(NPROC) +if (NPROC EQUAL 0) + set(NPROC 1) +endif () + +if (MSVC) + set(DEPS_BITS 64) + set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-64") + include("deps-windows.cmake") + set(DEPS_BITS 32) + set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-32") + include("deps-windows.cmake") + + add_custom_target(deps ALL + DEPENDS dep_boost_64 dep_tbb_64 dep_libcurl_64 dep_wxwidgets_64 + # dep_boost_32 dep_tbb_32 dep_libcurl_32 dep_wxwidgets_32 + ) +else () + set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir") + include("deps-unix-static.cmake") + + add_custom_target(deps ALL + DEPENDS dep_boost dep_tbb dep_libcurl dep_wxwidgets + ) +endif() diff --git a/deps/deps-unix-static.cmake b/deps/deps-unix-static.cmake new file mode 100644 index 000000000..615884518 --- /dev/null +++ b/deps/deps-unix-static.cmake @@ -0,0 +1,133 @@ + +ExternalProject_Add(dep_boost + EXCLUDE_FROM_ALL 1 + URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz" + URL_HASH SHA256=bd0df411efd9a585e5a2212275f8762079fed8842264954675a4fddc46cfcf60 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ./bootstrap.sh + --with-libraries=system,filesystem,thread,log,locale,regex + "--prefix=${INSTALL_DIR}/usr/local" + BUILD_COMMAND ./b2 + -j ${NPROC} + link=static + variant=release + threading=multi + boost.locale.icu=off + cxxflags=-fPIC cflags=-fPIC + install + INSTALL_COMMAND "" # b2 does that already + LOG_CONFIGURE 1 + LOG_BUILD 1 +) + +ExternalProject_Add(dep_tbb + EXCLUDE_FROM_ALL 1 + URL "https://github.com/wjakob/tbb/archive/a0dc9bf76d0120f917b641ed095360448cabc85b.tar.gz" + URL_HASH SHA256=0545cb6033bd1873fcae3ea304def720a380a88292726943ae3b9b207f322efe + BUILD_IN_SOURCE 1 + CMAKE_ARGS -DTBB_BUILD_SHARED=OFF + -DTBB_BUILD_TESTS=OFF + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + INSTALL_COMMAND make install "DESTDIR=${INSTALL_DIR}" + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 +) + +ExternalProject_Add(dep_libopenssl + EXCLUDE_FROM_ALL 1 + URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0g.tar.gz" + URL_HASH SHA256=8e9516b8635bb9113c51a7b5b27f9027692a56b104e75b709e588c3ffd6a0422 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ./config + "--prefix=${INSTALL_DIR}/usr/local" + no-shared + no-ssl3-method + no-dynamic-engine + -Wa,--noexecstack + BUILD_COMMAND make depend && make "-j${NPROC}" + INSTALL_COMMAND make install_sw + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 +) + +ExternalProject_Add(dep_libcurl + EXCLUDE_FROM_ALL 1 + DEPENDS dep_libopenssl + URL "https://curl.haxx.se/download/curl-7.58.0.tar.gz" + URL_HASH SHA256=cc245bf9a1a42a45df491501d97d5593392a03f7b4f07b952793518d97666115 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ./configure + --enable-static + --disable-shared + "--with-ssl=${DESTDIR}/usr/local" + --with-pic + --enable-ipv6 + --enable-versioned-symbols + --enable-threaded-resolver + --with-random=/dev/urandom + --with-ca-bundle=/etc/ssl/certs/ca-certificates.crt + --disable-ldap + --disable-ldaps + --disable-manual + --disable-rtsp + --disable-dict + --disable-telnet + --disable-pop3 + --disable-imap + --disable-smb + --disable-smtp + --disable-gopher + --disable-crypto-auth + --without-gssapi + --without-libpsl + --without-libidn2 + --without-gnutls + --without-polarssl + --without-mbedtls + --without-cyassl + --without-nss + --without-axtls + --without-brotli + --without-libmetalink + --without-libssh + --without-libssh2 + --without-librtmp + --without-nghttp2 + --without-zsh-functions-dir + BUILD_COMMAND make "-j${NPROC}" + INSTALL_COMMAND make install "DESTDIR=${INSTALL_DIR}" + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 +) + +ExternalProject_Add(dep_wxwidgets + EXCLUDE_FROM_ALL 1 + URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" + URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ./configure + "--prefix=${INSTALL_DIR}/usr/local" + --disable-shared + --with-gtk=2 + --with-opengl + --enable-unicode + --enable-graphics_ctx + --with-regex=builtin + --with-libpng=builtin + --with-libxpm=builtin + --with-libjpeg=builtin + --with-libtiff=builtin + --with-zlib=builtin + --with-expat=builtin + --disable-precomp-headers + --enable-debug_info + --enable-debug_gdb + BUILD_COMMAND make "-j${NPROC}" && make -C locale allmo + INSTALL_COMMAND make install + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 +) diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake new file mode 100644 index 000000000..834bdb9e3 --- /dev/null +++ b/deps/deps-windows.cmake @@ -0,0 +1,93 @@ + +# NB: I haven't enabled any of the LOG_xxx options because they tend to generate bogus build files, +# especially with compound commands like `cd foo && bar`. + +ExternalProject_Add("dep_boost_${DEPS_BITS}" + EXCLUDE_FROM_ALL 1 + URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz" + URL_HASH SHA256=bd0df411efd9a585e5a2212275f8762079fed8842264954675a4fddc46cfcf60 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND bootstrap.bat + BUILD_COMMAND b2.exe + -j "${NPROC}" + --with-system + --with-filesystem + --with-thread + --with-log + --with-locale + --with-regex + "--prefix=${DESTDIR}/usr/local" + "address-model=${DEPS_BITS}" + toolset=msvc-12.0 + link=static + variant=release + threading=multi + boost.locale.icu=off + install + INSTALL_COMMAND "" # b2 does that already +) + + +if ($DEPS_BITS EQUAL 32) + set(DEP_TBB_GEN "Visual Studio 12") +else () + set(DEP_TBB_GEN "Visual Studio 12 Win64") +endif () + +ExternalProject_Add("dep_tbb_${DEPS_BITS}" + EXCLUDE_FROM_ALL 1 + URL "https://github.com/wjakob/tbb/archive/a0dc9bf76d0120f917b641ed095360448cabc85b.tar.gz" + URL_HASH SHA256=0545cb6033bd1873fcae3ea304def720a380a88292726943ae3b9b207f322efe + CMAKE_GENERATOR "${DEP_TBB_GEN}" + CMAKE_ARGS + -DCMAKE_CONFIGURATION_TYPES=Release + -DTBB_BUILD_SHARED=OFF + -DTBB_BUILD_TESTS=OFF + "-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR}\\usr\\local" + BUILD_COMMAND msbuild /P:Configuration=Release INSTALL.vcxproj + INSTALL_COMMAND "" +) + + +if ($DEPS_BITS EQUAL 32) + set(DEP_LIBCURL_TARGET "x86") +else () + set(DEP_LIBCURL_TARGET "x64") +endif () + +ExternalProject_Add("dep_libcurl_${DEPS_BITS}" + EXCLUDE_FROM_ALL 1 + URL "https://curl.haxx.se/download/curl-7.58.0.tar.gz" + URL_HASH SHA256=cc245bf9a1a42a45df491501d97d5593392a03f7b4f07b952793518d97666115 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND cd winbuild && nmake /f Makefile.vc mode=static VC=12 GEN_PDB=yes DEBUG=no "MACHINE=${DEP_LIBCURL_TARGET}" + INSTALL_COMMAND cd builds\\libcurl-*-winssl + && "${CMAKE_COMMAND}" -E copy_directory include "${DESTDIR}\\usr\\local\\include" + && "${CMAKE_COMMAND}" -E copy_directory lib "${DESTDIR}\\usr\\local\\lib" +) + +if ($DEPS_BITS EQUAL 32) + set(DEP_WXWIDGETS_TARGET "") + set(DEP_WXWIDGETS_LIBDIR "vc_lib") +else () + set(DEP_WXWIDGETS_TARGET "TARGET_CPU=X64") + set(DEP_WXWIDGETS_LIBDIR "vc_x64_lib") +endif () + +ExternalProject_Add("dep_wxwidgets_${DEPS_BITS}" + EXCLUDE_FROM_ALL 1 + URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" + URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e + BUILD_IN_SOURCE 1 + PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}\\wxwidgets-pngprefix.h" src\\png\\pngprefix.h + CONFIGURE_COMMAND "" + BUILD_COMMAND cd build\\msw && nmake /f makefile.vc + BUILD=release + SHARED=0 + UNICODE=1 + USE_GUI=1 + "${DEP_WXWIDGETS_TARGET}" + INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy_directory include "${DESTDIR}\\usr\\local\\include" + && "${CMAKE_COMMAND}" -E copy_directory "lib\\${DEP_WXWIDGETS_LIBDIR}" "${DESTDIR}\\usr\\local\\lib\\${DEP_WXWIDGETS_LIBDIR}" +) diff --git a/deps/wxwidgets-pngprefix.h b/deps/wxwidgets-pngprefix.h new file mode 100644 index 000000000..de62e310b --- /dev/null +++ b/deps/wxwidgets-pngprefix.h @@ -0,0 +1,168 @@ +// Patched in Slic3r: These two were missing: +#define png_write_eXIf wx_png_write_eXIf +#define png_handle_eXIf wx_png_handle_eXIf + +#define png_sRGB_table wx_png_sRGB_table +#define png_sRGB_base wx_png_sRGB_base +#define png_sRGB_delta wx_png_sRGB_delta +#define png_zstream_error wx_png_zstream_error +#define png_free_buffer_list wx_png_free_buffer_list +#define png_fixed wx_png_fixed +#define png_user_version_check wx_png_user_version_check +#define png_malloc_base wx_png_malloc_base +#define png_malloc_array wx_png_malloc_array +#define png_realloc_array wx_png_realloc_array +#define png_create_png_struct wx_png_create_png_struct +#define png_destroy_png_struct wx_png_destroy_png_struct +#define png_free_jmpbuf wx_png_free_jmpbuf +#define png_zalloc wx_png_zalloc +#define png_zfree wx_png_zfree +#define png_default_read_data wx_png_default_read_data +#define png_push_fill_buffer wx_png_push_fill_buffer +#define png_default_write_data wx_png_default_write_data +#define png_default_flush wx_png_default_flush +#define png_reset_crc wx_png_reset_crc +#define png_write_data wx_png_write_data +#define png_read_sig wx_png_read_sig +#define png_read_chunk_header wx_png_read_chunk_header +#define png_read_data wx_png_read_data +#define png_crc_read wx_png_crc_read +#define png_crc_finish wx_png_crc_finish +#define png_crc_error wx_png_crc_error +#define png_calculate_crc wx_png_calculate_crc +#define png_flush wx_png_flush +#define png_write_IHDR wx_png_write_IHDR +#define png_write_PLTE wx_png_write_PLTE +#define png_compress_IDAT wx_png_compress_IDAT +#define png_write_IEND wx_png_write_IEND +#define png_write_gAMA_fixed wx_png_write_gAMA_fixed +#define png_write_sBIT wx_png_write_sBIT +#define png_write_cHRM_fixed wx_png_write_cHRM_fixed +#define png_write_sRGB wx_png_write_sRGB +#define png_write_iCCP wx_png_write_iCCP +#define png_write_sPLT wx_png_write_sPLT +#define png_write_tRNS wx_png_write_tRNS +#define png_write_bKGD wx_png_write_bKGD +#define png_write_hIST wx_png_write_hIST +#define png_write_tEXt wx_png_write_tEXt +#define png_write_zTXt wx_png_write_zTXt +#define png_write_iTXt wx_png_write_iTXt +#define png_set_text_2 wx_png_set_text_2 +#define png_write_oFFs wx_png_write_oFFs +#define png_write_pCAL wx_png_write_pCAL +#define png_write_pHYs wx_png_write_pHYs +#define png_write_tIME wx_png_write_tIME +#define png_write_sCAL_s wx_png_write_sCAL_s +#define png_write_finish_row wx_png_write_finish_row +#define png_write_start_row wx_png_write_start_row +#define png_combine_row wx_png_combine_row +#define png_do_read_interlace wx_png_do_read_interlace +#define png_do_write_interlace wx_png_do_write_interlace +#define png_read_filter_row wx_png_read_filter_row +#define png_write_find_filter wx_png_write_find_filter +#define png_read_IDAT_data wx_png_read_IDAT_data +#define png_read_finish_IDAT wx_png_read_finish_IDAT +#define png_read_finish_row wx_png_read_finish_row +#define png_read_start_row wx_png_read_start_row +#define png_zlib_inflate wx_png_zlib_inflate +#define png_read_transform_info wx_png_read_transform_info +#define png_do_strip_channel wx_png_do_strip_channel +#define png_do_swap wx_png_do_swap +#define png_do_packswap wx_png_do_packswap +#define png_do_invert wx_png_do_invert +#define png_do_bgr wx_png_do_bgr +#define png_handle_IHDR wx_png_handle_IHDR +#define png_handle_PLTE wx_png_handle_PLTE +#define png_handle_IEND wx_png_handle_IEND +#define png_handle_bKGD wx_png_handle_bKGD +#define png_handle_cHRM wx_png_handle_cHRM +#define png_handle_gAMA wx_png_handle_gAMA +#define png_handle_hIST wx_png_handle_hIST +#define png_handle_iCCP wx_png_handle_iCCP +#define png_handle_iTXt wx_png_handle_iTXt +#define png_handle_oFFs wx_png_handle_oFFs +#define png_handle_pCAL wx_png_handle_pCAL +#define png_handle_pHYs wx_png_handle_pHYs +#define png_handle_sBIT wx_png_handle_sBIT +#define png_handle_sCAL wx_png_handle_sCAL +#define png_handle_sPLT wx_png_handle_sPLT +#define png_handle_sRGB wx_png_handle_sRGB +#define png_handle_tEXt wx_png_handle_tEXt +#define png_handle_tIME wx_png_handle_tIME +#define png_handle_tRNS wx_png_handle_tRNS +#define png_handle_zTXt wx_png_handle_zTXt +#define png_check_chunk_name wx_png_check_chunk_name +#define png_check_chunk_length wx_png_check_chunk_length +#define png_handle_unknown wx_png_handle_unknown +#define png_chunk_unknown_handling wx_png_chunk_unknown_handling +#define png_do_read_transformations wx_png_do_read_transformations +#define png_do_write_transformations wx_png_do_write_transformations +#define png_init_read_transformations wx_png_init_read_transformations +#define png_push_read_chunk wx_png_push_read_chunk +#define png_push_read_sig wx_png_push_read_sig +#define png_push_check_crc wx_png_push_check_crc +#define png_push_save_buffer wx_png_push_save_buffer +#define png_push_restore_buffer wx_png_push_restore_buffer +#define png_push_read_IDAT wx_png_push_read_IDAT +#define png_process_IDAT_data wx_png_process_IDAT_data +#define png_push_process_row wx_png_push_process_row +#define png_push_handle_unknown wx_png_push_handle_unknown +#define png_push_have_info wx_png_push_have_info +#define png_push_have_end wx_png_push_have_end +#define png_push_have_row wx_png_push_have_row +#define png_push_read_end wx_png_push_read_end +#define png_process_some_data wx_png_process_some_data +#define png_read_push_finish_row wx_png_read_push_finish_row +#define png_push_handle_tEXt wx_png_push_handle_tEXt +#define png_push_read_tEXt wx_png_push_read_tEXt +#define png_push_handle_zTXt wx_png_push_handle_zTXt +#define png_push_read_zTXt wx_png_push_read_zTXt +#define png_push_handle_iTXt wx_png_push_handle_iTXt +#define png_push_read_iTXt wx_png_push_read_iTXt +#define png_colorspace_set_gamma wx_png_colorspace_set_gamma +#define png_colorspace_sync_info wx_png_colorspace_sync_info +#define png_colorspace_sync wx_png_colorspace_sync +#define png_colorspace_set_chromaticities wx_png_colorspace_set_chromaticities +#define png_colorspace_set_endpoints wx_png_colorspace_set_endpoints +#define png_colorspace_set_sRGB wx_png_colorspace_set_sRGB +#define png_colorspace_set_ICC wx_png_colorspace_set_ICC +#define png_icc_check_length wx_png_icc_check_length +#define png_icc_check_header wx_png_icc_check_header +#define png_icc_check_tag_table wx_png_icc_check_tag_table +#define png_icc_set_sRGB wx_png_icc_set_sRGB +#define png_colorspace_set_rgb_coefficients wx_png_colorspace_set_rgb_coefficients +#define png_check_IHDR wx_png_check_IHDR +#define png_do_check_palette_indexes wx_png_do_check_palette_indexes +#define png_fixed_error wx_png_fixed_error +#define png_safecat wx_png_safecat +#define png_format_number wx_png_format_number +#define png_warning_parameter wx_png_warning_parameter +#define png_warning_parameter_unsigned wx_png_warning_parameter_unsigned +#define png_warning_parameter_signed wx_png_warning_parameter_signed +#define png_formatted_warning wx_png_formatted_warning +#define png_app_warning wx_png_app_warning +#define png_app_error wx_png_app_error +#define png_chunk_report wx_png_chunk_report +#define png_ascii_from_fp wx_png_ascii_from_fp +#define png_ascii_from_fixed wx_png_ascii_from_fixed +#define png_check_fp_number wx_png_check_fp_number +#define png_check_fp_string wx_png_check_fp_string +#define png_muldiv wx_png_muldiv +#define png_muldiv_warn wx_png_muldiv_warn +#define png_reciprocal wx_png_reciprocal +#define png_reciprocal2 wx_png_reciprocal2 +#define png_gamma_significant wx_png_gamma_significant +#define png_gamma_correct wx_png_gamma_correct +#define png_gamma_16bit_correct wx_png_gamma_16bit_correct +#define png_gamma_8bit_correct wx_png_gamma_8bit_correct +#define png_destroy_gamma_table wx_png_destroy_gamma_table +#define png_build_gamma_table wx_png_build_gamma_table +#define png_safe_error wx_png_safe_error +#define png_safe_warning wx_png_safe_warning +#define png_safe_execute wx_png_safe_execute +#define png_image_error wx_png_image_error +#define png_check_keyword wx_png_check_keyword + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b19c5cd02..3c295ec5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ if(SLIC3R_GUI) else() set_target_properties(slic3r PROPERTIES OUTPUT_NAME "slic3r-console") endif() + target_link_libraries(slic3r libslic3r) if (APPLE) # add_compile_options(-stdlib=libc++) @@ -111,3 +112,35 @@ if (SLIC3R_GUI) target_link_libraries(slic3r -ldl -lGL -lGLU) endif () endif () + +# Link the resources dir to where Slic3r GUI expects it +if (MSVC) + if (CMAKE_CONFIGURATION_TYPES) + foreach (CONF ${CMAKE_CONFIGURATION_TYPES}) + file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}" WIN_CONF_OUTPUT_DIR) + file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONF}/resources" WIN_RESOURCES_SYMLINK) + add_custom_target("resources_symlink_${CONF}" ALL + DEPENDS slic3r + COMMAND if exist "${WIN_CONF_OUTPUT_DIR}" "(" + if not exist "${WIN_RESOURCES_SYMLINK}" "(" + mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" + ")" + ")" + VERBATIM + ) + endforeach () + else () + file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" OUTPUT_DIR) + add_custom_target(resources_symlink ALL + DEPENDS slic3r + COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")" + VERBATIM + ) + endif () +else () + add_custom_target(resources_symlink ALL + DEPENDS slic3r + COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/../resources" + VERBATIM + ) +endif() diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index 9a08beadc..27228dacf 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -207,11 +207,6 @@ install(FILES lib/Slic3r/XS.pm DESTINATION ${PERL_VENDORLIB}/Slic3r) enable_testing() get_filename_component(PERL_BIN_PATH "${PERL_EXECUTABLE}" DIRECTORY) if (MSVC) - # By default the startup project in MSVC is the 'ALL_BUILD' cmake-created project, - # but we want 'slic3r' as the startup one because debugging run command is associated with it. - # (Unfortunatelly it cannot be associated with ALL_BUILD using CMake.) - # Note: For some reason this needs to be set in the top-level CMakeLists.txt - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT XS) set(PERL_PROVE "${PERL_BIN_PATH}/prove.bat") else () set(PERL_PROVE "${PERL_BIN_PATH}/prove") From ce86fad28a5f239bb2314651c3de7273b0dc195f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 15 Oct 2018 17:18:38 +0200 Subject: [PATCH 03/24] Fixed assert "IsVisible(item)" failed in wxTreeCtrl::GetNextVisible() --- src/slic3r/GUI/Tab.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 015e03b25..023a6a67d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -476,6 +476,8 @@ void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool void Tab::update_changed_tree_ui() { auto cur_item = m_treectrl->GetFirstVisibleItem(); + if (!m_treectrl->IsVisible(cur_item)) + return; auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection()); while (cur_item){ auto title = m_treectrl->GetItemText(cur_item); From fb6c1a885c8e6511a1a8807c2a67b1259adc5824 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Mon, 15 Oct 2018 17:28:05 +0200 Subject: [PATCH 04/24] Build: Fix deps-unix-static.cmake --- deps/CMakeLists.txt | 3 +++ deps/deps-unix-static.cmake | 24 +++++------------------- deps/deps-windows.cmake | 3 --- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 22d3f7236..a20c7aa18 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -29,3 +29,6 @@ else () DEPENDS dep_boost dep_tbb dep_libcurl dep_wxwidgets ) endif() + +# Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands +# because they seem to generate bogus build files (possibly a bug in ExternalProject). diff --git a/deps/deps-unix-static.cmake b/deps/deps-unix-static.cmake index 615884518..f963f5356 100644 --- a/deps/deps-unix-static.cmake +++ b/deps/deps-unix-static.cmake @@ -6,7 +6,7 @@ ExternalProject_Add(dep_boost BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,filesystem,thread,log,locale,regex - "--prefix=${INSTALL_DIR}/usr/local" + "--prefix=${DESTDIR}/usr/local" BUILD_COMMAND ./b2 -j ${NPROC} link=static @@ -16,8 +16,6 @@ ExternalProject_Add(dep_boost cxxflags=-fPIC cflags=-fPIC install INSTALL_COMMAND "" # b2 does that already - LOG_CONFIGURE 1 - LOG_BUILD 1 ) ExternalProject_Add(dep_tbb @@ -28,10 +26,7 @@ ExternalProject_Add(dep_tbb CMAKE_ARGS -DTBB_BUILD_SHARED=OFF -DTBB_BUILD_TESTS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON - INSTALL_COMMAND make install "DESTDIR=${INSTALL_DIR}" - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 + INSTALL_COMMAND make install "DESTDIR=${DESTDIR}" ) ExternalProject_Add(dep_libopenssl @@ -40,16 +35,13 @@ ExternalProject_Add(dep_libopenssl URL_HASH SHA256=8e9516b8635bb9113c51a7b5b27f9027692a56b104e75b709e588c3ffd6a0422 BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./config - "--prefix=${INSTALL_DIR}/usr/local" + "--prefix=${DESTDIR}/usr/local" no-shared no-ssl3-method no-dynamic-engine -Wa,--noexecstack BUILD_COMMAND make depend && make "-j${NPROC}" INSTALL_COMMAND make install_sw - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 ) ExternalProject_Add(dep_libcurl @@ -97,10 +89,7 @@ ExternalProject_Add(dep_libcurl --without-nghttp2 --without-zsh-functions-dir BUILD_COMMAND make "-j${NPROC}" - INSTALL_COMMAND make install "DESTDIR=${INSTALL_DIR}" - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 + INSTALL_COMMAND make install "DESTDIR=${DESTDIR}" ) ExternalProject_Add(dep_wxwidgets @@ -109,7 +98,7 @@ ExternalProject_Add(dep_wxwidgets URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./configure - "--prefix=${INSTALL_DIR}/usr/local" + "--prefix=${DESTDIR}/usr/local" --disable-shared --with-gtk=2 --with-opengl @@ -127,7 +116,4 @@ ExternalProject_Add(dep_wxwidgets --enable-debug_gdb BUILD_COMMAND make "-j${NPROC}" && make -C locale allmo INSTALL_COMMAND make install - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 ) diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index 834bdb9e3..eaf5b8e65 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -1,7 +1,4 @@ -# NB: I haven't enabled any of the LOG_xxx options because they tend to generate bogus build files, -# especially with compound commands like `cd foo && bar`. - ExternalProject_Add("dep_boost_${DEPS_BITS}" EXCLUDE_FROM_ALL 1 URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz" From 059ab4a05c42dd47b621200f6a737c5534c02877 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 16 Oct 2018 09:51:30 +0200 Subject: [PATCH 05/24] ModelInstance's full 3D transform set as default --- src/libslic3r/Format/3mf.cpp | 25 ---- src/libslic3r/Format/AMF.cpp | 57 --------- src/libslic3r/Format/PRUS.cpp | 29 ----- src/libslic3r/Model.cpp | 68 ----------- src/libslic3r/Model.hpp | 15 --- src/libslic3r/ModelArrange.hpp | 29 ----- src/libslic3r/MultiPoint.cpp | 2 - src/libslic3r/MultiPoint.hpp | 2 - src/libslic3r/Print.cpp | 4 - src/libslic3r/PrintObject.cpp | 5 - src/libslic3r/Technologies.hpp | 6 +- src/slic3r/GUI/3DScene.cpp | 67 ----------- src/slic3r/GUI/3DScene.hpp | 14 --- src/slic3r/GUI/GLCanvas3D.cpp | 140 +--------------------- src/slic3r/GUI/GLCanvas3D.hpp | 10 -- src/slic3r/GUI/GLGizmo.cpp | 51 -------- src/slic3r/GUI/GLGizmo.hpp | 36 ------ src/slic3r/GUI/GUI_ObjectManipulation.cpp | 46 ------- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 6 - xs/xsp/Model.xsp | 20 ---- 20 files changed, 2 insertions(+), 630 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 4d749eb56..bf94db6b1 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1253,13 +1253,7 @@ namespace Slic3r { // we extract from the given matrix only the values currently used // translation -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d offset = transform.matrix().block(0, 3, 3, 1); -#else - double offset_x = transform(0, 3); - double offset_y = transform(1, 3); - double offset_z = transform(2, 3); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // scale Eigen::Matrix m3x3 = transform.matrix().block(0, 0, 3, 3); @@ -1269,35 +1263,16 @@ namespace Slic3r { if ((scale(0) == 0.0) || (scale(1) == 0.0) || (scale(2) == 0.0)) return; -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // non-uniform scale value, return - if ((std::abs(scale(0) - scale(1)) > 0.00001) || (std::abs(scale(0) - scale(2)) > 0.00001)) - return; -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // remove scale m3x3.col(0).normalize(); m3x3.col(1).normalize(); m3x3.col(2).normalize(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3); instance.set_offset(offset); instance.set_scaling_factor(scale); instance.set_rotation(rotation); -#else - Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3); - - // invalid rotation, we currently handle only rotations around Z axis - if ((rotation(0) != 0.0) || (rotation(1) != 0.0)) - return; - - instance.offset(0) = offset_x; - instance.offset(1) = offset_y; - instance.scaling_factor = scale(0); - instance.rotation = rotation(2); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes) diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 96befdabf..00ed0d937 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -29,14 +29,10 @@ // VERSION NUMBERS // 0 : .amf, .amf.xml and .zip.amf files saved by older slic3r. No version definition in them. // 1 : Introduction of amf versioning. No other change in data saved into amf files. -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // 2 : Added z component of offset // Added x and y components of rotation // Added x, y and z components of scale const unsigned int VERSION_AMF = 2; -#else -const unsigned int VERSION_AMF = 1; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version"; const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config"; @@ -125,34 +121,25 @@ struct AMFParserContext NODE_TYPE_INSTANCE, // amf/constellation/instance NODE_TYPE_DELTAX, // amf/constellation/instance/deltax NODE_TYPE_DELTAY, // amf/constellation/instance/deltay -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz NODE_TYPE_RX, // amf/constellation/instance/rx NODE_TYPE_RY, // amf/constellation/instance/ry -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM NODE_TYPE_RZ, // amf/constellation/instance/rz NODE_TYPE_SCALE, // amf/constellation/instance/scale -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM NODE_TYPE_SCALEX, // amf/constellation/instance/scalex NODE_TYPE_SCALEY, // amf/constellation/instance/scaley NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM NODE_TYPE_METADATA, // anywhere under amf/*/metadata }; struct Instance { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scalex_set(false), scaley_set(false), scalez_set(false) {} -#else - Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Shift in the X axis. float deltax; bool deltax_set; // Shift in the Y axis. float deltay; bool deltay_set; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Shift in the Z axis. float deltaz; bool deltaz_set; @@ -162,11 +149,9 @@ struct AMFParserContext // Rotation around the Y axis. float ry; bool ry_set; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Rotation around the Z axis. float rz; bool rz_set; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Scaling factors float scalex; bool scalex_set; @@ -174,11 +159,6 @@ struct AMFParserContext bool scaley_set; float scalez; bool scalez_set; -#else - // Scaling factor - float scale; - bool scale_set; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM }; struct Object { @@ -293,24 +273,20 @@ void AMFParserContext::startElement(const char *name, const char **atts) node_type_new = NODE_TYPE_DELTAX; else if (strcmp(name, "deltay") == 0) node_type_new = NODE_TYPE_DELTAY; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM else if (strcmp(name, "deltaz") == 0) node_type_new = NODE_TYPE_DELTAZ; else if (strcmp(name, "rx") == 0) node_type_new = NODE_TYPE_RX; else if (strcmp(name, "ry") == 0) node_type_new = NODE_TYPE_RY; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM else if (strcmp(name, "rz") == 0) node_type_new = NODE_TYPE_RZ; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM else if (strcmp(name, "scalex") == 0) node_type_new = NODE_TYPE_SCALEX; else if (strcmp(name, "scaley") == 0) node_type_new = NODE_TYPE_SCALEY; else if (strcmp(name, "scalez") == 0) node_type_new = NODE_TYPE_SCALEZ; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM else if (strcmp(name, "scale") == 0) node_type_new = NODE_TYPE_SCALE; } @@ -369,7 +345,6 @@ void AMFParserContext::characters(const XML_Char *s, int len) { switch (m_path.size()) { case 4: -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_DELTAZ || @@ -380,9 +355,6 @@ void AMFParserContext::characters(const XML_Char *s, int len) m_path.back() == NODE_TYPE_SCALEY || m_path.back() == NODE_TYPE_SCALEZ || m_path.back() == NODE_TYPE_SCALE) -#else - if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ || m_path.back() == NODE_TYPE_SCALE) -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_value[0].append(s, len); break; case 6: @@ -422,7 +394,6 @@ void AMFParserContext::endElement(const char * /* name */) m_instance->deltay_set = true; m_value[0].clear(); break; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM case NODE_TYPE_DELTAZ: assert(m_instance); m_instance->deltaz = float(atof(m_value[0].c_str())); @@ -441,7 +412,6 @@ void AMFParserContext::endElement(const char * /* name */) m_instance->ry_set = true; m_value[0].clear(); break; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM case NODE_TYPE_RZ: assert(m_instance); m_instance->rz = float(atof(m_value[0].c_str())); @@ -450,20 +420,14 @@ void AMFParserContext::endElement(const char * /* name */) break; case NODE_TYPE_SCALE: assert(m_instance); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_instance->scalex = float(atof(m_value[0].c_str())); m_instance->scalex_set = true; m_instance->scaley = float(atof(m_value[0].c_str())); m_instance->scaley_set = true; m_instance->scalez = float(atof(m_value[0].c_str())); m_instance->scalez_set = true; -#else - m_instance->scale = float(atof(m_value[0].c_str())); - m_instance->scale_set = true; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_value[0].clear(); break; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM case NODE_TYPE_SCALEX: assert(m_instance); m_instance->scalex = float(atof(m_value[0].c_str())); @@ -482,7 +446,6 @@ void AMFParserContext::endElement(const char * /* name */) m_instance->scalez_set = true; m_value[0].clear(); break; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Object vertices: case NODE_TYPE_VERTEX: @@ -619,16 +582,9 @@ void AMFParserContext::endDocument() for (const Instance &instance : object.second.instances) if (instance.deltax_set && instance.deltay_set) { ModelInstance *mi = m_model.objects[object.second.idx]->add_instance(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM mi->set_offset(Vec3d(instance.deltax_set ? (double)instance.deltax : 0.0, instance.deltay_set ? (double)instance.deltay : 0.0, instance.deltaz_set ? (double)instance.deltaz : 0.0)); mi->set_rotation(Vec3d(instance.rx_set ? (double)instance.rx : 0.0, instance.ry_set ? (double)instance.ry : 0.0, instance.rz_set ? (double)instance.rz : 0.0)); mi->set_scaling_factor(Vec3d(instance.scalex_set ? (double)instance.scalex : 1.0, instance.scaley_set ? (double)instance.scaley : 1.0, instance.scalez_set ? (double)instance.scalez : 1.0)); -#else - mi->offset(0) = instance.deltax; - mi->offset(1) = instance.deltay; - mi->rotation = instance.rz_set ? instance.rz : 0.f; - mi->scaling_factor = instance.scale_set ? instance.scale : 1.f; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } } @@ -928,22 +884,15 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c " \n" " %lf\n" " %lf\n" -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM " %lf\n" " %lf\n" " %lf\n" -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM " %lf\n" -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM " %lf\n" " %lf\n" " %lf\n" -#else - " %lf\n" -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM " \n", object_id, -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance->get_offset(X), instance->get_offset(Y), instance->get_offset(Z), @@ -953,12 +902,6 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c instance->get_scaling_factor(X), instance->get_scaling_factor(Y), instance->get_scaling_factor(Z)); -#else - instance->offset(0), - instance->offset(1), - instance->rotation, - instance->scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM //FIXME missing instance->scaling_factor instances.append(buf); diff --git a/src/libslic3r/Format/PRUS.cpp b/src/libslic3r/Format/PRUS.cpp index b68726a37..f79721be7 100644 --- a/src/libslic3r/Format/PRUS.cpp +++ b/src/libslic3r/Format/PRUS.cpp @@ -97,15 +97,9 @@ static void extract_model_from_archive( const char *zero_tag = ""; const char *zero_xml = strstr(scene_xml_data.data(), zero_tag); float trafo[3][4] = { 0 }; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d instance_rotation = Vec3d::Zero(); Vec3d instance_scaling_factor = Vec3d::Ones(); Vec3d instance_offset = Vec3d::Zero(); -#else - double instance_rotation = 0.; - double instance_scaling_factor = 1.f; - Vec2d instance_offset(0., 0.); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM bool trafo_set = false; unsigned int group_id = (unsigned int)-1; unsigned int extruder_id = (unsigned int)-1; @@ -128,19 +122,8 @@ static void extract_model_from_archive( "[%f, %f, %f]", scale, scale+1, scale+2) == 3 && sscanf(zero_xml+strlen(zero_tag), "[%f, %f, %f]", zero, zero+1, zero+2) == 3) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance_scaling_factor = Vec3d((double)scale[0], (double)scale[1], (double)scale[2]); instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[2]); -#else - if (scale[0] == scale[1] && scale[1] == scale[2]) { - instance_scaling_factor = scale[0]; - scale[0] = scale[1] = scale[2] = 1.; - } - if (rotation[0] == 0. && rotation[1] == 0.) { - instance_rotation = -rotation[2]; - rotation[2] = 0.; - } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Eigen::Matrix3f mat_rot, mat_scale, mat_trafo; mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) * Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) * @@ -151,15 +134,9 @@ static void extract_model_from_archive( for (size_t c = 0; c < 3; ++ c) trafo[r][c] += mat_trafo(r, c); } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance_offset = Vec3d((double)(position[0] - zero[0]), (double)(position[1] - zero[1]), (double)(position[2] - zero[2])); // CHECK_ME -> Is the following correct ? trafo[2][3] = position[2] / (float)instance_scaling_factor(2); -#else - instance_offset(0) = position[0] - zero[0]; - instance_offset(1) = position[1] - zero[1]; - trafo[2][3] = position[2] / instance_scaling_factor; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM trafo_set = true; } const char *group_tag = ""; @@ -315,15 +292,9 @@ static void extract_model_from_archive( model_object = model->add_object(name, path, std::move(mesh)); volume = model_object->volumes.front(); ModelInstance *instance = model_object->add_instance(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance->set_rotation(instance_rotation); instance->set_scaling_factor(instance_scaling_factor); instance->set_offset(instance_offset); -#else - instance->rotation = instance_rotation; - instance->scaling_factor = instance_scaling_factor; - instance->offset = instance_offset; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (group_id != (size_t)-1) group_to_model_object[group_id] = model_object; } else { diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 8ced1018d..dc2c37c7f 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -252,19 +252,11 @@ void Model::center_instances_around_point(const Vec2d &point) for (size_t i = 0; i < o->instances.size(); ++ i) bb.merge(o->instance_bounding_box(i, false)); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec2d shift2 = point - to_2d(bb.center()); Vec3d shift3 = Vec3d(shift2(0), shift2(1), 0.0); -#else - Vec2d shift = point - 0.5 * to_2d(bb.size()) - to_2d(bb.min); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM for (ModelObject *o : this->objects) { for (ModelInstance *i : o->instances) -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM i->set_offset(i->get_offset() + shift3); -#else - i->offset += shift; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM o->invalidate_bounding_box(); } } @@ -330,12 +322,8 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb) size_t idx = 0; for (ModelObject *o : this->objects) { for (ModelInstance *i : o->instances) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec2d offset_xy = positions[idx] - instance_centers[idx]; i->set_offset(Vec3d(offset_xy(0), offset_xy(1), i->get_offset(Z))); -#else - i->offset = positions[idx] - instance_centers[idx]; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ++idx; } o->invalidate_bounding_box(); @@ -360,11 +348,7 @@ void Model::duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb) for (const ModelInstance *i : instances) { for (const Vec2d &pos : positions) { ModelInstance *instance = o->add_instance(*i); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance->set_offset(instance->get_offset() + Vec3d(pos(0), pos(1), 0.0)); -#else - instance->offset += pos; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } o->invalidate_bounding_box(); @@ -394,21 +378,12 @@ void Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist) ModelObject* object = this->objects.front(); object->clear_instances(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d ext_size = object->bounding_box().size() + dist * Vec3d::Ones(); -#else - Vec3d size = object->bounding_box().size(); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM for (size_t x_copy = 1; x_copy <= x; ++x_copy) { for (size_t y_copy = 1; y_copy <= y; ++y_copy) { ModelInstance* instance = object->add_instance(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM instance->set_offset(Vec3d(ext_size(0) * (double)(x_copy - 1), ext_size(1) * (double)(y_copy - 1), 0.0)); -#else - instance->offset(0) = (size(0) + dist) * (x_copy - 1); - instance->offset(1) = (size(1) + dist) * (y_copy - 1); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } } @@ -728,23 +703,16 @@ void ModelObject::center_around_origin() this->translate(shift); this->origin_translation += shift; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if !ENABLE_EXTENDED_SELECTION // set z to zero, translation in z has already been done within the mesh shift(2) = 0.0; #endif // !ENABLE_EXTENDED_SELECTION -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (!this->instances.empty()) { for (ModelInstance *i : this->instances) { // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM i->set_offset(i->get_offset() + i->transform_vector(-shift, true)); -#else - Vec3d i_shift = i->world_matrix(true) * shift; - i->offset -= to_2d(i_shift); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } this->invalidate_bounding_box(); } @@ -1091,7 +1059,6 @@ size_t ModelVolume::split(unsigned int max_extruders) return idx; } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ModelInstance::set_rotation(const Vec3d& rotation) { set_rotation(X, rotation(0)); @@ -1112,7 +1079,6 @@ void ModelInstance::set_rotation(Axis axis, double rotation) } m_rotation(axis) = rotation; } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const { @@ -1127,7 +1093,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes BoundingBoxf3 bbox = copy.bounding_box(); if (!empty(bbox)) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Scale the bounding box along the three axes. for (unsigned int i = 0; i < 3; ++i) { @@ -1143,19 +1108,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes bbox.min += this->m_offset; bbox.max += this->m_offset; } -#else - // Scale the bounding box uniformly. - if (std::abs(this->scaling_factor - 1.) > EPSILON) { - bbox.min *= this->scaling_factor; - bbox.max *= this->scaling_factor; - } - - // Translate the bounding box. - if (!dont_translate) { - Eigen::Map(bbox.min.data()) += this->offset; - Eigen::Map(bbox.max.data()) += this->offset; - } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } return bbox; } @@ -1172,38 +1124,18 @@ Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const void ModelInstance::transform_polygon(Polygon* polygon) const { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // CHECK_ME -> Is the following correct or it should take in account all three rotations ? polygon->rotate(this->m_rotation(2)); // rotate around polygon origin // CHECK_ME -> Is the following correct ? polygon->scale(this->m_scaling_factor(0), this->m_scaling_factor(1)); // scale around polygon origin -#else - polygon->rotate(this->rotation); // rotate around polygon origin - polygon->scale(this->scaling_factor); // scale around polygon origin -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset; Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation; Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor; return Geometry::assemble_transform(translation, rotation, scale); -#else - Transform3d m = Transform3d::Identity(); - - if (!dont_translate) - m.translate(Vec3d(offset(0), offset(1), 0.0)); - - if (!dont_rotate) - m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); - - if (!dont_scale) - m.scale(scaling_factor); - - return m; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 695de6127..7fd889ffb 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -247,25 +247,17 @@ public: friend class ModelObject; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM private: Vec3d m_offset; // in unscaled coordinates Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point Vec3d m_scaling_factor; // Scaling factors along the three axes public: -#else - double rotation; // Rotation around the Z axis, in radians around mesh center point - double scaling_factor; - Vec2d offset; // in unscaled coordinates -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // flag showing the position of this instance with respect to the print volume (set by Print::validate() using ModelObject::check_instances_print_volume_state()) EPrintVolumeState print_volume_state; ModelObject* get_object() const { return this->object; } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& get_offset() const { return m_offset; } double get_offset(Axis axis) const { return m_offset(axis); } @@ -283,7 +275,6 @@ public: void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; } void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // To be called on an external mesh void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; @@ -304,15 +295,9 @@ private: // Parent object, owning this instance. ModelObject* object; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {} ModelInstance(ModelObject *object, const ModelInstance &other) : m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {} -#else - ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), offset(Vec2d::Zero()), object(object), print_volume_state(PVS_Inside) {} - ModelInstance(ModelObject *object, const ModelInstance &other) : - rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), print_volume_state(PVS_Inside) {} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM }; diff --git a/src/libslic3r/ModelArrange.hpp b/src/libslic3r/ModelArrange.hpp index f8beb668a..dffb951dd 100644 --- a/src/libslic3r/ModelArrange.hpp +++ b/src/libslic3r/ModelArrange.hpp @@ -29,12 +29,8 @@ std::string toString(const Model& model, bool holes = true) { if(!objinst) continue; Slic3r::TriangleMesh tmpmesh = rmesh; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // CHECK_ME -> Is the following correct ? tmpmesh.scale(objinst->get_scaling_factor()); -#else - tmpmesh.scale(objinst->scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM objinst->transform_mesh(&tmpmesh); ExPolygons expolys = tmpmesh.horizontal_projection(); for(auto& expoly_complex : expolys) { @@ -92,11 +88,7 @@ void toSVG(SVG& svg, const Model& model) { if(!objinst) continue; Slic3r::TriangleMesh tmpmesh = rmesh; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM tmpmesh.scale(objinst->get_scaling_factor()); -#else - tmpmesh.scale(objinst->scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM objinst->transform_mesh(&tmpmesh); ExPolygons expolys = tmpmesh.horizontal_projection(); svg.draw(expolys); @@ -522,12 +514,8 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) { Slic3r::TriangleMesh tmpmesh = rmesh; ClipperLib::PolygonImpl pn; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // CHECK_ME -> is the following correct ? tmpmesh.scale(objinst->get_scaling_factor()); -#else - tmpmesh.scale(objinst->scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // TODO export the exact 2D projection auto p = tmpmesh.convex_hull(); @@ -541,20 +529,11 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) { // Invalid geometries would throw exceptions when arranging if(item.vertexCount() > 3) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // CHECK_ME -> is the following correct or it should take in account all three rotations ? item.rotation(objinst->get_rotation(Z)); -#else - item.rotation(objinst->rotation); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM item.translation({ -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR), ClipperLib::cInt(objinst->get_offset(Y)/SCALING_FACTOR) -#else - ClipperLib::cInt(objinst->offset(0)/SCALING_FACTOR), - ClipperLib::cInt(objinst->offset(1)/SCALING_FACTOR) -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM }); ret.emplace_back(objinst, item); } @@ -691,7 +670,6 @@ void applyResult( // appropriately auto off = item.translation(); Radians rot = item.rotation(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR, 0.0); @@ -699,13 +677,6 @@ void applyResult( // write the transformation data into the model instance inst_ptr->set_rotation(Z, rot); inst_ptr->set_offset(foff); -#else - Vec2d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR); - - // write the transformation data into the model instance - inst_ptr->rotation = rot; - inst_ptr->offset = foff; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } diff --git a/src/libslic3r/MultiPoint.cpp b/src/libslic3r/MultiPoint.cpp index 45b354d63..6e49be958 100644 --- a/src/libslic3r/MultiPoint.cpp +++ b/src/libslic3r/MultiPoint.cpp @@ -14,7 +14,6 @@ void MultiPoint::scale(double factor) pt *= factor; } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void MultiPoint::scale(double factor_x, double factor_y) { for (Point &pt : points) @@ -23,7 +22,6 @@ void MultiPoint::scale(double factor_x, double factor_y) pt(1) *= factor_y; } } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void MultiPoint::translate(double x, double y) { diff --git a/src/libslic3r/MultiPoint.hpp b/src/libslic3r/MultiPoint.hpp index 288b3137e..9a7bd83e5 100644 --- a/src/libslic3r/MultiPoint.hpp +++ b/src/libslic3r/MultiPoint.hpp @@ -26,9 +26,7 @@ public: MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; } MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; } void scale(double factor); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void scale(double factor_x, double factor_y); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void translate(double x, double y); void translate(const Point &vector); void rotate(double angle) { this->rotate(cos(angle), sin(angle)); } diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 37b55f87d..5cd12f654 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -431,14 +431,10 @@ void Print::add_model_object(ModelObject* model_object, int idx) std::vector v_scale; for (const PrintObject *object : m_objects) { const ModelObject &mobj = *object->model_object(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // CHECK_ME -> Is the following correct ? v_scale.push_back("x:" + boost::lexical_cast(mobj.instances[0]->get_scaling_factor(X) * 100) + "% y:" + boost::lexical_cast(mobj.instances[0]->get_scaling_factor(Y) * 100) + "% z:" + boost::lexical_cast(mobj.instances[0]->get_scaling_factor(Z) * 100) + "%"); -#else - v_scale.push_back(boost::lexical_cast(mobj.instances[0]->scaling_factor * 100) + "%"); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (input_file.empty()) input_file = mobj.input_file; } diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 345cc9c5e..c62dd000c 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -113,16 +113,11 @@ bool PrintObject::reload_model_instances() copies.reserve(m_model_object->instances.size()); for (const ModelInstance *mi : m_model_object->instances) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (mi->is_printable()) { const Vec3d& offset = mi->get_offset(); copies.emplace_back(Point::new_scale(offset(0), offset(1))); } -#else - if (mi->is_printable()) - copies.emplace_back(Point::new_scale(mi->offset(0), mi->offset(1))); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } return this->set_copies(copies); } diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 0b918d7c9..4c653e543 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -4,16 +4,12 @@ // 1.42.0 techs #define ENABLE_1_42_0 1 -// Add z coordinate to model instances' offset -// Add x and y rotation components to model instances' rotation -// Add scaling factors for all the three axes to model instances -#define ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM (1 && ENABLE_1_42_0) // Add double click on gizmo grabbers to reset transformation components to their default value #define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0) // Uses a unique opengl context #define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0) // New selections -#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM) +#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 07f9b0fda..402d7b8ee 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -196,13 +196,8 @@ const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; GLVolume::GLVolume(float r, float g, float b, float a) : m_offset(Vec3d::Zero()) -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM , m_rotation(Vec3d::Zero()) , m_scaling_factor(Vec3d::Ones()) -#else - , m_rotation(0.0) - , m_scaling_factor(1.0) -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM , m_world_matrix(Transform3f::Identity()) , m_world_matrix_dirty(true) , m_transformed_bounding_box_dirty(true) @@ -262,7 +257,6 @@ void GLVolume::set_render_color() set_render_color(color, 4); } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& GLVolume::get_rotation() const { return m_rotation; @@ -295,23 +289,6 @@ void GLVolume::set_rotation(const Vec3d& rotation) m_transformed_convex_hull_bounding_box_dirty = true; } } -#else -double GLVolume::get_rotation() const -{ - return m_rotation; -} - -void GLVolume::set_rotation(double rotation) -{ - if (m_rotation != rotation) - { - m_rotation = rotation; - m_world_matrix_dirty = true; - m_transformed_bounding_box_dirty = true; - m_transformed_convex_hull_bounding_box_dirty = true; - } -} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& GLVolume::get_offset() const { @@ -329,7 +306,6 @@ void GLVolume::set_offset(const Vec3d& offset) } } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION const Vec3d& GLVolume::get_scaling_factor() const { @@ -347,18 +323,6 @@ void GLVolume::set_scaling_factor(const Vec3d& scaling_factor) m_transformed_convex_hull_bounding_box_dirty = true; } } -#else -void GLVolume::set_scaling_factor(double factor) -{ - if (m_scaling_factor != factor) - { - m_scaling_factor = factor; - m_world_matrix_dirty = true; - m_transformed_bounding_box_dirty = true; - m_transformed_convex_hull_bounding_box_dirty = true; - } -} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void GLVolume::set_convex_hull(const TriangleMesh& convex_hull) { @@ -389,14 +353,7 @@ const Transform3f& GLVolume::world_matrix() const { if (m_world_matrix_dirty) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast(); -#else - m_world_matrix = Transform3f::Identity(); - m_world_matrix.translate(m_offset.cast()); - m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ())); - m_world_matrix.scale((float)m_scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_world_matrix_dirty = false; } return m_world_matrix; @@ -471,13 +428,7 @@ void GLVolume::render() const ::glCullFace(GL_BACK); ::glPushMatrix(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ::glMultMatrixf(world_matrix().data()); -#else - ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); - ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); - ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (this->indexed_vertex_array.indexed()) this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); else @@ -602,13 +553,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c ::glPushMatrix(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ::glMultMatrixf(world_matrix().data()); -#else - ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); - ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); - ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (n_triangles > 0) { @@ -652,13 +597,7 @@ void GLVolume::render_legacy() const ::glPushMatrix(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ::glMultMatrixf(world_matrix().data()); -#else - ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); - ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); - ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (n_triangles > 0) ::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first); @@ -787,15 +726,9 @@ std::vector GLVolumeCollection::load_object( } v.is_modifier = ! model_volume->is_model_part(); v.shader_outside_printer_detection_enabled = model_volume->is_model_part(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM v.set_offset(instance->get_offset()); v.set_rotation(instance->get_rotation()); v.set_scaling_factor(instance->get_scaling_factor()); -#else - v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0)); - v.set_rotation(instance->rotation); - v.set_scaling_factor(instance->scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 5eb349f09..e3f7ea0d3 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -256,17 +256,10 @@ public: private: // Offset of the volume to be rendered. Vec3d m_offset; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Rotation around three axes of the volume to be rendered. Vec3d m_rotation; // Scale factor along the three axes of the volume to be rendered. Vec3d m_scaling_factor; -#else - // Rotation around Z axis of the volume to be rendered. - double m_rotation; - // Scale factor of the volume to be rendered. - double m_scaling_factor; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // World matrix of the volume to be rendered. mutable Transform3f m_world_matrix; // Whether or not is needed to recalculate the world matrix. @@ -336,7 +329,6 @@ public: // Sets render color in dependence of current state void set_render_color(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& get_rotation() const; void set_rotation(const Vec3d& rotation); @@ -344,12 +336,6 @@ public: const Vec3d& get_scaling_factor() const; #endif // ENABLE_EXTENDED_SELECTION void set_scaling_factor(const Vec3d& scaling_factor); -#else - double get_rotation() const; - void set_rotation(double rotation); - - void set_scaling_factor(double factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& get_offset() const; void set_offset(const Vec3d& offset); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 42b135448..47729cffb 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1830,11 +1830,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent) if (!gizmo->init()) return false; -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // temporary disable z grabber - gizmo->disable_grabber(2); -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - m_gizmos.insert(GizmosMap::value_type(Move, gizmo)); gizmo = new GLGizmoScale3D(parent); @@ -1844,18 +1839,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent) if (!gizmo->init()) return false; -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // temporary disable x grabbers - gizmo->disable_grabber(0); - gizmo->disable_grabber(1); - // temporary disable y grabbers - gizmo->disable_grabber(2); - gizmo->disable_grabber(3); - // temporary disable z grabbers - gizmo->disable_grabber(4); - gizmo->disable_grabber(5); -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - m_gizmos.insert(GizmosMap::value_type(Scale, gizmo)); gizmo = new GLGizmoRotate3D(parent); @@ -1871,12 +1854,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent) return false; } -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - // temporary disable x and y grabbers - gizmo->disable_grabber(0); - gizmo->disable_grabber(1); -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo)); gizmo = new GLGizmoFlatten(parent); @@ -2161,7 +2138,6 @@ void GLCanvas3D::Gizmos::set_position(const Vec3d& position) } #endif // ENABLE_EXTENDED_SELECTION -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d GLCanvas3D::Gizmos::get_scale() const { if (!m_enabled) @@ -2208,54 +2184,6 @@ Vec3d GLCanvas3D::Gizmos::get_flattening_rotation() const GizmosMap::const_iterator it = m_gizmos.find(Flatten); return (it != m_gizmos.end()) ? reinterpret_cast(it->second)->get_flattening_rotation() : Vec3d::Zero(); } -#else -float GLCanvas3D::Gizmos::get_scale() const -{ - if (!m_enabled) - return 1.0f; - - GizmosMap::const_iterator it = m_gizmos.find(Scale); - return (it != m_gizmos.end()) ? reinterpret_cast(it->second)->get_scale_x() : 1.0f; -} - -void GLCanvas3D::Gizmos::set_scale(float scale) -{ - if (!m_enabled) - return; - - GizmosMap::const_iterator it = m_gizmos.find(Scale); - if (it != m_gizmos.end()) - reinterpret_cast(it->second)->set_scale(scale); -} - -float GLCanvas3D::Gizmos::get_angle_z() const -{ - if (!m_enabled) - return 0.0f; - - GizmosMap::const_iterator it = m_gizmos.find(Rotate); - return (it != m_gizmos.end()) ? reinterpret_cast(it->second)->get_angle_z() : 0.0f; -} - -void GLCanvas3D::Gizmos::set_angle_z(float angle_z) -{ - if (!m_enabled) - return; - - GizmosMap::const_iterator it = m_gizmos.find(Rotate); - if (it != m_gizmos.end()) - reinterpret_cast(it->second)->set_angle_z(angle_z); -} - -Vec3d GLCanvas3D::Gizmos::get_flattening_normal() const -{ - if (!m_enabled) - return Vec3d::Zero(); - - GizmosMap::const_iterator it = m_gizmos.find(Flatten); - return (it != m_gizmos.end()) ? reinterpret_cast(it->second)->get_flattening_normal() : Vec3d::Zero(); -} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void GLCanvas3D::Gizmos::set_flattening_data(const ModelObject* model_object) { @@ -3306,15 +3234,9 @@ void GLCanvas3D::update_gizmos_data() ModelInstance* model_instance = model_object->instances[0]; if (model_instance != nullptr) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_gizmos.set_position(model_instance->get_offset()); m_gizmos.set_scale(model_instance->get_scaling_factor()); m_gizmos.set_rotation(model_instance->get_rotation()); -#else - m_gizmos.set_position(Vec3d(model_instance->offset(0), model_instance->offset(1), 0.0)); - m_gizmos.set_scale(model_instance->scaling_factor); - m_gizmos.set_angle_z(model_instance->rotation); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_gizmos.set_flattening_data(model_object); } } @@ -3322,13 +3244,8 @@ void GLCanvas3D::update_gizmos_data() else { m_gizmos.set_position(Vec3d::Zero()); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_gizmos.set_scale(Vec3d::Ones()); m_gizmos.set_rotation(Vec3d::Zero()); -#else - m_gizmos.set_scale(1.0f); - m_gizmos.set_angle_z(0.0f); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_gizmos.set_flattening_data(nullptr); } #endif // ENABLE_EXTENDED_SELECTION @@ -3862,17 +3779,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { case Gizmos::Scale: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION m_regenerate_volumes = false; m_selection.scale(m_gizmos.get_scale()); _on_scale(); -#else - post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale())); -#endif // ENABLE_EXTENDED_SELECTION #else m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM +#endif // ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION wxGetApp().obj_manipul()->update_settings_value(m_selection); #else @@ -3883,7 +3796,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } case Gizmos::Rotate: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION m_regenerate_volumes = false; m_selection.rotate(m_gizmos.get_rotation()); @@ -3891,9 +3803,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) #else post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation()))); #endif // ENABLE_EXTENDED_SELECTION -#else - m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z()); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION wxGetApp().obj_manipul()->update_settings_value(m_selection); #else @@ -3969,18 +3878,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) #endif // ENABLE_EXTENDED_SELECTION if (m_gizmos.get_current_type() == Gizmos::Flatten) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Rotate the object so the normal points downward: post_event(Vec3dEvent(EVT_GIZMO_FLATTEN, m_gizmos.get_flattening_rotation())); -#else - // Rotate the object so the normal points downward: - Vec3d normal = m_gizmos.get_flattening_normal(); - if (normal(0) != 0.0 || normal(1) != 0.0 || normal(2) != 0.0) { - Vec3d axis = normal(2) > 0.999 ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()).normalized(); - float angle = acos(clamp(-1.0, 1.0, -normal(2))); - m_on_gizmo_flatten_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2)); - } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } m_dirty = true; @@ -4215,7 +4114,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } case Gizmos::Scale: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Apply new temporary scale factors #if ENABLE_EXTENDED_SELECTION m_selection.scale(m_gizmos.get_scale()); @@ -4228,20 +4126,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } wxGetApp().obj_manipul()->update_scale_value(scale); #endif // ENABLE_EXTENDED_SELECTION -#else - // Apply new temporary scale factor - float scale_factor = m_gizmos.get_scale(); - for (GLVolume* v : volumes) - { - v->set_scaling_factor((double)scale_factor); - } - wxGetApp().obj_manipul()->update_scale_values((double)scale_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM break; } case Gizmos::Rotate: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // Apply new temporary rotations #if ENABLE_EXTENDED_SELECTION m_selection.rotate(m_gizmos.get_rotation()); @@ -4255,15 +4143,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } wxGetApp().obj_manipul()->update_rotation_value(rotation); #endif // ENABLE_EXTENDED_SELECTION -#else - // Apply new temporary angle_z - float angle_z = m_gizmos.get_angle_z(); - for (GLVolume* v : volumes) - { - v->set_rotation((double)angle_z); - } - update_rotation_value((double)angle_z, Z); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM break; } default: @@ -4280,12 +4159,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) bb.merge(volume->transformed_bounding_box()); } const Vec3d& size = bb.size(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& scale = m_gizmos.get_scale(); post_event(Vec3dsEvent<2>(EVT_GLCANVAS_UPDATE_GEOMETRY, {size, scale})); -#else - m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale()); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } #endif // ENABLE_EXTENDED_SELECTION @@ -4428,28 +4303,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } case Gizmos::Scale: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION m_regenerate_volumes = false; _on_scale(); #endif // ENABLE_EXTENDED_SELECTION -#else - m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM break; } case Gizmos::Rotate: { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION m_regenerate_volumes = false; _on_rotate(); #else post_event(Vec3dEvent(EVT_GIZMO_ROTATE, m_gizmos.get_rotation())); #endif // ENABLE_EXTENDED_SELECTION -#else - m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z()); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM break; } default: @@ -6625,12 +6492,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) ModelObject* model_object = m_model->objects[obj_idx]; if (model_object != nullptr) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM model_object->instances[instance_idx]->set_offset(volume->get_offset()); -#else - const Vec3d& offset = volume->get_offset(); - model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1)); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM model_object->invalidate_bounding_box(); wxGetApp().obj_manipul()->update_position_values(); object_moved = true; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index a6d84eaa3..8029ed4c4 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -589,7 +589,6 @@ private: void set_position(const Vec3d& position); #endif // ENABLE_EXTENDED_SELECTION -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d get_scale() const; void set_scale(const Vec3d& scale); @@ -597,15 +596,6 @@ private: void set_rotation(const Vec3d& rotation); Vec3d get_flattening_rotation() const; -#else - float get_scale() const; - void set_scale(float scale); - - float get_angle_z() const; - void set_angle_z(float angle_z); - - Vec3d get_flattening_normal() const; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void set_flattening_data(const ModelObject* model_object); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index b1e7473aa..88672f506 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1086,11 +1086,7 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray) #endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_scale(1) = m_starting_scale(1) * ratio; -#else - m_scale(0) = m_starting_scale(1) * ratio; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray) @@ -1102,11 +1098,7 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray) #endif // ENABLE_EXTENDED_SELECTION if (ratio > 0.0) -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_scale(2) = m_starting_scale(2) * ratio; -#else - m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray) @@ -1490,18 +1482,11 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const else ::glColor4f(0.9f, 0.9f, 0.9f, 0.5f); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM for (const InstanceData& inst : m_instances) { Transform3d m = inst.matrix; m.pretranslate(dragged_offset); ::glPushMatrix(); ::glMultMatrixd(m.data()); -#else - for (Vec2d offset : m_instances_positions) { - offset += to_2d(dragged_offset); - ::glPushMatrix(); - ::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ::glBegin(GL_POLYGON); for (const Vec3d& vertex : m_planes[i].vertices) ::glVertex3dv(vertex.data()); @@ -1524,15 +1509,9 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const for (unsigned int i = 0; i < m_planes.size(); ++i) { ::glColor3f(1.0f, 1.0f, picking_color_component(i)); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM for (const InstanceData& inst : m_instances) { ::glPushMatrix(); ::glMultMatrixd(inst.matrix.data()); -#else - for (const Vec2d& offset : m_instances_positions) { - ::glPushMatrix(); - ::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM ::glBegin(GL_POLYGON); for (const Vec3d& vertex : m_planes[i].vertices) ::glVertex3dv(vertex.data()); @@ -1548,17 +1527,9 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) // ...and save the updated positions of the object instances: if (m_model_object && !m_model_object->instances.empty()) { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_instances.clear(); -#else - m_instances_positions.clear(); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM for (const auto* instance : m_model_object->instances) -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_instances.emplace_back(instance->world_matrix()); -#else - m_instances_positions.emplace_back(instance->offset); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } if (is_plane_update_necessary()) @@ -1572,10 +1543,6 @@ void GLGizmoFlatten::update_planes() ch.merge(vol->get_convex_hull()); ch = ch.convex_hull_3d(); -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - ch.scale(m_model_object->instances.front()->scaling_factor); - ch.rotate_z(m_model_object->instances.front()->rotation); -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& bb_size = ch.bounding_box().size(); double min_bb_face_area = std::min(bb_size(0) * bb_size(1), std::min(bb_size(0) * bb_size(2), bb_size(1) * bb_size(2))); @@ -1741,10 +1708,6 @@ void GLGizmoFlatten::update_planes() m_source_data.bounding_boxes.clear(); for (const auto& vol : m_model_object->volumes) m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor; - m_source_data.rotation = m_model_object->instances.front()->rotation; -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]); } @@ -1756,13 +1719,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const if (m_state != On || !m_model_object || m_model_object->instances.empty()) return false; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size()) -#else - if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size() - || m_model_object->instances.front()->scaling_factor != m_source_data.scaling_factor - || m_model_object->instances.front()->rotation != m_source_data.rotation) -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM return true; // now compare the bounding boxes: @@ -1778,7 +1735,6 @@ bool GLGizmoFlatten::is_plane_update_necessary() const return false; } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d GLGizmoFlatten::get_flattening_rotation() const { // calculates the rotations in model space, taking in account the scaling factors @@ -1788,13 +1744,6 @@ Vec3d GLGizmoFlatten::get_flattening_rotation() const m_normal = Vec3d::Zero(); return Vec3d(angles(2), angles(1), angles(0)); } -#else -Vec3d GLGizmoFlatten::get_flattening_normal() const { - Vec3d normal = m_model_object->instances.front()->world_matrix(true).matrix().block(0, 0, 3, 3).inverse() * m_normal; - m_normal = Vec3d::Zero(); - return normal.normalized(); -} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 8babd21e5..7c0196a83 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -230,19 +230,8 @@ class GLGizmoRotate3D : public GLGizmoBase public: explicit GLGizmoRotate3D(GLCanvas3D& parent); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d get_rotation() const { return Vec3d(m_gizmos[X].get_angle(), m_gizmos[Y].get_angle(), m_gizmos[Z].get_angle()); } void set_rotation(const Vec3d& rotation) { m_gizmos[X].set_angle(rotation(0)); m_gizmos[Y].set_angle(rotation(1)); m_gizmos[Z].set_angle(rotation(2)); } -#else - double get_angle_x() const { return m_gizmos[X].get_angle(); } - void set_angle_x(double angle) { m_gizmos[X].set_angle(angle); } - - double get_angle_y() const { return m_gizmos[Y].get_angle(); } - void set_angle_y(double angle) { m_gizmos[Y].set_angle(angle); } - - double get_angle_z() const { return m_gizmos[Z].get_angle(); } - void set_angle_z(double angle) { m_gizmos[Z].set_angle(angle); } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM protected: virtual bool on_init(); @@ -329,25 +318,12 @@ class GLGizmoScale3D : public GLGizmoBase public: explicit GLGizmoScale3D(GLCanvas3D& parent); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM const Vec3d& get_scale() const { return m_scale; } #if ENABLE_EXTENDED_SELECTION void set_scale(const Vec3d& scale) { m_starting_scale = scale; m_scale = scale; } #else void set_scale(const Vec3d& scale) { m_starting_scale = scale; } #endif // ENABLE_EXTENDED_SELECTION -#else - double get_scale_x() const { return m_scale(0); } - void set_scale_x(double scale) { m_starting_scale(0) = scale; } - - double get_scale_y() const { return m_scale(1); } - void set_scale_y(double scale) { m_starting_scale(1) = scale; } - - double get_scale_z() const { return m_scale(2); } - void set_scale_z(double scale) { m_starting_scale(2) = scale; } - - void set_scale(double scale) { m_starting_scale = scale * Vec3d::Ones(); } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM protected: virtual bool on_init(); @@ -444,10 +420,6 @@ private: }; struct SourceDataSummary { std::vector bounding_boxes; // bounding boxes of convex hulls of individual volumes -#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - float scaling_factor; - float rotation; -#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d mesh_first_point; }; @@ -455,16 +427,12 @@ private: SourceDataSummary m_source_data; std::vector m_planes; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM struct InstanceData { Transform3d matrix; InstanceData(const Transform3d& matrix) : matrix(matrix) {} }; std::vector m_instances; -#else - std::vector m_instances_positions; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d m_starting_center; const ModelObject* m_model_object = nullptr; @@ -475,11 +443,7 @@ public: explicit GLGizmoFlatten(GLCanvas3D& parent); void set_flattening_data(const ModelObject* model_object); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d get_flattening_rotation() const; -#else - Vec3d get_flattening_normal() const; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM protected: virtual bool on_init(); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 94425a5e8..fc51b419b 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -375,7 +375,6 @@ void ObjectManipulation::update_scale_values() auto instance = objects[selection]->instances.front(); auto size = objects[selection]->instance_bounding_box(0).size(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (m_is_percent_scale) { m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100)); m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100)); @@ -386,34 +385,15 @@ void ObjectManipulation::update_scale_values() m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5)); m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5)); } -#else - if (m_is_percent_scale) { - auto scale = instance->scaling_factor * 100.0; - m_og->set_value("scale_x", int(scale)); - m_og->set_value("scale_y", int(scale)); - m_og->set_value("scale_z", int(scale)); - } - else { - m_og->set_value("scale_x", int(instance->scaling_factor * size(0) + 0.5)); - m_og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5)); - m_og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5)); - } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } void ObjectManipulation::update_position_values() { auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_og->set_value("position_x", int(instance->get_offset(X))); m_og->set_value("position_y", int(instance->get_offset(Y))); m_og->set_value("position_z", int(instance->get_offset(Z))); -#else - m_og->set_value("position_x", int(instance->offset(0))); - m_og->set_value("position_y", int(instance->offset(1))); - m_og->set_value("position_z", 0); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } void ObjectManipulation::update_position_value(const Vec3d& position) @@ -423,7 +403,6 @@ void ObjectManipulation::update_position_value(const Vec3d& position) m_og->set_value("position_z", int(position(2))); } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) { // this is temporary @@ -438,33 +417,10 @@ void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) m_og->set_value("scale_y", int(scale(1))); m_og->set_value("scale_z", int(scale(2))); } -#else -void ObjectManipulation::update_scale_values(double scaling_factor) -{ - // this is temporary - // to be able to update the values as size - // we need to store somewhere the original size - // or have it passed as parameter - if (!m_is_percent_scale) - m_og->set_value("scale_unit", _("%")); - - auto scale = scaling_factor * 100.0; - m_og->set_value("scale_x", int(scale)); - m_og->set_value("scale_y", int(scale)); - m_og->set_value("scale_z", int(scale)); -} -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ObjectManipulation::update_rotation_values() { -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM update_rotation_value(wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front()->get_rotation()); -#else - auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front(); - m_og->set_value("rotation_x", 0); - m_og->set_value("rotation_y", 0); - m_og->set_value("rotation_z", int(Geometry::rad2deg(instance->rotation))); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } void ObjectManipulation::update_rotation_value(double angle, Axis axis) @@ -485,14 +441,12 @@ void ObjectManipulation::update_rotation_value(double angle, Axis axis) m_og->set_value(axis_str, round_nearest(int(Geometry::rad2deg(angle)), 0)); } -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ObjectManipulation::update_rotation_value(const Vec3d& rotation) { m_og->set_value("rotation_x", int(round_nearest(Geometry::rad2deg(rotation(0)), 0))); m_og->set_value("rotation_y", int(round_nearest(Geometry::rad2deg(rotation(1)), 0))); m_og->set_value("rotation_z", int(round_nearest(Geometry::rad2deg(rotation(2)), 0))); } -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void ObjectManipulation::show_object_name(bool show) { diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index c0cd70160..13b9290a0 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -61,18 +61,12 @@ public: void update_position_value(const Vec3d& position); // update scale values after scale unit changing or "gizmos" void update_scale_values(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void update_scale_value(const Vec3d& scaling_factor); -#else - void update_scale_values(double scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // update rotation values object selection changing void update_rotation_values(); // update rotation value after "gizmos" void update_rotation_value(double angle, Axis axis); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void update_rotation_value(const Vec3d& rotation); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 62ccf2b06..cfe34a794 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -295,7 +295,6 @@ ModelMaterial::attributes() Ref object() %code%{ RETVAL = THIS->get_object(); %}; -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM Vec3d* rotation() %code%{ RETVAL = new Vec3d(THIS->get_rotation(X), THIS->get_rotation(Y), THIS->get_rotation(Z)); %}; @@ -322,25 +321,6 @@ ModelMaterial::attributes() THIS->set_offset(X, (*offset)(0)); THIS->set_offset(Y, (*offset)(1)); %}; -#else - double rotation() - %code%{ RETVAL = THIS->rotation; %}; - - double scaling_factor() - %code%{ RETVAL = THIS->scaling_factor; %}; - - Ref offset() - %code%{ RETVAL = &THIS->offset; %}; - - void set_rotation(double val) - %code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %}; - - void set_scaling_factor(double val) - %code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %}; - - void set_offset(Vec2d *offset) - %code%{ THIS->offset = *offset; %}; -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; void transform_polygon(Polygon* polygon) const; From 0263769d8f5462523cbf32899be5d4e4f3629ea1 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 16 Oct 2018 09:20:56 +0200 Subject: [PATCH 06/24] deps: Back to Boost 1.63 on Windows as newer ones require newer CMake 32bit deps fix --- deps/CMakeLists.txt | 10 ++++++---- deps/deps-windows.cmake | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index a20c7aa18..72df1a2fc 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -13,13 +13,15 @@ if (MSVC) set(DEPS_BITS 64) set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-64") include("deps-windows.cmake") + add_custom_target(deps_64 + DEPENDS dep_boost_64 dep_tbb_64 dep_libcurl_64 dep_wxwidgets_64 + ) + set(DEPS_BITS 32) set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-32") include("deps-windows.cmake") - - add_custom_target(deps ALL - DEPENDS dep_boost_64 dep_tbb_64 dep_libcurl_64 dep_wxwidgets_64 - # dep_boost_32 dep_tbb_32 dep_libcurl_32 dep_wxwidgets_32 + add_custom_target(deps_32 + DEPENDS dep_boost_32 dep_tbb_32 dep_libcurl_32 dep_wxwidgets_32 ) else () set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir") diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index eaf5b8e65..8a276c54e 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -1,8 +1,8 @@ ExternalProject_Add("dep_boost_${DEPS_BITS}" EXCLUDE_FROM_ALL 1 - URL "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz" - URL_HASH SHA256=bd0df411efd9a585e5a2212275f8762079fed8842264954675a4fddc46cfcf60 + URL "https://dl.bintray.com/boostorg/release/1.63.0/source/boost_1_63_0.tar.gz" + URL_HASH SHA256=fe34a4e119798e10b8cc9e565b3b0284e9fd3977ec8a1b19586ad1dec397088b BUILD_IN_SOURCE 1 CONFIGURE_COMMAND bootstrap.bat BUILD_COMMAND b2.exe From 97e7b6f18b83100b25998ba737b5a1df0a8af529 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 16 Oct 2018 11:06:26 +0200 Subject: [PATCH 07/24] deps: Fix arch resolution on Windows --- deps/CMakeLists.txt | 53 +++++++++++++++++++++++++++-------------- deps/deps-windows.cmake | 14 +++++------ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 72df1a2fc..852d17fa2 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,3 +1,21 @@ +# +# This CMake project downloads, configures and builds Slic3r PE dependencies on Unix and Windows. +# +# When using this script, it's recommended to perform an out-of-source build using CMake. +# +# All the dependencies are installed in a `destdir` directory in the root of the build directory, +# in a traditional Unix-style prefix structure. The destdir can be used directly by CMake +# when building Slic3r - to do this, set the CMAKE_PREFIX_PATH to the destdir's location. +# +# For better clarity of console output, it's recommended to _not_ use a parallelized build +# for the top-level command, ie. use `make -j 1` or `ninja -j 1` to force single-threaded top-level +# build. This doesn't degrade performance as individual dependencies are built in parallel fashion +# as appropriate anyway (cf. the `NPROC` variable). +# +# On Windows, architecture (64 vs 32 bits) is judged based on the compiler variant. +# To build dependencies for either 64 or 32 bit OS, use the respective compiler command line. +# + project(Slic3r-deps) cmake_minimum_required(VERSION 3.2) @@ -9,28 +27,27 @@ if (NPROC EQUAL 0) set(NPROC 1) endif () +set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir") + if (MSVC) - set(DEPS_BITS 64) - set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-64") - include("deps-windows.cmake") - add_custom_target(deps_64 - DEPENDS dep_boost_64 dep_tbb_64 dep_libcurl_64 dep_wxwidgets_64 - ) - - set(DEPS_BITS 32) - set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir-32") - include("deps-windows.cmake") - add_custom_target(deps_32 - DEPENDS dep_boost_32 dep_tbb_32 dep_libcurl_32 dep_wxwidgets_32 - ) + if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + message(STATUS "\nDetected 64-bit compiler => building 64-bit deps bundle\n") + set(DEPS_BITS 64) + include("deps-windows.cmake") + elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") + message(STATUS "\nDetected 32-bit compiler => building 32-bit deps bundle\n") + set(DEPS_BITS 32) + include("deps-windows.cmake") + else () + message(FATAL_ERROR "Unable to detect architecture") + endif () else () - set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir") include("deps-unix-static.cmake") - - add_custom_target(deps ALL - DEPENDS dep_boost dep_tbb dep_libcurl dep_wxwidgets - ) endif() +add_custom_target(deps ALL + DEPENDS dep_boost dep_tbb dep_libcurl dep_wxwidgets +) + # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands # because they seem to generate bogus build files (possibly a bug in ExternalProject). diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index 8a276c54e..2be0d448a 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -1,5 +1,5 @@ -ExternalProject_Add("dep_boost_${DEPS_BITS}" +ExternalProject_Add(dep_boost EXCLUDE_FROM_ALL 1 URL "https://dl.bintray.com/boostorg/release/1.63.0/source/boost_1_63_0.tar.gz" URL_HASH SHA256=fe34a4e119798e10b8cc9e565b3b0284e9fd3977ec8a1b19586ad1dec397088b @@ -25,13 +25,13 @@ ExternalProject_Add("dep_boost_${DEPS_BITS}" ) -if ($DEPS_BITS EQUAL 32) +if (${DEPS_BITS} EQUAL 32) set(DEP_TBB_GEN "Visual Studio 12") else () set(DEP_TBB_GEN "Visual Studio 12 Win64") endif () -ExternalProject_Add("dep_tbb_${DEPS_BITS}" +ExternalProject_Add(dep_tbb EXCLUDE_FROM_ALL 1 URL "https://github.com/wjakob/tbb/archive/a0dc9bf76d0120f917b641ed095360448cabc85b.tar.gz" URL_HASH SHA256=0545cb6033bd1873fcae3ea304def720a380a88292726943ae3b9b207f322efe @@ -46,13 +46,13 @@ ExternalProject_Add("dep_tbb_${DEPS_BITS}" ) -if ($DEPS_BITS EQUAL 32) +if (${DEPS_BITS} EQUAL 32) set(DEP_LIBCURL_TARGET "x86") else () set(DEP_LIBCURL_TARGET "x64") endif () -ExternalProject_Add("dep_libcurl_${DEPS_BITS}" +ExternalProject_Add(dep_libcurl EXCLUDE_FROM_ALL 1 URL "https://curl.haxx.se/download/curl-7.58.0.tar.gz" URL_HASH SHA256=cc245bf9a1a42a45df491501d97d5593392a03f7b4f07b952793518d97666115 @@ -64,7 +64,7 @@ ExternalProject_Add("dep_libcurl_${DEPS_BITS}" && "${CMAKE_COMMAND}" -E copy_directory lib "${DESTDIR}\\usr\\local\\lib" ) -if ($DEPS_BITS EQUAL 32) +if (${DEPS_BITS} EQUAL 32) set(DEP_WXWIDGETS_TARGET "") set(DEP_WXWIDGETS_LIBDIR "vc_lib") else () @@ -72,7 +72,7 @@ else () set(DEP_WXWIDGETS_LIBDIR "vc_x64_lib") endif () -ExternalProject_Add("dep_wxwidgets_${DEPS_BITS}" +ExternalProject_Add(dep_wxwidgets EXCLUDE_FROM_ALL 1 URL "https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.1/wxWidgets-3.1.1.tar.bz2" URL_HASH SHA256=c925dfe17e8f8b09eb7ea9bfdcfcc13696a3e14e92750effd839f5e10726159e From a8c459696f80ab696946ad16e44cd07cc9d884f0 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 16 Oct 2018 13:49:40 +0200 Subject: [PATCH 08/24] New selection -> Tighter bounding box for selections, tweaks to gizmo flatten and fix of instances update --- src/slic3r/GUI/GLCanvas3D.cpp | 51 ++++++++++++++++++++++++----------- src/slic3r/GUI/GLCanvas3D.hpp | 3 ++- src/slic3r/GUI/GLGizmo.cpp | 36 +++++++++++++++++++++++++ src/slic3r/GUI/GLGizmo.hpp | 2 ++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 47729cffb..440ca5fc6 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1346,7 +1346,7 @@ bool GLCanvas3D::Selection::is_single_full_instance() const int object_idx = m_valid ? get_object_idx() : -1; if (object_idx != -1) { - if (get_instance_idx() != -1) + if ((object_idx != -1) && (object_idx < 1000)) return m_model->objects[object_idx]->volumes.size() == m_list.size(); } @@ -1653,7 +1653,7 @@ void GLCanvas3D::Selection::_calc_bounding_box() const { for (unsigned int i : m_list) { - m_bounding_box.merge((*m_volumes)[i]->transformed_bounding_box()); + m_bounding_box.merge((*m_volumes)[i]->transformed_convex_hull_bounding_box()); } } m_bounding_box_dirty = false; @@ -1702,7 +1702,7 @@ void GLCanvas3D::Selection::_render_unselected_instances() const if (it == boxes.end()) it = boxes.insert(InstanceToBoxMap::value_type(box_id, BoundingBoxf3())).first; - it->second.merge(v->transformed_bounding_box()); + it->second.merge(v->transformed_convex_hull_bounding_box()); done.insert(j); } @@ -2081,6 +2081,9 @@ bool GLCanvas3D::Gizmos::is_running() const bool GLCanvas3D::Gizmos::is_dragging() const { + if (!m_enabled) + return false; + GLGizmoBase* curr = _get_current(); return (curr != nullptr) ? curr->is_dragging() : false; } @@ -2088,6 +2091,9 @@ bool GLCanvas3D::Gizmos::is_dragging() const #if ENABLE_EXTENDED_SELECTION void GLCanvas3D::Gizmos::start_dragging(const GLCanvas3D::Selection& selection) { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->start_dragging(selection); @@ -2095,6 +2101,9 @@ void GLCanvas3D::Gizmos::start_dragging(const GLCanvas3D::Selection& selection) #else void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box) { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->start_dragging(box); @@ -2103,6 +2112,9 @@ void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box) void GLCanvas3D::Gizmos::stop_dragging() { + if (!m_enabled) + return; + GLGizmoBase* curr = _get_current(); if (curr != nullptr) curr->stop_dragging(); @@ -2650,8 +2662,8 @@ wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); #if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); -#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); +#endif // !ENABLE_EXTENDED_SELECTION GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) @@ -3784,7 +3796,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_selection.scale(m_gizmos.get_scale()); _on_scale(); #else - m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); + post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale())); #endif // ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION wxGetApp().obj_manipul()->update_settings_value(m_selection); @@ -3879,7 +3891,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_gizmos.get_current_type() == Gizmos::Flatten) { // Rotate the object so the normal points downward: +#if ENABLE_EXTENDED_SELECTION + m_regenerate_volumes = false; + m_selection.rotate(m_gizmos.get_flattening_rotation()); + _on_flatten(); + wxGetApp().obj_manipul()->update_settings_value(m_selection); +#else post_event(Vec3dEvent(EVT_GIZMO_FLATTEN, m_gizmos.get_flattening_rotation())); +#endif // ENABLE_EXTENDED_SELECTION } m_dirty = true; @@ -5002,7 +5021,7 @@ void GLCanvas3D::_render_objects() const void GLCanvas3D::_render_selection() const { Gizmos::EType type = m_gizmos.get_current_type(); - bool show_indirect_selection = m_gizmos.is_running() && ((type == Gizmos::Rotate) || (type == Gizmos::Scale)); + bool show_indirect_selection = m_gizmos.is_running() && ((type == Gizmos::Rotate) || (type == Gizmos::Scale) || (type == Gizmos::Flatten)); m_selection.render(show_indirect_selection); } #endif // ENABLE_EXTENDED_SELECTION @@ -6354,11 +6373,9 @@ void GLCanvas3D::_on_move() std::set> done; // prevent moving instances twice bool object_moved = false; Vec3d wipe_tower_origin = Vec3d::Zero(); - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); int instance_idx = v->instance_idx(); @@ -6398,11 +6415,9 @@ void GLCanvas3D::_on_rotate() return; std::set> done; // prevent rotating instances twice - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); if (object_idx >= 1000) continue; @@ -6434,18 +6449,16 @@ void GLCanvas3D::_on_scale() return; std::set> done; // prevent scaling instances twice - const Selection::IndicesList& selection = m_selection.get_volume_idxs(); - for (unsigned int i : selection) + for (const GLVolume* v : m_volumes.volumes) { - const GLVolume* v = m_volumes.volumes[i]; int object_idx = v->object_idx(); if (object_idx >= 1000) continue; int instance_idx = v->instance_idx(); - // prevent rotating instances twice + // prevent scaling instances twice std::pair done_id(object_idx, instance_idx); if (done.find(done_id) != done.end()) continue; @@ -6463,6 +6476,12 @@ void GLCanvas3D::_on_scale() // schedule_background_process } + +void GLCanvas3D::_on_flatten() +{ + _on_rotate(); +} + #else void GLCanvas3D::_on_move(const std::vector& volume_idxs) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 8029ed4c4..e4019e2a1 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -118,8 +118,8 @@ wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); #if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); -#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); +#endif // !ENABLE_EXTENDED_SELECTION class GLCanvas3D @@ -946,6 +946,7 @@ private: void _on_move(); void _on_rotate(); void _on_scale(); + void _on_flatten(); #else void _on_move(const std::vector& volume_idxs); #endif // ENABLE_EXTENDED_SELECTION diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 88672f506..e01f57ff9 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1482,6 +1482,23 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const else ::glColor4f(0.9f, 0.9f, 0.9f, 0.5f); +#if ENABLE_EXTENDED_SELECTION + int instance_idx = selection.get_instance_idx(); + if ((instance_idx != -1) && (m_model_object != nullptr)) + { + Transform3d m = m_model_object->instances[instance_idx]->world_matrix(); + m.pretranslate(dragged_offset); + ::glPushMatrix(); + ::glMultMatrixd(m.data()); + ::glBegin(GL_POLYGON); + for (const Vec3d& vertex : m_planes[i].vertices) + { + ::glVertex3dv(vertex.data()); + } + ::glEnd(); + ::glPopMatrix(); + } +#else for (const InstanceData& inst : m_instances) { Transform3d m = inst.matrix; m.pretranslate(dragged_offset); @@ -1493,6 +1510,7 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const ::glEnd(); ::glPopMatrix(); } +#endif // ENABLE_EXTENDED_SELECTION } ::glDisable(GL_BLEND); @@ -1509,6 +1527,21 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const for (unsigned int i = 0; i < m_planes.size(); ++i) { ::glColor3f(1.0f, 1.0f, picking_color_component(i)); +#if ENABLE_EXTENDED_SELECTION + int instance_idx = selection.get_instance_idx(); + if ((instance_idx != -1) && (m_model_object != nullptr)) + { + ::glPushMatrix(); + ::glMultMatrixd(m_model_object->instances[instance_idx]->world_matrix().data()); + ::glBegin(GL_POLYGON); + for (const Vec3d& vertex : m_planes[i].vertices) + { + ::glVertex3dv(vertex.data()); + } + ::glEnd(); + ::glPopMatrix(); + } +#else for (const InstanceData& inst : m_instances) { ::glPushMatrix(); ::glMultMatrixd(inst.matrix.data()); @@ -1518,6 +1551,7 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const ::glEnd(); ::glPopMatrix(); } +#endif // ENABLE_EXTENDED_SELECTION } } @@ -1525,12 +1559,14 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) { m_model_object = model_object; +#if !ENABLE_EXTENDED_SELECTION // ...and save the updated positions of the object instances: if (m_model_object && !m_model_object->instances.empty()) { m_instances.clear(); for (const auto* instance : m_model_object->instances) m_instances.emplace_back(instance->world_matrix()); } +#endif // !ENABLE_EXTENDED_SELECTION if (is_plane_update_necessary()) update_planes(); diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 7c0196a83..cb0ef4f50 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -427,12 +427,14 @@ private: SourceDataSummary m_source_data; std::vector m_planes; +#if !ENABLE_EXTENDED_SELECTION struct InstanceData { Transform3d matrix; InstanceData(const Transform3d& matrix) : matrix(matrix) {} }; std::vector m_instances; +#endif // !ENABLE_EXTENDED_SELECTION Vec3d m_starting_center; const ModelObject* m_model_object = nullptr; From 561bbf5a804c24f3791c69cbaffc75fde578babb Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 16 Oct 2018 13:56:28 +0200 Subject: [PATCH 09/24] Fix build on non-MSVC --- src/slic3r/GUI/GUI_ObjectList.cpp | 2 +- src/slic3r/GUI/wxExtensions.cpp | 2 +- src/slic3r/GUI/wxExtensions.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 4d4de489e..743ac19b4 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1191,7 +1191,7 @@ void ObjectList::update_selections_on_canvas() return; } - auto add_to_selection = [this](wxDataViewItem& item, GLCanvas3D::Selection& selection, bool as_single_selection) + auto add_to_selection = [this](const wxDataViewItem& item, GLCanvas3D::Selection& selection, bool as_single_selection) { if (m_objects_model->GetParent(item) == wxDataViewItem(0)){ selection.add_object(m_objects_model->GetIdByItem(item), as_single_selection); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 9c9bcdaea..be3715641 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -607,7 +607,7 @@ wxDataViewItem PrusaObjectDataViewModel::GetItemByVolumeId(int obj_idx, int volu return wxDataViewItem(0); } -int PrusaObjectDataViewModel::GetIdByItem(wxDataViewItem& item) +int PrusaObjectDataViewModel::GetIdByItem(const wxDataViewItem& item) { wxASSERT(item.IsOk()); diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 43e5756a4..e199a1648 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -422,7 +422,7 @@ public: void DeleteChildren(wxDataViewItem& parent); wxDataViewItem GetItemById(int obj_idx); wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx); - int GetIdByItem(wxDataViewItem& item); + int GetIdByItem(const wxDataViewItem& item); int GetVolumeIdByItem(const wxDataViewItem& item); void GetObjectAndVolumeIdsByItem(const wxDataViewItem& item, int& obj_idx, int& vol_idx); bool IsEmpty() { return m_objects.empty(); } From af4570741c440ff47e3173a319947df2e6252344 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 16 Oct 2018 14:56:35 +0200 Subject: [PATCH 10/24] New selection -> Improved gizmos activation --- src/slic3r/GUI/GLCanvas3D.cpp | 34 ++++++++++++++++++++++++++-------- src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/GLGizmo.cpp | 7 ------- src/slic3r/GUI/GLGizmo.hpp | 18 +++++++++++++----- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 440ca5fc6..9ec8201d0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1893,7 +1893,7 @@ void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Vec2 float cnv_h = (float)canvas.get_canvas_size().get_height(); float height = _get_total_overlay_height(); float top_y = 0.5f * (cnv_h - height); - for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) + for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { if (it->second == nullptr) continue; @@ -1903,8 +1903,7 @@ void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Vec2 // we currently use circular icons for gizmo, so we check the radius #if ENABLE_EXTENDED_SELECTION - bool no_wipe_tower = selection.is_wipe_tower() && !it->second->get_accept_wipe_tower(); - if (!no_wipe_tower && (it->second->get_state() != GLGizmoBase::On)) + if (it->second->is_activable(selection) && (it->second->get_state() != GLGizmoBase::On)) #else if (it->second->get_state() != GLGizmoBase::On) #endif // ENABLE_EXTENDED_SELECTION @@ -1928,7 +1927,7 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec float cnv_h = (float)canvas.get_canvas_size().get_height(); float height = _get_total_overlay_height(); float top_y = 0.5f * (cnv_h - height); - for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) + for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { if (it->second == nullptr) continue; @@ -1938,18 +1937,17 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec // we currently use circular icons for gizmo, so we check the radius #if ENABLE_EXTENDED_SELECTION - bool no_wipe_tower = selection.is_wipe_tower() && !it->second->get_accept_wipe_tower(); - if (!no_wipe_tower && ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)) + if (it->second->is_activable(selection) && ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)) #else if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size) #endif // ENABLE_EXTENDED_SELECTION { if ((it->second->get_state() == GLGizmoBase::On)) { - it->second->set_state(GLGizmoBase::Off); + it->second->set_state(GLGizmoBase::Hover); m_current = Undefined; } - else + else if ((it->second->get_state() == GLGizmoBase::Hover)) { it->second->set_state(GLGizmoBase::On); m_current = it->first; @@ -1960,8 +1958,27 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec top_y += (tex_size + OverlayGapY); } + + GizmosMap::iterator it = m_gizmos.find(m_current); + if ((it != m_gizmos.end()) && (it->second != nullptr) && (it->second->get_state() != GLGizmoBase::On)) + it->second->set_state(GLGizmoBase::On); } +#if ENABLE_EXTENDED_SELECTION +void GLCanvas3D::Gizmos::update_on_off_state(const Selection& selection) +{ + GizmosMap::iterator it = m_gizmos.find(m_current); + if ((it != m_gizmos.end()) && (it->second != nullptr)) + { + if (!it->second->is_activable(selection)) + { + it->second->set_state(GLGizmoBase::Off); + m_current = Undefined; + } + } +} +#endif // ENABLE_EXTENDED_SELECTION + void GLCanvas3D::Gizmos::reset_all_states() { if (!m_enabled) @@ -3928,6 +3945,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else m_selection.add(m_hover_volume_id, !evt.ShiftDown()); + m_gizmos.update_on_off_state(m_selection); update_gizmos_data(); wxGetApp().obj_manipul()->update_settings_value(m_selection); m_dirty = true; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index e4019e2a1..70de0361a 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -552,6 +552,7 @@ private: #if ENABLE_EXTENDED_SELECTION void update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection); void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection); + void update_on_off_state(const Selection& selection); #else void update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos); void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index e01f57ff9..144301d2d 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -219,9 +219,6 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent) : m_parent(parent) , m_group_id(-1) , m_state(Off) -#if ENABLE_EXTENDED_SELECTION - , m_accept_wipe_tower(false) -#endif // ENABLE_EXTENDED_SELECTION , m_hover_id(-1) , m_dragging(false) { @@ -1216,10 +1213,6 @@ bool GLGizmoMove3D::on_init() m_grabbers.push_back(Grabber()); } -#if ENABLE_EXTENDED_SELECTION - m_accept_wipe_tower = true; -#endif // ENABLE_EXTENDED_SELECTION - return true; } diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index cb0ef4f50..1f2b77ab8 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -59,9 +59,6 @@ protected: int m_group_id; EState m_state; -#if ENABLE_EXTENDED_SELECTION - bool m_accept_wipe_tower; -#endif // ENABLE_EXTENDED_SELECTION // textures are assumed to be square and all with the same size in pixels, no internal check is done GLTexture m_textures[Num_States]; int m_hover_id; @@ -84,8 +81,7 @@ public: void set_state(EState state) { m_state = state; on_set_state(); } #if ENABLE_EXTENDED_SELECTION - bool get_accept_wipe_tower() { return m_accept_wipe_tower; } - void set_accept_wipe_tower(bool accept) { m_accept_wipe_tower = accept; } + bool is_activable(const GLCanvas3D::Selection& selection) const { return on_is_activable(selection); } #endif // ENABLE_EXTENDED_SELECTION unsigned int get_texture_id() const { return m_textures[m_state].get_id(); } @@ -125,6 +121,9 @@ protected: virtual bool on_init() = 0; virtual void on_set_state() {} virtual void on_set_hover_id() {} +#if ENABLE_EXTENDED_SELECTION + virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return true; } +#endif // ENABLE_EXTENDED_SELECTION virtual void on_enable_grabber(unsigned int id) {} virtual void on_disable_grabber(unsigned int id) {} #if ENABLE_EXTENDED_SELECTION @@ -249,6 +248,9 @@ protected: m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1); } } +#if ENABLE_EXTENDED_SELECTION + virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return !selection.is_wipe_tower(); } +#endif // ENABLE_EXTENDED_SELECTION virtual void on_enable_grabber(unsigned int id) { if ((0 <= id) && (id < 3)) @@ -327,6 +329,9 @@ public: protected: virtual bool on_init(); +#if ENABLE_EXTENDED_SELECTION + virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return !selection.is_wipe_tower(); } +#endif // ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION virtual void on_start_dragging(const GLCanvas3D::Selection& selection); #else @@ -449,6 +454,9 @@ public: protected: virtual bool on_init(); +#if ENABLE_EXTENDED_SELECTION + virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return selection.is_single_full_instance(); } +#endif // ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION virtual void on_start_dragging(const GLCanvas3D::Selection& selection); #else From b4a09d3d86bc12492452b4c732bc2060730acf25 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 16 Oct 2018 16:04:19 +0200 Subject: [PATCH 11/24] New selection -> Toolbar update --- src/slic3r/GUI/GLCanvas3D.cpp | 6 +++++- src/slic3r/GUI/GLCanvas3D.hpp | 5 ++++- src/slic3r/GUI/Plater.cpp | 40 +++++++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9ec8201d0..d41e59afe 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2661,7 +2661,11 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const } } +#if ENABLE_EXTENDED_SELECTION +wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); +#else wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); +#endif // ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); @@ -6551,7 +6555,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) void GLCanvas3D::_on_select(int volume_idx, int object_idx) { #if ENABLE_EXTENDED_SELECTION - post_event(ObjectSelectEvent(object_idx, -1)); + post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); #else int vol_id = -1; int obj_id = -1; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 70de0361a..c887f2c19 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -81,7 +81,9 @@ public: void set_bottom(float bottom); }; - +#if ENABLE_EXTENDED_SELECTION +wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); +#else struct ObjectSelectEvent; wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); struct ObjectSelectEvent : public ArrayEvent @@ -93,6 +95,7 @@ struct ObjectSelectEvent : public ArrayEvent ptrdiff_t object_id() const { return data[0]; } ptrdiff_t volume_id() const { return data[1]; } }; +#endif // ENABLE_EXTENDED_SELECTION using Vec2dEvent = Event; template using Vec2dsEvent = ArrayEvent; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f22b70074..f757c4bab 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -672,7 +672,6 @@ std::vector& Sidebar::combos_filament() return p->combos_filament; } - // Plater::Object struct PlaterObject @@ -801,7 +800,11 @@ struct Plater::priv void on_action_selectbyparts(SimpleEvent&); #endif // !ENABLE_EXTENDED_SELECTION +#if ENABLE_EXTENDED_SELECTION + void on_object_select(SimpleEvent&); +#else void on_object_select(ObjectSelectEvent&); +#endif // ENABLE_EXTENDED_SELECTION void on_viewport_changed(SimpleEvent&); void on_right_click(Vec2dEvent&); void on_model_update(SimpleEvent&); @@ -1253,17 +1256,27 @@ optional Plater::priv::selected_object() const void Plater::priv::selection_changed() { - // TODO +#if ENABLE_EXTENDED_SELECTION + const GUI::GLCanvas3D* canvas = _3DScene::get_canvas(this->canvas3D); + const GUI::GLCanvas3D::Selection& selection = canvas->get_selection(); + int obj_idx = selection.get_object_idx(); + bool have_sel = !selection.is_empty() && (0 <= obj_idx) && (obj_idx < 1000); +#else const auto obj_idx = selected_object(); const bool have_sel = !!obj_idx; +#endif // ENABLE_EXTENDED_SELECTION const bool layers_height_allowed = config->opt("variable_layer_height")->value; wxWindowUpdateLocker freeze_guard(sidebar); _3DScene::enable_toolbar_item(canvas3D, "delete", have_sel); _3DScene::enable_toolbar_item(canvas3D, "more", have_sel); +#if ENABLE_EXTENDED_SELECTION + _3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel && (model.objects[obj_idx]->instances.size() > 1)); +#else _3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel); +#endif // ENABLE_EXTENDED_SELECTION _3DScene::enable_toolbar_item(canvas3D, "split", have_sel); _3DScene::enable_toolbar_item(canvas3D, "cut", have_sel); _3DScene::enable_toolbar_item(canvas3D, "settings", have_sel); @@ -1272,18 +1285,14 @@ void Plater::priv::selection_changed() #if !ENABLE_EXTENDED_SELECTION bool can_select_by_parts = false; -#endif // !ENABLE_EXTENDED_SELECTION if (have_sel) { const auto *model_object = model.objects[*obj_idx]; -#if !ENABLE_EXTENDED_SELECTION // XXX: ? can_select_by_parts = *obj_idx < 1000 && model_object->volumes.size() > 1; -#endif // !ENABLE_EXTENDED_SELECTION _3DScene::enable_toolbar_item(canvas3D, "fewer", model_object->instances.size() > 1); } -#if !ENABLE_EXTENDED_SELECTION if (can_select_by_parts) { // first disable to let the item in the toolbar to switch to the unpressed state // XXX: ? _3DScene::enable_toolbar_item(canvas3D, "selectbyparts", false); @@ -1295,12 +1304,15 @@ void Plater::priv::selection_changed() #endif // !ENABLE_EXTENDED_SELECTION if (have_sel) { +#if ENABLE_EXTENDED_SELECTION + const ModelObject* model_object = model.objects[obj_idx]; +#else const auto *model_object = model.objects[*obj_idx]; +#endif // ENABLE_EXTENDED_SELECTION // FIXME print_info runs model fixing in two rounds, it is very slow, it should not be performed here! // # $model_object->print_info; - // my $model_instance = $model_object->instances->[0]; - const auto *model_instance = model_object->instances[0]; + const ModelInstance* model_instance = !model_object->instances.empty() ? model_object->instances.front() : nullptr; // TODO // $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size})); // $self->{object_info_materials}->SetLabel($model_object->materials_count); @@ -1611,6 +1623,14 @@ void Plater::priv::on_action_selectbyparts(SimpleEvent&) } #endif // !ENABLE_EXTENDED_SELECTION +#if ENABLE_EXTENDED_SELECTION +void Plater::priv::on_object_select(SimpleEvent& evt) +{ + selection_changed(); + item_changed_selection(); + wxGetApp().obj_list()->update_selections(); +} +#else void Plater::priv::on_object_select(ObjectSelectEvent &evt) { const auto obj_idx = evt.object_id(); @@ -1621,10 +1641,8 @@ void Plater::priv::on_object_select(ObjectSelectEvent &evt) select_object(obj_idx); item_changed_selection(); } -#if ENABLE_EXTENDED_SELECTION - wxGetApp().obj_list()->update_selections(); -#endif // ENABLE_EXTENDED_SELECTION } +#endif // ENABLE_EXTENDED_SELECTION void Plater::priv::on_viewport_changed(SimpleEvent& evt) { From 37a320c79e5542130f27f6a4befcff20df74d5be Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 16 Oct 2018 11:08:37 +0200 Subject: [PATCH 12/24] Changed logic of the PrusaObjectDataViewModelNode: now each node has: * name, * type, * id (-1, if type == itSettings OR itInstanceRoot), * bmp, * action_bmp * extruder --- src/slic3r/GUI/GUI_ObjectList.cpp | 101 ++++++++++++++++++++---------- src/slic3r/GUI/GUI_ObjectList.hpp | 9 +-- src/slic3r/GUI/Plater.cpp | 1 + src/slic3r/GUI/wxExtensions.cpp | 79 +++++++++++++---------- src/slic3r/GUI/wxExtensions.hpp | 89 ++++++++++++++------------ 5 files changed, 169 insertions(+), 110 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 4d4de489e..14773b593 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -58,7 +58,7 @@ ObjectList::ObjectList(wxWindow* parent) : Bind(wxEVT_CHOICE, [this](wxCommandEvent& event) { update_extruder_in_config(event.GetString()); }); GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) { - set_tooltip_for_item(event.GetPosition()); + set_tooltip_for_item(/*event.GetPosition()*/get_mouse_position_in_control()); event.Skip(); }); #else @@ -118,7 +118,7 @@ void ObjectList::set_tooltip_for_item(const wxPoint& pt) if (col->GetTitle() == " " && GetSelectedItemsCount()<2) GetMainWindow()->SetToolTip(_(L("Right button click the icon to change the object settings"))); else if (col->GetTitle() == _("Name") && - m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) { + m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.GetRefData()) { int obj_idx = m_objects_model->GetIdByItem(item); auto& stats = (*m_objects)[obj_idx]->volumes[0]->mesh.stl.stats; int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed + @@ -214,11 +214,11 @@ void ObjectList::update_extruder_in_config(const wxString& selection) } void ObjectList::init_icons(){ - m_icon_modifiermesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG); - m_icon_solidmesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG); + m_bmp_modifiermesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG); + m_bmp_solidmesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG); // init icon for manifold warning - m_icon_manifold_warning = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); + m_bmp_manifold_warning = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); // init bitmap for "Split to sub-objects" context menu m_bmp_split = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("split.png")), wxBITMAP_TYPE_PNG); @@ -268,7 +268,7 @@ void ObjectList::context_menu() show_context_menu(); else if (title == _("Name") && pt.x >15 && - m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) + m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.GetRefData()) { if (is_windows10()) /*fix_through_netfabb()*/;// #ys_FIXME @@ -325,14 +325,20 @@ void ObjectList::item_value_change(wxDataViewEvent& event) } } +struct draging_item_data +{ + int obj_idx; + int vol_idx; +}; + void ObjectList::on_begin_drag(wxDataViewEvent &event) { wxDataViewItem item(event.GetItem()); // only allow drags for item, not containers if (multiple_selection() || - m_objects_model->GetParent(item) == wxDataViewItem(0) || - m_objects_model->IsSettingsItem(item) ) { + m_objects_model->GetParent(item) == wxDataViewItem(0) || + m_objects_model->GetItemType(item) != itVolume ) { event.Veto(); return; } @@ -356,7 +362,7 @@ void ObjectList::on_drop_possible(wxDataViewEvent &event) // only allow drags for item or background, not containers if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || - event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) + event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume) event.Veto(); } @@ -366,7 +372,7 @@ void ObjectList::on_drop(wxDataViewEvent &event) // only allow drops for item, not containers if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || - event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) { + event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume) { event.Veto(); return; } @@ -495,7 +501,7 @@ void ObjectList::get_settings_choice(wxMenu *menu, int id, bool is_part) // Add settings item for object const auto item = GetSelection(); if (item) { - const auto settings_item = m_objects_model->HasSettings(item); + const auto settings_item = m_objects_model->GetSettingsItem(item); select_item(settings_item ? settings_item : m_objects_model->AddSettingsChild(item)); #ifndef __WXOSX__ @@ -547,7 +553,7 @@ wxMenu* ObjectList::create_add_part_popupmenu() int i = 0; for (auto& item : menu_items) { auto menu_item = new wxMenuItem(menu, config_id_base + i, _(item)); - menu_item->SetBitmap(i == 0 ? m_icon_solidmesh : m_icon_modifiermesh); + menu_item->SetBitmap(i == 0 ? m_bmp_solidmesh : m_bmp_modifiermesh); if (item == "Add generic") menu_item_add_generic(menu_item, config_id_base + i); menu->Append(menu_item); @@ -667,7 +673,7 @@ void ObjectList::load_subobject(bool is_modifier /*= false*/, bool is_lambda/* = for (int i = 0; i < part_names.size(); ++i) { const wxDataViewItem sel_item = m_objects_model->AddChild(item, part_names.Item(i), - is_modifier ? m_icon_modifiermesh : m_icon_solidmesh); + is_modifier ? m_bmp_modifiermesh : m_bmp_solidmesh); if (i == part_names.size() - 1) select_item(sel_item); @@ -817,7 +823,7 @@ void ObjectList::load_lambda(const std::string& type_name) parts_changed(m_selected_object_id); select_item(m_objects_model->AddChild(GetSelection(), - name, m_icon_modifiermesh)); + name, m_bmp_modifiermesh)); #ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME selection_changed(); #endif //no __WXOSX__ //__WXMSW__ @@ -830,15 +836,20 @@ void ObjectList::del_subobject_item(wxDataViewItem& item) { if (!item) return; - int obj_idx, vol_idx; - m_objects_model->GetObjectAndVolumeIdsByItem(item, obj_idx, vol_idx); + int obj_idx, idx; + ItemType type; - if (vol_idx == -1) + m_objects_model->GetItemInfo(item, type, obj_idx, idx); + if (type == itUndef) return; - if (vol_idx == -2) + if (type == itSettings) del_settings_from_config(); - else if (!del_subobject_from_object(obj_idx, vol_idx)) + else if (type == itInstanceRoot && obj_idx != -1) + del_instances_from_object(obj_idx); + else if (idx == -1) + return; + else if (!del_subobject_from_object(obj_idx, idx, type)) return; m_objects_model->Delete(item); @@ -859,21 +870,43 @@ void ObjectList::del_settings_from_config() m_config->set_key_value("extruder", new ConfigOptionInt(extruder)); } -bool ObjectList::del_subobject_from_object(const int obj_idx, const int vol_idx) +void ObjectList::del_instances_from_object(const int obj_idx) { - const auto volume = (*m_objects)[obj_idx]->volumes[vol_idx]; + auto instances = (*m_objects)[obj_idx]->instances; + if (instances.size() <= 1) + return; - // if user is deleting the last solid part, throw error - int solid_cnt = 0; - for (auto vol : (*m_objects)[obj_idx]->volumes) - if (vol->is_model_part()) - ++solid_cnt; - if (volume->is_model_part() && solid_cnt == 1) { - Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object."))); - return false; + while ( instances.size()> 1) + instances.pop_back(); + + (*m_objects)[obj_idx]->invalidate_bounding_box(); // ? #ys_FIXME + + m_parts_changed = true; + parts_changed(obj_idx); +} + +bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, const int type) +{ + if (type == itVolume) { + const auto volume = (*m_objects)[obj_idx]->volumes[idx]; + + // if user is deleting the last solid part, throw error + int solid_cnt = 0; + for (auto vol : (*m_objects)[obj_idx]->volumes) + if (vol->is_model_part()) + ++solid_cnt; + if (volume->is_model_part() && solid_cnt == 1) { + Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object."))); + return false; + } + + (*m_objects)[obj_idx]->delete_volume(idx); } + else if (type == itInstance) + (*m_objects)[obj_idx]->delete_instance(idx); + else + return false; - (*m_objects)[obj_idx]->delete_volume(vol_idx); m_parts_changed = true; parts_changed(obj_idx); @@ -902,7 +935,7 @@ void ObjectList::split(const bool split_part) for (auto id = 0; id < model_object->volumes.size(); id++) m_objects_model->AddChild(parent, model_object->volumes[id]->name, - model_object->volumes[id]->is_modifier() ? m_icon_modifiermesh : m_icon_solidmesh, + model_object->volumes[id]->is_modifier() ? m_bmp_modifiermesh : m_bmp_solidmesh, model_object->volumes[id]->config.has("extruder") ? model_object->volumes[id]->config.option("extruder")->value : 0, false); @@ -912,7 +945,7 @@ void ObjectList::split(const bool split_part) else { for (auto id = 0; id < model_object->volumes.size(); id++) m_objects_model->AddChild(item, model_object->volumes[id]->name, - m_icon_solidmesh, + m_bmp_solidmesh, model_object->volumes[id]->config.has("extruder") ? model_object->volumes[id]->config.option("extruder")->value : 0, false); @@ -1049,7 +1082,7 @@ void ObjectList::add_object_to_list(size_t obj_idx) stats.facets_added + stats.facets_reversed + stats.backwards_edges; if (errors > 0) { wxVariant variant; - variant << PrusaDataViewBitmapText(item_name, m_icon_manifold_warning); + variant << PrusaDataViewBitmapText(item_name, m_bmp_manifold_warning); m_objects_model->SetValue(variant, item, 0); } @@ -1057,7 +1090,7 @@ void ObjectList::add_object_to_list(size_t obj_idx) for (auto id = 0; id < model_object->volumes.size(); id++) m_objects_model->AddChild(item, model_object->volumes[id]->name, - m_icon_solidmesh, + m_bmp_solidmesh, model_object->volumes[id]->config.option("extruder")->value, false); Expand(item); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 21b4a729f..418e1e877 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -22,9 +22,9 @@ class ObjectList : public wxDataViewCtrl DynamicPrintConfig *m_default_config {nullptr}; - wxBitmap m_icon_modifiermesh; - wxBitmap m_icon_solidmesh; - wxBitmap m_icon_manifold_warning; + wxBitmap m_bmp_modifiermesh; + wxBitmap m_bmp_solidmesh; + wxBitmap m_bmp_manifold_warning; wxBitmap m_bmp_cog; wxBitmap m_bmp_split; @@ -87,7 +87,8 @@ public: void load_lambda(const std::string& type_name); void del_subobject_item(wxDataViewItem& item); void del_settings_from_config(); - bool del_subobject_from_object(const int obj_idx, const int vol_idx); + void del_instances_from_object(const int obj_idx); + bool del_subobject_from_object(const int obj_idx, const int idx, const int type); void split(const bool split_part); bool get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume); bool is_splittable_object(const bool split_part); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f22b70074..9f0cdc89b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2019,6 +2019,7 @@ void Plater::changed_object_settings(int obj_idx) _3DScene::set_objects_selections(p->canvas3D, selections); #endif // !ENABLE_EXTENDED_SELECTION _3DScene::reload_scene(p->canvas3D, false); + _3DScene::zoom_to_volumes(p->canvas3D); } else { // schedule_background_process(); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 9c9bcdaea..4b57540c2 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -362,12 +362,13 @@ void PrusaObjectDataViewModelNode::set_part_action_icon() { Slic3r::GUI::BitmapCache *m_bitmap_cache = nullptr; bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector& categories) { - if (m_type != "settings" || m_opt_categories == categories) + if (m_type != itSettings || m_opt_categories == categories) return false; m_opt_categories = categories; m_name = wxEmptyString; - m_icon = m_empty_icon; +// m_icon = m_empty_icon; + m_bmp = m_empty_bmp; std::map& categories_icon = Slic3r::GUI::wxGetApp().obj_list()->CATEGORY_ICON;//Slic3r::GUI::get_category_icon(); @@ -440,7 +441,7 @@ wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_ const wxString extruder_str = extruder == 0 ? "default" : wxString::Format("%d", extruder); if (create_frst_child && (root->GetChildren().Count() == 0 || - (root->GetChildren().Count() == 1 && root->GetNthChild(0)->m_type == "settings"))) + (root->GetChildren().Count() == 1 && root->GetNthChild(0)->m_type == itSettings))) { const auto icon_solid_mesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG); const auto node = new PrusaObjectDataViewModelNode(root, root->m_name, icon_solid_mesh, extruder_str, 0); @@ -450,7 +451,7 @@ wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_ ItemAdded(parent_item, child); } - const auto volume_id = root->GetChildCount() > 0 && root->GetNthChild(0)->m_type == "settings" ? + const auto volume_id = root->GetChildCount() > 0 && root->GetNthChild(0)->m_type == itSettings ? root->GetChildCount() - 1 : root->GetChildCount(); const auto node = new PrusaObjectDataViewModelNode(root, name, icon, extruder_str, volume_id); @@ -489,20 +490,20 @@ wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item) // thus removing the node from it doesn't result in freeing it if (node_parent){ auto id = node_parent->GetChildren().Index(node); - auto v_id = node->GetVolumeId(); + auto idx = node->GetIdx(); node_parent->GetChildren().Remove(node); if (id > 0){ if(id == node_parent->GetChildCount()) id--; ret_item = wxDataViewItem(node_parent->GetChildren().Item(id)); } - //update volume_id value for remaining child-nodes + //update idx value for remaining child-nodes auto children = node_parent->GetChildren(); - for (size_t i = 0; i < node_parent->GetChildCount() && v_id>=0; i++) + for (size_t i = 0; i < node_parent->GetChildCount() && idx>=0; i++) { - auto volume_id = children[i]->GetVolumeId(); - if (volume_id > v_id) - children[i]->SetVolumeId(volume_id-1); + auto cur_idx = children[i]->GetIdx(); + if (cur_idx > idx) + children[i]->SetIdx(cur_idx-1); } } else @@ -592,7 +593,7 @@ wxDataViewItem PrusaObjectDataViewModel::GetItemByVolumeId(int obj_idx, int volu auto parent = m_objects[obj_idx]; if (parent->GetChildCount() == 0 || - (parent->GetChildCount() == 1 && parent->GetNthChild(0)->m_volume_id == -2)) { + (parent->GetChildCount() == 1 && parent->GetNthChild(0)->GetType() & itSettings )) { if (volume_idx == 0) return GetItemById(obj_idx); @@ -601,13 +602,13 @@ wxDataViewItem PrusaObjectDataViewModel::GetItemByVolumeId(int obj_idx, int volu } for (size_t i = 0; i < parent->GetChildCount(); i++) - if (parent->GetNthChild(i)->m_volume_id == volume_idx) + if (parent->GetNthChild(i)->m_idx == volume_idx && parent->GetNthChild(0)->GetType() & itVolume) return wxDataViewItem(parent->GetNthChild(i)); return wxDataViewItem(0); } -int PrusaObjectDataViewModel::GetIdByItem(wxDataViewItem& item) +int PrusaObjectDataViewModel::GetIdByItem(const wxDataViewItem& item) { wxASSERT(item.IsOk()); @@ -624,22 +625,27 @@ int PrusaObjectDataViewModel::GetVolumeIdByItem(const wxDataViewItem& item) wxASSERT(item.IsOk()); PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - if (!node) // happens if item.IsOk()==false + if (!node || node->m_type != itVolume) return -1; - return node->GetVolumeId(); + return node->GetIdx(); } -void PrusaObjectDataViewModel::GetObjectAndVolumeIdsByItem(const wxDataViewItem& item, int& obj_idx, int& vol_idx) +void PrusaObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx) { wxASSERT(item.IsOk()); - obj_idx = vol_idx = -1; + type = itUndef; PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); if (!node) return; - vol_idx = node->GetVolumeId(); + + type = node->GetType(); + idx = node->GetIdx(); PrusaObjectDataViewModelNode *parent_node = node->GetParent(); if (!parent_node) return; + if (type == itInstance) + parent_node = node->GetParent()->GetParent(); + if (!parent_node) return; auto it = find(m_objects.begin(), m_objects.end(), parent_node); if (it != m_objects.end()) @@ -664,11 +670,11 @@ wxString PrusaObjectDataViewModel::GetCopy(const wxDataViewItem &item) const return node->m_copy; } -wxIcon& PrusaObjectDataViewModel::GetIcon(const wxDataViewItem &item) const -{ - PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - return node->m_icon; -} +// wxIcon& PrusaObjectDataViewModel::GetIcon(const wxDataViewItem &item) const +// { +// PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); +// return node->m_icon; +// } wxBitmap& PrusaObjectDataViewModel::GetBitmap(const wxDataViewItem &item) const { @@ -715,7 +721,7 @@ bool PrusaObjectDataViewModel::SetValue(const wxVariant &variant, const int item return m_objects[item_idx]->SetValue(variant, col); } - +/* wxDataViewItem PrusaObjectDataViewModel::MoveChildUp(const wxDataViewItem &item) { auto ret_item = wxDataViewItem(0); @@ -763,7 +769,7 @@ wxDataViewItem PrusaObjectDataViewModel::MoveChildDown(const wxDataViewItem &ite ret_item = wxDataViewItem(node_parent->GetNthChild(node_parent->GetChildCount()-1)); return ret_item; } - +*/ wxDataViewItem PrusaObjectDataViewModel::ReorganizeChildren(int current_volume_id, int new_volume_id, const wxDataViewItem &parent) { auto ret_item = wxDataViewItem(0); @@ -774,14 +780,14 @@ wxDataViewItem PrusaObjectDataViewModel::ReorganizeChildren(int current_volume_i if (!node_parent) // happens if item.IsOk()==false return ret_item; - const size_t shift = node_parent->GetChildren().Item(0)->m_type == "settings" ? 1 : 0; + const size_t shift = node_parent->GetChildren().Item(0)->m_type == itSettings ? 1 : 0; PrusaObjectDataViewModelNode *deleted_node = node_parent->GetNthChild(current_volume_id+shift); node_parent->GetChildren().Remove(deleted_node); ItemDeleted(parent, wxDataViewItem(deleted_node)); node_parent->Insert(deleted_node, new_volume_id+shift); ItemAdded(parent, wxDataViewItem(deleted_node)); - const auto settings_item = HasSettings(wxDataViewItem(deleted_node)); + const auto settings_item = GetSettingsItem(wxDataViewItem(deleted_node)); if (settings_item) ItemAdded(wxDataViewItem(deleted_node), settings_item); @@ -790,7 +796,7 @@ wxDataViewItem PrusaObjectDataViewModel::ReorganizeChildren(int current_volume_i int id_frst = current_volume_id < new_volume_id ? current_volume_id : new_volume_id; int id_last = current_volume_id > new_volume_id ? current_volume_id : new_volume_id; for (int id = id_frst; id <= id_last; ++id) - children[id+shift]->SetVolumeId(id); + children[id+shift]->SetIdx(id); return wxDataViewItem(node_parent->GetNthChild(new_volume_id+shift)); } @@ -854,7 +860,15 @@ unsigned int PrusaObjectDataViewModel::GetChildren(const wxDataViewItem &parent, return count; } -wxDataViewItem PrusaObjectDataViewModel::HasSettings(const wxDataViewItem &item) const +ItemType PrusaObjectDataViewModel::GetItemType(const wxDataViewItem &item) const +{ + if (!item.IsOk()) + return itUndef; + PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); + return node->m_type; +} + +wxDataViewItem PrusaObjectDataViewModel::GetSettingsItem(const wxDataViewItem &item) const { if (!item.IsOk()) return wxDataViewItem(0); @@ -863,9 +877,8 @@ wxDataViewItem PrusaObjectDataViewModel::HasSettings(const wxDataViewItem &item) if (node->GetChildCount() == 0) return wxDataViewItem(0); - auto& children = node->GetChildren(); - if (children[0]->m_type == "settings") - return wxDataViewItem((void*)children[0]);; + if (node->GetNthChild(0)->m_type == itSettings) + return wxDataViewItem((void*)node->GetNthChild(0)); return wxDataViewItem(0); } @@ -875,7 +888,7 @@ bool PrusaObjectDataViewModel::IsSettingsItem(const wxDataViewItem &item) const if (!item.IsOk()) return false; PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - return node->m_type == "settings"; + return node->m_type == itSettings; } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 43e5756a4..f3c417426 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -194,6 +194,15 @@ DECLARE_VARIANT_OBJECT(PrusaDataViewBitmapText) // PrusaObjectDataViewModelNode: a node inside PrusaObjectDataViewModel // ---------------------------------------------------------------------------- +enum ItemType{ + itUndef, + itObject, + itVolume, + itInstanceRoot, + itInstance, + itSettings +}; + class PrusaObjectDataViewModelNode; WX_DEFINE_ARRAY_PTR(PrusaObjectDataViewModelNode*, MyObjectTreeModelNodePtrArray); @@ -201,7 +210,6 @@ class PrusaObjectDataViewModelNode { PrusaObjectDataViewModelNode* m_parent; MyObjectTreeModelNodePtrArray m_children; - wxIcon m_empty_icon; wxBitmap m_empty_bmp; std::vector< std::string > m_opt_categories; public: @@ -209,8 +217,7 @@ public: m_parent = NULL; m_name = name; m_copy = wxString::Format("%d", instances_count); - m_type = "object"; - m_volume_id = -1; + m_type = itObject; #ifdef __WXGTK__ // it's necessary on GTK because of control have to know if this item will be container // in another case you couldn't to add subitem for this item @@ -224,13 +231,13 @@ public: const wxString& sub_obj_name, const wxBitmap& bmp, const wxString& extruder, - const int volume_id=-1) { + const int idx = -1 ) { m_parent = parent; m_name = sub_obj_name; m_copy = wxEmptyString; m_bmp = bmp; - m_type = "volume"; - m_volume_id = volume_id; + m_type = itVolume; + m_idx = idx; m_extruder = extruder; #ifdef __WXGTK__ // it's necessary on GTK because of control have to know if this item will be container @@ -241,12 +248,23 @@ public: set_part_action_icon(); } - PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent) : + PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent, const ItemType type = itSettings) : m_parent(parent), - m_name("Settings to modified"), m_copy(wxEmptyString), - m_type("settings"), - m_extruder(wxEmptyString) {} + m_type(type), + m_extruder(wxEmptyString) + { + if (type == itSettings) { + m_name = "Settings to modified"; + } + else if (type == itInstanceRoot) { + m_name = "Instances"; + } + else if (type == itInstance) { + m_name = wxString::Format("Instances_%d", parent->GetChildCount() + 1); + m_idx = parent->GetChildCount(); + } + } ~PrusaObjectDataViewModelNode() { @@ -260,11 +278,10 @@ public: } wxString m_name; - wxIcon& m_icon = m_empty_icon; wxBitmap& m_bmp = m_empty_bmp; wxString m_copy; - std::string m_type; - int m_volume_id = -2; + ItemType m_type; + int m_idx = -1; bool m_container = false; wxString m_extruder = "default"; wxBitmap m_action_icon; @@ -341,28 +358,21 @@ public: } return false; } - void SetIcon(const wxIcon &icon) - { - m_icon = icon; - } void SetBitmap(const wxBitmap &icon) { m_bmp = icon; } - - void SetType(const std::string& type){ - m_type = type; - } - const std::string& GetType(){ - return m_type; - } - void SetVolumeId(const int& volume_id){ - m_volume_id = volume_id; + ItemType GetType() const { + return m_type; + } + + void SetIdx(const int& idx) { + m_idx = idx; } - const int& GetVolumeId(){ - return m_volume_id; + int GetIdx() const { + return m_idx; } // use this function only for childrens @@ -370,9 +380,10 @@ public: { // ! Don't overwrite other values because of equality of this values for all children -- m_name = from_node.m_name; - m_icon = from_node.m_icon; - m_volume_id = from_node.m_volume_id; - m_extruder = from_node.m_extruder; + m_bmp = from_node.m_bmp; + m_idx = from_node.m_idx; + m_extruder = from_node.m_extruder; + m_type = from_node.m_type; } bool SwapChildrens(int frst_id, int scnd_id) { @@ -384,8 +395,8 @@ public: PrusaObjectDataViewModelNode new_scnd = *GetNthChild(frst_id); PrusaObjectDataViewModelNode new_frst = *GetNthChild(scnd_id); - new_scnd.m_volume_id = m_children.Item(scnd_id)->m_volume_id; - new_frst.m_volume_id = m_children.Item(frst_id)->m_volume_id; + new_scnd.m_idx = m_children.Item(scnd_id)->m_idx; + new_frst.m_idx = m_children.Item(frst_id)->m_idx; m_children.Item(frst_id)->AssignAllVal(new_frst); m_children.Item(scnd_id)->AssignAllVal(new_scnd); @@ -422,16 +433,15 @@ public: void DeleteChildren(wxDataViewItem& parent); wxDataViewItem GetItemById(int obj_idx); wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx); - int GetIdByItem(wxDataViewItem& item); + int GetIdByItem(const wxDataViewItem& item); int GetVolumeIdByItem(const wxDataViewItem& item); - void GetObjectAndVolumeIdsByItem(const wxDataViewItem& item, int& obj_idx, int& vol_idx); + void GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx); bool IsEmpty() { return m_objects.empty(); } // helper method for wxLog wxString GetName(const wxDataViewItem &item) const; wxString GetCopy(const wxDataViewItem &item) const; - wxIcon& GetIcon(const wxDataViewItem &item) const; wxBitmap& GetBitmap(const wxDataViewItem &item) const; // helper methods to change the model @@ -445,8 +455,8 @@ public: const wxDataViewItem &item, unsigned int col) override; bool SetValue(const wxVariant &variant, const int item_idx, unsigned int col); - wxDataViewItem MoveChildUp(const wxDataViewItem &item); - wxDataViewItem MoveChildDown(const wxDataViewItem &item); +// wxDataViewItem MoveChildUp(const wxDataViewItem &item); +// wxDataViewItem MoveChildDown(const wxDataViewItem &item); // For parent move child from cur_volume_id place to new_volume_id // Remaining items will moved up/down accordingly wxDataViewItem ReorganizeChildren(int cur_volume_id, @@ -464,7 +474,8 @@ public: // In our case it is an item with all columns virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const override { return true; } - wxDataViewItem HasSettings(const wxDataViewItem &item) const; + ItemType GetItemType(const wxDataViewItem &item) const ; + wxDataViewItem GetSettingsItem(const wxDataViewItem &item) const; bool IsSettingsItem(const wxDataViewItem &item) const; void UpdateSettingsDigest(const wxDataViewItem &item, const std::vector& categories); }; From b8ec71ab28cb92283419331873899d136e4b9dd1 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 17 Oct 2018 09:30:07 +0200 Subject: [PATCH 13/24] New selection -> Removed old plater selection --- src/slic3r/GUI/Plater.cpp | 143 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 136 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f757c4bab..f52b58565 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -672,6 +672,7 @@ std::vector& Sidebar::combos_filament() return p->combos_filament; } +#if !ENABLE_EXTENDED_SELECTION // Plater::Object struct PlaterObject @@ -681,6 +682,7 @@ struct PlaterObject PlaterObject(std::string name) : name(std::move(name)), selected(false) {} }; +#endif // !ENABLE_EXTENDED_SELECTION // Plater::DropTarget @@ -730,7 +732,9 @@ struct Plater::priv Slic3r::Print print; Slic3r::Model model; Slic3r::GCodePreviewData gcode_preview_data; +#if !ENABLE_EXTENDED_SELECTION std::vector objects; +#endif // !ENABLE_EXTENDED_SELECTION fs::path export_gcode_output_file; fs::path send_gcode_file; @@ -761,9 +765,15 @@ struct Plater::priv std::vector load_model_objects(const ModelObjectPtrs &model_objects); std::unique_ptr get_export_file(GUI::FileType file_type); +#if ENABLE_EXTENDED_SELECTION + const GLCanvas3D::Selection& get_selection() const; + GLCanvas3D::Selection& get_selection(); + int get_selected_object_idx() const; +#else void select_object(optional obj_idx); void select_object_from_cpp(); optional selected_object() const; +#endif // ENABLE_EXTENDED_SELECTION void selection_changed(); void object_list_changed(); void select_view(); @@ -808,7 +818,9 @@ struct Plater::priv void on_viewport_changed(SimpleEvent&); void on_right_click(Vec2dEvent&); void on_model_update(SimpleEvent&); +#if !ENABLE_EXTENDED_SELECTION void on_scale_uniformly(SimpleEvent&); +#endif // !ENABLE_EXTENDED_SELECTION void on_wipetower_moved(Vec3dEvent&); void on_enable_action_buttons(Event&); void on_update_geometry(Vec3dsEvent<2>&); @@ -1114,12 +1126,19 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs &mode bool need_arrange = false; bool scaled_down = false; std::vector obj_idxs; +#if ENABLE_EXTENDED_SELECTION + unsigned int obj_count = 0; +#endif // ENABLE_EXTENDED_SELECTION for (ModelObject *model_object : model_objects) { auto *object = model.add_object(*model_object); std::string object_name = object->name.empty() ? fs::path(object->input_file).filename().string() : object->name; +#if ENABLE_EXTENDED_SELECTION + obj_idxs.push_back(obj_count++); +#else objects.emplace_back(std::move(object_name)); obj_idxs.push_back(objects.size() - 1); +#endif // ENABLE_EXTENDED_SELECTION if (model_object->instances.empty()) { // if object has no defined position(s) we need to rearrange everything after loading @@ -1227,6 +1246,23 @@ std::unique_ptr Plater::priv::get_export_file(GUI::FileType return dlg; } +#if ENABLE_EXTENDED_SELECTION +const GLCanvas3D::Selection& Plater::priv::get_selection() const +{ + return _3DScene::get_canvas(canvas3D)->get_selection(); +} + +GLCanvas3D::Selection& Plater::priv::get_selection() +{ + return _3DScene::get_canvas(canvas3D)->get_selection(); +} + +int Plater::priv::get_selected_object_idx() const +{ + int idx = get_selection().get_object_idx(); + return ((0 <= idx) && (idx < 1000)) ? idx : -1; +} +#else void Plater::priv::select_object(optional obj_idx) { for (auto &obj : objects) { @@ -1253,15 +1289,13 @@ optional Plater::priv::selected_object() const return boost::none; } +#endif // ENABLE_EXTENDED_SELECTION void Plater::priv::selection_changed() { #if ENABLE_EXTENDED_SELECTION - const GUI::GLCanvas3D* canvas = _3DScene::get_canvas(this->canvas3D); - const GUI::GLCanvas3D::Selection& selection = canvas->get_selection(); - - int obj_idx = selection.get_object_idx(); - bool have_sel = !selection.is_empty() && (0 <= obj_idx) && (obj_idx < 1000); + int obj_idx = get_selected_object_idx(); + bool have_sel = (obj_idx != -1); #else const auto obj_idx = selected_object(); const bool have_sel = !!obj_idx; @@ -1354,7 +1388,11 @@ void Plater::priv::selection_changed() void Plater::priv::object_list_changed() { // Enable/disable buttons depending on whether there are any objects on the platter. +#if ENABLE_EXTENDED_SELECTION + const bool have_objects = !model.objects.empty(); +#else const bool have_objects = !objects.empty(); +#endif // ENABLE_EXTENDED_SELECTION _3DScene::enable_toolbar_item(canvas3D, "deleteall", have_objects); _3DScene::enable_toolbar_item(canvas3D, "arrange", have_objects); @@ -1378,7 +1416,9 @@ void Plater::priv::remove(size_t obj_idx) // Prevent toolpaths preview from rendering while we modify the Print object preview->set_enabled(false); +#if !ENABLE_EXTENDED_SELECTION objects.erase(objects.begin() + obj_idx); +#endif // !ENABLE_EXTENDED_SELECTION model.delete_object(obj_idx); print.delete_object(obj_idx); // Delete object from Sidebar list @@ -1386,7 +1426,9 @@ void Plater::priv::remove(size_t obj_idx) object_list_changed(); +#if !ENABLE_EXTENDED_SELECTION select_object(boost::none); +#endif // !ENABLE_EXTENDED_SELECTION update(); } @@ -1397,7 +1439,9 @@ void Plater::priv::reset() // Prevent toolpaths preview from rendering while we modify the Print object preview->set_enabled(false); +#if !ENABLE_EXTENDED_SELECTION objects.clear(); +#endif // !ENABLE_EXTENDED_SELECTION model.clear_objects(); print.clear_objects(); @@ -1405,7 +1449,9 @@ void Plater::priv::reset() sidebar->obj_list()->delete_all_objects_from_list(); object_list_changed(); +#if !ENABLE_EXTENDED_SELECTION select_object(boost::none); +#endif // !ENABLE_EXTENDED_SELECTION update(); } @@ -1416,11 +1462,20 @@ void Plater::priv::rotate() void Plater::priv::mirror(const Axis &axis) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = get_selected_object_idx(); + if (obj_idx == -1) + return; + + ModelObject* model_object = model.objects[obj_idx]; + ModelInstance* model_instance = model_object->instances.front(); +#else const auto obj_idx = selected_object(); if (! obj_idx) { return; } auto *model_object = model.objects[*obj_idx]; auto *model_instance = model_object->instances[0]; +#endif // ENABLE_EXTENDED_SELECTION // XXX: ? // # apply Z rotation before mirroring @@ -1432,7 +1487,11 @@ void Plater::priv::mirror(const Axis &axis) model_object->mirror(axis); // $self->stop_background_process; // TODO +#if ENABLE_EXTENDED_SELECTION + print.add_model_object(model_object, obj_idx); +#else print.add_model_object(model_object, *obj_idx); +#endif // ENABLE_EXTENDED_SELECTION selection_changed(); update(); } @@ -1663,6 +1722,7 @@ void Plater::priv::on_model_update(SimpleEvent&) // TODO } +#if !ENABLE_EXTENDED_SELECTION void Plater::priv::on_scale_uniformly(SimpleEvent&) { // my ($scale) = @_; @@ -1697,6 +1757,7 @@ void Plater::priv::on_scale_uniformly(SimpleEvent&) // $self->update; // $self->schedule_background_process; } +#endif // !ENABLE_EXTENDED_SELECTION void Plater::priv::on_wipetower_moved(Vec3dEvent &evt) { @@ -1741,19 +1802,34 @@ void Plater::remove(size_t obj_idx) { p->remove(obj_idx); } void Plater::remove_selected() { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = p->get_selected_object_idx(); + if (obj_idx != -1) + remove((size_t)obj_idx); +#else const auto selected = p->selected_object(); if (selected) { remove(*selected); } +#endif // ENABLE_EXTENDED_SELECTION } void Plater::increase(size_t num) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = p->get_selected_object_idx(); + if (obj_idx == -1) + return; + + ModelObject* model_object = p->model.objects[obj_idx]; + ModelInstance* model_instance = model_object->instances.back(); +#else const auto obj_idx = p->selected_object(); if (! obj_idx) { return; } auto *model_object = p->model.objects[*obj_idx]; auto *model_instance = model_object->instances[model_object->instances.size() - 1]; +#endif // ENABLE_EXTENDED_SELECTION // $self->stop_background_process; @@ -1761,10 +1837,18 @@ void Plater::increase(size_t num) for (size_t i = 0; i < num; i++, offset += 10.0) { Vec3d offset_vec = model_instance->get_offset() + Vec3d(offset, offset, 0.0); auto *new_instance = model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation()); +#if ENABLE_EXTENDED_SELECTION + p->print.get_object(obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); +#else p->print.get_object(*obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); +#endif // ENABLE_EXTENDED_SELECTION } +#if ENABLE_EXTENDED_SELECTION + sidebar().obj_list()->set_object_count(obj_idx, model_object->instances.size()); +#else sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); +#endif // ENABLE_EXTENDED_SELECTION if (p->get_config("autocenter") == "1") { p->arrange(); @@ -1779,18 +1863,39 @@ void Plater::increase(size_t num) void Plater::decrease(size_t num) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = p->get_selected_object_idx(); + if (obj_idx == -1) + return; + + ModelObject* model_object = p->model.objects[obj_idx]; +#else const auto obj_idx = p->selected_object(); if (! obj_idx) { return; } auto *model_object = p->model.objects[*obj_idx]; +#endif // ENABLE_EXTENDED_SELECTION if (model_object->instances.size() > num) { for (size_t i = 0; i < num; i++) { model_object->delete_last_instance(); +#if ENABLE_EXTENDED_SELECTION + p->print.get_object(obj_idx)->delete_last_copy(); +#else p->print.get_object(*obj_idx)->delete_last_copy(); +#endif // ENABLE_EXTENDED_SELECTION } +#if ENABLE_EXTENDED_SELECTION + sidebar().obj_list()->set_object_count(obj_idx, model_object->instances.size()); +#else sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); - } else { +#endif // ENABLE_EXTENDED_SELECTION + } + else { +#if ENABLE_EXTENDED_SELECTION + remove(obj_idx); +#else remove(*obj_idx); +#endif // ENABLE_EXTENDED_SELECTION } p->update(); @@ -1798,12 +1903,20 @@ void Plater::decrease(size_t num) void Plater::set_number_of_copies(size_t num) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = p->get_selected_object_idx(); + if (obj_idx == -1) + return; + + ModelObject* model_object = p->model.objects[obj_idx]; +#else const auto obj_idx = p->selected_object(); if (! obj_idx) { return; } auto *model_object = p->model.objects[*obj_idx]; +#endif // ENABLE_EXTENDED_SELECTION - auto diff = (ptrdiff_t)num - (ptrdiff_t)model_object->instances.size(); + int diff = (int)num - (int)model_object->instances.size(); if (diff > 0) { increase(diff); } else if (diff < 0) { @@ -1813,7 +1926,11 @@ void Plater::set_number_of_copies(size_t num) fs::path Plater::export_gcode(const fs::path &output_path) { +#if ENABLE_EXTENDED_SELECTION + if (p->model.objects.empty()) { return ""; } +#else if (p->objects.empty()) { return ""; } +#endif // ENABLE_EXTENDED_SELECTION if (! p->export_gcode_output_file.empty()) { GUI::show_error(this, _(L("Another export job is currently running."))); @@ -1866,7 +1983,11 @@ fs::path Plater::export_gcode(const fs::path &output_path) void Plater::export_stl() { +#if ENABLE_EXTENDED_SELECTION + if (p->model.objects.empty()) { return; } +#else if (p->objects.empty()) { return; } +#endif // ENABLE_EXTENDED_SELECTION auto dialog = p->get_export_file(FT_STL); if (! dialog) { return; } @@ -1881,7 +2002,11 @@ void Plater::export_stl() void Plater::export_amf() { +#if ENABLE_EXTENDED_SELECTION + if (p->model.objects.empty()) { return; } +#else if (p->objects.empty()) { return; } +#endif // ENABLE_EXTENDED_SELECTION auto dialog = p->get_export_file(FT_AMF); if (! dialog) { return; } @@ -1900,7 +2025,11 @@ void Plater::export_amf() void Plater::export_3mf() { +#if ENABLE_EXTENDED_SELECTION + if (p->model.objects.empty()) { return; } +#else if (p->objects.empty()) { return; } +#endif // ENABLE_EXTENDED_SELECTION auto dialog = p->get_export_file(FT_3MF); if (! dialog) { return; } From 3059438853cc75c6100a1a7b46c62a7e0eb3c95b Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 17 Oct 2018 09:40:04 +0200 Subject: [PATCH 14/24] Fixed toolbar update after reducing instances count --- src/slic3r/GUI/Plater.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f52b58565..cd0dc278d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1899,6 +1899,9 @@ void Plater::decrease(size_t num) } p->update(); + p->selection_changed(); + + // $self->schedule_background_process; } void Plater::set_number_of_copies(size_t num) From 7d1828df05e9f18cc988a6f4913a3e39b428f909 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 17 Oct 2018 12:17:25 +0200 Subject: [PATCH 15/24] Object context menu wip / Removed links to settings dialog from user interface / Fixed and unified append_menu_item() function / Fixed File->Open menu item / Fixed Window menu items / Added Plater menu --- src/slic3r/GUI/GLCanvas3D.cpp | 9 ++++ src/slic3r/GUI/GLCanvas3D.hpp | 2 + src/slic3r/GUI/GLToolbar.cpp | 2 + src/slic3r/GUI/GLToolbar.hpp | 2 + src/slic3r/GUI/GUI_App.cpp | 19 --------- src/slic3r/GUI/GUI_App.hpp | 9 +--- src/slic3r/GUI/MainFrame.cpp | 48 ++++----------------- src/slic3r/GUI/MainFrame.hpp | 11 +---- src/slic3r/GUI/Plater.cpp | 74 ++++++++++++++++++++++++++++----- src/slic3r/GUI/Plater.hpp | 2 + src/slic3r/GUI/wxExtensions.cpp | 14 +++++++ src/slic3r/GUI/wxExtensions.hpp | 3 ++ 12 files changed, 109 insertions(+), 86 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d41e59afe..f0568c5f0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2667,7 +2667,9 @@ wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent); #endif // ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDEFINE_EVENT(EVT_GLCANVAS_MODEL_UPDATE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); @@ -3439,6 +3441,9 @@ void GLCanvas3D::reload_scene(bool force) { load_object(*m_model, obj_idx); } + + // to update the toolbar + post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT)); } update_gizmos_data(); @@ -3796,8 +3801,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.position = Vec2d(-1.0, -1.0); m_dirty = true; } +#if !ENABLE_EXTENDED_SELECTION else if (evt.LeftDClick() && (m_hover_volume_id != -1) && !gizmos_overlay_contains_mouse && (toolbar_contains_mouse == -1)) post_event(SimpleEvent(EVT_GLCANVAS_DOUBLE_CLICK)); +#endif // !ENABLE_EXTENDED_SELECTION else if (evt.LeftDClick() && (toolbar_contains_mouse != -1)) { m_toolbar_action_running = true; @@ -4559,6 +4566,7 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.add_separator()) return false; +#if !ENABLE_EXTENDED_SELECTION item.name = "settings"; item.tooltip = GUI::L_str("Settings..."); item.sprite_id = 8; @@ -4566,6 +4574,7 @@ bool GLCanvas3D::_init_toolbar() item.action_event = EVT_GLTOOLBAR_SETTINGS; if (!m_toolbar.add_item(item)) return false; +#endif // !ENABLE_EXTENDED_SELECTION item.name = "layersediting"; item.tooltip = GUI::L_str("Layers editing"); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index c887f2c19..be9548a49 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -105,7 +105,9 @@ template using Vec3dsEvent = ArrayEvent; wxDECLARE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent); wxDECLARE_EVENT(EVT_GLCANVAS_MODEL_UPDATE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 479238368..ec203541e 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -24,7 +24,9 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_MORE, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_SPLIT, SimpleEvent); wxDEFINE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent); #if !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent); diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index dc4d10f37..7c0f5bf84 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -24,7 +24,9 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_MORE, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT, SimpleEvent); wxDECLARE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent); +#if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent); +#endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent); #if !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a01825d2b..fd4559a35 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -326,25 +326,6 @@ void GUI_App::CallAfter(std::function cb) callback_register.unlock(); } -wxMenuItem* GUI_App::append_menu_item( wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - const std::string& icon, - std::function cb, - wxItemKind kind/* = wxITEM_NORMAL*/) -{ - if (id == wxID_ANY) - id = wxNewId(); - auto item = new wxMenuItem(menu, id, string, description, kind); - if (!icon.empty()) - item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); - menu->Append(item); - - menu->Bind(wxEVT_MENU, /*[cb](wxCommandEvent& event){cb; }*/cb); - return item; -} - wxMenuItem* GUI_App::append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 4578f4c00..ff910ed42 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -107,14 +107,7 @@ public: // void notify(/*message*/); void update_ui_from_settings(); void CallAfter(std::function cb); - wxMenuItem* append_menu_item( wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - const std::string& icon, - std::function cb, - wxItemKind kind = wxITEM_NORMAL); - wxMenuItem* append_submenu( wxMenu* menu, + wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxString& string, diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 505a45125..767f629fd 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -17,6 +17,7 @@ #include "Print.hpp" #include "Polygon.hpp" #include "AppConfig.hpp" +#include "wxExtensions.hpp" #include #include "GUI_App.hpp" @@ -237,10 +238,8 @@ void MainFrame::init_menubar() // File menu wxMenu* fileMenu = new wxMenu; { - wxGetApp().append_menu_item(fileMenu, wxID_ANY, _(L("Open STL/OBJ/AMF/3MFā€¦\tCtrl+O")), _(L("Open a model")), - "", [](wxCommandEvent&){ -// if (m_plater) m_plater->add(); - }); //'brick_add.png'); + append_menu_item(fileMenu, wxID_ANY, _(L("Open STL/OBJ/AMF/3MFā€¦\tCtrl+O")), _(L("Open a model")), + [this](wxCommandEvent&) { if (m_plater) m_plater->add(); }, "brick_add.png"); append_menu_item(fileMenu, wxID_ANY, _(L("&Load Configā€¦\tCtrl+L")), _(L("Load exported configuration file")), [this](wxCommandEvent&){ load_config_file(); }, "plugin_add.png"); append_menu_item(fileMenu, wxID_ANY, _(L("&Export Configā€¦\tCtrl+E")), _(L("Export current configuration to file")), @@ -285,19 +284,16 @@ void MainFrame::init_menubar() } // Plater menu - if(m_plater) { - auto plater_menu = new wxMenu(); - append_menu_item(plater_menu, wxID_ANY, L("Export G-code..."), L("Export current plate as G-code"), + if (m_plater) { + m_plater_menu = new wxMenu(); + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export G-code...")), _(L("Export current plate as G-code")), [this](wxCommandEvent&){ /*m_plater->export_gcode(); */}, "cog_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as STL..."), L("Export current plate as STL"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as STL...")), _(L("Export current plate as STL")), [this](wxCommandEvent&){ /*m_plater->export_stl(); */}, "brick_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as AMF..."), L("Export current plate as AMF"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as AMF...")), _(L("Export current plate as AMF")), [this](wxCommandEvent&){ /*m_plater->export_amf();*/ }, "brick_go.png"); - append_menu_item(plater_menu, wxID_ANY, L("Export plate as 3MF..."), L("Export current plate as 3MF"), + append_menu_item(m_plater_menu, wxID_ANY, _(L("Export plate as 3MF...")), _(L("Export current plate as 3MF")), [this](wxCommandEvent&){ /*m_plater->export_3mf(); */}, "brick_go.png"); - -// m_object_menu = m_plater->object_menu; - on_plater_selection_changed(false); } // Window menu @@ -375,7 +371,6 @@ void MainFrame::init_menubar() auto menubar = new wxMenuBar(); menubar->Append(fileMenu, L("&File")); if (m_plater_menu) menubar->Append(m_plater_menu, L("&Plater")) ; - if (m_object_menu) menubar->Append(m_object_menu, L("&Object")) ; menubar->Append(windowMenu, L("&Window")); if (m_viewMenu) menubar->Append(m_viewMenu, L("&View")); // Add additional menus from C++ @@ -385,15 +380,6 @@ void MainFrame::init_menubar() } } -// Selection of a 3D object changed on the platter. -void MainFrame::on_plater_selection_changed(const bool have_selection) -{ - if (!m_object_menu) return; - - for (auto item : m_object_menu->GetMenuItems()) - m_object_menu->Enable(item->GetId(), have_selection); -} - void MainFrame::slice_to_png(){ // m_plater->stop_background_process(); // m_plater->async_apply_config(); @@ -702,22 +688,6 @@ void MainFrame::select_view(const std::string& direction){ // m_plater->select_view(direction); } -wxMenuItem* MainFrame::append_menu_item(wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - std::function cb, - const std::string& icon /*= ""*/) -{ - if (id == wxID_ANY) - id = wxNewId(); - auto item = menu->Append(id, string, description); - if (!icon.empty()) - item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); - menu->Bind(wxEVT_MENU, /*[cb](wxCommandEvent& event){cb; }*/cb); - return item; -} - void MainFrame::on_presets_changed(SimpleEvent &event) { auto *tab = dynamic_cast(event.GetEventObject()); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index ed2646b69..1015e783c 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -57,17 +57,9 @@ class MainFrame : public wxFrame AppController* m_appController { nullptr }; std::map m_options_tabs; - wxMenuItem* append_menu_item(wxMenu* menu, - int id, - const wxString& string, - const wxString& description, - std::function cb, - const std::string& icon = ""); - wxMenuItem* m_menu_item_reslice_now { nullptr }; wxMenu* m_plater_menu { nullptr }; - wxMenu* m_object_menu { nullptr }; - wxMenu* m_viewMenu { nullptr }; + wxMenu* m_viewMenu{ nullptr }; std::string get_base_name(const wxString full_name) const ; std::string get_dir_name(const wxString full_name) const ; @@ -93,7 +85,6 @@ public: bool is_loaded() const { return m_loaded; } bool is_last_input_file() const { return !m_qs_last_input_file.IsEmpty(); } - void on_plater_selection_changed(const bool have_selection); void slice_to_png(); void quick_slice(const int qs = qsUndef); void reslice_now(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index cd0dc278d..f6e3983d9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -37,6 +37,7 @@ #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" #include "GUI_Utils.hpp" +#include "wxExtensions.hpp" #include "MainFrame.hpp" #include "3DScene.hpp" #include "GLCanvas3D.hpp" @@ -727,6 +728,9 @@ struct Plater::priv Plater *q; MainFrame *main_frame; + // Object popup menu + wxMenu* object_menu; + // Data Slic3r::DynamicPrintConfig *config; Slic3r::Print print; @@ -751,6 +755,7 @@ struct Plater::priv static const std::regex pattern_zip_amf; priv(Plater *q, MainFrame *main_frame); + ~priv(); #if !ENABLE_EXTENDED_SELECTION std::vector collect_selections(); @@ -804,7 +809,9 @@ struct Plater::priv void on_action_add(SimpleEvent&); void on_action_split(SimpleEvent&); void on_action_cut(SimpleEvent&); +#if !ENABLE_EXTENDED_SELECTION void on_action_settings(SimpleEvent&); +#endif // !ENABLE_EXTENDED_SELECTION void on_action_layersediting(SimpleEvent&); #if !ENABLE_EXTENDED_SELECTION void on_action_selectbyparts(SimpleEvent&); @@ -824,6 +831,9 @@ struct Plater::priv void on_wipetower_moved(Vec3dEvent&); void on_enable_action_buttons(Event&); void on_update_geometry(Vec3dsEvent<2>&); + +private: + bool init_object_menu(); }; const std::regex Plater::priv::pattern_bundle("[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)$", std::regex::icase); @@ -833,6 +843,7 @@ const std::regex Plater::priv::pattern_zip_amf("[.]zip[.]amf$", std::regex::icas Plater::priv::priv(Plater *q, MainFrame *main_frame) : q(q), main_frame(main_frame), + object_menu(nullptr), config(Slic3r::DynamicPrintConfig::new_from_defaults_keys({ "bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", "brim_width", "variable_layer_height", "serial_port", "serial_speed", "host_type", "print_host", @@ -892,6 +903,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : hsizer->Add(sidebar, 0, wxEXPAND | wxLEFT | wxRIGHT, 0); q->SetSizer(hsizer); + init_object_menu(); + // Events: // Notebook page change event @@ -903,7 +916,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : // 3DScene events: canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this); canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this); - // canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) { }); // XXX: remove? +#if !ENABLE_EXTENDED_SELECTION + canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) {}); // XXX: remove? +#endif // !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this); canvas3D->Bind(EVT_GLCANVAS_MODEL_UPDATE, &priv::on_model_update, this); canvas3D->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); }); @@ -924,7 +939,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : canvas3D->Bind(EVT_GLTOOLBAR_FEWER, [q](SimpleEvent&) { q->decrease(); }); canvas3D->Bind(EVT_GLTOOLBAR_SPLIT, &priv::on_action_split, this); canvas3D->Bind(EVT_GLTOOLBAR_CUT, &priv::on_action_cut, this); +#if !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_SETTINGS, &priv::on_action_settings, this); +#endif // !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); #if !ENABLE_EXTENDED_SELECTION canvas3D->Bind(EVT_GLTOOLBAR_SELECTBYPARTS, &priv::on_action_selectbyparts, this); @@ -943,6 +960,12 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : q->Layout(); } +Plater::priv::~priv() +{ + if (object_menu != nullptr) + delete object_menu; +} + #if !ENABLE_EXTENDED_SELECTION std::vector Plater::priv::collect_selections() { @@ -1645,14 +1668,8 @@ void Plater::priv::on_layer_editing_toggled(bool enable) void Plater::priv::on_action_add(SimpleEvent&) { - wxArrayString input_files; - wxGetApp().open_model(q, input_files); - - std::vector input_paths; - for (const auto &file : input_files) { - input_paths.push_back(file.wx_str()); - } - load_files(input_paths); + if (q != nullptr) + q->add(); } void Plater::priv::on_action_split(SimpleEvent&) @@ -1665,10 +1682,12 @@ void Plater::priv::on_action_cut(SimpleEvent&) // TODO } +#if !ENABLE_EXTENDED_SELECTION void Plater::priv::on_action_settings(SimpleEvent&) { // TODO } +#endif // !ENABLE_EXTENDED_SELECTION void Plater::priv::on_action_layersediting(SimpleEvent&) { @@ -1712,9 +1731,18 @@ void Plater::priv::on_viewport_changed(SimpleEvent& evt) preview->set_viewport_from_scene(canvas3D); } -void Plater::priv::on_right_click(Vec2dEvent&) +void Plater::priv::on_right_click(Vec2dEvent& evt) { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = get_selected_object_idx(); + if (obj_idx == -1) + return; + + if ((q != nullptr) && (object_menu != nullptr)) + q->PopupMenu(object_menu, (int)evt.data.x(), (int)evt.data.y()); +#else // TODO +#endif // ENABLE_EXTENDED_SELECTION } void Plater::priv::on_model_update(SimpleEvent&) @@ -1777,6 +1805,20 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&) // TODO } +bool Plater::priv::init_object_menu() +{ + if (main_frame == nullptr) + return false; + + object_menu = new wxMenu(); + if (object_menu == nullptr) + return false; + + append_menu_item(object_menu, wxID_ANY, _(L("Deleteā€¦\tDel")), _(L("Remove the selected object")), + [this](wxCommandEvent&){ q->remove_selected(); }, "brick_delete.png"); + + return true; +} // Plater / Public @@ -1795,6 +1837,18 @@ Sidebar& Plater::sidebar() { return *p->sidebar; } Model& Plater::model() { return p->model; } Print& Plater::print() { return p->print; } +void Plater::add() +{ + wxArrayString input_files; + wxGetApp().open_model(this, input_files); + + std::vector input_paths; + for (const auto &file : input_files) { + input_paths.push_back(file.wx_str()); + } + load_files(input_paths); +} + void Plater::load_files(const std::vector &input_files) { p->load_files(input_files); } void Plater::update(bool force_autocenter) { p->update(force_autocenter); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index fba2e0dc0..135dcfcde 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -104,6 +104,8 @@ public: Model& model(); Print& print(); + void add(); + void load_files(const std::vector &input_files); void update(bool force_autocenter = false); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index be3715641..4eaffe49f 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -10,6 +10,20 @@ #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" +wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description, + std::function cb, const std::string& icon) +{ + if (id == wxID_ANY) + id = wxNewId(); + + wxMenuItem* item = menu->Append(id, string, description); + if (!icon.empty()) + item->SetBitmap(wxBitmap(Slic3r::var(icon), wxBITMAP_TYPE_PNG)); + + menu->Bind(wxEVT_MENU, cb, id); + return item; +} + const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200; const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200; const unsigned int wxCheckListBoxComboPopup::DefaultItemHeight = 18; diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index e199a1648..07f56e643 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -13,6 +13,9 @@ #include #include +wxMenuItem* append_menu_item(wxMenu* menu, int id, const wxString& string, const wxString& description, + std::function cb, const std::string& icon = ""); + class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { static const unsigned int DefaultWidth; From 2e274b5646c938d76a3f3e9e7813cbc6aea5c884 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 17 Oct 2018 12:59:58 +0200 Subject: [PATCH 16/24] Plater -> View Menu --- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 32 ++++++++++++-------------------- src/slic3r/GUI/Plater.cpp | 17 +++++++++++++++++ src/slic3r/GUI/Plater.hpp | 2 ++ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f0568c5f0..813d10f7c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3204,7 +3204,7 @@ void GLCanvas3D::select_view(const std::string& direction) else if (direction == "rear") dir_vec = VIEW_REAR; - if ((dir_vec != nullptr) && !empty(volumes_bounding_box())) + if (dir_vec != nullptr) { m_camera.phi = dir_vec[0]; m_camera.set_theta(dir_vec[1]); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 767f629fd..67f01ad42 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -319,23 +319,14 @@ void MainFrame::init_menubar() // View menu if (m_plater) { m_viewMenu = new wxMenu(); -// \xA0 is a non-breaing space. It is entered here to spoil the automatic accelerators, - // as the simple numeric accelerators spoil all numeric data entry. - // The camera control accelerators are captured by 3DScene Perl module instead. - auto accel = [](const wxString& st1, const wxString& st2) { -// if ($^O eq "MSWin32") -// return st1 + "\t\xA0" + st2; -// else - return st1; - }; - - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Iso")), "0"), L("Iso View"), [this](wxCommandEvent&){ select_view("iso"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Top")), "1"), L("Top View"), [this](wxCommandEvent&){ select_view("top"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Bottom")), "2"), L("Bottom View"),[this](wxCommandEvent&){ select_view("bottom"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Front")), "3"), L("Front View"), [this](wxCommandEvent&){ select_view("front"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Rear")), "4"), L("Rear View"), [this](wxCommandEvent&){ select_view("rear"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Left")), "5"), L("Left View"), [this](wxCommandEvent&){ select_view("left"); }); - append_menu_item(m_viewMenu, wxID_ANY, accel(_(L("Right")), "6"), L("Right View"), [this](wxCommandEvent&){ select_view("right"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Iso\t0")), _(L("Iso View")), [this](wxCommandEvent&){ select_view("iso"); }); + m_viewMenu->AppendSeparator(); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Top\t1")), _(L("Top View")), [this](wxCommandEvent&){ select_view("top"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Bottom\t2")), _(L("Bottom View")), [this](wxCommandEvent&){ select_view("bottom"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Front\t3")), _(L("Front View")), [this](wxCommandEvent&){ select_view("front"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Rear\t4")), _(L("Rear View")), [this](wxCommandEvent&){ select_view("rear"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Left\t5")), _(L("Left View")), [this](wxCommandEvent&){ select_view("left"); }); + append_menu_item(m_viewMenu, wxID_ANY, _(L("Right\t6")), _(L("Right View")), [this](wxCommandEvent&){ select_view("right"); }); } // Help menu @@ -683,9 +674,10 @@ void MainFrame::select_tab(size_t tab) const{ } // Set a camera direction, zoom to all objects. -void MainFrame::select_view(const std::string& direction){ -// if (m_plater) -// m_plater->select_view(direction); +void MainFrame::select_view(const std::string& direction) +{ + if (m_plater) + m_plater->select_view(direction); } void MainFrame::on_presets_changed(SimpleEvent &event) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f6e3983d9..6eb2c217e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -761,6 +761,7 @@ struct Plater::priv std::vector collect_selections(); #endif // !ENABLE_EXTENDED_SELECTION void update(bool force_autocenter = false); + void select_view(const std::string& direction); void update_ui_from_settings(); ProgressStatusBar* statusbar(); std::string get_config(const std::string &key) const; @@ -1002,6 +1003,19 @@ void Plater::priv::update(bool force_autocenter) // schedule_background_process(); // TODO } +void Plater::priv::select_view(const std::string& direction) +{ + int page_id = notebook->GetSelection(); + if (page_id != wxNOT_FOUND) + { + const wxString& page_text = notebook->GetPageText(page_id); + if (page_text == _(L("3D"))) + _3DScene::select_view(canvas3D, direction); + else if (page_text == _(L("Preview"))) + preview->select_view(direction); + } +} + void Plater::priv::update_ui_from_settings() { // TODO: (?) @@ -1852,6 +1866,9 @@ void Plater::add() void Plater::load_files(const std::vector &input_files) { p->load_files(input_files); } void Plater::update(bool force_autocenter) { p->update(force_autocenter); } + +void Plater::select_view(const std::string& direction) { p->select_view(direction); } + void Plater::remove(size_t obj_idx) { p->remove(obj_idx); } void Plater::remove_selected() diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 135dcfcde..eeb3123cd 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -109,6 +109,8 @@ public: void load_files(const std::vector &input_files); void update(bool force_autocenter = false); + void select_view(const std::string& direction); + void remove(size_t obj_idx); void remove_selected(); void increase(size_t num = 1); From d4371b60897acc4d95a5b24d8a1a379338bb4375 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 17 Oct 2018 14:01:10 +0200 Subject: [PATCH 17/24] Refactor window position & size persistence in a way that is hopefully robust wrt. platform quirks --- src/CMakeLists.txt | 6 +-- src/slic3r/GUI/GUI_App.cpp | 57 ++++++++++++---------- src/slic3r/GUI/GUI_App.hpp | 6 ++- src/slic3r/GUI/GUI_Utils.cpp | 95 ++++++++++++++++++++++++++++++------ src/slic3r/GUI/GUI_Utils.hpp | 25 ++++++++++ src/slic3r/GUI/MainFrame.cpp | 15 ++++-- 6 files changed, 153 insertions(+), 51 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c295ec5a..b2b3f4cf1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,14 +122,14 @@ if (MSVC) add_custom_target("resources_symlink_${CONF}" ALL DEPENDS slic3r COMMAND if exist "${WIN_CONF_OUTPUT_DIR}" "(" - if not exist "${WIN_RESOURCES_SYMLINK}" "(" - mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" + if not exist "${WIN_RESOURCES_SYMLINK}" "(" + mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")" ")" VERBATIM ) endforeach () - else () + else () file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" OUTPUT_DIR) add_custom_target(resources_symlink ALL DEPENDS slic3r diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fd4559a35..e58142f26 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -16,6 +16,7 @@ #include "Utils.hpp" #include "GUI.hpp" +#include "GUI_Utils.hpp" #include "AppConfig.hpp" #include "PresetBundle.hpp" #include "3DScene.hpp" @@ -344,41 +345,43 @@ wxMenuItem* GUI_App::append_submenu(wxMenu* menu, return item; } -void GUI_App::save_window_pos(wxTopLevelWindow* window, const std::string& name){ - int x, y; - window->GetScreenPosition(&x, &y); - app_config->set(name + "_pos", wxString::Format("%d,%d", x, y).ToStdString()); - - window->GetSize(&x, &y); - app_config->set(name + "_size", wxString::Format("%d,%d", x, y).ToStdString()); - - app_config->set(name + "_maximized", window->IsMaximized() ? "1" : "0"); +void GUI_App::window_pos_save(wxTopLevelWindow* window, const std::string &name) +{ + if (name.empty()) { return; } + const auto config_key = (boost::format("window_%1%") % name).str(); + WindowMetrics metrics = WindowMetrics::from_window(window); + app_config->set(config_key, metrics.serialize()); app_config->save(); } -void GUI_App::restore_window_pos(wxTopLevelWindow* window, const std::string& name) +void GUI_App::window_pos_restore(wxTopLevelWindow* window, const std::string &name) { - if (!app_config->has(name + "_pos")) - return; + if (name.empty()) { return; } + const auto config_key = (boost::format("window_%1%") % name).str(); - std::string str = app_config->get(name + "_size"); - std::vector values; - boost::split(values, str, boost::is_any_of(",")); - wxSize size = wxSize(atoi(values[0].c_str()), atoi(values[1].c_str())); - window->SetSize(size); + if (! app_config->has(config_key)) { return; } - auto display = (new wxDisplay())->GetClientArea(); - str = app_config->get(name + "_pos"); - values.resize(0); - boost::split(values, str, boost::is_any_of(",")); - wxPoint pos = wxPoint(atoi(values[0].c_str()), atoi(values[1].c_str())); - if (pos.x + 0.5*size.GetWidth() < display.GetRight() && - pos.y + 0.5*size.GetHeight() < display.GetBottom()) - window->Move(pos); + auto metrics = WindowMetrics::deserialize(app_config->get(config_key)); + if (! metrics) { return; } - if (app_config->get(name + "_maximized") == "1") - window->Maximize(); + window->SetSize(metrics->get_rect()); + window->Maximize(metrics->get_maximized()); +} + +void GUI_App::window_pos_sanitize(wxTopLevelWindow* window) +{ + const auto display_idx = wxDisplay::GetFromWindow(window); + if (display_idx == wxNOT_FOUND) { return; } + + const auto display = wxDisplay(display_idx).GetClientArea(); + + auto metrics = WindowMetrics::from_window(window); + + metrics.sanitize_for_display(display); + if (window->GetScreenRect() != metrics.get_rect()) { + window->SetSize(metrics.get_rect()); + } } // select language from the list of installed languages diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index ff910ed42..e1e48e9b9 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -113,8 +113,10 @@ public: const wxString& string, const wxString& description, const std::string& icon); - void save_window_pos(wxTopLevelWindow* window, const std::string& name); - void restore_window_pos(wxTopLevelWindow* window, const std::string& name); + + void window_pos_save(wxTopLevelWindow* window, const std::string &name); + void window_pos_restore(wxTopLevelWindow* window, const std::string &name); + void window_pos_sanitize(wxTopLevelWindow* window); bool select_language(wxArrayString & names, wxArrayLong & identifiers); bool load_language(); diff --git a/src/slic3r/GUI/GUI_Utils.cpp b/src/slic3r/GUI/GUI_Utils.cpp index b8cd60944..8fff2d208 100644 --- a/src/slic3r/GUI/GUI_Utils.cpp +++ b/src/slic3r/GUI/GUI_Utils.cpp @@ -1,16 +1,23 @@ #include "GUI_Utils.hpp" +#include +#include +#include + +#include #include #include #include +#include "libslic3r/Config.hpp" + namespace Slic3r { namespace GUI { CheckboxFileDialog::CheckboxFileDialog(wxWindow *parent, - const wxString &checkbox_label, + const wxString &checkbox_label, bool checkbox_value, const wxString &message, const wxString &default_dir, @@ -24,31 +31,87 @@ CheckboxFileDialog::CheckboxFileDialog(wxWindow *parent, : wxFileDialog(parent, message, default_dir, default_file, wildcard, style, pos, size, name) , cbox(nullptr) { - if (checkbox_label.IsEmpty()) { - return; - } + if (checkbox_label.IsEmpty()) { + return; + } - extra_control_creator = [this, checkbox_label](wxWindow *parent) -> wxWindow* { - wxPanel* panel = new wxPanel(parent, -1); - wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); - this->cbox = new wxCheckBox(panel, wxID_HIGHEST + 1, checkbox_label); - this->cbox->SetValue(true); - sizer->AddSpacer(5); - sizer->Add(this->cbox, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5); - panel->SetSizer(sizer); - sizer->SetSizeHints(panel); + extra_control_creator = [this, checkbox_label](wxWindow *parent) -> wxWindow* { + wxPanel* panel = new wxPanel(parent, -1); + wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + this->cbox = new wxCheckBox(panel, wxID_HIGHEST + 1, checkbox_label); + this->cbox->SetValue(true); + sizer->AddSpacer(5); + sizer->Add(this->cbox, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5); + panel->SetSizer(sizer); + sizer->SetSizeHints(panel); - return panel; - }; + return panel; + }; SetExtraControlCreator(*extra_control_creator.target()); } bool CheckboxFileDialog::get_checkbox_value() const { - return this->cbox != nullptr ? cbox->IsChecked() : false; + return this->cbox != nullptr ? cbox->IsChecked() : false; } + +WindowMetrics WindowMetrics::from_window(wxTopLevelWindow *window) +{ + WindowMetrics res; + res.rect = window->GetScreenRect(); + res.maximized = window->IsMaximized(); + return res; +} + +boost::optional WindowMetrics::deserialize(const std::string &str) +{ + std::vector metrics_str; + metrics_str.reserve(5); + + if (!unescape_strings_cstyle(str, metrics_str) || metrics_str.size() != 5) { + return boost::none; + } + + int metrics[5]; + try { + for (size_t i = 0; i < 5; i++) { + metrics[i] = boost::lexical_cast(metrics_str[i]); + } + } catch(const boost::bad_lexical_cast &) { + return boost::none; + } + + if ((metrics[4] & ~1) != 0) { // Checks if the maximized flag is 1 or 0 + metrics[4] = 0; + } + + WindowMetrics res; + res.rect = wxRect(metrics[0], metrics[1], metrics[2], metrics[3]); + res.maximized = metrics[4]; + + return res; +} + +void WindowMetrics::sanitize_for_display(const wxRect &screen_rect) +{ + rect = rect.Intersect(screen_rect); +} + +std::string WindowMetrics::serialize() +{ + return (boost::format("%1%; %2%; %3%; %4%; %5%") + % rect.GetX() + % rect.GetY() + % rect.GetWidth() + % rect.GetHeight() + % static_cast(maximized) + ).str(); +} + + + } } diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index bf2ee961f..1c776df81 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -2,10 +2,16 @@ #define slic3r_GUI_Utils_hpp_ #include +#include + +#include #include +#include class wxCheckBox; +class wxTopLevelWindow; +class wxRect; namespace Slic3r { @@ -36,6 +42,25 @@ private: }; +class WindowMetrics +{ +private: + wxRect rect; + bool maximized; + + WindowMetrics() : maximized(false) {} +public: + static WindowMetrics from_window(wxTopLevelWindow *window); + static boost::optional deserialize(const std::string &str); + + wxRect get_rect() const { return rect; } + bool get_maximized() const { return maximized; } + + void sanitize_for_display(const wxRect &screen_rect); + std::string serialize(); +}; + + }} #endif diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 67f01ad42..84b763a34 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -78,8 +78,6 @@ wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAUL Fit(); SetMinSize(wxSize(760, 490)); SetSize(GetMinSize()); - wxGetApp().restore_window_pos(this, "main_frame"); - Show(); Layout(); // declare events @@ -89,7 +87,7 @@ wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAUL return; } // save window size - wxGetApp().save_window_pos(this, "main_frame"); + wxGetApp().window_pos_save(this, "mainframe"); // Save the slic3r.ini.Usually the ini file is saved from "on idle" callback, // but in rare cases it may not have been called yet. wxGetApp().app_config->save(); @@ -101,6 +99,17 @@ wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAUL event.Skip(); }); + // NB: Restoring the window position is done in a two-phase manner here, + // first the saved position is restored as-is and validation is done after the window is shown + // and initial round of events is complete, because on some platforms that is the only way + // to get an accurate window position & size. + wxGetApp().window_pos_restore(this, "mainframe"); + Bind(wxEVT_SHOW, [this](wxShowEvent&) { + CallAfter([this]() { + wxGetApp().window_pos_sanitize(this); + }); + }); + update_ui_from_settings(); return; } From 23123cac2e0f5528f584502e699d3896bba05c20 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 17 Oct 2018 14:26:13 +0200 Subject: [PATCH 18/24] Increase and decrease command in object's context menu --- src/slic3r/GUI/Plater.cpp | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6eb2c217e..9fe5055b7 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -729,7 +729,7 @@ struct Plater::priv MainFrame *main_frame; // Object popup menu - wxMenu* object_menu; + wxMenu object_menu; // Data Slic3r::DynamicPrintConfig *config; @@ -755,7 +755,6 @@ struct Plater::priv static const std::regex pattern_zip_amf; priv(Plater *q, MainFrame *main_frame); - ~priv(); #if !ENABLE_EXTENDED_SELECTION std::vector collect_selections(); @@ -844,7 +843,6 @@ const std::regex Plater::priv::pattern_zip_amf("[.]zip[.]amf$", std::regex::icas Plater::priv::priv(Plater *q, MainFrame *main_frame) : q(q), main_frame(main_frame), - object_menu(nullptr), config(Slic3r::DynamicPrintConfig::new_from_defaults_keys({ "bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", "brim_width", "variable_layer_height", "serial_port", "serial_speed", "host_type", "print_host", @@ -961,12 +959,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : q->Layout(); } -Plater::priv::~priv() -{ - if (object_menu != nullptr) - delete object_menu; -} - #if !ENABLE_EXTENDED_SELECTION std::vector Plater::priv::collect_selections() { @@ -1752,8 +1744,8 @@ void Plater::priv::on_right_click(Vec2dEvent& evt) if (obj_idx == -1) return; - if ((q != nullptr) && (object_menu != nullptr)) - q->PopupMenu(object_menu, (int)evt.data.x(), (int)evt.data.y()); + if (q != nullptr) + q->PopupMenu(&object_menu, (int)evt.data.x(), (int)evt.data.y()); #else // TODO #endif // ENABLE_EXTENDED_SELECTION @@ -1821,15 +1813,26 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&) bool Plater::priv::init_object_menu() { - if (main_frame == nullptr) - return false; - - object_menu = new wxMenu(); - if (object_menu == nullptr) - return false; - - append_menu_item(object_menu, wxID_ANY, _(L("Deleteā€¦\tDel")), _(L("Remove the selected object")), + append_menu_item(&object_menu, wxID_ANY, _(L("Delete\tDel")), _(L("Remove the selected object")), [this](wxCommandEvent&){ q->remove_selected(); }, "brick_delete.png"); + append_menu_item(&object_menu, wxID_ANY, _(L("Increase copies\t+")), _(L("Place one more copy of the selected object")), + [this](wxCommandEvent&){ q->increase(); }, "add.png"); + wxMenuItem* item_decrease = append_menu_item(&object_menu, wxID_ANY, _(L("Decrease copies\t-")), _(L("Remove one copy of the selected object")), + [this](wxCommandEvent&){ q->decrease(); }, "delete.png"); + + // ui updates needs to be binded to the parent panel + if (q != nullptr) + { + q->Bind(wxEVT_UPDATE_UI, + [this](wxUpdateUIEvent& evt) + { +#if ENABLE_EXTENDED_SELECTION + int obj_idx = get_selected_object_idx(); + evt.Enable((obj_idx != -1) && (model.objects[obj_idx]->instances.size() > 1)); +#endif // ENABLE_EXTENDED_SELECTION + }, + item_decrease->GetId()); + } return true; } From 593eabd7c765e8f025ba15acffd0d51e2f2b749a Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 17 Oct 2018 15:22:45 +0200 Subject: [PATCH 19/24] Fix build --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b2b3f4cf1..330134c3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,7 +130,7 @@ if (MSVC) ) endforeach () else () - file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" OUTPUT_DIR) + file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources" WIN_RESOURCES_SYMLINK) add_custom_target(resources_symlink ALL DEPENDS slic3r COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")" From 143c23c54a971aa3ade1e13ea4f487d98be61dee Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 18 Oct 2018 08:51:06 +0200 Subject: [PATCH 20/24] New selection -> Force volume selection when right clicking to get the object context menu --- src/slic3r/GUI/GLCanvas3D.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 813d10f7c..e8c79b176 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3949,7 +3949,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) #endif // ENABLE_EXTENDED_SELECTION { #if ENABLE_EXTENDED_SELECTION - if (m_hover_volume_id != -1) + if (evt.LeftDown() && (m_hover_volume_id != -1)) { if (evt.ControlDown()) m_selection.remove(m_hover_volume_id); @@ -4043,13 +4043,24 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) render(); if (m_hover_volume_id != -1) { - // if right clicking on volume, propagate event through callback (shows context menu) #if ENABLE_EXTENDED_SELECTION - if (m_volumes.volumes[m_hover_volume_id]->hover) -#else - if (m_volumes.volumes[volume_idx]->hover) -#endif // ENABLE_EXTENDED_SELECTION + // if right clicking on volume, propagate event through callback (shows context menu) + if (m_volumes.volumes[m_hover_volume_id]->hover && !m_volumes.volumes[m_hover_volume_id]->is_wipe_tower) + { + // forces the selection of the volume + m_selection.add(m_hover_volume_id); + m_gizmos.update_on_off_state(m_selection); + update_gizmos_data(); + wxGetApp().obj_manipul()->update_settings_value(m_selection); + // forces a frame render to update the view before the context menu is shown + render(); post_event(Vec2dEvent(EVT_GLCANVAS_RIGHT_CLICK, pos.cast())); + } +#else + // if right clicking on volume, propagate event through callback (shows context menu) + if (m_volumes.volumes[volume_idx]->hover) + post_event(Vec2dEvent(EVT_GLCANVAS_RIGHT_CLICK, pos.cast())); +#endif // ENABLE_EXTENDED_SELECTION } } } From 82ec5bf22e56006a3dc4b8a169cefbb06b201bc4 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 18 Oct 2018 09:27:37 +0200 Subject: [PATCH 21/24] New selection -> Unified methods to update menu items --- src/slic3r/GUI/Plater.cpp | 108 ++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 33 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9fe5055b7..c58f02f83 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -834,6 +834,15 @@ struct Plater::priv private: bool init_object_menu(); + +#if ENABLE_EXTENDED_SELECTION + bool can_delete_object() const; + bool can_increase_instances() const; + bool can_decrease_instances() const; + bool can_split_object() const; + bool can_cut_object() const; + bool layers_height_allowed() const; +#endif // ENABLE_EXTENDED_SELECTION }; const std::regex Plater::priv::pattern_bundle("[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)$", std::regex::icase); @@ -1322,31 +1331,30 @@ optional Plater::priv::selected_object() const void Plater::priv::selection_changed() { +#if !ENABLE_EXTENDED_SELECTION + const auto obj_idx = selected_object(); + const bool have_sel = !!obj_idx; +#endif // !ENABLE_EXTENDED_SELECTION + +#if ENABLE_EXTENDED_SELECTION + _3DScene::enable_toolbar_item(canvas3D, "delete", can_delete_object()); + _3DScene::enable_toolbar_item(canvas3D, "more", can_increase_instances()); + _3DScene::enable_toolbar_item(canvas3D, "fewer", can_decrease_instances()); + _3DScene::enable_toolbar_item(canvas3D, "split", can_split_object()); + _3DScene::enable_toolbar_item(canvas3D, "cut", can_cut_object()); + _3DScene::enable_toolbar_item(canvas3D, "layersediting", layers_height_allowed()); +#else + _3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel); + _3DScene::enable_toolbar_item(canvas3D, "split", have_sel); + _3DScene::enable_toolbar_item(canvas3D, "cut", have_sel); + _3DScene::enable_toolbar_item(canvas3D, "settings", have_sel); + _3DScene::enable_toolbar_item(canvas3D, "layersediting", layers_height_allowed); +#endif // ENABLE_EXTENDED_SELECTION + #if ENABLE_EXTENDED_SELECTION int obj_idx = get_selected_object_idx(); bool have_sel = (obj_idx != -1); #else - const auto obj_idx = selected_object(); - const bool have_sel = !!obj_idx; -#endif // ENABLE_EXTENDED_SELECTION - const bool layers_height_allowed = config->opt("variable_layer_height")->value; - - wxWindowUpdateLocker freeze_guard(sidebar); - - _3DScene::enable_toolbar_item(canvas3D, "delete", have_sel); - _3DScene::enable_toolbar_item(canvas3D, "more", have_sel); -#if ENABLE_EXTENDED_SELECTION - _3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel && (model.objects[obj_idx]->instances.size() > 1)); -#else - _3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel); -#endif // ENABLE_EXTENDED_SELECTION - _3DScene::enable_toolbar_item(canvas3D, "split", have_sel); - _3DScene::enable_toolbar_item(canvas3D, "cut", have_sel); - _3DScene::enable_toolbar_item(canvas3D, "settings", have_sel); - - _3DScene::enable_toolbar_item(canvas3D, "layersediting", layers_height_allowed); - -#if !ENABLE_EXTENDED_SELECTION bool can_select_by_parts = false; if (have_sel) { @@ -1364,8 +1372,9 @@ void Plater::priv::selection_changed() _3DScene::enable_toolbar_item(canvas3D, "selectbyparts", false); _3DScene::set_select_by(canvas3D, "object"); } -#endif // !ENABLE_EXTENDED_SELECTION +#endif // ENABLE_EXTENDED_SELECTION + wxWindowUpdateLocker freeze_guard(sidebar); if (have_sel) { #if ENABLE_EXTENDED_SELECTION const ModelObject* model_object = model.objects[obj_idx]; @@ -1813,30 +1822,63 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&) bool Plater::priv::init_object_menu() { - append_menu_item(&object_menu, wxID_ANY, _(L("Delete\tDel")), _(L("Remove the selected object")), + wxMenuItem* item_delete = append_menu_item(&object_menu, wxID_ANY, _(L("Delete\tDel")), _(L("Remove the selected object")), [this](wxCommandEvent&){ q->remove_selected(); }, "brick_delete.png"); - append_menu_item(&object_menu, wxID_ANY, _(L("Increase copies\t+")), _(L("Place one more copy of the selected object")), + wxMenuItem* item_increase = append_menu_item(&object_menu, wxID_ANY, _(L("Increase copies\t+")), _(L("Place one more copy of the selected object")), [this](wxCommandEvent&){ q->increase(); }, "add.png"); wxMenuItem* item_decrease = append_menu_item(&object_menu, wxID_ANY, _(L("Decrease copies\t-")), _(L("Remove one copy of the selected object")), [this](wxCommandEvent&){ q->decrease(); }, "delete.png"); +#if ENABLE_EXTENDED_SELECTION // ui updates needs to be binded to the parent panel if (q != nullptr) { - q->Bind(wxEVT_UPDATE_UI, - [this](wxUpdateUIEvent& evt) - { -#if ENABLE_EXTENDED_SELECTION - int obj_idx = get_selected_object_idx(); - evt.Enable((obj_idx != -1) && (model.objects[obj_idx]->instances.size() > 1)); -#endif // ENABLE_EXTENDED_SELECTION - }, - item_decrease->GetId()); + q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_delete_object()); }, item_delete->GetId()); + q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_increase_instances()); }, item_increase->GetId()); + q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_decrease_instances()); }, item_decrease->GetId()); } +#endif // ENABLE_EXTENDED_SELECTION return true; } +#if ENABLE_EXTENDED_SELECTION +bool Plater::priv::can_delete_object() const +{ + int obj_idx = get_selected_object_idx(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()); +} + +bool Plater::priv::can_increase_instances() const +{ + int obj_idx = get_selected_object_idx(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()); +} + +bool Plater::priv::can_decrease_instances() const +{ + int obj_idx = get_selected_object_idx(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()) && (model.objects[obj_idx]->instances.size() > 1); +} + +bool Plater::priv::can_split_object() const +{ + int obj_idx = get_selected_object_idx(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()); +} + +bool Plater::priv::can_cut_object() const +{ + int obj_idx = get_selected_object_idx(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()); +} + +bool Plater::priv::layers_height_allowed() const +{ + return config->opt_bool("variable_layer_height") && _3DScene::is_layers_editing_allowed(canvas3D); +} +#endif // ENABLE_EXTENDED_SELECTION + // Plater / Public Plater::Plater(wxWindow *parent, MainFrame *main_frame) From e223120e7e88658ba5e13f21d5643507eeda9910 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 18 Oct 2018 10:40:26 +0200 Subject: [PATCH 22/24] Added instances to ObjectList --- src/slic3r/GUI/GUI_ObjectList.cpp | 49 +++++--- src/slic3r/GUI/GUI_ObjectList.hpp | 4 + src/slic3r/GUI/MainFrame.hpp | 10 +- src/slic3r/GUI/Plater.cpp | 2 + src/slic3r/GUI/wxExtensions.cpp | 184 +++++++++++++++++++++++++++--- src/slic3r/GUI/wxExtensions.hpp | 33 ++++-- 6 files changed, 238 insertions(+), 44 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 14773b593..5a20756ce 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -283,7 +283,7 @@ void ObjectList::show_context_menu() const auto item = GetSelection(); if (item) { - if (m_objects_model->IsSettingsItem(item)) + if (!(m_objects_model->GetItemType(item) & (itObject | itVolume))) return; const auto menu = m_objects_model->GetParent(item) == wxDataViewItem(0) ? create_add_part_popupmenu() : @@ -672,7 +672,7 @@ void ObjectList::load_subobject(bool is_modifier /*= false*/, bool is_lambda/* = parts_changed(obj_idx); for (int i = 0; i < part_names.size(); ++i) { - const wxDataViewItem sel_item = m_objects_model->AddChild(item, part_names.Item(i), + const wxDataViewItem sel_item = m_objects_model->AddVolumeChild(item, part_names.Item(i), is_modifier ? m_bmp_modifiermesh : m_bmp_solidmesh); if (i == part_names.size() - 1) @@ -822,7 +822,7 @@ void ObjectList::load_lambda(const std::string& type_name) m_parts_changed = true; parts_changed(m_selected_object_id); - select_item(m_objects_model->AddChild(GetSelection(), + select_item(m_objects_model->AddVolumeChild(GetSelection(), name, m_bmp_modifiermesh)); #ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME selection_changed(); @@ -896,14 +896,19 @@ bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, con if (vol->is_model_part()) ++solid_cnt; if (volume->is_model_part() && solid_cnt == 1) { - Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object."))); + Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from object."))); return false; } (*m_objects)[obj_idx]->delete_volume(idx); } - else if (type == itInstance) + else if (type == itInstance) { + if ((*m_objects)[obj_idx]->instances.size() == 1) { + Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last intance from object."))); + return false; + } (*m_objects)[obj_idx]->delete_instance(idx); + } else return false; @@ -934,7 +939,7 @@ void ObjectList::split(const bool split_part) m_objects_model->DeleteChildren(parent); for (auto id = 0; id < model_object->volumes.size(); id++) - m_objects_model->AddChild(parent, model_object->volumes[id]->name, + m_objects_model->AddVolumeChild(parent, model_object->volumes[id]->name, model_object->volumes[id]->is_modifier() ? m_bmp_modifiermesh : m_bmp_solidmesh, model_object->volumes[id]->config.has("extruder") ? model_object->volumes[id]->config.option("extruder")->value : 0, @@ -944,7 +949,7 @@ void ObjectList::split(const bool split_part) } else { for (auto id = 0; id < model_object->volumes.size(); id++) - m_objects_model->AddChild(item, model_object->volumes[id]->name, + m_objects_model->AddVolumeChild(item, model_object->volumes[id]->name, m_bmp_solidmesh, model_object->volumes[id]->config.has("extruder") ? model_object->volumes[id]->config.option("extruder")->value : 0, @@ -1034,7 +1039,7 @@ void ObjectList::part_selection_changed() m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config; } } - else { + else if (m_objects_model->GetItemType(item) == itVolume){ og_name = _(L("Part manipulation")); is_part = true; const auto volume_id = m_objects_model->GetVolumeIdByItem(item); @@ -1088,7 +1093,7 @@ void ObjectList::add_object_to_list(size_t obj_idx) if (model_object->volumes.size() > 1) { for (auto id = 0; id < model_object->volumes.size(); id++) - m_objects_model->AddChild(item, + m_objects_model->AddVolumeChild(item, model_object->volumes[id]->name, m_bmp_solidmesh, model_object->volumes[id]->config.option("extruder")->value, @@ -1128,6 +1133,16 @@ void ObjectList::delete_all_objects_from_list() part_selection_changed(); } +void ObjectList::increase_object_instances(const size_t obj_idx, const size_t num) +{ + select_item(m_objects_model->AddInstanceChild(m_objects_model->GetItemById(obj_idx), num)); +} + +void ObjectList::decrease_object_instances(const size_t obj_idx, const size_t num) +{ + select_item(m_objects_model->DeleteLastInstance(m_objects_model->GetItemById(obj_idx), num)); +} + void ObjectList::set_object_count(int idx, int count) { m_objects_model->SetValue(wxString::Format("%d", count), idx, 1); @@ -1231,15 +1246,21 @@ void ObjectList::update_selections_on_canvas() return; } - auto parent = m_objects_model->GetParent(item); - const int obj_idx = m_objects_model->GetIdByItem(parent); - const int vol_idx = m_objects_model->GetVolumeIdByItem(item); - selection.add_volume(obj_idx, vol_idx, as_single_selection); + if (m_objects_model->GetItemType(item) == itVolume) { + const int obj_idx = m_objects_model->GetIdByItem(m_objects_model->GetParent(item)); + const int vol_idx = m_objects_model->GetVolumeIdByItem(item); + selection.add_volume(obj_idx, vol_idx, as_single_selection); + } + else if (m_objects_model->GetItemType(item) == itInstance) { + const int obj_idx = m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item)); + const int inst_idx = m_objects_model->GetInstanceIdByItem(item); + selection.add_instance(obj_idx, inst_idx, as_single_selection); + } }; if (sel_cnt == 1) { wxDataViewItem item = GetSelection(); - if (m_objects_model->IsSettingsItem(item)) + if (m_objects_model->GetItemType(item) & (itSettings|itInstanceRoot)) add_to_selection(m_objects_model->GetParent(item), selection, true); else add_to_selection(item, selection, true); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 418e1e877..2325734bd 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -112,6 +112,10 @@ public: void delete_volume_from_list(const size_t obj_idx, const size_t vol_idx); // Delete all objects from the list void delete_all_objects_from_list(); + // Increase instances count + void increase_object_instances(const size_t obj_idx, const size_t num); + // Decrease instances count + void decrease_object_instances(const size_t obj_idx, const size_t num); // Set count of object on c++ side void set_object_count(int idx, int count); diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index ed2646b69..f298dc034 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -30,11 +30,11 @@ class Tab; enum QuickSlice { - qsUndef, - qsReslice, - qsSaveAs, - qsExportSVG, - qsExportPNG + qsUndef = 0, + qsReslice = 1, + qsSaveAs = 2, + qsExportSVG = 4, + qsExportPNG = 8 }; struct PresetTab { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9f0cdc89b..7ef58d8bb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1747,6 +1747,7 @@ void Plater::increase(size_t num) } sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); + sidebar().obj_list()->increase_object_instances(*obj_idx, num); if (p->get_config("autocenter") == "1") { p->arrange(); @@ -1771,6 +1772,7 @@ void Plater::decrease(size_t num) p->print.get_object(*obj_idx)->delete_last_copy(); } sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); + sidebar().obj_list()->decrease_object_instances(*obj_idx, num); } else { remove(*obj_idx); } diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 4b57540c2..cd5f339e0 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -429,7 +429,7 @@ wxDataViewItem PrusaObjectDataViewModel::Add(const wxString &name, const int ins return child; } -wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_item, +wxDataViewItem PrusaObjectDataViewModel::AddVolumeChild(const wxDataViewItem &parent_item, const wxString &name, const wxBitmap& icon, const int extruder/* = 0*/, @@ -440,8 +440,7 @@ wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_ const wxString extruder_str = extruder == 0 ? "default" : wxString::Format("%d", extruder); - if (create_frst_child && (root->GetChildren().Count() == 0 || - (root->GetChildren().Count() == 1 && root->GetNthChild(0)->m_type == itSettings))) + if (create_frst_child && root->m_volumes_cnt == 0) { const auto icon_solid_mesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG); const auto node = new PrusaObjectDataViewModelNode(root, root->m_name, icon_solid_mesh, extruder_str, 0); @@ -449,16 +448,17 @@ wxDataViewItem PrusaObjectDataViewModel::AddChild( const wxDataViewItem &parent_ // notify control const wxDataViewItem child((void*)node); ItemAdded(parent_item, child); + + root->m_volumes_cnt++; } - const auto volume_id = root->GetChildCount() > 0 && root->GetNthChild(0)->m_type == itSettings ? - root->GetChildCount() - 1 : root->GetChildCount(); - - const auto node = new PrusaObjectDataViewModelNode(root, name, icon, extruder_str, volume_id); + const auto node = new PrusaObjectDataViewModelNode(root, name, icon, extruder_str, root->m_volumes_cnt); root->Append(node); // notify control const wxDataViewItem child((void*)node); - ItemAdded(parent_item, child); + ItemAdded(parent_item, child); + root->m_volumes_cnt++; + return child; } @@ -467,7 +467,7 @@ wxDataViewItem PrusaObjectDataViewModel::AddSettingsChild(const wxDataViewItem & PrusaObjectDataViewModelNode *root = (PrusaObjectDataViewModelNode*)parent_item.GetID(); if (!root) return wxDataViewItem(0); - const auto node = new PrusaObjectDataViewModelNode(root); + const auto node = new PrusaObjectDataViewModelNode(root, itSettings); root->Insert(node, 0); // notify control const wxDataViewItem child((void*)node); @@ -475,6 +475,55 @@ wxDataViewItem PrusaObjectDataViewModel::AddSettingsChild(const wxDataViewItem & return child; } +int get_istances_root_idx(PrusaObjectDataViewModelNode *parent_node) +{ + int inst_root_id = -1; + int stop_search_i = parent_node->GetChildCount(); + if (stop_search_i > 2) stop_search_i = 2; + for (int i = 0; i < stop_search_i; ++i) + if (parent_node->GetNthChild(i)->m_type & itInstanceRoot) { + inst_root_id = i; + break; + } + return inst_root_id; +} + +wxDataViewItem PrusaObjectDataViewModel::AddInstanceChild(const wxDataViewItem &parent_item, size_t num) +{ + PrusaObjectDataViewModelNode *parent_node = (PrusaObjectDataViewModelNode*)parent_item.GetID(); + if (!parent_node) return wxDataViewItem(0); + + // Check and create/get instances root node + const int inst_root_id = get_istances_root_idx(parent_node); + + PrusaObjectDataViewModelNode *inst_root_node = inst_root_id < 0 ? + new PrusaObjectDataViewModelNode(parent_node, itInstanceRoot) : + parent_node->GetNthChild(inst_root_id); + const wxDataViewItem inst_root_item((void*)inst_root_node); + + if (inst_root_id < 0) { + const unsigned insert_pos = parent_node->GetChildCount() == 0 || parent_node->GetNthChild(0)->m_type != itSettings ? 0 : 1; + parent_node->Insert(inst_root_node, insert_pos); + // notify control + ItemAdded(parent_item, inst_root_item); + num++; + } + + // Add instance nodes + PrusaObjectDataViewModelNode *instance_node = nullptr; + size_t counter = 0; + while (counter < num){ + instance_node = new PrusaObjectDataViewModelNode(inst_root_node, itInstance); + inst_root_node->Append(instance_node); + // notify control + const wxDataViewItem instance_item((void*)instance_node); + ItemAdded(inst_root_item, instance_item); + ++counter; + } + + return wxDataViewItem((void*)instance_node); +} + wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item) { auto ret_item = wxDataViewItem(0); @@ -505,6 +554,30 @@ wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item) if (cur_idx > idx) children[i]->SetIdx(cur_idx-1); } + + // if there is last instance item, delete both of it and instance root item + if (node_parent->GetChildCount() == 1 && node_parent->GetNthChild(0)->m_type == itInstance) + { + delete node; + ItemDeleted(parent, item); + + PrusaObjectDataViewModelNode *last_instance_node = node_parent->GetNthChild(0); + node_parent->GetChildren().Remove(last_instance_node); + delete last_instance_node; + ItemDeleted(parent, wxDataViewItem(last_instance_node)); + + PrusaObjectDataViewModelNode *obj_node = node_parent->GetParent(); + obj_node->GetChildren().Remove(node_parent); + delete node_parent; + ret_item = wxDataViewItem(obj_node); + ItemDeleted(ret_item, wxDataViewItem(node_parent)); + +#ifndef __WXGTK__ + if (obj_node->GetChildCount() == 0) + obj_node->m_container = false; +#endif //__WXGTK__ + return ret_item; + } } else { @@ -534,6 +607,54 @@ wxDataViewItem PrusaObjectDataViewModel::Delete(const wxDataViewItem &item) return ret_item; } +wxDataViewItem PrusaObjectDataViewModel::DeleteLastInstance(const wxDataViewItem &parent_item, size_t num) +{ + auto ret_item = wxDataViewItem(0); + PrusaObjectDataViewModelNode *parent_node = (PrusaObjectDataViewModelNode*)parent_item.GetID(); + if (!parent_node) return ret_item; + + const int inst_root_id = get_istances_root_idx(parent_node); + if (inst_root_id < 0) return ret_item; + + wxDataViewItemArray items; + PrusaObjectDataViewModelNode *inst_root_node = parent_node->GetNthChild(inst_root_id); + const wxDataViewItem inst_root_item((void*)inst_root_node); + + const int inst_cnt = inst_root_node->GetChildCount(); + const bool delete_inst_root_item = inst_cnt - num < 2 ? true : false; + + int stop = delete_inst_root_item ? 0 : inst_cnt - num; + for (int i = inst_cnt - 1; i >= stop;--i) { + PrusaObjectDataViewModelNode *last_instance_node = inst_root_node->GetNthChild(i); + inst_root_node->GetChildren().Remove(last_instance_node); + delete last_instance_node; + ItemDeleted(inst_root_item, wxDataViewItem(last_instance_node)); + } + +// for (int i = delete_inst_root_item ? 0 : inst_cnt - num; i < inst_cnt; ++i) +// items.Add(wxDataViewItem(inst_root_node->GetNthChild(i))); +// +// if (delete_inst_root_item) +// inst_root_node->GetChildren().RemoveAt(0, inst_cnt); +// else { +// ret_item = wxDataViewItem(inst_root_node->GetNthChild(inst_cnt - num - 1)); +// inst_root_node->GetChildren().RemoveAt(inst_cnt - num, num); +// } + +// ItemsDeleted(inst_root_item, items); + if (delete_inst_root_item) { + ret_item = parent_item; + parent_node->GetChildren().Remove(inst_root_node); + ItemDeleted(parent_item, inst_root_item); +#ifndef __WXGTK__ + if (parent_node->GetChildCount() == 0) + parent_node->m_container = false; +#endif //__WXGTK__ + } + + return ret_item; +} + void PrusaObjectDataViewModel::DeleteAll() { while (!m_objects.empty()) @@ -620,36 +741,49 @@ int PrusaObjectDataViewModel::GetIdByItem(const wxDataViewItem& item) return it - m_objects.begin(); } -int PrusaObjectDataViewModel::GetVolumeIdByItem(const wxDataViewItem& item) +int PrusaObjectDataViewModel::GetIdByItemAndType(const wxDataViewItem& item, const ItemType type) const { wxASSERT(item.IsOk()); PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - if (!node || node->m_type != itVolume) + if (!node || node->m_type != type) return -1; return node->GetIdx(); } +int PrusaObjectDataViewModel::GetVolumeIdByItem(const wxDataViewItem& item) const +{ + return GetIdByItemAndType(item, itVolume); +} + +int PrusaObjectDataViewModel::GetInstanceIdByItem(const wxDataViewItem& item) const +{ + return GetIdByItemAndType(item, itInstance); +} + void PrusaObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx) { wxASSERT(item.IsOk()); type = itUndef; PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - if (!node) return; + if (!node || node->GetIdx() < 0 && node->GetType() != itObject) + return; - type = node->GetType(); idx = node->GetIdx(); + type = node->GetType(); PrusaObjectDataViewModelNode *parent_node = node->GetParent(); if (!parent_node) return; if (type == itInstance) parent_node = node->GetParent()->GetParent(); - if (!parent_node) return; + if (!parent_node || parent_node->m_type != itObject) { type = itUndef; return; } auto it = find(m_objects.begin(), m_objects.end(), parent_node); if (it != m_objects.end()) obj_idx = it - m_objects.begin(); + else + type = itUndef; } wxString PrusaObjectDataViewModel::GetName(const wxDataViewItem &item) const @@ -819,12 +953,32 @@ wxDataViewItem PrusaObjectDataViewModel::GetParent(const wxDataViewItem &item) c PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); // objects nodes has no parent too - if (find(m_objects.begin(), m_objects.end(),node) != m_objects.end()) + if (node->m_type == itObject) return wxDataViewItem(0); return wxDataViewItem((void*)node->GetParent()); } +wxDataViewItem PrusaObjectDataViewModel::GetTopParent(const wxDataViewItem &item) const +{ + // the invisible root node has no parent + if (!item.IsOk()) + return wxDataViewItem(0); + + PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); + if (node->m_type == itObject) + return item; + + PrusaObjectDataViewModelNode *parent_node = node->GetParent(); + while (parent_node->m_type != itObject) + { + node = parent_node; + parent_node = node->GetParent(); + } + + return wxDataViewItem((void*)parent_node); +} + bool PrusaObjectDataViewModel::IsContainer(const wxDataViewItem &item) const { // the invisible root node can have children diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index f3c417426..c1ff4074e 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -195,12 +195,12 @@ DECLARE_VARIANT_OBJECT(PrusaDataViewBitmapText) // ---------------------------------------------------------------------------- enum ItemType{ - itUndef, - itObject, - itVolume, - itInstanceRoot, - itInstance, - itSettings + itUndef = 0, + itObject = 1, + itVolume = 2, + itInstanceRoot = 4, + itInstance = 8, + itSettings = 16 }; class PrusaObjectDataViewModelNode; @@ -211,6 +211,7 @@ class PrusaObjectDataViewModelNode PrusaObjectDataViewModelNode* m_parent; MyObjectTreeModelNodePtrArray m_children; wxBitmap m_empty_bmp; + size_t m_volumes_cnt = 0; std::vector< std::string > m_opt_categories; public: PrusaObjectDataViewModelNode(const wxString &name, const int instances_count=1) { @@ -248,7 +249,7 @@ public: set_part_action_icon(); } - PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent, const ItemType type = itSettings) : + PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent, const ItemType type) : m_parent(parent), m_copy(wxEmptyString), m_type(type), @@ -261,8 +262,8 @@ public: m_name = "Instances"; } else if (type == itInstance) { - m_name = wxString::Format("Instances_%d", parent->GetChildCount() + 1); m_idx = parent->GetChildCount(); + m_name = wxString::Format("Instance_%d", m_idx+1); } } @@ -370,7 +371,11 @@ public: void SetIdx(const int& idx) { m_idx = idx; + // update name if this node is instance + if (m_type == itInstance) + m_name = wxString::Format("Instance_%d", m_idx + 1); } + int GetIdx() const { return m_idx; } @@ -407,6 +412,8 @@ public: void set_object_action_icon(); void set_part_action_icon(); bool update_settings_digest(const std::vector& categories); +private: + friend class PrusaObjectDataViewModel; }; // ---------------------------------------------------------------------------- @@ -422,19 +429,23 @@ public: wxDataViewItem Add(const wxString &name); wxDataViewItem Add(const wxString &name, const int instances_count); - wxDataViewItem AddChild(const wxDataViewItem &parent_item, + wxDataViewItem AddVolumeChild(const wxDataViewItem &parent_item, const wxString &name, const wxBitmap& icon, const int extruder = 0, const bool create_frst_child = true); wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item); + wxDataViewItem AddInstanceChild(const wxDataViewItem &parent_item, size_t num); wxDataViewItem Delete(const wxDataViewItem &item); + wxDataViewItem DeleteLastInstance(const wxDataViewItem &parent_item, size_t num); void DeleteAll(); void DeleteChildren(wxDataViewItem& parent); wxDataViewItem GetItemById(int obj_idx); wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx); int GetIdByItem(const wxDataViewItem& item); - int GetVolumeIdByItem(const wxDataViewItem& item); + int GetIdByItemAndType(const wxDataViewItem& item, const ItemType type) const; + int GetVolumeIdByItem(const wxDataViewItem& item) const; + int GetInstanceIdByItem(const wxDataViewItem& item) const; void GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx); bool IsEmpty() { return m_objects.empty(); } @@ -466,6 +477,8 @@ public: virtual bool IsEnabled(const wxDataViewItem &item, unsigned int col) const override; virtual wxDataViewItem GetParent(const wxDataViewItem &item) const override; + // get object item + wxDataViewItem GetTopParent(const wxDataViewItem &item) const; virtual bool IsContainer(const wxDataViewItem &item) const override; virtual unsigned int GetChildren(const wxDataViewItem &parent, wxDataViewItemArray &array) const override; From 33a0f5beff5d4ba91f4352741f99df303191cd8a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 18 Oct 2018 11:28:31 +0200 Subject: [PATCH 23/24] Deleted "Copy" column from ObjectList --- src/slic3r/GUI/GUI_ObjectList.cpp | 32 +++++++++---------------- src/slic3r/GUI/GUI_ObjectList.hpp | 2 -- src/slic3r/GUI/Plater.cpp | 4 +--- src/slic3r/GUI/Tab.cpp | 2 +- src/slic3r/GUI/wxExtensions.cpp | 39 ++++--------------------------- src/slic3r/GUI/wxExtensions.hpp | 15 +++--------- 6 files changed, 21 insertions(+), 73 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 5a20756ce..ca54a3ca0 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -94,17 +94,13 @@ void ObjectList::create_objects_ctrl() // column 0(Icon+Text) of the view control: // And Icon can be consisting of several bitmaps AppendColumn(new wxDataViewColumn(_(L("Name")), new PrusaBitmapTextRenderer(), - 0, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE)); + 0, 250, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE)); // column 1 of the view control: - AppendTextColumn(_(L("Copy")), 1, wxDATAVIEW_CELL_INERT, 45, - wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE); - - // column 2 of the view control: AppendColumn(create_objects_list_extruder_column(4)); - // column 3 of the view control: - AppendBitmapColumn(" ", 3, wxDATAVIEW_CELL_INERT, 25, + // column 2 of the view control: + AppendBitmapColumn(" ", 2, wxDATAVIEW_CELL_INERT, 25, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE); } @@ -178,7 +174,7 @@ wxDataViewColumn* ObjectList::create_objects_list_extruder_column(int extruders_ choices.Add(wxString::Format("%d", i)); wxDataViewChoiceRenderer *c = new wxDataViewChoiceRenderer(choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_CENTER_HORIZONTAL); - wxDataViewColumn* column = new wxDataViewColumn(_(L("Extruder")), c, 2, 60, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE); + wxDataViewColumn* column = new wxDataViewColumn(_(L("Extruder")), c, 1, 80, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE); return column; } @@ -188,17 +184,17 @@ void ObjectList::update_objects_list_extruder_column(int extruders_count) if (wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA) extruders_count = 1; - // delete old 3rd column - DeleteColumn(GetColumn(2)); + // delete old 2nd column + DeleteColumn(GetColumn(1)); // insert new created 3rd column - InsertColumn(2, create_objects_list_extruder_column(extruders_count)); + InsertColumn(1, create_objects_list_extruder_column(extruders_count)); // set show/hide for this column set_extruder_column_hidden(extruders_count <= 1); } void ObjectList::set_extruder_column_hidden(bool hide) { - GetColumn(2)->SetHidden(hide); + GetColumn(1)->SetHidden(hide); } void ObjectList::update_extruder_in_config(const wxString& selection) @@ -313,10 +309,10 @@ void ObjectList::key_event(wxKeyEvent& event) void ObjectList::item_value_change(wxDataViewEvent& event) { - if (event.GetColumn() == 2) + if (event.GetColumn() == 1) { wxVariant variant; - m_objects_model->GetValue(variant, event.GetItem(), 2); + m_objects_model->GetValue(variant, event.GetItem(), 1); #ifdef __WXOSX__ m_selected_extruder = variant.GetString(); #else // --> for Linux @@ -1076,7 +1072,7 @@ void ObjectList::add_object_to_list(size_t obj_idx) { auto model_object = (*m_objects)[obj_idx]; wxString item_name = model_object->name; - auto item = m_objects_model->Add(item_name, model_object->instances.size()); + auto item = m_objects_model->Add(item_name); #if !ENABLE_EXTENDED_SELECTION /*Select*/select_item(item); #endif // !ENABLE_EXTENDED_SELECTION @@ -1143,12 +1139,6 @@ void ObjectList::decrease_object_instances(const size_t obj_idx, const size_t nu select_item(m_objects_model->DeleteLastInstance(m_objects_model->GetItemById(obj_idx), num)); } -void ObjectList::set_object_count(int idx, int count) -{ - m_objects_model->SetValue(wxString::Format("%d", count), idx, 1); - Refresh(); -} - void ObjectList::unselect_objects() { if (!GetSelection()) diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 2325734bd..c56e69670 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -116,8 +116,6 @@ public: void increase_object_instances(const size_t obj_idx, const size_t num); // Decrease instances count void decrease_object_instances(const size_t obj_idx, const size_t num); - // Set count of object on c++ side - void set_object_count(int idx, int count); // #ys_FIXME_to_delete // Unselect all objects in the list on c++ side diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7ef58d8bb..8238db65a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1742,11 +1742,10 @@ void Plater::increase(size_t num) float offset = 10.0; for (size_t i = 0; i < num; i++, offset += 10.0) { Vec3d offset_vec = model_instance->get_offset() + Vec3d(offset, offset, 0.0); - auto *new_instance = model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation()); + model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation()); p->print.get_object(*obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); } - sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); sidebar().obj_list()->increase_object_instances(*obj_idx, num); if (p->get_config("autocenter") == "1") { @@ -1771,7 +1770,6 @@ void Plater::decrease(size_t num) model_object->delete_last_instance(); p->print.get_object(*obj_idx)->delete_last_copy(); } - sidebar().obj_list()->set_object_count(*obj_idx, model_object->instances.size()); sidebar().obj_list()->decrease_object_instances(*obj_idx, num); } else { remove(*obj_idx); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 023a6a67d..3b9fe0bd3 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1845,7 +1845,7 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){ if (!wxGetApp().mainframe) return; on_value_change("extruders_count", extruders_count); - wxGetApp().mainframe->m_plater->sidebar().update_objects_list_extruder_column(extruders_count); + wxGetApp().sidebar().update_objects_list_extruder_column(extruders_count); } void TabPrinter::append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index cd5f339e0..f74aa02b4 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -418,17 +418,6 @@ wxDataViewItem PrusaObjectDataViewModel::Add(const wxString &name) return child; } -wxDataViewItem PrusaObjectDataViewModel::Add(const wxString &name, const int instances_count/*, int scale*/) -{ - auto root = new PrusaObjectDataViewModelNode(name, instances_count); - m_objects.push_back(root); - // notify control - wxDataViewItem child((void*)root); - wxDataViewItem parent((void*)NULL); - ItemAdded(parent, child); - return child; -} - wxDataViewItem PrusaObjectDataViewModel::AddVolumeChild(const wxDataViewItem &parent_item, const wxString &name, const wxBitmap& icon, @@ -442,8 +431,8 @@ wxDataViewItem PrusaObjectDataViewModel::AddVolumeChild(const wxDataViewItem &pa if (create_frst_child && root->m_volumes_cnt == 0) { - const auto icon_solid_mesh = wxIcon(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG); - const auto node = new PrusaObjectDataViewModelNode(root, root->m_name, icon_solid_mesh, extruder_str, 0); + const auto bmp_solid_mesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG); + const auto node = new PrusaObjectDataViewModelNode(root, root->m_name, bmp_solid_mesh, extruder_str, 0); root->Append(node); // notify control const wxDataViewItem child((void*)node); @@ -795,21 +784,6 @@ wxString PrusaObjectDataViewModel::GetName(const wxDataViewItem &item) const return node->m_name; } -wxString PrusaObjectDataViewModel::GetCopy(const wxDataViewItem &item) const -{ - PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); - if (!node) // happens if item.IsOk()==false - return wxEmptyString; - - return node->m_copy; -} - -// wxIcon& PrusaObjectDataViewModel::GetIcon(const wxDataViewItem &item) const -// { -// PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); -// return node->m_icon; -// } - wxBitmap& PrusaObjectDataViewModel::GetBitmap(const wxDataViewItem &item) const { PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); @@ -823,16 +797,13 @@ void PrusaObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); switch (col) { - case 0:{ + case 0: variant << PrusaDataViewBitmapText(node->m_name, node->m_bmp); - break;} - case 1: - variant = node->m_copy; break; - case 2: + case 1: variant = node->m_extruder; break; - case 3: + case 2: variant << node->m_action_icon; break; default: diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index c1ff4074e..01677809d 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -166,7 +166,7 @@ public: void SetText(const wxString &text) { m_text = text; } wxString GetText() const { return m_text; } - void SetBitmap(const wxIcon &icon) { m_bmp = icon; } + void SetBitmap(const wxBitmap &bmp) { m_bmp = bmp; } const wxBitmap &GetBitmap() const { return m_bmp; } bool IsSameAs(const PrusaDataViewBitmapText& other) const { @@ -214,10 +214,9 @@ class PrusaObjectDataViewModelNode size_t m_volumes_cnt = 0; std::vector< std::string > m_opt_categories; public: - PrusaObjectDataViewModelNode(const wxString &name, const int instances_count=1) { + PrusaObjectDataViewModelNode(const wxString &name) { m_parent = NULL; m_name = name; - m_copy = wxString::Format("%d", instances_count); m_type = itObject; #ifdef __WXGTK__ // it's necessary on GTK because of control have to know if this item will be container @@ -235,7 +234,6 @@ public: const int idx = -1 ) { m_parent = parent; m_name = sub_obj_name; - m_copy = wxEmptyString; m_bmp = bmp; m_type = itVolume; m_idx = idx; @@ -251,7 +249,6 @@ public: PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent, const ItemType type) : m_parent(parent), - m_copy(wxEmptyString), m_type(type), m_extruder(wxEmptyString) { @@ -280,7 +277,6 @@ public: wxString m_name; wxBitmap& m_bmp = m_empty_bmp; - wxString m_copy; ItemType m_type; int m_idx = -1; bool m_container = false; @@ -346,12 +342,9 @@ public: m_name = data.GetText(); return true;} case 1: - m_copy = variant.GetString(); - return true; - case 2: m_extruder = variant.GetString(); return true; - case 3: + case 2: m_action_icon << variant; return true; default: @@ -428,7 +421,6 @@ public: ~PrusaObjectDataViewModel(); wxDataViewItem Add(const wxString &name); - wxDataViewItem Add(const wxString &name, const int instances_count); wxDataViewItem AddVolumeChild(const wxDataViewItem &parent_item, const wxString &name, const wxBitmap& icon, @@ -452,7 +444,6 @@ public: // helper method for wxLog wxString GetName(const wxDataViewItem &item) const; - wxString GetCopy(const wxDataViewItem &item) const; wxBitmap& GetBitmap(const wxDataViewItem &item) const; // helper methods to change the model From fef8d1fe51b96513dfcc18555eaa93f17bbe586c Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Thu, 18 Oct 2018 11:32:21 +0200 Subject: [PATCH 24/24] Fix a color value assert --- src/slic3r/GUI/Field.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 5dbc65877..29d23eee5 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -610,8 +610,13 @@ void ColourPicker::BUILD() if (m_opt.height >= 0) size.SetHeight(m_opt.height); if (m_opt.width >= 0) size.SetWidth(m_opt.width); - wxString clr(static_cast(m_opt.default_value)->get_at(m_opt_idx)); - // FIXME: verify clr is valid, otherwise this causes an assert + // Validate the color + wxString clr_str(static_cast(m_opt.default_value)->get_at(m_opt_idx)); + wxColour clr(clr_str); + if (! clr.IsOk()) { + clr = wxTransparentColour; + } + auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size); // // recast as a wxWindow to fit the calling convention @@ -619,7 +624,7 @@ void ColourPicker::BUILD() temp->Bind(wxEVT_COLOURPICKER_CHANGED, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); - temp->SetToolTip(get_tooltip_text(clr)); + temp->SetToolTip(get_tooltip_text(clr_str)); } boost::any& ColourPicker::get_value(){