mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Move toolpaths preview to the plater dialog
This commit is contained in:
		
							parent
							
								
									98cb9f0e18
								
							
						
					
					
						commit
						e8f242ee3f
					
				
					 5 changed files with 83 additions and 55 deletions
				
			
		|  | @ -102,10 +102,13 @@ sub new { | |||
|         } | ||||
|     }); | ||||
|      | ||||
|     # Initialize 3D preview canvas | ||||
|     # Initialize 3D preview and toolpaths preview | ||||
|     if ($Slic3r::GUI::have_OpenGL) { | ||||
|         $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config}); | ||||
|         $self->{preview_notebook}->AddPage($self->{canvas3D}, '3D'); | ||||
|          | ||||
|         $self->{toolpaths2D} = Slic3r::GUI::Plater::2DToolpaths->new($self->{preview_notebook}, $self->{print}); | ||||
|         $self->{preview_notebook}->AddPage($self->{toolpaths2D}, 'Preview'); | ||||
|     } | ||||
|      | ||||
|     # toolbar for object manipulation | ||||
|  | @ -169,11 +172,8 @@ sub new { | |||
|     # right pane buttons | ||||
|     $self->{btn_export_gcode} = Wx::Button->new($self, -1, "Export G-code…", wxDefaultPosition, [-1, 30], wxBU_LEFT); | ||||
|     $self->{btn_export_stl} = Wx::Button->new($self, -1, "Export STL…", wxDefaultPosition, [-1, 30], wxBU_LEFT); | ||||
|     $self->{btn_toolpaths_preview} = Wx::Button->new($self, -1, "Toolpaths preview…", wxDefaultPosition, [-1, 30], wxBU_LEFT); | ||||
|     $self->{btn_export_gcode}->SetFont($Slic3r::GUI::small_font); | ||||
|     $self->{btn_export_stl}->SetFont($Slic3r::GUI::small_font); | ||||
|     $self->{btn_toolpaths_preview}->SetFont($Slic3r::GUI::small_font); | ||||
|     $self->{btn_toolpaths_preview}->Disable; | ||||
|      | ||||
|     if ($Slic3r::GUI::have_button_icons) { | ||||
|         my %icons = qw( | ||||
|  | @ -183,7 +183,6 @@ sub new { | |||
|             arrange         bricks.png | ||||
|             export_gcode    cog_go.png | ||||
|             export_stl      brick_go.png | ||||
|             toolpaths_preview joystick.png | ||||
|              | ||||
|             increase        add.png | ||||
|             decrease        delete.png | ||||
|  | @ -205,7 +204,6 @@ sub new { | |||
|         Slic3r::thread_cleanup(); | ||||
|     }); | ||||
|     EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl); | ||||
|     EVT_BUTTON($self, $self->{btn_toolpaths_preview}, \&toolpaths_preview); | ||||
|      | ||||
|     if ($self->{htoolbar}) { | ||||
|         EVT_TOOL($self, TB_ADD, sub { $self->add; }); | ||||
|  | @ -346,7 +344,6 @@ sub new { | |||
|         my $right_buttons_sizer = Wx::BoxSizer->new(wxVERTICAL); | ||||
|         $right_buttons_sizer->Add($presets, 0, wxEXPAND, 0) if defined $presets; | ||||
|         $right_buttons_sizer->Add($self->{btn_export_gcode}, 0, wxEXPAND | wxTOP, 8); | ||||
|         $right_buttons_sizer->Add($self->{btn_toolpaths_preview}, 0, wxEXPAND | wxTOP, 2); | ||||
|         $right_buttons_sizer->Add($self->{btn_export_stl}, 0, wxEXPAND | wxTOP, 2); | ||||
|          | ||||
|         my $right_top_sizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||||
|  | @ -809,7 +806,7 @@ sub schedule_background_process { | |||
|      | ||||
|     if (defined $self->{apply_config_timer}) { | ||||
|         $self->{apply_config_timer}->Start(PROCESS_DELAY, 1);  # 1 = one shot | ||||
|         $self->{btn_toolpaths_preview}->Disable; | ||||
|         $self->{toolpaths2D}->reload_print; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -885,7 +882,7 @@ sub stop_background_process { | |||
|     $self->statusbar->SetCancelCallback(undef); | ||||
|     $self->statusbar->StopBusy; | ||||
|     $self->statusbar->SetStatusText(""); | ||||
|     $self->{btn_toolpaths_preview}->Disable; | ||||
|     $self->{toolpaths2D}->reload_print; | ||||
|      | ||||
|     if ($self->{process_thread}) { | ||||
|         Slic3r::debugf "Killing background process.\n"; | ||||
|  | @ -1004,7 +1001,7 @@ sub on_process_completed { | |||
|     $self->{process_thread} = undef; | ||||
|      | ||||
|     return if !$result; | ||||
|     $self->{btn_toolpaths_preview}->Enable; | ||||
|     $self->{toolpaths2D}->reload_print; | ||||
|      | ||||
|     # if we have an export filename, start a new thread for exporting G-code | ||||
|     if ($self->{export_gcode_output_file}) { | ||||
|  | @ -1281,19 +1278,6 @@ sub object_settings_dialog { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| sub toolpaths_preview { | ||||
|     my ($self) = @_; | ||||
|      | ||||
|     # TODO: we should check whether steps are done in $print rather then checking the thread | ||||
|     if ($self->{process_thread}) { | ||||
|         Slic3r::GUI::show_error($self, "Unable to show preview while toolpaths are being generated."); | ||||
|         return; | ||||
|     } | ||||
|      | ||||
|     my $dlg = Slic3r::GUI::Plater::2DToolpaths::Dialog->new($self, $self->{print}); | ||||
| 	$dlg->ShowModal; | ||||
| } | ||||
| 
 | ||||
| sub object_list_changed { | ||||
|     my $self = shift; | ||||
|      | ||||
|  |  | |||
|  | @ -3,11 +3,12 @@ use strict; | |||
| use warnings; | ||||
| use utf8; | ||||
| 
 | ||||
| use List::Util qw(); | ||||
| use Slic3r::Geometry qw(); | ||||
| use Slic3r::Print::State ':steps'; | ||||
| use Wx qw(:misc :sizer :slider :statictext); | ||||
| use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN); | ||||
| use base 'Wx::Panel'; | ||||
| use base qw(Wx::Panel Class::Accessor); | ||||
| 
 | ||||
| __PACKAGE__->mk_accessors(qw(print enabled)); | ||||
| 
 | ||||
| sub new { | ||||
|     my $class = shift; | ||||
|  | @ -15,17 +16,13 @@ sub new { | |||
|      | ||||
|     my $self = $class->SUPER::new($parent, -1, wxDefaultPosition); | ||||
|      | ||||
|     # init print | ||||
|     $self->{print} = $print; | ||||
|     $self->reload_print; | ||||
|      | ||||
|     # init GUI elements | ||||
|     my $canvas = $self->{canvas} = Slic3r::GUI::Plater::2DToolpaths::Canvas->new($self, $print); | ||||
|     my $slider = $self->{slider} = Wx::Slider->new( | ||||
|         $self, -1, | ||||
|         0,                              # default | ||||
|         0,                              # min | ||||
|         scalar(@{$self->{layers_z}})-1,    # max | ||||
|         0,                              # max | ||||
|         wxDefaultPosition, | ||||
|         wxDefaultSize, | ||||
|         wxVERTICAL | wxSL_INVERSE, | ||||
|  | @ -43,7 +40,8 @@ sub new { | |||
|     $sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5); | ||||
|      | ||||
|     EVT_SLIDER($self, $slider, sub { | ||||
|         $self->set_z($self->{layers_z}[$slider->GetValue]); | ||||
|         $self->set_z($self->{layers_z}[$slider->GetValue]) | ||||
|             if $self->enabled; | ||||
|     }); | ||||
|     EVT_KEY_DOWN($canvas, sub { | ||||
|         my ($s, $event) = @_; | ||||
|  | @ -62,7 +60,9 @@ sub new { | |||
|     $self->SetMinSize($self->GetSize); | ||||
|     $sizer->SetSizeHints($self); | ||||
|      | ||||
|     $self->set_z($self->{layers_z}[0]); | ||||
|     # init print | ||||
|     $self->{print} = $print; | ||||
|     $self->reload_print; | ||||
|      | ||||
|     return $self; | ||||
| } | ||||
|  | @ -70,6 +70,18 @@ sub new { | |||
| sub reload_print { | ||||
|     my ($self) = @_; | ||||
|      | ||||
|     # we require that there's at least one object and the posSlice step | ||||
|     # is performed on all of them (this ensures that _shifted_copies was | ||||
|     # populated and we know the number of layers) | ||||
|     if (!$self->print->object_step_done(STEP_SLICE)) { | ||||
|         $self->enabled(0); | ||||
|         $self->{slider}->Hide; | ||||
|         $self->{canvas}->Refresh;  # clears canvas | ||||
|         return; | ||||
|     } | ||||
|      | ||||
|     $self->{canvas}->bb($self->print->total_bounding_box); | ||||
|      | ||||
|     my %z = ();  # z => 1 | ||||
|     foreach my $object (@{$self->{print}->objects}) { | ||||
|         foreach my $layer (@{$object->layers}, @{$object->support_layers}) { | ||||
|  | @ -77,11 +89,16 @@ sub reload_print { | |||
|         } | ||||
|     } | ||||
|     $self->{layers_z} = [ sort { $a <=> $b } keys %z ]; | ||||
|     ###$self->{slider}->SetMax(scalar(@{$self->{layers_z}})-1); | ||||
|     $self->enabled(1); | ||||
|     $self->set_z($self->{layers_z}[0]) if @{$self->{layers_z}}; | ||||
|     $self->{slider}->Show; | ||||
| } | ||||
| 
 | ||||
| sub set_z { | ||||
|     my ($self, $z) = @_; | ||||
|      | ||||
|     return if !$self->enabled; | ||||
|     $self->{z_label}->SetLabel(sprintf '%.2f', $z); | ||||
|     $self->{canvas}->set_z($z); | ||||
| } | ||||
|  | @ -89,14 +106,15 @@ sub set_z { | |||
| 
 | ||||
| package Slic3r::GUI::Plater::2DToolpaths::Canvas; | ||||
| 
 | ||||
| use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_MOUSEWHEEL EVT_MOUSE_EVENTS); | ||||
| use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_MOUSEWHEEL EVT_MOUSE_EVENTS); | ||||
| use OpenGL qw(:glconstants :glfunctions :glufunctions); | ||||
| use base qw(Wx::GLCanvas Class::Accessor); | ||||
| use Wx::GLCanvas qw(:all); | ||||
| use List::Util qw(min first); | ||||
| use Slic3r::Geometry qw(scale unscale epsilon); | ||||
| use Slic3r::Print::State ':steps'; | ||||
| 
 | ||||
| __PACKAGE__->mk_accessors(qw(print z layers color init dirty bb)); | ||||
| __PACKAGE__->mk_accessors(qw(print z layers color init bb)); | ||||
| 
 | ||||
| # make OpenGL::Array thread-safe | ||||
| { | ||||
|  | @ -109,15 +127,12 @@ sub new { | |||
|      | ||||
|     my $self = $class->SUPER::new($parent); | ||||
|     $self->print($print); | ||||
|     $self->bb($self->print->total_bounding_box); | ||||
|      | ||||
|     EVT_PAINT($self, sub { | ||||
|         my $dc = Wx::PaintDC->new($self); | ||||
|         $self->Render($dc); | ||||
|     }); | ||||
|     EVT_SIZE($self, sub { $self->dirty(1) }); | ||||
|     EVT_IDLE($self, sub { | ||||
|         return unless $self->dirty; | ||||
|     EVT_SIZE($self, sub { | ||||
|         return if !$self->IsShownOnScreen; | ||||
|         $self->Resize( $self->GetSizeWH ); | ||||
|         $self->Refresh; | ||||
|  | @ -152,7 +167,7 @@ sub set_z { | |||
|      | ||||
|     $self->z($z); | ||||
|     $self->layers([ @layers ]); | ||||
|     $self->dirty(1); | ||||
|     $self->Refresh; | ||||
| } | ||||
| 
 | ||||
| sub Render { | ||||
|  | @ -164,6 +179,15 @@ sub Render { | |||
|     $self->SetCurrent($context); | ||||
|     $self->InitGL; | ||||
|      | ||||
|     glClearColor(1, 1, 1, 0); | ||||
|     glClear(GL_COLOR_BUFFER_BIT); | ||||
|      | ||||
|     if (!$self->GetParent->enabled || !$self->layers) { | ||||
|         glFlush(); | ||||
|         $self->SwapBuffers; | ||||
|         return; | ||||
|     } | ||||
|      | ||||
|     glMatrixMode(GL_PROJECTION); | ||||
|     glLoadIdentity(); | ||||
|     my $bb = $self->bb; | ||||
|  | @ -184,9 +208,6 @@ sub Render { | |||
|     glMatrixMode(GL_MODELVIEW); | ||||
|     glLoadIdentity(); | ||||
|      | ||||
|     glClearColor(1, 1, 1, 0); | ||||
|     glClear(GL_COLOR_BUFFER_BIT); | ||||
|      | ||||
|     my $skirt_drawn = 0; | ||||
|     my $brim_drawn = 0; | ||||
|     foreach my $layer (@{$self->layers}) { | ||||
|  | @ -194,29 +215,37 @@ sub Render { | |||
|         my $print_z = $layer->print_z; | ||||
|          | ||||
|         # draw brim | ||||
|         if ($layer->id == 0 && !$brim_drawn) { | ||||
|         if ($self->print->step_done(STEP_BRIM) && $layer->id == 0 && !$brim_drawn) { | ||||
|             $self->color([0, 0, 0]); | ||||
|             $self->_draw(undef, $print_z, $_) for @{$self->print->brim}; | ||||
|             $brim_drawn = 1; | ||||
|         } | ||||
|         if (($self->print->config->skirt_height == -1 || $self->print->config->skirt_height >= $layer->id) && !$skirt_drawn) { | ||||
|         if ($self->print->step_done(STEP_SKIRT) | ||||
|             && ($self->print->config->skirt_height == -1 || $self->print->config->skirt_height > $layer->id) | ||||
|             && !$skirt_drawn) { | ||||
|             $self->color([0, 0, 0]); | ||||
|             $self->_draw(undef, $print_z, $_) for @{$self->print->skirt}; | ||||
|             $skirt_drawn = 1; | ||||
|         } | ||||
|          | ||||
|         foreach my $layerm (@{$layer->regions}) { | ||||
|             $self->color([0.7, 0, 0]); | ||||
|             $self->_draw($object, $print_z, $_) for @{$layerm->perimeters}; | ||||
|             if ($object->step_done(STEP_PERIMETERS)) { | ||||
|                 $self->color([0.7, 0, 0]); | ||||
|                 $self->_draw($object, $print_z, $_) for @{$layerm->perimeters}; | ||||
|             } | ||||
|              | ||||
|             $self->color([0, 0, 0.7]); | ||||
|             $self->_draw($object, $print_z, $_) for map @$_, @{$layerm->fills}; | ||||
|             if ($object->step_done(STEP_INFILL)) { | ||||
|                 $self->color([0, 0, 0.7]); | ||||
|                 $self->_draw($object, $print_z, $_) for map @$_, @{$layerm->fills}; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         if ($layer->isa('Slic3r::Layer::Support')) { | ||||
|             $self->color([0, 0, 0]); | ||||
|             $self->_draw($object, $print_z, $_) for @{$layer->support_fills}; | ||||
|             $self->_draw($object, $print_z, $_) for @{$layer->support_interface_fills}; | ||||
|         if ($object->step_done(STEP_SUPPORTMATERIAL)) { | ||||
|             if ($layer->isa('Slic3r::Layer::Support')) { | ||||
|                 $self->color([0, 0, 0]); | ||||
|                 $self->_draw($object, $print_z, $_) for @{$layer->support_fills}; | ||||
|                 $self->_draw($object, $print_z, $_) for @{$layer->support_interface_fills}; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|      | ||||
|  | @ -299,8 +328,7 @@ sub Resize { | |||
|     my ($self, $x, $y) = @_; | ||||
|   | ||||
|     return unless $self->GetContext; | ||||
|     $self->dirty(0); | ||||
|   | ||||
|      | ||||
|     $self->SetCurrent($self->GetContext); | ||||
|     glViewport(0, 0, $x, $y); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci