diff --git a/lib/Slic3r/GUI/Plater/ObjectLayersDialog.pm b/lib/Slic3r/GUI/Plater/ObjectLayersDialog.pm index 295508e3f..502aa2d12 100644 --- a/lib/Slic3r/GUI/Plater/ObjectLayersDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectLayersDialog.pm @@ -6,8 +6,8 @@ use utf8; use Slic3r::Geometry qw(PI X scale unscale); use Slic3r::Print::State ':steps'; use List::Util qw(min max sum first); -use Wx qw(wxTheApp :dialog :id :misc :sizer wxTAB_TRAVERSAL); -use Wx::Event qw(EVT_CLOSE EVT_BUTTON); +use Wx qw(wxTheApp :dialog :id :misc :sizer :slider :statictext wxTAB_TRAVERSAL); +use Wx::Event qw(EVT_CLOSE EVT_BUTTON EVT_SLIDER); use base 'Wx::Dialog'; sub new { @@ -23,9 +23,6 @@ sub new { # Initialize 3D toolpaths preview if ($Slic3r::GUI::have_OpenGL) { $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self, $plater->{print}); - #$self->{preview3D}->canvas->on_viewport_changed(sub { - # $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas); - #}); $self->{preview3D}->canvas->set_auto_bed_shape; $self->{preview3D}->canvas->SetSize([500,500]); $self->{preview3D}->canvas->SetMinSize($self->{preview3D}->canvas->GetSize); @@ -33,14 +30,32 @@ sub new { $self->{preview3D}->canvas->zoom_to_volumes; } - $self->{splineControl} = Slic3r::GUI::Plater::SplineControl->new($self, Wx::Size->new(200, 200), $object); + $self->{splineControl} = Slic3r::GUI::Plater::SplineControl->new($self, Wx::Size->new(150, 200), $object); + +# my $cusp_slider = $self->{cusp_slider} = Wx::Slider->new( +# $self, -1, +# 0, # default +# 0, # min +# # we set max to a bogus non-zero value because the MSW implementation of wxSlider +# # will skip drawing the slider if max <= min: +# 1, # max +# wxDefaultPosition, +# wxDefaultSize, +# wxHORIZONTAL, +# ); + + #my $cusp_label = $self->{cusp_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, + # [150,-1], wxALIGN_CENTRE_HORIZONTAL); + #$cusp_label->SetFont($Slic3r::GUI::small_font); my $right_sizer = Wx::BoxSizer->new(wxVERTICAL); $right_sizer->Add($self->{splineControl}, 1, wxEXPAND | wxALL, 0); + #$right_sizer->Add($cusp_slider, 0, wxEXPAND | wxALL, 0); + #$right_sizer->Add($cusp_label, 0, wxEXPAND | wxALL, 0); $self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL); - $self->{sizer}->Add($self->{preview3D}, 1, wxEXPAND | wxTOP | wxBOTTOM, 0) if $self->{preview3D}; - $self->{sizer}->Add($right_sizer, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); + $self->{sizer}->Add($self->{preview3D}, 3, wxEXPAND | wxTOP | wxBOTTOM, 0) if $self->{preview3D}; + $self->{sizer}->Add($right_sizer, 1, wxEXPAND | wxTOP | wxBOTTOM, 10); $self->SetSizerAndFit($self->{sizer}); $self->SetSize([800, 600]); @@ -63,15 +78,48 @@ sub new { $self->{splineControl}->on_layer_update(sub { # trigger re-slicing + $self->{plater}->stop_background_process; $self->{object}->invalidate_step(STEP_SLICE); $self->{plater}->start_background_process; }); + $self->{splineControl}->on_z_indicator(sub { + my ($z) = @_; + #$self->{preview3D}->canvas->cutting_plane_z($z); + $self->{preview3D}->canvas->SetCuttingPlane($z, []); + $self->{preview3D}->canvas->Render; + }); + + # init cusp slider +# if($object->config->adaptive_slicing) { +# my $cusp_value = $object->config->get('cusp_value'); +# $cusp_label->SetLabel(sprintf 'Cusp value: %.2f mm', $cusp_value); +# $cusp_slider->SetRange(0, $max_height*100); +# $cusp_slider->SetValue($cusp_value*100); +# }else{ +# # disable slider +# $cusp_label->SetLabel("Cusp value: "); +# $cusp_label->Enable(0); +# $cusp_slider->Enable(0); +# } + +# EVT_SLIDER($self, $cusp_slider, sub { +# $self->{plater}->pause_background_process; +# my $cusp_value = $cusp_slider->GetValue/100; +# $cusp_label->SetLabel(sprintf 'Cusp value: %.2f mm', $cusp_value); +# my $success = $object->config->set('cusp_value', $cusp_value); +# # trigger re-slicing +# $self->{plater}->stop_background_process; +# $self->{object}->invalidate_step(STEP_SLICE); +# $self->{plater}->schedule_background_process; +# }); + return $self; } sub reload_preview { my ($self) = @_; + #$self->{splineControl}->update; $self->{preview3D}->reload_print; } diff --git a/lib/Slic3r/GUI/Plater/SplineControl.pm b/lib/Slic3r/GUI/Plater/SplineControl.pm index c824695f7..ba8885361 100644 --- a/lib/Slic3r/GUI/Plater/SplineControl.pm +++ b/lib/Slic3r/GUI/Plater/SplineControl.pm @@ -35,18 +35,8 @@ sub new { $self->{max_layer_height} = 0.4; $self->{object_height} = 1.0; - $self->{original_layers} = $object->layer_height_spline->getOriginalLayers; - $self->{original_interpolated_layers} = $object->layer_height_spline->getInterpolatedLayers; - $self->{interpolated_layers} = $object->layer_height_spline->getInterpolatedLayers; # Initialize to current values - - # initialize height vector - $self->{heights} = (); - $self->{interactive_heights} = (); - my $last_z = 0; - foreach my $z (@{$self->{original_layers}}) { - push (@{$self->{heights}}, $z - $last_z); - $last_z = $z; - } + # initialize values + $self->update; EVT_PAINT($self, \&repaint); EVT_ERASE_BACKGROUND($self, sub {}) if $self->{user_drawn_background}; @@ -185,13 +175,15 @@ sub mouse_event { $self->_interactive_curve($start_pos[1], $obj_pos[0], $range); $self->Refresh; - }# elsif ($event->Moving) { -# my $cursor = wxSTANDARD_CURSOR; -# if (defined first { $_->contour->contains_point($point) } map @$_, map @{$_->instance_thumbnails}, @{ $self->{objects} }) { -# $cursor = Wx::Cursor->new(wxCURSOR_HAND); -# } -# $self->SetCursor($cursor); -# } + } elsif ($event->Moving) { + if($self->{on_z_indicator}) { + $self->{on_z_indicator}->($obj_pos[1]); + } + } elsif ($event->Leaving) { + if($self->{on_z_indicator} && !$self->{drag_start_pos}) { + $self->{on_z_indicator}->(undef); + } + } } # Set basic parameters for this control. @@ -208,12 +200,36 @@ sub set_size_parameters { $self->Refresh; } +# Layers have been modified externally, re-initialize this control with new values +sub update { + my $self = shift; + + $self->{original_layers} = $self->{object}->layer_height_spline->getOriginalLayers; + $self->{original_interpolated_layers} = $self->{object}->layer_height_spline->getInterpolatedLayers; + $self->{interpolated_layers} = $self->{object}->layer_height_spline->getInterpolatedLayers; # Initialize to current values + + # initialize height vector + $self->{heights} = (); + $self->{interactive_heights} = (); + my $last_z = 0; + foreach my $z (@{$self->{original_layers}}) { + push (@{$self->{heights}}, $z - $last_z); + $last_z = $z; + } + $self->Refresh; +} + # Callback to notify parent element if layers have changed and reslicing should be triggered sub on_layer_update { my ($self, $cb) = @_; $self->{on_layer_update} = $cb; } +# Callback to tell parent element at which z-position the mouse currently hovers to update indicator in 3D-view +sub on_z_indicator { + my ($self, $cb) = @_; + $self->{on_z_indicator} = $cb; +} # Internal function to cache scaling factors sub _update_canvas_size {