diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 00267fe63..016c2e800 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); @@ -1141,13 +1169,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; } } @@ -1182,11 +1209,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); @@ -2106,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}); } } @@ -2336,12 +2360,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/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) = @_; diff --git a/resources/icons/toolbar.png b/resources/icons/toolbar.png index ce954143d..79246bcf9 100644 Binary files a/resources/icons/toolbar.png and b/resources/icons/toolbar.png differ diff --git a/resources/profiles/PrusaResearch.idx b/resources/profiles/PrusaResearch.idx index ba4123588..63a81db49 100644 --- a/resources/profiles/PrusaResearch.idx +++ b/resources/profiles/PrusaResearch.idx @@ -1,8 +1,14 @@ 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 +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..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.0-beta +config_version = 0.2.2 # 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 @@ -1207,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] @@ -1215,9 +1277,10 @@ 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 +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. 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/stlinit.cpp b/xs/src/admesh/stlinit.cpp index 47a37f0a5..e2939b8af 100644 --- a/xs/src/admesh/stlinit.cpp +++ b/xs/src/admesh/stlinit.cpp @@ -286,7 +286,7 @@ void stl_read(stl_file *stl, int first_facet, bool 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]); 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/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/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index fa18ddf3f..74a376ade 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, diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 1cd3b1413..19c474cad 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) @@ -670,22 +669,19 @@ 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.; - 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; - + // 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; + 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 +857,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 +986,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(true, 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 +1013,12 @@ 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)); + return bbox.transformed(world_matrix(dont_translate)); +} - matrix.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); - matrix.scale(scaling_factor); - return bbox.transformed(matrix); +Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const +{ + return world_matrix(dont_translate) * v; } void ModelInstance::transform_polygon(Polygon* polygon) const @@ -1046,4 +1027,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..8a8af481c 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 @@ -240,9 +239,13 @@ 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; + 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/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/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 58208d116..925e93031 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; 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) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 08a1b1457..57639fed0 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; @@ -303,14 +303,24 @@ void GLVolume::set_convex_hull(const TriangleMesh& convex_hull) m_convex_hull = &convex_hull; } +void GLVolume::set_select_group_id(const std::string& select_by) +{ + if (select_by == "object") + select_group_id = object_idx() * 1000000; + else if (select_by == "volume") + select_group_id = object_idx() * 1000000 + volume_idx() * 1000; + else if (select_by == "instance") + select_group_id = composite_id; +} + 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 +394,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 +520,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 +565,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); @@ -655,12 +665,7 @@ std::vector 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") @@ -675,9 +680,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 +751,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(); @@ -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. @@ -1190,7 +1204,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]); @@ -1198,10 +1212,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]); } @@ -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 69f1e1d35..ec9d1a501 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,13 +327,18 @@ 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); + 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; } @@ -443,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; @@ -496,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); @@ -559,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/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 4043a4457..f143e8bc6 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -228,24 +228,20 @@ 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; -#else - on_change_field(); + if (bChangedValueEvent) #endif //__WXGTK__ + on_change_field(); }), temp->GetId()); #ifdef __WXGTK__ - temp->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event) - { - if (bChangedValueEvent) { - on_change_field(); - bChangedValueEvent = false; - } - event.Skip(); - }); + // 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); #endif //__WXGTK__ // select all text using Ctrl+A @@ -271,6 +267,15 @@ 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 = event.GetEventType()==wxEVT_KEY_UP) + on_change_field(); + 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 e305f1e53..c38658e2b 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -235,7 +235,8 @@ 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: TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index bbc73b896..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() @@ -2018,6 +2008,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 +2137,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 +2145,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 +2431,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)) @@ -2467,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 ? @@ -2757,6 +2765,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) @@ -2952,7 +2966,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)) { @@ -2993,15 +3007,15 @@ 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) { // 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)); } } @@ -3036,14 +3050,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } update_gizmos_data(); - m_gizmos.refresh(); m_dirty = true; } } // 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) { @@ -3126,10 +3139,12 @@ 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)); + } + update_position_values(volume->get_offset()); m_mouse.drag.start_position_3D = cur_pos; - m_gizmos.refresh(); m_dirty = true; } @@ -3166,7 +3181,8 @@ 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); + update_scale_values((double)scale_factor); } break; } @@ -3176,7 +3192,8 @@ 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); + update_rotation_value((double)angle_z, Z); } break; } @@ -3193,13 +3210,8 @@ 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"); } - 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) @@ -3284,7 +3296,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(); } } @@ -3295,7 +3307,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: @@ -3307,6 +3318,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) break; } m_gizmos.stop_dragging(); + Slic3r::GUI::update_settings_value(); } m_mouse.drag.move_volume_idx = -1; @@ -3509,6 +3521,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; @@ -3748,6 +3771,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 @@ -5219,7 +5243,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,34 +5262,56 @@ 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)); - model_object->invalidate_bounding_box(); - 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. - 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)); } -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..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; @@ -514,6 +513,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 +556,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 +599,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 +635,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 +738,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/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index be085e913..1d02e1752 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -15,14 +15,95 @@ 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 { -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() @@ -131,6 +212,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)); @@ -152,18 +234,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) @@ -199,8 +284,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(); } } @@ -234,7 +322,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) { } @@ -252,6 +339,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)); @@ -293,18 +386,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(); @@ -335,12 +426,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(); @@ -512,23 +599,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(RED); - m_y.set_highlight_color(GREEN); - m_z.set_highlight_color(BLUE); + for (unsigned int i = 0; i < 3; ++i) + { + m_gizmos[i].set_highlight_color(AXES_COLOR[i]); + } std::string path = resources_dir() + "/icons/overlay/"; @@ -547,68 +640,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; @@ -655,13 +708,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; } } @@ -703,20 +756,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)); @@ -735,6 +788,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(); } @@ -815,13 +875,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(); } @@ -911,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; } } @@ -992,7 +992,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_starting_center(Vec3d::Zero()) { } @@ -1015,10 +1016,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_starting_center = box.center(); + } } void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const @@ -1026,13 +1030,10 @@ 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(Vec3d::Zero()); + if (m_dragging) + dragged_offset = box.center() - m_starting_center; - 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); @@ -1054,20 +1055,15 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const } } - if (!blending_was_enabled) - ::glDisable(GL_BLEND); - if (!depth_test_was_enabled) - ::glDisable(GL_DEPTH_TEST); + ::glDisable(GL_BLEND); } 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) { - // 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(); @@ -1083,7 +1079,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: @@ -1245,9 +1240,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(); @@ -1285,11 +1280,9 @@ 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(true).matrix().block(0, 0, 3, 3).inverse() * m_normal; m_normal = Vec3d::Zero(); - return normal; + return normal.normalized(); } } // namespace GUI diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 3041f2adf..0599955ed 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_starting_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(); } diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 94555f50e..af57db8ed 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(); @@ -1534,50 +1541,94 @@ 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); -} - -void update_scale_values(const Vec3d& size, float 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 = 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)); } 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)); + 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_position_values(const Vec3d& position) +{ + auto og = get_optgroup(ogFrequentlyObjectSettings); + + 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); + + // 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() { 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) +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 82bfe4a6c..8a1499e03 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp @@ -107,13 +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/src/slic3r/Utils/Duet.cpp b/xs/src/slic3r/Utils/Duet.cpp index 865d2b418..f25327161 100644 --- a/xs/src/slic3r/Utils/Duet.cpp +++ b/xs/src/slic3r/Utils/Duet.cpp @@ -197,7 +197,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(); } @@ -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); } @@ -248,9 +248,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 +276,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..9b67ceea8 100644 --- a/xs/src/slic3r/Utils/Http.cpp +++ b/xs/src/slic3r/Utils/Http.cpp @@ -421,6 +421,21 @@ bool Http::ca_file_supported() return res; } +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); + ::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); 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); %}; diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index c15fdc196..756f9e547 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; %}; @@ -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;