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-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
|
|
|
|
2011-11-05 17:19:35 +00:00
|
|
|
use Wx 0.9901 qw(:sizer :frame wxID_EXIT wxID_ABOUT);
|
2011-10-03 09:55:32 +00:00
|
|
|
use Wx::Event qw(EVT_MENU);
|
|
|
|
use base 'Wx::App';
|
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
my $growler;
|
|
|
|
|
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-18 09:26:21 +00:00
|
|
|
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', [-1, -1], [760,500], wxDEFAULT_FRAME_STYLE);
|
2012-05-01 10:58:47 +00:00
|
|
|
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
2012-05-29 12:19:14 +00:00
|
|
|
$frame->SetIcon(Wx::Icon->new("$Slic3r::var/Slic3r_128px.png", &Wx::wxBITMAP_TYPE_PNG) );
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2011-12-22 16:38:37 +00:00
|
|
|
my $panel = Slic3r::GUI::SkeinPanel->new($frame);
|
|
|
|
|
2012-06-14 11:49:50 +00:00
|
|
|
if (eval "use Growl::GNTP; 1") {
|
|
|
|
# register growl notifications
|
|
|
|
eval {
|
|
|
|
$growler = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => "$Slic3r::var/Slic3r.png");
|
|
|
|
$growler->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
# menubar
|
|
|
|
my $menubar = Wx::MenuBar->new;
|
|
|
|
|
2012-05-04 10:56:15 +00:00
|
|
|
# status bar
|
|
|
|
$frame->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($frame, -1);
|
|
|
|
$frame->SetStatusBar($frame->{statusbar});
|
|
|
|
|
2011-12-22 16:38:37 +00:00
|
|
|
# File menu
|
|
|
|
my $fileMenu = Wx::Menu->new;
|
2012-03-03 21:53:12 +00:00
|
|
|
$fileMenu->Append(1, "Save Config…");
|
|
|
|
$fileMenu->Append(2, "Open Config…");
|
|
|
|
$fileMenu->AppendSeparator();
|
|
|
|
$fileMenu->Append(3, "Slice…");
|
2012-03-12 17:52:23 +00:00
|
|
|
$fileMenu->Append(4, "Reslice");
|
|
|
|
$fileMenu->Append(5, "Slice and Save As…");
|
2012-03-26 15:57:54 +00:00
|
|
|
$fileMenu->Append(6, "Export SVG…");
|
2012-04-30 20:23:43 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
2012-06-12 21:47:59 +00:00
|
|
|
$fileMenu->Append(wxID_EXIT, "&Quit");
|
2011-12-22 16:38:37 +00:00
|
|
|
$menubar->Append($fileMenu, "&File");
|
2012-03-03 21:53:12 +00:00
|
|
|
EVT_MENU($frame, 1, sub { $panel->save_config });
|
|
|
|
EVT_MENU($frame, 2, sub { $panel->load_config });
|
|
|
|
EVT_MENU($frame, 3, sub { $panel->do_slice });
|
2012-03-12 17:52:23 +00:00
|
|
|
EVT_MENU($frame, 4, sub { $panel->do_slice(reslice => 1) });
|
|
|
|
EVT_MENU($frame, 5, sub { $panel->do_slice(save_as => 1) });
|
2012-03-26 15:57:54 +00:00
|
|
|
EVT_MENU($frame, 6, sub { $panel->do_slice(save_as => 1, export_svg => 1) });
|
2012-06-12 21:46:50 +00:00
|
|
|
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(1)});
|
|
|
|
|
|
|
|
# Help menu
|
|
|
|
my $helpMenu = Wx::Menu->new;
|
|
|
|
$helpMenu->Append(wxID_ABOUT, "&About");
|
|
|
|
$menubar->Append($helpMenu, "&Help");
|
|
|
|
EVT_MENU($frame, wxID_ABOUT, \&About);
|
|
|
|
|
|
|
|
# Set the menubar after appending items, otherwise special items
|
|
|
|
# will not be handled correctly
|
|
|
|
$frame->SetMenuBar($menubar);
|
2011-10-03 09:55:32 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
return 1;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub About {
|
|
|
|
my $frame = shift;
|
|
|
|
|
|
|
|
my $info = Wx::AboutDialogInfo->new;
|
|
|
|
$info->SetName('Slic3r');
|
|
|
|
$info->AddDeveloper('Alessandro Ranellucci');
|
2012-06-12 21:51:59 +00:00
|
|
|
$info->SetVersion($Slic3r::VERSION);
|
2012-06-18 11:52:38 +00:00
|
|
|
$info->SetDescription('G-code generator for 3D printers');
|
2011-10-03 09:55:32 +00:00
|
|
|
|
|
|
|
Wx::AboutBox($info);
|
|
|
|
}
|
|
|
|
|
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-05-05 19:08:15 +00:00
|
|
|
my @params = ($err, 'Error', &Wx::wxOK | &Wx::wxICON_ERROR);
|
|
|
|
$message_dialog
|
|
|
|
? $message_dialog->(@params)
|
|
|
|
: Wx::MessageDialog->new($self, @params)->ShowModal;
|
2012-04-30 12:56:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-05 19:08:15 +00:00
|
|
|
my @params = ($message, 'Warning', &Wx::wxOK | &Wx::wxICON_WARNING);
|
|
|
|
$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 {
|
|
|
|
my ($message) = @_;
|
|
|
|
|
|
|
|
eval {
|
|
|
|
$growler->notify(Event => 'SKEIN_DONE', Title => 'Slicing Done!', Message => $message)
|
|
|
|
if $growler;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-05-04 10:56:15 +00:00
|
|
|
package Slic3r::GUI::ProgressStatusBar;
|
|
|
|
use base 'Wx::StatusBar';
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
|
|
|
my $self = $class->SUPER::new(@_);
|
|
|
|
|
|
|
|
$self->{_changed} = 0;
|
|
|
|
$self->{busy} = 0;
|
|
|
|
$self->{timer} = Wx::Timer->new($self);
|
|
|
|
$self->{prog} = Wx::Gauge->new($self, &Wx::wxGA_HORIZONTAL, 100, [-1,-1], [-1,-1]);
|
|
|
|
$self->{prog}->Hide;
|
2012-05-05 19:08:15 +00:00
|
|
|
$self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", [-1,-1], [-1,8]);
|
|
|
|
$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_IDLE($self, sub { $self->_Reposition });
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _Reposition {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
##if ($self->{_changed}) {
|
2012-05-05 19:08:15 +00:00
|
|
|
{
|
2012-05-04 10:56:15 +00:00
|
|
|
my $rect = $self->GetFieldRect($self->GetFieldsCount - 1);
|
|
|
|
my $prog_pos = [$rect->GetX + 2, $rect->GetY + 2];
|
|
|
|
$self->{prog}->Move($prog_pos);
|
|
|
|
$self->{prog}->SetSize($rect->GetWidth - 8, $rect->GetHeight - 4);
|
2012-05-05 19:08:15 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
my $rect = $self->GetFieldRect($self->GetFieldsCount - 2);
|
|
|
|
my $pos = [$rect->GetX + 2, $rect->GetY + 2];
|
|
|
|
$self->{cancelbutton}->Move($pos);
|
|
|
|
$self->{cancelbutton}->SetSize($rect->GetWidth - 8, $rect->GetHeight - 4);
|
|
|
|
}
|
2012-05-04 10:56:15 +00:00
|
|
|
$self->{_changed} = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub OnSize {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
|
|
|
|
$self->{_changed} = 1;
|
|
|
|
$self->_Reposition;
|
|
|
|
$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->_Reposition;
|
|
|
|
$self->{prog}->Show($show);
|
|
|
|
$self->{prog}->Pulse;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub StartBusy {
|
|
|
|
my $self = shift;
|
|
|
|
my $rate = shift || 100;
|
|
|
|
|
|
|
|
$self->{_busy} = 1;
|
|
|
|
$self->_Reposition;
|
|
|
|
$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;
|