diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2011-10-03 13:55:32 +0400 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2011-10-03 13:55:32 +0400 |
commit | f2f9178e0708142722104884ad9d7fdf8440b131 (patch) | |
tree | 6a6aab71270579ccb1b87843ac61e928089aa715 /lib/Slic3r/GUI | |
parent | a311220c19d16ae402531651c73af993871b556c (diff) |
GUI
Diffstat (limited to 'lib/Slic3r/GUI')
-rw-r--r-- | lib/Slic3r/GUI/OptionsGroup.pm | 50 | ||||
-rw-r--r-- | lib/Slic3r/GUI/SkeinPanel.pm | 255 |
2 files changed, 305 insertions, 0 deletions
diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm new file mode 100644 index 000000000..aeb258182 --- /dev/null +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -0,0 +1,50 @@ +package Slic3r::GUI::OptionsGroup; +use strict; +use warnings; + +use Wx qw(:sizer); +use Wx::Event qw(EVT_TEXT EVT_CHECKBOX); +use base 'Wx::StaticBoxSizer'; + +sub new { + my $class = shift; + my ($parent, %p) = @_; + + my $box = Wx::StaticBox->new($parent, -1, $p{title}); + my $self = $class->SUPER::new($box, wxVERTICAL); + + my $grid_sizer = Wx::FlexGridSizer->new(scalar(@{$p{options}}), 2, 2, 0); + + foreach my $opt (@{$p{options}}) { + my $label = Wx::StaticText->new($parent, -1, "$opt->{label}:", Wx::wxDefaultPosition, [180,-1]); + my $field; + if ($opt->{type} =~ /^(i|f)$/) { + $field = Wx::TextCtrl->new($parent, -1, ${$opt->{value}}); + EVT_TEXT($parent, $field, sub { ${$opt->{value}} = $field->GetValue }); + } elsif ($opt->{type} eq 'bool') { + $field = Wx::CheckBox->new($parent, -1, ""); + $field->SetValue(${$opt->{value}}); + EVT_TEXT($parent, $field, sub { ${$opt->{value}} = $field->GetValue }); + } elsif ($opt->{type} eq 'point') { + $field = Wx::BoxSizer->new(wxHORIZONTAL); + my $field_size = Wx::Size->new(40, -1); + $field->Add($_) for ( + Wx::StaticText->new($parent, -1, "x:"), + my $x_field = Wx::TextCtrl->new($parent, -1, ${$opt->{value}}->[0], Wx::wxDefaultPosition, $field_size), + Wx::StaticText->new($parent, -1, " y:"), + my $y_field = Wx::TextCtrl->new($parent, -1, ${$opt->{value}}->[1], Wx::wxDefaultPosition, $field_size), + ); + EVT_TEXT($parent, $x_field, sub { ${$opt->{value}}->[0] = $x_field->GetValue }); + EVT_TEXT($parent, $y_field, sub { ${$opt->{value}}->[1] = $y_field->GetValue }); + } else { + die "Unsupported option type: " . $opt->{type}; + } + $grid_sizer->Add($_) for $label, $field; + } + + $self->Add($grid_sizer, 0, wxEXPAND); + + return $self; +} + +1; diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm new file mode 100644 index 000000000..ebb6f08d0 --- /dev/null +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -0,0 +1,255 @@ +package Slic3r::GUI::SkeinPanel; +use strict; +use warnings; + +use File::Basename qw(basename); +use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_ERROR wxID_OK wxFD_OPEN); +use Wx::Event qw(EVT_BUTTON); +use base 'Wx::Panel'; + +sub new { + my $class = shift; + my ($parent) = @_; + my $self = $class->SUPER::new($parent, -1); + + my %panels = ( + printer => Slic3r::GUI::OptionsGroup->new($self, + title => 'Printer', + options => [ + { + label => 'Nozzle diameter', + value => \$Slic3r::nozzle_diameter, + type => 'f', + }, + { + label => 'Print center', + value => \$Slic3r::print_center, + type => 'point', + }, + { + label => 'Use relative E distances', + value => \$Slic3r::use_relative_e_distances, + type => 'bool', + }, + { + label => 'Z offset', + value => \$Slic3r::z_offset, + type => 'f', + }, + ], + ), + + filament => Slic3r::GUI::OptionsGroup->new($self, + title => 'Filament', + options => [ + { + label => 'Diameter (mm)', + value => \$Slic3r::filament_diameter, + type => 'f', + }, + { + label => 'Packing density (mm)', + value => \$Slic3r::filament_packing_density, + type => 'f', + }, + ], + ), + + speed => Slic3r::GUI::OptionsGroup->new($self, + title => 'Speed', + options => [ + { + label => 'Print feed rate (mm/s)', + value => \$Slic3r::print_feed_rate, + type => 'f', + }, + { + label => 'Travel feed rate (mm/s)', + value => \$Slic3r::travel_feed_rate, + type => 'f', + }, + { + label => 'Perimeter feed rate (mm/s)', + value => \$Slic3r::perimeter_feed_rate, + type => 'f', + }, + { + label => 'Bottom layer ratio', + value => \$Slic3r::bottom_layer_speed_ratio, + type => 'f', + }, + ], + ), + + accuracy => Slic3r::GUI::OptionsGroup->new($self, + title => 'Accuracy', + options => [ + { + label => 'Layer height (mm)', + value => \$Slic3r::layer_height, + type => 'f', + }, + ], + ), + + print => Slic3r::GUI::OptionsGroup->new($self, + title => 'Print settings', + options => [ + { + label => 'Perimeters', + value => \$Slic3r::perimeter_offsets, + type => 'i', + }, + { + label => 'Solid layers', + value => \$Slic3r::solid_layers, + type => 'i', + }, + { + label => 'Fill density', + value => \$Slic3r::fill_density, + type => 'f', + }, + { + label => 'Fill angle (°)', + value => \$Slic3r::fill_angle, + type => 'i', + }, + { + label => 'Temperature (°C)', + value => \$Slic3r::temperature, + type => 'i', + }, + ], + ), + + retract => Slic3r::GUI::OptionsGroup->new($self, + title => 'Retraction', + options => [ + { + label => 'Length (mm)', + value => \$Slic3r::retract_length, + type => 'f', + }, + { + label => 'Speed (mm/s)', + value => \$Slic3r::retract_speed, + type => 'i', + }, + { + label => 'Extra length on restart (mm)', + value => \$Slic3r::retract_restart_extra, + type => 'f', + }, + { + label => 'Minimum travel after retraction (mm)', + value => \$Slic3r::retract_before_travel, + type => 'f', + }, + ], + ), + + skirt => Slic3r::GUI::OptionsGroup->new($self, + title => 'Skirt', + options => [ + { + label => 'Loops', + value => \$Slic3r::skirts, + type => 'i', + }, + { + label => 'Distance from object (mm)', + value => \$Slic3r::skirt_distance, + type => 'i', + }, + ], + ), + + transform => Slic3r::GUI::OptionsGroup->new($self, + title => 'Transform', + options => [ + { + label => 'Scale', + value => \$Slic3r::scale, + type => 'f', + }, + { + label => 'Rotate (°)', + value => \$Slic3r::rotate, + type => 'i', + }, + { + label => 'Multiply along X', + value => \$Slic3r::multiply_x, + type => 'i', + }, + { + label => 'Multiply along Y', + value => \$Slic3r::multiply_y, + type => 'i', + }, + { + label => 'Multiply distance', + value => \$Slic3r::multiply_distance, + type => 'i', + }, + ], + ), + ); + + $panels{slice} = Wx::BoxSizer->new(wxVERTICAL); + $panels{slice}->Add(-1, 20); # empty space before button + my $slice_button = Wx::Button->new($self, -1, "Slice..."); + $panels{slice}->Add($slice_button, 0, wxALIGN_CENTER); + EVT_BUTTON($self, $slice_button, \&do_slice); + + my @cols = ( + [qw(printer filament speed transform)], [qw(accuracy print retract skirt slice)], + ); + + my $sizer = Wx::BoxSizer->new(wxHORIZONTAL); + foreach my $col (@cols) { + my $vertical_sizer = Wx::BoxSizer->new(wxVERTICAL); + $vertical_sizer->Add($panels{$_}, 0, wxEXPAND | wxRIGHT, 10) for @$col; + $sizer->Add($vertical_sizer); + } + + $sizer->SetSizeHints($self); + $self->SetSizer($sizer); + + return $self; +} + +sub do_slice { + my $self = shift; + + eval { + # validate configuration + Slic3r::Config->validate; + + # select input file + my $dialog = Wx::FileDialog->new($self, 'Choose a STL file to slice:', "", "", "*.stl", wxFD_OPEN); + return unless $dialog->ShowModal == wxID_OK; + my ($input_file) = $dialog->GetPaths; + my $input_file_basename = basename($input_file); + + # show processbar dialog + my $process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...", + 100, $self, wxPD_APP_MODAL); + $process_dialog->Pulse; + my $skein = Slic3r::Skein->new( + input_file => $input_file, + ); + $skein->go; + $process_dialog->Destroy; + + Wx::MessageDialog->new($self, "$input_file_basename was successfully sliced.", 'Done!', + wxOK | wxICON_INFORMATION)->ShowModal; + }; + + if (my $err = $@) { + Wx::MessageDialog->new($self, $err, 'Error', wxOK | wxICON_ERROR)->ShowModal; + } +} + +1; |