Extended the Config Wizard to offer a selection of config bundles

bundled with Slic3r installation, and install it into user's Slic3r profile.
These bundled config bundles will be contained in the Slic3r source
tree under Slic3r/resources/profiles.

Breaking change! The Slic3r user directory has been renamed to Slic3rPE
for the Prusa Edition. Also it is likely, that the Slic3rPE directory
will be reorganized before the final 1.38 release to reserve space
for temporary profiles downloaded from the Internet.
This commit is contained in:
bubnikv 2017-12-10 13:19:44 +01:00
parent 9a80ff57b2
commit 657f2734f1
7 changed files with 125 additions and 30 deletions

View File

@ -42,6 +42,7 @@ use FindBin;
# Let the XS module know where the GUI resources reside. # Let the XS module know where the GUI resources reside.
set_var_dir(decode_path($FindBin::Bin) . "/var"); set_var_dir(decode_path($FindBin::Bin) . "/var");
set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/Resources' : '/resources'));
use Moo 1.003001; use Moo 1.003001;

View File

@ -70,7 +70,7 @@ our $grey = Wx::Colour->new(200,200,200);
sub OnInit { sub OnInit {
my ($self) = @_; my ($self) = @_;
$self->SetAppName('Slic3r'); $self->SetAppName('Slic3rPE');
$self->SetAppDisplayName('Slic3r Prusa Edition'); $self->SetAppDisplayName('Slic3r Prusa Edition');
Slic3r::debugf "wxWidgets version %s, Wx version %s\n", &Wx::wxVERSION_STRING, $Wx::VERSION; Slic3r::debugf "wxWidgets version %s, Wx version %s\n", &Wx::wxVERSION_STRING, $Wx::VERSION;

View File

@ -14,14 +14,14 @@ our $wizard = 'Wizard';
$wizard = 'Assistant' if &Wx::wxMAC || &Wx::wxGTK; $wizard = 'Assistant' if &Wx::wxMAC || &Wx::wxGTK;
sub new { sub new {
my $class = shift; my ($class, $parent, $presets) = @_;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, "Configuration $wizard"); my $self = $class->SUPER::new($parent, -1, "Configuration $wizard");
# initialize an empty repository # initialize an empty repository
$self->{config} = Slic3r::Config->new; $self->{config} = Slic3r::Config->new;
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Welcome->new($self)); my $welcome_page = Slic3r::GUI::ConfigWizard::Page::Welcome->new($self);
$self->add_page($welcome_page);
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Firmware->new($self)); $self->add_page(Slic3r::GUI::ConfigWizard::Page::Firmware->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Bed->new($self)); $self->add_page(Slic3r::GUI::ConfigWizard::Page::Bed->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Nozzle->new($self)); $self->add_page(Slic3r::GUI::ConfigWizard::Page::Nozzle->new($self));
@ -32,12 +32,13 @@ sub new {
$_->build_index for @{$self->{pages}}; $_->build_index for @{$self->{pages}};
$welcome_page->set_selection_presets([@{$presets}, 'Other']);
return $self; return $self;
} }
sub add_page { sub add_page {
my $self = shift; my ($self, $page) = @_;
my ($page) = @_;
my $n = push @{$self->{pages}}, $page; my $n = push @{$self->{pages}}, $page;
# add first page to the page area sizer # add first page to the page area sizer
@ -48,13 +49,13 @@ sub add_page {
} }
sub run { sub run {
my $self = shift; my ($self) = @_;
my $result = undef;
if (Wx::Wizard::RunWizard($self, $self->{pages}[0])) { if (Wx::Wizard::RunWizard($self, $self->{pages}[0])) {
my $preset_name = $self->{pages}[0]->{preset_name};
# it would be cleaner to have these defined inside each page class, if ($preset_name eq 'Other') {
# in some event getting called before leaving the page # it would be cleaner to have these defined inside each page class,
{ # in some event getting called before leaving the page
# set first_layer_height + layer_height based on nozzle_diameter # set first_layer_height + layer_height based on nozzle_diameter
my $nozzle = $self->{config}->nozzle_diameter; my $nozzle = $self->{config}->nozzle_diameter;
$self->{config}->set('first_layer_height', $nozzle->[0]); $self->{config}->set('first_layer_height', $nozzle->[0]);
@ -66,14 +67,13 @@ sub run {
# set first_layer_bed_temperature to temperature + 5 # set first_layer_bed_temperature to temperature + 5
$self->{config}->set('first_layer_bed_temperature', $self->{config}->set('first_layer_bed_temperature',
[ ($self->{config}->bed_temperature->[0] > 0) ? ($self->{config}->bed_temperature->[0] + 5) : 0 ]); [ ($self->{config}->bed_temperature->[0] > 0) ? ($self->{config}->bed_temperature->[0] + 5) : 0 ]);
$result = $self->{config};
} else {
$result = $preset_name;
} }
$self->Destroy;
return $self->{config};
} else {
$self->Destroy;
return undef;
} }
$self->Destroy;
return $result;
} }
package Slic3r::GUI::ConfigWizard::Index; package Slic3r::GUI::ConfigWizard::Index;
@ -127,6 +127,8 @@ sub repaint {
$dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index}; $dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index};
$dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gap), $label_w, $label_h)); $dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gap), $label_w, $label_h));
# Only show the first bullet if this is the only wizard page to be displayed.
last if $i == 0 && $self->{just_welcome};
$i++; $i++;
} }
@ -263,19 +265,58 @@ sub config {
package Slic3r::GUI::ConfigWizard::Page::Welcome; package Slic3r::GUI::ConfigWizard::Page::Welcome;
use base 'Slic3r::GUI::ConfigWizard::Page'; use base 'Slic3r::GUI::ConfigWizard::Page';
use Wx qw(:misc :sizer wxID_FORWARD);
use Wx::Event qw(EVT_ACTIVATE EVT_CHOICE);
sub new { sub new {
my $class = shift; my $class = shift;
my ($parent) = @_; my ($parent) = @_;
my $self = $class->SUPER::new($parent, "Welcome to the Slic3r Configuration $wizard", 'Welcome'); my $self = $class->SUPER::new($parent, "Welcome to the Slic3r Configuration $wizard", 'Welcome');
$self->{full_wizard_workflow} = 1;
$self->append_text('Hello, welcome to Slic3r! This '.lc($wizard).' helps you with the initial configuration; just a few settings and you will be ready to print.'); $self->append_text('Hello, welcome to Slic3r Prusa Edition! This '.lc($wizard).' helps you with the initial configuration; just a few settings and you will be ready to print.');
$self->append_text('To import an existing configuration instead, cancel this '.lc($wizard).' and use the Open Config menu item found in the File menu.'); $self->append_text('Please select your printer vendor and printer type. If your printer is not listed, you may try your luck and select a similar one. If you select "Other", this ' . lc($wizard) . ' will let you set the basic 3D printer parameters.');
$self->append_text('To continue, click Next.'); # To import an existing configuration instead, cancel this '.lc($wizard).' and use the Open Config menu item found in the File menu.');
$self->append_text('If you received a configuration file or a config bundle from your 3D printer vendor, cancel this '.lc($wizard).' and use the "File->Load Config" or "File->Load Config Bundle" menu.');
$self->{choice} = my $choice = Wx::Choice->new($self, -1, wxDefaultPosition, wxDefaultSize, []);
$self->{vsizer}->Add($choice, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
EVT_CHOICE($parent, $choice, sub {
my $sel = $self->{choice}->GetStringSelection;
$self->{preset_name} = $sel;
$self->set_full_wizard_workflow(($sel eq 'Other') || ($sel eq ''));
});
EVT_ACTIVATE($parent, sub {
$self->set_full_wizard_workflow($self->{preset_name} eq 'Other');
});
return $self; return $self;
} }
sub set_full_wizard_workflow {
my ($self, $full_workflow) = @_;
$self->{full_wizard_workflow} = $full_workflow;
$self->{index}->{just_welcome} = !$full_workflow;
$self->{index}->Refresh;
my $next_button = $self->GetParent->FindWindow(wxID_FORWARD);
$next_button->SetLabel($full_workflow ? "&Next >" : "&Finish");
}
# Set the preset names, select the first item.
sub set_selection_presets {
my ($self, $names) = @_;
$self->{choice}->Append($names);
$self->{choice}->SetSelection(0);
$self->{preset_name} = $names->[0];
}
sub GetNext {
my $self = shift;
return $self->{full_wizard_workflow} ? $self->{next_page} : undef;
}
package Slic3r::GUI::ConfigWizard::Page::Firmware; package Slic3r::GUI::ConfigWizard::Page::Firmware;
use base 'Slic3r::GUI::ConfigWizard::Page'; use base 'Slic3r::GUI::ConfigWizard::Page';

View File

@ -617,16 +617,40 @@ sub config_wizard {
my ($self) = @_; my ($self) = @_;
# Exit wizard if there are unsaved changes and the user cancels the action. # Exit wizard if there are unsaved changes and the user cancels the action.
return unless $self->check_unsaved_changes; return unless $self->check_unsaved_changes;
if (my $config = Slic3r::GUI::ConfigWizard->new($self)->run) { # Enumerate the profiles bundled with the Slic3r installation under resources/profiles.
for my $tab (values %{$self->{options_tabs}}) { my $directory = Slic3r::resources_dir() . "/profiles";
# Select the first visible preset, force. my @profiles = ();
$tab->select_preset(undef, 1); if (opendir(DIR, Slic3r::encode_path($directory))) {
while (my $file = readdir(DIR)) {
if ($file =~ /\.ini$/) {
$file =~ s/\.ini$//;
push @profiles, Slic3r::decode_path($file);
}
} }
# Load the config over the previously selected defaults. closedir(DIR);
$self->load_config($config); }
for my $tab (values %{$self->{options_tabs}}) { # Open the wizard.
# Save the settings under a new name, select the name. if (my $config = Slic3r::GUI::ConfigWizard->new($self, \@profiles)->run) {
$tab->save_preset('My Settings'); if (ref($config)) {
# Wizard returned a config. Add the config to each of the preset types.
for my $tab (values %{$self->{options_tabs}}) {
# Select the first visible preset, force.
$tab->select_preset(undef, 1);
}
# Load the config over the previously selected defaults.
$self->load_config($config);
for my $tab (values %{$self->{options_tabs}}) {
# Save the settings under a new name, select the name.
$tab->save_preset('My Settings');
}
} else {
# Wizard returned a name of a preset bundle bundled with the installation. Unpack it.
eval { wxTheApp->{preset_bundle}->load_configbundle($directory . '/' . $config . '.ini'); };
Slic3r::GUI::catch_error($self) and return;
# Load the currently selected preset into the GUI, update the preset selection box.
foreach my $tab (values %{$self->{options_tabs}}) {
$tab->load_current_preset;
}
} }
} }
} }

