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;
|
2012-05-04 08:15:33 +00:00
|
|
|
use Slic3r::GUI::Plater;
|
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;
|
2011-10-03 09:55:32 +00:00
|
|
|
use Slic3r::GUI::OptionsGroup;
|
|
|
|
use Slic3r::GUI::SkeinPanel;
|
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-01-18 17:43:55 +00:00
|
|
|
use Wx 0.9901 qw(:bitmap :dialog :frame :icon :id :misc :systemsettings :toplevelwindow
|
|
|
|
:filedialog);
|
2013-08-25 12:37:50 +00:00
|
|
|
use Wx::Event qw(EVT_CLOSE EVT_MENU EVT_IDLE);
|
2011-10-03 09:55:32 +00:00
|
|
|
use base 'Wx::App';
|
|
|
|
|
2012-08-02 19:11:36 +00:00
|
|
|
use constant MI_LOAD_CONF => &Wx::NewId;
|
2014-03-25 13:04:01 +00:00
|
|
|
use constant MI_LOAD_CONFBUNDLE => &Wx::NewId;
|
2012-08-02 19:11:36 +00:00
|
|
|
use constant MI_EXPORT_CONF => &Wx::NewId;
|
2014-03-25 13:04:01 +00:00
|
|
|
use constant MI_EXPORT_CONFBUNDLE => &Wx::NewId;
|
2012-08-02 19:11:36 +00:00
|
|
|
use constant MI_QUICK_SLICE => &Wx::NewId;
|
|
|
|
use constant MI_REPEAT_QUICK => &Wx::NewId;
|
|
|
|
use constant MI_QUICK_SAVE_AS => &Wx::NewId;
|
|
|
|
use constant MI_SLICE_SVG => &Wx::NewId;
|
2013-06-23 19:11:46 +00:00
|
|
|
use constant MI_REPAIR_STL => &Wx::NewId;
|
2012-09-23 12:48:58 +00:00
|
|
|
use constant MI_COMBINE_STLS => &Wx::NewId;
|
2012-07-24 10:59:02 +00:00
|
|
|
|
2012-08-29 15:11:56 +00:00
|
|
|
use constant MI_PLATER_EXPORT_GCODE => &Wx::NewId;
|
|
|
|
use constant MI_PLATER_EXPORT_STL => &Wx::NewId;
|
|
|
|
use constant MI_PLATER_EXPORT_AMF => &Wx::NewId;
|
|
|
|
|
2012-08-02 19:11:36 +00:00
|
|
|
use constant MI_TAB_PLATER => &Wx::NewId;
|
|
|
|
use constant MI_TAB_PRINT => &Wx::NewId;
|
|
|
|
use constant MI_TAB_FILAMENT => &Wx::NewId;
|
|
|
|
use constant MI_TAB_PRINTER => &Wx::NewId;
|
2012-07-24 10:59:02 +00:00
|
|
|
|
2012-08-02 19:11:36 +00:00
|
|
|
use constant MI_CONF_WIZARD => &Wx::NewId;
|
|
|
|
use constant MI_WEBSITE => &Wx::NewId;
|
2013-04-27 18:55:43 +00:00
|
|
|
use constant MI_VERSIONCHECK => &Wx::NewId;
|
2012-09-28 14:58:03 +00:00
|
|
|
use constant MI_DOCUMENTATION => &Wx::NewId;
|
2012-07-16 18:57:10 +00:00
|
|
|
|
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,
|
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 {
|
|
|
|
my $self = shift;
|
|
|
|
|
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;
|
2012-06-19 16:11:51 +00:00
|
|
|
}
|
2013-11-18 17:48:06 +00:00
|
|
|
$Settings->{_}{version} = $Slic3r::VERSION;
|
2013-11-11 21:20:25 +00:00
|
|
|
Slic3r::GUI->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);
|
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) );
|
2013-03-09 15:43:09 +00:00
|
|
|
$self->{skeinpanel} = Slic3r::GUI::SkeinPanel->new($frame,
|
|
|
|
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
|
|
|
|
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-23 14:31:16 +00:00
|
|
|
$fileMenu->Append(MI_LOAD_CONF, "&Load Config…\tCtrl+L", 'Load exported configuration file');
|
|
|
|
$fileMenu->Append(MI_EXPORT_CONF, "&Export Config…\tCtrl+E", 'Export current configuration to file');
|
2014-03-25 13:04:01 +00:00
|
|
|
$fileMenu->Append(MI_LOAD_CONFBUNDLE, "&Load Config Bundle…", 'Load presets from a bundle');
|
|
|
|
$fileMenu->Append(MI_EXPORT_CONFBUNDLE, "&Export Config Bundle…", 'Export all presets to file');
|
2012-06-18 20:27:57 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
2012-07-23 14:31:16 +00:00
|
|
|
$fileMenu->Append(MI_QUICK_SLICE, "Q&uick Slice…\tCtrl+U", 'Slice file');
|
|
|
|
$fileMenu->Append(MI_QUICK_SAVE_AS, "Quick Slice and Save &As…\tCtrl+Alt+U", 'Slice file and save as');
|
|
|
|
my $repeat = $fileMenu->Append(MI_REPEAT_QUICK, "&Repeat Last Quick Slice\tCtrl+Shift+U", 'Repeat last quick slice');
|
2012-07-17 21:53:16 +00:00
|
|
|
$repeat->Enable(0);
|
2012-07-03 17:16:45 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
2012-07-23 14:31:16 +00:00
|
|
|
$fileMenu->Append(MI_SLICE_SVG, "Slice to SV&G…\tCtrl+G", 'Slice file to SVG');
|
2012-06-18 20:27:57 +00:00
|
|
|
$fileMenu->AppendSeparator();
|
2013-06-23 19:11:46 +00:00
|
|
|
$fileMenu->Append(MI_REPAIR_STL, "Repair STL file…", 'Automatically repair an STL file');
|
2012-09-23 12:48:58 +00:00
|
|
|
$fileMenu->Append(MI_COMBINE_STLS, "Combine multi-material STL files…", 'Combine multiple STL files into a single multi-material AMF file');
|
|
|
|
$fileMenu->AppendSeparator();
|
2013-01-02 19:30:48 +00:00
|
|
|
$fileMenu->Append(wxID_PREFERENCES, "Preferences…", 'Application preferences');
|
|
|
|
$fileMenu->AppendSeparator();
|
2012-07-23 14:31:16 +00:00
|
|
|
$fileMenu->Append(wxID_EXIT, "&Quit", 'Quit Slic3r');
|
2012-07-27 19:13:03 +00:00
|
|
|
EVT_MENU($frame, MI_LOAD_CONF, sub { $self->{skeinpanel}->load_config_file });
|
2014-03-25 13:04:01 +00:00
|
|
|
EVT_MENU($frame, MI_LOAD_CONFBUNDLE, sub { $self->{skeinpanel}->load_configbundle });
|
2012-08-07 18:14:28 +00:00
|
|
|
EVT_MENU($frame, MI_EXPORT_CONF, sub { $self->{skeinpanel}->export_config });
|
2014-03-25 13:04:01 +00:00
|
|
|
EVT_MENU($frame, MI_EXPORT_CONFBUNDLE, sub { $self->{skeinpanel}->export_configbundle });
|
2013-05-20 09:02:12 +00:00
|
|
|
EVT_MENU($frame, MI_QUICK_SLICE, sub { $self->{skeinpanel}->quick_slice;
|
2012-07-17 21:53:16 +00:00
|
|
|
$repeat->Enable(defined $Slic3r::GUI::SkeinPanel::last_input_file) });
|
2013-05-20 09:02:12 +00:00
|
|
|
EVT_MENU($frame, MI_REPEAT_QUICK, sub { $self->{skeinpanel}->quick_slice(reslice => 1) });
|
|
|
|
EVT_MENU($frame, MI_QUICK_SAVE_AS, sub { $self->{skeinpanel}->quick_slice(save_as => 1);
|
2012-07-17 21:53:16 +00:00
|
|
|
$repeat->Enable(defined $Slic3r::GUI::SkeinPanel::last_input_file) });
|
2013-05-20 09:02:12 +00:00
|
|
|
EVT_MENU($frame, MI_SLICE_SVG, sub { $self->{skeinpanel}->quick_slice(save_as => 1, export_svg => 1) });
|
2013-06-23 19:11:46 +00:00
|
|
|
EVT_MENU($frame, MI_REPAIR_STL, sub { $self->{skeinpanel}->repair_stl });
|
2012-09-23 12:48:58 +00:00
|
|
|
EVT_MENU($frame, MI_COMBINE_STLS, sub { $self->{skeinpanel}->combine_stls });
|
2013-01-02 19:30:48 +00:00
|
|
|
EVT_MENU($frame, wxID_PREFERENCES, sub { Slic3r::GUI::Preferences->new($frame)->ShowModal });
|
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-08-29 15:11:56 +00:00
|
|
|
# Plater menu
|
2013-05-13 16:30:12 +00:00
|
|
|
my $platerMenu;
|
|
|
|
unless ($no_plater) {
|
|
|
|
$platerMenu = Wx::Menu->new;
|
2012-08-29 15:11:56 +00:00
|
|
|
$platerMenu->Append(MI_PLATER_EXPORT_GCODE, "Export G-code...", 'Export current plate as G-code');
|
|
|
|
$platerMenu->Append(MI_PLATER_EXPORT_STL, "Export STL...", 'Export current plate as STL');
|
|
|
|
$platerMenu->Append(MI_PLATER_EXPORT_AMF, "Export AMF...", 'Export current plate as AMF');
|
|
|
|
EVT_MENU($frame, MI_PLATER_EXPORT_GCODE, sub { $self->{skeinpanel}{plater}->export_gcode });
|
|
|
|
EVT_MENU($frame, MI_PLATER_EXPORT_STL, sub { $self->{skeinpanel}{plater}->export_stl });
|
|
|
|
EVT_MENU($frame, MI_PLATER_EXPORT_AMF, sub { $self->{skeinpanel}{plater}->export_amf });
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:59:02 +00:00
|
|
|
# Window menu
|
|
|
|
my $windowMenu = Wx::Menu->new;
|
|
|
|
{
|
2013-05-13 16:30:12 +00:00
|
|
|
my $tab_count = $no_plater ? 3 : 4;
|
|
|
|
$windowMenu->Append(MI_TAB_PLATER, "Select &Plater Tab\tCtrl+1", 'Show the plater') unless $no_plater;
|
2012-07-24 10:59:02 +00:00
|
|
|
$windowMenu->Append(MI_TAB_PRINT, "Select P&rint Settings Tab\tCtrl+2", 'Show the print settings');
|
|
|
|
$windowMenu->Append(MI_TAB_FILAMENT, "Select &Filament Settings Tab\tCtrl+3", 'Show the filament settings');
|
|
|
|
$windowMenu->Append(MI_TAB_PRINTER, "Select Print&er Settings Tab\tCtrl+4", 'Show the printer settings');
|
2013-05-13 16:30:12 +00:00
|
|
|
EVT_MENU($frame, MI_TAB_PLATER, sub { $self->{skeinpanel}->select_tab(0) }) unless $no_plater;
|
|
|
|
EVT_MENU($frame, MI_TAB_PRINT, sub { $self->{skeinpanel}->select_tab($tab_count-3) });
|
|
|
|
EVT_MENU($frame, MI_TAB_FILAMENT, sub { $self->{skeinpanel}->select_tab($tab_count-2) });
|
|
|
|
EVT_MENU($frame, MI_TAB_PRINTER, sub { $self->{skeinpanel}->select_tab($tab_count-1) });
|
2012-07-24 10:59:02 +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-07-23 14:31:16 +00:00
|
|
|
$helpMenu->Append(MI_CONF_WIZARD, "&Configuration $Slic3r::GUI::ConfigWizard::wizard…", "Run Configuration $Slic3r::GUI::ConfigWizard::wizard");
|
2012-09-28 14:58:03 +00:00
|
|
|
$helpMenu->AppendSeparator();
|
2012-07-23 14:31:16 +00:00
|
|
|
$helpMenu->Append(MI_WEBSITE, "Slic3r &Website", 'Open the Slic3r website in your browser');
|
2013-04-27 18:55:43 +00:00
|
|
|
my $versioncheck = $helpMenu->Append(MI_VERSIONCHECK, "Check for &Updates...", 'Check for new Slic3r versions');
|
|
|
|
$versioncheck->Enable(Slic3r::GUI->have_version_check);
|
2013-06-24 16:07:33 +00:00
|
|
|
$helpMenu->Append(MI_DOCUMENTATION, "Slic3r &Manual", 'Open the Slic3r manual in your browser');
|
2012-09-28 14:58:03 +00:00
|
|
|
$helpMenu->AppendSeparator();
|
2012-07-23 14:31:16 +00:00
|
|
|
$helpMenu->Append(wxID_ABOUT, "&About Slic3r", 'Show about dialog');
|
2012-07-16 18:57:10 +00:00
|
|
|
EVT_MENU($frame, MI_CONF_WIZARD, sub { $self->{skeinpanel}->config_wizard });
|
|
|
|
EVT_MENU($frame, MI_WEBSITE, sub { Wx::LaunchDefaultBrowser('http://slic3r.org/') });
|
2013-04-27 18:55:43 +00:00
|
|
|
EVT_MENU($frame, MI_VERSIONCHECK, sub { Slic3r::GUI->check_version(manual => 1) });
|
2013-06-24 18:38:20 +00:00
|
|
|
EVT_MENU($frame, MI_DOCUMENTATION, sub { Wx::LaunchDefaultBrowser('http://manual.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");
|
2013-05-13 16:30:12 +00:00
|
|
|
$menubar->Append($platerMenu, "&Plater") if $platerMenu;
|
2012-07-24 10:59:02 +00:00
|
|
|
$menubar->Append($windowMenu, "&Window");
|
2012-06-18 20:27:57 +00:00
|
|
|
$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-07-18 09:54:26 +00:00
|
|
|
$frame->Fit;
|
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;
|
|
|
|
|
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\./) {
|
|
|
|
show_info($self->{skeinpanel}, "Hello! Support material was improved since the "
|
|
|
|
. "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");
|
|
|
|
}
|
|
|
|
}
|
2012-07-15 15:54:57 +00:00
|
|
|
$self->{skeinpanel}->config_wizard if $run_wizard;
|
2012-06-27 20:13:57 +00:00
|
|
|
|
2013-04-27 18:55:43 +00:00
|
|
|
Slic3r::GUI->check_version
|
|
|
|
if Slic3r::GUI->have_version_check
|
|
|
|
&& ($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 {
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
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 {
|
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;
|
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 {
|
2012-10-24 18:24:11 +00:00
|
|
|
my $class = shift;
|
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 {
|
|
|
|
my ($class, $section) = @_;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
my $class = shift;
|
|
|
|
|
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 {
|
|
|
|
my $class = shift;
|
|
|
|
my %p = @_;
|
|
|
|
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();
|
|
|
|
Slic3r::GUI->save_settings;
|
|
|
|
} 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 {
|
|
|
|
my $class = shift;
|
|
|
|
my ($dir) = @_;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
my $dir = $Slic3r::GUI::Settings->{recent}{skein_directory}
|
|
|
|
|| $Slic3r::GUI::Settings->{recent}{config_directory}
|
|
|
|
|| '';
|
|
|
|
|
|
|
|
my $dialog = Wx::FileDialog->new($self, 'Choose one or more files (STL/OBJ/AMF):', $dir, "",
|
|
|
|
&Slic3r::GUI::SkeinPanel::MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
|
|
|
|
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 {
|
|
|
|
my $class = shift;
|
|
|
|
my ($cb) = @_;
|
|
|
|
push @cb, $cb;
|
|
|
|
}
|
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
|
2012-07-16 20:37:31 +00:00
|
|
|
package Slic3r::GUI::Notifier;
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
|
|
|
my $self;
|
|
|
|
|
|
|
|
$self->{icon} = "$Slic3r::var/Slic3r.png";
|
|
|
|
|
|
|
|
if (eval 'use Growl::GNTP; 1') {
|
|
|
|
# register with growl
|
|
|
|
eval {
|
|
|
|
$self->{growler} = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $self->{icon});
|
|
|
|
$self->{growler}->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub notify {
|
|
|
|
my ($self, $message) = @_;
|
|
|
|
my $title = 'Slicing Done!';
|
|
|
|
|
|
|
|
eval {
|
|
|
|
$self->{growler}->notify(Event => 'SKEIN_DONE', Title => $title, Message => $message)
|
|
|
|
if $self->{growler};
|
|
|
|
};
|
2013-04-29 13:57:07 +00:00
|
|
|
# Net::DBus is broken in multithreaded environment
|
|
|
|
if (0 && eval 'use Net::DBus; 1') {
|
2012-07-16 21:43:09 +00:00
|
|
|
eval {
|
|
|
|
my $session = Net::DBus->session;
|
|
|
|
my $serv = $session->get_service('org.freedesktop.Notifications');
|
|
|
|
my $notifier = $serv->get_object('/org/freedesktop/Notifications',
|
|
|
|
'org.freedesktop.Notifications');
|
2012-07-17 13:38:53 +00:00
|
|
|
$notifier->Notify('Slic3r', 0, $self->{icon}, $title, $message, [], {}, -1);
|
2013-01-25 20:29:44 +00:00
|
|
|
undef $Net::DBus::bus_session;
|
2013-01-26 17:31:28 +00:00
|
|
|
};
|
|
|
|
}
|
2012-07-16 20:37:31 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
1;
|