2011-10-03 09:55:32 +00:00
|
|
|
package Slic3r::GUI;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-03-11 18:59:09 +00:00
|
|
|
use utf8;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-04-07 18:45:02 +00:00
|
|
|
use FindBin;
|
2012-07-13 21:46:39 +00:00
|
|
|
use Slic3r::GUI::AboutDialog;
|
2012-06-26 15:42:29 +00:00
|
|
|
use Slic3r::GUI::ConfigWizard;
|
2012-05-04 08:15:33 +00:00
|
|
|
use Slic3r::GUI::Plater;
|
2011-10-03 09:55:32 +00:00
|
|
|
use Slic3r::GUI::OptionsGroup;
|
|
|
|
use Slic3r::GUI::SkeinPanel;
|
2012-06-17 20:27:05 +00:00
|
|
|
use Slic3r::GUI::Tab;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-07-02 23:20:30 +00:00
|
|
|
use Wx 0.9901 qw(:bitmap :dialog :frame :icon :id :misc :systemsettings);
|
2012-07-01 17:24:06 +00:00
|
|
|
use Wx::Event qw(EVT_CLOSE EVT_MENU);
|
2011-10-03 09:55:32 +00:00
|
|
|
use base 'Wx::App';
|
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
our $datadir;
|
2012-06-14 11:49:50 +00:00
|
|
|
|
2012-07-01 17:24:06 +00:00
|
|
|
our $small_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2012-06-20 19:43:06 +00:00
|
|
|
$small_font->SetPointSize(11) if !&Wx::wxMSW;
|
2012-07-01 17:24:06 +00:00
|
|
|
our $medium_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2012-06-19 15:23:10 +00:00
|
|
|
$medium_font->SetPointSize(12);
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
sub OnInit {
|
|
|
|
my $self = shift;
|
|
|
|
|
2012-02-23 20:51:45 +00:00
|
|
|
$self->SetAppName('Slic3r');
|
2012-05-04 11:51:09 +00:00
|
|
|
Slic3r::debugf "wxWidgets version %s\n", &Wx::wxVERSION_STRING;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
if (eval "use Growl::GNTP; 1") {
|
|
|
|
# register growl notifications
|
|
|
|
eval {
|
2012-07-15 21:36:18 +00:00
|
|
|
$self->{growler} = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => "$Slic3r::var/Slic3r.png");
|
|
|
|
$self->{growler}->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
2012-06-14 11:49:50 +00:00
|
|
|
};
|
|
|
|
}
|
2012-06-18 20:27:57 +00:00
|
|
|
|
|
|
|
# locate or create data directory
|
|
|
|
$datadir = Wx::StandardPaths::Get->GetUserDataDir;
|
2012-06-21 11:21:42 +00:00
|
|
|
Slic3r::debugf "Data directory: %s\n", $datadir;
|
2012-06-27 20:13:57 +00:00
|
|
|
my $run_wizard = (-d $datadir) ? 0 : 1;
|
2012-06-18 20:27:57 +00:00
|
|
|
for ($datadir, "$datadir/print", "$datadir/filament", "$datadir/printer") {
|
|
|
|
mkdir or $self->fatal_error("Slic3r was unable to create its data directory at $_ (errno: $!).")
|
|
|
|
unless -d $_;
|
|
|
|
}
|
|
|
|
|
2012-06-19 16:11:51 +00:00
|
|
|
# load settings
|
|
|
|
if (-f "$datadir/slic3r.ini") {
|
|
|
|
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
|
|
|
|
$Slic3r::Settings = $ini if $ini;
|
|
|
|
}
|
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
# application frame
|
|
|
|
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
2012-07-15 21:06:07 +00:00
|
|
|
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', wxDefaultPosition, [760, 470], wxDEFAULT_FRAME_STYLE);
|
2012-07-01 17:24:06 +00:00
|
|
|
$frame->SetIcon(Wx::Icon->new("$Slic3r::var/Slic3r_128px.png", wxBITMAP_TYPE_PNG) );
|
2012-07-15 15:54:57 +00:00
|
|
|
$self->{skeinpanel} = Slic3r::GUI::SkeinPanel->new($frame);
|
2012-06-28 21:20:10 +00:00
|
|
|
$self->SetTopWindow($frame);
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-05-04 10:56:15 +00:00
|
|
|
# status bar
|
|
|
|
$frame->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($frame, -1);
|
2012-07-15 21:06:07 +00:00
|
|
|
$frame->{statusbar}->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/");
|
2012-05-04 10:56:15 +00:00
|
|
|
$frame->SetStatusBar($frame->{statusbar});
|
|
|
|
|
2011-12-22 16:38:37 +00:00
|
|
|
# File menu
|
|
|
|
my $fileMenu = Wx::Menu->new;
|
2012-06-18 20:27:57 +00:00
|
|
|
{
|
2012-07-15 20:38:58 +00:00
|
|
|
$fileMenu->Append(1, "Load Config…\tCtrl+L");
|
|
|
|
$fileMenu->Append(2, "Export Config…\tCtrl+E");
|
2012-06-18 20:27:57 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
2012-07-15 20:38:58 +00:00
|
|
|
$fileMenu->Append(3, "Quick Slice…\tCtrl+U");
|
|
|
|
$fileMenu->Append(4, "Repeat Last Quick Slice\tCtrl+Shift+U");
|
|
|
|
$fileMenu->Append(5, "Quick Slice and Save As…\tCtrl+Alt+U");
|
2012-07-03 17:16:45 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
|
|
|
$fileMenu->Append(6, "Slice to SVG…");
|
2012-06-18 20:27:57 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
|
|
|
$fileMenu->Append(wxID_EXIT, "&Quit");
|
2012-07-15 15:54:57 +00:00
|
|
|
EVT_MENU($frame, 1, sub { $self->{skeinpanel}->load_config });
|
|
|
|
EVT_MENU($frame, 2, sub { $self->{skeinpanel}->save_config });
|
|
|
|
EVT_MENU($frame, 3, sub { $self->{skeinpanel}->do_slice });
|
|
|
|
EVT_MENU($frame, 4, sub { $self->{skeinpanel}->do_slice(reslice => 1) });
|
|
|
|
EVT_MENU($frame, 5, sub { $self->{skeinpanel}->do_slice(save_as => 1) });
|
|
|
|
EVT_MENU($frame, 6, sub { $self->{skeinpanel}->do_slice(save_as => 1, export_svg => 1) });
|
2012-06-23 15:39:20 +00:00
|
|
|
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(0)});
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-12 21:46:50 +00:00
|
|
|
# Help menu
|
|
|
|
my $helpMenu = Wx::Menu->new;
|
2012-06-18 20:27:57 +00:00
|
|
|
{
|
2012-06-26 15:42:29 +00:00
|
|
|
$helpMenu->Append(7, "Configuration Wizard…");
|
2012-07-11 14:31:17 +00:00
|
|
|
$helpMenu->Append(8, "Slic3r Website");
|
2012-06-24 10:09:48 +00:00
|
|
|
$helpMenu->Append(wxID_ABOUT, "&About Slic3r");
|
2012-07-15 15:54:57 +00:00
|
|
|
EVT_MENU($frame, 7, sub { $self->{skeinpanel}->config_wizard });
|
2012-07-11 14:31:17 +00:00
|
|
|
EVT_MENU($frame, 8, sub { Wx::LaunchDefaultBrowser('http://slic3r.org/') });
|
2012-06-24 10:09:48 +00:00
|
|
|
EVT_MENU($frame, wxID_ABOUT, \&about);
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# menubar
|
|
|
|
# assign menubar to frame after appending items, otherwise special items
|
2012-06-12 21:46:50 +00:00
|
|
|
# will not be handled correctly
|
2012-06-18 20:27:57 +00:00
|
|
|
{
|
|
|
|
my $menubar = Wx::MenuBar->new;
|
|
|
|
$menubar->Append($fileMenu, "&File");
|
|
|
|
$menubar->Append($helpMenu, "&Help");
|
|
|
|
$frame->SetMenuBar($menubar);
|
|
|
|
}
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-07-15 15:54:57 +00:00
|
|
|
EVT_CLOSE($frame, sub {
|
|
|
|
my (undef, $event) = @_;
|
|
|
|
if ($event->CanVeto && !$self->{skeinpanel}->check_unsaved_changes) {
|
|
|
|
$event->Veto;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$event->Skip;
|
|
|
|
});
|
|
|
|
|
2012-06-18 09:26:21 +00:00
|
|
|
$frame->SetMinSize($frame->GetSize);
|
2011-10-03 09:55:32 +00:00
|
|
|
$frame->Show;
|
2011-10-03 11:08:43 +00:00
|
|
|
$frame->Layout;
|
|
|
|
|
2012-07-15 15:54:57 +00:00
|
|
|
$self->{skeinpanel}->config_wizard if $run_wizard;
|
2012-06-27 20:13:57 +00:00
|
|
|
|
2011-10-03 11:08:43 +00:00
|
|
|
return 1;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2012-06-24 10:09:48 +00:00
|
|
|
sub about {
|
2011-10-03 09:55:32 +00:00
|
|
|
my $frame = shift;
|
|
|
|
|
2012-07-13 21:46:39 +00:00
|
|
|
my $about = Slic3r::GUI::AboutDialog->new($frame);
|
|
|
|
$about->ShowModal;
|
|
|
|
$about->Destroy;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:56:01 +00:00
|
|
|
sub catch_error {
|
2012-05-05 19:08:15 +00:00
|
|
|
my ($self, $cb, $message_dialog) = @_;
|
2012-04-30 12:56:01 +00:00
|
|
|
if (my $err = $@) {
|
|
|
|
$cb->() if $cb;
|
2012-07-01 17:24:06 +00:00
|
|
|
my @params = ($err, 'Error', wxOK | wxICON_ERROR);
|
2012-05-05 19:08:15 +00:00
|
|
|
$message_dialog
|
|
|
|
? $message_dialog->(@params)
|
|
|
|
: Wx::MessageDialog->new($self, @params)->ShowModal;
|
2012-04-30 12:56:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
sub show_error {
|
|
|
|
my $self = shift;
|
|
|
|
my ($message) = @_;
|
2012-07-01 17:24:06 +00:00
|
|
|
Wx::MessageDialog->new($self, $message, 'Error', wxOK | wxICON_ERROR)->ShowModal;
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub fatal_error {
|
|
|
|
my $self = shift;
|
|
|
|
$self->show_error(@_);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:56:01 +00:00
|
|
|
sub warning_catcher {
|
2012-05-05 19:08:15 +00:00
|
|
|
my ($self, $message_dialog) = @_;
|
2012-04-30 12:56:01 +00:00
|
|
|
return sub {
|
|
|
|
my $message = shift;
|
2012-07-01 17:24:06 +00:00
|
|
|
my @params = ($message, 'Warning', wxOK | wxICON_WARNING);
|
2012-05-05 19:08:15 +00:00
|
|
|
$message_dialog
|
|
|
|
? $message_dialog->(@params)
|
|
|
|
: Wx::MessageDialog->new($self, @params)->ShowModal;
|
2012-04-30 12:56:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
sub notify {
|
2012-07-15 21:36:18 +00:00
|
|
|
my $self = shift;
|
2012-06-14 11:49:50 +00:00
|
|
|
my ($message) = @_;
|
|
|
|
|
2012-07-15 21:57:31 +00:00
|
|
|
my $frame = $self->GetTopWindow;
|
|
|
|
$frame->RequestUserAttention unless ($frame->IsActive);
|
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
eval {
|
2012-07-15 21:36:18 +00:00
|
|
|
$self->{growler}->notify(Event => 'SKEIN_DONE', Title => 'Slicing Done!', Message => $message)
|
|
|
|
if $self->{growler};
|
2012-06-14 11:49:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-05-04 10:56:15 +00:00
|
|
|
package Slic3r::GUI::ProgressStatusBar;
|
2012-07-02 23:20:30 +00:00
|
|
|
use Wx qw(:gauge :misc);
|
2012-05-04 10:56:15 +00:00
|
|
|
use base 'Wx::StatusBar';
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
|
|
|
my $self = $class->SUPER::new(@_);
|
|
|
|
|
|
|
|
$self->{busy} = 0;
|
|
|
|
$self->{timer} = Wx::Timer->new($self);
|
2012-07-02 23:20:30 +00:00
|
|
|
$self->{prog} = Wx::Gauge->new($self, wxGA_HORIZONTAL, 100, wxDefaultPosition, wxDefaultSize);
|
2012-05-04 10:56:15 +00:00
|
|
|
$self->{prog}->Hide;
|
2012-07-10 21:09:11 +00:00
|
|
|
$self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", wxDefaultPosition, wxDefaultSize);
|
2012-05-05 19:08:15 +00:00
|
|
|
$self->{cancelbutton}->Hide;
|
2012-05-04 10:56:15 +00:00
|
|
|
|
2012-05-05 19:08:15 +00:00
|
|
|
$self->SetFieldsCount(3);
|
|
|
|
$self->SetStatusWidths(-1, 150, 155);
|
2012-05-04 10:56:15 +00:00
|
|
|
|
|
|
|
Wx::Event::EVT_TIMER($self, \&OnTimer, $self->{timer});
|
|
|
|
Wx::Event::EVT_SIZE($self, \&OnSize);
|
2012-05-05 19:08:15 +00:00
|
|
|
Wx::Event::EVT_BUTTON($self, $self->{cancelbutton}, sub {
|
|
|
|
$self->{cancel_cb}->();
|
|
|
|
$self->{cancelbutton}->Hide;
|
|
|
|
});
|
2012-05-04 10:56:15 +00:00
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub DESTROY {
|
|
|
|
my $self = shift;
|
|
|
|
$self->{timer}->Stop if $self->{timer} && $self->{timer}->IsRunning;
|
|
|
|
}
|
|
|
|
|
2012-07-11 14:55:47 +00:00
|
|
|
sub OnSize {
|
|
|
|
my ($self, $event) = @_;
|
2012-05-04 10:56:15 +00:00
|
|
|
|
2012-07-10 21:09:11 +00:00
|
|
|
my %fields = (
|
|
|
|
# 0 is reserved for status text
|
|
|
|
1 => $self->{cancelbutton},
|
|
|
|
2 => $self->{prog},
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach (keys %fields) {
|
|
|
|
my $rect = $self->GetFieldRect($_);
|
|
|
|
my $offset = &Wx::wxGTK ? 1 : 0; # add a cosmetic 1 pixel offset on wxGTK
|
|
|
|
my $pos = [$rect->GetX + $offset, $rect->GetY + $offset];
|
|
|
|
$fields{$_}->Move($pos);
|
|
|
|
$fields{$_}->SetSize($rect->GetWidth - $offset, $rect->GetHeight);
|
2012-05-05 19:08:15 +00:00
|
|
|
}
|
2012-05-04 10:56:15 +00:00
|
|
|
|
|
|
|
$event->Skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub OnTimer {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
|
|
|
|
if ($self->{prog}->IsShown) {
|
|
|
|
$self->{timer}->Stop;
|
|
|
|
}
|
|
|
|
$self->{prog}->Pulse if $self->{_busy};
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:08:15 +00:00
|
|
|
sub SetCancelCallback {
|
|
|
|
my $self = shift;
|
|
|
|
my ($cb) = @_;
|
|
|
|
$self->{cancel_cb} = $cb;
|
|
|
|
$cb ? $self->{cancelbutton}->Show : $self->{cancelbutton}->Hide;
|
|
|
|
}
|
|
|
|
|
2012-05-04 10:56:15 +00:00
|
|
|
sub Run {
|
|
|
|
my $self = shift;
|
|
|
|
my $rate = shift || 100;
|
|
|
|
if (!$self->{timer}->IsRunning) {
|
|
|
|
$self->{timer}->Start($rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub GetProgress {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->{prog}->GetValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub SetProgress {
|
|
|
|
my $self = shift;
|
|
|
|
my ($val) = @_;
|
|
|
|
if (!$self->{prog}->IsShown) {
|
|
|
|
$self->ShowProgress(1);
|
|
|
|
}
|
|
|
|
if ($val == $self->{prog}->GetRange) {
|
|
|
|
$self->{prog}->SetValue(0);
|
|
|
|
$self->ShowProgress(0);
|
|
|
|
} else {
|
|
|
|
$self->{prog}->SetValue($val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub SetRange {
|
|
|
|
my $self = shift;
|
|
|
|
my ($val) = @_;
|
|
|
|
|
|
|
|
if ($val != $self->{prog}->GetRange) {
|
|
|
|
$self->{prog}->SetRange($val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub ShowProgress {
|
|
|
|
my $self = shift;
|
|
|
|
my ($show) = @_;
|
|
|
|
|
|
|
|
$self->{prog}->Show($show);
|
|
|
|
$self->{prog}->Pulse;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub StartBusy {
|
|
|
|
my $self = shift;
|
|
|
|
my $rate = shift || 100;
|
|
|
|
|
|
|
|
$self->{_busy} = 1;
|
|
|
|
$self->ShowProgress(1);
|
|
|
|
if (!$self->{timer}->IsRunning) {
|
|
|
|
$self->{timer}->Start($rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub StopBusy {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{timer}->Stop;
|
|
|
|
$self->ShowProgress(0);
|
|
|
|
$self->{prog}->SetValue(0);
|
|
|
|
$self->{_busy} = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub IsBusy {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->{_busy};
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
1;
|