View File

@ -15,6 +15,11 @@ const std::string& var_dir();
// Return a full resource path for a file_name. // Return a full resource path for a file_name.
std::string var(const std::string &file_name); std::string var(const std::string &file_name);
// Set a path with various static definition data (for example the initial config bundles).
void set_resources_dir(const std::string &path);
// Return a full path to the resources directory.
const std::string& resources_dir();
// Set a path with preset files. // Set a path with preset files.
void set_data_dir(const std::string &path); void set_data_dir(const std::string &path);
// Return a full path to the GUI resource files. // Return a full path to the GUI resource files.

View File

@ -89,6 +89,18 @@ std::string var(const std::string &file_name)
return file.string(); return file.string();
} }
static std::string g_resources_dir;
void set_resources_dir(const std::string &dir)
{
g_resources_dir = dir;
}
const std::string& resources_dir()
{
return g_resources_dir;
}
static std::string g_data_dir; static std::string g_data_dir;
void set_data_dir(const std::string &dir) void set_data_dir(const std::string &dir)

View File

@ -60,6 +60,18 @@ var_dir()
RETVAL = const_cast<char*>(Slic3r::var_dir().c_str()); RETVAL = const_cast<char*>(Slic3r::var_dir().c_str());
OUTPUT: RETVAL OUTPUT: RETVAL
void
set_resources_dir(dir)
char *dir;
CODE:
Slic3r::set_resources_dir(dir);
char*
resources_dir()
CODE:
RETVAL = const_cast<char*>(Slic3r::resources_dir().c_str());
OUTPUT: RETVAL
std::string std::string
var(file_name) var(file_name)
const char *file_name; const char *file_name;