diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5fc83870..c6f2951501 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,8 +268,6 @@ set(LIBDIR_BIN ${CMAKE_CURRENT_BINARY_DIR}/src) include_directories(${LIBDIR}) # For generated header files include_directories(${LIBDIR_BIN}/platform) -# For libslic3r.h -include_directories(${LIBDIR}/clipper) if(WIN32) add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) diff --git a/deps/deps-linux.cmake b/deps/deps-linux.cmake index 35522504ca..c81d6785db 100644 --- a/deps/deps-linux.cmake +++ b/deps/deps-linux.cmake @@ -13,7 +13,7 @@ include("deps-unix-common.cmake") ExternalProject_Add(dep_boost EXCLUDE_FROM_ALL 1 - URL "https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz" + URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz" URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./bootstrap.sh @@ -100,5 +100,5 @@ ExternalProject_Add(dep_libcurl BUILD_COMMAND make "-j${NPROC}" INSTALL_COMMAND make install "DESTDIR=${DESTDIR}" ) - add_dependencies(dep_openvdb dep_boost) + diff --git a/deps/deps-macos.cmake b/deps/deps-macos.cmake index 53ba008c3e..de77dafa80 100644 --- a/deps/deps-macos.cmake +++ b/deps/deps-macos.cmake @@ -18,7 +18,7 @@ include("deps-unix-common.cmake") ExternalProject_Add(dep_boost EXCLUDE_FROM_ALL 1 - URL "https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz" + URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz" URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./bootstrap.sh @@ -87,5 +87,5 @@ ExternalProject_Add(dep_libcurl BUILD_COMMAND make "-j${NPROC}" INSTALL_COMMAND make install "DESTDIR=${DESTDIR}" ) +add_dependencies(dep_openvdb dep_boost) -add_dependencies(dep_openvdb dep_boost) \ No newline at end of file diff --git a/deps/deps-mingw.cmake b/deps/deps-mingw.cmake index c97346bb03..cae7fc3719 100644 --- a/deps/deps-mingw.cmake +++ b/deps/deps-mingw.cmake @@ -9,7 +9,7 @@ include("deps-unix-common.cmake") ExternalProject_Add(dep_boost EXCLUDE_FROM_ALL 1 - URL "https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz" + URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz" URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a BUILD_IN_SOURCE 1 CONFIGURE_COMMAND bootstrap.bat @@ -58,4 +58,5 @@ ExternalProject_Add(dep_libcurl -DCURL_DISABLE_GOPHER=ON -DCMAKE_INSTALL_PREFIX=${DESTDIR}/usr/local ${DEP_CMAKE_OPTS} -) \ No newline at end of file +) + diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index c0d80bb291..fc9f55f5f4 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -55,7 +55,7 @@ endmacro() ExternalProject_Add(dep_boost EXCLUDE_FROM_ALL 1 - URL "https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz" + URL "https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz" URL_HASH SHA256=aeb26f80e80945e82ee93e5939baebdca47b9dee80a07d3144be1e1a6a66dd6a BUILD_IN_SOURCE 1 CONFIGURE_COMMAND bootstrap.bat @@ -295,4 +295,5 @@ if (${DEP_DEBUG}) COMMAND msbuild /m /P:Configuration=Debug INSTALL.vcxproj WORKING_DIRECTORY "${BINARY_DIR}" ) -endif () \ No newline at end of file +endif () + diff --git a/resources/icons/info.png b/resources/icons/info.png new file mode 100644 index 0000000000..9eeee9b3cd Binary files /dev/null and b/resources/icons/info.png differ diff --git a/resources/icons/splashscreen-gcodepreview.jpg b/resources/icons/splashscreen-gcodepreview.jpg index 3bae384935..481c4a6e12 100644 Binary files a/resources/icons/splashscreen-gcodepreview.jpg and b/resources/icons/splashscreen-gcodepreview.jpg differ diff --git a/resources/icons/splashscreen.jpg b/resources/icons/splashscreen.jpg index 754e245880..08236bcccc 100644 Binary files a/resources/icons/splashscreen.jpg and b/resources/icons/splashscreen.jpg differ diff --git a/resources/profiles/Anycubic.idx b/resources/profiles/Anycubic.idx index b57fe3e660..cc3b55ef4c 100644 --- a/resources/profiles/Anycubic.idx +++ b/resources/profiles/Anycubic.idx @@ -1,11 +1,14 @@ -min_slic3r_version = 2.3.0-beta2 -0.0.8 Updated start and end g-code for Anycubic Mega. -0.0.7 Updated start g-code for Anycubic Mega. -0.0.6 Reduced max print height for Predator. Updated end g-code, before layer change g-code and output filename format for Kossel. -0.0.5 Updated end g-code. -min_slic3r_version = 2.3.0-alpha2 -0.0.4 Fixed predator output filename format, infill overlap, start gcode adjustments. -0.0.3 Fixed infill_overlap, start_gcode, end_gcode for Anycubic Predator -0.0.2 Added Anycubic Predator -min_slic3r_version = 2.3.0-alpha0 -0.0.1 Initial Version +min_slic3r_version = 2.3.1-beta +0.0.10 Various updates for Anycubic Mega. Added filament profiles. +0.0.9 Updated bed textures +min_slic3r_version = 2.3.0-beta2 +0.0.8 Updated start and end g-code for Anycubic Mega. +0.0.7 Updated start g-code for Anycubic Mega. +0.0.6 Reduced max print height for Predator. Updated end g-code, before layer change g-code and output filename format for Kossel. +0.0.5 Updated end g-code. +min_slic3r_version = 2.3.0-alpha2 +0.0.4 Fixed predator output filename format, infill overlap, start gcode adjustments. +0.0.3 Fixed infill_overlap, start_gcode, end_gcode for Anycubic Predator +0.0.2 Added Anycubic Predator +min_slic3r_version = 2.3.0-alpha0 +0.0.1 Initial Version diff --git a/resources/profiles/Anycubic.ini b/resources/profiles/Anycubic.ini index 639d5df475..ff03672910 100644 --- a/resources/profiles/Anycubic.ini +++ b/resources/profiles/Anycubic.ini @@ -5,7 +5,7 @@ name = Anycubic # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.0.8 +config_version = 0.0.10 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Anycubic/ # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% @@ -76,7 +76,7 @@ bridge_flow_ratio = 0.8 bridge_speed = 30 brim_width = 0 clip_multipart_objects = 1 -compatible_printers = +compatible_printers = complete_objects = 0 dont_support_bridges = 1 elefant_foot_compensation = 0 @@ -108,7 +108,7 @@ max_volumetric_extrusion_rate_slope_negative = 0 max_volumetric_extrusion_rate_slope_positive = 0 max_volumetric_speed = 0 min_skirt_length = 4 -notes = +notes = overhangs = 0 only_retract_when_crossing_perimeters = 0 ooze_prevention = 0 @@ -117,8 +117,8 @@ perimeters = 2 perimeter_extruder = 1 perimeter_extrusion_width = 0.45 perimeter_speed = 45 -post_process = -print_settings_id = +post_process = +print_settings_id = raft_layers = 0 resolution = 0 seam_position = nearest @@ -290,7 +290,7 @@ compatible_printers_condition = printer_notes=~/.*PRINTER_MODEL_AK(|LP).*/ and n # Common filament preset [filament:*common_akossel*] cooling = 0 -compatible_printers = +compatible_printers = extrusion_multiplier = 1 filament_cost = 0 filament_density = 0 @@ -375,9 +375,9 @@ filament_vendor = Generic # Common printer preset [printer:*common_akossel*] printer_technology = FFF -bed_shape = +bed_shape = before_layer_gcode = ;BEFORE_LAYER_CHANGE\nG92 E0\n;[layer_z] -between_objects_gcode = +between_objects_gcode = deretract_speed = 40 extruder_colour = #FFFF00 extruder_offset = 0x0 @@ -405,8 +405,8 @@ max_layer_height = 0.3 min_layer_height = 0.08 max_print_height = 300 nozzle_diameter = 0.4 -printer_notes = -printer_settings_id = +printer_notes = +printer_settings_id = retract_before_travel = 2 retract_before_wipe = 70% retract_layer_change = 1 @@ -419,9 +419,9 @@ retract_restart_extra = 0 retract_restart_extra_toolchange = 0 retract_speed = 60 single_extruder_multi_material = 0 -start_gcode = +start_gcode = end_gcode = M104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nG28 ; home\nM84 ; disable motors -toolchange_gcode = +toolchange_gcode = use_firmware_retraction = 0 use_relative_e_distances = 1 use_volumetric_e = 0 @@ -435,7 +435,7 @@ default_filament_profile = Generic PLA @AKOSSEL inherits = *common_akossel* printer_model = AKLP printer_variant = 0.4 -printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_Anycubic\nPRINTER_MODEL_AKLP\nPRINTER_HAS_BOWDEN\n +printer_notes = Do not remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_Anycubic\nPRINTER_MODEL_AKLP\nPRINTER_HAS_BOWDEN\n bed_shape = 114.562x10.0229,113.253x19.9695,111.081x29.7642,108.065x39.3323,104.225x48.6011,99.5929x57.5,94.2025x65.9613,88.0951x73.9206,81.3173x81.3173,73.9206x88.0951,65.9613x94.2025,57.5x99.5929,48.6011x104.225,39.3323x108.065,29.7642x111.081,19.9695x113.253,10.0229x114.562,7.04172e-15x115,-10.0229x114.562,-19.9695x113.253,-29.7642x111.081,-39.3323x108.065,-48.6011x104.225,-57.5x99.5929,-65.9613x94.2025,-73.9206x88.0951,-81.3173x81.3173,-88.0951x73.9206,-94.2025x65.9613,-99.5929x57.5,-104.225x48.6011,-108.065x39.3323,-111.081x29.7642,-113.253x19.9695,-114.562x10.0229,-115x1.40834e-14,-114.562x-10.0229,-113.253x-19.9695,-111.081x-29.7642,-108.065x-39.3323,-104.225x-48.6011,-99.5929x-57.5,-94.2025x-65.9613,-88.0951x-73.9206,-81.3173x-81.3173,-73.9206x-88.0951,-65.9613x-94.2025,-57.5x-99.5929,-48.6011x-104.225,-39.3323x-108.065,-29.7642x-111.081,-19.9695x-113.253,-10.0229x-114.562,-2.11252e-14x-115,10.0229x-114.562,19.9695x-113.253,29.7642x-111.081,39.3323x-108.065,48.6011x-104.225,57.5x-99.5929,65.9613x-94.2025,73.9206x-88.0951,81.3173x-81.3173,88.0951x-73.9206,94.2025x-65.9613,99.5929x-57.5,104.225x-48.6011,108.065x-39.3323,111.081x-29.7642,113.253x-19.9695,114.562x-10.0229,115x-2.81669e-14 start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 ; home\nG1 X-54.672 Y95.203 Z0.3 F9000\nG92 E0.0\nG1 F1000\nG1 X-52.931 Y96.185 E0.300\nG1 X-50.985 Y97.231 E0.331\nG1 X-49.018 Y98.238 E0.331\nG1 X-47.032 Y99.205 E0.331\nG1 X-45.026 Y100.132 E0.331\nG1 X-43.003 Y101.019 E0.331\nG1 X-40.961 Y101.864 E0.331\nG1 X-38.904 Y102.668 E0.331\nG1 X-36.83 Y103.431 E0.331\nG1 X-34.742 Y104.152 E0.331\nG1 X-32.639 Y104.83 E0.331\nG1 X-30.523 Y105.466 E0.331\nG1 X-28.395 Y106.06 E0.331\nG1 X-26.255 Y106.61 E0.331\nG1 X-24.105 Y107.117 E0.331\nG1 X-21.945 Y107.581 E0.331\nG1 X-19.776 Y108.001 E0.331\nG1 X-17.599 Y108.377 E0.331\nG1 X-15.415 Y108.71 E0.331\nG1 X-13.224 Y108.998 E0.331\nG1 X-11.028 Y109.242 E0.331\nG1 X-8.828 Y109.442 E0.331\nG1 X-6.624 Y109.598 E0.331\nG1 X-4.418 Y109.709 E0.331\nG1 X-2.209 Y109.776 E0.332\nG1 X0 Y109.798 E0.331\nG1 X2.209 Y109.776 E0.690\nG1 X4.418 Y109.709 E0.691\nG1 X6.624 Y109.598 E0.690\nG1 X8.828 Y109.442 E0.690\nG1 X11.028 Y109.242 E0.690\nG1 X13.224 Y108.998 E0.690\nG1 X15.415 Y108.71 E0.691\nG1 X17.599 Y108.377 E0.690\nG1 X19.776 Y108.001 E0.690\nG1 X21.945 Y107.581 E0.690\nG1 X24.105 Y107.117 E0.690\nG1 X26.255 Y106.61 E0.690\nG1 X28.395 Y106.06 E0.690\nG1 X30.523 Y105.466 E0.690\nG1 X32.639 Y104.83 E0.690\nG1 X34.742 Y104.152 E0.690\nG1 X36.83 Y103.431 E0.690\nG1 X38.904 Y102.668 E0.691\nG1 X40.961 Y101.864 E0.690\nG1 X43.003 Y101.019 E0.691\nG1 X45.026 Y100.132 E0.690\nG1 X47.032 Y99.205 E0.691\nG1 X49.018 Y98.238 E0.690\nG1 X50.985 Y97.231 E0.691\nG1 X52.931 Y96.185 E0.690\nG1 X54.672 Y95.203 E0.625\nG92 E0.0\nG1 E-5 F3000 ; retract 5mm\nG1 X52.931 Y96.185 F1000 ; wipe\nG1 X50.985 Y97.231 F1000 ; wipe\nG1 X49.018 Y98.238 F1000 ; wipe\nG1 X0 Y109.798 F1000\nG1 E4.8 F1500; de-retract\nG92 E0.0 ; reset extrusion distance\nM221 S{if layer_height<0.075}100{else}95{endif} @@ -443,7 +443,7 @@ start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 inherits = *common_akossel* printer_model = AK printer_variant = 0.4 -printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_Anycubic\nPRINTER_MODEL_AK\nPRINTER_HAS_BOWDEN\n +printer_notes = Do not remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_Anycubic\nPRINTER_MODEL_AK\nPRINTER_HAS_BOWDEN\n bed_shape = 89.6575x7.84402,88.6327x15.6283,86.9333x23.2937,84.5723x30.7818,81.5677x38.0356,77.9423x45,73.7237x51.6219,68.944x57.8509,63.6396x63.6396,57.8509x68.944,51.6219x73.7237,45x77.9423,38.0356x81.5677,30.7818x84.5723,23.2937x86.9333,15.6283x88.6327,7.84402x89.6575,5.51091e-15x90,-7.84402x89.6575,-15.6283x88.6327,-23.2937x86.9333,-30.7818x84.5723,-38.0356x81.5677,-45x77.9423,-51.6219x73.7237,-57.8509x68.944,-63.6396x63.6396,-68.944x57.8509,-73.7237x51.6219,-77.9423x45,-81.5677x38.0356,-84.5723x30.7818,-86.9333x23.2937,-88.6327x15.6283,-89.6575x7.84402,-90x1.10218e-14,-89.6575x-7.84402,-88.6327x-15.6283,-86.9333x-23.2937,-84.5723x-30.7818,-81.5677x-38.0356,-77.9423x-45,-73.7237x-51.6219,-68.944x-57.8509,-63.6396x-63.6396,-57.8509x-68.944,-51.6219x-73.7237,-45x-77.9423,-38.0356x-81.5677,-30.7818x-84.5723,-23.2937x-86.9333,-15.6283x-88.6327,-7.84402x-89.6575,-1.65327e-14x-90,7.84402x-89.6575,15.6283x-88.6327,23.2937x-86.9333,30.7818x-84.5723,38.0356x-81.5677,45x-77.9423,51.6219x-73.7237,57.8509x-68.944,63.6396x-63.6396,68.944x-57.8509,73.7237x-51.6219,77.9423x-45,81.5677x-38.0356,84.5723x-30.7818,86.9333x-23.2937,88.6327x-15.6283,89.6575x-7.84402,90x-2.20436e-14 start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 ; home\nG1 X-39.672 Y69.712 Z0.3 F9000\nG92 E0.0\nG1 F1000\nG1 X-38.457 Y70.397 E0.209\nG1 X-37.043 Y71.157 E0.241\nG1 X-35.614 Y71.889 E0.241\nG1 X-34.171 Y72.591 E0.241\nG1 X-32.714 Y73.265 E0.241\nG1 X-31.244 Y73.909 E0.241\nG1 X-29.761 Y74.523 E0.241\nG1 X-28.266 Y75.108 E0.241\nG1 X-26.759 Y75.662 E0.241\nG1 X-25.242 Y76.185 E0.241\nG1 X-23.714 Y76.678 E0.241\nG1 X-22.177 Y77.14 E0.241\nG1 X-20.63 Y77.571 E0.241\nG1 X-19.076 Y77.971 E0.241\nG1 X-17.514 Y78.34 E0.241\nG1 X-15.944 Y78.677 E0.241\nG1 X-14.368 Y78.982 E0.241\nG1 X-12.786 Y79.255 E0.241\nG1 X-11.199 Y79.497 E0.241\nG1 X-9.608 Y79.706 E0.241\nG1 X-8.013 Y79.884 E0.241\nG1 X-6.414 Y80.029 E0.241\nG1 X-4.813 Y80.142 E0.241\nG1 X-3.21 Y80.223 E0.241\nG1 X-1.605 Y80.271 E0.241\nG1 X0 Y80.287 E0.241\nG1 X1.605 Y80.271 E0.502\nG1 X3.21 Y80.223 E0.502\nG1 X4.813 Y80.142 E0.502\nG1 X6.414 Y80.029 E0.502\nG1 X8.013 Y79.884 E0.502\nG1 X9.608 Y79.706 E0.502\nG1 X11.199 Y79.497 E0.501\nG1 X12.786 Y79.255 E0.502\nG1 X14.368 Y78.982 E0.502\nG1 X15.944 Y78.677 E0.502\nG1 X17.514 Y78.34 E0.502\nG1 X19.076 Y77.971 E0.502\nG1 X20.63 Y77.571 E0.501\nG1 X22.177 Y77.14 E0.502\nG1 X23.714 Y76.678 E0.502\nG1 X25.242 Y76.185 E0.502\nG1 X26.759 Y75.662 E0.501\nG1 X28.266 Y75.108 E0.502\nG1 X29.761 Y74.523 E0.502\nG1 X31.244 Y73.909 E0.502\nG1 X32.714 Y73.265 E0.502\nG1 X34.171 Y72.591 E0.502\nG1 X35.614 Y71.889 E0.501\nG1 X37.043 Y71.157 E0.502\nG1 X38.457 Y70.397 E0.502\nG1 X39.672 Y69.712 E0.436\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif} @@ -784,7 +784,7 @@ printer_model = MEGA0 printer_variant = 0.4 max_layer_height = 0.3 min_layer_height = 0.1 -printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_ANYCUBIC\nPRINTER_MODEL_MEGA0 +printer_notes = Do not remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_ANYCUBIC\nPRINTER_MODEL_MEGA0 bed_shape = 0x0,220x0,220x220,0x220 max_print_height = 250 machine_max_acceleration_e = 5000 @@ -822,54 +822,61 @@ end_gcode = M117 Cooling down...\nM104 S0 ; turn off extruder\nM107 ; Fan off\nM [print:*common_mega*] bottom_solid_min_thickness = 0.5 -bridge_acceleration = 1800 -bridge_flow_ratio = 0.8 +bridge_acceleration = 1000 +bridge_flow_ratio = 0.95 bridge_speed = 30 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_ANYCUBIC.*/ and printer_notes=~/.*PRINTER_MODEL_I3_MEGA.*/ and nozzle_diameter[0]==0.4 -default_acceleration = 1800 +default_acceleration = 1000 ensure_vertical_shell_thickness = 1 -external_perimeter_extrusion_width = 0.6 -external_perimeter_speed = 40 +external_perimeter_extrusion_width = 0.45 +external_perimeter_speed = 25 extruder_clearance_height = 35 extruder_clearance_radius = 60 extrusion_width = 0.45 fill_density = 15% fill_pattern = gyroid -first_layer_acceleration = 1800 +first_layer_acceleration = 1000 first_layer_extrusion_width = 0.42 first_layer_height = 0.2 +first_layer_speed = 20 gap_fill_speed = 40 gcode_comments = 1 -infill_acceleration = 1800 +infill_acceleration = 1000 +infill_anchor = 2.5 +infill_anchor_max = 12 infill_extrusion_width = 0.45 -infill_speed = 60 +max_print_speed = 200 +min_skirt_length = 4 only_retract_when_crossing_perimeters = 0 -output_filename_format = {input_filename_base}_{nozzle_diameter[0]}n_{layer_height}mm_{filament_type[0]}_{printer_model}_{print_time}.gcode -perimeter_acceleration = 1800 +output_filename_format = {input_filename_base}_{layer_height}mm_{filament_type[0]}_{printer_model}_{print_time}.gcode +perimeter_acceleration = 800 perimeter_extrusion_width = 0.45 +perimeter_speed = 45 perimeters = 2 seam_position = nearest -skirts = 0 -slice_closing_radius = 0.05 -small_perimeter_speed = 30 +skirt_distance = 2 +skirt_height = 3 +skirts = 1 +small_perimeter_speed = 25 solid_infill_below_area = 0 -solid_infill_speed = 60 +solid_infill_extrusion_width = 0.45 +solid_infill_speed = 80 support_material_buildplate_only = 1 support_material_contact_distance = 0.1 support_material_extrusion_width = 0.35 support_material_interface_layers = 2 support_material_interface_spacing = 0.2 support_material_spacing = 2 +support_material_speed = 50 support_material_threshold = 55 -support_material_with_sheath = 0 thin_walls = 0 top_infill_extrusion_width = 0.4 top_solid_infill_speed = 40 +top_solid_layers = 5 top_solid_min_thickness = 0.6 travel_speed = 180 [print:*supported_mega*] -raft_layers = 2 support_material = 1 # XXXXXXXXXXXXXXXXXXXX @@ -911,7 +918,19 @@ inherits = *0.20mm_mega*;*supported_mega* [print:*0.30mm_mega*] inherits = *common_mega* bottom_solid_layers = 4 -bridge_flow_ratio = 0.95 +external_perimeter_extrusion_width = 0.6 +external_perimeter_speed = 35 +extrusion_width = 0.5 +fill_pattern = grid +infill_extrusion_width = 0.5 +infill_speed = 85 +layer_height = 0.3 +perimeter_extrusion_width = 0.5 +perimeter_speed = 50 +small_perimeter_speed = 30 +solid_infill_extrusion_width = 0.5 +support_material_extrusion_width = 0.38 +support_material_speed = 45 top_solid_layers = 4 [print:0.30mm DRAFT @MEGA] @@ -929,7 +948,6 @@ compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_ANYCUBIC.*/ and end_filament_gcode = "; Filament-specific end gcode" fan_always_on = 1 fan_below_layer_time = 100 -filament_colour = #FF8000 filament_vendor = Generic min_print_speed = 15 slowdown_below_layer_time = 20 @@ -941,13 +959,13 @@ slowdown_below_layer_time = 20 cooling = 0 fan_always_on = 0 fan_below_layer_time = 20 - filament_colour = #FFF2EC + filament_colour = #3A80CA filament_cost = 27.82 filament_density = 1.04 filament_max_volumetric_speed = 11 filament_ramming_parameters = "120 100 5.70968 6.03226 7 8.25806 9 9.19355 9.3871 9.77419 10.129 10.3226 10.4516 10.5161| 0.05 5.69677 0.45 6.15484 0.95 8.76774 1.45 9.20323 1.95 9.95806 2.45 10.3871 2.95 10.5677 3.45 7.6 3.95 7.6 4.45 7.6 4.95 7.6" filament_type = ABS - first_layer_bed_temperature = 100 + first_layer_bed_temperature = 105 first_layer_temperature = 255 max_fan_speed = 30 min_fan_speed = 20 @@ -955,14 +973,14 @@ slowdown_below_layer_time = 20 [filament:Generic ABS @MEGA] inherits = *ABS_mega* - + [filament:*FLEX_mega*] inherits = *common_mega* bed_temperature = 50 bridge_fan_speed = 80 cooling = 0 extrusion_multiplier = 1.15 -fan_always_on = 0 +fan_always_on = 0 filament_colour = #008000 filament_cost = 82.00 filament_density = 1.22 @@ -970,7 +988,7 @@ filament_deretract_speed = 25 filament_max_volumetric_speed = 1.2 filament_retract_length = 0.8 filament_type = FLEX -first_layer_bed_temperature = 50 +first_layer_bed_temperature = 55 first_layer_temperature = 240 max_fan_speed = 90 min_fan_speed = 70 @@ -979,16 +997,41 @@ temperature = 240 [filament:Generic FLEX @MEGA] inherits = *FLEX_mega* +[filament:SainSmart TPU @MEGA] +inherits = *FLEX_mega* +filament_vendor = SainSmart +bed_temperature = 50 +bridge_fan_speed = 100 +cooling = 1 +disable_fan_first_layers = 4 +filament_cost = 39.99 +filament_density = 1.21 +filament_deretract_speed = 15 +filament_max_volumetric_speed = 1.8 +filament_notes = "SainSmart TPU gains popularity among 3D Printing community for its balance of rigidity and flexibility. In addition, with a 95A Shore Hardness and improved bed adhesion, it is easier to print even with a stock elementary 3D Printer like the Creality Ender 3. SainSmart TPU will not disappoint if you are looking for flexible filament. From drone parts, phone cases, to small toys, all can be printed with ease.\n\nhttps://www.sainsmart.com/collections/tpu-filament/products/all-colors-tpu-flexible-filament-1-75mm-0-8kg-1-76lb" +filament_retract_before_travel = 5 +filament_retract_length = 4 +filament_retract_speed = 40 +filament_unloading_speed = 90 +first_layer_bed_temperature = 55 +first_layer_temperature = 235 +full_fan_speed_layer = 6 +max_fan_speed = 80 +min_fan_speed = 80 +slowdown_below_layer_time = 10 +temperature = 235 + [filament:*PETG_mega*] inherits = *common_mega* bed_temperature = 90 bridge_fan_speed = 50 fan_below_layer_time = 20 +filament_colour = #FF8000 filament_cost = 27.82 filament_density = 1.27 filament_max_volumetric_speed = 8 filament_type = PETG -first_layer_bed_temperature = 85 +first_layer_bed_temperature = 90 first_layer_temperature = 230 max_fan_speed = 50 min_fan_speed = 30 @@ -997,14 +1040,63 @@ temperature = 240 [filament:Generic PETG @MEGA] inherits = *PETG_mega* +[filament:ColorFabb XT-CF20 @MEGA] +inherits = *PETG_mega* +compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_notes=~/.*PRINTER_VENDOR_ANYCUBIC.*/ and printer_notes=~/.*PRINTER_MODEL_I3_MEGA.*/ +extrusion_multiplier = 1.05 +filament_colour = #804040 +filament_cost = 66.60 +filament_density = 1.35 +filament_deretract_speed = 25 +filament_max_volumetric_speed = 2 +filament_notes = "Based on colorFabb_XT, XT-CF20 is a carbon fiber composite material. Loaded with no less than 20% specially sourced carbon fibers we have developed a very stiff and tough 3D printing filament made for functional parts. It is truly a professional printers go-to material, especially for users looking for high melt strength, high melt viscosity and good dimensional accuracy and stability.\n\nhttps://colorfabb.com/xt-cf20" +filament_retract_before_travel = 1 +filament_retract_length = 1.4 +filament_retract_speed = 40 +filament_spool_weight = 236 +filament_vendor = ColorFabb +first_layer_temperature = 260 +full_fan_speed_layer = 5 +slowdown_below_layer_time = 15 +temperature = 260 + +[filament:ERYONE PETG @MEGA] +inherits = *PETG_mega* +filament_vendor = ERYONE +filament_cost = 20.99 +filament_notes = "https://eryone.com/petg/show/10.html" + +[filament:FormFutura HDglass @MEGA] +inherits = *PETG_mega* +filament_vendor = FormFutura +filament_cost = 46.65 +filament_notes = "HDglass is a high performance PETG type of 3D printer with unsurpassed 3D printing properties and improved mechanical strength, flexibility, toughness and heat resistance.\n\nhttps://www.formfutura.com/shop/product/hdglass-2812" + +[filament:FormFutura ReForm rPET @MEGA] +inherits = *PETG_mega* +filament_vendor = FormFutura +filament_cost = 26.65 +filament_notes = "ReForm rPET is a recycled PETG type of 3D printer filament that is made from post-industrial waste streams of a nearby located plastic bottle manufacturer.\n\nhttps://www.formfutura.com/shop/product/reform-rpet-2836" +filament_spool_weight = 176 + +[filament:Janbex transparent PETG @MEGA] +inherits = *PETG_mega* +filament_vendor = Janbex +filament_cost = 31.99 +filament_spool_weight = 222 +first_layer_temperature = 215 +min_fan_speed = 100 +temperature = 210 + [filament:*PLA_mega*] inherits = *common_mega* bed_temperature = 60 disable_fan_first_layers = 1 +filament_colour = #FF3232 filament_cost = 25.40 filament_density = 1.24 filament_max_volumetric_speed = 10 -first_layer_bed_temperature = 60 +first_layer_bed_temperature = 65 first_layer_temperature = 215 min_fan_speed = 100 temperature = 210 @@ -1012,73 +1104,97 @@ temperature = 210 [filament:Generic PLA @MEGA] inherits = *PLA_mega* -[filament:*3Dmensionals PLA_mega*] +[filament:3Dmensionals PLA @MEGA] inherits = *PLA_mega* filament_vendor = 3Dmensionals -filament_cost = 23.35 +filament_cost = 22.90 +filament_notes = "Das 3DFilaments - PLA von 3Dmensionals ist ein sehr leicht zu druckendes 3D-Drucker Filament. Dabei handelt es sich um ein etwas härteres PLA mit einer exzellenten thermischen Stabilität. Das Filament zeichnet sich vor allem durch verzugfreies 3D-Drucken aus und weist minimale bis keine Verformung nach dem Abkühlen auf. Daher ist es besonders gut für den Druck größerer Objekte geeignet. Zudem bietet 3DFilaments - PLA über die gesamte Fadenläge eine hervorragende Durchmesser- und Rundheitstoleranz.\n\nhttps://www.3dmensionals.de/3dfilaments?number=PSU3DM001V" -[filament:3Dmensionals PLA @MEGA] -inherits = *3Dmensionals PLA_mega* +[filament:3D Warhorse PLA @MEGA] +inherits = *PLA_mega* +filament_vendor = 3D Warhorse +filament_cost = 19.99 -[filament:3Dmensionals PLA blue @MEGA] -inherits = *3Dmensionals PLA_mega* -filament_colour = #4155FB +[filament:AMOLEN wood PLA] +inherits = *PLA_mega* +filament_vendor = AMOLEN +compatible_printers_condition = nozzle_diameter[0]>0.35 and printer_notes=~/.*PRINTER_VENDOR_ANYCUBIC.*/ and printer_notes=~/.*PRINTER_MODEL_I3_MEGA.*/ +extrusion_multiplier = 1.1 +filament_colour = #DFC287 +filament_cost = 33.99 +filament_density = 1.23 +filament_max_volumetric_speed = 9 +filament_notes = "https://amolen.com/collections/wood/products/amolen-pla-filament-1-75mm-wood-color-3d-printer-filament-1kg2-2lb" -[filament:3Dmensionals PLA silver @MEGA] -inherits = *3Dmensionals PLA_mega* -filament_colour = #B9B5B4 +[filament:FormFutura EasyFil PLA @MEGA] +inherits = *PLA_mega* +filament_vendor = FormFutura +filament_cost = 39.93 +filament_notes = "EasyFil PLA is an easy to print PLA type of 3D printer filament that is available in a wide variety of colors. Its improved flowing behavior make 3D printed layers flow more into each other.\n\nhttps://www.formfutura.com/shop/product/easyfil-pla-2801" -[filament:3Dmensionals PLA white @MEGA] -inherits = *3Dmensionals PLA_mega* -filament_colour = #FEFEFD +[filament:FormFutura ReForm rPLA @MEGA] +inherits = *PLA_mega* +filament_vendor = FormFutura +filament_cost = 26.65 +filament_notes = "ReForm is a sustainable initiative within Formfutura to efficiently manage residual extrusion waste streams and re-use them into high-end upcycled filaments. The ideology behind ReForm is to a make 3D printing more sustainable – without having to make compromises on material properties – and yet keep it affordable.\n\nhttps://www.formfutura.com/shop/product/reform-rpla-2838" -[filament:*Verbatim PLA_mega*] +[filament:GIANTARM PLA @MEGA] +inherits = *PLA_mega* +filament_vendor = GIANTARM +filament_cost = 24.99 + +[filament:Prusament PLA @MEGA] +inherits = *PLA_mega* +filament_vendor = Prusa Polymers +filament_cost = 30.24 +filament_notes = "Affordable filament for everyday printing in premium quality manufactured in-house by Josef Prusa" +filament_spool_weight = 201 +temperature = 215 + +[filament:Verbatim PLA @MEGA] inherits = *PLA_mega* filament_vendor = Verbatim filament_cost = 23.88 -[filament:Verbatim PLA @MEGA] -inherits = *Verbatim PLA_mega* - -[filament:Verbatim PLA black @MEGA] -inherits = *Verbatim PLA_mega* -filament_colour = #333333 - [printer:*common_mega*] printer_technology = FFF bed_shape = 0x0,210x0,210x210,0x210 -before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z] +before_layer_gcode = ;BEFORE_LAYER_CHANGE\nG92 E0.0\n;[layer_z] default_filament_profile = Generic PLA @MEGA default_print_profile = 0.15mm QUALITY @MEGA -deretract_speed = 50 -end_gcode = G4 ; wait\nG92 E0\nG1{if max_layer_z < max_print_height} Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; move print head up\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nG1 X0 Y200 F3000 ; home X axis\nM84 ; disable motors +deretract_speed = 40 +end_gcode = G1 E-1.0 F2100 ; retract\nG92 E0.0\nG1{if max_layer_z < max_print_height} Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; move print head up\nG4 ; wait\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nG1 X0 Y105 F3000 ; park print head\nM84 ; disable motors extruder_colour = #808080 gcode_flavor = marlin layer_gcode = ;AFTER_LAYER_CHANGE\n;[layer_z] max_layer_height = 0.36 max_print_height = 205 +remaining_times = 1 +retract_before_travel = 1.5 retract_before_wipe = 60% retract_layer_change = 1 -retract_length = 6 -retract_lift = 0.075 +retract_length = 3.2 +retract_lift = 0.2 retract_lift_below = 204 +retract_speed = 70 silent_mode = 0 -start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting]\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nG28 ; home all\nG1 Y0 Z1 F100 ; move print head up\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG92 E0\nG1 Z0.2 F360\nG1 X60 E9 F700 ; intro line\nG1 X100 E12.5 F700 ; intro line\nG92 E0 +start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting]\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nG28 ; home all\nG1 Y2.0 Z0.2 F1000 ; move print head up\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG92 E0.0\nG1 X60.0 E9.0 F1000 ; intro line\nG1 X100.0 E12.5 F1000 ; intro line\nG92 E0.0 +thumbnails = 16x16,220x124 use_relative_e_distances = 1 wipe = 1 -machine_max_acceleration_e = 5000 +machine_max_acceleration_e = 10000 machine_max_acceleration_extruding = 1250 machine_max_acceleration_retracting = 1250 -machine_max_acceleration_x = 1000 -machine_max_acceleration_y = 1000 -machine_max_acceleration_z = 200 +machine_max_acceleration_x = 3000 +machine_max_acceleration_y = 2000 +machine_max_acceleration_z = 60 machine_max_feedrate_e = 60 -machine_max_feedrate_x = 200 -machine_max_feedrate_y = 200 +machine_max_feedrate_x = 500 +machine_max_feedrate_y = 500 machine_max_feedrate_z = 6 machine_max_jerk_e = 5 -machine_max_jerk_x = 8 -machine_max_jerk_y = 8 +machine_max_jerk_x = 10 +machine_max_jerk_y = 10 machine_max_jerk_z = 0.4 [printer:Anycubic i3 Mega] @@ -1092,6 +1208,7 @@ inherits = *common_mega* printer_model = I3MEGAS printer_variant = 0.4 printer_notes = Do not remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_ANYCUBIC\nPRINTER_MODEL_I3_MEGA_S\nPRINTER_HAS_BOWDEN +machine_max_feedrate_e = 30 machine_max_feedrate_z = 8 @@ -1743,7 +1860,7 @@ machine_max_jerk_z = 5 machine_min_extruding_rate = 0 machine_min_travel_rate = 0 printer_settings_id = -printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_ANYCUBIC\nPRINTER_MODEL_PREDATOR\nPRINTER_HAS_BOWDEN\n +printer_notes = Do not remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_ANYCUBIC\nPRINTER_MODEL_PREDATOR\nPRINTER_HAS_BOWDEN\n default_filament_profile = Generic PLA @PREDATOR [printer:Anycubic Predator 0.4 nozzle] @@ -1775,4 +1892,4 @@ default_print_profile = 0.24mm 0.8 nozzle DETAILED QUALITY @PREDATOR ######################################### ########## end printer presets ########## -######################################### +#########################################"do not" cause ' is bad for syntax highlighting diff --git a/resources/profiles/Anycubic/i3megas.svg b/resources/profiles/Anycubic/i3megas.svg new file mode 100644 index 0000000000..dfb4ae4969 --- /dev/null +++ b/resources/profiles/Anycubic/i3megas.svg @@ -0,0 +1,561 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/profiles/Anycubic/i3megas_bed.stl b/resources/profiles/Anycubic/i3megas_bed.stl new file mode 100644 index 0000000000..49ff8c5b3b Binary files /dev/null and b/resources/profiles/Anycubic/i3megas_bed.stl differ diff --git a/resources/profiles/Artillery.idx b/resources/profiles/Artillery.idx index 1fa68f82b5..d1e3657728 100644 --- a/resources/profiles/Artillery.idx +++ b/resources/profiles/Artillery.idx @@ -1,2 +1,2 @@ -min_slic3r_version = 2.4.0-alpha0 +min_slic3r_version = 2.3.1-beta 0.0.1 Initial Artillery bundle diff --git a/resources/profiles/Artillery/genius_thumbnail.png b/resources/profiles/Artillery/Genius_thumbnail.png similarity index 100% rename from resources/profiles/Artillery/genius_thumbnail.png rename to resources/profiles/Artillery/Genius_thumbnail.png diff --git a/resources/profiles/Artillery/x1_thumbnail.png b/resources/profiles/Artillery/X1_thumbnail.png similarity index 100% rename from resources/profiles/Artillery/x1_thumbnail.png rename to resources/profiles/Artillery/X1_thumbnail.png diff --git a/resources/profiles/Creality.idx b/resources/profiles/Creality.idx index 328ae4cf33..c1242f27ec 100644 --- a/resources/profiles/Creality.idx +++ b/resources/profiles/Creality.idx @@ -1,3 +1,6 @@ +min_slic3r_version = 2.3.1-beta +0.0.16 Updated CR6-SE start g-code. Added and updated filament profiles. +0.0.15 Added new printer models, filament profiles. Various improvements. min_slic3r_version = 2.3.0-rc2 0.0.14 Optimized start g-code. Added filament profile. Various improvements. 0.0.13 Optimized start and end g-code. General improvements. diff --git a/resources/profiles/Creality.ini b/resources/profiles/Creality.ini index 1c11210dee..5248155250 100644 --- a/resources/profiles/Creality.ini +++ b/resources/profiles/Creality.ini @@ -5,7 +5,7 @@ name = Creality # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.0.14 +config_version = 0.0.16 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Creality/ # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% @@ -21,7 +21,7 @@ technology = FFF family = ENDER bed_model = ender3_bed.stl bed_texture = ender3.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER3BLTOUCH] name = Creality Ender-3 BLTouch @@ -30,7 +30,7 @@ technology = FFF family = ENDER bed_model = ender3_bed.stl bed_texture = ender3.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER3V2] name = Creality Ender-3 V2 @@ -39,7 +39,7 @@ technology = FFF family = ENDER bed_model = ender3v2_bed.stl bed_texture = ender3v2.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER3MAX] name = Creality Ender-3 Max @@ -48,7 +48,7 @@ technology = FFF family = ENDER bed_model = cr10v2_bed.stl bed_texture = cr10spro.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER4] name = Creality Ender-4 @@ -57,7 +57,7 @@ technology = FFF family = ENDER bed_model = ender3v2_bed.stl bed_texture = ender3v2.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER5] name = Creality Ender-5 @@ -66,7 +66,7 @@ technology = FFF family = ENDER bed_model = ender3_bed.stl bed_texture = ender3.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER5PLUS] name = Creality Ender-5 Plus @@ -75,7 +75,7 @@ technology = FFF family = ENDER bed_model = ender5plus_bed.stl bed_texture = ender5plus.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER6] name = Creality Ender-6 @@ -84,7 +84,7 @@ technology = FFF family = ENDER bed_model = ender6_bed.stl bed_texture = ender6.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:ENDER2] name = Creality Ender-2 @@ -93,7 +93,7 @@ technology = FFF family = ENDER bed_model = ender2_bed.stl bed_texture = ender2.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR5PRO] name = Creality CR-5 Pro @@ -102,7 +102,7 @@ technology = FFF family = CR bed_model = cr5pro_bed.stl bed_texture = cr5pro.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR5PROH] name = Creality CR-5 Pro H @@ -111,7 +111,7 @@ technology = FFF family = CR bed_model = cr5pro_bed.stl bed_texture = cr5pro.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR6SE] name = Creality CR-6 SE @@ -120,7 +120,7 @@ technology = FFF family = CR bed_model = cr6se_bed.stl bed_texture = cr6se.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR6MAX] name = Creality CR-6 Max @@ -129,7 +129,7 @@ technology = FFF family = CR bed_model = cr10s4_bed.stl bed_texture = cr10s4.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10MINI] name = Creality CR-10 Mini @@ -138,7 +138,7 @@ technology = FFF family = CR bed_model = cr10mini_bed.stl bed_texture = cr10mini.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10MAX] name = Creality CR-10 Max @@ -147,7 +147,7 @@ technology = FFF family = CR bed_model = cr10max_bed.stl bed_texture = cr10max.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10] name = Creality CR-10 @@ -156,7 +156,7 @@ technology = FFF family = CR bed_model = cr10_bed.stl bed_texture = cr10.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10V2] name = Creality CR-10 V2 @@ -165,7 +165,7 @@ technology = FFF family = CR bed_model = cr10v2_bed.stl bed_texture = cr10.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10V3] name = Creality CR-10 V3 @@ -174,7 +174,7 @@ technology = FFF family = CR bed_model = cr10v2_bed.stl bed_texture = cr10.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10S] name = Creality CR-10 S @@ -183,7 +183,7 @@ technology = FFF family = CR bed_model = cr10_bed.stl bed_texture = cr10.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10SPRO] name = Creality CR-10 S Pro @@ -192,7 +192,7 @@ technology = FFF family = CR bed_model = cr10v2_bed.stl bed_texture = cr10spro.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10SPROV2] name = Creality CR-10 S Pro V2 @@ -201,7 +201,7 @@ technology = FFF family = CR bed_model = cr10v2_bed.stl bed_texture = cr10.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10S4] name = Creality CR-10 S4 @@ -210,7 +210,7 @@ technology = FFF family = CR bed_model = cr10s4_bed.stl bed_texture = cr10s4.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR10S5] name = Creality CR-10 S5 @@ -219,7 +219,7 @@ technology = FFF family = CR bed_model = cr10s5_bed.stl bed_texture = cr10s5.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR20] name = Creality CR-20 @@ -228,7 +228,7 @@ technology = FFF family = CR bed_model = ender3_bed.stl bed_texture = cr20.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR20PRO] name = Creality CR-20 Pro @@ -237,7 +237,7 @@ technology = FFF family = CR bed_model = ender3_bed.stl bed_texture = cr20.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR200B] name = Creality CR-200B @@ -246,7 +246,7 @@ technology = FFF family = CR bed_model = cr200b_bed.stl bed_texture = cr200b.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY [printer_model:CR8] name = Creality CR-8 @@ -255,7 +255,7 @@ technology = FFF family = CR bed_model = cr8_bed.stl bed_texture = cr8.svg -default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY #[printer_model:CRX] #name = Creality CR-X @@ -264,7 +264,7 @@ default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @ #family = CR-X #bed_model = cr10v2_bed.stl #bed_texture = cr10spro.svg -#default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +#default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY #[printer_model:CRXPRO] #name = Creality CR-X Pro @@ -273,7 +273,7 @@ default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @ #family = CR-X #bed_model = cr10v2_bed.stl #bed_texture = cr10spro.svg -#default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA (Galaxy) @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 123-3D Jupiter PLA @CREALITY +#default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY # All presets starting with asterisk, for example *common*, are intermediate and they will # not make it into the user interface. @@ -281,6 +281,7 @@ default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @ # Common print preset [print:*common*] avoid_crossing_perimeters = 0 +bridge_acceleration = 250 bridge_angle = 0 bridge_flow_ratio = 0.95 bridge_speed = 25 @@ -288,6 +289,7 @@ brim_width = 0 clip_multipart_objects = 1 compatible_printers = complete_objects = 0 +default_acceleration = 500 dont_support_bridges = 1 elefant_foot_compensation = 0.1 ensure_vertical_shell_thickness = 1 @@ -383,6 +385,7 @@ layer_height = 0.08 perimeters = 3 bottom_solid_layers = 9 top_solid_layers = 11 +bridge_flow_ratio = 0.70 [print:*0.10mm*] inherits = *common* @@ -390,6 +393,7 @@ layer_height = 0.10 perimeters = 3 bottom_solid_layers = 7 top_solid_layers = 9 +bridge_flow_ratio = 0.70 [print:*0.12mm*] inherits = *common* @@ -397,12 +401,14 @@ layer_height = 0.12 perimeters = 3 bottom_solid_layers = 6 top_solid_layers = 7 +bridge_flow_ratio = 0.70 [print:*0.16mm*] inherits = *common* layer_height = 0.16 bottom_solid_layers = 5 top_solid_layers = 7 +bridge_flow_ratio = 0.85 [print:*0.20mm*] inherits = *common* @@ -631,9 +637,11 @@ first_layer_bed_temperature = 60 filament_cost = 19.00 filament_density = 1.24 filament_colour = #FF0000 +filament_spool_weight = 256 -[filament:Devil Design PLA (Galaxy) @CREALITY] +[filament:Devil Design PLA Galaxy @CREALITY] inherits = *PLA* +renamed_from = "Devil Design PLA (Galaxy) @CREALITY" filament_vendor = Devil Design temperature = 225 bed_temperature = 65 @@ -642,6 +650,7 @@ first_layer_bed_temperature = 65 filament_cost = 19.00 filament_density = 1.24 filament_colour = #FF0000 +filament_spool_weight = 256 [filament:Extrudr PLA NX2 @CREALITY] inherits = *PLA* @@ -700,6 +709,40 @@ filament_density = 1.24 filament_colour = #125467 filament_spool_weight = 238 +[filament:3DJAKE ecoPLA Matt @CREALITY] +inherits = *PLA* +filament_vendor = 3DJAKE +temperature = 195 +bed_temperature = 60 +first_layer_temperature = 195 +first_layer_bed_temperature = 60 +filament_cost = 24.99 +filament_density = 1.38 +filament_colour = #125467 +filament_spool_weight = 238 + +[filament:3DJAKE ecoPLA Tough @CREALITY] +inherits = *PLA* +filament_vendor = 3DJAKE +temperature = 215 +bed_temperature = 60 +first_layer_temperature = 215 +first_layer_bed_temperature = 60 +filament_cost = 29.99 +filament_density = 1.21 +filament_colour = #125467 + +[filament:FormFutura Tough PLA @CREALITY] +inherits = *PLA* +filament_vendor = FormFutura +temperature = 215 +bed_temperature = 60 +first_layer_temperature = 215 +first_layer_bed_temperature = 60 +filament_cost = 46.65 +filament_density = 1.21 +filament_colour = #ed000e + [filament:123-3D Jupiter PLA @CREALITY] inherits = *PLA* filament_vendor = 123-3D @@ -926,7 +969,7 @@ printer_model = CR5PROH printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_CR5PROH\nPRINTER_HAS_BOWDEN [printer:Creality CR-6 SE] -inherits = *common*; *fastabl*; *pauseprint* +inherits = *common*; *pauseprint* bed_shape = 5x0,230x0,230x235,5x235 printer_model = CR6SE printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_CR6SE\nPRINTER_HAS_BOWDEN diff --git a/resources/profiles/INAT.idx b/resources/profiles/INAT.idx index e682f4ed23..47632c29a0 100644 --- a/resources/profiles/INAT.idx +++ b/resources/profiles/INAT.idx @@ -1,2 +1,3 @@ -min_slic3r_version = 2.4.0-alpha0 +min_slic3r_version = 2.3.1-beta 0.0.1 Initial version +0.0.2 Improved start gcode, changed filename format diff --git a/resources/profiles/INAT.ini b/resources/profiles/INAT.ini index e11aeab86f..81a4f90ef4 100644 --- a/resources/profiles/INAT.ini +++ b/resources/profiles/INAT.ini @@ -3,8 +3,8 @@ [vendor] # Vendor name will be shown by the Config Wizard. name = INAT -config_version = 0.0.1 -config_update_url = http://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/INAT/ +config_version = 0.0.2 +config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/INAT/ ### ### PRINTER LIST @@ -133,7 +133,7 @@ extruder_clearance_radius = 85 extruder_clearance_height = 34 gcode_comments = 0 gcode_label_objects = 0 -output_filename_format = {input_filename_base}_{filament_type[0]}_{print_time}.gcode +output_filename_format = {input_filename_base}_{filament_type[0]}.gcode [print:0.2mm Standard @PROTON_X] @@ -193,7 +193,7 @@ use_firmware_retraction = 0 use_volumetric_e = 0 variable_layer_height = 1 #gcodes -start_gcode = G28 ;Home\nG0 Z0.3 F200 ;Move nozzle down\nM192 S50 ; Wait for probe temperature to settle\nG29\nG0 X0 Y0 Z30 F6000\nM84 E\nM0\nG1 Z15.0 F6000 ;Move the platform down 15mm\n;Prime the extruder\nG92 E0\nG1 F200 E3\nG92 E0\n +start_gcode = G28 ;Home\nG0 X-2 Y150 F6000 ;Move to the side\nG0 Z0.3 F200 ;Move nozzle down\nM192 ; Wait for probe temperature to settle\nG28 Z\nG29\nG0 X0 Y0 Z30 F6000\nM84 E\nM0\nG1 Z15.0 F6000 ;Move the platform down 15mm\n end_gcode = M400\nM104 S0\nM140 S0\nM107\n;Retract the filament\nG92 E1\nG1 E-1 F300\nG28 X R5\nG0 Y300 F2000\nM84\n color_change_gcode = M600 #limits diff --git a/resources/profiles/PrusaResearch.idx b/resources/profiles/PrusaResearch.idx index 8c14026ce1..dc3c79cd55 100644 --- a/resources/profiles/PrusaResearch.idx +++ b/resources/profiles/PrusaResearch.idx @@ -1,159 +1,161 @@ -min_slic3r_version = 2.3.0-rc1 -1.2.4 Updated cost/density values in filament settings. Various changes in print settings. -1.2.3 Updated firmware version. Updated end g-code in MMU2 printer profiles. -1.2.2 Added Prusament PVB filament profile. Added 0.8mm nozzle profiles. -1.2.1 Updated FW version for MK2.5 family printers. -1.2.0 Added full_fan_speed_layer value for PETG. Increased support interface spacing for 0.6mm nozzle profiles. Updated firmware version. -min_slic3r_version = 2.3.0-beta2 -1.2.0-beta1 Updated end g-code. Added full_fan_speed_layer values. -min_slic3r_version = 2.3.0-beta0 -1.2.0-beta0 Adjusted infill anchor limits. Added filament spool weights. -min_slic3r_version = 2.3.0-alpha4 -1.2.0-alpha1 Renamed MK3S and MINI printer profiles. Updated end g-code (MINI). Added new SLA materials and filament profiles. -1.2.0-alpha0 Added filament spool weights -min_slic3r_version = 2.2.0-alpha3 -1.1.13 Updated firmware version. Updated end g-code in MMU2 printer profiles. -1.1.12 Added Prusament PVB filament profile. Added 0.8mm nozzle profiles. -1.1.11 Renamed MK3S and MINI printer profiles. Updated end g-code (MINI). Added new SLA materials and filament profiles. -1.1.10 Updated firmware version. -1.1.9 Updated K values in filament profiles (linear advance). Added new filament profiles and SLA materials. -1.1.8 Updated start/end g-code scripts for MK3 family printer profiles (reduced extruder motor current for some print profiles). Added new filament and SLA material profiles. -1.1.7 Updated end g-code for MMU2 Single printer profiles. Added/updated filament and SLA material profiles. -1.1.6 Updated firmware version for MK2.5/S and MK3/S. -1.1.5 Updated MMU1 specific retraction settings for Prusament PC Blend -1.1.4 Added Prusament PC Blend filament profile. -1.1.3 Added SLA material and filament profile -1.1.2 Added renamed_from fields for PETG filaments to indicate that they were renamed from PET. -1.1.1 Added Verbatim and Fiberlogy PETG filament profiles. Updated auto cooling settings for ABS. -1.1.1-beta Updated for PrusaSlicer 2.2.0-beta -1.1.1-alpha4 Extended list of default filaments to be installed, top/bottom_solid_min_thickness defined, infill_acceleration changed etc -1.1.1-alpha3 Print bed textures are now configurable from the Preset Bundle. Requires PrusaSlicer 2.2.0-alpha3 and newer. -# The following line (max_slic3r_version) forces the users of PrusaSlicer 2.2.0-alpha3 and newer to update the profiles to 1.1.1-alpha3 and newer, -# so they will see the print bed. -max_slic3r_version = 2.2.0-alpha2 -min_slic3r_version = 2.2.0-alpha0 -1.1.1-alpha2 Bumped up config version, so our in house customer will get updated profiles. -1.1.0 Filament aliases, Creality profiles and other goodies for PrusaSlicer 2.2.0-alpha0 -min_slic3r_version = 2.1.1-beta0 -1.0.11 Updated firmware version. -1.0.10 Updated firmware version for MK2.5/S and MK3/S. -1.0.9 Updated firmware version for MK2.5/S and MK3/S. -1.0.8 Various changes in FFF profiles, new filaments/materials added. See changelog. -1.0.7 Updated layer height limits for MINI -1.0.6 Added Prusa MINI profiles -min_slic3r_version = 2.1.0-alpha0 -1.0.5 Added SLA materials -1.0.4 Updated firmware version and 0.25mm nozzle profiles -1.0.3 Added filament profiles -1.0.2 Added SLA materials -1.0.1 Updated MK3 firmware version check to 3.8.0, new soluble support profiles for 0.6mm nozzle diameter MMU2S printers. -1.0.0 Updated end G-code for the MMU2 profiles to lift the extruder at the end of print. Wipe tower bridging distance was made smaller for soluble supports. -1.0.0-beta1 Updated color for the ASA filaments to differ from the other filaments. Single extruder printers now have no extruder color assigned, obects and toolpaths will be colored with the color of the active filament. -1.0.0-beta0 Printer model checks in start G-codes, ASA filament profiles, limits on min / max SL1 exposition times -1.0.0-alpha2 Printer model and nozzle diameter check -1.0.0-alpha1 Added Prusament ASA profile -1.0.0-alpha0 Filament specific retract for PET and similar copolymers, and for FLEX -min_slic3r_version = 1.42.0-alpha6 -0.8.10 Updated firmware version. -0.8.9 Updated firmware version for MK2.5/S and MK3/S. -0.8.8 Updated firmware version for MK2.5/S and MK3/S. -0.8.7 Updated firmware version -0.8.6 Updated firmware version for MK2.5/S and MK3/S -0.8.5 Updated SL1 printer and material settings -0.8.4 Added Prusament ASA profile -0.8.3 FW version and SL1 materials update -0.8.2 FFF and SL1 settings update -0.8.1 Output settings and SLA materials update -0.8.0 Updated for the PrusaSlicer 2.0.0 final release -0.8.0-rc2 Updated firmware versions for MK2.5/S and MK3/S -0.8.0-rc1 Updated SLA profiles -0.8.0-rc Updated for the PrusaSlicer 2.0.0-rc release -0.8.0-beta4 Updated SLA profiles -0.8.0-beta3 Updated SLA profiles -0.8.0-beta2 Updated SLA profiles -0.8.0-beta1 Updated SLA profiles -0.8.0-beta Updated SLA profiles -0.8.0-alpha9 Updated SLA and FFF profiles -0.8.0-alpha8 Updated SLA profiles -0.8.0-alpha7 Updated SLA profiles -0.8.0-alpha6 Updated SLA profiles -min_slic3r_version = 1.42.0-alpha -0.8.0-alpha Updated SLA profiles -0.4.0-alpha4 Updated SLA profiles -0.4.0-alpha3 Update of SLA profiles -0.4.0-alpha2 First SLA profiles -min_slic3r_version = 1.41.3-alpha -0.4.12 Updated firmware version for MK2.5/S and MK3/S. -0.4.11 Updated firmware version for MK2.5/S and MK3/S. -0.4.10 Updated firmware version -0.4.9 Updated firmware version for MK2.5/S and MK3/S -0.4.8 MK2.5/3/S FW update -0.4.7 MK2/S/MMU FW update -0.4.6 Updated firmware versions for MK2.5/S and MK3/S -0.4.5 Enabled remaining time support for MK2/S/MMU1 -0.4.4 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt -0.4.3 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt -0.4.2 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt -0.4.1 New MK2.5S and MK3S FW versions -0.4.0 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt -min_slic3r_version = 1.41.1 -0.3.11 Updated firmware version for MK2.5/S and MK3/S. -0.3.10 Updated firmware version -0.3.9 Updated firmware version for MK2.5/S and MK3/S -0.3.8 MK2.5/3/S FW update -0.3.7 MK2/S/MMU FW update -0.3.6 Updated firmware versions for MK2.5 and MK3 -0.3.5 New MK2.5 and MK3 FW versions -0.3.4 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt -0.3.3 Prusament PETG released -0.3.2 New MK2.5 and MK3 FW versions -0.3.1 New MK2.5 and MK3 FW versions -0.3.0 New MK2.5 and MK3 FW version -min_slic3r_version = 1.41.0-alpha -0.2.9 New MK2.5 and MK3 FW versions -0.2.8 New MK2.5 and MK3 FW version -min_slic3r_version = 1.41.1 -0.2.7 New MK2.5 and MK3 FW version -0.2.6 Added MMU2 MK2.5 settings -min_slic3r_version = 1.41.0-alpha -0.2.5 Prusament is out - added prusament settings -0.2.4 Added soluble support profiles for MMU2 -0.2.3 Added materials for MMU2 single mode, edited MK3 xy stealth feedrate limit -0.2.2 Edited MMU2 Single mode purge line -0.2.1 Added PET and BVOH settings for MMU2 -0.2.0-beta5 Fixed MMU1 ramming parameters -0.2.0-beta4 Added filament loading speed at start, increased minimal purge on wipe tower -0.2.0-beta3 Edited ramming parameters and filament cooling moves for MMU2 -0.2.0-beta2 Edited first layer speed and wipe tower position -0.2.0-beta Removed limit on the MK3MMU2 height, added legacy M204 S T format to the MK2 profiles -0.2.0-alpha8 Added filament_load/unload_time for the PLA/ABS MMU2 filament presets. -0.2.0-alpha7 Vojtech's fix the incorrect *MK3* references -0.2.0-alpha6 Jindra's way to fix the 0.2.0-alpha5 version -0.2.0-alpha5 Bumped up firmware versions for MK2.5/MK3 to 3.3.1, disabled priming areas for MK3MMU2 -0.2.0-alpha4 Extended the custom start/end G-codes of the MMU2.0 printers for no priming towers. -0.2.0-alpha3 Adjusted machine limits for time estimates, added filament density and cost -0.2.0-alpha2 Renamed the key MK3SMMU to MK3MMU2, added a generic PLA MMU2 material -0.2.0-alpha1 added initial profiles for the i3 MK3 Multi Material Upgrade 2.0 -0.2.0-alpha moved machine limits from the start G-code to the new print profile parameters -min_slic3r_version = 1.40.0 -0.1.18 Updated firmware version -0.1.17 Updated firmware version for MK2.5/S and MK3/S -0.1.16 MK2.5/3/S FW update -0.1.15 MK2/S/MMU FW update -0.1.14 Updated firmware versions for MK2.5 and MK3 -0.1.13 New MK2.5 and MK3 FW versions -0.1.12 New MK2.5 and MK3 FW versions -0.1.11 fw version changed to 3.3.1 -0.1.10 MK3 jerk and acceleration update -0.1.9 edited support extrusion width for 0.25 and 0.6 nozzles -0.1.8 extrusion width for 0,25, 0.6 and variable layer height fixes -0.1.7 Fixed errors in 0.25mm and 0.6mm profiles -0.1.6 Split the MK2.5 profile from the MK2S -min_slic3r_version = 1.40.0-beta -0.1.5 fixed printer_variant fields for the i3 MK3 0.25 and 0.6mm nozzles -0.1.4 edited fw version, added z-raise after print -min_slic3r_version = 1.40.0-alpha -0.1.3 Fixed an incorrect position of the max_print_height parameter -0.1.2 Wipe tower changes -0.1.1 Minor print speed adjustments -0.1.0 Initial +min_slic3r_version = 2.4.0-alpha0 +1.3.0-alpha0 Disabled thick bridges, updated support settings. +min_slic3r_version = 2.3.0-rc1 +1.2.4 Updated cost/density values in filament settings. Various changes in print settings. +1.2.3 Updated firmware version. Updated end g-code in MMU2 printer profiles. +1.2.2 Added Prusament PVB filament profile. Added 0.8mm nozzle profiles. +1.2.1 Updated FW version for MK2.5 family printers. +1.2.0 Added full_fan_speed_layer value for PETG. Increased support interface spacing for 0.6mm nozzle profiles. Updated firmware version. +min_slic3r_version = 2.3.0-beta2 +1.2.0-beta1 Updated end g-code. Added full_fan_speed_layer values. +min_slic3r_version = 2.3.0-beta0 +1.2.0-beta0 Adjusted infill anchor limits. Added filament spool weights. +min_slic3r_version = 2.3.0-alpha4 +1.2.0-alpha1 Renamed MK3S and MINI printer profiles. Updated end g-code (MINI). Added new SLA materials and filament profiles. +1.2.0-alpha0 Added filament spool weights +min_slic3r_version = 2.2.0-alpha3 +1.1.13 Updated firmware version. Updated end g-code in MMU2 printer profiles. +1.1.12 Added Prusament PVB filament profile. Added 0.8mm nozzle profiles. +1.1.11 Renamed MK3S and MINI printer profiles. Updated end g-code (MINI). Added new SLA materials and filament profiles. +1.1.10 Updated firmware version. +1.1.9 Updated K values in filament profiles (linear advance). Added new filament profiles and SLA materials. +1.1.8 Updated start/end g-code scripts for MK3 family printer profiles (reduced extruder motor current for some print profiles). Added new filament and SLA material profiles. +1.1.7 Updated end g-code for MMU2 Single printer profiles. Added/updated filament and SLA material profiles. +1.1.6 Updated firmware version for MK2.5/S and MK3/S. +1.1.5 Updated MMU1 specific retraction settings for Prusament PC Blend +1.1.4 Added Prusament PC Blend filament profile. +1.1.3 Added SLA material and filament profile +1.1.2 Added renamed_from fields for PETG filaments to indicate that they were renamed from PET. +1.1.1 Added Verbatim and Fiberlogy PETG filament profiles. Updated auto cooling settings for ABS. +1.1.1-beta Updated for PrusaSlicer 2.2.0-beta +1.1.1-alpha4 Extended list of default filaments to be installed, top/bottom_solid_min_thickness defined, infill_acceleration changed etc +1.1.1-alpha3 Print bed textures are now configurable from the Preset Bundle. Requires PrusaSlicer 2.2.0-alpha3 and newer. +# The following line (max_slic3r_version) forces the users of PrusaSlicer 2.2.0-alpha3 and newer to update the profiles to 1.1.1-alpha3 and newer, +# so they will see the print bed. +max_slic3r_version = 2.2.0-alpha2 +min_slic3r_version = 2.2.0-alpha0 +1.1.1-alpha2 Bumped up config version, so our in house customer will get updated profiles. +1.1.0 Filament aliases, Creality profiles and other goodies for PrusaSlicer 2.2.0-alpha0 +min_slic3r_version = 2.1.1-beta0 +1.0.11 Updated firmware version. +1.0.10 Updated firmware version for MK2.5/S and MK3/S. +1.0.9 Updated firmware version for MK2.5/S and MK3/S. +1.0.8 Various changes in FFF profiles, new filaments/materials added. See changelog. +1.0.7 Updated layer height limits for MINI +1.0.6 Added Prusa MINI profiles +min_slic3r_version = 2.1.0-alpha0 +1.0.5 Added SLA materials +1.0.4 Updated firmware version and 0.25mm nozzle profiles +1.0.3 Added filament profiles +1.0.2 Added SLA materials +1.0.1 Updated MK3 firmware version check to 3.8.0, new soluble support profiles for 0.6mm nozzle diameter MMU2S printers. +1.0.0 Updated end G-code for the MMU2 profiles to lift the extruder at the end of print. Wipe tower bridging distance was made smaller for soluble supports. +1.0.0-beta1 Updated color for the ASA filaments to differ from the other filaments. Single extruder printers now have no extruder color assigned, obects and toolpaths will be colored with the color of the active filament. +1.0.0-beta0 Printer model checks in start G-codes, ASA filament profiles, limits on min / max SL1 exposition times +1.0.0-alpha2 Printer model and nozzle diameter check +1.0.0-alpha1 Added Prusament ASA profile +1.0.0-alpha0 Filament specific retract for PET and similar copolymers, and for FLEX +min_slic3r_version = 1.42.0-alpha6 +0.8.10 Updated firmware version. +0.8.9 Updated firmware version for MK2.5/S and MK3/S. +0.8.8 Updated firmware version for MK2.5/S and MK3/S. +0.8.7 Updated firmware version +0.8.6 Updated firmware version for MK2.5/S and MK3/S +0.8.5 Updated SL1 printer and material settings +0.8.4 Added Prusament ASA profile +0.8.3 FW version and SL1 materials update +0.8.2 FFF and SL1 settings update +0.8.1 Output settings and SLA materials update +0.8.0 Updated for the PrusaSlicer 2.0.0 final release +0.8.0-rc2 Updated firmware versions for MK2.5/S and MK3/S +0.8.0-rc1 Updated SLA profiles +0.8.0-rc Updated for the PrusaSlicer 2.0.0-rc release +0.8.0-beta4 Updated SLA profiles +0.8.0-beta3 Updated SLA profiles +0.8.0-beta2 Updated SLA profiles +0.8.0-beta1 Updated SLA profiles +0.8.0-beta Updated SLA profiles +0.8.0-alpha9 Updated SLA and FFF profiles +0.8.0-alpha8 Updated SLA profiles +0.8.0-alpha7 Updated SLA profiles +0.8.0-alpha6 Updated SLA profiles +min_slic3r_version = 1.42.0-alpha +0.8.0-alpha Updated SLA profiles +0.4.0-alpha4 Updated SLA profiles +0.4.0-alpha3 Update of SLA profiles +0.4.0-alpha2 First SLA profiles +min_slic3r_version = 1.41.3-alpha +0.4.12 Updated firmware version for MK2.5/S and MK3/S. +0.4.11 Updated firmware version for MK2.5/S and MK3/S. +0.4.10 Updated firmware version +0.4.9 Updated firmware version for MK2.5/S and MK3/S +0.4.8 MK2.5/3/S FW update +0.4.7 MK2/S/MMU FW update +0.4.6 Updated firmware versions for MK2.5/S and MK3/S +0.4.5 Enabled remaining time support for MK2/S/MMU1 +0.4.4 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt +0.4.3 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt +0.4.2 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt +0.4.1 New MK2.5S and MK3S FW versions +0.4.0 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt +min_slic3r_version = 1.41.1 +0.3.11 Updated firmware version for MK2.5/S and MK3/S. +0.3.10 Updated firmware version +0.3.9 Updated firmware version for MK2.5/S and MK3/S +0.3.8 MK2.5/3/S FW update +0.3.7 MK2/S/MMU FW update +0.3.6 Updated firmware versions for MK2.5 and MK3 +0.3.5 New MK2.5 and MK3 FW versions +0.3.4 Changelog: https://github.com/prusa3d/Slic3r-settings/blob/master/live/PrusaResearch/changelog.txt +0.3.3 Prusament PETG released +0.3.2 New MK2.5 and MK3 FW versions +0.3.1 New MK2.5 and MK3 FW versions +0.3.0 New MK2.5 and MK3 FW version +min_slic3r_version = 1.41.0-alpha +0.2.9 New MK2.5 and MK3 FW versions +0.2.8 New MK2.5 and MK3 FW version +min_slic3r_version = 1.41.1 +0.2.7 New MK2.5 and MK3 FW version +0.2.6 Added MMU2 MK2.5 settings +min_slic3r_version = 1.41.0-alpha +0.2.5 Prusament is out - added prusament settings +0.2.4 Added soluble support profiles for MMU2 +0.2.3 Added materials for MMU2 single mode, edited MK3 xy stealth feedrate limit +0.2.2 Edited MMU2 Single mode purge line +0.2.1 Added PET and BVOH settings for MMU2 +0.2.0-beta5 Fixed MMU1 ramming parameters +0.2.0-beta4 Added filament loading speed at start, increased minimal purge on wipe tower +0.2.0-beta3 Edited ramming parameters and filament cooling moves for MMU2 +0.2.0-beta2 Edited first layer speed and wipe tower position +0.2.0-beta Removed limit on the MK3MMU2 height, added legacy M204 S T format to the MK2 profiles +0.2.0-alpha8 Added filament_load/unload_time for the PLA/ABS MMU2 filament presets. +0.2.0-alpha7 Vojtech's fix the incorrect *MK3* references +0.2.0-alpha6 Jindra's way to fix the 0.2.0-alpha5 version +0.2.0-alpha5 Bumped up firmware versions for MK2.5/MK3 to 3.3.1, disabled priming areas for MK3MMU2 +0.2.0-alpha4 Extended the custom start/end G-codes of the MMU2.0 printers for no priming towers. +0.2.0-alpha3 Adjusted machine limits for time estimates, added filament density and cost +0.2.0-alpha2 Renamed the key MK3SMMU to MK3MMU2, added a generic PLA MMU2 material +0.2.0-alpha1 added initial profiles for the i3 MK3 Multi Material Upgrade 2.0 +0.2.0-alpha moved machine limits from the start G-code to the new print profile parameters +min_slic3r_version = 1.40.0 +0.1.18 Updated firmware version +0.1.17 Updated firmware version for MK2.5/S and MK3/S +0.1.16 MK2.5/3/S FW update +0.1.15 MK2/S/MMU FW update +0.1.14 Updated firmware versions for MK2.5 and MK3 +0.1.13 New MK2.5 and MK3 FW versions +0.1.12 New MK2.5 and MK3 FW versions +0.1.11 fw version changed to 3.3.1 +0.1.10 MK3 jerk and acceleration update +0.1.9 edited support extrusion width for 0.25 and 0.6 nozzles +0.1.8 extrusion width for 0,25, 0.6 and variable layer height fixes +0.1.7 Fixed errors in 0.25mm and 0.6mm profiles +0.1.6 Split the MK2.5 profile from the MK2S +min_slic3r_version = 1.40.0-beta +0.1.5 fixed printer_variant fields for the i3 MK3 0.25 and 0.6mm nozzles +0.1.4 edited fw version, added z-raise after print +min_slic3r_version = 1.40.0-alpha +0.1.3 Fixed an incorrect position of the max_print_height parameter +0.1.2 Wipe tower changes +0.1.1 Minor print speed adjustments +0.1.0 Initial diff --git a/resources/profiles/PrusaResearch.ini b/resources/profiles/PrusaResearch.ini index 796d578226..16737d1563 100644 --- a/resources/profiles/PrusaResearch.ini +++ b/resources/profiles/PrusaResearch.ini @@ -5,18 +5,15 @@ name = Prusa Research # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 1.2.4 +config_version = 1.3.0-alpha0 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/PrusaResearch/ changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% # The printer models will be shown by the Configuration Wizard in this order, # also the first model installed & the first nozzle installed will be activated after install. -#TODO: One day we may differentiate variants of the nozzles / hot ends, -#for example by the melt zone size, or whether the nozzle is hardened. # Printer model name will be shown by the installation wizard. - [printer_model:MINI] name = Original Prusa MINI && MINI+ variants = 0.4; 0.25; 0.6; 0.8 @@ -128,20 +125,21 @@ default_materials = Prusa Orange Tough @0.05 # All presets starting with asterisk, for example *common*, are intermediate and they will # not make it into the user interface. -# Common print preset, mostly derived from MK2 single material with a 0.4mm nozzle. -# All other print presets will derive from the *common* print preset. +# Common print presets + [print:*common*] avoid_crossing_perimeters = 0 +thick_bridges = 0 bridge_acceleration = 1000 bridge_angle = 0 -bridge_flow_ratio = 0.8 -bridge_speed = 20 +bridge_flow_ratio = 1 +bridge_speed = 25 brim_width = 0 clip_multipart_objects = 1 compatible_printers = complete_objects = 0 default_acceleration = 1000 -dont_support_bridges = 1 +dont_support_bridges = 0 elefant_foot_compensation = 0.2 ensure_vertical_shell_thickness = 1 external_fill_pattern = rectilinear @@ -154,7 +152,7 @@ extrusion_width = 0.45 fill_angle = 45 fill_density = 20% fill_pattern = cubic -first_layer_acceleration = 1000 +first_layer_acceleration = 800 first_layer_extrusion_width = 0.42 first_layer_height = 0.2 first_layer_speed = 20 @@ -183,6 +181,7 @@ perimeter_extrusion_width = 0.45 post_process = print_settings_id = raft_layers = 0 +raft_first_layer_density = 90% resolution = 0 seam_position = nearest single_extruder_multi_material_priming = 1 @@ -203,7 +202,7 @@ support_material_interface_extruder = 0 support_material_angle = 0 support_material_buildplate_only = 0 support_material_enforce_layers = 0 -support_material_contact_distance = 0.1 +support_material_contact_distance = 0.2 support_material_interface_contact_loops = 0 support_material_interface_layers = 2 support_material_interface_spacing = 0.2 @@ -212,9 +211,10 @@ support_material_pattern = rectilinear support_material_spacing = 2 support_material_speed = 50 support_material_synchronize_layers = 0 -support_material_threshold = 55 +support_material_threshold = 50 support_material_with_sheath = 0 -support_material_xy_spacing = 50% +support_material_xy_spacing = 60% +support_material_bottom_interface_layers = 0 thin_walls = 0 top_infill_extrusion_width = 0.45 top_solid_infill_speed = 40 @@ -240,20 +240,15 @@ wipe_tower_x = 170 wipe_tower_y = 125 [print:*MK306*] +inherits = *MK3* fill_pattern = gyroid fill_density = 15% -single_extruder_multi_material_priming = 0 -travel_speed = 180 -wipe_tower_x = 170 -wipe_tower_y = 125 - -## MINI [print:*MINI*] fill_pattern = grid travel_speed = 150 wipe_tower = 0 -default_acceleration = 1250 +default_acceleration = 1000 first_layer_acceleration = 800 infill_acceleration = 1000 bridge_acceleration = 1000 @@ -262,7 +257,6 @@ max_print_speed = 150 extruder_clearance_height = 20 extruder_clearance_radius = 35 -# Print parameters common to a 0.25mm diameter nozzle. [print:*0.25nozzle*] elefant_foot_compensation = 0 external_perimeter_extrusion_width = 0.25 @@ -277,7 +271,11 @@ support_material_interface_layers = 0 support_material_interface_spacing = 0.15 support_material_spacing = 1 support_material_xy_spacing = 150% +support_material_contact_distance = 0.1 output_filename_format = {input_filename_base}_{nozzle_diameter[0]}n_{layer_height}mm_{filament_type[0]}_{printer_model}_{print_time}.gcode +thick_bridges = 0 +bridge_flow_ratio = 1 +bridge_speed = 20 [print:*0.25nozzleMK3*] inherits = *0.25nozzle* @@ -288,7 +286,6 @@ infill_speed = 45 solid_infill_speed = 45 top_solid_infill_speed = 30 support_material_speed = 40 -bridge_speed = 20 gap_fill_speed = 30 perimeter_acceleration = 500 infill_acceleration = 1000 @@ -307,7 +304,6 @@ solid_infill_speed = 40 infill_acceleration = 800 first_layer_acceleration = 500 -# Print parameters common to a 0.6mm diameter nozzle. [print:*0.6nozzle*] external_perimeter_extrusion_width = 0.61 extrusion_width = 0.67 @@ -324,6 +320,31 @@ output_filename_format = {input_filename_base}_{nozzle_diameter[0]}n_{layer_heig infill_anchor_max = 15 top_solid_min_thickness = 0.9 bottom_solid_min_thickness = 0.6 +thick_bridges = 1 +bridge_flow_ratio = 0.95 +bridge_speed = 25 + +[print:*0.6nozzleMK3*] +inherits = *0.6nozzle* +external_perimeter_extrusion_width = 0.65 +extrusion_width = 0.65 +infill_extrusion_width = 0.65 +thick_bridges = 0 + +[print:*0.6nozzleMINI*] +inherits = *0.6nozzleMK3* +infill_extrusion_width = 0.68 +solid_infill_extrusion_width = 0.68 +fill_pattern = gyroid +fill_density = 15% +travel_speed = 150 +perimeter_acceleration = 800 +infill_acceleration = 1000 +bridge_acceleration = 1000 +first_layer_acceleration = 800 +default_acceleration = 1250 +support_material_speed = 40 +support_material_interface_speed = 100% [print:*0.8nozzle*] external_perimeter_extrusion_width = 0.9 @@ -356,34 +377,12 @@ bridge_flow_ratio = 0.9 perimeter_acceleration = 800 infill_acceleration = 1000 bridge_acceleration = 1000 -first_layer_acceleration = 1000 +first_layer_acceleration = 800 default_acceleration = 1000 top_solid_min_thickness = 1.2 bottom_solid_min_thickness = 0.8 single_extruder_multi_material_priming = 0 - -[print:*0.6nozzleMK3*] -inherits = *0.6nozzle* -external_perimeter_extrusion_width = 0.65 -extrusion_width = 0.65 -infill_extrusion_width = 0.65 -bridge_flow_ratio = 0.95 -bridge_speed = 25 - -[print:*0.6nozzleMINI*] -inherits = *0.6nozzleMK3* -infill_extrusion_width = 0.68 -solid_infill_extrusion_width = 0.68 -fill_pattern = gyroid -fill_density = 15% -travel_speed = 150 -perimeter_acceleration = 800 -infill_acceleration = 1000 -bridge_acceleration = 1000 -first_layer_acceleration = 1000 -default_acceleration = 1250 -support_material_speed = 40 -support_material_interface_speed = 100% +thick_bridges = 1 [print:*soluble_support*] overhangs = 1 @@ -399,29 +398,29 @@ support_material_threshold = 80 support_material_with_sheath = 1 wipe_tower_bridging = 6 support_material_interface_speed = 80% - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.05mm ---XXX -# XXXXXXXXXXXXXXXXXXXX +support_material_bottom_interface_layers = -1 +thick_bridges = 1 [print:*0.05mm*] inherits = *common* +layer_height = 0.05 bottom_solid_layers = 10 bridge_acceleration = 300 -bridge_flow_ratio = 0.7 +bridge_flow_ratio = 1.15 +bridge_speed = 15 default_acceleration = 1000 external_perimeter_speed = 20 fill_density = 20% -first_layer_acceleration = 500 +first_layer_acceleration = 800 gap_fill_speed = 20 infill_acceleration = 800 infill_speed = 30 max_print_speed = 80 small_perimeter_speed = 20 solid_infill_speed = 30 -support_material_extrusion_width = 0.3 +support_material_extrusion_width = 0.33 support_material_spacing = 1.5 -layer_height = 0.05 +support_material_contact_distance = 0.15 perimeter_acceleration = 300 perimeter_speed = 30 perimeters = 3 @@ -429,151 +428,28 @@ support_material_speed = 30 top_solid_infill_speed = 20 top_solid_layers = 15 -[print:0.05mm ULTRADETAIL] -inherits = *0.05mm* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.4 and num_extruders==1 -infill_extrusion_width = 0.5 - -# MK3 # -[print:0.05mm ULTRADETAIL @MK3] -inherits = *0.05mm*; *MK3* -fill_pattern = gyroid -fill_density = 15% -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and ! single_extruder_multi_material -top_infill_extrusion_width = 0.4 - -# MK2 # -[print:0.05mm ULTRADETAIL @0.25 nozzle] -inherits = *0.05mm*; *0.25nozzle* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 -fill_density = 20% -infill_speed = 20 -max_print_speed = 100 -perimeter_speed = 20 -small_perimeter_speed = 15 -solid_infill_speed = 20 -support_material_speed = 20 - -# MK3 # -[print:0.05mm ULTRADETAIL @0.25 nozzle MK3] -inherits = *0.05mm*; *0.25nozzle*; *MK3* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 -fill_pattern = grid -fill_density = 20% - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.07mm ---XXX -# XXXXXXXXXXXXXXXXXXXX - [print:*0.07mm*] -inherits = *common* -bottom_solid_layers = 8 -bridge_acceleration = 300 -bridge_flow_ratio = 0.7 -bridge_speed = 20 -default_acceleration = 1000 -external_perimeter_speed = 20 -fill_density = 15% -first_layer_acceleration = 500 -gap_fill_speed = 20 -infill_acceleration = 800 -infill_speed = 40 -max_print_speed = 80 -small_perimeter_speed = 20 -solid_infill_speed = 40 -support_material_extrusion_width = 0.3 -support_material_spacing = 1.5 +inherits = *0.05mm* layer_height = 0.07 -perimeter_acceleration = 300 -perimeter_speed = 30 -perimeters = 3 +bottom_solid_layers = 8 +bridge_flow_ratio = 1 +fill_density = 15% +infill_speed = 40 +solid_infill_speed = 40 support_material_speed = 40 top_solid_infill_speed = 30 top_solid_layers = 11 -# MK3 # -[print:0.07mm ULTRADETAIL @MK3] -inherits = *0.07mm*; *MK3* -fill_pattern = gyroid -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and ! single_extruder_multi_material -top_infill_extrusion_width = 0.4 - -[print:0.07mm ULTRADETAIL @0.25 nozzle MK3] -inherits = *0.07mm*; *0.25nozzle*; *MK3* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 -infill_speed = 30 -solid_infill_speed = 30 -support_material_speed = 30 -top_solid_infill_speed = 20 -fill_pattern = grid -fill_density = 20% - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.10mm ---XXX -# XXXXXXXXXXXXXXXXXXXX - -# MK2 # [print:*0.10mm*] inherits = *common* bottom_solid_layers = 7 -bridge_flow_ratio = 0.7 +bridge_flow_ratio = 1 +bridge_speed = 20 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.4 and num_extruders==1 layer_height = 0.1 perimeter_acceleration = 800 top_solid_layers = 9 - -# MK2 # -[print:0.10mm DETAIL] -inherits = *0.10mm* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.4 and num_extruders==1 -external_perimeter_speed = 40 -infill_acceleration = 2000 -infill_speed = 60 -perimeter_speed = 50 -solid_infill_speed = 50 -perimeters = 3 - -# MK3 # -[print:0.10mm DETAIL @MK3] -inherits = *0.10mm*; *MK3* -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 25 -infill_acceleration = 1000 -infill_speed = 80 -max_print_speed = 200 -perimeter_speed = 45 -solid_infill_speed = 80 -top_infill_extrusion_width = 0.4 -top_solid_infill_speed = 40 -fill_pattern = gyroid -fill_density = 15% -perimeters = 3 - -# MK2 # -[print:0.10mm DETAIL @0.25 nozzle] -inherits = *0.10mm*; *0.25nozzle* -bridge_acceleration = 600 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 -external_perimeter_speed = 20 -infill_acceleration = 1000 -infill_speed = 40 -perimeter_acceleration = 600 -perimeter_speed = 25 -small_perimeter_speed = 15 -solid_infill_speed = 40 -top_solid_infill_speed = 30 - -# MK3 # -[print:0.10mm DETAIL @0.25 nozzle MK3] -inherits = *0.10mm*; *0.25nozzleMK3*; *MK3* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 -fill_pattern = grid -fill_density = 20% - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.15mm ---XXX -# XXXXXXXXXXXXXXXXXXXX +support_material_contact_distance = 0.17 [print:*0.15mm*] inherits = *common* @@ -587,138 +463,8 @@ perimeter_speed = 50 solid_infill_speed = 50 top_infill_extrusion_width = 0.4 top_solid_layers = 7 - -# MK2 # -[print:0.15mm 100mms Linear Advance] -inherits = *0.15mm* -bridge_flow_ratio = 0.95 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 50 -infill_speed = 100 -max_print_speed = 150 -perimeter_speed = 60 -small_perimeter_speed = 30 -solid_infill_speed = 100 -support_material_speed = 60 -top_solid_infill_speed = 70 - -# MK2 # -[print:0.15mm OPTIMAL] -inherits = *0.15mm* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 -top_infill_extrusion_width = 0.45 - -# MK2 # -[print:0.15mm OPTIMAL @0.25 nozzle] -inherits = *0.15mm*; *0.25nozzle* -bridge_acceleration = 600 -bridge_flow_ratio = 0.7 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 -external_perimeter_speed = 20 -infill_acceleration = 1000 -infill_speed = 40 -perimeter_acceleration = 600 -perimeter_speed = 25 -small_perimeter_speed = 15 -solid_infill_speed = 40 -top_solid_infill_speed = 30 - -# MK2 # -[print:0.15mm OPTIMAL @0.6 nozzle] -inherits = *0.15mm*; *0.6nozzle* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 - -# MK3 # -[print:0.15mm QUALITY @MK3] -inherits = *0.15mm*; *MK3* -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 25 -infill_acceleration = 1000 -infill_speed = 80 -max_print_speed = 200 -perimeter_speed = 45 -solid_infill_speed = 80 -top_solid_infill_speed = 40 -fill_pattern = gyroid -fill_density = 15% - -[print:0.15mm SPEED @MK3] -inherits = *0.15mm*; *MK3* -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 200 -max_print_speed = 200 -perimeter_speed = 60 -solid_infill_speed = 200 -top_solid_infill_speed = 50 - -# MK3 MMU # -[print:0.15mm SOLUBLE FULL @MK3] -inherits = 0.15mm SPEED @MK3; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder -support_material_extruder = 5 -support_material_interface_extruder = 5 -perimeter_speed = 40 -solid_infill_speed = 40 -infill_speed = 80 -top_infill_extrusion_width = 0.45 -top_solid_infill_speed = 30 -support_material_speed = 45 - -# MK3 MMU # -[print:0.15mm SOLUBLE INTERFACE @MK3] -inherits = 0.15mm SOLUBLE FULL @MK3 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 - -# MK2 MMU # -[print:0.15mm OPTIMAL SOLUBLE FULL] -inherits = *0.15mm*; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -external_perimeter_speed = 25 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder -perimeter_speed = 40 -solid_infill_speed = 40 -top_infill_extrusion_width = 0.45 -top_solid_infill_speed = 30 - -# MK2 MMU # -[print:0.15mm OPTIMAL SOLUBLE INTERFACE] -inherits = 0.15mm OPTIMAL SOLUBLE FULL -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 -support_material_xy_spacing = 80% - -# MK3 # -[print:0.15mm QUALITY @0.25 nozzle MK3] -inherits = *0.15mm*; *0.25nozzleMK3*; *MK3* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 -fill_pattern = grid -fill_density = 20% - -# MK3 # -[print:0.15mm DETAIL @0.6 nozzle MK3] -inherits = *0.15mm*; *0.6nozzleMK3*; *MK306* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 70 -max_print_speed = 100 -perimeter_speed = 45 -solid_infill_speed = 70 -top_solid_infill_speed = 45 - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.20mm ---XXX -# XXXXXXXXXXXXXXXXXXXX +bridge_flow_ratio = 1 +bridge_speed = 25 [print:*0.20mm*] inherits = *common* @@ -734,114 +480,6 @@ solid_infill_speed = 50 top_infill_extrusion_width = 0.4 top_solid_layers = 5 -# MK2 # -[print:0.20mm 100mms Linear Advance] -inherits = *0.20mm* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 50 -infill_speed = 100 -max_print_speed = 150 -perimeter_speed = 60 -small_perimeter_speed = 30 -solid_infill_speed = 100 -support_material_speed = 60 -top_solid_infill_speed = 70 - -# MK3 # -[print:0.20mm QUALITY @MK3] -inherits = *0.20mm*; *MK3* -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 25 -infill_acceleration = 1000 -infill_speed = 80 -max_print_speed = 200 -perimeter_speed = 45 -solid_infill_speed = 80 -top_solid_infill_speed = 40 -fill_pattern = gyroid -fill_density = 15% - -[print:0.20mm SPEED @MK3] -inherits = *0.20mm*; *MK3* -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 200 -max_print_speed = 200 -perimeter_speed = 60 -solid_infill_speed = 200 -top_solid_infill_speed = 50 - -# MK3 MMU # -[print:0.20mm SOLUBLE FULL @MK3] -inherits = 0.20mm SPEED @MK3; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder -support_material_extruder = 5 -support_material_interface_extruder = 5 -perimeter_speed = 40 -solid_infill_speed = 40 -infill_speed = 80 -top_infill_extrusion_width = 0.45 -top_solid_infill_speed = 30 -support_material_speed = 45 - -# MK3 MMU # -[print:0.20mm SOLUBLE INTERFACE @MK3] -inherits = 0.20mm SOLUBLE FULL @MK3 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 - -# MK2 # -[print:0.20mm NORMAL] -inherits = *0.20mm* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 - -# MK2 # -[print:0.20mm NORMAL @0.6 nozzle] -inherits = *0.20mm*; *0.6nozzle* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 - -# MK2 MMU # -[print:0.20mm NORMAL SOLUBLE FULL] -inherits = *0.20mm*; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -external_perimeter_speed = 30 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder -perimeter_speed = 40 -solid_infill_speed = 40 -top_solid_infill_speed = 30 - -# MK2 MMU # -[print:0.20mm NORMAL SOLUBLE INTERFACE] -inherits = 0.20mm NORMAL SOLUBLE FULL -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 -support_material_xy_spacing = 80% - -# MK3 # -[print:0.20mm DETAIL @0.6 nozzle MK3] -inherits = *0.20mm*; *0.6nozzleMK3*; *MK306* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 70 -max_print_speed = 100 -perimeter_speed = 45 -solid_infill_speed = 70 -top_solid_infill_speed = 45 - - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.25mm ---XXX -# XXXXXXXXXXXXXXXXXXXX - [print:*0.25mm*] inherits = *common* bottom_solid_layers = 4 @@ -852,10 +490,6 @@ layer_height = 0.25 perimeter_speed = 50 top_solid_layers = 4 -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.30mm ---XXX -# XXXXXXXXXXXXXXXXXXXX - [print:*0.30mm*] inherits = *common* bottom_solid_layers = 4 @@ -869,65 +503,7 @@ perimeter_speed = 50 solid_infill_speed = 50 top_infill_extrusion_width = 0.4 top_solid_layers = 4 - -[print:0.30mm QUALITY @0.6 nozzle MK3] -inherits = *0.30mm*; *0.6nozzleMK3*; *MK306* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 70 -max_print_speed = 100 -perimeter_speed = 45 -solid_infill_speed = 70 -top_solid_infill_speed = 45 - -[print:0.30mm SOLUBLE FULL @0.6 nozzle MK3] -inherits = 0.30mm QUALITY @0.6 nozzle MK3; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 and num_extruders>1 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder -support_material_extruder = 5 -support_material_interface_extruder = 5 -support_material_speed = 40 -perimeter_speed = 40 -solid_infill_speed = 40 -top_infill_extrusion_width = 0.6 -support_material_extrusion_width = 0.6 -top_solid_infill_speed = 30 -support_material_xy_spacing = 80% - -[print:0.30mm SOLUBLE INTERFACE @0.6 nozzle MK3] -inherits = 0.30mm SOLUBLE FULL @0.6 nozzle MK3 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 - -[print:0.30mm DRAFT @MK3] -inherits = *0.30mm*; *MK3* -bottom_solid_layers = 3 -bridge_speed = 30 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 85 -max_print_speed = 200 -perimeter_speed = 50 -small_perimeter_speed = 30 -solid_infill_speed = 80 -top_solid_infill_speed = 40 -support_material_speed = 45 -external_perimeter_extrusion_width = 0.6 -extrusion_width = 0.5 -first_layer_extrusion_width = 0.42 -infill_extrusion_width = 0.5 -perimeter_extrusion_width = 0.5 -solid_infill_extrusion_width = 0.5 -top_infill_extrusion_width = 0.45 -support_material_extrusion_width = 0.38 - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.35mm ---XXX -# XXXXXXXXXXXXXXXXXXXX +support_material_contact_distance = 0.3 [print:*0.35mm*] inherits = *common* @@ -946,65 +522,6 @@ solid_infill_speed = 60 top_solid_infill_speed = 50 top_solid_layers = 4 -# MK2 # -[print:0.35mm FAST] -inherits = *0.35mm* -bridge_flow_ratio = 0.95 -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 -first_layer_extrusion_width = 0.42 -perimeter_extrusion_width = 0.43 -solid_infill_extrusion_width = 0.7 -top_infill_extrusion_width = 0.43 -support_material_extrusion_width = 0.37 - -# MK2 # -[print:0.35mm FAST @0.6 nozzle] -inherits = *0.35mm*; *0.6nozzle* -# alias = 0.35mm FAST -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 - -# MK2 MMU # -[print:0.35mm FAST sol full @0.6 nozzle] -inherits = *0.35mm*; *0.6nozzle*; *soluble_support* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_model=="MK2SMM" and nozzle_diameter[0]==0.6 and num_extruders>1 -external_perimeter_extrusion_width = 0.6 -external_perimeter_speed = 30 -notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder -perimeter_speed = 40 -support_material_speed = 40 -support_material_interface_layers = 2 -support_material_xy_spacing = 120% -top_infill_extrusion_width = 0.6 -support_material_extrusion_width = 0.6 - -# MK2 MMU # -[print:0.35mm FAST sol int @0.6 nozzle] -inherits = 0.35mm FAST sol full @0.6 nozzle -support_material_extruder = 0 -support_material_interface_layers = 3 -support_material_with_sheath = 0 -support_material_xy_spacing = 150% - -# MK3 # -[print:0.35mm SPEED @0.6 nozzle MK3] -inherits = *0.35mm*; *0.6nozzleMK3*; *MK306* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 70 -max_print_speed = 100 -perimeter_speed = 45 -solid_infill_speed = 70 -top_solid_infill_speed = 45 -external_perimeter_extrusion_width = 0.68 -perimeter_extrusion_width = 0.68 -infill_extrusion_width = 0.68 -solid_infill_extrusion_width = 0.68 - -# XXXXXXXXXXXXXXXXXXXX -# XXX--- 0.40mm ---XXX -# XXXXXXXXXXXXXXXXXXXX - [print:*0.40mm*] inherits = *common* bottom_solid_layers = 3 @@ -1022,71 +539,236 @@ solid_infill_speed = 60 top_solid_infill_speed = 40 top_solid_layers = 4 -# MK3 # -[print:0.40mm DRAFT @0.6 nozzle MK3] -inherits = *0.40mm*; *0.6nozzleMK3*; *MK306* -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 -external_perimeter_speed = 35 -infill_acceleration = 1000 -infill_speed = 70 +## MK2 family ## + +## MK2 - 0.4mm nozzle +[print:0.05mm ULTRADETAIL] +inherits = *0.05mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.4 and num_extruders==1 +infill_extrusion_width = 0.5 + +[print:0.10mm DETAIL] +inherits = *0.10mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.4 and num_extruders==1 +external_perimeter_speed = 40 +infill_acceleration = 2000 +infill_speed = 60 +perimeter_speed = 50 +solid_infill_speed = 50 +perimeters = 3 +bridge_acceleration = 800 + +[print:0.15mm 100mms Linear Advance] +inherits = *0.15mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 50 +infill_speed = 100 +max_print_speed = 150 +perimeter_speed = 60 +small_perimeter_speed = 30 +solid_infill_speed = 100 +support_material_speed = 60 +top_solid_infill_speed = 70 + +[print:0.15mm OPTIMAL] +inherits = *0.15mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 +top_infill_extrusion_width = 0.45 + +[print:0.20mm 100mms Linear Advance] +inherits = *0.20mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 50 +infill_speed = 100 +max_print_speed = 150 +perimeter_speed = 60 +small_perimeter_speed = 30 +solid_infill_speed = 100 +support_material_speed = 60 +top_solid_infill_speed = 70 + +[print:0.20mm NORMAL] +inherits = *0.20mm* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 + +[print:0.35mm FAST] +inherits = *0.35mm* +bridge_flow_ratio = 0.95 +bridge_speed = 30 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 +first_layer_extrusion_width = 0.42 +perimeter_extrusion_width = 0.43 +solid_infill_extrusion_width = 0.7 +top_infill_extrusion_width = 0.45 +support_material_extrusion_width = 0.37 +support_material_contact_distance = 0.1 +top_solid_infill_speed = 40 +thick_bridges = 1 + +## MMU1 specific +[print:0.15mm OPTIMAL SOLUBLE FULL] +inherits = *0.15mm*; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 and num_extruders>1 +external_perimeter_speed = 25 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder +perimeter_speed = 40 +solid_infill_speed = 40 +top_infill_extrusion_width = 0.45 +top_solid_infill_speed = 30 +bridge_flow_ratio = 0.8 +bridge_speed = 30 + +[print:0.15mm OPTIMAL SOLUBLE INTERFACE] +inherits = 0.15mm OPTIMAL SOLUBLE FULL +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 +support_material_xy_spacing = 80% + +[print:0.20mm NORMAL SOLUBLE FULL] +inherits = *0.20mm*; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2[^\.].*/ and nozzle_diameter[0]==0.4 and num_extruders>1 +external_perimeter_speed = 30 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder +perimeter_speed = 40 +solid_infill_speed = 40 +top_solid_infill_speed = 30 +bridge_flow_ratio = 0.95 +bridge_speed = 30 + +[print:0.20mm NORMAL SOLUBLE INTERFACE] +inherits = 0.20mm NORMAL SOLUBLE FULL +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 +support_material_xy_spacing = 80% + +## MK2 - 0.25mm nozzle + +[print:0.05mm ULTRADETAIL @0.25 nozzle] +inherits = *0.05mm*; *0.25nozzle* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 +fill_density = 20% +infill_speed = 20 max_print_speed = 100 -perimeter_speed = 45 -solid_infill_speed = 70 -top_solid_infill_speed = 45 -external_perimeter_extrusion_width = 0.68 -perimeter_extrusion_width = 0.68 -infill_extrusion_width = 0.68 -solid_infill_extrusion_width = 0.68 +perimeter_speed = 20 +small_perimeter_speed = 15 +solid_infill_speed = 20 +support_material_speed = 20 +support_material_contact_distance = 0.07 -# XXXXXXXXXXXXXXXXXXXXXX -# XXX----- MK2.5 ----XXX -# XXXXXXXXXXXXXXXXXXXXXX +[print:0.10mm DETAIL @0.25 nozzle] +inherits = *0.10mm*; *0.25nozzle* +bridge_acceleration = 600 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 +external_perimeter_speed = 20 +infill_acceleration = 1000 +infill_speed = 40 +perimeter_acceleration = 600 +perimeter_speed = 25 +small_perimeter_speed = 15 +solid_infill_speed = 40 +top_solid_infill_speed = 30 +support_material_contact_distance = 0.07 -# MK2.5 # -[print:0.15mm 100mms Linear Advance @MK2.5] -inherits = 0.15mm 100mms Linear Advance -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 -single_extruder_multi_material_priming = 0 +[print:0.15mm OPTIMAL @0.25 nozzle] +inherits = *0.15mm*; *0.25nozzle* +bridge_acceleration = 600 +bridge_flow_ratio = 0.8 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.25 +external_perimeter_speed = 20 +infill_acceleration = 1000 +infill_speed = 40 +perimeter_acceleration = 600 +perimeter_speed = 25 +small_perimeter_speed = 15 +solid_infill_speed = 40 +top_solid_infill_speed = 30 +support_material_contact_distance = 0.08 -# MK2.5 # -[print:0.15mm OPTIMAL @MK2.5] -inherits = 0.15mm OPTIMAL -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 -single_extruder_multi_material_priming = 0 +## MK2 - 0.6mm nozzle + +[print:0.15mm OPTIMAL @0.6 nozzle] +inherits = *0.15mm*; *0.6nozzle* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 + +[print:0.20mm NORMAL @0.6 nozzle] +inherits = *0.20mm*; *0.6nozzle* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 + +[print:0.35mm FAST @0.6 nozzle] +inherits = *0.35mm*; *0.6nozzle* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and nozzle_diameter[0]==0.6 + +## MMU1 specific +[print:0.35mm FAST sol full @0.6 nozzle] +inherits = *0.35mm*; *0.6nozzle*; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_model=="MK2SMM" and nozzle_diameter[0]==0.6 and num_extruders>1 +external_perimeter_extrusion_width = 0.6 +external_perimeter_speed = 30 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +perimeter_speed = 40 +support_material_speed = 40 +support_material_interface_layers = 2 +support_material_xy_spacing = 120% +top_infill_extrusion_width = 0.6 +support_material_extrusion_width = 0.6 + +[print:0.35mm FAST sol int @0.6 nozzle] +inherits = 0.35mm FAST sol full @0.6 nozzle +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 +support_material_xy_spacing = 150% + +## MK2.5 -# MK2.5 MMU2 # [print:0.10mm DETAIL @MK2.5] inherits = 0.10mm DETAIL compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 single_extruder_multi_material_priming = 0 -# MK2.5 MMU2 # +[print:0.15mm 100mms Linear Advance @MK2.5] +inherits = 0.15mm 100mms Linear Advance +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 +single_extruder_multi_material_priming = 0 + +[print:0.15mm OPTIMAL @MK2.5] +inherits = 0.15mm OPTIMAL +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 +single_extruder_multi_material_priming = 0 + +[print:0.20mm 100mms Linear Advance @MK2.5] +inherits = 0.20mm 100mms Linear Advance +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 +single_extruder_multi_material_priming = 0 + +[print:0.20mm NORMAL @MK2.5] +inherits = 0.20mm NORMAL +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 +single_extruder_multi_material_priming = 0 + +[print:0.35mm FAST @MK2.5] +inherits = 0.35mm FAST +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 +single_extruder_multi_material_priming = 0 + +## MK2.5 - MMU2 specific + [print:0.15mm OPTIMAL SOLUBLE FULL @MK2.5] inherits = 0.15mm OPTIMAL SOLUBLE FULL support_material_extruder = 5 support_material_interface_extruder = 5 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -# MK2.5 MMU2 # [print:0.15mm OPTIMAL SOLUBLE INTERFACE @MK2.5] inherits = 0.15mm OPTIMAL SOLUBLE INTERFACE support_material_extruder = 0 support_material_interface_extruder = 5 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 -# MK2.5 # -[print:0.20mm 100mms Linear Advance @MK2.5] -inherits = 0.20mm 100mms Linear Advance -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 -single_extruder_multi_material_priming = 0 - -# MK2.5 # -[print:0.20mm NORMAL @MK2.5] -inherits = 0.20mm NORMAL -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 -single_extruder_multi_material_priming = 0 - -# MK2.5 MMU2 # [print:0.20mm NORMAL SOLUBLE FULL @MK2.5] inherits = 0.20mm NORMAL SOLUBLE FULL support_material_extruder = 5 @@ -1094,7 +776,6 @@ support_material_interface_extruder = 5 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 single_extruder_multi_material_priming = 0 -# MK2.5 MMU2 # [print:0.20mm NORMAL SOLUBLE INTERFACE @MK2.5] inherits = 0.20mm NORMAL SOLUBLE INTERFACE support_material_extruder = 0 @@ -1102,14 +783,7 @@ support_material_interface_extruder = 5 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 single_extruder_multi_material_priming = 0 -# MK2.5 # -[print:0.35mm FAST @MK2.5] -inherits = 0.35mm FAST -# alias = 0.35mm FAST -compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.5.*/ and nozzle_diameter[0]==0.4 -single_extruder_multi_material_priming = 0 - -# MK2.5 MMU2 0.6 nozzle # +# MK2.5 MMU2 0.6 nozzle [print:0.35mm SOLUBLE FULL @0.6 nozzle MK2.5] inherits = *0.35mm*; *0.6nozzle*; *soluble_support* compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK2.*/ and printer_model!="MK2SMM" and nozzle_diameter[0]==0.6 and num_extruders>1 @@ -1132,12 +806,296 @@ support_material_interface_layers = 3 support_material_with_sheath = 0 support_material_xy_spacing = 80% -## 0.8mm nozzle print profiles +## MK3 family ## + +## MK3 - 0.4mm nozzle + +[print:0.05mm ULTRADETAIL @MK3] +inherits = *0.05mm*; *MK3* +fill_pattern = gyroid +fill_density = 15% +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and ! single_extruder_multi_material +top_infill_extrusion_width = 0.4 + +[print:0.07mm ULTRADETAIL @MK3] +inherits = *0.07mm*; *MK3* +fill_pattern = gyroid +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and ! single_extruder_multi_material +top_infill_extrusion_width = 0.4 + +[print:0.10mm DETAIL @MK3] +inherits = *0.10mm*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 25 +infill_acceleration = 1000 +bridge_acceleration = 800 +infill_speed = 80 +max_print_speed = 200 +perimeter_speed = 45 +solid_infill_speed = 80 +top_infill_extrusion_width = 0.4 +top_solid_infill_speed = 40 +fill_pattern = gyroid +fill_density = 15% +perimeters = 3 + +[print:0.15mm QUALITY @MK3] +inherits = *0.15mm*; *MK3* +bridge_speed = 25 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 25 +infill_acceleration = 1000 +infill_speed = 80 +max_print_speed = 200 +perimeter_speed = 45 +solid_infill_speed = 80 +top_solid_infill_speed = 40 +fill_pattern = gyroid +fill_density = 15% + +[print:0.15mm SPEED @MK3] +inherits = *0.15mm*; *MK3* +bridge_speed = 25 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 200 +max_print_speed = 200 +perimeter_speed = 60 +solid_infill_speed = 200 +top_solid_infill_speed = 50 + +[print:0.20mm QUALITY @MK3] +inherits = *0.20mm*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 25 +infill_acceleration = 1000 +infill_speed = 80 +max_print_speed = 200 +perimeter_speed = 45 +solid_infill_speed = 80 +top_solid_infill_speed = 40 +fill_pattern = gyroid +fill_density = 15% + +[print:0.20mm SPEED @MK3] +inherits = *0.20mm*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 200 +max_print_speed = 200 +perimeter_speed = 60 +solid_infill_speed = 200 +top_solid_infill_speed = 50 + +[print:0.30mm DRAFT @MK3] +inherits = *0.30mm*; *MK3* +bottom_solid_layers = 3 +bridge_speed = 25 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 85 +max_print_speed = 200 +perimeter_speed = 50 +small_perimeter_speed = 30 +solid_infill_speed = 80 +top_solid_infill_speed = 40 +support_material_speed = 45 +external_perimeter_extrusion_width = 0.6 +extrusion_width = 0.5 +first_layer_extrusion_width = 0.42 +infill_extrusion_width = 0.5 +perimeter_extrusion_width = 0.5 +solid_infill_extrusion_width = 0.5 +top_infill_extrusion_width = 0.45 +support_material_extrusion_width = 0.38 +support_material_contact_distance = 0.2 + +## MK3 - MMU2 specific +[print:0.15mm SOLUBLE FULL @MK3] +inherits = 0.15mm SPEED @MK3; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder +support_material_extruder = 5 +support_material_interface_extruder = 5 +perimeter_speed = 40 +solid_infill_speed = 40 +infill_speed = 80 +top_infill_extrusion_width = 0.45 +top_solid_infill_speed = 30 +support_material_speed = 45 +bridge_flow_ratio = 0.8 +bridge_speed = 30 + +[print:0.15mm SOLUBLE INTERFACE @MK3] +inherits = 0.15mm SOLUBLE FULL @MK3 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 + +[print:0.20mm SOLUBLE FULL @MK3] +inherits = 0.20mm SPEED @MK3; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.4 and num_extruders>1 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder +support_material_extruder = 5 +support_material_interface_extruder = 5 +perimeter_speed = 40 +solid_infill_speed = 40 +infill_speed = 80 +top_infill_extrusion_width = 0.45 +top_solid_infill_speed = 30 +support_material_speed = 45 +bridge_flow_ratio = 0.95 +bridge_speed = 30 + +[print:0.20mm SOLUBLE INTERFACE @MK3] +inherits = 0.20mm SOLUBLE FULL @MK3 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 + +## MK3 - 0.25mm nozzle + +[print:0.05mm ULTRADETAIL @0.25 nozzle MK3] +inherits = *0.05mm*; *0.25nozzle*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 +fill_pattern = grid +fill_density = 20% +support_material_contact_distance = 0.07 + +[print:0.07mm ULTRADETAIL @0.25 nozzle MK3] +inherits = *0.07mm*; *0.25nozzle*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 and num_extruders==1 +infill_speed = 30 +solid_infill_speed = 30 +support_material_speed = 30 +top_solid_infill_speed = 20 +fill_pattern = grid +fill_density = 20% +support_material_contact_distance = 0.07 + +[print:0.10mm DETAIL @0.25 nozzle MK3] +inherits = *0.10mm*; *0.25nozzleMK3*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 +fill_pattern = grid +fill_density = 20% +support_material_contact_distance = 0.07 + +[print:0.15mm QUALITY @0.25 nozzle MK3] +inherits = *0.15mm*; *0.25nozzleMK3*; *MK3* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.25 +fill_pattern = grid +fill_density = 20% +support_material_contact_distance = 0.08 + +## MK3 - 0.6mm nozzle + +[print:0.15mm DETAIL @0.6 nozzle MK3] +inherits = *0.15mm*; *0.6nozzleMK3*; *MK306* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 70 +max_print_speed = 100 +perimeter_speed = 45 +solid_infill_speed = 70 +top_solid_infill_speed = 45 +support_material_contact_distance = 0.22 +bridge_flow_ratio = 1 + +[print:0.20mm DETAIL @0.6 nozzle MK3] +inherits = *0.20mm*; *0.6nozzleMK3*; *MK306* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 70 +max_print_speed = 100 +perimeter_speed = 45 +solid_infill_speed = 70 +top_solid_infill_speed = 45 +support_material_contact_distance = 0.22 +bridge_flow_ratio = 1 + +[print:0.30mm QUALITY @0.6 nozzle MK3] +inherits = *0.30mm*; *0.6nozzleMK3*; *MK306* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 70 +max_print_speed = 100 +perimeter_speed = 45 +solid_infill_speed = 70 +top_solid_infill_speed = 45 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 1 + +[print:0.35mm SPEED @0.6 nozzle MK3] +inherits = *0.35mm*; *0.6nozzleMK3*; *MK306* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 70 +max_print_speed = 100 +perimeter_speed = 45 +solid_infill_speed = 70 +top_solid_infill_speed = 45 +external_perimeter_extrusion_width = 0.68 +perimeter_extrusion_width = 0.68 +infill_extrusion_width = 0.68 +solid_infill_extrusion_width = 0.68 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 0.95 + +[print:0.40mm DRAFT @0.6 nozzle MK3] +inherits = *0.40mm*; *0.6nozzleMK3*; *MK306* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 +external_perimeter_speed = 35 +infill_acceleration = 1000 +infill_speed = 70 +max_print_speed = 100 +perimeter_speed = 45 +solid_infill_speed = 70 +top_solid_infill_speed = 45 +external_perimeter_extrusion_width = 0.68 +perimeter_extrusion_width = 0.68 +infill_extrusion_width = 0.68 +solid_infill_extrusion_width = 0.68 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 0.95 + +## MK3 - MMU2 specific + +[print:0.30mm SOLUBLE FULL @0.6 nozzle MK3] +inherits = 0.30mm QUALITY @0.6 nozzle MK3; *soluble_support* +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and nozzle_diameter[0]==0.6 and num_extruders>1 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft/skirt extruder & Support material/raft interface extruder +support_material_extruder = 5 +support_material_interface_extruder = 5 +support_material_speed = 40 +perimeter_speed = 40 +solid_infill_speed = 40 +top_infill_extrusion_width = 0.6 +support_material_extrusion_width = 0.6 +top_solid_infill_speed = 30 +support_material_xy_spacing = 80% + +[print:0.30mm SOLUBLE INTERFACE @0.6 nozzle MK3] +inherits = 0.30mm SOLUBLE FULL @0.6 nozzle MK3 +notes = Set your soluble extruder in Multiple Extruders > Support material/raft interface extruder +support_material_extruder = 0 +support_material_interface_layers = 3 +support_material_with_sheath = 0 + +## 0.8mm nozzle - MK2.5 and MK3 +## Only for MMU2 Single mode at the moment [print:0.30mm DETAIL @0.8 nozzle] inherits = *common*; *0.8nozzle* layer_height = 0.30 -## Only for MMU2 Single mode at the moment compatible_printers_condition = printer_model=~/(MK3|MK2.5).*/ and nozzle_diameter[0]==0.8 and num_extruders==1 perimeter_speed = 35 external_perimeter_speed = 25 @@ -1151,7 +1109,6 @@ support_material_speed = 40 [print:0.40mm QUALITY @0.8 nozzle] inherits = *common*; *0.8nozzle* layer_height = 0.4 -## Only for MMU2 Single mode at the moment compatible_printers_condition = printer_model=~/(MK3|MK2.5).*/ and nozzle_diameter[0]==0.8 and num_extruders==1 perimeter_speed = 35 external_perimeter_speed = 25 @@ -1165,7 +1122,6 @@ support_material_speed = 40 [print:0.55mm DRAFT @0.8 nozzle] inherits = *common*; *0.8nozzle* layer_height = 0.55 -## Only for MMU2 Single mode at the moment compatible_printers_condition = printer_model=~/(MK3|MK2.5).*/ and nozzle_diameter[0]==0.8 and num_extruders==1 perimeter_speed = 30 external_perimeter_speed = 25 @@ -1179,9 +1135,9 @@ top_solid_infill_speed = 30 external_perimeter_extrusion_width = 1 perimeter_extrusion_width = 1 -## MINI print profiles +## MINI ## -# 0.4mm nozzle +# MINI - 0.4mm nozzle [print:0.05mm ULTRADETAIL @MINI] inherits = *0.05mm*; *MINI* @@ -1194,6 +1150,8 @@ perimeter_extrusion_width = 0.4 external_perimeter_extrusion_width = 0.4 support_material_xy_spacing = 60% support_material_speed = 30 +support_material_extrusion_width = 0.35 +bridge_acceleration = 300 [print:0.07mm ULTRADETAIL @MINI] inherits = *0.07mm*; *MINI* @@ -1205,10 +1163,13 @@ small_perimeter_speed = 15 perimeter_extrusion_width = 0.4 external_perimeter_extrusion_width = 0.4 support_material_xy_spacing = 60% +support_material_extrusion_width = 0.35 +bridge_acceleration = 300 [print:0.10mm DETAIL @MINI] inherits = *0.10mm*; *MINI* -bridge_speed = 30 +bridge_speed = 20 +bridge_acceleration = 700 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 perimeter_speed = 40 external_perimeter_speed = 30 @@ -1219,12 +1180,10 @@ top_solid_infill_speed = 40 fill_pattern = gyroid fill_density = 15% perimeters = 3 -bridge_acceleration = 1000 support_material_xy_spacing = 60% [print:0.15mm QUALITY @MINI] inherits = *0.15mm*; *MINI* -bridge_speed = 30 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 perimeter_speed = 40 external_perimeter_speed = 30 @@ -1233,24 +1192,20 @@ solid_infill_speed = 80 top_solid_infill_speed = 40 fill_pattern = gyroid fill_density = 15% -bridge_flow_ratio = 0.85 support_material_xy_spacing = 60% [print:0.15mm SPEED @MINI] inherits = *0.15mm*; *MINI* -bridge_speed = 30 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 perimeter_speed = 50 external_perimeter_speed = 40 infill_speed = 140 solid_infill_speed = 140 top_solid_infill_speed = 40 -bridge_flow_ratio = 0.85 support_material_xy_spacing = 60% [print:0.20mm QUALITY @MINI] inherits = *0.20mm*; *MINI* -bridge_speed = 30 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 perimeter_speed = 40 external_perimeter_speed = 30 @@ -1263,7 +1218,6 @@ support_material_xy_spacing = 60% [print:0.20mm SPEED @MINI] inherits = *0.20mm*; *MINI* -bridge_speed = 30 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 perimeter_speed = 50 external_perimeter_speed = 40 @@ -1275,7 +1229,8 @@ support_material_xy_spacing = 60% [print:0.25mm DRAFT @MINI] inherits = *0.25mm*; *MINI* -bridge_speed = 30 +bridge_speed = 25 +bridge_flow_ratio = 0.95 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.4 external_perimeter_speed = 40 infill_speed = 110 @@ -1288,8 +1243,9 @@ infill_extrusion_width = 0.45 solid_infill_extrusion_width = 0.45 top_infill_extrusion_width = 0.4 support_material_xy_spacing = 60% +support_material_contact_distance = 0.2 -# 0.25mm nozzle +# MINI - 0.25mm nozzle [print:0.05mm ULTRADETAIL @0.25 nozzle MINI] inherits = *0.05mm*; *0.25nozzle*; *MINI* @@ -1297,6 +1253,7 @@ compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and fill_pattern = grid fill_density = 20% support_material_speed = 30 +support_material_contact_distance = 0.07 [print:0.07mm ULTRADETAIL @0.25 nozzle MINI] inherits = *0.07mm*; *0.25nozzle*; *MINI* @@ -1307,20 +1264,23 @@ support_material_speed = 30 top_solid_infill_speed = 20 fill_pattern = grid fill_density = 20% +support_material_contact_distance = 0.07 [print:0.10mm DETAIL @0.25 nozzle MINI] inherits = *0.10mm*; *0.25nozzleMINI*; *MINI* compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.25 fill_pattern = grid fill_density = 20% +support_material_contact_distance = 0.07 [print:0.15mm QUALITY @0.25 nozzle MINI] inherits = *0.15mm*; *0.25nozzleMINI*; *MINI* compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.25 fill_pattern = grid fill_density = 20% +support_material_contact_distance = 0.08 -# 0.6mm nozzle MINI +# MINI - 0.6mm nozzle [print:0.15mm DETAIL @0.6 nozzle MINI] inherits = *0.15mm*; *0.6nozzleMINI* @@ -1333,6 +1293,8 @@ solid_infill_speed = 70 top_solid_infill_speed = 45 infill_extrusion_width = 0.65 solid_infill_extrusion_width = 0.65 +support_material_contact_distance = 0.22 +bridge_flow_ratio = 1 [print:0.20mm DETAIL @0.6 nozzle MINI] inherits = *0.20mm*; *0.6nozzleMINI* @@ -1345,6 +1307,8 @@ solid_infill_speed = 70 top_solid_infill_speed = 45 infill_extrusion_width = 0.65 solid_infill_extrusion_width = 0.65 +support_material_contact_distance = 0.22 +bridge_flow_ratio = 1 [print:0.30mm QUALITY @0.6 nozzle MINI] inherits = *0.30mm*; *0.6nozzleMINI* @@ -1357,6 +1321,8 @@ solid_infill_speed = 65 top_solid_infill_speed = 45 external_perimeter_extrusion_width = 0.68 perimeter_extrusion_width = 0.68 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 1 [print:0.35mm SPEED @0.6 nozzle MINI] inherits = *0.35mm*; *0.6nozzleMINI* @@ -1369,6 +1335,8 @@ solid_infill_speed = 60 top_solid_infill_speed = 45 external_perimeter_extrusion_width = 0.68 perimeter_extrusion_width = 0.68 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 0.95 [print:0.40mm DRAFT @0.6 nozzle MINI] inherits = *0.40mm*; *0.6nozzleMINI* @@ -1383,8 +1351,10 @@ external_perimeter_extrusion_width = 0.68 perimeter_extrusion_width = 0.68 infill_extrusion_width = 0.68 solid_infill_extrusion_width = 0.68 +support_material_contact_distance = 0.25 +bridge_flow_ratio = 0.95 -# 0.8mm nozzle MINI +# MINI - 0.8mm nozzle [print:0.30mm DETAIL @0.8 nozzle MINI] inherits = 0.30mm DETAIL @0.8 nozzle @@ -1490,7 +1460,7 @@ max_fan_speed = 50 min_fan_speed = 30 start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.02{elsif nozzle_diameter[0]==0.6}0.04{else}0.08{endif} ; Filament gcode LA 1.5\n{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K24{elsif nozzle_diameter[0]==0.8};{else}M900 K45{endif} ; Filament gcode LA 1.0" temperature = 240 -filament_retract_length = 1.4 +filament_retract_length = 1 filament_retract_lift = 0.2 compatible_printers_condition = printer_model!="MK2SMM" and printer_model!="MINI" and ! (printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK(2.5|3).*/ and single_extruder_multi_material) @@ -1500,14 +1470,14 @@ compatible_printers_condition = nozzle_diameter[0]==0.6 and printer_model!="MK2S filament_max_volumetric_speed = 15 [filament:*PETMMU1*] -inherits = *PET* +; inherits = *PET* filament_retract_length = nil filament_retract_speed = nil filament_retract_lift = 0.2 compatible_printers_condition = printer_model=="MK2SMM" [filament:*PETMINI*] -inherits = *PET* +; inherits = *PET* filament_retract_length = nil filament_retract_speed = 40 filament_deretract_speed = 25 @@ -1518,7 +1488,7 @@ compatible_printers_condition = printer_model=="MINI" start_filament_gcode = "M900 K{if nozzle_diameter[0]==0.6}0.12{elsif nozzle_diameter[0]==0.8}0.06{else}0.2{endif} ; Filament gcode" [filament:*PETMINI06*] -inherits = *PET* +; inherits = *PET* filament_retract_length = nil filament_retract_speed = 40 filament_deretract_speed = 25 @@ -1529,7 +1499,7 @@ start_filament_gcode = "M900 K0.12 ; Filament gcode" filament_max_volumetric_speed = 13 [filament:*ABSMINI*] -inherits = *ABS* +; inherits = *ABS* bed_temperature = 100 filament_retract_length = 2.7 filament_retract_speed = nil @@ -1861,8 +1831,8 @@ min_fan_speed = 20 max_fan_speed = 20 min_print_speed = 15 slowdown_below_layer_time = 15 -first_layer_temperature = 265 -temperature = 265 +first_layer_temperature = 260 +temperature = 260 filament_type = ASA [filament:Prusament ASA] @@ -2015,9 +1985,10 @@ filament_cost = 27.82 filament_density = 1.04 filament_spool_weight = 245 -[filament:Plasty Mladec ABS] +[filament:Filament PM ABS] inherits = *ABSC* -filament_vendor = Plasty Mladec +renamed_from = "Plasty Mladec ABS" +filament_vendor = Filament PM filament_cost = 27.82 filament_density = 1.08 filament_spool_weight = 230 @@ -2038,9 +2009,21 @@ filament_cost = 27.82 filament_density = 1.27 compatible_printers_condition = nozzle_diameter[0]!=0.8 and printer_model!="MK2SMM" and printer_model!="MINI" and ! (printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK(2.5|3).*/ and single_extruder_multi_material) -[filament:Plasty Mladec PETG] +[filament:Extrudr PETG] inherits = *PET* -filament_vendor = Plasty Mladec +filament_vendor = Extrudr +filament_cost = 35.45 +filament_density = 1.29 +temperature = 220 +bed_temperature = 70 +first_layer_temperature = 220 +first_layer_bed_temperature = 70 +slowdown_below_layer_time = 20 + +[filament:Filament PM PETG] +inherits = *PET* +renamed_from = "Plasty Mladec PETG" +filament_vendor = Filament PM filament_cost = 27.82 filament_density = 1.27 filament_spool_weight = 230 @@ -2301,9 +2284,10 @@ filament_vendor = Made for Prusa filament_cost = 27.82 filament_spool_weight = 230 -[filament:Plasty Mladec ABS @MMU2] +[filament:Filament PM ABS @MMU2] inherits = *ABS MMU2* -filament_vendor = Plasty Mladec +renamed_from = "Plasty Mladec ABS @MMU2" +filament_vendor = Filament PM filament_density = 1.08 filament_cost = 27.82 filament_spool_weight = 230 @@ -2402,9 +2386,10 @@ filament_density = 1.27 filament_spool_weight = 201 filament_type = PETG -[filament:Plasty Mladec PETG @0.6 nozzle] +[filament:Filament PM PETG @0.6 nozzle] inherits = *PET06* -filament_vendor = Plasty Mladec +renamed_from = "Plasty Mladec PETG @0.6 nozzle" +filament_vendor = Filament PM first_layer_temperature = 230 temperature = 240 filament_cost = 27.82 @@ -2458,7 +2443,7 @@ filament_unload_time = 12 filament_unloading_speed = 20 filament_unloading_speed_start = 120 filament_loading_speed_start = 19 -filament_retract_length = 1.4 +filament_retract_length = 1 filament_retract_lift = 0.2 [filament:*PET MMU2 06*] @@ -2471,9 +2456,10 @@ inherits = *PET MMU2* renamed_from = "Generic PET MMU2"; "Generic PETG MMU2" filament_vendor = Generic -[filament:Plasty Mladec PETG @MMU2] +[filament:Filament PM PETG @MMU2] inherits = *PET MMU2* -filament_vendor = Plasty Mladec +renamed_from = "Plasty Mladec PETG @MMU2" +filament_vendor = Filament PM filament_spool_weight = 230 [filament:Prusa PETG @MMU2] @@ -2510,10 +2496,11 @@ filament_cost = 36.29 filament_density = 1.27 filament_spool_weight = 201 -[filament:Plasty Mladec PETG @MMU2 0.6 nozzle] +[filament:Filament PM PETG @MMU2 0.6 nozzle] inherits = *PET MMU2 06* +renamed_from = "Plasty Mladec PETG @MMU2 0.6 nozzle" filament_type = PETG -filament_vendor = Plasty Mladec +filament_vendor = Filament PM filament_spool_weight = 230 [filament:Prusa PLA] @@ -2530,9 +2517,10 @@ filament_vendor = Fiberlogy filament_cost = 25.4 filament_density = 1.24 -[filament:Plasty Mladec PLA] +[filament:Filament PM PLA] inherits = *PLA* -filament_vendor = Plasty Mladec +renamed_from = "Plasty Mladec PLA" +filament_vendor = Filament PM filament_cost = 27.82 filament_density = 1.24 filament_spool_weight = 230 @@ -2576,6 +2564,26 @@ filament_vendor = EUMAKERS filament_cost = 25.4 filament_density = 1.24 +[filament:Extrudr PLA NX1] +inherits = *PLA* +filament_vendor = Extrudr +filament_cost = 22.76 +filament_density = 1.24 +temperature = 205 +bed_temperature = 60 +first_layer_temperature = 205 +first_layer_bed_temperature = 60 +full_fan_speed_layer = 3 +max_fan_speed = 90 +min_fan_speed = 30 +slowdown_below_layer_time = 20 + +[filament:Extrudr PLA NX2] +inherits = Extrudr PLA NX1 +filament_vendor = Extrudr +filament_cost = 23.63 +filament_density = 1.3 + [filament:Floreon3D PLA] inherits = *PLA* filament_vendor = Floreon3D @@ -2930,204 +2938,75 @@ temperature = 220 ## Filaments MMU1 [filament:ColorFabb HT @MMU1] -inherits = *PETMMU1* -filament_vendor = ColorFabb -bed_temperature = 110 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 0 -fan_below_layer_time = 10 -filament_cost = 58.66 -filament_density = 1.18 -filament_spool_weight = 236 -first_layer_bed_temperature = 105 -first_layer_temperature = 270 -max_fan_speed = 20 -min_fan_speed = 10 +inherits = ColorFabb HT; *PETMMU1* start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}200{else}45{endif}; Filament gcode" -temperature = 270 [filament:ColorFabb XT @MMU1] -inherits = *PETMMU1* -filament_vendor = ColorFabb -filament_type = PETG -filament_cost = 62.90 -filament_density = 1.27 -filament_spool_weight = 236 -first_layer_bed_temperature = 90 -first_layer_temperature = 260 -temperature = 270 +inherits = ColorFabb XT; *PETMMU1* [filament:ColorFabb XT-CF20 @MMU1] -inherits = *PETMMU1* -filament_vendor = ColorFabb -compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MK2SMM" -extrusion_multiplier = 1.05 -filament_cost = 80.65 -filament_density = 1.35 -filament_spool_weight = 236 -filament_colour = #804040 -filament_max_volumetric_speed = 2 -first_layer_bed_temperature = 90 -first_layer_temperature = 260 +inherits = ColorFabb XT-CF20; *PETMMU1* start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}200{else}30{endif}; Filament gcode" -temperature = 260 [filament:ColorFabb nGen @MMU1] -inherits = *PETMMU1* -filament_vendor = ColorFabb -filament_cost = 21.2 -filament_density = 1.2 -filament_spool_weight = 236 -bridge_fan_speed = 40 -fan_always_on = 0 -fan_below_layer_time = 10 -filament_type = NGEN -first_layer_temperature = 240 -max_fan_speed = 35 -min_fan_speed = 20 +inherits = ColorFabb nGen; *PETMMU1* [filament:E3D Edge @MMU1] -inherits = *PETMMU1* -filament_vendor = E3D -filament_cost = 56.9 -filament_density = 1.26 -filament_type = EDGE +inherits = E3D Edge; *PETMMU1* [filament:Fillamentum CPE @MMU1] -inherits = *PETMMU1* -filament_vendor = Fillamentum -filament_cost = 56.45 -filament_density = 1.25 -filament_spool_weight = 230 -filament_type = CPE -first_layer_bed_temperature = 90 -first_layer_temperature = 275 -max_fan_speed = 50 -min_fan_speed = 50 -disable_fan_first_layers = 3 -full_fan_speed_layer = 5 -temperature = 275 +inherits = Fillamentum CPE; *PETMMU1* [filament:Generic PETG @MMU1] -inherits = *PETMMU1* +inherits = Generic PETG; *PETMMU1* renamed_from = "Generic PET MMU1"; "Generic PETG MMU1" -filament_vendor = Generic -filament_cost = 27.82 -filament_density = 1.27 [filament:Devil Design PETG @MMU1] -inherits = *PETMMU1* -filament_vendor = Devil Design -filament_cost = 20.99 -filament_density = 1.23 -filament_spool_weight = 250 -first_layer_temperature = 230 -first_layer_bed_temperature = 85 -temperature = 230 -bed_temperature = 90 +inherits = Devil Design PETG; *PETMMU1* -[filament:Plasty Mladec PETG @MMU1] -inherits = *PETMMU1* -filament_vendor = Plasty Mladec -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 +[filament:Filament PM PETG @MMU1] +inherits = Filament PM PETG; *PETMMU1* +renamed_from = "Plasty Mladec PETG @MMU1" [filament:Verbatim PETG @MMU1] -inherits = *PETMMU1* -filament_vendor = Verbatim -filament_cost = 27.90 -filament_density = 1.27 -filament_spool_weight = 235 +inherits = Verbatim PETG; *PETMMU1* [filament:Fiberlogy PETG @MMU1] -inherits = *PETMMU1* -filament_vendor = Fiberlogy -filament_cost = 21.50 -filament_density = 1.27 +inherits = Fiberlogy PETG; *PETMMU1* [filament:Prusa PETG @MMU1] -inherits = *PETMMU1* +inherits = Prusa PETG; *PETMMU1* renamed_from = "Prusa PET MMU1"; "Prusa PETG MMU1" -filament_vendor = Made for Prusa -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 [filament:Prusament PETG @MMU1] -inherits = *PETMMU1* -filament_vendor = Prusa Polymers -first_layer_temperature = 240 -temperature = 250 -filament_cost = 36.29 -filament_density = 1.27 -filament_spool_weight = 201 -filament_type = PETG +inherits = Prusament PETG; *PETMMU1* + +[filament:Extrudr PETG @MMU1] +inherits = Extrudr PETG; *PETMMU1* +filament_vendor = Extrudr [filament:Taulman T-Glase @MMU1] -inherits = *PETMMU1* -filament_vendor = Taulman -filament_cost = 40 -filament_density = 1.27 -bridge_fan_speed = 40 -cooling = 0 -fan_always_on = 0 -first_layer_bed_temperature = 90 -first_layer_temperature = 240 -max_fan_speed = 5 -min_fan_speed = 0 +inherits = Taulman T-Glase; *PETMMU1* start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}200{else}30{endif}; Filament gcode" [filament:Fiberthree F3 PA Pure Pro @MMU1] -inherits = *common* -filament_vendor = Fiberthree -filament_cost = 200.84 -filament_density = 1.2 -bed_temperature = 70 -first_layer_bed_temperature = 75 -first_layer_temperature = 270 -temperature = 270 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 1 -fan_below_layer_time = 20 -min_print_speed = 15 -slowdown_below_layer_time = 10 -filament_colour = #DEE0E6 +inherits = Fiberthree F3 PA Pure Pro filament_max_volumetric_speed = 4 -filament_soluble = 0 -filament_type = NYLON -max_fan_speed = 20 -min_fan_speed = 20 -start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.01{elsif nozzle_diameter[0]==0.6}0.04{else}0.05{endif} ; Filament gcode LA 1.5\n{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K18{elsif nozzle_diameter[0]==0.8};{else}M900 K30{endif} ; Filament gcode LA 1.0" +filament_retract_length = nil +filament_retract_speed = nil +filament_retract_lift = nil +filament_retract_before_travel = nil +filament_wipe = nil compatible_printers_condition = printer_model=="MK2SMM" [filament:Fiberthree F3 PA-CF Pro @MMU1] -inherits = *common* -filament_vendor = Fiberthree -filament_cost = 208.1 -filament_density = 1.25 -bed_temperature = 70 -first_layer_bed_temperature = 75 -first_layer_temperature = 275 -temperature = 275 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 0 -fan_below_layer_time = 20 -min_print_speed = 15 -slowdown_below_layer_time = 10 -filament_colour = #DEE0E6 +inherits = Fiberthree F3 PA-CF Pro filament_max_volumetric_speed = 4 -filament_soluble = 0 -filament_type = NYLON -max_fan_speed = 0 -min_fan_speed = 0 -start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.01{elsif nozzle_diameter[0]==0.6}0.04{else}0.05{endif} ; Filament gcode LA 1.5\n{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K18{elsif nozzle_diameter[0]==0.8};{else}M900 K30{endif} ; Filament gcode LA 1.0" +filament_retract_length = nil +filament_retract_speed = nil +filament_retract_lift = nil +filament_retract_before_travel = nil +filament_wipe = nil compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MK2SMM" [filament:Fiberthree F3 PA-GF Pro @MMU1] @@ -3166,108 +3045,47 @@ compatible_printers_condition = printer_model=="MK2SMM" [filament:Generic PETG @MINI] inherits = Generic PETG; *PETMINI* renamed_from = "Generic PET MINI"; "Generic PETG MINI" -filament_vendor = Generic -filament_cost = 27.82 -filament_density = 1.27 compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 and nozzle_diameter[0]!=0.6 [filament:Devil Design PETG @MINI] -inherits = Generic PETG; *PETMINI* -filament_vendor = Devil Design -filament_cost = 20.99 -filament_density = 1.23 -filament_spool_weight = 250 -first_layer_temperature = 230 -first_layer_bed_temperature = 85 -temperature = 230 -bed_temperature = 90 +inherits = Devil Design PETG; *PETMINI* compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.6 -[filament:Plasty Mladec PETG @MINI] -inherits = Generic PETG; *PETMINI* -filament_vendor = Plasty Mladec -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 +[filament:Filament PM PETG @MINI] +inherits = Filament PM PETG; *PETMINI* +renamed_from = "Plasty Mladec PETG @MINI" compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.6 [filament:Verbatim PETG @MINI] -inherits = Generic PETG; *PETMINI* -filament_vendor = Verbatim -filament_cost = 27.90 -filament_density = 1.27 -filament_spool_weight = 235 +inherits = Verbatim PETG; *PETMINI* compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.6 [filament:Fiberlogy PETG @MINI] -inherits = Generic PETG; *PETMINI* -filament_vendor = Fiberlogy -filament_cost = 21.50 -filament_density = 1.27 +inherits = Fiberlogy PETG; *PETMINI* compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.6 [filament:Generic ABS @MINI] inherits = Generic ABS; *ABSMINI* -filament_vendor = Generic -filament_cost = 27.82 -filament_density = 1.08 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 [filament:Fiberthree F3 PA Pure Pro @MINI] -inherits = *common* -filament_vendor = Fiberthree -filament_cost = 200.84 -filament_density = 1.2 -bed_temperature = 70 -first_layer_bed_temperature = 75 -first_layer_temperature = 270 -temperature = 270 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 1 -fan_below_layer_time = 20 -min_print_speed = 15 -slowdown_below_layer_time = 10 -filament_colour = #DEE0E6 +inherits = Fiberthree F3 PA Pure Pro filament_max_volumetric_speed = 4 -filament_soluble = 0 -filament_type = NYLON -max_fan_speed = 20 -min_fan_speed = 20 -start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.01{elsif nozzle_diameter[0]==0.6}0.04{else}0.05{endif} ; Filament gcode LA 1.5\n{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K18{elsif nozzle_diameter[0]==0.8};{else}M900 K30{endif} ; Filament gcode LA 1.0" +filament_retract_length = nil +filament_retract_speed = nil +filament_retract_lift = nil +filament_retract_before_travel = nil +filament_wipe = nil compatible_printers_condition = printer_model=="MINI" [filament:Fiberthree F3 PA-CF Pro @MINI] -inherits = *common* -filament_vendor = Fiberthree -filament_cost = 208.1 -filament_density = 1.25 -bed_temperature = 70 -first_layer_bed_temperature = 75 -first_layer_temperature = 275 -temperature = 275 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 0 -fan_below_layer_time = 20 -min_print_speed = 15 -slowdown_below_layer_time = 10 -filament_colour = #DEE0E6 +inherits = Fiberthree F3 PA-CF Pro filament_max_volumetric_speed = 4 -filament_soluble = 0 -filament_type = NYLON -max_fan_speed = 0 -min_fan_speed = 0 -start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.01{elsif nozzle_diameter[0]==0.6}0.04{else}0.05{endif} ; Filament gcode LA 1.5\n{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K18{elsif nozzle_diameter[0]==0.8};{else}M900 K30{endif} ; Filament gcode LA 1.0" +filament_retract_length = nil +filament_retract_speed = nil +filament_retract_lift = nil +filament_retract_before_travel = nil +filament_wipe = nil compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MINI" [filament:Fiberthree F3 PA-GF Pro @MINI] @@ -3280,14 +3098,8 @@ max_fan_speed = 15 min_fan_speed = 15 [filament:Kimya ABS Carbon @MINI] -inherits = *ABSMINI* -filament_vendor = Kimya -filament_cost = 140.4 -filament_density = 1.032 -filament_colour = #804040 +inherits = Kimya ABS Carbon; *ABSMINI* filament_max_volumetric_speed = 6 -first_layer_temperature = 260 -temperature = 260 compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MINI" [filament:Kimya ABS Kevlar @MINI] @@ -3296,146 +3108,57 @@ filament_vendor = Kimya filament_density = 1.037 [filament:Esun ABS @MINI] -inherits = Generic ABS; *ABSMINI* -filament_vendor = Esun -filament_cost = 27.82 -filament_density = 1.01 -filament_spool_weight = 265 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 +inherits = Esun ABS; *ABSMINI* [filament:Hatchbox ABS @MINI] -inherits = Generic ABS; *ABSMINI* -filament_vendor = Hatchbox -filament_cost = 27.82 -filament_density = 1.08 -filament_spool_weight = 245 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 +inherits = Hatchbox ABS; *ABSMINI* -[filament:Plasty Mladec ABS @MINI] -inherits = Generic ABS; *ABSMINI* -filament_vendor = Plasty Mladec -filament_cost = 27.82 -filament_density = 1.08 -filament_spool_weight = 230 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 +[filament:Filament PM ABS @MINI] +inherits = Filament PM ABS; *ABSMINI* +renamed_from = "Plasty Mladec ABS @MINI" [filament:Verbatim ABS @MINI] -inherits = Generic ABS; *ABSMINI* -filament_vendor = Verbatim -filament_cost = 25.87 -filament_density = 1.05 -filament_spool_weight = 235 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 +inherits = Verbatim ABS; *ABSMINI* [filament:Prusament PETG @MINI] inherits = Prusament PETG; *PETMINI* -filament_vendor = Prusa Polymers -first_layer_temperature = 240 -temperature = 250 -filament_density = 1.27 -filament_spool_weight = 201 -filament_cost = 36.29 compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 and nozzle_diameter[0]!=0.6 +[filament:Extrudr PETG @MINI] +inherits = Extrudr PETG; *PETMINI* +filament_vendor = Extrudr + [filament:Kimya PETG Carbon @MINI] -inherits = *PETMINI* -filament_vendor = Kimya -extrusion_multiplier = 1.05 -filament_cost = 150.02 -filament_density = 1.317 -filament_colour = #804040 +inherits = Kimya PETG Carbon; *PETMINI* filament_max_volumetric_speed = 6 -first_layer_bed_temperature = 85 -first_layer_temperature = 240 -temperature = 240 filament_retract_length = nil filament_retract_lift = 0.3 compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MINI" [filament:Prusament PETG @0.6 nozzle MINI] inherits = Prusament PETG; *PETMINI06* -first_layer_temperature = 240 -temperature = 250 -filament_density = 1.27 -filament_spool_weight = 201 -filament_cost = 36.29 [filament:Generic PETG @0.6 nozzle MINI] inherits = Generic PETG; *PETMINI06* renamed_from = "Generic PET 0.6 nozzle MINI"; "Generic PETG 0.6 nozzle MINI" -filament_cost = 27.82 -filament_density = 1.27 [filament:Devil Design PETG @0.6 nozzle MINI] -inherits = Generic PETG; *PETMINI06* -filament_vendor = Devil Design -first_layer_temperature = 230 -first_layer_bed_temperature = 85 -temperature = 230 -bed_temperature = 90 -filament_cost = 20.99 -filament_density = 1.23 -filament_spool_weight = 250 +inherits = Devil Design PETG; *PETMINI06* -[filament:Plasty Mladec PETG @0.6 nozzle MINI] -inherits = Generic PETG; *PETMINI06* -filament_vendor = Plasty Mladec -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 +[filament:Filament PM PETG @0.6 nozzle MINI] +inherits = Filament PM PETG; *PETMINI06* +renamed_from = "Plasty Mladec PETG @0.6 nozzle MINI" [filament:Verbatim PETG @0.6 nozzle MINI] -inherits = Generic PETG; *PETMINI06* -filament_vendor = Verbatim -filament_spool_weight = 235 +inherits = Verbatim PETG; *PETMINI06* [filament:Fiberlogy PETG @0.6 nozzle MINI] -inherits = Generic PETG; *PETMINI06* -filament_vendor = Fiberlogy +inherits = Fiberlogy PETG; *PETMINI06* [filament:Prusament ASA @MINI] inherits = Prusament ASA; *ABSMINI* -first_layer_temperature = 260 first_layer_bed_temperature = 100 -temperature = 260 bed_temperature = 100 -fan_always_on = 1 -cooling = 1 -min_fan_speed = 20 -max_fan_speed = 20 -bridge_fan_speed = 30 -min_print_speed = 15 -slowdown_below_layer_time = 15 -disable_fan_first_layers = 4 -filament_type = ASA -filament_colour = #FFF2EC -filament_cost = 42.69 -filament_density = 1.07 -filament_spool_weight = 201 compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 [filament:Fillamentum Flexfill 98A @MINI] @@ -3541,89 +3264,43 @@ inherits = Fillamentum CPE; *PETMINI* first_layer_temperature = 265 first_layer_bed_temperature = 90 temperature = 265 -filament_type = CPE -filament_cost = 56.45 -filament_density = 1.25 -filament_spool_weight = 230 disable_fan_first_layers = 3 full_fan_speed_layer = 5 [filament:ColorFabb nGen @MINI] inherits = ColorFabb nGen; *PETMINI* -filament_cost = 52.46 -filament_density = 1.2 -filament_spool_weight = 236 [filament:E3D PC-ABS @MINI] inherits = E3D PC-ABS; *ABSMINI* -filament_density = 1.05 -filament_cost = 28.80 +filament_retract_length = nil +filament_retract_before_travel = nil +filament_wipe = nil [filament:Fillamentum ABS @MINI] inherits = Fillamentum ABS; *ABSMINI* -filament_cost = 32.4 -filament_density = 1.04 -filament_spool_weight = 230 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 [filament:Fillamentum ASA @MINI] inherits = Fillamentum ASA; *ABSMINI* -first_layer_temperature = 255 first_layer_bed_temperature = 100 -temperature = 255 bed_temperature = 100 -fan_always_on = 1 -cooling = 1 -min_fan_speed = 20 -max_fan_speed = 20 -min_print_speed = 15 -slowdown_below_layer_time = 15 -disable_fan_first_layers = 4 -filament_type = ASA -filament_colour = #FFF2EC -filament_cost = 38.7 -filament_density = 1.07 -filament_spool_weight = 230 [filament:Polymaker PC-Max @MINI] inherits = Polymaker PC-Max; *ABSMINI* -filament_type = PC filament_max_volumetric_speed = 7 bed_temperature = 100 -filament_colour = #FFF2EC first_layer_bed_temperature = 100 first_layer_temperature = 270 temperature = 270 -bridge_fan_speed = 0 -filament_cost = 77.3 -filament_density = 1.20 +filament_retract_length = nil +filament_retract_before_travel = nil +filament_wipe = nil [filament:Prusament PC Blend @MINI] -inherits = *ABSMINI* -filament_vendor = Prusa Polymers -filament_cost = 60.49 -filament_density = 1.22 -filament_spool_weight = 201 -fan_always_on = 0 +inherits = Prusament PC Blend; *ABSMINI* first_layer_temperature = 275 first_layer_bed_temperature = 100 temperature = 275 bed_temperature = 100 -cooling = 1 -min_fan_speed = 20 -max_fan_speed = 20 -bridge_fan_speed = 30 -min_print_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -filament_type = PC -filament_colour = #DEE0E6 filament_max_volumetric_speed = 7 filament_retract_length = nil filament_retract_speed = nil @@ -3634,117 +3311,43 @@ filament_wipe = nil compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 [filament:Prusa ABS @MINI] -inherits = *ABSMINI* -filament_vendor = Made for Prusa -filament_cost = 27.82 -filament_density = 1.08 -filament_spool_weight = 230 -fan_always_on = 0 -cooling = 1 -min_fan_speed = 15 -max_fan_speed = 15 -disable_fan_first_layers = 4 -fan_below_layer_time = 30 -bridge_fan_speed = 25 +inherits = Prusa ABS; *ABSMINI* compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 [filament:Generic HIPS @MINI] -inherits = *ABSMINI* -filament_vendor = Generic -filament_cost = 27.3 -filament_density = 1.04 -bridge_fan_speed = 50 -cooling = 1 -extrusion_multiplier = 1 -fan_always_on = 1 -fan_below_layer_time = 10 -filament_colour = #FFFFD7 -filament_soluble = 1 -filament_type = HIPS -first_layer_temperature = 230 -max_fan_speed = 20 -min_fan_speed = 20 -temperature = 230 +inherits = Generic HIPS; *ABSMINI* [filament:ColorFabb HT @MINI] -inherits = *PETMINI* -filament_vendor = ColorFabb +inherits = ColorFabb HT; *PETMINI* bed_temperature = 100 -bridge_fan_speed = 30 -cooling = 1 -disable_fan_first_layers = 3 -fan_always_on = 0 -fan_below_layer_time = 10 -filament_cost = 58.66 -filament_density = 1.18 -filament_spool_weight = 236 first_layer_bed_temperature = 100 -first_layer_temperature = 270 -max_fan_speed = 20 -min_fan_speed = 10 -temperature = 270 +min_fan_speed = 15 [filament:ColorFabb XT @MINI] -inherits = *PETMINI* -filament_vendor = ColorFabb -filament_type = PETG -filament_cost = 62.90 -filament_density = 1.27 -filament_spool_weight = 236 +inherits = ColorFabb XT; *PETMINI* first_layer_bed_temperature = 90 -first_layer_temperature = 260 -temperature = 270 [filament:ColorFabb XT-CF20 @MINI] -inherits = *PETMINI* -filament_vendor = ColorFabb +inherits = ColorFabb XT-CF20; *PETMINI* compatible_printers_condition = nozzle_diameter[0]>=0.4 and printer_model=="MINI" -extrusion_multiplier = 1.05 -filament_cost = 80.65 -filament_density = 1.35 -filament_spool_weight = 236 -filament_colour = #804040 -filament_max_volumetric_speed = 2 first_layer_bed_temperature = 90 first_layer_temperature = 260 temperature = 260 [filament:Taulman T-Glase @MINI] -inherits = *PETMINI* -filament_vendor = Taulman -filament_cost = 40 -filament_density = 1.27 -bridge_fan_speed = 40 -cooling = 0 -fan_always_on = 0 -first_layer_bed_temperature = 90 -first_layer_temperature = 240 -max_fan_speed = 5 -min_fan_speed = 0 +inherits = Taulman T-Glase; *PETMINI* [filament:E3D Edge @MINI] -inherits = *PETMINI* -filament_vendor = E3D -filament_cost = 56.9 -filament_density = 1.26 -filament_type = EDGE +inherits = E3D Edge; *PETMINI* [filament:Prusa PETG @MINI] -inherits = *PETMINI* +inherits = Prusa PETG; *PETMINI* renamed_from = "Prusa PET MINI"; "Prusa PETG MINI" -filament_vendor = Made for Prusa -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 compatible_printers_condition = printer_model=="MINI" and nozzle_diameter[0]!=0.8 and nozzle_diameter[0]!=0.6 [filament:Prusa PETG @0.6 nozzle MINI] -inherits = *PETMINI06* +inherits = Prusa PETG; *PETMINI06* renamed_from = "Prusa PET 0.6 nozzle MINI"; "Prusa PETG 0.6 nozzle MINI" -filament_vendor = Made for Prusa -filament_cost = 27.82 -filament_density = 1.27 -filament_spool_weight = 230 ## Filaments 0.8 nozzle @@ -5321,7 +4924,7 @@ retract_speed = 35 serial_port = serial_speed = 250000 single_extruder_multi_material = 0 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-2 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0 toolchange_gcode = use_firmware_retraction = 0 use_relative_e_distances = 1 @@ -5356,19 +4959,19 @@ printer_model = MK2SMM [printer:*mm-single*] inherits = *multimaterial* -end_gcode = G1 E-4 F2100.00000\nG91\nG1 Z1 F7200.000\nG90\nG1 X245 Y1\nG1 X240 E4\nG1 F4000\nG1 X190 E2.7 \nG1 F4600\nG1 X110 E2.8\nG1 F5200\nG1 X40 E3 \nG1 E-15.0000 F5000\nG1 E-50.0000 F5400\nG1 E-15.0000 F3000\nG1 E-12.0000 F2000\nG1 F1600\nG1 X0 Y1 E3.0000\nG1 X50 Y1 E-5.0000\nG1 F2000\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-5.0000\nG1 F2400\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-5.0000\nG1 F2400\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-3.0000\nG4 S0\nM107 ; turn off fan\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nG28 X0 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n\n +end_gcode = G1 E-4 F2100\nG91\nG1 Z1 F7200\nG90\nG1 X245 Y1\nG1 X240 E4\nG1 F4000\nG1 X190 E2.7\nG1 F4600\nG1 X110 E2.8\nG1 F5200\nG1 X40 E3\nG1 E-15 F5000\nG1 E-50 F5400\nG1 E-15 F3000\nG1 E-12 F2000\nG1 F1600\nG1 X0 Y1 E3\nG1 X50 Y1 E-5\nG1 F2000\nG1 X0 Y1 E5\nG1 X50 Y1 E-5\nG1 F2400\nG1 X0 Y1 E5\nG1 X50 Y1 E-5\nG1 F2400\nG1 X0 Y1 E5\nG1 X50 Y1 E-3\nG4 S0\nM107 ; turn off fan\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nG28 X0 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n\n printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2\nPRINTER_HAS_BOWDEN -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\n; Start G-Code sequence START\nT?\nM104 S[first_layer_temperature]\nM140 S[first_layer_bed_temperature]\nM109 S[first_layer_temperature]\nM190 S[first_layer_bed_temperature]\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG28 W\nG80\nG92 E0.0\nM203 E100\nM92 E140\nG1 Z0.250 F7200.000\nG1 X50.0 E80.0 F1000.0\nG1 X160.0 E20.0 F1000.0\nG1 Z0.200 F7200.000\nG1 X220.0 E13 F1000.0\nG1 X240.0 E0 F1000.0\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\n; Start G-Code sequence START\nT?\nM104 S[first_layer_temperature]\nM140 S[first_layer_bed_temperature]\nM109 S[first_layer_temperature]\nM190 S[first_layer_bed_temperature]\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG28 W\nG80\nG92 E0\nM203 E100\nM92 E140\nG1 Z0.25 F7200\nG1 X50 E80 F1000\nG1 X160 E20 F1000\nG1 Z0.2 F7200\nG1 X220 E13 F1000\nG1 X240 E0 F1000\nG92 E0 default_print_profile = 0.15mm OPTIMAL [printer:*mm-multi*] inherits = *multimaterial* high_current_on_filament_swap = 1 -end_gcode = {if not has_wipe_tower}\n; Pull the filament into the cooling tubes.\nG1 E-4 F2100.00000\nG91\nG1 Z1 F7200.000\nG90\nG1 X245 Y1\nG1 X240 E4\nG1 F4000\nG1 X190 E2.7 \nG1 F4600\nG1 X110 E2.8\nG1 F5200\nG1 X40 E3 \nG1 E-15.0000 F5000\nG1 E-50.0000 F5400\nG1 E-15.0000 F3000\nG1 E-12.0000 F2000\nG1 F1600\nG1 X0 Y1 E3.0000\nG1 X50 Y1 E-5.0000\nG1 F2000\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-5.0000\nG1 F2400\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-5.0000\nG1 F2400\nG1 X0 Y1 E5.0000\nG1 X50 Y1 E-3.0000\nG4 S0\n{endif}\nM107 ; turn off fan\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nG28 X0 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors +end_gcode = {if not has_wipe_tower}\n; Pull the filament into the cooling tubes.\nG1 E-4 F2100\nG91\nG1 Z1 F7200\nG90\nG1 X245 Y1\nG1 X240 E4\nG1 F4000\nG1 X190 E2.7\nG1 F4600\nG1 X110 E2.8\nG1 F5200\nG1 X40 E3\nG1 E-15 F5000\nG1 E-50 F5400\nG1 E-15 F3000\nG1 E-12 F2000\nG1 F1600\nG1 X0 Y1 E3\nG1 X50 Y1 E-5\nG1 F2000\nG1 X0 Y1 E5\nG1 X50 Y1 E-5\nG1 F2400\nG1 X0 Y1 E5\nG1 X50 Y1 E-5\nG1 F2400\nG1 X0 Y1 E5\nG1 X50 Y1 E-3\nG4 S0\n{endif}\nM107 ; turn off fan\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nG28 X0 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors extruder_colour = #FFAA55;#E37BA0;#4ECDD3;#FB7259 nozzle_diameter = 0.4,0.4,0.4,0.4 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2\nPRINTER_HAS_BOWDEN -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\n; Start G-Code sequence START\nT[initial_tool]\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG28 W\nG80\nG92 E0.0\nM203 E100 ; set max feedrate\nM92 E140 ; E-steps per filament milimeter\n{if not has_single_extruder_multi_material_priming}\nG1 Z0.250 F7200.000\nG1 X50.0 E80.0 F1000.0\nG1 X160.0 E20.0 F1000.0\nG1 Z0.200 F7200.000\nG1 X220.0 E13 F1000.0\nG1 X240.0 E0 F1000.0\n{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.2.3 ; tell printer latest fw version\nM204 S[machine_max_acceleration_extruding] T[machine_max_acceleration_retracting] ; MK2 firmware only supports the old M204 format\n; Start G-Code sequence START\nT[initial_tool]\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG28 W\nG80\nG92 E0\nM203 E100 ; set max feedrate\nM92 E140 ; E-steps per filament milimeter\n{if not has_single_extruder_multi_material_priming}\nG1 Z0.25 F7200\nG1 X50 E80 F1000\nG1 X160 E20 F1000\nG1 Z0.2 F7200\nG1 X220 E13 F1000\nG1 X240 E0 F1000\n{endif}\nG92 E0 default_print_profile = 0.15mm OPTIMAL # XXXXXXXXXXXXXXXXX @@ -5438,21 +5041,21 @@ inherits = Original Prusa i3 MK2S printer_model = MK2.5 remaining_times = 1 machine_max_jerk_e = 4.5 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0 [printer:Original Prusa i3 MK2.5 0.25 nozzle] inherits = Original Prusa i3 MK2S 0.25 nozzle printer_model = MK2.5 remaining_times = 1 machine_max_jerk_e = 4.5 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0 [printer:Original Prusa i3 MK2.5 0.6 nozzle] inherits = Original Prusa i3 MK2S 0.6 nozzle printer_model = MK2.5 remaining_times = 1 machine_max_jerk_e = 4.5 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0 [printer:Original Prusa i3 MK2.5 0.8 nozzle] inherits = Original Prusa i3 MK2S 0.6 nozzle @@ -5464,39 +5067,20 @@ min_layer_height = 0.2 retract_length = 1 remaining_times = 1 machine_max_jerk_e = 4.5 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0 default_print_profile = 0.40mm QUALITY @0.8 nozzle default_filament_profile = Prusament PLA @0.8 nozzle [printer:Original Prusa i3 MK2.5 MMU2 Single] -inherits = Original Prusa i3 MK2.5; *mm2* +inherits = *25mm2* printer_model = MK2.5MMU2 single_extruder_multi_material = 0 max_print_height = 200 -remaining_times = 1 -silent_mode = 0 -retract_lift_below = 199 -machine_max_acceleration_e = 10000 -machine_max_acceleration_extruding = 2000 -machine_max_acceleration_retracting = 1500 -machine_max_acceleration_x = 9000 -machine_max_acceleration_y = 9000 -machine_max_acceleration_z = 500 -machine_max_feedrate_e = 120 -machine_max_feedrate_x = 500 -machine_max_feedrate_y = 500 -machine_max_feedrate_z = 12 -machine_max_jerk_e = 4.5 -machine_max_jerk_x = 10 -machine_max_jerk_y = 10 -machine_max_jerk_z = 0.2 -machine_min_extruding_rate = 0 -machine_min_travel_rate = 0 default_print_profile = 0.15mm OPTIMAL @MK2.5 default_filament_profile = Prusament PLA printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2.5\n -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\n; select extruder\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; load to nozzle\nTc\n; purge line\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n -end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM104 S0 ; turn off temperature\nM900 K0 ; reset LA\nM84 ; disable motors +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\n; select extruder\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; load to nozzle\nTc\n; purge line\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.20 F1000\nG1 X5 E4 F1000\nG92 E0\n +end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM104 S0 ; turn off temperature\nM900 K0 ; reset LA\nM84 ; disable motors [printer:Original Prusa i3 MK2.5 MMU2 Single 0.8 nozzle] inherits = Original Prusa i3 MK2.5S MMU2S Single 0.8 nozzle @@ -5511,87 +5095,43 @@ inherits = Original Prusa i3 MK2.5S MMU2S Single 0.25 nozzle printer_model = MK2.5MMU2 [printer:Original Prusa i3 MK2.5 MMU2] -inherits = Original Prusa i3 MK2.5; *mm2* +inherits = *25mm2* printer_model = MK2.5MMU2 max_print_height = 200 -remaining_times = 1 -silent_mode = 0 -retract_lift_below = 199 -machine_max_acceleration_e = 10000 -machine_max_acceleration_extruding = 2000 -machine_max_acceleration_retracting = 1500 -machine_max_acceleration_x = 9000 -machine_max_acceleration_y = 9000 -machine_max_acceleration_z = 500 -machine_max_feedrate_e = 120 -machine_max_feedrate_x = 500 -machine_max_feedrate_y = 500 -machine_max_feedrate_z = 12 -machine_max_jerk_e = 4.5 -machine_max_jerk_x = 10 -machine_max_jerk_y = 10 -machine_max_jerk_z = 0.2 -machine_min_extruding_rate = 0 -machine_min_travel_rate = 0 default_print_profile = 0.15mm OPTIMAL @MK2.5 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2.5\n single_extruder_multi_material = 1 -# The 5x nozzle diameter defines the number of extruders. Other extruder parameters -# (for example the retract values) are duplicaed from the first value, so they do not need -# to be defined explicitely. nozzle_diameter = 0.4,0.4,0.4,0.4,0.4 extruder_colour = #FF8000;#DB5182;#00FFFF;#FF4F4F;#9FFF9F -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E32.0 F1073.0\nG1 X5.0 E32.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\nG92 E0.0\n -end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15.0000 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E32 F1073\nG1 X5 E32 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\nG92 E0\n +end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n [printer:Original Prusa i3 MK2.5S] inherits = Original Prusa i3 MK2.5 printer_model = MK2.5S -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 [printer:Original Prusa i3 MK2.5S 0.25 nozzle] inherits = Original Prusa i3 MK2.5 0.25 nozzle printer_model = MK2.5S -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 [printer:Original Prusa i3 MK2.5S 0.6 nozzle] inherits = Original Prusa i3 MK2.5 0.6 nozzle printer_model = MK2.5S -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0 [printer:Original Prusa i3 MK2.5S 0.8 nozzle] inherits = Original Prusa i3 MK2.5 0.8 nozzle printer_model = MK2.5S [printer:Original Prusa i3 MK2.5S MMU2S Single] -inherits = Original Prusa i3 MK2.5; *mm2s* +inherits = *25mm2s* printer_model = MK2.5SMMU2S single_extruder_multi_material = 0 max_print_height = 200 -remaining_times = 1 -silent_mode = 0 -retract_lift_below = 199 -machine_max_acceleration_e = 10000 -machine_max_acceleration_extruding = 2000 -machine_max_acceleration_retracting = 1500 -machine_max_acceleration_x = 9000 -machine_max_acceleration_y = 9000 -machine_max_acceleration_z = 500 -machine_max_feedrate_e = 120 -machine_max_feedrate_x = 500 -machine_max_feedrate_y = 500 -machine_max_feedrate_z = 12 -machine_max_jerk_e = 4.5 -machine_max_jerk_x = 10 -machine_max_jerk_y = 10 -machine_max_jerk_z = 0.2 -machine_min_extruding_rate = 0 -machine_min_travel_rate = 0 default_print_profile = 0.15mm OPTIMAL @MK2.5 default_filament_profile = Prusament PLA printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2.5\n -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n -end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM104 S0 ; turn off temperature\nM900 K0 ; reset LA\nM84 ; disable motors +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n +end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM104 S0 ; turn off temperature\nM900 K0 ; reset LA\nM84 ; disable motors [printer:Original Prusa i3 MK2.5S MMU2S Single 0.8 nozzle] inherits = Original Prusa i3 MK2.5S MMU2S Single @@ -5601,7 +5141,7 @@ min_layer_height = 0.2 nozzle_diameter = 0.8 printer_variant = 0.8 retract_length = 1 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n default_print_profile = 0.40mm QUALITY @0.8 nozzle default_filament_profile = Prusament PLA @0.8 nozzle @@ -5623,41 +5163,19 @@ nozzle_diameter = 0.25 printer_variant = 0.25 retract_lift = 0.15 default_print_profile = 0.10mm DETAIL 0.25 nozzle -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F1400.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F1400\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n [printer:Original Prusa i3 MK2.5S MMU2S] -inherits = Original Prusa i3 MK2.5; *mm2s* +inherits = *25mm2s* printer_model = MK2.5SMMU2S max_print_height = 200 -remaining_times = 1 -silent_mode = 0 -retract_lift_below = 199 -machine_max_acceleration_e = 10000 -machine_max_acceleration_extruding = 2000 -machine_max_acceleration_retracting = 1500 -machine_max_acceleration_x = 9000 -machine_max_acceleration_y = 9000 -machine_max_acceleration_z = 500 -machine_max_feedrate_e = 120 -machine_max_feedrate_x = 500 -machine_max_feedrate_y = 500 -machine_max_feedrate_z = 12 -machine_max_jerk_e = 4.5 -machine_max_jerk_x = 10 -machine_max_jerk_y = 10 -machine_max_jerk_z = 0.2 -machine_min_extruding_rate = 0 -machine_min_travel_rate = 0 default_print_profile = 0.15mm OPTIMAL @MK2.5 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK2.5\n single_extruder_multi_material = 1 -# The 5x nozzle diameter defines the number of extruders. Other extruder parameters -# (for example the retract values) are duplicaed from the first value, so they do not need -# to be defined explicitely. nozzle_diameter = 0.4,0.4,0.4,0.4,0.4 extruder_colour = #FF8000;#DB5182;#00FFFF;#FF4F4F;#9FFF9F -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E29.0 F1073.0\nG1 X5.0 E29.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\nG92 E0.0\n -end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15.0000 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E29 F1073\nG1 X5 E29 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\nG92 E0\n +end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM900 K0 ; reset LA\nM84 ; disable motors\n [printer:Original Prusa i3 MK2.5S MMU2S 0.6 nozzle] inherits = Original Prusa i3 MK2.5S MMU2S @@ -5675,7 +5193,7 @@ min_layer_height = 0.15 printer_variant = 0.6 default_print_profile = 0.20mm NORMAL @0.6 nozzle -## For later use. 0.8mm nozzle profiles are only available for MMU2 Single mode at the moment. +## 0.8mm nozzle profiles are only available for MMU2 Single mode at the moment. ## [printer:Original Prusa i3 MK2.5S MMU2S 0.8 nozzle] ## inherits = Original Prusa i3 MK2.5S MMU2S @@ -5725,7 +5243,7 @@ remaining_times = 1 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MK3\n retract_lift_below = 209 max_print_height = 210 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} printer_model = MK3 default_print_profile = 0.15mm QUALITY @MK3 @@ -5736,7 +5254,7 @@ max_layer_height = 0.15 min_layer_height = 0.05 printer_variant = 0.25 retract_lift = 0.15 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E8.0 F700.0 ; intro line\nG1 X100.0 E12.5 F700.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E8 F700 ; intro line\nG1 X100 E12.5 F700 ; intro line\nG92 E0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} default_print_profile = 0.10mm DETAIL @0.25 nozzle MK3 [printer:Original Prusa i3 MK3 0.6 nozzle] @@ -5745,7 +5263,7 @@ nozzle_diameter = 0.6 max_layer_height = 0.40 min_layer_height = 0.15 printer_variant = 0.6 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0\nM221 S{if layer_height<0.075}100{else}95{endif} default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 [printer:Original Prusa i3 MK3 0.8 nozzle] @@ -5755,7 +5273,7 @@ max_layer_height = 0.6 min_layer_height = 0.2 printer_variant = 0.8 retract_length = 1 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Z0.2 F720\nG1 Y-3 F1000 ; go outside print area\nG92 E0\nG1 X60 E9 F1000 ; intro line\nG1 X100 E12.5 F1000 ; intro line\nG92 E0\nM221 S95 default_print_profile = 0.40mm QUALITY @0.8 nozzle default_filament_profile = Prusament PLA @0.8 nozzle @@ -5763,13 +5281,11 @@ default_filament_profile = Prusament PLA @0.8 nozzle inherits = Original Prusa i3 MK3 renamed_from = "Original Prusa i3 MK3S" printer_model = MK3S -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E9.0 F1000.0 ; intro line\nG1 X100.0 E12.5 F1000.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} [printer:Original Prusa i3 MK3S & MK3S+ 0.25 nozzle] inherits = Original Prusa i3 MK3 0.25 nozzle renamed_from = "Original Prusa i3 MK3S 0.25 nozzle" printer_model = MK3S -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\nG1 Y-3.0 F1000.0 ; go outside print area\nG92 E0.0\nG1 X60.0 E8.0 F700.0 ; intro line\nG1 X100.0 E12.5 F700.0 ; intro line\nG92 E0.0\nM221 S{if layer_height<0.075}100{else}95{endif}\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} [printer:Original Prusa i3 MK3S & MK3S+ 0.6 nozzle] inherits = Original Prusa i3 MK3 0.6 nozzle @@ -5804,12 +5320,32 @@ printer_model = MK3SMMU2S default_print_profile = 0.15mm QUALITY @MK3 default_filament_profile = Prusament PLA @MMU2 +[printer:*25mm2*] +inherits = Original Prusa i3 MK2.5 +single_extruder_multi_material = 1 +cooling_tube_length = 10 +cooling_tube_retraction = 30 +parking_pos_retraction = 85 +retract_length_toolchange = 3 +extra_loading_move = -13 +default_filament_profile = Prusament PLA @MMU2 + +[printer:*25mm2s*] +inherits = Original Prusa i3 MK2.5S +single_extruder_multi_material = 1 +cooling_tube_length = 20 +cooling_tube_retraction = 40 +parking_pos_retraction = 85 +retract_length_toolchange = 3 +extra_loading_move = -25 +default_filament_profile = Prusament PLA @MMU2 + [printer:Original Prusa i3 MK3 MMU2 Single] inherits = *mm2* single_extruder_multi_material = 0 default_filament_profile = Prusament PLA -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} -end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nM84 ; disable motors +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} +end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nM84 ; disable motors [printer:Original Prusa i3 MK3 MMU2 Single 0.6 nozzle] inherits = Original Prusa i3 MK3 MMU2 Single @@ -5818,7 +5354,7 @@ nozzle_diameter = 0.6 max_layer_height = 0.40 min_layer_height = 0.15 printer_variant = 0.6 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 [printer:Original Prusa i3 MK3 MMU2 Single 0.8 nozzle] @@ -5829,7 +5365,7 @@ max_layer_height = 0.6 min_layer_height = 0.2 printer_variant = 0.8 retract_length = 1 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.40mm QUALITY @0.8 nozzle default_filament_profile = Prusament PLA @0.8 nozzle @@ -5841,27 +5377,24 @@ max_layer_height = 0.15 min_layer_height = 0.05 printer_variant = 0.25 retract_lift = 0.15 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 E8.0 F1000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F1400.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 E8 F1000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F1400\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} default_print_profile = 0.10mm DETAIL @0.25 nozzle MK3 [printer:Original Prusa i3 MK3 MMU2] inherits = *mm2* -# The 5x nozzle diameter defines the number of extruders. Other extruder parameters -# (for example the retract values) are duplicaed from the first value, so they do not need -# to be defined explicitely. machine_max_acceleration_e = 8000,8000 nozzle_diameter = 0.4,0.4,0.4,0.4,0.4 extruder_colour = #FF8000;#DB5182;#00FFFF;#FF4F4F;#9FFF9F -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E32.0 F1073.0\nG1 X5.0 E32.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} -end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15.0000 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM84 ; disable motors\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E32 F1073\nG1 X5 E32 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} +end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM84 ; disable motors\n [printer:Original Prusa i3 MK3S & MK3S+ MMU2S Single] inherits = *mm2s* renamed_from = "Original Prusa i3 MK3S MMU2S Single" single_extruder_multi_material = 0 default_filament_profile = Prusament PLA -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} -end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nM84 ; disable motors +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} +end_gcode = {if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+10, max_print_height)}{endif} F720 ; Move print head up\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM702 C\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nM84 ; disable motors [printer:Original Prusa i3 MK3S & MK3S+ MMU2S Single 0.6 nozzle] inherits = Original Prusa i3 MK3S & MK3S+ MMU2S Single @@ -5871,7 +5404,7 @@ nozzle_diameter = 0.6 max_layer_height = 0.40 min_layer_height = 0.15 printer_variant = 0.6 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 [printer:Original Prusa i3 MK3S & MK3S+ MMU2S Single 0.8 nozzle] @@ -5882,7 +5415,7 @@ max_layer_height = 0.6 min_layer_height = 0.2 printer_variant = 0.8 retract_length = 1 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.40mm QUALITY @0.8 nozzle default_filament_profile = Prusament PLA @0.8 nozzle @@ -5895,7 +5428,7 @@ max_layer_height = 0.15 min_layer_height = 0.05 printer_variant = 0.25 retract_lift = 0.15 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nTc\n; purge line\nG1 X55.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F1400.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nTx\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nTc\n; purge line\nG1 X55 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F1400\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E value below. Excessive value can damage the printer.\n{if print_settings_id=~/.*@0.25 nozzle MK3.*/}M907 E430 ; set extruder motor current{endif} default_print_profile = 0.10mm DETAIL @0.25 nozzle MK3 [printer:Original Prusa i3 MK3S & MK3S+ MMU2S] @@ -5904,8 +5437,8 @@ renamed_from = "Original Prusa i3 MK3S MMU2S" machine_max_acceleration_e = 8000,8000 nozzle_diameter = 0.4,0.4,0.4,0.4,0.4 extruder_colour = #FF8000;#DB5182;#00FFFF;#FF4F4F;#9FFF9F -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E29.0 F1073.0\nG1 X5.0 E29.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} -end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15.0000 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15.0000 F5800\nG1 E-20.0000 F5500\nG1 E10.0000 F3000\nG1 E-10.0000 F3100\nG1 E10.0000 F3150\nG1 E-10.0000 F3250\nG1 E10.0000 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM84 ; disable motors\n +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E29 F1073\nG1 X5 E29 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0\n\n; Don't change E values below. Excessive value can damage the printer.\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE).*/}M907 E430 ; set extruder motor current{endif}\n{if print_settings_id=~/.*(SPEED @MK3|DRAFT @MK3).*/}M907 E538 ; set extruder motor current{endif} +end_gcode = ; Lift print head a bit\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} ; Move print head up\n{if has_wipe_tower}\nG1 E-15 F3000\n{else}\nG1 X0 Y210 F7200\nG1 E2 F5000\nG1 E2 F5500\nG1 E2 F6000\nG1 E-15 F5800\nG1 E-20 F5500\nG1 E10 F3000\nG1 E-10 F3100\nG1 E10 F3150\nG1 E-10 F3250\nG1 E10 F3300\n{endif}\n\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n\n; Unload filament\nM702 C\n\nG4 ; wait\nM221 S100 ; reset flow\nM900 K0 ; reset LA\n{if print_settings_id=~/.*(DETAIL @MK3|QUALITY @MK3|SOLUBLE|@0.25 nozzle MK3).*/}M907 E538 ; reset extruder motor current{endif}\nM104 S0 ; turn off temperature\nG1 X0 Y210 F3000 ; home X axis\nM84 ; disable motors\n ## 0.6mm nozzle MMU2/S printer profiles @@ -5916,7 +5449,7 @@ nozzle_diameter = 0.6,0.6,0.6,0.6,0.6 max_layer_height = 0.40 min_layer_height = 0.15 printer_variant = 0.6 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E29.0 F1073.0\nG1 X5.0 E29.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E29 F1073\nG1 X5 E29 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 [printer:Original Prusa i3 MK3 MMU2 0.6 nozzle] @@ -5925,7 +5458,7 @@ nozzle_diameter = 0.6,0.6,0.6,0.6,0.6 max_layer_height = 0.40 min_layer_height = 0.15 printer_variant = 0.6 -start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E32.0 F1073.0\nG1 X5.0 E32.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM862.1 P[nozzle_diameter] ; nozzle diameter check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55 E32 F1073\nG1 X5 E32 F1800\nG1 X55 E8 F2000\nG1 Z0.3 F1000\nG92 E0\nG1 X240 E25 F2200\nG1 Y-2 F1000\nG1 X55 E25 F1400\nG1 Z0.2 F1000\nG1 X5 E4 F1000\nG92 E0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0 default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 ## 0.8mm nozzle MMU2/S printer profiles @@ -5938,7 +5471,7 @@ default_print_profile = 0.30mm QUALITY @0.6 nozzle MK3 ## max_layer_height = 0.6 ## min_layer_height = 0.2 ## printer_variant = 0.8 -## start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E32.0 F1073.0\nG1 X5.0 E32.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000.0\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 +## start_gcode = M862.3 P \"[printer_model]\" ; printer model check\nM115 U3.9.3 ; tell printer latest fw version\nG90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S[first_layer_temperature] ; set extruder temp\nM140 S[first_layer_bed_temperature] ; set bed temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nM109 S[first_layer_temperature] ; wait for extruder temp\nG28 W ; home all without mesh bed level\nG80 ; mesh bed leveling\n\n; Send the filament type to the MMU2.0 unit.\n; E stands for extruder number, F stands for filament type (0: default; 1:flex; 2: PVA)\nM403 E0 F{"" + ((filament_type[0]=="FLEX") ? 1 : ((filament_type[0]=="PVA") ? 2 : 0))}\nM403 E1 F{"" + ((filament_type[1]=="FLEX") ? 1 : ((filament_type[1]=="PVA") ? 2 : 0))}\nM403 E2 F{"" + ((filament_type[2]=="FLEX") ? 1 : ((filament_type[2]=="PVA") ? 2 : 0))}\nM403 E3 F{"" + ((filament_type[3]=="FLEX") ? 1 : ((filament_type[3]=="PVA") ? 2 : 0))}\nM403 E4 F{"" + ((filament_type[4]=="FLEX") ? 1 : ((filament_type[4]=="PVA") ? 2 : 0))}\n\n{if not has_single_extruder_multi_material_priming}\n;go outside print area\nG1 Y-3.0 F1000\nG1 Z0.4 F1000\n; select extruder\nT[initial_tool]\n; initial load\nG1 X55.0 E32.0 F1073.0\nG1 X5.0 E32.0 F1800.0\nG1 X55.0 E8.0 F2000.0\nG1 Z0.3 F1000\nG92 E0.0\nG1 X240.0 E25.0 F2200.0\nG1 Y-2.0 F1000.0\nG1 X55.0 E25 F1400.0\nG1 Z0.20 F1000.0\nG1 X5.0 E4.0 F1000.0\nG92 E0.0\n{endif}\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG92 E0.0 ## default_print_profile = 0.40mm QUALITY @0.8 nozzle ## [printer:Original Prusa i3 MK3S & MK3S+ MMU2S 0.8 nozzle] @@ -5963,10 +5496,11 @@ thumbnails = 16x16,220x124 bed_shape = 0x0,180x0,180x180,0x180 default_filament_profile = "Prusament PLA" default_print_profile = 0.15mm QUALITY @MINI -gcode_flavor = marlin +gcode_flavor = marlinfirmware machine_max_acceleration_e = 5000 machine_max_acceleration_extruding = 1250 machine_max_acceleration_retracting = 1250 +machine_max_acceleration_travel = 1250 machine_max_acceleration_x = 1250 machine_max_acceleration_y = 1250 machine_max_acceleration_z = 400 @@ -5996,7 +5530,7 @@ retract_lift_below = 179 retract_layer_change = 1 silent_mode = 0 remaining_times = 1 -start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S170 ; set extruder temp for bed leveling\nM140 S[first_layer_bed_temperature] ; set bed temp\nM109 R170 ; wait for bed leveling temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nG28 ; home all without mesh bed level\nG29 ; mesh bed leveling \nM104 S[first_layer_temperature] ; set extruder temp\nG92 E0.0\nG1 Y-2.0 X179 F2400\nG1 Z3 F720\nM109 S[first_layer_temperature] ; wait for extruder temp\n\n; intro line\nG1 X170 F1000\nG1 Z0.2 F720\nG1 X110.0 E8.0 F900\nG1 X40.0 E10.0 F700\nG92 E0.0\n\nM221 S95 ; set flow +start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S170 ; set extruder temp for bed leveling\nM140 S[first_layer_bed_temperature] ; set bed temp\nM109 R170 ; wait for bed leveling temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nG28 ; home all without mesh bed level\nG29 ; mesh bed leveling \nM104 S[first_layer_temperature] ; set extruder temp\nG92 E0\nG1 Y-2 X179 F2400\nG1 Z3 F720\nM109 S[first_layer_temperature] ; wait for extruder temp\n\n; intro line\nG1 X170 F1000\nG1 Z0.2 F720\nG1 X110 E8 F900\nG1 X40 E10 F700\nG92 E0\n\nM221 S95 ; set flow end_gcode = G1 E-1 F2100 ; retract\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+2, max_print_height)}{endif} F720 ; Move print head up\nG1 X178 Y178 F4200 ; park print head\n{if max_layer_z < max_print_height}G1 Z{z_offset+min(max_layer_z+30, max_print_height)}{endif} F720 ; Move print head further up\nG4 ; wait\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nM221 S100 ; reset flow\nM900 K0 ; reset LA\nM84 ; disable motors printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_PRUSA3D\nPRINTER_MODEL_MINI\n extruder_colour = @@ -6012,7 +5546,7 @@ default_print_profile = 0.10mm DETAIL @0.25 nozzle MINI retract_length = 3 retract_lift = 0.15 retract_before_travel = 1 -start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S170 ; set extruder temp for bed leveling\nM140 S[first_layer_bed_temperature] ; set bed temp\nM109 R170 ; wait for bed leveling temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nG28 ; home all without mesh bed level\nG29 ; mesh bed leveling \nM104 S[first_layer_temperature] ; set extruder temp\nG92 E0.0\nG1 Y-2.0 X179 F2400\nG1 Z3 F720\nM109 S[first_layer_temperature] ; wait for extruder temp\n\n; intro line\nG1 X170 F1000\nG1 Z0.2 F720\nG1 X110.0 E8.0 F600\nG1 X40.0 E10.0 F400\nG92 E0.0\n\nM221 S95 ; set flow +start_gcode = G90 ; use absolute coordinates\nM83 ; extruder relative mode\nM104 S170 ; set extruder temp for bed leveling\nM140 S[first_layer_bed_temperature] ; set bed temp\nM109 R170 ; wait for bed leveling temp\nM190 S[first_layer_bed_temperature] ; wait for bed temp\nG28 ; home all without mesh bed level\nG29 ; mesh bed leveling \nM104 S[first_layer_temperature] ; set extruder temp\nG92 E0\nG1 Y-2 X179 F2400\nG1 Z3 F720\nM109 S[first_layer_temperature] ; wait for extruder temp\n\n; intro line\nG1 X170 F1000\nG1 Z0.2 F720\nG1 X110 E8 F600\nG1 X40 E10 F400\nG92 E0\n\nM221 S95 ; set flow [printer:Original Prusa MINI & MINI+ 0.6 nozzle] inherits = Original Prusa MINI & MINI+ diff --git a/resources/profiles/PrusaResearch/mk2.svg b/resources/profiles/PrusaResearch/mk2.svg index b8fa8d0cd7..6214a55523 100644 --- a/resources/profiles/PrusaResearch/mk2.svg +++ b/resources/profiles/PrusaResearch/mk2.svg @@ -1 +1,885 @@ -MK2_bottom \ No newline at end of file + + + + + + image/svg+xml + + MK2_bottom + + + + + MK2_bottom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/profiles/PrusaResearch/mk3.svg b/resources/profiles/PrusaResearch/mk3.svg index c8f53373b5..03b24d572b 100644 --- a/resources/profiles/PrusaResearch/mk3.svg +++ b/resources/profiles/PrusaResearch/mk3.svg @@ -1 +1,883 @@ -MK3_bottom \ No newline at end of file + + + + + + image/svg+xml + + MK3_bottom + + + + + MK3_bottom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/profiles/TriLAB.idx b/resources/profiles/TriLAB.idx index 4a097ed6ae..65f47d59a6 100644 --- a/resources/profiles/TriLAB.idx +++ b/resources/profiles/TriLAB.idx @@ -1,8 +1,9 @@ min_slic3r_version = 2.3.0-alpha3 +0.0.7 Added PLA, PETG profiles for 0.25 nozzle, fixed supports on 0.8 nozzle profile, fixed max volumetric speed, disabled elefant foot compensation 0.0.6 Added material TPU 93A (SMARTFIL) 0.0.5 Removed obsolete host keys. 0.0.4 Added PLA, PETG profiles for 0.8 nozzle, update print materials 0.0.3 Added DeltiQ 2, DeltiQ 2 Plus printers, 0.10mm, 0.20mm FLEX print profiles, updated print materials, flexprint extension support min_slic3r_version = 2.3.0-alpha0 0.0.2 Added 0.15mm print profile -0.0.1 Initial TriLAB bundle +0.0.1 Initial TriLAB bundle \ No newline at end of file diff --git a/resources/profiles/TriLAB.ini b/resources/profiles/TriLAB.ini index d31461510d..d6824badeb 100644 --- a/resources/profiles/TriLAB.ini +++ b/resources/profiles/TriLAB.ini @@ -6,7 +6,7 @@ name = TriLAB # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.0.6 +config_version = 0.0.7 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/TriLAB/ # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% @@ -17,16 +17,16 @@ config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/Prus [printer_model:DQ2] name = DeltiQ 2 -variants = 0.4; 0.8 +variants = 0.4; 0.25; 0.8 technology = FFF family = DeltiQ 2 bed_model = dq2_bed.stl bed_texture = dq2_bed_texture.svg -default_materials = DeltiQ - PLA - Generic; DeltiQ - PETG - Generic; DeltiQ - ABS - Generic; DeltiQ - PLA - ExtraFill (Fillamentum); DeltiQ - PETG (Devil Design); DeltiQ - ABS - ExtraFill (Fillamentum); DeltiQ - ASA - ExtraFill (Fillamentum); DeltiQ - CPE - HG100 (Fillamentum); DeltiQ FP2 - PLA - Generic; DeltiQ FP2 - PETG - Generic; DeltiQ FP2 - ABS - Generic; DeltiQ FP2 - PLA - ExtraFill (Fillamentum); DeltiQ FP2 - PETG (Devil Design); DeltiQ FP2 - ABS - ExtraFill (Fillamentum); DeltiQ FP2 - ASA - ExtraFill (Fillamentum); DeltiQ FP2 - CPE - HG100 (Fillamentum); DeltiQ FP2 - FLEX - Generic; DeltiQ FP2 - TPU 92A - FlexFill (Fillamentum); DeltiQ FP2 - TPU 98A - FlexFill (Fillamentum); DeltiQ FP2 - TPU 93A (SMARTFIL); DeltiQ - PLA - ExtraFill (Fillamentum) @0.8 nozzle +default_materials = DeltiQ - PLA - Generic; DeltiQ - PETG - Generic; DeltiQ - ABS - Generic; DeltiQ - PLA - ExtraFill (Fillamentum); DeltiQ - PETG (Devil Design); DeltiQ - ABS - ExtraFill (Fillamentum); DeltiQ - ASA - ExtraFill (Fillamentum); DeltiQ - CPE - HG100 (Fillamentum); DeltiQ FP2 - PLA - Generic; DeltiQ FP2 - PETG - Generic; DeltiQ FP2 - ABS - Generic; DeltiQ FP2 - PLA - ExtraFill (Fillamentum); DeltiQ FP2 - PETG (Devil Design); DeltiQ FP2 - ABS - ExtraFill (Fillamentum); DeltiQ FP2 - ASA - ExtraFill (Fillamentum); DeltiQ FP2 - CPE - HG100 (Fillamentum); DeltiQ FP2 - FLEX - Generic; DeltiQ FP2 - TPU 92A - FlexFill (Fillamentum); DeltiQ FP2 - TPU 98A - FlexFill (Fillamentum); DeltiQ FP2 - TPU 93A (SMARTFIL); DeltiQ - PLA - ExtraFill (Fillamentum) @0.8 nozzle; DeltiQ - PLA - ExtraFill (Fillamentum) @0.25 nozzle [printer_model:DQ2P] name = DeltiQ 2 Plus -variants = 0.4; 0.8 +variants = 0.4; 0.25; 0.8 technology = FFF family = DeltiQ 2 bed_model = dq2_bed.stl @@ -110,7 +110,7 @@ complete_objects = 0 default_acceleration = 2000 dont_support_bridges = 0 draft_shield = 0 -elefant_foot_compensation = 0.2 +elefant_foot_compensation = 0.0 ensure_vertical_shell_thickness = 0 external_perimeter_extrusion_width = 0.45 external_perimeter_speed = 30 @@ -150,7 +150,7 @@ min_skirt_length = 4 notes = only_retract_when_crossing_perimeters = 1 ooze_prevention = 0 -output_filename_format = {input_filename_base}_{printer_model}_{filament_type[0]}_{layer_height}mm_{print_time}.gcode +output_filename_format = {input_filename_base}_{printer_model}_{filament_type[0]}_{layer_height}mm_{print_time}_{timestamp}.gcode overhangs = 1 perimeter_acceleration = 1500 perimeter_extruder = 1 @@ -283,6 +283,37 @@ travel_speed = 200 max_print_speed = 40 complete_objects = 1 +[print:DeltiQ 0.07mm Quality @0.25 nozzle] +inherits = DeltiQ 0.20mm Normal +bottom_solid_layers = 6 +bottom_solid_min_thickness = 0.5 +bridge_speed = 60 +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_TRILAB.*/ and nozzle_diameter[0]==0.25 +elefant_foot_compensation = 0.0 +external_perimeter_extrusion_width = 0.27 +extrusion_width = 0.25 +first_layer_extrusion_width = 0.26 +first_layer_height = 0.1 +infill_extrusion_width = 0.27 +infill_overlap = 50% +layer_height = 0.07 +overhangs = 1 +perimeter_extrusion_width = 0.27 +perimeters = 5 +solid_infill_extrusion_width = 0.27 +skirts = 2 +support_material_extrusion_width = 0.27 +support_material_contact_distance = 0.1 +top_infill_extrusion_width = 0.27 +top_solid_layers = 6 +top_solid_min_thickness = 0.5 +thin_walls = 1 + +[print:DeltiQ 0.20mm Normal @0.25 nozzle] +inherits = DeltiQ 0.07mm Quality @0.25 nozzle +first_layer_height = 0.2 +layer_height = 0.2 + [print:DeltiQ 0.40mm Normal @0.8 nozzle] inherits = DeltiQ 0.20mm Normal bottom_solid_layers = 3 @@ -290,7 +321,7 @@ bottom_solid_min_thickness = 1.2 bridge_flow_ratio = 0.90 bridge_speed = 20 compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_TRILAB.*/ and nozzle_diameter[0]==0.8 -elefant_foot_compensation = 0.2 +elefant_foot_compensation = 0.0 external_perimeter_extrusion_width = 0.80 external_perimeter_speed = 30 extrusion_width = 0.80 @@ -311,6 +342,8 @@ perimeters = 2 small_perimeter_speed = 20 solid_infill_extrusion_width = 0.8 solid_infill_speed = 60 +support_material_extrusion_width = 0.8 +support_material_contact_distance = 0.2 top_infill_extrusion_width = 0.8 top_solid_infill_speed = 40 top_solid_layers = 4 @@ -412,7 +445,7 @@ fan_below_layer_time = 20 filament_vendor = Fillamentum filament_cost = 774 filament_density = 1.08 -filament_max_volumetric_speed = 4 +filament_max_volumetric_speed = 8 filament_retract_before_travel = 3 filament_retract_before_wipe = 70% filament_retract_layer_change = 1 @@ -474,6 +507,19 @@ min_print_speed = 10 slowdown_below_layer_time = 5 temperature = 260 +[filament:DeltiQ - PLA - ExtraFill (Fillamentum) @0.25 nozzle] +inherits = DeltiQ - PLA - ExtraFill (Fillamentum) +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_TRILAB.*/ and printer_notes=~/.*PRINTER_FAMILY_DQ.*/ and !(printer_notes=~/.*FLEXPRINT.*/) and nozzle_diameter[0]==0.25 + +[filament:DeltiQ - PETG (Devil Design) @0.25 nozzle] +inherits = DeltiQ - PETG (Devil Design) +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_TRILAB.*/ and printer_notes=~/.*PRINTER_FAMILY_DQ.*/ and !(printer_notes=~/.*FLEXPRINT.*/) and nozzle_diameter[0]==0.25 +first_layer_temperature = 225 +temperature = 220 +max_fan_speed = 65 +min_fan_speed = 40 +bridge_fan_speed = 100 + [filament:DeltiQ - PLA - ExtraFill (Fillamentum) @0.8 nozzle] inherits = DeltiQ - PLA - ExtraFill (Fillamentum) compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_TRILAB.*/ and printer_notes=~/.*PRINTER_FAMILY_DQ.*/ and !(printer_notes=~/.*FLEXPRINT.*/) and nozzle_diameter[0]==0.8 @@ -536,7 +582,7 @@ filament_vendor = Generic filament_cost = 1870 filament_density = 1.22 filament_deretract_speed = nil -filament_max_volumetric_speed = 0.7 +filament_max_volumetric_speed = 3.0 filament_retract_before_travel = 2 filament_retract_before_wipe = 70% filament_retract_layer_change = 0 @@ -634,7 +680,7 @@ filament_vendor = Fillamentum filament_cost = 1870 filament_density = 1.22 filament_deretract_speed = nil -filament_max_volumetric_speed = 2.9 +filament_max_volumetric_speed = 3.0 filament_retract_before_travel = 2 filament_retract_before_wipe = 70% filament_retract_layer_change = 0 @@ -665,7 +711,7 @@ filament_vendor = Fillamentum filament_cost = 1870 filament_density = 1.22 filament_deretract_speed = nil -filament_max_volumetric_speed = 2.9 +filament_max_volumetric_speed = 3.0 filament_retract_before_travel = 2 filament_retract_before_wipe = 70% filament_retract_layer_change = 0 @@ -689,7 +735,7 @@ extrusion_multiplier = 1.10 filament_cost = 1870 filament_density = 1.23 filament_deretract_speed = nil -filament_max_volumetric_speed = 2.9 +filament_max_volumetric_speed = 3.0 filament_retract_before_wipe = 70% filament_retract_length = 2.5 filament_retract_speed = 20 @@ -822,6 +868,15 @@ printer_model = DQ2 printer_variant = 0.4 max_print_height = 320 +[printer:DeltiQ 2 - 0.25 nozzle] +inherits = DeltiQ 2 +printer_variant = 0.25 +max_layer_height = 0.15 +min_layer_height = 0.07 +nozzle_diameter = 0.25 +default_filament_profile = "DeltiQ - PLA - ExtraFill (Fillamentum) @0.25 nozzle" +default_print_profile = DeltiQ 0.07mm Quality @0.25 nozzle + [printer:DeltiQ 2 - 0.8 nozzle] inherits = DeltiQ 2 printer_variant = 0.8 @@ -837,6 +892,15 @@ printer_model = DQ2P printer_variant = 0.4 max_print_height = 500 +[printer:DeltiQ 2 Plus - 0.25 nozzle] +inherits = DeltiQ 2 Plus +printer_variant = 0.25 +max_layer_height = 0.15 +min_layer_height = 0.07 +nozzle_diameter = 0.25 +default_filament_profile = "DeltiQ - PLA - ExtraFill (Fillamentum) @0.25 nozzle" +default_print_profile = DeltiQ 0.07mm Quality @0.25 nozzle + [printer:DeltiQ 2 Plus - 0.8 nozzle] inherits = DeltiQ 2 Plus printer_variant = 0.8 diff --git a/src/PrusaSlicer_app_msvc.cpp b/src/PrusaSlicer_app_msvc.cpp index 7710d9eb7e..2ccf2f1ffd 100644 --- a/src/PrusaSlicer_app_msvc.cpp +++ b/src/PrusaSlicer_app_msvc.cpp @@ -217,6 +217,11 @@ int APIENTRY wWinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, int wmain(int argc, wchar_t **argv) { #endif + // Allow the asserts to open message box, such message box allows to ignore the assert and continue with the application. + // Without this call, the seemingly same message box is being opened by the abort() function, but that is too late and + // the application will be killed even if "Ignore" button is pressed. + _set_error_mode(_OUT_TO_MSGBOX); + std::vector argv_extended; argv_extended.emplace_back(argv[0]); diff --git a/src/clipper/CMakeLists.txt b/src/clipper/CMakeLists.txt index 8a4e928526..0362a4d849 100644 --- a/src/clipper/CMakeLists.txt +++ b/src/clipper/CMakeLists.txt @@ -2,8 +2,9 @@ project(clipper) cmake_minimum_required(VERSION 2.6) add_library(clipper STATIC - clipper.cpp - clipper.hpp +# We are using ClipperLib compiled as part of the libslic3r project using Slic3r::Point as its base type. +# clipper.cpp +# clipper.hpp clipper_z.cpp clipper_z.hpp ) diff --git a/src/clipper/clipper.cpp b/src/clipper/clipper.cpp index 3c0057b22b..0285d9167f 100644 --- a/src/clipper/clipper.cpp +++ b/src/clipper/clipper.cpp @@ -61,11 +61,15 @@ #define CLIPPERLIB_PROFILE_BLOCK(name) #endif -#ifdef use_xyz +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +namespace CLIPPERLIB_NAMESPACE_PREFIX { +#endif // CLIPPERLIB_NAMESPACE_PREFIX + +#ifdef CLIPPERLIB_USE_XYZ namespace ClipperLib_Z { -#else /* use_xyz */ +#else /* CLIPPERLIB_USE_XYZ */ namespace ClipperLib { -#endif /* use_xyz */ +#endif /* CLIPPERLIB_USE_XYZ */ static double const pi = 3.141592653589793238; static double const two_pi = pi *2; @@ -156,7 +160,7 @@ double Area(const Path &poly) double a = 0; for (int i = 0, j = size -1; i < size; ++i) { - a += ((double)poly[j].X + poly[i].X) * ((double)poly[j].Y - poly[i].Y); + a += ((double)poly[j].x() + poly[i].x()) * ((double)poly[j].y() - poly[i].y()); j = i; } return -a * 0.5; @@ -169,7 +173,7 @@ double Area(const OutRec &outRec) if (!op) return 0; double a = 0; do { - a += (double)(op->Prev->Pt.X + op->Pt.X) * (double)(op->Prev->Pt.Y - op->Pt.Y); + a += (double)(op->Prev->Pt.x() + op->Pt.x()) * (double)(op->Prev->Pt.y() - op->Pt.y()); op = op->Next; } while (op != outRec.Pts); return a * 0.5; @@ -201,26 +205,26 @@ int PointInPolygon(const IntPoint &pt, const Path &path) for(size_t i = 1; i <= cnt; ++i) { IntPoint ipNext = (i == cnt ? path[0] : path[i]); - if (ipNext.Y == pt.Y && ((ipNext.X == pt.X) || (ip.Y == pt.Y && ((ipNext.X > pt.X) == (ip.X < pt.X))))) + if (ipNext.y() == pt.y() && ((ipNext.x() == pt.x()) || (ip.y() == pt.y() && ((ipNext.x() > pt.x()) == (ip.x() < pt.x()))))) return -1; - if ((ip.Y < pt.Y) != (ipNext.Y < pt.Y)) + if ((ip.y() < pt.y()) != (ipNext.y() < pt.y())) { - if (ip.X >= pt.X) + if (ip.x() >= pt.x()) { - if (ipNext.X > pt.X) result = 1 - result; + if (ipNext.x() > pt.x()) result = 1 - result; else { - double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - (double)(ipNext.X - pt.X) * (ip.Y - pt.Y); + double d = (double)(ip.x() - pt.x()) * (ipNext.y() - pt.y()) - (double)(ipNext.x() - pt.x()) * (ip.y() - pt.y()); if (!d) return -1; - if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result; + if ((d > 0) == (ipNext.y() > ip.y())) result = 1 - result; } } else { - if (ipNext.X > pt.X) + if (ipNext.x() > pt.x()) { - double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - (double)(ipNext.X - pt.X) * (ip.Y - pt.Y); + double d = (double)(ip.x() - pt.x()) * (ipNext.y() - pt.y()) - (double)(ipNext.x() - pt.x()) * (ip.y() - pt.y()); if (!d) return -1; - if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result; + if ((d > 0) == (ipNext.y() > ip.y())) result = 1 - result; } } } @@ -238,29 +242,29 @@ int PointInPolygon (const IntPoint &pt, OutPt *op) OutPt* startOp = op; do { - if (op->Next->Pt.Y == pt.Y) + if (op->Next->Pt.y() == pt.y()) { - if ((op->Next->Pt.X == pt.X) || (op->Pt.Y == pt.Y && - ((op->Next->Pt.X > pt.X) == (op->Pt.X < pt.X)))) return -1; + if ((op->Next->Pt.x() == pt.x()) || (op->Pt.y() == pt.y() && + ((op->Next->Pt.x() > pt.x()) == (op->Pt.x() < pt.x())))) return -1; } - if ((op->Pt.Y < pt.Y) != (op->Next->Pt.Y < pt.Y)) + if ((op->Pt.y() < pt.y()) != (op->Next->Pt.y() < pt.y())) { - if (op->Pt.X >= pt.X) + if (op->Pt.x() >= pt.x()) { - if (op->Next->Pt.X > pt.X) result = 1 - result; + if (op->Next->Pt.x() > pt.x()) result = 1 - result; else { - double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y); + double d = (double)(op->Pt.x() - pt.x()) * (op->Next->Pt.y() - pt.y()) - (double)(op->Next->Pt.x() - pt.x()) * (op->Pt.y() - pt.y()); if (!d) return -1; - if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result; + if ((d > 0) == (op->Next->Pt.y() > op->Pt.y())) result = 1 - result; } } else { - if (op->Next->Pt.X > pt.X) + if (op->Next->Pt.x() > pt.x()) { - double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y); + double d = (double)(op->Pt.x() - pt.x()) * (op->Next->Pt.y() - pt.y()) - (double)(op->Next->Pt.x() - pt.x()) * (op->Pt.y() - pt.y()); if (!d) return -1; - if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result; + if ((d > 0) == (op->Next->Pt.y() > op->Pt.y())) result = 1 - result; } } } @@ -287,6 +291,11 @@ bool Poly2ContainsPoly1(OutPt *OutPt1, OutPt *OutPt2) } //---------------------------------------------------------------------- +#ifdef CLIPPERLIB_INT32 +inline bool SlopesEqual(const cInt dx1, const cInt dy1, const cInt dx2, const cInt dy2, bool /* UseFullInt64Range */) { + return int64_t(dy1) * int64_t(dx2) == int64_t(dx1) * int64_t(dy2); +} +#else inline bool SlopesEqual(const cInt dx1, const cInt dy1, const cInt dx2, const cInt dy2, bool UseFullInt64Range) { return (UseFullInt64Range) ? // |dx1| < 2^63, |dx2| < 2^63 etc, @@ -296,101 +305,103 @@ inline bool SlopesEqual(const cInt dx1, const cInt dy1, const cInt dx2, const cI // therefore the following computation could be done with 64bit arithmetics. dy1 * dx2 == dx1 * dy2; } +#endif + inline bool SlopesEqual(const TEdge &e1, const TEdge &e2, bool UseFullInt64Range) - { return SlopesEqual(e1.Delta.X, e1.Delta.Y, e2.Delta.X, e2.Delta.Y, UseFullInt64Range); } + { return SlopesEqual(e1.Delta.x(), e1.Delta.y(), e2.Delta.x(), e2.Delta.y(), UseFullInt64Range); } inline bool SlopesEqual(const IntPoint &pt1, const IntPoint &pt2, const IntPoint &pt3, bool UseFullInt64Range) - { return SlopesEqual(pt1.X-pt2.X, pt1.Y-pt2.Y, pt2.X-pt3.X, pt2.Y-pt3.Y, UseFullInt64Range); } + { return SlopesEqual(pt1.x()-pt2.x(), pt1.y()-pt2.y(), pt2.x()-pt3.x(), pt2.y()-pt3.y(), UseFullInt64Range); } inline bool SlopesEqual(const IntPoint &pt1, const IntPoint &pt2, const IntPoint &pt3, const IntPoint &pt4, bool UseFullInt64Range) - { return SlopesEqual(pt1.X-pt2.X, pt1.Y-pt2.Y, pt3.X-pt4.X, pt3.Y-pt4.Y, UseFullInt64Range); } + { return SlopesEqual(pt1.x()-pt2.x(), pt1.y()-pt2.y(), pt3.x()-pt4.x(), pt3.y()-pt4.y(), UseFullInt64Range); } //------------------------------------------------------------------------------ inline bool IsHorizontal(TEdge &e) { - return e.Delta.Y == 0; + return e.Delta.y() == 0; } //------------------------------------------------------------------------------ inline double GetDx(const IntPoint &pt1, const IntPoint &pt2) { - return (pt1.Y == pt2.Y) ? - HORIZONTAL : (double)(pt2.X - pt1.X) / (pt2.Y - pt1.Y); + return (pt1.y() == pt2.y()) ? + HORIZONTAL : (double)(pt2.x() - pt1.x()) / (pt2.y() - pt1.y()); } //--------------------------------------------------------------------------- inline cInt TopX(TEdge &edge, const cInt currentY) { - return (currentY == edge.Top.Y) ? - edge.Top.X : - edge.Bot.X + Round(edge.Dx *(currentY - edge.Bot.Y)); + return (currentY == edge.Top.y()) ? + edge.Top.x() : + edge.Bot.x() + Round(edge.Dx *(currentY - edge.Bot.y())); } //------------------------------------------------------------------------------ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip) { -#ifdef use_xyz - ip.Z = 0; +#ifdef CLIPPERLIB_USE_XYZ + ip.z() = 0; #endif double b1, b2; if (Edge1.Dx == Edge2.Dx) { - ip.Y = Edge1.Curr.Y; - ip.X = TopX(Edge1, ip.Y); + ip.y() = Edge1.Curr.y(); + ip.x() = TopX(Edge1, ip.y()); return; } - else if (Edge1.Delta.X == 0) + else if (Edge1.Delta.x() == 0) { - ip.X = Edge1.Bot.X; + ip.x() = Edge1.Bot.x(); if (IsHorizontal(Edge2)) - ip.Y = Edge2.Bot.Y; + ip.y() = Edge2.Bot.y(); else { - b2 = Edge2.Bot.Y - (Edge2.Bot.X / Edge2.Dx); - ip.Y = Round(ip.X / Edge2.Dx + b2); + b2 = Edge2.Bot.y() - (Edge2.Bot.x() / Edge2.Dx); + ip.y() = Round(ip.x() / Edge2.Dx + b2); } } - else if (Edge2.Delta.X == 0) + else if (Edge2.Delta.x() == 0) { - ip.X = Edge2.Bot.X; + ip.x() = Edge2.Bot.x(); if (IsHorizontal(Edge1)) - ip.Y = Edge1.Bot.Y; + ip.y() = Edge1.Bot.y(); else { - b1 = Edge1.Bot.Y - (Edge1.Bot.X / Edge1.Dx); - ip.Y = Round(ip.X / Edge1.Dx + b1); + b1 = Edge1.Bot.y() - (Edge1.Bot.x() / Edge1.Dx); + ip.y() = Round(ip.x() / Edge1.Dx + b1); } } else { - b1 = Edge1.Bot.X - Edge1.Bot.Y * Edge1.Dx; - b2 = Edge2.Bot.X - Edge2.Bot.Y * Edge2.Dx; + b1 = double(Edge1.Bot.x()) - double(Edge1.Bot.y()) * Edge1.Dx; + b2 = double(Edge2.Bot.x()) - double(Edge2.Bot.y()) * Edge2.Dx; double q = (b2-b1) / (Edge1.Dx - Edge2.Dx); - ip.Y = Round(q); - ip.X = (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx)) ? + ip.y() = Round(q); + ip.x() = (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx)) ? Round(Edge1.Dx * q + b1) : Round(Edge2.Dx * q + b2); } - if (ip.Y < Edge1.Top.Y || ip.Y < Edge2.Top.Y) + if (ip.y() < Edge1.Top.y() || ip.y() < Edge2.Top.y()) { - if (Edge1.Top.Y > Edge2.Top.Y) - ip.Y = Edge1.Top.Y; + if (Edge1.Top.y() > Edge2.Top.y()) + ip.y() = Edge1.Top.y(); else - ip.Y = Edge2.Top.Y; + ip.y() = Edge2.Top.y(); if (std::fabs(Edge1.Dx) < std::fabs(Edge2.Dx)) - ip.X = TopX(Edge1, ip.Y); + ip.x() = TopX(Edge1, ip.y()); else - ip.X = TopX(Edge2, ip.Y); + ip.x() = TopX(Edge2, ip.y()); } - //finally, don't allow 'ip' to be BELOW curr.Y (ie bottom of scanbeam) ... - if (ip.Y > Edge1.Curr.Y) + //finally, don't allow 'ip' to be BELOW curr.y() (ie bottom of scanbeam) ... + if (ip.y() > Edge1.Curr.y()) { - ip.Y = Edge1.Curr.Y; + ip.y() = Edge1.Curr.y(); //use the more vertical edge to derive X ... if (std::fabs(Edge1.Dx) > std::fabs(Edge2.Dx)) - ip.X = TopX(Edge2, ip.Y); else - ip.X = TopX(Edge1, ip.Y); + ip.x() = TopX(Edge2, ip.y()); else + ip.x() = TopX(Edge1, ip.y()); } } //------------------------------------------------------------------------------ @@ -422,7 +433,7 @@ inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt) void InitEdge2(TEdge& e, PolyType Pt) { - if (e.Curr.Y >= e.Next->Curr.Y) + if (e.Curr.y() >= e.Next->Curr.y()) { e.Bot = e.Curr; e.Top = e.Next->Curr; @@ -432,11 +443,11 @@ void InitEdge2(TEdge& e, PolyType Pt) e.Bot = e.Next->Curr; } - e.Delta.X = (e.Top.X - e.Bot.X); - e.Delta.Y = (e.Top.Y - e.Bot.Y); + e.Delta.x() = (e.Top.x() - e.Bot.x()); + e.Delta.y() = (e.Top.y() - e.Bot.y()); - if (e.Delta.Y == 0) e.Dx = HORIZONTAL; - else e.Dx = (double)(e.Delta.X) / e.Delta.Y; + if (e.Delta.y() == 0) e.Dx = HORIZONTAL; + else e.Dx = (double)(e.Delta.x()) / e.Delta.y(); e.PolyTyp = Pt; } @@ -459,9 +470,9 @@ inline void ReverseHorizontal(TEdge &e) //swap horizontal edges' Top and Bottom x's so they follow the natural //progression of the bounds - ie so their xbots will align with the //adjoining lower edge. [Helpful in the ProcessHorizontal() method.] - std::swap(e.Top.X, e.Bot.X); -#ifdef use_xyz - std::swap(e.Top.Z, e.Bot.Z); + std::swap(e.Top.x(), e.Bot.x()); +#ifdef CLIPPERLIB_USE_XYZ + std::swap(e.Top.z(), e.Bot.z()); #endif } //------------------------------------------------------------------------------ @@ -470,20 +481,20 @@ bool GetOverlapSegment(IntPoint pt1a, IntPoint pt1b, IntPoint pt2a, IntPoint pt2b, IntPoint &pt1, IntPoint &pt2) { //precondition: segments are Collinear. - if (std::abs(pt1a.X - pt1b.X) > std::abs(pt1a.Y - pt1b.Y)) + if (std::abs(pt1a.x() - pt1b.x()) > std::abs(pt1a.y() - pt1b.y())) { - if (pt1a.X > pt1b.X) std::swap(pt1a, pt1b); - if (pt2a.X > pt2b.X) std::swap(pt2a, pt2b); - if (pt1a.X > pt2a.X) pt1 = pt1a; else pt1 = pt2a; - if (pt1b.X < pt2b.X) pt2 = pt1b; else pt2 = pt2b; - return pt1.X < pt2.X; + if (pt1a.x() > pt1b.x()) std::swap(pt1a, pt1b); + if (pt2a.x() > pt2b.x()) std::swap(pt2a, pt2b); + if (pt1a.x() > pt2a.x()) pt1 = pt1a; else pt1 = pt2a; + if (pt1b.x() < pt2b.x()) pt2 = pt1b; else pt2 = pt2b; + return pt1.x() < pt2.x(); } else { - if (pt1a.Y < pt1b.Y) std::swap(pt1a, pt1b); - if (pt2a.Y < pt2b.Y) std::swap(pt2a, pt2b); - if (pt1a.Y < pt2a.Y) pt1 = pt1a; else pt1 = pt2a; - if (pt1b.Y > pt2b.Y) pt2 = pt1b; else pt2 = pt2b; - return pt1.Y > pt2.Y; + if (pt1a.y() < pt1b.y()) std::swap(pt1a, pt1b); + if (pt2a.y() < pt2b.y()) std::swap(pt2a, pt2b); + if (pt1a.y() < pt2a.y()) pt1 = pt1a; else pt1 = pt2a; + if (pt1b.y() > pt2b.y()) pt2 = pt1b; else pt2 = pt2b; + return pt1.y() > pt2.y(); } } //------------------------------------------------------------------------------ @@ -514,14 +525,14 @@ OutPt* GetBottomPt(OutPt *pp) OutPt* p = pp->Next; while (p != pp) { - if (p->Pt.Y > pp->Pt.Y) + if (p->Pt.y() > pp->Pt.y()) { pp = p; dups = 0; } - else if (p->Pt.Y == pp->Pt.Y && p->Pt.X <= pp->Pt.X) + else if (p->Pt.y() == pp->Pt.y() && p->Pt.x() <= pp->Pt.x()) { - if (p->Pt.X < pp->Pt.X) + if (p->Pt.x() < pp->Pt.x()) { dups = 0; pp = p; @@ -551,10 +562,10 @@ bool Pt2IsBetweenPt1AndPt3(const IntPoint &pt1, { if ((pt1 == pt3) || (pt1 == pt2) || (pt3 == pt2)) return false; - else if (pt1.X != pt3.X) - return (pt2.X > pt1.X) == (pt2.X < pt3.X); + else if (pt1.x() != pt3.x()) + return (pt2.x() > pt1.x()) == (pt2.x() < pt3.x()); else - return (pt2.Y > pt1.Y) == (pt2.Y < pt3.Y); + return (pt2.y() > pt1.y()) == (pt2.y() < pt3.y()); } //------------------------------------------------------------------------------ @@ -569,20 +580,22 @@ bool HorzSegmentsOverlap(cInt seg1a, cInt seg1b, cInt seg2a, cInt seg2b) // ClipperBase class methods ... //------------------------------------------------------------------------------ +#ifndef CLIPPERLIB_INT32 // Called from ClipperBase::AddPath() to verify the scale of the input polygon coordinates. inline void RangeTest(const IntPoint& Pt, bool& useFullRange) { if (useFullRange) { - if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) + if (Pt.x() > hiRange || Pt.y() > hiRange || -Pt.x() > hiRange || -Pt.y() > hiRange) throw clipperException("Coordinate outside allowed range"); } - else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) + else if (Pt.x() > loRange|| Pt.y() > loRange || -Pt.x() > loRange || -Pt.y() > loRange) { useFullRange = true; RangeTest(Pt, useFullRange); } } +#endif // CLIPPERLIB_INT32 //------------------------------------------------------------------------------ // Called from ClipperBase::AddPath() to construct the Local Minima List. @@ -596,8 +609,8 @@ inline TEdge* FindNextLocMin(TEdge* E) while (IsHorizontal(*E->Prev)) E = E->Prev; TEdge* E2 = E; while (IsHorizontal(*E)) E = E->Next; - if (E->Top.Y == E->Prev->Bot.Y) continue; //ie just an intermediate horz. - if (E2->Prev->Bot.X < E->Bot.X) E = E2; + if (E->Top.y() == E->Prev->Bot.y()) continue; //ie just an intermediate horz. + if (E2->Prev->Bot.x() < E->Bot.x()) E = E2; break; } return E; @@ -616,14 +629,14 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) //create another LocMin and call ProcessBound once more if (NextIsForward) { - while (E->Top.Y == E->Next->Bot.Y) E = E->Next; + while (E->Top.y() == E->Next->Bot.y()) E = E->Next; //don't include top horizontals when parsing a bound a second time, //they will be contained in the opposite bound ... while (E != Result && IsHorizontal(*E)) E = E->Prev; } else { - while (E->Top.Y == E->Prev->Bot.Y) E = E->Prev; + while (E->Top.y() == E->Prev->Bot.y()) E = E->Prev; while (E != Result && IsHorizontal(*E)) E = E->Next; } @@ -640,7 +653,7 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) else E = Result->Prev; LocalMinimum locMin; - locMin.Y = E->Bot.Y; + locMin.Y = E->Bot.y(); locMin.LeftBound = 0; locMin.RightBound = E; E->WindDelta = 0; @@ -663,17 +676,17 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) EStart = E->Next; if (IsHorizontal(*EStart)) //ie an adjoining horizontal skip edge { - if (EStart->Bot.X != E->Bot.X && EStart->Top.X != E->Bot.X) + if (EStart->Bot.x() != E->Bot.x() && EStart->Top.x() != E->Bot.x()) ReverseHorizontal(*E); } - else if (EStart->Bot.X != E->Bot.X) + else if (EStart->Bot.x() != E->Bot.x()) ReverseHorizontal(*E); } EStart = E; if (NextIsForward) { - while (Result->Top.Y == Result->Next->Bot.Y && Result->Next->OutIdx != Skip) + while (Result->Top.y() == Result->Next->Bot.y() && Result->Next->OutIdx != Skip) Result = Result->Next; if (IsHorizontal(*Result) && Result->Next->OutIdx != Skip) { @@ -682,38 +695,38 @@ TEdge* ClipperBase::ProcessBound(TEdge* E, bool NextIsForward) //unless a Skip edge is encountered when that becomes the top divide Horz = Result; while (IsHorizontal(*Horz->Prev)) Horz = Horz->Prev; - if (Horz->Prev->Top.X > Result->Next->Top.X) Result = Horz->Prev; + if (Horz->Prev->Top.x() > Result->Next->Top.x()) Result = Horz->Prev; } while (E != Result) { E->NextInLML = E->Next; if (IsHorizontal(*E) && E != EStart && - E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E); + E->Bot.x() != E->Prev->Top.x()) ReverseHorizontal(*E); E = E->Next; } - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Prev->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.x() != E->Prev->Top.x()) ReverseHorizontal(*E); Result = Result->Next; //move to the edge just beyond current bound } else { - while (Result->Top.Y == Result->Prev->Bot.Y && Result->Prev->OutIdx != Skip) + while (Result->Top.y() == Result->Prev->Bot.y() && Result->Prev->OutIdx != Skip) Result = Result->Prev; if (IsHorizontal(*Result) && Result->Prev->OutIdx != Skip) { Horz = Result; while (IsHorizontal(*Horz->Next)) Horz = Horz->Next; - if (Horz->Next->Top.X == Result->Prev->Top.X || - Horz->Next->Top.X > Result->Prev->Top.X) Result = Horz->Next; + if (Horz->Next->Top.x() == Result->Prev->Top.x() || + Horz->Next->Top.x() > Result->Prev->Top.x()) Result = Horz->Next; } while (E != Result) { E->NextInLML = E->Prev; - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.x() != E->Next->Top.x()) ReverseHorizontal(*E); E = E->Prev; } - if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) + if (IsHorizontal(*E) && E != EStart && E->Bot.x() != E->Next->Top.x()) ReverseHorizontal(*E); Result = Result->Prev; //move to the edge just beyond current bound } @@ -746,48 +759,6 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed) return result; } -bool ClipperBase::AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed) -{ - CLIPPERLIB_PROFILE_FUNC(); - std::vector num_edges(ppg.size(), 0); - int num_edges_total = 0; - for (size_t i = 0; i < ppg.size(); ++ i) { - const Path &pg = ppg[i]; - // Remove duplicate end point from a closed input path. - // Remove duplicate points from the end of the input path. - int highI = (int)pg.size() -1; - if (Closed) - while (highI > 0 && (pg[highI] == pg[0])) - --highI; - while (highI > 0 && (pg[highI] == pg[highI -1])) - --highI; - if ((Closed && highI < 2) || (!Closed && highI < 1)) - highI = -1; - num_edges[i] = highI + 1; - num_edges_total += highI + 1; - } - if (num_edges_total == 0) - return false; - - // Allocate a new edge array. - std::vector edges(num_edges_total); - // Fill in the edge array. - bool result = false; - TEdge *p_edge = edges.data(); - for (Paths::size_type i = 0; i < ppg.size(); ++i) - if (num_edges[i]) { - bool res = AddPathInternal(ppg[i], num_edges[i] - 1, PolyTyp, Closed, p_edge); - if (res) { - p_edge += num_edges[i]; - result = true; - } - } - if (result) - // At least some edges were generated. Remember the edge array. - m_edges.emplace_back(std::move(edges)); - return result; -} - bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, bool Closed, TEdge* edges) { CLIPPERLIB_PROFILE_FUNC(); @@ -805,13 +776,17 @@ bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, b try { edges[1].Curr = pg[1]; +#ifndef CLIPPERLIB_INT32 RangeTest(pg[0], m_UseFullRange); RangeTest(pg[highI], m_UseFullRange); +#endif // CLIPPERLIB_INT32 InitEdge(&edges[0], &edges[1], &edges[highI], pg[0]); InitEdge(&edges[highI], &edges[0], &edges[highI-1], pg[highI]); for (int i = highI - 1; i >= 1; --i) { +#ifndef CLIPPERLIB_INT32 RangeTest(pg[i], m_UseFullRange); +#endif // CLIPPERLIB_INT32 InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]); } } @@ -874,7 +849,7 @@ bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, b { InitEdge2(*E, PolyTyp); E = E->Next; - if (IsFlat && E->Curr.Y != eStart->Curr.Y) IsFlat = false; + if (IsFlat && E->Curr.y() != eStart->Curr.y()) IsFlat = false; } while (E != eStart); @@ -890,14 +865,14 @@ bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, b } E->Prev->OutIdx = Skip; LocalMinimum locMin; - locMin.Y = E->Bot.Y; + locMin.Y = E->Bot.y(); locMin.LeftBound = 0; locMin.RightBound = E; locMin.RightBound->Side = esRight; locMin.RightBound->WindDelta = 0; for (;;) { - if (E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E); + if (E->Bot.x() != E->Prev->Top.x()) ReverseHorizontal(*E); if (E->Next->OutIdx == Skip) break; E->NextInLML = E->Next; E = E->Next; @@ -924,7 +899,7 @@ bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, b //E and E.Prev now share a local minima (left aligned if horizontal). //Compare their slopes to find which starts which bound ... LocalMinimum locMin; - locMin.Y = E->Bot.Y; + locMin.Y = E->Bot.y(); if (E->Dx < E->Prev->Dx) { locMin.LeftBound = E->Prev; @@ -967,7 +942,9 @@ void ClipperBase::Clear() CLIPPERLIB_PROFILE_FUNC(); m_MinimaList.clear(); m_edges.clear(); +#ifndef CLIPPERLIB_INT32 m_UseFullRange = false; +#endif // CLIPPERLIB_INT32 m_HasOpenPaths = false; } //------------------------------------------------------------------------------ @@ -1013,27 +990,27 @@ IntRect ClipperBase::GetBounds() result.left = result.top = result.right = result.bottom = 0; return result; } - result.left = lm->LeftBound->Bot.X; - result.top = lm->LeftBound->Bot.Y; - result.right = lm->LeftBound->Bot.X; - result.bottom = lm->LeftBound->Bot.Y; + result.left = lm->LeftBound->Bot.x(); + result.top = lm->LeftBound->Bot.y(); + result.right = lm->LeftBound->Bot.x(); + result.bottom = lm->LeftBound->Bot.y(); while (lm != m_MinimaList.end()) { - result.bottom = std::max(result.bottom, lm->LeftBound->Bot.Y); + result.bottom = std::max(result.bottom, lm->LeftBound->Bot.y()); TEdge* e = lm->LeftBound; for (;;) { TEdge* bottomE = e; while (e->NextInLML) { - if (e->Bot.X < result.left) result.left = e->Bot.X; - if (e->Bot.X > result.right) result.right = e->Bot.X; + if (e->Bot.x() < result.left) result.left = e->Bot.x(); + if (e->Bot.x() > result.right) result.right = e->Bot.x(); e = e->NextInLML; } - result.left = std::min(result.left, e->Bot.X); - result.right = std::max(result.right, e->Bot.X); - result.left = std::min(result.left, e->Top.X); - result.right = std::max(result.right, e->Top.X); - result.top = std::min(result.top, e->Top.Y); + result.left = std::min(result.left, e->Bot.x()); + result.right = std::max(result.right, e->Bot.x()); + result.left = std::min(result.left, e->Top.x()); + result.right = std::max(result.right, e->Top.x()); + result.top = std::min(result.top, e->Top.y()); if (bottomE == lm->LeftBound) e = lm->RightBound; else break; } @@ -1058,7 +1035,7 @@ Clipper::Clipper(int initOptions) : m_StrictSimple = ((initOptions & ioStrictlySimple) != 0); m_PreserveCollinear = ((initOptions & ioPreserveCollinear) != 0); m_HasOpenPaths = false; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ m_ZFill = 0; #endif } @@ -1084,7 +1061,7 @@ bool Clipper::Execute(ClipType clipType, Paths &solution, CLIPPERLIB_PROFILE_FUNC(); if (m_HasOpenPaths) throw clipperException("Error: PolyTree struct is needed for open path clipping."); - solution.resize(0); + solution.clear(); m_SubjFillType = subjFillType; m_ClipFillType = clipFillType; m_ClipType = clipType; @@ -1439,7 +1416,7 @@ OutPt* Clipper::AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &Pt) } if (prevE && prevE->OutIdx >= 0 && - (TopX(*prevE, Pt.Y) == TopX(*e, Pt.Y)) && + (TopX(*prevE, Pt.y()) == TopX(*e, Pt.y())) && SlopesEqual(*e, *prevE, m_UseFullRange) && (e->WindDelta != 0) && (prevE->WindDelta != 0)) { @@ -1525,7 +1502,7 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) SetWindingCount(*lb); if (IsContributing(*lb)) Op1 = AddOutPt(lb, lb->Bot); - m_Scanbeam.push(lb->Top.Y); + m_Scanbeam.push(lb->Top.y()); } else { @@ -1536,13 +1513,13 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) rb->WindCnt2 = lb->WindCnt2; if (IsContributing(*lb)) Op1 = AddLocalMinPoly(lb, rb, lb->Bot); - m_Scanbeam.push(lb->Top.Y); + m_Scanbeam.push(lb->Top.y()); } if (rb) { if(IsHorizontal(*rb)) AddEdgeToSEL(rb); - else m_Scanbeam.push(rb->Top.Y); + else m_Scanbeam.push(rb->Top.y()); } if (!lb || !rb) continue; @@ -1554,12 +1531,12 @@ void Clipper::InsertLocalMinimaIntoAEL(const cInt botY) for (Join &jr : m_GhostJoins) //if the horizontal Rb and a 'ghost' horizontal overlap, then convert //the 'ghost' join to a real join ready for later ... - if (HorzSegmentsOverlap(jr.OutPt1->Pt.X, jr.OffPt.X, rb->Bot.X, rb->Top.X)) + if (HorzSegmentsOverlap(jr.OutPt1->Pt.x(), jr.OffPt.x(), rb->Bot.x(), rb->Top.x())) m_Joins.emplace_back(Join(jr.OutPt1, Op1, jr.OffPt)); } if (lb->OutIdx >= 0 && lb->PrevInAEL && - lb->PrevInAEL->Curr.X == lb->Bot.X && + lb->PrevInAEL->Curr.x() == lb->Bot.x() && lb->PrevInAEL->OutIdx >= 0 && SlopesEqual(*lb->PrevInAEL, *lb, m_UseFullRange) && (lb->WindDelta != 0) && (lb->PrevInAEL->WindDelta != 0)) @@ -1622,14 +1599,14 @@ void Clipper::DeleteFromSEL(TEdge *e) } //------------------------------------------------------------------------------ -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void Clipper::SetZ(IntPoint& pt, TEdge& e1, TEdge& e2) { - if (pt.Z != 0 || !m_ZFill) return; - else if (pt == e1.Bot) pt.Z = e1.Bot.Z; - else if (pt == e1.Top) pt.Z = e1.Top.Z; - else if (pt == e2.Bot) pt.Z = e2.Bot.Z; - else if (pt == e2.Top) pt.Z = e2.Top.Z; + if (pt.z() != 0 || !m_ZFill) return; + else if (pt == e1.Bot) pt.z() = e1.Bot.z(); + else if (pt == e1.Top) pt.z() = e1.Top.z(); + else if (pt == e2.Bot) pt.z() = e2.Bot.z(); + else if (pt == e2.Top) pt.z() = e2.Top.z(); else m_ZFill(e1.Bot, e1.Top, e2.Bot, e2.Top, pt); } //------------------------------------------------------------------------------ @@ -1640,7 +1617,7 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt) bool e1Contributing = ( e1->OutIdx >= 0 ); bool e2Contributing = ( e2->OutIdx >= 0 ); -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ SetZ(Pt, *e1, *e2); #endif @@ -1857,10 +1834,10 @@ OutRec* GetLowermostRec(OutRec *outRec1, OutRec *outRec2) outRec2->BottomPt = GetBottomPt(outRec2->Pts); OutPt *OutPt1 = outRec1->BottomPt; OutPt *OutPt2 = outRec2->BottomPt; - if (OutPt1->Pt.Y > OutPt2->Pt.Y) return outRec1; - else if (OutPt1->Pt.Y < OutPt2->Pt.Y) return outRec2; - else if (OutPt1->Pt.X < OutPt2->Pt.X) return outRec1; - else if (OutPt1->Pt.X > OutPt2->Pt.X) return outRec2; + if (OutPt1->Pt.y() > OutPt2->Pt.y()) return outRec1; + else if (OutPt1->Pt.y() < OutPt2->Pt.y()) return outRec2; + else if (OutPt1->Pt.x() < OutPt2->Pt.x()) return outRec1; + else if (OutPt1->Pt.x() > OutPt2->Pt.x()) return outRec2; else if (OutPt1->Next == OutPt1) return outRec2; else if (OutPt2->Next == OutPt2) return outRec1; else if (FirstIsBottomPt(OutPt1, OutPt2)) return outRec1; @@ -2066,13 +2043,13 @@ void Clipper::ProcessHorizontals() inline bool IsMaxima(TEdge *e, const cInt Y) { - return e && e->Top.Y == Y && !e->NextInLML; + return e && e->Top.y() == Y && !e->NextInLML; } //------------------------------------------------------------------------------ inline bool IsIntermediate(TEdge *e, const cInt Y) { - return e->Top.Y == Y && e->NextInLML; + return e->Top.y() == Y && e->NextInLML; } //------------------------------------------------------------------------------ @@ -2187,15 +2164,15 @@ void Clipper::SwapPositionsInSEL(TEdge *Edge1, TEdge *Edge2) inline void GetHorzDirection(TEdge& HorzEdge, Direction& Dir, cInt& Left, cInt& Right) { - if (HorzEdge.Bot.X < HorzEdge.Top.X) + if (HorzEdge.Bot.x() < HorzEdge.Top.x()) { - Left = HorzEdge.Bot.X; - Right = HorzEdge.Top.X; + Left = HorzEdge.Bot.x(); + Right = HorzEdge.Top.x(); Dir = dLeftToRight; } else { - Left = HorzEdge.Top.X; - Right = HorzEdge.Bot.X; + Left = HorzEdge.Top.x(); + Right = HorzEdge.Bot.x(); Dir = dRightToLeft; } } @@ -2204,8 +2181,8 @@ inline void GetHorzDirection(TEdge& HorzEdge, Direction& Dir, cInt& Left, cInt& /******************************************************************************* * Notes: Horizontal edges (HEs) at scanline intersections (ie at the Top or * * Bottom of a scanbeam) are processed as if layered. The order in which HEs * -* are processed doesn't matter. HEs intersect with other HE Bot.Xs only [#] * -* (or they could intersect with Top.Xs only, ie EITHER Bot.Xs OR Top.Xs), * +* are processed doesn't matter. HEs intersect with other HE Bot.x()s only [#] * +* (or they could intersect with Top.x()s only, ie EITHER Bot.x()s OR Top.x()s), * * and with other non-horizontal edges [*]. Once these intersections are * * processed, intermediate HEs then 'promote' the Edge above (NextInLML) into * * the AEL. These 'promoted' edges may in turn intersect [%] with other HEs. * @@ -2233,15 +2210,15 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) if (dir == dLeftToRight) { maxIt = m_Maxima.begin(); - while (maxIt != m_Maxima.end() && *maxIt <= horzEdge->Bot.X) ++maxIt; - if (maxIt != m_Maxima.end() && *maxIt >= eLastHorz->Top.X) + while (maxIt != m_Maxima.end() && *maxIt <= horzEdge->Bot.x()) ++maxIt; + if (maxIt != m_Maxima.end() && *maxIt >= eLastHorz->Top.x()) maxIt = m_Maxima.end(); } else { maxRit = m_Maxima.rbegin(); - while (maxRit != m_Maxima.rend() && *maxRit > horzEdge->Bot.X) ++maxRit; - if (maxRit != m_Maxima.rend() && *maxRit <= eLastHorz->Top.X) + while (maxRit != m_Maxima.rend() && *maxRit > horzEdge->Bot.x()) ++maxRit; + if (maxRit != m_Maxima.rend() && *maxRit <= eLastHorz->Top.x()) maxRit = m_Maxima.rend(); } } @@ -2263,30 +2240,30 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) { if (dir == dLeftToRight) { - while (maxIt != m_Maxima.end() && *maxIt < e->Curr.X) + while (maxIt != m_Maxima.end() && *maxIt < e->Curr.x()) { if (horzEdge->OutIdx >= 0 && !IsOpen) - AddOutPt(horzEdge, IntPoint(*maxIt, horzEdge->Bot.Y)); + AddOutPt(horzEdge, IntPoint(*maxIt, horzEdge->Bot.y())); ++maxIt; } } else { - while (maxRit != m_Maxima.rend() && *maxRit > e->Curr.X) + while (maxRit != m_Maxima.rend() && *maxRit > e->Curr.x()) { if (horzEdge->OutIdx >= 0 && !IsOpen) - AddOutPt(horzEdge, IntPoint(*maxRit, horzEdge->Bot.Y)); + AddOutPt(horzEdge, IntPoint(*maxRit, horzEdge->Bot.y())); ++maxRit; } } }; - if ((dir == dLeftToRight && e->Curr.X > horzRight) || - (dir == dRightToLeft && e->Curr.X < horzLeft)) break; + if ((dir == dLeftToRight && e->Curr.x() > horzRight) || + (dir == dRightToLeft && e->Curr.x() < horzLeft)) break; //Also break if we've got to the end of an intermediate horizontal edge ... //nb: Smaller Dx's are to the right of larger Dx's ABOVE the horizontal. - if (e->Curr.X == horzEdge->Top.X && horzEdge->NextInLML && + if (e->Curr.x() == horzEdge->Top.x() && horzEdge->NextInLML && e->Dx < horzEdge->NextInLML->Dx) break; if (horzEdge->OutIdx >= 0 && !IsOpen) //note: may be done multiple times @@ -2296,8 +2273,8 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) while (eNextHorz) { if (eNextHorz->OutIdx >= 0 && - HorzSegmentsOverlap(horzEdge->Bot.X, - horzEdge->Top.X, eNextHorz->Bot.X, eNextHorz->Top.X)) + HorzSegmentsOverlap(horzEdge->Bot.x(), + horzEdge->Top.x(), eNextHorz->Bot.x(), eNextHorz->Top.x())) { OutPt* op2 = GetLastOutPt(eNextHorz); m_Joins.emplace_back(Join(op2, op1, eNextHorz->Top)); @@ -2320,12 +2297,12 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) if(dir == dLeftToRight) { - IntPoint Pt = IntPoint(e->Curr.X, horzEdge->Curr.Y); + IntPoint Pt = IntPoint(e->Curr.x(), horzEdge->Curr.y()); IntersectEdges(horzEdge, e, Pt); } else { - IntPoint Pt = IntPoint(e->Curr.X, horzEdge->Curr.Y); + IntPoint Pt = IntPoint(e->Curr.x(), horzEdge->Curr.y()); IntersectEdges( e, horzEdge, Pt); } TEdge* eNext = (dir == dLeftToRight) ? e->NextInAEL : e->PrevInAEL; @@ -2349,8 +2326,8 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) while (eNextHorz) { if (eNextHorz->OutIdx >= 0 && - HorzSegmentsOverlap(horzEdge->Bot.X, - horzEdge->Top.X, eNextHorz->Bot.X, eNextHorz->Top.X)) + HorzSegmentsOverlap(horzEdge->Bot.x(), + horzEdge->Top.x(), eNextHorz->Bot.x(), eNextHorz->Top.x())) { OutPt* op2 = GetLastOutPt(eNextHorz); m_Joins.emplace_back(Join(op2, op1, eNextHorz->Top)); @@ -2370,17 +2347,17 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge) //nb: HorzEdge is no longer horizontal here TEdge* ePrev = horzEdge->PrevInAEL; TEdge* eNext = horzEdge->NextInAEL; - if (ePrev && ePrev->Curr.X == horzEdge->Bot.X && - ePrev->Curr.Y == horzEdge->Bot.Y && ePrev->WindDelta != 0 && - (ePrev->OutIdx >= 0 && ePrev->Curr.Y > ePrev->Top.Y && + if (ePrev && ePrev->Curr.x() == horzEdge->Bot.x() && + ePrev->Curr.y() == horzEdge->Bot.y() && ePrev->WindDelta != 0 && + (ePrev->OutIdx >= 0 && ePrev->Curr.y() > ePrev->Top.y() && SlopesEqual(*horzEdge, *ePrev, m_UseFullRange))) { OutPt* op2 = AddOutPt(ePrev, horzEdge->Bot); m_Joins.emplace_back(Join(op1, op2, horzEdge->Top)); } - else if (eNext && eNext->Curr.X == horzEdge->Bot.X && - eNext->Curr.Y == horzEdge->Bot.Y && eNext->WindDelta != 0 && - eNext->OutIdx >= 0 && eNext->Curr.Y > eNext->Top.Y && + else if (eNext && eNext->Curr.x() == horzEdge->Bot.x() && + eNext->Curr.y() == horzEdge->Bot.y() && eNext->WindDelta != 0 && + eNext->OutIdx >= 0 && eNext->Curr.y() > eNext->Top.y() && SlopesEqual(*horzEdge, *eNext, m_UseFullRange)) { OutPt* op2 = AddOutPt(eNext, horzEdge->Bot); @@ -2418,7 +2395,7 @@ void Clipper::UpdateEdgeIntoAEL(TEdge *&e) e->PrevInAEL = AelPrev; e->NextInAEL = AelNext; if (!IsHorizontal(*e)) - m_Scanbeam.push(e->Top.Y); + m_Scanbeam.push(e->Top.y()); } //------------------------------------------------------------------------------ @@ -2461,7 +2438,7 @@ void Clipper::BuildIntersectList(const cInt topY) { e->PrevInSEL = e->PrevInAEL; e->NextInSEL = e->NextInAEL; - e->Curr.X = TopX( *e, topY ); + e->Curr.x() = TopX( *e, topY ); e = e->NextInAEL; } @@ -2475,7 +2452,7 @@ void Clipper::BuildIntersectList(const cInt topY) { TEdge *eNext = e->NextInSEL; IntPoint Pt; - if(e->Curr.X > eNext->Curr.X) + if(e->Curr.x() > eNext->Curr.x()) { IntersectPoint(*e, *eNext, Pt); m_IntersectList.emplace_back(IntersectNode(e, eNext, Pt)); @@ -2507,7 +2484,7 @@ bool Clipper::FixupIntersectionOrder() //Now it's crucial that intersections are made only between adjacent edges, //so to ensure this the order of intersections may need adjusting ... CopyAELToSEL(); - std::sort(m_IntersectList.begin(), m_IntersectList.end(), [](const IntersectNode &node1, const IntersectNode &node2) { return node2.Pt.Y < node1.Pt.Y; }); + std::sort(m_IntersectList.begin(), m_IntersectList.end(), [](const IntersectNode &node1, const IntersectNode &node2) { return node2.Pt.y() < node1.Pt.y(); }); size_t cnt = m_IntersectList.size(); for (size_t i = 0; i < cnt; ++i) @@ -2595,7 +2572,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) if(IsMaximaEdge) { - if (m_StrictSimple) m_Maxima.push_back(e->Top.X); + if (m_StrictSimple) m_Maxima.push_back(e->Top.x()); TEdge* ePrev = e->PrevInAEL; DoMaxima(e); if( !ePrev ) e = m_ActiveEdges; @@ -2603,7 +2580,7 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) } else { - //2. promote horizontal edges, otherwise update Curr.X and Curr.Y ... + //2. promote horizontal edges, otherwise update Curr.x() and Curr.y() ... if (IsIntermediate(e, topY) && IsHorizontal(*e->NextInLML)) { UpdateEdgeIntoAEL(e); @@ -2613,8 +2590,8 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) } else { - e->Curr.X = TopX( *e, topY ); - e->Curr.Y = topY; + e->Curr.x() = TopX( *e, topY ); + e->Curr.y() = topY; } //When StrictlySimple and 'e' is being touched by another edge, then @@ -2623,10 +2600,10 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) { TEdge* ePrev = e->PrevInAEL; if ((e->OutIdx >= 0) && (e->WindDelta != 0) && ePrev && (ePrev->OutIdx >= 0) && - (ePrev->Curr.X == e->Curr.X) && (ePrev->WindDelta != 0)) + (ePrev->Curr.x() == e->Curr.x()) && (ePrev->WindDelta != 0)) { IntPoint pt = e->Curr; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ SetZ(pt, *ePrev, *e); #endif OutPt* op = AddOutPt(ePrev, pt); @@ -2658,18 +2635,18 @@ void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY) //if output polygons share an edge, they'll need joining later ... TEdge* ePrev = e->PrevInAEL; TEdge* eNext = e->NextInAEL; - if (ePrev && ePrev->Curr.X == e->Bot.X && - ePrev->Curr.Y == e->Bot.Y && op && - ePrev->OutIdx >= 0 && ePrev->Curr.Y > ePrev->Top.Y && + if (ePrev && ePrev->Curr.x() == e->Bot.x() && + ePrev->Curr.y() == e->Bot.y() && op && + ePrev->OutIdx >= 0 && ePrev->Curr.y() > ePrev->Top.y() && SlopesEqual(*e, *ePrev, m_UseFullRange) && (e->WindDelta != 0) && (ePrev->WindDelta != 0)) { OutPt* op2 = AddOutPt(ePrev, e->Bot); m_Joins.emplace_back(Join(op, op2, e->Top)); } - else if (eNext && eNext->Curr.X == e->Bot.X && - eNext->Curr.Y == e->Bot.Y && op && - eNext->OutIdx >= 0 && eNext->Curr.Y > eNext->Top.Y && + else if (eNext && eNext->Curr.x() == e->Bot.x() && + eNext->Curr.y() == e->Bot.y() && op && + eNext->OutIdx >= 0 && eNext->Curr.y() > eNext->Top.y() && SlopesEqual(*e, *eNext, m_UseFullRange) && (e->WindDelta != 0) && (eNext->WindDelta != 0)) { @@ -2846,13 +2823,13 @@ void Clipper::BuildResult2(PolyTree& polytree) inline bool E2InsertsBeforeE1(TEdge &e1, TEdge &e2) { - if (e2.Curr.X == e1.Curr.X) + if (e2.Curr.x() == e1.Curr.x()) { - if (e2.Top.Y > e1.Top.Y) - return e2.Top.X < TopX(e1, e2.Top.Y); - else return e1.Top.X > TopX(e2, e1.Top.Y); + if (e2.Top.y() > e1.Top.y()) + return e2.Top.x() < TopX(e1, e2.Top.y()); + else return e1.Top.x() > TopX(e2, e1.Top.y()); } - else return e2.Curr.X < e1.Curr.X; + else return e2.Curr.x() < e1.Curr.x(); } //------------------------------------------------------------------------------ @@ -2941,8 +2918,8 @@ OutPt* Clipper::DupOutPt(OutPt* outPt, bool InsertAfter) bool Clipper::JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, const IntPoint &Pt, bool DiscardLeft) { - Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? dRightToLeft : dLeftToRight); - Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? dRightToLeft : dLeftToRight); + Direction Dir1 = (op1->Pt.x() > op1b->Pt.x() ? dRightToLeft : dLeftToRight); + Direction Dir2 = (op2->Pt.x() > op2b->Pt.x() ? dRightToLeft : dLeftToRight); if (Dir1 == Dir2) return false; //When DiscardLeft, we want Op1b to be on the Left of Op1, otherwise we @@ -2952,10 +2929,10 @@ bool Clipper::JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, //otherwise make sure we're AT or LEFT of Pt. (Likewise with Op2b.) if (Dir1 == dLeftToRight) { - while (op1->Next->Pt.X <= Pt.X && - op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) + while (op1->Next->Pt.x() <= Pt.x() && + op1->Next->Pt.x() >= op1->Pt.x() && op1->Next->Pt.y() == Pt.y()) op1 = op1->Next; - if (DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next; + if (DiscardLeft && (op1->Pt.x() != Pt.x())) op1 = op1->Next; op1b = this->DupOutPt(op1, !DiscardLeft); if (op1b->Pt != Pt) { @@ -2966,10 +2943,10 @@ bool Clipper::JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, } else { - while (op1->Next->Pt.X >= Pt.X && - op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) + while (op1->Next->Pt.x() >= Pt.x() && + op1->Next->Pt.x() <= op1->Pt.x() && op1->Next->Pt.y() == Pt.y()) op1 = op1->Next; - if (!DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next; + if (!DiscardLeft && (op1->Pt.x() != Pt.x())) op1 = op1->Next; op1b = this->DupOutPt(op1, DiscardLeft); if (op1b->Pt != Pt) { @@ -2981,10 +2958,10 @@ bool Clipper::JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, if (Dir2 == dLeftToRight) { - while (op2->Next->Pt.X <= Pt.X && - op2->Next->Pt.X >= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) + while (op2->Next->Pt.x() <= Pt.x() && + op2->Next->Pt.x() >= op2->Pt.x() && op2->Next->Pt.y() == Pt.y()) op2 = op2->Next; - if (DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next; + if (DiscardLeft && (op2->Pt.x() != Pt.x())) op2 = op2->Next; op2b = this->DupOutPt(op2, !DiscardLeft); if (op2b->Pt != Pt) { @@ -2994,10 +2971,10 @@ bool Clipper::JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b, }; } else { - while (op2->Next->Pt.X >= Pt.X && - op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) + while (op2->Next->Pt.x() >= Pt.x() && + op2->Next->Pt.x() <= op2->Pt.x() && op2->Next->Pt.y() == Pt.y()) op2 = op2->Next; - if (!DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next; + if (!DiscardLeft && (op2->Pt.x() != Pt.x())) op2 = op2->Next; op2b = this->DupOutPt(op2, DiscardLeft); if (op2b->Pt != Pt) { @@ -3037,7 +3014,7 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) //location at the Bottom of the overlapping segment (& Join.OffPt is above). //3. StrictSimple joins where edges touch but are not collinear and where //Join.OutPt1, Join.OutPt2 & Join.OffPt all share the same point. - bool isHorizontal = (j->OutPt1->Pt.Y == j->OffPt.Y); + bool isHorizontal = (j->OutPt1->Pt.y() == j->OffPt.y()); if (isHorizontal && (j->OffPt == j->OutPt1->Pt) && (j->OffPt == j->OutPt2->Pt)) @@ -3047,11 +3024,11 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) op1b = j->OutPt1->Next; while (op1b != op1 && (op1b->Pt == j->OffPt)) op1b = op1b->Next; - bool reverse1 = (op1b->Pt.Y > j->OffPt.Y); + bool reverse1 = (op1b->Pt.y() > j->OffPt.y()); op2b = j->OutPt2->Next; while (op2b != op2 && (op2b->Pt == j->OffPt)) op2b = op2b->Next; - bool reverse2 = (op2b->Pt.Y > j->OffPt.Y); + bool reverse2 = (op2b->Pt.y() > j->OffPt.y()); if (reverse1 == reverse2) return false; if (reverse1) { @@ -3083,22 +3060,22 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) //them we're not yet sure where the overlapping is. OutPt1.Pt & OutPt2.Pt //may be anywhere along the horizontal edge. op1b = op1; - while (op1->Prev->Pt.Y == op1->Pt.Y && op1->Prev != op1b && op1->Prev != op2) + while (op1->Prev->Pt.y() == op1->Pt.y() && op1->Prev != op1b && op1->Prev != op2) op1 = op1->Prev; - while (op1b->Next->Pt.Y == op1b->Pt.Y && op1b->Next != op1 && op1b->Next != op2) + while (op1b->Next->Pt.y() == op1b->Pt.y() && op1b->Next != op1 && op1b->Next != op2) op1b = op1b->Next; if (op1b->Next == op1 || op1b->Next == op2) return false; //a flat 'polygon' op2b = op2; - while (op2->Prev->Pt.Y == op2->Pt.Y && op2->Prev != op2b && op2->Prev != op1b) + while (op2->Prev->Pt.y() == op2->Pt.y() && op2->Prev != op2b && op2->Prev != op1b) op2 = op2->Prev; - while (op2b->Next->Pt.Y == op2b->Pt.Y && op2b->Next != op2 && op2b->Next != op1) + while (op2b->Next->Pt.y() == op2b->Pt.y() && op2b->Next != op2 && op2b->Next != op1) op2b = op2b->Next; if (op2b->Next == op2 || op2b->Next == op1) return false; //a flat 'polygon' cInt Left, Right; //Op1 --> Op1b & Op2 --> Op2b are the extremites of the horizontal edges - if (!GetOverlap(op1->Pt.X, op1b->Pt.X, op2->Pt.X, op2b->Pt.X, Left, Right)) + if (!GetOverlap(op1->Pt.x(), op1b->Pt.x(), op2->Pt.x(), op2b->Pt.x(), Left, Right)) return false; //DiscardLeftSide: when overlapping edges are joined, a spike will created @@ -3106,51 +3083,51 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2) //on the discard Side as either may still be needed for other joins ... IntPoint Pt; bool DiscardLeftSide; - if (op1->Pt.X >= Left && op1->Pt.X <= Right) + if (op1->Pt.x() >= Left && op1->Pt.x() <= Right) { - Pt = op1->Pt; DiscardLeftSide = (op1->Pt.X > op1b->Pt.X); + Pt = op1->Pt; DiscardLeftSide = (op1->Pt.x() > op1b->Pt.x()); } - else if (op2->Pt.X >= Left&& op2->Pt.X <= Right) + else if (op2->Pt.x() >= Left&& op2->Pt.x() <= Right) { - Pt = op2->Pt; DiscardLeftSide = (op2->Pt.X > op2b->Pt.X); + Pt = op2->Pt; DiscardLeftSide = (op2->Pt.x() > op2b->Pt.x()); } - else if (op1b->Pt.X >= Left && op1b->Pt.X <= Right) + else if (op1b->Pt.x() >= Left && op1b->Pt.x() <= Right) { - Pt = op1b->Pt; DiscardLeftSide = op1b->Pt.X > op1->Pt.X; + Pt = op1b->Pt; DiscardLeftSide = op1b->Pt.x() > op1->Pt.x(); } else { - Pt = op2b->Pt; DiscardLeftSide = (op2b->Pt.X > op2->Pt.X); + Pt = op2b->Pt; DiscardLeftSide = (op2b->Pt.x() > op2->Pt.x()); } j->OutPt1 = op1; j->OutPt2 = op2; return JoinHorz(op1, op1b, op2, op2b, Pt, DiscardLeftSide); } else { //nb: For non-horizontal joins ... - // 1. Jr.OutPt1.Pt.Y == Jr.OutPt2.Pt.Y - // 2. Jr.OutPt1.Pt > Jr.OffPt.Y + // 1. Jr.OutPt1.Pt.y() == Jr.OutPt2.Pt.y() + // 2. Jr.OutPt1.Pt > Jr.OffPt.y() //make sure the polygons are correctly oriented ... op1b = op1->Next; while ((op1b->Pt == op1->Pt) && (op1b != op1)) op1b = op1b->Next; - bool Reverse1 = ((op1b->Pt.Y > op1->Pt.Y) || + bool Reverse1 = ((op1b->Pt.y() > op1->Pt.y()) || !SlopesEqual(op1->Pt, op1b->Pt, j->OffPt, m_UseFullRange)); if (Reverse1) { op1b = op1->Prev; while ((op1b->Pt == op1->Pt) && (op1b != op1)) op1b = op1b->Prev; - if ((op1b->Pt.Y > op1->Pt.Y) || + if ((op1b->Pt.y() > op1->Pt.y()) || !SlopesEqual(op1->Pt, op1b->Pt, j->OffPt, m_UseFullRange)) return false; }; op2b = op2->Next; while ((op2b->Pt == op2->Pt) && (op2b != op2))op2b = op2b->Next; - bool Reverse2 = ((op2b->Pt.Y > op2->Pt.Y) || + bool Reverse2 = ((op2b->Pt.y() > op2->Pt.y()) || !SlopesEqual(op2->Pt, op2b->Pt, j->OffPt, m_UseFullRange)); if (Reverse2) { op2b = op2->Prev; while ((op2b->Pt == op2->Pt) && (op2b != op2)) op2b = op2b->Prev; - if ((op2b->Pt.Y > op2->Pt.Y) || + if ((op2b->Pt.y() > op2->Pt.y()) || !SlopesEqual(op2->Pt, op2b->Pt, j->OffPt, m_UseFullRange)) return false; } @@ -3319,12 +3296,12 @@ void Clipper::JoinCommonEdges() DoublePoint GetUnitNormal(const IntPoint &pt1, const IntPoint &pt2) { - if(pt2.X == pt1.X && pt2.Y == pt1.Y) + if(pt2.x() == pt1.x() && pt2.y() == pt1.y()) return DoublePoint(0, 0); - double Dx = (double)(pt2.X - pt1.X); - double dy = (double)(pt2.Y - pt1.Y); - double f = 1 *1.0/ std::sqrt( Dx*Dx + dy*dy ); + double Dx = double(pt2.x() - pt1.x()); + double dy = double(pt2.y() - pt1.y()); + double f = 1.0 / std::sqrt( Dx*Dx + dy*dy ); Dx *= f; dy *= f; return DoublePoint(dy, -Dx); @@ -3339,7 +3316,7 @@ void ClipperOffset::Clear() for (int i = 0; i < m_polyNodes.ChildCount(); ++i) delete m_polyNodes.Childs[i]; m_polyNodes.Childs.clear(); - m_lowest.X = -1; + m_lowest.x() = -1; } //------------------------------------------------------------------------------ @@ -3358,8 +3335,8 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType for (; highI > 0; -- highI) { bool same = false; if (has_shortest_edge_length) { - double dx = double(path[highI].X - path[0].X); - double dy = double(path[highI].Y - path[0].Y); + double dx = double(path[highI].x() - path[0].x()); + double dy = double(path[highI].y() - path[0].y()); same = dx*dx + dy*dy < shortest_edge_length2; } else same = path[0] == path[highI]; @@ -3372,8 +3349,8 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType for (int i = 1; i <= highI; i++) { bool same = false; if (has_shortest_edge_length) { - double dx = double(path[i].X - newNode->Contour[j].X); - double dy = double(path[i].Y - newNode->Contour[j].Y); + double dx = double(path[i].x() - newNode->Contour[j].x()); + double dy = double(path[i].y() - newNode->Contour[j].y()); same = dx*dx + dy*dy < shortest_edge_length2; } else same = newNode->Contour[j] == path[i]; @@ -3381,9 +3358,9 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType continue; j++; newNode->Contour.push_back(path[i]); - if (path[i].Y > newNode->Contour[k].Y || - (path[i].Y == newNode->Contour[k].Y && - path[i].X < newNode->Contour[k].X)) k = j; + if (path[i].y() > newNode->Contour[k].y() || + (path[i].y() == newNode->Contour[k].y() && + path[i].x() < newNode->Contour[k].x())) k = j; } if (endType == etClosedPolygon && j < 2) { @@ -3394,32 +3371,25 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType //if this path's lowest pt is lower than all the others then update m_lowest if (endType != etClosedPolygon) return; - if (m_lowest.X < 0) + if (m_lowest.x() < 0) m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k); else { - IntPoint ip = m_polyNodes.Childs[(int)m_lowest.X]->Contour[(int)m_lowest.Y]; - if (newNode->Contour[k].Y > ip.Y || - (newNode->Contour[k].Y == ip.Y && - newNode->Contour[k].X < ip.X)) + IntPoint ip = m_polyNodes.Childs[(int)m_lowest.x()]->Contour[(int)m_lowest.y()]; + if (newNode->Contour[k].y() > ip.y() || + (newNode->Contour[k].y() == ip.y() && + newNode->Contour[k].x() < ip.x())) m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k); } } //------------------------------------------------------------------------------ -void ClipperOffset::AddPaths(const Paths& paths, JoinType joinType, EndType endType) -{ - for (const Path &path : paths) - AddPath(path, joinType, endType); -} -//------------------------------------------------------------------------------ - void ClipperOffset::FixOrientations() { //fixup orientations of all closed paths if the orientation of the //closed path with the lowermost vertex is wrong ... - if (m_lowest.X >= 0 && - !Orientation(m_polyNodes.Childs[(int)m_lowest.X]->Contour)) + if (m_lowest.x() >= 0 && + !Orientation(m_polyNodes.Childs[(int)m_lowest.x()]->Contour)) { for (int i = 0; i < m_polyNodes.ChildCount(); ++i) { @@ -3530,8 +3500,9 @@ void ClipperOffset::DoOffset(double delta) } //see offset_triginometry3.svg in the documentation folder ... - if (MiterLimit > 2) m_miterLim = 2/(MiterLimit * MiterLimit); - else m_miterLim = 0.5; + m_miterLim = (MiterLimit > 2) ? + 2. / (MiterLimit * MiterLimit) : + 0.5; double y; if (ArcTolerance <= 0.0) y = def_arc_tolerance; @@ -3566,8 +3537,8 @@ void ClipperOffset::DoOffset(double delta) for (cInt j = 1; j <= steps; j++) { m_destPoly.push_back(IntPoint( - Round(m_srcPoly[0].X + X * delta), - Round(m_srcPoly[0].Y + Y * delta))); + Round(m_srcPoly[0].x() + X * delta), + Round(m_srcPoly[0].y() + Y * delta))); double X2 = X; X = X * m_cos - m_sin * Y; Y = X2 * m_sin + Y * m_cos; @@ -3579,8 +3550,8 @@ void ClipperOffset::DoOffset(double delta) for (int j = 0; j < 4; ++j) { m_destPoly.push_back(IntPoint( - Round(m_srcPoly[0].X + X * delta), - Round(m_srcPoly[0].Y + Y * delta))); + Round(m_srcPoly[0].x() + X * delta), + Round(m_srcPoly[0].y() + Y * delta))); if (X < 0) X = 1; else if (Y < 0) Y = 1; else X = -1; @@ -3616,8 +3587,8 @@ void ClipperOffset::DoOffset(double delta) //re-build m_normals ... DoublePoint n = m_normals[len -1]; for (int j = len - 1; j > 0; j--) - m_normals[j] = DoublePoint(-m_normals[j - 1].X, -m_normals[j - 1].Y); - m_normals[0] = DoublePoint(-n.X, -n.Y); + m_normals[j] = DoublePoint(-m_normals[j - 1].x(), -m_normals[j - 1].y()); + m_normals[0] = DoublePoint(-n.x(), -n.y()); k = 0; for (int j = len - 1; j >= 0; j--) OffsetPoint(j, k, node.m_jointype); @@ -3633,11 +3604,9 @@ void ClipperOffset::DoOffset(double delta) if (node.m_endtype == etOpenButt) { int j = len - 1; - pt1 = IntPoint(Round(m_srcPoly[j].X + m_normals[j].X * - delta), Round(m_srcPoly[j].Y + m_normals[j].Y * delta)); + pt1 = IntPoint(Round(m_srcPoly[j].x() + m_normals[j].x() * delta), Round(m_srcPoly[j].y() + m_normals[j].y() * delta)); m_destPoly.push_back(pt1); - pt1 = IntPoint(Round(m_srcPoly[j].X - m_normals[j].X * - delta), Round(m_srcPoly[j].Y - m_normals[j].Y * delta)); + pt1 = IntPoint(Round(m_srcPoly[j].x() - m_normals[j].x() * delta), Round(m_srcPoly[j].y() - m_normals[j].y() * delta)); m_destPoly.push_back(pt1); } else @@ -3645,7 +3614,7 @@ void ClipperOffset::DoOffset(double delta) int j = len - 1; k = len - 2; m_sinA = 0; - m_normals[j] = DoublePoint(-m_normals[j].X, -m_normals[j].Y); + m_normals[j] = DoublePoint(-m_normals[j].x(), -m_normals[j].y()); if (node.m_endtype == etOpenSquare) DoSquare(j, k); else @@ -3654,19 +3623,17 @@ void ClipperOffset::DoOffset(double delta) //re-build m_normals ... for (int j = len - 1; j > 0; j--) - m_normals[j] = DoublePoint(-m_normals[j - 1].X, -m_normals[j - 1].Y); - m_normals[0] = DoublePoint(-m_normals[1].X, -m_normals[1].Y); + m_normals[j] = DoublePoint(-m_normals[j - 1].x(), -m_normals[j - 1].y()); + m_normals[0] = DoublePoint(-m_normals[1].x(), -m_normals[1].y()); k = len - 1; for (int j = k - 1; j > 0; --j) OffsetPoint(j, k, node.m_jointype); if (node.m_endtype == etOpenButt) { - pt1 = IntPoint(Round(m_srcPoly[0].X - m_normals[0].X * delta), - Round(m_srcPoly[0].Y - m_normals[0].Y * delta)); + pt1 = IntPoint(Round(m_srcPoly[0].x() - m_normals[0].x() * delta), Round(m_srcPoly[0].y() - m_normals[0].y() * delta)); m_destPoly.push_back(pt1); - pt1 = IntPoint(Round(m_srcPoly[0].X + m_normals[0].X * delta), - Round(m_srcPoly[0].Y + m_normals[0].Y * delta)); + pt1 = IntPoint(Round(m_srcPoly[0].x() + m_normals[0].x() * delta), Round(m_srcPoly[0].y() + m_normals[0].y() * delta)); m_destPoly.push_back(pt1); } else @@ -3687,15 +3654,15 @@ void ClipperOffset::DoOffset(double delta) void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype) { //cross product ... - m_sinA = (m_normals[k].X * m_normals[j].Y - m_normals[j].X * m_normals[k].Y); + m_sinA = (m_normals[k].x() * m_normals[j].y() - m_normals[j].x() * m_normals[k].y()); if (std::fabs(m_sinA * m_delta) < 1.0) { //dot product ... - double cosA = (m_normals[k].X * m_normals[j].X + m_normals[j].Y * m_normals[k].Y ); + double cosA = (m_normals[k].x() * m_normals[j].x() + m_normals[j].y() * m_normals[k].y() ); if (cosA > 0) // angle => 0 degrees { - m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].X + m_normals[k].X * m_delta), - Round(m_srcPoly[j].Y + m_normals[k].Y * m_delta))); + m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta), + Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta))); return; } //else angle => 180 degrees @@ -3705,19 +3672,19 @@ void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype) if (m_sinA * m_delta < 0) { - m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].X + m_normals[k].X * m_delta), - Round(m_srcPoly[j].Y + m_normals[k].Y * m_delta))); + m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta), + Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta))); m_destPoly.push_back(m_srcPoly[j]); - m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].X + m_normals[j].X * m_delta), - Round(m_srcPoly[j].Y + m_normals[j].Y * m_delta))); + m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta), + Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta))); } else switch (jointype) { case jtMiter: { - double r = 1 + (m_normals[j].X * m_normals[k].X + - m_normals[j].Y * m_normals[k].Y); + double r = 1 + (m_normals[j].x() * m_normals[k].x() + + m_normals[j].y() * m_normals[k].y()); if (r >= m_miterLim) DoMiter(j, k, r); else DoSquare(j, k); break; } @@ -3731,43 +3698,43 @@ void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype) void ClipperOffset::DoSquare(int j, int k) { double dx = std::tan(std::atan2(m_sinA, - m_normals[k].X * m_normals[j].X + m_normals[k].Y * m_normals[j].Y) / 4); + m_normals[k].x() * m_normals[j].x() + m_normals[k].y() * m_normals[j].y()) / 4); m_destPoly.push_back(IntPoint( - Round(m_srcPoly[j].X + m_delta * (m_normals[k].X - m_normals[k].Y * dx)), - Round(m_srcPoly[j].Y + m_delta * (m_normals[k].Y + m_normals[k].X * dx)))); + Round(m_srcPoly[j].x() + m_delta * (m_normals[k].x() - m_normals[k].y() * dx)), + Round(m_srcPoly[j].y() + m_delta * (m_normals[k].y() + m_normals[k].x() * dx)))); m_destPoly.push_back(IntPoint( - Round(m_srcPoly[j].X + m_delta * (m_normals[j].X + m_normals[j].Y * dx)), - Round(m_srcPoly[j].Y + m_delta * (m_normals[j].Y - m_normals[j].X * dx)))); + Round(m_srcPoly[j].x() + m_delta * (m_normals[j].x() + m_normals[j].y() * dx)), + Round(m_srcPoly[j].y() + m_delta * (m_normals[j].y() - m_normals[j].x() * dx)))); } //------------------------------------------------------------------------------ void ClipperOffset::DoMiter(int j, int k, double r) { double q = m_delta / r; - m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].X + (m_normals[k].X + m_normals[j].X) * q), - Round(m_srcPoly[j].Y + (m_normals[k].Y + m_normals[j].Y) * q))); + m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + (m_normals[k].x() + m_normals[j].x()) * q), + Round(m_srcPoly[j].y() + (m_normals[k].y() + m_normals[j].y()) * q))); } //------------------------------------------------------------------------------ void ClipperOffset::DoRound(int j, int k) { double a = std::atan2(m_sinA, - m_normals[k].X * m_normals[j].X + m_normals[k].Y * m_normals[j].Y); - int steps = std::max((int)Round(m_StepsPerRad * std::fabs(a)), 1); + m_normals[k].x() * m_normals[j].x() + m_normals[k].y() * m_normals[j].y()); + auto steps = std::max(Round(m_StepsPerRad * std::fabs(a)), 1); - double X = m_normals[k].X, Y = m_normals[k].Y, X2; + double X = m_normals[k].x(), Y = m_normals[k].y(), X2; for (int i = 0; i < steps; ++i) { m_destPoly.push_back(IntPoint( - Round(m_srcPoly[j].X + X * m_delta), - Round(m_srcPoly[j].Y + Y * m_delta))); + Round(m_srcPoly[j].x() + X * m_delta), + Round(m_srcPoly[j].y() + Y * m_delta))); X2 = X; X = X * m_cos - m_sin * Y; Y = X2 * m_sin + Y * m_cos; } m_destPoly.push_back(IntPoint( - Round(m_srcPoly[j].X + m_normals[j].X * m_delta), - Round(m_srcPoly[j].Y + m_normals[j].Y * m_delta))); + Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta), + Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta))); } //------------------------------------------------------------------------------ @@ -3859,34 +3826,22 @@ void ReversePaths(Paths& p) } //------------------------------------------------------------------------------ -void SimplifyPolygon(const Path &in_poly, Paths &out_polys, PolyFillType fillType) +Paths SimplifyPolygon(const Path &in_poly, PolyFillType fillType) { Clipper c; c.StrictlySimple(true); c.AddPath(in_poly, ptSubject, true); - c.Execute(ctUnion, out_polys, fillType, fillType); + Paths out; + c.Execute(ctUnion, out, fillType, fillType); + return out; } -//------------------------------------------------------------------------------ -void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType) -{ - Clipper c; - c.StrictlySimple(true); - c.AddPaths(in_polys, ptSubject, true); - c.Execute(ctUnion, out_polys, fillType, fillType); -} -//------------------------------------------------------------------------------ - -void SimplifyPolygons(Paths &polys, PolyFillType fillType) -{ - SimplifyPolygons(polys, polys, fillType); -} //------------------------------------------------------------------------------ inline double DistanceSqrd(const IntPoint& pt1, const IntPoint& pt2) { - double Dx = ((double)pt1.X - pt2.X); - double dy = ((double)pt1.Y - pt2.Y); + auto Dx = double(pt1.x() - pt2.x()); + auto dy = double(pt1.y() - pt2.y()); return (Dx*Dx + dy*dy); } //------------------------------------------------------------------------------ @@ -3900,10 +3855,10 @@ double DistanceFromLineSqrd( //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹ //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²) //see http://en.wikipedia.org/wiki/Perpendicular_distance - double A = double(ln1.Y - ln2.Y); - double B = double(ln2.X - ln1.X); - double C = A * ln1.X + B * ln1.Y; - C = A * pt.X + B * pt.Y - C; + double A = double(ln1.y() - ln2.y()); + double B = double(ln2.x() - ln1.x()); + double C = A * ln1.x() + B * ln1.y(); + C = A * pt.x() + B * pt.y() - C; return (C * C) / (A * A + B * B); } //--------------------------------------------------------------------------- @@ -3914,20 +3869,20 @@ bool SlopesNearCollinear(const IntPoint& pt1, //this function is more accurate when the point that's geometrically //between the other 2 points is the one that's tested for distance. //ie makes it more likely to pick up 'spikes' ... - if (std::abs(pt1.X - pt2.X) > std::abs(pt1.Y - pt2.Y)) + if (std::abs(pt1.x() - pt2.x()) > std::abs(pt1.y() - pt2.y())) { - if ((pt1.X > pt2.X) == (pt1.X < pt3.X)) + if ((pt1.x() > pt2.x()) == (pt1.x() < pt3.x())) return DistanceFromLineSqrd(pt1, pt2, pt3) < distSqrd; - else if ((pt2.X > pt1.X) == (pt2.X < pt3.X)) + else if ((pt2.x() > pt1.x()) == (pt2.x() < pt3.x())) return DistanceFromLineSqrd(pt2, pt1, pt3) < distSqrd; else return DistanceFromLineSqrd(pt3, pt1, pt2) < distSqrd; } else { - if ((pt1.Y > pt2.Y) == (pt1.Y < pt3.Y)) + if ((pt1.y() > pt2.y()) == (pt1.y() < pt3.y())) return DistanceFromLineSqrd(pt1, pt2, pt3) < distSqrd; - else if ((pt2.Y > pt1.Y) == (pt2.Y < pt3.Y)) + else if ((pt2.y() > pt1.y()) == (pt2.y() < pt3.y())) return DistanceFromLineSqrd(pt2, pt1, pt3) < distSqrd; else return DistanceFromLineSqrd(pt3, pt1, pt2) < distSqrd; @@ -3937,8 +3892,8 @@ bool SlopesNearCollinear(const IntPoint& pt1, bool PointsAreClose(IntPoint pt1, IntPoint pt2, double distSqrd) { - double Dx = (double)pt1.X - pt2.X; - double dy = (double)pt1.Y - pt2.Y; + auto Dx = double(pt1.x() - pt2.x()); + auto dy = double(pt1.y() - pt2.y()); return ((Dx * Dx) + (dy * dy) <= distSqrd); } //------------------------------------------------------------------------------ @@ -4046,7 +4001,7 @@ void Minkowski(const Path& poly, const Path& path, Path p; p.reserve(polyCnt); for (size_t j = 0; j < poly.size(); ++j) - p.push_back(IntPoint(path[i].X + poly[j].X, path[i].Y + poly[j].Y)); + p.push_back(IntPoint(path[i].x() + poly[j].x(), path[i].y() + poly[j].y())); pp.push_back(p); } else @@ -4055,7 +4010,7 @@ void Minkowski(const Path& poly, const Path& path, Path p; p.reserve(polyCnt); for (size_t j = 0; j < poly.size(); ++j) - p.push_back(IntPoint(path[i].X - poly[j].X, path[i].Y - poly[j].Y)); + p.push_back(IntPoint(path[i].x() - poly[j].x(), path[i].y() - poly[j].y())); pp.push_back(p); } @@ -4090,7 +4045,7 @@ void TranslatePath(const Path& input, Path& output, const IntPoint& delta) //precondition: input != output output.resize(input.size()); for (size_t i = 0; i < input.size(); ++i) - output[i] = IntPoint(input[i].X + delta.X, input[i].Y + delta.Y); + output[i] = IntPoint(input[i].x() + delta.x(), input[i].y() + delta.y()); } //------------------------------------------------------------------------------ @@ -4166,7 +4121,7 @@ void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths) std::ostream& operator <<(std::ostream &s, const IntPoint &p) { - s << "(" << p.X << "," << p.Y << ")"; + s << "(" << p.x() << "," << p.y() << ")"; return s; } //------------------------------------------------------------------------------ @@ -4176,8 +4131,8 @@ std::ostream& operator <<(std::ostream &s, const Path &p) if (p.empty()) return s; Path::size_type last = p.size() -1; for (Path::size_type i = 0; i < last; i++) - s << "(" << p[i].X << "," << p[i].Y << "), "; - s << "(" << p[last].X << "," << p[last].Y << ")\n"; + s << "(" << p[i].x() << "," << p[i].y() << "), "; + s << "(" << p[last].x() << "," << p[last].y() << ")\n"; return s; } //------------------------------------------------------------------------------ @@ -4192,3 +4147,7 @@ std::ostream& operator <<(std::ostream &s, const Paths &p) //------------------------------------------------------------------------------ } //ClipperLib namespace + +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +} // namespace CLIPPERLIB_NAMESPACE_PREFIX +#endif // CLIPPERLIB_NAMESPACE_PREFIX diff --git a/src/clipper/clipper.hpp b/src/clipper/clipper.hpp index 8b34779e3a..74e6601f96 100644 --- a/src/clipper/clipper.hpp +++ b/src/clipper/clipper.hpp @@ -37,10 +37,12 @@ #include #include +#include + #define CLIPPER_VERSION "6.2.6" -//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance. -//#define use_xyz +//CLIPPERLIB_USE_XYZ: adds a Z member to IntPoint. Adds a minor cost to perfomance. +//#define CLIPPERLIB_USE_XYZ //use_lines: Enables line clipping. Adds a very minor cost to performance. #define use_lines @@ -57,11 +59,15 @@ #include #include -#ifdef use_xyz -namespace ClipperLib_Z { -#else /* use_xyz */ -namespace ClipperLib { -#endif /* use_xyz */ +#ifdef CLIPPERLIB_NAMESPACE_PREFIX + namespace CLIPPERLIB_NAMESPACE_PREFIX { +#endif // CLIPPERLIB_NAMESPACE_PREFIX + +#ifdef CLIPPERLIB_USE_XYZ + namespace ClipperLib_Z { +#else + namespace ClipperLib { +#endif enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor }; enum PolyType { ptSubject, ptClip }; @@ -71,36 +77,41 @@ enum PolyType { ptSubject, ptClip }; //see http://glprogramming.com/red/chapter11.html enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; +// If defined, Clipper will work with 32bit signed int coordinates to reduce memory +// consumption and to speed up exact orientation predicate calculation. +// In that case, coordinates and their differences (vectors of the coordinates) have to fit int32_t. +#define CLIPPERLIB_INT32 + // Point coordinate type -typedef int64_t cInt; -// Maximum cInt value to allow a cross product calculation using 32bit expressions. -static cInt const loRange = 0x3FFFFFFF; -// Maximum allowed cInt value. -static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; - -struct IntPoint { - cInt X; - cInt Y; -#ifdef use_xyz - cInt Z; - IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {}; +#ifdef CLIPPERLIB_INT32 + // Coordinates and their differences (vectors of the coordinates) have to fit int32_t. + typedef int32_t cInt; #else - IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {}; -#endif + typedef int64_t cInt; + // Maximum cInt value to allow a cross product calculation using 32bit expressions. + static constexpr cInt const loRange = 0x3FFFFFFF; // 0x3FFFFFFF = 1 073 741 823 + // Maximum allowed cInt value. + static constexpr cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; +#endif // CLIPPERLIB_INT32 + +#ifdef CLIPPERLIB_INTPOINT_TYPE +using IntPoint = CLIPPERLIB_INTPOINT_TYPE; +#else // CLIPPERLIB_INTPOINT_TYPE +using IntPoint = Eigen::Matrix; +#endif // CLIPPERLIB_INTPOINT_TYPE + +using DoublePoint = Eigen::Matrix; - friend inline bool operator== (const IntPoint& a, const IntPoint& b) - { - return a.X == b.X && a.Y == b.Y; - } - friend inline bool operator!= (const IntPoint& a, const IntPoint& b) - { - return a.X != b.X || a.Y != b.Y; - } -}; //------------------------------------------------------------------------------ -typedef std::vector< IntPoint > Path; -typedef std::vector< Path > Paths; +typedef std::vector Path; +typedef std::vector Paths; inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;} inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;} @@ -109,16 +120,9 @@ std::ostream& operator <<(std::ostream &s, const IntPoint &p); std::ostream& operator <<(std::ostream &s, const Path &p); std::ostream& operator <<(std::ostream &s, const Paths &p); -struct DoublePoint -{ - double X; - double Y; - DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} - DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {} -}; //------------------------------------------------------------------------------ -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ typedef std::function ZFillCallback; #endif @@ -187,9 +191,7 @@ double Area(const Path &poly); inline bool Orientation(const Path &poly) { return Area(poly) >= 0; } int PointInPolygon(const IntPoint &pt, const Path &path); -void SimplifyPolygon(const Path &in_poly, Paths &out_polys, PolyFillType fillType = pftEvenOdd); -void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType = pftEvenOdd); -void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd); +Paths SimplifyPolygon(const Path &in_poly, PolyFillType fillType = pftEvenOdd); void CleanPolygon(const Path& in_poly, Path& out_poly, double distance = 1.415); void CleanPolygon(Path& poly, double distance = 1.415); @@ -259,11 +261,11 @@ enum EdgeSide { esLeft = 1, esRight = 2}; }; // Point of an output polygon. - // 36B on 64bit system without use_xyz. + // 36B on 64bit system without CLIPPERLIB_USE_XYZ. struct OutPt { // 4B int Idx; - // 16B without use_xyz / 24B with use_xyz + // 16B without CLIPPERLIB_USE_XYZ / 24B with CLIPPERLIB_USE_XYZ IntPoint Pt; // 4B on 32bit system, 8B on 64bit system OutPt *Next; @@ -289,10 +291,65 @@ enum EdgeSide { esLeft = 1, esRight = 2}; class ClipperBase { public: - ClipperBase() : m_UseFullRange(false), m_HasOpenPaths(false) {} + ClipperBase() : +#ifndef CLIPPERLIB_INT32 + m_UseFullRange(false), +#endif // CLIPPERLIB_INT32 + m_HasOpenPaths(false) {} ~ClipperBase() { Clear(); } bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed); - bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed); + + template + bool AddPaths(PathsProvider &&paths_provider, PolyType PolyTyp, bool Closed) + { + size_t num_paths = paths_provider.size(); + if (num_paths == 0) + return false; + if (num_paths == 1) + return AddPath(*paths_provider.begin(), PolyTyp, Closed); + + std::vector num_edges(num_paths, 0); + int num_edges_total = 0; + size_t i = 0; + for (const Path &pg : paths_provider) { + // Remove duplicate end point from a closed input path. + // Remove duplicate points from the end of the input path. + int highI = (int)pg.size() -1; + if (Closed) + while (highI > 0 && (pg[highI] == pg[0])) + --highI; + while (highI > 0 && (pg[highI] == pg[highI -1])) + --highI; + if ((Closed && highI < 2) || (!Closed && highI < 1)) + highI = -1; + num_edges[i ++] = highI + 1; + num_edges_total += highI + 1; + } + if (num_edges_total == 0) + return false; + + // Allocate a new edge array. + std::vector edges(num_edges_total); + // Fill in the edge array. + bool result = false; + TEdge *p_edge = edges.data(); + i = 0; + for (const Path &pg : paths_provider) { + if (num_edges[i]) { + bool res = AddPathInternal(pg, num_edges[i] - 1, PolyTyp, Closed, p_edge); + if (res) { + p_edge += num_edges[i]; + result = true; + } + } + ++ i; + } + if (result) + // At least some edges were generated. Remember the edge array. + m_edges.emplace_back(std::move(edges)); + return result; + } + void Clear(); IntRect GetBounds(); // By default, when three or more vertices are collinear in input polygons (subject or clip), the Clipper object removes the 'inner' vertices before clipping. @@ -310,9 +367,14 @@ protected: // Local minima (Y, left edge, right edge) sorted by ascending Y. std::vector m_MinimaList; +#ifdef CLIPPERLIB_INT32 + static constexpr const bool m_UseFullRange = false; +#else // CLIPPERLIB_INT32 // True if the input polygons have abs values higher than loRange, but lower than hiRange. // False if the input polygons have abs values lower or equal to loRange. bool m_UseFullRange; +#endif // CLIPPERLIB_INT32 + // A vector of edges per each input path. std::vector> m_edges; // Don't remove intermediate vertices of a collinear sequence of points. @@ -349,7 +411,7 @@ public: bool StrictlySimple() const {return m_StrictSimple;}; void StrictlySimple(bool value) {m_StrictSimple = value;}; //set the callback function for z value filling on intersections (otherwise Z is 0) -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void ZFillFunction(ZFillCallback zFillFunc) { m_ZFill = zFillFunc; } #endif protected: @@ -382,7 +444,7 @@ private: // Does the result go to a PolyTree or Paths? bool m_UsingPolyTree; bool m_StrictSimple; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ ZFillCallback m_ZFill; //custom callback #endif void SetWindingCount(TEdge& edge) const; @@ -435,7 +497,7 @@ private: void DoSimplePolygons(); void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec) const; void FixupFirstLefts2(OutRec* OldOutRec, OutRec* NewOutRec) const; -#ifdef use_xyz +#ifdef CLIPPERLIB_USE_XYZ void SetZ(IntPoint& pt, TEdge& e1, TEdge& e2); #endif }; @@ -448,7 +510,11 @@ public: MiterLimit(miterLimit), ArcTolerance(roundPrecision), ShortestEdgeLength(shortestEdgeLength), m_lowest(-1, 0) {} ~ClipperOffset() { Clear(); } void AddPath(const Path& path, JoinType joinType, EndType endType); - void AddPaths(const Paths& paths, JoinType joinType, EndType endType); + template + void AddPaths(PathsProvider &&paths, JoinType joinType, EndType endType) { + for (const Path &path : paths) + AddPath(path, joinType, endType); + } void Execute(Paths& solution, double delta); void Execute(PolyTree& solution, double delta); void Clear(); @@ -485,8 +551,20 @@ class clipperException : public std::exception }; //------------------------------------------------------------------------------ +template +inline Paths SimplifyPolygons(PathsProvider &&in_polys, PolyFillType fillType = pftEvenOdd) { + Clipper c; + c.StrictlySimple(true); + c.AddPaths(std::forward(in_polys), ptSubject, true); + Paths out; + c.Execute(ctUnion, out, fillType, fillType); + return out; +} + } //ClipperLib namespace +#ifdef CLIPPERLIB_NAMESPACE_PREFIX +} // namespace CLIPPERLIB_NAMESPACE_PREFIX +#endif // CLIPPERLIB_NAMESPACE_PREFIX + #endif //clipper_hpp - - diff --git a/src/clipper/clipper_z.cpp b/src/clipper/clipper_z.cpp index 4a54ef3467..f26be7089a 100644 --- a/src/clipper/clipper_z.cpp +++ b/src/clipper/clipper_z.cpp @@ -1,7 +1,7 @@ // Hackish wrapper around the ClipperLib library to compile the Clipper library with the Z support. // Enable the Z coordinate support. -#define use_xyz +#define CLIPPERLIB_USE_XYZ // and let it compile #include "clipper.cpp" diff --git a/src/clipper/clipper_z.hpp b/src/clipper/clipper_z.hpp index e5e7d48ce1..20596d8e19 100644 --- a/src/clipper/clipper_z.hpp +++ b/src/clipper/clipper_z.hpp @@ -2,17 +2,17 @@ #ifndef clipper_z_hpp #ifdef clipper_hpp -#error "You should include the clipper_z.hpp first" +#error "You should include clipper_z.hpp before clipper.hpp" #endif #define clipper_z_hpp // Enable the Z coordinate support. -#define use_xyz +#define CLIPPERLIB_USE_XYZ #include "clipper.hpp" #undef clipper_hpp -#undef use_xyz +#undef CLIPPERLIB_USE_XYZ #endif // clipper_z_hpp diff --git a/src/libnest2d/CMakeLists.txt b/src/libnest2d/CMakeLists.txt index 3892ed30bc..c18dc31cb4 100644 --- a/src/libnest2d/CMakeLists.txt +++ b/src/libnest2d/CMakeLists.txt @@ -12,11 +12,8 @@ set(LIBNEST2D_SRCFILES include/libnest2d/placers/bottomleftplacer.hpp include/libnest2d/placers/nfpplacer.hpp include/libnest2d/selections/selection_boilerplate.hpp - #include/libnest2d/selections/filler.hpp include/libnest2d/selections/firstfit.hpp - #include/libnest2d/selections/djd_heuristic.hpp - include/libnest2d/backends/clipper/geometries.hpp - include/libnest2d/backends/clipper/clipper_polygon.hpp + include/libnest2d/backends/libslic3r/geometries.hpp include/libnest2d/optimizers/nlopt/nlopt_boilerplate.hpp include/libnest2d/optimizers/nlopt/simplex.hpp include/libnest2d/optimizers/nlopt/subplex.hpp @@ -27,5 +24,5 @@ set(LIBNEST2D_SRCFILES add_library(libnest2d STATIC ${LIBNEST2D_SRCFILES}) target_include_directories(libnest2d PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) -target_link_libraries(libnest2d PUBLIC clipper NLopt::nlopt TBB::tbb Boost::boost) -target_compile_definitions(libnest2d PUBLIC LIBNEST2D_THREADING_tbb LIBNEST2D_STATIC LIBNEST2D_OPTIMIZER_nlopt LIBNEST2D_GEOMETRIES_clipper) +target_link_libraries(libnest2d PUBLIC NLopt::nlopt TBB::tbb Boost::boost libslic3r) +target_compile_definitions(libnest2d PUBLIC LIBNEST2D_THREADING_tbb LIBNEST2D_STATIC LIBNEST2D_OPTIMIZER_nlopt LIBNEST2D_GEOMETRIES_libslic3r) diff --git a/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp b/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp deleted file mode 100644 index 6511fbb72a..0000000000 --- a/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef CLIPPER_POLYGON_HPP -#define CLIPPER_POLYGON_HPP - -#include - -namespace ClipperLib { - -struct Polygon { - Path Contour; - Paths Holes; - - inline Polygon() = default; - - inline explicit Polygon(const Path& cont): Contour(cont) {} -// inline explicit Polygon(const Paths& holes): -// Holes(holes) {} - inline Polygon(const Path& cont, const Paths& holes): - Contour(cont), Holes(holes) {} - - inline explicit Polygon(Path&& cont): Contour(std::move(cont)) {} -// inline explicit Polygon(Paths&& holes): Holes(std::move(holes)) {} - inline Polygon(Path&& cont, Paths&& holes): - Contour(std::move(cont)), Holes(std::move(holes)) {} -}; - -inline IntPoint& operator +=(IntPoint& p, const IntPoint& pa ) { - // This could be done with SIMD - p.X += pa.X; - p.Y += pa.Y; - return p; -} - -inline IntPoint operator+(const IntPoint& p1, const IntPoint& p2) { - IntPoint ret = p1; - ret += p2; - return ret; -} - -inline IntPoint& operator -=(IntPoint& p, const IntPoint& pa ) { - p.X -= pa.X; - p.Y -= pa.Y; - return p; -} - -inline IntPoint operator -(const IntPoint& p ) { - IntPoint ret = p; - ret.X = -ret.X; - ret.Y = -ret.Y; - return ret; -} - -inline IntPoint operator-(const IntPoint& p1, const IntPoint& p2) { - IntPoint ret = p1; - ret -= p2; - return ret; -} - -inline IntPoint& operator *=(IntPoint& p, const IntPoint& pa ) { - p.X *= pa.X; - p.Y *= pa.Y; - return p; -} - -inline IntPoint operator*(const IntPoint& p1, const IntPoint& p2) { - IntPoint ret = p1; - ret *= p2; - return ret; -} - -} - -#endif // CLIPPER_POLYGON_HPP diff --git a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp b/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp deleted file mode 100644 index 9586db35c6..0000000000 --- a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp +++ /dev/null @@ -1,356 +0,0 @@ -#ifndef CLIPPER_BACKEND_HPP -#define CLIPPER_BACKEND_HPP - -#include -#include -#include -#include -#include - -#include -#include - -#include "clipper_polygon.hpp" - -namespace libnest2d { - -// Aliases for convinience -using PointImpl = ClipperLib::IntPoint; -using PathImpl = ClipperLib::Path; -using HoleStore = ClipperLib::Paths; -using PolygonImpl = ClipperLib::Polygon; - -template<> struct ShapeTag { using Type = PolygonTag; }; -template<> struct ShapeTag { using Type = PathTag; }; -template<> struct ShapeTag { using Type = PointTag; }; - -// Type of coordinate units used by Clipper. Enough to specialize for point, -// the rest of the types will work (Path, Polygon) -template<> struct CoordType { - using Type = ClipperLib::cInt; - static const constexpr ClipperLib::cInt MM_IN_COORDS = 1000000; -}; - -// Enough to specialize for path, it will work for multishape and Polygon -template<> struct PointType { using Type = PointImpl; }; - -// This is crucial. CountourType refers to itself by default, so we don't have -// to secialize for clipper Path. ContourType::Type is PathImpl. -template<> struct ContourType { using Type = PathImpl; }; - -// The holes are contained in Clipper::Paths -template<> struct HolesContainer { using Type = ClipperLib::Paths; }; - -namespace pointlike { - -// Tell libnest2d how to extract the X coord from a ClipperPoint object -template<> inline ClipperLib::cInt x(const PointImpl& p) -{ - return p.X; -} - -// Tell libnest2d how to extract the Y coord from a ClipperPoint object -template<> inline ClipperLib::cInt y(const PointImpl& p) -{ - return p.Y; -} - -// Tell libnest2d how to extract the X coord from a ClipperPoint object -template<> inline ClipperLib::cInt& x(PointImpl& p) -{ - return p.X; -} - -// Tell libnest2d how to extract the Y coord from a ClipperPoint object -template<> inline ClipperLib::cInt& y(PointImpl& p) -{ - return p.Y; -} - -} - -// Using the libnest2d default area implementation -#define DISABLE_BOOST_AREA - -namespace shapelike { - -template<> -inline void offset(PolygonImpl& sh, TCoord distance, const PolygonTag&) -{ - #define DISABLE_BOOST_OFFSET - - using ClipperLib::ClipperOffset; - using ClipperLib::jtSquare; - using ClipperLib::etClosedPolygon; - using ClipperLib::Paths; - - Paths result; - - try { - ClipperOffset offs; - offs.AddPath(sh.Contour, jtSquare, etClosedPolygon); - offs.AddPaths(sh.Holes, jtSquare, etClosedPolygon); - offs.Execute(result, static_cast(distance)); - } catch (ClipperLib::clipperException &) { - throw GeometryException(GeomErr::OFFSET); - } - - // Offsetting reverts the orientation and also removes the last vertex - // so boost will not have a closed polygon. - - // we plan to replace contours - sh.Holes.clear(); - - bool found_the_contour = false; - for(auto& r : result) { - if(ClipperLib::Orientation(r)) { - // We don't like if the offsetting generates more than one contour - // but throwing would be an overkill. Instead, we should warn the - // caller about the inability to create correct geometries - if(!found_the_contour) { - sh.Contour = std::move(r); - ClipperLib::ReversePath(sh.Contour); - auto front_p = sh.Contour.front(); - sh.Contour.emplace_back(std::move(front_p)); - found_the_contour = true; - } else { - dout() << "Warning: offsetting result is invalid!"; - /* TODO warning */ - } - } else { - // TODO If there are multiple contours we can't be sure which hole - // belongs to the first contour. (But in this case the situation is - // bad enough to let it go...) - sh.Holes.emplace_back(std::move(r)); - ClipperLib::ReversePath(sh.Holes.back()); - auto front_p = sh.Holes.back().front(); - sh.Holes.back().emplace_back(std::move(front_p)); - } - } -} - -template<> -inline void offset(PathImpl& sh, TCoord distance, const PathTag&) -{ - PolygonImpl p(std::move(sh)); - offset(p, distance, PolygonTag()); - sh = p.Contour; -} - -// Tell libnest2d how to make string out of a ClipperPolygon object -template<> inline std::string toString(const PolygonImpl& sh) -{ - std::stringstream ss; - - ss << "Contour {\n"; - for(auto p : sh.Contour) { - ss << "\t" << p.X << " " << p.Y << "\n"; - } - ss << "}\n"; - - for(auto& h : sh.Holes) { - ss << "Holes {\n"; - for(auto p : h) { - ss << "\t{\n"; - ss << "\t\t" << p.X << " " << p.Y << "\n"; - ss << "\t}\n"; - } - ss << "}\n"; - } - - return ss.str(); -} - -template<> -inline PolygonImpl create(const PathImpl& path, const HoleStore& holes) -{ - PolygonImpl p; - p.Contour = path; - p.Holes = holes; - - return p; -} - -template<> inline PolygonImpl create( PathImpl&& path, HoleStore&& holes) { - PolygonImpl p; - p.Contour.swap(path); - p.Holes.swap(holes); - - return p; -} - -template<> -inline const THolesContainer& holes(const PolygonImpl& sh) -{ - return sh.Holes; -} - -template<> inline THolesContainer& holes(PolygonImpl& sh) -{ - return sh.Holes; -} - -template<> -inline TContour& hole(PolygonImpl& sh, unsigned long idx) -{ - return sh.Holes[idx]; -} - -template<> -inline const TContour& hole(const PolygonImpl& sh, - unsigned long idx) -{ - return sh.Holes[idx]; -} - -template<> inline size_t holeCount(const PolygonImpl& sh) -{ - return sh.Holes.size(); -} - -template<> inline PathImpl& contour(PolygonImpl& sh) -{ - return sh.Contour; -} - -template<> -inline const PathImpl& contour(const PolygonImpl& sh) -{ - return sh.Contour; -} - -#define DISABLE_BOOST_TRANSLATE -template<> -inline void translate(PolygonImpl& sh, const PointImpl& offs) -{ - for(auto& p : sh.Contour) { p += offs; } - for(auto& hole : sh.Holes) for(auto& p : hole) { p += offs; } -} - -#define DISABLE_BOOST_ROTATE -template<> -inline void rotate(PolygonImpl& sh, const Radians& rads) -{ - using Coord = TCoord; - - auto cosa = rads.cos(); - auto sina = rads.sin(); - - for(auto& p : sh.Contour) { - p = { - static_cast(p.X * cosa - p.Y * sina), - static_cast(p.X * sina + p.Y * cosa) - }; - } - for(auto& hole : sh.Holes) for(auto& p : hole) { - p = { - static_cast(p.X * cosa - p.Y * sina), - static_cast(p.X * sina + p.Y * cosa) - }; - } -} - -} // namespace shapelike - -#define DISABLE_BOOST_NFP_MERGE -inline TMultiShape clipper_execute( - ClipperLib::Clipper& clipper, - ClipperLib::ClipType clipType, - ClipperLib::PolyFillType subjFillType = ClipperLib::pftEvenOdd, - ClipperLib::PolyFillType clipFillType = ClipperLib::pftEvenOdd) -{ - TMultiShape retv; - - ClipperLib::PolyTree result; - clipper.Execute(clipType, result, subjFillType, clipFillType); - - retv.reserve(static_cast(result.Total())); - - std::function processHole; - - auto processPoly = [&retv, &processHole](ClipperLib::PolyNode *pptr) { - PolygonImpl poly; - poly.Contour.swap(pptr->Contour); - - assert(!pptr->IsHole()); - - if(!poly.Contour.empty() ) { - auto front_p = poly.Contour.front(); - auto &back_p = poly.Contour.back(); - if(front_p.X != back_p.X || front_p.Y != back_p.X) - poly.Contour.emplace_back(front_p); - } - - for(auto h : pptr->Childs) { processHole(h, poly); } - retv.push_back(poly); - }; - - processHole = [&processPoly](ClipperLib::PolyNode *pptr, PolygonImpl& poly) - { - poly.Holes.emplace_back(std::move(pptr->Contour)); - - assert(pptr->IsHole()); - - if(!poly.Contour.empty() ) { - auto front_p = poly.Contour.front(); - auto &back_p = poly.Contour.back(); - if(front_p.X != back_p.X || front_p.Y != back_p.X) - poly.Contour.emplace_back(front_p); - } - - for(auto c : pptr->Childs) processPoly(c); - }; - - auto traverse = [&processPoly] (ClipperLib::PolyNode *node) - { - for(auto ch : node->Childs) processPoly(ch); - }; - - traverse(&result); - - return retv; -} - -namespace nfp { - -template<> inline TMultiShape -merge(const TMultiShape& shapes) -{ - ClipperLib::Clipper clipper(ClipperLib::ioReverseSolution); - - bool closed = true; - bool valid = true; - - for(auto& path : shapes) { - valid &= clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed); - - for(auto& h : path.Holes) - valid &= clipper.AddPath(h, ClipperLib::ptSubject, closed); - } - - if(!valid) throw GeometryException(GeomErr::MERGE); - - return clipper_execute(clipper, ClipperLib::ctUnion, ClipperLib::pftNegative); -} - -} - -} - -#define DISABLE_BOOST_CONVEX_HULL - -//#define DISABLE_BOOST_SERIALIZE -//#define DISABLE_BOOST_UNSERIALIZE - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4244) -#pragma warning(disable: 4267) -#endif -// All other operators and algorithms are implemented with boost -#include -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#endif // CLIPPER_BACKEND_HPP diff --git a/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp new file mode 100644 index 0000000000..14b075b19d --- /dev/null +++ b/src/libnest2d/include/libnest2d/backends/libslic3r/geometries.hpp @@ -0,0 +1,283 @@ +#ifndef CLIPPER_BACKEND_HPP +#define CLIPPER_BACKEND_HPP + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace Slic3r { + +template struct IsVec_ : public std::false_type {}; + +template struct IsVec_< Vec<2, T> >: public std::true_type {}; + +template +static constexpr const bool IsVec = IsVec_>::value; + +template using VecOnly = std::enable_if_t, O>; + +inline Point operator+(const Point& p1, const Point& p2) { + Point ret = p1; + ret += p2; + return ret; +} + +inline Point operator -(const Point& p ) { + Point ret = p; + ret.x() = -ret.x(); + ret.y() = -ret.y(); + return ret; +} + +inline Point operator-(const Point& p1, const Point& p2) { + Point ret = p1; + ret -= p2; + return ret; +} + +inline Point& operator *=(Point& p, const Point& pa ) { + p.x() *= pa.x(); + p.y() *= pa.y(); + return p; +} + +inline Point operator*(const Point& p1, const Point& p2) { + Point ret = p1; + ret *= p2; + return ret; +} + +} // namespace Slic3r + +namespace libnest2d { + +template using Vec = Slic3r::Vec<2, T>; + +// Aliases for convinience +using PointImpl = Slic3r::Point; +using PathImpl = Slic3r::Polygon; +using HoleStore = Slic3r::Polygons; +using PolygonImpl = Slic3r::ExPolygon; + +template<> struct ShapeTag { using Type = PointTag; }; +template<> struct ShapeTag { using Type = PointTag; }; + +template<> struct ShapeTag> { using Type = PathTag; }; +template<> struct ShapeTag { using Type = PathTag; }; +template<> struct ShapeTag { using Type = PathTag; }; +template<> struct ShapeTag { using Type = PolygonTag; }; +template<> struct ShapeTag { using Type = MultiPolygonTag; }; + +// Type of coordinate units used by Clipper. Enough to specialize for point, +// the rest of the types will work (Path, Polygon) +template<> struct CoordType { + using Type = coord_t; + static const constexpr coord_t MM_IN_COORDS = 1000000; +}; + +template<> struct CoordType { + using Type = coord_t; + static const constexpr coord_t MM_IN_COORDS = 1000000; +}; + +// Enough to specialize for path, it will work for multishape and Polygon +template<> struct PointType> { using Type = Slic3r::Vec2crd; }; +template<> struct PointType { using Type = Slic3r::Point; }; +template<> struct PointType { using Type = Slic3r::Point; }; + +// This is crucial. CountourType refers to itself by default, so we don't have +// to secialize for clipper Path. ContourType::Type is PathImpl. +template<> struct ContourType { using Type = Slic3r::Polygon; }; + +// The holes are contained in Clipper::Paths +template<> struct HolesContainer { using Type = Slic3r::Polygons; }; + +template<> +struct OrientationType { + static const constexpr Orientation Value = Orientation::COUNTER_CLOCKWISE; +}; + +template<> +struct OrientationType { + static const constexpr Orientation Value = Orientation::COUNTER_CLOCKWISE; +}; + +template<> +struct ClosureType { + static const constexpr Closure Value = Closure::OPEN; +}; + +template<> +struct ClosureType { + static const constexpr Closure Value = Closure::OPEN; +}; + +template<> struct MultiShape { using Type = Slic3r::ExPolygons; }; +template<> struct ContourType { using Type = Slic3r::Polygon; }; + +// Using the libnest2d default area implementation +#define DISABLE_BOOST_AREA + +namespace shapelike { + +template<> +inline void offset(Slic3r::ExPolygon& sh, coord_t distance, const PolygonTag&) +{ +#define DISABLE_BOOST_OFFSET + auto res = Slic3r::offset_ex(sh, distance, Slic3r::ClipperLib::jtSquare); + if (!res.empty()) sh = res.front(); +} + +template<> +inline void offset(Slic3r::Polygon& sh, coord_t distance, const PathTag&) +{ + auto res = Slic3r::offset(sh, distance, Slic3r::ClipperLib::jtSquare); + if (!res.empty()) sh = res.front(); +} + +// Tell libnest2d how to make string out of a ClipperPolygon object +template<> inline std::string toString(const Slic3r::ExPolygon& sh) +{ + std::stringstream ss; + + ss << "Contour {\n"; + for(auto &p : sh.contour.points) { + ss << "\t" << p.x() << " " << p.y() << "\n"; + } + ss << "}\n"; + + for(auto& h : sh.holes) { + ss << "Holes {\n"; + for(auto p : h.points) { + ss << "\t{\n"; + ss << "\t\t" << p.x() << " " << p.y() << "\n"; + ss << "\t}\n"; + } + ss << "}\n"; + } + + return ss.str(); +} + +template<> +inline Slic3r::ExPolygon create(const Slic3r::Polygon& path, const Slic3r::Polygons& holes) +{ + Slic3r::ExPolygon p; + p.contour = path; + p.holes = holes; + + return p; +} + +template<> inline Slic3r::ExPolygon create(Slic3r::Polygon&& path, Slic3r::Polygons&& holes) { + Slic3r::ExPolygon p; + p.contour.points.swap(path.points); + p.holes.swap(holes); + + return p; +} + +template<> +inline const THolesContainer& holes(const Slic3r::ExPolygon& sh) +{ + return sh.holes; +} + +template<> inline THolesContainer& holes(Slic3r::ExPolygon& sh) +{ + return sh.holes; +} + +template<> +inline Slic3r::Polygon& hole(Slic3r::ExPolygon& sh, unsigned long idx) +{ + return sh.holes[idx]; +} + +template<> +inline const Slic3r::Polygon& hole(const Slic3r::ExPolygon& sh, unsigned long idx) +{ + return sh.holes[idx]; +} + +template<> inline size_t holeCount(const Slic3r::ExPolygon& sh) +{ + return sh.holes.size(); +} + +template<> inline Slic3r::Polygon& contour(Slic3r::ExPolygon& sh) +{ + return sh.contour; +} + +template<> +inline const Slic3r::Polygon& contour(const Slic3r::ExPolygon& sh) +{ + return sh.contour; +} + +template<> +inline void reserve(Slic3r::Polygon& p, size_t vertex_capacity, const PathTag&) +{ + p.points.reserve(vertex_capacity); +} + +template<> +inline void addVertex(Slic3r::Polygon& sh, const PathTag&, const Slic3r::Point &p) +{ + sh.points.emplace_back(p); +} + +#define DISABLE_BOOST_TRANSLATE +template<> +inline void translate(Slic3r::ExPolygon& sh, const Slic3r::Point& offs) +{ + sh.translate(offs); +} + +#define DISABLE_BOOST_ROTATE +template<> +inline void rotate(Slic3r::ExPolygon& sh, const Radians& rads) +{ + sh.rotate(rads); +} + +} // namespace shapelike + +namespace nfp { + +#define DISABLE_BOOST_NFP_MERGE +template<> +inline TMultiShape merge(const TMultiShape& shapes) +{ + return Slic3r::union_ex(shapes); +} + +} // namespace nfp +} // namespace libnest2d + +#define DISABLE_BOOST_CONVEX_HULL + +//#define DISABLE_BOOST_SERIALIZE +//#define DISABLE_BOOST_UNSERIALIZE + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4244) +#pragma warning(disable: 4267) +#endif +// All other operators and algorithms are implemented with boost +#include +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif // CLIPPER_BACKEND_HPP diff --git a/src/libnest2d/include/libnest2d/geometry_traits.hpp b/src/libnest2d/include/libnest2d/geometry_traits.hpp index d9c3d78626..7ea4373398 100644 --- a/src/libnest2d/include/libnest2d/geometry_traits.hpp +++ b/src/libnest2d/include/libnest2d/geometry_traits.hpp @@ -128,22 +128,32 @@ template struct ContourType> { using Type = typename ContourType::Type; }; -enum class Orientation { - CLOCKWISE, - COUNTER_CLOCKWISE -}; +enum class Orientation { CLOCKWISE, COUNTER_CLOCKWISE }; template struct OrientationType { // Default Polygon orientation that the library expects - static const Orientation Value = Orientation::CLOCKWISE; + static const constexpr Orientation Value = Orientation::CLOCKWISE; }; -template inline /*constexpr*/ bool is_clockwise() { +template inline constexpr bool is_clockwise() { return OrientationType>::Value == Orientation::CLOCKWISE; } +template +inline const constexpr Orientation OrientationTypeV = + OrientationType>::Value; + +enum class Closure { OPEN, CLOSED }; + +template struct ClosureType { + static const constexpr Closure Value = Closure::CLOSED; +}; + +template +inline const constexpr Closure ClosureTypeV = + ClosureType>::Value; /** * \brief A point pair base class for other point pairs (segment, box, ...). @@ -474,8 +484,8 @@ inline _Box

_Box

::infinite(const P& center) { // It is important for Mx and My to be strictly less than half of the // range of type C. width(), height() and area() will not overflow this way. - C Mx = C((std::numeric_limits::lowest() + 2 * getX(center)) / 2.01); - C My = C((std::numeric_limits::lowest() + 2 * getY(center)) / 2.01); + C Mx = C((std::numeric_limits::lowest() + 2 * getX(center)) / 4.01); + C My = C((std::numeric_limits::lowest() + 2 * getY(center)) / 4.01); ret.maxCorner() = center - P{Mx, My}; ret.minCorner() = center + P{Mx, My}; @@ -587,9 +597,9 @@ inline void reserve(RawPath& p, size_t vertex_capacity, const PathTag&) } template -inline void addVertex(S& sh, const PathTag&, Args...args) +inline void addVertex(S& sh, const PathTag&, const TPoint &p) { - sh.emplace_back(std::forward(args)...); + sh.emplace_back(p); } template @@ -841,9 +851,9 @@ template auto rbegin(P& p) -> decltype(_backward(end(p))) return _backward(end(p)); } -template auto rcbegin(const P& p) -> decltype(_backward(end(p))) +template auto rcbegin(const P& p) -> decltype(_backward(cend(p))) { - return _backward(end(p)); + return _backward(cend(p)); } template auto rend(P& p) -> decltype(_backward(begin(p))) @@ -873,16 +883,16 @@ inline void reserve(T& sh, size_t vertex_capacity) { reserve(sh, vertex_capacity, Tag()); } -template -inline void addVertex(S& sh, const PolygonTag&, Args...args) +template +inline void addVertex(S& sh, const PolygonTag&, const TPoint &p) { - addVertex(contour(sh), PathTag(), std::forward(args)...); + addVertex(contour(sh), PathTag(), p); } -template // Tag dispatcher -inline void addVertex(S& sh, Args...args) +template // Tag dispatcher +inline void addVertex(S& sh, const TPoint &p) { - addVertex(sh, Tag(), std::forward(args)...); + addVertex(sh, Tag(), p); } template diff --git a/src/libnest2d/include/libnest2d/geometry_traits_nfp.hpp b/src/libnest2d/include/libnest2d/geometry_traits_nfp.hpp index 29a1ccd047..d9f9478026 100644 --- a/src/libnest2d/include/libnest2d/geometry_traits_nfp.hpp +++ b/src/libnest2d/include/libnest2d/geometry_traits_nfp.hpp @@ -28,7 +28,7 @@ inline void buildPolygon(const EdgeList& edgelist, auto& rsh = sl::contour(rpoly); - sl::reserve(rsh, 2*edgelist.size()); + sl::reserve(rsh, 2 * edgelist.size()); // Add the two vertices from the first edge into the final polygon. sl::addVertex(rsh, edgelist.front().first()); @@ -57,7 +57,6 @@ inline void buildPolygon(const EdgeList& edgelist, tmp = std::next(tmp); } - } template @@ -214,15 +213,24 @@ inline NfpResult nfpConvexOnly(const RawShape& sh, // Reserve the needed memory edgelist.reserve(cap); sl::reserve(rsh, static_cast(cap)); + auto add_edge = [&edgelist](const Vertex &v1, const Vertex &v2) { + Edge e{v1, v2}; + if (e.sqlength() > 0) + edgelist.emplace_back(e); + }; { // place all edges from sh into edgelist auto first = sl::cbegin(sh); auto next = std::next(first); while(next != sl::cend(sh)) { - edgelist.emplace_back(*(first), *(next)); + add_edge(*(first), *(next)); + ++first; ++next; } + + if constexpr (ClosureTypeV == Closure::OPEN) + add_edge(*sl::rcbegin(sh), *sl::cbegin(sh)); } { // place all edges from other into edgelist @@ -230,15 +238,19 @@ inline NfpResult nfpConvexOnly(const RawShape& sh, auto next = std::next(first); while(next != sl::cend(other)) { - edgelist.emplace_back(*(next), *(first)); + add_edge(*(next), *(first)); + ++first; ++next; } + + if constexpr (ClosureTypeV == Closure::OPEN) + add_edge(*sl::cbegin(other), *sl::rcbegin(other)); } - std::sort(edgelist.begin(), edgelist.end(), - [](const Edge& e1, const Edge& e2) + std::sort(edgelist.begin(), edgelist.end(), + [](const Edge& e1, const Edge& e2) { - Vertex ax(1, 0); // Unit vector for the X axis + const Vertex ax(1, 0); // Unit vector for the X axis // get cectors from the edges Vertex p1 = e1.second() - e1.first(); @@ -284,12 +296,18 @@ inline NfpResult nfpConvexOnly(const RawShape& sh, // If Ratio is an actual rational type, there is no precision loss auto pcos1 = Ratio(lcos[0]) / lsq1 * sign * lcos[0]; auto pcos2 = Ratio(lcos[1]) / lsq2 * sign * lcos[1]; - - return q[0] < 2 ? pcos1 < pcos2 : pcos1 > pcos2; + + if constexpr (is_clockwise()) + return q[0] < 2 ? pcos1 < pcos2 : pcos1 > pcos2; + else + return q[0] < 2 ? pcos1 > pcos2 : pcos1 < pcos2; } // If in different quadrants, compare the quadrant indices only. - return q[0] > q[1]; + if constexpr (is_clockwise()) + return q[0] > q[1]; + else + return q[0] < q[1]; }); __nfp::buildPolygon(edgelist, rsh, top_nfp); diff --git a/src/libnest2d/include/libnest2d/libnest2d.hpp b/src/libnest2d/include/libnest2d/libnest2d.hpp index 9d24a25696..a4cf7dc569 100644 --- a/src/libnest2d/include/libnest2d/libnest2d.hpp +++ b/src/libnest2d/include/libnest2d/libnest2d.hpp @@ -7,6 +7,10 @@ #include #endif +#ifdef LIBNEST2D_GEOMETRIES_libslic3r +#include +#endif + #ifdef LIBNEST2D_OPTIMIZER_nlopt // We include the stock optimizers for local and global optimization #include // Local subplex for NfpPlacer diff --git a/src/libnest2d/include/libnest2d/nester.hpp b/src/libnest2d/include/libnest2d/nester.hpp index 20da9b9a1e..52c738a4c1 100644 --- a/src/libnest2d/include/libnest2d/nester.hpp +++ b/src/libnest2d/include/libnest2d/nester.hpp @@ -96,7 +96,7 @@ public: * @return The orientation type identifier for the _Item type. */ static BP2D_CONSTEXPR Orientation orientation() { - return OrientationType::Value; + return OrientationType>::Value; } /** @@ -446,44 +446,32 @@ private: } }; +template Sh create_rect(TCoord width, TCoord height) +{ + auto sh = sl::create( + {{0, 0}, {0, height}, {width, height}, {width, 0}}); + + if constexpr (ClosureTypeV == Closure::CLOSED) + sl::addVertex(sh, {0, 0}); + + if constexpr (OrientationTypeV == Orientation::COUNTER_CLOCKWISE) + std::reverse(sl::begin(sh), sl::end(sh)); + + return sh; +} + /** * \brief Subclass of _Item for regular rectangle items. */ -template -class _Rectangle: public _Item { - using _Item::vertex; +template +class _Rectangle: public _Item { + using _Item::vertex; using TO = Orientation; public: - using Unit = TCoord>; + using Unit = TCoord; - template::Value> - inline _Rectangle(Unit width, Unit height, - // disable this ctor if o != CLOCKWISE - enable_if_t< o == TO::CLOCKWISE, int> = 0 ): - _Item( sl::create( { - {0, 0}, - {0, height}, - {width, height}, - {width, 0}, - {0, 0} - } )) - { - } - - template::Value> - inline _Rectangle(Unit width, Unit height, - // disable this ctor if o != COUNTER_CLOCKWISE - enable_if_t< o == TO::COUNTER_CLOCKWISE, int> = 0 ): - _Item( sl::create( { - {0, 0}, - {width, 0}, - {width, height}, - {0, height}, - {0, 0} - } )) - { - } + inline _Rectangle(Unit w, Unit h): _Item{create_rect(w, h)} {} inline Unit width() const BP2D_NOEXCEPT { return getX(vertex(2)); diff --git a/src/libnest2d/include/libnest2d/placers/bottomleftplacer.hpp b/src/libnest2d/include/libnest2d/placers/bottomleftplacer.hpp index e1a4ffbd92..a067194dc9 100644 --- a/src/libnest2d/include/libnest2d/placers/bottomleftplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/bottomleftplacer.hpp @@ -365,44 +365,50 @@ protected: // the additional vertices for maintaning min object distance sl::reserve(rsh, finish-start+4); - /*auto addOthers = [&rsh, finish, start, &item](){ + auto addOthers_ = [&rsh, finish, start, &item](){ for(size_t i = start+1; i < finish; i++) sl::addVertex(rsh, item.vertex(i)); - };*/ + }; - auto reverseAddOthers = [&rsh, finish, start, &item](){ + auto reverseAddOthers_ = [&rsh, finish, start, &item](){ for(auto i = finish-1; i > start; i--) - sl::addVertex(rsh, item.vertex( - static_cast(i))); + sl::addVertex(rsh, item.vertex(static_cast(i))); + }; + + auto addOthers = [&addOthers_, &reverseAddOthers_]() { + if constexpr (!is_clockwise()) + addOthers_(); + else + reverseAddOthers_(); }; // Final polygon construction... - static_assert(OrientationType::Value == - Orientation::CLOCKWISE, - "Counter clockwise toWallPoly() Unimplemented!"); - // Clockwise polygon construction sl::addVertex(rsh, topleft_vertex); - if(dir == Dir::LEFT) reverseAddOthers(); + if(dir == Dir::LEFT) addOthers(); else { - sl::addVertex(rsh, getX(topleft_vertex), 0); - sl::addVertex(rsh, getX(bottomleft_vertex), 0); + sl::addVertex(rsh, {getX(topleft_vertex), 0}); + sl::addVertex(rsh, {getX(bottomleft_vertex), 0}); } sl::addVertex(rsh, bottomleft_vertex); if(dir == Dir::LEFT) { - sl::addVertex(rsh, 0, getY(bottomleft_vertex)); - sl::addVertex(rsh, 0, getY(topleft_vertex)); + sl::addVertex(rsh, {0, getY(bottomleft_vertex)}); + sl::addVertex(rsh, {0, getY(topleft_vertex)}); } - else reverseAddOthers(); + else addOthers(); // Close the polygon - sl::addVertex(rsh, topleft_vertex); + if constexpr (ClosureTypeV == Closure::CLOSED) + sl::addVertex(rsh, topleft_vertex); + + if constexpr (!is_clockwise()) + std::reverse(rsh.begin(), rsh.end()); return ret; } diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index bd9c603558..47ba7bbdc5 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -250,8 +250,8 @@ template class EdgeCache { Vertex ret = edge.first(); // Get the point on the edge which lies in ed distance from the start - ret += { static_cast(std::round(ed*std::cos(angle))), - static_cast(std::round(ed*std::sin(angle))) }; + ret += Vertex(static_cast(std::round(ed*std::cos(angle))), + static_cast(std::round(ed*std::sin(angle)))); return ret; } @@ -724,8 +724,7 @@ private: auto rawobjfunc = [_objfunc, iv, startpos] (Vertex v, Item& itm) { - auto d = v - iv; - d += startpos; + auto d = (v - iv) + startpos; itm.translation(d); return _objfunc(itm); }; @@ -742,8 +741,7 @@ private: &item, &bin, &iv, &startpos] (const Optimum& o) { auto v = getNfpPoint(o); - auto d = v - iv; - d += startpos; + auto d = (v - iv) + startpos; item.translation(d); merged_pile.emplace_back(item.transformedShape()); @@ -877,8 +875,7 @@ private: } if( best_score < global_score ) { - auto d = getNfpPoint(optimum) - iv; - d += startpos; + auto d = (getNfpPoint(optimum) - iv) + startpos; final_tr = d; final_rot = initial_rot + rot; can_pack = true; diff --git a/src/libnest2d/include/libnest2d/utils/boost_alg.hpp b/src/libnest2d/include/libnest2d/utils/boost_alg.hpp index 16dee513b2..d6213d0edd 100644 --- a/src/libnest2d/include/libnest2d/utils/boost_alg.hpp +++ b/src/libnest2d/include/libnest2d/utils/boost_alg.hpp @@ -19,7 +19,7 @@ #pragma warning(pop) #endif // this should be removed to not confuse the compiler -// #include +// #include "../libnest2d.hpp" namespace bp2d { @@ -30,6 +30,10 @@ using libnest2d::PolygonImpl; using libnest2d::PathImpl; using libnest2d::Orientation; using libnest2d::OrientationType; +using libnest2d::OrientationTypeV; +using libnest2d::ClosureType; +using libnest2d::Closure; +using libnest2d::ClosureTypeV; using libnest2d::getX; using libnest2d::getY; using libnest2d::setX; @@ -213,8 +217,15 @@ struct ToBoostOrienation { static const order_selector Value = counterclockwise; }; -static const bp2d::Orientation RealOrientation = - bp2d::OrientationType::Value; +template struct ToBoostClosure {}; + +template<> struct ToBoostClosure { + static const constexpr closure_selector Value = closure_selector::open; +}; + +template<> struct ToBoostClosure { + static const constexpr closure_selector Value = closure_selector::closed; +}; // Ring implementation ///////////////////////////////////////////////////////// @@ -225,12 +236,13 @@ template<> struct tag { template<> struct point_order { static const order_selector value = - ToBoostOrienation::Value; + ToBoostOrienation>::Value; }; // All our Paths should be closed for the bin packing application template<> struct closure { - static const closure_selector value = closed; + static const constexpr closure_selector value = + ToBoostClosure< bp2d::ClosureTypeV >::Value; }; // Polygon implementation ////////////////////////////////////////////////////// diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 3800d49e31..61a32678b9 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -3,7 +3,7 @@ #include "BoundingBox.hpp" -#include +#include #include #include #include @@ -54,23 +54,22 @@ namespace Slic3r { template, int...EigenArgs> inline constexpr Eigen::Matrix unscaled( - const ClipperLib::IntPoint &v) noexcept + const Slic3r::ClipperLib::IntPoint &v) noexcept { - return Eigen::Matrix{unscaled(v.X), - unscaled(v.Y)}; + return Eigen::Matrix{unscaled(v.x()), + unscaled(v.y())}; } namespace arrangement { using namespace libnest2d; -namespace clppr = ClipperLib; // Get the libnest2d types for clipper backend -using Item = _Item; -using Box = _Box; -using Circle = _Circle; -using Segment = _Segment; -using MultiPolygon = TMultiShape; +using Item = _Item; +using Box = _Box; +using Circle = _Circle; +using Segment = _Segment; +using MultiPolygon = ExPolygons; // Summon the spatial indexing facilities from boost namespace bgi = boost::geometry::index; @@ -127,8 +126,8 @@ template class AutoArranger { public: // Useful type shortcuts... - using Placer = typename placers::_NofitPolyPlacer; - using Selector = selections::_FirstFitSelection; + using Placer = typename placers::_NofitPolyPlacer; + using Selector = selections::_FirstFitSelection; using Packer = _Nester; using PConfig = typename Packer::PlacementConfig; using Distance = TCoord; @@ -168,7 +167,7 @@ protected: // as it possibly can be but at the same time, it has to provide // reasonable results. std::tuple - objfunc(const Item &item, const clppr::IntPoint &bincenter) + objfunc(const Item &item, const Point &bincenter) { const double bin_area = m_bin_area; const SpatIndex& spatindex = m_rtree; @@ -220,12 +219,12 @@ protected: switch (compute_case) { case BIG_ITEM: { - const clppr::IntPoint& minc = ibb.minCorner(); // bottom left corner - const clppr::IntPoint& maxc = ibb.maxCorner(); // top right corner + const Point& minc = ibb.minCorner(); // bottom left corner + const Point& maxc = ibb.maxCorner(); // top right corner // top left and bottom right corners - clppr::IntPoint top_left{getX(minc), getY(maxc)}; - clppr::IntPoint bottom_right{getX(maxc), getY(minc)}; + Point top_left{getX(minc), getY(maxc)}; + Point bottom_right{getX(maxc), getY(minc)}; // Now the distance of the gravity center will be calculated to the // five anchor points and the smallest will be chosen. @@ -452,7 +451,7 @@ template<> std::function AutoArranger::get_objfn() // Specialization for a generalized polygon. // Warning: this is unfinished business. It may or may not work. template<> -std::function AutoArranger::get_objfn() +std::function AutoArranger::get_objfn() { auto bincenter = sl::boundingBox(m_bin).center(); return [this, bincenter](const Item &item) { @@ -521,7 +520,7 @@ void _arrange( inline Box to_nestbin(const BoundingBox &bb) { return Box{{bb.min(X), bb.min(Y)}, {bb.max(X), bb.max(Y)}};} inline Circle to_nestbin(const CircleBed &c) { return Circle({c.center()(0), c.center()(1)}, c.radius()); } -inline clppr::Polygon to_nestbin(const Polygon &p) { return sl::create(Slic3rMultiPoint_to_ClipperPath(p)); } +inline ExPolygon to_nestbin(const Polygon &p) { return ExPolygon{p}; } inline Box to_nestbin(const InfiniteBed &bed) { return Box::infinite({bed.center.x(), bed.center.y()}); } inline coord_t width(const BoundingBox& box) { return box.max.x() - box.min.x(); } @@ -568,19 +567,12 @@ static void process_arrangeable(const ArrangePolygon &arrpoly, const Vec2crd &offs = arrpoly.translation; double rotation = arrpoly.rotation; - if (p.is_counter_clockwise()) p.reverse(); - - clppr::Polygon clpath(Slic3rMultiPoint_to_ClipperPath(p)); - // This fixes: // https://github.com/prusa3d/PrusaSlicer/issues/2209 - if (clpath.Contour.size() < 3) + if (p.points.size() < 3) return; - auto firstp = clpath.Contour.front(); - clpath.Contour.emplace_back(firstp); - - outp.emplace_back(std::move(clpath)); + outp.emplace_back(std::move(p)); outp.back().rotation(rotation); outp.back().translation({offs.x(), offs.y()}); outp.back().binId(arrpoly.bed_idx); @@ -624,7 +616,7 @@ void arrange(ArrangePolygons & arrangables, const BedT & bed, const ArrangeParams & params) { - namespace clppr = ClipperLib; + namespace clppr = Slic3r::ClipperLib; std::vector items, fixeditems; items.reserve(arrangables.size()); @@ -643,8 +635,8 @@ void arrange(ArrangePolygons & arrangables, _arrange(items, fixeditems, to_nestbin(bed), params, pri, cfn); for(size_t i = 0; i < items.size(); ++i) { - clppr::IntPoint tr = items[i].translation(); - arrangables[i].translation = {coord_t(tr.X), coord_t(tr.Y)}; + Point tr = items[i].translation(); + arrangables[i].translation = {coord_t(tr.x()), coord_t(tr.y())}; arrangables[i].rotation = items[i].rotation(); arrangables[i].bed_idx = items[i].binId(); } diff --git a/src/libslic3r/BoundingBox.cpp b/src/libslic3r/BoundingBox.cpp index eb4e042a08..4f52c5108d 100644 --- a/src/libslic3r/BoundingBox.cpp +++ b/src/libslic3r/BoundingBox.cpp @@ -225,24 +225,11 @@ BoundingBox3Base::max_size() const template coordf_t BoundingBox3Base::max_size() const; template coordf_t BoundingBox3Base::max_size() const; -// Align a coordinate to a grid. The coordinate may be negative, -// the aligned value will never be bigger than the original one. -static inline coord_t _align_to_grid(const coord_t coord, const coord_t spacing) { - // Current C++ standard defines the result of integer division to be rounded to zero, - // for both positive and negative numbers. Here we want to round down for negative - // numbers as well. - coord_t aligned = (coord < 0) ? - ((coord - spacing + 1) / spacing) * spacing : - (coord / spacing) * spacing; - assert(aligned <= coord); - return aligned; -} - void BoundingBox::align_to_grid(const coord_t cell_size) { if (this->defined) { - min(0) = _align_to_grid(min(0), cell_size); - min(1) = _align_to_grid(min(1), cell_size); + min(0) = Slic3r::align_to_grid(min(0), cell_size); + min(1) = Slic3r::align_to_grid(min(1), cell_size); } } diff --git a/src/libslic3r/BridgeDetector.cpp b/src/libslic3r/BridgeDetector.cpp index ff33e81d53..cd90a1f03d 100644 --- a/src/libslic3r/BridgeDetector.cpp +++ b/src/libslic3r/BridgeDetector.cpp @@ -40,7 +40,7 @@ void BridgeDetector::initialize() this->angle = -1.; // Outset our bridge by an arbitrary amout; we'll use this outer margin for detecting anchors. - Polygons grown = offset(to_polygons(this->expolygons), float(this->spacing)); + Polygons grown = offset(this->expolygons, float(this->spacing)); // Detect possible anchoring edges of this bridging region. // Detect what edges lie on lower slices by turning bridge contour and holes @@ -227,29 +227,33 @@ void ExPolygon::get_trapezoids(ExPolygon clone, Polygons* polygons, double angle // This algorithm may return more trapezoids than necessary // (i.e. it may break a single trapezoid in several because // other parts of the object have x coordinates in the middle) -static void get_trapezoids2(const ExPolygon &expoly, Polygons* polygons) +static void get_trapezoids2(const ExPolygon& expoly, Polygons* polygons) { Polygons src_polygons = to_polygons(expoly); // get all points of this ExPolygon - const Points pp = to_points(src_polygons); - + const Points pp = to_points(src_polygons); + // build our bounding box BoundingBox bb(pp); - + // get all x coordinates std::vector xx; xx.reserve(pp.size()); for (Points::const_iterator p = pp.begin(); p != pp.end(); ++p) xx.push_back(p->x()); std::sort(xx.begin(), xx.end()); - + // find trapezoids by looping from first to next-to-last coordinate + Polygons rectangle; + rectangle.emplace_back(Polygon()); for (std::vector::const_iterator x = xx.begin(); x != xx.end()-1; ++x) { coord_t next_x = *(x + 1); - if (*x != next_x) + if (*x != next_x) { // intersect with rectangle // append results to return value - polygons_append(*polygons, intersection({ { { *x, bb.min.y() }, { next_x, bb.min.y() }, { next_x, bb.max.y() }, { *x, bb.max.y() } } }, src_polygons)); + rectangle.front() = { { *x, bb.min.y() }, { next_x, bb.min.y() }, { next_x, bb.max.y() }, { *x, bb.max.y() } }; + polygons_append(*polygons, intersection(rectangle, src_polygons)); + } } } @@ -302,7 +306,7 @@ Polygons BridgeDetector::coverage(double angle) const covered = union_(covered); // Intersect trapezoids with actual bridge area to remove extra margins and append it to result. polygons_rotate(covered, -(PI/2.0 - angle)); - covered = intersection(covered, to_polygons(this->expolygons)); + covered = intersection(this->expolygons, covered); #if 0 { my @lines = map @{$_->lines}, @$trapezoids; diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index 08bedc5c04..68851e051e 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -78,7 +78,7 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print) // Assign the maximum Z from four points. This values is valid index of the island clipper.ZFillFunction([](const ClipperLib_Z::IntPoint &e1bot, const ClipperLib_Z::IntPoint &e1top, const ClipperLib_Z::IntPoint &e2bot, const ClipperLib_Z::IntPoint &e2top, ClipperLib_Z::IntPoint &pt) { - pt.Z = std::max(std::max(e1bot.Z, e1top.Z), std::max(e2bot.Z, e2top.Z)); + pt.z() = std::max(std::max(e1bot.z(), e1top.z()), std::max(e2bot.z(), e2top.z())); }); // Add islands clipper.AddPaths(islands_clip, ClipperLib_Z::ptSubject, true); @@ -90,9 +90,9 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print) ConstPrintObjectPtrs top_level_objects_with_brim; for (int i = 0; i < islands_polytree.ChildCount(); ++i) { for (const ClipperLib_Z::IntPoint &point : islands_polytree.Childs[i]->Contour) { - if (point.Z != 0 && processed_objects_idx.find(island_to_object[point.Z - 1]->id().id) == processed_objects_idx.end()) { - top_level_objects_with_brim.emplace_back(island_to_object[point.Z - 1]); - processed_objects_idx.insert(island_to_object[point.Z - 1]->id().id); + if (point.z() != 0 && processed_objects_idx.find(island_to_object[point.z() - 1]->id().id) == processed_objects_idx.end()) { + top_level_objects_with_brim.emplace_back(island_to_object[point.z() - 1]); + processed_objects_idx.insert(island_to_object[point.z() - 1]->id().id); } } } @@ -139,7 +139,7 @@ static ExPolygons top_level_outer_brim_area(const Print &print, const ConstPrint Polygons no_brim_area_object; for (const ExPolygon &ex_poly : object->layers().front()->lslices) { if ((brim_type == BrimType::btOuterOnly || brim_type == BrimType::btOuterAndInner) && is_top_outer_brim) - append(brim_area_object, diff_ex(offset_ex(ex_poly.contour, brim_width + brim_offset), offset_ex(ex_poly.contour, brim_offset))); + append(brim_area_object, diff_ex(offset(ex_poly.contour, brim_width + brim_offset), offset(ex_poly.contour, brim_offset))); if (brim_type == BrimType::btOuterOnly || brim_type == BrimType::btNoBrim) append(no_brim_area_object, offset(ex_poly.holes, -no_brim_offset)); @@ -156,7 +156,7 @@ static ExPolygons top_level_outer_brim_area(const Print &print, const ConstPrint } } - return diff_ex(to_polygons(std::move(brim_area)), no_brim_area); + return diff_ex(brim_area, no_brim_area); } static ExPolygons inner_brim_area(const Print &print, const ConstPrintObjectPtrs &top_level_objects_with_brim, const float no_brim_offset) @@ -183,14 +183,14 @@ static ExPolygons inner_brim_area(const Print &print, const ConstPrintObjectPtrs if (top_outer_brim) no_brim_area_object.emplace_back(ex_poly); else - append(brim_area_object, diff_ex(offset_ex(ex_poly.contour, brim_width + brim_offset), offset_ex(ex_poly.contour, brim_offset))); + append(brim_area_object, diff_ex(offset(ex_poly.contour, brim_width + brim_offset), offset(ex_poly.contour, brim_offset))); } if (brim_type == BrimType::btInnerOnly || brim_type == BrimType::btOuterAndInner) append(brim_area_object, diff_ex(offset_ex(ex_poly.holes, -brim_offset), offset_ex(ex_poly.holes, -brim_width - brim_offset))); if (brim_type == BrimType::btInnerOnly || brim_type == BrimType::btNoBrim) - append(no_brim_area_object, offset_ex(ex_poly.contour, no_brim_offset)); + append(no_brim_area_object, to_expolygons(offset(ex_poly.contour, no_brim_offset))); if (brim_type == BrimType::btOuterOnly || brim_type == BrimType::btNoBrim) append(no_brim_area_object, offset_ex(ex_poly.holes, -no_brim_offset)); @@ -317,7 +317,7 @@ static void make_inner_brim(const Print &print, const ConstPrintObjectPtrs &top_ islands_ex = offset_ex(islands_ex, -float(flow.scaled_spacing()), jtSquare); } - loops = union_pt_chained_outside_in(loops, false); + loops = union_pt_chained_outside_in(loops); std::reverse(loops.begin(), loops.end()); extrusion_entities_append_loops(brim.entities, std::move(loops), erSkirt, float(flow.mm3_per_mm()), float(flow.width()), float(print.skirt_first_layer_height())); @@ -342,7 +342,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance poly.douglas_peucker(SCALED_RESOLUTION); polygons_append(loops, offset(islands, -0.5f * float(flow.scaled_spacing()))); } - loops = union_pt_chained_outside_in(loops, false); + loops = union_pt_chained_outside_in(loops); std::vector loops_pl_by_levels; { @@ -456,7 +456,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance clipper.ZFillFunction([](const ClipperLib_Z::IntPoint& e1bot, const ClipperLib_Z::IntPoint& e1top, const ClipperLib_Z::IntPoint& e2bot, const ClipperLib_Z::IntPoint& e2top, ClipperLib_Z::IntPoint& pt) { // Assign a valid input loop identifier. Such an identifier is strictly positive, the next line is safe even in case one side of a segment // hat the Z coordinate not set to the contour coordinate. - pt.Z = std::max(std::max(e1bot.Z, e1top.Z), std::max(e2bot.Z, e2top.Z)); + pt.z() = std::max(std::max(e1bot.z(), e1top.z()), std::max(e2bot.z(), e2top.z())); }); // add polygons clipper.AddPaths(input_clip, ClipperLib_Z::ptSubject, false); @@ -474,8 +474,8 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance for (const ClipperLib_Z::Path &path : loops_trimmed) { size_t input_idx = 0; for (const ClipperLib_Z::IntPoint &pt : path) - if (pt.Z > 0) { - input_idx = (size_t)pt.Z; + if (pt.z() > 0) { + input_idx = (size_t)pt.z(); break; } assert(input_idx != 0); @@ -492,14 +492,14 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance size_t j = i + 1; for (; j < loops_trimmed_order.size() && loops_trimmed_order[i].second == loops_trimmed_order[j].second; ++ j) ; const ClipperLib_Z::Path &first_path = *loops_trimmed_order[i].first; - if (i + 1 == j && first_path.size() > 3 && first_path.front().X == first_path.back().X && first_path.front().Y == first_path.back().Y) { + if (i + 1 == j && first_path.size() > 3 && first_path.front().x() == first_path.back().x() && first_path.front().y() == first_path.back().y()) { auto *loop = new ExtrusionLoop(); brim.entities.emplace_back(loop); loop->paths.emplace_back(erSkirt, float(flow.mm3_per_mm()), float(flow.width()), float(print.skirt_first_layer_height())); Points &points = loop->paths.front().polyline.points; points.reserve(first_path.size()); for (const ClipperLib_Z::IntPoint &pt : first_path) - points.emplace_back(coord_t(pt.X), coord_t(pt.Y)); + points.emplace_back(coord_t(pt.x()), coord_t(pt.y())); i = j; } else { //FIXME The path chaining here may not be optimal. @@ -511,7 +511,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance Points &points = static_cast(this_loop_trimmed.entities.back())->polyline.points; points.reserve(path.size()); for (const ClipperLib_Z::IntPoint &pt : path) - points.emplace_back(coord_t(pt.X), coord_t(pt.Y)); + points.emplace_back(coord_t(pt.x()), coord_t(pt.y())); } chain_and_reorder_extrusion_entities(this_loop_trimmed.entities, &last_pt); brim.entities.reserve(brim.entities.size() + this_loop_trimmed.entities.size()); diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 4a762f7e15..16299f442d 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -23,6 +23,8 @@ add_library(libslic3r STATIC BridgeDetector.hpp Brim.cpp Brim.hpp + clipper.cpp + clipper.hpp ClipperUtils.cpp ClipperUtils.hpp Config.cpp @@ -219,6 +221,9 @@ add_library(libslic3r STATIC SimplifyMeshImpl.hpp SimplifyMesh.cpp MarchingSquares.hpp + Execution/Execution.hpp + Execution/ExecutionSeq.hpp + Execution/ExecutionTBB.hpp Optimize/Optimizer.hpp Optimize/NLoptOptimizer.hpp Optimize/BruteforceOptimizer.hpp diff --git a/src/libslic3r/ClipperUtils.cpp b/src/libslic3r/ClipperUtils.cpp index 305ea134f0..8bca3b25a3 100644 --- a/src/libslic3r/ClipperUtils.cpp +++ b/src/libslic3r/ClipperUtils.cpp @@ -24,7 +24,6 @@ namespace Slic3r { #ifdef CLIPPER_UTILS_DEBUG -bool clipper_export_enabled = false; // For debugging the Clipper library, for providing bug reports to the Clipper author. bool export_clipper_input_polygons_bin(const char *path, const ClipperLib::Paths &input_subject, const ClipperLib::Paths &input_clip) { @@ -57,377 +56,265 @@ err: } #endif /* CLIPPER_UTILS_DEBUG */ -void scaleClipperPolygon(ClipperLib::Path &polygon) -{ - CLIPPERUTILS_PROFILE_FUNC(); - for (ClipperLib::Path::iterator pit = polygon.begin(); pit != polygon.end(); ++pit) { - pit->X <<= CLIPPER_OFFSET_POWER_OF_2; - pit->Y <<= CLIPPER_OFFSET_POWER_OF_2; - } +namespace ClipperUtils { + Points EmptyPathsProvider::s_empty_points; + Points SinglePathProvider::s_end; } -void scaleClipperPolygons(ClipperLib::Paths &polygons) +static ExPolygons PolyTreeToExPolygons(ClipperLib::PolyTree &&polytree) { - CLIPPERUTILS_PROFILE_FUNC(); - for (ClipperLib::Paths::iterator it = polygons.begin(); it != polygons.end(); ++it) - for (ClipperLib::Path::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) { - pit->X <<= CLIPPER_OFFSET_POWER_OF_2; - pit->Y <<= CLIPPER_OFFSET_POWER_OF_2; + struct Inner { + static void PolyTreeToExPolygonsRecursive(ClipperLib::PolyNode &&polynode, ExPolygons *expolygons) + { + size_t cnt = expolygons->size(); + expolygons->resize(cnt + 1); + (*expolygons)[cnt].contour.points = std::move(polynode.Contour); + (*expolygons)[cnt].holes.resize(polynode.ChildCount()); + for (int i = 0; i < polynode.ChildCount(); ++ i) { + (*expolygons)[cnt].holes[i].points = std::move(polynode.Childs[i]->Contour); + // Add outer polygons contained by (nested within) holes. + for (int j = 0; j < polynode.Childs[i]->ChildCount(); ++ j) + PolyTreeToExPolygonsRecursive(std::move(*polynode.Childs[i]->Childs[j]), expolygons); + } } -} -void unscaleClipperPolygon(ClipperLib::Path &polygon) -{ - CLIPPERUTILS_PROFILE_FUNC(); - for (ClipperLib::Path::iterator pit = polygon.begin(); pit != polygon.end(); ++pit) { - pit->X += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; - pit->Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; - pit->X >>= CLIPPER_OFFSET_POWER_OF_2; - pit->Y >>= CLIPPER_OFFSET_POWER_OF_2; - } -} - -void unscaleClipperPolygons(ClipperLib::Paths &polygons) -{ - CLIPPERUTILS_PROFILE_FUNC(); - for (ClipperLib::Paths::iterator it = polygons.begin(); it != polygons.end(); ++it) - for (ClipperLib::Path::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) { - pit->X += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; - pit->Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; - pit->X >>= CLIPPER_OFFSET_POWER_OF_2; - pit->Y >>= CLIPPER_OFFSET_POWER_OF_2; + static size_t PolyTreeCountExPolygons(const ClipperLib::PolyNode &polynode) + { + size_t cnt = 1; + for (int i = 0; i < polynode.ChildCount(); ++ i) { + for (int j = 0; j < polynode.Childs[i]->ChildCount(); ++ j) + cnt += PolyTreeCountExPolygons(*polynode.Childs[i]->Childs[j]); + } + return cnt; } -} + }; -//----------------------------------------------------------- -// legacy code from Clipper documentation -void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, ExPolygons* expolygons) -{ - size_t cnt = expolygons->size(); - expolygons->resize(cnt + 1); - (*expolygons)[cnt].contour = ClipperPath_to_Slic3rPolygon(polynode.Contour); - (*expolygons)[cnt].holes.resize(polynode.ChildCount()); - for (int i = 0; i < polynode.ChildCount(); ++i) - { - (*expolygons)[cnt].holes[i] = ClipperPath_to_Slic3rPolygon(polynode.Childs[i]->Contour); - //Add outer polygons contained by (nested within) holes ... - for (int j = 0; j < polynode.Childs[i]->ChildCount(); ++j) - AddOuterPolyNodeToExPolygons(*polynode.Childs[i]->Childs[j], expolygons); - } -} - -ExPolygons PolyTreeToExPolygons(ClipperLib::PolyTree& polytree) -{ ExPolygons retval; - for (int i = 0; i < polytree.ChildCount(); ++i) - AddOuterPolyNodeToExPolygons(*polytree.Childs[i], &retval); - return retval; -} -//----------------------------------------------------------- - -Slic3r::Polygon ClipperPath_to_Slic3rPolygon(const ClipperLib::Path &input) -{ - Polygon retval; - for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit) - retval.points.emplace_back(pit->X, pit->Y); + size_t cnt = 0; + for (int i = 0; i < polytree.ChildCount(); ++ i) + cnt += Inner::PolyTreeCountExPolygons(*polytree.Childs[i]); + retval.reserve(cnt); + for (int i = 0; i < polytree.ChildCount(); ++ i) + Inner::PolyTreeToExPolygonsRecursive(std::move(*polytree.Childs[i]), &retval); return retval; } -Slic3r::Polyline ClipperPath_to_Slic3rPolyline(const ClipperLib::Path &input) +Polylines PolyTreeToPolylines(ClipperLib::PolyTree &&polytree) { - Polyline retval; - for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit) - retval.points.emplace_back(pit->X, pit->Y); - return retval; -} + struct Inner { + static void AddPolyNodeToPaths(ClipperLib::PolyNode &polynode, Polylines &out) + { + if (! polynode.Contour.empty()) + out.emplace_back(std::move(polynode.Contour)); + for (ClipperLib::PolyNode *child : polynode.Childs) + AddPolyNodeToPaths(*child, out); + } + }; -Slic3r::Polygons ClipperPaths_to_Slic3rPolygons(const ClipperLib::Paths &input) -{ - Slic3r::Polygons retval; - retval.reserve(input.size()); - for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it) - retval.emplace_back(ClipperPath_to_Slic3rPolygon(*it)); - return retval; -} - -Slic3r::Polylines ClipperPaths_to_Slic3rPolylines(const ClipperLib::Paths &input) -{ - Slic3r::Polylines retval; - retval.reserve(input.size()); - for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it) - retval.emplace_back(ClipperPath_to_Slic3rPolyline(*it)); - return retval; + Polylines out; + out.reserve(polytree.Total()); + Inner::AddPolyNodeToPaths(polytree, out); + return out; } ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input) { - // init Clipper ClipperLib::Clipper clipper; - clipper.Clear(); - - // perform union clipper.AddPaths(input, ClipperLib::ptSubject, true); ClipperLib::PolyTree polytree; clipper.Execute(ClipperLib::ctUnion, polytree, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd); // offset results work with both EvenOdd and NonZero - - // write to ExPolygons object - return PolyTreeToExPolygons(polytree); + return PolyTreeToExPolygons(std::move(polytree)); } -ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const MultiPoint &input) +// Offset outside by 10um, one by one. +template +static ClipperLib::Paths safety_offset(PathsProvider &&paths) { - ClipperLib::Path retval; - for (Points::const_iterator pit = input.points.begin(); pit != input.points.end(); ++pit) - retval.emplace_back((*pit)(0), (*pit)(1)); - return retval; -} - -ClipperLib::Path Slic3rMultiPoint_to_ClipperPath_reversed(const Slic3r::MultiPoint &input) -{ - ClipperLib::Path output; - output.reserve(input.points.size()); - for (Slic3r::Points::const_reverse_iterator pit = input.points.rbegin(); pit != input.points.rend(); ++pit) - output.emplace_back((*pit)(0), (*pit)(1)); - return output; -} - -ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input) -{ - ClipperLib::Paths retval; - for (Polygons::const_iterator it = input.begin(); it != input.end(); ++it) - retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(*it)); - return retval; -} - -ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const ExPolygons &input) -{ - ClipperLib::Paths retval; - for (auto &ep : input) { - retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(ep.contour)); - - for (auto &h : ep.holes) - retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(h)); + ClipperLib::ClipperOffset co; + ClipperLib::Paths out; + out.reserve(paths.size()); + ClipperLib::Paths out_this; + for (const ClipperLib::Path &path : paths) { + co.Clear(); + co.MiterLimit = 2.; + co.AddPath(path, ClipperLib::jtMiter, ClipperLib::etClosedPolygon); + co.Execute(out_this, ClipperSafetyOffset); + append(out, std::move(out_this)); } - - return retval; + return out; } -ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input) +template +ClipperLib::Paths _offset(PathsProvider &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit) { - ClipperLib::Paths retval; - for (Polylines::const_iterator it = input.begin(); it != input.end(); ++it) - retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(*it)); - return retval; -} - -ClipperLib::Paths _offset(ClipperLib::Paths &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit) -{ - // scale input - scaleClipperPolygons(input); - // perform offset ClipperLib::ClipperOffset co; if (joinType == jtRound) co.ArcTolerance = miterLimit; else co.MiterLimit = miterLimit; - float delta_scaled = delta * float(CLIPPER_OFFSET_SCALE); + float delta_scaled = delta; co.ShortestEdgeLength = double(std::abs(delta_scaled * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - co.AddPaths(input, joinType, endType); + co.AddPaths(std::forward(input), joinType, endType); ClipperLib::Paths retval; co.Execute(retval, delta_scaled); - - // unscale output - unscaleClipperPolygons(retval); return retval; } -ClipperLib::Paths _offset(ClipperLib::Path &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit) -{ - ClipperLib::Paths paths; - paths.emplace_back(std::move(input)); - return _offset(std::move(paths), endType, delta, joinType, miterLimit); -} +Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(ClipperUtils::SinglePathProvider(polygon.points), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } -// This is a safe variant of the polygon offset, tailored for a single ExPolygon: -// a single polygon with multiple non-overlapping holes. -// Each contour and hole is offsetted separately, then the holes are subtracted from the outer contours. -ClipperLib::Paths _offset(const Slic3r::ExPolygon &expolygon, const float delta, - ClipperLib::JoinType joinType, double miterLimit) +#ifdef CLIPPERUTILS_UNSAFE_OFFSET +Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(ClipperUtils::PolygonsProvider(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } +#endif // CLIPPERUTILS_UNSAFE_OFFSET + +Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(ClipperUtils::SinglePathProvider(polyline.points), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(ClipperUtils::PolylinesProvider(polylines), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } + +#ifdef CLIPPERUTILS_UNSAFE_OFFSET +Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return ClipperPaths_to_Slic3rExPolygons(_offset(ClipperUtils::PolygonsProvider(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } +#endif // CLIPPERUTILS_UNSAFE_OFFSET + +// returns number of expolygons collected (0 or 1). +static int offset_expolygon_inner(const Slic3r::ExPolygon &expoly, const float delta, ClipperLib::JoinType joinType, double miterLimit, ClipperLib::Paths &out) { -// printf("new ExPolygon offset\n"); // 1) Offset the outer contour. - const float delta_scaled = delta * float(CLIPPER_OFFSET_SCALE); ClipperLib::Paths contours; { - ClipperLib::Path input = Slic3rMultiPoint_to_ClipperPath(expolygon.contour); - scaleClipperPolygon(input); ClipperLib::ClipperOffset co; if (joinType == jtRound) - co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE); + co.ArcTolerance = miterLimit; else co.MiterLimit = miterLimit; - co.ShortestEdgeLength = double(std::abs(delta_scaled * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - co.AddPath(input, joinType, ClipperLib::etClosedPolygon); - co.Execute(contours, delta_scaled); + co.ShortestEdgeLength = double(std::abs(delta * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); + co.AddPath(expoly.contour.points, joinType, ClipperLib::etClosedPolygon); + co.Execute(contours, delta); } + if (contours.empty()) + // No need to try to offset the holes. + return 0; - // 2) Offset the holes one by one, collect the results. - ClipperLib::Paths holes; - { - holes.reserve(expolygon.holes.size()); - for (Polygons::const_iterator it_hole = expolygon.holes.begin(); it_hole != expolygon.holes.end(); ++ it_hole) { - ClipperLib::Path input = Slic3rMultiPoint_to_ClipperPath_reversed(*it_hole); - scaleClipperPolygon(input); - ClipperLib::ClipperOffset co; - if (joinType == jtRound) - co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE); - else - co.MiterLimit = miterLimit; - co.ShortestEdgeLength = double(std::abs(delta_scaled * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - co.AddPath(input, joinType, ClipperLib::etClosedPolygon); - ClipperLib::Paths out; - co.Execute(out, - delta_scaled); - holes.insert(holes.end(), out.begin(), out.end()); + if (expoly.holes.empty()) { + // No need to subtract holes from the offsetted expolygon, we are done. + append(out, std::move(contours)); + } else { + // 2) Offset the holes one by one, collect the offsetted holes. + ClipperLib::Paths holes; + { + for (const Polygon &hole : expoly.holes) { + ClipperLib::ClipperOffset co; + if (joinType == jtRound) + co.ArcTolerance = miterLimit; + else + co.MiterLimit = miterLimit; + co.ShortestEdgeLength = double(std::abs(delta * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); + co.AddPath(hole.points, joinType, ClipperLib::etClosedPolygon); + ClipperLib::Paths out2; + // Execute reorients the contours so that the outer most contour has a positive area. Thus the output + // contours will be CCW oriented even though the input paths are CW oriented. + // Offset is applied after contour reorientation, thus the signum of the offset value is reversed. + co.Execute(out2, - delta); + append(holes, std::move(out2)); + } + } + + // 3) Subtract holes from the contours. + if (holes.empty()) { + // No hole remaining after an offset. Just copy the outer contour. + append(out, std::move(contours)); + } else if (delta < 0) { + // Negative offset. There is a chance, that the offsetted hole intersects the outer contour. + // Subtract the offsetted holes from the offsetted contours. + ClipperLib::Clipper clipper; + clipper.Clear(); + clipper.AddPaths(contours, ClipperLib::ptSubject, true); + clipper.AddPaths(holes, ClipperLib::ptClip, true); + ClipperLib::Paths output; + clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); + if (! output.empty()) { + append(out, std::move(output)); + } else { + // The offsetted holes have eaten up the offsetted outer contour. + return 0; + } + } else { + // Positive offset. As long as the Clipper offset does what one expects it to do, the offsetted hole will have a smaller + // area than the original hole or even disappear, therefore there will be no new intersections. + // Just collect the reversed holes. + out.reserve(contours.size() + holes.size()); + append(out, std::move(contours)); + // Reverse the holes in place. + for (size_t i = 0; i < holes.size(); ++ i) + std::reverse(holes[i].begin(), holes[i].end()); + append(out, std::move(holes)); } } - // 3) Subtract holes from the contours. - ClipperLib::Paths output; - if (holes.empty()) { - output = std::move(contours); - } else { - ClipperLib::Clipper clipper; - clipper.Clear(); - clipper.AddPaths(contours, ClipperLib::ptSubject, true); - clipper.AddPaths(holes, ClipperLib::ptClip, true); - clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); - } - - // 4) Unscale the output. - unscaleClipperPolygons(output); - return output; + return 1; +} + +static int offset_expolygon_inner(const Slic3r::Surface &surface, const float delta, ClipperLib::JoinType joinType, double miterLimit, ClipperLib::Paths &out) + { return offset_expolygon_inner(surface.expolygon, delta, joinType, miterLimit, out); } +static int offset_expolygon_inner(const Slic3r::Surface *surface, const float delta, ClipperLib::JoinType joinType, double miterLimit, ClipperLib::Paths &out) + { return offset_expolygon_inner(surface->expolygon, delta, joinType, miterLimit, out); } + +ClipperLib::Paths _offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit) +{ + ClipperLib::Paths out; + offset_expolygon_inner(expolygon, delta, joinType, miterLimit, out); + return out; } // This is a safe variant of the polygons offset, tailored for multiple ExPolygons. // It is required, that the input expolygons do not overlap and that the holes of each ExPolygon don't intersect with their respective outer contours. // Each ExPolygon is offsetted separately, then the offsetted ExPolygons are united. -ClipperLib::Paths _offset(const Slic3r::ExPolygons &expolygons, const float delta, - ClipperLib::JoinType joinType, double miterLimit) +template +ClipperLib::Paths _offset(const ExPolygonVector &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit) { - const float delta_scaled = delta * float(CLIPPER_OFFSET_SCALE); // Offsetted ExPolygons before they are united. - ClipperLib::Paths contours_cummulative; - contours_cummulative.reserve(expolygons.size()); - // How many non-empty offsetted expolygons were actually collected into contours_cummulative? + ClipperLib::Paths output; + output.reserve(expolygons.size()); + // How many non-empty offsetted expolygons were actually collected into output? // If only one, then there is no need to do a final union. size_t expolygons_collected = 0; - for (Slic3r::ExPolygons::const_iterator it_expoly = expolygons.begin(); it_expoly != expolygons.end(); ++ it_expoly) { - // 1) Offset the outer contour. - ClipperLib::Paths contours; - { - ClipperLib::Path input = Slic3rMultiPoint_to_ClipperPath(it_expoly->contour); - scaleClipperPolygon(input); - ClipperLib::ClipperOffset co; - if (joinType == jtRound) - co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE); - else - co.MiterLimit = miterLimit; - co.ShortestEdgeLength = double(std::abs(delta_scaled * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - co.AddPath(input, joinType, ClipperLib::etClosedPolygon); - co.Execute(contours, delta_scaled); - } - if (contours.empty()) - // No need to try to offset the holes. - continue; - - if (it_expoly->holes.empty()) { - // No need to subtract holes from the offsetted expolygon, we are done. - contours_cummulative.insert(contours_cummulative.end(), contours.begin(), contours.end()); - ++ expolygons_collected; - } else { - // 2) Offset the holes one by one, collect the offsetted holes. - ClipperLib::Paths holes; - { - for (Polygons::const_iterator it_hole = it_expoly->holes.begin(); it_hole != it_expoly->holes.end(); ++ it_hole) { - ClipperLib::Path input = Slic3rMultiPoint_to_ClipperPath_reversed(*it_hole); - scaleClipperPolygon(input); - ClipperLib::ClipperOffset co; - if (joinType == jtRound) - co.ArcTolerance = miterLimit * double(CLIPPER_OFFSET_SCALE); - else - co.MiterLimit = miterLimit; - co.ShortestEdgeLength = double(std::abs(delta_scaled * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - co.AddPath(input, joinType, ClipperLib::etClosedPolygon); - ClipperLib::Paths out; - co.Execute(out, - delta_scaled); - holes.insert(holes.end(), out.begin(), out.end()); - } - } - - // 3) Subtract holes from the contours. - if (holes.empty()) { - // No hole remaining after an offset. Just copy the outer contour. - contours_cummulative.insert(contours_cummulative.end(), contours.begin(), contours.end()); - ++ expolygons_collected; - } else if (delta < 0) { - // Negative offset. There is a chance, that the offsetted hole intersects the outer contour. - // Subtract the offsetted holes from the offsetted contours. - ClipperLib::Clipper clipper; - clipper.Clear(); - clipper.AddPaths(contours, ClipperLib::ptSubject, true); - clipper.AddPaths(holes, ClipperLib::ptClip, true); - ClipperLib::Paths output; - clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); - if (! output.empty()) { - contours_cummulative.insert(contours_cummulative.end(), output.begin(), output.end()); - ++ expolygons_collected; - } else { - // The offsetted holes have eaten up the offsetted outer contour. - } - } else { - // Positive offset. As long as the Clipper offset does what one expects it to do, the offsetted hole will have a smaller - // area than the original hole or even disappear, therefore there will be no new intersections. - // Just collect the reversed holes. - contours_cummulative.reserve(contours.size() + holes.size()); - contours_cummulative.insert(contours_cummulative.end(), contours.begin(), contours.end()); - // Reverse the holes in place. - for (size_t i = 0; i < holes.size(); ++ i) - std::reverse(holes[i].begin(), holes[i].end()); - contours_cummulative.insert(contours_cummulative.end(), holes.begin(), holes.end()); - ++ expolygons_collected; - } - } - } + for (const auto &expoly : expolygons) + expolygons_collected += offset_expolygon_inner(expoly, delta, joinType, miterLimit, output); // 4) Unite the offsetted expolygons. - ClipperLib::Paths output; if (expolygons_collected > 1 && delta > 0) { // There is a chance that the outwards offsetted expolygons may intersect. Perform a union. ClipperLib::Clipper clipper; clipper.Clear(); - clipper.AddPaths(contours_cummulative, ClipperLib::ptSubject, true); + clipper.AddPaths(output, ClipperLib::ptSubject, true); clipper.Execute(ClipperLib::ctUnion, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); } else { // Negative offset. The shrunk expolygons shall not mutually intersect. Just copy the output. - output = std::move(contours_cummulative); } - // 4) Unscale the output. - unscaleClipperPolygons(output); return output; } -ClipperLib::Paths -_offset2(const Polygons &polygons, const float delta1, const float delta2, - const ClipperLib::JoinType joinType, const double miterLimit) +Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(expolygon, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(expolygons, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(surfaces, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::SurfacesPtr &surfaces, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return to_polygons(_offset(surfaces, delta, joinType, miterLimit)); } +Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return ClipperPaths_to_Slic3rExPolygons(_offset(expolygon, delta, joinType, miterLimit)); } +Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return ClipperPaths_to_Slic3rExPolygons(_offset(expolygons, delta, joinType, miterLimit)); } +Slic3r::ExPolygons offset_ex(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType, double miterLimit) + { return ClipperPaths_to_Slic3rExPolygons(_offset(surfaces, delta, joinType, miterLimit)); } + +ClipperLib::Paths _offset2(const Polygons &polygons, const float delta1, const float delta2, const ClipperLib::JoinType joinType, const double miterLimit) { - // read input - ClipperLib::Paths input = Slic3rMultiPoints_to_ClipperPaths(polygons); - - // scale input - scaleClipperPolygons(input); - // prepare ClipperOffset object ClipperLib::ClipperOffset co; if (joinType == jtRound) { @@ -435,13 +322,13 @@ _offset2(const Polygons &polygons, const float delta1, const float delta2, } else { co.MiterLimit = miterLimit; } - float delta_scaled1 = delta1 * float(CLIPPER_OFFSET_SCALE); - float delta_scaled2 = delta2 * float(CLIPPER_OFFSET_SCALE); + float delta_scaled1 = delta1; + float delta_scaled2 = delta2; co.ShortestEdgeLength = double(std::max(std::abs(delta_scaled1), std::abs(delta_scaled2)) * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR); // perform first offset ClipperLib::Paths output1; - co.AddPaths(input, joinType, ClipperLib::etClosedPolygon); + co.AddPaths(ClipperUtils::PolygonsProvider(polygons), joinType, ClipperLib::etClosedPolygon); co.Execute(output1, delta_scaled1); // perform second offset @@ -450,104 +337,81 @@ _offset2(const Polygons &polygons, const float delta1, const float delta2, ClipperLib::Paths retval; co.Execute(retval, delta_scaled2); - // unscale output - unscaleClipperPolygons(retval); return retval; } -Polygons -offset2(const Polygons &polygons, const float delta1, const float delta2, - const ClipperLib::JoinType joinType, const double miterLimit) +Polygons offset2(const Polygons &polygons, const float delta1, const float delta2, const ClipperLib::JoinType joinType, const double miterLimit) { - // perform offset - ClipperLib::Paths output = _offset2(polygons, delta1, delta2, joinType, miterLimit); - - // convert into ExPolygons - return ClipperPaths_to_Slic3rPolygons(output); + return to_polygons(_offset2(polygons, delta1, delta2, joinType, miterLimit)); } -ExPolygons -offset2_ex(const Polygons &polygons, const float delta1, const float delta2, - const ClipperLib::JoinType joinType, const double miterLimit) +ExPolygons offset2_ex(const Polygons &polygons, const float delta1, const float delta2, const ClipperLib::JoinType joinType, const double miterLimit) { - // perform offset - ClipperLib::Paths output = _offset2(polygons, delta1, delta2, joinType, miterLimit); - - // convert into ExPolygons - return ClipperPaths_to_Slic3rExPolygons(output); + return ClipperPaths_to_Slic3rExPolygons(_offset2(polygons, delta1, delta2, joinType, miterLimit)); } //FIXME Vojtech: This functon may likely be optimized to avoid some of the Slic3r to Clipper -// conversions and unnecessary Clipper calls. -ExPolygons offset2_ex(const ExPolygons &expolygons, const float delta1, - const float delta2, ClipperLib::JoinType joinType, double miterLimit) +// conversions and unnecessary Clipper calls. It is not that bad now as Clipper uses Slic3r's own Point / Polygon types directly. +Polygons offset2(const ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType, double miterLimit) { - Polygons polys; - for (const ExPolygon &expoly : expolygons) - append(polys, - offset(offset_ex(expoly, delta1, joinType, miterLimit), - delta2, joinType, miterLimit)); - return union_ex(polys); + return offset(offset_ex(expolygons, delta1, joinType, miterLimit), delta2, joinType, miterLimit); +} +ExPolygons offset2_ex(const ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType, double miterLimit) +{ + return offset_ex(offset_ex(expolygons, delta1, joinType, miterLimit), delta2, joinType, miterLimit); } -template -T _clipper_do(const ClipperLib::ClipType clipType, - TSubj && subject, - TClip && clip, - const ClipperLib::PolyFillType fillType, - const bool safety_offset_) +template +TResult _clipper_do( + const ClipperLib::ClipType clipType, + TSubj && subject, + TClip && clip, + const ClipperLib::PolyFillType fillType) { - // read input - ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(std::forward(subject)); - ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(std::forward(clip)); - - // perform safety offset - if (safety_offset_) { - if (clipType == ClipperLib::ctUnion) { - safety_offset(&input_subject); - } else { - safety_offset(&input_clip); - } - } - - // init Clipper ClipperLib::Clipper clipper; - clipper.Clear(); - - // add polygons - clipper.AddPaths(input_subject, ClipperLib::ptSubject, true); - clipper.AddPaths(input_clip, ClipperLib::ptClip, true); - - // perform operation - T retval; + clipper.AddPaths(std::forward(subject), ClipperLib::ptSubject, true); + clipper.AddPaths(std::forward(clip), ClipperLib::ptClip, true); + TResult retval; clipper.Execute(clipType, retval, fillType, fillType); return retval; } +template +TResult _clipper_do( + const ClipperLib::ClipType clipType, + TSubj && subject, + TClip && clip, + const ClipperLib::PolyFillType fillType, + const bool do_safety_offset) +{ + return do_safety_offset ? + (clipType == ClipperLib::ctUnion ? + _clipper_do(clipType, safety_offset(std::forward(subject)), std::forward(clip), fillType) : + _clipper_do(clipType, std::forward(subject), safety_offset(std::forward(clip)), fillType)) : + _clipper_do(clipType, std::forward(subject), std::forward(clip), fillType); +} + // Fix of #117: A large fractal pyramid takes ages to slice // The Clipper library has difficulties processing overlapping polygons. // Namely, the function ClipperLib::JoinCommonEdges() has potentially a terrible time complexity if the output // of the operation is of the PolyTree type. -// This function implmenets a following workaround: +// This function implemenets a following workaround: // 1) Peform the Clipper operation with the output to Paths. This method handles overlaps in a reasonable time. // 2) Run Clipper Union once again to extract the PolyTree from the result of 1). -inline ClipperLib::PolyTree _clipper_do_polytree2(const ClipperLib::ClipType clipType, const Polygons &subject, - const Polygons &clip, const ClipperLib::PolyFillType fillType, const bool safety_offset_) +template +inline ClipperLib::PolyTree _clipper_do_polytree2( + const ClipperLib::ClipType clipType, + PathProvider1 &&subject, + PathProvider2 &&clip, + const ClipperLib::PolyFillType fillType) { - // read input - ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); - ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(clip); - - // perform safety offset - if (safety_offset_) - safety_offset((clipType == ClipperLib::ctUnion) ? &input_subject : &input_clip); - ClipperLib::Clipper clipper; - clipper.AddPaths(input_subject, ClipperLib::ptSubject, true); - clipper.AddPaths(input_clip, ClipperLib::ptClip, true); + clipper.AddPaths(std::forward(subject), ClipperLib::ptSubject, true); + clipper.AddPaths(std::forward(clip), ClipperLib::ptClip, true); // Perform the operation with the output to input_subject. // This pass does not generate a PolyTree, which is a very expensive operation with the current Clipper library // if there are overapping edges. + ClipperLib::Paths input_subject; clipper.Execute(clipType, input_subject, fillType, fillType); // Perform an additional Union operation to generate the PolyTree ordering. clipper.Clear(); @@ -556,101 +420,192 @@ inline ClipperLib::PolyTree _clipper_do_polytree2(const ClipperLib::ClipType cli clipper.Execute(ClipperLib::ctUnion, retval, fillType, fillType); return retval; } - -ClipperLib::PolyTree _clipper_do_pl(const ClipperLib::ClipType clipType, const Polylines &subject, - const Polygons &clip, const ClipperLib::PolyFillType fillType, - const bool safety_offset_) +template +inline ClipperLib::PolyTree _clipper_do_polytree2( + const ClipperLib::ClipType clipType, + PathProvider1 &&subject, + PathProvider2 &&clip, + const ClipperLib::PolyFillType fillType, + const bool do_safety_offset) +{ + return do_safety_offset ? + (clipType == ClipperLib::ctUnion ? + _clipper_do_polytree2(clipType, safety_offset(std::forward(subject)), std::forward(clip), fillType) : + _clipper_do_polytree2(clipType, std::forward(subject), safety_offset(std::forward(clip)), fillType)) : + _clipper_do_polytree2(clipType, std::forward(subject), std::forward(clip), fillType); +} + +template +static inline Polygons _clipper(ClipperLib::ClipType clipType, TSubj &&subject, TClip &&clip, bool do_safety_offset) +{ + return to_polygons(_clipper_do(clipType, std::forward(subject), std::forward(clip), ClipperLib::pftNonZero, do_safety_offset)); +} + +Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctDifference, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctDifference, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctDifference, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::ExPolygon &subject, const Slic3r::ExPolygon &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::ExPolygonProvider(subject), ClipperUtils::ExPolygonProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::SurfacesProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper(ClipperLib::ctIntersection, ClipperUtils::SurfacesProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::Polygons union_(const Slic3r::Polygons &subject, bool do_safety_offset) + { return _clipper(ClipperLib::ctUnion, ClipperUtils::PolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), do_safety_offset); } +Slic3r::Polygons union_(const Slic3r::ExPolygons &subject, bool do_safety_offset) + { return _clipper(ClipperLib::ctUnion, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), do_safety_offset); } +Slic3r::Polygons union_(const Slic3r::Polygons &subject, const Slic3r::Polygons &subject2, bool do_safety_offset) + { return _clipper(ClipperLib::ctUnion, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(subject2), do_safety_offset); } + +template +static ExPolygons _clipper_ex(ClipperLib::ClipType clipType, TSubject &&subject, TClip &&clip, bool do_safety_offset) + { return PolyTreeToExPolygons(_clipper_do_polytree2(clipType, std::forward(subject), std::forward(clip), ClipperLib::pftNonZero, do_safety_offset)); } + +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Surfaces &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::PolygonsProvider(subject), ClipperUtils::SurfacesProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::PolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::ExPolygonProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::SurfacesProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::SurfacesProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Surfaces &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::SurfacesProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::SurfacesProvider(subject), ClipperUtils::SurfacesProvider(clip), do_safety_offset); } +Slic3r::ExPolygons diff_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctDifference, ClipperUtils::SurfacesPtrProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } + +Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::ExPolygonProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::PolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::SurfacesProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::SurfacesProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::SurfacesProvider(subject), ClipperUtils::SurfacesProvider(clip), do_safety_offset); } +Slic3r::ExPolygons intersection_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctIntersection, ClipperUtils::SurfacesPtrProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, bool do_safety_offset) + { return _clipper_ex(ClipperLib::ctUnion, ClipperUtils::PolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), do_safety_offset); } +Slic3r::ExPolygons union_ex(const Slic3r::ExPolygons& subject) + { return PolyTreeToExPolygons(_clipper_do_polytree2(ClipperLib::ctUnion, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), ClipperLib::pftNonZero)); } +Slic3r::ExPolygons union_ex(const Slic3r::Surfaces& subject) + { return PolyTreeToExPolygons(_clipper_do_polytree2(ClipperLib::ctUnion, ClipperUtils::SurfacesProvider(subject), ClipperUtils::EmptyPathsProvider(), ClipperLib::pftNonZero)); } + +template +Polylines _clipper_pl_open(ClipperLib::ClipType clipType, PathsProvider1 &&subject, PathsProvider2 &&clip, bool do_safety_offset) { - // read input - ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); - ClipperLib::Paths input_clip = Slic3rMultiPoints_to_ClipperPaths(clip); - - // perform safety offset - if (safety_offset_) safety_offset(&input_clip); - - // init Clipper ClipperLib::Clipper clipper; - clipper.Clear(); - - // add polygons - clipper.AddPaths(input_subject, ClipperLib::ptSubject, false); - clipper.AddPaths(input_clip, ClipperLib::ptClip, true); - - // perform operation + clipper.AddPaths(std::forward(subject), ClipperLib::ptSubject, false); + if (do_safety_offset) + clipper.AddPaths(safety_offset(std::forward(clip)), ClipperLib::ptClip, true); + else + clipper.AddPaths(std::forward(clip), ClipperLib::ptClip, true); ClipperLib::PolyTree retval; - clipper.Execute(clipType, retval, fillType, fillType); - return retval; + clipper.Execute(clipType, retval, ClipperLib::pftNonZero, ClipperLib::pftNonZero); + return PolyTreeToPolylines(std::move(retval)); } -Polygons _clipper(ClipperLib::ClipType clipType, const Polygons &subject, const Polygons &clip, bool safety_offset_) +// If the split_at_first_point() call above happens to split the polygon inside the clipping area +// we would get two consecutive polylines instead of a single one, so we go through them in order +// to recombine continuous polylines. +static void _clipper_pl_recombine(Polylines &polylines) { - return ClipperPaths_to_Slic3rPolygons(_clipper_do(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_)); -} - -ExPolygons _clipper_ex(ClipperLib::ClipType clipType, const Polygons &subject, const Polygons &clip, bool safety_offset_) -{ - ClipperLib::PolyTree polytree = _clipper_do_polytree2(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_); - return PolyTreeToExPolygons(polytree); -} - -Polylines _clipper_pl(ClipperLib::ClipType clipType, const Polylines &subject, const Polygons &clip, bool safety_offset_) -{ - ClipperLib::Paths output; - ClipperLib::PolyTreeToPaths(_clipper_do_pl(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_), output); - return ClipperPaths_to_Slic3rPolylines(output); -} - -Polylines _clipper_pl(ClipperLib::ClipType clipType, const Polygons &subject, const Polygons &clip, bool safety_offset_) -{ - // transform input polygons into polylines - Polylines polylines; - polylines.reserve(subject.size()); - for (Polygons::const_iterator polygon = subject.begin(); polygon != subject.end(); ++polygon) - polylines.emplace_back(polygon->operator Polyline()); // implicit call to split_at_first_point() - - // perform clipping - Polylines retval = _clipper_pl(clipType, polylines, clip, safety_offset_); - - /* If the split_at_first_point() call above happens to split the polygon inside the clipping area - we would get two consecutive polylines instead of a single one, so we go through them in order - to recombine continuous polylines. */ - for (size_t i = 0; i < retval.size(); ++i) { - for (size_t j = i+1; j < retval.size(); ++j) { - if (retval[i].points.back() == retval[j].points.front()) { + for (size_t i = 0; i < polylines.size(); ++i) { + for (size_t j = i+1; j < polylines.size(); ++j) { + if (polylines[i].points.back() == polylines[j].points.front()) { /* If last point of i coincides with first point of j, append points of j to i and delete j */ - retval[i].points.insert(retval[i].points.end(), retval[j].points.begin()+1, retval[j].points.end()); - retval.erase(retval.begin() + j); + polylines[i].points.insert(polylines[i].points.end(), polylines[j].points.begin()+1, polylines[j].points.end()); + polylines.erase(polylines.begin() + j); --j; - } else if (retval[i].points.front() == retval[j].points.back()) { + } else if (polylines[i].points.front() == polylines[j].points.back()) { /* If first point of i coincides with last point of j, prepend points of j to i and delete j */ - retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1); - retval.erase(retval.begin() + j); + polylines[i].points.insert(polylines[i].points.begin(), polylines[j].points.begin(), polylines[j].points.end()-1); + polylines.erase(polylines.begin() + j); --j; - } else if (retval[i].points.front() == retval[j].points.front()) { + } else if (polylines[i].points.front() == polylines[j].points.front()) { /* Since Clipper does not preserve orientation of polylines, also check the case when first point of i coincides with first point of j. */ - retval[j].reverse(); - retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1); - retval.erase(retval.begin() + j); + polylines[j].reverse(); + polylines[i].points.insert(polylines[i].points.begin(), polylines[j].points.begin(), polylines[j].points.end()-1); + polylines.erase(polylines.begin() + j); --j; - } else if (retval[i].points.back() == retval[j].points.back()) { + } else if (polylines[i].points.back() == polylines[j].points.back()) { /* Since Clipper does not preserve orientation of polylines, also check the case when last point of i coincides with last point of j. */ - retval[j].reverse(); - retval[i].points.insert(retval[i].points.end(), retval[j].points.begin()+1, retval[j].points.end()); - retval.erase(retval.begin() + j); + polylines[j].reverse(); + polylines[i].points.insert(polylines[i].points.end(), polylines[j].points.begin()+1, polylines[j].points.end()); + polylines.erase(polylines.begin() + j); --j; } } } +} + +template +Polylines _clipper_pl_closed(ClipperLib::ClipType clipType, PathProvider1 &&subject, PathProvider2 &&clip, bool do_safety_offset) +{ + // Transform input polygons into open paths. + ClipperLib::Paths paths; + paths.reserve(subject.size()); + for (const Points &poly : subject) { + // Emplace polygon, duplicate the 1st point. + paths.push_back({}); + ClipperLib::Path &path = paths.back(); + path.reserve(poly.size() + 1); + path = poly; + path.emplace_back(poly.front()); + } + // perform clipping + Polylines retval = _clipper_pl_open(clipType, paths, std::forward(clip), do_safety_offset); + _clipper_pl_recombine(retval); return retval; } -Lines -_clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons &clip, - bool safety_offset_) +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_pl_open(ClipperLib::ctDifference, ClipperUtils::PolylinesProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygon &clip, bool do_safety_offset) + { return _clipper_pl_open(ClipperLib::ctDifference, ClipperUtils::PolylinesProvider(subject), ClipperUtils::ExPolygonProvider(clip), do_safety_offset); } +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_pl_open(ClipperLib::ctDifference, ClipperUtils::PolylinesProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::Polylines diff_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_pl_closed(ClipperLib::ctDifference, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_pl_open(ClipperLib::ctIntersection, ClipperUtils::PolylinesProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } +Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset) + { return _clipper_pl_open(ClipperLib::ctIntersection, ClipperUtils::PolylinesProvider(subject), ClipperUtils::ExPolygonsProvider(clip), do_safety_offset); } +Slic3r::Polylines intersection_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset) + { return _clipper_pl_closed(ClipperLib::ctIntersection, ClipperUtils::PolygonsProvider(subject), ClipperUtils::PolygonsProvider(clip), do_safety_offset); } + +Lines _clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons &clip, bool do_safety_offset) { // convert Lines to Polylines Polylines polylines; @@ -659,7 +614,7 @@ _clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons polylines.emplace_back(Polyline(line.a, line.b)); // perform operation - polylines = _clipper_pl(clipType, polylines, clip, safety_offset_); + polylines = _clipper_pl_open(clipType, ClipperUtils::PolylinesProvider(polylines), ClipperUtils::PolygonsProvider(clip), do_safety_offset); // convert Polylines to Lines Lines retval; @@ -668,24 +623,14 @@ _clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons return retval; } -ClipperLib::PolyTree union_pt(const Polygons &subject, bool safety_offset_) +ClipperLib::PolyTree union_pt(const Polygons &subject) { - return _clipper_do(ClipperLib::ctUnion, subject, Polygons(), ClipperLib::pftEvenOdd, safety_offset_); + return _clipper_do(ClipperLib::ctUnion, ClipperUtils::PolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), ClipperLib::pftEvenOdd); } -ClipperLib::PolyTree union_pt(const ExPolygons &subject, bool safety_offset_) +ClipperLib::PolyTree union_pt(const ExPolygons &subject) { - return _clipper_do(ClipperLib::ctUnion, subject, Polygons(), ClipperLib::pftEvenOdd, safety_offset_); -} - -ClipperLib::PolyTree union_pt(Polygons &&subject, bool safety_offset_) -{ - return _clipper_do(ClipperLib::ctUnion, std::move(subject), Polygons(), ClipperLib::pftEvenOdd, safety_offset_); -} - -ClipperLib::PolyTree union_pt(ExPolygons &&subject, bool safety_offset_) -{ - return _clipper_do(ClipperLib::ctUnion, std::move(subject), Polygons(), ClipperLib::pftEvenOdd, safety_offset_); + return _clipper_do(ClipperLib::ctUnion, ClipperUtils::ExPolygonsProvider(subject), ClipperUtils::EmptyPathsProvider(), ClipperLib::pftEvenOdd); } // Simple spatial ordering of Polynodes @@ -697,7 +642,7 @@ ClipperLib::PolyNodes order_nodes(const ClipperLib::PolyNodes &nodes) for (const ClipperLib::PolyNode *node : nodes) ordering_points.emplace_back( - Point(node->Contour.front().X, node->Contour.front().Y)); + Point(node->Contour.front().x(), node->Contour.front().y())); // perform the ordering ClipperLib::PolyNodes ordered_nodes = @@ -711,7 +656,7 @@ static void traverse_pt_noholes(const ClipperLib::PolyNodes &nodes, Polygons *ou foreach_node(nodes, [&out](const ClipperLib::PolyNode *node) { traverse_pt_noholes(node->Childs, out); - out->emplace_back(ClipperPath_to_Slic3rPolygon(node->Contour)); + out->emplace_back(node->Contour); if (node->IsHole()) out->back().reverse(); // ccw }); } @@ -722,12 +667,12 @@ static void traverse_pt_outside_in(const ClipperLib::PolyNodes &nodes, Polygons Points ordering_points; ordering_points.reserve(nodes.size()); for (const ClipperLib::PolyNode *node : nodes) - ordering_points.emplace_back(node->Contour.front().X, node->Contour.front().Y); + ordering_points.emplace_back(node->Contour.front().x(), node->Contour.front().y()); // Perform the ordering, push results recursively. //FIXME pass the last point to chain_clipper_polynodes? for (const ClipperLib::PolyNode *node : chain_clipper_polynodes(ordering_points, nodes)) { - retval->emplace_back(ClipperPath_to_Slic3rPolygon(node->Contour)); + retval->emplace_back(node->Contour); if (node->IsHole()) // Orient a hole, which is clockwise oriented, to CCW. retval->back().reverse(); @@ -736,9 +681,9 @@ static void traverse_pt_outside_in(const ClipperLib::PolyNodes &nodes, Polygons } } -Polygons union_pt_chained_outside_in(const Polygons &subject, bool safety_offset_) +Polygons union_pt_chained_outside_in(const Polygons &subject) { - ClipperLib::PolyTree polytree = union_pt(subject, safety_offset_); + ClipperLib::PolyTree polytree = union_pt(subject); Polygons retval; traverse_pt_outside_in(polytree.Childs, &retval); @@ -747,22 +692,19 @@ Polygons union_pt_chained_outside_in(const Polygons &subject, bool safety_offset Polygons simplify_polygons(const Polygons &subject, bool preserve_collinear) { - // convert into Clipper polygons - ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); - ClipperLib::Paths output; if (preserve_collinear) { ClipperLib::Clipper c; c.PreserveCollinear(true); c.StrictlySimple(true); - c.AddPaths(input_subject, ClipperLib::ptSubject, true); + c.AddPaths(ClipperUtils::PolygonsProvider(subject), ClipperLib::ptSubject, true); c.Execute(ClipperLib::ctUnion, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); } else { - ClipperLib::SimplifyPolygons(input_subject, output, ClipperLib::pftNonZero); + output = ClipperLib::SimplifyPolygons(ClipperUtils::PolygonsProvider(subject), ClipperLib::pftNonZero); } // convert into Slic3r polygons - return ClipperPaths_to_Slic3rPolygons(output); + return to_polygons(std::move(output)); } ExPolygons simplify_polygons_ex(const Polygons &subject, bool preserve_collinear) @@ -770,68 +712,15 @@ ExPolygons simplify_polygons_ex(const Polygons &subject, bool preserve_collinear if (! preserve_collinear) return union_ex(simplify_polygons(subject, false)); - // convert into Clipper polygons - ClipperLib::Paths input_subject = Slic3rMultiPoints_to_ClipperPaths(subject); - - ClipperLib::PolyTree polytree; - + ClipperLib::PolyTree polytree; ClipperLib::Clipper c; c.PreserveCollinear(true); c.StrictlySimple(true); - c.AddPaths(input_subject, ClipperLib::ptSubject, true); + c.AddPaths(ClipperUtils::PolygonsProvider(subject), ClipperLib::ptSubject, true); c.Execute(ClipperLib::ctUnion, polytree, ClipperLib::pftNonZero, ClipperLib::pftNonZero); // convert into ExPolygons - return PolyTreeToExPolygons(polytree); -} - -void safety_offset(ClipperLib::Paths* paths) -{ - CLIPPERUTILS_PROFILE_FUNC(); - - // scale input - scaleClipperPolygons(*paths); - - // perform offset (delta = scale 1e-05) - ClipperLib::ClipperOffset co; -#ifdef CLIPPER_UTILS_DEBUG - if (clipper_export_enabled) { - static int iRun = 0; - export_clipper_input_polygons_bin(debug_out_path("safety_offset-polygons-%d", ++iRun).c_str(), *paths, ClipperLib::Paths()); - } -#endif /* CLIPPER_UTILS_DEBUG */ - ClipperLib::Paths out; - for (size_t i = 0; i < paths->size(); ++ i) { - ClipperLib::Path &path = (*paths)[i]; - co.Clear(); - co.MiterLimit = 2; - bool ccw = ClipperLib::Orientation(path); - if (! ccw) - std::reverse(path.begin(), path.end()); - { - CLIPPERUTILS_PROFILE_BLOCK(safety_offset_AddPaths); - co.AddPath((*paths)[i], ClipperLib::jtMiter, ClipperLib::etClosedPolygon); - } - { - CLIPPERUTILS_PROFILE_BLOCK(safety_offset_Execute); - // offset outside by 10um - ClipperLib::Paths out_this; - co.Execute(out_this, ccw ? 10.f * float(CLIPPER_OFFSET_SCALE) : -10.f * float(CLIPPER_OFFSET_SCALE)); - if (! ccw) { - // Reverse the resulting contours once again. - for (ClipperLib::Paths::iterator it = out_this.begin(); it != out_this.end(); ++ it) - std::reverse(it->begin(), it->end()); - } - if (out.empty()) - out = std::move(out_this); - else - std::move(std::begin(out_this), std::end(out_this), std::back_inserter(out)); - } - } - *paths = std::move(out); - - // unscale output - unscaleClipperPolygons(*paths); + return PolyTreeToExPolygons(std::move(polytree)); } Polygons top_level_islands(const Slic3r::Polygons &polygons) @@ -840,14 +729,14 @@ Polygons top_level_islands(const Slic3r::Polygons &polygons) ClipperLib::Clipper clipper; clipper.Clear(); // perform union - clipper.AddPaths(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::ptSubject, true); + clipper.AddPaths(ClipperUtils::PolygonsProvider(polygons), ClipperLib::ptSubject, true); ClipperLib::PolyTree polytree; clipper.Execute(ClipperLib::ctUnion, polytree, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd); // Convert only the top level islands to the output. Polygons out; out.reserve(polytree.ChildCount()); for (int i = 0; i < polytree.ChildCount(); ++i) - out.emplace_back(ClipperPath_to_Slic3rPolygon(polytree.Childs[i]->Contour)); + out.emplace_back(std::move(polytree.Childs[i]->Contour)); return out; } @@ -925,8 +814,7 @@ ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::v // Add a new point to the output, scale by CLIPPER_OFFSET_SCALE and round to ClipperLib::cInt. auto add_offset_point = [&out](Vec2d pt) { - pt *= double(CLIPPER_OFFSET_SCALE); - pt += Vec2d(0.5 - (pt.x() < 0), 0.5 - (pt.y() < 0)); + pt += Vec2d(0.5 - (pt.x() < 0), 0.5 - (pt.y() < 0)); out.emplace_back(ClipperLib::cInt(pt.x()), ClipperLib::cInt(pt.y())); }; @@ -1021,7 +909,7 @@ ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::v { ClipperLib::Path polytmp(out); unscaleClipperPolygon(polytmp); - Slic3r::Polygon offsetted = ClipperPath_to_Slic3rPolygon(polytmp); + Slic3r::Polygon offsetted(std::move(polytmp)); BoundingBox bbox = get_extents(contour); bbox.merge(get_extents(offsetted)); static int iRun = 0; @@ -1075,9 +963,7 @@ Polygons variable_offset_inner(const ExPolygon &expoly, const std::vector> &deltas, double miter_limit) @@ -1119,9 +1005,7 @@ for (const std::vector& ds : deltas) clipper.Execute(ClipperLib::ctDifference, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero); } - // 4) Unscale the output. - unscaleClipperPolygons(output); - return ClipperPaths_to_Slic3rPolygons(output); + return to_polygons(std::move(output)); } ExPolygons variable_offset_outer_ex(const ExPolygon &expoly, const std::vector> &deltas, double miter_limit) @@ -1152,20 +1036,18 @@ for (const std::vector& ds : deltas) #endif /* NDEBUG */ // 3) Subtract holes from the contours. - unscaleClipperPolygons(contours); ExPolygons output; if (holes.empty()) { output.reserve(contours.size()); for (ClipperLib::Path &path : contours) - output.emplace_back(ClipperPath_to_Slic3rPolygon(path)); + output.emplace_back(std::move(path)); } else { ClipperLib::Clipper clipper; - unscaleClipperPolygons(holes); clipper.AddPaths(contours, ClipperLib::ptSubject, true); clipper.AddPaths(holes, ClipperLib::ptClip, true); ClipperLib::PolyTree polytree; clipper.Execute(ClipperLib::ctDifference, polytree, ClipperLib::pftNonZero, ClipperLib::pftNonZero); - output = PolyTreeToExPolygons(polytree); + output = PolyTreeToExPolygons(std::move(polytree)); } return output; @@ -1200,20 +1082,18 @@ ExPolygons variable_offset_inner_ex(const ExPolygon &expoly, const std::vectorcbegin(); } + iterator cend() const { return iterator(s_end); } + iterator end() const { return this->cend(); } + size_t size() const { return 1; } + + private: + const Points &m_points; + static Points s_end; + }; + + template + class MultiPointsProvider { + public: + MultiPointsProvider(const std::vector &multipoints) : m_multipoints(multipoints) {} + + struct iterator : public PathsProviderIteratorBase { + public: + explicit iterator(typename std::vector::const_iterator it) : m_it(it) {} + const Points& operator*() const { return m_it->points; } + bool operator==(const iterator &rhs) const { return m_it == rhs.m_it; } + bool operator!=(const iterator &rhs) const { return !(*this == rhs); } + const Points& operator++(int) { return (m_it ++)->points; } + iterator& operator++() { ++ m_it; return *this; } + private: + typename std::vector::const_iterator m_it; + }; + + iterator cbegin() const { return iterator(m_multipoints.begin()); } + iterator begin() const { return this->cbegin(); } + iterator cend() const { return iterator(m_multipoints.end()); } + iterator end() const { return this->cend(); } + size_t size() const { return m_multipoints.size(); } + + private: + const std::vector &m_multipoints; + }; + + using PolygonsProvider = MultiPointsProvider; + using PolylinesProvider = MultiPointsProvider; + + struct ExPolygonProvider { + ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {} + + struct iterator : public PathsProviderIteratorBase { + public: + explicit iterator(const ExPolygon &expoly, int idx) : m_expoly(expoly), m_idx(idx) {} + const Points& operator*() const { return (m_idx == 0) ? m_expoly.contour.points : m_expoly.holes[m_idx - 1].points; } + bool operator==(const iterator &rhs) const { assert(m_expoly == rhs.m_expoly); return m_idx == rhs.m_idx; } + bool operator!=(const iterator &rhs) const { return !(*this == rhs); } + const Points& operator++(int) { const Points &out = **this; ++ m_idx; return out; } + iterator& operator++() { ++ m_idx; return *this; } + private: + const ExPolygon &m_expoly; + int m_idx; + }; + + iterator cbegin() const { return iterator(m_expoly, 0); } + iterator begin() const { return this->cbegin(); } + iterator cend() const { return iterator(m_expoly, m_expoly.holes.size() + 1); } + iterator end() const { return this->cend(); } + size_t size() const { return m_expoly.holes.size() + 1; } + + private: + const ExPolygon &m_expoly; + }; + + struct ExPolygonsProvider { + ExPolygonsProvider(const ExPolygons &expolygons) : m_expolygons(expolygons) { + m_size = 0; + for (const ExPolygon &expoly : expolygons) + m_size += expoly.holes.size() + 1; + } + + struct iterator : public PathsProviderIteratorBase { + public: + explicit iterator(ExPolygons::const_iterator it) : m_it_expolygon(it), m_idx_contour(0) {} + const Points& operator*() const { return (m_idx_contour == 0) ? m_it_expolygon->contour.points : m_it_expolygon->holes[m_idx_contour - 1].points; } + bool operator==(const iterator &rhs) const { return m_it_expolygon == rhs.m_it_expolygon && m_idx_contour == rhs.m_idx_contour; } + bool operator!=(const iterator &rhs) const { return !(*this == rhs); } + iterator& operator++() { + if (++ m_idx_contour == m_it_expolygon->holes.size() + 1) { + ++ m_it_expolygon; + m_idx_contour = 0; + } + return *this; + } + const Points& operator++(int) { + const Points &out = **this; + ++ (*this); + return out; + } + private: + ExPolygons::const_iterator m_it_expolygon; + size_t m_idx_contour; + }; + + iterator cbegin() const { return iterator(m_expolygons.cbegin()); } + iterator begin() const { return this->cbegin(); } + iterator cend() const { return iterator(m_expolygons.cend()); } + iterator end() const { return this->cend(); } + size_t size() const { return m_size; } + + private: + const ExPolygons &m_expolygons; + size_t m_size; + }; + + struct SurfacesProvider { + SurfacesProvider(const Surfaces &surfaces) : m_surfaces(surfaces) { + m_size = 0; + for (const Surface &surface : surfaces) + m_size += surface.expolygon.holes.size() + 1; + } + + struct iterator : public PathsProviderIteratorBase { + public: + explicit iterator(Surfaces::const_iterator it) : m_it_surface(it), m_idx_contour(0) {} + const Points& operator*() const { return (m_idx_contour == 0) ? m_it_surface->expolygon.contour.points : m_it_surface->expolygon.holes[m_idx_contour - 1].points; } + bool operator==(const iterator &rhs) const { return m_it_surface == rhs.m_it_surface && m_idx_contour == rhs.m_idx_contour; } + bool operator!=(const iterator &rhs) const { return !(*this == rhs); } + iterator& operator++() { + if (++ m_idx_contour == m_it_surface->expolygon.holes.size() + 1) { + ++ m_it_surface; + m_idx_contour = 0; + } + return *this; + } + const Points& operator++(int) { + const Points &out = **this; + ++ (*this); + return out; + } + private: + Surfaces::const_iterator m_it_surface; + size_t m_idx_contour; + }; + + iterator cbegin() const { return iterator(m_surfaces.cbegin()); } + iterator begin() const { return this->cbegin(); } + iterator cend() const { return iterator(m_surfaces.cend()); } + iterator end() const { return this->cend(); } + size_t size() const { return m_size; } + + private: + const Surfaces &m_surfaces; + size_t m_size; + }; + + struct SurfacesPtrProvider { + SurfacesPtrProvider(const SurfacesPtr &surfaces) : m_surfaces(surfaces) { + m_size = 0; + for (const Surface *surface : surfaces) + m_size += surface->expolygon.holes.size() + 1; + } + + struct iterator : public PathsProviderIteratorBase { + public: + explicit iterator(SurfacesPtr::const_iterator it) : m_it_surface(it), m_idx_contour(0) {} + const Points& operator*() const { return (m_idx_contour == 0) ? (*m_it_surface)->expolygon.contour.points : (*m_it_surface)->expolygon.holes[m_idx_contour - 1].points; } + bool operator==(const iterator &rhs) const { return m_it_surface == rhs.m_it_surface && m_idx_contour == rhs.m_idx_contour; } + bool operator!=(const iterator &rhs) const { return !(*this == rhs); } + iterator& operator++() { + if (++ m_idx_contour == (*m_it_surface)->expolygon.holes.size() + 1) { + ++ m_it_surface; + m_idx_contour = 0; + } + return *this; + } + const Points& operator++(int) { + const Points &out = **this; + ++ (*this); + return out; + } + private: + SurfacesPtr::const_iterator m_it_surface; + size_t m_idx_contour; + }; + + iterator cbegin() const { return iterator(m_surfaces.cbegin()); } + iterator begin() const { return this->cbegin(); } + iterator cend() const { return iterator(m_surfaces.cend()); } + iterator end() const { return this->cend(); } + size_t size() const { return m_size; } + + private: + const SurfacesPtr &m_surfaces; + size_t m_size; + }; +} + +ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input); // offset Polygons -ClipperLib::Paths _offset(ClipperLib::Path &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit); -ClipperLib::Paths _offset(ClipperLib::Paths &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit); -inline Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } -inline Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); + +#ifdef CLIPPERUTILS_UNSAFE_OFFSET +Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +#endif // CLIPPERUTILS_UNSAFE_OFFSET // offset Polylines -inline Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polyline), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } -inline Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polylines), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } +Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3); +Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3); +Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::Polygons offset(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::Polygons offset(const Slic3r::SurfacesPtr &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset_ex(const Slic3r::Surfaces &surfaces, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); -// offset expolygons and surfaces -ClipperLib::Paths _offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit); -ClipperLib::Paths _offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit); -inline Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(expolygon, delta, joinType, miterLimit)); } -inline Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rPolygons(_offset(expolygons, delta, joinType, miterLimit)); } -inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rExPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } -inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rExPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } -inline Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rExPolygons(_offset(expolygon, delta, joinType, miterLimit)); } -inline Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rExPolygons(_offset(expolygons, delta, joinType, miterLimit)); } +Slic3r::Polygons offset2(const Slic3r::ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset2_ex(const Slic3r::ExPolygons &expolygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); -ClipperLib::Paths _offset2(const Slic3r::Polygons &polygons, const float delta1, - const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, - double miterLimit = 3); -Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1, - const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, - double miterLimit = 3); -Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1, - const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, - double miterLimit = 3); -Slic3r::ExPolygons offset2_ex(const Slic3r::ExPolygons &expolygons, const float delta1, - const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, - double miterLimit = 3); +#ifdef CLIPPERUTILS_UNSAFE_OFFSET +Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +ClipperLib::Paths _offset2(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1, const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +#endif // CLIPPERUTILS_UNSAFE_OFFSET -Slic3r::Polygons _clipper(ClipperLib::ClipType clipType, - const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); -Slic3r::ExPolygons _clipper_ex(ClipperLib::ClipType clipType, - const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); -Slic3r::Polylines _clipper_pl(ClipperLib::ClipType clipType, - const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); -Slic3r::Polylines _clipper_pl(ClipperLib::ClipType clipType, - const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); -Slic3r::Lines _clipper_ln(ClipperLib::ClipType clipType, - const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false); +Slic3r::Lines _clipper_ln(ClipperLib::ClipType clipType, const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); -// diff -inline Slic3r::Polygons -diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) +Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polygons diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Polygons &subject, const Slic3r::Surfaces &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Polygon &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::Surfaces &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, bool do_safety_offset = false); +Slic3r::ExPolygons diff_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygon &clip, bool do_safety_offset = false); +Slic3r::Polylines diff_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::Polylines diff_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); + +inline Slic3r::Lines diff_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false) { - return _clipper(ClipperLib::ctDifference, subject, clip, safety_offset_); + return _clipper_ln(ClipperLib::ctDifference, subject, clip, do_safety_offset); } -inline Slic3r::ExPolygons -diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) +Slic3r::Polygons intersection(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polygons intersection(const Slic3r::ExPolygon &subject, const Slic3r::ExPolygon &clip, bool do_safety_offset = false); +Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polygons intersection(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polygons intersection(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygon &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::Polygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::Surfaces &subject, const Slic3r::Surfaces &clip, bool do_safety_offset = false); +Slic3r::ExPolygons intersection_ex(const Slic3r::SurfacesPtr &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); +Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::ExPolygons &clip, bool do_safety_offset = false); +Slic3r::Polylines intersection_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false); + +inline Slic3r::Lines intersection_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false) { - return _clipper_ex(ClipperLib::ctDifference, subject, clip, safety_offset_); + return _clipper_ln(ClipperLib::ctIntersection, subject, clip, do_safety_offset); } -inline Slic3r::ExPolygons -diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctDifference, to_polygons(subject), to_polygons(clip), safety_offset_); -} - -inline Slic3r::Polygons -diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false) -{ - return _clipper(ClipperLib::ctDifference, to_polygons(subject), to_polygons(clip), safety_offset_); -} - -inline Slic3r::Polylines -diff_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_pl(ClipperLib::ctDifference, subject, clip, safety_offset_); -} - -inline Slic3r::Polylines -diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_pl(ClipperLib::ctDifference, subject, clip, safety_offset_); -} - -inline Slic3r::Lines -diff_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_ln(ClipperLib::ctDifference, subject, clip, safety_offset_); -} - -// intersection -inline Slic3r::Polygons -intersection(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper(ClipperLib::ctIntersection, subject, clip, safety_offset_); -} - -inline Slic3r::ExPolygons -intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctIntersection, subject, clip, safety_offset_); -} - -inline Slic3r::ExPolygons -intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctIntersection, to_polygons(subject), to_polygons(clip), safety_offset_); -} - -inline Slic3r::Polygons -intersection(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false) -{ - return _clipper(ClipperLib::ctIntersection, to_polygons(subject), to_polygons(clip), safety_offset_); -} - -inline Slic3r::Polylines -intersection_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_pl(ClipperLib::ctIntersection, subject, clip, safety_offset_); -} - -inline Slic3r::Polylines -intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_pl(ClipperLib::ctIntersection, subject, clip, safety_offset_); -} - -inline Slic3r::Lines intersection_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) -{ - return _clipper_ln(ClipperLib::ctIntersection, subject, clip, safety_offset_); -} - -inline Slic3r::Lines intersection_ln(const Slic3r::Line &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false) +inline Slic3r::Lines intersection_ln(const Slic3r::Line &subject, const Slic3r::Polygons &clip, bool do_safety_offset = false) { Slic3r::Lines lines; lines.emplace_back(subject); - return _clipper_ln(ClipperLib::ctIntersection, lines, clip, safety_offset_); + return _clipper_ln(ClipperLib::ctIntersection, lines, clip, do_safety_offset); } -// union -inline Slic3r::Polygons union_(const Slic3r::Polygons &subject, bool safety_offset_ = false) -{ - return _clipper(ClipperLib::ctUnion, subject, Slic3r::Polygons(), safety_offset_); -} +Slic3r::Polygons union_(const Slic3r::Polygons &subject, bool do_safety_offset = false); +Slic3r::Polygons union_(const Slic3r::ExPolygons &subject, bool do_safety_offset = false); +Slic3r::Polygons union_(const Slic3r::Polygons &subject, const Slic3r::Polygons &subject2, bool do_safety_offset = false); +Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, bool do_safety_offset = false); +Slic3r::ExPolygons union_ex(const Slic3r::ExPolygons &subject); +Slic3r::ExPolygons union_ex(const Slic3r::Surfaces &subject); -inline Slic3r::Polygons union_(const Slic3r::Polygons &subject, const Slic3r::Polygons &subject2, bool safety_offset_ = false) -{ - return _clipper(ClipperLib::ctUnion, subject, subject2, safety_offset_); -} +ClipperLib::PolyTree union_pt(const Slic3r::Polygons &subject); +ClipperLib::PolyTree union_pt(const Slic3r::ExPolygons &subject); -inline Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctUnion, subject, Slic3r::Polygons(), safety_offset_); -} - -inline Slic3r::ExPolygons union_ex(const Slic3r::ExPolygons &subject, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctUnion, to_polygons(subject), Slic3r::Polygons(), safety_offset_); -} - -inline Slic3r::ExPolygons union_ex(const Slic3r::Surfaces &subject, bool safety_offset_ = false) -{ - return _clipper_ex(ClipperLib::ctUnion, to_polygons(subject), Slic3r::Polygons(), safety_offset_); -} - -ClipperLib::PolyTree union_pt(const Slic3r::Polygons &subject, bool safety_offset_ = false); -ClipperLib::PolyTree union_pt(const Slic3r::ExPolygons &subject, bool safety_offset_ = false); -ClipperLib::PolyTree union_pt(Slic3r::Polygons &&subject, bool safety_offset_ = false); -ClipperLib::PolyTree union_pt(Slic3r::ExPolygons &&subject, bool safety_offset_ = false); - -Slic3r::Polygons union_pt_chained_outside_in(const Slic3r::Polygons &subject, bool safety_offset_ = false); +Slic3r::Polygons union_pt_chained_outside_in(const Slic3r::Polygons &subject); ClipperLib::PolyNodes order_nodes(const ClipperLib::PolyNodes &nodes); @@ -267,7 +403,7 @@ void traverse_pt(const ClipperLib::PolyNode *tree, Polygons *out) if (!tree) return; // terminates recursion // Push the contour of the current level - out->emplace_back(ClipperPath_to_Slic3rPolygon(tree->Contour)); + out->emplace_back(tree->Contour); // Do the recursion for all the children. traverse_pt(tree->Childs, out); @@ -286,13 +422,13 @@ void traverse_pt(const ClipperLib::PolyNode *tree, ExPolygons *out) } ExPolygon level; - level.contour = ClipperPath_to_Slic3rPolygon(tree->Contour); + level.contour.points = tree->Contour; foreach_node(tree->Childs, [out, &level] (const ClipperLib::PolyNode *node) { // Holes are collected here. - level.holes.emplace_back(ClipperPath_to_Slic3rPolygon(node->Contour)); + level.holes.emplace_back(node->Contour); // By doing a recursion, a new level expoly is created with the contour // and holes of the lower level. Doing this for all the childs. @@ -315,10 +451,9 @@ void traverse_pt(const ClipperLib::PolyNodes &nodes, ExOrJustPolygons *retval) Slic3r::Polygons simplify_polygons(const Slic3r::Polygons &subject, bool preserve_collinear = false); Slic3r::ExPolygons simplify_polygons_ex(const Slic3r::Polygons &subject, bool preserve_collinear = false); -void safety_offset(ClipperLib::Paths* paths); - Polygons top_level_islands(const Slic3r::Polygons &polygons); +ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::vector &deltas, double miter_limit); Polygons variable_offset_inner(const ExPolygon &expoly, const std::vector> &deltas, double miter_limit = 2.); Polygons variable_offset_outer(const ExPolygon &expoly, const std::vector> &deltas, double miter_limit = 2.); ExPolygons variable_offset_outer_ex(const ExPolygon &expoly, const std::vector> &deltas, double miter_limit = 2.); diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 6755a63781..5db1d8179b 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -471,8 +471,8 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src, { t_config_option_key opt_key = opt_key_src; std::string value = value_src; - // Both opt_key and value may be modified by _handle_legacy(). - // If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by _handle_legacy(). + // Both opt_key and value may be modified by handle_legacy(). + // If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy(). this->handle_legacy(opt_key, value); if (opt_key.empty()) // Ignore the option. diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 80d34e8216..c49c492a3f 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -18,11 +18,53 @@ #include #include +#include #include #include #include +namespace Slic3r { + struct FloatOrPercent + { + double value; + bool percent; + + private: + friend class cereal::access; + template void serialize(Archive& ar) { ar(this->value); ar(this->percent); } + }; + + inline bool operator==(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return l.value == r.value && l.percent == r.percent; } + inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return !(l == r); } +} + +namespace std { + template<> struct hash { + std::size_t operator()(const Slic3r::FloatOrPercent& v) const noexcept { + std::size_t seed = std::hash{}(v.value); + return v.percent ? seed ^ 0x9e3779b9 : seed; + } + }; + + template<> struct hash { + std::size_t operator()(const Slic3r::Vec2d& v) const noexcept { + std::size_t seed = std::hash{}(v.x()); + boost::hash_combine(seed, std::hash{}(v.y())); + return seed; + } + }; + + template<> struct hash { + std::size_t operator()(const Slic3r::Vec3d& v) const noexcept { + std::size_t seed = std::hash{}(v.x()); + boost::hash_combine(seed, std::hash{}(v.y())); + boost::hash_combine(seed, std::hash{}(v.z())); + return seed; + } + }; +} + namespace Slic3r { // Name of the configuration option. @@ -137,6 +179,7 @@ public: virtual void setInt(int /* val */) { throw BadOptionTypeException("Calling ConfigOption::setInt on a non-int ConfigOption"); } virtual bool operator==(const ConfigOption &rhs) const = 0; bool operator!=(const ConfigOption &rhs) const { return ! (*this == rhs); } + virtual size_t hash() const throw() = 0; bool is_scalar() const { return (int(this->type()) & int(coVectorType)) == 0; } bool is_vector() const { return ! this->is_scalar(); } // If this option is nullable, then it may have its value or values set to nil. @@ -185,8 +228,10 @@ public: return this->value == static_cast*>(&rhs)->value; } - bool operator==(const T &rhs) const { return this->value == rhs; } - bool operator!=(const T &rhs) const { return this->value != rhs; } + bool operator==(const T &rhs) const throw() { return this->value == rhs; } + bool operator!=(const T &rhs) const throw() { return this->value != rhs; } + + size_t hash() const throw() override { return std::hash{}(this->value); } private: friend class cereal::access; @@ -339,8 +384,16 @@ public: return this->values == static_cast*>(&rhs)->values; } - bool operator==(const std::vector &rhs) const { return this->values == rhs; } - bool operator!=(const std::vector &rhs) const { return this->values != rhs; } + bool operator==(const std::vector &rhs) const throw() { return this->values == rhs; } + bool operator!=(const std::vector &rhs) const throw() { return this->values != rhs; } + + size_t hash() const throw() override { + std::hash hasher; + size_t seed = 0; + for (const auto &v : this->values) + boost::hash_combine(seed, hasher(v)); + return seed; + } // Is this option overridden by another option? // An option overrides another option if it is not nil and not equal. @@ -413,7 +466,7 @@ public: ConfigOptionType type() const override { return static_type(); } double getFloat() const override { return this->value; } ConfigOption* clone() const override { return new ConfigOptionFloat(*this); } - bool operator==(const ConfigOptionFloat &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionFloat &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -454,7 +507,7 @@ public: static ConfigOptionType static_type() { return coFloats; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionFloatsTempl(*this); } - bool operator==(const ConfigOptionFloatsTempl &rhs) const { return vectors_equal(this->values, rhs.values); } + bool operator==(const ConfigOptionFloatsTempl &rhs) const throw() { return vectors_equal(this->values, rhs.values); } bool operator==(const ConfigOption &rhs) const override { if (rhs.type() != this->type()) throw Slic3r::RuntimeError("ConfigOptionFloatsTempl: Comparing incompatible types"); @@ -566,7 +619,7 @@ public: int getInt() const override { return this->value; } void setInt(int val) override { this->value = val; } ConfigOption* clone() const override { return new ConfigOptionInt(*this); } - bool operator==(const ConfigOptionInt &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionInt &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -606,7 +659,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionIntsTempl(*this); } ConfigOptionIntsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionIntsTempl &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionIntsTempl &rhs) const throw() { return this->values == rhs.values; } // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -689,7 +742,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionString(*this); } ConfigOptionString& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionString &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionString &rhs) const throw() { return this->value == rhs.value; } bool empty() const { return this->value.empty(); } std::string serialize() const override @@ -722,7 +775,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionStrings(*this); } ConfigOptionStrings& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionStrings &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionStrings &rhs) const throw() { return this->values == rhs.values; } bool is_nil(size_t) const override { return false; } std::string serialize() const override @@ -757,7 +810,8 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPercent(*this); } ConfigOptionPercent& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPercent &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPercent &rhs) const throw() { return this->value == rhs.value; } + double get_abs_value(double ratio_over) const { return ratio_over * this->value / 100; } std::string serialize() const override @@ -796,8 +850,8 @@ public: static ConfigOptionType static_type() { return coPercents; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPercentsTempl(*this); } - ConfigOptionPercentsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPercentsTempl &rhs) const { return this->values == rhs.values; } + ConfigOptionPercentsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } + bool operator==(const ConfigOptionPercentsTempl &rhs) const throw() { return this->values == rhs.values; } std::string serialize() const override { @@ -856,8 +910,12 @@ public: assert(dynamic_cast(&rhs)); return *this == *static_cast(&rhs); } - bool operator==(const ConfigOptionFloatOrPercent &rhs) const + bool operator==(const ConfigOptionFloatOrPercent &rhs) const throw() { return this->value == rhs.value && this->percent == rhs.percent; } + size_t hash() const throw() override { + size_t seed = std::hash{}(this->value); + return this->percent ? seed ^ 0x9e3779b9 : seed; + } double get_abs_value(double ratio_over) const { return this->percent ? (ratio_over * this->value / 100) : this->value; } @@ -891,27 +949,6 @@ private: template void serialize(Archive &ar) { ar(cereal::base_class(this), percent); } }; - -struct FloatOrPercent -{ - double value; - bool percent; - -private: - friend class cereal::access; - template void serialize(Archive & ar) { ar(this->value); ar(this->percent); } -}; - -inline bool operator==(const FloatOrPercent &l, const FloatOrPercent &r) -{ - return l.value == r.value && l.percent == r.percent; -} - -inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) -{ - return !(l == r); -} - template class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector { @@ -925,13 +962,14 @@ public: static ConfigOptionType static_type() { return coFloatsOrPercents; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionFloatsOrPercentsTempl(*this); } - bool operator==(const ConfigOptionFloatsOrPercentsTempl &rhs) const { return vectors_equal(this->values, rhs.values); } + bool operator==(const ConfigOptionFloatsOrPercentsTempl &rhs) const throw() { return vectors_equal(this->values, rhs.values); } bool operator==(const ConfigOption &rhs) const override { if (rhs.type() != this->type()) throw Slic3r::RuntimeError("ConfigOptionFloatsOrPercentsTempl: Comparing incompatible types"); assert(dynamic_cast*>(&rhs)); return vectors_equal(this->values, static_cast*>(&rhs)->values); } + // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -1038,7 +1076,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoint(*this); } ConfigOptionPoint& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoint &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPoint &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1074,7 +1112,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoints(*this); } ConfigOptionPoints& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoints &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionPoints &rhs) const throw() { return this->values == rhs.values; } bool is_nil(size_t) const override { return false; } std::string serialize() const override @@ -1146,7 +1184,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoint3(*this); } ConfigOptionPoint3& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoint3 &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPoint3 &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1183,7 +1221,7 @@ public: bool getBool() const override { return this->value; } ConfigOption* clone() const override { return new ConfigOptionBool(*this); } ConfigOptionBool& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionBool &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionBool &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1217,7 +1255,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionBoolsTempl(*this); } ConfigOptionBoolsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionBoolsTempl &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionBoolsTempl &rhs) const throw() { return this->values == rhs.values; } // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -1311,7 +1349,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionEnum(*this); } ConfigOptionEnum& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionEnum &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionEnum &rhs) const throw() { return this->value == rhs.value; } int getInt() const override { return (int)this->value; } void setInt(int val) override { this->value = T(val); } @@ -1397,7 +1435,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionEnumGeneric(*this); } ConfigOptionEnumGeneric& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionEnumGeneric &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionEnumGeneric &rhs) const throw() { return this->value == rhs.value; } bool operator==(const ConfigOption &rhs) const override { @@ -1967,8 +2005,9 @@ public: int opt_int(const t_config_option_key &opt_key, unsigned int idx) const { return dynamic_cast(this->option(opt_key))->get_at(idx); } // In ConfigManipulation::toggle_print_fff_options, it is called on option with type ConfigOptionEnumGeneric* and also ConfigOptionEnum*. + // Thus the virtual method getInt() is used to retrieve the enum value. template - ENUM opt_enum(const t_config_option_key &opt_key) const { return this->option>(opt_key)->value; } + ENUM opt_enum(const t_config_option_key &opt_key) const { return static_cast(this->option(opt_key)->getInt()); } bool opt_bool(const t_config_option_key &opt_key) const { return this->option(opt_key)->value != 0; } bool opt_bool(const t_config_option_key &opt_key, unsigned int idx) const { return this->option(opt_key)->get_at(idx) != 0; } diff --git a/src/libslic3r/ExPolygon.hpp b/src/libslic3r/ExPolygon.hpp index 46b3a3a1b9..04b84f7670 100644 --- a/src/libslic3r/ExPolygon.hpp +++ b/src/libslic3r/ExPolygon.hpp @@ -83,8 +83,8 @@ inline bool operator!=(const ExPolygon &lhs, const ExPolygon &rhs) { return lhs. inline size_t number_polygons(const ExPolygons &expolys) { size_t n_polygons = 0; - for (ExPolygons::const_iterator it = expolys.begin(); it != expolys.end(); ++ it) - n_polygons += it->holes.size() + 1; + for (const ExPolygon &ex : expolys) + n_polygons += ex.holes.size() + 1; return n_polygons; } @@ -217,6 +217,28 @@ inline Polygons to_polygons(const ExPolygons &src) return polygons; } +inline ConstPolygonPtrs to_polygon_ptrs(const ExPolygon &src) +{ + ConstPolygonPtrs polygons; + polygons.reserve(src.holes.size() + 1); + polygons.emplace_back(&src.contour); + for (const Polygon &hole : src.holes) + polygons.emplace_back(&hole); + return polygons; +} + +inline ConstPolygonPtrs to_polygon_ptrs(const ExPolygons &src) +{ + ConstPolygonPtrs polygons; + polygons.reserve(number_polygons(src)); + for (const ExPolygon &expoly : src) { + polygons.emplace_back(&expoly.contour); + for (const Polygon &hole : expoly.holes) + polygons.emplace_back(&hole); + } + return polygons; +} + inline Polygons to_polygons(ExPolygon &&src) { Polygons polygons; @@ -338,6 +360,8 @@ extern std::vector get_extents_vector(const ExPolygons &polygons); extern bool remove_sticks(ExPolygon &poly); extern void keep_largest_contour_only(ExPolygons &polygons); +inline double area(const ExPolygon &poly) { return poly.area(); } + inline double area(const ExPolygons &polys) { double s = 0.; diff --git a/src/libslic3r/Execution/Execution.hpp b/src/libslic3r/Execution/Execution.hpp new file mode 100644 index 0000000000..62e49cfeb3 --- /dev/null +++ b/src/libslic3r/Execution/Execution.hpp @@ -0,0 +1,128 @@ +#ifndef EXECUTION_HPP +#define EXECUTION_HPP + +#include +#include +#include +#include + +#include "libslic3r/libslic3r.h" + +namespace Slic3r { + +// Override for valid execution policies +template struct IsExecutionPolicy_ : public std::false_type {}; + +template constexpr bool IsExecutionPolicy = + IsExecutionPolicy_>::value; + +template +using ExecutionPolicyOnly = std::enable_if_t, T>; + +namespace execution { + +// This struct needs to be specialized for each execution policy. +// See ExecutionSeq.hpp and ExecutionTBB.hpp for example. +template struct Traits {}; + +template using AsTraits = Traits>; + +// Each execution policy should declare two types of mutexes. A a spin lock and +// a blocking mutex. These types should satisfy the BasicLockable concept. +template using SpinningMutex = typename Traits::SpinningMutex; +template using BlockingMutex = typename Traits::BlockingMutex; + +// Query the available threads for concurrency. +template > +size_t max_concurrency(const EP &ep) +{ + return AsTraits::max_concurrency(ep); +} + +// foreach loop with the execution policy passed as argument. Granularity can +// be specified explicitly. max_concurrency() can be used for optimal results. +template> +void for_each(const EP &ep, It from, It to, Fn &&fn, size_t granularity = 1) +{ + AsTraits::for_each(ep, from, to, std::forward(fn), granularity); +} + +// A reduce operation with the execution policy passed as argument. +// mergefn has T(const T&, const T&) signature +// accessfn has T(I) signature if I is an integral type and +// T(const I::value_type &) if I is an iterator type. +template > +T reduce(const EP & ep, + I from, + I to, + const T & init, + MergeFn && mergefn, + AccessFn &&accessfn, + size_t granularity = 1) +{ + return AsTraits::reduce(ep, from, to, init, + std::forward(mergefn), + std::forward(accessfn), + granularity); +} + +// An overload of reduce method to be used with iterators as 'from' and 'to' +// arguments. Access functor is omitted here. +template > +T reduce(const EP &ep, + I from, + I to, + const T & init, + MergeFn &&mergefn, + size_t granularity = 1) +{ + return reduce( + ep, from, to, init, std::forward(mergefn), + [](const auto &i) { return i; }, granularity); +} + +template> +T accumulate(const EP & ep, + I from, + I to, + const T & init, + AccessFn &&accessfn, + size_t granularity = 1) +{ + return reduce(ep, from, to, init, std::plus{}, + std::forward(accessfn), granularity); +} + + +template > +T accumulate(const EP &ep, + I from, + I to, + const T & init, + size_t granularity = 1) +{ + return reduce( + ep, from, to, init, std::plus{}, [](const auto &i) { return i; }, + granularity); +} + +} // namespace execution_policy +} // namespace Slic3r + +#endif // EXECUTION_HPP diff --git a/src/libslic3r/Execution/ExecutionSeq.hpp b/src/libslic3r/Execution/ExecutionSeq.hpp new file mode 100644 index 0000000000..321d65631b --- /dev/null +++ b/src/libslic3r/Execution/ExecutionSeq.hpp @@ -0,0 +1,84 @@ +#ifndef EXECUTIONSEQ_HPP +#define EXECUTIONSEQ_HPP + +#ifdef PRUSASLICER_USE_EXECUTION_STD // Conflicts with our version of TBB +#include +#endif + +#include "Execution.hpp" + +namespace Slic3r { + +// Execution policy implementing dummy sequential algorithms +struct ExecutionSeq {}; + +template<> struct IsExecutionPolicy_ : public std::true_type {}; + +static constexpr ExecutionSeq ex_seq = {}; + +template struct IsSequentialEP_ { static constexpr bool value = false; }; + +template<> struct IsSequentialEP_: public std::true_type {}; +#ifdef PRUSASLICER_USE_EXECUTION_STD +template<> struct IsExecutionPolicy_: public std::true_type {}; +template<> struct IsSequentialEP_: public std::true_type {}; +#endif + +template +constexpr bool IsSequentialEP = IsSequentialEP_>::value; + +template +using SequentialEPOnly = std::enable_if_t, R>; + +template +struct execution::Traits> { +private: + struct _Mtx { inline void lock() {} inline void unlock() {} }; + + template + static IteratorOnly loop_(It from, It to, Fn &&fn) + { + for (auto it = from; it != to; ++it) fn(*it); + } + + template + static IntegerOnly loop_(I from, I to, Fn &&fn) + { + for (I i = from; i < to; ++i) fn(i); + } + +public: + using SpinningMutex = _Mtx; + using BlockingMutex = _Mtx; + + template + static void for_each(const EP &, + It from, + It to, + Fn &&fn, + size_t /* ignore granularity */ = 1) + { + loop_(from, to, std::forward(fn)); + } + + template + static T reduce(const EP &, + I from, + I to, + const T & init, + MergeFn &&mergefn, + AccessFn &&access, + size_t /*granularity*/ = 1 + ) + { + T acc = init; + loop_(from, to, [&](auto &i) { acc = mergefn(acc, access(i)); }); + return acc; + } + + static size_t max_concurrency(const EP &) { return 1; } +}; + +} // namespace Slic3r + +#endif // EXECUTIONSEQ_HPP diff --git a/src/libslic3r/Execution/ExecutionTBB.hpp b/src/libslic3r/Execution/ExecutionTBB.hpp new file mode 100644 index 0000000000..cf6373c466 --- /dev/null +++ b/src/libslic3r/Execution/ExecutionTBB.hpp @@ -0,0 +1,77 @@ +#ifndef EXECUTIONTBB_HPP +#define EXECUTIONTBB_HPP + +#include +#include +#include +#include +#include + +#include "Execution.hpp" + +namespace Slic3r { + +struct ExecutionTBB {}; +template<> struct IsExecutionPolicy_ : public std::true_type {}; + +// Execution policy using Intel TBB library under the hood. +static constexpr ExecutionTBB ex_tbb = {}; + +template<> struct execution::Traits { +private: + + template + static IteratorOnly loop_(const tbb::blocked_range &range, Fn &&fn) + { + for (auto &el : range) fn(el); + } + + template + static IntegerOnly loop_(const tbb::blocked_range &range, Fn &&fn) + { + for (I i = range.begin(); i < range.end(); ++i) fn(i); + } + +public: + using SpinningMutex = tbb::spin_mutex; + using BlockingMutex = tbb::mutex; + + template + static void for_each(const ExecutionTBB &, + It from, It to, Fn &&fn, size_t granularity) + { + tbb::parallel_for(tbb::blocked_range{from, to, granularity}, + [&fn](const auto &range) { + loop_(range, std::forward(fn)); + }); + } + + template + static T reduce(const ExecutionTBB &, + I from, + I to, + const T &init, + MergeFn &&mergefn, + AccessFn &&access, + size_t granularity = 1 + ) + { + return tbb::parallel_reduce( + tbb::blocked_range{from, to, granularity}, init, + [&](const auto &range, T subinit) { + T acc = subinit; + loop_(range, [&](auto &i) { acc = mergefn(acc, access(i)); }); + return acc; + }, + std::forward(mergefn)); + } + + static size_t max_concurrency(const ExecutionTBB &) + { + return tbb::this_task_arena::max_concurrency(); + } +}; + +} + +#endif // EXECUTIONTBB_HPP diff --git a/src/libslic3r/ExtrusionEntity.cpp b/src/libslic3r/ExtrusionEntity.cpp index 3284bc39e4..d9320373f1 100644 --- a/src/libslic3r/ExtrusionEntity.cpp +++ b/src/libslic3r/ExtrusionEntity.cpp @@ -14,12 +14,12 @@ namespace Slic3r { void ExtrusionPath::intersect_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const { - this->_inflate_collection(intersection_pl((Polylines)polyline, to_polygons(collection.expolygons)), retval); + this->_inflate_collection(intersection_pl(Polylines{ polyline }, collection.expolygons), retval); } void ExtrusionPath::subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const { - this->_inflate_collection(diff_pl((Polylines)this->polyline, to_polygons(collection.expolygons)), retval); + this->_inflate_collection(diff_pl(Polylines{ this->polyline }, collection.expolygons), retval); } void ExtrusionPath::clip_end(double distance) @@ -318,7 +318,7 @@ std::string ExtrusionEntity::role_to_string(ExtrusionRole role) case erIroning : return L("Ironing"); case erBridgeInfill : return L("Bridge infill"); case erGapFill : return L("Gap fill"); - case erSkirt : return L("Skirt"); + case erSkirt : return L("Skirt/Brim"); case erSupportMaterial : return L("Support material"); case erSupportMaterialInterface : return L("Support material interface"); case erWipeTower : return L("Wipe tower"); @@ -349,7 +349,7 @@ ExtrusionRole ExtrusionEntity::string_to_role(const std::string_view role) return erBridgeInfill; else if (role == L("Gap fill")) return erGapFill; - else if (role == L("Skirt")) + else if (role == L("Skirt") || role == L("Skirt/Brim")) // "Skirt" is for backward compatibility with 2.3.1 and earlier return erSkirt; else if (role == L("Support material")) return erSupportMaterial; diff --git a/src/libslic3r/ExtrusionEntity.hpp b/src/libslic3r/ExtrusionEntity.hpp index 2c43cd4af8..2f35083169 100644 --- a/src/libslic3r/ExtrusionEntity.hpp +++ b/src/libslic3r/ExtrusionEntity.hpp @@ -203,6 +203,8 @@ public: void reverse() override; const Point& first_point() const override { return this->paths.front().polyline.points.front(); } const Point& last_point() const override { return this->paths.back().polyline.points.back(); } + size_t size() const { return this->paths.size(); } + bool empty() const { return this->paths.empty(); } double length() const override; ExtrusionRole role() const override { return this->paths.empty() ? erNone : this->paths.front().role(); } // Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width. diff --git a/src/libslic3r/Fill/Fill3DHoneycomb.cpp b/src/libslic3r/Fill/Fill3DHoneycomb.cpp index 2ddca7fe4a..0dec8004b2 100644 --- a/src/libslic3r/Fill/Fill3DHoneycomb.cpp +++ b/src/libslic3r/Fill/Fill3DHoneycomb.cpp @@ -147,7 +147,7 @@ void Fill3DHoneycomb::_fill_surface_single( // align bounding box to a multiple of our honeycomb grid module // (a module is 2*$distance since one $distance half-module is // growing while the other $distance half-module is shrinking) - bb.merge(_align_to_grid(bb.min, Point(2*distance, 2*distance))); + bb.merge(align_to_grid(bb.min, Point(2*distance, 2*distance))); // generate pattern Polylines polylines = makeGrid( @@ -162,7 +162,7 @@ void Fill3DHoneycomb::_fill_surface_single( pl.translate(bb.min); // clip pattern to boundaries, chain the clipped polylines - polylines = intersection_pl(polylines, to_polygons(expolygon)); + polylines = intersection_pl(polylines, expolygon); // connect lines if needed if (params.dont_connect() || polylines.size() <= 1) diff --git a/src/libslic3r/Fill/FillAdaptive.cpp b/src/libslic3r/Fill/FillAdaptive.cpp index d8c05887ec..6b303e636a 100644 --- a/src/libslic3r/Fill/FillAdaptive.cpp +++ b/src/libslic3r/Fill/FillAdaptive.cpp @@ -1368,7 +1368,7 @@ void Filler::_fill_surface_single( all_polylines.reserve(lines.size()); std::transform(lines.begin(), lines.end(), std::back_inserter(all_polylines), [](const Line& l) { return Polyline{ l.a, l.b }; }); // Crop all polylines - all_polylines = intersection_pl(std::move(all_polylines), to_polygons(expolygon)); + all_polylines = intersection_pl(std::move(all_polylines), expolygon); #endif } diff --git a/src/libslic3r/Fill/FillBase.cpp b/src/libslic3r/Fill/FillBase.cpp index b4afd25917..a41a11cb79 100644 --- a/src/libslic3r/Fill/FillBase.cpp +++ b/src/libslic3r/Fill/FillBase.cpp @@ -19,6 +19,8 @@ #include "FillRectilinear.hpp" #include "FillAdaptive.hpp" +// #define INFILL_DEBUG_OUTPUT + namespace Slic3r { Fill* Fill::new_from_type(const InfillPattern type) @@ -41,6 +43,7 @@ Fill* Fill::new_from_type(const InfillPattern type) case ipOctagramSpiral: return new FillOctagramSpiral(); case ipAdaptiveCubic: return new FillAdaptive::Filler(); case ipSupportCubic: return new FillAdaptive::Filler(); + case ipSupportBase: return new FillSupportBase(); default: throw Slic3r::InvalidArgument("unknown type"); } } @@ -253,15 +256,15 @@ std::pair path_lengths_along_contour(const ContourIntersectionPo } // Add contour points from interval (idx_start, idx_end> to polyline. -static inline void take_cw_full(Polyline &pl, const Points& contour, size_t idx_start, size_t idx_end) +static inline void take_cw_full(Polyline &pl, const Points &contour, size_t idx_start, size_t idx_end) { assert(! pl.empty() && pl.points.back() == contour[idx_start]); - size_t i = (idx_end == 0) ? contour.size() - 1 : idx_start - 1; + size_t i = (idx_start == 0) ? contour.size() - 1 : idx_start - 1; while (i != idx_end) { pl.points.emplace_back(contour[i]); if (i == 0) i = contour.size(); - --i; + -- i; } pl.points.emplace_back(contour[i]); } @@ -592,7 +595,6 @@ static inline bool line_rounded_thick_segment_collision( // Very short line vector. Just test whether the center point is inside the offset line. Vec2d lpt = 0.5 * (line_a + line_b); if (segment_l > SCALED_EPSILON) { - struct Linef { Vec2d a, b; }; intersects = line_alg::distance_to_squared(Linef{ segment_a, segment_b }, lpt) < offset2; } else intersects = (0.5 * (segment_a + segment_b) - lpt).squaredNorm() < offset2; @@ -612,13 +614,13 @@ static inline bool line_rounded_thick_segment_collision( }; // Intersections with the inflated segment end points. - auto ray_circle_intersection_interval_extend = [&extend_interval, &line_v0](const Vec2d &segment_pt, const double offset2, const Vec2d &line_pt, const Vec2d &line_vec) { + auto ray_circle_intersection_interval_extend = [&extend_interval](const Vec2d &segment_pt, const double offset2, const Vec2d &line_pt, const Vec2d &line_vec) { std::pair pts; Vec2d p0 = line_pt - segment_pt; - double c = - line_pt.dot(p0); - if (Geometry::ray_circle_intersections_r2_lv2_c(offset2, line_vec.x(), line_vec.y(), line_vec.squaredNorm(), c, pts)) { - double tmin = (pts.first - p0).dot(line_v0); - double tmax = (pts.second - p0).dot(line_v0); + double lv2 = line_vec.squaredNorm(); + if (Geometry::ray_circle_intersections_r2_lv2_c(offset2, line_vec.y(), - line_vec.x(), lv2, - line_vec.y() * p0.x() + line_vec.x() * p0.y(), pts)) { + double tmin = (pts.first - p0).dot(line_vec) / lv2; + double tmax = (pts.second - p0).dot(line_vec) / lv2; if (tmin > tmax) std::swap(tmin, tmax); tmin = std::max(tmin, 0.); @@ -705,8 +707,6 @@ static inline bool cyclic_interval_inside_interval(double outer_low, double oute } #endif // NDEBUG -// #define INFILL_DEBUG_OUTPUT - #ifdef INFILL_DEBUG_OUTPUT static void export_infill_to_svg( // Boundary contour, along which the perimeter extrusions will be drawn. @@ -1099,61 +1099,214 @@ void Fill::connect_infill(Polylines &&infill_ordered, const Polygons &boundary_s connect_infill(std::move(infill_ordered), polygons_src, bbox, polylines_out, spacing, params); } -void Fill::connect_infill(Polylines &&infill_ordered, const std::vector &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms) +static constexpr auto boundary_idx_unconnected = std::numeric_limits::max(); + +struct BoundaryInfillGraph { - assert(! infill_ordered.empty()); - assert(params.anchor_length >= 0.); - assert(params.anchor_length_max >= 0.01f); - assert(params.anchor_length_max >= params.anchor_length); - const double anchor_length = scale_(params.anchor_length); - const double anchor_length_max = scale_(params.anchor_length_max); + std::vector boundary; + std::vector> boundary_params; + std::vector map_infill_end_point_to_boundary; -#if 0 - append(polylines_out, infill_ordered); - return; -#endif + const Point& point(const ContourIntersectionPoint &cp) const { + assert(cp.contour_idx != size_t(-1)); + assert(cp.point_idx != size_t(-1)); + return this->boundary[cp.contour_idx][cp.point_idx]; + } - // 1) Add the end points of infill_ordered to boundary_src. - std::vector boundary; - std::vector> boundary_params; - boundary.assign(boundary_src.size(), Points()); - boundary_params.assign(boundary_src.size(), std::vector()); - // Mapping the infill_ordered end point to a (contour, point) of boundary. - static constexpr auto boundary_idx_unconnected = std::numeric_limits::max(); - std::vector map_infill_end_point_to_boundary(infill_ordered.size() * 2, ContourIntersectionPoint{ boundary_idx_unconnected, boundary_idx_unconnected }); - { - // Project the infill_ordered end points onto boundary_src. - std::vector> intersection_points; - { - EdgeGrid::Grid grid; - grid.set_bbox(bbox.inflated(SCALED_EPSILON)); - grid.create(boundary_src, coord_t(scale_(10.))); - intersection_points.reserve(infill_ordered.size() * 2); - for (const Polyline &pl : infill_ordered) - for (const Point *pt : { &pl.points.front(), &pl.points.back() }) { - EdgeGrid::Grid::ClosestPointResult cp = grid.closest_point_signed_distance(*pt, coord_t(SCALED_EPSILON)); - if (cp.valid()) { - // The infill end point shall lie on the contour. - assert(cp.distance <= 3.); - intersection_points.emplace_back(cp, (&pl - infill_ordered.data()) * 2 + (pt == &pl.points.front() ? 0 : 1)); - } - } - std::sort(intersection_points.begin(), intersection_points.end(), [](const std::pair &cp1, const std::pair &cp2) { - return cp1.first.contour_idx < cp2.first.contour_idx || - (cp1.first.contour_idx == cp2.first.contour_idx && - (cp1.first.start_point_idx < cp2.first.start_point_idx || - (cp1.first.start_point_idx == cp2.first.start_point_idx && cp1.first.t < cp2.first.t))); - }); - } - auto it = intersection_points.begin(); - auto it_end = intersection_points.end(); - std::vector> boundary_intersection_points(boundary.size(), std::vector()); - for (size_t idx_contour = 0; idx_contour < boundary_src.size(); ++ idx_contour) { + const Point& infill_end_point(size_t infill_end_point_idx) const { + return this->point(this->map_infill_end_point_to_boundary[infill_end_point_idx]); + } + + const Point interpolate_contour_point(const ContourIntersectionPoint &cp, double param) { + const Points &contour = this->boundary[cp.contour_idx]; + const std::vector &contour_params = this->boundary_params[cp.contour_idx]; + // Find the start of a contour segment with param. + auto it = std::lower_bound(contour_params.begin(), contour_params.end(), param); + if (*it != param) { + assert(it != contour_params.begin()); + -- it; + } + size_t i = it - contour_params.begin(); + if (i == contour.size()) + i = 0; + double t1 = contour_params[i]; + double t2 = next_value_modulo(i, contour_params); + return lerp(contour[i], next_value_modulo(i, contour), (param - t1) / (t2 - t1)); + } + + enum Direction { + Left, + Right, + Up, + Down, + Taken, + }; + + static Direction dir(const Point &p1, const Point &p2) { + return p1.x() == p2.x() ? + (p1.y() < p2.y() ? Up : Down) : + (p1.x() < p2.x() ? Right : Left); + } + + const Direction dir_prev(const ContourIntersectionPoint &cp) const { + assert(cp.prev_on_contour); + return cp.could_take_prev() ? + dir(this->point(cp), this->point(*cp.prev_on_contour)) : + Taken; + } + + const Direction dir_next(const ContourIntersectionPoint &cp) const { + assert(cp.next_on_contour); + return cp.could_take_next() ? + dir(this->point(cp), this->point(*cp.next_on_contour)) : + Taken; + } + + bool first(const ContourIntersectionPoint &cp) const { + return ((&cp - this->map_infill_end_point_to_boundary.data()) & 1) == 0; + } + + const ContourIntersectionPoint& other(const ContourIntersectionPoint &cp) const { + return this->map_infill_end_point_to_boundary[((&cp - this->map_infill_end_point_to_boundary.data()) ^ 1)]; + } + + ContourIntersectionPoint& other(const ContourIntersectionPoint &cp) { + return this->map_infill_end_point_to_boundary[((&cp - this->map_infill_end_point_to_boundary.data()) ^ 1)]; + } + + bool prev_vertical(const ContourIntersectionPoint &cp) const { + return this->point(cp).x() == this->point(*cp.prev_on_contour).x(); + } + + bool next_vertical(const ContourIntersectionPoint &cp) const { + return this->point(cp).x() == this->point(*cp.next_on_contour).x(); + } + +}; + + +// After mark_boundary_segments_touching_infill() marks boundary segments overlapping trimmed infill lines, +// there are possibly some very short boundary segments unmarked, but overlapping the untrimmed infill lines fully +// Mark those short boundary segments. +static inline void mark_boundary_segments_overlapping_infill( + BoundaryInfillGraph &graph, + // Infill lines, either completely inside the boundary, or touching the boundary. + const Polylines &infill, + // Spacing (width) of the infill lines. + const double spacing) +{ + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + const Points &contour = graph.boundary[cp.contour_idx]; + const std::vector &contour_params = graph.boundary_params[cp.contour_idx]; + const Polyline &infill_polyline = infill[(&cp - graph.map_infill_end_point_to_boundary.data()) / 2]; + const double radius = 0.5 * (spacing + SCALED_EPSILON); + assert(infill_polyline.size() == 2); + const Linef infill_line { infill_polyline.points.front().cast(), infill_polyline.points.back().cast() }; + if (cp.could_take_next()) { + bool inside = true; + for (size_t i = cp.point_idx; i != cp.next_on_contour->point_idx; ) { + size_t j = next_idx_modulo(i, contour); + const Vec2d seg_pt2 = contour[j].cast(); + if (line_alg::distance_to_squared(infill_line, seg_pt2) < radius * radius) { + // The segment is completely inside. + } else { + std::pair interval; + line_rounded_thick_segment_collision(contour[i].cast(), seg_pt2, infill_line.a, infill_line.b, radius, interval); + assert(interval.first == 0.); + double len_out = closed_contour_distance_ccw(contour_params[cp.point_idx], contour_params[i], contour_params.back()) + interval.second; + if (len_out < cp.contour_not_taken_length_next) { + // Leaving the infill line region before exiting cp.contour_not_taken_length_next, + // thus at least some of the contour is outside and we will extrude this segment. + inside = false; + break; + } + } + if (closed_contour_distance_ccw(contour_params[cp.point_idx], contour_params[j], contour_params.back()) >= cp.contour_not_taken_length_next) + break; + i = j; + } + if (inside) { + if (! cp.next_trimmed) + // The arc from cp to cp.next_on_contour was not trimmed yet, however it is completely overlapping the infill line. + cp.next_on_contour->trim_prev(0); + cp.trim_next(0); + } + } else + cp.trim_next(0); + if (cp.could_take_prev()) { + bool inside = true; + for (size_t i = cp.point_idx; i != cp.prev_on_contour->point_idx; ) { + size_t j = prev_idx_modulo(i, contour); + const Vec2d seg_pt2 = contour[j].cast(); + // Distance of the second segment line from the infill line. + if (line_alg::distance_to_squared(infill_line, seg_pt2) < radius * radius) { + // The segment is completely inside. + } else { + std::pair interval; + line_rounded_thick_segment_collision(contour[i].cast(), seg_pt2, infill_line.a, infill_line.b, radius, interval); + assert(interval.first == 0.); + double len_out = closed_contour_distance_cw(contour_params[cp.point_idx], contour_params[i], contour_params.back()) + interval.second; + if (len_out < cp.contour_not_taken_length_prev) { + // Leaving the infill line region before exiting cp.contour_not_taken_length_next, + // thus at least some of the contour is outside and we will extrude this segment. + inside = false; + break; + } + } + if (closed_contour_distance_cw(contour_params[cp.point_idx], contour_params[j], contour_params.back()) >= cp.contour_not_taken_length_prev) + break; + i = j; + } + if (inside) { + if (! cp.prev_trimmed) + // The arc from cp to cp.prev_on_contour was not trimmed yet, however it is completely overlapping the infill line. + cp.prev_on_contour->trim_next(0); + cp.trim_prev(0); + } + } else + cp.trim_prev(0); + } +} + +BoundaryInfillGraph create_boundary_infill_graph(const Polylines &infill_ordered, const std::vector &boundary_src, const BoundingBox &bbox, const double spacing) +{ + BoundaryInfillGraph out; + out.boundary.assign(boundary_src.size(), Points()); + out.boundary_params.assign(boundary_src.size(), std::vector()); + out.map_infill_end_point_to_boundary.assign(infill_ordered.size() * 2, ContourIntersectionPoint{ boundary_idx_unconnected, boundary_idx_unconnected }); + { + // Project the infill_ordered end points onto boundary_src. + std::vector> intersection_points; + { + EdgeGrid::Grid grid; + grid.set_bbox(bbox.inflated(SCALED_EPSILON)); + grid.create(boundary_src, coord_t(scale_(10.))); + intersection_points.reserve(infill_ordered.size() * 2); + for (const Polyline &pl : infill_ordered) + for (const Point *pt : { &pl.points.front(), &pl.points.back() }) { + EdgeGrid::Grid::ClosestPointResult cp = grid.closest_point_signed_distance(*pt, coord_t(SCALED_EPSILON)); + if (cp.valid()) { + // The infill end point shall lie on the contour. + assert(cp.distance <= 3.); + intersection_points.emplace_back(cp, (&pl - infill_ordered.data()) * 2 + (pt == &pl.points.front() ? 0 : 1)); + } + } + std::sort(intersection_points.begin(), intersection_points.end(), [](const std::pair &cp1, const std::pair &cp2) { + return cp1.first.contour_idx < cp2.first.contour_idx || + (cp1.first.contour_idx == cp2.first.contour_idx && + (cp1.first.start_point_idx < cp2.first.start_point_idx || + (cp1.first.start_point_idx == cp2.first.start_point_idx && cp1.first.t < cp2.first.t))); + }); + } + auto it = intersection_points.begin(); + auto it_end = intersection_points.end(); + std::vector> boundary_intersection_points(out.boundary.size(), std::vector()); + for (size_t idx_contour = 0; idx_contour < boundary_src.size(); ++ idx_contour) { // Copy contour_src to contour_dst while adding intersection points. // Map infill end points map_infill_end_point_to_boundary to the newly inserted boundary points of contour_dst. // chain the points of map_infill_end_point_to_boundary along their respective contours. - const Polygon &contour_src = *boundary_src[idx_contour]; - Points &contour_dst = boundary[idx_contour]; + const Polygon &contour_src = *boundary_src[idx_contour]; + Points &contour_dst = out.boundary[idx_contour]; std::vector &contour_intersection_points = boundary_intersection_points[idx_contour]; ContourIntersectionPoint *pfirst = nullptr; ContourIntersectionPoint *pprev = nullptr; @@ -1164,18 +1317,18 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorfirst.contour_idx == idx_contour && it->first.start_point_idx == idx_point; ++ it) { - // Add these points to the destination contour. + contour_dst.emplace_back(ipt); + for (; it != it_end && it->first.contour_idx == idx_contour && it->first.start_point_idx == idx_point; ++ it) { + // Add these points to the destination contour. const Polyline &infill_line = infill_ordered[it->second / 2]; const Point &pt = (it->second & 1) ? infill_line.points.back() : infill_line.points.front(); //#ifndef NDEBUG // { -// const Vec2d pt1 = ipt.cast(); -// const Vec2d pt2 = (idx_point + 1 == contour_src.size() ? contour_src.points.front() : contour_src.points[idx_point + 1]).cast(); +// const Vec2d pt1 = ipt.cast(); +// const Vec2d pt2 = (idx_point + 1 == contour_src.size() ? contour_src.points.front() : contour_src.points[idx_point + 1]).cast(); // const Vec2d ptx = lerp(pt1, pt2, it->first.t); // assert(std::abs(ptx.x() - pt.x()) < SCALED_EPSILON); // assert(std::abs(ptx.y() - pt.y()) < SCALED_EPSILON); @@ -1187,8 +1340,8 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorsecond] = ContourIntersectionPoint{ idx_contour, idx_tjoint_pt }; - ContourIntersectionPoint *pthis = &map_infill_end_point_to_boundary[it->second]; + out.map_infill_end_point_to_boundary[it->second] = ContourIntersectionPoint{ /* it->second, */ idx_contour, idx_tjoint_pt }; + ContourIntersectionPoint *pthis = &out.map_infill_end_point_to_boundary[it->second]; if (pprev) { pprev->next_on_contour = pthis; pthis->prev_on_contour = pprev; @@ -1196,15 +1349,15 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectornext_on_contour = pfirst; pfirst->prev_on_contour = pprev; } - } - // Parametrize the new boundary with the intersection points inserted. - std::vector &contour_params = boundary_params[idx_contour]; - contour_params.assign(contour_dst.size() + 1, 0.); + } + // Parametrize the new boundary with the intersection points inserted. + std::vector &contour_params = out.boundary_params[idx_contour]; + contour_params.assign(contour_dst.size() + 1, 0.); for (size_t i = 1; i < contour_dst.size(); ++i) { contour_params[i] = contour_params[i - 1] + (contour_dst[i].cast() - contour_dst[i - 1].cast()).norm(); assert(contour_params[i] > contour_params[i - 1]); @@ -1225,18 +1378,18 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorcontour_not_taken_length_prev = closed_contour_distance_ccw(ip->prev_on_contour->param, ip->param, contour_length); ip->contour_not_taken_length_next = closed_contour_distance_ccw(ip->param, ip->next_on_contour->param, contour_length); } - } + } - assert(boundary.size() == boundary_src.size()); + assert(out.boundary.size() == boundary_src.size()); #if 0 // Adaptive Cubic Infill produces infill lines, which not always end at the outer boundary. - assert(std::all_of(map_infill_end_point_to_boundary.begin(), map_infill_end_point_to_boundary.end(), - [&boundary](const ContourIntersectionPoint &contour_point) { - return contour_point.contour_idx < boundary.size() && contour_point.point_idx < boundary[contour_point.contour_idx].size(); - })); + assert(std::all_of(out.map_infill_end_point_to_boundary.begin(), out.map_infill_end_point_to_boundary.end(), + [&out.boundary](const ContourIntersectionPoint &contour_point) { + return contour_point.contour_idx < out.boundary.size() && contour_point.point_idx < out.boundary[contour_point.contour_idx].size(); + })); #endif - // Mark the points and segments of split boundary as consumed if they are very close to some of the infill line. + // Mark the points and segments of split out.boundary as consumed if they are very close to some of the infill line. { // @supermerill used 2. * scale_(spacing) const double clip_distance = 1.7 * scale_(spacing); @@ -1244,37 +1397,31 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector merged_with(infill_ordered.size()); + return out; +} + +void Fill::connect_infill(Polylines &&infill_ordered, const std::vector &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms) +{ + assert(! infill_ordered.empty()); + assert(params.anchor_length >= 0.); + assert(params.anchor_length_max >= 0.01f); + assert(params.anchor_length_max >= params.anchor_length); + const double anchor_length = scale_(params.anchor_length); + const double anchor_length_max = scale_(params.anchor_length_max); + +#if 0 + append(polylines_out, infill_ordered); + return; +#endif + + BoundaryInfillGraph graph = create_boundary_infill_graph(infill_ordered, boundary_src, bbox, spacing); + + std::vector merged_with(infill_ordered.size()); std::iota(merged_with.begin(), merged_with.end(), 0); - struct ConnectionCost { - ConnectionCost(size_t idx_first, double cost, bool reversed) : idx_first(idx_first), cost(cost), reversed(reversed) {} - size_t idx_first; - double cost; - bool reversed; - }; - std::vector connections_sorted; - connections_sorted.reserve(infill_ordered.size() * 2 - 2); - for (size_t idx_chain = 1; idx_chain < infill_ordered.size(); ++ idx_chain) { - const ContourIntersectionPoint *cp1 = &map_infill_end_point_to_boundary[(idx_chain - 1) * 2 + 1]; - const ContourIntersectionPoint *cp2 = &map_infill_end_point_to_boundary[idx_chain * 2]; - if (cp1->contour_idx != boundary_idx_unconnected && cp1->contour_idx == cp2->contour_idx) { - // End points on the same contour. Try to connect them. - std::pair len = path_lengths_along_contour(cp1, cp2, boundary_params[cp1->contour_idx].back()); - if (len.first < length_max) - connections_sorted.emplace_back(idx_chain - 1, len.first, false); - if (len.second < length_max) - connections_sorted.emplace_back(idx_chain - 1, len.second, true); - } - } - std::sort(connections_sorted.begin(), connections_sorted.end(), [](const ConnectionCost& l, const ConnectionCost& r) { return l.cost < r.cost; }); auto get_and_update_merged_with = [&merged_with](size_t polyline_idx) -> size_t { for (size_t last = polyline_idx;;) { @@ -1293,9 +1440,35 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector connections_sorted; + connections_sorted.reserve(infill_ordered.size() * 2 - 2); + for (size_t idx_chain = 1; idx_chain < infill_ordered.size(); ++ idx_chain) { + const ContourIntersectionPoint *cp1 = &graph.map_infill_end_point_to_boundary[(idx_chain - 1) * 2 + 1]; + const ContourIntersectionPoint *cp2 = &graph.map_infill_end_point_to_boundary[idx_chain * 2]; + if (cp1->contour_idx != boundary_idx_unconnected && cp1->contour_idx == cp2->contour_idx) { + // End points on the same contour. Try to connect them. + std::pair len = path_lengths_along_contour(cp1, cp2, graph.boundary_params[cp1->contour_idx].back()); + if (len.first < length_max) + connections_sorted.emplace_back(idx_chain - 1, len.first, false); + if (len.second < length_max) + connections_sorted.emplace_back(idx_chain - 1, len.second, true); + } + } + std::sort(connections_sorted.begin(), connections_sorted.end(), [](const ConnectionCost& l, const ConnectionCost& r) { return l.cost < r.cost; }); + for (ConnectionCost &connection_cost : connections_sorted) { - ContourIntersectionPoint *cp1 = &map_infill_end_point_to_boundary[connection_cost.idx_first * 2 + 1]; - ContourIntersectionPoint *cp2 = &map_infill_end_point_to_boundary[(connection_cost.idx_first + 1) * 2]; + ContourIntersectionPoint *cp1 = &graph.map_infill_end_point_to_boundary[connection_cost.idx_first * 2 + 1]; + ContourIntersectionPoint *cp2 = &graph.map_infill_end_point_to_boundary[(connection_cost.idx_first + 1) * 2]; assert(cp1 != cp2); assert(cp1->contour_idx == cp2->contour_idx && cp1->contour_idx != boundary_idx_unconnected); if (cp1->consumed || cp2->consumed) @@ -1306,7 +1479,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorparam, cp_high->param, boundary_params[cp1->contour_idx].back())) < SCALED_EPSILON); + assert(std::abs(length - closed_contour_distance_ccw(cp_low->param, cp_high->param, graph.boundary_params[cp1->contour_idx].back())) < SCALED_EPSILON); could_connect = ! cp_low->next_trimmed && ! cp_high->prev_trimmed; if (could_connect && cp_low->next_on_contour != cp_high) { // Other end of cp1, may or may not be on the same contour as cp1. @@ -1329,14 +1502,14 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectorcontour_idx], cp1, cp2, connection_cost.reversed); + take(infill_ordered[idx_first], infill_ordered[idx_second], graph.boundary[cp1->contour_idx], cp1, cp2, connection_cost.reversed); // Mark the second polygon as merged with the first one. merged_with[idx_second] = merged_with[idx_first]; infill_ordered[idx_second].points.clear(); } else { // Try to connect cp1 resp. cp2 with a piece of perimeter line. - take_limited(infill_ordered[idx_first], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp1, cp2, connection_cost.reversed, anchor_length, line_half_width); - take_limited(infill_ordered[idx_second], boundary[cp1->contour_idx], boundary_params[cp1->contour_idx], cp2, cp1, ! connection_cost.reversed, anchor_length, line_half_width); + take_limited(infill_ordered[idx_first], graph.boundary[cp1->contour_idx], graph.boundary_params[cp1->contour_idx], cp1, cp2, connection_cost.reversed, anchor_length, line_half_width); + take_limited(infill_ordered[idx_second], graph.boundary[cp1->contour_idx], graph.boundary_params[cp1->contour_idx], cp2, cp1, ! connection_cost.reversed, anchor_length, line_half_width); } } #endif @@ -1346,10 +1519,10 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector arches; - arches.reserve(map_infill_end_point_to_boundary.size()); - for (ContourIntersectionPoint &cp : map_infill_end_point_to_boundary) + arches.reserve(graph.map_infill_end_point_to_boundary.size()); + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) if (cp.contour_idx != boundary_idx_unconnected && cp.next_on_contour != &cp && cp.could_connect_next()) - arches.push_back({ &cp, path_length_along_contour_ccw(&cp, cp.next_on_contour, boundary_params[cp.contour_idx].back()) }); + arches.push_back({ &cp, path_length_along_contour_ccw(&cp, cp.next_on_contour, graph.boundary_params[cp.contour_idx].back()) }); std::sort(arches.begin(), arches.end(), [](const auto &l, const auto &r) { return l.arc_length < r.arc_length; }); //FIXME improve the Traveling Salesman problem with 2-opt and 3-opt local optimization. @@ -1358,10 +1531,10 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vectornext_on_contour; - size_t polyline_idx1 = get_and_update_merged_with(((cp1 - map_infill_end_point_to_boundary.data()) / 2)); - size_t polyline_idx2 = get_and_update_merged_with(((cp2 - map_infill_end_point_to_boundary.data()) / 2)); - const Points &contour = boundary[cp1->contour_idx]; - const std::vector &contour_params = boundary_params[cp1->contour_idx]; + size_t polyline_idx1 = get_and_update_merged_with(((cp1 - graph.map_infill_end_point_to_boundary.data()) / 2)); + size_t polyline_idx2 = get_and_update_merged_with(((cp2 - graph.map_infill_end_point_to_boundary.data()) / 2)); + const Points &contour = graph.boundary[cp1->contour_idx]; + const std::vector &contour_params = graph.boundary_params[cp1->contour_idx]; if (polyline_idx1 != polyline_idx2) { Polyline &polyline1 = infill_ordered[polyline_idx1]; Polyline &polyline2 = infill_ordered[polyline_idx2]; @@ -1392,10 +1565,10 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector &contour_params = boundary_params[contour_point.contour_idx]; + const Points &contour = graph.boundary[contour_point.contour_idx]; + const std::vector &contour_params = graph.boundary_params[contour_point.contour_idx]; double lprev = contour_point.could_connect_prev() ? path_length_along_contour_ccw(contour_point.prev_on_contour, &contour_point, contour_params.back()) : @@ -1403,7 +1576,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector::max(); - size_t polyline_idx = get_and_update_merged_with(((&contour_point - map_infill_end_point_to_boundary.data()) / 2)); + size_t polyline_idx = get_and_update_merged_with(((&contour_point - graph.map_infill_end_point_to_boundary.data()) / 2)); Polyline &polyline = infill_ordered[polyline_idx]; assert(! polyline.empty()); assert(contour[contour_point.point_idx] == polyline.points.front() || contour[contour_point.point_idx] == polyline.points.back()); @@ -1415,7 +1588,7 @@ void Fill::connect_infill(Polylines &&infill_ordered, const std::vector &contour_param = graph.boundary_params[cp.contour_idx]; + const Point &pt = contour[cp.point_idx]; + const bool first = graph.first(cp); + int extend_next_idx = -1; + int extend_prev_idx = -1; + coord_t dist_y_prev; + coord_t dist_y_next; + double arc_len_prev; + double arc_len_next; + + if (! graph.next_vertical(cp)){ + size_t i = cp.point_idx; + size_t j = next_idx_modulo(i, contour); + while (j != cp.next_on_contour->point_idx) { + //const Point &p1 = contour[i]; + const Point &p2 = contour[j]; + if (std::abs(p2.x() - pt.x()) > dist_max_x) + break; + i = j; + j = next_idx_modulo(j, contour); + } + if (i != cp.point_idx) { + const Point &p2 = contour[i]; + coord_t dist_y = p2.y() - pt.y(); + if (first) + dist_y = - dist_y; + if (dist_y > dist_min_y) { + arc_len_next = closed_contour_distance_ccw(contour_param[cp.point_idx], contour_param[i], contour_param.back()); + if (arc_len_next < cp.contour_not_taken_length_next) { + extend_next_idx = i; + dist_y_next = dist_y; + } + } + } + } + + if (! graph.prev_vertical(cp)) { + size_t i = cp.point_idx; + size_t j = prev_idx_modulo(i, contour); + while (j != cp.prev_on_contour->point_idx) { + //const Point &p1 = contour[i]; + const Point &p2 = contour[j]; + if (std::abs(p2.x() - pt.x()) > dist_max_x) + break; + i = j; + j = prev_idx_modulo(j, contour); + } + if (i != cp.point_idx) { + const Point &p2 = contour[i]; + coord_t dist_y = p2.y() - pt.y(); + if (first) + dist_y = - dist_y; + if (dist_y > dist_min_y) { + arc_len_prev = closed_contour_distance_ccw(contour_param[i], contour_param[cp.point_idx], contour_param.back()); + if (arc_len_prev < cp.contour_not_taken_length_prev) { + extend_prev_idx = i; + dist_y_prev = dist_y; + } + } + } + } + + if (extend_prev_idx >= 0 && extend_next_idx >= 0) + // Which side to move the point? + dist_y_prev < dist_y_next ? extend_prev_idx : extend_next_idx = -1; + + assert(cp.prev_trimmed == cp.prev_on_contour->next_trimmed); + assert(cp.next_trimmed == cp.next_on_contour->prev_trimmed); + Polyline &infill_line = infill[(&cp - graph.map_infill_end_point_to_boundary.data()) / 2]; + if (extend_prev_idx >= 0) { + if (first) + infill_line.reverse(); + take_cw_full(infill_line, contour, cp.point_idx, extend_prev_idx); + if (first) + infill_line.reverse(); + cp.point_idx = extend_prev_idx; + if (cp.prev_trimmed) + cp.contour_not_taken_length_prev -= arc_len_prev; + else + cp.contour_not_taken_length_prev = cp.prev_on_contour->contour_not_taken_length_next = + closed_contour_distance_ccw(contour_param[cp.prev_on_contour->point_idx], contour_param[cp.point_idx], contour_param.back()); + cp.trim_next(0); + cp.next_on_contour->prev_trimmed = true; + } else if (extend_next_idx >= 0) { + if (first) + infill_line.reverse(); + take_ccw_full(infill_line, contour, cp.point_idx, extend_next_idx); + if (first) + infill_line.reverse(); + cp.point_idx = extend_next_idx; + cp.trim_prev(0); + cp.prev_on_contour->next_trimmed = true; + if (cp.next_trimmed) + cp.contour_not_taken_length_next -= arc_len_next; + else + cp.contour_not_taken_length_next = cp.next_on_contour->contour_not_taken_length_prev = + closed_contour_distance_ccw(contour_param[cp.point_idx], contour_param[cp.next_on_contour->point_idx], contour_param.back()); + } + } +} + +// Called by Fill::connect_base_support() as part of the sparse support infill generator. +// Emit contour loops tracing the contour from tbegin to tend inside a band of (left, right). +// The contour is supposed to enter the "forbidden" zone outside of the (left, right) band at tbegin and also at tend. +static inline void emit_loops_in_band( + // Vertical band, which will trim the contour between tbegin and tend. + coord_t left, + coord_t right, + // Contour and its parametrization. + const Points &contour, + const std::vector &contour_params, + // Span of the parameters of an arch to trim with the vertical band. + double tbegin, + double tend, + // Minimum arch length to put into polylines_out. Shorter arches are not necessary to support a dense support infill. + double min_length, + Polylines &polylines_out) +{ + assert(left < right); + assert(contour.size() + 1 == contour_params.size()); + assert(contour.size() >= 3); +#ifndef NDEBUG + double contour_length = contour_params.back(); + assert(tbegin >= 0 && tbegin < contour_length); + assert(tend >= 0 && tend < contour_length); + assert(min_length > 0); +#endif // NDEBUG + + // Find iterators of the range of segments, where the first and last segment contains tbegin and tend. + size_t ibegin, iend; + { + auto it_begin = std::lower_bound(contour_params.begin(), contour_params.end(), tbegin); + auto it_end = std::lower_bound(contour_params.begin(), contour_params.end(), tend); + assert(it_begin != contour_params.end()); + assert(it_end != contour_params.end()); + if (*it_begin != tbegin) { + assert(it_begin != contour_params.begin()); + -- it_begin; + } + ibegin = it_begin - contour_params.begin(); + iend = it_end - contour_params.begin(); + } + + if (ibegin == contour.size()) + ibegin = 0; + if (iend == contour.size()) + iend = 0; + assert(ibegin != iend); + + // Trim the start and end segment to calculate start and end points. + Point pbegin, pend; + { + double t1 = contour_params[ibegin]; + double t2 = next_value_modulo(ibegin, contour_params); + pbegin = lerp(contour[ibegin], next_value_modulo(ibegin, contour), (tbegin - t1) / (t2 - t1)); + t1 = contour_params[iend]; + t2 = prev_value_modulo(iend, contour_params); + pend = lerp(contour[iend], prev_value_modulo(iend, contour), (tend - t1) / (t2 - t1)); + } + + // Trace the contour from ibegin to iend. + enum Side { + Left, + Right, + Mid, + Unknown + }; + + enum InOutBand { + Entering, + Leaving, + }; + + class State { + public: + State(coord_t left, coord_t right, double min_length, Polylines &polylines_out) : + m_left(left), m_right(right), m_min_length(min_length), m_polylines_out(polylines_out) {} + + void add_inner_point(const Point* p) + { + m_polyline.points.emplace_back(*p); + } + + void add_outer_point(const Point* p) + { + if (m_polyline_end > 0) + m_polyline.points.emplace_back(*p); + } + + void add_interpolated_point(const Point* p1, const Point* p2, Side side, InOutBand inout) + { + assert(side == Left || side == Right); + + coord_t x = side == Left ? m_left : m_right; + coord_t y = p1->y() + coord_t(double(x - p1->x()) * double(p2->y() - p1->y()) / double(p2->x() - p1->x())); + + if (inout == Leaving) { + assert(m_polyline_end == 0); + m_polyline_end = m_polyline.size(); + m_polyline.points.emplace_back(x, y); + } else { + assert(inout == Entering); + if (m_polyline_end > 0) { + if ((this->side1 == Left) == (y - m_polyline.points[m_polyline_end].y() < 0)) { + // Emit the vertical segment. Remove the point, where the source contour was split the last time at m_left / m_right. + m_polyline.points.erase(m_polyline.points.begin() + m_polyline_end); + } else { + // Don't emit the vertical segment, split the contour. + this->finalize(); + m_polyline.points.emplace_back(x, y); + } + m_polyline_end = 0; + } else + m_polyline.points.emplace_back(x, y); + } + }; + + void finalize() + { + m_polyline.points.erase(m_polyline.points.begin() + m_polyline_end, m_polyline.points.end()); + if (! m_polyline.empty()) { + if (! m_polylines_out.empty() && (m_polylines_out.back().points.back() - m_polyline.points.front()).cast().squaredNorm() < SCALED_EPSILON) + m_polylines_out.back().points.insert(m_polylines_out.back().points.end(), m_polyline.points.begin() + 1, m_polyline.points.end()); + else if (m_polyline.length() > m_min_length) + m_polylines_out.emplace_back(std::move(m_polyline)); + m_polyline.clear(); + } + }; + + private: + coord_t m_left; + coord_t m_right; + double m_min_length; + Polylines &m_polylines_out; + + Polyline m_polyline; + size_t m_polyline_end { 0 }; + Polyline m_overlapping; + + public: + Side side1 { Unknown }; + Side side2 { Unknown }; + }; + + State state { left, right, min_length, polylines_out }; + + const Point *p1 = &pbegin; + auto side = [left, right](const Point* p) { + coord_t x = p->x(); + return x < left ? Left : x > right ? Right : Mid; + }; + state.side1 = side(p1); + if (state.side1 == Mid) + state.add_inner_point(p1); + + for (size_t i = ibegin; i != iend; ) { + size_t inext = i + 1; + if (inext == contour.size()) + inext = 0; + const Point *p2 = inext == iend ? &pend : &contour[inext]; + state.side2 = side(p2); + if (state.side1 == Mid) { + if (state.side2 == Mid) { + // Inside the band. + state.add_inner_point(p2); + } else { + // From intisde the band to the outside of the band. + state.add_interpolated_point(p1, p2, state.side2, Leaving); + state.add_outer_point(p2); + } + } else if (state.side2 == Mid) { + // From outside the band into the band. + state.add_interpolated_point(p1, p2, state.side1, Entering); + state.add_inner_point(p2); + } else if (state.side1 != state.side2) { + // Both points outside the band. + state.add_interpolated_point(p1, p2, state.side1, Entering); + state.add_interpolated_point(p1, p2, state.side2, Leaving); + } else { + // Complete segment is outside. + assert((state.side1 == Left && state.side2 == Left) || (state.side1 == Right && state.side2 == Right)); + state.add_outer_point(p2); + } + state.side1 = state.side2; + p1 = p2; + i = inext; + } + state.finalize(); +} + +#ifdef INFILL_DEBUG_OUTPUT +static void export_partial_infill_to_svg(const std::string &path, const BoundaryInfillGraph &graph, const Polylines &infill, const Polylines &emitted) +{ + Polygons polygons; + for (const Points &pts : graph.boundary) + polygons.emplace_back(pts); + BoundingBox bbox = get_extents(polygons); + bbox.merge(get_extents(infill)); + ::Slic3r::SVG svg(path, bbox); + svg.draw(union_ex(polygons)); + svg.draw(infill, "blue"); + svg.draw(emitted, "darkblue"); + for (const ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) + svg.draw(graph.point(cp), cp.consumed ? "red" : "green", scaled(0.2)); + for (const ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + assert(cp.next_trimmed == cp.next_on_contour->prev_trimmed); + assert(cp.prev_trimmed == cp.prev_on_contour->next_trimmed); + if (cp.contour_not_taken_length_next > SCALED_EPSILON) { + Polyline pl { graph.point(cp) }; + take_ccw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.next_on_contour->point_idx, cp.contour_not_taken_length_next); + svg.draw(pl, cp.could_take_next() ? "lime" : "magenta", scaled(0.1)); + } + if (cp.contour_not_taken_length_prev > SCALED_EPSILON) { + Polyline pl { graph.point(cp) }; + take_cw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.prev_on_contour->point_idx, cp.contour_not_taken_length_prev); + svg.draw(pl, cp.could_take_prev() ? "lime" : "magenta", scaled(0.1)); + } + } +} +#endif // INFILL_DEBUG_OUTPUT + +// To classify perimeter segments connecting infill lines, whether they are required for structural stability of the supports. +struct SupportArcCost +{ + // Connecting one end of an infill line to the other end of the same infill line. + bool self_loop { false }; + // Some of the arc touches some infill line. + bool open { false }; + // How needed is this arch for support structural stability. + // Zero means don't take. The higher number, the more likely it is to take the arc. + double cost { 0 }; +}; + +static double evaluate_support_arch_cost(const Polyline &pl) +{ + Point front = pl.points.front(); + Point back = pl.points.back(); + + coord_t ymin = front.y(); + coord_t ymax = back.y(); + if (ymin > ymax) + std::swap(ymin, ymax); + + double dmax = 0; + // Maximum distance in Y axis out of the (ymin, ymax) band and from the (front, back) line. + Linef line { front.cast(), back.cast() }; + for (const Point &pt : pl.points) + dmax = std::max(std::max(dmax, line_alg::distance_to(line, Vec2d(pt.cast()))), std::max(pt.y() - ymax, ymin - pt.y())); + return dmax; +} + +// Costs for prev / next arch of each infill line end point. +static inline std::vector evaluate_support_arches(Polylines &infill, BoundaryInfillGraph &graph, const double spacing, const FillParams ¶ms) +{ + std::vector arches(graph.map_infill_end_point_to_boundary.size() * 2); + + Polyline pl; + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + // Not a losed loop, such loops should already be consumed. + assert(cp.next_on_contour != &cp); + const size_t infill_line_idx = &cp - graph.map_infill_end_point_to_boundary.data(); + const bool first = (infill_line_idx & 1) == 0; + const ContourIntersectionPoint *other_end = first ? &cp + 1 : &cp - 1; + + SupportArcCost &out_prev = arches[infill_line_idx * 2]; + SupportArcCost &out_next = *(&out_prev + 1); + out_prev.self_loop = cp.prev_on_contour == other_end; + out_prev.open = cp.prev_trimmed; + out_next.self_loop = cp.next_on_contour == other_end; + out_next.open = cp.next_trimmed; + + if (cp.contour_not_taken_length_next > SCALED_EPSILON) { + pl.clear(); + pl.points.emplace_back(graph.point(cp)); + if (cp.next_trimmed) + take_ccw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.next_on_contour->point_idx, cp.contour_not_taken_length_next); + else + take_ccw_full(pl, graph.boundary[cp.contour_idx], cp.point_idx, cp.next_on_contour->point_idx); + out_next.cost = evaluate_support_arch_cost(pl); + } + + if (cp.contour_not_taken_length_prev > SCALED_EPSILON) { + pl.clear(); + pl.points.emplace_back(graph.point(cp)); + if (cp.prev_trimmed) + take_cw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.prev_on_contour->point_idx, cp.contour_not_taken_length_prev); + else + take_cw_full(pl, graph.boundary[cp.contour_idx], cp.point_idx, cp.prev_on_contour->point_idx); + out_prev.cost = evaluate_support_arch_cost(pl); + } + } + + return arches; +} + +// Both the poly_with_offset and polylines_out are rotated, so the infill lines are strictly vertical. +void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms) +{ +// assert(! infill_ordered.empty()); + assert(params.anchor_length >= 0.); + assert(params.anchor_length_max >= 0.01f); + assert(params.anchor_length_max >= params.anchor_length); + + BoundaryInfillGraph graph = create_boundary_infill_graph(infill_ordered, boundary_src, bbox, spacing); + +#ifdef INFILL_DEBUG_OUTPUT + static int iRun = 0; + ++ iRun; + export_partial_infill_to_svg(debug_out_path("connect_base_support-initial-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + const double line_half_width = 0.5 * scale_(spacing); + const double line_spacing = scale_(spacing) / params.density; + const double min_arch_length = 1.3 * line_spacing; + const double trim_length = line_half_width * 0.3; + +// After mark_boundary_segments_touching_infill() marks boundary segments overlapping trimmed infill lines, +// there are possibly some very short boundary segments unmarked, but overlapping the untrimmed infill lines fully. +// Mark those short boundary segments. + mark_boundary_segments_overlapping_infill(graph, infill_ordered, scale_(spacing)); + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-marked-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + // Detect loops with zero infill end points connected. + // Extrude these loops as perimeters. + { + std::vector num_boundary_contour_infill_points(graph.boundary.size(), 0); + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) + ++ num_boundary_contour_infill_points[cp.contour_idx]; + for (size_t i = 0; i < num_boundary_contour_infill_points.size(); ++ i) + if (num_boundary_contour_infill_points[i] == 0 && graph.boundary_params[i].back() > trim_length + 0.5 * line_spacing) { + // Emit a perimeter. + Polyline pl(graph.boundary[i]); + pl.points.emplace_back(pl.points.front()); + pl.clip_end(trim_length); + if (pl.size() > 1) + polylines_out.emplace_back(std::move(pl)); + } + } + + // Before processing the boundary arches, emit those arches, which were trimmed by the infill lines at both sides, but which + // depart from the infill line at least once after touching the infill line. + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + if (cp.next_on_contour && cp.next_trimmed && cp.next_on_contour->prev_trimmed) { + // The arch is leaving one infill line to end up at the same infill line or at the neighbouring one. + // The arch is touching one of those infill lines at least once. + // Trace those arches and emit their parts, which are not attached to the end points and they are not overlapping with the two infill lines mentioned. + bool first = graph.first(cp); + coord_t left = graph.point(cp).x(); + coord_t right = left; + if (first) { + left += line_half_width; + right += line_spacing - line_half_width; + } else { + left -= line_spacing - line_half_width; + right -= line_half_width; + } + double param_start = cp.param + cp.contour_not_taken_length_next; + double param_end = cp.next_on_contour->param - cp.next_on_contour->contour_not_taken_length_prev; + double contour_length = graph.boundary_params[cp.contour_idx].back(); + if (param_start >= contour_length) + param_start -= contour_length; + if (param_end < 0) + param_end += contour_length; + // Verify that the interval (param_overlap1, param_overlap2) is inside the interval (ip_low->param, ip_high->param). + assert(cyclic_interval_inside_interval(cp.param, cp.next_on_contour->param, param_start, param_end, contour_length)); + emit_loops_in_band(left, right, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], param_start, param_end, 0.5 * line_spacing, polylines_out); + } + } +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-excess-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + base_support_extend_infill_lines(infill_ordered, graph, spacing, params); + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-extended-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + std::vector merged_with(infill_ordered.size()); + std::iota(merged_with.begin(), merged_with.end(), 0); + auto get_and_update_merged_with = [&graph, &merged_with](const ContourIntersectionPoint *cp) -> size_t { + size_t polyline_idx = (cp - graph.map_infill_end_point_to_boundary.data()) / 2; + for (size_t last = polyline_idx;;) { + size_t lower = merged_with[last]; + assert(lower <= last); + if (lower == last) { + merged_with[polyline_idx] = last; + return last; + } + last = lower; + } + assert(false); + return std::numeric_limits::max(); + }; + + auto vertical = [](BoundaryInfillGraph::Direction dir) { + return dir == BoundaryInfillGraph::Up || dir == BoundaryInfillGraph::Down; + }; + // When both left / right arch connected to cp is vertical (ends up at the same vertical infill line), which one to take? + auto take_vertical_prev = [](const ContourIntersectionPoint &cp) { + return cp.prev_trimmed == cp.next_trimmed ? + // Both are either trimmed or not trimmed. Take the longer contour. + cp.contour_not_taken_length_prev > cp.contour_not_taken_length_next : + // One is trimmed, the other is not trimmed. Take the not trimmed. + ! cp.prev_trimmed && cp.next_trimmed; + }; + + // Connect infill lines at cp and cpo_next_on_contour. + // If the complete arch cannot be taken, then + // if (take_first) + // take the infill line at cp and an arc from cp towards cp.next_on_contour. + // else + // take the infill line at cp_next_on_contour and an arc from cp.next_on_contour towards cp. + // If cp1 == next_on_contour (a single infill line is connected to a contour, this is a valid case for contours with holes), + // then extrude the full circle. + // Nothing is done if the arch could no more be taken (one of it end points were consumed already). + auto take_next = [&graph, &infill_ordered, &merged_with, get_and_update_merged_with, line_half_width, trim_length](ContourIntersectionPoint &cp, bool take_first) { + // Indices of the polylines to be connected by a perimeter segment. + ContourIntersectionPoint *cp1 = &cp; + ContourIntersectionPoint *cp2 = cp.next_on_contour; + assert(cp1->next_trimmed == cp2->prev_trimmed); + //assert(cp1->next_trimmed || cp1->consumed == cp2->consumed); + if (take_first ? cp1->consumed : cp2->consumed) + return; + size_t polyline_idx1 = get_and_update_merged_with(cp1); + size_t polyline_idx2 = get_and_update_merged_with(cp2); + Polyline &polyline1 = infill_ordered[polyline_idx1]; + Polyline &polyline2 = infill_ordered[polyline_idx2]; + const Points &contour = graph.boundary[cp1->contour_idx]; + const std::vector &contour_params = graph.boundary_params[cp1->contour_idx]; + assert(cp1->consumed || contour[cp1->point_idx] == polyline1.points.front() || contour[cp1->point_idx] == polyline1.points.back()); + assert(cp2->consumed || contour[cp2->point_idx] == polyline2.points.front() || contour[cp2->point_idx] == polyline2.points.back()); + bool trimmed = take_first ? cp1->next_trimmed : cp2->prev_trimmed; + if (! trimmed) { + // Trim the end if closing a loop or making a T-joint. + trimmed = cp1 == cp2 || polyline_idx1 == polyline_idx2 || (take_first ? cp2->consumed : cp1->consumed); + if (! trimmed) { + const bool cp1_first = ((cp1 - graph.map_infill_end_point_to_boundary.data()) & 1) == 0; + const ContourIntersectionPoint* cp1_other = cp1_first ? cp1 + 1 : cp1 - 1; + // Self loop, connecting the end points of the same infill line. + trimmed = cp2 == cp1_other; + } + if (trimmed) /* [[unlikely]] */ { + // Single end point on a contour. This may happen on contours with holes. Extrude a loop. + // Or a self loop, connecting the end points of the same infill line. + // Or closing a chain of infill lines. This may happen if infilling a contour with a hole. + double len = cp1 == cp2 ? contour_params.back() : path_length_along_contour_ccw(cp1, cp2, contour_params.back()); + if (take_first) { + cp1->trim_next(std::max(0., len - trim_length - SCALED_EPSILON)); + cp2->trim_prev(0); + } else { + cp1->trim_next(0); + cp2->trim_prev(std::max(0., len - trim_length - SCALED_EPSILON)); + } + } + } + if (trimmed) { + if (take_first) + take_limited(polyline1, contour, contour_params, cp1, cp2, false, 1e10, line_half_width); + else + take_limited(polyline2, contour, contour_params, cp2, cp1, true, 1e10, line_half_width); + } else if (! cp1->consumed && ! cp2->consumed) { + if (contour[cp1->point_idx] == polyline1.points.front()) + polyline1.reverse(); + if (contour[cp2->point_idx] == polyline2.points.back()) + polyline2.reverse(); + take(polyline1, polyline2, contour, cp1, cp2, false); + // Mark the second polygon as merged with the first one. + if (polyline_idx2 < polyline_idx1) { + polyline2 = std::move(polyline1); + polyline1.points.clear(); + merged_with[polyline_idx1] = merged_with[polyline_idx2]; + } else { + polyline2.points.clear(); + merged_with[polyline_idx2] = merged_with[polyline_idx1]; + } + } + }; + + // Consume all vertical arches. If a vertical arch is touching a neighboring vertical infill line, thus the vertical arch is trimmed, + // only consume the trimmed part if it is longer than min_arch_length. + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + assert(cp.contour_idx != boundary_idx_unconnected); + if (cp.consumed) + continue; + const ContourIntersectionPoint &cp_other = graph.other(cp); + assert((cp.next_on_contour == &cp_other) == (cp_other.prev_on_contour == &cp)); + assert((cp.prev_on_contour == &cp_other) == (cp_other.next_on_contour == &cp)); + BoundaryInfillGraph::Direction dir_prev = graph.dir_prev(cp); + BoundaryInfillGraph::Direction dir_next = graph.dir_next(cp); + // Following code will also consume contours with just a single infill line attached. (cp1->next_on_contour == cp1). + assert((cp.next_on_contour == &cp) == (cp.prev_on_contour == &cp)); + bool can_take_prev = vertical(dir_prev) && ! cp.prev_on_contour->consumed && cp.prev_on_contour != &cp_other; + bool can_take_next = vertical(dir_next) && ! cp.next_on_contour->consumed && cp.next_on_contour != &cp_other; + if (can_take_prev && (! can_take_next || take_vertical_prev(cp))) { + if (! cp.prev_trimmed || cp.contour_not_taken_length_prev > min_arch_length) + // take previous + take_next(*cp.prev_on_contour, false); + } else if (can_take_next) { + if (! cp.next_trimmed || cp.contour_not_taken_length_next > min_arch_length) + // take next + take_next(cp, true); + } + } + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-vertical-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + const std::vector arches = evaluate_support_arches(infill_ordered, graph, spacing, params); + static const double cost_low = line_spacing * 1.3; + static const double cost_high = line_spacing * 2.; + static const double cost_veryhigh = line_spacing * 3.; + + { + std::vector selected; + selected.reserve(graph.map_infill_end_point_to_boundary.size()); + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + if (cp.consumed) + continue; + const SupportArcCost &cost_prev = arches[(&cp - graph.map_infill_end_point_to_boundary.data()) * 2]; + const SupportArcCost &cost_next = *(&cost_prev + 1); + double cost_min = cost_prev.cost; + double cost_max = cost_next.cost; + if (cost_min > cost_max) + std::swap(cost_min, cost_max); + if (cost_max < cost_low || cost_min > cost_high) + // Don't take any of the prev / next arches now, take zig-zag instead. It does not matter which one will be taken. + continue; + const double cost_diff_relative = (cost_max - cost_min) / cost_max; + if (cost_diff_relative < 0.25) + // Don't take any of the prev / next arches now, take zig-zag instead. It does not matter which one will be taken. + continue; + if (cost_prev.cost > cost_low) + selected.emplace_back(&cost_prev); + if (cost_next.cost > cost_low) + selected.emplace_back(&cost_next); + } + // Take the longest arch first. + std::sort(selected.begin(), selected.end(), [](const auto *l, const auto *r) { return l->cost > r->cost; }); + // And connect along the arches. + for (const SupportArcCost *arc : selected) { + ContourIntersectionPoint &cp = graph.map_infill_end_point_to_boundary[(arc - arches.data()) / 2]; + if (! cp.consumed) { + bool prev = ((arc - arches.data()) & 1) == 0; + if (prev) + take_next(*cp.prev_on_contour, false); + else + take_next(cp, true); + } + } + } + +#if 0 + { + // Connect infill lines with long horizontal arches. Only take a horizontal arch, if it will not block + // the end caps (vertical arches) at the other side of the infill line. + struct Arc { + ContourIntersectionPoint *intersection; + double arc_length; + bool take_next; + }; + std::vector arches; + arches.reserve(graph.map_infill_end_point_to_boundary.size()); + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + if (cp.consumed) + continue; + // Not a losed loop, such loops should already be consumed. + assert(cp.next_on_contour != &cp); + const bool first = ((&cp - graph.map_infill_end_point_to_boundary.data()) & 1) == 0; + const ContourIntersectionPoint *other_end = first ? &cp + 1 : &cp - 1; + const bool loop_next = cp.next_on_contour == other_end; + if (! loop_next && cp.could_connect_next()) { + if (cp.contour_not_taken_length_next > min_arch_length) { + // Try both directions. This is useful to be able to close a loop back to the same line to take a long arch. + arches.push_back({ &cp, cp.contour_not_taken_length_next, true }); + arches.push_back({ cp.next_on_contour, cp.contour_not_taken_length_next, false }); + } + } else { + //bool first = ((&cp - graph.map_infill_end_point_to_boundary) & 1) == 0; + if (cp.prev_trimmed && cp.could_take_prev()) { + //FIXME trace the trimmed line to decide what priority to assign to it. + // Is the end point close to the current vertical line or to the other vertical line? + const Point &pt = graph.point(cp); + const Point &prev = graph.point(*cp.prev_on_contour); + if (std::abs(pt.x() - prev.x()) < coord_t(0.5 * line_spacing)) { + // End point on the same line. + // Measure maximum distance from the current vertical line. + if (cp.contour_not_taken_length_prev > 0.5 * line_spacing) + arches.push_back({ &cp, cp.contour_not_taken_length_prev, false }); + } else { + // End point on the other line. + if (cp.contour_not_taken_length_prev > min_arch_length) + arches.push_back({ &cp, cp.contour_not_taken_length_prev, false }); + } + } + if (cp.next_trimmed && cp.could_take_next()) { + //FIXME trace the trimmed line to decide what priority to assign to it. + const Point &pt = graph.point(cp); + const Point &next = graph.point(*cp.next_on_contour); + if (std::abs(pt.x() - next.x()) < coord_t(0.5 * line_spacing)) { + // End point on the same line. + // Measure maximum distance from the current vertical line. + if (cp.contour_not_taken_length_next > 0.5 * line_spacing) + arches.push_back({ &cp, cp.contour_not_taken_length_next, true }); + } else { + // End point on the other line. + if (cp.contour_not_taken_length_next > min_arch_length) + arches.push_back({ &cp, cp.contour_not_taken_length_next, true }); + } + } + } + } + // Take the longest arch first. + std::sort(arches.begin(), arches.end(), [](const auto &l, const auto &r) { return l.arc_length > r.arc_length; }); + // And connect along the arches. + for (Arc &arc : arches) + if (arc.take_next) + take_next(*arc.intersection, true); + else + take_next(*arc.intersection->prev_on_contour, false); + } +#endif + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-arches-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + // Traverse the unconnected lines in a zig-zag fashion, left to right only. + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + assert(cp.contour_idx != boundary_idx_unconnected); + if (cp.consumed) + continue; + bool first = ((&cp - graph.map_infill_end_point_to_boundary.data()) & 1) == 0; + if (first) { + // Only connect if the two lines are not connected by the same line already. + if (get_and_update_merged_with(&cp) != get_and_update_merged_with(cp.next_on_contour)) + take_next(cp, true); + } else { + if (get_and_update_merged_with(&cp) != get_and_update_merged_with(cp.prev_on_contour)) + take_next(*cp.prev_on_contour, false); + } + } + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-zigzag-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + // Add the left caps. + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + const bool first = ((&cp - graph.map_infill_end_point_to_boundary.data()) & 1) == 0; + const ContourIntersectionPoint *other_end = first ? &cp + 1 : &cp - 1; + const bool loop_next = cp.next_on_contour == other_end; + const bool loop_prev = other_end->next_on_contour == &cp; +#ifndef NDEBUG + const SupportArcCost &cost_prev = arches[(&cp - graph.map_infill_end_point_to_boundary.data()) * 2]; + const SupportArcCost &cost_next = *(&cost_prev + 1); + assert(cost_prev.self_loop == loop_prev); + assert(cost_next.self_loop == loop_next); +#endif // NDEBUG + if (loop_prev && cp.could_take_prev()) + take_next(*cp.prev_on_contour, false); + if (loop_next && cp.could_take_next()) + take_next(cp, true); + } + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-caps-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + // Connect with T joints using long arches. Loops could be created only if a very long arc has to be added. + { + std::vector candidates; + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + if (cp.could_take_prev()) + candidates.emplace_back(&arches[(&cp - graph.map_infill_end_point_to_boundary.data()) * 2]); + if (cp.could_take_next()) + candidates.emplace_back(&arches[(&cp - graph.map_infill_end_point_to_boundary.data()) * 2 + 1]); + } + std::sort(candidates.begin(), candidates.end(), [](auto *c1, auto *c2) { return c1->cost > c2->cost; }); + for (const SupportArcCost *candidate : candidates) { + ContourIntersectionPoint &cp = graph.map_infill_end_point_to_boundary[(candidate - arches.data()) / 2]; + bool prev = ((candidate - arches.data()) & 1) == 0; + if (prev) { + if (cp.could_take_prev() && (get_and_update_merged_with(&cp) != get_and_update_merged_with(cp.prev_on_contour) || candidate->cost > cost_high)) + take_next(*cp.prev_on_contour, false); + } else { + if (cp.could_take_next() && (get_and_update_merged_with(&cp) != get_and_update_merged_with(cp.next_on_contour) || candidate->cost > cost_high)) + take_next(cp, true); + } + } + } + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-Tjoints-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + // Add very long arches and reasonably long caps even if both of its end points were already consumed. + const double cap_cost = 0.5 * line_spacing; + for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { + const SupportArcCost &cost_prev = arches[(&cp - graph.map_infill_end_point_to_boundary.data()) * 2]; + const SupportArcCost &cost_next = *(&cost_prev + 1); + if (cp.contour_not_taken_length_prev > SCALED_EPSILON && + (cost_prev.self_loop ? + cost_prev.cost > cap_cost : + cost_prev.cost > cost_veryhigh)) { + assert(cp.consumed && (cp.prev_on_contour->consumed || cp.prev_trimmed)); + Polyline pl { graph.point(cp) }; + if (! cp.prev_trimmed) { + cp.trim_prev(cp.contour_not_taken_length_prev - line_half_width); + cp.prev_on_contour->trim_next(0); + } + if (cp.contour_not_taken_length_prev > SCALED_EPSILON) { + take_cw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.prev_on_contour->point_idx, cp.contour_not_taken_length_prev); + cp.trim_prev(0); + pl.clip_start(line_half_width); + polylines_out.emplace_back(std::move(pl)); + } + } + if (cp.contour_not_taken_length_next > SCALED_EPSILON && + (cost_next.self_loop ? + cost_next.cost > cap_cost : + cost_next.cost > cost_veryhigh)) { + assert(cp.consumed && (cp.next_on_contour->consumed || cp.next_trimmed)); + Polyline pl { graph.point(cp) }; + if (! cp.next_trimmed) { + cp.trim_next(cp.contour_not_taken_length_next - line_half_width); + cp.next_on_contour->trim_prev(0); + } + if (cp.contour_not_taken_length_next > SCALED_EPSILON) { + take_ccw_limited(pl, graph.boundary[cp.contour_idx], graph.boundary_params[cp.contour_idx], cp.point_idx, cp.next_on_contour->point_idx, cp.contour_not_taken_length_next); // line_half_width); + cp.trim_next(0); + pl.clip_start(line_half_width); + polylines_out.emplace_back(std::move(pl)); + } + } + } + +#ifdef INFILL_DEBUG_OUTPUT + export_partial_infill_to_svg(debug_out_path("connect_base_support-final-%03d.svg", iRun), graph, infill_ordered, polylines_out); +#endif // INFILL_DEBUG_OUTPUT + + polylines_out.reserve(polylines_out.size() + std::count_if(infill_ordered.begin(), infill_ordered.end(), [](const Polyline &pl) { return ! pl.empty(); })); + for (Polyline &pl : infill_ordered) + if (! pl.empty()) + polylines_out.emplace_back(std::move(pl)); +} + +void Fill::connect_base_support(Polylines &&infill_ordered, const Polygons &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms) +{ + auto polygons_src = reserve_vector(boundary_src.size()); + for (const Polygon &polygon : boundary_src) + polygons_src.emplace_back(&polygon); + + connect_base_support(std::move(infill_ordered), polygons_src, bbox, polylines_out, spacing, params); +} + } // namespace Slic3r diff --git a/src/libslic3r/Fill/FillBase.hpp b/src/libslic3r/Fill/FillBase.hpp index c09b70bca0..eb9c4f1cc3 100644 --- a/src/libslic3r/Fill/FillBase.hpp +++ b/src/libslic3r/Fill/FillBase.hpp @@ -133,26 +133,10 @@ public: static void connect_infill(Polylines &&infill_ordered, const Polygons &boundary, const BoundingBox& bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms); static void connect_infill(Polylines &&infill_ordered, const std::vector &boundary, const BoundingBox &bbox, Polylines &polylines_out, double spacing, const FillParams ¶ms); - static coord_t _adjust_solid_spacing(const coord_t width, const coord_t distance); + static void connect_base_support(Polylines &&infill_ordered, const std::vector &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms); + static void connect_base_support(Polylines &&infill_ordered, const Polygons &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms); - // Align a coordinate to a grid. The coordinate may be negative, - // the aligned value will never be bigger than the original one. - static coord_t _align_to_grid(const coord_t coord, const coord_t spacing) { - // Current C++ standard defines the result of integer division to be rounded to zero, - // for both positive and negative numbers. Here we want to round down for negative - // numbers as well. - coord_t aligned = (coord < 0) ? - ((coord - spacing + 1) / spacing) * spacing : - (coord / spacing) * spacing; - assert(aligned <= coord); - return aligned; - } - static Point _align_to_grid(Point coord, Point spacing) - { return Point(_align_to_grid(coord(0), spacing(0)), _align_to_grid(coord(1), spacing(1))); } - static coord_t _align_to_grid(coord_t coord, coord_t spacing, coord_t base) - { return base + _align_to_grid(coord - base, spacing); } - static Point _align_to_grid(Point coord, Point spacing, Point base) - { return Point(_align_to_grid(coord(0), spacing(0), base(0)), _align_to_grid(coord(1), spacing(1), base(1))); } + static coord_t _adjust_solid_spacing(const coord_t width, const coord_t distance); }; } // namespace Slic3r diff --git a/src/libslic3r/Fill/FillConcentric.cpp b/src/libslic3r/Fill/FillConcentric.cpp index 1b96c43a4d..d5997552b9 100644 --- a/src/libslic3r/Fill/FillConcentric.cpp +++ b/src/libslic3r/Fill/FillConcentric.cpp @@ -24,16 +24,16 @@ void FillConcentric::_fill_surface_single( this->spacing = unscale(distance); } - Polygons loops = to_polygons(std::move(expolygon)); - Polygons last = loops; + Polygons loops = to_polygons(expolygon); + ExPolygons last { std::move(expolygon) }; while (! last.empty()) { - last = offset2(last, -(distance + min_spacing/2), +min_spacing/2); - append(loops, last); + last = offset2_ex(last, -(distance + min_spacing/2), +min_spacing/2); + append(loops, to_polygons(last)); } // generate paths from the outermost to the innermost, to avoid // adhesion problems of the first central tiny loops - loops = union_pt_chained_outside_in(loops, false); + loops = union_pt_chained_outside_in(loops); // split paths using a nearest neighbor search size_t iPathFirst = polylines_out.size(); diff --git a/src/libslic3r/Fill/FillGyroid.cpp b/src/libslic3r/Fill/FillGyroid.cpp index 5797c47a5c..c6510daa2e 100644 --- a/src/libslic3r/Fill/FillGyroid.cpp +++ b/src/libslic3r/Fill/FillGyroid.cpp @@ -166,7 +166,7 @@ void FillGyroid::_fill_surface_single( coord_t distance = coord_t(scale_(this->spacing) / density_adjusted); // align bounding box to a multiple of our grid module - bb.merge(_align_to_grid(bb.min, Point(2*M_PI*distance, 2*M_PI*distance))); + bb.merge(align_to_grid(bb.min, Point(2*M_PI*distance, 2*M_PI*distance))); // generate pattern Polylines polylines = make_gyroid_waves( @@ -180,7 +180,7 @@ void FillGyroid::_fill_surface_single( for (Polyline &pl : polylines) pl.translate(bb.min); - polylines = intersection_pl(polylines, to_polygons(expolygon)); + polylines = intersection_pl(polylines, expolygon); if (! polylines.empty()) { // Remove very small bits, but be careful to not remove infill lines connecting thin walls! diff --git a/src/libslic3r/Fill/FillHoneycomb.cpp b/src/libslic3r/Fill/FillHoneycomb.cpp index 5e70000888..5dc2ed501c 100644 --- a/src/libslic3r/Fill/FillHoneycomb.cpp +++ b/src/libslic3r/Fill/FillHoneycomb.cpp @@ -47,7 +47,7 @@ void FillHoneycomb::_fill_surface_single( // extend bounding box so that our pattern will be aligned with other layers // $bounding_box->[X1] and [Y1] represent the displacement between new bounding box offset and old one // The infill is not aligned to the object bounding box, but to a world coordinate system. Supposedly good enough. - bounding_box.merge(_align_to_grid(bounding_box.min, Point(m.hex_width, m.pattern_height))); + bounding_box.merge(align_to_grid(bounding_box.min, Point(m.hex_width, m.pattern_height))); } coord_t x = bounding_box.min(0); @@ -73,7 +73,7 @@ void FillHoneycomb::_fill_surface_single( } } - all_polylines = intersection_pl(std::move(all_polylines), to_polygons(expolygon)); + all_polylines = intersection_pl(std::move(all_polylines), expolygon); if (params.dont_connect() || all_polylines.size() <= 1) append(polylines_out, chain_polylines(std::move(all_polylines))); else diff --git a/src/libslic3r/Fill/FillLine.cpp b/src/libslic3r/Fill/FillLine.cpp index 1cb9b2244d..f6431a3333 100644 --- a/src/libslic3r/Fill/FillLine.cpp +++ b/src/libslic3r/Fill/FillLine.cpp @@ -31,7 +31,7 @@ void FillLine::_fill_surface_single( } else { // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. - bounding_box.merge(_align_to_grid( + bounding_box.merge(align_to_grid( bounding_box.min, Point(this->_line_spacing, this->_line_spacing), direction.second.rotated(- direction.first))); @@ -58,7 +58,7 @@ void FillLine::_fill_surface_single( pts.push_back(it->a); pts.push_back(it->b); } - Polylines polylines = intersection_pl(polylines_src, offset(to_polygons(expolygon), scale_(0.02)), false); + Polylines polylines = intersection_pl(polylines_src, offset(expolygon, scale_(0.02)), false); // FIXME Vojtech: This is only performed for horizontal lines, not for the vertical lines! const float INFILL_OVERLAP_OVER_SPACING = 0.3f; diff --git a/src/libslic3r/Fill/FillPlanePath.cpp b/src/libslic3r/Fill/FillPlanePath.cpp index 7beaf2f08e..6385a880e9 100644 --- a/src/libslic3r/Fill/FillPlanePath.cpp +++ b/src/libslic3r/Fill/FillPlanePath.cpp @@ -44,7 +44,7 @@ void FillPlanePath::_fill_surface_single( coord_t(floor(pt.x() * distance_between_lines + 0.5)), coord_t(floor(pt.y() * distance_between_lines + 0.5)))); // intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines); - polylines = intersection_pl(std::move(polylines), to_polygons(expolygon)); + polylines = intersection_pl(std::move(polylines), expolygon); Polylines chained; if (params.dont_connect() || params.density > 0.5 || polylines.size() <= 1) chained = chain_polylines(std::move(polylines)); diff --git a/src/libslic3r/Fill/FillRectilinear.cpp b/src/libslic3r/Fill/FillRectilinear.cpp index 07f41de383..baf57f4269 100644 --- a/src/libslic3r/Fill/FillRectilinear.cpp +++ b/src/libslic3r/Fill/FillRectilinear.cpp @@ -798,33 +798,44 @@ static std::vector slice_region_by_vertical_lines(con assert(l <= this_x); assert(r >= this_x); // Calculate the intersection position in y axis. x is known. - if (p1(0) == this_x) { - if (p2(0) == this_x) { + if (p1.x() == this_x) { + if (p2.x() == this_x) { // Ignore strictly vertical segments. continue; } - is.pos_p = p1(1); + const Point &p0 = prev_value_modulo(iPrev, contour); + if (int64_t(p0.x() - p1.x()) * int64_t(p2.x() - p1.x()) > 0) { + // Ignore points of a contour touching the infill line from one side. + continue; + } + is.pos_p = p1.y(); is.pos_q = 1; - } else if (p2(0) == this_x) { - is.pos_p = p2(1); + } else if (p2.x() == this_x) { + const Point &p3 = next_value_modulo(iSegment, contour); + if (int64_t(p3.x() - p2.x()) * int64_t(p1.x() - p2.x()) > 0) { + // Ignore points of a contour touching the infill line from one side. + continue; + } + is.pos_p = p2.y(); is.pos_q = 1; } else { // First calculate the intersection parameter 't' as a rational number with non negative denominator. - if (p2(0) > p1(0)) { - is.pos_p = this_x - p1(0); - is.pos_q = p2(0) - p1(0); + if (p2.x() > p1.x()) { + is.pos_p = this_x - p1.x(); + is.pos_q = p2.x() - p1.x(); } else { - is.pos_p = p1(0) - this_x; - is.pos_q = p1(0) - p2(0); + is.pos_p = p1.x() - this_x; + is.pos_q = p1.x() - p2.x(); } - assert(is.pos_p >= 0 && is.pos_p <= is.pos_q); + assert(is.pos_q > 1); + assert(is.pos_p > 0 && is.pos_p < is.pos_q); // Make an intersection point from the 't'. - is.pos_p *= int64_t(p2(1) - p1(1)); - is.pos_p += p1(1) * int64_t(is.pos_q); + is.pos_p *= int64_t(p2.y() - p1.y()); + is.pos_p += p1.y() * int64_t(is.pos_q); } // +-1 to take rounding into account. - assert(is.pos() + 1 >= std::min(p1(1), p2(1))); - assert(is.pos() <= std::max(p1(1), p2(1)) + 1); + assert(is.pos() + 1 >= std::min(p1.y(), p2.y())); + assert(is.pos() <= std::max(p1.y(), p2.y()) + 1); segs[i].intersections.push_back(is); } } @@ -844,55 +855,46 @@ static std::vector slice_region_by_vertical_lines(con size_t j = 0; for (size_t i = 0; i < sil.intersections.size(); ++ i) { // What is the orientation of the segment at the intersection point? - size_t iContour = sil.intersections[i].iContour; - const Points &contour = poly_with_offset.contour(iContour).points; - size_t iSegment = sil.intersections[i].iSegment; - size_t iPrev = ((iSegment == 0) ? contour.size() : iSegment) - 1; - coord_t dir = contour[iSegment](0) - contour[iPrev](0); - bool low = dir > 0; - sil.intersections[i].type = poly_with_offset.is_contour_outer(iContour) ? + SegmentIntersection &is = sil.intersections[i]; + const size_t iContour = is.iContour; + const Points &contour = poly_with_offset.contour(iContour).points; + const size_t iSegment = is.iSegment; + const size_t iPrev = prev_idx_modulo(iSegment, contour); + const coord_t dir = contour[iSegment].x() - contour[iPrev].x(); + const bool low = dir > 0; + is.type = poly_with_offset.is_contour_outer(iContour) ? (low ? SegmentIntersection::OUTER_LOW : SegmentIntersection::OUTER_HIGH) : (low ? SegmentIntersection::INNER_LOW : SegmentIntersection::INNER_HIGH); - if (j > 0 && sil.intersections[i].iContour == sil.intersections[j-1].iContour) { - // Two successive intersection points on a vertical line with the same contour. This may be a special case. - if (sil.intersections[i].pos() == sil.intersections[j-1].pos()) { - // Two successive segments meet exactly at the vertical line. - #ifdef SLIC3R_DEBUG - // Verify that the segments of sil.intersections[i] and sil.intersections[j-1] are adjoint. - size_t iSegment2 = sil.intersections[j-1].iSegment; - size_t iPrev2 = ((iSegment2 == 0) ? contour.size() : iSegment2) - 1; - assert(iSegment == iPrev2 || iSegment2 == iPrev); - #endif /* SLIC3R_DEBUG */ - if (sil.intersections[i].type == sil.intersections[j-1].type) { + bool take_next = true; + if (j > 0) { + SegmentIntersection &is2 = sil.intersections[j - 1]; + if (iContour == is2.iContour && is.pos_q == 1 && is2.pos_q == 1) { + // Two successive intersection points on a vertical line with the same contour, both points are end points of their respective contour segments. + if (is.pos_p == is2.pos_p) { + // Two successive segments meet exactly at the vertical line. + // Verify that the segments of sil.intersections[i] and sil.intersections[j-1] are adjoint. + assert(iSegment == prev_idx_modulo(is2.iSegment, contour) || is2.iSegment == iPrev); + assert(is.type == is2.type); // Two successive segments of the same direction (both to the right or both to the left) // meet exactly at the vertical line. // Remove the second intersection point. - } else { - // This is a loop returning to the same point. - // It may as well be a vertex of a loop touching this vertical line. - // Remove both the lines. - -- j; + take_next = false; + } else if (is.type == is2.type) { + // Two non successive segments of the same direction (both to the right or both to the left) + // meet exactly at the vertical line. That means there is a Z shaped path, where the center segment + // of the Z shaped path is aligned with this vertical line. + // Remove one of the intersection points while maximizing the vertical segment length. + if (low) { + // Remove the second intersection point, keep the first intersection point. + } else { + // Remove the first intersection point, keep the second intersection point. + sil.intersections[j-1] = sil.intersections[i]; + } + take_next = false; } - } else if (sil.intersections[i].type == sil.intersections[j-1].type) { - // Two non successive segments of the same direction (both to the right or both to the left) - // meet exactly at the vertical line. That means there is a Z shaped path, where the center segment - // of the Z shaped path is aligned with this vertical line. - // Remove one of the intersection points while maximizing the vertical segment length. - if (low) { - // Remove the second intersection point, keep the first intersection point. - } else { - // Remove the first intersection point, keep the second intersection point. - sil.intersections[j-1] = sil.intersections[i]; - } - } else { - // Vertical line intersects a contour segment at a general position (not at one of its end points). - // or the contour just touches this vertical line with a vertical segment or a sequence of vertical segments. - // Keep both intersection points. - if (j < i) - sil.intersections[j] = sil.intersections[i]; - ++ j; } - } else { + } + if (take_next) { // Vertical line intersects a contour segment at a general position (not at one of its end points). if (j < i) sil.intersections[j] = sil.intersections[i]; @@ -905,7 +907,13 @@ static std::vector slice_region_by_vertical_lines(con } // Verify the segments. If something is wrong, give up. -#define ASSERT_THROW(CONDITION) do { assert(CONDITION); if (! (CONDITION)) throw InfillFailedException(); } while (0) +#ifdef INFILL_DEBUG_OUTPUT + #define INFILL_DEBUG_ASSERT(CONDITION) + try { +#else // INFILL_DEBUG_OUTPUT + #define INFILL_DEBUG_ASSERT(CONDITION) assert(CONDITION) +#endif // INFILL_DEBUG_OUTPUT +#define ASSERT_THROW(CONDITION) do { INFILL_DEBUG_ASSERT(CONDITION); if (! (CONDITION)) throw InfillFailedException(); } while (0) for (size_t i_seg = 0; i_seg < segs.size(); ++ i_seg) { SegmentedIntersectionLine &sil = segs[i_seg]; // The intersection points have to be even. @@ -925,6 +933,56 @@ static std::vector slice_region_by_vertical_lines(con } } #undef ASSERT_THROW +#undef INFILL_DEBUG_ASSERT +#ifdef INFILL_DEBUG_OUTPUT + } catch (const InfillFailedException & /* ex */) { + // Export the buggy result into an SVG file. + static int iRun = 0; + BoundingBox bbox = get_extents(poly_with_offset.polygons_src); + bbox.offset(scale_(3.)); + ::Slic3r::SVG svg(debug_out_path("slice_region_by_vertical_lines-failed-%d.svg", iRun ++), bbox); + svg.draw(poly_with_offset.polygons_src); + svg.draw_outline(poly_with_offset.polygons_src, "green"); + svg.draw_outline(poly_with_offset.polygons_outer, "green"); + svg.draw_outline(poly_with_offset.polygons_inner, "green"); + for (size_t i_seg = 0; i_seg < segs.size(); ++i_seg) { + SegmentedIntersectionLine &sil = segs[i_seg]; + for (size_t i = 0; i < sil.intersections.size();) { + // An intersection segment crossing the bigger contour may cross the inner offsetted contour even number of times. + if (sil.intersections[i].type != SegmentIntersection::OUTER_LOW) { + svg.draw(Point(sil.pos, sil.intersections[i].pos()), "red"); + break; + } + size_t j = i + 1; + if (j == sil.intersections.size()) { + svg.draw(Point(sil.pos, sil.intersections[i].pos()), "magenta"); + break; + } + if (! (sil.intersections[j].type == SegmentIntersection::INNER_LOW || sil.intersections[j].type == SegmentIntersection::OUTER_HIGH)) { + svg.draw(Point(sil.pos, sil.intersections[j].pos()), "blue"); + break; + } + for (; j < sil.intersections.size() && sil.intersections[j].is_inner(); ++j); + if (j == sil.intersections.size()) { + svg.draw(Point(sil.pos, sil.intersections[j - 1].pos()), "magenta"); + break; + } + if ((j & 1) != 1 || sil.intersections[j].type != SegmentIntersection::OUTER_HIGH) { + svg.draw(Point(sil.pos, sil.intersections[j].pos()), "red"); + break; + } + if (! (i + 1 == j || sil.intersections[j - 1].type == SegmentIntersection::INNER_HIGH)) { + svg.draw(Point(sil.pos, sil.intersections[j].pos()), "red"); + break; + } + svg.draw(Line(Point(sil.pos, sil.intersections[i].pos()), Point(sil.pos, sil.intersections[j].pos())), "black"); + i = j + 1; + } + } + assert(false); + throw; + } +#endif //INFILL_DEBUG_OUTPUT return segs; } @@ -2714,10 +2772,10 @@ bool FillRectilinear::fill_surface_by_lines(const Surface *surface, const FillPa // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. Point refpt = rotate_vector.second.rotated(- rotate_vector.first); - // _align_to_grid will not work correctly with positive pattern_shift. + // align_to_grid will not work correctly with positive pattern_shift. coord_t pattern_shift_scaled = coord_t(scale_(pattern_shift)) % line_spacing; refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); - bounding_box.merge(_align_to_grid( + bounding_box.merge(align_to_grid( bounding_box.min, Point(line_spacing, line_spacing), refpt)); @@ -2825,6 +2883,45 @@ bool FillRectilinear::fill_surface_by_lines(const Surface *surface, const FillPa return true; } +void make_fill_lines(const ExPolygonWithOffset &poly_with_offset, Point refpt, double angle, coord_t x_margin, coord_t line_spacing, coord_t pattern_shift, Polylines &fill_lines) +{ + BoundingBox bounding_box = poly_with_offset.bounding_box_src(); + // Don't produce infill lines, which fully overlap with the infill perimeter. + coord_t x_min = bounding_box.min.x() + x_margin; + coord_t x_max = bounding_box.max.x() - x_margin; + // extend bounding box so that our pattern will be aligned with other layers + // align_to_grid will not work correctly with positive pattern_shift. + coord_t pattern_shift_scaled = pattern_shift % line_spacing; + refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); + bounding_box.merge(Slic3r::align_to_grid(bounding_box.min, Point(line_spacing, line_spacing), refpt)); + + // Intersect a set of euqally spaced vertical lines wiht expolygon. + // n_vlines = ceil(bbox_width / line_spacing) + const size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing; + const double cos_a = cos(angle); + const double sin_a = sin(angle); + for (const SegmentedIntersectionLine &vline : slice_region_by_vertical_lines(poly_with_offset, n_vlines, bounding_box.min.x(), line_spacing)) + if (vline.pos >= x_min) { + if (vline.pos > x_max) + break; + for (auto it = vline.intersections.begin(); it != vline.intersections.end();) { + auto it_low = it ++; + assert(it_low->type == SegmentIntersection::OUTER_LOW); + if (it_low->type != SegmentIntersection::OUTER_LOW) + continue; + auto it_high = it; + assert(it_high->type == SegmentIntersection::OUTER_HIGH); + if (it_high->type == SegmentIntersection::OUTER_HIGH) { + if (angle == 0.) + fill_lines.emplace_back(Point(vline.pos, it_low->pos()), Point(vline.pos, it_high->pos())); + else + fill_lines.emplace_back(Point(vline.pos, it_low->pos()).rotated(cos_a, sin_a), Point(vline.pos, it_high->pos()).rotated(cos_a, sin_a)); + ++ it; + } + } + } +} + bool FillRectilinear::fill_surface_by_multilines(const Surface *surface, FillParams params, const std::initializer_list &sweep_params, Polylines &polylines_out) { assert(sweep_params.size() > 1); @@ -2843,42 +2940,8 @@ bool FillRectilinear::fill_surface_by_multilines(const Surface *surface, FillPar std::pair rotate_vector = this->_infill_direction(surface); for (const SweepParams &sweep : sweep_params) { // Rotate polygons so that we can work with vertical lines here - double angle = rotate_vector.first + sweep.angle_base; - ExPolygonWithOffset poly_with_offset(poly_with_offset_base, - angle); - BoundingBox bounding_box = poly_with_offset.bounding_box_src(); - // Don't produce infill lines, which fully overlap with the infill perimeter. - coord_t x_min = bounding_box.min.x() + line_width + coord_t(SCALED_EPSILON); - coord_t x_max = bounding_box.max.x() - line_width - coord_t(SCALED_EPSILON); - // extend bounding box so that our pattern will be aligned with other layers - // Transform the reference point to the rotated coordinate system. - Point refpt = rotate_vector.second.rotated(- angle); - // _align_to_grid will not work correctly with positive pattern_shift. - coord_t pattern_shift_scaled = coord_t(scale_(sweep.pattern_shift)) % line_spacing; - refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); - bounding_box.merge(_align_to_grid(bounding_box.min, Point(line_spacing, line_spacing), refpt)); - - // Intersect a set of euqally spaced vertical lines wiht expolygon. - // n_vlines = ceil(bbox_width / line_spacing) - const size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing; - const double cos_a = cos(angle); - const double sin_a = sin(angle); - for (const SegmentedIntersectionLine &vline : slice_region_by_vertical_lines(poly_with_offset, n_vlines, bounding_box.min.x(), line_spacing)) - if (vline.pos > x_min) { - if (vline.pos >= x_max) - break; - for (auto it = vline.intersections.begin(); it != vline.intersections.end();) { - auto it_low = it ++; - assert(it_low->type == SegmentIntersection::OUTER_LOW); - if (it_low->type != SegmentIntersection::OUTER_LOW) - continue; - auto it_high = it; - assert(it_high->type == SegmentIntersection::OUTER_HIGH); - if (it_high->type == SegmentIntersection::OUTER_HIGH) { - fill_lines.emplace_back(Point(vline.pos, it_low->pos()).rotated(cos_a, sin_a), Point(vline.pos, it_high->pos()).rotated(cos_a, sin_a)); - ++ it; - } - } - } + float angle = rotate_vector.first + sweep.angle_base; + make_fill_lines(ExPolygonWithOffset(poly_with_offset_base, - angle), rotate_vector.second.rotated(-angle), angle, line_width + coord_t(SCALED_EPSILON), line_spacing, coord_t(scale_(sweep.pattern_shift)), fill_lines); } if (params.dont_connect() || fill_lines.size() <= 1) { @@ -2954,4 +3017,29 @@ Polylines FillCubic::fill_surface(const Surface *surface, const FillParams ¶ return polylines_out; } +Polylines FillSupportBase::fill_surface(const Surface *surface, const FillParams ¶ms) +{ + assert(! params.full_infill()); + + Polylines polylines_out; + std::pair rotate_vector = this->_infill_direction(surface); + ExPolygonWithOffset poly_with_offset(surface->expolygon, - rotate_vector.first, float(scale_(this->overlap - 0.5 * this->spacing))); + if (poly_with_offset.n_contours > 0) { + Polylines fill_lines; + coord_t line_spacing = coord_t(scale_(this->spacing) / params.density); + // Create infill lines, keep them vertical. + make_fill_lines(poly_with_offset, rotate_vector.second.rotated(- rotate_vector.first), 0, 0, line_spacing, 0, fill_lines); + // Both the poly_with_offset and polylines_out are rotated, so the infill lines are strictly vertical. + connect_base_support(std::move(fill_lines), poly_with_offset.polygons_outer, poly_with_offset.bounding_box_outer(), polylines_out, this->spacing, params); + // Rotate back by rotate_vector.first + const double cos_a = cos(rotate_vector.first); + const double sin_a = sin(rotate_vector.first); + for (Polyline &pl : polylines_out) + for (Point &pt : pl.points) + pt.rotate(cos_a, sin_a); + } + return polylines_out; +} + } // namespace Slic3r + diff --git a/src/libslic3r/Fill/FillRectilinear.hpp b/src/libslic3r/Fill/FillRectilinear.hpp index 692fba2bd1..ad32ad20f3 100644 --- a/src/libslic3r/Fill/FillRectilinear.hpp +++ b/src/libslic3r/Fill/FillRectilinear.hpp @@ -97,6 +97,17 @@ protected: float _layer_angle(size_t idx) const override { return 0.f; } }; +class FillSupportBase : public FillRectilinear +{ +public: + Fill* clone() const override { return new FillSupportBase(*this); } + ~FillSupportBase() override = default; + Polylines fill_surface(const Surface *surface, const FillParams ¶ms) override; + +protected: + // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill. + float _layer_angle(size_t idx) const override { return 0.f; } +}; } // namespace Slic3r diff --git a/src/libslic3r/Flow.cpp b/src/libslic3r/Flow.cpp index 1645bf683a..9f4730261e 100644 --- a/src/libslic3r/Flow.cpp +++ b/src/libslic3r/Flow.cpp @@ -89,18 +89,11 @@ double Flow::extrusion_width(const std::string& opt_key, const ConfigOptionFloat if (opt->percent) { auto opt_key_layer_height = first_layer ? "first_layer_height" : "layer_height"; - auto opt_layer_height = config.option(opt_key_layer_height); + auto opt_layer_height = config.option(opt_key_layer_height); if (opt_layer_height == nullptr) throw_on_missing_variable(opt_key, opt_key_layer_height); - double layer_height = opt_layer_height->getFloat(); - if (first_layer && static_cast(opt_layer_height)->percent) { - // first_layer_height depends on layer_height. - opt_layer_height = config.option("layer_height"); - if (opt_layer_height == nullptr) - throw_on_missing_variable(opt_key, "layer_height"); - layer_height *= 0.01 * opt_layer_height->getFloat(); - } - return opt->get_abs_value(layer_height); + assert(! first_layer || ! static_cast(opt_layer_height)->percent); + return opt->get_abs_value(opt_layer_height->getFloat()); } if (opt->value == 0.) { @@ -238,13 +231,14 @@ Flow support_material_flow(const PrintObject *object, float layer_height) Flow support_material_1st_layer_flow(const PrintObject *object, float layer_height) { - const auto &width = (object->print()->config().first_layer_extrusion_width.value > 0) ? object->print()->config().first_layer_extrusion_width : object->config().support_material_extrusion_width; + const PrintConfig &print_config = object->print()->config(); + const auto &width = (print_config.first_layer_extrusion_width.value > 0) ? print_config.first_layer_extrusion_width : object->config().support_material_extrusion_width; return Flow::new_from_config_width( frSupportMaterial, // The width parameter accepted by new_from_config_width is of type ConfigOptionFloatOrPercent, the Flow class takes care of the percent to value substitution. (width.value > 0) ? width : object->config().extrusion_width, - float(object->print()->config().nozzle_diameter.get_at(object->config().support_material_extruder-1)), - (layer_height > 0.f) ? layer_height : float(object->config().first_layer_height.get_abs_value(object->config().layer_height.value))); + float(print_config.nozzle_diameter.get_at(object->config().support_material_extruder-1)), + (layer_height > 0.f) ? layer_height : float(print_config.first_layer_height.get_abs_value(object->config().layer_height.value))); } Flow support_material_interface_flow(const PrintObject *object, float layer_height) diff --git a/src/libslic3r/Format/SL1.cpp b/src/libslic3r/Format/SL1.cpp index f048551826..4038cb0467 100644 --- a/src/libslic3r/Format/SL1.cpp +++ b/src/libslic3r/Format/SL1.cpp @@ -87,7 +87,7 @@ PNGBuffer read_png(const mz_zip_archive_file_stat &entry, } ArchiveData extract_sla_archive(const std::string &zipfname, - const std::string &exclude) + const std::string &exclude) { ArchiveData arch; @@ -248,7 +248,7 @@ std::vector extract_slices_from_sla_archive( { double incr, val, prev; bool stop = false; - tbb::spin_mutex mutex; + tbb::spin_mutex mutex = {}; } st {100. / slices.size(), 0., 0.}; tbb::parallel_for(size_t(0), arch.images.size(), @@ -371,6 +371,13 @@ void fill_iniconf(ConfMap &m, const SLAPrint &print) m["numSlow"] = std::to_string(stats.slow_layers_count); m["numFast"] = std::to_string(stats.fast_layers_count); m["printTime"] = std::to_string(stats.estimated_print_time); + + bool hollow_en = false; + auto it = print.objects().begin(); + while (!hollow_en && it != print.objects().end()) + hollow_en = (*it++)->config().hollowing_enable; + + m["hollow"] = hollow_en ? "1" : "0"; m["action"] = "print"; } diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index d7e72b4ade..c5b28b3a01 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -435,19 +435,18 @@ namespace Slic3r { { std::string gcode; assert(m_layer_idx >= 0); - if (!m_brim_done || gcodegen.writer().need_toolchange(extruder_id) || finish_layer) { + if (gcodegen.writer().need_toolchange(extruder_id) || finish_layer) { if (m_layer_idx < (int)m_tool_changes.size()) { if (!(size_t(m_tool_change_idx) < m_tool_changes[m_layer_idx].size())) throw Slic3r::RuntimeError("Wipe tower generation failed, possibly due to empty first layer."); - // Calculate where the wipe tower layer will be printed. -1 means that print z will not change, // resulting in a wipe tower with sparse layers. double wipe_tower_z = -1; bool ignore_sparse = false; if (gcodegen.config().wipe_tower_no_sparse_layers.value) { wipe_tower_z = m_last_wipe_tower_print_z; - ignore_sparse = (m_brim_done && m_tool_changes[m_layer_idx].size() == 1 && m_tool_changes[m_layer_idx].front().initial_tool == m_tool_changes[m_layer_idx].front().new_tool); + ignore_sparse = (m_tool_changes[m_layer_idx].size() == 1 && m_tool_changes[m_layer_idx].front().initial_tool == m_tool_changes[m_layer_idx].front().new_tool); if (m_tool_change_idx == 0 && !ignore_sparse) wipe_tower_z = m_last_wipe_tower_print_z + m_tool_changes[m_layer_idx].front().layer_height; } @@ -457,7 +456,6 @@ namespace Slic3r { m_last_wipe_tower_print_z = wipe_tower_z; } } - m_brim_done = true; } return gcode; } @@ -786,7 +784,8 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re namespace DoExport { static void init_gcode_processor(const PrintConfig& config, GCodeProcessor& processor, bool& silent_time_estimator_enabled) { - silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlin) && config.silent_mode; + silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware) + && config.silent_mode; processor.reset(); processor.apply_config(config); processor.enable_stealth_time_estimator(silent_time_estimator_enabled); @@ -1112,7 +1111,8 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu // Write some terse information on the slicing parameters. const PrintObject *first_object = print.objects().front(); const double layer_height = first_object->config().layer_height.value; - const double first_layer_height = first_object->config().first_layer_height.get_abs_value(layer_height); + assert(! print.config().first_layer_height.percent); + const double first_layer_height = print.config().first_layer_height.value; for (const PrintRegion* region : print.regions()) { _write_format(file, "; external perimeters extrusion width = %.2fmm\n", region->flow(*first_object, frExternalPerimeter, layer_height).width()); _write_format(file, "; perimeters extrusion width = %.2fmm\n", region->flow(*first_object, frPerimeter, layer_height).width()); @@ -1357,7 +1357,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu bbox_prime.offset(0.5f); bool overlap = bbox_prime.overlap(bbox_print); - if (print.config().gcode_flavor == gcfMarlin) { + if (print.config().gcode_flavor == gcfMarlinLegacy || print.config().gcode_flavor == gcfMarlinFirmware) { _write(file, this->retract()); _write(file, "M300 S800 P500\n"); // Beep for 500ms, tone 800Hz. if (overlap) { @@ -1560,7 +1560,8 @@ static bool custom_gcode_sets_temperature(const std::string &gcode, const int mc // Do not process this piece of G-code by the time estimator, it already knows the values through another sources. void GCode::print_machine_envelope(FILE *file, Print &print) { - if (print.config().gcode_flavor.value == gcfMarlin && print.config().machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) { + if ((print.config().gcode_flavor.value == gcfMarlinLegacy || print.config().gcode_flavor.value == gcfMarlinFirmware) + && print.config().machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) { fprintf(file, "M201 X%d Y%d Z%d E%d ; sets maximum accelerations, mm/sec^2\n", int(print.config().machine_max_acceleration_x.values.front() + 0.5), int(print.config().machine_max_acceleration_y.values.front() + 0.5), @@ -1571,10 +1572,20 @@ void GCode::print_machine_envelope(FILE *file, Print &print) int(print.config().machine_max_feedrate_y.values.front() + 0.5), int(print.config().machine_max_feedrate_z.values.front() + 0.5), int(print.config().machine_max_feedrate_e.values.front() + 0.5)); + + // Now M204 - acceleration. This one is quite hairy thanks to how Marlin guys care about + // backwards compatibility: https://github.com/prusa3d/PrusaSlicer/issues/1089 + // Legacy Marlin should export travel acceleration the same as printing acceleration. + // MarlinFirmware has the two separated. + int travel_acc = print.config().gcode_flavor == gcfMarlinLegacy + ? int(print.config().machine_max_acceleration_extruding.values.front() + 0.5) + : int(print.config().machine_max_acceleration_travel.values.front() + 0.5); fprintf(file, "M204 P%d R%d T%d ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2\n", int(print.config().machine_max_acceleration_extruding.values.front() + 0.5), int(print.config().machine_max_acceleration_retracting.values.front() + 0.5), - int(print.config().machine_max_acceleration_extruding.values.front() + 0.5)); + travel_acc); + + fprintf(file, "M205 X%.2lf Y%.2lf Z%.2lf E%.2lf ; sets the jerk limits, mm/sec\n", print.config().machine_max_jerk_x.values.front(), print.config().machine_max_jerk_y.values.front(), @@ -1768,6 +1779,10 @@ namespace ProcessLayer else { gcode += gcodegen.placeholder_parser_process("color_change_gcode", config.color_change_gcode, current_extruder_id); gcode += "\n"; + //FIXME Tell G-code writer that M600 filled the extruder, thus the G-code writer shall reset the extruder to unretracted state after + // return from M600. Thus the G-code generated by the following line is ignored. + // see GH issue #6362 + gcodegen.writer().unretract(); } } else { diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 9ecabd47df..08ab830024 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -75,8 +75,8 @@ public: m_tool_changes(tool_changes), m_final_purge(final_purge), m_layer_idx(-1), - m_tool_change_idx(0), - m_brim_done(false) {} + m_tool_change_idx(0) + {} std::string prime(GCode &gcodegen); void next_layer() { ++ m_layer_idx; m_tool_change_idx = 0; } @@ -105,8 +105,6 @@ private: // Current layer index. int m_layer_idx; int m_tool_change_idx; - bool m_brim_done; - bool i_have_brim = false; double m_last_wipe_tower_print_z = 0.f; }; diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index 7f48aae808..07b9b07bbc 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -326,7 +326,7 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: PerExtruderAdjustments *adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]]; const char *line_start = gcode.c_str(); const char *line_end = line_start; - const char extrusion_axis = config.get_extrusion_axis()[0]; + const char extrusion_axis = get_extrusion_axis(config)[0]; // Index of an existing CoolingLine of the current adjustment, which holds the feedrate setting command // for a sequence of extrusion moves. size_t active_speed_modifier = size_t(-1); diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 7c89cf467f..006595eb7d 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -26,6 +26,7 @@ static const float INCHES_TO_MM = 25.4f; static const float MMMIN_TO_MMSEC = 1.0f / 60.0f; static const float DEFAULT_ACCELERATION = 1500.0f; // Prusa Firmware 1_75mm_MK2 +static const float DEFAULT_TRAVEL_ACCELERATION = 1250.0f; namespace Slic3r { @@ -190,6 +191,8 @@ void GCodeProcessor::TimeMachine::reset() enabled = false; acceleration = 0.0f; max_acceleration = 0.0f; + travel_acceleration = 0.0f; + max_travel_acceleration = 0.0f; extrude_factor_override_percentage = 1.0f; time = 0.0f; #if ENABLE_EXTENDED_M73_LINES @@ -823,8 +826,13 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_filament_diameters[i] = static_cast(config.filament_diameter.values[i]); } - if (m_flavor == gcfMarlin && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) + if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) { m_time_processor.machine_limits = reinterpret_cast(config); + if (m_flavor == gcfMarlinLegacy) { + // Legacy Marlin does not have separate travel acceleration, it uses the 'extruding' value instead. + m_time_processor.machine_limits.machine_max_acceleration_travel = m_time_processor.machine_limits.machine_max_acceleration_extruding; + } + } // Filament load / unload times are not specific to a firmware flavor. Let anybody use it if they find it useful. // As of now the fields are shown at the UI dialog in the same combo box as the ramming values, so they @@ -842,10 +850,19 @@ void GCodeProcessor::apply_config(const PrintConfig& config) float max_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_extruding, i); m_time_processor.machines[i].max_acceleration = max_acceleration; m_time_processor.machines[i].acceleration = (max_acceleration > 0.0f) ? max_acceleration : DEFAULT_ACCELERATION; + float max_travel_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_travel, i); + m_time_processor.machines[i].max_travel_acceleration = max_travel_acceleration; + m_time_processor.machines[i].travel_acceleration = (max_travel_acceleration > 0.0f) ? max_travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; } m_time_processor.export_remaining_time_enabled = config.remaining_times.value; m_use_volumetric_e = config.use_volumetric_e; + +#if ENABLE_START_GCODE_VISUALIZATION + const ConfigOptionFloatOrPercent* first_layer_height = config.option("first_layer_height"); + if (first_layer_height != nullptr) + m_first_layer_height = std::abs(first_layer_height->value); +#endif // ENABLE_START_GCODE_VISUALIZATION } void GCodeProcessor::apply_config(const DynamicPrintConfig& config) @@ -934,7 +951,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) } } - if (m_flavor == gcfMarlin) { + if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) { const ConfigOptionFloats* machine_max_acceleration_x = config.option("machine_max_acceleration_x"); if (machine_max_acceleration_x != nullptr) m_time_processor.machine_limits.machine_max_acceleration_x.values = machine_max_acceleration_x->values; @@ -991,6 +1008,15 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) if (machine_max_acceleration_retracting != nullptr) m_time_processor.machine_limits.machine_max_acceleration_retracting.values = machine_max_acceleration_retracting->values; + + // Legacy Marlin does not have separate travel acceleration, it uses the 'extruding' value instead. + const ConfigOptionFloats* machine_max_acceleration_travel = config.option(m_flavor == gcfMarlinLegacy + ? "machine_max_acceleration_extruding" + : "machine_max_acceleration_travel"); + if (machine_max_acceleration_travel != nullptr) + m_time_processor.machine_limits.machine_max_acceleration_travel.values = machine_max_acceleration_travel->values; + + const ConfigOptionFloats* machine_min_extruding_rate = config.option("machine_min_extruding_rate"); if (machine_min_extruding_rate != nullptr) m_time_processor.machine_limits.machine_min_extruding_rate.values = machine_min_extruding_rate->values; @@ -1004,6 +1030,9 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) float max_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_extruding, i); m_time_processor.machines[i].max_acceleration = max_acceleration; m_time_processor.machines[i].acceleration = (max_acceleration > 0.0f) ? max_acceleration : DEFAULT_ACCELERATION; + float max_travel_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_travel, i); + m_time_processor.machines[i].max_travel_acceleration = max_travel_acceleration; + m_time_processor.machines[i].travel_acceleration = (max_travel_acceleration > 0.0f) ? max_travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; } if (m_time_processor.machine_limits.machine_max_acceleration_x.values.size() > 1) @@ -1012,6 +1041,12 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) const ConfigOptionBool* use_volumetric_e = config.option("use_volumetric_e"); if (use_volumetric_e != nullptr) m_use_volumetric_e = use_volumetric_e->value; + +#if ENABLE_START_GCODE_VISUALIZATION + const ConfigOptionFloatOrPercent* first_layer_height = config.option("first_layer_height"); + if (first_layer_height != nullptr) + m_first_layer_height = std::abs(first_layer_height->value); +#endif // ENABLE_START_GCODE_VISUALIZATION } void GCodeProcessor::enable_stealth_time_estimator(bool enabled) @@ -1037,6 +1072,9 @@ void GCodeProcessor::reset() #if ENABLE_GCODE_LINES_ID_IN_H_SLIDER m_line_id = 0; +#if ENABLE_SEAMS_VISUALIZATION + m_last_line_id = 0; +#endif // ENABLE_SEAMS_VISUALIZATION #endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER m_feedrate = 0.0f; m_width = 0.0f; @@ -1059,6 +1097,10 @@ void GCodeProcessor::reset() m_filament_diameters = std::vector(Min_Extruder_Count, 1.75f); m_extruded_last_z = 0.0f; +#if ENABLE_START_GCODE_VISUALIZATION + m_first_layer_height = 0.0f; + m_processing_start_custom_gcode = false; +#endif // ENABLE_START_GCODE_VISUALIZATION m_g1_line_id = 0; m_layer_id = 0; m_cp_color.reset(); @@ -1420,6 +1462,13 @@ void GCodeProcessor::process_tags(const std::string_view comment) // extrusion role tag if (boost::starts_with(comment, reserved_tag(ETags::Role))) { m_extrusion_role = ExtrusionEntity::string_to_role(comment.substr(reserved_tag(ETags::Role).length())); +#if ENABLE_SEAMS_VISUALIZATION + if (m_extrusion_role == erExternalPerimeter) + m_seams_detector.activate(true); +#endif // ENABLE_SEAMS_VISUALIZATION +#if ENABLE_START_GCODE_VISUALIZATION + m_processing_start_custom_gcode = (m_extrusion_role == erCustom && m_g1_line_id == 0); +#endif // ENABLE_START_GCODE_VISUALIZATION return; } @@ -1646,23 +1695,23 @@ bool GCodeProcessor::process_cura_tags(const std::string_view comment) if (pos != comment.npos) { const std::string_view flavor = comment.substr(pos + tag.length()); if (flavor == "BFB") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Mach3") m_flavor = gcfMach3; else if (flavor == "Makerbot") m_flavor = gcfMakerWare; else if (flavor == "UltiGCode") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Marlin(Volumetric)") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Griffin") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Repetier") m_flavor = gcfRepetier; else if (flavor == "RepRap") m_flavor = gcfRepRapFirmware; else if (flavor == "Marlin") - m_flavor = gcfMarlin; + m_flavor = gcfMarlinLegacy; else BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown flavor: " << flavor; @@ -2164,7 +2213,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING } +#if ENABLE_START_GCODE_VISUALIZATION + if (type == EMoveType::Extrude && (m_width == 0.0f || m_height == 0.0f)) +#else if (type == EMoveType::Extrude && (m_extrusion_role == erCustom || m_width == 0.0f || m_height == 0.0f)) +#endif // ENABLE_START_GCODE_VISUALIZATION type = EMoveType::Travel; // time estimate section @@ -2226,9 +2279,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) } // calculates block acceleration - float acceleration = is_extrusion_only_move(delta_pos) ? - get_retract_acceleration(static_cast(i)) : - get_acceleration(static_cast(i)); + float acceleration = + (type == EMoveType::Travel) ? get_travel_acceleration(static_cast(i)) : + (is_extrusion_only_move(delta_pos) ? + get_retract_acceleration(static_cast(i)) : + get_acceleration(static_cast(i))); for (unsigned char a = X; a <= E; ++a) { float axis_max_acceleration = get_axis_max_acceleration(static_cast(i), static_cast(a)); @@ -2278,13 +2333,13 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) // Calculate the jerk depending on whether the axis is coasting in the same direction or reversing a direction. float jerk = (v_exit > v_entry) ? - (((v_entry > 0.0f) || (v_exit < 0.0f)) ? + ((v_entry > 0.0f || v_exit < 0.0f) ? // coasting (v_exit - v_entry) : // axis reversal std::max(v_exit, -v_entry)) : // v_exit <= v_entry - (((v_entry < 0.0f) || (v_exit > 0.0f)) ? + ((v_entry < 0.0f || v_exit > 0.0f) ? // coasting (v_entry - v_exit) : // axis reversal @@ -2305,7 +2360,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) float vmax_junction_threshold = vmax_junction * 0.99f; // Not coasting. The machine will stop and start the movements anyway, better to start the segment from start. - if ((prev.safe_feedrate > vmax_junction_threshold) && (curr.safe_feedrate > vmax_junction_threshold)) + if (prev.safe_feedrate > vmax_junction_threshold && curr.safe_feedrate > vmax_junction_threshold) vmax_junction = curr.safe_feedrate; } @@ -2329,6 +2384,31 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) machine.calculate_time(TimeProcessor::Planner::queue_size); } +#if ENABLE_SEAMS_VISUALIZATION + // check for seam starting vertex + if (type == EMoveType::Extrude && m_extrusion_role == erExternalPerimeter && m_seams_detector.is_active() && !m_seams_detector.has_first_vertex()) + m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]); + // check for seam ending vertex and store the resulting move + else if ((type != EMoveType::Extrude || m_extrusion_role != erExternalPerimeter) && m_seams_detector.is_active()) { + auto set_end_position = [this](const Vec3f& pos) { + m_end_position[X] = pos.x(); m_end_position[Y] = pos.y(); m_end_position[Z] = pos.z(); + }; + + assert(m_seams_detector.has_first_vertex()); + const Vec3f curr_pos(m_end_position[X], m_end_position[Y], m_end_position[Z]); + const Vec3f new_pos = m_result.moves.back().position - m_extruder_offsets[m_extruder_id]; + const std::optional first_vertex = m_seams_detector.get_first_vertex(); + // the threshold value = 0.25 is arbitrary, we may find some smarter condition later + if ((new_pos - *first_vertex).norm() < 0.25f) { + set_end_position(0.5f * (new_pos + *first_vertex)); + store_move_vertex(EMoveType::Seam); + set_end_position(curr_pos); + } + + m_seams_detector.activate(false); + } +#endif // ENABLE_SEAMS_VISUALIZATION + // store move store_move_vertex(type); } @@ -2575,7 +2655,7 @@ void GCodeProcessor::process_M203(const GCodeReader::GCodeLine& line) // see http://reprap.org/wiki/G-code#M203:_Set_maximum_feedrate // http://smoothieware.org/supported-g-codes - float factor = (m_flavor == gcfMarlin || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; + float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; for (size_t i = 0; i < static_cast(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) { if (static_cast(i) == PrintEstimatedTimeStatistics::ETimeMode::Normal || @@ -2602,10 +2682,11 @@ void GCodeProcessor::process_M204(const GCodeReader::GCodeLine& line) if (static_cast(i) == PrintEstimatedTimeStatistics::ETimeMode::Normal || m_time_processor.machine_envelope_processing_enabled) { if (line.has_value('S', value)) { - // Legacy acceleration format. This format is used by the legacy Marlin, MK2 or MK3 firmware, - // and it is also generated by Slic3r to control acceleration per extrusion type - // (there is a separate acceleration settings in Slicer for perimeter, first layer etc). + // Legacy acceleration format. This format is used by the legacy Marlin, MK2 or MK3 firmware + // It is also generated by PrusaSlicer to control acceleration per extrusion type + // (perimeters, first layer etc) when 'Marlin (legacy)' flavor is used. set_acceleration(static_cast(i), value); + set_travel_acceleration(static_cast(i), value); if (line.has_value('T', value)) set_option_value(m_time_processor.machine_limits.machine_max_acceleration_retracting, i, value); } @@ -2615,11 +2696,9 @@ void GCodeProcessor::process_M204(const GCodeReader::GCodeLine& line) set_acceleration(static_cast(i), value); if (line.has_value('R', value)) set_option_value(m_time_processor.machine_limits.machine_max_acceleration_retracting, i, value); - if (line.has_value('T', value)) { + if (line.has_value('T', value)) // Interpret the T value as the travel acceleration in the new Marlin format. - //FIXME Prusa3D firmware currently does not support travel acceleration value independent from the extruding acceleration value. - // set_travel_acceleration(value); - } + set_travel_acceleration(static_cast(i), value); } } } @@ -2749,7 +2828,7 @@ void GCodeProcessor::process_T(const std::string_view command) int eid = 0; if (! parse_number(command.substr(1), eid) || eid < 0 || eid > 255) { // Specific to the MMU2 V2 (see https://www.help.prusa3d.com/en/article/prusa-specific-g-codes_112173): - if (m_flavor == gcfMarlin && (command == "Tx" || command == "Tc" || command == "T?")) + if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && (command == "Tx" || command == "Tc" || command == "T?")) return; // T-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools) see https://github.com/prusa3d/PrusaSlicer/issues/5677 @@ -2783,15 +2862,29 @@ void GCodeProcessor::process_T(const std::string_view command) void GCodeProcessor::store_move_vertex(EMoveType type) { +#if ENABLE_SEAMS_VISUALIZATION + m_last_line_id = (type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ? + m_line_id + 1 : + ((type == EMoveType::Seam) ? m_last_line_id : m_line_id); +#endif // ENABLE_SEAMS_VISUALIZATION + MoveVertex vertex = { #if ENABLE_GCODE_LINES_ID_IN_H_SLIDER +#if ENABLE_SEAMS_VISUALIZATION + m_last_line_id, +#else (type == EMoveType::Color_change || type == EMoveType::Pause_Print || type == EMoveType::Custom_GCode) ? m_line_id + 1 : m_line_id, +#endif // ENABLE_SEAMS_VISUALIZATION #endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER type, m_extrusion_role, m_extruder_id, m_cp_color.current, +#if ENABLE_START_GCODE_VISUALIZATION + Vec3f(m_end_position[X], m_end_position[Y], m_processing_start_custom_gcode ? m_first_layer_height : m_end_position[Z]) + m_extruder_offsets[m_extruder_id], +#else Vec3f(m_end_position[X], m_end_position[Y], m_end_position[Z]) + m_extruder_offsets[m_extruder_id], +#endif // ENABLE_START_GCODE_VISUALIZATION m_end_position[E] - m_start_position[E], m_feedrate, m_width, @@ -2890,6 +2983,22 @@ void GCodeProcessor::set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mo } } +float GCodeProcessor::get_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const +{ + size_t id = static_cast(mode); + return (id < m_time_processor.machines.size()) ? m_time_processor.machines[id].travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; +} + +void GCodeProcessor::set_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value) +{ + size_t id = static_cast(mode); + if (id < m_time_processor.machines.size()) { + m_time_processor.machines[id].travel_acceleration = (m_time_processor.machines[id].max_travel_acceleration == 0.0f) ? value : + // Clamp the acceleration with the maximum. + std::min(value, m_time_processor.machines[id].max_travel_acceleration); + } +} + float GCodeProcessor::get_filament_load_time(size_t extruder_id) { return (m_time_processor.filament_load_times.empty() || m_time_processor.extruder_unloaded) ? diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 96e2160205..75ec1546b3 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -12,6 +12,9 @@ #include #include #include +#if ENABLE_SEAMS_VISUALIZATION +#include +#endif // ENABLE_SEAMS_VISUALIZATION namespace Slic3r { @@ -20,6 +23,9 @@ namespace Slic3r { Noop, Retract, Unretract, +#if ENABLE_SEAMS_VISUALIZATION + Seam, +#endif // ENABLE_SEAMS_VISUALIZATION Tool_change, Color_change, Pause_Print, @@ -251,6 +257,9 @@ namespace Slic3r { float acceleration; // mm/s^2 // hard limit for the acceleration, to which the firmware will clamp. float max_acceleration; // mm/s^2 + float travel_acceleration; // mm/s^2 + // hard limit for the travel acceleration, to which the firmware will clamp. + float max_travel_acceleration; // mm/s^2 float extrude_factor_override_percentage; float time; // s #if ENABLE_EXTENDED_M73_LINES @@ -367,8 +376,7 @@ namespace Slic3r { #if ENABLE_GCODE_VIEWER_STATISTICS int64_t time{ 0 }; - void reset() - { + void reset() { time = 0; moves = std::vector(); bed_shape = Pointfs(); @@ -377,8 +385,7 @@ namespace Slic3r { settings_ids.reset(); } #else - void reset() - { + void reset() { moves = std::vector(); bed_shape = Pointfs(); extruder_colors = std::vector(); @@ -388,6 +395,29 @@ namespace Slic3r { #endif // ENABLE_GCODE_VIEWER_STATISTICS }; +#if ENABLE_SEAMS_VISUALIZATION + class SeamsDetector + { + bool m_active{ false }; + std::optional m_first_vertex; + + public: + void activate(bool active) { + if (m_active != active) { + m_active = active; + if (m_active) + m_first_vertex.reset(); + } + } + + std::optional get_first_vertex() const { return m_first_vertex; } + void set_first_vertex(const Vec3f& vertex) { m_first_vertex = vertex; } + + bool is_active() const { return m_active; } + bool has_first_vertex() const { return m_first_vertex.has_value(); } + }; +#endif // ENABLE_SEAMS_VISUALIZATION + #if ENABLE_GCODE_VIEWER_DATA_CHECKING struct DataChecker { @@ -473,6 +503,9 @@ namespace Slic3r { #if ENABLE_GCODE_LINES_ID_IN_H_SLIDER unsigned int m_line_id; +#if ENABLE_SEAMS_VISUALIZATION + unsigned int m_last_line_id; +#endif // ENABLE_SEAMS_VISUALIZATION #endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER float m_feedrate; // mm/s float m_width; // mm @@ -487,10 +520,17 @@ namespace Slic3r { ExtruderTemps m_extruder_temps; std::vector m_filament_diameters; float m_extruded_last_z; +#if ENABLE_START_GCODE_VISUALIZATION + float m_first_layer_height; // mm + bool m_processing_start_custom_gcode; +#endif // ENABLE_START_GCODE_VISUALIZATION unsigned int m_g1_line_id; unsigned int m_layer_id; CpColor m_cp_color; bool m_use_volumetric_e; +#if ENABLE_SEAMS_VISUALIZATION + SeamsDetector m_seams_detector; +#endif // ENABLE_SEAMS_VISUALIZATION enum class EProducer { @@ -668,7 +708,9 @@ namespace Slic3r { float get_axis_max_jerk(PrintEstimatedTimeStatistics::ETimeMode mode, Axis axis) const; float get_retract_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; float get_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; - void set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); + void set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); + float get_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; + void set_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); float get_filament_load_time(size_t extruder_id); float get_filament_unload_time(size_t extruder_id); diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 8520cf35bd..c45e260158 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -329,6 +329,16 @@ void ToolOrdering::reorder_extruders(unsigned int last_extruder_id) lt.extruders.front() = last_extruder_id; break; } + + // On first layer with wipe tower, prefer a soluble extruder + // at the beginning, so it is not wiped on the first layer. + if (lt == m_layer_tools[0] && m_print_config_ptr && m_print_config_ptr->wipe_tower) { + for (size_t i = 0; ifilament_soluble.get_at(lt.extruders[i]-1)) { // 1-based... + std::swap(lt.extruders[i], lt.extruders.front()); + break; + } + } } last_extruder_id = lt.extruders.back(); } diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index f3ecd2cf33..ae800a5ff0 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -9,17 +9,6 @@ #include "BoundingBox.hpp" -// Experimental "Peter's wipe tower" feature was partially implemented, inspired by -// PJR's idea of alternating two perpendicular wiping directions on a square tower. -// It is probably never going to be finished, there are multiple remaining issues -// and there is probably no need to go down this way. m_peters_wipe_tower variable -// turns this on, maybe it should just be removed. Anyway, the issues are -// - layer's are not exactly square -// - variable width for higher levels -// - make sure it is not too sparse (apply max_bridge_distance and make last wipe longer) -// - enable enhanced first layer adhesion - - namespace Slic3r { @@ -122,8 +111,10 @@ public: WipeTowerWriter& feedrate(float f) { - if (f != m_current_feedrate) + if (f != m_current_feedrate) { m_gcode += "G1" + set_format_F(f) + "\n"; + m_current_feedrate = f; + } return *this; } @@ -216,7 +207,7 @@ public: WipeTowerWriter& extrude(const Vec2f &dest, const float f = 0.f) { return extrude(dest.x(), dest.y(), f); } - + WipeTowerWriter& rectangle(const Vec2f& ld,float width,float height,const float f = 0.f) { Vec2f corners[4]; @@ -242,6 +233,14 @@ public: return (*this); } + WipeTowerWriter& rectangle(const WipeTower::box_coordinates& box, const float f = 0.f) + { + rectangle(Vec2f(box.ld.x(), box.ld.y()), + box.ru.x() - box.lu.x(), + box.ru.y() - box.rd.y(), f); + return (*this); + } + WipeTowerWriter& load(float e, float f = 0.f) { if (e == 0.f && (f == 0.f || f == m_current_feedrate)) @@ -343,7 +342,7 @@ public: WipeTowerWriter& speed_override_backup() { // This is only supported by Prusa at this point (https://github.com/prusa3d/PrusaSlicer/issues/3114) - if (m_gcode_flavor == gcfMarlin) + if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 B\n"; return *this; } @@ -351,7 +350,7 @@ public: // Let the firmware restore the active speed override value. WipeTowerWriter& speed_override_restore() { - if (m_gcode_flavor == gcfMarlin) + if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 R\n"; return *this; } @@ -523,13 +522,21 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector& bed_points = config.bed_shape.values; + BoundingBoxf bb(bed_points); + m_bed_width = float(bb.size().x()); m_bed_shape = (bed_points.size() == 4 ? RectangularBed : CircularBed); - m_bed_width = float(BoundingBoxf(bed_points).size().x()); + + if (m_bed_shape == CircularBed) { + // this may still be a custom bed, check that the points are roughly on a circle + double r2 = std::pow(m_bed_width/2., 2.); + double lim2 = std::pow(m_bed_width/10., 2.); + Vec2d center = bb.center(); + for (const Vec2d& pt : bed_points) + if (std::abs(std::pow(pt.x()-center.x(), 2.) + std::pow(pt.y()-center.y(), 2.) - r2) > lim2) { + m_bed_shape = CustomBed; + break; + } + } + m_bed_bottom_left = m_bed_shape == RectangularBed ? Vec2f(bed_points.front().x(), bed_points.front().y()) : Vec2f::Zero(); @@ -556,6 +577,7 @@ void WipeTower::set_extruder(size_t idx, const PrintConfig& config) m_filpar.push_back(FilamentParameters()); m_filpar[idx].material = config.filament_type.get_at(idx); + m_filpar[idx].is_soluble = config.filament_soluble.get_at(idx); m_filpar[idx].temperature = config.temperature.get_at(idx); m_filpar[idx].first_layer_temperature = config.first_layer_temperature.get_at(idx); @@ -617,10 +639,12 @@ std::vector WipeTower::prime( float prime_section_width = std::min(0.9f * m_bed_width / tools.size(), 60.f); box_coordinates cleaning_box(Vec2f(0.02f * m_bed_width, 0.01f + m_perimeter_width/2.f), prime_section_width, 100.f); - // In case of a circular bed, place it so it goes across the diameter and hope it will fit - if (m_bed_shape == CircularBed) - cleaning_box.translate(-m_bed_width/2 + m_bed_width * 0.03f, -m_bed_width * 0.12f); - if (m_bed_shape == RectangularBed) + if (m_bed_shape == CircularBed) { + cleaning_box = box_coordinates(Vec2f(0.f, 0.f), prime_section_width, 100.f); + float total_width_half = tools.size() * prime_section_width / 2.f; + cleaning_box.translate(-total_width_half, -std::sqrt(std::max(0.f, std::pow(m_bed_width/2, 2.f) - std::pow(1.05f * total_width_half, 2.f)))); + } + else cleaning_box.translate(m_bed_bottom_left); std::vector results; @@ -680,7 +704,7 @@ std::vector WipeTower::prime( if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); writer.speed_override_restore() - .feedrate(6000) + .feedrate(m_travel_speed * 60.f) .flush_planner_queue() .reset_extruder() .append("; CP PRIMING END\n" @@ -694,21 +718,14 @@ std::vector WipeTower::prime( m_old_temperature = -1; // If the priming is turned off in config, the temperature changing commands will not actually appear // in the output gcode - we should not remember emitting them (we will output them twice in the worst case) - // so that tool_change() will know to extrude the wipe tower brim: - m_print_brim = true; - return results; } WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) { - if ( m_print_brim ) - return toolchange_Brim(); - size_t old_tool = m_current_tool; - float wipe_area = 0.f; - bool last_change_in_layer = false; + float wipe_area = 0.f; float wipe_volume = 0.f; // Finds this toolchange info @@ -716,9 +733,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) { for (const auto &b : m_layer_info->tool_changes) if ( b.new_tool == tool ) { - wipe_volume = b.wipe_volume; - if (tool == m_layer_info->tool_changes.back().new_tool) - last_change_in_layer = true; + wipe_volume = b.wipe_volume; wipe_area = b.required_depth * m_layer_info->extra_spacing; break; } @@ -727,17 +742,17 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) // Otherwise we are going to Unload only. And m_layer_info would be invalid. } - box_coordinates cleaning_box( + box_coordinates cleaning_box( Vec2f(m_perimeter_width / 2.f, m_perimeter_width / 2.f), m_wipe_tower_width - m_perimeter_width, - (tool != (unsigned int)(-1) ? /*m_layer_info->depth*/wipe_area+m_depth_traversed-0.5f*m_perimeter_width + (tool != (unsigned int)(-1) ? wipe_area+m_depth_traversed-0.5f*m_perimeter_width : m_wipe_tower_depth-m_perimeter_width)); WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) - .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED && !m_peters_wipe_tower) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) + .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) .append(";--------------------\n" "; CP TOOLCHANGE START\n") .comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based @@ -759,7 +774,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) // Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool. if (tool != (unsigned int)-1){ // This is not the last change. toolchange_Unload(writer, cleaning_box, m_filpar[m_current_tool].material, - m_is_first_layer ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); + is_first_layer() ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); toolchange_Change(writer, tool, m_filpar[tool].material); // Change the tool, set a speed override for soluble and flex materials. toolchange_Load(writer, cleaning_box); writer.travel(writer.x(), writer.y()-m_perimeter_width); // cooling and loading were done a bit down the road @@ -770,24 +785,10 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) m_depth_traversed += wipe_area; - if (last_change_in_layer) {// draw perimeter line - writer.set_y_shift(m_y_shift); - if (m_peters_wipe_tower) - writer.rectangle(Vec2f::Zero(), m_layer_info->depth + 3*m_perimeter_width, m_wipe_tower_depth); - else { - writer.rectangle(Vec2f::Zero(), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); - if (layer_finished()) { // no finish_layer will be called, we must wipe the nozzle - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(writer.x()> m_wipe_tower_width / 2.f ? 0.f : m_wipe_tower_width, writer.y()); - - } - } - } - if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); // Reset the extruder current to a normal value. writer.speed_override_restore(); - writer.feedrate(6000) + writer.feedrate(m_travel_speed * 60.f) .flush_planner_queue() .reset_extruder() .append("; CP TOOLCHANGE END\n" @@ -801,66 +802,6 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) return construct_tcr(writer, false, old_tool); } -WipeTower::ToolChangeResult WipeTower::toolchange_Brim(bool sideOnly, float y_offset) -{ - size_t old_tool = m_current_tool; - - const box_coordinates wipeTower_box( - Vec2f::Zero(), - m_wipe_tower_width, - m_wipe_tower_depth); - - WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); - writer.set_extrusion_flow(m_extrusion_flow * 1.1f) - .set_z(m_z_pos) // Let the writer know the current Z position as a base for Z-hop. - .set_initial_tool(m_current_tool) - .append(";-------------------------------------\n" - "; CP WIPE TOWER FIRST LAYER BRIM START\n"); - - Vec2f initial_position = wipeTower_box.lu - Vec2f(m_wipe_tower_brim_width + 2*m_perimeter_width, 0); - writer.set_initial_position(initial_position, m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); - - // Prime the extruder left of the wipe tower. - writer.extrude_explicit(wipeTower_box.ld - Vec2f(m_wipe_tower_brim_width + 2*m_perimeter_width, 0), - 1.5f * m_extrusion_flow * (wipeTower_box.lu.y() - wipeTower_box.ld.y()), 2400); - - // The tool is supposed to be active and primed at the time when the wipe tower brim is extruded. - // Extrude brim around the future wipe tower ('normal' spacing with no extra void space). - box_coordinates box(wipeTower_box); - float spacing = m_perimeter_width - m_layer_height*float(1.-M_PI_4); - - // How many perimeters shall the brim have? - size_t loops_num = (m_wipe_tower_brim_width + spacing/2.f) / spacing; - - for (size_t i = 0; i < loops_num; ++ i) { - box.expand(spacing); - writer.travel (box.ld, 7000) - .extrude(box.lu, 2100).extrude(box.ru) - .extrude(box.rd ).extrude(box.ld); - } - - // Save actual brim width to be later passed to the Print object, which will use it - // for skirt calculation and pass it to GLCanvas for precise preview box - m_wipe_tower_brim_width_real = wipeTower_box.ld.x() - box.ld.x() + spacing/2.f; - - box.expand(-spacing); - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(box.ld) - .add_wipe_point(box.rd); - - writer.append("; CP WIPE TOWER FIRST LAYER BRIM END\n" - ";-----------------------------------\n"); - - m_print_brim = false; // Mark the brim as extruded - - // Ask our writer about how much material was consumed: - if (m_current_tool < m_used_filament_length.size()) - m_used_filament_length[m_current_tool] += writer.get_and_reset_used_filament_length(); - - return construct_tcr(writer, false, old_tool); -} - - // Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool. void WipeTower::toolchange_Unload( @@ -957,7 +898,7 @@ void WipeTower::toolchange_Unload( // be already set and there is no need to change anything. Also, the temperature could be changed // for wrong extruder. if (m_semm) { - if (new_temperature != 0 && (new_temperature != m_old_temperature || m_is_first_layer) ) { // Set the extruder temperature, but don't wait. + if (new_temperature != 0 && (new_temperature != m_old_temperature || is_first_layer()) ) { // Set the extruder temperature, but don't wait. // If the required temperature is the same as last time, don't emit the M104 again (if user adjusted the value, it would be reset) // However, always change temperatures on the first layer (this is to avoid issues with priming lines turned off). writer.set_extruder_temp(new_temperature, false); @@ -1017,7 +958,10 @@ void WipeTower::toolchange_Change( // gcode could have left the extruder somewhere, we cannot just start extruding. We should also inform the // postprocessor that we absolutely want to have this in the gcode, even if it thought it is the same as before. Vec2f current_pos = writer.pos_rotated(); - writer.append(std::string("G1 X") + std::to_string(current_pos.x()) + " Y" + std::to_string(current_pos.y()) + never_skip_tag() + "\n"); + writer.feedrate(m_travel_speed * 60.f) // see https://github.com/prusa3d/PrusaSlicer/issues/5483 + .append(std::string("G1 X") + std::to_string(current_pos.x()) + + " Y" + std::to_string(current_pos.y()) + + never_skip_tag() + "\n"); // The toolchange Tn command will be inserted later, only in case that the user does // not provide a custom toolchange gcode. @@ -1063,9 +1007,8 @@ void WipeTower::toolchange_Wipe( float wipe_volume) { // Increase flow on first layer, slow down print. - writer.set_extrusion_flow(m_extrusion_flow * (m_is_first_layer ? 1.18f : 1.f)) + writer.set_extrusion_flow(m_extrusion_flow * (is_first_layer() ? 1.18f : 1.f)) .append("; CP TOOLCHANGE WIPE\n"); - float wipe_coeff = m_is_first_layer ? 0.5f : 1.f; const float& xl = cleaning_box.ld.x(); const float& xr = cleaning_box.rd.x(); @@ -1075,7 +1018,9 @@ void WipeTower::toolchange_Wipe( float x_to_wipe = volume_to_length(wipe_volume, m_perimeter_width, m_layer_height); float dy = m_extra_spacing*m_perimeter_width; - float wipe_speed = 1600.f; + + const float target_speed = is_first_layer() ? m_first_layer_speed * 60.f : 4800.f; + float wipe_speed = 0.33f * target_speed; // if there is less than 2.5*m_perimeter_width to the edge, advance straightaway (there is likely a blob anyway) if ((m_left_to_right ? xr-writer.x() : writer.x()-xl) < 2.5f*m_perimeter_width) { @@ -1086,17 +1031,17 @@ void WipeTower::toolchange_Wipe( // now the wiping itself: for (int i = 0; true; ++i) { if (i!=0) { - if (wipe_speed < 1610.f) wipe_speed = 1800.f; - else if (wipe_speed < 1810.f) wipe_speed = 2200.f; - else if (wipe_speed < 2210.f) wipe_speed = 4200.f; - else wipe_speed = std::min(4800.f, wipe_speed + 50.f); + if (wipe_speed < 0.34f * target_speed) wipe_speed = 0.375f * target_speed; + else if (wipe_speed < 0.377 * target_speed) wipe_speed = 0.458f * target_speed; + else if (wipe_speed < 0.46f * target_speed) wipe_speed = 0.875f * target_speed; + else wipe_speed = std::min(target_speed, wipe_speed + 50.f); } float traversed_x = writer.x(); if (m_left_to_right) - writer.extrude(xr - (i % 4 == 0 ? 0 : 1.5f*m_perimeter_width), writer.y(), wipe_speed * wipe_coeff); + writer.extrude(xr - (i % 4 == 0 ? 0 : 1.5f*m_perimeter_width), writer.y(), wipe_speed); else - writer.extrude(xl + (i % 4 == 1 ? 0 : 1.5f*m_perimeter_width), writer.y(), wipe_speed * wipe_coeff); + writer.extrude(xl + (i % 4 == 1 ? 0 : 1.5f*m_perimeter_width), writer.y(), wipe_speed); if (writer.y()+float(EPSILON) > cleaning_box.lu.y()-0.5f*m_perimeter_width) break; // in case next line would not fit @@ -1112,17 +1057,16 @@ void WipeTower::toolchange_Wipe( m_left_to_right = !m_left_to_right; } - // this is neither priming nor not the last toolchange on this layer - we are - // going back to the model - wipe the nozzle. - if (m_layer_info != m_plan.end() && m_current_tool != m_layer_info->tool_changes.back().new_tool) { + // We may be going back to the model - wipe the nozzle. If this is followed + // by finish_layer, this wipe path will be overwritten. + writer.add_wipe_point(writer.x(), writer.y()) + .add_wipe_point(writer.x(), writer.y() - dy) + .add_wipe_point(! m_left_to_right ? m_wipe_tower_width : 0.f, writer.y() - dy); + + if (m_layer_info != m_plan.end() && m_current_tool != m_layer_info->tool_changes.back().new_tool) m_left_to_right = !m_left_to_right; - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(writer.x(), writer.y() - dy) - .add_wipe_point(m_left_to_right ? m_wipe_tower_width : 0.f, writer.y() - dy); - } - - writer.set_extrusion_flow(m_extrusion_flow); // Reset the extrusion flow. + writer.set_extrusion_flow(m_extrusion_flow); // Reset the extrusion flow. } @@ -1130,9 +1074,8 @@ void WipeTower::toolchange_Wipe( WipeTower::ToolChangeResult WipeTower::finish_layer() { - // This should only be called if the layer is not finished yet. - // Otherwise the caller would likely travel to the wipe tower in vain. assert(! this->layer_finished()); + m_current_layer_finished = true; size_t old_tool = m_current_tool; @@ -1140,61 +1083,75 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) - .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED && !m_peters_wipe_tower ? m_layer_info->toolchanges_depth() : 0.f)) - .append(";--------------------\n" - "; CP EMPTY GRID START\n") - .comment_with_value(" layer #", m_num_layer_changes + 1); + .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)); + // Slow down on the 1st layer. - float speed_factor = m_is_first_layer ? 0.5f : 1.f; + bool first_layer = is_first_layer(); + float feedrate = first_layer ? m_first_layer_speed * 60.f : 2900.f; float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth(); - box_coordinates fill_box(Vec2f(m_perimeter_width, m_depth_traversed + m_perimeter_width), - m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); + box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), + m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); writer.set_initial_position((m_left_to_right ? fill_box.ru : fill_box.lu), // so there is never a diagonal travel m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); bool toolchanges_on_layer = m_layer_info->toolchanges_depth() > WT_EPSILON; - box_coordinates box = fill_box; - for (int i=0;i<2;++i) { - if (! toolchanges_on_layer) { - if (i==0) box.expand(m_perimeter_width); - else box.expand(-m_perimeter_width); - } - else i=2; // only draw the inner perimeter, outer has been already drawn by tool_change(...) - writer.rectangle(box.ld, box.rd.x()-box.ld.x(), box.ru.y()-box.rd.y(), 2900*speed_factor); - } + box_coordinates wt_box(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), + m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); + + // inner perimeter of the sparse section, if there is space for it: + if (fill_box.ru.y() - fill_box.rd.y() > m_perimeter_width - WT_EPSILON) + writer.rectangle(fill_box.ld, fill_box.rd.x()-fill_box.ld.x(), fill_box.ru.y()-fill_box.rd.y(), feedrate); // we are in one of the corners, travel to ld along the perimeter: if (writer.x() > fill_box.ld.x()+EPSILON) writer.travel(fill_box.ld.x(),writer.y()); if (writer.y() > fill_box.ld.y()+EPSILON) writer.travel(writer.x(),fill_box.ld.y()); - if (m_is_first_layer && m_adhesion) { - // Extrude a dense infill at the 1st layer to improve 1st layer adhesion of the wipe tower. - box.expand(-m_perimeter_width/2.f); - int nsteps = int(floor((box.lu.y() - box.ld.y()) / (2*m_perimeter_width))); - float step = (box.lu.y() - box.ld.y()) / nsteps; - writer.travel(box.ld - Vec2f(m_perimeter_width/2.f, m_perimeter_width/2.f)); - if (nsteps >= 0) - for (int i = 0; i < nsteps; ++i) { - writer.extrude(box.ld.x()+m_perimeter_width/2.f, writer.y() + 0.5f * step); - writer.extrude(box.rd.x() - m_perimeter_width / 2.f, writer.y()); - writer.extrude(box.rd.x() - m_perimeter_width / 2.f, writer.y() + 0.5f * step); - writer.extrude(box.ld.x() + m_perimeter_width / 2.f, writer.y()); + // Extrude infill to support the material to be printed above. + const float dy = (fill_box.lu.y() - fill_box.ld.y() - m_perimeter_width); + float left = fill_box.lu.x() + 2*m_perimeter_width; + float right = fill_box.ru.x() - 2 * m_perimeter_width; + if (dy > m_perimeter_width) + { + writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) + .append(";--------------------\n" + "; CP EMPTY GRID START\n") + .comment_with_value(" layer #", m_num_layer_changes + 1); + + // Is there a soluble filament wiped/rammed at the next layer? + // If so, the infill should not be sparse. + bool solid_infill = m_layer_info+1 == m_plan.end() + ? false + : std::any_of((m_layer_info+1)->tool_changes.begin(), + (m_layer_info+1)->tool_changes.end(), + [this](const WipeTowerInfo::ToolChange& tch) { + return m_filpar[tch.new_tool].is_soluble + || m_filpar[tch.old_tool].is_soluble; + }); + solid_infill |= first_layer && m_adhesion; + + if (solid_infill) { + float sparse_factor = 1.5f; // 1=solid, 2=every other line, etc. + if (first_layer) { // the infill should touch perimeters + left -= m_perimeter_width; + right += m_perimeter_width; + sparse_factor = 1.f; } - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(box.rd.x()-m_perimeter_width/2.f,writer.y()); - } - else { // Extrude a sparse infill to support the material to be printed above. - const float dy = (fill_box.lu.y() - fill_box.ld.y() - m_perimeter_width); - const float left = fill_box.lu.x() + 2*m_perimeter_width; - const float right = fill_box.ru.x() - 2 * m_perimeter_width; - if (dy > m_perimeter_width) - { - // Extrude an inverse U at the left of the region. - writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) - .extrude(fill_box.lu + Vec2f(m_perimeter_width * 2, 0.f), 2900 * speed_factor); + float y = fill_box.ld.y() + m_perimeter_width; + int n = dy / (m_perimeter_width * sparse_factor); + float spacing = (dy-m_perimeter_width)/(n-1); + int i=0; + for (i=0; itool_changes.size()==0) // we have no way to save anything on an empty layer continue; - for (const auto &toolchange : m_layer_info->tool_changes) + // Which toolchange will finish_layer extrusions be subtracted from? + int idx = first_toolchange_to_nonsoluble(m_layer_info->tool_changes); + + for (int i=0; itool_changes.size()); ++i) { + auto& toolchange = m_layer_info->tool_changes[i]; tool_change(toolchange.new_tool); - float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into - float length_to_save = 2*(m_wipe_tower_width+m_wipe_tower_depth) + (!layer_finished() ? finish_layer().total_extrusion_length_in_plane() : 0.f); - float length_to_wipe = volume_to_length(m_layer_info->tool_changes.back().wipe_volume, - m_perimeter_width,m_layer_info->height) - m_layer_info->tool_changes.back().first_wipe_line - length_to_save; + if (i == idx) { + float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into + float length_to_save = finish_layer().total_extrusion_length_in_plane(); + float length_to_wipe = volume_to_length(toolchange.wipe_volume, + m_perimeter_width, m_layer_info->height) - toolchange.first_wipe_line - length_to_save; - length_to_wipe = std::max(length_to_wipe,0.f); - float depth_to_wipe = m_perimeter_width * (std::floor(length_to_wipe/width) + ( length_to_wipe > 0.f ? 1.f : 0.f ) ) * m_extra_spacing; + length_to_wipe = std::max(length_to_wipe,0.f); + float depth_to_wipe = m_perimeter_width * (std::floor(length_to_wipe/width) + ( length_to_wipe > 0.f ? 1.f : 0.f ) ) * m_extra_spacing; - //depth += (int(length_to_extrude / width) + 1) * m_perimeter_width; - m_layer_info->tool_changes.back().required_depth = m_layer_info->tool_changes.back().ramming_depth + depth_to_wipe; + toolchange.required_depth = toolchange.ramming_depth + depth_to_wipe; + } + } } } + +// Return index of first toolchange that switches to non-soluble extruder +// ot -1 if there is no such toolchange. +int WipeTower::first_toolchange_to_nonsoluble( + const std::vector& tool_changes) const +{ + for (size_t idx=0; idx> &result) { if (m_plan.empty()) - return; m_extra_spacing = 1.f; @@ -1325,9 +1340,6 @@ void WipeTower::generate(std::vector> & plan_tower(); } - if (m_peters_wipe_tower) - make_wipe_tower_square(); - m_layer_info = m_plan.begin(); // we don't know which extruder to start with - we'll set it according to the first toolchange @@ -1346,65 +1358,41 @@ void WipeTower::generate(std::vector> & std::vector layer_result; for (auto layer : m_plan) { - set_layer(layer.z,layer.height,0,layer.z == m_plan.front().z,layer.z == m_plan.back().z); - if (m_peters_wipe_tower) - m_internal_rotation += 90.f; - else - m_internal_rotation += 180.f; + set_layer(layer.z, layer.height, 0, false/*layer.z == m_plan.front().z*/, layer.z == m_plan.back().z); + m_internal_rotation += 180.f; - if (!m_peters_wipe_tower && m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) + if (m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) m_y_shift = (m_wipe_tower_depth-m_layer_info->depth-m_perimeter_width)/2.f; - for (const auto &toolchange : layer.tool_changes) - layer_result.emplace_back(tool_change(toolchange.new_tool)); + int idx = first_toolchange_to_nonsoluble(layer.tool_changes); + ToolChangeResult finish_layer_tcr; - if (! layer_finished()) { - auto finish_layer_toolchange = finish_layer(); - if ( ! layer.tool_changes.empty() ) { // we will merge it to the last toolchange - auto& last_toolchange = layer_result.back(); - if (last_toolchange.end_pos != finish_layer_toolchange.start_pos) { - char buf[2048]; // Add a travel move from tc1.end_pos to tc2.start_pos. - sprintf(buf, "G1 X%.3f Y%.3f F7200\n", finish_layer_toolchange.start_pos.x(), finish_layer_toolchange.start_pos.y()); - last_toolchange.gcode += buf; - } - last_toolchange.gcode += finish_layer_toolchange.gcode; - last_toolchange.extrusions.insert(last_toolchange.extrusions.end(), finish_layer_toolchange.extrusions.begin(), finish_layer_toolchange.extrusions.end()); - last_toolchange.end_pos = finish_layer_toolchange.end_pos; - last_toolchange.wipe_path = finish_layer_toolchange.wipe_path; - } + if (idx == -1) { + // if there is no toolchange switching to non-soluble, finish layer + // will be called at the very beginning. That's the last possibility + // where a nonsoluble tool can be. + finish_layer_tcr = finish_layer(); + } + + for (int i=0; i> &result); @@ -129,9 +160,8 @@ public: { m_z_pos = print_z; m_layer_height = layer_height; - m_is_first_layer = is_first_layer; - m_print_brim = is_first_layer; m_depth_traversed = 0.f; + m_current_layer_finished = false; m_current_shape = (! is_first_layer && m_current_shape == SHAPE_NORMAL) ? SHAPE_REVERSED : SHAPE_NORMAL; if (is_first_layer) { this->m_num_layer_changes = 0; @@ -175,7 +205,7 @@ public: // Is the current layer finished? bool layer_finished() const { - return ( (m_is_first_layer ? m_wipe_tower_depth - m_perimeter_width : m_layer_info->depth) - WT_EPSILON < m_depth_traversed); + return m_current_layer_finished; } std::vector get_used_filament() const { return m_used_filament_length; } @@ -183,6 +213,7 @@ public: struct FilamentParameters { std::string material = "PLA"; + bool is_soluble = false; int temperature = 0; int first_layer_temperature = 0; float loading_speed = 0.f; @@ -208,7 +239,6 @@ private: SHAPE_REVERSED = -1 }; - const bool m_peters_wipe_tower = false; // sparse wipe tower inspired by Peter's post processor - not finished yet const float Width_To_Nozzle_Ratio = 1.25f; // desired line width (oval) in multiples of nozzle diameter - may not be actually neccessary to adjust const float WT_EPSILON = 1e-3f; float filament_area() const { @@ -228,8 +258,10 @@ private: float m_z_pos = 0.f; // Current Z position. float m_layer_height = 0.f; // Current layer height. size_t m_max_color_changes = 0; // Maximum number of color changes per layer. - bool m_is_first_layer = false;// Is this the 1st layer of the print? If so, print the brim around the waste tower. int m_old_temperature = -1; // To keep track of what was the last temp that we set (so we don't issue the command when not neccessary) + float m_travel_speed = 0.f; + float m_first_layer_speed = 0.f; + size_t m_first_layer_idx = size_t(-1); // G-code generator parameters. float m_cooling_tube_retraction = 0.f; @@ -245,7 +277,8 @@ private: // Bed properties enum { RectangularBed, - CircularBed + CircularBed, + CustomBed } m_bed_shape; float m_bed_width; // width of the bed bounding box Vec2f m_bed_bottom_left; // bottom-left corner coordinates (for rectangular beds) @@ -268,9 +301,12 @@ private: const std::vector> wipe_volumes; float m_depth_traversed = 0.f; // Current y position at the wipe tower. + bool m_current_layer_finished = false; bool m_left_to_right = true; float m_extra_spacing = 1.f; + bool is_first_layer() const { return size_t(m_layer_info - m_plan.begin()) == m_first_layer_idx; } + // Calculates extrusion flow needed to produce required line width for given layer height float extrusion_flow(float layer_height = -1.f) const // negative layer_height - return current m_extrusion_flow { @@ -294,39 +330,7 @@ private: void save_on_last_wipe(); - struct box_coordinates - { - box_coordinates(float left, float bottom, float width, float height) : - ld(left , bottom ), - lu(left , bottom + height), - rd(left + width, bottom ), - ru(left + width, bottom + height) {} - box_coordinates(const Vec2f &pos, float width, float height) : box_coordinates(pos(0), pos(1), width, height) {} - void translate(const Vec2f &shift) { - ld += shift; lu += shift; - rd += shift; ru += shift; - } - void translate(const float dx, const float dy) { translate(Vec2f(dx, dy)); } - void expand(const float offset) { - ld += Vec2f(- offset, - offset); - lu += Vec2f(- offset, offset); - rd += Vec2f( offset, - offset); - ru += Vec2f( offset, offset); - } - void expand(const float offset_x, const float offset_y) { - ld += Vec2f(- offset_x, - offset_y); - lu += Vec2f(- offset_x, offset_y); - rd += Vec2f( offset_x, - offset_y); - ru += Vec2f( offset_x, offset_y); - } - Vec2f ld; // left down - Vec2f lu; // left upper - Vec2f rd; // right lower - Vec2f ru; // right upper - }; - - - // to store information about tool changes for a given layer + // to store information about tool changes for a given layer struct WipeTowerInfo{ struct ToolChange { size_t old_tool; @@ -356,11 +360,10 @@ private: // Stores information about used filament length per extruder: std::vector m_used_filament_length; - - // Returns gcode for wipe tower brim - // sideOnly -- set to false -- experimental, draw brim on sides of wipe tower - // offset -- set to 0 -- experimental, offset to replace brim in front / rear of wipe tower - ToolChangeResult toolchange_Brim(bool sideOnly = false, float y_offset = 0.f); + // Return index of first toolchange that switches to non-soluble extruder + // ot -1 if there is no such toolchange. + int first_toolchange_to_nonsoluble( + const std::vector& tool_changes) const; void toolchange_Unload( WipeTowerWriter &writer, @@ -386,6 +389,6 @@ private: -}; // namespace Slic3r +} // namespace Slic3r #endif // WipeTowerPrusaMM_hpp_ diff --git a/src/libslic3r/GCodeReader.cpp b/src/libslic3r/GCodeReader.cpp index fb493fcb7e..9753e48206 100644 --- a/src/libslic3r/GCodeReader.cpp +++ b/src/libslic3r/GCodeReader.cpp @@ -13,13 +13,13 @@ namespace Slic3r { void GCodeReader::apply_config(const GCodeConfig &config) { m_config = config; - m_extrusion_axis = m_config.get_extrusion_axis()[0]; + m_extrusion_axis = get_extrusion_axis(m_config)[0]; } void GCodeReader::apply_config(const DynamicPrintConfig &config) { m_config.apply(config, true); - m_extrusion_axis = m_config.get_extrusion_axis()[0]; + m_extrusion_axis = get_extrusion_axis(m_config)[0]; } const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair &command) diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 847398e69f..c84c7b09ed 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -18,9 +18,10 @@ namespace Slic3r { void GCodeWriter::apply_print_config(const PrintConfig &print_config) { this->config.apply(print_config, true); - m_extrusion_axis = this->config.get_extrusion_axis(); + m_extrusion_axis = get_extrusion_axis(this->config); m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; - m_max_acceleration = std::lrint((print_config.gcode_flavor.value == gcfMarlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? + bool is_marlin = print_config.gcode_flavor.value == gcfMarlinLegacy || print_config.gcode_flavor.value == gcfMarlinFirmware; + m_max_acceleration = std::lrint((is_marlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? print_config.machine_max_acceleration_extruding.values.front() : 0); } @@ -48,7 +49,8 @@ std::string GCodeWriter::preamble() } if (FLAVOR_IS(gcfRepRapSprinter) || FLAVOR_IS(gcfRepRapFirmware) || - FLAVOR_IS(gcfMarlin) || + FLAVOR_IS(gcfMarlinLegacy) || + FLAVOR_IS(gcfMarlinFirmware) || FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepetier) || FLAVOR_IS(gcfSmoothie)) @@ -205,8 +207,12 @@ std::string GCodeWriter::set_acceleration(unsigned int acceleration) // M202: Set max travel acceleration gcode << "M202 X" << acceleration << " Y" << acceleration; } else if (FLAVOR_IS(gcfRepRapFirmware)) { - // M204: Set default acceleration - gcode << "M204 P" << acceleration; + // M204: Set default acceleration + gcode << "M204 P" << acceleration; + } else if (FLAVOR_IS(gcfMarlinFirmware)) { + // This is new MarlinFirmware with separated print/retraction/travel acceleration. + // Use M204 P, we don't want to override travel acc by M204 S (which is deprecated anyway). + gcode << "M204 P" << acceleration; } else { // M204: Set default acceleration gcode << "M204 S" << acceleration; diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index aac7c77524..d5ef41125a 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1087,11 +1087,13 @@ bool MedialAxis::validate_edge(const VD::edge_type* edge) { // prevent overflows and detect almost-infinite edges +#ifndef CLIPPERLIB_INT32 if (std::abs(edge->vertex0()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || std::abs(edge->vertex0()->y()) > double(CLIPPER_MAX_COORD_UNSCALED) || std::abs(edge->vertex1()->x()) > double(CLIPPER_MAX_COORD_UNSCALED) || std::abs(edge->vertex1()->y()) > double(CLIPPER_MAX_COORD_UNSCALED)) return false; +#endif // CLIPPERLIB_INT32 // construct the line representing this edge of the Voronoi diagram const Line line( diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 9d98ea6aeb..c6af515c83 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -22,12 +22,14 @@ #pragma warning(pop) #endif // _MSC_VER -namespace ClipperLib { -class PolyNode; -using PolyNodes = std::vector; -} +namespace Slic3r { -namespace Slic3r { namespace Geometry { + namespace ClipperLib { + class PolyNode; + using PolyNodes = std::vector; + } + +namespace Geometry { // Generic result of an orientation predicate. enum Orientation @@ -299,20 +301,23 @@ bool liang_barsky_line_clipping( // Ugly named variant, that accepts the squared line // Don't call me with a nearly zero length vector! +// sympy: +// factor(solve([a * x + b * y + c, x**2 + y**2 - r**2], [x, y])[0]) +// factor(solve([a * x + b * y + c, x**2 + y**2 - r**2], [x, y])[1]) template int ray_circle_intersections_r2_lv2_c(T r2, T a, T b, T lv2, T c, std::pair, Eigen::Matrix> &out) { - T x0 = - a * c / lv2; - T y0 = - b * c / lv2; - T d = r2 - c * c / lv2; - if (d < T(0)) + T x0 = - a * c; + T y0 = - b * c; + T d2 = r2 * lv2 - c * c; + if (d2 < T(0)) return 0; - T mult = sqrt(d / lv2); - out.first.x() = x0 + b * mult; - out.first.y() = y0 - a * mult; - out.second.x() = x0 - b * mult; - out.second.y() = y0 + a * mult; - return mult == T(0) ? 1 : 2; + T d = sqrt(d2); + out.first.x() = (x0 + b * d) / lv2; + out.first.y() = (y0 - a * d) / lv2; + out.second.x() = (x0 - b * d) / lv2; + out.second.y() = (y0 + a * d) / lv2; + return d == T(0) ? 1 : 2; } template int ray_circle_intersections(T r, T a, T b, T c, std::pair, Eigen::Matrix> &out) @@ -527,6 +532,6 @@ inline bool is_rotation_ninety_degrees(const Vec3d &rotation) return is_rotation_ninety_degrees(rotation.x()) && is_rotation_ninety_degrees(rotation.y()) && is_rotation_ninety_degrees(rotation.z()); } -} } +} } // namespace Slicer::Geometry #endif diff --git a/src/libslic3r/Layer.cpp b/src/libslic3r/Layer.cpp index b974ff2172..e8e3c4275c 100644 --- a/src/libslic3r/Layer.cpp +++ b/src/libslic3r/Layer.cpp @@ -39,11 +39,11 @@ void Layer::make_slices() ExPolygons slices; if (m_regions.size() == 1) { // optimization: if we only have one region, take its slices - slices = m_regions.front()->slices; + slices = to_expolygons(m_regions.front()->slices.surfaces); } else { Polygons slices_p; for (LayerRegion *layerm : m_regions) - polygons_append(slices_p, to_polygons(layerm->slices)); + polygons_append(slices_p, to_polygons(layerm->slices.surfaces)); slices = union_ex(slices_p); } @@ -105,7 +105,7 @@ ExPolygons Layer::merged(float offset_scaled) const const PrintRegionConfig &config = layerm->region()->config(); // Our users learned to bend Slic3r to produce empty volumes to act as subtracters. Only add the region if it is non-empty. if (config.bottom_solid_layers > 0 || config.top_solid_layers > 0 || config.fill_density > 0. || config.perimeters > 0) - append(polygons, offset(to_expolygons(layerm->slices.surfaces), offset_scaled)); + append(polygons, offset(layerm->slices.surfaces, offset_scaled)); } ExPolygons out = union_ex(polygons); if (offset_scaled2 != 0.f) @@ -185,7 +185,7 @@ void Layer::make_perimeters() } // merge the surfaces assigned to each group for (std::pair &surfaces_with_extra_perimeters : slices) - new_slices.append(union_ex(surfaces_with_extra_perimeters.second, true), surfaces_with_extra_perimeters.second.front()); + new_slices.append(offset_ex(surfaces_with_extra_perimeters.second, ClipperSafetyOffset), surfaces_with_extra_perimeters.second.front()); } // make perimeters @@ -196,7 +196,7 @@ void Layer::make_perimeters() if (!fill_surfaces.surfaces.empty()) { for (LayerRegionPtrs::iterator l = layerms.begin(); l != layerms.end(); ++l) { // Separate the fill surfaces. - ExPolygons expp = intersection_ex(to_polygons(fill_surfaces), (*l)->slices); + ExPolygons expp = intersection_ex(fill_surfaces.surfaces, (*l)->slices.surfaces); (*l)->fill_expolygons = expp; (*l)->fill_surfaces.set(std::move(expp), fill_surfaces.surfaces.front()); } diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 87296f8f1c..2e3e29eab8 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -196,7 +196,7 @@ protected: // between the raft and the object first layer. SupportLayer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z, coordf_t slice_z) : Layer(id, object, height, print_z, slice_z) {} - virtual ~SupportLayer() {} + virtual ~SupportLayer() = default; }; } diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index f6c0c9c7a5..5b4a021b02 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -49,19 +49,17 @@ void LayerRegion::slices_to_fill_surfaces_clipped() // in place. However we're now only using its boundaries (which are invariant) // so we're safe. This guarantees idempotence of prepare_infill() also in case // that combine_infill() turns some fill_surface into VOID surfaces. -// Polygons fill_boundaries = to_polygons(std::move(this->fill_surfaces)); - Polygons fill_boundaries = to_polygons(this->fill_expolygons); // Collect polygons per surface type. - std::vector polygons_by_surface; - polygons_by_surface.assign(size_t(stCount), Polygons()); + std::vector by_surface; + by_surface.assign(size_t(stCount), SurfacesPtr()); for (Surface &surface : this->slices.surfaces) - polygons_append(polygons_by_surface[(size_t)surface.surface_type], surface.expolygon); + by_surface[size_t(surface.surface_type)].emplace_back(&surface); // Trim surfaces by the fill_boundaries. this->fill_surfaces.surfaces.clear(); for (size_t surface_type = 0; surface_type < size_t(stCount); ++ surface_type) { - const Polygons &polygons = polygons_by_surface[surface_type]; - if (! polygons.empty()) - this->fill_surfaces.append(intersection_ex(polygons, fill_boundaries), SurfaceType(surface_type)); + const SurfacesPtr &this_surfaces = by_surface[surface_type]; + if (! this_surfaces.empty()) + this->fill_surfaces.append(intersection_ex(this_surfaces, this->fill_expolygons), SurfaceType(surface_type)); } } @@ -216,12 +214,12 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly break; } // Grown by 3mm. - Polygons polys = offset(to_polygons(bridges[i].expolygon), margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS); + Polygons polys = offset(bridges[i].expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS); if (idx_island == -1) { BOOST_LOG_TRIVIAL(trace) << "Bridge did not fall into the source region!"; } else { // Found an island, to which this bridge region belongs. Trim it, - polys = intersection(polys, to_polygons(fill_boundaries_ex[idx_island])); + polys = intersection(polys, fill_boundaries_ex[idx_island]); } bridge_bboxes.push_back(get_extents(polys)); bridges_grown.push_back(std::move(polys)); @@ -325,11 +323,11 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly if (s1.empty()) continue; Polygons polys; - polygons_append(polys, std::move(s1)); + polygons_append(polys, to_polygons(std::move(s1))); for (size_t j = i + 1; j < top.size(); ++ j) { Surface &s2 = top[j]; if (! s2.empty() && surfaces_could_merge(s1, s2)) { - polygons_append(polys, std::move(s2)); + polygons_append(polys, to_polygons(std::move(s2))); s2.clear(); } } @@ -351,11 +349,11 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly if (s1.empty()) continue; Polygons polys; - polygons_append(polys, std::move(s1)); + polygons_append(polys, to_polygons(std::move(s1))); for (size_t j = i + 1; j < internal.size(); ++ j) { Surface &s2 = internal[j]; if (! s2.empty() && surfaces_could_merge(s1, s2)) { - polygons_append(polys, std::move(s2)); + polygons_append(polys, to_polygons(std::move(s2))); s2.clear(); } } @@ -423,7 +421,7 @@ void LayerRegion::trim_surfaces(const Polygons &trimming_polygons) for (const Surface &surface : this->slices.surfaces) assert(surface.surface_type == stInternal); #endif /* NDEBUG */ - this->slices.set(intersection_ex(to_polygons(std::move(this->slices.surfaces)), trimming_polygons, false), stInternal); + this->slices.set(intersection_ex(this->slices.surfaces, trimming_polygons), stInternal); } void LayerRegion::elephant_foot_compensation_step(const float elephant_foot_compensation_perimeter_step, const Polygons &trimming_polygons) @@ -432,10 +430,9 @@ void LayerRegion::elephant_foot_compensation_step(const float elephant_foot_comp for (const Surface &surface : this->slices.surfaces) assert(surface.surface_type == stInternal); #endif /* NDEBUG */ - ExPolygons slices_expolygons = to_expolygons(std::move(this->slices.surfaces)); - Polygons slices_polygons = to_polygons(slices_expolygons); - Polygons tmp = intersection(slices_polygons, trimming_polygons, false); - append(tmp, diff(slices_polygons, offset(offset_ex(slices_expolygons, -elephant_foot_compensation_perimeter_step), elephant_foot_compensation_perimeter_step))); + ExPolygons surfaces = to_expolygons(std::move(this->slices.surfaces)); + Polygons tmp = intersection(surfaces, trimming_polygons); + append(tmp, diff(surfaces, offset(offset_ex(surfaces, -elephant_foot_compensation_perimeter_step), elephant_foot_compensation_perimeter_step))); this->slices.set(union_ex(tmp), stInternal); } diff --git a/src/libslic3r/Line.hpp b/src/libslic3r/Line.hpp index 72532b4e33..b62775bfe4 100644 --- a/src/libslic3r/Line.hpp +++ b/src/libslic3r/Line.hpp @@ -4,6 +4,8 @@ #include "libslic3r.h" #include "Point.hpp" +#include + namespace Slic3r { class BoundingBox; @@ -20,12 +22,28 @@ Linef3 transform(const Linef3& line, const Transform3d& t); namespace line_alg { +template struct Traits { + static constexpr int Dim = L::Dim; + using Scalar = typename L::Scalar; + + static Vec& get_a(L &l) { return l.a; } + static Vec& get_b(L &l) { return l.b; } + static const Vec& get_a(const L &l) { return l.a; } + static const Vec& get_b(const L &l) { return l.b; } +}; + +template const constexpr int Dim = Traits>::Dim; +template using Scalar = typename Traits>::Scalar; + +template auto get_a(L &&l) { return Traits>::get_a(l); } +template auto get_b(L &&l) { return Traits>::get_b(l); } + // Distance to the closest point of line. -template -double distance_to_squared(const L &line, const Vec &point) +template +double distance_to_squared(const L &line, const Vec, Scalar> &point) { - const Vec v = (line.b - line.a).template cast(); - const Vec va = (point - line.a).template cast(); + const Vec, double> v = (get_b(line) - get_a(line)).template cast(); + const Vec, double> va = (point - get_a(line)).template cast(); const double l2 = v.squaredNorm(); // avoid a sqrt if (l2 == 0.0) // a == b case @@ -35,12 +53,12 @@ double distance_to_squared(const L &line, const Vec &point) // It falls where t = [(this-a) . (b-a)] / |b-a|^2 const double t = va.dot(v) / l2; if (t < 0.0) return va.squaredNorm(); // beyond the 'a' end of the segment - else if (t > 1.0) return (point - line.b).template cast().squaredNorm(); // beyond the 'b' end of the segment + else if (t > 1.0) return (point - get_b(line)).template cast().squaredNorm(); // beyond the 'b' end of the segment return (t * v - va).squaredNorm(); } -template -double distance_to(const L &line, const Vec &point) +template +double distance_to(const L &line, const Vec, Scalar> &point) { return std::sqrt(distance_to_squared(line, point)); } @@ -84,6 +102,9 @@ public: Point a; Point b; + + static const constexpr int Dim = 2; + using Scalar = Point::Scalar; }; class ThickLine : public Line @@ -107,6 +128,9 @@ public: Vec3crd a; Vec3crd b; + + static const constexpr int Dim = 3; + using Scalar = Vec3crd::Scalar; }; class Linef @@ -117,6 +141,9 @@ public: Vec2d a; Vec2d b; + + static const constexpr int Dim = 2; + using Scalar = Vec2d::Scalar; }; class Linef3 @@ -133,6 +160,9 @@ public: Vec3d a; Vec3d b; + + static const constexpr int Dim = 3; + using Scalar = Vec3d::Scalar; }; BoundingBox get_extents(const Lines &lines); diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 555cfe5019..9e77aa90af 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -106,13 +106,8 @@ template bool all_of(const C &container) }); } -template struct remove_cvref -{ - using type = - typename std::remove_cv::type>::type; -}; - -template using remove_cvref_t = typename remove_cvref::type; +//template +//using remove_cvref_t = std::remove_reference_t>; /// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html template> diff --git a/src/libslic3r/MinAreaBoundingBox.cpp b/src/libslic3r/MinAreaBoundingBox.cpp index 15c04517d0..51fd8a45e7 100644 --- a/src/libslic3r/MinAreaBoundingBox.cpp +++ b/src/libslic3r/MinAreaBoundingBox.cpp @@ -14,55 +14,9 @@ #include #endif -#include +#include #include -namespace libnest2d { - -template<> struct PointType { using Type = Slic3r::Point; }; -template<> struct CoordType { using Type = coord_t; }; -template<> struct ShapeTag { using Type = PolygonTag; }; -template<> struct ShapeTag { using Type = PolygonTag; }; -template<> struct ShapeTag { using Type = PathTag; }; -template<> struct ShapeTag { using Type = PointTag; }; -template<> struct ContourType { using Type = Slic3r::Points; }; -template<> struct ContourType { using Type = Slic3r::Points; }; - -namespace pointlike { - -template<> inline coord_t x(const Slic3r::Point& p) { return p.x(); } -template<> inline coord_t y(const Slic3r::Point& p) { return p.y(); } -template<> inline coord_t& x(Slic3r::Point& p) { return p.x(); } -template<> inline coord_t& y(Slic3r::Point& p) { return p.y(); } - -} // pointlike - -namespace shapelike { -template<> inline Slic3r::Points& contour(Slic3r::ExPolygon& sh) { return sh.contour.points; } -template<> inline const Slic3r::Points& contour(const Slic3r::ExPolygon& sh) { return sh.contour.points; } -template<> inline Slic3r::Points& contour(Slic3r::Polygon& sh) { return sh.points; } -template<> inline const Slic3r::Points& contour(const Slic3r::Polygon& sh) { return sh.points; } - -template<> Slic3r::Points::iterator begin(Slic3r::Points& pts, const PathTag&) { return pts.begin();} -template<> Slic3r::Points::const_iterator cbegin(const Slic3r::Points& pts, const PathTag&) { return pts.cbegin(); } -template<> Slic3r::Points::iterator end(Slic3r::Points& pts, const PathTag&) { return pts.end();} -template<> Slic3r::Points::const_iterator cend(const Slic3r::Points& pts, const PathTag&) { return pts.cend(); } - -template<> inline Slic3r::ExPolygon create(Slic3r::Points&& contour) -{ - Slic3r::ExPolygon expoly; expoly.contour.points.swap(contour); - return expoly; -} - -template<> inline Slic3r::Polygon create(Slic3r::Points&& contour) -{ - Slic3r::Polygon poly; poly.points.swap(contour); - return poly; -} - -} // shapelike -} // libnest2d - namespace Slic3r { // Used as compute type. @@ -74,13 +28,22 @@ using Rational = boost::rational; using Rational = boost::rational<__int128>; #endif +template +libnest2d::RotatedBox minAreaBoundigBox_( + const P &p, MinAreaBoundigBox::PolygonLevel lvl) +{ + P chull = lvl == MinAreaBoundigBox::pcConvex ? + p : + libnest2d::sl::convexHull(p); + + libnest2d::removeCollinearPoints(chull); + + return libnest2d::minAreaBoundingBox(chull); +} + MinAreaBoundigBox::MinAreaBoundigBox(const Polygon &p, PolygonLevel pc) { - const Polygon &chull = pc == pcConvex ? p : - libnest2d::sl::convexHull(p); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(p, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); @@ -89,11 +52,7 @@ MinAreaBoundigBox::MinAreaBoundigBox(const Polygon &p, PolygonLevel pc) MinAreaBoundigBox::MinAreaBoundigBox(const ExPolygon &p, PolygonLevel pc) { - const ExPolygon &chull = pc == pcConvex ? p : - libnest2d::sl::convexHull(p); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(p, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); @@ -102,11 +61,7 @@ MinAreaBoundigBox::MinAreaBoundigBox(const ExPolygon &p, PolygonLevel pc) MinAreaBoundigBox::MinAreaBoundigBox(const Points &pts, PolygonLevel pc) { - const Points &chull = pc == pcConvex ? pts : - libnest2d::sl::convexHull(pts); - - libnest2d::RotatedBox box = - libnest2d::minAreaBoundingBox(chull); + libnest2d::RotatedBox box = minAreaBoundigBox_(pts, pc); m_right = libnest2d::cast(box.right_extent()); m_bottom = libnest2d::cast(box.bottom_extent()); diff --git a/src/libslic3r/MinAreaBoundingBox.hpp b/src/libslic3r/MinAreaBoundingBox.hpp index 30d0e9799d..242fc96111 100644 --- a/src/libslic3r/MinAreaBoundingBox.hpp +++ b/src/libslic3r/MinAreaBoundingBox.hpp @@ -26,12 +26,8 @@ public: }; // Constructors with various types of geometry data used in Slic3r. - // If the convexity is known apriory, pcConvex can be used to skip - // convex hull calculation. It is very important that the input polygons - // do NOT have any collinear points (except for the first and the last - // vertex being the same -- meaning a closed polygon for boost) - // To make sure this constraint is satisfied, you can call - // remove_collinear_points on the input polygon before handing over here) + // If the convexity is known apriory, pcConvex can be used to skip + // convex hull calculation. explicit MinAreaBoundigBox(const Polygon&, PolygonLevel = pcSimple); explicit MinAreaBoundigBox(const ExPolygon&, PolygonLevel = pcSimple); explicit MinAreaBoundigBox(const Points&, PolygonLevel = pcSimple); diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index d48443181f..8b829fc138 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -833,18 +833,6 @@ indexed_triangle_set ModelObject::raw_indexed_triangle_set() const return out; } -// Non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes. -TriangleMesh ModelObject::full_raw_mesh() const -{ - TriangleMesh mesh; - for (const ModelVolume *v : this->volumes) - { - TriangleMesh vol_mesh(v->mesh()); - vol_mesh.transform(v->get_matrix()); - mesh.merge(vol_mesh); - } - return mesh; -} const BoundingBoxf3& ModelObject::raw_mesh_bounding_box() const { diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 868639ee80..50797aeeb5 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -289,8 +289,6 @@ public: TriangleMesh raw_mesh() const; // The same as above, but producing a lightweight indexed_triangle_set. indexed_triangle_set raw_indexed_triangle_set() const; - // Non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes. - TriangleMesh full_raw_mesh() const; // A transformed snug bounding box around the non-modifier object volumes, without the translation applied. // This bounding box is only used for the actual slicing. const BoundingBoxf3& raw_bounding_box() const; diff --git a/src/libslic3r/MultiPoint.hpp b/src/libslic3r/MultiPoint.hpp index d5bac7249c..46b47832a7 100644 --- a/src/libslic3r/MultiPoint.hpp +++ b/src/libslic3r/MultiPoint.hpp @@ -64,6 +64,7 @@ public: bool has_duplicate_points() const; // Remove exact duplicates, return true if any duplicate has been removed. bool remove_duplicate_points(); + void clear() { this->points.clear(); } void append(const Point &point) { this->points.push_back(point); } void append(const Points &src) { this->append(src.begin(), src.end()); } void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); } @@ -83,6 +84,13 @@ public: static Points _douglas_peucker(const Points &points, const double tolerance); static Points visivalingam(const Points& pts, const double& tolerance); + + inline auto begin() { return points.begin(); } + inline auto begin() const { return points.begin(); } + inline auto end() { return points.end(); } + inline auto end() const { return points.end(); } + inline auto cbegin() const { return points.begin(); } + inline auto cend() const { return points.end(); } }; class MultiPoint3 diff --git a/src/libslic3r/Optimize/Optimizer.hpp b/src/libslic3r/Optimize/Optimizer.hpp index 05191eba26..8ae55c61c5 100644 --- a/src/libslic3r/Optimize/Optimizer.hpp +++ b/src/libslic3r/Optimize/Optimizer.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Slic3r { namespace opt { diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index 6ec4dbf6b8..a459b90fad 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -349,9 +349,7 @@ void PerimeterGenerator::process() coord_t min_width = coord_t(scale_(this->ext_perimeter_flow.nozzle_diameter() / 3)); ExPolygons expp = offset2_ex( // medial axis requires non-overlapping geometry - diff_ex(to_polygons(last), - offset(offsets, float(ext_perimeter_width / 2.)), - true), + diff_ex(last, offset(offsets, float(ext_perimeter_width / 2.)), true), - float(min_width / 2.), float(min_width / 2.)); // the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop for (ExPolygon &ex : expp) @@ -514,7 +512,7 @@ void PerimeterGenerator::process() and use zigzag). */ //FIXME Vojtech: This grows by a rounded extrusion width, not by line spacing, // therefore it may cover the area, but no the volume. - last = diff_ex(to_polygons(last), gap_fill.polygons_covered_by_width(10.f)); + last = diff_ex(last, gap_fill.polygons_covered_by_width(10.f)); this->gap_fill->append(std::move(gap_fill.entities)); } } diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index 84b4a825da..12870b7132 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -17,42 +17,42 @@ class BoundingBox; class Line; class MultiPoint; class Point; -typedef Point Vector; +using Vector = Point; // Eigen types, to replace the Slic3r's own types in the future. // Vector types with a fixed point coordinate base type. -typedef Eigen::Matrix Vec2crd; -typedef Eigen::Matrix Vec3crd; -typedef Eigen::Matrix Vec2i; -typedef Eigen::Matrix Vec3i; -typedef Eigen::Matrix Vec2i32; -typedef Eigen::Matrix Vec2i64; -typedef Eigen::Matrix Vec3i32; -typedef Eigen::Matrix Vec3i64; +using Vec2crd = Eigen::Matrix; +using Vec3crd = Eigen::Matrix; +using Vec2i = Eigen::Matrix; +using Vec3i = Eigen::Matrix; +using Vec2i32 = Eigen::Matrix; +using Vec2i64 = Eigen::Matrix; +using Vec3i32 = Eigen::Matrix; +using Vec3i64 = Eigen::Matrix; // Vector types with a double coordinate base type. -typedef Eigen::Matrix Vec2f; -typedef Eigen::Matrix Vec3f; -typedef Eigen::Matrix Vec2d; -typedef Eigen::Matrix Vec3d; +using Vec2f = Eigen::Matrix; +using Vec3f = Eigen::Matrix; +using Vec2d = Eigen::Matrix; +using Vec3d = Eigen::Matrix; -typedef std::vector Points; -typedef std::vector PointPtrs; -typedef std::vector PointConstPtrs; -typedef std::vector Points3; -typedef std::vector Pointfs; -typedef std::vector Vec2ds; -typedef std::vector Pointf3s; +using Points = std::vector; +using PointPtrs = std::vector; +using PointConstPtrs = std::vector; +using Points3 = std::vector; +using Pointfs = std::vector; +using Vec2ds = std::vector; +using Pointf3s = std::vector; -typedef Eigen::Matrix Matrix2f; -typedef Eigen::Matrix Matrix2d; -typedef Eigen::Matrix Matrix3f; -typedef Eigen::Matrix Matrix3d; +using Matrix2f = Eigen::Matrix; +using Matrix2d = Eigen::Matrix; +using Matrix3f = Eigen::Matrix; +using Matrix3d = Eigen::Matrix; -typedef Eigen::Transform Transform2f; -typedef Eigen::Transform Transform2d; -typedef Eigen::Transform Transform3f; -typedef Eigen::Transform Transform3d; +using Transform2f = Eigen::Transform; +using Transform2d = Eigen::Transform; +using Transform3f = Eigen::Transform; +using Transform3d = Eigen::Transform; inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); } @@ -101,7 +101,7 @@ template using Vec = Eigen::Matrix map_type; + using map_type = typename std::unordered_multimap; PointAccessor m_point_accessor; map_type m_map; coord_t m_search_radius; @@ -413,6 +413,25 @@ unscaled(const Eigen::Matrix &v) noexcept return v.template cast() * SCALING_FACTOR; } +// Align a coordinate to a grid. The coordinate may be negative, +// the aligned value will never be bigger than the original one. +inline coord_t align_to_grid(const coord_t coord, const coord_t spacing) { + // Current C++ standard defines the result of integer division to be rounded to zero, + // for both positive and negative numbers. Here we want to round down for negative + // numbers as well. + coord_t aligned = (coord < 0) ? + ((coord - spacing + 1) / spacing) * spacing : + (coord / spacing) * spacing; + assert(aligned <= coord); + return aligned; +} +inline Point align_to_grid(Point coord, Point spacing) + { return Point(align_to_grid(coord.x(), spacing.x()), align_to_grid(coord.y(), spacing.y())); } +inline coord_t align_to_grid(coord_t coord, coord_t spacing, coord_t base) + { return base + align_to_grid(coord - base, spacing); } +inline Point align_to_grid(Point coord, Point spacing, Point base) + { return Point(align_to_grid(coord.x(), spacing.x(), base.x()), align_to_grid(coord.y(), spacing.y(), base.y())); } + } // namespace Slic3r // start Boost @@ -420,11 +439,11 @@ unscaled(const Eigen::Matrix &v) noexcept #include namespace boost { namespace polygon { template <> - struct geometry_concept { typedef point_concept type; }; + struct geometry_concept { using type = point_concept; }; template <> struct point_traits { - typedef coord_t coordinate_type; + using coordinate_type = coord_t; static inline coordinate_type get(const Slic3r::Point& point, orientation_2d orient) { return static_cast(point((orient == HORIZONTAL) ? 0 : 1)); @@ -433,7 +452,7 @@ namespace boost { namespace polygon { template <> struct point_mutable_traits { - typedef coord_t coordinate_type; + using coordinate_type = coord_t; static inline void set(Slic3r::Point& point, orientation_2d orient, coord_t value) { point((orient == HORIZONTAL) ? 0 : 1) = value; } diff --git a/src/libslic3r/Polygon.cpp b/src/libslic3r/Polygon.cpp index 7c588c67cc..e744272ac0 100644 --- a/src/libslic3r/Polygon.cpp +++ b/src/libslic3r/Polygon.cpp @@ -70,7 +70,7 @@ double Polygon::area() const bool Polygon::is_counter_clockwise() const { - return ClipperLib::Orientation(Slic3rMultiPoint_to_ClipperPath(*this)); + return ClipperLib::Orientation(this->points); } bool Polygon::is_clockwise() const diff --git a/src/libslic3r/Polygon.hpp b/src/libslic3r/Polygon.hpp index aa72b4244d..333f1e6b1a 100644 --- a/src/libslic3r/Polygon.hpp +++ b/src/libslic3r/Polygon.hpp @@ -11,7 +11,9 @@ namespace Slic3r { class Polygon; -typedef std::vector Polygons; +using Polygons = std::vector; +using PolygonPtrs = std::vector; +using ConstPolygonPtrs = std::vector; class Polygon : public MultiPoint { @@ -70,6 +72,9 @@ public: // Projection of a point onto the polygon. Point point_projection(const Point &point) const; std::vector parameter_by_length() const; + + using iterator = Points::iterator; + using const_iterator = Points::const_iterator; }; inline bool operator==(const Polygon &lhs, const Polygon &rhs) { return lhs.points == rhs.points; } @@ -88,6 +93,8 @@ inline double total_length(const Polygons &polylines) { return total; } +inline double area(const Polygon &poly) { return poly.area(); } + inline double area(const Polygons &polys) { double s = 0.; @@ -215,6 +222,24 @@ inline Polylines to_polylines(Polygons &&polys) return polylines; } +inline Polygons to_polygons(const std::vector &paths) +{ + Polygons out; + out.reserve(paths.size()); + for (const Points &path : paths) + out.emplace_back(path); + return out; +} + +inline Polygons to_polygons(std::vector &&paths) +{ + Polygons out; + out.reserve(paths.size()); + for (const Points &path : paths) + out.emplace_back(std::move(path)); + return out; +} + } // Slic3r // start Boost diff --git a/src/libslic3r/Polyline.hpp b/src/libslic3r/Polyline.hpp index 9c70522bfb..88f910590b 100644 --- a/src/libslic3r/Polyline.hpp +++ b/src/libslic3r/Polyline.hpp @@ -124,6 +124,24 @@ inline Lines to_lines(const Polylines &polys) return lines; } +inline Polylines to_polylines(const std::vector &paths) +{ + Polylines out; + out.reserve(paths.size()); + for (const Points &path : paths) + out.emplace_back(path); + return out; +} + +inline Polylines to_polylines(std::vector &&paths) +{ + Polylines out; + out.reserve(paths.size()); + for (const Points &path : paths) + out.emplace_back(std::move(path)); + return out; +} + inline void polylines_append(Polylines &dst, const Polylines &src) { dst.insert(dst.end(), src.begin(), src.end()); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index aae6a29dcc..99492864b0 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -296,6 +296,13 @@ void Preset::normalize(DynamicPrintConfig &config) if (auto *gap_fill_enabled = config.option("gap_fill_enabled", false); gap_fill_enabled) gap_fill_enabled->value = false; } + if (auto *first_layer_height = config.option("first_layer_height", false); first_layer_height && first_layer_height->percent) + if (const auto *layer_height = config.option("layer_height", false); layer_height) { + // Legacy conversion - first_layer_height moved from PrintObject setting to a Print setting, thus we are getting rid of the dependency + // of first_layer_height on PrintObject specific layer_height. Covert the first layer heigth to an absolute value. + first_layer_height->value = first_layer_height->get_abs_value(layer_height->value); + first_layer_height->percent = false; + } } std::string Preset::remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config) @@ -427,7 +434,7 @@ const std::vector& Preset::print_options() "bridge_acceleration", "first_layer_acceleration", "default_acceleration", "skirts", "skirt_distance", "skirt_height", "draft_shield", "min_skirt_length", "brim_width", "brim_offset", "brim_type", "support_material", "support_material_auto", "support_material_threshold", "support_material_enforce_layers", "raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion", - "support_material_pattern", "support_material_with_sheath", "support_material_spacing", "support_material_style", + "support_material_pattern", "support_material_with_sheath", "support_material_spacing", "support_material_closing_radius", "support_material_style", "support_material_synchronize_layers", "support_material_angle", "support_material_interface_layers", "support_material_bottom_interface_layers", "support_material_interface_pattern", "support_material_interface_spacing", "support_material_interface_contact_loops", "support_material_contact_distance", "support_material_bottom_contact_distance", @@ -468,7 +475,7 @@ const std::vector& Preset::machine_limits_options() static std::vector s_opts; if (s_opts.empty()) { s_opts = { - "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", + "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", "machine_max_acceleration_travel", "machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e", "machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e", "machine_min_extruding_rate", "machine_min_travel_rate", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index e39fd8685e..7fcb752978 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -100,7 +100,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "filament_spool_weight", "first_layer_acceleration", "first_layer_bed_temperature", - "first_layer_speed", "gcode_comments", "gcode_label_objects", "infill_acceleration", @@ -139,7 +138,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "start_filament_gcode", "toolchange_gcode", "threads", - "travel_speed", "use_firmware_retraction", "use_relative_e_distances", "use_volumetric_e", @@ -182,7 +180,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n } else if ( opt_key == "complete_objects" || opt_key == "filament_type" - || opt_key == "filament_soluble" || opt_key == "first_layer_temperature" || opt_key == "filament_loading_speed" || opt_key == "filament_loading_speed_start" @@ -210,9 +207,17 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n || opt_key == "cooling_tube_retraction" || opt_key == "cooling_tube_length" || opt_key == "extra_loading_move" + || opt_key == "travel_speed" + || opt_key == "first_layer_speed" || opt_key == "z_offset") { steps.emplace_back(psWipeTower); steps.emplace_back(psSkirt); + } else if (opt_key == "filament_soluble") { + steps.emplace_back(psWipeTower); + // Soluble support interface / non-soluble base interface produces non-soluble interface layers below soluble interface layers. + // Thus switching between soluble / non-soluble interface layer material may require recalculation of supports. + //FIXME Killing supports on any change of "filament_soluble" is rough. We should check for each object whether that is necessary. + osteps.emplace_back(posSupportMaterial); } else if ( opt_key == "first_layer_extrusion_width" || opt_key == "min_layer_height" @@ -1293,7 +1298,7 @@ std::string Print::validate(std::string* warning) const } if (m_config.gcode_flavor != gcfRepRapSprinter && m_config.gcode_flavor != gcfRepRapFirmware && - m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlin) + m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlinLegacy && m_config.gcode_flavor != gcfMarlinFirmware) return L("The Wipe Tower is currently only supported for the Marlin, RepRap/Sprinter, RepRapFirmware and Repetier G-code flavors."); if (! m_config.use_relative_e_distances) return L("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1)."); @@ -1459,7 +1464,8 @@ std::string Print::validate(std::string* warning) const } // validate first_layer_height - double first_layer_height = object->config().get_abs_value("first_layer_height"); + assert(! m_config.first_layer_height.percent); + double first_layer_height = m_config.first_layer_height.value; double first_layer_min_nozzle_diameter; if (object->has_raft()) { // if we have raft layers, only support material extruder is used on first layer @@ -1556,9 +1562,8 @@ BoundingBox Print::total_bounding_box() const double Print::skirt_first_layer_height() const { - if (m_objects.empty()) - throw Slic3r::InvalidArgument("skirt_first_layer_height() can't be called without PrintObjects"); - return m_objects.front()->config().get_abs_value("first_layer_height"); + assert(! m_config.first_layer_height.percent); + return m_config.first_layer_height.value; } Flow Print::brim_flow() const @@ -1987,9 +1992,7 @@ void Print::_make_wipe_tower() // Set the extruder & material properties at the wipe tower object. for (size_t i = 0; i < number_of_extruders; ++ i) - - wipe_tower.set_extruder( - i, m_config); + wipe_tower.set_extruder(i, m_config); m_wipe_tower_data.priming = Slic3r::make_unique>( wipe_tower.prime((float)this->skirt_first_layer_height(), m_wipe_tower_data.tool_ordering.all_extruders(), false)); @@ -2015,8 +2018,8 @@ void Print::_make_wipe_tower() volume_to_wipe += (float)m_config.filament_minimal_purge_on_wipe_tower.get_at(extruder_id); // request a toolchange at the wipe tower with at least volume_to_wipe purging amount - wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, - first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back(), volume_to_wipe); + wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, + current_extruder_id, extruder_id, volume_to_wipe); current_extruder_id = extruder_id; } } diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 2c6918acf0..f2c5f70a97 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -995,10 +995,8 @@ void PrintConfigDef::init_fff_params() def->label = L("First layer height"); def->category = L("Layers and Perimeters"); def->tooltip = L("When printing with very low layer heights, you might still want to print a thicker " - "bottom layer to improve adhesion and tolerance for non perfect build plates. " - "This can be expressed as an absolute value or as a percentage (for example: 150%) " - "over the default layer height."); - def->sidetext = L("mm or %"); + "bottom layer to improve adhesion and tolerance for non perfect build plates."); + def->sidetext = L("mm"); def->ratio_over = "layer_height"; def->set_default_value(new ConfigOptionFloatOrPercent(0.35, false)); @@ -1103,6 +1101,7 @@ void PrintConfigDef::init_fff_params() def->enum_values.push_back("teacup"); def->enum_values.push_back("makerware"); def->enum_values.push_back("marlin"); + def->enum_values.push_back("marlinfirmware"); def->enum_values.push_back("sailfish"); def->enum_values.push_back("mach3"); def->enum_values.push_back("machinekit"); @@ -1113,7 +1112,8 @@ void PrintConfigDef::init_fff_params() def->enum_labels.push_back("Repetier"); def->enum_labels.push_back("Teacup"); def->enum_labels.push_back("MakerWare (MakerBot)"); - def->enum_labels.push_back("Marlin"); + def->enum_labels.push_back("Marlin (legacy)"); + def->enum_labels.push_back("Marlin Firmware"); def->enum_labels.push_back("Sailfish (MakerBot)"); def->enum_labels.push_back("Mach3/LinuxCNC"); def->enum_labels.push_back("Machinekit"); @@ -1467,21 +1467,34 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloats{ 0., 0. }); - // M204 S... [mm/sec^2] + // M204 P... [mm/sec^2] def = this->add("machine_max_acceleration_extruding", coFloats); def->full_label = L("Maximum acceleration when extruding"); def->category = L("Machine limits"); - def->tooltip = L("Maximum acceleration when extruding (M204 S)"); + def->tooltip = L("Maximum acceleration when extruding (M204 P)\n\n" + "Marlin (legacy) firmware flavor will use this also " + "as travel acceleration (M204 T)."); + def->sidetext = L("mm/s²"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); + + + // M204 R... [mm/sec^2] + def = this->add("machine_max_acceleration_retracting", coFloats); + def->full_label = L("Maximum acceleration when retracting"); + def->category = L("Machine limits"); + def->tooltip = L("Maximum acceleration when retracting (M204 R)"); def->sidetext = L("mm/s²"); def->min = 0; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); // M204 T... [mm/sec^2] - def = this->add("machine_max_acceleration_retracting", coFloats); - def->full_label = L("Maximum acceleration when retracting"); + def = this->add("machine_max_acceleration_travel", coFloats); + def->full_label = L("Maximum acceleration for travel moves"); def->category = L("Machine limits"); - def->tooltip = L("Maximum acceleration when retracting (M204 T)"); + def->tooltip = L("Maximum acceleration for travel moves (M204 T)"); def->sidetext = L("mm/s²"); def->min = 0; def->mode = comAdvanced; @@ -1799,8 +1812,8 @@ void PrintConfigDef::init_fff_params() def->category = L("Support material"); def->tooltip = L("Density of the first raft or support layer."); def->sidetext = L("%"); - def->min = 0; - def->max = 150; + def->min = 10; + def->max = 100; def->mode = comExpert; def->set_default_value(new ConfigOptionPercent(90)); @@ -2351,6 +2364,16 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionInt(-1)); + def = this->add("support_material_closing_radius", coFloat); + def->label = L("Closing radius"); + def->category = L("Support material"); + def->tooltip = L("For snug supports, the support regions will be merged using morphological closing operation." + " Gaps smaller than the closing radius will be filled in."); + def->sidetext = L("mm"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(2)); + def = this->add("support_material_interface_spacing", coFloat); def->label = L("Interface pattern spacing"); def->category = L("Support material"); @@ -3585,7 +3608,7 @@ std::string DynamicPrintConfig::validate() FullPrintConfig fpc; fpc.apply(*this, true); // Verify this print options through the FullPrintConfig. - return fpc.validate(); + return Slic3r::validate(fpc); } default: //FIXME no validation on SLA data? @@ -3594,134 +3617,135 @@ std::string DynamicPrintConfig::validate() } //FIXME localize this function. -std::string FullPrintConfig::validate() +std::string validate(const FullPrintConfig &cfg) { // --layer-height - if (this->get_abs_value("layer_height") <= 0) + if (cfg.get_abs_value("layer_height") <= 0) return "Invalid value for --layer-height"; - if (fabs(fmod(this->get_abs_value("layer_height"), SCALING_FACTOR)) > 1e-4) + if (fabs(fmod(cfg.get_abs_value("layer_height"), SCALING_FACTOR)) > 1e-4) return "--layer-height must be a multiple of print resolution"; // --first-layer-height - if (this->get_abs_value("first_layer_height") <= 0) + if (cfg.first_layer_height.value <= 0) return "Invalid value for --first-layer-height"; // --filament-diameter - for (double fd : this->filament_diameter.values) + for (double fd : cfg.filament_diameter.values) if (fd < 1) return "Invalid value for --filament-diameter"; // --nozzle-diameter - for (double nd : this->nozzle_diameter.values) + for (double nd : cfg.nozzle_diameter.values) if (nd < 0.005) return "Invalid value for --nozzle-diameter"; // --perimeters - if (this->perimeters.value < 0) + if (cfg.perimeters.value < 0) return "Invalid value for --perimeters"; // --solid-layers - if (this->top_solid_layers < 0) + if (cfg.top_solid_layers < 0) return "Invalid value for --top-solid-layers"; - if (this->bottom_solid_layers < 0) + if (cfg.bottom_solid_layers < 0) return "Invalid value for --bottom-solid-layers"; - if (this->use_firmware_retraction.value && - this->gcode_flavor.value != gcfSmoothie && - this->gcode_flavor.value != gcfRepRapSprinter && - this->gcode_flavor.value != gcfRepRapFirmware && - this->gcode_flavor.value != gcfMarlin && - this->gcode_flavor.value != gcfMachinekit && - this->gcode_flavor.value != gcfRepetier) + if (cfg.use_firmware_retraction.value && + cfg.gcode_flavor.value != gcfSmoothie && + cfg.gcode_flavor.value != gcfRepRapSprinter && + cfg.gcode_flavor.value != gcfRepRapFirmware && + cfg.gcode_flavor.value != gcfMarlinLegacy && + cfg.gcode_flavor.value != gcfMarlinFirmware && + cfg.gcode_flavor.value != gcfMachinekit && + cfg.gcode_flavor.value != gcfRepetier) return "--use-firmware-retraction is only supported by Marlin, Smoothie, RepRapFirmware, Repetier and Machinekit firmware"; - if (this->use_firmware_retraction.value) - for (unsigned char wipe : this->wipe.values) + if (cfg.use_firmware_retraction.value) + for (unsigned char wipe : cfg.wipe.values) if (wipe) return "--use-firmware-retraction is not compatible with --wipe"; // --gcode-flavor - if (! print_config_def.get("gcode_flavor")->has_enum_value(this->gcode_flavor.serialize())) + if (! print_config_def.get("gcode_flavor")->has_enum_value(cfg.gcode_flavor.serialize())) return "Invalid value for --gcode-flavor"; // --fill-pattern - if (! print_config_def.get("fill_pattern")->has_enum_value(this->fill_pattern.serialize())) + if (! print_config_def.get("fill_pattern")->has_enum_value(cfg.fill_pattern.serialize())) return "Invalid value for --fill-pattern"; // --top-fill-pattern - if (! print_config_def.get("top_fill_pattern")->has_enum_value(this->top_fill_pattern.serialize())) + if (! print_config_def.get("top_fill_pattern")->has_enum_value(cfg.top_fill_pattern.serialize())) return "Invalid value for --top-fill-pattern"; // --bottom-fill-pattern - if (! print_config_def.get("bottom_fill_pattern")->has_enum_value(this->bottom_fill_pattern.serialize())) + if (! print_config_def.get("bottom_fill_pattern")->has_enum_value(cfg.bottom_fill_pattern.serialize())) return "Invalid value for --bottom-fill-pattern"; // --fill-density - if (fabs(this->fill_density.value - 100.) < EPSILON && - ! print_config_def.get("top_fill_pattern")->has_enum_value(this->fill_pattern.serialize())) + if (fabs(cfg.fill_density.value - 100.) < EPSILON && + ! print_config_def.get("top_fill_pattern")->has_enum_value(cfg.fill_pattern.serialize())) return "The selected fill pattern is not supposed to work at 100% density"; // --infill-every-layers - if (this->infill_every_layers < 1) + if (cfg.infill_every_layers < 1) return "Invalid value for --infill-every-layers"; // --skirt-height - if (this->skirt_height < 0) + if (cfg.skirt_height < 0) return "Invalid value for --skirt-height"; // --bridge-flow-ratio - if (this->bridge_flow_ratio <= 0) + if (cfg.bridge_flow_ratio <= 0) return "Invalid value for --bridge-flow-ratio"; // extruder clearance - if (this->extruder_clearance_radius <= 0) + if (cfg.extruder_clearance_radius <= 0) return "Invalid value for --extruder-clearance-radius"; - if (this->extruder_clearance_height <= 0) + if (cfg.extruder_clearance_height <= 0) return "Invalid value for --extruder-clearance-height"; // --extrusion-multiplier - for (double em : this->extrusion_multiplier.values) + for (double em : cfg.extrusion_multiplier.values) if (em <= 0) return "Invalid value for --extrusion-multiplier"; // --default-acceleration - if ((this->perimeter_acceleration != 0. || this->infill_acceleration != 0. || this->bridge_acceleration != 0. || this->first_layer_acceleration != 0.) && - this->default_acceleration == 0.) + if ((cfg.perimeter_acceleration != 0. || cfg.infill_acceleration != 0. || cfg.bridge_acceleration != 0. || cfg.first_layer_acceleration != 0.) && + cfg.default_acceleration == 0.) return "Invalid zero value for --default-acceleration when using other acceleration settings"; // --spiral-vase - if (this->spiral_vase) { + if (cfg.spiral_vase) { // Note that we might want to have more than one perimeter on the bottom // solid layers. - if (this->perimeters > 1) + if (cfg.perimeters > 1) return "Can't make more than one perimeter when spiral vase mode is enabled"; - else if (this->perimeters < 1) + else if (cfg.perimeters < 1) return "Can't make less than one perimeter when spiral vase mode is enabled"; - if (this->fill_density > 0) + if (cfg.fill_density > 0) return "Spiral vase mode can only print hollow objects, so you need to set Fill density to 0"; - if (this->top_solid_layers > 0) + if (cfg.top_solid_layers > 0) return "Spiral vase mode is not compatible with top solid layers"; - if (this->support_material || this->support_material_enforce_layers > 0) + if (cfg.support_material || cfg.support_material_enforce_layers > 0) return "Spiral vase mode is not compatible with support material"; } // extrusion widths { double max_nozzle_diameter = 0.; - for (double dmr : this->nozzle_diameter.values) + for (double dmr : cfg.nozzle_diameter.values) max_nozzle_diameter = std::max(max_nozzle_diameter, dmr); const char *widths[] = { "external_perimeter", "perimeter", "infill", "solid_infill", "top_infill", "support_material", "first_layer" }; for (size_t i = 0; i < sizeof(widths) / sizeof(widths[i]); ++ i) { std::string key(widths[i]); key += "_extrusion_width"; - if (this->get_abs_value(key, max_nozzle_diameter) > 10. * max_nozzle_diameter) + if (cfg.get_abs_value(key, max_nozzle_diameter) > 10. * max_nozzle_diameter) return std::string("Invalid extrusion width (too large): ") + key; } } // Out of range validation of numeric values. - for (const std::string &opt_key : this->keys()) { - const ConfigOption *opt = this->optptr(opt_key); + for (const std::string &opt_key : cfg.keys()) { + const ConfigOption *opt = cfg.optptr(opt_key); assert(opt != nullptr); const ConfigOptionDef *optdef = print_config_def.get(opt_key); assert(optdef != nullptr); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 10f3b11d5e..7209bea899 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -19,20 +19,28 @@ #include "libslic3r.h" #include "Config.hpp" +#include +#include +#include +#include +#include +#include +#include + // #define HAS_PRESSURE_EQUALIZER namespace Slic3r { enum GCodeFlavor : unsigned char { - gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlin, gcfSailfish, gcfMach3, gcfMachinekit, + gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlinLegacy, gcfMarlinFirmware, gcfSailfish, gcfMach3, gcfMachinekit, gcfSmoothie, gcfNoExtrusion, }; enum class MachineLimitsUsage { - EmitToGCode, - TimeEstimateOnly, - Ignore, - Count, + EmitToGCode, + TimeEstimateOnly, + Ignore, + Count, }; enum PrintHostType { @@ -51,14 +59,14 @@ enum class FuzzySkinType { enum InfillPattern : int { ipRectilinear, ipMonotonic, ipAlignedRectilinear, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, - ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipCount, + ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipSupportBase, ipCount, }; enum class IroningType { - TopSurfaces, - TopmostOnly, - AllSolid, - Count, + TopSurfaces, + TopmostOnly, + AllSolid, + Count, }; enum SupportMaterialPattern { @@ -120,7 +128,8 @@ template<> inline const t_config_enum_values& ConfigOptionEnum::get keys_map["repetier"] = gcfRepetier; keys_map["teacup"] = gcfTeacup; keys_map["makerware"] = gcfMakerWare; - keys_map["marlin"] = gcfMarlin; + keys_map["marlin"] = gcfMarlinLegacy; + keys_map["marlinfirmware"] = gcfMarlinFirmware; keys_map["sailfish"] = gcfSailfish; keys_map["smoothie"] = gcfSmoothie; keys_map["mach3"] = gcfMach3; @@ -135,7 +144,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum m_extruder_option_keys; - std::vector m_extruder_retract_keys; + std::vector m_extruder_option_keys; + std::vector m_extruder_retract_keys; }; // The one and only global definition of SLic3r configuration options. @@ -336,7 +345,7 @@ public: void normalize_fdm(); - void set_num_extruders(unsigned int num_extruders); + void set_num_extruders(unsigned int num_extruders); // Validate the PrintConfig. Returns an empty string on success, otherwise an error message is returned. std::string validate(); @@ -357,7 +366,7 @@ public: // Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here. const ConfigDef* def() const override { return &print_config_def; } // Reference to the cached list of keys. - virtual const t_config_option_keys& keys_ref() const = 0; + virtual const t_config_option_keys& keys_ref() const = 0; protected: // Verify whether the opt_key has not been obsoleted or renamed. @@ -481,723 +490,498 @@ public: \ void handle_legacy(t_config_option_key &opt_key, std::string &value) const override \ { PrintConfigDef::handle_legacy(opt_key, value); } -#define OPT_PTR(KEY) cache.opt_add(#KEY, base_ptr, this->KEY) +#define PRINT_CONFIG_CLASS_ELEMENT_DEFINITION(r, data, elem) BOOST_PP_TUPLE_ELEM(0, elem) BOOST_PP_TUPLE_ELEM(1, elem); +#define PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2(KEY) cache.opt_add(BOOST_PP_STRINGIZE(KEY), base_ptr, this->KEY); +#define PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION(r, data, elem) PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2(BOOST_PP_TUPLE_ELEM(1, elem)) +#define PRINT_CONFIG_CLASS_ELEMENT_HASH(r, data, elem) boost::hash_combine(seed, BOOST_PP_TUPLE_ELEM(1, elem).hash()); +#define PRINT_CONFIG_CLASS_ELEMENT_EQUAL(r, data, elem) if (! (BOOST_PP_TUPLE_ELEM(1, elem) == rhs.BOOST_PP_TUPLE_ELEM(1, elem))) return false; + +#define PRINT_CONFIG_CLASS_DEFINE(CLASS_NAME, PARAMETER_DEFINITION_SEQ) \ +class CLASS_NAME : public StaticPrintConfig { \ + STATIC_PRINT_CONFIG_CACHE(CLASS_NAME) \ +public: \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_DEFINITION, _, PARAMETER_DEFINITION_SEQ) \ + size_t hash() const throw() \ + { \ + size_t seed = 0; \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_HASH, _, PARAMETER_DEFINITION_SEQ) \ + return seed; \ + } \ + bool operator==(const CLASS_NAME &rhs) const throw() \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_EQUAL, _, PARAMETER_DEFINITION_SEQ) \ + return true; \ + } \ + bool operator!=(const CLASS_NAME &rhs) const throw() { return ! (*this == rhs); } \ +protected: \ + void initialize(StaticCacheBase &cache, const char *base_ptr) \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION, _, PARAMETER_DEFINITION_SEQ) \ + } \ +}; + +#define PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM(r, data, i, elem) BOOST_PP_COMMA_IF(i) public elem +#define PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST(CLASSES_PARENTS_TUPLE) BOOST_PP_SEQ_FOR_EACH_I(PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM(r, VALUE, i, elem) BOOST_PP_COMMA_IF(i) elem(VALUE) +#define PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, VALUE) BOOST_PP_SEQ_FOR_EACH_I(PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM, VALUE, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM(r, data, elem) this->elem::initialize(cache, base_ptr); +#define PRINT_CONFIG_CLASS_DERIVED_INITCACHE(CLASSES_PARENTS_TUPLE) BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_HASH(r, data, elem) boost::hash_combine(seed, static_cast(this)->hash()); +#define PRINT_CONFIG_CLASS_DERIVED_EQUAL(r, data, elem) \ + if (! (*static_cast(this) == static_cast(rhs))) return false; + +// Generic version, with or without new parameters. Don't use this directly. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, PARAMETER_DEFINITION, PARAMETER_REGISTRATION, PARAMETER_HASHES, PARAMETER_EQUALS) \ +class CLASS_NAME : PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST(CLASSES_PARENTS_TUPLE) { \ + STATIC_PRINT_CONFIG_CACHE_DERIVED(CLASS_NAME) \ + CLASS_NAME() : PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, 0) { initialize_cache(); *this = s_cache_##CLASS_NAME.defaults(); } \ +public: \ + PARAMETER_DEFINITION \ + size_t hash() const throw() \ + { \ + size_t seed = 0; \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_HASH, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) \ + PARAMETER_HASHES \ + return seed; \ + } \ + bool operator==(const CLASS_NAME &rhs) const throw() \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_EQUAL, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) \ + PARAMETER_EQUALS \ + return true; \ + } \ + bool operator!=(const CLASS_NAME &rhs) const throw() { return ! (*this == rhs); } \ +protected: \ + CLASS_NAME(int) : PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, 1) {} \ + void initialize(StaticCacheBase &cache, const char* base_ptr) { \ + PRINT_CONFIG_CLASS_DERIVED_INITCACHE(CLASSES_PARENTS_TUPLE) \ + PARAMETER_REGISTRATION \ + } \ +}; +// Variant without adding new parameters. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE0(CLASS_NAME, CLASSES_PARENTS_TUPLE) \ + PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, BOOST_PP_EMPTY(), BOOST_PP_EMPTY(), BOOST_PP_EMPTY(), BOOST_PP_EMPTY()) +// Variant with adding new parameters. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE(CLASS_NAME, CLASSES_PARENTS_TUPLE, PARAMETER_DEFINITION_SEQ) \ + PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_DEFINITION, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_HASH, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_EQUAL, _, PARAMETER_DEFINITION_SEQ)) // This object is mapped to Perl as Slic3r::Config::PrintObject. -class PrintObjectConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(PrintObjectConfig) -public: - ConfigOptionFloat brim_offset; - ConfigOptionEnum brim_type; - ConfigOptionFloat brim_width; - ConfigOptionBool clip_multipart_objects; - ConfigOptionBool dont_support_bridges; - ConfigOptionFloat elefant_foot_compensation; - ConfigOptionFloatOrPercent extrusion_width; - ConfigOptionFloatOrPercent first_layer_height; - ConfigOptionBool infill_only_where_needed; - // Force the generation of solid shells between adjacent materials/volumes. - ConfigOptionBool interface_shells; - ConfigOptionFloat layer_height; - ConfigOptionFloat raft_contact_distance; - ConfigOptionFloat raft_expansion; - ConfigOptionPercent raft_first_layer_density; - ConfigOptionFloat raft_first_layer_expansion; - ConfigOptionInt raft_layers; - ConfigOptionEnum seam_position; -// ConfigOptionFloat seam_preferred_direction; -// ConfigOptionFloat seam_preferred_direction_jitter; - ConfigOptionFloat slice_closing_radius; - ConfigOptionBool support_material; - // Automatic supports (generated based on support_material_threshold). - ConfigOptionBool support_material_auto; - // Direction of the support pattern (in XY plane). - ConfigOptionFloat support_material_angle; - ConfigOptionBool support_material_buildplate_only; - ConfigOptionFloat support_material_contact_distance; - ConfigOptionFloat support_material_bottom_contact_distance; - ConfigOptionInt support_material_enforce_layers; - ConfigOptionInt support_material_extruder; - ConfigOptionFloatOrPercent support_material_extrusion_width; - ConfigOptionBool support_material_interface_contact_loops; - ConfigOptionInt support_material_interface_extruder; - ConfigOptionInt support_material_interface_layers; - ConfigOptionInt support_material_bottom_interface_layers; - // Spacing between interface lines (the hatching distance). Set zero to get a solid interface. - ConfigOptionFloat support_material_interface_spacing; - ConfigOptionFloatOrPercent support_material_interface_speed; - ConfigOptionEnum support_material_pattern; - ConfigOptionEnum support_material_interface_pattern; - // Spacing between support material lines (the hatching distance). - ConfigOptionFloat support_material_spacing; - ConfigOptionFloat support_material_speed; - ConfigOptionEnum support_material_style; - ConfigOptionBool support_material_synchronize_layers; - // Overhang angle threshold. - ConfigOptionInt support_material_threshold; - ConfigOptionBool support_material_with_sheath; - ConfigOptionFloatOrPercent support_material_xy_spacing; - ConfigOptionBool thick_bridges; - ConfigOptionFloat xy_size_compensation; - ConfigOptionBool wipe_into_objects; +PRINT_CONFIG_CLASS_DEFINE( + PrintObjectConfig, -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(brim_offset); - OPT_PTR(brim_type); - OPT_PTR(brim_width); - OPT_PTR(clip_multipart_objects); - OPT_PTR(dont_support_bridges); - OPT_PTR(elefant_foot_compensation); - OPT_PTR(extrusion_width); - OPT_PTR(first_layer_height); - OPT_PTR(infill_only_where_needed); - OPT_PTR(interface_shells); - OPT_PTR(layer_height); - OPT_PTR(raft_contact_distance); - OPT_PTR(raft_expansion); - OPT_PTR(raft_first_layer_density); - OPT_PTR(raft_first_layer_expansion); - OPT_PTR(raft_layers); - OPT_PTR(seam_position); - OPT_PTR(slice_closing_radius); -// OPT_PTR(seam_preferred_direction); -// OPT_PTR(seam_preferred_direction_jitter); - OPT_PTR(support_material); - OPT_PTR(support_material_auto); - OPT_PTR(support_material_angle); - OPT_PTR(support_material_buildplate_only); - OPT_PTR(support_material_contact_distance); - OPT_PTR(support_material_bottom_contact_distance); - OPT_PTR(support_material_enforce_layers); - OPT_PTR(support_material_interface_contact_loops); - OPT_PTR(support_material_extruder); - OPT_PTR(support_material_extrusion_width); - OPT_PTR(support_material_interface_extruder); - OPT_PTR(support_material_interface_layers); - OPT_PTR(support_material_bottom_interface_layers); - OPT_PTR(support_material_interface_spacing); - OPT_PTR(support_material_interface_speed); - OPT_PTR(support_material_pattern); - OPT_PTR(support_material_interface_pattern); - OPT_PTR(support_material_spacing); - OPT_PTR(support_material_speed); - OPT_PTR(support_material_style); - OPT_PTR(support_material_synchronize_layers); - OPT_PTR(support_material_xy_spacing); - OPT_PTR(support_material_threshold); - OPT_PTR(support_material_with_sheath); - OPT_PTR(thick_bridges); - OPT_PTR(xy_size_compensation); - OPT_PTR(wipe_into_objects); - } -}; + ((ConfigOptionFloat, brim_offset)) + ((ConfigOptionEnum, brim_type)) + ((ConfigOptionFloat, brim_width)) + ((ConfigOptionBool, clip_multipart_objects)) + ((ConfigOptionBool, dont_support_bridges)) + ((ConfigOptionFloat, elefant_foot_compensation)) + ((ConfigOptionFloatOrPercent, extrusion_width)) + ((ConfigOptionBool, infill_only_where_needed)) + // Force the generation of solid shells between adjacent materials/volumes. + ((ConfigOptionBool, interface_shells)) + ((ConfigOptionFloat, layer_height)) + ((ConfigOptionFloat, raft_contact_distance)) + ((ConfigOptionFloat, raft_expansion)) + ((ConfigOptionPercent, raft_first_layer_density)) + ((ConfigOptionFloat, raft_first_layer_expansion)) + ((ConfigOptionInt, raft_layers)) + ((ConfigOptionEnum, seam_position)) +// ((ConfigOptionFloat, seam_preferred_direction)) +// ((ConfigOptionFloat, seam_preferred_direction_jitter)) + ((ConfigOptionFloat, slice_closing_radius)) + ((ConfigOptionBool, support_material)) + // Automatic supports (generated based on support_material_threshold). + ((ConfigOptionBool, support_material_auto)) + // Direction of the support pattern (in XY plane).` + ((ConfigOptionFloat, support_material_angle)) + ((ConfigOptionBool, support_material_buildplate_only)) + ((ConfigOptionFloat, support_material_contact_distance)) + ((ConfigOptionFloat, support_material_bottom_contact_distance)) + ((ConfigOptionInt, support_material_enforce_layers)) + ((ConfigOptionInt, support_material_extruder)) + ((ConfigOptionFloatOrPercent, support_material_extrusion_width)) + ((ConfigOptionBool, support_material_interface_contact_loops)) + ((ConfigOptionInt, support_material_interface_extruder)) + ((ConfigOptionInt, support_material_interface_layers)) + ((ConfigOptionInt, support_material_bottom_interface_layers)) + // Spacing between interface lines (the hatching distance). Set zero to get a solid interface. + ((ConfigOptionFloat, support_material_interface_spacing)) + ((ConfigOptionFloatOrPercent, support_material_interface_speed)) + ((ConfigOptionEnum, support_material_pattern)) + ((ConfigOptionEnum, support_material_interface_pattern)) + // Morphological closing of support areas. Only used for "sung" supports. + ((ConfigOptionFloat, support_material_closing_radius)) + // Spacing between support material lines (the hatching distance). + ((ConfigOptionFloat, support_material_spacing)) + ((ConfigOptionFloat, support_material_speed)) + ((ConfigOptionEnum, support_material_style)) + ((ConfigOptionBool, support_material_synchronize_layers)) + // Overhang angle threshold. + ((ConfigOptionInt, support_material_threshold)) + ((ConfigOptionBool, support_material_with_sheath)) + ((ConfigOptionFloatOrPercent, support_material_xy_spacing)) + ((ConfigOptionBool, thick_bridges)) + ((ConfigOptionFloat, xy_size_compensation)) + ((ConfigOptionBool, wipe_into_objects)) +) // This object is mapped to Perl as Slic3r::Config::PrintRegion. -class PrintRegionConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(PrintRegionConfig) -public: - ConfigOptionFloat bridge_angle; - ConfigOptionInt bottom_solid_layers; - ConfigOptionFloat bottom_solid_min_thickness; - ConfigOptionFloat bridge_flow_ratio; - ConfigOptionFloat bridge_speed; - ConfigOptionBool ensure_vertical_shell_thickness; - ConfigOptionEnum top_fill_pattern; - ConfigOptionEnum bottom_fill_pattern; - ConfigOptionFloatOrPercent external_perimeter_extrusion_width; - ConfigOptionFloatOrPercent external_perimeter_speed; - ConfigOptionBool external_perimeters_first; - ConfigOptionBool extra_perimeters; - ConfigOptionFloat fill_angle; - ConfigOptionPercent fill_density; - ConfigOptionEnum fill_pattern; - ConfigOptionEnum fuzzy_skin; - ConfigOptionFloat fuzzy_skin_thickness; - ConfigOptionFloat fuzzy_skin_point_dist; - ConfigOptionBool gap_fill_enabled; - ConfigOptionFloat gap_fill_speed; - ConfigOptionFloatOrPercent infill_anchor; - ConfigOptionFloatOrPercent infill_anchor_max; - ConfigOptionInt infill_extruder; - ConfigOptionFloatOrPercent infill_extrusion_width; - ConfigOptionInt infill_every_layers; - ConfigOptionFloatOrPercent infill_overlap; - ConfigOptionFloat infill_speed; +PRINT_CONFIG_CLASS_DEFINE( + PrintRegionConfig, + + ((ConfigOptionFloat, bridge_angle)) + ((ConfigOptionInt, bottom_solid_layers)) + ((ConfigOptionFloat, bottom_solid_min_thickness)) + ((ConfigOptionFloat, bridge_flow_ratio)) + ((ConfigOptionFloat, bridge_speed)) + ((ConfigOptionBool, ensure_vertical_shell_thickness)) + ((ConfigOptionEnum, top_fill_pattern)) + ((ConfigOptionEnum, bottom_fill_pattern)) + ((ConfigOptionFloatOrPercent, external_perimeter_extrusion_width)) + ((ConfigOptionFloatOrPercent, external_perimeter_speed)) + ((ConfigOptionBool, external_perimeters_first)) + ((ConfigOptionBool, extra_perimeters)) + ((ConfigOptionFloat, fill_angle)) + ((ConfigOptionPercent, fill_density)) + ((ConfigOptionEnum, fill_pattern)) + ((ConfigOptionEnum, fuzzy_skin)) + ((ConfigOptionFloat, fuzzy_skin_thickness)) + ((ConfigOptionFloat, fuzzy_skin_point_dist)) + ((ConfigOptionBool, gap_fill_enabled)) + ((ConfigOptionFloat, gap_fill_speed)) + ((ConfigOptionFloatOrPercent, infill_anchor)) + ((ConfigOptionFloatOrPercent, infill_anchor_max)) + ((ConfigOptionInt, infill_extruder)) + ((ConfigOptionFloatOrPercent, infill_extrusion_width)) + ((ConfigOptionInt, infill_every_layers)) + ((ConfigOptionFloatOrPercent, infill_overlap)) + ((ConfigOptionFloat, infill_speed)) // Ironing options - ConfigOptionBool ironing; - ConfigOptionEnum ironing_type; - ConfigOptionPercent ironing_flowrate; - ConfigOptionFloat ironing_spacing; - ConfigOptionFloat ironing_speed; + ((ConfigOptionBool, ironing)) + ((ConfigOptionEnum, ironing_type)) + ((ConfigOptionPercent, ironing_flowrate)) + ((ConfigOptionFloat, ironing_spacing)) + ((ConfigOptionFloat, ironing_speed)) // Detect bridging perimeters - ConfigOptionBool overhangs; - ConfigOptionInt perimeter_extruder; - ConfigOptionFloatOrPercent perimeter_extrusion_width; - ConfigOptionFloat perimeter_speed; + ((ConfigOptionBool, overhangs)) + ((ConfigOptionInt, perimeter_extruder)) + ((ConfigOptionFloatOrPercent, perimeter_extrusion_width)) + ((ConfigOptionFloat, perimeter_speed)) // Total number of perimeters. - ConfigOptionInt perimeters; - ConfigOptionFloatOrPercent small_perimeter_speed; - ConfigOptionFloat solid_infill_below_area; - ConfigOptionInt solid_infill_extruder; - ConfigOptionFloatOrPercent solid_infill_extrusion_width; - ConfigOptionInt solid_infill_every_layers; - ConfigOptionFloatOrPercent solid_infill_speed; + ((ConfigOptionInt, perimeters)) + ((ConfigOptionFloatOrPercent, small_perimeter_speed)) + ((ConfigOptionFloat, solid_infill_below_area)) + ((ConfigOptionInt, solid_infill_extruder)) + ((ConfigOptionFloatOrPercent, solid_infill_extrusion_width)) + ((ConfigOptionInt, solid_infill_every_layers)) + ((ConfigOptionFloatOrPercent, solid_infill_speed)) // Detect thin walls. - ConfigOptionBool thin_walls; - ConfigOptionFloatOrPercent top_infill_extrusion_width; - ConfigOptionInt top_solid_layers; - ConfigOptionFloat top_solid_min_thickness; - ConfigOptionFloatOrPercent top_solid_infill_speed; - ConfigOptionBool wipe_into_infill; + ((ConfigOptionBool, thin_walls)) + ((ConfigOptionFloatOrPercent, top_infill_extrusion_width)) + ((ConfigOptionInt, top_solid_layers)) + ((ConfigOptionFloat, top_solid_min_thickness)) + ((ConfigOptionFloatOrPercent, top_solid_infill_speed)) + ((ConfigOptionBool, wipe_into_infill)) +) -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(bridge_angle); - OPT_PTR(bottom_solid_layers); - OPT_PTR(bottom_solid_min_thickness); - OPT_PTR(bridge_flow_ratio); - OPT_PTR(bridge_speed); - OPT_PTR(ensure_vertical_shell_thickness); - OPT_PTR(top_fill_pattern); - OPT_PTR(bottom_fill_pattern); - OPT_PTR(external_perimeter_extrusion_width); - OPT_PTR(external_perimeter_speed); - OPT_PTR(external_perimeters_first); - OPT_PTR(extra_perimeters); - OPT_PTR(fill_angle); - OPT_PTR(fill_density); - OPT_PTR(fill_pattern); - OPT_PTR(fuzzy_skin); - OPT_PTR(fuzzy_skin_thickness); - OPT_PTR(fuzzy_skin_point_dist); - OPT_PTR(gap_fill_enabled); - OPT_PTR(gap_fill_speed); - OPT_PTR(infill_anchor); - OPT_PTR(infill_anchor_max); - OPT_PTR(infill_extruder); - OPT_PTR(infill_extrusion_width); - OPT_PTR(infill_every_layers); - OPT_PTR(infill_overlap); - OPT_PTR(infill_speed); - OPT_PTR(ironing); - OPT_PTR(ironing_type); - OPT_PTR(ironing_flowrate); - OPT_PTR(ironing_spacing); - OPT_PTR(ironing_speed); - OPT_PTR(overhangs); - OPT_PTR(perimeter_extruder); - OPT_PTR(perimeter_extrusion_width); - OPT_PTR(perimeter_speed); - OPT_PTR(perimeters); - OPT_PTR(small_perimeter_speed); - OPT_PTR(solid_infill_below_area); - OPT_PTR(solid_infill_extruder); - OPT_PTR(solid_infill_extrusion_width); - OPT_PTR(solid_infill_every_layers); - OPT_PTR(solid_infill_speed); - OPT_PTR(thin_walls); - OPT_PTR(top_infill_extrusion_width); - OPT_PTR(top_solid_infill_speed); - OPT_PTR(top_solid_layers); - OPT_PTR(top_solid_min_thickness); - OPT_PTR(wipe_into_infill); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + MachineEnvelopeConfig, -class MachineEnvelopeConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(MachineEnvelopeConfig) -public: - // Allowing the machine limits to be completely ignored or used just for time estimator. - ConfigOptionEnum machine_limits_usage; + // Allowing the machine limits to be completely ignored or used just for time estimator. + ((ConfigOptionEnum, machine_limits_usage)) // M201 X... Y... Z... E... [mm/sec^2] - ConfigOptionFloats machine_max_acceleration_x; - ConfigOptionFloats machine_max_acceleration_y; - ConfigOptionFloats machine_max_acceleration_z; - ConfigOptionFloats machine_max_acceleration_e; + ((ConfigOptionFloats, machine_max_acceleration_x)) + ((ConfigOptionFloats, machine_max_acceleration_y)) + ((ConfigOptionFloats, machine_max_acceleration_z)) + ((ConfigOptionFloats, machine_max_acceleration_e)) // M203 X... Y... Z... E... [mm/sec] - ConfigOptionFloats machine_max_feedrate_x; - ConfigOptionFloats machine_max_feedrate_y; - ConfigOptionFloats machine_max_feedrate_z; - ConfigOptionFloats machine_max_feedrate_e; - // M204 S... [mm/sec^2] - ConfigOptionFloats machine_max_acceleration_extruding; - // M204 T... [mm/sec^2] - ConfigOptionFloats machine_max_acceleration_retracting; - // M205 X... Y... Z... E... [mm/sec] - ConfigOptionFloats machine_max_jerk_x; - ConfigOptionFloats machine_max_jerk_y; - ConfigOptionFloats machine_max_jerk_z; - ConfigOptionFloats machine_max_jerk_e; - // M205 T... [mm/sec] - ConfigOptionFloats machine_min_travel_rate; - // M205 S... [mm/sec] - ConfigOptionFloats machine_min_extruding_rate; + ((ConfigOptionFloats, machine_max_feedrate_x)) + ((ConfigOptionFloats, machine_max_feedrate_y)) + ((ConfigOptionFloats, machine_max_feedrate_z)) + ((ConfigOptionFloats, machine_max_feedrate_e)) -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(machine_limits_usage); - OPT_PTR(machine_max_acceleration_x); - OPT_PTR(machine_max_acceleration_y); - OPT_PTR(machine_max_acceleration_z); - OPT_PTR(machine_max_acceleration_e); - OPT_PTR(machine_max_feedrate_x); - OPT_PTR(machine_max_feedrate_y); - OPT_PTR(machine_max_feedrate_z); - OPT_PTR(machine_max_feedrate_e); - OPT_PTR(machine_max_acceleration_extruding); - OPT_PTR(machine_max_acceleration_retracting); - OPT_PTR(machine_max_jerk_x); - OPT_PTR(machine_max_jerk_y); - OPT_PTR(machine_max_jerk_z); - OPT_PTR(machine_max_jerk_e); - OPT_PTR(machine_min_travel_rate); - OPT_PTR(machine_min_extruding_rate); - } -}; + // M204 P... R... T...[mm/sec^2] + ((ConfigOptionFloats, machine_max_acceleration_extruding)) + ((ConfigOptionFloats, machine_max_acceleration_retracting)) + ((ConfigOptionFloats, machine_max_acceleration_travel)) + + // M205 X... Y... Z... E... [mm/sec] + ((ConfigOptionFloats, machine_max_jerk_x)) + ((ConfigOptionFloats, machine_max_jerk_y)) + ((ConfigOptionFloats, machine_max_jerk_z)) + ((ConfigOptionFloats, machine_max_jerk_e)) + // M205 T... [mm/sec] + ((ConfigOptionFloats, machine_min_travel_rate)) + // M205 S... [mm/sec] + ((ConfigOptionFloats, machine_min_extruding_rate)) +) // This object is mapped to Perl as Slic3r::Config::GCode. -class GCodeConfig : public StaticPrintConfig +PRINT_CONFIG_CLASS_DEFINE( + GCodeConfig, + + ((ConfigOptionString, before_layer_gcode)) + ((ConfigOptionString, between_objects_gcode)) + ((ConfigOptionFloats, deretract_speed)) + ((ConfigOptionString, end_gcode)) + ((ConfigOptionStrings, end_filament_gcode)) + ((ConfigOptionString, extrusion_axis)) + ((ConfigOptionFloats, extrusion_multiplier)) + ((ConfigOptionFloats, filament_diameter)) + ((ConfigOptionFloats, filament_density)) + ((ConfigOptionStrings, filament_type)) + ((ConfigOptionBools, filament_soluble)) + ((ConfigOptionFloats, filament_cost)) + ((ConfigOptionFloats, filament_spool_weight)) + ((ConfigOptionFloats, filament_max_volumetric_speed)) + ((ConfigOptionFloats, filament_loading_speed)) + ((ConfigOptionFloats, filament_loading_speed_start)) + ((ConfigOptionFloats, filament_load_time)) + ((ConfigOptionFloats, filament_unloading_speed)) + ((ConfigOptionFloats, filament_unloading_speed_start)) + ((ConfigOptionFloats, filament_toolchange_delay)) + ((ConfigOptionFloats, filament_unload_time)) + ((ConfigOptionInts, filament_cooling_moves)) + ((ConfigOptionFloats, filament_cooling_initial_speed)) + ((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower)) + ((ConfigOptionFloats, filament_cooling_final_speed)) + ((ConfigOptionStrings, filament_ramming_parameters)) + ((ConfigOptionBool, gcode_comments)) + ((ConfigOptionEnum, gcode_flavor)) + ((ConfigOptionBool, gcode_label_objects)) + ((ConfigOptionString, layer_gcode)) + ((ConfigOptionFloat, max_print_speed)) + ((ConfigOptionFloat, max_volumetric_speed)) +//#ifdef HAS_PRESSURE_EQUALIZER +// ((ConfigOptionFloat, max_volumetric_extrusion_rate_slope_positive)) +// ((ConfigOptionFloat, max_volumetric_extrusion_rate_slope_negative)) +//#endif + ((ConfigOptionPercents, retract_before_wipe)) + ((ConfigOptionFloats, retract_length)) + ((ConfigOptionFloats, retract_length_toolchange)) + ((ConfigOptionFloats, retract_lift)) + ((ConfigOptionFloats, retract_lift_above)) + ((ConfigOptionFloats, retract_lift_below)) + ((ConfigOptionFloats, retract_restart_extra)) + ((ConfigOptionFloats, retract_restart_extra_toolchange)) + ((ConfigOptionFloats, retract_speed)) + ((ConfigOptionString, start_gcode)) + ((ConfigOptionStrings, start_filament_gcode)) + ((ConfigOptionBool, single_extruder_multi_material)) + ((ConfigOptionBool, single_extruder_multi_material_priming)) + ((ConfigOptionBool, wipe_tower_no_sparse_layers)) + ((ConfigOptionString, toolchange_gcode)) + ((ConfigOptionFloat, travel_speed)) + ((ConfigOptionBool, use_firmware_retraction)) + ((ConfigOptionBool, use_relative_e_distances)) + ((ConfigOptionBool, use_volumetric_e)) + ((ConfigOptionBool, variable_layer_height)) + ((ConfigOptionFloat, cooling_tube_retraction)) + ((ConfigOptionFloat, cooling_tube_length)) + ((ConfigOptionBool, high_current_on_filament_swap)) + ((ConfigOptionFloat, parking_pos_retraction)) + ((ConfigOptionBool, remaining_times)) + ((ConfigOptionBool, silent_mode)) + ((ConfigOptionFloat, extra_loading_move)) + ((ConfigOptionString, color_change_gcode)) + ((ConfigOptionString, pause_print_gcode)) + ((ConfigOptionString, template_custom_gcode)) +) + +static inline std::string get_extrusion_axis(const GCodeConfig &cfg) { - STATIC_PRINT_CONFIG_CACHE(GCodeConfig) -public: - ConfigOptionString before_layer_gcode; - ConfigOptionString between_objects_gcode; - ConfigOptionFloats deretract_speed; - ConfigOptionString end_gcode; - ConfigOptionStrings end_filament_gcode; - ConfigOptionString extrusion_axis; - ConfigOptionFloats extrusion_multiplier; - ConfigOptionFloats filament_diameter; - ConfigOptionFloats filament_density; - ConfigOptionStrings filament_type; - ConfigOptionBools filament_soluble; - ConfigOptionFloats filament_cost; - ConfigOptionFloats filament_spool_weight; - ConfigOptionFloats filament_max_volumetric_speed; - ConfigOptionFloats filament_loading_speed; - ConfigOptionFloats filament_loading_speed_start; - ConfigOptionFloats filament_load_time; - ConfigOptionFloats filament_unloading_speed; - ConfigOptionFloats filament_unloading_speed_start; - ConfigOptionFloats filament_toolchange_delay; - ConfigOptionFloats filament_unload_time; - ConfigOptionInts filament_cooling_moves; - ConfigOptionFloats filament_cooling_initial_speed; - ConfigOptionFloats filament_minimal_purge_on_wipe_tower; - ConfigOptionFloats filament_cooling_final_speed; - ConfigOptionStrings filament_ramming_parameters; - ConfigOptionBool gcode_comments; - ConfigOptionEnum gcode_flavor; - ConfigOptionBool gcode_label_objects; - ConfigOptionString layer_gcode; - ConfigOptionFloat max_print_speed; - ConfigOptionFloat max_volumetric_speed; -#ifdef HAS_PRESSURE_EQUALIZER - ConfigOptionFloat max_volumetric_extrusion_rate_slope_positive; - ConfigOptionFloat max_volumetric_extrusion_rate_slope_negative; -#endif - ConfigOptionPercents retract_before_wipe; - ConfigOptionFloats retract_length; - ConfigOptionFloats retract_length_toolchange; - ConfigOptionFloats retract_lift; - ConfigOptionFloats retract_lift_above; - ConfigOptionFloats retract_lift_below; - ConfigOptionFloats retract_restart_extra; - ConfigOptionFloats retract_restart_extra_toolchange; - ConfigOptionFloats retract_speed; - ConfigOptionString start_gcode; - ConfigOptionStrings start_filament_gcode; - ConfigOptionBool single_extruder_multi_material; - ConfigOptionBool single_extruder_multi_material_priming; - ConfigOptionBool wipe_tower_no_sparse_layers; - ConfigOptionString toolchange_gcode; - ConfigOptionFloat travel_speed; - ConfigOptionBool use_firmware_retraction; - ConfigOptionBool use_relative_e_distances; - ConfigOptionBool use_volumetric_e; - ConfigOptionBool variable_layer_height; - ConfigOptionFloat cooling_tube_retraction; - ConfigOptionFloat cooling_tube_length; - ConfigOptionBool high_current_on_filament_swap; - ConfigOptionFloat parking_pos_retraction; - ConfigOptionBool remaining_times; - ConfigOptionBool silent_mode; - ConfigOptionFloat extra_loading_move; - ConfigOptionString color_change_gcode; - ConfigOptionString pause_print_gcode; - ConfigOptionString template_custom_gcode; - - std::string get_extrusion_axis() const - { - return - ((this->gcode_flavor.value == gcfMach3) || (this->gcode_flavor.value == gcfMachinekit)) ? "A" : - (this->gcode_flavor.value == gcfNoExtrusion) ? "" : this->extrusion_axis.value; - } - -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(before_layer_gcode); - OPT_PTR(between_objects_gcode); - OPT_PTR(deretract_speed); - OPT_PTR(end_gcode); - OPT_PTR(end_filament_gcode); - OPT_PTR(extrusion_axis); - OPT_PTR(extrusion_multiplier); - OPT_PTR(filament_diameter); - OPT_PTR(filament_density); - OPT_PTR(filament_type); - OPT_PTR(filament_soluble); - OPT_PTR(filament_cost); - OPT_PTR(filament_spool_weight); - OPT_PTR(filament_max_volumetric_speed); - OPT_PTR(filament_loading_speed); - OPT_PTR(filament_loading_speed_start); - OPT_PTR(filament_load_time); - OPT_PTR(filament_unloading_speed); - OPT_PTR(filament_unloading_speed_start); - OPT_PTR(filament_unload_time); - OPT_PTR(filament_toolchange_delay); - OPT_PTR(filament_cooling_moves); - OPT_PTR(filament_cooling_initial_speed); - OPT_PTR(filament_minimal_purge_on_wipe_tower); - OPT_PTR(filament_cooling_final_speed); - OPT_PTR(filament_ramming_parameters); - OPT_PTR(gcode_comments); - OPT_PTR(gcode_flavor); - OPT_PTR(gcode_label_objects); - OPT_PTR(layer_gcode); - OPT_PTR(max_print_speed); - OPT_PTR(max_volumetric_speed); -#ifdef HAS_PRESSURE_EQUALIZER - OPT_PTR(max_volumetric_extrusion_rate_slope_positive); - OPT_PTR(max_volumetric_extrusion_rate_slope_negative); -#endif /* HAS_PRESSURE_EQUALIZER */ - OPT_PTR(retract_before_wipe); - OPT_PTR(retract_length); - OPT_PTR(retract_length_toolchange); - OPT_PTR(retract_lift); - OPT_PTR(retract_lift_above); - OPT_PTR(retract_lift_below); - OPT_PTR(retract_restart_extra); - OPT_PTR(retract_restart_extra_toolchange); - OPT_PTR(retract_speed); - OPT_PTR(single_extruder_multi_material); - OPT_PTR(single_extruder_multi_material_priming); - OPT_PTR(wipe_tower_no_sparse_layers); - OPT_PTR(start_gcode); - OPT_PTR(start_filament_gcode); - OPT_PTR(toolchange_gcode); - OPT_PTR(travel_speed); - OPT_PTR(use_firmware_retraction); - OPT_PTR(use_relative_e_distances); - OPT_PTR(use_volumetric_e); - OPT_PTR(variable_layer_height); - OPT_PTR(cooling_tube_retraction); - OPT_PTR(cooling_tube_length); - OPT_PTR(high_current_on_filament_swap); - OPT_PTR(parking_pos_retraction); - OPT_PTR(remaining_times); - OPT_PTR(silent_mode); - OPT_PTR(extra_loading_move); - OPT_PTR(color_change_gcode); - OPT_PTR(pause_print_gcode); - OPT_PTR(template_custom_gcode); - } -}; + return + ((cfg.gcode_flavor.value == gcfMach3) || (cfg.gcode_flavor.value == gcfMachinekit)) ? "A" : + (cfg.gcode_flavor.value == gcfNoExtrusion) ? "" : cfg.extrusion_axis.value; +} // This object is mapped to Perl as Slic3r::Config::Print. -class PrintConfig : public MachineEnvelopeConfig, public GCodeConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig) - PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); } -public: +PRINT_CONFIG_CLASS_DERIVED_DEFINE( + PrintConfig, + (MachineEnvelopeConfig, GCodeConfig), - ConfigOptionBool avoid_crossing_perimeters; - ConfigOptionFloatOrPercent avoid_crossing_perimeters_max_detour; - ConfigOptionPoints bed_shape; - ConfigOptionInts bed_temperature; - ConfigOptionFloat bridge_acceleration; - ConfigOptionInts bridge_fan_speed; - ConfigOptionBool complete_objects; - ConfigOptionFloats colorprint_heights; - ConfigOptionBools cooling; - ConfigOptionFloat default_acceleration; - ConfigOptionInts disable_fan_first_layers; - ConfigOptionFloat duplicate_distance; - ConfigOptionFloat extruder_clearance_height; - ConfigOptionFloat extruder_clearance_radius; - ConfigOptionStrings extruder_colour; - ConfigOptionPoints extruder_offset; - ConfigOptionBools fan_always_on; - ConfigOptionInts fan_below_layer_time; - ConfigOptionStrings filament_colour; - ConfigOptionStrings filament_notes; - ConfigOptionFloat first_layer_acceleration; - ConfigOptionInts first_layer_bed_temperature; - ConfigOptionFloatOrPercent first_layer_extrusion_width; - ConfigOptionFloatOrPercent first_layer_speed; - ConfigOptionInts first_layer_temperature; - ConfigOptionInts full_fan_speed_layer; - ConfigOptionFloat infill_acceleration; - ConfigOptionBool infill_first; - ConfigOptionInts max_fan_speed; - ConfigOptionFloats max_layer_height; - ConfigOptionInts min_fan_speed; - ConfigOptionFloats min_layer_height; - ConfigOptionFloat max_print_height; - ConfigOptionFloats min_print_speed; - ConfigOptionFloat min_skirt_length; - ConfigOptionString notes; - ConfigOptionFloats nozzle_diameter; - ConfigOptionBool only_retract_when_crossing_perimeters; - ConfigOptionBool ooze_prevention; - ConfigOptionString output_filename_format; - ConfigOptionFloat perimeter_acceleration; - ConfigOptionStrings post_process; - ConfigOptionString printer_model; - ConfigOptionString printer_notes; - ConfigOptionFloat resolution; - ConfigOptionFloats retract_before_travel; - ConfigOptionBools retract_layer_change; - ConfigOptionFloat skirt_distance; - ConfigOptionInt skirt_height; - ConfigOptionBool draft_shield; - ConfigOptionInt skirts; - ConfigOptionInts slowdown_below_layer_time; - ConfigOptionBool spiral_vase; - ConfigOptionInt standby_temperature_delta; - ConfigOptionInts temperature; - ConfigOptionInt threads; - ConfigOptionBools wipe; - ConfigOptionBool wipe_tower; - ConfigOptionFloat wipe_tower_x; - ConfigOptionFloat wipe_tower_y; - ConfigOptionFloat wipe_tower_width; - ConfigOptionFloat wipe_tower_per_color_wipe; - ConfigOptionFloat wipe_tower_rotation_angle; - ConfigOptionFloat wipe_tower_brim_width; - ConfigOptionFloat wipe_tower_bridging; - ConfigOptionFloats wiping_volumes_matrix; - ConfigOptionFloats wiping_volumes_extruders; - ConfigOptionFloat z_offset; - -protected: - PrintConfig(int) : MachineEnvelopeConfig(1), GCodeConfig(1) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->MachineEnvelopeConfig::initialize(cache, base_ptr); - this->GCodeConfig::initialize(cache, base_ptr); - OPT_PTR(avoid_crossing_perimeters); - OPT_PTR(avoid_crossing_perimeters_max_detour); - OPT_PTR(bed_shape); - OPT_PTR(bed_temperature); - OPT_PTR(bridge_acceleration); - OPT_PTR(bridge_fan_speed); - OPT_PTR(complete_objects); - OPT_PTR(colorprint_heights); - OPT_PTR(cooling); - OPT_PTR(default_acceleration); - OPT_PTR(disable_fan_first_layers); - OPT_PTR(duplicate_distance); - OPT_PTR(extruder_clearance_height); - OPT_PTR(extruder_clearance_radius); - OPT_PTR(extruder_colour); - OPT_PTR(extruder_offset); - OPT_PTR(fan_always_on); - OPT_PTR(fan_below_layer_time); - OPT_PTR(filament_colour); - OPT_PTR(filament_notes); - OPT_PTR(first_layer_acceleration); - OPT_PTR(first_layer_bed_temperature); - OPT_PTR(first_layer_extrusion_width); - OPT_PTR(first_layer_speed); - OPT_PTR(first_layer_temperature); - OPT_PTR(full_fan_speed_layer); - OPT_PTR(infill_acceleration); - OPT_PTR(infill_first); - OPT_PTR(max_fan_speed); - OPT_PTR(max_layer_height); - OPT_PTR(min_fan_speed); - OPT_PTR(min_layer_height); - OPT_PTR(max_print_height); - OPT_PTR(min_print_speed); - OPT_PTR(min_skirt_length); - OPT_PTR(notes); - OPT_PTR(nozzle_diameter); - OPT_PTR(only_retract_when_crossing_perimeters); - OPT_PTR(ooze_prevention); - OPT_PTR(output_filename_format); - OPT_PTR(perimeter_acceleration); - OPT_PTR(post_process); - OPT_PTR(printer_model); - OPT_PTR(printer_notes); - OPT_PTR(resolution); - OPT_PTR(retract_before_travel); - OPT_PTR(retract_layer_change); - OPT_PTR(skirt_distance); - OPT_PTR(skirt_height); - OPT_PTR(draft_shield); - OPT_PTR(skirts); - OPT_PTR(slowdown_below_layer_time); - OPT_PTR(spiral_vase); - OPT_PTR(standby_temperature_delta); - OPT_PTR(temperature); - OPT_PTR(threads); - OPT_PTR(wipe); - OPT_PTR(wipe_tower); - OPT_PTR(wipe_tower_x); - OPT_PTR(wipe_tower_y); - OPT_PTR(wipe_tower_width); - OPT_PTR(wipe_tower_per_color_wipe); - OPT_PTR(wipe_tower_rotation_angle); - OPT_PTR(wipe_tower_brim_width); - OPT_PTR(wipe_tower_bridging); - OPT_PTR(wiping_volumes_matrix); - OPT_PTR(wiping_volumes_extruders); - OPT_PTR(z_offset); - } -}; + ((ConfigOptionBool, avoid_crossing_perimeters)) + ((ConfigOptionFloatOrPercent, avoid_crossing_perimeters_max_detour)) + ((ConfigOptionPoints, bed_shape)) + ((ConfigOptionInts, bed_temperature)) + ((ConfigOptionFloat, bridge_acceleration)) + ((ConfigOptionInts, bridge_fan_speed)) + ((ConfigOptionBool, complete_objects)) + ((ConfigOptionFloats, colorprint_heights)) + ((ConfigOptionBools, cooling)) + ((ConfigOptionFloat, default_acceleration)) + ((ConfigOptionInts, disable_fan_first_layers)) + ((ConfigOptionFloat, duplicate_distance)) + ((ConfigOptionFloat, extruder_clearance_height)) + ((ConfigOptionFloat, extruder_clearance_radius)) + ((ConfigOptionStrings, extruder_colour)) + ((ConfigOptionPoints, extruder_offset)) + ((ConfigOptionBools, fan_always_on)) + ((ConfigOptionInts, fan_below_layer_time)) + ((ConfigOptionStrings, filament_colour)) + ((ConfigOptionStrings, filament_notes)) + ((ConfigOptionFloat, first_layer_acceleration)) + ((ConfigOptionInts, first_layer_bed_temperature)) + ((ConfigOptionFloatOrPercent, first_layer_extrusion_width)) + ((ConfigOptionFloatOrPercent, first_layer_height)) + ((ConfigOptionFloatOrPercent, first_layer_speed)) + ((ConfigOptionInts, first_layer_temperature)) + ((ConfigOptionInts, full_fan_speed_layer)) + ((ConfigOptionFloat, infill_acceleration)) + ((ConfigOptionBool, infill_first)) + ((ConfigOptionInts, max_fan_speed)) + ((ConfigOptionFloats, max_layer_height)) + ((ConfigOptionInts, min_fan_speed)) + ((ConfigOptionFloats, min_layer_height)) + ((ConfigOptionFloat, max_print_height)) + ((ConfigOptionFloats, min_print_speed)) + ((ConfigOptionFloat, min_skirt_length)) + ((ConfigOptionString, notes)) + ((ConfigOptionFloats, nozzle_diameter)) + ((ConfigOptionBool, only_retract_when_crossing_perimeters)) + ((ConfigOptionBool, ooze_prevention)) + ((ConfigOptionString, output_filename_format)) + ((ConfigOptionFloat, perimeter_acceleration)) + ((ConfigOptionStrings, post_process)) + ((ConfigOptionString, printer_model)) + ((ConfigOptionString, printer_notes)) + ((ConfigOptionFloat, resolution)) + ((ConfigOptionFloats, retract_before_travel)) + ((ConfigOptionBools, retract_layer_change)) + ((ConfigOptionFloat, skirt_distance)) + ((ConfigOptionInt, skirt_height)) + ((ConfigOptionBool, draft_shield)) + ((ConfigOptionInt, skirts)) + ((ConfigOptionInts, slowdown_below_layer_time)) + ((ConfigOptionBool, spiral_vase)) + ((ConfigOptionInt, standby_temperature_delta)) + ((ConfigOptionInts, temperature)) + ((ConfigOptionInt, threads)) + ((ConfigOptionBools, wipe)) + ((ConfigOptionBool, wipe_tower)) + ((ConfigOptionFloat, wipe_tower_x)) + ((ConfigOptionFloat, wipe_tower_y)) + ((ConfigOptionFloat, wipe_tower_width)) + ((ConfigOptionFloat, wipe_tower_per_color_wipe)) + ((ConfigOptionFloat, wipe_tower_rotation_angle)) + ((ConfigOptionFloat, wipe_tower_brim_width)) + ((ConfigOptionFloat, wipe_tower_bridging)) + ((ConfigOptionFloats, wiping_volumes_matrix)) + ((ConfigOptionFloats, wiping_volumes_extruders)) + ((ConfigOptionFloat, z_offset)) +) // This object is mapped to Perl as Slic3r::Config::Full. -class FullPrintConfig : - public PrintObjectConfig, - public PrintRegionConfig, - public PrintConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(FullPrintConfig) - FullPrintConfig() : PrintObjectConfig(0), PrintRegionConfig(0), PrintConfig(0) { initialize_cache(); *this = s_cache_FullPrintConfig.defaults(); } +PRINT_CONFIG_CLASS_DERIVED_DEFINE0( + FullPrintConfig, + (PrintObjectConfig, PrintRegionConfig, PrintConfig) +) -public: - // Validate the FullPrintConfig. Returns an empty string on success, otherwise an error message is returned. - std::string validate(); +// Validate the FullPrintConfig. Returns an empty string on success, otherwise an error message is returned. +std::string validate(const FullPrintConfig &config); -protected: - // Protected constructor to be called to initialize ConfigCache::m_default. - FullPrintConfig(int) : PrintObjectConfig(0), PrintRegionConfig(0), PrintConfig(0) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->PrintObjectConfig::initialize(cache, base_ptr); - this->PrintRegionConfig::initialize(cache, base_ptr); - this->PrintConfig ::initialize(cache, base_ptr); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrintConfig, + ((ConfigOptionString, output_filename_format)) +) -// This object is mapped to Perl as Slic3r::Config::PrintRegion. -class SLAPrintConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrintConfig) -public: - ConfigOptionString output_filename_format; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrintObjectConfig, -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(output_filename_format); - } -}; - -class SLAPrintObjectConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrintObjectConfig) -public: - ConfigOptionFloat layer_height; + ((ConfigOptionFloat, layer_height)) //Number of the layers needed for the exposure time fade [3;20] - ConfigOptionInt faded_layers /*= 10*/; + ((ConfigOptionInt, faded_layers))/*= 10*/ - ConfigOptionFloat slice_closing_radius; + ((ConfigOptionFloat, slice_closing_radius)) // Enabling or disabling support creation - ConfigOptionBool supports_enable; + ((ConfigOptionBool, supports_enable)) // Diameter in mm of the pointing side of the head. - ConfigOptionFloat support_head_front_diameter /*= 0.2*/; + ((ConfigOptionFloat, support_head_front_diameter))/*= 0.2*/ // How much the pinhead has to penetrate the model surface - ConfigOptionFloat support_head_penetration /*= 0.2*/; + ((ConfigOptionFloat, support_head_penetration))/*= 0.2*/ // Width in mm from the back sphere center to the front sphere center. - ConfigOptionFloat support_head_width /*= 1.0*/; + ((ConfigOptionFloat, support_head_width))/*= 1.0*/ // Radius in mm of the support pillars. - ConfigOptionFloat support_pillar_diameter /*= 0.8*/; + ((ConfigOptionFloat, support_pillar_diameter))/*= 0.8*/ // The percentage of smaller pillars compared to the normal pillar diameter // which are used in problematic areas where a normal pilla cannot fit. - ConfigOptionPercent support_small_pillar_diameter_percent; + ((ConfigOptionPercent, support_small_pillar_diameter_percent)) // How much bridge (supporting another pinhead) can be placed on a pillar. - ConfigOptionInt support_max_bridges_on_pillar; + ((ConfigOptionInt, support_max_bridges_on_pillar)) // How the pillars are bridged together - ConfigOptionEnum support_pillar_connection_mode; + ((ConfigOptionEnum, support_pillar_connection_mode)) // Generate only ground facing supports - ConfigOptionBool support_buildplate_only; + ((ConfigOptionBool, support_buildplate_only)) // TODO: unimplemented at the moment. This coefficient will have an impact // when bridges and pillars are merged. The resulting pillar should be a bit // thicker than the ones merging into it. How much thicker? I don't know // but it will be derived from this value. - ConfigOptionFloat support_pillar_widening_factor; + ((ConfigOptionFloat, support_pillar_widening_factor)) // Radius in mm of the pillar base. - ConfigOptionFloat support_base_diameter /*= 2.0*/; + ((ConfigOptionFloat, support_base_diameter))/*= 2.0*/ // The height of the pillar base cone in mm. - ConfigOptionFloat support_base_height /*= 1.0*/; + ((ConfigOptionFloat, support_base_height))/*= 1.0*/ // The minimum distance of the pillar base from the model in mm. - ConfigOptionFloat support_base_safety_distance; /*= 1.0*/ + ((ConfigOptionFloat, support_base_safety_distance)) /*= 1.0*/ // The default angle for connecting support sticks and junctions. - ConfigOptionFloat support_critical_angle /*= 45*/; + ((ConfigOptionFloat, support_critical_angle))/*= 45*/ // The max length of a bridge in mm - ConfigOptionFloat support_max_bridge_length /*= 15.0*/; + ((ConfigOptionFloat, support_max_bridge_length))/*= 15.0*/ // The max distance of two pillars to get cross linked. - ConfigOptionFloat support_max_pillar_link_distance; + ((ConfigOptionFloat, support_max_pillar_link_distance)) // The elevation in Z direction upwards. This is the space between the pad // and the model object's bounding box bottom. Units in mm. - ConfigOptionFloat support_object_elevation /*= 5.0*/; + ((ConfigOptionFloat, support_object_elevation))/*= 5.0*/ /////// Following options influence automatic support points placement: - ConfigOptionInt support_points_density_relative; - ConfigOptionFloat support_points_minimal_distance; + ((ConfigOptionInt, support_points_density_relative)) + ((ConfigOptionFloat, support_points_minimal_distance)) // Now for the base pool (pad) ///////////////////////////////////////////// // Enabling or disabling support creation - ConfigOptionBool pad_enable; + ((ConfigOptionBool, pad_enable)) // The thickness of the pad walls - ConfigOptionFloat pad_wall_thickness /*= 2*/; + ((ConfigOptionFloat, pad_wall_thickness))/*= 2*/ // The height of the pad from the bottom to the top not considering the pit - ConfigOptionFloat pad_wall_height /*= 5*/; + ((ConfigOptionFloat, pad_wall_height))/*= 5*/ // How far should the pad extend around the contained geometry - ConfigOptionFloat pad_brim_size; + ((ConfigOptionFloat, pad_brim_size)) // The greatest distance where two individual pads are merged into one. The // distance is measured roughly from the centroids of the pads. - ConfigOptionFloat pad_max_merge_distance /*= 50*/; + ((ConfigOptionFloat, pad_max_merge_distance))/*= 50*/ // The smoothing radius of the pad edges - // ConfigOptionFloat pad_edge_radius /*= 1*/; + // ((ConfigOptionFloat, pad_edge_radius))/*= 1*/; // The slope of the pad wall... - ConfigOptionFloat pad_wall_slope; + ((ConfigOptionFloat, pad_wall_slope)) // ///////////////////////////////////////////////////////////////////////// // Zero elevation mode parameters: @@ -1208,21 +992,21 @@ public: // ///////////////////////////////////////////////////////////////////////// // Disable the elevation (ignore its value) and use the zero elevation mode - ConfigOptionBool pad_around_object; + ((ConfigOptionBool, pad_around_object)) - ConfigOptionBool pad_around_object_everywhere; + ((ConfigOptionBool, pad_around_object_everywhere)) // This is the gap between the object bottom and the generated pad - ConfigOptionFloat pad_object_gap; + ((ConfigOptionFloat, pad_object_gap)) // How far to place the connector sticks on the object pad perimeter - ConfigOptionFloat pad_object_connector_stride; + ((ConfigOptionFloat, pad_object_connector_stride)) // The width of the connectors sticks - ConfigOptionFloat pad_object_connector_width; + ((ConfigOptionFloat, pad_object_connector_width)) // How much should the tiny connectors penetrate into the model body - ConfigOptionFloat pad_object_connector_penetration; + ((ConfigOptionFloat, pad_object_connector_penetration)) // ///////////////////////////////////////////////////////////////////////// // Model hollowing parameters: @@ -1233,169 +1017,85 @@ public: // - resin removal. // ///////////////////////////////////////////////////////////////////////// - ConfigOptionBool hollowing_enable; + ((ConfigOptionBool, hollowing_enable)) // The minimum thickness of the model walls to maintain. Note that the // resulting walls may be thicker due to smoothing out fine cavities where // resin could stuck. - ConfigOptionFloat hollowing_min_thickness; + ((ConfigOptionFloat, hollowing_min_thickness)) // Indirectly controls the voxel size (resolution) used by openvdb - ConfigOptionFloat hollowing_quality; + ((ConfigOptionFloat, hollowing_quality)) // Indirectly controls the minimum size of created cavities. - ConfigOptionFloat hollowing_closing_distance; + ((ConfigOptionFloat, hollowing_closing_distance)) +) -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(layer_height); - OPT_PTR(faded_layers); - OPT_PTR(slice_closing_radius); - OPT_PTR(supports_enable); - OPT_PTR(support_head_front_diameter); - OPT_PTR(support_head_penetration); - OPT_PTR(support_head_width); - OPT_PTR(support_pillar_diameter); - OPT_PTR(support_small_pillar_diameter_percent); - OPT_PTR(support_max_bridges_on_pillar); - OPT_PTR(support_pillar_connection_mode); - OPT_PTR(support_buildplate_only); - OPT_PTR(support_pillar_widening_factor); - OPT_PTR(support_base_diameter); - OPT_PTR(support_base_height); - OPT_PTR(support_base_safety_distance); - OPT_PTR(support_critical_angle); - OPT_PTR(support_max_bridge_length); - OPT_PTR(support_max_pillar_link_distance); - OPT_PTR(support_points_density_relative); - OPT_PTR(support_points_minimal_distance); - OPT_PTR(support_object_elevation); - OPT_PTR(pad_enable); - OPT_PTR(pad_wall_thickness); - OPT_PTR(pad_wall_height); - OPT_PTR(pad_brim_size); - OPT_PTR(pad_max_merge_distance); - // OPT_PTR(pad_edge_radius); - OPT_PTR(pad_wall_slope); - OPT_PTR(pad_around_object); - OPT_PTR(pad_around_object_everywhere); - OPT_PTR(pad_object_gap); - OPT_PTR(pad_object_connector_stride); - OPT_PTR(pad_object_connector_width); - OPT_PTR(pad_object_connector_penetration); - OPT_PTR(hollowing_enable); - OPT_PTR(hollowing_min_thickness); - OPT_PTR(hollowing_quality); - OPT_PTR(hollowing_closing_distance); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAMaterialConfig, -class SLAMaterialConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAMaterialConfig) -public: - ConfigOptionFloat initial_layer_height; - ConfigOptionFloat bottle_cost; - ConfigOptionFloat bottle_volume; - ConfigOptionFloat bottle_weight; - ConfigOptionFloat material_density; - ConfigOptionFloat exposure_time; - ConfigOptionFloat initial_exposure_time; - ConfigOptionFloats material_correction; -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(initial_layer_height); - OPT_PTR(bottle_cost); - OPT_PTR(bottle_volume); - OPT_PTR(bottle_weight); - OPT_PTR(material_density); - OPT_PTR(exposure_time); - OPT_PTR(initial_exposure_time); - OPT_PTR(material_correction); - } -}; + ((ConfigOptionFloat, initial_layer_height)) + ((ConfigOptionFloat, bottle_cost)) + ((ConfigOptionFloat, bottle_volume)) + ((ConfigOptionFloat, bottle_weight)) + ((ConfigOptionFloat, material_density)) + ((ConfigOptionFloat, exposure_time)) + ((ConfigOptionFloat, initial_exposure_time)) + ((ConfigOptionFloats, material_correction)) +) -class SLAPrinterConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrinterConfig) -public: - ConfigOptionEnum printer_technology; - ConfigOptionPoints bed_shape; - ConfigOptionFloat max_print_height; - ConfigOptionFloat display_width; - ConfigOptionFloat display_height; - ConfigOptionInt display_pixels_x; - ConfigOptionInt display_pixels_y; - ConfigOptionEnum display_orientation; - ConfigOptionBool display_mirror_x; - ConfigOptionBool display_mirror_y; - ConfigOptionFloats relative_correction; - ConfigOptionFloat absolute_correction; - ConfigOptionFloat elefant_foot_compensation; - ConfigOptionFloat elefant_foot_min_width; - ConfigOptionFloat gamma_correction; - ConfigOptionFloat fast_tilt_time; - ConfigOptionFloat slow_tilt_time; - ConfigOptionFloat area_fill; - ConfigOptionFloat min_exposure_time; - ConfigOptionFloat max_exposure_time; - ConfigOptionFloat min_initial_exposure_time; - ConfigOptionFloat max_initial_exposure_time; -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(printer_technology); - OPT_PTR(bed_shape); - OPT_PTR(max_print_height); - OPT_PTR(display_width); - OPT_PTR(display_height); - OPT_PTR(display_pixels_x); - OPT_PTR(display_pixels_y); - OPT_PTR(display_mirror_x); - OPT_PTR(display_mirror_y); - OPT_PTR(display_orientation); - OPT_PTR(relative_correction); - OPT_PTR(absolute_correction); - OPT_PTR(elefant_foot_compensation); - OPT_PTR(elefant_foot_min_width); - OPT_PTR(gamma_correction); - OPT_PTR(fast_tilt_time); - OPT_PTR(slow_tilt_time); - OPT_PTR(area_fill); - OPT_PTR(min_exposure_time); - OPT_PTR(max_exposure_time); - OPT_PTR(min_initial_exposure_time); - OPT_PTR(max_initial_exposure_time); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrinterConfig, -class SLAFullPrintConfig : public SLAPrinterConfig, public SLAPrintConfig, public SLAPrintObjectConfig, public SLAMaterialConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(SLAFullPrintConfig) - SLAFullPrintConfig() : SLAPrinterConfig(0), SLAPrintConfig(0), SLAPrintObjectConfig(0), SLAMaterialConfig(0) { initialize_cache(); *this = s_cache_SLAFullPrintConfig.defaults(); } + ((ConfigOptionEnum, printer_technology)) + ((ConfigOptionPoints, bed_shape)) + ((ConfigOptionFloat, max_print_height)) + ((ConfigOptionFloat, display_width)) + ((ConfigOptionFloat, display_height)) + ((ConfigOptionInt, display_pixels_x)) + ((ConfigOptionInt, display_pixels_y)) + ((ConfigOptionEnum,display_orientation)) + ((ConfigOptionBool, display_mirror_x)) + ((ConfigOptionBool, display_mirror_y)) + ((ConfigOptionFloats, relative_correction)) + ((ConfigOptionFloat, absolute_correction)) + ((ConfigOptionFloat, elefant_foot_compensation)) + ((ConfigOptionFloat, elefant_foot_min_width)) + ((ConfigOptionFloat, gamma_correction)) + ((ConfigOptionFloat, fast_tilt_time)) + ((ConfigOptionFloat, slow_tilt_time)) + ((ConfigOptionFloat, area_fill)) + ((ConfigOptionFloat, min_exposure_time)) + ((ConfigOptionFloat, max_exposure_time)) + ((ConfigOptionFloat, min_initial_exposure_time)) + ((ConfigOptionFloat, max_initial_exposure_time)) +) -public: - // Validate the SLAFullPrintConfig. Returns an empty string on success, otherwise an error message is returned. -// std::string validate(); - -protected: - // Protected constructor to be called to initialize ConfigCache::m_default. - SLAFullPrintConfig(int) : SLAPrinterConfig(0), SLAPrintConfig(0), SLAPrintObjectConfig(0), SLAMaterialConfig(0) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->SLAPrinterConfig ::initialize(cache, base_ptr); - this->SLAPrintConfig ::initialize(cache, base_ptr); - this->SLAPrintObjectConfig::initialize(cache, base_ptr); - this->SLAMaterialConfig ::initialize(cache, base_ptr); - } -}; +PRINT_CONFIG_CLASS_DERIVED_DEFINE0( + SLAFullPrintConfig, + (SLAPrinterConfig, SLAPrintConfig, SLAPrintObjectConfig, SLAMaterialConfig) +) #undef STATIC_PRINT_CONFIG_CACHE #undef STATIC_PRINT_CONFIG_CACHE_BASE #undef STATIC_PRINT_CONFIG_CACHE_DERIVED -#undef OPT_PTR +#undef PRINT_CONFIG_CLASS_ELEMENT_DEFINITION +#undef PRINT_CONFIG_CLASS_ELEMENT_EQUAL +#undef PRINT_CONFIG_CLASS_ELEMENT_HASH +#undef PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION +#undef PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2 +#undef PRINT_CONFIG_CLASS_DEFINE +#undef PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST +#undef PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE0 +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE1 +#undef PRINT_CONFIG_CLASS_DERIVED_HASH +#undef PRINT_CONFIG_CLASS_DERIVED_EQUAL +#undef PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM +#undef PRINT_CONFIG_CLASS_DERIVED_INITCACHE +#undef PRINT_CONFIG_CLASS_DERIVED_INITIALIZER +#undef PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM class CLIActionsConfigDef : public ConfigDef { diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 1989b18846..8445855586 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -186,7 +186,7 @@ void PrintObject::make_perimeters() m_print->throw_if_canceled(); LayerRegion &layerm = *m_layers[layer_idx]->m_regions[region_id]; const LayerRegion &upper_layerm = *m_layers[layer_idx+1]->m_regions[region_id]; - const Polygons upper_layerm_polygons = upper_layerm.slices; + const Polygons upper_layerm_polygons = to_polygons(upper_layerm.slices.surfaces); // Filter upper layer polygons in intersection_ppl by their bounding boxes? // my $upper_layerm_poly_bboxes= [ map $_->bounding_box, @{$upper_layerm_polygons} ]; const double total_loop_length = total_length(upper_layerm_polygons); @@ -591,6 +591,7 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "support_material_style" || opt_key == "support_material_xy_spacing" || opt_key == "support_material_spacing" + || opt_key == "support_material_closing_radius" || opt_key == "support_material_synchronize_layers" || opt_key == "support_material_threshold" || opt_key == "support_material_with_sheath" @@ -808,19 +809,14 @@ void PrintObject::detect_surfaces_type() // collapse very narrow parts (using the safety offset in the diff is not enough) float offset = layerm->flow(frExternalPerimeter).scaled_width() / 10.f; - Polygons layerm_slices_surfaces = to_polygons(layerm->slices.surfaces); - // find top surfaces (difference between current surfaces // of current layer and upper one) Surfaces top; if (upper_layer) { - Polygons upper_slices = interface_shells ? - to_polygons(upper_layer->m_regions[idx_region]->slices.surfaces) : - to_polygons(upper_layer->lslices); - surfaces_append(top, - //FIXME implement offset2_ex working over ExPolygons, that should be a bit more efficient than calling offset_ex twice. - offset_ex(offset_ex(diff_ex(layerm_slices_surfaces, upper_slices, true), -offset), offset), - stTop); + ExPolygons upper_slices = interface_shells ? + diff_ex(layerm->slices.surfaces, upper_layer->m_regions[idx_region]->slices.surfaces, true) : + diff_ex(layerm->slices.surfaces, upper_layer->lslices, true); + surfaces_append(top, offset2_ex(upper_slices, -offset, offset), stTop); } else { // if no upper layer, all surfaces of this one are solid // we clone surfaces because we're going to clear the slices collection @@ -838,14 +834,14 @@ void PrintObject::detect_surfaces_type() to_polygons(lower_layer->get_region(idx_region)->slices.surfaces) : to_polygons(lower_layer->slices); surfaces_append(bottom, - offset2_ex(diff(layerm_slices_surfaces, lower_slices, true), -offset, offset), + offset2_ex(diff(layerm->slices.surfaces, lower_slices, true), -offset, offset), surface_type_bottom_other); #else // Any surface lying on the void is a true bottom bridge (an overhang) surfaces_append( bottom, offset2_ex( - diff(layerm_slices_surfaces, to_polygons(lower_layer->lslices), true), + diff_ex(layerm->slices.surfaces, lower_layer->lslices, true), -offset, offset), surface_type_bottom_other); // if user requested internal shells, we need to identify surfaces @@ -856,10 +852,10 @@ void PrintObject::detect_surfaces_type() surfaces_append( bottom, offset2_ex( - diff( - intersection(layerm_slices_surfaces, to_polygons(lower_layer->lslices)), // supported - to_polygons(lower_layer->m_regions[idx_region]->slices.surfaces), - true), + diff_ex( + intersection(layerm->slices.surfaces, lower_layer->lslices), // supported + lower_layer->m_regions[idx_region]->slices.surfaces, + true), -offset, offset), stBottom); } @@ -882,7 +878,7 @@ void PrintObject::detect_surfaces_type() Polygons top_polygons = to_polygons(std::move(top)); top.clear(); surfaces_append(top, - diff_ex(top_polygons, to_polygons(bottom), false), + diff_ex(top_polygons, bottom, false), stTop); } @@ -899,15 +895,18 @@ void PrintObject::detect_surfaces_type() // save surfaces to layer Surfaces &surfaces_out = interface_shells ? surfaces_new[idx_layer] : layerm->slices.surfaces; - surfaces_out.clear(); + Surfaces surfaces_backup; + if (! interface_shells) { + surfaces_backup = std::move(surfaces_out); + surfaces_out.clear(); + } + const Surfaces &surfaces_prev = interface_shells ? layerm->slices.surfaces : surfaces_backup; // find internal surfaces (difference between top/bottom surfaces and others) { Polygons topbottom = to_polygons(top); polygons_append(topbottom, to_polygons(bottom)); - surfaces_append(surfaces_out, - diff_ex(layerm_slices_surfaces, topbottom, false), - stInternal); + surfaces_append(surfaces_out, diff_ex(surfaces_prev, topbottom, false), stInternal); } surfaces_append(surfaces_out, std::move(top)); @@ -1011,7 +1010,7 @@ void PrintObject::process_external_surfaces() // Shrink the holes, let the layer above expand slightly inside the unsupported areas. polygons_append(voids, offset(surface.expolygon, unsupported_width)); } - surfaces_covered[layer_idx] = diff(to_polygons(this->m_layers[layer_idx]->lslices), voids); + surfaces_covered[layer_idx] = diff(this->m_layers[layer_idx]->lslices, voids); } } ); @@ -1106,11 +1105,11 @@ void PrintObject::discover_vertical_shells() LayerRegion &layerm = *layer.m_regions[idx_region]; float min_perimeter_infill_spacing = float(layerm.flow(frSolidInfill).scaled_spacing()) * 1.05f; // Top surfaces. - append(cache.top_surfaces, offset(to_expolygons(layerm.slices.filter_by_type(stTop)), min_perimeter_infill_spacing)); - append(cache.top_surfaces, offset(to_expolygons(layerm.fill_surfaces.filter_by_type(stTop)), min_perimeter_infill_spacing)); + append(cache.top_surfaces, offset(layerm.slices.filter_by_type(stTop), min_perimeter_infill_spacing)); + append(cache.top_surfaces, offset(layerm.fill_surfaces.filter_by_type(stTop), min_perimeter_infill_spacing)); // Bottom surfaces. - append(cache.bottom_surfaces, offset(to_expolygons(layerm.slices.filter_by_types(surfaces_bottom, 2)), min_perimeter_infill_spacing)); - append(cache.bottom_surfaces, offset(to_expolygons(layerm.fill_surfaces.filter_by_types(surfaces_bottom, 2)), min_perimeter_infill_spacing)); + append(cache.bottom_surfaces, offset(layerm.slices.filter_by_types(surfaces_bottom, 2), min_perimeter_infill_spacing)); + append(cache.bottom_surfaces, offset(layerm.fill_surfaces.filter_by_types(surfaces_bottom, 2), min_perimeter_infill_spacing)); // Calculate the maximum perimeter offset as if the slice was extruded with a single extruder only. // First find the maxium number of perimeters per region slice. unsigned int perimeters = 0; @@ -1180,11 +1179,11 @@ void PrintObject::discover_vertical_shells() float min_perimeter_infill_spacing = float(layerm.flow(frSolidInfill).scaled_spacing()) * 1.05f; // Top surfaces. auto &cache = cache_top_botom_regions[idx_layer]; - cache.top_surfaces = offset(to_expolygons(layerm.slices.filter_by_type(stTop)), min_perimeter_infill_spacing); - append(cache.top_surfaces, offset(to_expolygons(layerm.fill_surfaces.filter_by_type(stTop)), min_perimeter_infill_spacing)); + cache.top_surfaces = offset(layerm.slices.filter_by_type(stTop), min_perimeter_infill_spacing); + append(cache.top_surfaces, offset(layerm.fill_surfaces.filter_by_type(stTop), min_perimeter_infill_spacing)); // Bottom surfaces. - cache.bottom_surfaces = offset(to_expolygons(layerm.slices.filter_by_types(surfaces_bottom, 2)), min_perimeter_infill_spacing); - append(cache.bottom_surfaces, offset(to_expolygons(layerm.fill_surfaces.filter_by_types(surfaces_bottom, 2)), min_perimeter_infill_spacing)); + cache.bottom_surfaces = offset(layerm.slices.filter_by_types(surfaces_bottom, 2), min_perimeter_infill_spacing); + append(cache.bottom_surfaces, offset(layerm.fill_surfaces.filter_by_types(surfaces_bottom, 2), min_perimeter_infill_spacing)); // Holes over all regions. Only collect them once, they are valid for all idx_region iterations. if (cache.holes.empty()) { for (size_t idx_region = 0; idx_region < layer.regions().size(); ++ idx_region) @@ -1406,16 +1405,8 @@ void PrintObject::discover_vertical_shells() #endif /* SLIC3R_DEBUG_SLICE_PROCESSING */ // Trim the internal & internalvoid by the shell. - Slic3r::ExPolygons new_internal = diff_ex( - to_polygons(layerm->fill_surfaces.filter_by_type(stInternal)), - shell, - false - ); - Slic3r::ExPolygons new_internal_void = diff_ex( - to_polygons(layerm->fill_surfaces.filter_by_type(stInternalVoid)), - shell, - false - ); + Slic3r::ExPolygons new_internal = diff_ex(layerm->fill_surfaces.filter_by_type(stInternal), shell); + Slic3r::ExPolygons new_internal_void = diff_ex(layerm->fill_surfaces.filter_by_type(stInternalVoid), shell); #ifdef SLIC3R_DEBUG_SLICE_PROCESSING { @@ -1520,8 +1511,8 @@ void PrintObject::bridge_over_infill() #endif // compute the remaning internal solid surfaces as difference - ExPolygons not_to_bridge = diff_ex(internal_solid, to_polygons(to_bridge), true); - to_bridge = intersection_ex(to_polygons(to_bridge), internal_solid, true); + ExPolygons not_to_bridge = diff_ex(internal_solid, to_bridge, true); + to_bridge = intersection_ex(to_bridge, internal_solid, true); // build the new collection of fill_surfaces layerm->fill_surfaces.remove_type(stInternalSolid); for (ExPolygon &ex : to_bridge) @@ -1874,7 +1865,7 @@ void PrintObject::_slice(const std::vector &layer_height_profile) slices = offset_ex(std::move(slices), delta); if (! processed.empty()) // Trim by the slices of already processed regions. - slices = diff_ex(to_polygons(std::move(slices)), processed); + slices = diff_ex(slices, processed); if (size_t(&sliced_volume - &sliced_volumes.front()) + 1 < sliced_volumes.size()) // Collect the already processed regions to trim the to be processed regions. polygons_append(processed, slices); @@ -1925,12 +1916,11 @@ void PrintObject::_slice(const std::vector &layer_height_profile) LayerRegion *other_layerm = layer->m_regions[other_region_id]; if (layerm == nullptr || other_layerm == nullptr || other_layerm->slices.empty() || expolygons_by_layer[layer_id].empty()) continue; - Polygons other_slices = to_polygons(other_layerm->slices); - ExPolygons my_parts = intersection_ex(other_slices, to_polygons(expolygons_by_layer[layer_id])); + ExPolygons my_parts = intersection_ex(other_layerm->slices.surfaces, expolygons_by_layer[layer_id]); if (my_parts.empty()) continue; // Remove such parts from original region. - other_layerm->slices.set(diff_ex(other_slices, to_polygons(my_parts)), stInternal); + other_layerm->slices.set(diff_ex(other_layerm->slices.surfaces, my_parts), stInternal); // Append new parts to our region. layerm->slices.append(std::move(my_parts), stInternal); } @@ -2017,7 +2007,7 @@ end: slices = offset_ex(std::move(slices), xy_compensation_scaled); if (region_id > 0 && clip) // Trim by the slices of already processed regions. - slices = diff_ex(to_polygons(std::move(slices)), processed); + slices = diff_ex(slices, processed); if (clip && (region_id + 1 < layer->m_regions.size())) // Collect the already processed regions to trim the to be processed regions. polygons_append(processed, slices); @@ -2206,6 +2196,7 @@ std::vector PrintObject::slice_volumes( TriangleMesh vol_mesh(model_volume.mesh()); vol_mesh.transform(model_volume.get_matrix(), true); mesh.merge(vol_mesh); + mesh.repair(false); } if (mesh.stl.stats.number_of_facets > 0) { mesh.transform(m_trafo, true); @@ -2648,10 +2639,7 @@ void PrintObject::discover_horizontal_shells() neighbor_layerm->fill_surfaces.set(internal_solid, stInternalSolid); // subtract intersections from layer surfaces to get resulting internal surfaces Polygons polygons_internal = to_polygons(std::move(internal_solid)); - ExPolygons internal = diff_ex( - to_polygons(backup.filter_by_type(stInternal)), - polygons_internal, - true); + ExPolygons internal = diff_ex(backup.filter_by_type(stInternal), polygons_internal, true); // assign resulting internal surfaces to layer neighbor_layerm->fill_surfaces.append(internal, stInternal); polygons_append(polygons_internal, to_polygons(std::move(internal))); @@ -2662,7 +2650,7 @@ void PrintObject::discover_horizontal_shells() backup.group(&top_bottom_groups); for (SurfacesPtr &group : top_bottom_groups) neighbor_layerm->fill_surfaces.append( - diff_ex(to_polygons(group), polygons_internal), + diff_ex(group, polygons_internal), // Use an existing surface as a template, it carries the bridge angle etc. *group.front()); } @@ -2741,10 +2729,7 @@ void PrintObject::combine_infill() ExPolygons intersection = to_expolygons(layerms.front()->fill_surfaces.filter_by_type(stInternal)); // Start looping from the second layer and intersect the current intersection with it. for (size_t i = 1; i < layerms.size(); ++ i) - intersection = intersection_ex( - to_polygons(intersection), - to_polygons(layerms[i]->fill_surfaces.filter_by_type(stInternal)), - false); + intersection = intersection_ex(layerms[i]->fill_surfaces.filter_by_type(stInternal), intersection); double area_threshold = layerms.front()->infill_area_threshold(); if (! intersection.empty() && area_threshold > 0.) intersection.erase(std::remove_if(intersection.begin(), intersection.end(), @@ -2773,7 +2758,7 @@ void PrintObject::combine_infill() for (ExPolygon &expoly : intersection) polygons_append(intersection_with_clearance, offset(expoly, clearance_offset)); for (LayerRegion *layerm : layerms) { - Polygons internal = to_polygons(layerm->fill_surfaces.filter_by_type(stInternal)); + Polygons internal = to_polygons(std::move(layerm->fill_surfaces.filter_by_type(stInternal))); layerm->fill_surfaces.remove_type(stInternal); layerm->fill_surfaces.append(diff_ex(internal, intersection_with_clearance, false), stInternal); if (layerm == layerms.back()) { diff --git a/src/libslic3r/SLA/AGGRaster.hpp b/src/libslic3r/SLA/AGGRaster.hpp index 849cec30a1..2243a3c1b5 100644 --- a/src/libslic3r/SLA/AGGRaster.hpp +++ b/src/libslic3r/SLA/AGGRaster.hpp @@ -4,7 +4,6 @@ #include #include "libslic3r/ExPolygon.hpp" #include "libslic3r/MTUtils.hpp" -#include // For rasterizing #include @@ -21,10 +20,7 @@ namespace Slic3r { inline const Polygon& contour(const ExPolygon& p) { return p.contour; } -inline const ClipperLib::Path& contour(const ClipperLib::Polygon& p) { return p.Contour; } - inline const Polygons& holes(const ExPolygon& p) { return p.holes; } -inline const ClipperLib::Paths& holes(const ClipperLib::Polygon& p) { return p.Holes; } namespace sla { @@ -77,8 +73,6 @@ protected: double getPx(const Point &p) { return p(0) * m_pxdim_scaled.w_mm; } double getPy(const Point &p) { return p(1) * m_pxdim_scaled.h_mm; } agg::path_storage to_path(const Polygon &poly) { return to_path(poly.points); } - double getPx(const ClipperLib::IntPoint &p) { return p.X * m_pxdim_scaled.w_mm; } - double getPy(const ClipperLib::IntPoint& p) { return p.Y * m_pxdim_scaled.h_mm; } template agg::path_storage _to_path(const PointVec& v) { @@ -168,7 +162,6 @@ public: } void draw(const ExPolygon &poly) override { _draw(poly); } - void draw(const ClipperLib::Polygon &poly) override { _draw(poly); } EncodedRaster encode(RasterEncoder encoder) const override { diff --git a/src/libslic3r/SLA/ConcaveHull.cpp b/src/libslic3r/SLA/ConcaveHull.cpp index d3c0d10224..1724089894 100644 --- a/src/libslic3r/SLA/ConcaveHull.cpp +++ b/src/libslic3r/SLA/ConcaveHull.cpp @@ -42,9 +42,10 @@ Point ConcaveHull::centroid(const Points &pp) // As it shows, the current offset_ex in ClipperUtils hangs if used in jtRound // mode -static ClipperLib::Paths fast_offset(const ClipperLib::Paths &paths, - coord_t delta, - ClipperLib::JoinType jointype) +template +static ClipperLib::Paths fast_offset(PolygonsProvider &&paths, + coord_t delta, + ClipperLib::JoinType jointype) { using ClipperLib::ClipperOffset; using ClipperLib::etClosedPolygon; @@ -61,7 +62,7 @@ static ClipperLib::Paths fast_offset(const ClipperLib::Paths &paths, return {}; } - offs.AddPaths(paths, jointype, etClosedPolygon); + offs.AddPaths(std::forward(paths), jointype, etClosedPolygon); Paths result; offs.Execute(result, static_cast(delta)); @@ -157,11 +158,9 @@ ExPolygons ConcaveHull::to_expolygons() const ExPolygons offset_waffle_style_ex(const ConcaveHull &hull, coord_t delta) { - ClipperLib::Paths paths = Slic3rMultiPoints_to_ClipperPaths(hull.polygons()); - paths = fast_offset(paths, 2 * delta, ClipperLib::jtRound); - paths = fast_offset(paths, -delta, ClipperLib::jtRound); - ExPolygons ret = ClipperPaths_to_Slic3rExPolygons(paths); - for (ExPolygon &p : ret) p.holes = {}; + ExPolygons ret = ClipperPaths_to_Slic3rExPolygons( + fast_offset(fast_offset(ClipperUtils::PolygonsProvider(hull.polygons()), 2 * delta, ClipperLib::jtRound), -delta, ClipperLib::jtRound)); + for (ExPolygon &p : ret) p.holes.clear(); return ret; } diff --git a/src/libslic3r/SLA/Concurrency.hpp b/src/libslic3r/SLA/Concurrency.hpp index 8ff0ff809e..7299101b31 100644 --- a/src/libslic3r/SLA/Concurrency.hpp +++ b/src/libslic3r/SLA/Concurrency.hpp @@ -1,16 +1,10 @@ #ifndef SLA_CONCURRENCY_H #define SLA_CONCURRENCY_H -#include -#include -#include -#include -#include +// FIXME: Deprecated -#include -#include - -#include +#include +#include namespace Slic3r { namespace sla { @@ -23,124 +17,48 @@ template struct _ccr {}; template<> struct _ccr { - using SpinningMutex = tbb::spin_mutex; - using BlockingMutex = tbb::mutex; - - template - static IteratorOnly loop_(const tbb::blocked_range &range, Fn &&fn) - { - for (auto &el : range) fn(el); - } - - template - static IntegerOnly loop_(const tbb::blocked_range &range, Fn &&fn) - { - for (I i = range.begin(); i < range.end(); ++i) fn(i); - } + using SpinningMutex = execution::SpinningMutex; + using BlockingMutex = execution::BlockingMutex; template static void for_each(It from, It to, Fn &&fn, size_t granularity = 1) { - tbb::parallel_for(tbb::blocked_range{from, to, granularity}, - [&fn](const auto &range) { - loop_(range, std::forward(fn)); - }); + execution::for_each(ex_tbb, from, to, std::forward(fn), granularity); } - template - static T reduce(I from, - I to, - const T &init, - MergeFn &&mergefn, - AccessFn &&access, - size_t granularity = 1 - ) + template + static auto reduce(Args&&...args) { - return tbb::parallel_reduce( - tbb::blocked_range{from, to, granularity}, init, - [&](const auto &range, T subinit) { - T acc = subinit; - loop_(range, [&](auto &i) { acc = mergefn(acc, access(i)); }); - return acc; - }, - std::forward(mergefn)); - } - - template - static IteratorOnly reduce(I from, - I to, - const T & init, - MergeFn &&mergefn, - size_t granularity = 1) - { - return reduce( - from, to, init, std::forward(mergefn), - [](typename I::value_type &i) { return i; }, granularity); + return execution::reduce(ex_tbb, std::forward(args)...); } static size_t max_concurreny() { - return tbb::this_task_arena::max_concurrency(); + return execution::max_concurrency(ex_tbb); } }; template<> struct _ccr { -private: - struct _Mtx { inline void lock() {} inline void unlock() {} }; - -public: - using SpinningMutex = _Mtx; - using BlockingMutex = _Mtx; - - template - static IteratorOnly loop_(It from, It to, Fn &&fn) - { - for (auto it = from; it != to; ++it) fn(*it); - } - - template - static IntegerOnly loop_(I from, I to, Fn &&fn) - { - for (I i = from; i < to; ++i) fn(i); - } + using SpinningMutex = execution::SpinningMutex; + using BlockingMutex = execution::BlockingMutex; template - static void for_each(It from, - It to, - Fn &&fn, - size_t /* ignore granularity */ = 1) + static void for_each(It from, It to, Fn &&fn, size_t granularity = 1) { - loop_(from, to, std::forward(fn)); + execution::for_each(ex_seq, from, to, std::forward(fn), granularity); } - template - static T reduce(I from, - I to, - const T & init, - MergeFn &&mergefn, - AccessFn &&access, - size_t /*granularity*/ = 1 - ) + template + static auto reduce(Args&&...args) { - T acc = init; - loop_(from, to, [&](auto &i) { acc = mergefn(acc, access(i)); }); - return acc; + return execution::reduce(ex_seq, std::forward(args)...); } - template - static IteratorOnly reduce(I from, - I to, - const T &init, - MergeFn &&mergefn, - size_t /*granularity*/ = 1 - ) + static size_t max_concurreny() { - return reduce(from, to, init, std::forward(mergefn), - [](typename I::value_type &i) { return i; }); + return execution::max_concurrency(ex_seq); } - - static size_t max_concurreny() { return 1; } }; using ccr = _ccr; diff --git a/src/libslic3r/SLA/Pad.cpp b/src/libslic3r/SLA/Pad.cpp index 927c325898..e11914a1cb 100644 --- a/src/libslic3r/SLA/Pad.cpp +++ b/src/libslic3r/SLA/Pad.cpp @@ -179,10 +179,10 @@ PadSkeleton divide_blueprint(const ExPolygons &bp) ret.outer.reserve(size_t(ptree.Total())); for (ClipperLib::PolyTree::PolyNode *node : ptree.Childs) { - ExPolygon poly(ClipperPath_to_Slic3rPolygon(node->Contour)); + ExPolygon poly; + poly.contour.points = std::move(node->Contour); for (ClipperLib::PolyTree::PolyNode *child : node->Childs) { - poly.holes.emplace_back( - ClipperPath_to_Slic3rPolygon(child->Contour)); + poly.holes.emplace_back(std::move(child->Contour)); traverse_pt(child->Childs, &ret.inner); } @@ -342,18 +342,18 @@ public: template ExPolygon offset_contour_only(const ExPolygon &poly, coord_t delta, Args...args) { - ExPolygons tmp = offset_ex(poly.contour, float(delta), args...); + Polygons tmp = offset(poly.contour, float(delta), args...); if (tmp.empty()) return {}; Polygons holes = poly.holes; for (auto &h : holes) h.reverse(); - tmp = diff_ex(to_polygons(tmp), holes); + ExPolygons tmp2 = diff_ex(tmp, holes); - if (tmp.empty()) return {}; + if (tmp2.empty()) return {}; - return tmp.front(); + return std::move(tmp2.front()); } bool add_cavity(Contour3D &pad, ExPolygon &top_poly, const PadConfig3D &cfg, diff --git a/src/libslic3r/SLA/RasterBase.hpp b/src/libslic3r/SLA/RasterBase.hpp index 9f9f29cd52..bbb83b5a0b 100644 --- a/src/libslic3r/SLA/RasterBase.hpp +++ b/src/libslic3r/SLA/RasterBase.hpp @@ -11,8 +11,6 @@ #include #include -namespace ClipperLib { struct Polygon; } - namespace Slic3r { template using uqptr = std::unique_ptr; @@ -92,7 +90,6 @@ public: /// Draw a polygon with holes. virtual void draw(const ExPolygon& poly) = 0; - virtual void draw(const ClipperLib::Polygon& poly) = 0; /// Get the resolution of the raster. virtual Resolution resolution() const = 0; diff --git a/src/libslic3r/SLA/Rotfinder.cpp b/src/libslic3r/SLA/Rotfinder.cpp index 702690c196..b849212793 100644 --- a/src/libslic3r/SLA/Rotfinder.cpp +++ b/src/libslic3r/SLA/Rotfinder.cpp @@ -1,91 +1,110 @@ #include #include -#include + +#include +#include #include +#include #include "libslic3r/SLAPrint.hpp" #include "libslic3r/PrintConfig.hpp" #include -#include "Model.hpp" #include namespace Slic3r { namespace sla { -inline bool is_on_floor(const SLAPrintObject &mo) -{ - auto opt_elevation = mo.config().support_object_elevation.getFloat(); - auto opt_padaround = mo.config().pad_around_object.getBool(); +namespace { - return opt_elevation < EPSILON || opt_padaround; -} - -// Find transformed mesh ground level without copy and with parallel reduce. -double find_ground_level(const TriangleMesh &mesh, - const Transform3d & tr, - size_t threads) -{ - size_t vsize = mesh.its.vertices.size(); - - auto minfn = [](double a, double b) { return std::min(a, b); }; - - auto accessfn = [&mesh, &tr] (size_t vi) { - return (tr * mesh.its.vertices[vi].template cast()).z(); - }; - - double zmin = std::numeric_limits::max(); - size_t granularity = vsize / threads; - return ccr_par::reduce(size_t(0), vsize, zmin, minfn, accessfn, granularity); -} +inline const Vec3f DOWN = {0.f, 0.f, -1.f}; +constexpr double POINTS_PER_UNIT_AREA = 1.f; // Get the vertices of a triangle directly in an array of 3 points -std::array get_triangle_vertices(const TriangleMesh &mesh, +std::array get_triangle_vertices(const TriangleMesh &mesh, size_t faceidx) { const auto &face = mesh.its.indices[faceidx]; - return {Vec3d{mesh.its.vertices[face(0)].cast()}, - Vec3d{mesh.its.vertices[face(1)].cast()}, - Vec3d{mesh.its.vertices[face(2)].cast()}}; + return {mesh.its.vertices[face(0)], + mesh.its.vertices[face(1)], + mesh.its.vertices[face(2)]}; } -std::array get_transformed_triangle(const TriangleMesh &mesh, - const Transform3d & tr, +std::array get_transformed_triangle(const TriangleMesh &mesh, + const Transform3f & tr, size_t faceidx) { const auto &tri = get_triangle_vertices(mesh, faceidx); return {tr * tri[0], tr * tri[1], tr * tri[2]}; } +template Vec<3, T> normal(const std::array, 3> &tri) +{ + Vec<3, T> U = tri[1] - tri[0]; + Vec<3, T> V = tri[2] - tri[0]; + return U.cross(V).normalized(); +} + +template +T sum_score(AccessFn &&accessfn, size_t facecount, size_t Nthreads) +{ + T initv = 0.; + auto mergefn = [](T a, T b) { return a + b; }; + size_t grainsize = facecount / Nthreads; + size_t from = 0, to = facecount; + + return execution::reduce(ex_tbb, from, to, initv, mergefn, accessfn, grainsize); +} + +// Try to guess the number of support points needed to support a mesh +double get_misalginment_score(const TriangleMesh &mesh, const Transform3f &tr) +{ + if (mesh.its.vertices.empty()) return std::nan(""); + + auto accessfn = [&mesh, &tr](size_t fi) { + auto triangle = get_transformed_triangle(mesh, tr, fi); + Vec3f U = triangle[1] - triangle[0]; + Vec3f V = triangle[2] - triangle[0]; + Vec3f C = U.cross(V); + + // We should score against the alignment with the reference planes + return scaled(std::abs(C.dot(Vec3f::UnitX())) + + std::abs(C.dot(Vec3f::UnitY()))); + }; + + size_t facecount = mesh.its.indices.size(); + size_t Nthreads = std::thread::hardware_concurrency(); + double S = unscaled(sum_score(accessfn, facecount, Nthreads)); + + return S / facecount; +} + // Get area and normal of a triangle struct Facestats { - Vec3d normal; + Vec3f normal; double area; - explicit Facestats(const std::array &triangle) + explicit Facestats(const std::array &triangle) { - Vec3d U = triangle[1] - triangle[0]; - Vec3d V = triangle[2] - triangle[0]; - Vec3d C = U.cross(V); + Vec3f U = triangle[1] - triangle[0]; + Vec3f V = triangle[2] - triangle[0]; + Vec3f C = U.cross(V); normal = C.normalized(); area = 0.5 * C.norm(); } }; -inline const Vec3d DOWN = {0., 0., -1.}; -constexpr double POINTS_PER_UNIT_AREA = 1.; - // The score function for a particular face -inline double get_score(const Facestats &fc) +inline double get_supportedness_score(const Facestats &fc) { // Simply get the angle (acos of dot product) between the face normal and // the DOWN vector. - double phi = 1. - std::acos(fc.normal.dot(DOWN)) / PI; + float phi = 1. - std::acos(fc.normal.dot(DOWN)) / float(PI); - // Only consider faces that have have slopes below 90 deg: - phi = phi * (phi > 0.5); + // Only consider faces that have slopes below 90 deg: + phi = phi * (phi >= 0.5f); // Make the huge slopes more significant than the smaller slopes phi = phi * phi * phi; @@ -94,96 +113,92 @@ inline double get_score(const Facestats &fc) return fc.area * POINTS_PER_UNIT_AREA * phi; } -template -double sum_score(AccessFn &&accessfn, size_t facecount, size_t Nthreads) -{ - double initv = 0.; - auto mergefn = std::plus{}; - size_t grainsize = facecount / Nthreads; - size_t from = 0, to = facecount; - - return ccr_par::reduce(from, to, initv, mergefn, accessfn, grainsize); -} - // Try to guess the number of support points needed to support a mesh -double get_model_supportedness(const TriangleMesh &mesh, const Transform3d &tr) +double get_supportedness_score(const TriangleMesh &mesh, const Transform3f &tr) { if (mesh.its.vertices.empty()) return std::nan(""); auto accessfn = [&mesh, &tr](size_t fi) { Facestats fc{get_transformed_triangle(mesh, tr, fi)}; - return get_score(fc); + + return get_supportedness_score(fc); }; size_t facecount = mesh.its.indices.size(); size_t Nthreads = std::thread::hardware_concurrency(); - return sum_score(accessfn, facecount, Nthreads) / facecount; + double S = unscaled(sum_score(accessfn, facecount, Nthreads)); + + return S / facecount; } -double get_model_supportedness_onfloor(const TriangleMesh &mesh, - const Transform3d & tr) +// Find transformed mesh ground level without copy and with parallel reduce. +float find_ground_level(const TriangleMesh &mesh, + const Transform3f & tr, + size_t threads) +{ + size_t vsize = mesh.its.vertices.size(); + + auto minfn = [](float a, float b) { return std::min(a, b); }; + + auto accessfn = [&mesh, &tr] (size_t vi) { + return (tr * mesh.its.vertices[vi]).z(); + }; + + auto zmin = std::numeric_limits::max(); + size_t granularity = vsize / threads; + return execution::reduce(ex_tbb, size_t(0), vsize, zmin, minfn, accessfn, granularity); +} + +float get_supportedness_onfloor_score(const TriangleMesh &mesh, + const Transform3f & tr) { if (mesh.its.vertices.empty()) return std::nan(""); size_t Nthreads = std::thread::hardware_concurrency(); - double zmin = find_ground_level(mesh, tr, Nthreads); - double zlvl = zmin + 0.1; // Set up a slight tolerance from z level + float zmin = find_ground_level(mesh, tr, Nthreads); + float zlvl = zmin + 0.1f; // Set up a slight tolerance from z level auto accessfn = [&mesh, &tr, zlvl](size_t fi) { - std::array tri = get_transformed_triangle(mesh, tr, fi); + std::array tri = get_transformed_triangle(mesh, tr, fi); Facestats fc{tri}; if (tri[0].z() <= zlvl && tri[1].z() <= zlvl && tri[2].z() <= zlvl) return -fc.area * POINTS_PER_UNIT_AREA; - return get_score(fc); + return get_supportedness_score(fc); }; size_t facecount = mesh.its.indices.size(); - return sum_score(accessfn, facecount, Nthreads) / facecount; + double S = unscaled(sum_score(accessfn, facecount, Nthreads)); + + return S / facecount; } using XYRotation = std::array; // prepare the rotation transformation -Transform3d to_transform3d(const XYRotation &rot) +Transform3f to_transform3f(const XYRotation &rot) { - Transform3d rt = Transform3d::Identity(); - rt.rotate(Eigen::AngleAxisd(rot[1], Vec3d::UnitY())); - rt.rotate(Eigen::AngleAxisd(rot[0], Vec3d::UnitX())); + Transform3f rt = Transform3f::Identity(); + rt.rotate(Eigen::AngleAxisf(float(rot[1]), Vec3f::UnitY())); + rt.rotate(Eigen::AngleAxisf(float(rot[0]), Vec3f::UnitX())); + return rt; } -XYRotation from_transform3d(const Transform3d &tr) +XYRotation from_transform3f(const Transform3f &tr) { - Vec3d rot3d = Geometry::Transformation {tr}.get_rotation(); - return {rot3d.x(), rot3d.y()}; + Vec3d rot3 = Geometry::Transformation{tr.cast()}.get_rotation(); + return {rot3.x(), rot3.y()}; } -// Find the best score from a set of function inputs. Evaluate for every point. -template -std::array find_min_score(Fn &&fn, It from, It to, StopCond &&stopfn) +inline bool is_on_floor(const SLAPrintObjectConfig &cfg) { - std::array ret = {}; + auto opt_elevation = cfg.support_object_elevation.getFloat(); + auto opt_padaround = cfg.pad_around_object.getBool(); - double score = std::numeric_limits::max(); - - size_t Nthreads = std::thread::hardware_concurrency(); - size_t dist = std::distance(from, to); - std::vector scores(dist, score); - - ccr_par::for_each(size_t(0), dist, [&stopfn, &scores, &fn, &from](size_t i) { - if (stopfn()) return; - - scores[i] = fn(*(from + i)); - }, dist / Nthreads); - - auto it = std::min_element(scores.begin(), scores.end()); - - if (it != scores.end()) ret = *(from + std::distance(scores.begin(), it)); - - return ret; + return opt_elevation < EPSILON || opt_padaround; } // collect the rotations for each face of the convex hull @@ -214,8 +229,8 @@ std::vector get_chull_rotations(const TriangleMesh &mesh, size_t max Facestats fc{get_triangle_vertices(chull, fi)}; if (fc.area > area_threshold) { - auto q = Eigen::Quaterniond{}.FromTwoVectors(fc.normal, DOWN); - XYRotation rot = from_transform3d(Transform3d::Identity() * q); + auto q = Eigen::Quaternionf{}.FromTwoVectors(fc.normal, DOWN); + XYRotation rot = from_transform3f(Transform3f::Identity() * q); RotArea ra = {rot, fc.area}; auto it = std::lower_bound(inputs.begin(), inputs.end(), ra, rotcmp); @@ -238,10 +253,95 @@ std::vector get_chull_rotations(const TriangleMesh &mesh, size_t max return ret; } -Vec2d find_best_rotation(const SLAPrintObject & po, - float accuracy, - std::function statuscb, - std::function stopcond) +// Find the best score from a set of function inputs. Evaluate for every point. +template +std::array find_min_score(Fn &&fn, It from, It to, StopCond &&stopfn) +{ + std::array ret = {}; + + double score = std::numeric_limits::max(); + + size_t Nthreads = std::thread::hardware_concurrency(); + size_t dist = std::distance(from, to); + std::vector scores(dist, score); + + execution::for_each( + ex_tbb, size_t(0), dist, [&stopfn, &scores, &fn, &from](size_t i) { + if (stopfn()) return; + + scores[i] = fn(*(from + i)); + }, + dist / Nthreads); + + auto it = std::min_element(scores.begin(), scores.end()); + + if (it != scores.end()) + ret = *(from + std::distance(scores.begin(), it)); + + return ret; +} + +} // namespace + +Vec2d find_best_misalignment_rotation(const ModelObject & mo, + const RotOptimizeParams ¶ms) +{ + static constexpr unsigned MAX_TRIES = 1000; + + // return value + XYRotation rot; + + // We will use only one instance of this converted mesh to examine different + // rotations + TriangleMesh mesh = mo.raw_mesh(); + mesh.require_shared_vertices(); + + // To keep track of the number of iterations + int status = 0; + + // The maximum number of iterations + auto max_tries = unsigned(params.accuracy() * MAX_TRIES); + + auto &statuscb = params.statuscb(); + + // call status callback with zero, because we are at the start + statuscb(status); + + auto statusfn = [&statuscb, &status, &max_tries] { + // report status + statuscb(++status * 100.0/max_tries); + }; + + auto stopcond = [&statuscb] { + return ! statuscb(-1); + }; + + // Preparing the optimizer. + size_t gridsize = std::sqrt(max_tries); + opt::Optimizer solver(opt::StopCriteria{} + .max_iterations(max_tries) + .stop_condition(stopcond), + gridsize); + + // We are searching rotations around only two axes x, y. Thus the + // problem becomes a 2 dimensional optimization task. + // We can specify the bounds for a dimension in the following way: + auto bounds = opt::bounds({ {-PI/2, PI/2}, {-PI/2, PI/2} }); + + auto result = solver.to_max().optimize( + [&mesh, &statusfn] (const XYRotation &rot) + { + statusfn(); + return get_misalginment_score(mesh, to_transform3f(rot)); + }, opt::initvals({0., 0.}), bounds); + + rot = result.optimum; + + return {rot[0], rot[1]}; +} + +Vec2d find_least_supports_rotation(const ModelObject & mo, + const RotOptimizeParams ¶ms) { static const unsigned MAX_TRIES = 1000; @@ -250,14 +350,16 @@ Vec2d find_best_rotation(const SLAPrintObject & po, // We will use only one instance of this converted mesh to examine different // rotations - TriangleMesh mesh = po.model_object()->raw_mesh(); + TriangleMesh mesh = mo.raw_mesh(); mesh.require_shared_vertices(); // To keep track of the number of iterations unsigned status = 0; // The maximum number of iterations - auto max_tries = unsigned(accuracy * MAX_TRIES); + auto max_tries = unsigned(params.accuracy() * MAX_TRIES); + + auto &statuscb = params.statuscb(); // call status callback with zero, because we are at the start statuscb(status); @@ -267,8 +369,18 @@ Vec2d find_best_rotation(const SLAPrintObject & po, statuscb(unsigned(++status * 100.0/max_tries) ); }; + auto stopcond = [&statuscb] { + return ! statuscb(-1); + }; + + SLAPrintObjectConfig pocfg; + if (params.print_config()) + pocfg.apply(*params.print_config(), true); + + pocfg.apply(mo.config.get()); + // Different search methods have to be used depending on the model elevation - if (is_on_floor(po)) { + if (is_on_floor(pocfg)) { std::vector inputs = get_chull_rotations(mesh, max_tries); max_tries = inputs.size(); @@ -278,17 +390,19 @@ Vec2d find_best_rotation(const SLAPrintObject & po, auto objfn = [&mesh, &statusfn](const XYRotation &rot) { statusfn(); - Transform3d tr = to_transform3d(rot); - return get_model_supportedness_onfloor(mesh, tr); + Transform3f tr = to_transform3f(rot); + return get_supportedness_onfloor_score(mesh, tr); }; rot = find_min_score<2>(objfn, inputs.begin(), inputs.end(), stopcond); + } else { + // Preparing the optimizer. size_t gridsize = std::sqrt(max_tries); // 2D grid has gridsize^2 calls opt::Optimizer solver(opt::StopCriteria{} - .max_iterations(max_tries) - .stop_condition(stopcond), + .max_iterations(max_tries) + .stop_condition(stopcond), gridsize); // We are searching rotations around only two axes x, y. Thus the @@ -300,23 +414,14 @@ Vec2d find_best_rotation(const SLAPrintObject & po, [&mesh, &statusfn] (const XYRotation &rot) { statusfn(); - return get_model_supportedness(mesh, to_transform3d(rot)); + return get_supportedness_score(mesh, to_transform3f(rot)); }, opt::initvals({0., 0.}), bounds); - // Save the result and fck off + // Save the result rot = result.optimum; } return {rot[0], rot[1]}; } -double get_model_supportedness(const SLAPrintObject &po, const Transform3d &tr) -{ - TriangleMesh mesh = po.model_object()->raw_mesh(); - mesh.require_shared_vertices(); - - return is_on_floor(po) ? get_model_supportedness_onfloor(mesh, tr) : - get_model_supportedness(mesh, tr); -} - }} // namespace Slic3r::sla diff --git a/src/libslic3r/SLA/Rotfinder.hpp b/src/libslic3r/SLA/Rotfinder.hpp index 96561a890f..77a39016db 100644 --- a/src/libslic3r/SLA/Rotfinder.hpp +++ b/src/libslic3r/SLA/Rotfinder.hpp @@ -8,10 +8,39 @@ namespace Slic3r { +class ModelObject; class SLAPrintObject; +class TriangleMesh; +class DynamicPrintConfig; namespace sla { +using RotOptimizeStatusCB = std::function; + +class RotOptimizeParams { + float m_accuracy = 1.; + const DynamicPrintConfig *m_print_config = nullptr; + RotOptimizeStatusCB m_statuscb = [](int) { return true; }; + +public: + + RotOptimizeParams &accuracy(float a) { m_accuracy = a; return *this; } + RotOptimizeParams &print_config(const DynamicPrintConfig *c) + { + m_print_config = c; + return *this; + } + RotOptimizeParams &statucb(RotOptimizeStatusCB cb) + { + m_statuscb = std::move(cb); + return *this; + } + + float accuracy() const { return m_accuracy; } + const DynamicPrintConfig * print_config() const { return m_print_config; } + const RotOptimizeStatusCB &statuscb() const { return m_statuscb; } +}; + /** * The function should find the best rotation for SLA upside down printing. * @@ -19,23 +48,22 @@ namespace sla { * @param accuracy The optimization accuracy from 0.0f to 1.0f. Currently, * the nlopt genetic optimizer is used and the number of iterations is * accuracy * 100000. This can change in the future. - * @param statuscb A status indicator callback called with the unsigned + * @param statuscb A status indicator callback called with the int * argument spanning from 0 to 100. May not reach 100 if the optimization finds - * an optimum before max iterations are reached. - * @param stopcond A function that if returns true, the search process will be - * terminated and the best solution found will be returned. + * an optimum before max iterations are reached. It should return a boolean + * signaling if the operation may continue (true) or not (false). A status + * value lower than 0 shall not update the status but still return a valid + * continuation indicator. * * @return Returns the rotations around each axis (x, y, z) */ -Vec2d find_best_rotation( - const SLAPrintObject& modelobj, - float accuracy = 1.0f, - std::function statuscb = [] (unsigned) {}, - std::function stopcond = [] () { return false; } - ); +Vec2d find_best_misalignment_rotation(const ModelObject &modelobj, + const RotOptimizeParams & = {}); -double get_model_supportedness(const SLAPrintObject &mesh, - const Transform3d & tr); +Vec2d find_least_supports_rotation(const ModelObject &modelobj, + const RotOptimizeParams & = {}); + +double find_Z_fit_to_bed_rotation(const ModelObject &mo, const BoundingBox &bed); } // namespace sla } // namespace Slic3r diff --git a/src/libslic3r/SLA/SupportPointGenerator.cpp b/src/libslic3r/SLA/SupportPointGenerator.cpp index 7a4c290685..bbc6b03fa5 100644 --- a/src/libslic3r/SLA/SupportPointGenerator.cpp +++ b/src/libslic3r/SLA/SupportPointGenerator.cpp @@ -12,11 +12,9 @@ #include "ClipperUtils.hpp" #include "Tesselate.hpp" #include "ExPolygonCollection.hpp" +#include "MinAreaBoundingBox.hpp" #include "libslic3r.h" -#include "libnest2d/backends/clipper/geometries.hpp" -#include "libnest2d/utils/rotcalipers.hpp" - #include #include @@ -181,9 +179,8 @@ static std::vector make_layers( } } if (! top.islands_below.empty()) { - Polygons top_polygons = to_polygons(*top.polygon); Polygons bottom_polygons = top.polygons_below(); - top.overhangs = diff_ex(top_polygons, bottom_polygons); + top.overhangs = diff_ex(*top.polygon, bottom_polygons); if (! top.overhangs.empty()) { // Produce 2 bands around the island, a safe band for dangling overhangs @@ -193,7 +190,7 @@ static std::vector make_layers( auto overh_mask = offset(bottom_polygons, slope_offset, ClipperLib::jtSquare); // Absolutely hopeless overhangs are those outside the unsafe band - top.overhangs = diff_ex(top_polygons, overh_mask); + top.overhangs = diff_ex(*top.polygon, overh_mask); // Now cut out the supported core from the safe band // and cut the safe band from the unsafe band to get distinct @@ -201,8 +198,8 @@ static std::vector make_layers( overh_mask = diff(overh_mask, dangl_mask); dangl_mask = diff(dangl_mask, bottom_polygons); - top.dangling_areas = intersection_ex(top_polygons, dangl_mask); - top.overhangs_slopes = intersection_ex(top_polygons, overh_mask); + top.dangling_areas = intersection_ex(*top.polygon, dangl_mask); + top.overhangs_slopes = intersection_ex(*top.polygon, overh_mask); top.overhangs_area = 0.f; std::vector> expolys_with_areas; @@ -400,7 +397,7 @@ std::vector sample_expolygon(const ExPolygons &expolys, float samples_per void sample_expolygon_boundary(const ExPolygon & expoly, float samples_per_mm, std::vector &out, - std::mt19937 & rng) + std::mt19937 & /*rng*/) { double point_stepping_scaled = scale_(1.f) / samples_per_mm; for (size_t i_contour = 0; i_contour <= expoly.holes.size(); ++ i_contour) { @@ -553,9 +550,8 @@ void SupportPointGenerator::uniformly_cover(const ExPolygons& islands, Structure // auto bb = get_extents(islands); if (flags & icfIsNew) { - auto chull_ex = ExPolygonCollection{islands}.convex_hull(); - auto chull = Slic3rMultiPoint_to_ClipperPath(chull_ex); - auto rotbox = libnest2d::minAreaBoundingBox(chull); + auto chull = ExPolygonCollection{islands}.convex_hull(); + auto rotbox = MinAreaBoundigBox{chull, MinAreaBoundigBox::pcConvex}; Vec2d bbdim = {unscaled(rotbox.width()), unscaled(rotbox.height())}; if (bbdim.x() > bbdim.y()) std::swap(bbdim.x(), bbdim.y()); diff --git a/src/libslic3r/SLA/SupportPointGenerator.hpp b/src/libslic3r/SLA/SupportPointGenerator.hpp index d7588e3ba3..9ceda7896b 100644 --- a/src/libslic3r/SLA/SupportPointGenerator.hpp +++ b/src/libslic3r/SLA/SupportPointGenerator.hpp @@ -90,7 +90,7 @@ public: float overlap_area(const Structure &rhs) const { double out = 0.; if (this->bbox.overlap(rhs.bbox)) { - Polygons polys = intersection(to_polygons(*this->polygon), to_polygons(*rhs.polygon), false); + Polygons polys = intersection(*this->polygon, *rhs.polygon, false); for (const Polygon &poly : polys) out += poly.area(); } diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 74c71dc1e8..a94eb35fa4 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -9,7 +9,6 @@ #include "Point.hpp" #include "MTUtils.hpp" #include "Zipper.hpp" -#include namespace Slic3r { @@ -390,16 +389,25 @@ public: virtual void apply(const SLAPrinterConfig &cfg) = 0; // Fn have to be thread safe: void(sla::RasterBase& raster, size_t lyrid); - template void draw_layers(size_t layer_num, Fn &&drawfn) + template + void draw_layers( + size_t layer_num, + Fn && drawfn, + CancelFn cancelfn = []() { return false; }, + const EP & ep = {}) { m_layers.resize(layer_num); - sla::ccr::for_each(size_t(0), m_layers.size(), - [this, &drawfn] (size_t idx) { - sla::EncodedRaster& enc = m_layers[idx]; - auto rst = create_raster(); - drawfn(*rst, idx); - enc = rst->encode(get_encoder()); - }); + execution::for_each( + ep, size_t(0), m_layers.size(), + [this, &drawfn, &cancelfn](size_t idx) { + if (cancelfn()) return; + + sla::EncodedRaster &enc = m_layers[idx]; + auto rst = create_raster(); + drawfn(*rst, idx); + enc = rst->encode(get_encoder()); + }, + execution::max_concurrency(ep)); } }; @@ -474,7 +482,7 @@ public: // The collection of slice records for the current level. std::vector> m_slices; - std::vector m_transformed_slices; + ExPolygons m_transformed_slices; template void transformed_slices(Container&& c) { @@ -498,7 +506,7 @@ public: auto slices() const -> const decltype (m_slices)& { return m_slices; } - const std::vector & transformed_slices() const { + const ExPolygons & transformed_slices() const { return m_transformed_slices; } }; diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index fc66862011..108159b891 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -16,9 +16,6 @@ #include -// For geometry algorithms with native Clipper types (no copies and conversions) -#include - #include #include "I18N.hpp" @@ -717,55 +714,49 @@ void SLAPrint::Steps::slice_supports(SLAPrintObject &po) { report_status(-2, "", SlicingStatus::RELOAD_SLA_PREVIEW); } -using ClipperPoint = ClipperLib::IntPoint; -using ClipperPolygon = ClipperLib::Polygon; // see clipper_polygon.hpp in libnest2d -using ClipperPolygons = std::vector; +//static ClipperPolygons polyunion(const ClipperPolygons &subjects) +//{ +// ClipperLib::Clipper clipper; -static ClipperPolygons polyunion(const ClipperPolygons &subjects) -{ - ClipperLib::Clipper clipper; +// bool closed = true; - bool closed = true; +// for(auto& path : subjects) { +// clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed); +// clipper.AddPaths(path.Holes, ClipperLib::ptSubject, closed); +// } - for(auto& path : subjects) { - clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed); - clipper.AddPaths(path.Holes, ClipperLib::ptSubject, closed); - } +// auto mode = ClipperLib::pftPositive; - auto mode = ClipperLib::pftPositive; +// return libnest2d::clipper_execute(clipper, ClipperLib::ctUnion, mode, mode); +//} - return libnest2d::clipper_execute(clipper, ClipperLib::ctUnion, mode, mode); -} +//static ClipperPolygons polydiff(const ClipperPolygons &subjects, const ClipperPolygons& clips) +//{ +// ClipperLib::Clipper clipper; -static ClipperPolygons polydiff(const ClipperPolygons &subjects, const ClipperPolygons& clips) -{ - ClipperLib::Clipper clipper; +// bool closed = true; - bool closed = true; +// for(auto& path : subjects) { +// clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed); +// clipper.AddPaths(path.Holes, ClipperLib::ptSubject, closed); +// } - for(auto& path : subjects) { - clipper.AddPath(path.Contour, ClipperLib::ptSubject, closed); - clipper.AddPaths(path.Holes, ClipperLib::ptSubject, closed); - } +// for(auto& path : clips) { +// clipper.AddPath(path.Contour, ClipperLib::ptClip, closed); +// clipper.AddPaths(path.Holes, ClipperLib::ptClip, closed); +// } - for(auto& path : clips) { - clipper.AddPath(path.Contour, ClipperLib::ptClip, closed); - clipper.AddPaths(path.Holes, ClipperLib::ptClip, closed); - } +// auto mode = ClipperLib::pftPositive; - auto mode = ClipperLib::pftPositive; - - return libnest2d::clipper_execute(clipper, ClipperLib::ctDifference, mode, mode); -} +// return libnest2d::clipper_execute(clipper, ClipperLib::ctDifference, mode, mode); +//} // get polygons for all instances in the object -static ClipperPolygons get_all_polygons(const SliceRecord& record, SliceOrigin o) +static ExPolygons get_all_polygons(const SliceRecord& record, SliceOrigin o) { - namespace sl = libnest2d::sl; - if (!record.print_obj()) return {}; - ClipperPolygons polygons; + ExPolygons polygons; auto &input_polygons = record.get_slice(o); auto &instances = record.print_obj()->instances(); bool is_lefthanded = record.print_obj()->is_left_handed(); @@ -776,43 +767,42 @@ static ClipperPolygons get_all_polygons(const SliceRecord& record, SliceOrigin o for (size_t i = 0; i < instances.size(); ++i) { - ClipperPolygon poly; + ExPolygon poly; // We need to reverse if is_lefthanded is true but bool needreverse = is_lefthanded; // should be a move - poly.Contour.reserve(polygon.contour.size() + 1); + poly.contour.points.reserve(polygon.contour.size() + 1); auto& cntr = polygon.contour.points; if(needreverse) for(auto it = cntr.rbegin(); it != cntr.rend(); ++it) - poly.Contour.emplace_back(it->x(), it->y()); + poly.contour.points.emplace_back(it->x(), it->y()); else for(auto& p : cntr) - poly.Contour.emplace_back(p.x(), p.y()); + poly.contour.points.emplace_back(p.x(), p.y()); for(auto& h : polygon.holes) { - poly.Holes.emplace_back(); - auto& hole = poly.Holes.back(); - hole.reserve(h.points.size() + 1); + poly.holes.emplace_back(); + auto& hole = poly.holes.back(); + hole.points.reserve(h.points.size() + 1); if(needreverse) for(auto it = h.points.rbegin(); it != h.points.rend(); ++it) - hole.emplace_back(it->x(), it->y()); + hole.points.emplace_back(it->x(), it->y()); else for(auto& p : h.points) - hole.emplace_back(p.x(), p.y()); + hole.points.emplace_back(p.x(), p.y()); } if(is_lefthanded) { - for(auto& p : poly.Contour) p.X = -p.X; - for(auto& h : poly.Holes) for(auto& p : h) p.X = -p.X; + for(auto& p : poly.contour) p.x() = -p.x(); + for(auto& h : poly.holes) for(auto& p : h) p.x() = -p.x(); } - sl::rotate(poly, double(instances[i].rotation)); - sl::translate(poly, ClipperPoint{instances[i].shift.x(), - instances[i].shift.y()}); + poly.rotate(double(instances[i].rotation)); + poly.translate(Point{instances[i].shift.x(), instances[i].shift.y()}); polygons.emplace_back(std::move(poly)); } @@ -878,9 +868,6 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { print_statistics.clear(); - // libnest calculates positive area for clockwise polygons, Slic3r is in counter-clockwise - auto areafn = [](const ClipperPolygon& poly) { return - libnest2d::sl::area(poly); }; - const double area_fill = printer_config.area_fill.getFloat()*0.01;// 0.5 (50%); const double fast_tilt = printer_config.fast_tilt_time.getFloat();// 5.0; const double slow_tilt = printer_config.slow_tilt_time.getFloat();// 8.0; @@ -913,7 +900,7 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { // Going to parallel: auto printlayerfn = [this, // functions and read only vars - areafn, area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time, + area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time, // write vars &mutex, &models_volume, &supports_volume, &estim_time, &slow_layers, @@ -931,8 +918,8 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { // Calculation of the consumed material - ClipperPolygons model_polygons; - ClipperPolygons supports_polygons; + ExPolygons model_polygons; + ExPolygons supports_polygons; size_t c = std::accumulate(layer.slices().begin(), layer.slices().end(), @@ -954,44 +941,44 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { for(const SliceRecord& record : layer.slices()) { - ClipperPolygons modelslices = get_all_polygons(record, soModel); - for(ClipperPolygon& p_tmp : modelslices) model_polygons.emplace_back(std::move(p_tmp)); + ExPolygons modelslices = get_all_polygons(record, soModel); + for(ExPolygon& p_tmp : modelslices) model_polygons.emplace_back(std::move(p_tmp)); - ClipperPolygons supportslices = get_all_polygons(record, soSupport); - for(ClipperPolygon& p_tmp : supportslices) supports_polygons.emplace_back(std::move(p_tmp)); + ExPolygons supportslices = get_all_polygons(record, soSupport); + for(ExPolygon& p_tmp : supportslices) supports_polygons.emplace_back(std::move(p_tmp)); } - model_polygons = polyunion(model_polygons); + model_polygons = union_ex(model_polygons); double layer_model_area = 0; - for (const ClipperPolygon& polygon : model_polygons) - layer_model_area += areafn(polygon); + for (const ExPolygon& polygon : model_polygons) + layer_model_area += area(polygon); if (layer_model_area < 0 || layer_model_area > 0) { Lock lck(mutex); models_volume += layer_model_area * l_height; } if(!supports_polygons.empty()) { - if(model_polygons.empty()) supports_polygons = polyunion(supports_polygons); - else supports_polygons = polydiff(supports_polygons, model_polygons); + if(model_polygons.empty()) supports_polygons = union_ex(supports_polygons); + else supports_polygons = diff_ex(supports_polygons, model_polygons); // allegedly, union of subject is done withing the diff according to the pftPositive polyFillType } double layer_support_area = 0; - for (const ClipperPolygon& polygon : supports_polygons) - layer_support_area += areafn(polygon); + for (const ExPolygon& polygon : supports_polygons) + layer_support_area += area(polygon); if (layer_support_area < 0 || layer_support_area > 0) { Lock lck(mutex); supports_volume += layer_support_area * l_height; } // Here we can save the expensively calculated polygons for printing - ClipperPolygons trslices; + ExPolygons trslices; trslices.reserve(model_polygons.size() + supports_polygons.size()); - for(ClipperPolygon& poly : model_polygons) trslices.emplace_back(std::move(poly)); - for(ClipperPolygon& poly : supports_polygons) trslices.emplace_back(std::move(poly)); + for(ExPolygon& poly : model_polygons) trslices.emplace_back(std::move(poly)); + for(ExPolygon& poly : supports_polygons) trslices.emplace_back(std::move(poly)); - layer.transformed_slices(polyunion(trslices)); + layer.transformed_slices(union_ex(trslices)); // Calculation of the slow and fast layers to the future controlling those values on FW @@ -1074,7 +1061,7 @@ void SLAPrint::Steps::rasterize() PrintLayer& printlayer = m_print->m_printer_input[idx]; if(canceled()) return; - for (const ClipperLib::Polygon& poly : printlayer.transformed_slices()) + for (const ExPolygon& poly : printlayer.transformed_slices()) raster.draw(poly); // Status indication guarded with the spinlock @@ -1093,7 +1080,8 @@ void SLAPrint::Steps::rasterize() if(canceled()) return; // Print all the layers in parallel - m_print->m_printer->draw_layers(m_print->m_printer_input.size(), lvlfn); + m_print->m_printer->draw_layers(m_print->m_printer_input.size(), lvlfn, + [this]() { return canceled(); }, ex_tbb); } std::string SLAPrint::Steps::label(SLAPrintObjectStep step) diff --git a/src/libslic3r/SVG.cpp b/src/libslic3r/SVG.cpp index 7308d7e50c..6bc334eecf 100644 --- a/src/libslic3r/SVG.cpp +++ b/src/libslic3r/SVG.cpp @@ -273,8 +273,8 @@ std::string SVG::get_path_d(const ClipperLib::Path &path, double scale, bool clo std::ostringstream d; d << "M "; for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) { - d << to_svg_x(scale * p->X - origin(0)) << " "; - d << to_svg_y(scale * p->Y - origin(1)) << " "; + d << to_svg_x(scale * p->x() - origin(0)) << " "; + d << to_svg_y(scale * p->y() - origin(1)) << " "; } if (closed) d << "z"; return d.str(); diff --git a/src/libslic3r/Slicing.cpp b/src/libslic3r/Slicing.cpp index d0b1e9ce26..82b3cf1b66 100644 --- a/src/libslic3r/Slicing.cpp +++ b/src/libslic3r/Slicing.cpp @@ -64,9 +64,9 @@ SlicingParameters SlicingParameters::create_from_config( coordf_t object_height, const std::vector &object_extruders) { - coordf_t first_layer_height = (object_config.first_layer_height.value <= 0) ? - object_config.layer_height.value : - object_config.first_layer_height.get_abs_value(object_config.layer_height.value); + assert(! print_config.first_layer_height.percent); + coordf_t first_layer_height = (print_config.first_layer_height.value <= 0) ? + object_config.layer_height.value : print_config.first_layer_height.value; // If object_config.support_material_extruder == 0 resp. object_config.support_material_interface_extruder == 0, // print_config.nozzle_diameter.get_at(size_t(-1)) returns the 0th nozzle diameter, // which is consistent with the requirement that if support_material_extruder == 0 resp. support_material_interface_extruder == 0, diff --git a/src/libslic3r/SupportMaterial.cpp b/src/libslic3r/SupportMaterial.cpp index bfd879e523..b4f5fefae2 100644 --- a/src/libslic3r/SupportMaterial.cpp +++ b/src/libslic3r/SupportMaterial.cpp @@ -672,6 +672,7 @@ struct SupportGridParams { grid_resolution(object_config.support_material_spacing.value + support_material_flow.spacing()), support_angle(Geometry::deg2rad(object_config.support_material_angle.value)), extrusion_width(support_material_flow.spacing()), + support_material_closing_radius(object_config.support_material_closing_radius.value), expansion_to_slice(coord_t(support_material_flow.scaled_spacing() / 2 + 5)), expansion_to_propagate(-3) {} @@ -679,6 +680,7 @@ struct SupportGridParams { double grid_resolution; double support_angle; double extrusion_width; + double support_material_closing_radius; coord_t expansion_to_slice; coord_t expansion_to_propagate; }; @@ -694,7 +696,9 @@ public: const SupportGridParams ¶ms) : m_style(params.style), m_support_polygons(support_polygons), m_trimming_polygons(trimming_polygons), - m_support_spacing(params.grid_resolution), m_support_angle(params.support_angle) + m_support_spacing(params.grid_resolution), m_support_angle(params.support_angle), + m_extrusion_width(params.extrusion_width), + m_support_material_closing_radius(params.support_material_closing_radius) { switch (m_style) { case smsGrid: @@ -811,7 +815,7 @@ public: // Expanding, thus m_support_polygons are all inside islands. union_ex(*m_support_polygons) : // Shrinking, thus m_support_polygons may be trimmed a tiny bit by islands. - intersection_ex(*m_support_polygons, to_polygons(islands))); + intersection_ex(*m_support_polygons, islands)); std::vector> samples_inside; for (ExPolygon &island : islands) { @@ -878,9 +882,10 @@ public: return out; } case smsSnug: - // Just close the gaps. - float thr = scaled(0.5); - return smooth_outward(offset(offset_ex(*m_support_polygons, thr), - thr), thr); + // Merge the support polygons by applying morphological closing and inwards smoothing. + auto closing_distance = scaled(m_support_material_closing_radius); + auto smoothing_distance = scaled(m_extrusion_width); + return smooth_outward(offset(offset_ex(*m_support_polygons, closing_distance), - closing_distance), smoothing_distance); } assert(false); return Polygons(); @@ -927,7 +932,7 @@ public: } // Deserialization constructor - bool deserialize_(const std::string &path, int which = -1) + bool deserialize_(const std::string &path, int which = -1) { FILE *file = ::fopen(path.c_str(), "rb"); if (file == nullptr) @@ -956,7 +961,7 @@ public: poly.points.emplace_back(Point(x * scale, y * scale)); } if (which == -1 || which == i) - m_support_polygons_deserialized.emplace_back(std::move(poly)); + m_support_polygons_deserialized.emplace_back(std::move(poly)); printf("Polygon %d, area: %lf\n", i, area(poly.points)); } ::fread(&n_polygons, 4, 1, file); @@ -979,14 +984,14 @@ public: m_support_polygons_deserialized = simplify_polygons(m_support_polygons_deserialized, false); //m_support_polygons_deserialized = to_polygons(union_ex(m_support_polygons_deserialized, false)); - // Create an EdgeGrid, initialize it with projection, initialize signed distance field. - coord_t grid_resolution = coord_t(scale_(m_support_spacing)); - BoundingBox bbox = get_extents(*m_support_polygons); + // Create an EdgeGrid, initialize it with projection, initialize signed distance field. + coord_t grid_resolution = coord_t(scale_(m_support_spacing)); + BoundingBox bbox = get_extents(*m_support_polygons); bbox.offset(20); - bbox.align_to_grid(grid_resolution); - m_grid.set_bbox(bbox); - m_grid.create(*m_support_polygons, grid_resolution); - m_grid.calculate_sdf(); + bbox.align_to_grid(grid_resolution); + m_grid.set_bbox(bbox); + m_grid.create(*m_support_polygons, grid_resolution); + m_grid.calculate_sdf(); return true; } @@ -1128,6 +1133,9 @@ private: coordf_t m_support_angle; // X spacing of the support lines parallel with the Y axis. coordf_t m_support_spacing; + coordf_t m_extrusion_width; + // For snug supports: Morphological closing of support areas. + coordf_t m_support_material_closing_radius; #ifdef SUPPORT_USE_AGG_RASTERIZER Vec2i m_grid_size; @@ -1277,7 +1285,7 @@ namespace SupportMaterialInternal { // Is the straight perimeter segment supported at both sides? Point pts[2] = { polyline.first_point(), polyline.last_point() }; bool supported[2] = { false, false }; - for (size_t i = 0; i < lower_layer.lslices.size() && ! (supported[0] && supported[1]); ++ i) + for (size_t i = 0; i < lower_layer.lslices.size() && ! (supported[0] && supported[1]); ++ i) for (int j = 0; j < 2; ++ j) if (! supported[j] && lower_layer.lslices_bboxes[i].contains(pts[j]) && lower_layer.lslices[i].contains(pts[j])) supported[j] = true; @@ -1429,7 +1437,7 @@ static inline std::tuple detect_overhangs( 0.5f * fw); // Overhang polygons for this layer and region. Polygons diff_polygons; - Polygons layerm_polygons = to_polygons(layerm->slices); + Polygons layerm_polygons = to_polygons(layerm->slices.surfaces); if (lower_layer_offset == 0.f) { // Support everything. diff_polygons = diff(layerm_polygons, lower_layer_polygons); @@ -1461,13 +1469,13 @@ static inline std::tuple detect_overhangs( diff_polygons = diff(diff_polygons, annotations.buildplate_covered[layer_id]); } if (! diff_polygons.empty()) { - // Offset the support regions back to a full overhang, restrict them to the full overhang. - // This is done to increase size of the supporting columns below, as they are calculated by - // propagating these contact surfaces downwards. - diff_polygons = diff( - intersection(offset(diff_polygons, lower_layer_offset, SUPPORT_SURFACES_OFFSET_PARAMETERS), layerm_polygons), - lower_layer_polygons); - } + // Offset the support regions back to a full overhang, restrict them to the full overhang. + // This is done to increase size of the supporting columns below, as they are calculated by + // propagating these contact surfaces downwards. + diff_polygons = diff( + intersection(offset(diff_polygons, lower_layer_offset, SUPPORT_SURFACES_OFFSET_PARAMETERS), layerm_polygons), + lower_layer_polygons); + } } } @@ -1481,7 +1489,7 @@ static inline std::tuple detect_overhangs( // Subtracting them as they are may leave unwanted narrow // residues of diff_polygons that would then be supported. diff_polygons = diff(diff_polygons, - offset(union_(to_polygons(std::move(annotations.blockers_layers[layer_id]))), float(1000.*SCALED_EPSILON))); + offset(union_(annotations.blockers_layers[layer_id]), float(1000.*SCALED_EPSILON))); } #ifdef SLIC3R_DEBUG @@ -1530,7 +1538,7 @@ static inline std::tuple detect_overhangs( slices_margin.offset = slices_margin_offset; slices_margin.polygons = (slices_margin_offset == 0.f) ? lower_layer_polygons : - offset2(to_polygons(lower_layer.lslices), - no_interface_offset * 0.5f, slices_margin_offset + no_interface_offset * 0.5f, SUPPORT_SURFACES_OFFSET_PARAMETERS); + offset2(lower_layer.lslices, - no_interface_offset * 0.5f, slices_margin_offset + no_interface_offset * 0.5f, SUPPORT_SURFACES_OFFSET_PARAMETERS); if (buildplate_only && ! annotations.buildplate_covered[layer_id].empty()) { if (has_enforcer) // Make a backup of trimming polygons before enforcing "on build plate only". @@ -1561,9 +1569,9 @@ static inline std::tuple detect_overhangs( if (has_enforcer) { // Enforce supports (as if with 90 degrees of slope) for the regions covered by the enforcer meshes. #ifdef SLIC3R_DEBUG - ExPolygons enforcers_united = union_ex(to_polygons(annotations.enforcers_layers[layer_id]), false); + ExPolygons enforcers_united = union_ex(annotations.enforcers_layers[layer_id]); #endif // SLIC3R_DEBUG - enforcer_polygons = diff(intersection(to_polygons(layer.lslices), to_polygons(std::move(annotations.enforcers_layers[layer_id]))), + enforcer_polygons = diff(intersection(layer.lslices, annotations.enforcers_layers[layer_id]), // Inflate just a tiny bit to avoid intersection of the overhang areas with the object. offset(lower_layer_polygons, 0.05f * fw, SUPPORT_SURFACES_OFFSET_PARAMETERS)); #ifdef SLIC3R_DEBUG @@ -1607,7 +1615,7 @@ static inline std::pairheight; bottom_z = (layer_id == 1) ? slicing_params.object_print_z_min : layer.lower_layer->lower_layer->print_z; } else { - print_z = layer.bottom_z() - slicing_params.gap_object_support; + print_z = layer.bottom_z() - slicing_params.gap_support_object; bottom_z = print_z; height = 0.; // Ignore this contact area if it's too low. @@ -2764,8 +2772,7 @@ void PrintObjectSupportMaterial::trim_support_layers_by_object( break; some_region_overlaps = true; polygons_append(polygons_trimming, - offset(to_expolygons(region->fill_surfaces.filter_by_type(stBottomBridge)), - gap_xy_scaled, SUPPORT_SURFACES_OFFSET_PARAMETERS)); + offset(region->fill_surfaces.filter_by_type(stBottomBridge), gap_xy_scaled, SUPPORT_SURFACES_OFFSET_PARAMETERS)); if (region->region()->config().overhangs.value) // Add bridging perimeters. SupportMaterialInternal::collect_bridging_perimeter_areas(region->perimeters, gap_xy_scaled, polygons_trimming); @@ -2898,9 +2905,9 @@ PrintObjectSupportMaterial::MyLayersPtr PrintObjectSupportMaterial::generate_raf //FIXME misusing contact_polygons for support columns. new_layer.contact_polygons = std::make_unique(columns); } - } else if (columns_base != nullptr) { + } else { + if (columns_base != nullptr) { // Expand the bases of the support columns in the 1st layer. - { Polygons &raft = columns_base->polygons; Polygons trimming = offset(m_object->layers().front()->lslices, (float)scale_(m_support_params.gap_xy), SUPPORT_SURFACES_OFFSET_PARAMETERS); if (inflate_factor_1st_layer > SCALED_EPSILON) { @@ -2911,11 +2918,12 @@ PrintObjectSupportMaterial::MyLayersPtr PrintObjectSupportMaterial::generate_raf raft = diff(offset(raft, step), trimming); } else raft = diff(raft, trimming); + if (contacts != nullptr) + columns_base->polygons = diff(columns_base->polygons, interface_polygons); } - if (contacts != nullptr) - columns_base->polygons = diff(columns_base->polygons, interface_polygons); if (! brim.empty()) { - columns_base->polygons = diff(columns_base->polygons, brim); + if (columns_base) + columns_base->polygons = diff(columns_base->polygons, brim); if (contacts) contacts->polygons = diff(contacts->polygons, brim); if (interfaces) @@ -3084,8 +3092,8 @@ static inline void fill_expolygon_generate_paths( Polylines polylines; try { polylines = filler->fill_surface(&surface, fill_params); - } catch (InfillFailedException &) { - } + } catch (InfillFailedException &) { + } extrusion_entities_append_paths( dst, std::move(polylines), @@ -3166,7 +3174,7 @@ static inline void fill_expolygons_with_sheath_generate_paths( extrusion_entities_append_paths(out, polylines, erSupportMaterial, flow.mm3_per_mm(), flow.width(), flow.height()); // Fill in the rest. fill_expolygons_generate_paths(out, offset_ex(expoly, float(-0.4 * spacing)), filler, fill_params, density, role, flow); - if (no_sort) + if (no_sort && ! eec->empty()) dst.emplace_back(eec.release()); } } @@ -3174,8 +3182,13 @@ static inline void fill_expolygons_with_sheath_generate_paths( // Support layers, partially processed. struct MyLayerExtruded { - MyLayerExtruded() : layer(nullptr), m_polygons_to_extrude(nullptr) {} - ~MyLayerExtruded() { delete m_polygons_to_extrude; m_polygons_to_extrude = nullptr; } + MyLayerExtruded& operator=(MyLayerExtruded &&rhs) { + this->layer = rhs.layer; + this->extrusions = std::move(rhs.extrusions); + this->m_polygons_to_extrude = std::move(rhs.m_polygons_to_extrude); + rhs.layer = nullptr; + return *this; + } bool empty() const { return layer == nullptr || layer->polygons.empty(); @@ -3183,7 +3196,7 @@ struct MyLayerExtruded void set_polygons_to_extrude(Polygons &&polygons) { if (m_polygons_to_extrude == nullptr) - m_polygons_to_extrude = new Polygons(std::move(polygons)); + m_polygons_to_extrude = std::make_unique(std::move(polygons)); else *m_polygons_to_extrude = std::move(polygons); } @@ -3204,12 +3217,11 @@ struct MyLayerExtruded if (m_polygons_to_extrude == nullptr) { // This layer has no extrusions generated yet, if it has no m_polygons_to_extrude (its area to extrude was not reduced yet). assert(this->extrusions.empty()); - m_polygons_to_extrude = new Polygons(this->layer->polygons); + m_polygons_to_extrude = std::make_unique(this->layer->polygons); } Slic3r::polygons_append(*m_polygons_to_extrude, std::move(*other.m_polygons_to_extrude)); *m_polygons_to_extrude = union_(*m_polygons_to_extrude, true); - delete other.m_polygons_to_extrude; - other.m_polygons_to_extrude = nullptr; + other.m_polygons_to_extrude.reset(); } else if (m_polygons_to_extrude != nullptr) { assert(other.m_polygons_to_extrude == nullptr); // The other layer has no extrusions generated yet, if it has no m_polygons_to_extrude (its area to extrude was not reduced yet). @@ -3232,12 +3244,14 @@ struct MyLayerExtruded } // The source layer. It carries the height and extrusion type (bridging / non bridging, extrusion height). - PrintObjectSupportMaterial::MyLayer *layer; + PrintObjectSupportMaterial::MyLayer *layer { nullptr }; // Collect extrusions. They will be exported sorted by the bottom height. ExtrusionEntitiesPtr extrusions; + +private: // In case the extrusions are non-empty, m_polygons_to_extrude may contain the rest areas yet to be filled by additional support. // This is useful mainly for the loop interfaces, which are generated before the zig-zag infills. - Polygons *m_polygons_to_extrude; + std::unique_ptr m_polygons_to_extrude; }; typedef std::vector MyLayerExtrudedPtrs; @@ -3763,7 +3777,7 @@ void PrintObjectSupportMaterial::generate_toolpaths( // Prepare fillers. SupportMaterialPattern support_pattern = m_object_config->support_material_pattern; bool with_sheath = m_object_config->support_material_with_sheath; - InfillPattern infill_pattern = (support_pattern == smpHoneycomb ? ipHoneycomb : ipRectilinear); + InfillPattern infill_pattern = (support_pattern == smpHoneycomb ? ipHoneycomb : ipSupportBase); std::vector angles; angles.push_back(base_angle); @@ -3900,7 +3914,7 @@ void PrintObjectSupportMaterial::generate_toolpaths( std::stable_sort(this->nonempty.begin(), this->nonempty.end(), [](const LayerCacheItem &lc1, const LayerCacheItem &lc2) { return lc1.layer_extruded->layer->height > lc2.layer_extruded->layer->height; }); } }; - std::vector layer_caches(support_layers.size(), LayerCache()); + std::vector layer_caches(support_layers.size()); const auto fill_type_interface = @@ -4152,6 +4166,27 @@ void PrintObjectSupportMaterial::generate_toolpaths( } } }); + +#ifndef NDEBUG + struct Test { + static bool verify_nonempty(const ExtrusionEntityCollection *collection) { + for (const ExtrusionEntity *ee : collection->entities) { + if (const ExtrusionPath *path = dynamic_cast(ee)) + assert(! path->empty()); + else if (const ExtrusionMultiPath *multipath = dynamic_cast(ee)) + assert(! multipath->empty()); + else if (const ExtrusionEntityCollection *eecol = dynamic_cast(ee)) { + assert(! eecol->empty()); + return verify_nonempty(eecol); + } else + assert(false); + } + return true; + } + }; + for (const SupportLayer *support_layer : support_layers) + assert(Test::verify_nonempty(&support_layer->support_fills)); +#endif // NDEBUG } /* diff --git a/src/libslic3r/Surface.hpp b/src/libslic3r/Surface.hpp index fbebe56102..4920efbbfd 100644 --- a/src/libslic3r/Surface.hpp +++ b/src/libslic3r/Surface.hpp @@ -90,7 +90,6 @@ public: return *this; } - operator Polygons() const { return this->expolygon; } double area() const { return this->expolygon.area(); } bool empty() const { return expolygon.empty(); } void clear() { expolygon.clear(); } @@ -107,6 +106,16 @@ public: typedef std::vector Surfaces; typedef std::vector SurfacesPtr; +inline Polygons to_polygons(const Surface &surface) +{ + return to_polygons(surface.expolygon); +} + +inline Polygons to_polygons(Surface &&surface) +{ + return to_polygons(std::move(surface.expolygon)); +} + inline Polygons to_polygons(const Surfaces &src) { size_t num = 0; diff --git a/src/libslic3r/SurfaceCollection.cpp b/src/libslic3r/SurfaceCollection.cpp index 6db5993067..ec847d2a3f 100644 --- a/src/libslic3r/SurfaceCollection.cpp +++ b/src/libslic3r/SurfaceCollection.cpp @@ -6,18 +6,7 @@ namespace Slic3r { -SurfaceCollection::operator Polygons() const -{ - return to_polygons(surfaces); -} - -SurfaceCollection::operator ExPolygons() const -{ - return to_expolygons(surfaces); -} - -void -SurfaceCollection::simplify(double tolerance) +void SurfaceCollection::simplify(double tolerance) { Surfaces ss; for (Surfaces::const_iterator it_s = this->surfaces.begin(); it_s != this->surfaces.end(); ++it_s) { @@ -33,8 +22,7 @@ SurfaceCollection::simplify(double tolerance) } /* group surfaces by common properties */ -void -SurfaceCollection::group(std::vector *retval) +void SurfaceCollection::group(std::vector *retval) { for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) { // find a group with the same properties @@ -54,8 +42,7 @@ SurfaceCollection::group(std::vector *retval) } } -SurfacesPtr -SurfaceCollection::filter_by_type(const SurfaceType type) +SurfacesPtr SurfaceCollection::filter_by_type(const SurfaceType type) { SurfacesPtr ss; for (Surfaces::iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { @@ -64,8 +51,7 @@ SurfaceCollection::filter_by_type(const SurfaceType type) return ss; } -SurfacesPtr -SurfaceCollection::filter_by_types(const SurfaceType *types, int ntypes) +SurfacesPtr SurfaceCollection::filter_by_types(const SurfaceType *types, int ntypes) { SurfacesPtr ss; for (Surfaces::iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { @@ -79,8 +65,7 @@ SurfaceCollection::filter_by_types(const SurfaceType *types, int ntypes) return ss; } -void -SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons) +void SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons) { for (Surfaces::iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) { if (surface->surface_type == type) { @@ -90,8 +75,7 @@ SurfaceCollection::filter_by_type(SurfaceType type, Polygons* polygons) } } -void -SurfaceCollection::keep_type(const SurfaceType type) +void SurfaceCollection::keep_type(const SurfaceType type) { size_t j = 0; for (size_t i = 0; i < surfaces.size(); ++ i) { @@ -105,8 +89,7 @@ SurfaceCollection::keep_type(const SurfaceType type) surfaces.erase(surfaces.begin() + j, surfaces.end()); } -void -SurfaceCollection::keep_types(const SurfaceType *types, int ntypes) +void SurfaceCollection::keep_types(const SurfaceType *types, int ntypes) { size_t j = 0; for (size_t i = 0; i < surfaces.size(); ++ i) { @@ -127,8 +110,7 @@ SurfaceCollection::keep_types(const SurfaceType *types, int ntypes) surfaces.erase(surfaces.begin() + j, surfaces.end()); } -void -SurfaceCollection::remove_type(const SurfaceType type) +void SurfaceCollection::remove_type(const SurfaceType type) { size_t j = 0; for (size_t i = 0; i < surfaces.size(); ++ i) { @@ -142,8 +124,7 @@ SurfaceCollection::remove_type(const SurfaceType type) surfaces.erase(surfaces.begin() + j, surfaces.end()); } -void -SurfaceCollection::remove_types(const SurfaceType *types, int ntypes) +void SurfaceCollection::remove_types(const SurfaceType *types, int ntypes) { size_t j = 0; for (size_t i = 0; i < surfaces.size(); ++ i) { diff --git a/src/libslic3r/SurfaceCollection.hpp b/src/libslic3r/SurfaceCollection.hpp index 9f0324d20a..7e01a68dfb 100644 --- a/src/libslic3r/SurfaceCollection.hpp +++ b/src/libslic3r/SurfaceCollection.hpp @@ -12,11 +12,10 @@ class SurfaceCollection public: Surfaces surfaces; - SurfaceCollection() {}; - SurfaceCollection(const Surfaces &surfaces) : surfaces(surfaces) {}; + SurfaceCollection() = default; + SurfaceCollection(const Surfaces& surfaces) : surfaces(surfaces) {}; SurfaceCollection(Surfaces &&surfaces) : surfaces(std::move(surfaces)) {}; - operator Polygons() const; - operator ExPolygons() const; + void simplify(double tolerance); void group(std::vector *retval); template bool any_internal_contains(const T &item) const { diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index a74ff55ae5..efb7ab4861 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -57,6 +57,12 @@ #define ENABLE_GCODE_WINDOW (1 && ENABLE_2_4_0_ALPHA0) // Enable exporting lines M73 for remaining time to next printer stop to gcode #define ENABLE_EXTENDED_M73_LINES (1 && ENABLE_VALIDATE_CUSTOM_GCODE) +// Enable a modified version of automatic downscale on load of objects too big +#define ENABLE_MODIFIED_DOWNSCALE_ON_LOAD_OBJECTS_TOO_BIG (1 && ENABLE_2_4_0_ALPHA0) +// Enable visualization of start gcode as regular toolpaths +#define ENABLE_START_GCODE_VISUALIZATION (1 && ENABLE_2_4_0_ALPHA0) +// Enable visualization of seams in preview +#define ENABLE_SEAMS_VISUALIZATION (1 && ENABLE_2_4_0_ALPHA0) // Enable project dirty state manager #define ENABLE_PROJECT_DIRTY_STATE (1 && ENABLE_2_4_0_ALPHA0) diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index d5a3490877..7b5c40466e 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -357,10 +357,14 @@ void TriangleMesh::transform(const Transform3d& t, bool fix_left_handed) its_transform(its, t); if (fix_left_handed && t.matrix().block(0, 0, 3, 3).determinant() < 0.) { // Left handed transformation is being applied. It is a good idea to flip the faces and their normals. - this->repair(false); - stl_reverse_all_facets(&stl); - this->its.clear(); - this->require_shared_vertices(); + // As for the assert: the repair function would fix the normals, reversing would + // break them again. The caller should provide a mesh that does not need repair. + // The repair call is left here so things don't break more than they were. + assert(this->repaired); + this->repair(false); + stl_reverse_all_facets(&stl); + this->its.clear(); + this->require_shared_vertices(); } } @@ -369,11 +373,12 @@ void TriangleMesh::transform(const Matrix3d& m, bool fix_left_handed) stl_transform(&stl, m); its_transform(its, m); if (fix_left_handed && m.determinant() < 0.) { - // Left handed transformation is being applied. It is a good idea to flip the faces and their normals. + // See comments in function above. + assert(this->repaired); this->repair(false); stl_reverse_all_facets(&stl); - this->its.clear(); - this->require_shared_vertices(); + this->its.clear(); + this->require_shared_vertices(); } } @@ -511,20 +516,22 @@ void TriangleMesh::merge(const TriangleMesh &mesh) //FIXME This could be extremely slow! Use it for tiny meshes only! ExPolygons TriangleMesh::horizontal_projection() const { - Polygons pp; - pp.reserve(this->stl.stats.number_of_facets); + ClipperLib::Paths paths; + Polygon p; + p.points.assign(3, Point()); + auto delta = scaled(0.01); + std::vector deltas { delta, delta, delta }; + paths.reserve(this->stl.stats.number_of_facets); for (const stl_facet &facet : this->stl.facet_start) { - Polygon p; - p.points.resize(3); p.points[0] = Point::new_scale(facet.vertex[0](0), facet.vertex[0](1)); p.points[1] = Point::new_scale(facet.vertex[1](0), facet.vertex[1](1)); p.points[2] = Point::new_scale(facet.vertex[2](0), facet.vertex[2](1)); - p.make_counter_clockwise(); // do this after scaling, as winding order might change while doing that - pp.emplace_back(p); + p.make_counter_clockwise(); + paths.emplace_back(mittered_offset_path_scaled(p.points, deltas, 3.)); } // the offset factor was tuned using groovemount.stl - return union_ex(offset(pp, scale_(0.01)), true); + return ClipperPaths_to_Slic3rExPolygons(paths); } // 2D convex hull of a 3D mesh projected into the Z=0 plane. @@ -1797,9 +1804,9 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, const float clos // append to the supplied collection if (safety_offset > 0) - expolygons_append(*slices, offset2_ex(union_(loops, false), +safety_offset, -safety_offset)); + expolygons_append(*slices, offset2_ex(union_ex(loops), +safety_offset, -safety_offset)); else - expolygons_append(*slices, union_ex(loops, false)); + expolygons_append(*slices, union_ex(loops)); } void TriangleMeshSlicer::make_expolygons(std::vector &lines, const float closing_radius, ExPolygons* slices) const diff --git a/src/libslic3r/clipper.cpp b/src/libslic3r/clipper.cpp new file mode 100644 index 0000000000..8f38ba6215 --- /dev/null +++ b/src/libslic3r/clipper.cpp @@ -0,0 +1,13 @@ +// Hackish wrapper around the ClipperLib library to compile the Clipper library using Slic3r::Point. + +#include "clipper.hpp" + +// Don't include for the second time. +#define clipper_hpp + +// Override ClipperLib namespace to Slic3r::ClipperLib +#define CLIPPERLIB_NAMESPACE_PREFIX Slic3r +// Override Slic3r::ClipperLib::IntPoint to Slic3r::Point +#define CLIPPERLIB_INTPOINT_TYPE Slic3r::Point + +#include diff --git a/src/libslic3r/clipper.hpp b/src/libslic3r/clipper.hpp new file mode 100644 index 0000000000..b0dd51a4f7 --- /dev/null +++ b/src/libslic3r/clipper.hpp @@ -0,0 +1,26 @@ +// Hackish wrapper around the ClipperLib library to compile the Clipper library using Slic3r's own Point type. + +#ifndef slic3r_clipper_hpp + +#ifdef clipper_hpp +#error "You should include the libslic3r/clipper.hpp before clipper/clipper.hpp" +#endif + +#ifdef CLIPPERLIB_USE_XYZ +#error "Something went wrong. Using clipper.hpp with Slic3r Point type, but CLIPPERLIB_USE_XYZ is defined." +#endif + +#define slic3r_clipper_hpp + +#include "Point.hpp" + +#define CLIPPERLIB_NAMESPACE_PREFIX Slic3r +#define CLIPPERLIB_INTPOINT_TYPE Slic3r::Point + +#include + +#undef clipper_hpp +#undef CLIPPERLIB_NAMESPACE_PREFIX +#undef CLIPPERLIB_INTPOINT_TYPE + +#endif // slic3r_clipper_hpp diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index efdecbac8f..2b0c94161d 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -308,6 +308,10 @@ IntegerOnly> reserve_vector(I capacity) return ret; } +// Borrowed from C++20 +template +using remove_cvref_t = std::remove_cv_t>; + } // namespace Slic3r #endif diff --git a/src/libslic3r/pchheader.hpp b/src/libslic3r/pchheader.hpp index 9386fdf369..b55755b892 100644 --- a/src/libslic3r/pchheader.hpp +++ b/src/libslic3r/pchheader.hpp @@ -114,7 +114,7 @@ #include #include -#include +#include "clipper.hpp" #include "BoundingBox.hpp" #include "ClipperUtils.hpp" #include "Config.hpp" @@ -129,8 +129,6 @@ #include "libslic3r.h" #include "libslic3r_version.h" -#include "clipper.hpp" - #include #include diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 74b58b052a..29551ac15d 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -113,7 +113,7 @@ void Bed3D::Axes::render() const glsafe(::glPopMatrix()); }; - m_arrow.init_from(stilized_arrow(16, DefaultTipRadius, DefaultTipLength, DefaultStemRadius, m_stem_length)); + const_cast(&m_arrow)->init_from(stilized_arrow(16, DefaultTipRadius, DefaultTipLength, DefaultStemRadius, m_stem_length)); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) @@ -143,13 +143,6 @@ void Bed3D::Axes::render() const glsafe(::glDisable(GL_DEPTH_TEST)); } -Bed3D::Bed3D() - : m_type(Custom) - , m_vbo_id(0) - , m_scale_factor(1.0f) -{ -} - bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom) { auto check_texture = [](const std::string& texture) { @@ -193,7 +186,7 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, c ExPolygon poly; for (const Vec2d& p : m_shape) { - poly.contour.append(Point(scale_(p(0)), scale_(p(1)))); + poly.contour.append({ scale_(p(0)), scale_(p(1)) }); } calc_triangles(poly); @@ -201,7 +194,7 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, c const BoundingBox& bed_bbox = poly.contour.bounding_box(); calc_gridlines(poly, bed_bbox); - m_polygon = offset_ex(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5))[0].contour; + m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5))[0]; reset(); m_texture.reset(); @@ -228,7 +221,8 @@ Point Bed3D::point_projection(const Point& point) const void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture) const { - m_scale_factor = scale_factor; + float* factor = const_cast(&m_scale_factor); + *factor = scale_factor; if (show_axes) render_axes(); @@ -247,22 +241,24 @@ void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, void Bed3D::calc_bounding_boxes() const { - m_bounding_box = BoundingBoxf3(); + BoundingBoxf3* bounding_box = const_cast(&m_bounding_box); + *bounding_box = BoundingBoxf3(); for (const Vec2d& p : m_shape) { - m_bounding_box.merge(Vec3d(p(0), p(1), 0.0)); + bounding_box->merge({ p(0), p(1), 0.0 }); } - m_extended_bounding_box = m_bounding_box; + BoundingBoxf3* extended_bounding_box = const_cast(&m_extended_bounding_box); + *extended_bounding_box = m_bounding_box; // extend to contain axes - m_extended_bounding_box.merge(m_axes.get_origin() + m_axes.get_total_length() * Vec3d::Ones()); - m_extended_bounding_box.merge(m_extended_bounding_box.min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, m_extended_bounding_box.max(2))); + extended_bounding_box->merge(m_axes.get_origin() + m_axes.get_total_length() * Vec3d::Ones()); + extended_bounding_box->merge(extended_bounding_box->min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, extended_bounding_box->max(2))); // extend to contain model, if any BoundingBoxf3 model_bb = m_model.get_bounding_box(); if (model_bb.defined) { model_bb.translate(m_model_offset); - m_extended_bounding_box.merge(model_bb); + extended_bounding_box->merge(model_bb); } } @@ -339,21 +335,24 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) co void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const { + GLTexture* texture = const_cast(&m_texture); + GLTexture* temp_texture = const_cast(&m_temp_texture); + if (m_texture_filename.empty()) { - m_texture.reset(); + texture->reset(); render_default(bottom); return; } - if ((m_texture.get_id() == 0) || (m_texture.get_source() != m_texture_filename)) { - m_texture.reset(); + if (texture->get_id() == 0 || texture->get_source() != m_texture_filename) { + texture->reset(); if (boost::algorithm::iends_with(m_texture_filename, ".svg")) { // use higher resolution images if graphic card and opengl version allow GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size(); - if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename)) { + if (temp_texture->get_id() == 0 || temp_texture->get_source() != m_texture_filename) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed - if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { + if (!temp_texture->load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { render_default(bottom); return; } @@ -361,15 +360,15 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const } // starts generating the main texture, compression will run asynchronously - if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { + if (!texture->load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { render_default(bottom); return; } } else if (boost::algorithm::iends_with(m_texture_filename, ".png")) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed - if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename)) { - if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { + if (temp_texture->get_id() == 0 || temp_texture->get_source() != m_texture_filename) { + if (!temp_texture->load_from_file(m_texture_filename, false, GLTexture::None, false)) { render_default(bottom); return; } @@ -377,7 +376,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const } // starts generating the main texture, compression will run asynchronously - if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { + if (!texture->load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { render_default(bottom); return; } @@ -387,13 +386,13 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const return; } } - else if (m_texture.unsent_compressed_data_available()) { + else if (texture->unsent_compressed_data_available()) { // sends to gpu the already available compressed levels of the main texture - m_texture.send_compressed_data_to_gpu(); + texture->send_compressed_data_to_gpu(); // the temporary texture is not needed anymore, reset it - if (m_temp_texture.get_id() != 0) - m_temp_texture.reset(); + if (temp_texture->get_id() != 0) + temp_texture->reset(); canvas.request_extra_frame(); @@ -406,9 +405,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const shader->set_uniform("transparent_background", bottom); shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg")); - if (m_vbo_id == 0) { - glsafe(::glGenBuffers(1, &m_vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); + unsigned int* vbo_id = const_cast(&m_vbo_id); + + if (*vbo_id == 0) { + glsafe(::glGenBuffers(1, vbo_id)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id)); glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } @@ -428,12 +429,12 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const GLint tex_coords_id = shader->get_attrib_location("v_tex_coords"); // show the temporary texture while no compressed data is available - GLuint tex_id = (GLuint)m_temp_texture.get_id(); + GLuint tex_id = (GLuint)temp_texture->get_id(); if (tex_id == 0) - tex_id = (GLuint)m_texture.get_id(); + tex_id = (GLuint)texture->get_id(); glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id)); if (position_id != -1) { glsafe(::glEnableVertexAttribArray(position_id)); @@ -471,24 +472,26 @@ void Bed3D::render_model() const if (m_model_filename.empty()) return; - if ((m_model.get_filename() != m_model_filename) && m_model.init_from_file(m_model_filename)) { + GLModel* model = const_cast(&m_model); + + if (model->get_filename() != m_model_filename && model->init_from_file(m_model_filename)) { // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad Vec3d shift = m_bounding_box.center(); shift(2) = -0.03; - m_model_offset = shift; + *const_cast(&m_model_offset) = shift; // update extended bounding box calc_bounding_boxes(); } - if (!m_model.get_filename().empty()) { + if (!model->get_filename().empty()) { GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader != nullptr) { shader->start_using(); shader->set_uniform("uniform_color", m_model_color); ::glPushMatrix(); ::glTranslated(m_model_offset(0), m_model_offset(1), m_model_offset(2)); - m_model.render(); + model->render(); ::glPopMatrix(); shader->stop_using(); } @@ -511,7 +514,7 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture) co void Bed3D::render_default(bool bottom) const { - m_texture.reset(); + const_cast(&m_texture)->reset(); unsigned int triangles_vcount = m_triangles.get_vertices_count(); if (triangles_vcount > 0) { diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index 6266304bee..c2630b7993 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -48,7 +48,7 @@ class Bed3D private: Vec3d m_origin{ Vec3d::Zero() }; float m_stem_length{ DefaultStemLength }; - mutable GLModel m_arrow; + GLModel m_arrow; public: const Vec3d& get_origin() const { return m_origin; } @@ -67,28 +67,28 @@ public: }; private: - EType m_type; + EType m_type{ Custom }; Pointfs m_shape; std::string m_texture_filename; std::string m_model_filename; - mutable BoundingBoxf3 m_bounding_box; - mutable BoundingBoxf3 m_extended_bounding_box; + BoundingBoxf3 m_bounding_box; + BoundingBoxf3 m_extended_bounding_box; Polygon m_polygon; GeometryBuffer m_triangles; GeometryBuffer m_gridlines; - mutable GLTexture m_texture; - mutable GLModel m_model; - mutable Vec3d m_model_offset{ Vec3d::Zero() }; - std::array m_model_color{ 0.235f, 0.235f, 0.235f, 1.0f }; + GLTexture m_texture; // temporary texture shown until the main texture has still no levels compressed - mutable GLTexture m_temp_texture; - mutable unsigned int m_vbo_id; + GLTexture m_temp_texture; + GLModel m_model; + Vec3d m_model_offset{ Vec3d::Zero() }; + std::array m_model_color{ 0.235f, 0.235f, 0.235f, 1.0f }; + unsigned int m_vbo_id{ 0 }; Axes m_axes; - mutable float m_scale_factor; + float m_scale_factor{ 1.0f }; public: - Bed3D(); + Bed3D() = default; ~Bed3D() { reset(); } EType get_type() const { return m_type; } diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 6c226cd74d..ba62576f23 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -421,20 +421,24 @@ const BoundingBoxf3& GLVolume::transformed_bounding_box() const const BoundingBoxf3& box = bounding_box(); assert(box.defined || box.min(0) >= box.max(0) || box.min(1) >= box.max(1) || box.min(2) >= box.max(2)); - if (m_transformed_bounding_box_dirty) - { - m_transformed_bounding_box = box.transformed(world_matrix()); - m_transformed_bounding_box_dirty = false; + BoundingBoxf3* transformed_bounding_box = const_cast(&m_transformed_bounding_box); + bool* transformed_bounding_box_dirty = const_cast(&m_transformed_bounding_box_dirty); + if (*transformed_bounding_box_dirty) { + *transformed_bounding_box = box.transformed(world_matrix()); + *transformed_bounding_box_dirty = false; } - - return m_transformed_bounding_box; + return *transformed_bounding_box; } const BoundingBoxf3& GLVolume::transformed_convex_hull_bounding_box() const { - if (m_transformed_convex_hull_bounding_box_dirty) - m_transformed_convex_hull_bounding_box = this->transformed_convex_hull_bounding_box(world_matrix()); - return m_transformed_convex_hull_bounding_box; + BoundingBoxf3* transformed_convex_hull_bounding_box = const_cast(&m_transformed_convex_hull_bounding_box); + bool* transformed_convex_hull_bounding_box_dirty = const_cast(&m_transformed_convex_hull_bounding_box_dirty); + if (*transformed_convex_hull_bounding_box_dirty) { + *transformed_convex_hull_bounding_box = this->transformed_convex_hull_bounding_box(world_matrix()); + *transformed_convex_hull_bounding_box_dirty = false; + } + return *transformed_convex_hull_bounding_box; } BoundingBoxf3 GLVolume::transformed_convex_hull_bounding_box(const Transform3d &trafo) const @@ -795,7 +799,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glDisable(GL_BLEND)); } -bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, ModelInstanceEPrintVolumeState* out_state) +bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, ModelInstanceEPrintVolumeState* out_state) const { if (config == nullptr) return false; @@ -805,7 +809,7 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M return false; BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - BoundingBoxf3 print_volume(Vec3d(unscale(bed_box_2D.min(0)), unscale(bed_box_2D.min(1)), 0.0), Vec3d(unscale(bed_box_2D.max(0)), unscale(bed_box_2D.max(1)), config->opt_float("max_print_height"))); + BoundingBoxf3 print_volume({ unscale(bed_box_2D.min(0)), unscale(bed_box_2D.min(1)), 0.0 }, { unscale(bed_box_2D.max(0)), unscale(bed_box_2D.max(1)), config->opt_float("max_print_height") }); // Allow the objects to protrude below the print bed print_volume.min(2) = -1e10; print_volume.min(0) -= BedEpsilon; @@ -817,9 +821,8 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M bool contained_min_one = false; - for (GLVolume* volume : this->volumes) - { - if ((volume == nullptr) || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || ((volume->composite_id.volume_id < 0) && !volume->shader_outside_printer_detection_enabled)) + for (GLVolume* volume : this->volumes) { + if (volume == nullptr || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || (volume->composite_id.volume_id < 0 && !volume->shader_outside_printer_detection_enabled)) continue; const BoundingBoxf3& bb = volume->transformed_convex_hull_bounding_box(); @@ -832,10 +835,10 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M if (contained) contained_min_one = true; - if ((state == ModelInstancePVS_Inside) && volume->is_outside) + if (state == ModelInstancePVS_Inside && volume->is_outside) state = ModelInstancePVS_Fully_Outside; - if ((state == ModelInstancePVS_Fully_Outside) && volume->is_outside && print_volume.intersects(bb)) + if (state == ModelInstancePVS_Fully_Outside && volume->is_outside && print_volume.intersects(bb)) state = ModelInstancePVS_Partly_Outside; } @@ -845,7 +848,7 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M return contained_min_one; } -bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut) +bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut) const { if (config == nullptr) return false; @@ -867,9 +870,8 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, b partlyOut = false; fullyOut = false; - for (GLVolume* volume : this->volumes) - { - if ((volume == nullptr) || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || ((volume->composite_id.volume_id < 0) && !volume->shader_outside_printer_detection_enabled)) + for (GLVolume* volume : this->volumes) { + if (volume == nullptr || volume->is_modifier || (volume->is_wipe_tower && !volume->shader_outside_printer_detection_enabled) || (volume->composite_id.volume_id < 0 && !volume->shader_outside_printer_detection_enabled)) continue; const BoundingBoxf3& bb = volume->transformed_convex_hull_bounding_box(); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 2ae2a36b29..25c5443cda 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -267,15 +267,15 @@ private: // Shift in z required by sla supports+pad double m_sla_shift_z; // Bounding box of this volume, in unscaled coordinates. - mutable BoundingBoxf3 m_transformed_bounding_box; + BoundingBoxf3 m_transformed_bounding_box; // Whether or not is needed to recalculate the transformed bounding box. - mutable bool m_transformed_bounding_box_dirty; + bool m_transformed_bounding_box_dirty; // Convex hull of the volume, if any. std::shared_ptr m_convex_hull; // Bounding box of this volume, in unscaled coordinates. - mutable BoundingBoxf3 m_transformed_convex_hull_bounding_box; + BoundingBoxf3 m_transformed_convex_hull_bounding_box; // Whether or not is needed to recalculate the transformed convex hull bounding box. - mutable bool m_transformed_convex_hull_bounding_box_dirty; + bool m_transformed_convex_hull_bounding_box_dirty; public: // Color of the triangles / quads held by this volume. @@ -568,8 +568,8 @@ public: // returns true if all the volumes are completely contained in the print volume // returns the containment state in the given out_state, if non-null - bool check_outside_state(const DynamicPrintConfig* config, ModelInstanceEPrintVolumeState* out_state); - bool check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut); + bool check_outside_state(const DynamicPrintConfig* config, ModelInstanceEPrintVolumeState* out_state) const; + bool check_outside_state(const DynamicPrintConfig* config, bool& partlyOut, bool& fullyOut) const; void reset_outside_state(); void update_colors_by_extruder(const DynamicPrintConfig* config); diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index ade1d40437..d8b80f1ce8 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -21,12 +21,6 @@ double Camera::FrustrumMinNearZ = 100.0; double Camera::FrustrumZMargin = 10.0; double Camera::MaxFovDeg = 60.0; -Camera::Camera() - : requires_zoom_to_bed(false) -{ - set_default_orientation(); -} - std::string Camera::get_type_as_string() const { switch (m_type) @@ -49,11 +43,6 @@ void Camera::set_type(EType type) } } -void Camera::set_type(const std::string& type) -{ - set_type((type == "1") ? Perspective : Ortho); -} - void Camera::select_next_type() { unsigned char next = (unsigned char)m_type + 1; @@ -65,24 +54,18 @@ void Camera::select_next_type() void Camera::set_target(const Vec3d& target) { - Vec3d new_target = validate_target(target); - Vec3d new_displacement = new_target - m_target; - if (!new_displacement.isApprox(Vec3d::Zero())) - { + const Vec3d new_target = validate_target(target); + const Vec3d new_displacement = new_target - m_target; + if (!new_displacement.isApprox(Vec3d::Zero())) { m_target = new_target; m_view_matrix.translate(-new_displacement); } } -void Camera::update_zoom(double delta_zoom) -{ - set_zoom(m_zoom / (1.0 - std::max(std::min(delta_zoom, 4.0), -4.0) * 0.1)); -} - void Camera::set_zoom(double zoom) { // Don't allow to zoom too far outside the scene. - double zoom_min = min_zoom(); + const double zoom_min = min_zoom(); if (zoom_min > 0.0) zoom = std::max(zoom, zoom_min); @@ -123,7 +106,7 @@ double Camera::get_fov() const void Camera::apply_viewport(int x, int y, unsigned int w, unsigned int h) const { glsafe(::glViewport(0, 0, w, h)); - glsafe(::glGetIntegerv(GL_VIEWPORT, m_viewport.data())); + glsafe(::glGetIntegerv(GL_VIEWPORT, const_cast*>(&m_viewport)->data())); } void Camera::apply_view_matrix() const @@ -138,22 +121,23 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa double w = 0.0; double h = 0.0; - double old_distance = m_distance; - m_frustrum_zs = calc_tight_frustrum_zs_around(box); + const double old_distance = m_distance; + std::pair* frustrum_zs = const_cast*>(&m_frustrum_zs); + *frustrum_zs = calc_tight_frustrum_zs_around(box); if (m_distance != old_distance) // the camera has been moved re-apply view matrix apply_view_matrix(); if (near_z > 0.0) - m_frustrum_zs.first = std::max(std::min(m_frustrum_zs.first, near_z), FrustrumMinNearZ); + frustrum_zs->first = std::max(std::min(frustrum_zs->first, near_z), FrustrumMinNearZ); if (far_z > 0.0) - m_frustrum_zs.second = std::max(m_frustrum_zs.second, far_z); + frustrum_zs->second = std::max(frustrum_zs->second, far_z); w = 0.5 * (double)m_viewport[2]; h = 0.5 * (double)m_viewport[3]; - double inv_zoom = get_inv_zoom(); + const double inv_zoom = get_inv_zoom(); w *= inv_zoom; h *= inv_zoom; @@ -162,16 +146,16 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa default: case Ortho: { - m_gui_scale = 1.0; + *const_cast(&m_gui_scale) = 1.0; break; } case Perspective: { // scale near plane to keep w and h constant on the plane at z = m_distance - double scale = m_frustrum_zs.first / m_distance; + const double scale = frustrum_zs->first / m_distance; w *= scale; h *= scale; - m_gui_scale = scale; + *const_cast(&m_gui_scale) = scale; break; } } @@ -184,26 +168,25 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa default: case Ortho: { - glsafe(::glOrtho(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); + glsafe(::glOrtho(-w, w, -h, h, frustrum_zs->first, frustrum_zs->second)); break; } case Perspective: { - glsafe(::glFrustum(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); + glsafe(::glFrustum(-w, w, -h, h, frustrum_zs->first, frustrum_zs->second)); break; } } - glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, m_projection_matrix.data())); + glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, const_cast(&m_projection_matrix)->data())); glsafe(::glMatrixMode(GL_MODELVIEW)); } void Camera::zoom_to_box(const BoundingBoxf3& box, double margin_factor) { // Calculate the zoom factor needed to adjust the view around the given box. - double zoom = calc_zoom_to_bounding_box_factor(box, margin_factor); - if (zoom > 0.0) - { + const double zoom = calc_zoom_to_bounding_box_factor(box, margin_factor); + if (zoom > 0.0) { m_zoom = zoom; // center view around box center set_target(box.center()); @@ -213,9 +196,8 @@ void Camera::zoom_to_box(const BoundingBoxf3& box, double margin_factor) void Camera::zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor) { Vec3d center; - double zoom = calc_zoom_to_volumes_factor(volumes, center, margin_factor); - if (zoom > 0.0) - { + const double zoom = calc_zoom_to_volumes_factor(volumes, center, margin_factor); + if (zoom > 0.0) { m_zoom = zoom; // center view around the calculated center set_target(center); @@ -289,8 +271,8 @@ void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad, b } } - Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target; - auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ()); + const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target; + const auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ()); m_view_rotation *= rot_z * Eigen::AngleAxisd(delta_zenit_rad, rot_z.inverse() * get_dir_right()); m_view_rotation.normalize(); m_view_matrix.fromPositionOrientationScale(m_view_rotation * (- m_target) + translation, m_view_rotation, Vec3d(1., 1., 1.)); @@ -299,10 +281,10 @@ void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad, b // Virtual trackball, rotate around an axis, where the eucledian norm of the axis gives the rotation angle in radians. void Camera::rotate_local_around_target(const Vec3d& rotation_rad) { - double angle = rotation_rad.norm(); + const double angle = rotation_rad.norm(); if (std::abs(angle) > EPSILON) { - Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target; - Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized(); + const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target; + const Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized(); m_view_rotation *= Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis)); m_view_rotation.normalize(); m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-m_target) + translation, m_view_rotation, Vec3d(1., 1., 1.)); @@ -310,18 +292,13 @@ void Camera::rotate_local_around_target(const Vec3d& rotation_rad) } } -double Camera::min_zoom() const -{ - return 0.7 * calc_zoom_to_bounding_box_factor(m_scene_box); -} - std::pair Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const { std::pair ret; auto& [near_z, far_z] = ret; // box in eye space - BoundingBoxf3 eye_box = box.transformed(m_view_matrix); + const BoundingBoxf3 eye_box = box.transformed(m_view_matrix); near_z = -eye_box.max(2); far_z = -eye_box.min(2); @@ -330,73 +307,71 @@ std::pair Camera::calc_tight_frustrum_zs_around(const BoundingBo far_z += FrustrumZMargin; // ensure min size - if (far_z - near_z < FrustrumMinZRange) - { - double mid_z = 0.5 * (near_z + far_z); - double half_size = 0.5 * FrustrumMinZRange; + if (far_z - near_z < FrustrumMinZRange) { + const double mid_z = 0.5 * (near_z + far_z); + const double half_size = 0.5 * FrustrumMinZRange; near_z = mid_z - half_size; far_z = mid_z + half_size; } - if (near_z < FrustrumMinNearZ) - { - float delta = FrustrumMinNearZ - near_z; + if (near_z < FrustrumMinNearZ) { + const double delta = FrustrumMinNearZ - near_z; set_distance(m_distance + delta); near_z += delta; far_z += delta; } - else if ((near_z > 2.0 * FrustrumMinNearZ) && (m_distance > DefaultDistance)) - { - float delta = m_distance - DefaultDistance; - set_distance(DefaultDistance); - near_z -= delta; - far_z -= delta; - } +// The following is commented out because it causes flickering of the 3D scene GUI +// when the bounding box of the scene gets large enough +// We need to introduce some smarter code to move the camera back and forth in such case +// else if (near_z > 2.0 * FrustrumMinNearZ && m_distance > DefaultDistance) { +// float delta = m_distance - DefaultDistance; +// set_distance(DefaultDistance); +// near_z -= delta; +// far_z -= delta; +// } return ret; } double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, double margin_factor) const { - double max_bb_size = box.max_size(); + const double max_bb_size = box.max_size(); if (max_bb_size == 0.0) return -1.0; // project the box vertices on a plane perpendicular to the camera forward axis // then calculates the vertices coordinate on this plane along the camera xy axes - Vec3d right = get_dir_right(); - Vec3d up = get_dir_up(); - Vec3d forward = get_dir_forward(); - - Vec3d bb_center = box.center(); + const Vec3d right = get_dir_right(); + const Vec3d up = get_dir_up(); + const Vec3d forward = get_dir_forward(); + const Vec3d bb_center = box.center(); // box vertices in world space - std::vector vertices; - vertices.reserve(8); - vertices.push_back(box.min); - vertices.emplace_back(box.max(0), box.min(1), box.min(2)); - vertices.emplace_back(box.max(0), box.max(1), box.min(2)); - vertices.emplace_back(box.min(0), box.max(1), box.min(2)); - vertices.emplace_back(box.min(0), box.min(1), box.max(2)); - vertices.emplace_back(box.max(0), box.min(1), box.max(2)); - vertices.push_back(box.max); - vertices.emplace_back(box.min(0), box.max(1), box.max(2)); + const std::vector vertices = { + box.min, + { box.max(0), box.min(1), box.min(2) }, + { box.max(0), box.max(1), box.min(2) }, + { box.min(0), box.max(1), box.min(2) }, + { box.min(0), box.min(1), box.max(2) }, + { box.max(0), box.min(1), box.max(2) }, + box.max, + { box.min(0), box.max(1), box.max(2) } + }; double min_x = DBL_MAX; double min_y = DBL_MAX; double max_x = -DBL_MAX; double max_y = -DBL_MAX; - for (const Vec3d& v : vertices) - { + for (const Vec3d& v : vertices) { // project vertex on the plane perpendicular to camera forward axis - Vec3d pos = v - bb_center; - Vec3d proj_on_plane = pos - pos.dot(forward) * forward; + const Vec3d pos = v - bb_center; + const Vec3d proj_on_plane = pos - pos.dot(forward) * forward; // calculates vertex coordinate along camera xy axes - double x_on_plane = proj_on_plane.dot(right); - double y_on_plane = proj_on_plane.dot(up); + const double x_on_plane = proj_on_plane.dot(right); + const double y_on_plane = proj_on_plane.dot(up); min_x = std::min(min_x, x_on_plane); min_y = std::min(min_y, y_on_plane); @@ -406,7 +381,7 @@ double Camera::calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, double double dx = max_x - min_x; double dy = max_y - min_y; - if ((dx <= 0.0) || (dy <= 0.0)) + if (dx <= 0.0 || dy <= 0.0) return -1.0f; dx *= margin_factor; @@ -423,13 +398,12 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c // project the volumes vertices on a plane perpendicular to the camera forward axis // then calculates the vertices coordinate on this plane along the camera xy axes - Vec3d right = get_dir_right(); - Vec3d up = get_dir_up(); - Vec3d forward = get_dir_forward(); + const Vec3d right = get_dir_right(); + const Vec3d up = get_dir_up(); + const Vec3d forward = get_dir_forward(); BoundingBoxf3 box; - for (const GLVolume* volume : volumes) - { + for (const GLVolume* volume : volumes) { box.merge(volume->transformed_bounding_box()); } center = box.center(); @@ -439,24 +413,22 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c double max_x = -DBL_MAX; double max_y = -DBL_MAX; - for (const GLVolume* volume : volumes) - { + for (const GLVolume* volume : volumes) { const Transform3d& transform = volume->world_matrix(); const TriangleMesh* hull = volume->convex_hull(); if (hull == nullptr) continue; - for (const Vec3f& vertex : hull->its.vertices) - { - Vec3d v = transform * vertex.cast(); + for (const Vec3f& vertex : hull->its.vertices) { + const Vec3d v = transform * vertex.cast(); // project vertex on the plane perpendicular to camera forward axis - Vec3d pos = v - center; - Vec3d proj_on_plane = pos - pos.dot(forward) * forward; + const Vec3d pos = v - center; + const Vec3d proj_on_plane = pos - pos.dot(forward) * forward; // calculates vertex coordinate along camera xy axes - double x_on_plane = proj_on_plane.dot(right); - double y_on_plane = proj_on_plane.dot(up); + const double x_on_plane = proj_on_plane.dot(right); + const double y_on_plane = proj_on_plane.dot(up); min_x = std::min(min_x, x_on_plane); min_y = std::min(min_y, y_on_plane); @@ -467,10 +439,10 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c center += 0.5 * (max_x + min_x) * right + 0.5 * (max_y + min_y) * up; - double dx = margin_factor * (max_x - min_x); - double dy = margin_factor * (max_y - min_y); + const double dx = margin_factor * (max_x - min_x); + const double dy = margin_factor * (max_y - min_y); - if ((dx <= 0.0) || (dy <= 0.0)) + if (dx <= 0.0 || dy <= 0.0) return -1.0f; return std::min((double)m_viewport[2] / dx, (double)m_viewport[3] / dy); @@ -478,22 +450,21 @@ double Camera::calc_zoom_to_volumes_factor(const GLVolumePtrs& volumes, Vec3d& c void Camera::set_distance(double distance) const { - if (m_distance != distance) - { - m_view_matrix.translate((distance - m_distance) * get_dir_forward()); - m_distance = distance; + if (m_distance != distance) { + const_cast(&m_view_matrix)->translate((distance - m_distance) * get_dir_forward()); + *const_cast(&m_distance) = distance; } } void Camera::look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up) { - Vec3d unit_z = (position - target).normalized(); - Vec3d unit_x = up.cross(unit_z).normalized(); - Vec3d unit_y = unit_z.cross(unit_x).normalized(); + const Vec3d unit_z = (position - target).normalized(); + const Vec3d unit_x = up.cross(unit_z).normalized(); + const Vec3d unit_y = unit_z.cross(unit_x).normalized(); m_target = target; m_distance = (position - target).norm(); - Vec3d new_position = m_target + m_distance * unit_z; + const Vec3d new_position = m_target + m_distance * unit_z; m_view_matrix(0, 0) = unit_x(0); m_view_matrix(0, 1) = unit_x(1); @@ -525,10 +496,10 @@ void Camera::look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up void Camera::set_default_orientation() { m_zenit = 45.0f; - double theta_rad = Geometry::deg2rad(-(double)m_zenit); - double phi_rad = Geometry::deg2rad(45.0); - double sin_theta = ::sin(theta_rad); - Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad)); + const double theta_rad = Geometry::deg2rad(-(double)m_zenit); + const double phi_rad = Geometry::deg2rad(45.0); + const double sin_theta = ::sin(theta_rad); + const Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad)); m_view_rotation = Eigen::AngleAxisd(theta_rad, Vec3d::UnitX()) * Eigen::AngleAxisd(phi_rad, Vec3d::UnitZ()); m_view_rotation.normalize(); m_view_matrix.fromPositionOrientationScale(m_view_rotation * (- camera_pos), m_view_rotation, Vec3d(1., 1., 1.)); @@ -543,9 +514,9 @@ Vec3d Camera::validate_target(const Vec3d& target) const test_box.scale(ScaleFactor); test_box.translate(m_scene_box.center()); - return Vec3d(std::clamp(target(0), test_box.min(0), test_box.max(0)), - std::clamp(target(1), test_box.min(1), test_box.max(1)), - std::clamp(target(2), test_box.min(2), test_box.max(2))); + return { std::clamp(target(0), test_box.min(0), test_box.max(0)), + std::clamp(target(1), test_box.min(1), test_box.max(1)), + std::clamp(target(2), test_box.min(2), test_box.max(2)) }; } void Camera::update_zenit() diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index 91f4661b46..1abb430ca9 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -26,7 +26,7 @@ struct Camera Num_types }; - bool requires_zoom_to_bed; + bool requires_zoom_to_bed{ false }; private: EType m_type{ Perspective }; @@ -35,26 +35,26 @@ private: float m_zenit{ 45.0f }; double m_zoom{ 1.0 }; // Distance between camera position and camera target measured along the camera Z axis - mutable double m_distance{ DefaultDistance }; - mutable double m_gui_scale{ 1.0 }; + double m_distance{ DefaultDistance }; + double m_gui_scale{ 1.0 }; - mutable std::array m_viewport; - mutable Transform3d m_view_matrix{ Transform3d::Identity() }; + std::array m_viewport; + Transform3d m_view_matrix{ Transform3d::Identity() }; // We are calculating the rotation part of the m_view_matrix from m_view_rotation. - mutable Eigen::Quaterniond m_view_rotation{ 1.0, 0.0, 0.0, 0.0 }; - mutable Transform3d m_projection_matrix{ Transform3d::Identity() }; - mutable std::pair m_frustrum_zs; + Eigen::Quaterniond m_view_rotation{ 1.0, 0.0, 0.0, 0.0 }; + Transform3d m_projection_matrix{ Transform3d::Identity() }; + std::pair m_frustrum_zs; BoundingBoxf3 m_scene_box; public: - Camera(); + Camera() { set_default_orientation(); } EType get_type() const { return m_type; } std::string get_type_as_string() const; void set_type(EType type); // valid values for type: "0" -> ortho, "1" -> perspective - void set_type(const std::string& type); + void set_type(const std::string& type) { set_type((type == "1") ? Perspective : Ortho); } void select_next_type(); void enable_update_config_on_type_change(bool enable) { m_update_config_on_type_change_enabled = enable; } @@ -67,7 +67,7 @@ public: double get_zoom() const { return m_zoom; } double get_inv_zoom() const { assert(m_zoom != 0.0); return 1.0 / m_zoom; } - void update_zoom(double delta_zoom); + void update_zoom(double delta_zoom) { set_zoom(m_zoom / (1.0 - std::max(std::min(delta_zoom, 4.0), -4.0) * 0.1)); } void set_zoom(double zoom); const BoundingBoxf3& get_scene_box() const { return m_scene_box; } @@ -119,8 +119,7 @@ public: bool is_looking_downward() const { return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; } // forces camera right vector to be parallel to XY plane - void recover_from_free_camera() - { + void recover_from_free_camera() { if (std::abs(get_dir_right()(2)) > EPSILON) look_at(get_position(), m_target, Vec3d::UnitZ()); } @@ -128,7 +127,7 @@ public: void look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up); double max_zoom() const { return 250.0; } - double min_zoom() const; + double min_zoom() const { return 0.7 * calc_zoom_to_bounding_box_factor(m_scene_box); } private: // returns tight values for nearZ and farZ plane around the given bounding box diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 9334eea471..d557585384 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -45,7 +45,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con // layer_height shouldn't be equal to zero if (config->opt_float("layer_height") < EPSILON) { - const wxString msg_text = _(L("Zero layer height is not valid.\n\nThe layer height will be reset to 0.01.")); + const wxString msg_text = _(L("Layer height is not valid.\n\nThe layer height will be reset to 0.01.")); wxMessageDialog dialog(nullptr, msg_text, _(L("Layer height")), wxICON_WARNING | wxOK); DynamicPrintConfig new_conf = *config; is_msg_dlg_already_exist = true; @@ -55,9 +55,9 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con is_msg_dlg_already_exist = false; } - if (fabs(config->option("first_layer_height")->value - 0) < EPSILON) + if (config->option("first_layer_height")->value < EPSILON) { - const wxString msg_text = _(L("Zero first layer height is not valid.\n\nThe first layer height will be reset to 0.01.")); + const wxString msg_text = _(L("First layer height is not valid.\n\nThe first layer height will be reset to 0.01.")); wxMessageDialog dialog(nullptr, msg_text, _(L("First layer height")), wxICON_WARNING | wxOK); DynamicPrintConfig new_conf = *config; is_msg_dlg_already_exist = true; @@ -278,6 +278,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config) bool have_support_material_auto = have_support_material && config->opt_bool("support_material_auto"); bool have_support_interface = config->opt_int("support_material_interface_layers") > 0; bool have_support_soluble = have_support_material && config->opt_float("support_material_contact_distance") == 0; + auto support_material_style = config->opt_enum("support_material_style"); for (auto el : { "support_material_style", "support_material_pattern", "support_material_with_sheath", "support_material_spacing", "support_material_angle", "support_material_interface_pattern", "support_material_interface_layers", @@ -286,6 +287,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config) toggle_field(el, have_support_material); toggle_field("support_material_threshold", have_support_material_auto); toggle_field("support_material_bottom_contact_distance", have_support_material && ! have_support_soluble); + toggle_field("support_material_closing_radius", have_support_material && support_material_style == smsSnug); for (auto el : { "support_material_bottom_interface_layers", "support_material_interface_spacing", "support_material_interface_extruder", "support_material_interface_speed", "support_material_interface_contact_loops" }) diff --git a/src/slic3r/GUI/ConfigSnapshotDialog.cpp b/src/slic3r/GUI/ConfigSnapshotDialog.cpp index 9f996d378b..6a02e67534 100644 --- a/src/slic3r/GUI/ConfigSnapshotDialog.cpp +++ b/src/slic3r/GUI/ConfigSnapshotDialog.cpp @@ -29,11 +29,20 @@ static wxString format_reason(const Config::Snapshot::Reason reason) } } -static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active) +static std::string get_color(wxColour colour) { + wxString clr_str = wxString::Format(wxT("#%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue()); + return clr_str.ToStdString(); +}; + + +static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active, bool dark_mode) +{ // Start by declaring a row with an alternating background color. wxString text = ""; text += ""; @@ -92,14 +101,15 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve static wxString generate_html_page(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot) { + bool dark_mode = wxGetApp().dark_mode(); wxString text = "" - "" - ""; + "" + ""; text += ""; for (size_t i_row = 0; i_row < snapshot_db.snapshots().size(); ++ i_row) { const Config::Snapshot &snapshot = snapshot_db.snapshots()[snapshot_db.snapshots().size() - i_row - 1]; - text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot); + text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot, dark_mode); } text += "
" @@ -115,8 +125,8 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX) { this->SetFont(wxGetApp().normal_font()); - this->SetBackgroundColour(*wxWHITE); - + this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL); this->SetSizer(vsizer); diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 29b488b907..84a499d6fd 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -2165,7 +2165,7 @@ static std::string get_custom_code(const std::string& code_in, double height) if (dlg.ShowModal() != wxID_OK) return ""; - value = dlg.GetValue().ToStdString(); + value = into_u8(dlg.GetValue()); valid = GUI::Tab::validate_custom_gcode("Custom G-code", value); } while (!valid); return value; @@ -2173,7 +2173,7 @@ static std::string get_custom_code(const std::string& code_in, double height) if (dlg.ShowModal() != wxID_OK) return ""; - return dlg.GetValue().ToStdString(); + return into_u8(dlg.GetValue()); #endif // ENABLE_VALIDATE_CUSTOM_GCODE } diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index eacf69c917..ca1617bc29 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -143,6 +143,9 @@ bool GCodeViewer::Path::matches(const GCodeProcessor::MoveVertex& move) const case EMoveType::Custom_GCode: case EMoveType::Retract: case EMoveType::Unretract: +#if ENABLE_SEAMS_VISUALIZATION + case EMoveType::Seam: +#endif // ENABLE_SEAMS_VISUALIZATION case EMoveType::Extrude: { // use rounding to reduce the number of generated paths #if ENABLE_SPLITTED_VERTEX_BUFFER @@ -540,6 +543,9 @@ const std::vector GCodeViewer::Extrusion_Role_Colors {{ const std::vector GCodeViewer::Options_Colors {{ { 0.803f, 0.135f, 0.839f }, // Retractions { 0.287f, 0.679f, 0.810f }, // Unretractions +#if ENABLE_SEAMS_VISUALIZATION + { 0.900f, 0.900f, 0.900f }, // Seams +#endif // ENABLE_SEAMS_VISUALIZATION { 0.758f, 0.744f, 0.389f }, // ToolChanges { 0.856f, 0.582f, 0.546f }, // ColorChanges { 0.322f, 0.942f, 0.512f }, // PausePrints @@ -582,11 +588,20 @@ GCodeViewer::GCodeViewer() case EMoveType::Pause_Print: case EMoveType::Custom_GCode: case EMoveType::Retract: +#if ENABLE_SEAMS_VISUALIZATION + case EMoveType::Unretract: + case EMoveType::Seam: { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; + buffer.vertices.format = VBuffer::EFormat::Position; + break; + } +#else case EMoveType::Unretract: { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; buffer.vertices.format = VBuffer::EFormat::Position; break; } +#endif // ENABLE_SEAMS_VISUALIZATION case EMoveType::Wipe: case EMoveType::Extrude: { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; @@ -796,10 +811,18 @@ void GCodeViewer::render() const case EMoveType::Pause_Print: case EMoveType::Custom_GCode: case EMoveType::Retract: +#if ENABLE_SEAMS_VISUALIZATION + case EMoveType::Unretract: + case EMoveType::Seam: { + buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; + break; + } +#else case EMoveType::Unretract: { buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; break; } +#endif // ENABLE_SEAMS_VISUALIZATION case EMoveType::Wipe: case EMoveType::Extrude: { buffer.shader = "gouraud_light"; @@ -938,6 +961,9 @@ unsigned int GCodeViewer::get_options_visibility_flags() const flags = set_flag(flags, static_cast(Preview::OptionType::Wipe), is_toolpath_move_type_visible(EMoveType::Wipe)); flags = set_flag(flags, static_cast(Preview::OptionType::Retractions), is_toolpath_move_type_visible(EMoveType::Retract)); flags = set_flag(flags, static_cast(Preview::OptionType::Unretractions), is_toolpath_move_type_visible(EMoveType::Unretract)); +#if ENABLE_SEAMS_VISUALIZATION + flags = set_flag(flags, static_cast(Preview::OptionType::Seams), is_toolpath_move_type_visible(EMoveType::Seam)); +#endif // ENABLE_SEAMS_VISUALIZATION flags = set_flag(flags, static_cast(Preview::OptionType::ToolChanges), is_toolpath_move_type_visible(EMoveType::Tool_change)); flags = set_flag(flags, static_cast(Preview::OptionType::ColorChanges), is_toolpath_move_type_visible(EMoveType::Color_change)); flags = set_flag(flags, static_cast(Preview::OptionType::PausePrints), is_toolpath_move_type_visible(EMoveType::Pause_Print)); @@ -958,6 +984,9 @@ void GCodeViewer::set_options_visibility_from_flags(unsigned int flags) set_toolpath_move_type_visible(EMoveType::Wipe, is_flag_set(static_cast(Preview::OptionType::Wipe))); set_toolpath_move_type_visible(EMoveType::Retract, is_flag_set(static_cast(Preview::OptionType::Retractions))); set_toolpath_move_type_visible(EMoveType::Unretract, is_flag_set(static_cast(Preview::OptionType::Unretractions))); +#if ENABLE_SEAMS_VISUALIZATION + set_toolpath_move_type_visible(EMoveType::Seam, is_flag_set(static_cast(Preview::OptionType::Seams))); +#endif // ENABLE_SEAMS_VISUALIZATION set_toolpath_move_type_visible(EMoveType::Tool_change, is_flag_set(static_cast(Preview::OptionType::ToolChanges))); set_toolpath_move_type_visible(EMoveType::Color_change, is_flag_set(static_cast(Preview::OptionType::ColorChanges))); set_toolpath_move_type_visible(EMoveType::Pause_Print, is_flag_set(static_cast(Preview::OptionType::PausePrints))); @@ -1595,13 +1624,15 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) #if ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS const std::array first_seg_v_offsets = convert_vertices_offset(vbuffer_size, { 0, 1, 2, 3, 4, 5, 6, 7 }); const std::array non_first_seg_v_offsets = convert_vertices_offset(vbuffer_size, { -4, 0, -2, 1, 2, 3, 4, 5 }); -#endif // ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS - + bool is_first_segment = (last_path.vertices_count() == 1); + if (is_first_segment || vbuffer_size == 0) { +#else if (last_path.vertices_count() == 1 || vbuffer_size == 0) { +#endif // ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS // 1st segment or restart into a new vertex buffer // =============================================== #if ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS - if (last_path.vertices_count() == 1) + if (is_first_segment) // starting cap triangles append_starting_cap_triangles(indices, first_seg_v_offsets); #endif // ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS @@ -1679,7 +1710,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) #if ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS if (next != nullptr && (curr.type != next->type || !last_path.matches(*next))) // ending cap triangles - append_ending_cap_triangles(indices, non_first_seg_v_offsets); + append_ending_cap_triangles(indices, is_first_segment ? first_seg_v_offsets : non_first_seg_v_offsets); #endif // ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS last_path.sub_paths.back().last = { ibuffer_id, indices.size() - 1, move_id, curr.position }; @@ -1714,7 +1745,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) // for the gcode viewer we need to take in account all moves to correctly size the printbed m_paths_bounding_box.merge(move.position.cast()); else { +#if ENABLE_START_GCODE_VISUALIZATION + if (move.type == EMoveType::Extrude && move.extrusion_role != erCustom && move.width != 0.0f && move.height != 0.0f) +#else if (move.type == EMoveType::Extrude && move.width != 0.0f && move.height != 0.0f) +#endif // ENABLE_START_GCODE_VISUALIZATION m_paths_bounding_box.merge(move.position.cast()); } } @@ -3163,6 +3198,9 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool case EMoveType::Custom_GCode: { color = Options_Colors[static_cast(EOptionsColors::CustomGCodes)]; break; } case EMoveType::Retract: { color = Options_Colors[static_cast(EOptionsColors::Retractions)]; break; } case EMoveType::Unretract: { color = Options_Colors[static_cast(EOptionsColors::Unretractions)]; break; } +#if ENABLE_SEAMS_VISUALIZATION + case EMoveType::Seam: { color = Options_Colors[static_cast(EOptionsColors::Seams)]; break; } +#endif // ENABLE_SEAMS_VISUALIZATION case EMoveType::Extrude: { if (!top_layer_only || m_sequential_view.current.last == global_endpoints.last || @@ -4557,7 +4595,12 @@ void GCodeViewer::render_legend() const available(EMoveType::Pause_Print) || available(EMoveType::Retract) || available(EMoveType::Tool_change) || +#if ENABLE_SEAMS_VISUALIZATION + available(EMoveType::Unretract) || + available(EMoveType::Seam); +#else available(EMoveType::Unretract); +#endif // ENABLE_SEAMS_VISUALIZATION }; auto add_option = [this, append_item](EMoveType move_type, EOptionsColors color, const std::string& text) { @@ -4575,6 +4618,9 @@ void GCodeViewer::render_legend() const // items add_option(EMoveType::Retract, EOptionsColors::Retractions, _u8L("Retractions")); add_option(EMoveType::Unretract, EOptionsColors::Unretractions, _u8L("Deretractions")); +#if ENABLE_SEAMS_VISUALIZATION + add_option(EMoveType::Seam, EOptionsColors::Seams, _u8L("Seams")); +#endif // ENABLE_SEAMS_VISUALIZATION add_option(EMoveType::Tool_change, EOptionsColors::ToolChanges, _u8L("Tool changes")); add_option(EMoveType::Color_change, EOptionsColors::ColorChanges, _u8L("Color changes")); add_option(EMoveType::Pause_Print, EOptionsColors::PausePrints, _u8L("Print pauses")); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 051260b72c..2ccda6f5de 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -46,6 +46,9 @@ class GCodeViewer { Retractions, Unretractions, +#if ENABLE_SEAMS_VISUALIZATION + Seams, +#endif // ENABLE_SEAMS_VISUALIZATION ToolChanges, ColorChanges, PausePrints, diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 4570670cbf..b81b7f58a3 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1,7 +1,6 @@ #include "libslic3r/libslic3r.h" #include "GLCanvas3D.hpp" -#include "admesh/stl.h" #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/PrintConfig.hpp" #include "libslic3r/GCode/ThumbnailData.hpp" @@ -508,6 +507,7 @@ void GLCanvas3D::LayersEditing::reset_layer_height_profile(GLCanvas3D& canvas) m_layer_height_profile.clear(); m_layers_texture.valid = false; canvas.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + wxGetApp().obj_list()->update_info_items(last_object_id); } void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas, float quality_factor) @@ -517,6 +517,7 @@ void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas const_cast(m_model_object)->layer_height_profile.set(m_layer_height_profile); m_layers_texture.valid = false; canvas.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + wxGetApp().obj_list()->update_info_items(last_object_id); } void GLCanvas3D::LayersEditing::smooth_layer_height_profile(GLCanvas3D& canvas, const HeightProfileSmoothingParams& smoothing_params) @@ -526,6 +527,7 @@ void GLCanvas3D::LayersEditing::smooth_layer_height_profile(GLCanvas3D& canvas, const_cast(m_model_object)->layer_height_profile.set(m_layer_height_profile); m_layers_texture.valid = false; canvas.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + wxGetApp().obj_list()->update_info_items(last_object_id); } void GLCanvas3D::LayersEditing::generate_layer_height_texture() @@ -565,6 +567,7 @@ void GLCanvas3D::LayersEditing::accept_changes(GLCanvas3D& canvas) wxGetApp().plater()->take_snapshot(_(L("Variable layer height - Manual edit"))); const_cast(m_model_object)->layer_height_profile.set(m_layer_height_profile); canvas.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + wxGetApp().obj_list()->update_info_items(last_object_id); } } m_layer_height_profile_modified = false; @@ -1678,8 +1681,10 @@ void GLCanvas3D::render() if (m_picking_enabled) m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); - _render_current_gizmo(); + // sidebar hints need to be rendered before the gizmos because the depth buffer + // could be invalidated by the following gizmo render methods _render_selection_sidebar_hints(); + _render_current_gizmo(); #if ENABLE_RENDER_PICKING_PASS } #endif // ENABLE_RENDER_PICKING_PASS @@ -3529,7 +3534,7 @@ Vec2d GLCanvas3D::get_local_mouse_position() const void GLCanvas3D::set_tooltip(const std::string& tooltip) const { if (m_canvas != nullptr) - m_tooltip.set_text(tooltip); + const_cast(&m_tooltip)->set_text(tooltip); } void GLCanvas3D::do_move(const std::string& snapshot_type) @@ -3546,22 +3551,19 @@ void GLCanvas3D::do_move(const std::string& snapshot_type) Selection::EMode selection_mode = m_selection.get_mode(); - for (const GLVolume* v : m_volumes.volumes) - { + for (const GLVolume* v : m_volumes.volumes) { int object_idx = v->object_idx(); int instance_idx = v->instance_idx(); int volume_idx = v->volume_idx(); std::pair done_id(object_idx, instance_idx); - if ((0 <= object_idx) && (object_idx < (int)m_model->objects.size())) - { + if (0 <= object_idx && object_idx < (int)m_model->objects.size()) { done.insert(done_id); // Move instances/volumes ModelObject* model_object = m_model->objects[object_idx]; - if (model_object != nullptr) - { + if (model_object != nullptr) { if (selection_mode == Selection::Instance) model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); else if (selection_mode == Selection::Volume) @@ -3577,8 +3579,7 @@ void GLCanvas3D::do_move(const std::string& snapshot_type) } // Fixes sinking/flying instances - for (const std::pair& i : done) - { + for (const std::pair& i : done) { ModelObject* m = m_model->objects[i.first]; Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second)); m_selection.translate(i.first, i.second, shift); @@ -3937,13 +3938,13 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const em *= m_retina_helper->get_scale_factor(); #endif - if (imgui->undo_redo_list(ImVec2(18 * em, 26 * em), is_undo, &string_getter, hovered, selected, m_mouse_wheel)) - m_imgui_undo_redo_hovered_pos = hovered; + int* mouse_wheel = const_cast(&m_mouse_wheel); + if (imgui->undo_redo_list(ImVec2(18 * em, 26 * em), is_undo, &string_getter, hovered, selected, *mouse_wheel)) + *const_cast(&m_imgui_undo_redo_hovered_pos) = hovered; else - m_imgui_undo_redo_hovered_pos = -1; + *const_cast(&m_imgui_undo_redo_hovered_pos) = -1; - if (selected >= 0) - { + if (selected >= 0) { is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected); action_taken = true; } @@ -3984,9 +3985,10 @@ bool GLCanvas3D::_render_search_list(float pos_x) const char *s = new char[255]; strcpy(s, search_line.empty() ? _u8L("Enter a search term").c_str() : search_line.c_str()); - imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s, - sidebar.get_searcher().view_params, - selected, edited, m_mouse_wheel, wxGetApp().is_localized()); + int* mouse_wheel = const_cast(&m_mouse_wheel); + imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s, + sidebar.get_searcher().view_params, + selected, edited, *mouse_wheel, wxGetApp().is_localized()); search_line = s; delete [] s; @@ -4845,8 +4847,10 @@ void GLCanvas3D::_refresh_if_shown_on_screen() void GLCanvas3D::_picking_pass() const { + std::vector* hover_volume_idxs = const_cast*>(&m_hover_volume_idxs); + if (m_picking_enabled && !m_mouse.dragging && m_mouse.position != Vec2d(DBL_MAX, DBL_MAX)) { - m_hover_volume_idxs.clear(); + hover_volume_idxs->clear(); // Render the object for picking. // FIXME This cannot possibly work in a multi - sampled context as the color gets mangled by the anti - aliasing. @@ -4861,9 +4865,10 @@ void GLCanvas3D::_picking_pass() const glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - m_camera_clipping_plane = m_gizmos.get_clipping_plane(); - if (m_camera_clipping_plane.is_active()) { - ::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_camera_clipping_plane.get_data()); + ClippingPlane* camera_clipping_plane = const_cast(&m_camera_clipping_plane); + *camera_clipping_plane = m_gizmos.get_clipping_plane(); + if (camera_clipping_plane->is_active()) { + ::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)camera_clipping_plane->get_data()); ::glEnable(GL_CLIP_PLANE0); } _render_volumes_for_picking(); @@ -4889,11 +4894,11 @@ void GLCanvas3D::_picking_pass() const if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) { // do not add the volume id if any gizmo is active and CTRL is pressed if (m_gizmos.get_current_type() == GLGizmosManager::EType::Undefined || !wxGetKeyState(WXK_CONTROL)) - m_hover_volume_idxs.emplace_back(volume_id); - m_gizmos.set_hover_id(-1); + hover_volume_idxs->emplace_back(volume_id); + const_cast(&m_gizmos)->set_hover_id(-1); } else - m_gizmos.set_hover_id(inside && (unsigned int)volume_id <= GLGizmoBase::BASE_ID ? ((int)GLGizmoBase::BASE_ID - volume_id) : -1); + const_cast(&m_gizmos)->set_hover_id(inside && (unsigned int)volume_id <= GLGizmoBase::BASE_ID ? ((int)GLGizmoBase::BASE_ID - volume_id) : -1); _update_volumes_hover_state(); } @@ -4901,12 +4906,11 @@ void GLCanvas3D::_picking_pass() const void GLCanvas3D::_rectangular_selection_picking_pass() const { - m_gizmos.set_hover_id(-1); + const_cast(&m_gizmos)->set_hover_id(-1); std::set idxs; - if (m_picking_enabled) - { + if (m_picking_enabled) { if (m_multisample_allowed) // This flag is often ignored by NVIDIA drivers if rendering into a screen buffer. glsafe(::glDisable(GL_MULTISAMPLE)); @@ -4927,8 +4931,7 @@ void GLCanvas3D::_rectangular_selection_picking_pass() const int left = (int)m_rectangle_selection.get_left(); int top = get_canvas_size().get_height() - (int)m_rectangle_selection.get_top(); - if ((left >= 0) && (top >= 0)) - { + if (left >= 0 && top >= 0) { #define USE_PARALLEL 1 #if USE_PARALLEL struct Pixel @@ -4948,7 +4951,7 @@ void GLCanvas3D::_rectangular_selection_picking_pass() const for (size_t i = range.begin(); i < range.end(); ++i) if (frame[i].valid()) { int volume_id = frame[i].id(); - if ((0 <= volume_id) && (volume_id < (int)m_volumes.volumes.size())) { + if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) { mutex.lock(); idxs.insert(volume_id); mutex.unlock(); @@ -4963,14 +4966,14 @@ void GLCanvas3D::_rectangular_selection_picking_pass() const { int px_id = 4 * i; int volume_id = frame[px_id] + (frame[px_id + 1] << 8) + (frame[px_id + 2] << 16); - if ((0 <= volume_id) && (volume_id < (int)m_volumes.volumes.size())) + if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) idxs.insert(volume_id); } #endif // USE_PARALLEL } } - m_hover_volume_idxs.assign(idxs.begin(), idxs.end()); + const_cast*>(&m_hover_volume_idxs)->assign(idxs.begin(), idxs.end()); _update_volumes_hover_state(); } @@ -5001,8 +5004,9 @@ void GLCanvas3D::_render_background() const if (!m_volumes.empty()) use_error_color &= _is_any_volume_outside(); else { - BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); - use_error_color &= (test_volume.radius() > 0.0) ? !test_volume.contains(m_gcode_viewer.get_paths_bounding_box()) : false; + const BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3(); + const BoundingBoxf3& paths_volume = m_gcode_viewer.get_paths_bounding_box(); + use_error_color &= (test_volume.radius() > 0.0 && paths_volume.radius() > 0.0) ? !test_volume.contains(paths_volume) : false; } } @@ -5063,7 +5067,9 @@ void GLCanvas3D::_render_objects() const glsafe(::glEnable(GL_DEPTH_TEST)); - m_camera_clipping_plane = m_gizmos.get_clipping_plane(); + ClippingPlane* camera_clipping_plane = const_cast(&m_camera_clipping_plane); + GLVolumeCollection* volumes = const_cast(&m_volumes); + *camera_clipping_plane = m_gizmos.get_clipping_plane(); if (m_picking_enabled) { // Update the layer editing selection to the first object selected, update the current object maximum Z. @@ -5071,17 +5077,17 @@ void GLCanvas3D::_render_objects() const if (m_config != nullptr) { const BoundingBoxf3& bed_bb = wxGetApp().plater()->get_bed().get_bounding_box(false); - m_volumes.set_print_box((float)bed_bb.min(0) - BedEpsilon, (float)bed_bb.min(1) - BedEpsilon, 0.0f, (float)bed_bb.max(0) + BedEpsilon, (float)bed_bb.max(1) + BedEpsilon, (float)m_config->opt_float("max_print_height")); - m_volumes.check_outside_state(m_config, nullptr); + volumes->set_print_box((float)bed_bb.min(0) - BedEpsilon, (float)bed_bb.min(1) - BedEpsilon, 0.0f, (float)bed_bb.max(0) + BedEpsilon, (float)bed_bb.max(1) + BedEpsilon, (float)m_config->opt_float("max_print_height")); + volumes->check_outside_state(m_config, nullptr); } } if (m_use_clipping_planes) - m_volumes.set_z_range(-m_clipping_planes[0].get_data()[3], m_clipping_planes[1].get_data()[3]); + volumes->set_z_range(-m_clipping_planes[0].get_data()[3], m_clipping_planes[1].get_data()[3]); else - m_volumes.set_z_range(-FLT_MAX, FLT_MAX); + volumes->set_z_range(-FLT_MAX, FLT_MAX); - m_volumes.set_clipping_plane(m_camera_clipping_plane.get_data()); + volumes->set_clipping_plane(camera_clipping_plane->get_data()); GLShaderProgram* shader = wxGetApp().get_shader("gouraud"); if (shader != nullptr) { @@ -5089,16 +5095,16 @@ void GLCanvas3D::_render_objects() const if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) { int object_id = m_layers_editing.last_object_id; - m_volumes.render(GLVolumeCollection::Opaque, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) { + volumes->render(GLVolumeCollection::Opaque, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) { // Which volume to paint without the layer height profile shader? return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); }); // Let LayersEditing handle rendering of the active object using the layer height profile shader. - m_layers_editing.render_volumes(*this, this->m_volumes); + m_layers_editing.render_volumes(*this, *volumes); } else { - // do not cull backfaces to show broken geometry, if any - m_volumes.render(GLVolumeCollection::Opaque, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) { - return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); + // do not cull backfaces to show broken geometry, if any + volumes->render(GLVolumeCollection::Opaque, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) { + return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); }); } @@ -5116,11 +5122,11 @@ void GLCanvas3D::_render_objects() const } } - m_volumes.render(GLVolumeCollection::Transparent, false, wxGetApp().plater()->get_camera().get_view_matrix()); + volumes->render(GLVolumeCollection::Transparent, false, wxGetApp().plater()->get_camera().get_view_matrix()); shader->stop_using(); } - m_camera_clipping_plane = ClippingPlane::ClipsNothing(); + *camera_clipping_plane = ClippingPlane::ClipsNothing(); } void GLCanvas3D::_render_gcode() const @@ -5161,13 +5167,13 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() const GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); #if ENABLE_RETINA_GL const float sc = m_retina_helper->get_scale_factor() * scale; - m_main_toolbar.set_scale(sc); - m_undoredo_toolbar.set_scale(sc); + const_cast(&m_main_toolbar)->set_scale(sc); + const_cast(&m_undoredo_toolbar)->set_scale(sc); collapse_toolbar.set_scale(sc); size *= m_retina_helper->get_scale_factor(); #else - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); + const_cast(&m_main_toolbar)->set_icons_size(size); + const_cast(&m_undoredo_toolbar)->set_icons_size(size); collapse_toolbar.set_icons_size(size); #endif // ENABLE_RETINA_GL @@ -5215,13 +5221,13 @@ void GLCanvas3D::_render_overlays() const // to correctly place them #if ENABLE_RETINA_GL const float scale = m_retina_helper->get_scale_factor() * wxGetApp().toolbar_icon_scale(/*true*/); - m_main_toolbar.set_scale(scale); - m_undoredo_toolbar.set_scale(scale); + const_cast(&m_main_toolbar)->set_scale(scale); + const_cast(&m_undoredo_toolbar)->set_scale(scale); wxGetApp().plater()->get_collapse_toolbar().set_scale(scale); #else const float size = int(GLToolbar::Default_Icons_Size * wxGetApp().toolbar_icon_scale(/*true*/)); - m_main_toolbar.set_icons_size(size); - m_undoredo_toolbar.set_icons_size(size); + const_cast(&m_main_toolbar)->set_icons_size(size); + const_cast(&m_undoredo_toolbar)->set_icons_size(size); wxGetApp().plater()->get_collapse_toolbar().set_icons_size(size); #endif // ENABLE_RETINA_GL @@ -5296,12 +5302,12 @@ void GLCanvas3D::_render_gizmos_overlay() const #if ENABLE_RETINA_GL // m_gizmos.set_overlay_scale(m_retina_helper->get_scale_factor()); const float scale = m_retina_helper->get_scale_factor()*wxGetApp().toolbar_icon_scale(); - m_gizmos.set_overlay_scale(scale); //! #ys_FIXME_experiment + const_cast(&m_gizmos)->set_overlay_scale(scale); //! #ys_FIXME_experiment #else // m_gizmos.set_overlay_scale(m_canvas->GetContentScaleFactor()); // m_gizmos.set_overlay_scale(wxGetApp().em_unit()*0.1f); - const float size = int(GLGizmosManager::Default_Icons_Size*wxGetApp().toolbar_icon_scale()); - m_gizmos.set_overlay_icon_size(size); //! #ys_FIXME_experiment + const float size = int(GLGizmosManager::Default_Icons_Size * wxGetApp().toolbar_icon_scale()); + const_cast(&m_gizmos)->set_overlay_icon_size(size); //! #ys_FIXME_experiment #endif /* __WXMSW__ */ m_gizmos.render_overlay(); @@ -5320,8 +5326,9 @@ void GLCanvas3D::_render_main_toolbar() const float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width) * inv_zoom; - m_main_toolbar.set_position(top, left); - m_main_toolbar.render(*this); + GLToolbar* main_toolbar = const_cast(&m_main_toolbar); + main_toolbar->set_position(top, left); + main_toolbar->render(*this); } void GLCanvas3D::_render_undoredo_toolbar() const @@ -5336,8 +5343,10 @@ void GLCanvas3D::_render_undoredo_toolbar() const const GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width)) * inv_zoom; - m_undoredo_toolbar.set_position(top, left); - m_undoredo_toolbar.render(*this); + + GLToolbar* undoredo_toolbar = const_cast(&m_undoredo_toolbar); + undoredo_toolbar->set_position(top, left); + undoredo_toolbar->render(*this); } void GLCanvas3D::_render_collapse_toolbar() const @@ -5428,20 +5437,21 @@ void GLCanvas3D::_render_sla_slices() const if (!obj->is_step_done(slaposSliceSupports)) continue; - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i); - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i); + SlaCap* sla_caps = const_cast(m_sla_caps); + SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = sla_caps[0].triangles.find(i); + SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = sla_caps[1].triangles.find(i); { - if (it_caps_bottom == m_sla_caps[0].triangles.end()) - it_caps_bottom = m_sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first; - if (! m_sla_caps[0].matches(clip_min_z)) { - m_sla_caps[0].z = clip_min_z; + if (it_caps_bottom == sla_caps[0].triangles.end()) + it_caps_bottom = sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first; + if (!sla_caps[0].matches(clip_min_z)) { + sla_caps[0].z = clip_min_z; it_caps_bottom->second.object.clear(); it_caps_bottom->second.supports.clear(); } - if (it_caps_top == m_sla_caps[1].triangles.end()) - it_caps_top = m_sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first; - if (! m_sla_caps[1].matches(clip_max_z)) { - m_sla_caps[1].z = clip_max_z; + if (it_caps_top == sla_caps[1].triangles.end()) + it_caps_top = sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first; + if (!sla_caps[1].matches(clip_max_z)) { + sla_caps[1].z = clip_max_z; it_caps_top->second.object.clear(); it_caps_top->second.supports.clear(); } @@ -5547,7 +5557,7 @@ void GLCanvas3D::_update_volumes_hover_state() const if (alt_pressed && (shift_pressed || ctrl_pressed)) { // illegal combinations of keys - m_hover_volume_idxs.clear(); + const_cast*>(&m_hover_volume_idxs)->clear(); return; } @@ -5571,7 +5581,7 @@ void GLCanvas3D::_update_volumes_hover_state() const if (hover_modifiers_only && !hover_from_single_instance) { // do not allow to select volumes from different instances - m_hover_volume_idxs.clear(); + const_cast*>(&m_hover_volume_idxs)->clear(); return; } @@ -5592,23 +5602,15 @@ void GLCanvas3D::_update_volumes_hover_state() const (deselect && !m_selection.is_single_full_instance() && (volume.object_idx() == m_selection.get_object_idx()) && (volume.instance_idx() == m_selection.get_instance_idx())) ); - if (as_volume) { - if (deselect) - volume.hover = GLVolume::HS_Deselect; - else - volume.hover = GLVolume::HS_Select; - } + if (as_volume) + volume.hover = deselect ? GLVolume::HS_Deselect : GLVolume::HS_Select; else { int object_idx = volume.object_idx(); int instance_idx = volume.instance_idx(); for (GLVolume* v : m_volumes.volumes) { - if (v->object_idx() == object_idx && v->instance_idx() == instance_idx) { - if (deselect) - v->hover = GLVolume::HS_Deselect; - else - v->hover = GLVolume::HS_Select; - } + if (v->object_idx() == object_idx && v->instance_idx() == instance_idx) + v->hover = deselect ? GLVolume::HS_Deselect : GLVolume::HS_Select; } } } @@ -6315,31 +6317,47 @@ std::vector GLCanvas3D::_parse_colors(const std::vector& col #if ENABLE_WARNING_TEXTURE_REMOVAL void GLCanvas3D::_set_warning_notification(EWarning warning, bool state) { + enum ErrorType{ + PLATER_WARNING, + PLATER_ERROR, + SLICING_ERROR + }; std::string text; - bool error = false; + ErrorType error = ErrorType::PLATER_WARNING; switch (warning) { case EWarning::ObjectOutside: text = _u8L("An object outside the print area was detected."); break; - case EWarning::ToolpathOutside: text = _u8L("A toolpath outside the print area was detected."); error = true; break; - case EWarning::SlaSupportsOutside: text = _u8L("SLA supports outside the print area were detected."); error = true; break; + case EWarning::ToolpathOutside: text = _u8L("A toolpath outside the print area was detected."); error = ErrorType::SLICING_ERROR; break; + case EWarning::SlaSupportsOutside: text = _u8L("SLA supports outside the print area were detected."); error = ErrorType::PLATER_ERROR; break; case EWarning::SomethingNotShown: text = _u8L("Some objects are not visible."); break; case EWarning::ObjectClashed: text = _u8L("An object outside the print area was detected.\n" "Resolve the current problem to continue slicing."); - error = true; + error = ErrorType::PLATER_ERROR; break; } auto& notification_manager = *wxGetApp().plater()->get_notification_manager(); - if (state) { - if (error) - notification_manager.push_plater_error_notification(text); - else + switch (error) + { + case PLATER_WARNING: + if (state) notification_manager.push_plater_warning_notification(text); - } - else { - if (error) - notification_manager.close_plater_error_notification(text); else notification_manager.close_plater_warning_notification(text); + break; + case PLATER_ERROR: + if (state) + notification_manager.push_plater_error_notification(text); + else + notification_manager.close_plater_error_notification(text); + break; + case SLICING_ERROR: + if (state) + notification_manager.push_slicing_error_notification(text); + else + notification_manager.close_slicing_error_notification(text); + break; + default: + break; } } #else diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index f4d862b66c..9e9a2501e1 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -449,13 +449,13 @@ private: wxTimer m_timer; LayersEditing m_layers_editing; Mouse m_mouse; - mutable GLGizmosManager m_gizmos; - mutable GLToolbar m_main_toolbar; - mutable GLToolbar m_undoredo_toolbar; + GLGizmosManager m_gizmos; + GLToolbar m_main_toolbar; + GLToolbar m_undoredo_toolbar; ClippingPlane m_clipping_planes[2]; - mutable ClippingPlane m_camera_clipping_plane; + ClippingPlane m_camera_clipping_plane; bool m_use_clipping_planes; - mutable SlaCap m_sla_caps[2]; + SlaCap m_sla_caps[2]; std::string m_sidebar_field; // when true renders an extra frame by not resetting m_dirty to false // see request_extra_frame() @@ -463,7 +463,7 @@ private: int m_extra_frame_requested_delayed { std::numeric_limits::max() }; bool m_event_handlers_bound{ false }; - mutable GLVolumeCollection m_volumes; + GLVolumeCollection m_volumes; GCodeViewer m_gcode_viewer; RenderTimer m_render_timer; @@ -478,7 +478,6 @@ private: bool m_dirty; bool m_initialized; bool m_apply_zoom_to_volumes_filter; - mutable std::vector m_hover_volume_idxs; bool m_picking_enabled; bool m_moving_enabled; bool m_dynamic_background_enabled; @@ -487,6 +486,7 @@ private: bool m_tab_down; ECursorType m_cursor_type; GLSelectionRectangle m_rectangle_selection; + std::vector m_hover_volume_idxs; // Following variable is obsolete and it should be safe to remove it. // I just don't want to do it now before a release (Lukas Matena 24.3.2019) @@ -504,13 +504,13 @@ private: RenderStats m_render_stats; #endif // ENABLE_RENDER_STATISTICS - mutable int m_imgui_undo_redo_hovered_pos{ -1 }; - mutable int m_mouse_wheel {0}; + int m_imgui_undo_redo_hovered_pos{ -1 }; + int m_mouse_wheel{ 0 }; int m_selected_extruder; Labels m_labels; - mutable Tooltip m_tooltip; - mutable bool m_tooltip_enabled{ true }; + Tooltip m_tooltip; + bool m_tooltip_enabled{ true }; Slope m_slope; ArrangeSettings m_arrange_settings_fff, m_arrange_settings_sla, @@ -519,8 +519,7 @@ private: PrinterTechnology current_printer_technology() const; template - static auto & get_arrange_settings(Self *self) - { + static auto & get_arrange_settings(Self *self) { PrinterTechnology ptech = self->current_printer_technology(); auto *ptr = &self->m_arrange_settings_fff; @@ -529,11 +528,10 @@ private: ptr = &self->m_arrange_settings_sla; } else if (ptech == ptFFF) { auto co_opt = self->m_config->template option("complete_objects"); - if (co_opt && co_opt->value) { + if (co_opt && co_opt->value) ptr = &self->m_arrange_settings_fff_seq_print; - } else { + else ptr = &self->m_arrange_settings_fff; - } } return *ptr; @@ -715,10 +713,9 @@ public: double m_rotation = 0.; BoundingBoxf m_bb; friend class GLCanvas3D; - public: - - inline operator bool() const - { + + public: + inline operator bool() const { return !std::isnan(m_pos.x()) && !std::isnan(m_pos.y()); } @@ -763,8 +760,7 @@ public: void use_slope(bool use) { m_slope.use(use); } void set_slope_normal_angle(float angle_in_deg) { m_slope.set_normal_angle(angle_in_deg); } - ArrangeSettings get_arrange_settings() const - { + ArrangeSettings get_arrange_settings() const { const ArrangeSettings &settings = get_arrange_settings(this); ArrangeSettings ret = settings; if (&settings == &m_arrange_settings_fff_seq_print) { diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 79e7ea1c64..0e6a4ce291 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -428,8 +428,7 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) bool processed = false; // mouse anywhere - if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr)) - { + if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && m_mouse_capture.parent != nullptr) { if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())) { // prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it, // as when switching between views @@ -441,38 +440,31 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) if (evt.Moving()) update_hover_state(mouse_pos, parent); - else if (evt.LeftUp()) - { - if (m_mouse_capture.left) - { + else if (evt.LeftUp()) { + if (m_mouse_capture.left) { processed = true; m_mouse_capture.left = false; } else return false; } - else if (evt.MiddleUp()) - { - if (m_mouse_capture.middle) - { + else if (evt.MiddleUp()) { + if (m_mouse_capture.middle) { processed = true; m_mouse_capture.middle = false; } else return false; } - else if (evt.RightUp()) - { - if (m_mouse_capture.right) - { + else if (evt.RightUp()) { + if (m_mouse_capture.right) { processed = true; m_mouse_capture.right = false; } else return false; } - else if (evt.Dragging()) - { + else if (evt.Dragging()) { if (m_mouse_capture.any()) // if the button down was done on this toolbar, prevent from dragging into the scene processed = true; @@ -481,35 +473,29 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) } int item_id = contains_mouse(mouse_pos, parent); - if (item_id != -1) - { + if (item_id != -1) { // mouse inside toolbar - if (evt.LeftDown() || evt.LeftDClick()) - { + if (evt.LeftDown() || evt.LeftDClick()) { m_mouse_capture.left = true; m_mouse_capture.parent = &parent; processed = true; - if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && - ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left))) - { + if (item_id != -2 && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && + (m_pressed_toggable_id == -1 || m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)) { // mouse is inside an icon do_action(GLToolbarItem::Left, item_id, parent, true); parent.set_as_dirty(); } } - else if (evt.MiddleDown()) - { + else if (evt.MiddleDown()) { m_mouse_capture.middle = true; m_mouse_capture.parent = &parent; } - else if (evt.RightDown()) - { + else if (evt.RightDown()) { m_mouse_capture.right = true; m_mouse_capture.parent = &parent; processed = true; - if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && - ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right))) - { + if (item_id != -2 && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && + (m_pressed_toggable_id == -1 || m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)) { // mouse is inside an icon do_action(GLToolbarItem::Right, item_id, parent, true); parent.set_as_dirty(); @@ -522,24 +508,26 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) void GLToolbar::calc_layout() const { - switch (m_layout.type) + Layout* layout = const_cast(&m_layout); + + switch (layout->type) { default: case Layout::Horizontal: { - m_layout.width = get_width_horizontal(); - m_layout.height = get_height_horizontal(); + layout->width = get_width_horizontal(); + layout->height = get_height_horizontal(); break; } case Layout::Vertical: { - m_layout.width = get_width_vertical(); - m_layout.height = get_height_vertical(); + layout->width = get_width_vertical(); + layout->height = get_height_vertical(); break; } } - m_layout.dirty = false; + layout->dirty = false; } float GLToolbar::get_width_horizontal() const @@ -1196,19 +1184,17 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const left += scaled_border; top -= scaled_border; - if ((tex_id == 0) || (tex_width <= 0) || (tex_height <= 0)) + if (tex_id == 0 || tex_width <= 0 || tex_height <= 0) return; // renders icons - for (const GLToolbarItem* item : m_items) - { + for (const GLToolbarItem* item : m_items) { if (!item->is_visible()) continue; if (item->is_separator()) top -= separator_stride; - else - { + else { item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); top -= icon_stride; } @@ -1219,16 +1205,14 @@ bool GLToolbar::generate_icons_texture() const { std::string path = resources_dir() + "/icons/"; std::vector filenames; - for (GLToolbarItem* item : m_items) - { + for (GLToolbarItem* item : m_items) { const std::string& icon_filename = item->get_icon_filename(); if (!icon_filename.empty()) filenames.push_back(path + icon_filename); } std::vector> states; - if (m_type == Normal) - { + if (m_type == Normal) { states.push_back({ 1, false }); // Normal states.push_back({ 0, false }); // Pressed states.push_back({ 2, false }); // Disabled @@ -1236,8 +1220,7 @@ bool GLToolbar::generate_icons_texture() const states.push_back({ 0, false }); // HoverPressed states.push_back({ 2, false }); // HoverDisabled } - else - { + else { states.push_back({ 1, false }); // Normal states.push_back({ 1, true }); // Pressed states.push_back({ 1, false }); // Disabled @@ -1251,9 +1234,9 @@ bool GLToolbar::generate_icons_texture() const // if (sprite_size_px % 2 != 0) // sprite_size_px += 1; - bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, sprite_size_px, false); + bool res = const_cast(&m_icons_texture)->load_from_svg_files_as_sprites_array(filenames, states, sprite_size_px, false); if (res) - m_icons_texture_dirty = false; + *const_cast(&m_icons_texture_dirty) = false; return res; } @@ -1262,8 +1245,7 @@ bool GLToolbar::update_items_visibility() { bool ret = false; - for (GLToolbarItem* item : m_items) - { + for (GLToolbarItem* item : m_items) { ret |= item->update_visibility(); } @@ -1272,12 +1254,10 @@ bool GLToolbar::update_items_visibility() // updates separators visibility to avoid having two of them consecutive bool any_item_visible = false; - for (GLToolbarItem* item : m_items) - { + for (GLToolbarItem* item : m_items) { if (!item->is_separator()) any_item_visible |= item->is_visible(); - else - { + else { item->set_visible(any_item_visible); any_item_visible = false; } diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 74e18de975..3237c44953 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -233,10 +233,10 @@ private: EType m_type; std::string m_name; bool m_enabled; - mutable GLTexture m_icons_texture; - mutable bool m_icons_texture_dirty; + GLTexture m_icons_texture; + bool m_icons_texture_dirty; BackgroundTexture m_background_texture; - mutable Layout m_layout; + Layout m_layout; ItemsList m_items; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 610e5f07ac..8b091e7b8a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -244,10 +244,11 @@ private: // credits infornation credits = title + " " + - _L("is based on Slic3r by Alessandro Ranellucci and the RepRap community.") + "\n\n" + + _L("is based on Slic3r by Alessandro Ranellucci and the RepRap community.") + "\n" + + _L("Developed by Prusa Research.")+ "\n\n" + title + " " + _L("is licensed under the") + " " + _L("GNU Affero General Public License, version 3") + "\n\n" + _L("Contributions by Vojtech Bubnik, Enrico Turri, Oleksandra Iushchenko, Tamas Meszaros, Lukas Matena, Vojtech Kral, David Kocik and numerous others.") + "\n\n" + - _L("Artwork model by Nora Al-Badri and Jan Nikolai Nelles"); + _L("Artwork model by M Boyer"); title_font = version_font = credits_font = init_font; } @@ -691,7 +692,7 @@ void GUI_App::init_app_config() { // Profiles for the alpha are stored into the PrusaSlicer-alpha directory to not mix with the current release. // SetAppName(SLIC3R_APP_KEY); - SetAppName(SLIC3R_APP_KEY "-beta"); + SetAppName(SLIC3R_APP_KEY "-alpha"); // SetAppDisplayName(SLIC3R_APP_NAME); // Set the Slic3r data directory at the Slic3r XS module. diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index 0bd523b261..01ea53ad37 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -858,10 +858,6 @@ void MenuFactory::create_sla_object_menu() []() { return plater()->can_split(true); }, m_parent); m_sla_object_menu.AppendSeparator(); - - // Add the automatic rotation sub-menu - append_menu_item(&m_sla_object_menu, wxID_ANY, _L("Optimize orientation"), _L("Optimize the rotation of the object for better print results."), - [](wxCommandEvent&) { plater()->optimize_rotation(); }); } void MenuFactory::create_part_menu() diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index bce64f9ea7..f687dc38e8 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1531,14 +1531,20 @@ void ObjectList::del_subobject_item(wxDataViewItem& item) if (type == itUndef) return; + wxDataViewItem parent = m_objects_model->GetParent(item); + if (type & itSettings) - del_settings_from_config(m_objects_model->GetParent(item)); + del_settings_from_config(parent); else if (type & itInstanceRoot && obj_idx != -1) del_instances_from_object(obj_idx); else if (type & itLayerRoot && obj_idx != -1) del_layers_from_object(obj_idx); else if (type & itLayer && obj_idx != -1) del_layer_from_object(obj_idx, m_objects_model->GetLayerRangeByItem(item)); + else if (type & itInfo && obj_idx != -1) { + Unselect(item); + Select(parent); + } else if (idx == -1) return; else if (!del_subobject_from_object(obj_idx, idx, type)) @@ -1546,9 +1552,10 @@ void ObjectList::del_subobject_item(wxDataViewItem& item) // If last volume item with warning was deleted, unmark object item if (type & itVolume && (*m_objects)[obj_idx]->get_mesh_errors_count() == 0) - m_objects_model->DeleteWarningIcon(m_objects_model->GetParent(item)); + m_objects_model->DeleteWarningIcon(parent); m_objects_model->Delete(item); + update_info_items(obj_idx); } void ObjectList::del_settings_from_config(const wxDataViewItem& parent_item) @@ -2124,20 +2131,32 @@ void ObjectList::part_selection_changed() { if (item) { - if (m_objects_model->GetParent(item) == wxDataViewItem(nullptr)) { - obj_idx = m_objects_model->GetIdByItem(item); + const ItemType type = m_objects_model->GetItemType(item); + const wxDataViewItem parent = m_objects_model->GetParent(item); + const ItemType parent_type = m_objects_model->GetItemType(parent); + obj_idx = m_objects_model->GetObjectIdByItem(item); + + if (parent == wxDataViewItem(nullptr) + || type == itInfo) { og_name = _(L("Object manipulation")); m_config = &(*m_objects)[obj_idx]->config; update_and_show_manipulations = true; + + if (type == itInfo) { + InfoItemType info_type = m_objects_model->GetInfoItemType(item); + if (info_type != InfoItemType::VariableLayerHeight) { + GLGizmosManager::EType gizmo_type = + info_type == InfoItemType::CustomSupports ? GLGizmosManager::EType::FdmSupports + : GLGizmosManager::EType::Seam; + GLGizmosManager& gizmos_mgr = wxGetApp().plater()->canvas3D()->get_gizmos_manager(); + if (gizmos_mgr.get_current_type() != gizmo_type) + gizmos_mgr.open_gizmo(gizmo_type); + } else + wxGetApp().plater()->toggle_layers_editing(true); + } } else { - obj_idx = m_objects_model->GetObjectIdByItem(item); - - const ItemType type = m_objects_model->GetItemType(item); if (type & itSettings) { - const auto parent = m_objects_model->GetParent(item); - const ItemType parent_type = m_objects_model->GetItemType(parent); - if (parent_type & itObject) { og_name = _(L("Object Settings to modify")); m_config = &(*m_objects)[obj_idx]->config; @@ -2249,6 +2268,52 @@ wxDataViewItem ObjectList::add_settings_item(wxDataViewItem parent_item, const D return ret; } + +void ObjectList::update_info_items(size_t obj_idx) +{ + const ModelObject* model_object = (*m_objects)[obj_idx]; + wxDataViewItem item_obj = m_objects_model->GetItemById(obj_idx); + assert(item_obj.IsOk()); + + for (InfoItemType type : {InfoItemType::CustomSupports, + InfoItemType::CustomSeam, + InfoItemType::VariableLayerHeight}) { + wxDataViewItem item = m_objects_model->GetInfoItemByType(item_obj, type); + bool shows = item.IsOk(); + bool should_show = false; + + switch (type) { + case InfoItemType::CustomSupports : + case InfoItemType::CustomSeam : + should_show = printer_technology() == ptFFF + && std::any_of(model_object->volumes.begin(), model_object->volumes.end(), + [type](const ModelVolume* mv) { + return ! (type == InfoItemType::CustomSupports + ? mv->supported_facets.empty() + : mv->seam_facets.empty()); + }); + break; + + case InfoItemType::VariableLayerHeight : + should_show = printer_technology() == ptFFF + && ! model_object->layer_height_profile.empty(); + break; + } + + if (! shows && should_show) { + m_objects_model->AddInfoChild(item_obj, type); + Expand(item_obj); + } + else if (shows && ! should_show) { + Unselect(item); + m_objects_model->Delete(item); + Select(item_obj); + } + } +} + + + void ObjectList::add_object_to_list(size_t obj_idx, bool call_selection_changed) { auto model_object = (*m_objects)[obj_idx]; @@ -2257,6 +2322,8 @@ void ObjectList::add_object_to_list(size_t obj_idx, bool call_selection_changed) model_object->config.has("extruder") ? model_object->config.extruder() : 0, get_mesh_errors_count(obj_idx) > 0); + update_info_items(obj_idx); + // add volumes to the object if (model_object->volumes.size() > 1) { for (const ModelVolume* volume : model_object->volumes) { @@ -2835,7 +2902,8 @@ void ObjectList::update_selections() { const auto item = GetSelection(); if (selection.is_single_full_object()) { - if (m_objects_model->GetItemType(m_objects_model->GetParent(item)) & itObject) + if (m_objects_model->GetItemType(m_objects_model->GetParent(item)) & itObject && + m_objects_model->GetObjectIdByItem(item) == selection.get_object_idx() ) return; sels.Add(m_objects_model->GetItemById(selection.get_object_idx())); } @@ -3035,7 +3103,7 @@ void ObjectList::update_selections_on_canvas() if (sel_cnt == 1) { wxDataViewItem item = GetSelection(); - if (m_objects_model->GetItemType(item) & (itSettings | itInstanceRoot | itLayerRoot | itLayer)) + if (m_objects_model->GetItemType(item) & (itSettings | itInstanceRoot | itLayerRoot | itLayer | itInfo)) add_to_selection(m_objects_model->GetParent(item), selection, instance_idx, mode); else add_to_selection(item, selection, instance_idx, mode); @@ -3448,6 +3516,9 @@ void ObjectList::update_object_list_by_printer_technology() m_objects_model->GetChildren(wxDataViewItem(nullptr), object_items); for (auto& object_item : object_items) { + // update custom supports info + update_info_items(m_objects_model->GetObjectIdByItem(object_item)); + // Update Settings Item for object update_settings_item_and_selection(object_item, sel); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index d70c53849d..5812e26f75 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -18,7 +18,6 @@ class wxBoxSizer; class wxBitmapComboBox; class wxMenuItem; -class ObjectDataViewModel; class MenuWithSeparators; namespace Slic3r { @@ -347,6 +346,7 @@ public: void update_and_show_object_settings_item(); void update_settings_item_and_selection(wxDataViewItem item, wxDataViewItemArray& selections); void update_object_list_by_printer_technology(); + void update_info_items(size_t obj_idx); void instances_to_separated_object(const int obj_idx, const std::set& inst_idx); void instances_to_separated_objects(const int obj_idx); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index e67ddb0452..ea289bb146 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -235,7 +235,7 @@ bool Preview::init(wxWindow* parent, Model* model) _L("Ironing") + "|1|" + _L("Bridge infill") + "|1|" + _L("Gap fill") + "|1|" + - _L("Skirt") + "|1|" + + _L("Skirt/Brim") + "|1|" + _L("Support material") + "|1|" + _L("Support material interface") + "|1|" + _L("Wipe tower") + "|1|" + @@ -250,6 +250,9 @@ bool Preview::init(wxWindow* parent, Model* model) get_option_type_string(OptionType::Wipe) + "|0|" + get_option_type_string(OptionType::Retractions) + "|0|" + get_option_type_string(OptionType::Unretractions) + "|0|" + +#if ENABLE_SEAMS_VISUALIZATION + get_option_type_string(OptionType::Seams) + "|0|" + +#endif // ENABLE_SEAMS_VISUALIZATION get_option_type_string(OptionType::ToolChanges) + "|0|" + get_option_type_string(OptionType::ColorChanges) + "|0|" + get_option_type_string(OptionType::PausePrints) + "|0|" + @@ -1008,6 +1011,9 @@ wxString Preview::get_option_type_string(OptionType type) const case OptionType::Wipe: { return _L("Wipe"); } case OptionType::Retractions: { return _L("Retractions"); } case OptionType::Unretractions: { return _L("Deretractions"); } +#if ENABLE_SEAMS_VISUALIZATION + case OptionType::Seams: { return _L("Seams"); } +#endif // ENABLE_SEAMS_VISUALIZATION case OptionType::ToolChanges: { return _L("Tool changes"); } case OptionType::ColorChanges: { return _L("Color changes"); } case OptionType::PausePrints: { return _L("Print pauses"); } diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 3bf0e21ae3..d49e6e7ac1 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -116,6 +116,9 @@ public: Wipe, Retractions, Unretractions, +#if ENABLE_SEAMS_VISUALIZATION + Seams, +#endif // ENABLE_SEAMS_VISUALIZATION ToolChanges, ColorChanges, PausePrints, diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index f3f87cc33e..d870687129 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -7,6 +7,7 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/ImGuiWrapper.hpp" #include "slic3r/GUI/Plater.hpp" +#include "slic3r/GUI/GUI_ObjectList.hpp" #include @@ -316,8 +317,12 @@ void GLGizmoFdmSupports::update_model_object() const updated |= mv->supported_facets.set(*m_triangle_selectors[idx].get()); } - if (updated) + if (updated) { + const ModelObjectPtrs& mos = wxGetApp().model().objects; + wxGetApp().obj_list()->update_info_items(std::find(mos.begin(), mos.end(), mo) - mos.begin()); + m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index c5060a88ed..6b6905e4d2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -7,9 +7,10 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI.hpp" +#include "slic3r/GUI/Plater.hpp" #include "libslic3r/PresetBundle.hpp" -#include "libslic3r/SLA/Rotfinder.hpp" +#include "slic3r/GUI/Jobs/RotoptimizeJob.hpp" namespace Slic3r { namespace GUI { @@ -204,6 +205,30 @@ void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limi { if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA) return; + + RotoptimzeWindow popup{m_imgui, m_rotoptimizewin_state, {x, y, bottom_limit}}; +} + +void GLGizmoRotate3D::load_rotoptimize_state() +{ + std::string accuracy_str = + wxGetApp().app_config->get("sla_auto_rotate", "accuracy"); + + std::string method_str = + wxGetApp().app_config->get("sla_auto_rotate", "method_id"); + + if (!accuracy_str.empty()) { + float accuracy = std::stof(accuracy_str); + accuracy = std::max(0.f, std::min(accuracy, 1.f)); + + m_rotoptimizewin_state.accuracy = accuracy; + } + + if (!method_str.empty()) { + int method_id = std::stoi(method_str); + if (method_id < int(RotoptimizeJob::get_methods_count())) + m_rotoptimizewin_state.method_id = method_id; + } } void GLGizmoRotate::render_circle() const @@ -436,6 +461,8 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_fil { m_gizmos[i].set_group_id(i); } + + load_rotoptimize_state(); } bool GLGizmoRotate3D::on_init() @@ -492,5 +519,51 @@ void GLGizmoRotate3D::on_render() const m_gizmos[Z].render(); } +const char * GLGizmoRotate3D::RotoptimzeWindow::options[RotoptimizeJob::get_methods_count()]; +bool GLGizmoRotate3D::RotoptimzeWindow::options_valid = false; + +GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui, + State & state, + const Alignment &alignment) + : m_imgui{imgui} +{ + imgui->begin(_L("Optimize orientation"), ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoCollapse); + + // adjust window position to avoid overlap the view toolbar + float win_h = ImGui::GetWindowHeight(); + float x = alignment.x, y = alignment.y; + y = std::min(y, alignment.bottom_limit - win_h); + ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always); + + ImGui::PushItemWidth(200.f); + + size_t methods_cnt = RotoptimizeJob::get_methods_count(); + if (!options_valid) { + for (size_t i = 0; i < methods_cnt; ++i) + options[i] = RotoptimizeJob::get_method_names()[i].c_str(); + + options_valid = true; + } + + int citem = state.method_id; + if (ImGui::Combo(_L("Choose goal").c_str(), &citem, options, methods_cnt) ) { + state.method_id = citem; + wxGetApp().app_config->set("sla_auto_rotate", "method_id", std::to_string(state.method_id)); + } + + ImGui::Separator(); + + if ( imgui->button(_L("Optimize")) ) { + wxGetApp().plater()->optimize_rotation(); + } +} + +GLGizmoRotate3D::RotoptimzeWindow::~RotoptimzeWindow() +{ + m_imgui->end(); +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index 126c97b1dd..c18d0eefd9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -2,6 +2,7 @@ #define slic3r_GLGizmoRotate_hpp_ #include "GLGizmoBase.hpp" +#include "../Jobs/RotoptimizeJob.hpp" namespace Slic3r { @@ -136,6 +137,39 @@ protected: } void on_render_input_window(float x, float y, float bottom_limit) override; + +private: + + class RotoptimzeWindow { + ImGuiWrapper *m_imgui = nullptr; + + static const char * options []; + static bool options_valid; + + public: + + struct State { + float accuracy = 1.f; + int method_id = 0; + }; + + struct Alignment { float x, y, bottom_limit; }; + + RotoptimzeWindow(ImGuiWrapper * imgui, + State & state, + const Alignment &bottom_limit); + + ~RotoptimzeWindow(); + + RotoptimzeWindow(const RotoptimzeWindow&) = delete; + RotoptimzeWindow(RotoptimzeWindow &&) = delete; + RotoptimzeWindow& operator=(const RotoptimzeWindow &) = delete; + RotoptimzeWindow& operator=(RotoptimzeWindow &&) = delete; + }; + + RotoptimzeWindow::State m_rotoptimizewin_state = {}; + + void load_rotoptimize_state(); }; } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp index 6c3a8ddd3a..9724767550 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp @@ -7,7 +7,7 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/ImGuiWrapper.hpp" #include "slic3r/GUI/Plater.hpp" - +#include "slic3r/GUI/GUI_ObjectList.hpp" #include @@ -222,8 +222,12 @@ void GLGizmoSeam::update_model_object() const updated |= mv->seam_facets.set(*m_triangle_selectors[idx].get()); } - if (updated) + if (updated) { + const ModelObjectPtrs& mos = wxGetApp().model().objects; + wxGetApp().obj_list()->update_info_items(std::find(mos.begin(), mos.end(), mo) - mos.begin()); + m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); + } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 9dc785b3fa..2f1396d634 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -163,6 +163,17 @@ void GLGizmosManager::reset_all_states() m_hover = Undefined; } +bool GLGizmosManager::open_gizmo(EType type) +{ + int idx = int(type); + if (m_gizmos[idx]->is_selectable() && m_gizmos[idx]->is_activable()) { + activate_gizmo(m_current == idx ? Undefined : (EType)idx); + update_data(); + return true; + } + return false; +} + void GLGizmosManager::set_hover_id(int id) { if (!m_enabled || m_current == Undefined) @@ -266,24 +277,21 @@ bool GLGizmosManager::is_running() const bool GLGizmosManager::handle_shortcut(int key) { - if (!m_enabled) + if (!m_enabled || m_parent.get_selection().is_empty()) return false; - if (m_parent.get_selection().is_empty()) + auto it = std::find_if(m_gizmos.begin(), m_gizmos.end(), + [key](const std::unique_ptr& gizmo) { + int gizmo_key = gizmo->get_shortcut_key(); + return gizmo->is_selectable() + && ((gizmo_key == key - 64) || (gizmo_key == key - 96)); + }); + + if (it == m_gizmos.end()) return false; - bool handled = false; - - for (size_t idx : get_selectable_idxs()) { - int it_key = m_gizmos[idx]->get_shortcut_key(); - - if (m_gizmos[idx]->is_activable() && ((it_key == key - 64) || (it_key == key - 96))) { - activate_gizmo(m_current == idx ? Undefined : (EType)idx); - handled = true; - } - } - - return handled; + EType gizmo_type = EType(it - m_gizmos.begin()); + return open_gizmo(gizmo_type); } bool GLGizmosManager::is_dragging() const @@ -814,10 +822,7 @@ bool GLGizmosManager::on_char(wxKeyEvent& evt) if (!processed && !evt.HasModifiers()) { if (handle_shortcut(keyCode)) - { - update_data(); processed = true; - } } if (processed) @@ -1156,5 +1161,11 @@ bool GLGizmosManager::is_in_editing_mode(bool error_notification) const return true; } + +int GLGizmosManager::get_shortcut_key(GLGizmosManager::EType type) const +{ + return m_gizmos[type]->get_shortcut_key(); +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 917a5830c2..c8951966e6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -171,6 +171,7 @@ public: void refresh_on_off_state(); void reset_all_states(); bool is_serializing() const { return m_serializing; } + bool open_gizmo(EType type); void set_hover_id(int id); void enable_grabber(EType type, unsigned int id, bool enable); @@ -228,6 +229,7 @@ public: void update_after_undo_redo(const UndoRedo::Snapshot& snapshot); int get_selectable_icons_cnt() const { return get_selectable_idxs().size(); } + int get_shortcut_key(GLGizmosManager::EType) const; private: void render_background(float left, float top, float right, float bottom, float border) const; diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 3f1207b479..391c1fe284 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -78,7 +78,7 @@ void ArrangeJob::prepare_all() { for (ModelObject *obj: m_plater->model().objects) for (ModelInstance *mi : obj->instances) { ArrangePolygons & cont = mi->printable ? m_selected : m_unprintable; - cont.emplace_back(get_arrange_poly(PtrWrapper{mi}, m_plater)); + cont.emplace_back(get_arrange_poly(mi, m_plater)); } if (auto wti = get_wipe_tower_arrangepoly(*m_plater)) @@ -111,7 +111,7 @@ void ArrangeJob::prepare_selected() { for (size_t i = 0; i < inst_sel.size(); ++i) { ArrangePolygon &&ap = - get_arrange_poly(PtrWrapper{mo->instances[i]}, m_plater); + get_arrange_poly(mo->instances[i], m_plater); ArrangePolygons &cont = mo->instances[i]->printable ? (inst_sel[i] ? m_selected : @@ -161,12 +161,7 @@ void ArrangeJob::process() { static const auto arrangestr = _(L("Arranging")); - const GLCanvas3D::ArrangeSettings &settings = - static_cast(m_plater->canvas3D())->get_arrange_settings(); - - arrangement::ArrangeParams params; - params.allow_rotations = settings.enable_rotation; - params.min_obj_distance = scaled(settings.distance); + arrangement::ArrangeParams params = get_arrange_params(m_plater); auto count = unsigned(m_selected.size() + m_unprintable.size()); Points bedpts = get_bed_shape(*m_plater->config()); @@ -235,4 +230,23 @@ double bed_stride(const Plater *plater) { return scaled((1. + LOGICAL_BED_GAP) * bedwidth); } +template<> +arrangement::ArrangePolygon get_arrange_poly(ModelInstance *inst, + const Plater * plater) +{ + return get_arrange_poly(PtrWrapper{inst}, plater); +} + +arrangement::ArrangeParams get_arrange_params(Plater *p) +{ + const GLCanvas3D::ArrangeSettings &settings = + static_cast(p->canvas3D())->get_arrange_settings(); + + arrangement::ArrangeParams params; + params.allow_rotations = settings.enable_rotation; + params.min_obj_distance = scaled(settings.distance); + + return params; +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.hpp b/src/slic3r/GUI/Jobs/ArrangeJob.hpp index 38aafb52c1..7fa4b927e6 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.hpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.hpp @@ -4,7 +4,11 @@ #include "PlaterJob.hpp" #include "libslic3r/Arrange.hpp" -namespace Slic3r { namespace GUI { +namespace Slic3r { + +class ModelInstance; + +namespace GUI { class ArrangeJob : public PlaterJob { @@ -89,6 +93,11 @@ arrangement::ArrangePolygon get_arrange_poly(T obj, const Plater *plater) return ap; } +template<> +arrangement::ArrangePolygon get_arrange_poly(ModelInstance *inst, + const Plater * plater); + +arrangement::ArrangeParams get_arrange_params(Plater *p); }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Jobs/Job.cpp b/src/slic3r/GUI/Jobs/Job.cpp index 1f7f58875b..6346227aab 100644 --- a/src/slic3r/GUI/Jobs/Job.cpp +++ b/src/slic3r/GUI/Jobs/Job.cpp @@ -24,7 +24,7 @@ void GUI::Job::run(std::exception_ptr &eptr) void GUI::Job::update_status(int st, const wxString &msg) { - auto evt = new wxThreadEvent(); + auto evt = new wxThreadEvent(wxEVT_THREAD, m_thread_evt_id); evt->SetInt(st); evt->SetString(msg); wxQueueEvent(this, evt); @@ -33,7 +33,11 @@ void GUI::Job::update_status(int st, const wxString &msg) GUI::Job::Job(std::shared_ptr pri) : m_progress(std::move(pri)) { - Bind(wxEVT_THREAD, [this](const wxThreadEvent &evt) { + m_thread_evt_id = wxNewId(); + + Bind(wxEVT_THREAD, [this](const wxThreadEvent &evt) { + if (m_finalizing) return; + auto msg = evt.GetString(); if (!msg.empty() && !m_worker_error) m_progress->set_status_text(msg.ToUTF8().data()); @@ -53,13 +57,27 @@ GUI::Job::Job(std::shared_ptr pri) m_progress->set_progress(m_range); on_exception(m_worker_error); } - else + else { + // This is an RAII solution to remember that finalization is + // running. The run method calls update_status(status_range(), "") + // at the end, which queues up a call to this handler in all cases. + // If process also calls update_status with maxed out status arg + // it will call this handler twice. It is not a problem unless + // yield is called inside the finilize() method, which would + // jump out of finalize and call this handler again. + struct Finalizing { + bool &flag; + Finalizing (bool &f): flag(f) { flag = true; } + ~Finalizing() { flag = false; } + } fin(m_finalizing); + finalize(); + } // dont do finalization again for the same process m_finalized = true; } - }); + }, m_thread_evt_id); } void GUI::Job::start() @@ -76,7 +94,8 @@ void GUI::Job::start() m_progress->set_cancel_callback( [this]() { m_canceled.store(true); }); - m_finalized = false; + m_finalized = false; + m_finalizing = false; // Changing cursor to busy wxBeginBusyCursor(); diff --git a/src/slic3r/GUI/Jobs/Job.hpp b/src/slic3r/GUI/Jobs/Job.hpp index cb73fe74d4..082e5f4e8b 100644 --- a/src/slic3r/GUI/Jobs/Job.hpp +++ b/src/slic3r/GUI/Jobs/Job.hpp @@ -29,9 +29,10 @@ namespace Slic3r { namespace GUI { class Job : public wxEvtHandler { int m_range = 100; + int m_thread_evt_id = wxID_ANY; boost::thread m_thread; std::atomic m_running{false}, m_canceled{false}; - bool m_finalized = false; + bool m_finalized = false, m_finalizing = false; std::shared_ptr m_progress; std::exception_ptr m_worker_error = nullptr; diff --git a/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp b/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp index 978ccf8fcf..a670affefb 100644 --- a/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp +++ b/src/slic3r/GUI/Jobs/RotoptimizeJob.cpp @@ -7,47 +7,84 @@ #include "libslic3r/SLAPrint.hpp" #include "slic3r/GUI/Plater.hpp" +#include "libslic3r/PresetBundle.hpp" + +#include "slic3r/GUI/GUI_App.hpp" +#include "libslic3r/AppConfig.hpp" namespace Slic3r { namespace GUI { +void RotoptimizeJob::prepare() +{ + std::string accuracy_str = + wxGetApp().app_config->get("sla_auto_rotate", "accuracy"); + + std::string method_str = + wxGetApp().app_config->get("sla_auto_rotate", "method_id"); + + if (!accuracy_str.empty()) + m_accuracy = std::stof(accuracy_str); + + if (!method_str.empty()) + m_method_id = std::stoi(method_str); + + m_accuracy = std::max(0.f, std::min(m_accuracy, 1.f)); + m_method_id = std::max(size_t(0), std::min(get_methods_count() - 1, m_method_id)); + + m_default_print_cfg = wxGetApp().preset_bundle->full_config(); + + const auto &sel = m_plater->get_selection().get_content(); + + m_selected_object_ids.clear(); + m_selected_object_ids.reserve(sel.size()); + for (auto &[obj_idx, ignore] : sel) + m_selected_object_ids.emplace_back(obj_idx); +} + void RotoptimizeJob::process() { - int obj_idx = m_plater->get_selected_object_idx(); - if (obj_idx < 0 || int(m_plater->sla_print().objects().size()) <= obj_idx) - return; - - ModelObject *o = m_plater->model().objects[size_t(obj_idx)]; - const SLAPrintObject *po = m_plater->sla_print().objects()[size_t(obj_idx)]; + int prev_status = 0; + auto params = + sla::RotOptimizeParams{} + .accuracy(m_accuracy) + .print_config(&m_default_print_cfg) + .statucb([this, &prev_status](int s) + { + if (s > 0 && s < 100) + update_status(prev_status + s / m_selected_object_ids.size(), + _(L("Searching for optimal orientation"))); - if (!o || !po) return; - - TriangleMesh mesh = o->raw_mesh(); - mesh.require_shared_vertices(); - -// for (auto inst : o->instances) { -// Transform3d tr = Transform3d::Identity(); -// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(Z), Vec3d::UnitZ())); -// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(Y), Vec3d::UnitY())); -// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(X), Vec3d::UnitX())); - -// double score = sla::get_model_supportedness(*po, tr); - -// std::cout << "Model supportedness before: " << score << std::endl; -// } - - Vec2d r = sla::find_best_rotation(*po, 0.75f, - [this](unsigned s) { - if (s < 100) - update_status(int(s), _(L("Searching for optimal orientation"))); - }, - [this] () { return was_canceled(); }); + return !was_canceled(); + }); - double mindist = 6.0; // FIXME + for (ObjRot &objrot : m_selected_object_ids) { + ModelObject *o = m_plater->model().objects[size_t(objrot.idx)]; + if (!o) continue; + + if (Methods[m_method_id].findfn) + objrot.rot = Methods[m_method_id].findfn(*o, params); + + prev_status += 100 / m_selected_object_ids.size(); + + if (was_canceled()) break; + } + + update_status(100, was_canceled() ? _(L("Orientation search canceled.")) : + _(L("Orientation found."))); +} + +void RotoptimizeJob::finalize() +{ + if (was_canceled()) return; + + for (const ObjRot &objrot : m_selected_object_ids) { + ModelObject *o = m_plater->model().objects[size_t(objrot.idx)]; + if (!o) continue; - if (!was_canceled()) { for(ModelInstance * oi : o->instances) { - oi->set_rotation({r[X], r[Y], 0.}); + if (objrot.rot) + oi->set_rotation({objrot.rot->x(), objrot.rot->y(), 0.}); auto trmatrix = oi->get_transformation().get_matrix(); Polygon trchull = o->convex_hull_2d(trmatrix); @@ -63,19 +100,13 @@ void RotoptimizeJob::process() oi->set_rotation(rt); } - m_plater->find_new_position(o->instances, scaled(mindist)); - // Correct the z offset of the object which was corrupted be // the rotation o->ensure_on_bed(); + +// m_plater->find_new_position(o->instances); } - update_status(100, was_canceled() ? _(L("Orientation search canceled.")) : - _(L("Orientation found."))); -} - -void RotoptimizeJob::finalize() -{ if (!was_canceled()) m_plater->update(); diff --git a/src/slic3r/GUI/Jobs/RotoptimizeJob.hpp b/src/slic3r/GUI/Jobs/RotoptimizeJob.hpp index 06688b52d9..3144f3c3e6 100644 --- a/src/slic3r/GUI/Jobs/RotoptimizeJob.hpp +++ b/src/slic3r/GUI/Jobs/RotoptimizeJob.hpp @@ -3,17 +3,70 @@ #include "PlaterJob.hpp" -namespace Slic3r { namespace GUI { +#include "libslic3r/SLA/Rotfinder.hpp" +#include "libslic3r/PrintConfig.hpp" + +namespace Slic3r { + +namespace GUI { class RotoptimizeJob : public PlaterJob { + using FindFn = std::function; + + struct FindMethod { std::string name; FindFn findfn; }; + + static inline const FindMethod Methods[] = { + { L("Best surface quality"), sla::find_best_misalignment_rotation }, + { L("Least supports"), sla::find_least_supports_rotation }, + // Just a min area bounding box that is done for all methods anyway. + { L("Z axis only"), nullptr } + }; + + size_t m_method_id = 0; + float m_accuracy = 0.75; + + DynamicPrintConfig m_default_print_cfg; + + struct ObjRot + { + size_t idx; + std::optional rot; + ObjRot(size_t id): idx{id}, rot{} {} + }; + + std::vector m_selected_object_ids; + +protected: + + void prepare() override; + public: + RotoptimizeJob(std::shared_ptr pri, Plater *plater) : PlaterJob{std::move(pri), plater} {} void process() override; void finalize() override; + + static constexpr size_t get_methods_count() { return std::size(Methods); } + static const auto & get_method_names() + { + static bool m_method_names_valid = false; + static std::array m_method_names; + + if (!m_method_names_valid) { + + for (size_t i = 0; i < std::size(Methods); ++i) + m_method_names[i] = _utf8(Methods[i].name); + + m_method_names_valid = true; + } + + return m_method_names; + } }; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index f9fbef8a8f..3da937f0ac 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -132,7 +132,8 @@ SLAImportJob::~SLAImportJob() = default; void SLAImportJob::process() { auto progr = [this](int s) { - if (s < 100) update_status(int(s), _(L("Importing SLA archive"))); + if (s < 100) + update_status(int(s), _(L("Importing SLA archive"))); return !was_canceled(); }; @@ -178,7 +179,7 @@ void SLAImportJob::prepare() if (dlg.ShowModal() == wxID_OK) { auto path = dlg.get_path(); auto nm = wxFileName(path); - p->path = !nm.Exists(wxFILE_EXISTS_REGULAR) ? "" : path.ToUTF8(); + p->path = !nm.Exists(wxFILE_EXISTS_REGULAR) ? "" : nm.GetFullPath(); p->sel = dlg.get_selection(); p->win = dlg.get_marchsq_windowsize(); } else { diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index f556431f6f..8c54e10f87 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -534,6 +534,10 @@ void MainFrame::init_tabpanel() m_tabpanel = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList m_tabpanel->SetFont(Slic3r::GUI::wxGetApp().normal_font()); +#endif +#if wxCHECK_VERSION(3,1,3) + if (wxSystemSettings::GetAppearance().IsDark()) + m_tabpanel->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); #endif m_tabpanel->Hide(); m_settings_dialog.set_tabpanel(m_tabpanel); @@ -877,6 +881,9 @@ void MainFrame::on_sys_color_changed() // update label colors in respect to the system mode wxGetApp().init_label_colours(); +#ifdef __WXMSW__ + m_tabpanel->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif // update Plater wxGetApp().plater()->sys_color_changed(); @@ -1526,10 +1533,10 @@ void MainFrame::repair_stl() output_file = dlg.GetPath(); } - auto tmesh = new Slic3r::TriangleMesh(); - tmesh->ReadSTLFile(input_file.ToUTF8().data()); - tmesh->repair(); - tmesh->WriteOBJFile(output_file.ToUTF8().data()); + Slic3r::TriangleMesh tmesh; + tmesh.ReadSTLFile(input_file.ToUTF8().data()); + tmesh.repair(); + tmesh.WriteOBJFile(output_file.ToUTF8().data()); Slic3r::GUI::show_info(this, L("Your file was repaired."), L("Repair")); } diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index e83a0014c4..7f61ad7f39 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -169,13 +169,16 @@ void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float init imgui.set_next_window_pos(win_pos.x, win_pos.y, ImGuiCond_Always, 1.0f, 0.0f); imgui.set_next_window_size(m_window_width, m_window_height, ImGuiCond_Always); - // find if hovered - if (m_state == EState::Hovered) - m_state = EState::Shown; - + + // find if hovered FIXME: do it only in update state? + if (m_state == EState::Hovered) { + m_state = EState::Unknown; + init(); + } + if (mouse_pos.x < win_pos.x && mouse_pos.x > win_pos.x - m_window_width && mouse_pos.y > win_pos.y && mouse_pos.y < win_pos.y + m_window_height) { ImGui::SetNextWindowFocus(); - m_state = EState::Hovered; + set_hovered(); } // color change based on fading out @@ -185,22 +188,8 @@ void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float init fading_pop = true; } - // background color - if (m_is_gray) { - ImVec4 backcolor(0.7f, 0.7f, 0.7f, 0.5f); - Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); - } - else if (m_data.level == NotificationLevel::ErrorNotification) { - ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg); - backcolor.x += 0.3f; - Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); - } - else if (m_data.level == NotificationLevel::WarningNotification) { - ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg); - backcolor.x += 0.3f; - backcolor.y += 0.15f; - Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); - } + bool bgrnd_color_pop = push_background_color(); + // name of window indentifies window - has to be unique string if (m_id == 0) @@ -219,13 +208,34 @@ void NotificationManager::PopNotification::render(GLCanvas3D& canvas, float init } imgui.end(); - if (m_is_gray || m_data.level == NotificationLevel::ErrorNotification || m_data.level == NotificationLevel::WarningNotification) + if (bgrnd_color_pop) ImGui::PopStyleColor(); if (fading_pop) ImGui::PopStyleColor(2); } - +bool NotificationManager::PopNotification::push_background_color() +{ + if (m_is_gray) { + ImVec4 backcolor(0.7f, 0.7f, 0.7f, 0.5f); + Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); + return true; + } + if (m_data.level == NotificationLevel::ErrorNotification) { + ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg); + backcolor.x += 0.3f; + Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); + return true; + } + if (m_data.level == NotificationLevel::WarningNotification) { + ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg); + backcolor.x += 0.3f; + backcolor.y += 0.15f; + Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); + return true; + } + return false; +} void NotificationManager::PopNotification::count_spaces() { //determine line width @@ -242,34 +252,28 @@ void NotificationManager::PopNotification::count_spaces() m_window_width = m_line_height * 25; } -void NotificationManager::PopNotification::init() +void NotificationManager::PopNotification::count_lines() { - // Do not init closing notification - if (is_finished()) - return; - - std::string text = m_text1 + " " + m_hypertext; - size_t last_end = 0; - m_lines_count = 0; + std::string text = m_text1 + " " + m_hypertext; + size_t last_end = 0; + m_lines_count = 0; - count_spaces(); - - // count lines m_endlines.clear(); while (last_end < text.length() - 1) { - size_t next_hard_end = text.find_first_of('\n', last_end); - if (next_hard_end != std::string::npos && ImGui::CalcTextSize(text.substr(last_end, next_hard_end - last_end).c_str()).x < m_window_width - m_window_width_offset) { + size_t next_hard_end = text.find_first_of('\n', last_end); + if (next_hard_end != std::string::npos && ImGui::CalcTextSize(text.substr(last_end, next_hard_end - last_end).c_str()).x < m_window_width - m_window_width_offset) { //next line is ended by '/n' m_endlines.push_back(next_hard_end); last_end = next_hard_end + 1; - } else { + } + else { // find next suitable endline if (ImGui::CalcTextSize(text.substr(last_end).c_str()).x >= m_window_width - m_window_width_offset) { // more than one line till end - size_t next_space = text.find_first_of(' ', last_end); + size_t next_space = text.find_first_of(' ', last_end); if (next_space > 0) { - size_t next_space_candidate = text.find_first_of(' ', next_space + 1); + size_t next_space_candidate = text.find_first_of(' ', next_space + 1); while (next_space_candidate > 0 && ImGui::CalcTextSize(text.substr(last_end, next_space_candidate - last_end).c_str()).x < m_window_width - m_window_width_offset) { next_space = next_space_candidate; next_space_candidate = text.find_first_of(' ', next_space + 1); @@ -283,7 +287,8 @@ void NotificationManager::PopNotification::init() } m_endlines.push_back(last_end + letter_count); last_end += letter_count; - } else { + } + else { m_endlines.push_back(next_space); last_end = next_space + 1; } @@ -297,11 +302,22 @@ void NotificationManager::PopNotification::init() } m_lines_count++; } +} + +void NotificationManager::PopNotification::init() +{ + // Do not init closing notification + if (is_finished()) + return; + + count_spaces(); + count_lines(); + if (m_lines_count == 3) m_multiline = true; m_notification_start = GLCanvas3D::timestamp_now(); - //if (m_state != EState::Hidden) - // m_state = EState::Shown; + if (m_state == EState::Unknown) + m_state = EState::Shown; } void NotificationManager::PopNotification::set_next_window_size(ImGuiWrapper& imgui) { @@ -324,8 +340,8 @@ void NotificationManager::PopNotification::render_text(ImGuiWrapper& imgui, cons if (m_multiline) { int last_end = 0; - float starting_y = m_line_height/2;//10; - float shift_y = m_line_height;// -m_line_height / 20; + float starting_y = m_line_height/2; + float shift_y = m_line_height; for (size_t i = 0; i < m_lines_count; i++) { std::string line = m_text1.substr(last_end , m_endlines[i] - last_end); if(i < m_lines_count - 1) @@ -549,7 +565,7 @@ void NotificationManager::PopNotification::update(const NotificationData& n) m_text2 = n.text2; init(); } -bool NotificationManager::PopNotification::compare_text(const std::string& text) +bool NotificationManager::PopNotification::compare_text(const std::string& text) const { std::wstring wt1 = boost::nowide::widen(m_text1); std::wstring wt2 = boost::nowide::widen(text); @@ -579,9 +595,10 @@ bool NotificationManager::PopNotification::update_state(bool paused, const int64 // reset timers - hovered state is set in render if (m_state == EState::Hovered) { m_current_fade_opacity = 1.0f; - m_notification_start = now; + m_state = EState::Unknown; + init(); // Timers when not fading - } else if (m_state != EState::FadingOut && m_data.duration != 0 && !paused) { + } else if (m_state != EState::NotFading && m_state != EState::FadingOut && m_data.duration != 0 && !paused) { int64_t up_time = now - m_notification_start; if (up_time >= m_data.duration * 1000) { m_state = EState::FadingOut; @@ -785,53 +802,154 @@ bool NotificationManager::ExportFinishedNotification::on_text_click() void NotificationManager::ProgressBarNotification::init() { PopNotification::init(); - m_lines_count++; - m_endlines.push_back(m_endlines.back()); -} -void NotificationManager::ProgressBarNotification::count_spaces() -{ - //determine line width - m_line_height = ImGui::CalcTextSize("A").y; - - m_left_indentation = m_line_height; - if (m_data.level == NotificationLevel::ErrorNotification || m_data.level == NotificationLevel::WarningNotification) { - std::string text; - text = (m_data.level == NotificationLevel::ErrorNotification ? ImGui::ErrorMarker : ImGui::WarningMarker); - float picture_width = ImGui::CalcTextSize(text.c_str()).x; - m_left_indentation = picture_width + m_line_height / 2; + //m_lines_count++; + if(m_lines_count >= 2) { + m_lines_count = 3; + m_multiline = true; + while (m_endlines.size() < 3) + m_endlines.push_back(m_endlines.back()); + } else { + m_lines_count = 2; + m_endlines.push_back(m_endlines.back()); } - m_window_width_offset = m_line_height * (m_has_cancel_button ? 6 : 4); - m_window_width = m_line_height * 25; + if(m_state == EState::Shown) + m_state = EState::NotFading; } + +void NotificationManager::ProgressBarNotification::count_lines() +{ + std::string text = m_text1 + " " + m_hypertext; + size_t last_end = 0; + m_lines_count = 0; + + m_endlines.clear(); + while (last_end < text.length() - 1) + { + size_t next_hard_end = text.find_first_of('\n', last_end); + if (next_hard_end != std::string::npos && ImGui::CalcTextSize(text.substr(last_end, next_hard_end - last_end).c_str()).x < m_window_width - m_window_width_offset) { + //next line is ended by '/n' + m_endlines.push_back(next_hard_end); + last_end = next_hard_end + 1; + } + else { + // find next suitable endline + if (ImGui::CalcTextSize(text.substr(last_end).c_str()).x >= m_window_width - m_window_width_offset) { + // more than one line till end + size_t next_space = text.find_first_of(' ', last_end); + if (next_space > 0) { + size_t next_space_candidate = text.find_first_of(' ', next_space + 1); + while (next_space_candidate > 0 && ImGui::CalcTextSize(text.substr(last_end, next_space_candidate - last_end).c_str()).x < m_window_width - m_window_width_offset) { + next_space = next_space_candidate; + next_space_candidate = text.find_first_of(' ', next_space + 1); + } + // when one word longer than line. Or the last space is too early. + if (ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x > m_window_width - m_window_width_offset || + ImGui::CalcTextSize(text.substr(last_end, next_space - last_end).c_str()).x < (m_window_width - m_window_width_offset) / 4 * 3 + ) { + float width_of_a = ImGui::CalcTextSize("a").x; + int letter_count = (int)((m_window_width - m_window_width_offset) / width_of_a); + while (last_end + letter_count < text.size() && ImGui::CalcTextSize(text.substr(last_end, letter_count).c_str()).x < m_window_width - m_window_width_offset) { + letter_count++; + } + m_endlines.push_back(last_end + letter_count); + last_end += letter_count; + } + else { + m_endlines.push_back(next_space); + last_end = next_space + 1; + } + } + } + else { + m_endlines.push_back(text.length()); + last_end = text.length(); + } + + } + m_lines_count++; + } +} + + + void NotificationManager::ProgressBarNotification::render_text(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) { // line1 - we do not print any more text than what fits on line 1. Line 2 is bar. - ImGui::SetCursorPosX(m_left_indentation); - ImGui::SetCursorPosY(win_size_y / 2 - win_size_y / 6 - m_line_height / 2); - imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); - if (m_has_cancel_button) - render_cancel_button(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); - render_bar(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); + if (m_multiline) { + // two lines text, one line bar + ImGui::SetCursorPosX(m_left_indentation); + ImGui::SetCursorPosY(m_line_height / 4); + imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); + ImGui::SetCursorPosX(m_left_indentation); + ImGui::SetCursorPosY(m_line_height + m_line_height / 4); + std::string line = m_text1.substr(m_endlines[0] + (m_text1[m_endlines[0]] == '\n' || m_text1[m_endlines[0]] == ' ' ? 1 : 0), m_endlines[1] - m_endlines[0] - (m_text1[m_endlines[0]] == '\n' || m_text1[m_endlines[0]] == ' ' ? 1 : 0)); + imgui.text(line.c_str()); + if (m_has_cancel_button) + render_cancel_button(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); + render_bar(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); + } else { + //one line text, one line bar + ImGui::SetCursorPosX(m_left_indentation); + ImGui::SetCursorPosY(/*win_size_y / 2 - win_size_y / 6 -*/ m_line_height / 4); + imgui.text(m_text1.substr(0, m_endlines[0]).c_str()); + if (m_has_cancel_button) + render_cancel_button(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); + render_bar(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); + } + } void NotificationManager::ProgressBarNotification::render_bar(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) { ImVec4 orange_color = ImVec4(.99f, .313f, .0f, 1.0f); ImVec4 gray_color = ImVec4(.34f, .34f, .34f, 1.0f); - ImVec2 lineEnd = ImVec2(win_pos_x - m_window_width_offset, win_pos_y + win_size_y / 2 + m_line_height / 4); - ImVec2 lineStart = ImVec2(win_pos_x - win_size_x + m_left_indentation, win_pos_y + win_size_y / 2 + m_line_height / 4); + ImVec2 lineEnd = ImVec2(win_pos_x - m_window_width_offset, win_pos_y + win_size_y / 2 + (m_multiline ? m_line_height / 2 : 0)); + ImVec2 lineStart = ImVec2(win_pos_x - win_size_x + m_left_indentation, win_pos_y + win_size_y / 2 + (m_multiline ? m_line_height / 2 : 0)); ImVec2 midPoint = ImVec2(lineStart.x + (lineEnd.x - lineStart.x) * m_percentage, lineStart.y); ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, IM_COL32((int)(gray_color.x * 255), (int)(gray_color.y * 255), (int)(gray_color.z * 255), (1.0f * 255.f)), m_line_height * 0.2f); ImGui::GetWindowDrawList()->AddLine(lineStart, midPoint, IM_COL32((int)(orange_color.x * 255), (int)(orange_color.y * 255), (int)(orange_color.z * 255), (1.0f * 255.f)), m_line_height * 0.2f); } //------PrintHostUploadNotification---------------- +void NotificationManager::PrintHostUploadNotification::init() +{ + ProgressBarNotification::init(); + if (m_state == EState::NotFading && m_uj_state == UploadJobState::PB_COMPLETED) + m_state = EState::Shown; +} +void NotificationManager::PrintHostUploadNotification::count_spaces() +{ + //determine line width + m_line_height = ImGui::CalcTextSize("A").y; + + m_left_indentation = m_line_height; + if (m_uj_state == UploadJobState::PB_ERROR) { + std::string text; + text = (m_data.level == NotificationLevel::ErrorNotification ? ImGui::ErrorMarker : ImGui::WarningMarker); + float picture_width = ImGui::CalcTextSize(text.c_str()).x; + m_left_indentation = picture_width + m_line_height / 2; + } + m_window_width_offset = m_line_height * 6; //(m_has_cancel_button ? 6 : 4); + m_window_width = m_line_height * 25; +} +bool NotificationManager::PrintHostUploadNotification::push_background_color() +{ + + if (m_uj_state == UploadJobState::PB_ERROR) { + ImVec4 backcolor = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg); + backcolor.x += 0.3f; + Notifications_Internal::push_style_color(ImGuiCol_WindowBg, backcolor, m_state == EState::FadingOut, m_current_fade_opacity); + return true; + } + return false; +} void NotificationManager::PrintHostUploadNotification::set_percentage(float percent) { m_percentage = percent; if (percent >= 1.0f) { m_uj_state = UploadJobState::PB_COMPLETED; m_has_cancel_button = false; + init(); } else if (percent < 0.0f) { error(); } else { @@ -846,34 +964,44 @@ void NotificationManager::PrintHostUploadNotification::render_bar(ImGuiWrapper& case Slic3r::GUI::NotificationManager::PrintHostUploadNotification::UploadJobState::PB_PROGRESS: { ProgressBarNotification::render_bar(imgui, win_size_x, win_size_y, win_pos_x, win_pos_y); - float uploaded = m_file_size / 100 * m_percentage; + float uploaded = m_file_size * m_percentage; std::stringstream stream; stream << std::fixed << std::setprecision(2) << (int)(m_percentage * 100) << "% - " << uploaded << " of " << m_file_size << "MB uploaded"; text = stream.str(); ImGui::SetCursorPosX(m_left_indentation); - ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 /*- m_line_height / 4 * 3*/); + ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - (m_multiline ? 0 : m_line_height / 4)); break; } case Slic3r::GUI::NotificationManager::PrintHostUploadNotification::UploadJobState::PB_ERROR: text = _u8L("ERROR"); ImGui::SetCursorPosX(m_left_indentation); - ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - m_line_height / 2); + ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - (m_multiline ? m_line_height / 4 : m_line_height / 2)); break; case Slic3r::GUI::NotificationManager::PrintHostUploadNotification::UploadJobState::PB_CANCELLED: text = _u8L("CANCELED"); ImGui::SetCursorPosX(m_left_indentation); - ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - m_line_height / 2); + ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - (m_multiline ? m_line_height / 4 : m_line_height / 2)); break; case Slic3r::GUI::NotificationManager::PrintHostUploadNotification::UploadJobState::PB_COMPLETED: text = _u8L("COMPLETED"); ImGui::SetCursorPosX(m_left_indentation); - ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - m_line_height / 2); + ImGui::SetCursorPosY(win_size_y / 2 + win_size_y / 6 - (m_multiline ? m_line_height / 4 : m_line_height / 2)); break; } imgui.text(text.c_str()); } +void NotificationManager::PrintHostUploadNotification::render_left_sign(ImGuiWrapper& imgui) +{ + if (m_uj_state == UploadJobState::PB_ERROR) { + std::string text; + text = ImGui::ErrorMarker; + ImGui::SetCursorPosX(m_line_height / 3); + ImGui::SetCursorPosY(m_window_height / 2 - m_line_height); + imgui.text(text.c_str()); + } +} void NotificationManager::PrintHostUploadNotification::render_cancel_button(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) { ImVec2 win_size(win_size_x, win_size_y); @@ -1059,6 +1187,14 @@ void NotificationManager::close_slicing_errors_and_warnings() } } } +void NotificationManager::close_slicing_error_notification(const std::string& text) +{ + for (std::unique_ptr& notification : m_pop_notifications) { + if (notification->get_type() == NotificationType::SlicingError && notification->compare_text(_u8L("ERROR:") + "\n" + text)) { + notification->close(); + } + } +} void NotificationManager::push_slicing_complete_notification(int timestamp, bool large) { std::string hypertext; @@ -1122,39 +1258,53 @@ void NotificationManager::push_exporting_finished_notification(const std::string void NotificationManager::push_upload_job_notification(int id, float filesize, const std::string& filename, const std::string& host, float percentage) { + // find if upload with same id was not already in notification + // done by compare_jon_id not compare_text thus has to be performed here + for (std::unique_ptr& notification : m_pop_notifications) { + if (notification->get_type() == NotificationType::PrintHostUpload && dynamic_cast(notification.get())->compare_job_id(id)) { + return; + } + } std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); - NotificationData data{ NotificationType::PrintHostUpload, NotificationLevel::ProgressBarNotification, 0, text }; + NotificationData data{ NotificationType::PrintHostUpload, NotificationLevel::ProgressBarNotification, 10, text }; push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, 0, id, filesize), 0); } void NotificationManager::set_upload_job_notification_percentage(int id, const std::string& filename, const std::string& host, float percentage) { - std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); for (std::unique_ptr& notification : m_pop_notifications) { - if (notification->get_type() == NotificationType::PrintHostUpload && notification->compare_text(text)) { - dynamic_cast(notification.get())->set_percentage(percentage); - wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + if (notification->get_type() == NotificationType::PrintHostUpload) { + PrintHostUploadNotification* phun = dynamic_cast(notification.get()); + if (phun->compare_job_id(id)) { + phun->set_percentage(percentage); + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + break; + } } } } void NotificationManager::upload_job_notification_show_canceled(int id, const std::string& filename, const std::string& host) { - std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); for (std::unique_ptr& notification : m_pop_notifications) { - if (notification->get_type() == NotificationType::PrintHostUpload && notification->compare_text(text)) { - dynamic_cast(notification.get())->cancel(); - wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); - break; + if (notification->get_type() == NotificationType::PrintHostUpload) { + PrintHostUploadNotification* phun = dynamic_cast(notification.get()); + if (phun->compare_job_id(id)) { + phun->cancel(); + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + break; + } } } } void NotificationManager::upload_job_notification_show_error(int id, const std::string& filename, const std::string& host) { - std::string text = PrintHostUploadNotification::get_upload_job_text(id, filename, host); for (std::unique_ptr& notification : m_pop_notifications) { - if (notification->get_type() == NotificationType::PrintHostUpload && notification->compare_text(text)) { - dynamic_cast(notification.get())->error(); - wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); - break; + if (notification->get_type() == NotificationType::PrintHostUpload) { + PrintHostUploadNotification* phun = dynamic_cast(notification.get()); + if(phun->compare_job_id(id)) { + phun->error(); + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + break; + } } } } diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 4f3900aeb4..17657948e6 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -125,6 +125,7 @@ public: // void set_slicing_warning_gray(const std::string& text, bool g); // immediately stops showing slicing errors void close_slicing_errors_and_warnings(); + void close_slicing_error_notification(const std::string& text); // Release those slicing warnings, which refer to an ObjectID, which is not in the list. // living_oids is expected to be sorted. void remove_slicing_warnings_of_released_objects(const std::vector& living_oids); @@ -207,6 +208,7 @@ private: Unknown, // NOT initialized Hidden, Shown, // Requesting Render at some time if duration != 0 + NotFading, // Never jumps to state Fading out even if duration says so FadingOut, // Requesting Render at some time ClosePending, // Requesting Render Finished, // Requesting Render @@ -230,18 +232,17 @@ private: const NotificationData get_data() const { return m_data; } const bool is_gray() const { return m_is_gray; } void set_gray(bool g) { m_is_gray = g; } - bool compare_text(const std::string& text); + virtual bool compare_text(const std::string& text) const; void hide(bool h) { if (is_finished()) return; m_state = h ? EState::Hidden : EState::Unknown; } // sets m_next_render with time of next mandatory rendering. Delta is time since last render. bool update_state(bool paused, const int64_t delta); int64_t next_render() const { return is_finished() ? 0 : m_next_render; } EState get_state() const { return m_state; } bool is_hovered() const { return m_state == EState::Hovered; } - + void set_hovered() { if (m_state != EState::Finished && m_state != EState::ClosePending && m_state != EState::Hidden && m_state != EState::Unknown) m_state = EState::Hovered; } + protected: // Call after every size change virtual void init(); - // Part of init() - virtual void count_spaces(); // Calculetes correct size but not se it in imgui! virtual void set_next_window_size(ImGuiWrapper& imgui); virtual void render_text(ImGuiWrapper& imgui, @@ -255,13 +256,20 @@ private: const std::string text, bool more = false); // Left sign could be error or warning sign - void render_left_sign(ImGuiWrapper& imgui); + virtual void render_left_sign(ImGuiWrapper& imgui); virtual void render_minimize_button(ImGuiWrapper& imgui, const float win_pos_x, const float win_pos_y); // Hypertext action, returns true if notification should close. // Action is stored in NotificationData::callback as std::function virtual bool on_text_click(); - protected: + + // Part of init(), counts horizontal spacing like left indentation + virtual void count_spaces(); + // Part of init(), counts end lines + virtual void count_lines(); + // returns true if PopStyleColor should be called later to pop this push + virtual bool push_background_color(); + const NotificationData m_data; // For reusing ImGUI windows. NotificationIDProvider &m_id_provider; @@ -364,7 +372,8 @@ private: virtual void set_percentage(float percent) { m_percentage = percent; } protected: virtual void init() override; - virtual void count_spaces() override; + virtual void count_lines() override; + virtual void render_text(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) override; @@ -375,6 +384,8 @@ private: const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) {} + virtual void render_minimize_button(ImGuiWrapper& imgui, + const float win_pos_x, const float win_pos_y) override {} float m_percentage; bool m_has_cancel_button {false}; @@ -401,17 +412,23 @@ private: { m_has_cancel_button = true; } - static std::string get_upload_job_text(int id, const std::string& filename, const std::string& host) { return "[" + std::to_string(id) + "] " + filename + " -> " + host; } + static std::string get_upload_job_text(int id, const std::string& filename, const std::string& host) { return /*"[" + std::to_string(id) + "] " + */filename + " -> " + host; } virtual void set_percentage(float percent) override; void cancel() { m_uj_state = UploadJobState::PB_CANCELLED; m_has_cancel_button = false; } - void error() { m_uj_state = UploadJobState::PB_ERROR; m_has_cancel_button = false; } + void error() { m_uj_state = UploadJobState::PB_ERROR; m_has_cancel_button = false; init(); } + bool compare_job_id(const int other_id) const { return m_job_id == other_id; } + virtual bool compare_text(const std::string& text) const override { return false; } protected: + virtual void init() override; + virtual void count_spaces() override; + virtual bool push_background_color() override; virtual void render_bar(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) override; virtual void render_cancel_button(ImGuiWrapper& imgui, const float win_size_x, const float win_size_y, const float win_pos_x, const float win_pos_y) override; + virtual void render_left_sign(ImGuiWrapper& imgui) override; // Identifies job in cancel callback int m_job_id; // Size of uploaded size to be displayed in MB diff --git a/src/slic3r/GUI/ObjectDataViewModel.cpp b/src/slic3r/GUI/ObjectDataViewModel.cpp index cf7b7b4796..49c75f9f2f 100644 --- a/src/slic3r/GUI/ObjectDataViewModel.cpp +++ b/src/slic3r/GUI/ObjectDataViewModel.cpp @@ -47,6 +47,19 @@ void ObjectDataViewModelNode::init_container() static constexpr char LayerRootIcon[] = "edit_layers_all"; static constexpr char LayerIcon[] = "edit_layers_some"; static constexpr char WarningIcon[] = "exclamation"; +static constexpr char InfoIcon[] = "info"; + +ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const InfoItemType info_type) : + m_parent(parent), + m_type(itInfo), + m_extruder(wxEmptyString) +{ + m_name = info_type == InfoItemType::CustomSupports ? _L("Paint-on supports") + : info_type == InfoItemType::CustomSeam ? _L("Paint-on seam") + : _L("Variable layer height"); + m_info_item_type = info_type; +} + ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const ItemType type) : m_parent(parent), @@ -69,6 +82,8 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent m_bmp = create_scaled_bitmap(LayerRootIcon); // FIXME: pass window ptr m_name = _(L("Layers")); } + else if (type == itInfo) + assert(false); if (type & (itInstanceRoot | itLayerRoot)) init_container(); @@ -250,6 +265,7 @@ ObjectDataViewModel::ObjectDataViewModel() m_volume_bmps = MenuFactory::get_volume_bitmaps(); m_warning_bmp = create_scaled_bitmap(WarningIcon); + m_info_bmp = create_scaled_bitmap(InfoIcon); } ObjectDataViewModel::~ObjectDataViewModel() @@ -330,12 +346,37 @@ wxDataViewItem ObjectDataViewModel::AddVolumeChild( const wxDataViewItem &parent return child; } +wxDataViewItem ObjectDataViewModel::AddInfoChild(const wxDataViewItem &parent_item, InfoItemType info_type) +{ + ObjectDataViewModelNode *root = static_cast(parent_item.GetID()); + if (!root) return wxDataViewItem(0); + + const auto node = new ObjectDataViewModelNode(root, info_type); + + // The new item should be added according to its order in InfoItemType. + // Find last info item with lower index and append after it. + const auto& children = root->GetChildren(); + int idx = -1; + for (int i=0; iGetType() == itInfo && int(children[i]->GetInfoItemType()) < int(info_type) ) + idx = i; + } + + root->Insert(node, idx+1); + node->SetBitmap(m_info_bmp); + // notify control + const wxDataViewItem child((void*)node); + ItemAdded(parent_item, child); + return child; +} + wxDataViewItem ObjectDataViewModel::AddSettingsChild(const wxDataViewItem &parent_item) { ObjectDataViewModelNode *root = static_cast(parent_item.GetID()); if (!root) return wxDataViewItem(0); const auto node = new ObjectDataViewModelNode(root, itSettings); + root->Insert(node, 0); // notify control const wxDataViewItem child((void*)node); @@ -1379,6 +1420,14 @@ ItemType ObjectDataViewModel::GetItemType(const wxDataViewItem &item) const return node->m_type < 0 ? itUndef : node->m_type; } +InfoItemType ObjectDataViewModel::GetInfoItemType(const wxDataViewItem &item) const +{ + if (!item.IsOk()) + return InfoItemType::Undef; + ObjectDataViewModelNode *node = static_cast(item.GetID()); + return node->m_info_item_type; +} + wxDataViewItem ObjectDataViewModel::GetItemByType(const wxDataViewItem &parent_item, ItemType type) const { if (!parent_item.IsOk()) @@ -1411,6 +1460,21 @@ wxDataViewItem ObjectDataViewModel::GetLayerRootItem(const wxDataViewItem &item) return GetItemByType(item, itLayerRoot); } +wxDataViewItem ObjectDataViewModel::GetInfoItemByType(const wxDataViewItem &parent_item, InfoItemType type) const +{ + if (! parent_item.IsOk()) + return wxDataViewItem(0); + + ObjectDataViewModelNode *node = static_cast(parent_item.GetID()); + for (size_t i = 0; i < node->GetChildCount(); i++) { + const ObjectDataViewModelNode* child_node = node->GetNthChild(i); + if (child_node->m_type == itInfo && child_node->m_info_item_type == type) + return wxDataViewItem((void*)child_node); + } + + return wxDataViewItem(0); // not found +} + bool ObjectDataViewModel::IsSettingsItem(const wxDataViewItem &item) const { if (!item.IsOk()) diff --git a/src/slic3r/GUI/ObjectDataViewModel.hpp b/src/slic3r/GUI/ObjectDataViewModel.hpp index c23ec195bd..1dd41bb107 100644 --- a/src/slic3r/GUI/ObjectDataViewModel.hpp +++ b/src/slic3r/GUI/ObjectDataViewModel.hpp @@ -27,6 +27,7 @@ enum ItemType { itSettings = 16, itLayerRoot = 32, itLayer = 64, + itInfo = 128 }; enum ColumnNumber @@ -44,6 +45,14 @@ enum PrintIndicator piUnprintable , // unprintable }; +enum class InfoItemType +{ + Undef, + CustomSupports, + CustomSeam, + VariableLayerHeight +}; + class ObjectDataViewModelNode; WX_DEFINE_ARRAY_PTR(ObjectDataViewModelNode*, MyObjectTreeModelNodePtrArray); @@ -69,6 +78,7 @@ class ObjectDataViewModelNode std::string m_action_icon_name = ""; ModelVolumeType m_volume_type; + InfoItemType m_info_item_type {InfoItemType::Undef}; public: ObjectDataViewModelNode(const wxString& name, @@ -104,6 +114,7 @@ public: const wxString& extruder = wxEmptyString ); ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const ItemType type); + ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const InfoItemType type); ~ObjectDataViewModelNode() { @@ -176,6 +187,7 @@ public: const wxBitmap& GetBitmap() const { return m_bmp; } const wxString& GetName() const { return m_name; } ItemType GetType() const { return m_type; } + InfoItemType GetInfoItemType() const { return m_info_item_type; } void SetIdx(const int& idx); int GetIdx() const { return m_idx; } ModelVolumeType GetVolumeType() { return m_volume_type; } @@ -244,6 +256,7 @@ class ObjectDataViewModel :public wxDataViewModel std::vector m_objects; std::vector m_volume_bmps; wxBitmap m_warning_bmp; + wxBitmap m_info_bmp; wxDataViewCtrl* m_ctrl { nullptr }; @@ -261,6 +274,7 @@ public: const int extruder = 0, const bool create_frst_child = true); wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item); + wxDataViewItem AddInfoChild(const wxDataViewItem &parent_item, InfoItemType info_type); wxDataViewItem AddInstanceChild(const wxDataViewItem &parent_item, size_t num); wxDataViewItem AddInstanceChild(const wxDataViewItem &parent_item, const std::vector& print_indicator); wxDataViewItem AddLayersRoot(const wxDataViewItem &parent_item); @@ -335,12 +349,15 @@ public: // In our case it is an item with all columns bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const override { return true; } - ItemType GetItemType(const wxDataViewItem &item) const ; + ItemType GetItemType(const wxDataViewItem &item) const; + InfoItemType GetInfoItemType(const wxDataViewItem &item) const; wxDataViewItem GetItemByType( const wxDataViewItem &parent_item, ItemType type) const; wxDataViewItem GetSettingsItem(const wxDataViewItem &item) const; wxDataViewItem GetInstanceRootItem(const wxDataViewItem &item) const; wxDataViewItem GetLayerRootItem(const wxDataViewItem &item) const; + wxDataViewItem GetInfoItemByType(const wxDataViewItem &parent_item, InfoItemType type) const; + bool IsSettingsItem(const wxDataViewItem &item) const; void UpdateSettingsDigest( const wxDataViewItem &item, const std::vector& categories); diff --git a/src/slic3r/GUI/OpenGLManager.cpp b/src/slic3r/GUI/OpenGLManager.cpp index c843da4600..91f1f1f0b6 100644 --- a/src/slic3r/GUI/OpenGLManager.cpp +++ b/src/slic3r/GUI/OpenGLManager.cpp @@ -90,22 +90,24 @@ float OpenGLManager::GLInfo::get_max_anisotropy() const void OpenGLManager::GLInfo::detect() const { - m_version = gl_get_string_safe(GL_VERSION, "N/A"); - m_glsl_version = gl_get_string_safe(GL_SHADING_LANGUAGE_VERSION, "N/A"); - m_vendor = gl_get_string_safe(GL_VENDOR, "N/A"); - m_renderer = gl_get_string_safe(GL_RENDERER, "N/A"); + *const_cast(&m_version) = gl_get_string_safe(GL_VERSION, "N/A"); + *const_cast(&m_glsl_version) = gl_get_string_safe(GL_SHADING_LANGUAGE_VERSION, "N/A"); + *const_cast(&m_vendor) = gl_get_string_safe(GL_VENDOR, "N/A"); + *const_cast(&m_renderer) = gl_get_string_safe(GL_RENDERER, "N/A"); - glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_tex_size)); + int* max_tex_size = const_cast(&m_max_tex_size); + glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_tex_size)); - m_max_tex_size /= 2; + *max_tex_size /= 2; if (Slic3r::total_physical_memory() / (1024 * 1024 * 1024) < 6) - m_max_tex_size /= 2; + *max_tex_size /= 2; - if (GLEW_EXT_texture_filter_anisotropic) - glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_max_anisotropy)); - - m_detected = true; + if (GLEW_EXT_texture_filter_anisotropic) { + float* max_anisotropy = const_cast(&m_max_anisotropy); + glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); + } + *const_cast(&m_detected) = true; } static bool version_greater_or_equal_to(const std::string& version, unsigned int major, unsigned int minor) @@ -174,19 +176,16 @@ std::string OpenGLManager::GLInfo::to_string(bool format_as_html, bool extension out << b_start << "Renderer: " << b_end << m_renderer << line_end; out << b_start << "GLSL version: " << b_end << m_glsl_version << line_end; - if (extensions) - { + if (extensions) { std::vector extensions_list; std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_off); - if (!extensions_list.empty()) - { + if (!extensions_list.empty()) { out << h2_start << "Installed extensions:" << h2_end << line_end; std::sort(extensions_list.begin(), extensions_list.end()); - for (const std::string& ext : extensions_list) - { + for (const std::string& ext : extensions_list) { out << ext << line_end; } } @@ -252,7 +251,7 @@ bool OpenGLManager::init_gl() message += _L("You may need to update your graphics card driver."); #ifdef _WIN32 message += "\n"; - message += _L("As a workaround, you may run PrusaSlicer with a software rendered 3D graphics by running prusa-slicer.exe with the --sw_renderer parameter."); + message += _L("As a workaround, you may run PrusaSlicer with a software rendered 3D graphics by running prusa-slicer.exe with the --sw-renderer parameter."); #endif wxMessageBox(message, wxString("PrusaSlicer - ") + _L("Unsupported OpenGL version"), wxOK | wxICON_ERROR); } @@ -304,8 +303,7 @@ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent) 0 }; - if (s_multisample == EMultisampleState::Unknown) - { + if (s_multisample == EMultisampleState::Unknown) { detect_multisample(attribList); // // debug output // std::cout << "Multisample " << (can_multisample() ? "enabled" : "disabled") << std::endl; diff --git a/src/slic3r/GUI/OpenGLManager.hpp b/src/slic3r/GUI/OpenGLManager.hpp index 5f8cd7959c..ca9452db66 100644 --- a/src/slic3r/GUI/OpenGLManager.hpp +++ b/src/slic3r/GUI/OpenGLManager.hpp @@ -22,14 +22,14 @@ public: class GLInfo { - mutable bool m_detected{ false }; - mutable int m_max_tex_size{ 0 }; - mutable float m_max_anisotropy{ 0.0f }; + bool m_detected{ false }; + int m_max_tex_size{ 0 }; + float m_max_anisotropy{ 0.0f }; - mutable std::string m_version; - mutable std::string m_glsl_version; - mutable std::string m_vendor; - mutable std::string m_renderer; + std::string m_version; + std::string m_glsl_version; + std::string m_vendor; + std::string m_renderer; public: GLInfo() = default; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0da345c1e4..c57f4a9858 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -967,6 +967,10 @@ void Sidebar::msw_rescale() void Sidebar::sys_color_changed() { +#ifdef __WXMSW__ + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif + for (PlaterPresetComboBox* combo : std::vector{ p->combo_print, p->combo_sla_print, p->combo_sla_material, @@ -975,6 +979,7 @@ void Sidebar::sys_color_changed() for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); + p->object_list->msw_rescale(); p->object_list->sys_color_changed(); p->object_manipulation->sys_color_changed(); p->object_layers->sys_color_changed(); @@ -2439,6 +2444,29 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs &mode #endif /* AUTOPLACEMENT_ON_LOAD */ } +#if ENABLE_MODIFIED_DOWNSCALE_ON_LOAD_OBJECTS_TOO_BIG + for (size_t i = 0; i < object->instances.size(); ++i) { + ModelInstance* instance = object->instances[i]; + const Vec3d size = object->instance_bounding_box(i).size(); + const Vec3d ratio = size.cwiseQuotient(bed_size); + const double max_ratio = std::max(ratio(0), ratio(1)); + if (max_ratio > 10000) { + // the size of the object is too big -> this could lead to overflow when moving to clipper coordinates, + // so scale down the mesh + double inv = 1. / max_ratio; + object->scale_mesh_after_creation(inv * Vec3d::Ones()); + object->origin_translation = Vec3d::Zero(); + object->center_around_origin(); + scaled_down = true; + break; + } + else if (max_ratio > 5) { + const Vec3d inverse = 1.0 / max_ratio * Vec3d::Ones(); + instance->set_scaling_factor(inverse.cwiseProduct(instance->get_scaling_factor())); + scaled_down = true; + } + } +#else const Vec3d size = object->bounding_box().size(); const Vec3d ratio = size.cwiseQuotient(bed_size); const double max_ratio = std::max(ratio(0), ratio(1)); @@ -2457,6 +2485,7 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs &mode } scaled_down = true; } +#endif // ENABLE_MODIFIED_DOWNSCALE_ON_LOAD_OBJECTS_TOO_BIG object->ensure_on_bed(); } @@ -2701,32 +2730,36 @@ void Plater::priv::mirror(Axis axis) view3D->mirror_selection(axis); } -void Plater::find_new_position(const ModelInstancePtrs &instances, - coord_t min_d) +void Plater::find_new_position(const ModelInstancePtrs &instances) { arrangement::ArrangePolygons movable, fixed; + arrangement::ArrangeParams arr_params = get_arrange_params(this); for (const ModelObject *mo : p->model.objects) - for (const ModelInstance *inst : mo->instances) { + for (ModelInstance *inst : mo->instances) { auto it = std::find(instances.begin(), instances.end(), inst); - auto arrpoly = inst->get_arrange_polygon(); + auto arrpoly = get_arrange_poly(inst, this); if (it == instances.end()) fixed.emplace_back(std::move(arrpoly)); - else + else { + arrpoly.setter = [it](const arrangement::ArrangePolygon &p) { + if (p.is_arranged() && p.bed_idx == 0) { + Vec2d t = p.translation.cast(); + (*it)->apply_arrange_result(t, p.rotation); + } + }; movable.emplace_back(std::move(arrpoly)); + } } if (auto wt = get_wipe_tower_arrangepoly(*this)) fixed.emplace_back(*wt); - arrangement::arrange(movable, fixed, get_bed_shape(*config()), - arrangement::ArrangeParams{min_d}); + arrangement::arrange(movable, fixed, get_bed_shape(*config()), arr_params); - for (size_t i = 0; i < instances.size(); ++i) - if (movable[i].bed_idx == 0) - instances[i]->apply_arrange_result(movable[i].translation.cast(), - movable[i].rotation); + for (auto & m : movable) + m.apply(); } void Plater::priv::split_object() @@ -5024,6 +5057,12 @@ void Plater::convert_unit(ConversionType conv_type) } } +void Plater::toggle_layers_editing(bool enable) +{ + if (canvas3D()->is_layers_editing_enabled() != enable) + wxPostEvent(canvas3D()->get_wxglcanvas(), SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); +} + void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper, bool keep_lower, bool rotate_lower) { wxCHECK_RET(obj_idx < p->model.objects.size(), "obj_idx out of bounds"); @@ -5136,6 +5175,30 @@ void Plater::export_stl(bool extended, bool selection_only) if (selection_only && (obj_idx == -1 || selection.is_wipe_tower())) return; + // Following lambda generates a combined mesh for export with normals pointing outwards. + auto mesh_to_export = [](const ModelObject* mo, bool instances) -> TriangleMesh { + TriangleMesh mesh; + for (const ModelVolume *v : mo->volumes) + if (v->is_model_part()) { + TriangleMesh vol_mesh(v->mesh()); + vol_mesh.repair(); + vol_mesh.transform(v->get_matrix(), true); + mesh.merge(vol_mesh); + } + mesh.repair(); + if (instances) { + TriangleMesh vols_mesh(mesh); + mesh = TriangleMesh(); + for (const ModelInstance *i : mo->instances) { + TriangleMesh m = vols_mesh; + m.transform(i->get_matrix(), true); + mesh.merge(m); + } + } + mesh.repair(); + return mesh; + }; + TriangleMesh mesh; if (p->printer_technology == ptFFF) { if (selection_only) { @@ -5143,20 +5206,21 @@ void Plater::export_stl(bool extended, bool selection_only) if (selection.get_mode() == Selection::Instance) { if (selection.is_single_full_object()) - mesh = model_object->mesh(); + mesh = mesh_to_export(model_object, true); else - mesh = model_object->full_raw_mesh(); + mesh = mesh_to_export(model_object, false); } else { const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); mesh = model_object->volumes[volume->volume_idx()]->mesh(); - mesh.transform(volume->get_volume_transformation().get_matrix()); + mesh.transform(volume->get_volume_transformation().get_matrix(), true); mesh.translate(-model_object->origin_translation.cast()); } } else { - mesh = p->model.mesh(); + for (const ModelObject *o : p->model.objects) + mesh.merge(mesh_to_export(o, true)); } } else diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 8d228e68f3..e6a5160f32 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -202,6 +202,7 @@ public: bool is_selection_empty() const; void scale_selection_to_fit_print_volume(); void convert_unit(ConversionType conv_type); + void toggle_layers_editing(bool enable); void cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false); @@ -276,7 +277,7 @@ public: BoundingBoxf bed_shape_bb() const; void arrange(); - void find_new_position(const ModelInstancePtrs &instances, coord_t min_d); + void find_new_position(const ModelInstancePtrs &instances); void set_current_canvas_as_dirty(); void unbind_canvas_event_handlers(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 67381cf220..38a31bf76b 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -51,6 +51,9 @@ void PreferencesDialog::build() auto app_config = get_app_config(); wxNotebook* tabs = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); +#ifdef __WXMSW__ + tabs->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif // Add "General" tab m_optgroup_general = create_options_tab(_L("General"), tabs); diff --git a/src/slic3r/GUI/PresetHints.cpp b/src/slic3r/GUI/PresetHints.cpp index 181dcfda47..0e2b7f8364 100644 --- a/src/slic3r/GUI/PresetHints.cpp +++ b/src/slic3r/GUI/PresetHints.cpp @@ -86,7 +86,8 @@ std::string PresetHints::maximum_volumetric_flow_description(const PresetBundle // Print config values double layer_height = print_config.opt_float("layer_height"); - double first_layer_height = print_config.get_abs_value("first_layer_height", layer_height); + assert(! print_config.option("first_layer_height")->percent); + double first_layer_height = print_config.opt_float("first_layer_height"); double support_material_speed = print_config.opt_float("support_material_speed"); double support_material_interface_speed = print_config.get_abs_value("support_material_interface_speed", support_material_speed); double bridge_speed = print_config.opt_float("bridge_speed"); diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index f69db2ea30..935746a64e 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -68,8 +69,10 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, bool can_start_pr combo_groups->SetValue(recent_group); } - btn_sizer->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL)); - + auto* szr = CreateStdDialogButtonSizer(wxOK | wxCANCEL); + auto* btn_ok = szr->GetAffirmativeButton(); + btn_sizer->Add(szr); + wxString recent_path = from_u8(app_config->get("recent", CONFIG_KEY_PATH)); if (recent_path.Length() > 0 && recent_path[recent_path.Length() - 1] != '/') { recent_path += '/'; @@ -82,6 +85,20 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, bool can_start_pr txt_filename->SetValue(recent_path); txt_filename->SetFocus(); + wxString suffix = recent_path.substr(recent_path.find_last_of('.')); + + btn_ok->Bind(wxEVT_BUTTON, [this, suffix](wxCommandEvent&) { + wxString path = txt_filename->GetValue(); + // .gcode suffix control + if (!path.Lower().EndsWith(suffix.Lower())) + { + wxMessageDialog msg_wingow(this, wxString::Format(_L("Upload filename doesn't end with \"%s\". Do you wish to continue?"), suffix), wxString(SLIC3R_APP_NAME), wxYES | wxNO); + if (msg_wingow.ShowModal() == wxID_NO) + return; + } + EndDialog(wxID_OK); + }); + Fit(); CenterOnParent(); diff --git a/src/slic3r/GUI/RemovableDriveManagerMM.mm b/src/slic3r/GUI/RemovableDriveManagerMM.mm index 3bd1fba7eb..8542c2509d 100644 --- a/src/slic3r/GUI/RemovableDriveManagerMM.mm +++ b/src/slic3r/GUI/RemovableDriveManagerMM.mm @@ -80,7 +80,9 @@ static void unmount_callback(DADiskRef disk, DADissenterRef dissenter, void *con NSLog(@"-%@",(CFStringRef)deviceModelKey); */ if (mediaEjectableKey != nullptr) { - BOOL op = ejectable && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceModelKey, CFSTR("SD Card Reader")) || CFEqual(deviceProtocolName, CFSTR("Secure Digital"))); + BOOL op = ejectable && + ( (deviceProtocolName != nullptr && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceProtocolName, CFSTR("Secure Digital")))) || + (deviceModelKey != nullptr && CFEqual(deviceModelKey, CFSTR("SD Card Reader"))) ); //!CFEqual(deviceModelKey, CFSTR("Disk Image")); if (op) [result addObject:volURL.path]; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index faf25ff8bc..fd68737493 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1102,39 +1102,32 @@ void Selection::erase() if (is_single_full_object()) wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itObject, get_object_idx(), 0); - else if (is_multiple_full_object()) - { + else if (is_multiple_full_object()) { std::vector items; items.reserve(m_cache.content.size()); - for (ObjectIdxsToInstanceIdxsMap::iterator it = m_cache.content.begin(); it != m_cache.content.end(); ++it) - { + for (ObjectIdxsToInstanceIdxsMap::iterator it = m_cache.content.begin(); it != m_cache.content.end(); ++it) { items.emplace_back(ItemType::itObject, it->first, 0); } wxGetApp().obj_list()->delete_from_model_and_list(items); } - else if (is_multiple_full_instance()) - { + else if (is_multiple_full_instance()) { std::set> instances_idxs; - for (ObjectIdxsToInstanceIdxsMap::iterator obj_it = m_cache.content.begin(); obj_it != m_cache.content.end(); ++obj_it) - { - for (InstanceIdxsList::reverse_iterator inst_it = obj_it->second.rbegin(); inst_it != obj_it->second.rend(); ++inst_it) - { + for (ObjectIdxsToInstanceIdxsMap::iterator obj_it = m_cache.content.begin(); obj_it != m_cache.content.end(); ++obj_it) { + for (InstanceIdxsList::reverse_iterator inst_it = obj_it->second.rbegin(); inst_it != obj_it->second.rend(); ++inst_it) { instances_idxs.insert(std::make_pair(obj_it->first, *inst_it)); } } std::vector items; items.reserve(instances_idxs.size()); - for (const std::pair& i : instances_idxs) - { + for (const std::pair& i : instances_idxs) { items.emplace_back(ItemType::itInstance, i.first, i.second); } wxGetApp().obj_list()->delete_from_model_and_list(items); } else if (is_single_full_instance()) wxGetApp().obj_list()->delete_from_model_and_list(ItemType::itInstance, get_object_idx(), get_instance_idx()); - else if (is_mixed()) - { + else if (is_mixed()) { std::set items_set; std::map volumes_in_obj; @@ -1186,11 +1179,9 @@ void Selection::erase() wxGetApp().obj_list()->delete_from_model_and_list(items); } - else - { + else { std::set> volumes_idxs; - for (unsigned int i : m_list) - { + for (unsigned int i : m_list) { const GLVolume* v = (*m_volumes)[i]; // Only remove volumes associated with ModelVolumes from the object list. // Temporary meshes (SLA supports or pads) are not managed by the object list. @@ -1200,8 +1191,7 @@ void Selection::erase() std::vector items; items.reserve(volumes_idxs.size()); - for (const std::pair& v : volumes_idxs) - { + for (const std::pair& v : volumes_idxs) { items.emplace_back(ItemType::itVolume, v.first, v.second); } @@ -1214,7 +1204,7 @@ void Selection::render(float scale_factor) const if (!m_valid || is_empty()) return; - m_scale_factor = scale_factor; + *const_cast(&m_scale_factor) = scale_factor; // render cumulative bounding box of selected volumes render_selected_volumes(); @@ -1224,10 +1214,10 @@ void Selection::render(float scale_factor) const #if ENABLE_RENDER_SELECTION_CENTER void Selection::render_center(bool gizmo_is_dragging) const { - if (!m_valid || is_empty() || (m_quadric == nullptr)) + if (!m_valid || is_empty() || m_quadric == nullptr) return; - Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); + const Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); glsafe(::glDisable(GL_DEPTH_TEST)); @@ -1250,8 +1240,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) const GLShaderProgram* shader = nullptr; - if (!boost::starts_with(sidebar_field, "layer")) - { + if (!boost::starts_with(sidebar_field, "layer")) { shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; @@ -1297,7 +1286,7 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) const } else { glsafe(::glTranslated(center(0), center(1), center(2))); if (requires_local_axes()) { - Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); + const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); glsafe(::glMultMatrixd(orient_matrix.data())); } } @@ -1735,18 +1724,16 @@ void Selection::do_remove_volume(unsigned int volume_idx) void Selection::do_remove_instance(unsigned int object_idx, unsigned int instance_idx) { - for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) - { + for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) { GLVolume* v = (*m_volumes)[i]; - if ((v->object_idx() == (int)object_idx) && (v->instance_idx() == (int)instance_idx)) + if (v->object_idx() == (int)object_idx && v->instance_idx() == (int)instance_idx) do_remove_volume(i); } } void Selection::do_remove_object(unsigned int object_idx) { - for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) - { + for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++i) { GLVolume* v = (*m_volumes)[i]; if (v->object_idx() == (int)object_idx) do_remove_volume(i); @@ -1755,47 +1742,48 @@ void Selection::do_remove_object(unsigned int object_idx) void Selection::calc_bounding_box() const { - m_bounding_box = BoundingBoxf3(); - if (m_valid) - { - for (unsigned int i : m_list) - { - m_bounding_box.merge((*m_volumes)[i]->transformed_convex_hull_bounding_box()); + BoundingBoxf3* bounding_box = const_cast(&m_bounding_box); + *bounding_box = BoundingBoxf3(); + if (m_valid) { + for (unsigned int i : m_list) { + bounding_box->merge((*m_volumes)[i]->transformed_convex_hull_bounding_box()); } } - m_bounding_box_dirty = false; + *const_cast(&m_bounding_box_dirty) = false; } void Selection::calc_unscaled_instance_bounding_box() const { - m_unscaled_instance_bounding_box = BoundingBoxf3(); - if (m_valid) { - for (unsigned int i : m_list) { - const GLVolume &volume = *(*m_volumes)[i]; + BoundingBoxf3* unscaled_instance_bounding_box = const_cast(&m_unscaled_instance_bounding_box); + *unscaled_instance_bounding_box = BoundingBoxf3(); + if (m_valid) { + for (unsigned int i : m_list) { + const GLVolume& volume = *(*m_volumes)[i]; if (volume.is_modifier) continue; - Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix(); - trafo.translation()(2) += volume.get_sla_shift_z(); - m_unscaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); - } - } - m_unscaled_instance_bounding_box_dirty = false; + Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix(); + trafo.translation()(2) += volume.get_sla_shift_z(); + unscaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo)); + } + } + *const_cast(&m_unscaled_instance_bounding_box_dirty) = false; } void Selection::calc_scaled_instance_bounding_box() const { - m_scaled_instance_bounding_box = BoundingBoxf3(); + BoundingBoxf3* scaled_instance_bounding_box = const_cast(&m_scaled_instance_bounding_box); + *scaled_instance_bounding_box = BoundingBoxf3(); if (m_valid) { for (unsigned int i : m_list) { - const GLVolume &volume = *(*m_volumes)[i]; + const GLVolume& volume = *(*m_volumes)[i]; if (volume.is_modifier) continue; Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix(); trafo.translation()(2) += volume.get_sla_shift_z(); - m_scaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); + scaled_instance_bounding_box->merge(volume.transformed_convex_hull_bounding_box(trafo)); } } - m_scaled_instance_bounding_box_dirty = false; + *const_cast(&m_scaled_instance_bounding_box_dirty) = false; } void Selection::render_selected_volumes() const @@ -1988,7 +1976,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co if (pos == std::string::npos) return; - double min_z = std::stod(field.substr(pos + 1)); + const double min_z = std::stod(field.substr(pos + 1)); // extract type field = field.substr(0, pos); @@ -1996,7 +1984,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co if (pos == std::string::npos) return; - int type = std::stoi(field.substr(pos + 1)); + const int type = std::stoi(field.substr(pos + 1)); const BoundingBoxf3& box = get_bounding_box(); @@ -2007,8 +1995,8 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co // view dependend order of rendering to keep correct transparency bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward(); - float z1 = camera_on_top ? min_z : max_z; - float z2 = camera_on_top ? max_z : min_z; + const float z1 = camera_on_top ? min_z : max_z; + const float z2 = camera_on_top ? max_z : min_z; glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_CULL_FACE)); @@ -2016,7 +2004,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); ::glBegin(GL_QUADS); - if ((camera_on_top && (type == 1)) || (!camera_on_top && (type == 2))) + if ((camera_on_top && type == 1) || (!camera_on_top && type == 2)) ::glColor4f(1.0f, 0.38f, 0.0f, 1.0f); else ::glColor4f(0.8f, 0.8f, 0.8f, 0.5f); @@ -2027,7 +2015,7 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co glsafe(::glEnd()); ::glBegin(GL_QUADS); - if ((camera_on_top && (type == 2)) || (!camera_on_top && (type == 1))) + if ((camera_on_top && type == 2) || (!camera_on_top && type == 1)) ::glColor4f(1.0f, 0.38f, 0.0f, 1.0f); else ::glColor4f(0.8f, 0.8f, 0.8f, 0.5f); diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index a9095adcbf..8bb418baac 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -206,14 +206,14 @@ private: IndicesList m_list; Cache m_cache; Clipboard m_clipboard; - mutable BoundingBoxf3 m_bounding_box; - mutable bool m_bounding_box_dirty; + BoundingBoxf3 m_bounding_box; + bool m_bounding_box_dirty; // Bounding box of a selection, with no instance scaling applied. This bounding box // is useful for absolute scaling of tilted objects in world coordinate space. - mutable BoundingBoxf3 m_unscaled_instance_bounding_box; - mutable bool m_unscaled_instance_bounding_box_dirty; - mutable BoundingBoxf3 m_scaled_instance_bounding_box; - mutable bool m_scaled_instance_bounding_box_dirty; + BoundingBoxf3 m_unscaled_instance_bounding_box; + bool m_unscaled_instance_bounding_box_dirty; + BoundingBoxf3 m_scaled_instance_bounding_box; + bool m_scaled_instance_bounding_box_dirty; #if ENABLE_RENDER_SELECTION_CENTER GLUquadricObj* m_quadric; @@ -222,7 +222,7 @@ private: GLModel m_arrow; GLModel m_curved_arrow; - mutable float m_scale_factor; + float m_scale_factor; public: Selection(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 294af5f76b..b239c29756 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1002,7 +1002,9 @@ void Tab::sys_color_changed() for (ScalableBitmap& bmp : m_scaled_icons_list) m_icons->Add(bmp.bmp()); m_treectrl->AssignImageList(m_icons); - +#ifdef __WXMSW__ + m_treectrl->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif // Colors for ui "decoration" update_label_colours(); @@ -1516,6 +1518,7 @@ void TabPrint::build() optgroup->append_single_option_line("support_material_with_sheath", category_path + "with-sheath-around-the-support"); optgroup->append_single_option_line("support_material_spacing", category_path + "pattern-spacing-0-inf"); optgroup->append_single_option_line("support_material_angle", category_path + "pattern-angle"); + optgroup->append_single_option_line("support_material_closing_radius", category_path + "pattern-angle"); optgroup->append_single_option_line("support_material_interface_layers", category_path + "interface-layers"); optgroup->append_single_option_line("support_material_bottom_interface_layers", category_path + "interface-layers"); optgroup->append_single_option_line("support_material_interface_pattern", category_path + "interface-pattern"); @@ -2273,6 +2276,13 @@ void TabPrinter::build_fff() m_use_silent_mode = val; } } + if (opt_key == "gcode_flavor") { + bool supports_travel_acceleration = (boost::any_cast(value) == int(gcfMarlinFirmware)); + if (supports_travel_acceleration != m_supports_travel_acceleration) { + m_rebuild_kinematics_page = true; + m_supports_travel_acceleration = supports_travel_acceleration; + } + } build_unregular_pages(); update_dirty(); on_value_change(opt_key, value); @@ -2569,6 +2579,8 @@ PageShp TabPrinter::build_kinematics_page() } append_option_line(optgroup, "machine_max_acceleration_extruding"); append_option_line(optgroup, "machine_max_acceleration_retracting"); + if (m_supports_travel_acceleration) + append_option_line(optgroup, "machine_max_acceleration_travel"); optgroup = page->new_optgroup(L("Jerk limits")); for (const std::string &axis : axes) { @@ -2591,7 +2603,8 @@ PageShp TabPrinter::build_kinematics_page() void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/) { size_t n_before_extruders = 2; // Count of pages before Extruder pages - bool is_marlin_flavor = m_config->option>("gcode_flavor")->value == gcfMarlin; + auto flavor = m_config->option>("gcode_flavor")->value; + bool is_marlin_flavor = (flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware); /* ! Freeze/Thaw in this function is needed to avoid call OnPaint() for erased pages * and be cause of application crash, when try to change Preset in moment, @@ -2861,7 +2874,8 @@ void TabPrinter::toggle_options() if (m_active_page->title() == "General") { toggle_option("single_extruder_multi_material", have_multiple_extruders); - bool is_marlin_flavor = m_config->option>("gcode_flavor")->value == gcfMarlin; + auto flavor = m_config->option>("gcode_flavor")->value; + bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware; // Disable silent mode for non-marlin firmwares. toggle_option("silent_mode", is_marlin_flavor); } @@ -2929,7 +2943,8 @@ void TabPrinter::toggle_options() } if (m_active_page->title() == "Machine limits" && m_machine_limits_description_line) { - assert(m_config->option>("gcode_flavor")->value == gcfMarlin); + assert(m_config->option>("gcode_flavor")->value == gcfMarlinLegacy + || m_config->option>("gcode_flavor")->value == gcfMarlinFirmware); const auto *machine_limits_usage = m_config->option>("machine_limits_usage"); bool enabled = machine_limits_usage->value != MachineLimitsUsage::Ignore; bool silent_mode = m_config->opt_bool("silent_mode"); @@ -2960,6 +2975,12 @@ void TabPrinter::update_fff() m_use_silent_mode = m_config->opt_bool("silent_mode"); } + bool supports_travel_acceleration = (m_config->option>("gcode_flavor")->value == gcfMarlinFirmware); + if (m_supports_travel_acceleration != supports_travel_acceleration) { + m_rebuild_kinematics_page = true; + m_supports_travel_acceleration = supports_travel_acceleration; + } + toggle_options(); } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index c1806cfcd2..601995ea70 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -443,6 +443,7 @@ class TabPrinter : public Tab private: bool m_has_single_extruder_MM_page = false; bool m_use_silent_mode = false; + bool m_supports_travel_acceleration = false; void append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key); bool m_rebuild_kinematics_page = false; ogStaticText* m_machine_limits_description_line {nullptr}; diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 28c3ba40b9..c8b0dfd31d 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -590,6 +590,9 @@ void LockButton::msw_rescale() void LockButton::update_button_bitmaps() { +#ifdef __WXMSW__ + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif SetBitmap(m_is_pushed ? m_bmp_lock_closed.bmp() : m_bmp_lock_open.bmp()); SetBitmapHover(m_is_pushed ? m_bmp_lock_closed_f.bmp() : m_bmp_lock_open_f.bmp()); @@ -885,6 +888,9 @@ void ScalableButton::UseDefaultBitmapDisabled() void ScalableButton::msw_rescale() { +#ifdef __WXMSW__ + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif SetBitmap(create_scaled_bitmap(m_current_icon_name, m_parent, m_px_cnt)); if (!m_disabled_icon_name.empty()) SetBitmapDisabled(create_scaled_bitmap(m_disabled_icon_name, m_parent, m_px_cnt)); diff --git a/t/flow.t b/t/flow.t index 4d7ee5ca2a..50c4916049 100644 --- a/t/flow.t +++ b/t/flow.t @@ -21,7 +21,7 @@ use Slic3r::Test; $config->set('fill_density', 0.4); $config->set('bottom_solid_layers', 1); $config->set('first_layer_extrusion_width', 2); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('filament_diameter', [ 3.0 ]); $config->set('nozzle_diameter', [ 0.5 ]); diff --git a/t/layers.t b/t/layers.t index a9f7dfe39f..4d958808a6 100644 --- a/t/layers.t +++ b/t/layers.t @@ -49,7 +49,7 @@ use Slic3r::Test qw(_eq); $config->set('first_layer_height', 0.2); ok $test->(), "absolute first layer height"; - $config->set('first_layer_height', '60%'); + $config->set('first_layer_height', 0.6 * $config->layer_height); ok $test->(), "relative first layer height"; $config->set('z_offset', 0.9); diff --git a/t/multi.t b/t/multi.t index 8e7225bec7..e74a7a1a8b 100644 --- a/t/multi.t +++ b/t/multi.t @@ -181,7 +181,7 @@ use Slic3r::Test; my $config = Slic3r::Config::new_from_defaults; $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]); $config->set('layer_height', 0.4); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('skirts', 0); my $print = Slic3r::Test::init_print($model, config => $config); diff --git a/t/perimeters.t b/t/perimeters.t index d0657cb23f..3d3fd3819c 100644 --- a/t/perimeters.t +++ b/t/perimeters.t @@ -394,9 +394,9 @@ use Slic3r::Test; }); return scalar keys %z_with_bridges; }; - ok $test->(Slic3r::Test::init_print('V', config => $config)) == 1, - 'no overhangs printed with bridge speed'; # except for the first internal solid layers above void - ok $test->(Slic3r::Test::init_print('V', config => $config, scale_xyz => [3,1,1])) > 1, + ok $test->(Slic3r::Test::init_print('V', config => $config)) == 2, + 'no overhangs printed with bridge speed'; # except for the two internal solid layers above void + ok $test->(Slic3r::Test::init_print('V', config => $config, scale_xyz => [3,1,1])) > 2, 'overhangs printed with bridge speed'; } diff --git a/t/shells.t b/t/shells.t index 47b5c8881d..29bc0b5f00 100644 --- a/t/shells.t +++ b/t/shells.t @@ -84,7 +84,7 @@ use Slic3r::Test; { my $config = Slic3r::Config::new_from_defaults; $config->set('layer_height', 0.3); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('bottom_solid_layers', 0); $config->set('top_solid_layers', 3); $config->set('cooling', [ 0 ]); @@ -119,7 +119,7 @@ use Slic3r::Test; $config->set('cooling', [ 0 ]); # prevent speed alteration $config->set('first_layer_speed', '100%'); # prevent speed alteration $config->set('layer_height', 0.4); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('extrusion_width', 0.55); $config->set('bottom_solid_layers', 3); $config->set('top_solid_layers', 0); @@ -142,7 +142,7 @@ use Slic3r::Test; $config->set('cooling', [ 0 ]); # prevent speed alteration $config->set('first_layer_speed', '100%'); # prevent speed alteration $config->set('layer_height', 0.4); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('bottom_solid_layers', 3); $config->set('top_solid_layers', 3); $config->set('solid_infill_speed', 99); @@ -170,7 +170,7 @@ use Slic3r::Test; $config->set('spiral_vase', 1); $config->set('bottom_solid_layers', 0); $config->set('skirts', 0); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('start_gcode', ''); $config->set('temperature', [200]); $config->set('first_layer_temperature', [205]); @@ -231,8 +231,8 @@ use Slic3r::Test; $config->set('bottom_solid_layers', 0); $config->set('retract_layer_change', [0]); $config->set('skirts', 0); - $config->set('first_layer_height', '100%'); $config->set('layer_height', 0.4); + $config->set('first_layer_height', $config->layer_height); $config->set('start_gcode', ''); # $config->set('use_relative_e_distances', 1); $config->validate; @@ -310,7 +310,7 @@ use Slic3r::Test; # $config->set('spiral_vase', 1); # $config->set('bottom_solid_layers', 0); # $config->set('skirts', 0); -# $config->set('first_layer_height', '100%'); +# $config->set('first_layer_height', $config->layer_height); # $config->set('start_gcode', ''); # # my $print = Slic3r::Test::init_print('two_hollow_squares', config => $config); diff --git a/t/thin.t b/t/thin.t index 9147236ee5..50e7abc950 100644 --- a/t/thin.t +++ b/t/thin.t @@ -18,7 +18,7 @@ use Slic3r::Test; if (0) { my $config = Slic3r::Config::new_from_defaults; $config->set('layer_height', 0.2); - $config->set('first_layer_height', '100%'); + $config->set('first_layer_height', $config->layer_height); $config->set('extrusion_width', 0.5); $config->set('first_layer_extrusion_width', '200%'); # check this one too $config->set('skirts', 0); diff --git a/tests/fff_print/test_flow.cpp b/tests/fff_print/test_flow.cpp index 08ba15a84a..dc73f4b6ec 100644 --- a/tests/fff_print/test_flow.cpp +++ b/tests/fff_print/test_flow.cpp @@ -24,7 +24,7 @@ SCENARIO("Extrusion width specifics", "[Flow]") { { "skirts", 1 }, { "perimeters", 3 }, { "fill_density", "40%" }, - { "first_layer_height", "100%" } + { "first_layer_height", 0.3 } }); WHEN("first layer width set to 2mm") { diff --git a/tests/fff_print/test_support_material.cpp b/tests/fff_print/test_support_material.cpp index 1b85532d31..442db7654f 100644 --- a/tests/fff_print/test_support_material.cpp +++ b/tests/fff_print/test_support_material.cpp @@ -29,7 +29,7 @@ SCENARIO("SupportMaterial: support_layers_z and contact_distance", "[SupportMate { ConstSupportLayerPtrsAdaptor support_layers = print.objects().front()->support_layers(); - first_support_layer_height_ok = support_layers.front()->print_z == print.default_object_config().first_layer_height.value; + first_support_layer_height_ok = support_layers.front()->print_z == print.config().first_layer_height.value; layer_height_minimum_ok = true; layer_height_maximum_ok = true; diff --git a/tests/libnest2d/CMakeLists.txt b/tests/libnest2d/CMakeLists.txt index d4f684dd3c..bcb7594520 100644 --- a/tests/libnest2d/CMakeLists.txt +++ b/tests/libnest2d/CMakeLists.txt @@ -4,4 +4,4 @@ target_link_libraries(${_TEST_NAME}_tests test_common libnest2d ) set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests") # catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ") -add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${CATCH_EXTRA_ARGS}) +add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests "${CATCH_EXTRA_ARGS} exclude:[NotWorking]") diff --git a/tests/libnest2d/libnest2d_tests_main.cpp b/tests/libnest2d/libnest2d_tests_main.cpp index a0f1924603..97c7ef99dd 100644 --- a/tests/libnest2d/libnest2d_tests_main.cpp +++ b/tests/libnest2d/libnest2d_tests_main.cpp @@ -44,12 +44,74 @@ struct NfpImpl } } +namespace { +using namespace libnest2d; + +template +void exportSVG(const char *loc, It from, It to) { + + static const char* svg_header = + R"raw( + + +)raw"; + + // for(auto r : result) { + std::fstream out(loc, std::fstream::out); + if(out.is_open()) { + out << svg_header; + // Item rbin( RectangleItem(bin.width(), bin.height()) ); + // for(unsigned j = 0; j < rbin.vertexCount(); j++) { + // auto v = rbin.vertex(j); + // setY(v, -getY(v)/SCALE + 500 ); + // setX(v, getX(v)/SCALE); + // rbin.setVertex(j, v); + // } + // out << shapelike::serialize(rbin.rawShape()) << std::endl; + for(auto it = from; it != to; ++it) { + const Item &itm = *it; + Item tsh(itm.transformedShape()); + for(unsigned j = 0; j < tsh.vertexCount(); j++) { + auto v = tsh.vertex(j); + setY(v, -getY(v)/SCALE + 500); + setX(v, getX(v)/SCALE); + tsh.setVertex(j, v); + } + out << shapelike::serialize(tsh.rawShape()) << std::endl; + } + out << "\n" << std::endl; + } + out.close(); + + // i++; + // } +} + +template +void exportSVG(std::vector>& result, int idx = 0) { + exportSVG((std::string("out") + std::to_string(idx) + ".svg").c_str(), + result.begin(), result.end()); +} +} + static std::vector& prusaParts() { - static std::vector ret; + using namespace libnest2d; + + static std::vector ret; if(ret.empty()) { ret.reserve(PRINTER_PART_POLYGONS.size()); - for(auto& inp : PRINTER_PART_POLYGONS) ret.emplace_back(inp); + for(auto& inp : PRINTER_PART_POLYGONS) { + auto inp_cpy = inp; + + if (ClosureTypeV == Closure::OPEN) + inp_cpy.points.pop_back(); + + if constexpr (!libnest2d::is_clockwise()) + std::reverse(inp_cpy.begin(), inp_cpy.end()); + + ret.emplace_back(inp_cpy); + } } return ret; @@ -140,15 +202,15 @@ TEST_CASE("boundingCircle", "[Geometry]") { PolygonImpl p = {{{0, 10}, {10, 0}, {0, -10}, {0, 10}}, {}}; Circle c = boundingCircle(p); - REQUIRE(c.center().X == 0); - REQUIRE(c.center().Y == 0); + REQUIRE(getX(c.center()) == 0); + REQUIRE(getY(c.center()) == 0); REQUIRE(c.radius() == Approx(10)); shapelike::translate(p, PointImpl{10, 10}); c = boundingCircle(p); - REQUIRE(c.center().X == 10); - REQUIRE(c.center().Y == 10); + REQUIRE(getX(c.center()) == 10); + REQUIRE(getY(c.center()) == 10); REQUIRE(c.radius() == Approx(10)); auto parts = prusaParts(); @@ -243,7 +305,7 @@ TEST_CASE("Area", "[Geometry]") { {61, 97} }; - REQUIRE(shapelike::area(item.transformedShape()) > 0 ); + REQUIRE(std::abs(shapelike::area(item.transformedShape())) > 0 ); } TEST_CASE("IsPointInsidePolygon", "[Geometry]") { @@ -296,30 +358,36 @@ TEST_CASE("LeftAndDownPolygon", "[Geometry]") Box bin(100, 100); BottomLeftPlacer placer(bin); - Item item = {{70, 75}, {88, 60}, {65, 50}, {60, 30}, {80, 20}, {42, 20}, - {35, 35}, {35, 55}, {40, 75}, {70, 75}}; + PathImpl pitem = {{70, 75}, {88, 60}, {65, 50}, {60, 30}, {80, 20}, + {42, 20}, {35, 35}, {35, 55}, {40, 75}}; - Item leftControl = { {40, 75}, - {35, 55}, - {35, 35}, - {42, 20}, - {0, 20}, - {0, 75}, - {40, 75}}; + PathImpl pleftControl = {{40, 75}, {35, 55}, {35, 35}, + {42, 20}, {0, 20}, {0, 75}}; - Item downControl = {{88, 60}, - {88, 0}, - {35, 0}, - {35, 35}, - {42, 20}, - {80, 20}, - {60, 30}, - {65, 50}, - {88, 60}}; + PathImpl pdownControl = {{88, 60}, {88, 0}, {35, 0}, {35, 35}, + {42, 20}, {80, 20}, {60, 30}, {65, 50}}; + if constexpr (!is_clockwise()) { + std::reverse(sl::begin(pitem), sl::end(pitem)); + std::reverse(sl::begin(pleftControl), sl::end(pleftControl)); + std::reverse(sl::begin(pdownControl), sl::end(pdownControl)); + } + + if constexpr (ClosureTypeV == Closure::CLOSED) { + sl::addVertex(pitem, sl::front(pitem)); + sl::addVertex(pleftControl, sl::front(pleftControl)); + sl::addVertex(pdownControl, sl::front(pdownControl)); + } + + Item item{pitem}, leftControl{pleftControl}, downControl{pdownControl}; Item leftp(placer.leftPoly(item)); - REQUIRE(shapelike::isValid(leftp.rawShape()).first); + auto valid = sl::isValid(leftp.rawShape()); + + std::vector> to_export{ leftp, leftControl }; + exportSVG<1>("leftp.svg", to_export.begin(), to_export.end()); + + REQUIRE(valid.first); REQUIRE(leftp.vertexCount() == leftControl.vertexCount()); for(unsigned long i = 0; i < leftControl.vertexCount(); i++) { @@ -338,7 +406,7 @@ TEST_CASE("LeftAndDownPolygon", "[Geometry]") } } -TEST_CASE("ArrangeRectanglesTight", "[Nesting]") +TEST_CASE("ArrangeRectanglesTight", "[Nesting][NotWorking]") { using namespace libnest2d; @@ -390,6 +458,8 @@ TEST_CASE("ArrangeRectanglesTight", "[Nesting]") // check for no intersections, no containment: + // exportSVG<1>("arrangeRectanglesTight.svg", rects.begin(), rects.end()); + bool valid = true; for(Item& r1 : rects) { for(Item& r2 : rects) { @@ -470,57 +540,7 @@ TEST_CASE("ArrangeRectanglesLoose", "[Nesting]") } -namespace { -using namespace libnest2d; - -template -void exportSVG(const char *loc, It from, It to) { - - static const char* svg_header = -R"raw( - - -)raw"; - - // for(auto r : result) { - std::fstream out(loc, std::fstream::out); - if(out.is_open()) { - out << svg_header; -// Item rbin( RectangleItem(bin.width(), bin.height()) ); -// for(unsigned j = 0; j < rbin.vertexCount(); j++) { -// auto v = rbin.vertex(j); -// setY(v, -getY(v)/SCALE + 500 ); -// setX(v, getX(v)/SCALE); -// rbin.setVertex(j, v); -// } -// out << shapelike::serialize(rbin.rawShape()) << std::endl; - for(auto it = from; it != to; ++it) { - const Item &itm = *it; - Item tsh(itm.transformedShape()); - for(unsigned j = 0; j < tsh.vertexCount(); j++) { - auto v = tsh.vertex(j); - setY(v, -getY(v)/SCALE + 500); - setX(v, getX(v)/SCALE); - tsh.setVertex(j, v); - } - out << shapelike::serialize(tsh.rawShape()) << std::endl; - } - out << "\n" << std::endl; - } - out.close(); - - // i++; - // } -} - -template -void exportSVG(std::vector>& result, int idx = 0) { - exportSVG((std::string("out") + std::to_string(idx) + ".svg").c_str(), - result.begin(), result.end()); -} -} - -TEST_CASE("BottomLeftStressTest", "[Geometry]") { +TEST_CASE("BottomLeftStressTest", "[Geometry][NotWorking]") { using namespace libnest2d; const Coord SCALE = 1000000; @@ -563,7 +583,7 @@ TEST_CASE("BottomLeftStressTest", "[Geometry]") { TEST_CASE("convexHull", "[Geometry]") { using namespace libnest2d; - ClipperLib::Path poly = PRINTER_PART_POLYGONS[0]; + PathImpl poly = PRINTER_PART_POLYGONS[0]; auto chull = sl::convexHull(poly); @@ -597,7 +617,7 @@ TEST_CASE("PrusaPartsShouldFitIntoTwoBins", "[Nesting]") { })); // Gather the items into piles of arranged polygons... - using Pile = TMultiShape; + using Pile = TMultiShape; std::vector piles(bins); for (auto &itm : input) @@ -609,6 +629,20 @@ TEST_CASE("PrusaPartsShouldFitIntoTwoBins", "[Nesting]") { auto bb = sl::boundingBox(pile); REQUIRE(sl::isInside(bb, bin)); } + + // Check the area of merged pile vs the sum of area of all the parts + // They should match, otherwise there is an overlap which should not happen. + for (auto &pile : piles) { + double area_sum = 0.; + + for (auto &obj : pile) + area_sum += sl::area(obj); + + auto pile_m = nfp::merge(pile); + double area_merge = sl::area(pile_m); + + REQUIRE(area_sum == Approx(area_merge)); + } } TEST_CASE("EmptyItemShouldBeUntouched", "[Nesting]") { @@ -616,7 +650,7 @@ TEST_CASE("EmptyItemShouldBeUntouched", "[Nesting]") { std::vector items; items.emplace_back(Item{}); // Emplace empty item - items.emplace_back(Item{0, 200, 0}); // Emplace zero area item + items.emplace_back(Item{ {0, 200} }); // Emplace zero area item size_t bins = libnest2d::nest(items, bin); @@ -661,12 +695,12 @@ TEST_CASE("Items can be preloaded", "[Nesting]") { REQUIRE(bins == 1); REQUIRE(fixed_rect.binId() == 0); - REQUIRE(fixed_rect.translation().X == bin.center().X); - REQUIRE(fixed_rect.translation().Y == bin.center().Y); + REQUIRE(getX(fixed_rect.translation()) == getX(bin.center())); + REQUIRE(getY(fixed_rect.translation()) == getY(bin.center())); REQUIRE(movable_rect.binId() == 0); - REQUIRE(movable_rect.translation().X != bin.center().X); - REQUIRE(movable_rect.translation().Y != bin.center().Y); + REQUIRE(getX(movable_rect.translation()) != getX(bin.center())); + REQUIRE(getY(movable_rect.translation()) != getY(bin.center())); } SECTION("Preloaded Item should not affect free bins") { @@ -677,14 +711,14 @@ TEST_CASE("Items can be preloaded", "[Nesting]") { REQUIRE(bins == 2); REQUIRE(fixed_rect.binId() == 1); - REQUIRE(fixed_rect.translation().X == bin.center().X); - REQUIRE(fixed_rect.translation().Y == bin.center().Y); + REQUIRE(getX(fixed_rect.translation()) == getX(bin.center())); + REQUIRE(getY(fixed_rect.translation()) == getY(bin.center())); REQUIRE(movable_rect.binId() == 0); auto bb = movable_rect.boundingBox(); - REQUIRE(bb.center().X == bin.center().X); - REQUIRE(bb.center().Y == bin.center().Y); + REQUIRE(getX(bb.center()) == getX(bin.center())); + REQUIRE(getY(bb.center()) == getY(bin.center())); } } @@ -700,15 +734,13 @@ std::vector nfp_testdata = { { {80, 50}, {100, 70}, - {120, 50}, - {80, 50} + {120, 50} }, { {10, 10}, {10, 40}, {40, 40}, - {40, 10}, - {10, 10} + {40, 10} } }, { @@ -718,15 +750,13 @@ std::vector nfp_testdata = { {80, 90}, {120, 90}, {140, 70}, - {120, 50}, - {80, 50} + {120, 50} }, { {10, 10}, {10, 40}, {40, 40}, - {40, 10}, - {10, 10} + {40, 10} } }, { @@ -738,15 +768,13 @@ std::vector nfp_testdata = { {30, 40}, {40, 40}, {50, 30}, - {50, 20}, - {40, 10} + {50, 20} }, { {80, 0}, {80, 30}, {110, 30}, - {110, 0}, - {80, 0} + {110, 0} } }, { @@ -766,9 +794,8 @@ std::vector nfp_testdata = { {122, 97}, {120, 98}, {118, 101}, - {117, 103}, - {117, 107} - }, + {117, 103} + }, { {102, 116}, {111, 126}, @@ -777,9 +804,8 @@ std::vector nfp_testdata = { {148, 100}, {148, 85}, {147, 84}, - {102, 84}, - {102, 116}, - } + {102, 84} + } }, { { @@ -793,9 +819,8 @@ std::vector nfp_testdata = { {139, 68}, {111, 68}, {108, 70}, - {99, 102}, - {99, 122}, - }, + {99, 102} + }, { {107, 124}, {128, 125}, @@ -810,9 +835,8 @@ std::vector nfp_testdata = { {136, 86}, {134, 85}, {108, 85}, - {107, 86}, - {107, 124}, - } + {107, 86} + } }, { { @@ -825,9 +849,8 @@ std::vector nfp_testdata = { {156, 66}, {133, 57}, {132, 57}, - {91, 98}, - {91, 100}, - }, + {91, 98} + }, { {101, 90}, {103, 98}, @@ -843,9 +866,8 @@ std::vector nfp_testdata = { {145, 84}, {105, 84}, {102, 87}, - {101, 89}, - {101, 90}, - } + {101, 89} + } } }; @@ -860,10 +882,9 @@ std::vector nfp_testdata = { {533659, 157607}, {538669, 160091}, {537178, 142155}, - {534959, 143386}, - {533726, 142141}, - } - }, + {534959, 143386} + } + }, { { {118305, 11603}, @@ -884,8 +905,7 @@ std::vector nfp_testdata = { {209315, 17080}, {205326, 17080}, {203334, 13629}, - {204493, 11616}, - {118305, 11603}, + {204493, 11616} } }, } @@ -957,6 +977,14 @@ void testNfp(const std::vector& testdata) { for(auto& td : testdata) { auto orbiter = td.orbiter; auto stationary = td.stationary; + if (!libnest2d::is_clockwise()) { + auto porb = orbiter.rawShape(); + auto pstat = stationary.rawShape(); + std::reverse(sl::begin(porb), sl::end(porb)); + std::reverse(sl::begin(pstat), sl::end(pstat)); + orbiter = Item{porb}; + stationary = Item{pstat}; + } onetest(orbiter, stationary, tidx++); } @@ -964,6 +992,14 @@ void testNfp(const std::vector& testdata) { for(auto& td : testdata) { auto orbiter = td.stationary; auto stationary = td.orbiter; + if (!libnest2d::is_clockwise()) { + auto porb = orbiter.rawShape(); + auto pstat = stationary.rawShape(); + std::reverse(sl::begin(porb), sl::end(porb)); + std::reverse(sl::begin(pstat), sl::end(pstat)); + orbiter = Item{porb}; + stationary = Item{pstat}; + } onetest(orbiter, stationary, tidx++); } } @@ -1073,7 +1109,7 @@ using Ratio = boost::rational; TEST_CASE("MinAreaBBWithRotatingCalipers", "[Geometry]") { long double err_epsilon = 500e6l; - for(ClipperLib::Path rinput : PRINTER_PART_POLYGONS) { + for(PathImpl rinput : PRINTER_PART_POLYGONS) { PolygonImpl poly(rinput); long double arearef = refMinAreaBox(poly); @@ -1085,8 +1121,8 @@ TEST_CASE("MinAreaBBWithRotatingCalipers", "[Geometry]") { REQUIRE(succ); } - for(ClipperLib::Path rinput : STEGOSAUR_POLYGONS) { - rinput.pop_back(); + for(PathImpl rinput : STEGOSAUR_POLYGONS) { +// rinput.pop_back(); std::reverse(rinput.begin(), rinput.end()); PolygonImpl poly(removeCollinearPoints(rinput, 1000000)); @@ -1116,7 +1152,7 @@ template MultiPolygon merged_pile(It from, It to, int bin_id) TEST_CASE("Test for bed center distance optimization", "[Nesting], [NestKernels]") { - static const constexpr ClipperLib::cInt W = 10000000; + static const constexpr Slic3r::ClipperLib::cInt W = 10000000; // Get the input items and define the bin. std::vector input(9, {W, W}); @@ -1151,7 +1187,7 @@ TEST_CASE("Test for bed center distance optimization", "[Nesting], [NestKernels] TEST_CASE("Test for biggest bounding box area", "[Nesting], [NestKernels]") { - static const constexpr ClipperLib::cInt W = 10000000; + static const constexpr Slic3r::ClipperLib::cInt W = 10000000; static const constexpr size_t N = 100; // Get the input items and define the bin. @@ -1171,7 +1207,7 @@ TEST_CASE("Test for biggest bounding box area", "[Nesting], [NestKernels]") pconfig.object_function = [&pile_box](const Item &item) -> double { Box b = sl::boundingBox(item.boundingBox(), pile_box); - double area = b.area() / (W * W); + double area = b.area() / (double(W) * W); return -area; }; @@ -1187,5 +1223,5 @@ TEST_CASE("Test for biggest bounding box area", "[Nesting], [NestKernels]") // Here the result shall be a stairway of boxes REQUIRE(pile.size() == N); - REQUIRE(bb.area() == N * N * W * W); + REQUIRE(bb.area() == double(N) * N * W * W); } diff --git a/tests/libslic3r/test_clipper_utils.cpp b/tests/libslic3r/test_clipper_utils.cpp index a660b29cb2..bbf76ea180 100644 --- a/tests/libslic3r/test_clipper_utils.cpp +++ b/tests/libslic3r/test_clipper_utils.cpp @@ -22,7 +22,7 @@ SCENARIO("Various Clipper operations - xs/t/11_clipper.t", "[ClipperUtils]") { THEN("offset matches") { REQUIRE(result == Polygons { { { 205, 205 }, { 95, 205 }, { 95, 95 }, { 205, 95 }, }, - { { 145, 145 }, { 145, 155 }, { 155, 155 }, { 155, 145 } } }); + { { 155, 145 }, { 145, 145 }, { 145, 155 }, { 155, 155 } } }); } } WHEN("offset_ex") { @@ -56,7 +56,7 @@ SCENARIO("Various Clipper operations - xs/t/11_clipper.t", "[ClipperUtils]") { } GIVEN("square and hole") { WHEN("diff_ex") { - ExPolygons result = Slic3r::diff_ex({ square }, { hole_in_square }); + ExPolygons result = Slic3r::diff_ex(Polygons{ square }, Polygons{ hole_in_square }); THEN("hole is created") { REQUIRE(result.size() == 1); REQUIRE(square_with_hole.area() == result.front().area()); @@ -77,7 +77,7 @@ SCENARIO("Various Clipper operations - xs/t/11_clipper.t", "[ClipperUtils]") { } } WHEN("diff_pl") { - Polylines result = Slic3r::diff_pl({ polyline }, { square, hole_in_square }); + Polylines result = Slic3r::diff_pl({ polyline }, Polygons{ square, hole_in_square }); THEN("correct number of result lines") { REQUIRE(result.size() == 3); } @@ -180,7 +180,7 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") { // CW oriented contour Slic3r::Polygon hole_in_square { { 14, 14 }, { 14, 16 }, { 16, 16 }, { 16, 14 } }; WHEN("intersection_ex with another square") { - ExPolygons intersection = Slic3r::intersection_ex({ square, hole_in_square }, { square2 }); + ExPolygons intersection = Slic3r::intersection_ex(Polygons{ square, hole_in_square }, Polygons{ square2 }); THEN("intersection area matches (hole is preserved)") { ExPolygon match({ { 20, 18 }, { 10, 18 }, { 10, 12 }, { 20, 12 } }, { { 14, 16 }, { 16, 16 }, { 16, 14 }, { 14, 14 } }); @@ -203,7 +203,7 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") { } } WHEN("diff_ex with another square") { - ExPolygons diff = Slic3r::diff_ex({ square, square2 }, { hole }); + ExPolygons diff = Slic3r::diff_ex(Polygons{ square, square2 }, Polygons{ hole }); THEN("difference of a cw from two ccw is a contour with one hole") { REQUIRE(diff.size() == 1); REQUIRE(diff.front().area() == Approx(ExPolygon({ {40, 40}, {0, 40}, {0, 0}, {40, 0} }, { {15, 25}, {25, 25}, {25, 15}, {15, 15} }).area())); @@ -214,7 +214,7 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") { Slic3r::Polygon square { { 10, 10 }, { 20, 10 }, { 20, 20 }, { 10, 20 } }; Slic3r::Polyline square_pl = square.split_at_first_point(); WHEN("no-op diff_pl") { - Slic3r::Polylines res = Slic3r::diff_pl({ square_pl }, {}); + Slic3r::Polylines res = Slic3r::diff_pl({ square_pl }, Polygons{}); THEN("returns the right number of polylines") { REQUIRE(res.size() == 1); } diff --git a/tests/libslic3r/test_elephant_foot_compensation.cpp b/tests/libslic3r/test_elephant_foot_compensation.cpp index 4e340c37a4..a1c23f4a97 100644 --- a/tests/libslic3r/test_elephant_foot_compensation.cpp +++ b/tests/libslic3r/test_elephant_foot_compensation.cpp @@ -26,7 +26,7 @@ namespace Slic3r { pt.Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; pt.X >>= CLIPPER_OFFSET_POWER_OF_2; pt.Y >>= CLIPPER_OFFSET_POWER_OF_2; - out.emplace_back(coord_t(pt.X), coord_t(pt.Y)); + out.emplace_back(coord_t(pt.x()), coord_t(pt.y())); } return out; } diff --git a/tests/libslic3r/test_placeholder_parser.cpp b/tests/libslic3r/test_placeholder_parser.cpp index e632dc7057..8c56afc6d0 100644 --- a/tests/libslic3r/test_placeholder_parser.cpp +++ b/tests/libslic3r/test_placeholder_parser.cpp @@ -14,9 +14,12 @@ SCENARIO("Placeholder parser scripting", "[PlaceholderParser]") { { "nozzle_diameter", "0.6;0.6;0.6;0.6" }, { "temperature", "357;359;363;378" } }); - // To test the "first_layer_extrusion_width" over "first_layer_heigth" over "layer_height" chain. - config.option("first_layer_height")->value = 150.; - config.option("first_layer_height")->percent = true; + // To test the "first_layer_extrusion_width" over "first_layer_heigth". + // "first_layer_heigth" over "layer_height" is no more supported after first_layer_height was moved from PrintObjectConfig to PrintConfig. +// config.option("first_layer_height")->value = 150.; +// config.option("first_layer_height")->percent = true; + config.option("first_layer_height")->value = 1.5 * config.opt_float("layer_height"); + config.option("first_layer_height")->percent = false; // To let the PlaceholderParser throw when referencing first_layer_speed if it is set to percent, as the PlaceholderParser does not know // a percent to what. config.option("first_layer_speed")->value = 50.; @@ -50,7 +53,7 @@ SCENARIO("Placeholder parser scripting", "[PlaceholderParser]") { SECTION("math: int(-13.4)") { REQUIRE(parser.process("{int(-13.4)}") == "-13"); } // Test the "coFloatOrPercent" and "xxx_extrusion_width" substitutions. - // first_layer_extrusion_width ratio_over first_layer_heigth ratio_over layer_height + // first_layer_extrusion_width ratio_over first_layer_heigth. SECTION("perimeter_extrusion_width") { REQUIRE(std::stod(parser.process("{perimeter_extrusion_width}")) == Approx(0.67500001192092896)); } SECTION("first_layer_extrusion_width") { REQUIRE(std::stod(parser.process("{first_layer_extrusion_width}")) == Approx(0.9)); } SECTION("support_material_xy_spacing") { REQUIRE(std::stod(parser.process("{support_material_xy_spacing}")) == Approx(0.3375)); } diff --git a/tests/libslic3r/test_voronoi.cpp b/tests/libslic3r/test_voronoi.cpp index bbcea7301f..c78849c01e 100644 --- a/tests/libslic3r/test_voronoi.cpp +++ b/tests/libslic3r/test_voronoi.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -1922,3 +1923,238 @@ TEST_CASE("Voronoi skeleton", "[VoronoiSkeleton]") REQUIRE(! skeleton_edges.empty()); } + +// Simple detection with complexity N^2 if there is any point in the input polygons that doesn't have Voronoi vertex. +[[maybe_unused]] static bool has_missing_voronoi_vertices(const Polygons &polygons, const VD &vd) +{ + auto are_equal = [](const VD::vertex_type v, const Point &p) { return (Vec2d(v.x(), v.y()) - p.cast()).norm() <= SCALED_EPSILON; }; + + Points poly_points = to_points(polygons); + std::vector found_vertices(poly_points.size()); + for (const Point &point : poly_points) + for (const auto &vertex : vd.vertices()) + if (are_equal(vertex, point)) { + found_vertices[&point - &poly_points.front()] = true; + break; + } + + return std::find(found_vertices.begin(), found_vertices.end(), false) != found_vertices.end(); +} + +// This case is composed of one square polygon, and one of the edges is divided into two parts by a point that lies on this edge. +// In some applications, this point is unnecessary and can be removed (merge two parts to one edge). But for the case of +// multi-material segmentation, these points are necessary. In this case, Voronoi vertex for the point, which divides the edge +// into two parts. Even we add more points to the edge, and then for these points, the Voronoin vertex is also missing. An +// infinity-edge passes through the missing Voronoi vertex. Therefore, this missing Voronoi vertex and edge can be reconstructed +// using the intersection between the infinity-edge with the input polygon. +// Rotation of the polygon solves this problem. +TEST_CASE("Voronoi missing vertex 1", "[VoronoiMissingVertex1]") +{ + Polygon poly = { + { 25000000, 25000000}, + {-25000000, 25000000}, + {-25000000, -25000000}, + {-12412500, -25000000}, +// {- 1650000, -25000000}, + { 25000000, -25000000} + }; + +// poly.rotate(PI / 6); + + REQUIRE(poly.area() > 0.); + REQUIRE(intersecting_edges({poly}).empty()); + + VD vd; + Lines lines = to_lines(poly); + construct_voronoi(lines.begin(), lines.end(), &vd); +#ifdef VORONOI_DEBUG_OUT + dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex1-out.svg").c_str(), vd, Points(), lines); +#endif + +// REQUIRE(!has_missing_voronoi_vertices({poly}, vd)); +} + +// This case is composed of two square polygons (contour and hole), and again one of the edges is divided into two parts by a +// point that lies on this edge, and for this point is Voronoi vertex missing. A difference between the previous and this case is +// that for this case, through the missing Voronoi vertex is passing a finite edge between two internal Voronoin vertices. +// Therefore, this missing Voronoi vertex and edge can be reconstructed using the intersection between the finite edge with the +// input polygon. +// Rotation of the polygons solves this problem. +TEST_CASE("Voronoi missing vertex 2", "[VoronoiMissingVertex2]") +{ + Polygons poly = { + Polygon { + { 50000000, 50000000}, + {-50000000, 50000000}, + {-50000000, -50000000}, + { 50000000, -50000000}, + }, + Polygon { + {-45000000, -45000000}, + {-45000000, 45000000}, + { 45000000, 45000000}, + { 45000000, 8280000}, + { 45000000, -45000000}, + } + }; + +// polygons_rotate(poly, PI / 6); + + double area = std::accumulate(poly.begin(), poly.end(), 0., [](double a, auto &poly) { return a + poly.area(); }); + REQUIRE(area > 0.); + REQUIRE(intersecting_edges(poly).empty()); + + VD vd; + Lines lines = to_lines(poly); + construct_voronoi(lines.begin(), lines.end(), &vd); +#ifdef VORONOI_DEBUG_OUT + dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex2-out.svg").c_str(), vd, Points(), lines); +#endif + +// REQUIRE(!has_missing_voronoi_vertices(poly, vd)); +} + +// This case is composed of two polygons, and again one of the edges is divided into two parts by a point that lies on this edge, +// and for this point is Voronoi vertex missing. A difference between the previous cases and this case through the missing +// Voronoi vertex is passing finite edge between one inner Voronoi vertex and one outer Voronoi vertex. +// Rotating the polygon also help solve this problem. +TEST_CASE("Voronoi missing vertex 3", "[VoronoiMissingVertex3]") +{ + Polygons poly = { + Polygon { + {-29715088, -29310899}, + {-29022573, -28618384}, + {-27771147, -27366958}, + {-28539221, -26519393}, + {-30619013, -28586348}, + {-29812018, -29407830}, + }, + Polygon { + {-27035112, -28071875}, + {-27367482, -27770679}, + {-28387008, -28790205}, + {-29309438, -29712635}, + {-29406319, -29809515}, + {-29032985, -30179156}, + } + }; + double area = std::accumulate(poly.begin(), poly.end(), 0., [](double a, auto &poly){ return a + poly.area(); }); + REQUIRE(area > 0.); + REQUIRE(intersecting_edges(poly).empty()); + + // polygons_rotate(poly, PI/180); + // polygons_rotate(poly, PI/6); + + VD vd; + Lines lines = to_lines(poly); + construct_voronoi(lines.begin(), lines.end(), &vd); +#ifdef VORONOI_DEBUG_OUT + dump_voronoi_to_svg(debug_out_path("voronoi-missing-vertex3-out.svg").c_str(), vd, Points(), lines); +#endif + +// REQUIRE(!has_missing_voronoi_vertices(poly, vd)); +} + +// In this case, the Voronoi vertex (146873, -146873) is included twice. +// Also, near to those duplicate Voronoi vertices is another Voronoi vertex (146872, -146872). +// Rotating the polygon will help solve this problem, but then there arise three very close Voronoi vertices. +// Rotating of the input polygon will help solve this problem. +TEST_CASE("Duplicate Voronoi vertices", "[Voronoi]") +{ + Polygon poly = { + { 25000000, 25000000}, + {-25000000, 25000000}, + {-25000000, -25000000}, + { 146872, -25000000}, + { 9912498, -25000000}, + { 25000000, -25000000}, + { 25000000, - 8056252}, + { 25000000, - 146873}, + { 25000000, 10790627}, + }; + +// poly.rotate(PI / 6); + + REQUIRE(poly.area() > 0.); + REQUIRE(intersecting_edges({poly}).empty()); + + VD vd; + Lines lines = to_lines(poly); + construct_voronoi(lines.begin(), lines.end(), &vd); +#ifdef VORONOI_DEBUG_OUT + dump_voronoi_to_svg(debug_out_path("voronoi-duplicate-vertices-out.svg").c_str(), vd, Points(), lines); +#endif + + [[maybe_unused]] auto has_duplicate_vertices = [](const VD &vd) -> bool { + std::vector vertices; + for (const auto &vertex : vd.vertices()) + vertices.emplace_back(Vec2d(vertex.x(), vertex.y())); + + std::sort(vertices.begin(), vertices.end(), [](const Vec2d &l, const Vec2d &r) { return l.x() < r.x() || (l.x() == r.x() && l.y() < r.y()); }); + return std::unique(vertices.begin(), vertices.end()) != vertices.end(); + }; + +// REQUIRE(!has_duplicate_vertices(vd)); +} + +// In this case, there are three very close Voronoi vertices like in the previous test case after rotation. There is also one +// missing Voronoi vertex. One infinity-edge (after clip [(146872, -70146871), (146872, -146871)]) passes through this missing +// Voronoi vertex. This infinite edge [(146872, -70146871), (146872, -146871)] and edge [(146873, -146873), (0, 0)] are intersecting. +// They intersect probably because the three points are very close to each other, with a combination of the missing Voronoi vertex. +// Rotating of the input polygon will help solve this problem. +TEST_CASE("Intersecting Voronoi edges", "[Voronoi]") +{ + Polygon poly = { + { 25000000, 25000000}, + {-25000000, 25000000}, + {-25000000, -25000000}, + { 146872, -25000000}, + { 25000000, -25000000}, + { 25000000, - 146873}, + }; + +// poly.rotate(PI / 6); + + REQUIRE(poly.area() > 0.); + REQUIRE(intersecting_edges({poly}).empty()); + + VD vd; + Lines lines = to_lines(poly); + construct_voronoi(lines.begin(), lines.end(), &vd); +#ifdef VORONOI_DEBUG_OUT + dump_voronoi_to_svg(debug_out_path("voronoi-intersecting-edges-out.svg").c_str(), vd, Points(), lines); +#endif + + [[maybe_unused]] auto has_intersecting_edges = [](const Polygon &poly, const VD &vd) -> bool { + BoundingBox bbox = get_extents(poly); + const double bbox_dim_max = double(std::max(bbox.size().x(), bbox.size().y())); + + std::vector segments; + for (const Line &line : to_lines(poly)) + segments.emplace_back(Voronoi::Internal::point_type(double(line.a.x()), double(line.a.y())), + Voronoi::Internal::point_type(double(line.b.x()), double(line.b.y()))); + + Lines edges; + for (const auto &edge : vd.edges()) + if (edge.cell()->source_index() < edge.twin()->cell()->source_index()) { + if (edge.is_finite()) { + edges.emplace_back(Point(coord_t(edge.vertex0()->x()), coord_t(edge.vertex0()->y())), + Point(coord_t(edge.vertex1()->x()), coord_t(edge.vertex1()->y()))); + } else if (edge.is_infinite()) { + std::vector samples; + Voronoi::Internal::clip_infinite_edge(poly.points, segments, edge, bbox_dim_max, &samples); + if (!samples.empty()) + edges.emplace_back(Point(coord_t(samples[0].x()), coord_t(samples[0].y())), Point(coord_t(samples[1].x()), coord_t(samples[1].y()))); + } + } + + Point intersect_point; + for (auto first_it = edges.begin(); first_it != edges.end(); ++first_it) + for (auto second_it = first_it + 1; second_it != edges.end(); ++second_it) + if (first_it->intersection(*second_it, &intersect_point) && first_it->a != intersect_point && first_it->b != intersect_point) + return true; + return false; + }; + +// REQUIRE(!has_intersecting_edges(poly, vd)); +} diff --git a/tests/sla_print/sla_print_tests.cpp b/tests/sla_print/sla_print_tests.cpp index bdd5731dcc..1f98463cc3 100644 --- a/tests/sla_print/sla_print_tests.cpp +++ b/tests/sla_print/sla_print_tests.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "sla_test_utils.hpp" @@ -248,7 +249,7 @@ TEST_CASE("Test concurrency") double ref = std::accumulate(vals.begin(), vals.end(), 0.); - double s = sla::ccr_par::reduce(vals.begin(), vals.end(), 0., std::plus{}); + double s = execution::accumulate(ex_tbb, vals.begin(), vals.end(), 0.); REQUIRE(s == Approx(ref)); } diff --git a/xs/t/15_config.t b/xs/t/15_config.t index 55b6791015..4d032019c2 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 147; +use Test::More tests => 143; foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintConfig) { $config->set('layer_height', 0.3); @@ -70,10 +70,11 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintCo ok abs($config->get('first_layer_height') - 0.3) < 1e-4, 'set/get absolute floatOrPercent'; is $config->opt_serialize('first_layer_height'), '0.3', 'serialize absolute floatOrPercent'; - $config->set('first_layer_height', '50%'); - $config->get_abs_value('first_layer_height'); - ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent'; - is $config->opt_serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent'; +# This is no more supported after first_layer_height was moved from PrintObjectConfig to PrintConfig. +# $config->set('first_layer_height', $config->get('layer_height')); +# $config->get_abs_value('first_layer_height'); +# ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent'; +# is $config->opt_serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent'; # Uh-oh, we have no point option to test at the moment #ok $config->set('print_center', [50,80]), 'valid point coordinates'; diff --git a/xs/xsp/Clipper.xsp b/xs/xsp/Clipper.xsp index 277b598259..c4640dcf4f 100644 --- a/xs/xsp/Clipper.xsp +++ b/xs/xsp/Clipper.xsp @@ -2,7 +2,6 @@ %{ #include -#include "clipper.hpp" #include "libslic3r/ClipperUtils.hpp" %} @@ -21,10 +20,10 @@ _constant() OUTPUT: RETVAL Polygons -offset(polygons, delta, joinType = ClipperLib::jtMiter, miterLimit = 3) +offset(polygons, delta, joinType = Slic3r::ClipperLib::jtMiter, miterLimit = 3) Polygons polygons const float delta - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: RETVAL = offset(polygons, delta, joinType, miterLimit); @@ -32,10 +31,10 @@ offset(polygons, delta, joinType = ClipperLib::jtMiter, miterLimit = 3) RETVAL ExPolygons -offset_ex(polygons, delta, joinType = ClipperLib::jtMiter, miterLimit = 3) +offset_ex(polygons, delta, joinType = Slic3r::ClipperLib::jtMiter, miterLimit = 3) Polygons polygons const float delta - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: RETVAL = offset_ex(polygons, delta, joinType, miterLimit); @@ -43,11 +42,11 @@ offset_ex(polygons, delta, joinType = ClipperLib::jtMiter, miterLimit = 3) RETVAL Polygons -offset2(polygons, delta1, delta2, joinType = ClipperLib::jtMiter, miterLimit = 3) +offset2(polygons, delta1, delta2, joinType = Slic3r::ClipperLib::jtMiter, miterLimit = 3) Polygons polygons const float delta1 const float delta2 - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: RETVAL = offset2(polygons, delta1, delta2, joinType, miterLimit); @@ -55,11 +54,11 @@ offset2(polygons, delta1, delta2, joinType = ClipperLib::jtMiter, miterLimit = 3 RETVAL ExPolygons -offset2_ex(polygons, delta1, delta2, joinType = ClipperLib::jtMiter, miterLimit = 3) +offset2_ex(polygons, delta1, delta2, joinType = Slic3r::ClipperLib::jtMiter, miterLimit = 3) Polygons polygons const float delta1 const float delta2 - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: RETVAL = offset2_ex(polygons, delta1, delta2, joinType, miterLimit); diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index d8b60bc846..52a5e7d839 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -108,7 +108,7 @@ std::string get_extrusion_axis() %code{% if (GCodeConfig* config = dynamic_cast(THIS)) { - RETVAL = config->get_extrusion_axis(); + RETVAL = get_extrusion_axis(*config); } else { CONFESS("This StaticConfig object does not provide get_extrusion_axis()"); } diff --git a/xs/xsp/Polyline.xsp b/xs/xsp/Polyline.xsp index 0dbd0e5728..10bbb263f8 100644 --- a/xs/xsp/Polyline.xsp +++ b/xs/xsp/Polyline.xsp @@ -79,9 +79,9 @@ Polyline::rotate(angle, center_sv) THIS->rotate(angle, center); Polygons -Polyline::grow(delta, joinType = ClipperLib::jtSquare, miterLimit = 3) +Polyline::grow(delta, joinType = Slic3r::ClipperLib::jtSquare, miterLimit = 3) const float delta - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: RETVAL = offset(*THIS, delta, joinType, miterLimit); diff --git a/xs/xsp/Surface.xsp b/xs/xsp/Surface.xsp index 379774f0a4..49d988333c 100644 --- a/xs/xsp/Surface.xsp +++ b/xs/xsp/Surface.xsp @@ -85,7 +85,7 @@ Surface::polygons() Surfaces Surface::offset(delta, joinType = ClipperLib::jtMiter, miterLimit = 3) const float delta - ClipperLib::JoinType joinType + Slic3r::ClipperLib::JoinType joinType double miterLimit CODE: surfaces_append(RETVAL, offset_ex(THIS->expolygon, delta, joinType, miterLimit), *THIS); diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 2ecff6e3f4..54e686ae36 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -211,8 +211,8 @@ FlowRole T_UV PrintStep T_UV PrintObjectStep T_UV SurfaceType T_UV -ClipperLib::JoinType T_UV -ClipperLib::PolyFillType T_UV +Slic3r::ClipperLib::JoinType T_UV +Slic3r::ClipperLib::PolyFillType T_UV # we return these types whenever we want the items to be cloned Points T_ARRAYREF