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
|
|
|
|
2014-03-25 13:04:01 +00:00
|
|
|
use File::Basename qw(basename);
|
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;
|
2014-06-14 17:11:04 +00:00
|
|
|
use Slic3r::GUI::MainFrame;
|
2014-06-14 17:54:18 +00:00
|
|
|
use Slic3r::GUI::Notifier;
|
2012-05-04 08:15:33 +00:00
|
|
|
use Slic3r::GUI::Plater;
|
2014-05-28 10:29:43 +00:00
|
|
|
use Slic3r::GUI::Plater::2D;
|
2014-01-08 18:36:41 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectPartsPanel;
|
2014-04-25 12:54:08 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectCutDialog;
|
2013-08-25 16:01:59 +00:00
|
|
|
use Slic3r::GUI::Plater::ObjectPreviewDialog;
|
|
|
|
use Slic3r::GUI::Plater::ObjectSettingsDialog;
|
2014-02-14 21:24:30 +00:00
|
|
|
use Slic3r::GUI::Plater::OverrideSettingsPanel;
|
2013-01-02 19:30:48 +00:00
|
|
|
use Slic3r::GUI::Preferences;
|
2014-06-14 17:54:18 +00:00
|
|
|
use Slic3r::GUI::ProgressStatusBar;
|
2011-10-03 09:55:32 +00:00
|
|
|
use Slic3r::GUI::OptionsGroup;
|
2013-03-09 15:27:18 +00:00
|
|
|
use Slic3r::GUI::SimpleTab;
|
2012-06-17 20:27:05 +00:00
|
|
|
use Slic3r::GUI::Tab;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2013-06-30 23:50:58 +00:00
|
|
|
our $have_OpenGL = eval "use Slic3r::GUI::PreviewCanvas; 1";
|
2013-05-17 12:14:33 +00:00
|
|
|
|
2014-06-14 17:11:04 +00:00
|
|
|
use Wx 0.9901 qw(:bitmap :dialog :icon :id :misc :systemsettings :toplevelwindow
|
2014-01-18 17:43:55 +00:00
|
|
|
:filedialog);
|
2014-06-14 17:11:04 +00:00
|
|
|
use Wx::Event qw(EVT_IDLE);
|
2011-10-03 09:55:32 +00:00
|
|
|
use base 'Wx::App';
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
use constant FILE_WILDCARDS => {
|
|
|
|
known => 'Known files (*.stl, *.obj, *.amf, *.xml)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML',
|
|
|
|
stl => 'STL files (*.stl)|*.stl;*.STL',
|
|
|
|
obj => 'OBJ files (*.obj)|*.obj;*.OBJ',
|
|
|
|
amf => 'AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML',
|
|
|
|
ini => 'INI files *.ini|*.ini;*.INI',
|
|
|
|
gcode => 'G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC',
|
|
|
|
svg => 'SVG files *.svg|*.svg;*.SVG',
|
|
|
|
};
|
|
|
|
use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf)};
|
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
our $datadir;
|
2013-03-09 15:43:09 +00:00
|
|
|
our $no_plater;
|
|
|
|
our $mode;
|
2013-06-02 18:03:22 +00:00
|
|
|
our $autosave;
|
2013-08-25 12:37:50 +00:00
|
|
|
our @cb;
|
2013-03-09 15:43:09 +00:00
|
|
|
|
2013-01-03 14:49:20 +00:00
|
|
|
our $Settings = {
|
|
|
|
_ => {
|
|
|
|
mode => 'simple',
|
2013-04-27 18:55:43 +00:00
|
|
|
version_check => 1,
|
2013-12-18 18:11:20 +00:00
|
|
|
autocenter => 1,
|
2014-06-13 13:54:13 +00:00
|
|
|
background_processing => 1,
|
2013-01-03 14:49:20 +00:00
|
|
|
},
|
|
|
|
};
|
2012-06-14 11:49:50 +00:00
|
|
|
|
2013-08-25 16:01:59 +00:00
|
|
|
our $have_button_icons = &Wx::wxVERSION_STRING =~ / 2\.9\.[1-9]/;
|
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 {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-02-23 20:51:45 +00:00
|
|
|
$self->SetAppName('Slic3r');
|
2012-08-04 20:19:42 +00:00
|
|
|
Slic3r::debugf "wxWidgets version %s, Wx version %s\n", &Wx::wxVERSION_STRING, $Wx::VERSION;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-07-16 20:37:31 +00:00
|
|
|
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
2012-06-18 20:27:57 +00:00
|
|
|
|
|
|
|
# locate or create data directory
|
2012-08-25 17:06:14 +00:00
|
|
|
$datadir ||= Wx::StandardPaths::Get->GetUserDataDir;
|
2013-11-10 16:06:59 +00:00
|
|
|
$datadir = Slic3r::encode_path($datadir);
|
2012-06-21 11:21:42 +00:00
|
|
|
Slic3r::debugf "Data directory: %s\n", $datadir;
|
2014-03-25 13:07:03 +00:00
|
|
|
|
|
|
|
# just checking for existence of $datadir is not enough: it may be an empty directory
|
|
|
|
# supplied as argument to --datadir; in that case we should still run the wizard
|
|
|
|
my $run_wizard = (-d $datadir && -e "$datadir/slic3r.ini") ? 0 : 1;
|
2013-11-10 16:06:59 +00:00
|
|
|
for ($datadir, "$datadir/print", "$datadir/filament", "$datadir/printer") {
|
2012-06-18 20:27:57 +00:00
|
|
|
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
|
2013-11-11 21:20:25 +00:00
|
|
|
my $last_version;
|
2013-11-10 16:06:59 +00:00
|
|
|
if (-f "$datadir/slic3r.ini") {
|
2012-06-19 16:11:51 +00:00
|
|
|
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
|
2012-07-27 19:13:03 +00:00
|
|
|
$Settings = $ini if $ini;
|
2013-11-11 21:20:25 +00:00
|
|
|
$last_version = $Settings->{_}{version};
|
2013-01-03 14:49:20 +00:00
|
|
|
$Settings->{_}{mode} ||= 'expert';
|
2013-12-18 18:11:20 +00:00
|
|
|
$Settings->{_}{autocenter} //= 1;
|
2014-06-13 13:54:13 +00:00
|
|
|
$Settings->{_}{background_processing} //= 1;
|
2012-06-19 16:11:51 +00:00
|
|
|
}
|
2013-11-18 17:48:06 +00:00
|
|
|
$Settings->{_}{version} = $Slic3r::VERSION;
|
2014-06-14 17:59:59 +00:00
|
|
|
$self->save_settings;
|
2012-06-19 16:11:51 +00:00
|
|
|
|
2012-06-18 20:27:57 +00:00
|
|
|
# application frame
|
|
|
|
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
2014-06-14 17:54:18 +00:00
|
|
|
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
2013-03-09 15:43:09 +00:00
|
|
|
mode => $mode // $Settings->{_}{mode},
|
|
|
|
no_plater => $no_plater,
|
|
|
|
);
|
2012-06-28 21:20:10 +00:00
|
|
|
$self->SetTopWindow($frame);
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2013-11-11 21:20:25 +00:00
|
|
|
if (!$run_wizard && (!defined $last_version || $last_version ne $Slic3r::VERSION)) {
|
|
|
|
# user was running another Slic3r version on this computer
|
|
|
|
if (!defined $last_version || $last_version =~ /^0\./) {
|
2014-06-14 17:54:18 +00:00
|
|
|
show_info($self->{mainframe}, "Hello! Support material was improved since the "
|
2013-11-11 21:20:25 +00:00
|
|
|
. "last version of Slic3r you used. It is strongly recommended to revert "
|
|
|
|
. "your support material settings to the factory defaults and start from "
|
|
|
|
. "those. Enjoy and provide feedback!", "Support Material");
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 17:54:18 +00:00
|
|
|
$self->{mainframe}->config_wizard if $run_wizard;
|
2012-06-27 20:13:57 +00:00
|
|
|
|
2014-06-14 17:59:59 +00:00
|
|
|
$self->check_version
|
|
|
|
if $self->have_version_check
|
2013-04-27 18:55:43 +00:00
|
|
|
&& ($Settings->{_}{version_check} // 1)
|
|
|
|
&& (!$Settings->{_}{last_version_check} || (time - $Settings->{_}{last_version_check}) >= 86400);
|
|
|
|
|
2013-08-25 12:37:50 +00:00
|
|
|
EVT_IDLE($frame, sub {
|
|
|
|
while (my $cb = shift @cb) {
|
|
|
|
$cb->();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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 {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
my $about = Slic3r::GUI::AboutDialog->new(undef);
|
2012-07-13 21:46:39 +00:00
|
|
|
$about->ShowModal;
|
|
|
|
$about->Destroy;
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
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
|
|
|
$message_dialog
|
2014-06-13 12:27:55 +00:00
|
|
|
? $message_dialog->($err, 'Error', wxOK | wxICON_ERROR)
|
|
|
|
: Slic3r::GUI::show_error($self, $err);
|
2012-04-30 12:56:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
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
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2013-04-27 18:55:43 +00:00
|
|
|
sub show_info {
|
|
|
|
my $self = shift;
|
|
|
|
my ($message, $title) = @_;
|
|
|
|
Wx::MessageDialog->new($self, $message, $title || 'Notice', wxOK | wxICON_INFORMATION)->ShowModal;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
2012-06-18 20:27:57 +00:00
|
|
|
sub fatal_error {
|
|
|
|
my $self = shift;
|
|
|
|
$self->show_error(@_);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
# static method accepting a wxWindow object as first parameter
|
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;
|
2013-06-07 11:54:40 +00:00
|
|
|
return if $message =~ /GLUquadricObjPtr|Attempt to free unreferenced scalar/;
|
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 {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $message) = @_;
|
2012-06-14 11:49:50 +00:00
|
|
|
|
2012-07-15 21:57:31 +00:00
|
|
|
my $frame = $self->GetTopWindow;
|
2012-08-01 11:59:43 +00:00
|
|
|
# try harder to attract user attention on OS X
|
|
|
|
$frame->RequestUserAttention(&Wx::wxMAC ? wxUSER_ATTENTION_ERROR : wxUSER_ATTENTION_INFO)
|
|
|
|
unless ($frame->IsActive);
|
2012-07-15 21:57:31 +00:00
|
|
|
|
2012-07-16 20:37:31 +00:00
|
|
|
$self->{notifier}->notify($message);
|
2012-06-14 11:49:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub save_settings {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
2012-07-27 19:13:03 +00:00
|
|
|
Slic3r::Config->write_ini("$datadir/slic3r.ini", $Settings);
|
|
|
|
}
|
|
|
|
|
2014-03-25 13:04:01 +00:00
|
|
|
sub presets {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $section) = @_;
|
2014-03-25 13:04:01 +00:00
|
|
|
|
|
|
|
my %presets = ();
|
|
|
|
opendir my $dh, "$Slic3r::GUI::datadir/$section" or die "Failed to read directory $Slic3r::GUI::datadir/$section (errno: $!)\n";
|
|
|
|
foreach my $file (grep /\.ini$/i, readdir $dh) {
|
|
|
|
my $name = basename($file);
|
|
|
|
$name =~ s/\.ini$//;
|
|
|
|
$presets{$name} = "$Slic3r::GUI::datadir/$section/$file";
|
|
|
|
}
|
|
|
|
closedir $dh;
|
|
|
|
|
|
|
|
return %presets;
|
|
|
|
}
|
|
|
|
|
2013-04-27 18:55:43 +00:00
|
|
|
sub have_version_check {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self) = @_;
|
2013-04-27 18:55:43 +00:00
|
|
|
|
2013-06-16 14:06:20 +00:00
|
|
|
# return an explicit 0
|
|
|
|
return ($Slic3r::have_threads && $Slic3r::build && eval "use LWP::UserAgent; 1") || 0;
|
2013-04-27 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub check_version {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, %p) = @_;
|
|
|
|
|
2013-04-27 18:55:43 +00:00
|
|
|
Slic3r::debugf "Checking for updates...\n";
|
|
|
|
|
2013-05-19 15:34:33 +00:00
|
|
|
@_ = ();
|
2013-04-27 18:55:43 +00:00
|
|
|
threads->create(sub {
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
$ua->timeout(10);
|
|
|
|
my $response = $ua->get('http://slic3r.org/updatecheck');
|
|
|
|
if ($response->is_success) {
|
|
|
|
if ($response->decoded_content =~ /^obsolete ?= ?([a-z0-9.-]+,)*\Q$Slic3r::VERSION\E(?:,|$)/) {
|
|
|
|
my $res = Wx::MessageDialog->new(undef, "A new version is available. Do you want to open the Slic3r website now?",
|
|
|
|
'Update', wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_INFORMATION | wxICON_ERROR)->ShowModal;
|
|
|
|
Wx::LaunchDefaultBrowser('http://slic3r.org/') if $res == wxID_YES;
|
|
|
|
} else {
|
|
|
|
Slic3r::GUI::show_info(undef, "You're using the latest version. No updates are available.") if $p{manual};
|
|
|
|
}
|
|
|
|
$Settings->{_}{last_version_check} = time();
|
2014-06-14 17:59:59 +00:00
|
|
|
$self->save_settings;
|
2013-04-27 18:55:43 +00:00
|
|
|
} else {
|
|
|
|
Slic3r::GUI::show_error(undef, "Failed to check for updates. Try later.") if $p{manual};
|
|
|
|
}
|
2014-04-22 09:59:01 +00:00
|
|
|
Slic3r::thread_cleanup();
|
2013-04-27 18:55:43 +00:00
|
|
|
})->detach;
|
|
|
|
}
|
|
|
|
|
2013-04-27 19:07:30 +00:00
|
|
|
sub output_path {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $dir) = @_;
|
2013-04-27 19:07:30 +00:00
|
|
|
|
|
|
|
return ($Settings->{_}{last_output_path} && $Settings->{_}{remember_output_path})
|
|
|
|
? $Settings->{_}{last_output_path}
|
|
|
|
: $dir;
|
|
|
|
}
|
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
sub open_model {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $window) = @_;
|
2014-01-18 17:43:55 +00:00
|
|
|
|
|
|
|
my $dir = $Slic3r::GUI::Settings->{recent}{skein_directory}
|
|
|
|
|| $Slic3r::GUI::Settings->{recent}{config_directory}
|
|
|
|
|| '';
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
my $dialog = Wx::FileDialog->new($window // $self->GetTopWindow, 'Choose one or more files (STL/OBJ/AMF):', $dir, "",
|
|
|
|
MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
|
2014-01-18 17:43:55 +00:00
|
|
|
if ($dialog->ShowModal != wxID_OK) {
|
|
|
|
$dialog->Destroy;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my @input_files = $dialog->GetPaths;
|
|
|
|
$dialog->Destroy;
|
|
|
|
|
|
|
|
return @input_files;
|
|
|
|
}
|
|
|
|
|
2013-08-25 12:37:50 +00:00
|
|
|
sub CallAfter {
|
2014-06-14 17:54:18 +00:00
|
|
|
my ($self, $cb) = @_;
|
2013-08-25 12:37:50 +00:00
|
|
|
push @cb, $cb;
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
1;
|