From 75cbe879b721155e6913f50aa68185f003b46ee5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 22 Dec 2011 17:38:37 +0100 Subject: [PATCH] New "Slice and save as..." command to specify output filename. #53 --- lib/Slic3r/GUI.pm | 14 +++++++++++--- lib/Slic3r/GUI/SkeinPanel.pm | 30 +++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 782403323..2b3b8a640 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -17,15 +17,23 @@ sub OnInit { my $frame = Wx::Frame->new( undef, -1, 'Slic3r', [-1, -1], Wx::wxDefaultSize, wxDEFAULT_FRAME_STYLE ^ (wxRESIZE_BORDER | wxMAXIMIZE_BOX) ); + my $panel = Slic3r::GUI::SkeinPanel->new($frame); + my $box = Wx::BoxSizer->new(wxVERTICAL); + $box->Add($panel, 0); + # menubar my $menubar = Wx::MenuBar->new; $frame->SetMenuBar($menubar); EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(1)}); EVT_MENU($frame, wxID_ABOUT, \&About); - my $panel = Slic3r::GUI::SkeinPanel->new($frame); - my $box = Wx::BoxSizer->new(wxVERTICAL); - $box->Add($panel, 0); + # File menu + my $fileMenu = Wx::Menu->new; + $fileMenu->Append(1, "Slice..."); + $fileMenu->Append(2, "Slice and save as..."); + $menubar->Append($fileMenu, "&File"); + EVT_MENU($frame, 1, sub { $panel->do_slice }); + EVT_MENU($frame, 2, sub { $panel->do_slice(save_as => 1) }); $box->SetSizeHints($frame); $frame->SetSizer($box); diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index e42d14507..cc75e56d5 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -101,15 +101,15 @@ sub new { my $slice_button = Wx::Button->new($self, -1, "Slice..."); $buttons_sizer->Add($slice_button, 0); - EVT_BUTTON($self, $slice_button, \&do_slice); + EVT_BUTTON($self, $slice_button, sub { $self->do_slice }); my $save_button = Wx::Button->new($self, -1, "Save configuration..."); $buttons_sizer->Add($save_button, 0); - EVT_BUTTON($self, $save_button, \&save_config); + EVT_BUTTON($self, $save_button, sub { $self->save_config }); my $load_button = Wx::Button->new($self, -1, "Load configuration..."); $buttons_sizer->Add($load_button, 0); - EVT_BUTTON($self, $load_button, \&load_config); + EVT_BUTTON($self, $load_button, sub { $self->load_config }); my $text = Wx::StaticText->new($self, -1, "Remember to check for updates at http://slic3r.org/\nVersion: $Slic3r::VERSION", Wx::wxDefaultPosition, Wx::wxDefaultSize, wxALIGN_RIGHT); my $font = Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL); @@ -128,8 +128,13 @@ sub new { return $self; } +my $stl_wildcard = "STL files *.stl|*.stl;*.STL"; +my $ini_wildcard = "INI files *.ini|*.ini;*.INI"; +my $gcode_wildcard = "GCODE files *.gcode|*.gcode;*.GCODE"; + sub do_slice { my $self = shift; + my %params = @_; my $process_dialog; eval { @@ -137,12 +142,25 @@ sub do_slice { Slic3r::Config->validate; # select input file - my $dialog = Wx::FileDialog->new($self, 'Choose a STL file to slice:', $last_dir || "", "", "STL files *.stl|*.stl;*.STL", wxFD_OPEN); + my $dialog = Wx::FileDialog->new($self, 'Choose a STL file to slice:', $last_dir || "", "", $stl_wildcard, wxFD_OPEN); return unless $dialog->ShowModal == wxID_OK; my ($input_file) = $dialog->GetPaths; my $input_file_basename = basename($input_file); $last_dir = dirname($input_file); + # select output file + my $output_file = $main::opt{output}; + if ($params{save_as}) { + if (!$output_file) { + $output_file = $input_file_basename; + $output_file =~ s/\.stl$/.gcode/i; + } + my $dlg = Wx::FileDialog->new($self, 'Save gcode file as:', dirname($output_file), + basename($output_file), $gcode_wildcard, wxFD_SAVE); + return if $dlg->ShowModal != wxID_OK; + $output_file = $dlg->GetPath; + } + # show processbar dialog $process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...", 100, $self, wxPD_APP_MODAL); @@ -150,7 +168,7 @@ sub do_slice { my $skein = Slic3r::Skein->new( input_file => $input_file, - output_file => $main::opt{output}, + output_file => $output_file, status_cb => sub { my ($percent, $message) = @_; if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) { @@ -180,8 +198,6 @@ sub do_slice { $self->catch_error(sub { $process_dialog->Destroy if $process_dialog }); } -my $ini_wildcard = "INI files *.ini|*.ini;*.INI"; - sub save_config { my $self = shift;