From d57725ee183e3730a7bcc3778fd880cc31771a39 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 30 Aug 2018 16:08:25 +0200 Subject: [PATCH 01/31] Bumped up the version number to 1.41.0 release, bundled updated PrusaResearch configs. --- resources/profiles/PrusaResearch.idx | 10 ++- resources/profiles/PrusaResearch.ini | 117 ++++++++++++++++++++------- xs/src/libslic3r/libslic3r.h | 2 +- 3 files changed, 98 insertions(+), 31 deletions(-) diff --git a/resources/profiles/PrusaResearch.idx b/resources/profiles/PrusaResearch.idx index ba4123588..7a0c58aa6 100644 --- a/resources/profiles/PrusaResearch.idx +++ b/resources/profiles/PrusaResearch.idx @@ -1,8 +1,12 @@ -min_slic3r_version = 1.41.0-alpha +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 Fixed the *MK3* references -0.2.0-alpha6 +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 diff --git a/resources/profiles/PrusaResearch.ini b/resources/profiles/PrusaResearch.ini index 32ec800e7..ab86af976 100644 --- a/resources/profiles/PrusaResearch.ini +++ b/resources/profiles/PrusaResearch.ini @@ -5,7 +5,7 @@ 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 Slic3r configuration to be downgraded. -config_version = 0.2.0-beta +config_version = 0.2.1 # Where to get the updates from? config_update_url = https://raw.githubusercontent.com/prusa3d/Slic3r-settings/master/live/PrusaResearch/ @@ -67,7 +67,7 @@ fill_pattern = cubic first_layer_acceleration = 1000 first_layer_extrusion_width = 0.42 first_layer_height = 0.2 -first_layer_speed = 30 +first_layer_speed = 20 gap_fill_speed = 40 gcode_comments = 0 infill_every_layers = 1 @@ -113,7 +113,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.15 +support_material_contact_distance = 0.1 support_material_interface_contact_loops = 0 support_material_interface_layers = 2 support_material_interface_spacing = 0.2 @@ -122,9 +122,9 @@ support_material_pattern = rectilinear support_material_spacing = 2 support_material_speed = 50 support_material_synchronize_layers = 0 -support_material_threshold = 45 +support_material_threshold = 55 support_material_with_sheath = 0 -support_material_xy_spacing = 60% +support_material_xy_spacing = 50% thin_walls = 0 top_infill_extrusion_width = 0.45 top_solid_infill_speed = 40 @@ -133,13 +133,15 @@ wipe_tower = 1 wipe_tower_bridging = 10 wipe_tower_rotation_angle = 0 wipe_tower_width = 60 -wipe_tower_x = 180 -wipe_tower_y = 135 +wipe_tower_x = 170 +wipe_tower_y = 140 xy_size_compensation = 0 [print:*MK3*] fill_pattern = grid single_extruder_multi_material_priming = 0 +wipe_tower_x = 170 +wipe_tower_y = 125 # Print parameters common to a 0.25mm diameter nozzle. [print:*0.25nozzle*] @@ -557,13 +559,17 @@ compatible_printers_condition = ! (printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ a end_filament_gcode = "; Filament-specific end gcode" extrusion_multiplier = 1 filament_loading_speed = 28 +filament_loading_speed_start = 3 filament_unloading_speed = 90 +filament_unloading_speed_start = 100 filament_toolchange_delay = 0 filament_cooling_moves = 4 filament_cooling_initial_speed = 2.2 filament_cooling_final_speed = 3.4 +filament_load_time = 0 +filament_unload_time = 0 filament_ramming_parameters = "120 100 6.6 6.8 7.2 7.6 7.9 8.2 8.7 9.4 9.9 10.0| 0.05 6.6 0.45 6.8 0.95 7.8 1.45 8.3 1.95 9.7 2.45 10 2.95 7.6 3.45 7.6 3.95 7.6 4.45 7.6 4.95 7.6" -filament_minimal_purge_on_wipe_tower = 5 +filament_minimal_purge_on_wipe_tower = 15 filament_cost = 0 filament_density = 0 filament_diameter = 1.75 @@ -664,6 +670,8 @@ cooling = 1 disable_fan_first_layers = 3 fan_always_on = 0 fan_below_layer_time = 10 +filament_cost = 58.66 +filament_density = 1.18 first_layer_bed_temperature = 105 first_layer_temperature = 270 max_fan_speed = 20 @@ -741,7 +749,7 @@ temperature = 260 [filament:E3D Edge] inherits = *PET* -filament_cost = 0 +filament_cost = 56.9 filament_density = 1.26 filament_notes = "List of manufacturers tested with standart PET print settings for MK2:\n\nE3D Edge\nFillamentum CPE GH100\nPlasty Mladeč PETG" @@ -754,14 +762,14 @@ temperature = 270 [filament:Fillamentum ABS] inherits = *ABS* -filament_cost = 0 +filament_cost = 32.4 filament_density = 1.04 first_layer_temperature = 240 temperature = 240 [filament:Fillamentum ASA] inherits = *ABS* -filament_cost = 0 +filament_cost = 38.7 filament_density = 1.04 fan_always_on = 1 first_layer_temperature = 265 @@ -769,7 +777,7 @@ temperature = 265 [filament:Fillamentum CPE HG100 HM100] inherits = *PET* -filament_cost = 0 +filament_cost = 54.1 filament_density = 1.25 filament_notes = "CPE HG100 , CPE HM100" first_layer_bed_temperature = 90 @@ -783,7 +791,7 @@ inherits = *PLA* # For now, all but selected filaments are disabled for the MMU 2.0 compatible_printers_condition = nozzle_diameter[0]>0.35 and ! (printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and single_extruder_multi_material) extrusion_multiplier = 1.2 -filament_cost = 0 +filament_cost = 68 filament_density = 1.15 filament_colour = #804040 filament_max_volumetric_speed = 10 @@ -793,24 +801,26 @@ temperature = 190 [filament:Generic ABS] inherits = *ABS* -filament_cost = 0 +filament_cost = 27.82 filament_density = 1.04 filament_notes = "List of materials tested with standart ABS print settings for MK2:\n\nEsun ABS\nFil-A-Gehr ABS\nHatchboxABS\nPlasty Mladeč ABS" [filament:Generic PET] inherits = *PET* -filament_cost = 0 +filament_cost = 27.82 filament_density = 1.24 filament_notes = "List of manufacturers tested with standart PET print settings for MK2:\n\nE3D Edge\nFillamentum CPE GH100\nPlasty Mladeč PETG" [filament:Generic PLA] inherits = *PLA* -filament_cost = 0 +filament_cost = 25.4 filament_density = 1.27 filament_notes = "List of materials tested with standart PLA print settings for MK2:\n\nDas Filament\nEsun PLA\nEUMAKERS PLA\nFiberlogy HD-PLA\nFillamentum PLA\nFloreon3D\nHatchbox PLA\nPlasty Mladeč PLA\nPrimavalue PLA\nProto pasta Matte Fiber\nVerbatim PLA\nVerbatim BVOH" [filament:Polymaker PC-Max] inherits = *ABS* +filament_cost = 77.3 +filament_density = 1.20 bed_temperature = 115 filament_colour = #3A80CA first_layer_bed_temperature = 100 @@ -819,6 +829,8 @@ temperature = 270 [filament:Primavalue PVA] inherits = *PLA* +filament_cost = 108 +filament_density = 1.23 cooling = 0 fan_always_on = 0 filament_colour = #FFFFD7 @@ -843,10 +855,7 @@ compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and filament_cooling_final_speed = 50 filament_cooling_initial_speed = 10 filament_cooling_moves = 5 -filament_loading_speed = 14 filament_ramming_parameters = "120 110 5.32258 5.45161 5.67742 6 6.48387 7.12903 7.90323 8.70968 9.3871 9.83871 10.0968 10.2258| 0.05 5.30967 0.45 5.50967 0.95 6.1871 1.45 7.39677 1.95 9.05484 2.45 10 2.95 10.3098 3.45 13.0839 3.95 7.6 4.45 7.6 4.95 7.6"; -filament_load_time = 12 -filament_unload_time = 11 [filament:Generic ABS MMU2] inherits = *ABS MMU2* @@ -856,6 +865,8 @@ inherits = *ABS MMU2* [filament:Prusa HIPS] inherits = *ABS* +filament_cost = 27.3 +filament_density = 1.04 bridge_fan_speed = 50 cooling = 1 extrusion_multiplier = 0.9 @@ -876,6 +887,28 @@ filament_cost = 27.82 filament_density = 1.27 filament_notes = "List of manufacturers tested with standart PET print settings for MK2:\n\nE3D Edge\nFillamentum CPE GH100\nPlasty Mladeč PETG" +[filament:*PET MMU2*] +inherits = Prusa PET +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and single_extruder_multi_material +temperature = 230 +first_layer_temperature = 230 +filament_cooling_final_speed = 1 +filament_cooling_initial_speed = 2 +filament_cooling_moves = 1 +filament_load_time = 12 +filament_loading_speed = 14 +filament_notes = PET +filament_ramming_parameters = "120 140 4.70968 4.74194 4.77419 4.80645 4.83871 4.87097 4.90323 5 5.25806 5.67742 6.29032 7.06452 7.83871 8.3871| 0.05 4.72901 0.45 4.73545 0.95 4.83226 1.45 4.88067 1.95 5.05483 2.45 5.93553 2.95 7.53556 3.45 8.6323 3.95 7.6 4.45 7.6 4.95 7.6" +filament_unload_time = 11 +filament_unloading_speed = 20 +filament_unloading_speed_start = 120 + +[filament:Generic PET MMU2] +inherits = *PET MMU2* + +[filament:Prusa PET MMU2] +inherits = *PET MMU2* + [filament:Prusa PLA] inherits = *PLA* filament_cost = 25.4 @@ -885,13 +918,15 @@ filament_notes = "List of materials tested with standart PLA print settings for [filament:*PLA MMU2*] inherits = Prusa PLA compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and single_extruder_multi_material -filament_cooling_final_speed = 50 -filament_cooling_initial_speed = 10 -filament_cooling_moves = 7 -filament_loading_speed = 14 -filament_ramming_parameters = "120 110 4.03226 4.12903 4.25806 4.41935 4.58065 4.80645 5.35484 6.29032 7.58065 9.09677 10.5806 11.8387 12.6452 12.9677| 0.05 4.01935 0.45 4.15483 0.95 4.50968 1.45 4.94516 1.95 6.79677 2.45 9.87102 2.95 12.4388 3.45 13.0839 3.95 7.6 4.45 7.6 4.95 7.6" +temperature = 205 +filament_cooling_final_speed = 1 +filament_cooling_initial_speed = 2 +filament_cooling_moves = 1 filament_load_time = 12 +filament_loading_speed = 14 +filament_ramming_parameters = "120 110 2.70968 2.93548 3.32258 3.83871 4.58065 5.54839 6.51613 7.35484 7.93548 8.16129| 0.05 2.66451 0.45 3.05805 0.95 4.05807 1.45 5.97742 1.95 7.69999 2.45 8.1936 2.95 11.342 3.45 11.4065 3.95 7.6 4.45 7.6 4.95 7.6" filament_unload_time = 11 +filament_unloading_speed = 20 [filament:Generic PLA MMU2] inherits = *PLA MMU2* @@ -901,11 +936,13 @@ inherits = *PLA MMU2* [filament:SemiFlex or Flexfill 98A] inherits = *FLEX* -filament_cost = 0 +filament_cost = 82 filament_density = 1.22 [filament:Taulman Bridge] inherits = *common* +filament_cost = 40 +filament_density = 1.13 bed_temperature = 90 bridge_fan_speed = 40 cooling = 0 @@ -925,6 +962,8 @@ temperature = 250 [filament:Taulman T-Glase] inherits = *PET* +filament_cost = 40 +filament_density = 1.27 bridge_fan_speed = 40 cooling = 0 fan_always_on = 0 @@ -936,6 +975,8 @@ start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}200{el [filament:Verbatim BVOH] inherits = *common* +filament_cost = 218 +filament_density = 1.23 bed_temperature = 60 bridge_fan_speed = 100 cooling = 0 @@ -944,7 +985,7 @@ extrusion_multiplier = 1 fan_always_on = 0 fan_below_layer_time = 100 filament_colour = #FFFFD7 -filament_max_volumetric_speed = 10 +filament_max_volumetric_speed = 4 filament_notes = "List of materials tested with standart PLA print settings for MK2:\n\nDas Filament\nEsun PLA\nEUMAKERS PLA\nFiberlogy HD-PLA\nFillamentum PLA\nFloreon3D\nHatchbox PLA\nPlasty Mladeč PLA\nPrimavalue PLA\nProto pasta Matte Fiber\nVerbatim PLA\nVerbatim BVOH" filament_soluble = 1 filament_type = PLA @@ -955,8 +996,29 @@ min_fan_speed = 100 start_filament_gcode = "M900 K{if printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}200{else}10{endif}; Filament gcode" temperature = 210 +[filament:Verbatim BVOH MMU2] +inherits = Verbatim BVOH +compatible_printers_condition = printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK3.*/ and single_extruder_multi_material +temperature = 195 +filament_notes = BVOH +fan_always_on = 1 +first_layer_temperature = 200 +filament_cooling_final_speed = 1 +filament_cooling_initial_speed = 2 +filament_max_volumetric_speed = 4 +filament_type = PVA +filament_cooling_moves = 1 +filament_load_time = 12 +filament_loading_speed = 14 +filament_ramming_parameters = "120 110 1.74194 1.90323 2.16129 2.48387 2.83871 3.25806 3.83871 4.6129 5.41935 5.96774| 0.05 1.69677 0.45 1.96128 0.95 2.63872 1.45 3.46129 1.95 4.99031 2.45 6.12908 2.95 8.30974 3.45 11.4065 3.95 7.6 4.45 7.6 4.95 7.6" +filament_unload_time = 11 +filament_unloading_speed = 20 +filament_unloading_speed_start = 100 + [filament:Verbatim PP] inherits = *common* +filament_cost = 72 +filament_density = 0.89 bed_temperature = 100 bridge_fan_speed = 100 cooling = 1 @@ -1215,6 +1277,7 @@ 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;#0080FF;#00FFFF;#FF4F4F;#9FFF9F start_gcode = M107\nM115 U3.3.1 ; tell printer latest fw version\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\nG21 ; set units to millimeters\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\n;M221 S{if layer_height<0.075}100{else}95{endif}\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG92 E0.0\n @@ -1223,4 +1286,4 @@ end_gcode = {if has_wipe_tower}\nG1 E-15.0000 F3000\n{else}\nG1 X0 Y210 F7200\nG # The obsolete presets will be removed when upgrading from the legacy configuration structure (up to Slic3r 1.39.2) to 1.40.0 and newer. [obsolete_presets] print="0.05mm DETAIL 0.25 nozzle";"0.05mm DETAIL MK3";"0.05mm DETAIL";"0.20mm NORMAL MK3";"0.35mm FAST MK3";"print:0.15mm OPTIMAL MK3 MMU2";"print:0.20mm FAST MK3 MMU2" -filament="ColorFabb Brass Bronze 1.75mm";"ColorFabb HT 1.75mm";"ColorFabb nGen 1.75mm";"ColorFabb Woodfil 1.75mm";"ColorFabb XT 1.75mm";"ColorFabb XT-CF20 1.75mm";"E3D PC-ABS 1.75mm";"Fillamentum ABS 1.75mm";"Fillamentum ASA 1.75mm";"Generic ABS 1.75mm";"Generic PET 1.75mm";"Generic PLA 1.75mm";"Prusa ABS 1.75mm";"Prusa HIPS 1.75mm";"Prusa PET 1.75mm";"Prusa PLA 1.75mm";"Taulman Bridge 1.75mm";"Taulman T-Glase 1.75mm" +filament="ColorFabb Brass Bronze 1.75mm";"ColorFabb HT 1.75mm";"ColorFabb nGen 1.75mm";"ColorFabb Woodfil 1.75mm";"ColorFabb XT 1.75mm";"ColorFabb XT-CF20 1.75mm";"E3D PC-ABS 1.75mm";"Fillamentum ABS 1.75mm";"Fillamentum ASA 1.75mm";"Generic ABS 1.75mm";"Generic PET 1.75mm";"Generic PLA 1.75mm";"Prusa ABS 1.75mm";"Prusa HIPS 1.75mm";"Prusa PET 1.75mm";"Prusa PLA 1.75mm";"Taulman Bridge 1.75mm";"Taulman T-Glase 1.75mm" \ No newline at end of file diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 6db60440b..ddd056bc7 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -14,7 +14,7 @@ #include #define SLIC3R_FORK_NAME "Slic3r Prusa Edition" -#define SLIC3R_VERSION "1.41.0-beta2" +#define SLIC3R_VERSION "1.41.0" #define SLIC3R_BUILD "UNKNOWN" typedef int32_t coord_t; From 453e7e37d3335c6fc1050d23f2e4cd7d11adc01c Mon Sep 17 00:00:00 2001 From: bubnikv Date: Sat, 1 Sep 2018 09:54:02 +0200 Subject: [PATCH 02/31] Bundled newer versions of PrusaResearch profiles. --- resources/profiles/PrusaResearch.idx | 2 ++ resources/profiles/PrusaResearch.ini | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/profiles/PrusaResearch.idx b/resources/profiles/PrusaResearch.idx index 7a0c58aa6..63a81db49 100644 --- a/resources/profiles/PrusaResearch.idx +++ b/resources/profiles/PrusaResearch.idx @@ -1,3 +1,5 @@ +min_slic3r_version = 1.41.0-alpha +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 diff --git a/resources/profiles/PrusaResearch.ini b/resources/profiles/PrusaResearch.ini index ab86af976..3b44a4bc7 100644 --- a/resources/profiles/PrusaResearch.ini +++ b/resources/profiles/PrusaResearch.ini @@ -5,7 +5,7 @@ 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 Slic3r configuration to be downgraded. -config_version = 0.2.1 +config_version = 0.2.2 # Where to get the updates from? config_update_url = https://raw.githubusercontent.com/prusa3d/Slic3r-settings/master/live/PrusaResearch/ @@ -1269,7 +1269,7 @@ default_filament_profile = Prusa PLA MMU2 [printer:Original Prusa i3 MK3 MMU2 Single] inherits = *mm2* -start_gcode = M107\nM115 U3.3.1 ; tell printer latest fw version\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\nG21 ; set units to millimeters\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT?\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\n\nM221 S{if layer_height<0.075}100{else}95{endif}\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG92 E0.0\n +start_gcode = M107\nM115 U3.4.0-RC2 ; tell printer latest fw version\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\nG21 ; set units to millimeters\n\n;go outside print area\nG1 Y-3.0 F1000.0\nG1 Z0.4 F1000.0\n; select extruder\nT?\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}\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG92 E0.0\n end_gcode = G1 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\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nG1 X0 Y200; home X axis\nM84 ; disable motors [printer:Original Prusa i3 MK3 MMU2] @@ -1280,10 +1280,10 @@ inherits = *mm2* machine_max_acceleration_e = 8000,8000 nozzle_diameter = 0.4,0.4,0.4,0.4,0.4 extruder_colour = #FF8000;#0080FF;#00FFFF;#FF4F4F;#9FFF9F -start_gcode = M107\nM115 U3.3.1 ; tell printer latest fw version\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\nG21 ; set units to millimeters\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\n;M221 S{if layer_height<0.075}100{else}95{endif}\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG92 E0.0\n +start_gcode = M107\nM115 U3.4.0-RC2 ; tell printer latest fw version\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\nG21 ; set units to millimeters\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}\nG90 ; use absolute coordinates\nM83 ; use relative distances for extrusion\nG92 E0.0\n end_gcode = {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\n; Unload filament\nM702 C\n\nG4 ; wait\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\n; Lift print head a bit\n{if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up\nG1 X0 Y200; home X axis\nM84 ; disable motors\n # The obsolete presets will be removed when upgrading from the legacy configuration structure (up to Slic3r 1.39.2) to 1.40.0 and newer. [obsolete_presets] print="0.05mm DETAIL 0.25 nozzle";"0.05mm DETAIL MK3";"0.05mm DETAIL";"0.20mm NORMAL MK3";"0.35mm FAST MK3";"print:0.15mm OPTIMAL MK3 MMU2";"print:0.20mm FAST MK3 MMU2" -filament="ColorFabb Brass Bronze 1.75mm";"ColorFabb HT 1.75mm";"ColorFabb nGen 1.75mm";"ColorFabb Woodfil 1.75mm";"ColorFabb XT 1.75mm";"ColorFabb XT-CF20 1.75mm";"E3D PC-ABS 1.75mm";"Fillamentum ABS 1.75mm";"Fillamentum ASA 1.75mm";"Generic ABS 1.75mm";"Generic PET 1.75mm";"Generic PLA 1.75mm";"Prusa ABS 1.75mm";"Prusa HIPS 1.75mm";"Prusa PET 1.75mm";"Prusa PLA 1.75mm";"Taulman Bridge 1.75mm";"Taulman T-Glase 1.75mm" \ No newline at end of file +filament="ColorFabb Brass Bronze 1.75mm";"ColorFabb HT 1.75mm";"ColorFabb nGen 1.75mm";"ColorFabb Woodfil 1.75mm";"ColorFabb XT 1.75mm";"ColorFabb XT-CF20 1.75mm";"E3D PC-ABS 1.75mm";"Fillamentum ABS 1.75mm";"Fillamentum ASA 1.75mm";"Generic ABS 1.75mm";"Generic PET 1.75mm";"Generic PLA 1.75mm";"Prusa ABS 1.75mm";"Prusa HIPS 1.75mm";"Prusa PET 1.75mm";"Prusa PLA 1.75mm";"Taulman Bridge 1.75mm";"Taulman T-Glase 1.75mm" From 22569de00fb05d3e69695d1a07819b795bbde134 Mon Sep 17 00:00:00 2001 From: Martin Loidl Date: Sat, 25 Aug 2018 08:50:42 +0200 Subject: [PATCH 03/31] fixes date for uploaded files --- xs/src/slic3r/Utils/Duet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/slic3r/Utils/Duet.cpp b/xs/src/slic3r/Utils/Duet.cpp index 865d2b418..82a42eb71 100644 --- a/xs/src/slic3r/Utils/Duet.cpp +++ b/xs/src/slic3r/Utils/Duet.cpp @@ -230,7 +230,7 @@ std::string Duet::timestamp_str() const auto tm = *std::localtime(&t); char buffer[BUFFER_SIZE]; - std::strftime(buffer, BUFFER_SIZE, "time=%Y-%d-%mT%H:%M:%S", &tm); + std::strftime(buffer, BUFFER_SIZE, "time=%Y-%m-%dT%H:%M:%S", &tm); return std::string(buffer); } From 5f2afad95eaa6dfeb81e772f37adfa1d0812788f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 4 Sep 2018 12:41:14 +0200 Subject: [PATCH 04/31] Fixed render of picking pass for flatten gizmo --- xs/src/slic3r/GUI/GLGizmo.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index be085e913..2980e34a1 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1031,8 +1031,6 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const Vec3d dragged_offset = box.center() - *m_center; - bool blending_was_enabled = ::glIsEnabled(GL_BLEND); - bool depth_test_was_enabled = ::glIsEnabled(GL_DEPTH_TEST); ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); @@ -1053,16 +1051,11 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const ::glPopMatrix(); } } - - if (!blending_was_enabled) - ::glDisable(GL_BLEND); - if (!depth_test_was_enabled) - ::glDisable(GL_DEPTH_TEST); } void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const { - ::glDisable(GL_DEPTH_TEST); + ::glEnable(GL_DEPTH_TEST); for (unsigned int i = 0; i < m_planes.size(); ++i) { From 15b13405141ca7481f156d204a917fab38c30dc1 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 4 Sep 2018 14:42:14 +0200 Subject: [PATCH 05/31] Added ModelInstance::world_matrix() method and stl_transform using eigen transform --- lib/Slic3r/GUI/Plater.pm | 5 +-- xs/src/admesh/stl.h | 1 + xs/src/admesh/util.cpp | 41 ++++++++++++++++++ xs/src/libslic3r/Model.cpp | 70 ++++++++++++++----------------- xs/src/libslic3r/Model.hpp | 2 + xs/src/libslic3r/TriangleMesh.cpp | 9 +++- xs/src/libslic3r/TriangleMesh.hpp | 1 + xs/src/slic3r/GUI/GLGizmo.cpp | 6 +-- 8 files changed, 89 insertions(+), 46 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 00267fe63..ce9e0da68 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1141,13 +1141,12 @@ sub rotate { } # Let's calculate vector of rotation axis (if we don't have it already) - # The minus is there so that the direction is the same as was established if (defined $axis) { if ($axis == X) { - $axis_x = -1; + $axis_x = 1; } if ($axis == Y) { - $axis_y = -1; + $axis_y = 1; } } diff --git a/xs/src/admesh/stl.h b/xs/src/admesh/stl.h index 5f7a3c5c1..096430d15 100644 --- a/xs/src/admesh/stl.h +++ b/xs/src/admesh/stl.h @@ -173,6 +173,7 @@ extern void stl_mirror_xy(stl_file *stl); extern void stl_mirror_yz(stl_file *stl); extern void stl_mirror_xz(stl_file *stl); extern void stl_transform(stl_file *stl, float *trafo3x4); +extern void stl_transform(stl_file *stl, const Eigen::Transform& t); extern void stl_open_merge(stl_file *stl, char *file); extern void stl_invalidate_shared_vertices(stl_file *stl); extern void stl_generate_shared_vertices(stl_file *stl); diff --git a/xs/src/admesh/util.cpp b/xs/src/admesh/util.cpp index fba1ee76b..cc104fdd1 100644 --- a/xs/src/admesh/util.cpp +++ b/xs/src/admesh/util.cpp @@ -155,6 +155,47 @@ void stl_transform(stl_file *stl, float *trafo3x4) { calculate_normals(stl); } +void stl_transform(stl_file *stl, const Eigen::Transform& t) +{ + if (stl->error) + return; + + unsigned int vertices_count = 3 * (unsigned int)stl->stats.number_of_facets; + if (vertices_count == 0) + return; + + Eigen::MatrixXf src_vertices(3, vertices_count); + stl_facet* facet_ptr = stl->facet_start; + unsigned int v_id = 0; + while (facet_ptr < stl->facet_start + stl->stats.number_of_facets) + { + for (int i = 0; i < 3; ++i) + { + ::memcpy((void*)src_vertices.col(v_id).data(), (const void*)&facet_ptr->vertex[i], 3 * sizeof(float)); + ++v_id; + } + facet_ptr += 1; + } + + Eigen::MatrixXf dst_vertices(3, vertices_count); + dst_vertices = t * src_vertices.colwise().homogeneous(); + + facet_ptr = stl->facet_start; + v_id = 0; + while (facet_ptr < stl->facet_start + stl->stats.number_of_facets) + { + for (int i = 0; i < 3; ++i) + { + ::memcpy((void*)&facet_ptr->vertex[i], (const void*)dst_vertices.col(v_id).data(), 3 * sizeof(float)); + ++v_id; + } + facet_ptr += 1; + } + + stl_get_size(stl); + calculate_normals(stl); +} + void stl_rotate_x(stl_file *stl, float angle) { int i; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 1cd3b1413..36c210844 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -672,20 +672,18 @@ void ModelObject::center_around_origin() // First align to origin on XYZ, then center it on XY. Vec3d size = bb.size(); - size(2) = 0.; - Vec3d shift3 = - bb.min - 0.5 * size; - // Unaligned vector, for the Rotation2D to work on Visual Studio 2013. - Eigen::Vector2d shift2 = to_2d(shift3); - - this->translate(shift3); - this->origin_translation += shift3; - + size(2) = 0.0; + Vec3d shift = -bb.min - 0.5 * size; + + this->translate(shift); + this->origin_translation += shift; + if (!this->instances.empty()) { for (ModelInstance *i : this->instances) { // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered - Eigen::Rotation2Dd rot(i->rotation); - i->offset -= rot * shift2 * i->scaling_factor; + Vec3d i_shift = i->world_matrix(true) * shift; + i->offset -= to_2d(i_shift); } this->invalidate_bounding_box(); } @@ -861,12 +859,7 @@ void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_ { for (ModelInstance* inst : this->instances) { - Transform3d m = Transform3d::Identity(); - m.translate(Vec3d(inst->offset(0), inst->offset(1), 0.0)); - m.rotate(Eigen::AngleAxisd(inst->rotation, Vec3d::UnitZ())); - m.scale(inst->scaling_factor); - - BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(m); + BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(inst->world_matrix()); if (print_volume.contains(bb)) inst->print_volume_state = ModelInstance::PVS_Inside; @@ -995,26 +988,17 @@ size_t ModelVolume::split(unsigned int max_extruders) void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const { - mesh->rotate_z(this->rotation); // rotate around mesh origin - mesh->scale(this->scaling_factor); // scale around mesh origin - if (!dont_translate) - mesh->translate(this->offset(0), this->offset(1), 0); + mesh->transform(world_matrix(dont_translate).cast()); } BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const { // Rotate around mesh origin. - double c = cos(this->rotation); - double s = sin(this->rotation); - BoundingBoxf3 bbox; - for (int i = 0; i < mesh->stl.stats.number_of_facets; ++ i) { - const stl_facet &facet = mesh->stl.facet_start[i]; - for (int j = 0; j < 3; ++ j) { - const stl_vertex &v = facet.vertex[j]; - bbox.merge(Vec3d(c * v(0) - s * v(1), s * v(0) + c * v(1), v(2))); - } - } - if (! empty(bbox)) { + TriangleMesh copy(*mesh); + copy.transform(world_matrix(dont_translate, false, true).cast()); + BoundingBoxf3 bbox = copy.bounding_box(); + + if (!empty(bbox)) { // Scale the bounding box uniformly. if (std::abs(this->scaling_factor - 1.) > EPSILON) { bbox.min *= this->scaling_factor; @@ -1031,13 +1015,7 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const { - Transform3d matrix = Transform3d::Identity(); - if (!dont_translate) - matrix.translate(Vec3d(offset(0), offset(1), 0.0)); - - matrix.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); - matrix.scale(scaling_factor); - return bbox.transformed(matrix); + return bbox.transformed(world_matrix(dont_translate)); } void ModelInstance::transform_polygon(Polygon* polygon) const @@ -1046,4 +1024,20 @@ void ModelInstance::transform_polygon(Polygon* polygon) const polygon->scale(this->scaling_factor); // scale around polygon origin } +Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const +{ + Transform3d m = Transform3d::Identity(); + + if (!dont_translate) + m.translate(Vec3d(offset(0), offset(1), 0.0)); + + if (!dont_rotate) + m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); + + if (!dont_scale) + m.scale(scaling_factor); + + return m; +} + } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index f8a36527d..66b53618a 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -243,6 +243,8 @@ public: // To be called on an external polygon. It does not translate the polygon, only rotates and scales. void transform_polygon(Polygon* polygon) const; + Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const; + bool is_printable() const { return print_volume_state == PVS_Inside; } private: diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 6840bc96e..6d40731f8 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -264,7 +264,7 @@ void TriangleMesh::rotate(float angle, const Vec3d& axis) Vec3f axis_norm = axis.cast().normalized(); Transform3f m = Transform3f::Identity(); m.rotate(Eigen::AngleAxisf(angle, axis_norm)); - stl_transform(&stl, (float*)m.data()); + stl_transform(&stl, m); } void TriangleMesh::mirror(const Axis &axis) @@ -279,6 +279,11 @@ void TriangleMesh::mirror(const Axis &axis) stl_invalidate_shared_vertices(&this->stl); } +void TriangleMesh::transform(const Transform3f& t) +{ + stl_transform(&stl, t); +} + void TriangleMesh::align_to_origin() { this->translate( @@ -523,9 +528,9 @@ BoundingBoxf3 TriangleMesh::transformed_bounding_box(const Transform3d& t) const src_vertices(0, v_id) = (double)facet_ptr->vertex[i](0); src_vertices(1, v_id) = (double)facet_ptr->vertex[i](1); src_vertices(2, v_id) = (double)facet_ptr->vertex[i](2); + ++v_id; } facet_ptr += 1; - ++v_id; } } diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 666252887..aebed4a2e 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -48,6 +48,7 @@ public: void mirror_x() { this->mirror(X); } void mirror_y() { this->mirror(Y); } void mirror_z() { this->mirror(Z); } + void transform(const Transform3f& t); void align_to_origin(); void rotate(double angle, Point* center); TriangleMeshPtrs split() const; diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 2980e34a1..a35165db4 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1051,6 +1051,8 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const ::glPopMatrix(); } } + + ::glDisable(GL_BLEND); } void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const @@ -1278,9 +1280,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const } Vec3d GLGizmoFlatten::get_flattening_normal() const { - Transform3d m = Transform3d::Identity(); - m.rotate(Eigen::AngleAxisd(-m_model_object->instances.front()->rotation, Vec3d::UnitZ())); - Vec3d normal = m * m_normal; + Vec3d normal = m_model_object->instances.front()->world_matrix().matrix().block(0, 0, 3, 3) * m_normal; m_normal = Vec3d::Zero(); return normal; } From 87c5c8e7f6de6e6773baa590ca43edb4fc71f5ac Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 09:11:58 +0200 Subject: [PATCH 06/31] Renamed GLVolume member variables to match the corresponding ModelInstance ones --- xs/src/libslic3r/Model.cpp | 3 +- xs/src/libslic3r/Model.hpp | 1 - xs/src/slic3r/GUI/3DScene.cpp | 70 ++++++++++++++++---------------- xs/src/slic3r/GUI/3DScene.hpp | 19 +++++---- xs/src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++----- xs/xsp/GUI_3DScene.xsp | 4 +- 6 files changed, 61 insertions(+), 58 deletions(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 36c210844..6ad8ebb49 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -237,7 +237,6 @@ BoundingBoxf3 Model::bounding_box() const void Model::center_instances_around_point(const Vec2d &point) { -// BoundingBoxf3 bb = this->bounding_box(); BoundingBoxf3 bb; for (ModelObject *o : this->objects) for (size_t i = 0; i < o->instances.size(); ++ i) @@ -995,7 +994,7 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes { // Rotate around mesh origin. TriangleMesh copy(*mesh); - copy.transform(world_matrix(dont_translate, false, true).cast()); + copy.transform(world_matrix(true, false, true).cast()); BoundingBoxf3 bbox = copy.bounding_box(); if (!empty(bbox)) { diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 66b53618a..bbfd2bde2 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -224,7 +224,6 @@ public: friend class ModelObject; -// Transform3d transform; double rotation; // Rotation around the Z axis, in radians around mesh center point double scaling_factor; Vec2d offset; // in unscaled coordinates diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 08a1b1457..3f44b727e 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -195,9 +195,9 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f }; const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; GLVolume::GLVolume(float r, float g, float b, float a) - : m_origin(0, 0, 0) - , m_angle_z(0.0f) - , m_scale_factor(1.0f) + : m_offset(Vec3d::Zero()) + , m_rotation(0.0) + , m_scaling_factor(1.0) , m_world_matrix(Transform3f::Identity()) , m_world_matrix_dirty(true) , m_transformed_bounding_box_dirty(true) @@ -255,43 +255,43 @@ void GLVolume::set_render_color() set_render_color(color, 4); } -const Vec3d& GLVolume::get_origin() const +double GLVolume::get_rotation() { - return m_origin; + return m_rotation; } -float GLVolume::get_angle_z() +void GLVolume::set_rotation(double rotation) { - return m_angle_z; -} - -void GLVolume::set_origin(const Vec3d& origin) -{ - if (m_origin != origin) + if (m_rotation != rotation) { - m_origin = origin; + m_rotation = rotation; m_world_matrix_dirty = true; m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; } } -void GLVolume::set_angle_z(float angle_z) +const Vec3d& GLVolume::get_offset() const { - if (m_angle_z != angle_z) + return m_offset; +} + +void GLVolume::set_offset(const Vec3d& offset) +{ + if (m_offset != offset) { - m_angle_z = angle_z; + m_offset = offset; m_world_matrix_dirty = true; m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; } } -void GLVolume::set_scale_factor(float scale_factor) +void GLVolume::set_scaling_factor(double factor) { - if (m_scale_factor != scale_factor) + if (m_scaling_factor != factor) { - m_scale_factor = scale_factor; + m_scaling_factor = factor; m_world_matrix_dirty = true; m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; @@ -308,9 +308,9 @@ const Transform3f& GLVolume::world_matrix() const if (m_world_matrix_dirty) { m_world_matrix = Transform3f::Identity(); - m_world_matrix.translate(Vec3f((float)m_origin(0), (float)m_origin(1), (float)m_origin(2))); - m_world_matrix.rotate(Eigen::AngleAxisf(m_angle_z, Vec3f::UnitZ())); - m_world_matrix.scale(m_scale_factor); + m_world_matrix.translate(m_offset.cast()); + m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ())); + m_world_matrix.scale((float)m_scaling_factor); m_world_matrix_dirty = false; } return m_world_matrix; @@ -384,9 +384,9 @@ void GLVolume::render() const ::glCullFace(GL_BACK); ::glPushMatrix(); - ::glTranslated(m_origin(0), m_origin(1), m_origin(2)); - ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); - ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); + ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); + ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); + ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); if (this->indexed_vertex_array.indexed()) this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); else @@ -510,9 +510,9 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr); ::glPushMatrix(); - ::glTranslated(m_origin(0), m_origin(1), m_origin(2)); - ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); - ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); + ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); + ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); + ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); if (n_triangles > 0) { @@ -555,9 +555,9 @@ void GLVolume::render_legacy() const ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data()); ::glPushMatrix(); - ::glTranslated(m_origin(0), m_origin(1), m_origin(2)); - ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); - ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); + ::glTranslated(m_offset(0), m_offset(1), m_offset(2)); + ::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0); + ::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor); if (n_triangles > 0) ::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first); @@ -675,9 +675,9 @@ std::vector GLVolumeCollection::load_object( } v.is_modifier = model_volume->modifier; v.shader_outside_printer_detection_enabled = !model_volume->modifier; - v.set_origin(Vec3d(instance->offset(0), instance->offset(1), 0.0)); - v.set_angle_z(instance->rotation); - v.set_scale_factor(instance->scaling_factor); + v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0)); + v.set_rotation(instance->rotation); + v.set_scaling_factor(instance->scaling_factor); } } @@ -746,7 +746,7 @@ int GLVolumeCollection::load_wipe_tower_preview( else v.indexed_vertex_array.load_mesh_flat_shading(mesh); - v.set_origin(Vec3d(pos_x, pos_y, 0.)); + v.set_offset(Vec3d(pos_x, pos_y, 0.0)); // finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry(). v.bounding_box = v.indexed_vertex_array.bounding_box(); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 69f1e1d35..1785ecf4a 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -255,11 +255,11 @@ public: private: // Offset of the volume to be rendered. - Vec3d m_origin; + Vec3d m_offset; // Rotation around Z axis of the volume to be rendered. - float m_angle_z; + double m_rotation; // Scale factor of the volume to be rendered. - float m_scale_factor; + double m_scaling_factor; // World matrix of the volume to be rendered. mutable Transform3f m_world_matrix; // Whether or not is needed to recalculate the world matrix. @@ -327,11 +327,14 @@ public: // Sets render color in dependence of current state void set_render_color(); - float get_angle_z(); - const Vec3d& get_origin() const; - void set_origin(const Vec3d& origin); - void set_angle_z(float angle_z); - void set_scale_factor(float scale_factor); + double get_rotation(); + void set_rotation(double rotation); + + const Vec3d& get_offset() const; + void set_offset(const Vec3d& offset); + + void set_scaling_factor(double factor); + void set_convex_hull(const TriangleMesh& convex_hull); int object_idx() const { return this->composite_id / 1000000; } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index bbc73b896..73966a7f5 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -3001,7 +3001,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) Vec3d normal = m_gizmos.get_flattening_normal(); if (normal != Vec3d::Zero()) { Vec3d axis = normal(2) > 0.999f ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()); - float angle = -acos(-normal(2)); + float angle = acos(-normal(2)); m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2)); } } @@ -3126,7 +3126,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Apply new temporary volume origin and ignore Z. for (GLVolume* v : volumes) - v->set_origin(v->get_origin() + Vec3d(vector(0), vector(1), 0.0)); + { + v->set_offset(v->get_offset() + Vec3d(vector(0), vector(1), 0.0)); + } m_mouse.drag.start_position_3D = cur_pos; m_gizmos.refresh(); @@ -3166,7 +3168,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) float scale_factor = m_gizmos.get_scale(); for (GLVolume* v : volumes) { - v->set_scale_factor(scale_factor); + v->set_scaling_factor((double)scale_factor); } break; } @@ -3176,7 +3178,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) float angle_z = m_gizmos.get_angle_z(); for (GLVolume* v : volumes) { - v->set_angle_z(angle_z); + v->set_rotation((double)angle_z); } break; } @@ -3194,7 +3196,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) const Vec3d& size = bb.size(); m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale()); update_scale_values(size, m_gizmos.get_scale()); - update_rotation_value(volumes[0]->get_angle_z(), "z"); + update_rotation_value(volumes[0]->get_rotation(), "z"); } if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1)) @@ -5219,7 +5221,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) std::set done; // prevent moving instances twice bool object_moved = false; - Vec3d wipe_tower_origin(0.0, 0.0, 0.0); + Vec3d wipe_tower_origin = Vec3d::Zero(); for (int volume_idx : volume_idxs) { GLVolume* volume = m_volumes.volumes[volume_idx]; @@ -5238,20 +5240,20 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) { // Move a regular object. ModelObject* model_object = m_model->objects[obj_idx]; - const Vec3d& origin = volume->get_origin(); - model_object->instances[instance_idx]->offset = Vec2d(origin(0), origin(1)); + const Vec3d& offset = volume->get_offset(); + model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1)); model_object->invalidate_bounding_box(); object_moved = true; } else if (obj_idx == 1000) // Move a wipe tower proxy. - wipe_tower_origin = volume->get_origin(); + wipe_tower_origin = volume->get_offset(); } if (object_moved) m_on_instance_moved_callback.call(); - if (wipe_tower_origin != Vec3d(0.0, 0.0, 0.0)) + if (wipe_tower_origin != Vec3d::Zero()) m_on_wipe_tower_moved_callback.call(wipe_tower_origin(0), wipe_tower_origin(1)); } diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index c15fdc196..6c199aacb 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -56,9 +56,9 @@ int volume_idx() const; int instance_idx() const; Clone origin() const - %code%{ RETVAL = THIS->get_origin(); %}; + %code%{ RETVAL = THIS->get_offset(); %}; void translate(double x, double y, double z) - %code%{ THIS->set_origin(THIS->get_origin() + Vec3d(x, y, z)); %}; + %code%{ THIS->set_offset(THIS->get_offset() + Vec3d(x, y, z)); %}; Clone bounding_box() const %code%{ RETVAL = THIS->bounding_box; %}; From f67060f0129cbe897e6a144b8181146c35ace174 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 5 Sep 2018 09:47:36 +0200 Subject: [PATCH 07/31] Fixed bug from issue #1169 --- xs/src/slic3r/GUI/Field.cpp | 23 +++++++++++++++-------- xs/src/slic3r/GUI/Field.hpp | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 757a18f11..44cdb33f5 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -234,14 +234,10 @@ namespace Slic3r { namespace GUI { }), temp->GetId()); #ifdef __WXGTK__ - temp->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event) - { - if (bChangedValueEvent) { - on_change_field(); - bChangedValueEvent = false; - } - event.Skip(); - }); + // to correct value update on GTK we should call on_change_field() on + // wxEVT_KEY_UP or wxEVT_TEXT_PASTE instead of wxEVT_TEXT + temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); + temp->Bind(wxEVT_TEXT_PASTE, &TextCtrl::change_field_value, this); #endif //__WXGTK__ // select all text using Ctrl+A @@ -267,6 +263,17 @@ namespace Slic3r { namespace GUI { void TextCtrl::enable() { dynamic_cast(window)->Enable(); dynamic_cast(window)->SetEditable(true); } void TextCtrl::disable() { dynamic_cast(window)->Disable(); dynamic_cast(window)->SetEditable(false); } +#ifdef __WXGTK__ + void TextCtrl::change_field_value(wxEvent& event) + { + if (bChangedValueEvent) { + on_change_field(); + bChangedValueEvent = false; + } + event.Skip(); + }; +#endif //__WXGTK__ + void CheckBox::BUILD() { auto size = wxSize(wxDefaultSize); if (m_opt.height >= 0) size.SetHeight(m_opt.height); diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index db8d2a408..67c7692fc 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -223,6 +223,7 @@ class TextCtrl : public Field { using Field::Field; #ifdef __WXGTK__ bool bChangedValueEvent = false; + void change_field_value(wxEvent& event); #endif //__WXGTK__ public: TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} From f95b84e913eee5b7cf800fee89c7b10bea05d090 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 09:49:10 +0200 Subject: [PATCH 08/31] Fixed stl import when endsolid lines contains extra data --- xs/src/admesh/stlinit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/admesh/stlinit.cpp b/xs/src/admesh/stlinit.cpp index e572ce930..ed8beb9d1 100644 --- a/xs/src/admesh/stlinit.cpp +++ b/xs/src/admesh/stlinit.cpp @@ -287,7 +287,7 @@ stl_read(stl_file *stl, int first_facet, int first) { { // skip solid/endsolid // (in this order, otherwise it won't work when they are paired in the middle of a file) - fscanf(stl->fp, "endsolid\n"); + fscanf(stl->fp, "endsolid%*[^\n]\n"); fscanf(stl->fp, "solid%*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid") // Leading space in the fscanf format skips all leading white spaces including numerous new lines and tabs. int res_normal = fscanf(stl->fp, " facet normal %31s %31s %31s", normal_buf[0], normal_buf[1], normal_buf[2]); From e2830dc33736dc5afede0ea073a9e7671205fed3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 5 Sep 2018 12:02:34 +0200 Subject: [PATCH 09/31] Fix to last commit --- xs/src/slic3r/GUI/Field.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 44cdb33f5..228d320da 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -224,10 +224,13 @@ namespace Slic3r { namespace GUI { }), temp->GetId()); #endif // __WXGTK__ - temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent) + temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) { #ifdef __WXGTK__ - bChangedValueEvent = true; + if (bChangedValueEvent) + change_field_value(ent); + else + bChangedValueEvent = true; #else on_change_field(); #endif //__WXGTK__ @@ -266,7 +269,9 @@ namespace Slic3r { namespace GUI { #ifdef __WXGTK__ void TextCtrl::change_field_value(wxEvent& event) { - if (bChangedValueEvent) { + if (event.GetEventType() == wxEVT_TEXT_PASTE) + bChangedValueEvent = true; + else if (bChangedValueEvent) { on_change_field(); bChangedValueEvent = false; } From 8ba48f8dc508fcde572514052cfa1acb91644c4f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 5 Sep 2018 12:33:04 +0200 Subject: [PATCH 10/31] fixed typo-bug --- xs/src/slic3r/GUI/Field.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 228d320da..f679de1fa 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -228,7 +228,7 @@ namespace Slic3r { namespace GUI { { #ifdef __WXGTK__ if (bChangedValueEvent) - change_field_value(ent); + change_field_value(evt); else bChangedValueEvent = true; #else From 011281068b1a6047a5d1eab61cdeeafd10f15176 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 14:02:08 +0200 Subject: [PATCH 11/31] Fixed flatten gizmo's flattening normal --- xs/src/libslic3r/Format/3mf.cpp | 5 +---- xs/src/slic3r/GUI/GLCanvas3D.cpp | 6 +++--- xs/src/slic3r/GUI/GLGizmo.cpp | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/xs/src/libslic3r/Format/3mf.cpp b/xs/src/libslic3r/Format/3mf.cpp index b838f65c1..4dc40bd3c 100644 --- a/xs/src/libslic3r/Format/3mf.cpp +++ b/xs/src/libslic3r/Format/3mf.cpp @@ -1738,10 +1738,7 @@ namespace Slic3r { stream << " \n"; } - Transform3d t = Transform3d::Identity(); - t.translate(Vec3d(instance->offset(0), instance->offset(1), 0.0)); - t.rotate(Eigen::AngleAxisd(instance->rotation, Vec3d::UnitZ())); - t.scale(instance->scaling_factor); + Transform3d t = instance->world_matrix(); build_items.emplace_back(instance_id, t); stream << " \n"; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 73966a7f5..36f664f34 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -2999,9 +2999,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_gizmos.get_current_type() == Gizmos::Flatten) { // Rotate the object so the normal points downward: Vec3d normal = m_gizmos.get_flattening_normal(); - if (normal != Vec3d::Zero()) { - Vec3d axis = normal(2) > 0.999f ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()); - float angle = acos(-normal(2)); + if (normal(0) != 0.0 || normal(1) != 0.0 || normal(2) != 0.0) { + Vec3d axis = normal(2) > 0.999 ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()).normalized(); + float angle = acos(clamp(-1.0, 1.0, -normal(2))); m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2)); } } diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index a35165db4..aa4152c85 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1282,7 +1282,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const Vec3d GLGizmoFlatten::get_flattening_normal() const { Vec3d normal = m_model_object->instances.front()->world_matrix().matrix().block(0, 0, 3, 3) * m_normal; m_normal = Vec3d::Zero(); - return normal; + return normal.normalized(); } } // namespace GUI From 82838cc640950a2505e77b0b5205f74cd86dfdf1 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 5 Sep 2018 15:03:20 +0200 Subject: [PATCH 12/31] Final bug-fix for #1169 considering issue #971 --- xs/src/slic3r/GUI/Field.cpp | 23 ++++++++--------------- xs/src/slic3r/GUI/Field.hpp | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index f679de1fa..c7f1d48ff 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -227,20 +227,17 @@ namespace Slic3r { namespace GUI { temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) { #ifdef __WXGTK__ - if (bChangedValueEvent) - change_field_value(evt); - else - bChangedValueEvent = true; -#else - on_change_field(); + if (bChangedValueEvent) #endif //__WXGTK__ + on_change_field(); }), temp->GetId()); #ifdef __WXGTK__ - // to correct value update on GTK we should call on_change_field() on - // wxEVT_KEY_UP or wxEVT_TEXT_PASTE instead of wxEVT_TEXT + // to correct value updating on GTK we should: + // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT + // and prevent value updating on wxEVT_KEY_DOWN + temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); - temp->Bind(wxEVT_TEXT_PASTE, &TextCtrl::change_field_value, this); #endif //__WXGTK__ // select all text using Ctrl+A @@ -269,12 +266,8 @@ namespace Slic3r { namespace GUI { #ifdef __WXGTK__ void TextCtrl::change_field_value(wxEvent& event) { - if (event.GetEventType() == wxEVT_TEXT_PASTE) - bChangedValueEvent = true; - else if (bChangedValueEvent) { - on_change_field(); - bChangedValueEvent = false; - } + if (bChangedValueEvent = event.GetEventType()==wxEVT_KEY_UP) + on_change_field(); event.Skip(); }; #endif //__WXGTK__ diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index 67c7692fc..923f0fd7e 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -222,7 +222,7 @@ inline bool is_sizer_field(const t_field& obj) { return !is_bad_field(obj) && ob class TextCtrl : public Field { using Field::Field; #ifdef __WXGTK__ - bool bChangedValueEvent = false; + bool bChangedValueEvent = true; void change_field_value(wxEvent& event); #endif //__WXGTK__ public: From df594fc5b023d23946fa27dad402cf0912498bc3 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 15:09:13 +0200 Subject: [PATCH 13/31] Tweaks to update of object properties on gui --- xs/src/slic3r/GUI/GUI_ObjectParts.cpp | 45 +++++++++++++++++++++------ xs/src/slic3r/GUI/GUI_ObjectParts.hpp | 1 + 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 94555f50e..0c45b70ac 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -1368,13 +1368,20 @@ void update_settings_value() { auto og = get_optgroup(ogFrequentlyObjectSettings); if (m_selected_object_id < 0 || m_objects->size() <= m_selected_object_id) { - og->set_value("scale_x", 0); + og->set_value("position_x", 0); + og->set_value("position_y", 0); + og->set_value("position_z", 0); + og->set_value("scale_x", 0); og->set_value("scale_y", 0); og->set_value("scale_z", 0); + og->set_value("rotation_x", 0); + og->set_value("rotation_y", 0); + og->set_value("rotation_z", 0); og->disable(); return; } g_is_percent_scale = boost::any_cast(og->get_value("scale_unit")) == _("%"); + update_position_values(); update_scale_values(); update_rotation_values(); og->enable(); @@ -1535,8 +1542,31 @@ void update_extruder_in_config(const wxString& selection) void update_scale_values() { - update_scale_values((*m_objects)[m_selected_object_id]->instance_bounding_box(0).size(), - (*m_objects)[m_selected_object_id]->instances[0]->scaling_factor); + auto og = get_optgroup(ogFrequentlyObjectSettings); + auto instance = (*m_objects)[m_selected_object_id]->instances.front(); + auto size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size(); + + if (g_is_percent_scale) { + auto scale = instance->scaling_factor * 100; + og->set_value("scale_x", int(scale)); + og->set_value("scale_y", int(scale)); + og->set_value("scale_z", int(scale)); + } + else { + og->set_value("scale_x", int(instance->scaling_factor * size(0) + 0.5)); + og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5)); + og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5)); + } +} + +void update_position_values() +{ + auto og = get_optgroup(ogFrequentlyObjectSettings); + auto instance = (*m_objects)[m_selected_object_id]->instances.front(); + + og->set_value("position_x", int(instance->offset(0))); + og->set_value("position_y", int(instance->offset(1))); + og->set_value("position_z", 0); } void update_scale_values(const Vec3d& size, float scaling_factor) @@ -1559,15 +1589,10 @@ void update_scale_values(const Vec3d& size, float scaling_factor) void update_rotation_values() { auto og = get_optgroup(ogFrequentlyObjectSettings); - + auto instance = (*m_objects)[m_selected_object_id]->instances.front(); og->set_value("rotation_x", 0); og->set_value("rotation_y", 0); - - auto rotation_z = (*m_objects)[m_selected_object_id]->instances[0]->rotation; - auto deg = int(Geometry::rad2deg(rotation_z)); -// if (deg > 180) deg -= 360; - - og->set_value("rotation_z", deg); + og->set_value("rotation_z", int(Geometry::rad2deg(instance->rotation))); } void update_rotation_value(const double angle, const std::string& axis) diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp index 82bfe4a6c..c64dd8f22 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp @@ -107,6 +107,7 @@ void update_settings_value(); void set_extruder_column_hidden(bool hide); // update extruder in current config void update_extruder_in_config(const wxString& selection); +void update_position_values(); // update scale values after scale unit changing or "gizmos" void update_scale_values(); void update_scale_values(const Vec3d& size, float scale); From aef871f1a078b378e59c68e94ec449e25c6880ab Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 15:13:29 +0200 Subject: [PATCH 14/31] Another fix in flatten gizmo's flattening normal --- xs/src/slic3r/GUI/GLGizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index aa4152c85..e46cfa925 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1280,7 +1280,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const } Vec3d GLGizmoFlatten::get_flattening_normal() const { - Vec3d normal = m_model_object->instances.front()->world_matrix().matrix().block(0, 0, 3, 3) * m_normal; + Vec3d normal = m_model_object->instances.front()->world_matrix(true).matrix().block(0, 0, 3, 3).inverse() * m_normal; m_normal = Vec3d::Zero(); return normal.normalized(); } From 42567e3af27bafa93d9e118b261795f3236cd124 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 15:35:09 +0200 Subject: [PATCH 15/31] Object's position updated on gui after displacement --- xs/src/slic3r/GUI/GLCanvas3D.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 36f664f34..b52bc2a54 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -5243,6 +5243,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) const Vec3d& offset = volume->get_offset(); model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1)); model_object->invalidate_bounding_box(); + update_position_values(); object_moved = true; } else if (obj_idx == 1000) From 677dad06695d7954fcabd681cca1975fb1a6e4d5 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 5 Sep 2018 16:22:48 +0200 Subject: [PATCH 16/31] Object's properties updated while manipulating gizmos --- lib/Slic3r/GUI/Plater.pm | 6 +-- xs/src/slic3r/GUI/GLCanvas3D.cpp | 7 +-- xs/src/slic3r/GUI/GUI_ObjectParts.cpp | 63 +++++++++++++++++++-------- xs/src/slic3r/GUI/GUI_ObjectParts.hpp | 6 ++- xs/xsp/GUI.xsp | 5 +-- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index ce9e0da68..b48ab0f97 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1181,11 +1181,7 @@ sub rotate { # $model_object->center_around_origin; # $self->reset_thumbnail($obj_idx); } - - if (defined $axis) { - Slic3r::GUI::update_rotation_value(deg2rad($angle), $axis == X ? "x" : ($axis == Y ? "y" : "z")); - } - + # update print and start background processing $self->{print}->add_model_object($model_object, $obj_idx); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index b52bc2a54..063b96cbe 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -3130,6 +3130,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) v->set_offset(v->get_offset() + Vec3d(vector(0), vector(1), 0.0)); } + update_position_values(volume->get_offset()); m_mouse.drag.start_position_3D = cur_pos; m_gizmos.refresh(); @@ -3169,6 +3170,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) for (GLVolume* v : volumes) { v->set_scaling_factor((double)scale_factor); + update_scale_values((double)scale_factor); } break; } @@ -3179,6 +3181,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) for (GLVolume* v : volumes) { v->set_rotation((double)angle_z); + update_rotation_value((double)angle_z, Z); } break; } @@ -3195,8 +3198,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } const Vec3d& size = bb.size(); m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale()); - update_scale_values(size, m_gizmos.get_scale()); - update_rotation_value(volumes[0]->get_rotation(), "z"); } if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1)) @@ -3297,7 +3298,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) case Gizmos::Scale: { m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); - Slic3r::GUI::update_settings_value(); break; } case Gizmos::Rotate: @@ -3309,6 +3309,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) break; } m_gizmos.stop_dragging(); + Slic3r::GUI::update_settings_value(); } m_mouse.drag.move_volume_idx = -1; diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 0c45b70ac..9ec39b976 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -1547,7 +1547,7 @@ void update_scale_values() auto size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size(); if (g_is_percent_scale) { - auto scale = instance->scaling_factor * 100; + auto scale = instance->scaling_factor * 100.0; og->set_value("scale_x", int(scale)); og->set_value("scale_y", int(scale)); og->set_value("scale_z", int(scale)); @@ -1569,21 +1569,31 @@ void update_position_values() og->set_value("position_z", 0); } -void update_scale_values(const Vec3d& size, float scaling_factor) +void update_position_values(const Vec3d& position) +{ + auto og = get_optgroup(ogFrequentlyObjectSettings); + auto instance = (*m_objects)[m_selected_object_id]->instances.front(); + + og->set_value("position_x", int(position(0))); + og->set_value("position_y", int(position(1))); + og->set_value("position_z", int(position(2))); +} + +void update_scale_values(double scaling_factor) { auto og = get_optgroup(ogFrequentlyObjectSettings); - if (g_is_percent_scale) { - auto scale = scaling_factor * 100; - og->set_value("scale_x", int(scale)); - og->set_value("scale_y", int(scale)); - og->set_value("scale_z", int(scale)); - } - else { - og->set_value("scale_x", int(size(0) + 0.5)); - og->set_value("scale_y", int(size(1) + 0.5)); - og->set_value("scale_z", int(size(2) + 0.5)); - } + // this is temporary + // to be able to update the values as size + // we need to store somewhere the original size + // or have it passed as parameter + if (!g_is_percent_scale) + og->set_value("scale_unit", _("%")); + + auto scale = scaling_factor * 100.0; + og->set_value("scale_x", int(scale)); + og->set_value("scale_y", int(scale)); + og->set_value("scale_z", int(scale)); } void update_rotation_values() @@ -1595,14 +1605,31 @@ void update_rotation_values() og->set_value("rotation_z", int(Geometry::rad2deg(instance->rotation))); } -void update_rotation_value(const double angle, const std::string& axis) +void update_rotation_value(double angle, Axis axis) { auto og = get_optgroup(ogFrequentlyObjectSettings); - - int deg = int(Geometry::rad2deg(angle)); -// if (deg>180) deg -= 360; - og->set_value("rotation_"+axis, deg); + std::string axis_str; + switch (axis) + { + case X: + { + axis_str = "rotation_x"; + break; + } + case Y: + { + axis_str = "rotation_y"; + break; + } + case Z: + { + axis_str = "rotation_z"; + break; + } + } + + og->set_value(axis_str, int(Geometry::rad2deg(angle))); } void set_uniform_scaling(const bool uniform_scale) diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp index c64dd8f22..8a1499e03 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp @@ -107,14 +107,16 @@ void update_settings_value(); void set_extruder_column_hidden(bool hide); // update extruder in current config void update_extruder_in_config(const wxString& selection); +// update position values displacements or "gizmos" void update_position_values(); +void update_position_values(const Vec3d& position); // update scale values after scale unit changing or "gizmos" void update_scale_values(); -void update_scale_values(const Vec3d& size, float scale); +void update_scale_values(double scaling_factor); // update rotation values object selection changing void update_rotation_values(); // update rotation value after "gizmos" -void update_rotation_value(const double angle, const std::string& axis); +void update_rotation_value(double angle, Axis axis); void set_uniform_scaling(const bool uniform_scale); void on_begin_drag(wxDataViewEvent &event); diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index c18fce44d..03da43abe 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -154,10 +154,7 @@ void select_current_object(int idx) void remove_obj() %code%{ Slic3r::GUI::remove(); %}; - -void update_rotation_value(double angle, const char *axis) - %code%{ Slic3r::GUI::update_rotation_value(angle, axis); %}; - + std::string fold_utf8_to_ascii(const char *src) %code%{ RETVAL = Slic3r::fold_utf8_to_ascii(src); %}; From e1417f182701858cc369a233096eb845d7a081f7 Mon Sep 17 00:00:00 2001 From: Martin Loidl Date: Tue, 4 Sep 2018 23:55:37 +0200 Subject: [PATCH 17/31] allow whitespaces for duet upload * now url_encoding characters which could not used for URLs --- xs/src/slic3r/Utils/Duet.cpp | 7 ++++--- xs/src/slic3r/Utils/Http.cpp | 12 ++++++++++++ xs/src/slic3r/Utils/Http.hpp | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/Utils/Duet.cpp b/xs/src/slic3r/Utils/Duet.cpp index 82a42eb71..a3dc4a3bb 100644 --- a/xs/src/slic3r/Utils/Duet.cpp +++ b/xs/src/slic3r/Utils/Duet.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -197,7 +198,7 @@ std::string Duet::get_upload_url(const std::string &filename) const { return (boost::format("%1%rr_upload?name=0:/gcodes/%2%&%3%") % get_base_url() - % filename + % Http::url_encode(filename) % timestamp_str()).str(); } @@ -248,9 +249,10 @@ wxString Duet::format_error(const std::string &body, const std::string &error, u bool Duet::start_print(wxString &msg, const std::string &filename) const { bool res = false; + auto url = (boost::format("%1%rr_gcode?gcode=M32%%20\"%2%\"") % get_base_url() - % filename).str(); + % Http::url_encode(filename)).str(); auto http = Http::get(std::move(url)); http.on_error([&](std::string body, std::string error, unsigned status) { @@ -275,5 +277,4 @@ int Duet::get_err_code_from_body(const std::string &body) const return root.get("err", 0); } - } diff --git a/xs/src/slic3r/Utils/Http.cpp b/xs/src/slic3r/Utils/Http.cpp index a92e399a0..3024b08fe 100644 --- a/xs/src/slic3r/Utils/Http.cpp +++ b/xs/src/slic3r/Utils/Http.cpp @@ -421,6 +421,18 @@ bool Http::ca_file_supported() return res; } +std::string Http::url_encode(const std::string &str) +{ + ::CURL *curl = ::curl_easy_init(); + char *ce = ::curl_easy_escape(curl, str.c_str(), str.length()); + std::string encoded = std::string(ce); + + ::curl_free(ce); + if (curl != nullptr) { ::curl_easy_cleanup(curl); } + + return encoded; +} + std::ostream& operator<<(std::ostream &os, const Http::Progress &progress) { os << "Http::Progress(" diff --git a/xs/src/slic3r/Utils/Http.hpp b/xs/src/slic3r/Utils/Http.hpp index f1302b0ed..44580b7ea 100644 --- a/xs/src/slic3r/Utils/Http.hpp +++ b/xs/src/slic3r/Utils/Http.hpp @@ -98,6 +98,9 @@ public: // Tells whether current backend supports seting up a CA file using ca_file() static bool ca_file_supported(); + + // converts the given string to an url_encoded_string + static std::string url_encode(const std::string &str); private: Http(const std::string &url); From b9287d51dd89c0fdec8dcea398285055e13e71ce Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 6 Sep 2018 08:56:33 +0200 Subject: [PATCH 18/31] Tweaks to ModelObject::center_around_origin() --- xs/src/libslic3r/Model.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 6ad8ebb49..93f0152c8 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -669,10 +669,9 @@ void ModelObject::center_around_origin() if (! v->modifier) bb.merge(v->mesh.bounding_box()); - // First align to origin on XYZ, then center it on XY. - Vec3d size = bb.size(); - size(2) = 0.0; - Vec3d shift = -bb.min - 0.5 * size; + // Shift is the vector from the center of the bottom face of the bounding box to the origin + Vec3d shift = -bb.center(); + shift(2) = -bb.min(2); this->translate(shift); this->origin_translation += shift; From c8f136982438b264ef7030d5f228479b7bbf8ab9 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 6 Sep 2018 09:16:32 +0200 Subject: [PATCH 19/31] Added Vec3d ModelInstance::transform_vector() method --- xs/src/libslic3r/Model.cpp | 5 +++++ xs/src/libslic3r/Model.hpp | 2 ++ xs/src/slic3r/GUI/GLCanvas3D.cpp | 13 ++++++++----- xs/src/slic3r/GUI/GLGizmo.cpp | 6 ++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 93f0152c8..19c474cad 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1016,6 +1016,11 @@ BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, b return bbox.transformed(world_matrix(dont_translate)); } +Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const +{ + return world_matrix(dont_translate) * v; +} + void ModelInstance::transform_polygon(Polygon* polygon) const { polygon->rotate(this->rotation); // rotate around polygon origin diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index bbfd2bde2..8a8af481c 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -239,6 +239,8 @@ public: BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate = false) const; // Transform an external bounding box. BoundingBoxf3 transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate = false) const; + // Transform an external vector. + Vec3d transform_vector(const Vec3d& v, bool dont_translate = false) const; // To be called on an external polygon. It does not translate the polygon, only rotates and scales. void transform_polygon(Polygon* polygon) const; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 063b96cbe..2bec6b66b 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -5241,11 +5241,14 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) { // Move a regular object. ModelObject* model_object = m_model->objects[obj_idx]; - const Vec3d& offset = volume->get_offset(); - model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1)); - model_object->invalidate_bounding_box(); - update_position_values(); - object_moved = true; + if (model_object != nullptr) + { + const Vec3d& offset = volume->get_offset(); + model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1)); + model_object->invalidate_bounding_box(); + update_position_values(); + object_moved = true; + } } else if (obj_idx == 1000) // Move a wipe tower proxy. diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index e46cfa925..1c0456fa8 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1061,8 +1061,6 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const for (unsigned int i = 0; i < m_planes.size(); ++i) { - // FIXME: the color assignement will fail if the planes count is greater than 254 - // use the other color components in that case !! ::glColor3f(1.0f, 1.0f, picking_color_component(i)); for (const Vec2d& offset : m_instances_positions) { ::glPushMatrix(); @@ -1240,9 +1238,9 @@ void GLGizmoFlatten::update_planes() polygon = transform(polygon, m); } - // We'll sort the planes by area and only keep the 255 largest ones (because of the picking pass limitations): + // We'll sort the planes by area and only keep the 254 largest ones (because of the picking pass limitations): std::sort(m_planes.rbegin(), m_planes.rend(), [](const PlaneData& a, const PlaneData& b) { return a.area < b.area; }); - m_planes.resize(std::min((int)m_planes.size(), 255)); + m_planes.resize(std::min((int)m_planes.size(), 254)); // Planes are finished - let's save what we calculated it from: m_source_data.bounding_boxes.clear(); From 8460926d36f777282e0cfc47a86341a6b1991fc2 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 6 Sep 2018 16:10:31 +0200 Subject: [PATCH 20/31] Added select by part tool to toolbar --- lib/Slic3r/GUI/Plater.pm | 46 +++++++++++++++- resources/icons/toolbar.png | Bin 20451 -> 21874 bytes xs/src/slic3r/GUI/3DScene.cpp | 53 ++++++++++++++---- xs/src/slic3r/GUI/3DScene.hpp | 9 +++ xs/src/slic3r/GUI/GLCanvas3D.cpp | 70 +++++++++++++++++++++--- xs/src/slic3r/GUI/GLCanvas3D.hpp | 8 ++- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 19 +++++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 5 ++ xs/src/slic3r/GUI/GUI_ObjectParts.cpp | 1 - xs/xsp/GUI_3DScene.xsp | 24 ++++++++ 10 files changed, 211 insertions(+), 24 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index b48ab0f97..8a9d13aae 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -85,9 +85,13 @@ sub new { # Initialize handlers for canvases my $on_select_object = sub { - my ($obj_idx) = @_; - # Ignore the special objects (the wipe tower proxy and such). - $self->select_object((defined($obj_idx) && $obj_idx >= 0 && $obj_idx < 1000) ? $obj_idx : undef); + my ($obj_idx, $vol_idx) = @_; + + if (($obj_idx != -1) && ($vol_idx == -1)) { + # Ignore the special objects (the wipe tower proxy and such). + $self->select_object((defined($obj_idx) && $obj_idx >= 0 && $obj_idx < 1000) ? $obj_idx : undef); + $self->item_changed_selection($obj_idx) if (defined($obj_idx)); + } }; my $on_double_click = sub { $self->object_settings_dialog if $self->selected_object; @@ -217,6 +221,29 @@ sub new { my $state = Slic3r::GUI::_3DScene::is_toolbar_item_pressed($self->{canvas3D}, "layersediting"); $self->on_layer_editing_toggled($state); }; + + my $on_action_selectbyparts = sub { + my $curr = Slic3r::GUI::_3DScene::get_select_by($self->{canvas3D}); + if ($curr eq 'volume') { + Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'object'); + my $selections = $self->collect_selections; + Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections); + Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1); + } + elsif ($curr eq 'object') { + Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'volume'); + my $selections = []; + Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections); + Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D}); + Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1); + + my ($obj_idx, $object) = $self->selected_object; + if (defined $obj_idx) { + my $vol_idx = Slic3r::GUI::_3DScene::get_first_volume_id($self->{canvas3D}, $obj_idx); + Slic3r::GUI::_3DScene::select_volume($self->{canvas3D}, $vol_idx) if ($vol_idx != -1); + } + } + }; # Initialize 3D plater if ($Slic3r::GUI::have_OpenGL) { @@ -247,6 +274,7 @@ sub new { Slic3r::GUI::_3DScene::register_action_cut_callback($self->{canvas3D}, $on_action_cut); Slic3r::GUI::_3DScene::register_action_settings_callback($self->{canvas3D}, $on_action_settings); Slic3r::GUI::_3DScene::register_action_layersediting_callback($self->{canvas3D}, $on_action_layersediting); + Slic3r::GUI::_3DScene::register_action_selectbyparts_callback($self->{canvas3D}, $on_action_selectbyparts); Slic3r::GUI::_3DScene::enable_gizmos($self->{canvas3D}, 1); Slic3r::GUI::_3DScene::enable_toolbar($self->{canvas3D}, 1); Slic3r::GUI::_3DScene::enable_shader($self->{canvas3D}, 1); @@ -2331,12 +2359,24 @@ sub selection_changed { } Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "layersediting", $layers_height_allowed); + + my $can_select_by_parts = 0; if ($have_sel) { my $model_object = $self->{model}->objects->[$obj_idx]; + $can_select_by_parts = ($obj_idx >= 0) && ($obj_idx < 1000) && ($model_object->volumes_count > 1); Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "fewer", $model_object->instances_count > 1); } + if ($can_select_by_parts) { + # first disable to let the item in the toolbar to switch to the unpressed state + Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 0); + Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 1); + } else { + Slic3r::GUI::_3DScene::enable_toolbar_item($self->{canvas3D}, "selectbyparts", 0); + Slic3r::GUI::_3DScene::set_select_by($self->{canvas3D}, 'object'); + } + if ($self->{object_info_size}) { # have we already loaded the info pane? if ($have_sel) { my $model_object = $self->{model}->objects->[$obj_idx]; diff --git a/resources/icons/toolbar.png b/resources/icons/toolbar.png index ce954143dbe98cc25d31ea8831332e402ee395cb..79246bcf91761ca4d6c89393cbfd9a5f6a28e6ea 100644 GIT binary patch delta 5304 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 GLVolumeCollection::load_object( v.bounding_box = v.indexed_vertex_array.bounding_box(); v.indexed_vertex_array.finalize_geometry(use_VBOs); v.composite_id = obj_idx * 1000000 + volume_idx * 1000 + instance_idx; - if (select_by == "object") - v.select_group_id = obj_idx * 1000000; - else if (select_by == "volume") - v.select_group_id = obj_idx * 1000000 + volume_idx * 1000; - else if (select_by == "instance") - v.select_group_id = v.composite_id; + v.set_select_group_id(select_by); if (drag_by == "object") v.drag_group_id = obj_idx * 1000; else if (drag_by == "instance") @@ -949,6 +954,15 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con } } +void GLVolumeCollection::set_select_by(const std::string& select_by) +{ + for (GLVolume *vol : this->volumes) + { + if (vol != nullptr) + vol->set_select_group_id(select_by); + } +} + std::vector GLVolumeCollection::get_current_print_zs(bool active_only) const { // Collect layer top positions of all volumes. @@ -1772,12 +1786,12 @@ void _3DScene::set_model(wxGLCanvas* canvas, Model* model) void _3DScene::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape) { - return s_canvas_mgr.set_bed_shape(canvas, shape); + s_canvas_mgr.set_bed_shape(canvas, shape); } void _3DScene::set_auto_bed_shape(wxGLCanvas* canvas) { - return s_canvas_mgr.set_auto_bed_shape(canvas); + s_canvas_mgr.set_auto_bed_shape(canvas); } BoundingBoxf3 _3DScene::get_volumes_bounding_box(wxGLCanvas* canvas) @@ -1792,22 +1806,27 @@ void _3DScene::set_axes_length(wxGLCanvas* canvas, float length) void _3DScene::set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons) { - return s_canvas_mgr.set_cutting_plane(canvas, z, polygons); + s_canvas_mgr.set_cutting_plane(canvas, z, polygons); } void _3DScene::set_color_by(wxGLCanvas* canvas, const std::string& value) { - return s_canvas_mgr.set_color_by(canvas, value); + s_canvas_mgr.set_color_by(canvas, value); } void _3DScene::set_select_by(wxGLCanvas* canvas, const std::string& value) { - return s_canvas_mgr.set_select_by(canvas, value); + s_canvas_mgr.set_select_by(canvas, value); } void _3DScene::set_drag_by(wxGLCanvas* canvas, const std::string& value) { - return s_canvas_mgr.set_drag_by(canvas, value); + s_canvas_mgr.set_drag_by(canvas, value); +} + +std::string _3DScene::get_select_by(wxGLCanvas* canvas) +{ + return s_canvas_mgr.get_select_by(canvas); } bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas) @@ -2080,6 +2099,11 @@ void _3DScene::register_action_layersediting_callback(wxGLCanvas* canvas, void* s_canvas_mgr.register_action_layersediting_callback(canvas, callback); } +void _3DScene::register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback) +{ + s_canvas_mgr.register_action_selectbyparts_callback(canvas, callback); +} + static inline int hex_digit_to_int(const char c) { return @@ -2117,6 +2141,11 @@ std::vector _3DScene::load_object(wxGLCanvas* canvas, const Model* model, i return s_canvas_mgr.load_object(canvas, model, obj_idx); } +int _3DScene::get_first_volume_id(wxGLCanvas* canvas, int obj_idx) +{ + return s_canvas_mgr.get_first_volume_id(canvas, obj_idx); +} + void _3DScene::reload_scene(wxGLCanvas* canvas, bool force) { s_canvas_mgr.reload_scene(canvas, force); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 1785ecf4a..ec9d1a501 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -337,6 +337,8 @@ public: void set_convex_hull(const TriangleMesh& convex_hull); + void set_select_group_id(const std::string& select_by); + int object_idx() const { return this->composite_id / 1000000; } int volume_idx() const { return (this->composite_id / 1000) % 1000; } int instance_idx() const { return this->composite_id % 1000; } @@ -446,6 +448,8 @@ public: void update_colors_by_extruder(const DynamicPrintConfig* config); + void set_select_by(const std::string& select_by); + // Returns a vector containing the sorted list of all the print_zs of the volumes contained in this collection std::vector get_current_print_zs(bool active_only) const; @@ -499,6 +503,8 @@ public: static void set_select_by(wxGLCanvas* canvas, const std::string& value); static void set_drag_by(wxGLCanvas* canvas, const std::string& value); + static std::string get_select_by(wxGLCanvas* canvas); + static bool is_layers_editing_enabled(wxGLCanvas* canvas); static bool is_layers_editing_allowed(wxGLCanvas* canvas); static bool is_shader_enabled(wxGLCanvas* canvas); @@ -562,10 +568,13 @@ public: static void register_action_cut_callback(wxGLCanvas* canvas, void* callback); static void register_action_settings_callback(wxGLCanvas* canvas, void* callback); static void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback); + static void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback); static std::vector load_object(wxGLCanvas* canvas, const ModelObject* model_object, int obj_idx, std::vector instance_idxs); static std::vector load_object(wxGLCanvas* canvas, const Model* model, int obj_idx); + static int get_first_volume_id(wxGLCanvas* canvas, int obj_idx); + static void reload_scene(wxGLCanvas* canvas, bool force); static void load_gcode_preview(wxGLCanvas* canvas, const GCodePreviewData* preview_data, const std::vector& str_tool_colors); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 2bec6b66b..56bfb8f37 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -2018,6 +2018,9 @@ void GLCanvas3D::update_volumes_selection(const std::vector& selections) if (m_model == nullptr) return; + if (selections.empty()) + return; + for (unsigned int obj_idx = 0; obj_idx < (unsigned int)m_model->objects.size(); ++obj_idx) { if ((selections[obj_idx] == 1) && (obj_idx < (unsigned int)m_objects_volumes_idxs.size())) @@ -2144,6 +2147,7 @@ void GLCanvas3D::set_color_by(const std::string& value) void GLCanvas3D::set_select_by(const std::string& value) { m_select_by = value; + m_volumes.set_select_by(value); } void GLCanvas3D::set_drag_by(const std::string& value) @@ -2151,6 +2155,11 @@ void GLCanvas3D::set_drag_by(const std::string& value) m_drag_by = value; } +const std::string& GLCanvas3D::get_select_by() const +{ + return m_select_by; +} + float GLCanvas3D::get_camera_zoom() const { return m_camera.zoom; @@ -2432,6 +2441,17 @@ std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) return std::vector(); } +int GLCanvas3D::get_first_volume_id(int obj_idx) const +{ + for (int i = 0; i < (int)m_volumes.volumes.size(); ++i) + { + if ((m_volumes.volumes[i] != nullptr) && (m_volumes.volumes[i]->object_idx() == obj_idx)) + return i; + } + + return -1; +} + void GLCanvas3D::reload_scene(bool force) { if ((m_canvas == nullptr) || (m_config == nullptr) || (m_model == nullptr)) @@ -2757,6 +2777,12 @@ void GLCanvas3D::register_action_layersediting_callback(void* callback) m_action_layersediting_callback.register_callback(callback); } +void GLCanvas3D::register_action_selectbyparts_callback(void* callback) +{ + if (callback != nullptr) + m_action_selectbyparts_callback.register_callback(callback); +} + void GLCanvas3D::bind_event_handlers() { if (m_canvas != nullptr) @@ -3043,7 +3069,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // propagate event through callback if (m_picking_enabled && (volume_idx != -1)) - _on_select(volume_idx); + _on_select(volume_idx, selected_object_idx); if (volume_idx != -1) { @@ -3287,7 +3313,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_picking_enabled && !m_toolbar_action_running) { deselect_volumes(); - _on_select(-1); + _on_select(-1, -1); update_gizmos_data(); } } @@ -3512,6 +3538,17 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.add_item(item)) return false; + if (!m_toolbar.add_separator()) + return false; + + item.name = "selectbyparts"; + item.tooltip = GUI::L_str("Select by parts"); + item.sprite_id = 10; + item.is_toggable = true; + item.action_callback = &m_action_selectbyparts_callback; + if (!m_toolbar.add_item(item)) + return false; + enable_toolbar_item("add", true); return true; @@ -3751,6 +3788,7 @@ void GLCanvas3D::_deregister_callbacks() m_action_cut_callback.deregister_callback(); m_action_settings_callback.deregister_callback(); m_action_layersediting_callback.deregister_callback(); + m_action_selectbyparts_callback.deregister_callback(); } void GLCanvas3D::_mark_volumes_for_layer_height() const @@ -5262,17 +5300,35 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) m_on_wipe_tower_moved_callback.call(wipe_tower_origin(0), wipe_tower_origin(1)); } -void GLCanvas3D::_on_select(int volume_idx) +void GLCanvas3D::_on_select(int volume_idx, int object_idx) { - int id = -1; + int vol_id = -1; + int obj_id = -1; + if ((volume_idx != -1) && (volume_idx < (int)m_volumes.volumes.size())) { if (m_select_by == "volume") - id = m_volumes.volumes[volume_idx]->volume_idx(); + { + if (m_volumes.volumes[volume_idx]->object_idx() != object_idx) + { + set_select_by("object"); + obj_id = m_volumes.volumes[volume_idx]->object_idx(); + vol_id = -1; + } + else + { + obj_id = object_idx; + vol_id = m_volumes.volumes[volume_idx]->volume_idx(); + } + } else if (m_select_by == "object") - id = m_volumes.volumes[volume_idx]->object_idx(); + { + obj_id = m_volumes.volumes[volume_idx]->object_idx(); + vol_id = -1; + } } - m_on_select_object_callback.call(id); + + m_on_select_object_callback.call(obj_id, vol_id); } std::vector GLCanvas3D::_parse_colors(const std::vector& colors) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 2969d12c6..541495eec 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -514,6 +514,7 @@ private: PerlCallback m_action_cut_callback; PerlCallback m_action_settings_callback; PerlCallback m_action_layersediting_callback; + PerlCallback m_action_selectbyparts_callback; public: GLCanvas3D(wxGLCanvas* canvas); @@ -556,6 +557,8 @@ public: void set_select_by(const std::string& value); void set_drag_by(const std::string& value); + const std::string& get_select_by() const; + float get_camera_zoom() const; BoundingBoxf3 volumes_bounding_box() const; @@ -597,6 +600,8 @@ public: std::vector load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs); std::vector load_object(const Model& model, int obj_idx); + int get_first_volume_id(int obj_idx) const; + void reload_scene(bool force); void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector& str_tool_colors); @@ -631,6 +636,7 @@ public: void register_action_cut_callback(void* callback); void register_action_settings_callback(void* callback); void register_action_layersediting_callback(void* callback); + void register_action_selectbyparts_callback(void* callback); void bind_event_handlers(); void unbind_event_handlers(); @@ -733,7 +739,7 @@ private: void _show_warning_texture_if_needed(); void _on_move(const std::vector& volume_idxs); - void _on_select(int volume_idx); + void _on_select(int volume_idx, int object_idx); // generates the legend texture in dependence of the current shown view type void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector& tool_colors); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 57a49d7ab..a09d83b89 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -338,6 +338,12 @@ void GLCanvas3DManager::set_drag_by(wxGLCanvas* canvas, const std::string& value it->second->set_drag_by(value); } +std::string GLCanvas3DManager::get_select_by(wxGLCanvas* canvas) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->get_select_by() : ""; +} + bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const { CanvasesMap::const_iterator it = _get_canvas(canvas); @@ -536,6 +542,12 @@ std::vector GLCanvas3DManager::load_object(wxGLCanvas* canvas, const Model* return (it != m_canvases.end()) ? it->second->load_object(*model, obj_idx) : std::vector(); } +int GLCanvas3DManager::get_first_volume_id(wxGLCanvas* canvas, int obj_idx) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->get_first_volume_id(obj_idx) : -1; +} + void GLCanvas3DManager::reload_scene(wxGLCanvas* canvas, bool force) { CanvasesMap::iterator it = _get_canvas(canvas); @@ -765,6 +777,13 @@ void GLCanvas3DManager::register_action_layersediting_callback(wxGLCanvas* canva it->second->register_action_layersediting_callback(callback); } +void GLCanvas3DManager::register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->register_action_selectbyparts_callback(callback); +} + GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas) { return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index f7705a56c..1c715a9a3 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -98,6 +98,8 @@ public: void set_select_by(wxGLCanvas* canvas, const std::string& value); void set_drag_by(wxGLCanvas* canvas, const std::string& value); + std::string get_select_by(wxGLCanvas* canvas) const; + bool is_layers_editing_enabled(wxGLCanvas* canvas) const; bool is_layers_editing_allowed(wxGLCanvas* canvas) const; bool is_shader_enabled(wxGLCanvas* canvas) const; @@ -135,6 +137,8 @@ public: std::vector load_object(wxGLCanvas* canvas, const ModelObject* model_object, int obj_idx, std::vector instance_idxs); std::vector load_object(wxGLCanvas* canvas, const Model* model, int obj_idx); + int get_first_volume_id(wxGLCanvas* canvas, int obj_idx) const; + void reload_scene(wxGLCanvas* canvas, bool force); void load_gcode_preview(wxGLCanvas* canvas, const GCodePreviewData* preview_data, const std::vector& str_tool_colors); @@ -171,6 +175,7 @@ public: void register_action_cut_callback(wxGLCanvas* canvas, void* callback); void register_action_settings_callback(wxGLCanvas* canvas, void* callback); void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback); + void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback); private: CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 9ec39b976..af57db8ed 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -1572,7 +1572,6 @@ void update_position_values() void update_position_values(const Vec3d& position) { auto og = get_optgroup(ogFrequentlyObjectSettings); - auto instance = (*m_objects)[m_selected_object_id]->instances.front(); og->set_value("position_x", int(position(0))); og->set_value("position_y", int(position(1))); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 6c199aacb..756f9e547 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -337,6 +337,14 @@ set_drag_by(canvas, value) CODE: _3DScene::set_drag_by((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), value); +std::string +get_select_by(canvas) + SV *canvas; + CODE: + RETVAL = _3DScene::get_select_by((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + OUTPUT: + RETVAL + bool is_layers_editing_enabled(canvas) SV *canvas; @@ -720,6 +728,13 @@ register_action_layersediting_callback(canvas, callback) CODE: _3DScene::register_action_layersediting_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); +void +register_action_selectbyparts_callback(canvas, callback) + SV *canvas; + SV *callback; + CODE: + _3DScene::register_action_selectbyparts_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback); + void reset_legend_texture() CODE: @@ -736,6 +751,15 @@ load_model_object(canvas, model_object, obj_idx, instance_idxs) OUTPUT: RETVAL +int +get_first_volume_id(canvas, obj_idx) + SV *canvas; + int obj_idx; + CODE: + RETVAL = _3DScene::get_first_volume_id((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), obj_idx); + OUTPUT: + RETVAL + std::vector load_model(canvas, model, obj_idx) SV *canvas; From 6960958276457fe5fbcee0ad10fb1d3c991a41fd Mon Sep 17 00:00:00 2001 From: Martin Loidl Date: Thu, 6 Sep 2018 19:07:54 +0200 Subject: [PATCH 21/31] minor changes for url_encode --- xs/src/slic3r/Utils/Duet.cpp | 1 - xs/src/slic3r/Utils/Http.cpp | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xs/src/slic3r/Utils/Duet.cpp b/xs/src/slic3r/Utils/Duet.cpp index a3dc4a3bb..f25327161 100644 --- a/xs/src/slic3r/Utils/Duet.cpp +++ b/xs/src/slic3r/Utils/Duet.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/xs/src/slic3r/Utils/Http.cpp b/xs/src/slic3r/Utils/Http.cpp index 3024b08fe..9b67ceea8 100644 --- a/xs/src/slic3r/Utils/Http.cpp +++ b/xs/src/slic3r/Utils/Http.cpp @@ -424,11 +424,14 @@ bool Http::ca_file_supported() std::string Http::url_encode(const std::string &str) { ::CURL *curl = ::curl_easy_init(); + if (curl == nullptr) { + return str; + } char *ce = ::curl_easy_escape(curl, str.c_str(), str.length()); std::string encoded = std::string(ce); ::curl_free(ce); - if (curl != nullptr) { ::curl_easy_cleanup(curl); } + ::curl_easy_cleanup(curl); return encoded; } From 0ea18d57d0c27e4fe8d46f90ac9d620140d90dc5 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 09:21:12 +0200 Subject: [PATCH 22/31] Fixed wipe tower selection --- lib/Slic3r/GUI/Plater.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 8a9d13aae..016c2e800 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -2129,17 +2129,18 @@ sub on_config_change { $self->schedule_background_process; } -sub item_changed_selection{ +sub item_changed_selection { my ($self, $obj_idx) = @_; -# $self->{canvas}->Refresh; - if ($self->{canvas3D}) { - Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D}); - if ($obj_idx >= 0){ - my $selections = $self->collect_selections; - Slic3r::GUI::_3DScene::update_volumes_selection($self->{canvas3D}, \@$selections); + if (($obj_idx >= 0) && ($obj_idx < 1000)) { # skip if wipe tower selected + if ($self->{canvas3D}) { + Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D}); + if ($obj_idx >= 0) { + my $selections = $self->collect_selections; + Slic3r::GUI::_3DScene::update_volumes_selection($self->{canvas3D}, \@$selections); + } +# Slic3r::GUI::_3DScene::render($self->{canvas3D}); } - Slic3r::GUI::_3DScene::render($self->{canvas3D}); } } From 125ece0aadb51814473787a33852cf94a48a53fd Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 7 Sep 2018 09:33:18 +0200 Subject: [PATCH 23/31] Fixed #1204 --- lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm index 3b10ed99f..ea4ce7132 100644 --- a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm +++ b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm @@ -136,7 +136,7 @@ sub update_optgroup { full_labels => 1, label_font => $Slic3r::GUI::small_font, sidetext_font => $Slic3r::GUI::small_font, - label_width => 120, + label_width => 150, on_change => sub { $self->{on_change}->() if $self->{on_change} }, extra_column => sub { my ($line) = @_; From e04805eaa2593a7c8a5c521c33a3c1adc05ff976 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 10:30:13 +0200 Subject: [PATCH 24/31] Fixed rendering of endcaps on open toolpaths --- xs/src/slic3r/GUI/3DScene.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 705347094..9cf55513c 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1182,7 +1182,7 @@ static void thick_lines_to_indexed_vertex_array( b1_prev = b1; v_prev = v; - if (bottom_z_different) + if (bottom_z_different && (closed || (!is_first && !is_last))) { // Found a change of the layer thickness -> Add a cap at the beginning of this segment. volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); @@ -1190,10 +1190,10 @@ static void thick_lines_to_indexed_vertex_array( if (! closed) { // Terminate open paths with caps. - if (is_first && !bottom_z_different) + if (is_first) volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); // We don't use 'else' because both cases are true if we have only one line. - if (is_last && !bottom_z_different) + if (is_last) volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); } From ea15475ad87db66bfde5fc2a65a2b831773d4518 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 12:00:04 +0200 Subject: [PATCH 25/31] Fixed double click on gizmo overlay and toolbar --- xs/src/slic3r/GUI/GLCanvas3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 56bfb8f37..edc5bc78e 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -2978,7 +2978,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.position = Vec2d(-1.0, -1.0); m_dirty = true; } - else if (evt.LeftDClick() && (m_hover_volume_id != -1)) + else if (evt.LeftDClick() && (m_hover_volume_id != -1) && !gizmos_overlay_contains_mouse && (toolbar_contains_mouse == -1)) m_on_double_click_callback.call(); else if (evt.LeftDClick() && (toolbar_contains_mouse != -1)) { From ada6dba00b8ff33be8087bbe276856a2742bc6ef Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 12:20:56 +0200 Subject: [PATCH 26/31] Selection of picking color for gizmo grabber moved into GLGizmoBase --- xs/src/slic3r/GUI/GLGizmo.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 1c0456fa8..75d818a55 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -199,8 +199,11 @@ void GLGizmoBase::render_grabbers() const void GLGizmoBase::render_grabbers_for_picking() const { - for (int i = 0; i < (int)m_grabbers.size(); ++i) + for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) { + m_grabbers[i].color[0] = 1.0f; + m_grabbers[i].color[1] = 1.0f; + m_grabbers[i].color[2] = picking_color_component(i); m_grabbers[i].render_for_picking(); } } @@ -335,12 +338,8 @@ void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const ::glDisable(GL_DEPTH_TEST); ::glPushMatrix(); + transform_to_local(); - - m_grabbers[0].color[0] = 1.0f; - m_grabbers[0].color[1] = 1.0f; - m_grabbers[0].color[2] = picking_color_component(0); - render_grabbers_for_picking(); ::glPopMatrix(); @@ -815,13 +814,6 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const { ::glDisable(GL_DEPTH_TEST); - for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) - { - m_grabbers[i].color[0] = 1.0f; - m_grabbers[i].color[1] = 1.0f; - m_grabbers[i].color[2] = picking_color_component(i); - } - render_grabbers_for_picking(); } From 775ec1b5467d0d27776bc6c598cda010d1137f2c Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 13:40:26 +0200 Subject: [PATCH 27/31] Tweaks to gizmo scale 3D --- xs/src/slic3r/GUI/GLGizmo.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 75d818a55..4e8a6d3d5 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -15,9 +15,7 @@ static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f }; static const float DEFAULT_DRAG_COLOR[3] = { 1.0f, 1.0f, 1.0f }; static const float DEFAULT_HIGHLIGHT_COLOR[3] = { 1.0f, 0.38f, 0.0f }; -static const float RED[3] = { 1.0f, 0.0f, 0.0f }; -static const float GREEN[3] = { 0.0f, 1.0f, 0.0f }; -static const float BLUE[3] = { 0.0f, 0.0f, 1.0f }; +static const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }; namespace Slic3r { namespace GUI { @@ -525,9 +523,9 @@ bool GLGizmoRotate3D::on_init() if (!m_x.init() || !m_y.init() || !m_z.init()) return false; - m_x.set_highlight_color(RED); - m_y.set_highlight_color(GREEN); - m_z.set_highlight_color(BLUE); + m_x.set_highlight_color(AXES_COLOR[0]); + m_y.set_highlight_color(AXES_COLOR[1]); + m_z.set_highlight_color(AXES_COLOR[2]); std::string path = resources_dir() + "/icons/overlay/"; @@ -702,20 +700,20 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const // x axis m_grabbers[0].center = Vec3d(m_box.min(0), center(1), center(2)); m_grabbers[1].center = Vec3d(m_box.max(0), center(1), center(2)); - ::memcpy((void*)m_grabbers[0].color, (const void*)RED, 3 * sizeof(float)); - ::memcpy((void*)m_grabbers[1].color, (const void*)RED, 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[0].color, (const void*)&AXES_COLOR[0], 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[1].color, (const void*)&AXES_COLOR[0], 3 * sizeof(float)); // y axis m_grabbers[2].center = Vec3d(center(0), m_box.min(1), center(2)); m_grabbers[3].center = Vec3d(center(0), m_box.max(1), center(2)); - ::memcpy((void*)m_grabbers[2].color, (const void*)GREEN, 3 * sizeof(float)); - ::memcpy((void*)m_grabbers[3].color, (const void*)GREEN, 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[2].color, (const void*)&AXES_COLOR[1], 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[3].color, (const void*)&AXES_COLOR[1], 3 * sizeof(float)); // z axis m_grabbers[4].center = Vec3d(center(0), center(1), m_box.min(2)); m_grabbers[5].center = Vec3d(center(0), center(1), m_box.max(2)); - ::memcpy((void*)m_grabbers[4].color, (const void*)BLUE, 3 * sizeof(float)); - ::memcpy((void*)m_grabbers[5].color, (const void*)BLUE, 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[4].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); + ::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); // uniform m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2)); @@ -734,6 +732,13 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const // draw box ::glColor3fv(m_base_color); render_box(m_box); + // draw connections + ::glColor3fv(m_grabbers[0].color); + render_grabbers_connection(0, 1); + ::glColor3fv(m_grabbers[2].color); + render_grabbers_connection(2, 3); + ::glColor3fv(m_grabbers[4].color); + render_grabbers_connection(4, 5); // draw grabbers render_grabbers(); } From e1deb03d3cc469f29aff0bfe461b782330526250 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 14:21:04 +0200 Subject: [PATCH 28/31] Added perl callback for three doubles --- xs/src/libslic3r/Utils.hpp | 3 ++- xs/src/libslic3r/utils.cpp | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index 349222854..f1390b8a2 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -97,8 +97,9 @@ public: void call(int i) const; void call(int i, int j) const; void call(const std::vector& ints) const; - void call(double d) const; + void call(double a) const; void call(double a, double b) const; + void call(double a, double b, double c) const; void call(double a, double b, double c, double d) const; void call(bool b) const; private: diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index 55164bbdd..95aaf5453 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -251,7 +251,7 @@ void PerlCallback::call(const std::vector& ints) const LEAVE; } -void PerlCallback::call(double d) const +void PerlCallback::call(double a) const { if (!m_callback) return; @@ -259,7 +259,7 @@ void PerlCallback::call(double d) const ENTER; SAVETMPS; PUSHMARK(SP); - XPUSHs(sv_2mortal(newSVnv(d))); + XPUSHs(sv_2mortal(newSVnv(a))); PUTBACK; perl_call_sv(SvRV((SV*)m_callback), G_DISCARD); FREETMPS; @@ -282,6 +282,23 @@ void PerlCallback::call(double a, double b) const LEAVE; } +void PerlCallback::call(double a, double b, double c) const +{ + if (!m_callback) + return; + dSP; + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs(sv_2mortal(newSVnv(a))); + XPUSHs(sv_2mortal(newSVnv(b))); + XPUSHs(sv_2mortal(newSVnv(c))); + PUTBACK; + perl_call_sv(SvRV((SV*)m_callback), G_DISCARD); + FREETMPS; + LEAVE; +} + void PerlCallback::call(double a, double b, double c, double d) const { if (!m_callback) From 62894d3f7b841436c1fb849336b4e0dd15726fad Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 7 Sep 2018 16:05:10 +0200 Subject: [PATCH 29/31] Export the first M73 line to gcode before custom gcode --- xs/src/libslic3r/GCode.cpp | 9 ++++++++- xs/src/libslic3r/GCodeTimeEstimator.cpp | 13 ++++++++++++- xs/src/libslic3r/GCodeTimeEstimator.hpp | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index b34ba5441..67a682d18 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -665,6 +665,14 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) _write_format(file, "\n"); } + // adds tags for time estimators + if (print.config.remaining_times.value) + { + _writeln(file, GCodeTimeEstimator::Normal_First_M73_Output_Placeholder_Tag); + if (m_silent_time_estimator_enabled) + _writeln(file, GCodeTimeEstimator::Silent_First_M73_Output_Placeholder_Tag); + } + // Prepare the helper object for replacing placeholders in custom G-code and output filename. m_placeholder_parser = print.placeholder_parser; m_placeholder_parser.update_timestamp(); @@ -724,7 +732,6 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) m_placeholder_parser.set("has_wipe_tower", has_wipe_tower); m_placeholder_parser.set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config.single_extruder_multi_material_priming); std::string start_gcode = this->placeholder_parser_process("start_gcode", print.config.start_gcode.value, initial_extruder_id); - // Set bed temperature if the start G-code does not contain any bed temp control G-codes. this->_print_first_layer_bed_temperature(file, print, start_gcode, initial_extruder_id, true); // Set extruder(s) temperature before and after start G-code. diff --git a/xs/src/libslic3r/GCodeTimeEstimator.cpp b/xs/src/libslic3r/GCodeTimeEstimator.cpp index c4ffb572a..f4f6472e5 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.cpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.cpp @@ -168,6 +168,9 @@ namespace Slic3r { } #endif // ENABLE_MOVE_STATS + const std::string GCodeTimeEstimator::Normal_First_M73_Output_Placeholder_Tag = "; NORMAL_FIRST_M73_OUTPUT_PLACEHOLDER"; + const std::string GCodeTimeEstimator::Silent_First_M73_Output_Placeholder_Tag = "; SILENT_FIRST_M73_OUTPUT_PLACEHOLDER"; + GCodeTimeEstimator::GCodeTimeEstimator(EMode mode) : _mode(mode) { @@ -294,7 +297,15 @@ namespace Slic3r { throw std::runtime_error(std::string("Remaining times export failed.\nError while reading from file.\n")); } - gcode_line += "\n"; + // replaces placeholders for initial line M73 with the real lines + if (((_mode == Normal) && (gcode_line == Normal_First_M73_Output_Placeholder_Tag)) || + ((_mode == Silent) && (gcode_line == Silent_First_M73_Output_Placeholder_Tag))) + { + sprintf(time_line, time_mask.c_str(), std::to_string(0), _get_time_minutes(_time).c_str()); + gcode_line = time_line; + } + else + gcode_line += "\n"; // add remaining time lines where needed _parser.parse_line(gcode_line, diff --git a/xs/src/libslic3r/GCodeTimeEstimator.hpp b/xs/src/libslic3r/GCodeTimeEstimator.hpp index 1fa74e304..e9da584c3 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.hpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.hpp @@ -17,6 +17,9 @@ namespace Slic3r { class GCodeTimeEstimator { public: + static const std::string Normal_First_M73_Output_Placeholder_Tag; + static const std::string Silent_First_M73_Output_Placeholder_Tag; + enum EMode : unsigned char { Normal, From 5e8bd4798834d0d5f22afb58acb13dd081585742 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 10 Sep 2018 10:01:49 +0200 Subject: [PATCH 30/31] Partial refactoring of 3d gizmos --- xs/src/slic3r/GUI/GLCanvas3D.cpp | 23 +----- xs/src/slic3r/GUI/GLCanvas3D.hpp | 3 +- xs/src/slic3r/GUI/GLGizmo.cpp | 129 +++++++++++++------------------ xs/src/slic3r/GUI/GLGizmo.hpp | 74 +++++++++--------- 4 files changed, 91 insertions(+), 138 deletions(-) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index edc5bc78e..161ce89da 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1320,16 +1320,6 @@ void GLCanvas3D::Gizmos::update(const Linef3& mouse_ray) curr->update(mouse_ray); } -void GLCanvas3D::Gizmos::refresh() -{ - if (!m_enabled) - return; - - GLGizmoBase* curr = _get_current(); - if (curr != nullptr) - curr->refresh(); -} - GLCanvas3D::Gizmos::EType GLCanvas3D::Gizmos::get_current_type() const { return m_current; @@ -1349,12 +1339,12 @@ bool GLCanvas3D::Gizmos::is_dragging() const return m_dragging; } -void GLCanvas3D::Gizmos::start_dragging() +void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box) { m_dragging = true; GLGizmoBase* curr = _get_current(); if (curr != nullptr) - curr->start_dragging(); + curr->start_dragging(box); } void GLCanvas3D::Gizmos::stop_dragging() @@ -2487,8 +2477,6 @@ void GLCanvas3D::reload_scene(bool force) if (!m_objects_selections.empty()) update_gizmos_data(); - m_gizmos.refresh(); - if (m_config->has("nozzle_diameter")) { // Should the wipe tower be visualized ? @@ -3019,7 +3007,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if ((selected_object_idx != -1) && m_gizmos.grabber_contains_mouse()) { update_gizmos_data(); - m_gizmos.start_dragging(); + m_gizmos.start_dragging(_selected_volumes_bounding_box()); m_mouse.drag.gizmo_volume_idx = _get_first_selected_volume_id(selected_object_idx); if (m_gizmos.get_current_type() == Gizmos::Flatten) { @@ -3062,7 +3050,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } update_gizmos_data(); - m_gizmos.refresh(); m_dirty = true; } } @@ -3158,7 +3145,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) update_position_values(volume->get_offset()); m_mouse.drag.start_position_3D = cur_pos; - m_gizmos.refresh(); m_dirty = true; } @@ -3226,9 +3212,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale()); } - if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1)) - m_gizmos.refresh(); - m_dirty = true; } else if (evt.Dragging() && !gizmos_overlay_contains_mouse) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 541495eec..c5b4581fa 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -367,14 +367,13 @@ public: bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const; bool grabber_contains_mouse() const; void update(const Linef3& mouse_ray); - void refresh(); EType get_current_type() const; bool is_running() const; bool is_dragging() const; - void start_dragging(); + void start_dragging(const BoundingBoxf3& box); void stop_dragging(); float get_scale() const; diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 4e8a6d3d5..ff0adac62 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -129,6 +129,7 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent) , m_group_id(-1) , m_state(Off) , m_hover_id(-1) + , m_dragging(false) { ::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 3 * sizeof(float)); ::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 3 * sizeof(float)); @@ -150,18 +151,21 @@ void GLGizmoBase::set_highlight_color(const float* color) ::memcpy((void*)m_highlight_color, (const void*)color, 3 * sizeof(float)); } -void GLGizmoBase::start_dragging() +void GLGizmoBase::start_dragging(const BoundingBoxf3& box) { + m_dragging = true; + for (int i = 0; i < (int)m_grabbers.size(); ++i) { m_grabbers[i].dragging = (m_hover_id == i); } - on_start_dragging(); + on_start_dragging(box); } void GLGizmoBase::stop_dragging() { + m_dragging = false; set_tooltip(""); for (int i = 0; i < (int)m_grabbers.size(); ++i) @@ -235,7 +239,6 @@ GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis) , m_angle(0.0) , m_center(0.0, 0.0, 0.0) , m_radius(0.0f) - , m_keep_initial_values(false) { } @@ -253,6 +256,12 @@ bool GLGizmoRotate::on_init() return true; } +void GLGizmoRotate::on_start_dragging(const BoundingBoxf3& box) +{ + m_center = box.center(); + m_radius = Offset + box.radius(); +} + void GLGizmoRotate::on_update(const Linef3& mouse_ray) { Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(mouse_ray)); @@ -294,18 +303,16 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray) void GLGizmoRotate::on_render(const BoundingBoxf3& box) const { - if (m_grabbers[0].dragging) + if (m_dragging) set_tooltip(format(m_angle * 180.0f / (float)PI, 4)); - - ::glEnable(GL_DEPTH_TEST); - - if (!m_keep_initial_values) + else { m_center = box.center(); m_radius = Offset + box.radius(); - m_keep_initial_values = true; } + ::glEnable(GL_DEPTH_TEST); + ::glPushMatrix(); transform_to_local(); @@ -509,23 +516,29 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) cons GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent) : GLGizmoBase(parent) - , m_x(parent, GLGizmoRotate::X) - , m_y(parent, GLGizmoRotate::Y) - , m_z(parent, GLGizmoRotate::Z) { - m_x.set_group_id(0); - m_y.set_group_id(1); - m_z.set_group_id(2); + m_gizmos.emplace_back(parent, GLGizmoRotate::X); + m_gizmos.emplace_back(parent, GLGizmoRotate::Y); + m_gizmos.emplace_back(parent, GLGizmoRotate::Z); + + for (unsigned int i = 0; i < 3; ++i) + { + m_gizmos[i].set_group_id(i); + } } bool GLGizmoRotate3D::on_init() { - if (!m_x.init() || !m_y.init() || !m_z.init()) - return false; + for (GLGizmoRotate& g : m_gizmos) + { + if (!g.init()) + return false; + } - m_x.set_highlight_color(AXES_COLOR[0]); - m_y.set_highlight_color(AXES_COLOR[1]); - m_z.set_highlight_color(AXES_COLOR[2]); + for (unsigned int i = 0; i < 3; ++i) + { + m_gizmos[i].set_highlight_color(AXES_COLOR[i]); + } std::string path = resources_dir() + "/icons/overlay/"; @@ -544,68 +557,28 @@ bool GLGizmoRotate3D::on_init() return true; } -void GLGizmoRotate3D::on_start_dragging() +void GLGizmoRotate3D::on_start_dragging(const BoundingBoxf3& box) { - switch (m_hover_id) - { - case 0: - { - m_x.start_dragging(); - break; - } - case 1: - { - m_y.start_dragging(); - break; - } - case 2: - { - m_z.start_dragging(); - break; - } - default: - { - break; - } - } + if ((0 <= m_hover_id) && (m_hover_id < 3)) + m_gizmos[m_hover_id].start_dragging(box); } void GLGizmoRotate3D::on_stop_dragging() { - switch (m_hover_id) - { - case 0: - { - m_x.stop_dragging(); - break; - } - case 1: - { - m_y.stop_dragging(); - break; - } - case 2: - { - m_z.stop_dragging(); - break; - } - default: - { - break; - } - } + if ((0 <= m_hover_id) && (m_hover_id < 3)) + m_gizmos[m_hover_id].stop_dragging(); } void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const { if ((m_hover_id == -1) || (m_hover_id == 0)) - m_x.render(box); + m_gizmos[X].render(box); if ((m_hover_id == -1) || (m_hover_id == 1)) - m_y.render(box); + m_gizmos[Y].render(box); if ((m_hover_id == -1) || (m_hover_id == 2)) - m_z.render(box); + m_gizmos[Z].render(box); } const float GLGizmoScale3D::Offset = 5.0f; @@ -652,13 +625,13 @@ bool GLGizmoScale3D::on_init() return true; } -void GLGizmoScale3D::on_start_dragging() +void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box) { if (m_hover_id != -1) { m_starting_drag_position = m_grabbers[m_hover_id].center; m_show_starting_box = true; - m_starting_box = m_box; + m_starting_box = box; } } @@ -989,7 +962,8 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent) : GLGizmoBase(parent) - , m_normal(0.0, 0.0, 0.0) + , m_normal(Vec3d::Zero()) + , m_center(Vec3d::Zero()) { } @@ -1012,10 +986,13 @@ bool GLGizmoFlatten::on_init() return true; } -void GLGizmoFlatten::on_start_dragging() +void GLGizmoFlatten::on_start_dragging(const BoundingBoxf3& box) { if (m_hover_id != -1) + { m_normal = m_planes[m_hover_id].normal; + m_center = box.center(); + } } void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const @@ -1023,10 +1000,9 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const // the dragged_offset is a vector measuring where was the object moved // with the gizmo being on. This is reset in set_flattening_data and // does not work correctly when there are multiple copies. - if (!m_center) // this is the first bounding box that we see - m_center.reset(new Vec3d(box.center())); - - Vec3d dragged_offset = box.center() - *m_center; + Vec3d dragged_offset(Vec3d::Zero()); + if (m_dragging) + dragged_offset = box.center() - m_center; ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); @@ -1073,7 +1049,6 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) { - m_center.release(); // object is not being dragged (this would not be called otherwise) - we must forget about the bounding box position... m_model_object = model_object; // ...and save the updated positions of the object instances: diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 3041f2adf..82a004b5b 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -57,6 +57,7 @@ protected: // textures are assumed to be square and all with the same size in pixels, no internal check is done GLTexture m_textures[Num_States]; int m_hover_id; + bool m_dragging; float m_base_color[3]; float m_drag_color[3]; float m_highlight_color[3]; @@ -82,10 +83,11 @@ public: void set_highlight_color(const float* color); - void start_dragging(); + void start_dragging(const BoundingBoxf3& box); void stop_dragging(); + bool is_dragging() const { return m_dragging; } + void update(const Linef3& mouse_ray); - void refresh() { on_refresh(); } void render(const BoundingBoxf3& box) const { on_render(box); } void render_for_picking(const BoundingBoxf3& box) const { on_render_for_picking(box); } @@ -94,10 +96,9 @@ protected: virtual bool on_init() = 0; virtual void on_set_state() {} virtual void on_set_hover_id() {} - virtual void on_start_dragging() {} + virtual void on_start_dragging(const BoundingBoxf3& box) {} virtual void on_stop_dragging() {} virtual void on_update(const Linef3& mouse_ray) = 0; - virtual void on_refresh() {} virtual void on_render(const BoundingBoxf3& box) const = 0; virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0; @@ -136,7 +137,6 @@ private: mutable Vec3d m_center; mutable float m_radius; - mutable bool m_keep_initial_values; public: GLGizmoRotate(GLCanvas3D& parent, Axis axis); @@ -146,9 +146,8 @@ public: protected: virtual bool on_init(); - virtual void on_set_state() { m_keep_initial_values = (m_state == On) ? false : true; } + virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_update(const Linef3& mouse_ray); - virtual void on_refresh() { m_keep_initial_values = false; } virtual void on_render(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const; @@ -167,56 +166,52 @@ private: class GLGizmoRotate3D : public GLGizmoBase { - GLGizmoRotate m_x; - GLGizmoRotate m_y; - GLGizmoRotate m_z; + std::vector m_gizmos; public: explicit GLGizmoRotate3D(GLCanvas3D& parent); - double get_angle_x() const { return m_x.get_angle(); } - void set_angle_x(double angle) { m_x.set_angle(angle); } + double get_angle_x() const { return m_gizmos[X].get_angle(); } + void set_angle_x(double angle) { m_gizmos[X].set_angle(angle); } - double get_angle_y() const { return m_y.get_angle(); } - void set_angle_y(double angle) { m_y.set_angle(angle); } + double get_angle_y() const { return m_gizmos[Y].get_angle(); } + void set_angle_y(double angle) { m_gizmos[Y].set_angle(angle); } - double get_angle_z() const { return m_z.get_angle(); } - void set_angle_z(double angle) { m_z.set_angle(angle); } + double get_angle_z() const { return m_gizmos[Z].get_angle(); } + void set_angle_z(double angle) { m_gizmos[Z].set_angle(angle); } protected: virtual bool on_init(); virtual void on_set_state() { - m_x.set_state(m_state); - m_y.set_state(m_state); - m_z.set_state(m_state); + for (GLGizmoRotate& g : m_gizmos) + { + g.set_state(m_state); + } } virtual void on_set_hover_id() { - m_x.set_hover_id(m_hover_id == 0 ? 0 : -1); - m_y.set_hover_id(m_hover_id == 1 ? 0 : -1); - m_z.set_hover_id(m_hover_id == 2 ? 0 : -1); + for (unsigned int i = 0; i < 3; ++i) + { + m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1); + } } - virtual void on_start_dragging(); + virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_stop_dragging(); virtual void on_update(const Linef3& mouse_ray) { - m_x.update(mouse_ray); - m_y.update(mouse_ray); - m_z.update(mouse_ray); - } - virtual void on_refresh() - { - m_x.refresh(); - m_y.refresh(); - m_z.refresh(); + for (GLGizmoRotate& g : m_gizmos) + { + g.update(mouse_ray); + } } virtual void on_render(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const { - m_x.render_for_picking(box); - m_y.render_for_picking(box); - m_z.render_for_picking(box); + for (const GLGizmoRotate& g : m_gizmos) + { + g.render_for_picking(box); + } } }; @@ -249,7 +244,7 @@ public: protected: virtual bool on_init(); - virtual void on_start_dragging(); + virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_stop_dragging() { m_show_starting_box = false; } virtual void on_update(const Linef3& mouse_ray); virtual void on_render(const BoundingBoxf3& box) const; @@ -291,7 +286,7 @@ private: std::vector m_planes; std::vector m_instances_positions; - mutable std::unique_ptr m_center = nullptr; + Vec3d m_center; const ModelObject* m_model_object = nullptr; void update_planes(); @@ -305,11 +300,12 @@ public: protected: virtual bool on_init(); - virtual void on_start_dragging(); + virtual void on_start_dragging(const BoundingBoxf3& box); virtual void on_update(const Linef3& mouse_ray) {} virtual void on_render(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const; - virtual void on_set_state() { + virtual void on_set_state() + { if (m_state == On && is_plane_update_necessary()) update_planes(); } From d8936b1ad8e14372e911c7a7ebb7f1adc30ceae3 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 10 Sep 2018 11:58:24 +0200 Subject: [PATCH 31/31] Another partial refactoring of 3d gizmos --- xs/src/slic3r/GUI/GLGizmo.cpp | 154 ++++++++++++++++++++-------------- xs/src/slic3r/GUI/GLGizmo.hpp | 2 +- 2 files changed, 93 insertions(+), 63 deletions(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index ff0adac62..1d02e1752 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -20,7 +20,90 @@ static const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f namespace Slic3r { namespace GUI { -const float GLGizmoBase::Grabber::HalfSize = 2.0f; + // returns the intersection of the given ray with the plane parallel to plane XY and passing through the given center + // coordinates are local to the plane + Vec3d intersection_on_plane_xy(const Linef3& ray, const Vec3d& center) + { + Transform3d m = Transform3d::Identity(); + m.translate(-center); + Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0)); + return Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0); + } + + // returns the intersection of the given ray with the plane parallel to plane XZ and passing through the given center + // coordinates are local to the plane + Vec3d intersection_on_plane_xz(const Linef3& ray, const Vec3d& center) + { + Transform3d m = Transform3d::Identity(); + m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX())); + m.translate(-center); + Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0)); + return Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1)); + } + + // returns the intersection of the given ray with the plane parallel to plane YZ and passing through the given center + // coordinates are local to the plane + Vec3d intersection_on_plane_yz(const Linef3& ray, const Vec3d& center) + { + Transform3d m = Transform3d::Identity(); + m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY())); + m.translate(-center); + Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0)); + + return Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0)); + } + + // return an index: + // 0 for plane XY + // 1 for plane XZ + // 2 for plane YZ + // which indicates which plane is best suited for intersecting the given unit vector + // giving precedence to the plane with the given index + unsigned int select_best_plane(const Vec3d& unit_vector, unsigned int preferred_plane) + { + unsigned int ret = preferred_plane; + + // 1st checks if the given vector is not parallel to the given preferred plane + double dot_to_normal = 0.0; + switch (ret) + { + case 0: // plane xy + { + dot_to_normal = std::abs(unit_vector.dot(Vec3d::UnitZ())); + break; + } + case 1: // plane xz + { + dot_to_normal = std::abs(unit_vector.dot(-Vec3d::UnitY())); + break; + } + case 2: // plane yz + { + dot_to_normal = std::abs(unit_vector.dot(Vec3d::UnitX())); + break; + } + default: + { + break; + } + } + + // if almost parallel, select the plane whose normal direction is closest to the given vector direction, + // otherwise return the given preferred plane index + if (dot_to_normal < 0.1) + { + typedef std::map ProjsMap; + ProjsMap projs_map; + projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(Vec3d::UnitZ())), 0)); // plane xy + projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(-Vec3d::UnitY())), 1)); // plane xz + projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(Vec3d::UnitX())), 2)); // plane yz + ret = projs_map.rbegin()->second; + } + + return ret; + } + + const float GLGizmoBase::Grabber::HalfSize = 2.0f; const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; GLGizmoBase::Grabber::Grabber() @@ -881,77 +964,24 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& Vec3d starting_vec_dir = starting_vec.normalized(); Vec3d mouse_dir = mouse_ray.unit_vector(); - unsigned int plane_id = preferred_plane_id; - // 1st try to see if the mouse direction is close enough to the preferred plane normal - double dot_to_normal = 0.0; + unsigned int plane_id = select_best_plane(mouse_dir, preferred_plane_id); + // ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length switch (plane_id) { case 0: { - dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitZ())); + ratio = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, center)) / len_starting_vec; break; } case 1: { - dot_to_normal = std::abs(mouse_dir.dot(-Vec3d::UnitY())); + ratio = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, center)) / len_starting_vec; break; } case 2: { - dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitX())); - break; - } - } - - if (dot_to_normal < 0.1) - { - // if not, select the plane who's normal is closest to the mouse direction - - typedef std::map ProjsMap; - ProjsMap projs_map; - - projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitZ())), 0)); // plane xy - projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(-Vec3d::UnitY())), 1)); // plane xz - projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitX())), 2)); // plane yz - plane_id = projs_map.rbegin()->second; - } - - switch (plane_id) - { - case 0: - { - // calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the given center - Transform3d m = Transform3d::Identity(); - m.translate(-center); - Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0)); - - // ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length - ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0)) / len_starting_vec; - break; - } - case 1: - { - // calculates the intersection of the mouse ray with the plane parallel to plane XZ and passing through the given center - Transform3d m = Transform3d::Identity(); - m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX())); - m.translate(-center); - Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0)); - - // ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length - ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1))) / len_starting_vec; - break; - } - case 2: - { - // calculates the intersection of the mouse ray with the plane parallel to plane YZ and passing through the given center - Transform3d m = Transform3d::Identity(); - m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY())); - m.translate(-center); - Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0)); - - // ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length - ratio = starting_vec_dir.dot(Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0))) / len_starting_vec; + ratio = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, center)) / len_starting_vec; break; } } @@ -963,7 +993,7 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent) : GLGizmoBase(parent) , m_normal(Vec3d::Zero()) - , m_center(Vec3d::Zero()) + , m_starting_center(Vec3d::Zero()) { } @@ -991,7 +1021,7 @@ void GLGizmoFlatten::on_start_dragging(const BoundingBoxf3& box) if (m_hover_id != -1) { m_normal = m_planes[m_hover_id].normal; - m_center = box.center(); + m_starting_center = box.center(); } } @@ -1002,7 +1032,7 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const // does not work correctly when there are multiple copies. Vec3d dragged_offset(Vec3d::Zero()); if (m_dragging) - dragged_offset = box.center() - m_center; + dragged_offset = box.center() - m_starting_center; ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 82a004b5b..0599955ed 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -286,7 +286,7 @@ private: std::vector m_planes; std::vector m_instances_positions; - Vec3d m_center; + Vec3d m_starting_center; const ModelObject* m_model_object = nullptr; void update_planes();