Another step towards C++ presets.
This commit is contained in:
parent
7308017ee8
commit
ee645007f2
@ -50,8 +50,9 @@ warn "Running Slic3r under Perl 5.16 is neither supported nor recommended\n"
|
||||
if $^V == v5.16;
|
||||
|
||||
use FindBin;
|
||||
# Path to the images.
|
||||
our $var = sub { decode_path($FindBin::Bin) . "/var/" . $_[0] };
|
||||
|
||||
# Let the XS module know where the GUI resources reside.
|
||||
set_var_dir(decode_path($FindBin::Bin) . "/var");
|
||||
|
||||
use Moo 1.003001;
|
||||
|
||||
|
@ -111,16 +111,6 @@ sub load {
|
||||
}
|
||||
}
|
||||
|
||||
# Deserialize a perl hash into the underlying C++ Slic3r::DynamicConfig class,
|
||||
# convert legacy configuration names.
|
||||
# Used to load a config bundle.
|
||||
sub load_ini_hash {
|
||||
my ($class, $ini_hash) = @_;
|
||||
my $config = $class->new;
|
||||
$config->set_deserialize($_, $ini_hash->{$_}) for keys %$ini_hash;
|
||||
return $config;
|
||||
}
|
||||
|
||||
sub clone {
|
||||
my $self = shift;
|
||||
my $new = (ref $self)->new;
|
||||
@ -135,170 +125,6 @@ sub get_value {
|
||||
: $self->get($opt_key);
|
||||
}
|
||||
|
||||
# Create a hash of hashes from the underlying C++ Slic3r::DynamicPrintConfig.
|
||||
# The first hash key is '_' meaning no category.
|
||||
# Used to create a config bundle.
|
||||
sub as_ini {
|
||||
my ($self) = @_;
|
||||
my $ini = { _ => {} };
|
||||
foreach my $opt_key (sort @{$self->get_keys}) {
|
||||
next if $Options->{$opt_key}{shortcut};
|
||||
$ini->{_}{$opt_key} = $self->serialize($opt_key);
|
||||
}
|
||||
return $ini;
|
||||
}
|
||||
|
||||
# this method is idempotent by design and only applies to ::DynamicConfig or ::Full
|
||||
# objects because it performs cross checks
|
||||
sub validate {
|
||||
my $self = shift;
|
||||
|
||||
# -j, --threads
|
||||
die "Invalid value for --threads\n"
|
||||
if $self->threads < 1;
|
||||
|
||||
# --layer-height
|
||||
die "Invalid value for --layer-height\n"
|
||||
if $self->layer_height <= 0;
|
||||
die "--layer-height must be a multiple of print resolution\n"
|
||||
if $self->layer_height / &Slic3r::SCALING_FACTOR % 1 != 0;
|
||||
|
||||
# --first-layer-height
|
||||
die "Invalid value for --first-layer-height\n"
|
||||
if $self->first_layer_height !~ /^(?:\d*(?:\.\d+)?)%?$/;
|
||||
die "Invalid value for --first-layer-height\n"
|
||||
if $self->get_value('first_layer_height') <= 0;
|
||||
|
||||
# --filament-diameter
|
||||
die "Invalid value for --filament-diameter\n"
|
||||
if grep $_ < 1, @{$self->filament_diameter};
|
||||
|
||||
# --nozzle-diameter
|
||||
die "Invalid value for --nozzle-diameter\n"
|
||||
if grep $_ < 0, @{$self->nozzle_diameter};
|
||||
|
||||
# --perimeters
|
||||
die "Invalid value for --perimeters\n"
|
||||
if $self->perimeters < 0;
|
||||
|
||||
# --solid-layers
|
||||
die "Invalid value for --solid-layers\n" if defined $self->solid_layers && $self->solid_layers < 0;
|
||||
die "Invalid value for --top-solid-layers\n" if $self->top_solid_layers < 0;
|
||||
die "Invalid value for --bottom-solid-layers\n" if $self->bottom_solid_layers < 0;
|
||||
|
||||
# --gcode-flavor
|
||||
die "Invalid value for --gcode-flavor\n"
|
||||
if !first { $_ eq $self->gcode_flavor } @{$Options->{gcode_flavor}{values}};
|
||||
|
||||
die "--use-firmware-retraction is only supported by Marlin, Smoothie, Repetier and Machinekit firmware\n"
|
||||
if $self->use_firmware_retraction && $self->gcode_flavor ne 'smoothie'
|
||||
&& $self->gcode_flavor ne 'reprap'
|
||||
&& $self->gcode_flavor ne 'machinekit'
|
||||
&& $self->gcode_flavor ne 'repetier';
|
||||
|
||||
die "--use-firmware-retraction is not compatible with --wipe\n"
|
||||
if $self->use_firmware_retraction && first {$_} @{$self->wipe};
|
||||
|
||||
# --fill-pattern
|
||||
die "Invalid value for --fill-pattern\n"
|
||||
if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}};
|
||||
|
||||
# --external-fill-pattern
|
||||
die "Invalid value for --external-fill-pattern\n"
|
||||
if !first { $_ eq $self->external_fill_pattern } @{$Options->{external_fill_pattern}{values}};
|
||||
|
||||
# --fill-density
|
||||
die "The selected fill pattern is not supposed to work at 100% density\n"
|
||||
if $self->fill_density == 100
|
||||
&& !first { $_ eq $self->fill_pattern } @{$Options->{external_fill_pattern}{values}};
|
||||
|
||||
# --infill-every-layers
|
||||
die "Invalid value for --infill-every-layers\n"
|
||||
if $self->infill_every_layers !~ /^\d+$/ || $self->infill_every_layers < 1;
|
||||
|
||||
# --skirt-height
|
||||
die "Invalid value for --skirt-height\n"
|
||||
if $self->skirt_height < -1; # -1 means as tall as the object
|
||||
|
||||
# --bridge-flow-ratio
|
||||
die "Invalid value for --bridge-flow-ratio\n"
|
||||
if $self->bridge_flow_ratio <= 0;
|
||||
|
||||
# extruder clearance
|
||||
die "Invalid value for --extruder-clearance-radius\n"
|
||||
if $self->extruder_clearance_radius <= 0;
|
||||
die "Invalid value for --extruder-clearance-height\n"
|
||||
if $self->extruder_clearance_height <= 0;
|
||||
|
||||
# --extrusion-multiplier
|
||||
die "Invalid value for --extrusion-multiplier\n"
|
||||
if defined first { $_ <= 0 } @{$self->extrusion_multiplier};
|
||||
|
||||
# --default-acceleration
|
||||
die "Invalid zero value for --default-acceleration when using other acceleration settings\n"
|
||||
if ($self->perimeter_acceleration || $self->infill_acceleration || $self->bridge_acceleration || $self->first_layer_acceleration)
|
||||
&& !$self->default_acceleration;
|
||||
|
||||
# --spiral-vase
|
||||
if ($self->spiral_vase) {
|
||||
# Note that we might want to have more than one perimeter on the bottom
|
||||
# solid layers.
|
||||
die "Can't make more than one perimeter when spiral vase mode is enabled\n"
|
||||
if $self->perimeters > 1;
|
||||
|
||||
die "Can't make less than one perimeter when spiral vase mode is enabled\n"
|
||||
if $self->perimeters < 1;
|
||||
|
||||
die "Spiral vase mode can only print hollow objects, so you need to set Fill density to 0\n"
|
||||
if $self->fill_density > 0;
|
||||
|
||||
die "Spiral vase mode is not compatible with top solid layers\n"
|
||||
if $self->top_solid_layers > 0;
|
||||
|
||||
die "Spiral vase mode is not compatible with support material\n"
|
||||
if $self->support_material || $self->support_material_enforce_layers > 0;
|
||||
}
|
||||
|
||||
# extrusion widths
|
||||
{
|
||||
my $max_nozzle_diameter = max(@{ $self->nozzle_diameter });
|
||||
die "Invalid extrusion width (too large)\n"
|
||||
if defined first { $_ > 10 * $max_nozzle_diameter }
|
||||
map $self->get_abs_value_over("${_}_extrusion_width", $max_nozzle_diameter),
|
||||
qw(perimeter infill solid_infill top_infill support_material first_layer);
|
||||
}
|
||||
|
||||
# general validation, quick and dirty
|
||||
foreach my $opt_key (@{$self->get_keys}) {
|
||||
my $opt = $Options->{$opt_key};
|
||||
next unless defined $self->$opt_key;
|
||||
next unless defined $opt->{cli} && $opt->{cli} =~ /=(.+)$/;
|
||||
my $type = $1;
|
||||
my @values = ();
|
||||
if ($type =~ s/\@$//) {
|
||||
die "Invalid value for $opt_key\n" if ref($self->$opt_key) ne 'ARRAY';
|
||||
@values = @{ $self->$opt_key };
|
||||
} else {
|
||||
@values = ($self->$opt_key);
|
||||
}
|
||||
foreach my $value (@values) {
|
||||
if ($type eq 'i' || $type eq 'f' || $opt->{type} eq 'percent') {
|
||||
$value =~ s/%$// if $opt->{type} eq 'percent';
|
||||
die "Invalid value for $opt_key\n"
|
||||
if ($type eq 'i' && $value !~ /^-?\d+$/)
|
||||
|| (($type eq 'f' || $opt->{type} eq 'percent') && $value !~ /^-?(?:\d+|\d*\.\d+)$/)
|
||||
|| (defined $opt->{min} && $value < $opt->{min})
|
||||
|| (defined $opt->{max} && $value > $opt->{max});
|
||||
} elsif ($type eq 's' && $opt->{type} eq 'select') {
|
||||
die "Invalid value for $opt_key\n"
|
||||
unless first { $_ eq $value } @{ $opt->{values} };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
# CLASS METHODS:
|
||||
|
||||
# Write a "Windows" style ini file with categories enclosed in squre brackets.
|
||||
|
@ -52,7 +52,6 @@ use constant FILE_WILDCARDS => {
|
||||
};
|
||||
use constant MODEL_WILDCARD => join '|', @{&FILE_WILDCARDS}{qw(known stl obj amf prusa)};
|
||||
|
||||
our $datadir;
|
||||
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
||||
our $no_controller;
|
||||
our $no_plater;
|
||||
@ -84,8 +83,6 @@ our $grey = Wx::Colour->new(200,200,200);
|
||||
|
||||
#our $VERSION_CHECK_EVENT : shared = Wx::NewEventType;
|
||||
|
||||
our $DLP_projection_screen;
|
||||
|
||||
sub OnInit {
|
||||
my ($self) = @_;
|
||||
|
||||
@ -96,16 +93,10 @@ sub OnInit {
|
||||
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
||||
$self->{preset_bundle} = Slic3r::GUI::PresetBundle->new;
|
||||
|
||||
# locate or create data directory
|
||||
# Unix: ~/.Slic3r
|
||||
# Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
|
||||
# Mac: "~/Library/Application Support/Slic3r"
|
||||
$datadir ||= Wx::StandardPaths::Get->GetUserDataDir;
|
||||
my $enc_datadir = Slic3r::encode_path($datadir);
|
||||
Slic3r::debugf "Data directory: %s\n", $datadir;
|
||||
|
||||
# just checking for existence of $datadir is not enough: it may be an empty directory
|
||||
# just checking for existence of Slic3r::data_dir is not enough: it may be an empty directory
|
||||
# supplied as argument to --datadir; in that case we should still run the wizard
|
||||
my $enc_datadir = Slic3r::encode_path(Slic3r::data_dir);
|
||||
Slic3r::debugf "Data directory: %s\n", $enc_datadir;
|
||||
my $run_wizard = (-d $enc_datadir && -e "$enc_datadir/slic3r.ini") ? 0 : 1;
|
||||
foreach my $dir ($enc_datadir, "$enc_datadir/print", "$enc_datadir/filament", "$enc_datadir/printer") {
|
||||
next if -d $dir;
|
||||
@ -119,7 +110,7 @@ sub OnInit {
|
||||
# load settings
|
||||
my $last_version;
|
||||
if (-f "$enc_datadir/slic3r.ini") {
|
||||
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
|
||||
my $ini = eval { Slic3r::Config->read_ini(Slic3r::data_dir . "/slic3r.ini") };
|
||||
$Settings = $ini if $ini;
|
||||
$last_version = $Settings->{_}{version};
|
||||
$Settings->{_}{autocenter} //= 1;
|
||||
@ -132,6 +123,8 @@ sub OnInit {
|
||||
$Settings->{_}{version} = $Slic3r::VERSION;
|
||||
$self->save_settings;
|
||||
|
||||
eval { $self->{preset_bundle}->load_presets(Slic3r::data_dir) };
|
||||
|
||||
# application frame
|
||||
Wx::Image::AddHandler(Wx::PNGHandler->new);
|
||||
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
||||
@ -142,20 +135,21 @@ sub OnInit {
|
||||
$self->SetTopWindow($frame);
|
||||
|
||||
# load init bundle
|
||||
{
|
||||
my @dirs = ($FindBin::Bin);
|
||||
if (&Wx::wxMAC) {
|
||||
push @dirs, qw();
|
||||
} elsif (&Wx::wxMSW) {
|
||||
push @dirs, qw();
|
||||
}
|
||||
my $init_bundle = first { -e $_ } map "$_/.init_bundle.ini", @dirs;
|
||||
if ($init_bundle) {
|
||||
Slic3r::debugf "Loading config bundle from %s\n", $init_bundle;
|
||||
$self->{mainframe}->load_configbundle($init_bundle, 1);
|
||||
$run_wizard = 0;
|
||||
}
|
||||
}
|
||||
#FIXME this is undocumented and the use case is unclear.
|
||||
# {
|
||||
# my @dirs = ($FindBin::Bin);
|
||||
# if (&Wx::wxMAC) {
|
||||
# push @dirs, qw();
|
||||
# } elsif (&Wx::wxMSW) {
|
||||
# push @dirs, qw();
|
||||
# }
|
||||
# my $init_bundle = first { -e $_ } map "$_/.init_bundle.ini", @dirs;
|
||||
# if ($init_bundle) {
|
||||
# Slic3r::debugf "Loading config bundle from %s\n", $init_bundle;
|
||||
# $self->{mainframe}->load_configbundle($init_bundle, 1);
|
||||
# $run_wizard = 0;
|
||||
# }
|
||||
# }
|
||||
|
||||
if (!$run_wizard && (!defined $last_version || $last_version ne $Slic3r::VERSION)) {
|
||||
# user was running another Slic3r version on this computer
|
||||
@ -171,8 +165,10 @@ sub OnInit {
|
||||
. "to Print Settings and click the \"Set\" button next to \"Bed Shape\".", "Bed Shape");
|
||||
}
|
||||
}
|
||||
$self->{mainframe}->config_wizard if $run_wizard;
|
||||
eval { $self->{preset_bundle}->load_presets($datadir) };
|
||||
if ($run_wizard) {
|
||||
$self->{mainframe}->config_wizard;
|
||||
eval { $self->{preset_bundle}->load_presets(Slic3r::data_dir) };
|
||||
}
|
||||
|
||||
# $self->check_version
|
||||
# if $self->have_version_check
|
||||
@ -297,7 +293,7 @@ sub notify {
|
||||
|
||||
sub save_settings {
|
||||
my ($self) = @_;
|
||||
Slic3r::Config->write_ini("$datadir/slic3r.ini", $Settings);
|
||||
Slic3r::Config->write_ini(Slic3r::data_dir . "/slic3r.ini", $Settings);
|
||||
}
|
||||
|
||||
# Called after the Preferences dialog is closed and the program settings are saved.
|
||||
@ -307,48 +303,6 @@ sub update_ui_from_settings {
|
||||
$self->{mainframe}->update_ui_from_settings;
|
||||
}
|
||||
|
||||
sub presets {
|
||||
my ($self, $section) = @_;
|
||||
|
||||
my %presets = ();
|
||||
opendir my $dh, Slic3r::encode_path("$Slic3r::GUI::datadir/$section")
|
||||
or die "Failed to read directory $Slic3r::GUI::datadir/$section (errno: $!)\n";
|
||||
# Instead of using the /i modifier for case-insensitive matching, the case insensitivity is expressed
|
||||
# explicitely to avoid having to bundle the UTF8 Perl library.
|
||||
foreach my $file (grep /\.[iI][nN][iI]$/, readdir $dh) {
|
||||
$file = Slic3r::decode_path($file);
|
||||
my $name = basename($file);
|
||||
$name =~ s/\.ini$//;
|
||||
$presets{$name} = "$Slic3r::GUI::datadir/$section/$file";
|
||||
}
|
||||
closedir $dh;
|
||||
|
||||
return %presets;
|
||||
}
|
||||
|
||||
#sub have_version_check {
|
||||
# my ($self) = @_;
|
||||
#
|
||||
# # return an explicit 0
|
||||
# return ($Slic3r::have_threads && $Slic3r::build && $have_LWP) || 0;
|
||||
#}
|
||||
|
||||
#sub check_version {
|
||||
# my ($self, $manual_check) = @_;
|
||||
#
|
||||
# Slic3r::debugf "Checking for updates...\n";
|
||||
#
|
||||
# @_ = ();
|
||||
# threads->create(sub {
|
||||
# my $ua = LWP::UserAgent->new;
|
||||
# $ua->timeout(10);
|
||||
# my $response = $ua->get('http://slic3r.org/updatecheck');
|
||||
# Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $VERSION_CHECK_EVENT,
|
||||
# threads::shared::shared_clone([ $response->is_success, $response->decoded_content, $manual_check ])));
|
||||
# Slic3r::thread_cleanup();
|
||||
# })->detach;
|
||||
#}
|
||||
|
||||
sub output_path {
|
||||
my ($self, $dir) = @_;
|
||||
|
||||
@ -434,7 +388,7 @@ sub set_menu_item_icon {
|
||||
|
||||
# SetBitmap was not available on OS X before Wx 0.9927
|
||||
if ($icon && $menuItem->can('SetBitmap')) {
|
||||
$menuItem->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG));
|
||||
$menuItem->SetBitmap(Wx::Bitmap->new(Slic3r::var($icon), wxBITMAP_TYPE_PNG));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1390,7 +1390,7 @@ sub _load_image_set_texture {
|
||||
my ($self, $file_name) = @_;
|
||||
# Load a PNG with an alpha channel.
|
||||
my $img = Wx::Image->new;
|
||||
$img->LoadFile($Slic3r::var->($file_name), wxBITMAP_TYPE_PNG);
|
||||
$img->LoadFile(Slic3r::var($file_name), wxBITMAP_TYPE_PNG);
|
||||
# Get RGB & alpha raw data from wxImage, interleave them into a Perl array.
|
||||
my @rgb = unpack 'C*', $img->GetData();
|
||||
my @alpha = $img->HasAlpha ? unpack 'C*', $img->GetAlpha() : (255) x (int(@rgb) / 3);
|
||||
|
@ -97,7 +97,7 @@ sub new {
|
||||
my $class = shift;
|
||||
my $self = $class->SUPER::new(@_);
|
||||
|
||||
$self->{logo} = Wx::Bitmap->new($Slic3r::var->("Slic3r_192px.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{logo} = Wx::Bitmap->new(Slic3r::var("Slic3r_192px.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->SetMinSize(Wx::Size->new($self->{logo}->GetWidth, $self->{logo}->GetHeight));
|
||||
|
||||
EVT_PAINT($self, \&repaint);
|
||||
|
@ -89,11 +89,11 @@ sub new {
|
||||
push @{$self->{titles}}, $title;
|
||||
$self->{own_index} = 0;
|
||||
|
||||
$self->{bullets}->{before} = Wx::Bitmap->new($Slic3r::var->("bullet_black.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{bullets}->{own} = Wx::Bitmap->new($Slic3r::var->("bullet_blue.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{bullets}->{after} = Wx::Bitmap->new($Slic3r::var->("bullet_white.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{bullets}->{before} = Wx::Bitmap->new(Slic3r::var("bullet_black.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{bullets}->{own} = Wx::Bitmap->new(Slic3r::var("bullet_blue.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{bullets}->{after} = Wx::Bitmap->new(Slic3r::var("bullet_white.png"), wxBITMAP_TYPE_PNG);
|
||||
|
||||
$self->{background} = Wx::Bitmap->new($Slic3r::var->("Slic3r_192px_transparent.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->{background} = Wx::Bitmap->new(Slic3r::var("Slic3r_192px_transparent.png"), wxBITMAP_TYPE_PNG);
|
||||
$self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight));
|
||||
|
||||
EVT_PAINT($self, \&repaint);
|
||||
|
@ -32,21 +32,21 @@ sub new {
|
||||
|
||||
# button for adding new printer panels
|
||||
{
|
||||
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("add.png"), wxBITMAP_TYPE_PNG),
|
||||
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("add.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE);
|
||||
$btn->SetToolTipString("Add printer…")
|
||||
if $btn->can('SetToolTipString');
|
||||
|
||||
EVT_LEFT_DOWN($btn, sub {
|
||||
my $menu = Wx::Menu->new;
|
||||
my %presets = wxTheApp->presets('printer');
|
||||
my $presets = wxTheApp->{preset_bundle}->printer->presets_hash;
|
||||
|
||||
# remove printers that already exist
|
||||
my @panels = $self->print_panels;
|
||||
delete $presets{$_} for map $_->printer_name, @panels;
|
||||
delete $presets->{$_} for map $_->printer_name, @panels;
|
||||
|
||||
foreach my $preset_name (sort keys %presets) {
|
||||
my $config = Slic3r::Config->load($presets{$preset_name});
|
||||
foreach my $preset_name (sort keys %{$presets}) {
|
||||
my $config = Slic3r::Config->load($presets->{$preset_name});
|
||||
next if !$config->serial_port;
|
||||
|
||||
my $id = &Wx::NewId();
|
||||
@ -100,9 +100,9 @@ sub OnActivate {
|
||||
# get all available presets
|
||||
my %presets = ();
|
||||
{
|
||||
my %all = wxTheApp->presets('printer');
|
||||
my %configs = map { my $name = $_; $name => Slic3r::Config->load($all{$name}) } keys %all;
|
||||
%presets = map { $_ => $configs{$_} } grep $configs{$_}->serial_port, keys %all;
|
||||
my $all = wxTheApp->{preset_bundle}->printer->presets_hash;
|
||||
my %configs = map { my $name = $_; $name => Slic3r::Config->load($all->{$name}) } keys %{$all};
|
||||
%presets = map { $_ => $configs{$_} } grep $configs{$_}->serial_port, keys %{$all};
|
||||
}
|
||||
|
||||
# decide which ones we want to keep
|
||||
@ -183,8 +183,7 @@ sub print_panels {
|
||||
# Slic3r::GUI::Tab::Printer::_on_presets_changed
|
||||
# when the presets are loaded or the user select another preset.
|
||||
sub update_presets {
|
||||
my $self = shift;
|
||||
my ($group, $presets, $default_suppressed, $selected, $is_dirty) = @_;
|
||||
my ($self, $group, $presets, $default_suppressed, $selected, $is_dirty) = @_;
|
||||
|
||||
# update configs of currently loaded print panels
|
||||
foreach my $panel ($self->print_panels) {
|
||||
|
@ -34,7 +34,7 @@ sub new {
|
||||
my $btn = Wx::Button->new($self, -1, $label, wxDefaultPosition, wxDefaultSize,
|
||||
wxBU_LEFT | wxBU_EXACTFIT);
|
||||
$btn->SetFont($bold ? $Slic3r::GUI::small_bold_font : $Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("$icon.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("$icon.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapPosition($pos);
|
||||
EVT_BUTTON($self, $btn, $handler);
|
||||
$sizer->Add($btn, 1, wxEXPAND | wxALL, 0);
|
||||
|
@ -103,7 +103,7 @@ sub new {
|
||||
$serial_port_sizer->Add($self->{serial_port_combobox}, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1);
|
||||
}
|
||||
{
|
||||
$self->{btn_rescan_serial} = my $btn = Wx::BitmapButton->new($box, -1, Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
|
||||
$self->{btn_rescan_serial} = my $btn = Wx::BitmapButton->new($box, -1, Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE);
|
||||
$btn->SetToolTipString("Rescan serial ports")
|
||||
if $btn->can('SetToolTipString');
|
||||
@ -127,7 +127,7 @@ sub new {
|
||||
{
|
||||
$self->{btn_disconnect} = my $btn = Wx::Button->new($box, -1, "Disconnect", wxDefaultPosition, wxDefaultSize);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG));
|
||||
$serial_speed_sizer->Add($btn, 0, wxLEFT, 5);
|
||||
EVT_BUTTON($self, $btn, \&disconnect);
|
||||
}
|
||||
@ -140,7 +140,7 @@ sub new {
|
||||
my $font = $btn->GetFont;
|
||||
$font->SetPointSize($font->GetPointSize + 2);
|
||||
$btn->SetFont($font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("arrow_up.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("arrow_up.png"), wxBITMAP_TYPE_PNG));
|
||||
$left_sizer->Add($btn, 0, wxTOP, 15);
|
||||
EVT_BUTTON($self, $btn, \&connect);
|
||||
}
|
||||
@ -160,7 +160,7 @@ sub new {
|
||||
{
|
||||
$self->{btn_manual_control} = my $btn = Wx::Button->new($box, -1, "Manual control", wxDefaultPosition, wxDefaultSize);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("cog.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->Hide;
|
||||
$left_sizer->Add($btn, 0, wxTOP, 15);
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
@ -577,7 +577,7 @@ sub new {
|
||||
$btn->SetToolTipString("Delete this job from print queue")
|
||||
if $btn->can('SetToolTipString');
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG));
|
||||
if ($job->printing) {
|
||||
$btn->Hide;
|
||||
}
|
||||
@ -597,8 +597,8 @@ sub new {
|
||||
my $btn = $self->{btn_print} = Wx::Button->new($self, -1, $label, wxDefaultPosition, wxDefaultSize,
|
||||
$button_style);
|
||||
$btn->SetFont($Slic3r::GUI::small_bold_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("control_play.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new($Slic3r::var->("control_play_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("control_play.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new(Slic3r::var("control_play_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
#$btn->SetBitmapPosition(wxRIGHT);
|
||||
$btn->Hide;
|
||||
$buttons_sizer->Add($btn, 0, wxBOTTOM, 2);
|
||||
@ -616,8 +616,8 @@ sub new {
|
||||
if (!$job->printing || $job->paused) {
|
||||
$btn->Hide;
|
||||
}
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("control_pause.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new($Slic3r::var->("control_pause_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("control_pause.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new(Slic3r::var("control_pause_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$buttons_sizer->Add($btn, 0, wxBOTTOM, 2);
|
||||
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
@ -633,8 +633,8 @@ sub new {
|
||||
if (!$job->printing || !$job->paused) {
|
||||
$btn->Hide;
|
||||
}
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("control_play.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new($Slic3r::var->("control_play_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("control_play.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new(Slic3r::var("control_play_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$buttons_sizer->Add($btn, 0, wxBOTTOM, 2);
|
||||
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
@ -650,8 +650,8 @@ sub new {
|
||||
if (!$job->printing) {
|
||||
$btn->Hide;
|
||||
}
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("control_stop.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new($Slic3r::var->("control_stop_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("control_stop.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmapCurrent(Wx::Bitmap->new(Slic3r::var("control_stop_blue.png"), wxBITMAP_TYPE_PNG));
|
||||
$buttons_sizer->Add($btn, 0, wxBOTTOM, 2);
|
||||
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
|
@ -6,6 +6,7 @@ use warnings;
|
||||
use utf8;
|
||||
|
||||
use File::Basename qw(basename dirname);
|
||||
use FindBin;
|
||||
use List::Util qw(min);
|
||||
use Slic3r::Geometry qw(X Y);
|
||||
use Wx qw(:frame :bitmap :id :misc :notebook :panel :sizer :menu :dialog :filedialog
|
||||
@ -22,12 +23,12 @@ sub new {
|
||||
|
||||
my $self = $class->SUPER::new(undef, -1, $Slic3r::FORK_NAME . ' - ' . $Slic3r::VERSION, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
|
||||
if ($^O eq 'MSWin32') {
|
||||
# Load the icon either from the exe, or fron the ico file.
|
||||
my $iconfile = $Slic3r::var->('..\slic3r.exe');
|
||||
$iconfile = $Slic3r::var->("Slic3r.ico") unless -f $iconfile;
|
||||
# Load the icon either from the exe, or from the ico file.
|
||||
my $iconfile = Slic3r::decode_path($FindBin::Bin) . '\slic3r.exe';
|
||||
$iconfile = Slic3r::var("Slic3r.ico") unless -f $iconfile;
|
||||
$self->SetIcon(Wx::Icon->new($iconfile, wxBITMAP_TYPE_ICO));
|
||||
} else {
|
||||
$self->SetIcon(Wx::Icon->new($Slic3r::var->("Slic3r_128px.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->SetIcon(Wx::Icon->new(Slic3r::var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG));
|
||||
}
|
||||
|
||||
# store input params
|
||||
@ -112,7 +113,7 @@ sub _init_tabpanel {
|
||||
# Callback to be executed after any of the configuration fields (Perl class Slic3r::GUI::OptionsGroup::Field) change their value.
|
||||
$tab->on_value_change(sub {
|
||||
my ($opt_key, $value) = @_;
|
||||
my $config = $tab->config;
|
||||
my $config = $tab->{presets}->get_current_preset->config;
|
||||
if ($self->{plater}) {
|
||||
$self->{plater}->on_config_change($config); # propagate config change events to the plater
|
||||
$self->{plater}->on_extruders_change($value) if $opt_key eq 'extruders_count';
|
||||
@ -126,7 +127,7 @@ sub _init_tabpanel {
|
||||
if ($self->{plater}) {
|
||||
# Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs.
|
||||
$self->{plater}->update_presets($tab_name, @_);
|
||||
$self->{plater}->on_config_change($tab->config);
|
||||
$self->{plater}->on_config_change($tab->{presets}->get_current_preset->config);
|
||||
if ($self->{controller}) {
|
||||
$self->{controller}->update_presets($tab_name, @_);
|
||||
}
|
||||
@ -143,7 +144,7 @@ sub _init_tabpanel {
|
||||
});
|
||||
|
||||
# load initial config
|
||||
$self->{plater}->on_config_change($self->config);
|
||||
$self->{plater}->on_config_change(wxTheApp->{preset_bundle}->full_config);
|
||||
}
|
||||
}
|
||||
|
||||
@ -495,7 +496,7 @@ sub repair_stl {
|
||||
sub extra_variables {
|
||||
my $self = shift;
|
||||
my %extra_variables = ();
|
||||
$extra_variables{"${_}_preset"} = $self->{options_tabs}{$_}->get_current_preset->name
|
||||
$extra_variables{"${_}_preset"} = wxTheApp->{preset_bundle}->{$_}->get_current_preset_name
|
||||
for qw(print filament printer);
|
||||
return { %extra_variables };
|
||||
}
|
||||
@ -569,9 +570,9 @@ sub export_configbundle {
|
||||
$ini->{presets} = $Slic3r::GUI::Settings->{presets};
|
||||
|
||||
foreach my $section (qw(print filament printer)) {
|
||||
my %presets = wxTheApp->presets($section);
|
||||
foreach my $preset_name (keys %presets) {
|
||||
my $config = Slic3r::Config->load($presets{$preset_name});
|
||||
my $presets = wxTheApp->{preset_bundle}->$section->presets_hash;
|
||||
foreach my $preset_name (keys %{$presets}) {
|
||||
my $config = Slic3r::Config->load($presets->{$preset_name});
|
||||
$ini->{"$section:$preset_name"} = $config->as_ini->{_};
|
||||
}
|
||||
}
|
||||
@ -616,15 +617,15 @@ sub load_configbundle {
|
||||
next if $skip_no_id && !$config->get($section . "_settings_id");
|
||||
|
||||
{
|
||||
my %current_presets = Slic3r::GUI->presets($section);
|
||||
my $current_presets = wxTheApp->{preset_bundle}->$section->presets_hash;
|
||||
my %current_ids = map { $_ => 1 }
|
||||
grep $_,
|
||||
map Slic3r::Config->load($_)->get($section . "_settings_id"),
|
||||
values %current_presets;
|
||||
values %{$current_presets};
|
||||
next INI_BLOCK if exists $current_ids{$config->get($section . "_settings_id")};
|
||||
}
|
||||
|
||||
$config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $section, $preset_name);
|
||||
$config->save(sprintf Slic3r::data_dir . "/%s/%s.ini", $section, $preset_name);
|
||||
Slic3r::debugf "Imported %s preset %s\n", $section, $preset_name;
|
||||
$imported++;
|
||||
}
|
||||
@ -658,7 +659,8 @@ sub config_wizard {
|
||||
return unless $self->check_unsaved_changes;
|
||||
if (my $config = Slic3r::GUI::ConfigWizard->new($self)->run) {
|
||||
for my $tab (values %{$self->{options_tabs}}) {
|
||||
$tab->select_default_preset;
|
||||
# Select the first visible preset.
|
||||
$tab->select_preset(undef);
|
||||
}
|
||||
$self->load_config($config);
|
||||
for my $tab (values %{$self->{options_tabs}}) {
|
||||
@ -667,84 +669,27 @@ sub config_wizard {
|
||||
}
|
||||
}
|
||||
|
||||
=head2 config
|
||||
|
||||
This method collects all config values from the tabs and merges them into a single config object.
|
||||
|
||||
=cut
|
||||
|
||||
sub config {
|
||||
my $self = shift;
|
||||
|
||||
return Slic3r::Config->new_from_defaults
|
||||
if !exists $self->{options_tabs}{print}
|
||||
|| !exists $self->{options_tabs}{filament}
|
||||
|| !exists $self->{options_tabs}{printer};
|
||||
|
||||
# retrieve filament presets and build a single config object for them
|
||||
my $filament_config;
|
||||
if (!$self->{plater} || $self->{plater}->filament_presets == 1) {
|
||||
$filament_config = $self->{options_tabs}{filament}->config;
|
||||
} else {
|
||||
my $i = -1;
|
||||
foreach my $preset_idx ($self->{plater}->filament_presets) {
|
||||
$i++;
|
||||
my $config;
|
||||
if ($preset_idx == $self->{options_tabs}{filament}->current_preset) {
|
||||
# the selected preset for this extruder is the one in the tab
|
||||
# use the tab's config instead of the preset in case it is dirty
|
||||
# perhaps plater shouldn't expose dirty presets at all in multi-extruder environments.
|
||||
$config = $self->{options_tabs}{filament}->config;
|
||||
} else {
|
||||
my $preset = $self->{options_tabs}{filament}->get_preset($preset_idx);
|
||||
$config = $self->{options_tabs}{filament}->get_preset_config($preset);
|
||||
}
|
||||
if (!$filament_config) {
|
||||
$filament_config = $config->clone;
|
||||
next;
|
||||
}
|
||||
foreach my $opt_key (@{$config->get_keys}) {
|
||||
my $value = $filament_config->get($opt_key);
|
||||
next unless ref $value eq 'ARRAY';
|
||||
$value->[$i] = $config->get($opt_key)->[0];
|
||||
$filament_config->set($opt_key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $config = Slic3r::Config->merge(
|
||||
Slic3r::Config->new_from_defaults,
|
||||
$self->{options_tabs}{print}->config,
|
||||
$self->{options_tabs}{printer}->config,
|
||||
$filament_config,
|
||||
);
|
||||
|
||||
my $extruders_count = $self->{options_tabs}{printer}{extruders_count};
|
||||
$config->set("${_}_extruder", min($config->get("${_}_extruder"), $extruders_count))
|
||||
for qw(perimeter infill solid_infill support_material support_material_interface);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
sub filament_preset_names {
|
||||
my ($self) = @_;
|
||||
return map $self->{options_tabs}{filament}->get_preset($_)->name,
|
||||
return map $self->{options_tabs}{filament}->{presets}->preset($_)->name,
|
||||
$self->{plater}->filament_presets;
|
||||
}
|
||||
|
||||
# This is called when closing the application, when loading a config file or when starting the config wizard
|
||||
# to notify the user whether he is aware that some preset changes will be lost.
|
||||
sub check_unsaved_changes {
|
||||
my $self = shift;
|
||||
|
||||
my @dirty = ();
|
||||
foreach my $tab (values %{$self->{options_tabs}}) {
|
||||
push @dirty, $tab->title if $tab->is_dirty;
|
||||
push @dirty, $tab->title if $tab->{presets}->current_is_dirty;
|
||||
}
|
||||
|
||||
if (@dirty) {
|
||||
my $titles = join ', ', @dirty;
|
||||
my $confirm = Wx::MessageDialog->new($self, "You have unsaved changes ($titles). Discard changes and continue anyway?",
|
||||
'Unsaved Presets', wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT);
|
||||
return ($confirm->ShowModal == wxID_YES);
|
||||
return $confirm->ShowModal == wxID_YES;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -779,7 +724,7 @@ sub _set_menu_item_icon {
|
||||
|
||||
# SetBitmap was not available on OS X before Wx 0.9927
|
||||
if ($icon && $menuItem->can('SetBitmap')) {
|
||||
$menuItem->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG));
|
||||
$menuItem->SetBitmap(Wx::Bitmap->new(Slic3r::var($icon), wxBITMAP_TYPE_PNG));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use Moo;
|
||||
|
||||
has 'growler' => (is => 'rw');
|
||||
|
||||
my $icon = $Slic3r::var->("Slic3r.png");
|
||||
my $icon = Slic3r::var("Slic3r.png");
|
||||
|
||||
sub BUILD {
|
||||
my ($self) = @_;
|
||||
|
@ -166,22 +166,22 @@ sub new {
|
||||
if (!&Wx::wxMSW) {
|
||||
Wx::ToolTip::Enable(1);
|
||||
$self->{htoolbar} = Wx::ToolBar->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_TEXT | wxBORDER_SIMPLE | wxTAB_TRAVERSAL);
|
||||
$self->{htoolbar}->AddTool(TB_ADD, "Add…", Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_REMOVE, "Delete", Wx::Bitmap->new($Slic3r::var->("brick_delete.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_RESET, "Delete All", Wx::Bitmap->new($Slic3r::var->("cross.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_ARRANGE, "Arrange", Wx::Bitmap->new($Slic3r::var->("bricks.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_ADD, "Add…", Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_REMOVE, "Delete", Wx::Bitmap->new(Slic3r::var("brick_delete.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_RESET, "Delete All", Wx::Bitmap->new(Slic3r::var("cross.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_ARRANGE, "Arrange", Wx::Bitmap->new(Slic3r::var("bricks.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddSeparator;
|
||||
$self->{htoolbar}->AddTool(TB_MORE, "More", Wx::Bitmap->new($Slic3r::var->("add.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_FEWER, "Fewer", Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_MORE, "More", Wx::Bitmap->new(Slic3r::var("add.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_FEWER, "Fewer", Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddSeparator;
|
||||
$self->{htoolbar}->AddTool(TB_45CCW, "45° ccw", Wx::Bitmap->new($Slic3r::var->("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_45CW, "45° cw", Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_SCALE, "Scale…", Wx::Bitmap->new($Slic3r::var->("arrow_out.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_SPLIT, "Split", Wx::Bitmap->new($Slic3r::var->("shape_ungroup.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_CUT, "Cut…", Wx::Bitmap->new($Slic3r::var->("package.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_45CCW, "45° ccw", Wx::Bitmap->new(Slic3r::var("arrow_rotate_anticlockwise.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_45CW, "45° cw", Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_SCALE, "Scale…", Wx::Bitmap->new(Slic3r::var("arrow_out.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_SPLIT, "Split", Wx::Bitmap->new(Slic3r::var("shape_ungroup.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_CUT, "Cut…", Wx::Bitmap->new(Slic3r::var("package.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddSeparator;
|
||||
$self->{htoolbar}->AddTool(TB_SETTINGS, "Settings…", Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_LAYER_EDITING, 'Layer Editing', Wx::Bitmap->new($Slic3r::var->("variable_layer_height.png"), wxBITMAP_TYPE_PNG), wxNullBitmap, 1, 0, 'Layer Editing');
|
||||
$self->{htoolbar}->AddTool(TB_SETTINGS, "Settings…", Wx::Bitmap->new(Slic3r::var("cog.png"), wxBITMAP_TYPE_PNG), '');
|
||||
$self->{htoolbar}->AddTool(TB_LAYER_EDITING, 'Layer Editing', Wx::Bitmap->new(Slic3r::var("variable_layer_height.png"), wxBITMAP_TYPE_PNG), wxNullBitmap, 1, 0, 'Layer Editing');
|
||||
} else {
|
||||
my %tbar_buttons = (
|
||||
add => "Add…",
|
||||
@ -256,7 +256,7 @@ sub new {
|
||||
settings cog.png
|
||||
);
|
||||
for (grep $self->{"btn_$_"}, keys %icons) {
|
||||
$self->{"btn_$_"}->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icons{$_}), wxBITMAP_TYPE_PNG));
|
||||
$self->{"btn_$_"}->SetBitmap(Wx::Bitmap->new(Slic3r::var($icons{$_}), wxBITMAP_TYPE_PNG));
|
||||
}
|
||||
$self->selection_changed(0);
|
||||
$self->object_list_changed;
|
||||
@ -414,7 +414,7 @@ sub new {
|
||||
$self->{"object_info_$field"} = Wx::StaticText->new($self, -1, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
|
||||
$self->{"object_info_$field"}->SetFont($Slic3r::GUI::small_font);
|
||||
if ($field eq 'manifold') {
|
||||
$self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new($Slic3r::var->("error.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{object_info_manifold_warning_icon} = Wx::StaticBitmap->new($self, -1, Wx::Bitmap->new(Slic3r::var("error.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{object_info_manifold_warning_icon}->Hide;
|
||||
|
||||
my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
@ -527,7 +527,7 @@ sub _on_select_preset {
|
||||
}
|
||||
|
||||
# get new config and generate on_config_change() event for updating plater and other things
|
||||
$self->on_config_change($self->GetFrame->config);
|
||||
$self->on_config_change(wxTheApp->{preset_bundle}->full_config);
|
||||
}
|
||||
|
||||
sub on_layer_editing_toggled {
|
||||
@ -572,50 +572,51 @@ sub update_ui_from_settings
|
||||
# For Print settings and Printer, synchronize the selection index with their tabs.
|
||||
# For Filament, synchronize the selection index for a single extruder printer only, otherwise keep the selection.
|
||||
sub update_presets {
|
||||
my $self = shift;
|
||||
# $presets: one of qw(print filament printer)
|
||||
# $selected: index of the selected preset in the array. This may not correspond
|
||||
# with the index of selection in the UI element, where not all items are displayed.
|
||||
my ($group, $presets, $default_suppressed, $selected, $is_dirty) = @_;
|
||||
my ($self, $group, $presets, $default_suppressed, $selected, $is_dirty) = @_;
|
||||
|
||||
my @choosers = @{ $self->{preset_choosers}{$group} };
|
||||
my $choice_idx = 0;
|
||||
foreach my $choice (@choosers) {
|
||||
if ($group eq 'filament' && @choosers > 1) {
|
||||
print "Plater.pm update_presets presets: $presets\n";
|
||||
# my @choosers = @{ $self->{preset_choosers}{$group} };
|
||||
# my $choice_idx = 0;
|
||||
# foreach my $choice (@choosers) {
|
||||
# if ($group eq 'filament' && @choosers > 1) {
|
||||
# if we have more than one filament chooser, keep our selection
|
||||
# instead of importing the one from the tab
|
||||
$selected = $choice->GetSelection + $self->{preset_choosers_default_suppressed}{$group};
|
||||
$is_dirty = 0;
|
||||
}
|
||||
$choice->Clear;
|
||||
foreach my $preset (@$presets) {
|
||||
next if ($preset->default && $default_suppressed);
|
||||
my $bitmap;
|
||||
if ($group eq 'filament') {
|
||||
$bitmap = Wx::Bitmap->new($Slic3r::var->("spool.png"), wxBITMAP_TYPE_PNG);
|
||||
} elsif ($group eq 'print') {
|
||||
$bitmap = Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG);
|
||||
} elsif ($group eq 'printer') {
|
||||
$bitmap = Wx::Bitmap->new($Slic3r::var->("printer_empty.png"), wxBITMAP_TYPE_PNG);
|
||||
}
|
||||
$choice->AppendString($preset->name, $bitmap);
|
||||
}
|
||||
# $selected = $choice->GetSelection + $self->{preset_choosers_default_suppressed}{$group};
|
||||
# $is_dirty = 0;
|
||||
# }
|
||||
# $choice->Clear;
|
||||
# foreach my $preset (@{$presets}) {
|
||||
# print "Prset of $presets: $preset\n";
|
||||
# next if ($preset->default && $default_suppressed);
|
||||
# my $bitmap;
|
||||
# if ($group eq 'filament') {
|
||||
# $bitmap = Wx::Bitmap->new(Slic3r::var("spool.png"), wxBITMAP_TYPE_PNG);
|
||||
# } elsif ($group eq 'print') {
|
||||
# $bitmap = Wx::Bitmap->new(Slic3r::var("cog.png"), wxBITMAP_TYPE_PNG);
|
||||
# } elsif ($group eq 'printer') {
|
||||
# $bitmap = Wx::Bitmap->new(Slic3r::var("printer_empty.png"), wxBITMAP_TYPE_PNG);
|
||||
# }
|
||||
# $choice->AppendString($preset->name, $bitmap);
|
||||
# }
|
||||
|
||||
if ($selected <= $#$presets) {
|
||||
my $idx = $selected - $default_suppressed;
|
||||
if ($idx >= 0) {
|
||||
if ($is_dirty) {
|
||||
$choice->SetString($idx, $choice->GetString($idx) . " (modified)");
|
||||
}
|
||||
# call SetSelection() only after SetString() otherwise the new string
|
||||
# won't be picked up as the visible string
|
||||
$choice->SetSelection($idx);
|
||||
}
|
||||
}
|
||||
$choice_idx += 1;
|
||||
}
|
||||
# if ($selected <= $#$presets) {
|
||||
# my $idx = $selected - $default_suppressed;
|
||||
# if ($idx >= 0) {
|
||||
# if ($is_dirty) {
|
||||
# $choice->SetString($idx, $choice->GetString($idx) . " (modified)");
|
||||
# }
|
||||
# # call SetSelection() only after SetString() otherwise the new string
|
||||
# # won't be picked up as the visible string
|
||||
# $choice->SetSelection($idx);
|
||||
# }
|
||||
# }
|
||||
# $choice_idx += 1;
|
||||
# }
|
||||
|
||||
$self->{preset_choosers_default_suppressed}{$group} = $default_suppressed;
|
||||
# $self->{preset_choosers_default_suppressed}{$group} = $default_suppressed;
|
||||
|
||||
wxTheApp->CallAfter(sub { $self->update_filament_colors_preview }) if $group eq 'filament' || $group eq 'printer';
|
||||
}
|
||||
@ -626,63 +627,65 @@ sub update_presets {
|
||||
sub update_filament_colors_preview {
|
||||
my ($self, $extruder_idx) = shift;
|
||||
|
||||
my @choosers = @{$self->{preset_choosers}{filament}};
|
||||
# my @choosers = @{$self->{preset_choosers}{filament}};
|
||||
|
||||
if (ref $extruder_idx) {
|
||||
# if (ref $extruder_idx) {
|
||||
# $extruder_idx is the chooser.
|
||||
foreach my $chooser (@choosers) {
|
||||
if ($extruder_idx == $chooser) {
|
||||
$extruder_idx = $chooser;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
# foreach my $chooser (@choosers) {
|
||||
# if ($extruder_idx == $chooser) {
|
||||
# $extruder_idx = $chooser;
|
||||
# last;
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
my @extruder_colors = @{$self->{config}->extruder_colour};
|
||||
# my @extruder_colors = @{$self->{config}->extruder_colour};
|
||||
|
||||
my @extruder_list;
|
||||
if (defined $extruder_idx) {
|
||||
@extruder_list = ($extruder_idx);
|
||||
} else {
|
||||
# my @extruder_list;
|
||||
# if (defined $extruder_idx) {
|
||||
# @extruder_list = ($extruder_idx);
|
||||
# } else {
|
||||
# Collect extruder indices.
|
||||
@extruder_list = (0..$#extruder_colors);
|
||||
}
|
||||
# @extruder_list = (0..$#extruder_colors);
|
||||
# }
|
||||
|
||||
my $filament_tab = $self->GetFrame->{options_tabs}{filament};
|
||||
my $presets = $filament_tab->{presets};
|
||||
my $default_suppressed = $filament_tab->{default_suppressed};
|
||||
# my $filament_tab = $self->GetFrame->{options_tabs}{filament};
|
||||
# my $presets = $filament_tab->{presets};
|
||||
# my $default_suppressed = $filament_tab->{default_suppressed};
|
||||
|
||||
foreach my $extruder_idx (@extruder_list) {
|
||||
my $chooser = $choosers[$extruder_idx];
|
||||
my $extruder_color = $self->{config}->extruder_colour->[$extruder_idx];
|
||||
my $preset_idx = 0;
|
||||
my $selection_idx = $chooser->GetSelection;
|
||||
foreach my $preset (@$presets) {
|
||||
my $bitmap;
|
||||
if ($preset->default) {
|
||||
next if $default_suppressed;
|
||||
} else {
|
||||
# foreach my $extruder_idx (@extruder_list) {
|
||||
# my $chooser = $choosers[$extruder_idx];
|
||||
# my $extruder_color = $self->{config}->extruder_colour->[$extruder_idx];
|
||||
# my $preset_idx = 0;
|
||||
# my $selection_idx = $chooser->GetSelection;
|
||||
# foreach my $preset (@$presets) {
|
||||
# my $bitmap;
|
||||
# if ($preset->default) {
|
||||
# next if $default_suppressed;
|
||||
# } else {
|
||||
# Assign an extruder color to the selected item if the extruder color is defined.
|
||||
my $filament_rgb = $preset->config(['filament_colour'])->filament_colour->[0];
|
||||
my $extruder_rgb = ($preset_idx == $selection_idx && $extruder_color =~ m/^#[[:xdigit:]]{6}/) ? $extruder_color : $filament_rgb;
|
||||
$filament_rgb =~ s/^#//;
|
||||
$extruder_rgb =~ s/^#//;
|
||||
my $image = Wx::Image->new(24,16);
|
||||
if ($filament_rgb ne $extruder_rgb) {
|
||||
my @rgb = unpack 'C*', pack 'H*', $extruder_rgb;
|
||||
$image->SetRGB(Wx::Rect->new(0,0,16,16), @rgb);
|
||||
@rgb = unpack 'C*', pack 'H*', $filament_rgb;
|
||||
$image->SetRGB(Wx::Rect->new(16,0,8,16), @rgb);
|
||||
} else {
|
||||
my @rgb = unpack 'C*', pack 'H*', $filament_rgb;
|
||||
$image->SetRGB(Wx::Rect->new(0,0,24,16), @rgb);
|
||||
}
|
||||
$bitmap = Wx::Bitmap->new($image);
|
||||
}
|
||||
$chooser->SetItemBitmap($preset_idx, $bitmap) if $bitmap;
|
||||
$preset_idx += 1;
|
||||
}
|
||||
}
|
||||
# my $filament_colour_cfg = $preset->config_ref->filament_colour;
|
||||
# print $filament_colour_cfg . "\n";
|
||||
# my $filament_rgb = $filament_colour_cfg->[0];
|
||||
# my $extruder_rgb = ($preset_idx == $selection_idx && $extruder_color =~ m/^#[[:xdigit:]]{6}/) ? $extruder_color : $filament_rgb;
|
||||
# $filament_rgb =~ s/^#//;
|
||||
# $extruder_rgb =~ s/^#//;
|
||||
# my $image = Wx::Image->new(24,16);
|
||||
# if ($filament_rgb ne $extruder_rgb) {
|
||||
# my @rgb = unpack 'C*', pack 'H*', $extruder_rgb;
|
||||
# $image->SetRGB(Wx::Rect->new(0,0,16,16), @rgb);
|
||||
# @rgb = unpack 'C*', pack 'H*', $filament_rgb;
|
||||
# $image->SetRGB(Wx::Rect->new(16,0,8,16), @rgb);
|
||||
# } else {
|
||||
# my @rgb = unpack 'C*', pack 'H*', $filament_rgb;
|
||||
# $image->SetRGB(Wx::Rect->new(0,0,24,16), @rgb);
|
||||
# }
|
||||
# $bitmap = Wx::Bitmap->new($image);
|
||||
# }
|
||||
# $chooser->SetItemBitmap($preset_idx, $bitmap) if $bitmap;
|
||||
# $preset_idx += 1;
|
||||
# }
|
||||
# }
|
||||
}
|
||||
|
||||
# Return a vector of indices of filaments selected by the $self->{preset_choosers}{filament} combo boxes.
|
||||
@ -1163,7 +1166,7 @@ sub arrange {
|
||||
$self->pause_background_process;
|
||||
|
||||
my $bb = Slic3r::Geometry::BoundingBoxf->new_from_points($self->{config}->bed_shape);
|
||||
my $success = $self->{model}->arrange_objects($self->GetFrame->config->min_object_distance, $bb);
|
||||
my $success = $self->{model}->arrange_objects(wxTheApp->{preset_bundle}->full_config->min_object_distance, $bb);
|
||||
# ignore arrange failures on purpose: user has visual feedback and we don't need to warn him
|
||||
# when parts don't fit in print bed
|
||||
|
||||
@ -1224,7 +1227,7 @@ sub async_apply_config {
|
||||
$self->pause_background_process;
|
||||
|
||||
# apply new config
|
||||
my $invalidated = $self->{print}->apply_config($self->GetFrame->config);
|
||||
my $invalidated = $self->{print}->apply_config(wxTheApp->{preset_bundle}->full_config);
|
||||
|
||||
# Just redraw the 3D canvas without reloading the scene.
|
||||
# $self->{canvas3D}->Refresh if ($invalidated && $self->{canvas3D}->layer_editing_enabled);
|
||||
@ -1266,7 +1269,7 @@ sub start_background_process {
|
||||
# don't start process thread if config is not valid
|
||||
eval {
|
||||
# this will throw errors if config is not valid
|
||||
$self->GetFrame->config->validate;
|
||||
wxTheApp->{preset_bundle}->full_config->validate;
|
||||
$self->{print}->validate;
|
||||
};
|
||||
if ($@) {
|
||||
@ -1378,14 +1381,14 @@ sub export_gcode {
|
||||
# (we assume that if it is running, config is valid)
|
||||
eval {
|
||||
# this will throw errors if config is not valid
|
||||
$self->GetFrame->config->validate;
|
||||
wxTheApp->{preset_bundle}->full_config->validate;
|
||||
$self->{print}->validate;
|
||||
};
|
||||
Slic3r::GUI::catch_error($self) and return;
|
||||
|
||||
|
||||
# apply config and validate print
|
||||
my $config = $self->GetFrame->config;
|
||||
my $config = wxTheApp->{preset_bundle}->full_config;
|
||||
eval {
|
||||
# this will throw errors if config is not valid
|
||||
$config->validate;
|
||||
@ -1549,11 +1552,9 @@ sub on_export_completed {
|
||||
sub do_print {
|
||||
my ($self) = @_;
|
||||
|
||||
my $printer_tab = $self->GetFrame->{options_tabs}{printer};
|
||||
my $printer_name = $printer_tab->get_current_preset->name;
|
||||
|
||||
my $controller = $self->GetFrame->{controller};
|
||||
my $printer_panel = $controller->add_printer($printer_name, $printer_tab->config);
|
||||
my $printer_preset = wxTheApp->{preset_bundle}->printer->get_edited_preset;
|
||||
my $printer_panel = $controller->add_printer($printer_preset->name, $printer_preset->config);
|
||||
|
||||
my $filament_stats = $self->{print}->filament_stats;
|
||||
my @filament_names = $self->GetFrame->filament_preset_names;
|
||||
@ -1859,7 +1860,7 @@ sub filament_color_box_lmouse_down
|
||||
my $dialog = Wx::ColourDialog->new($self->GetFrame, $data);
|
||||
if ($dialog->ShowModal == wxID_OK) {
|
||||
my $cfg = Slic3r::Config->new;
|
||||
my $colors = $self->GetFrame->config->get('extruder_colour');
|
||||
my $colors = wxTheApp->{preset_bundle}->full_config->get('extruder_colour');
|
||||
$colors->[$extruder_idx] = $dialog->GetColourData->GetColour->GetAsString(wxC2S_HTML_SYNTAX);
|
||||
$cfg->set('extruder_colour', $colors);
|
||||
$self->GetFrame->{options_tabs}{printer}->load_config($cfg);
|
||||
@ -1912,7 +1913,7 @@ sub object_settings_dialog {
|
||||
my $dlg = Slic3r::GUI::Plater::ObjectSettingsDialog->new($self,
|
||||
object => $self->{objects}[$obj_idx],
|
||||
model_object => $model_object,
|
||||
config => $self->GetFrame->config,
|
||||
config => wxTheApp->{preset_bundle}->full_config,
|
||||
);
|
||||
$self->pause_background_process;
|
||||
$dlg->ShowModal;
|
||||
@ -2048,18 +2049,14 @@ sub selected_object {
|
||||
}
|
||||
|
||||
sub validate_config {
|
||||
my $self = shift;
|
||||
|
||||
eval {
|
||||
$self->GetFrame->config->validate;
|
||||
wxTheApp->{preset_bundle}->full_config->validate;
|
||||
};
|
||||
return 0 if Slic3r::GUI::catch_error($self);
|
||||
return 1;
|
||||
return Slic3r::GUI::catch_error($_[0]) ? 0 : 1;
|
||||
}
|
||||
|
||||
sub statusbar {
|
||||
my $self = shift;
|
||||
return $self->GetFrame->{statusbar};
|
||||
return $_[0]->GetFrame->{statusbar};
|
||||
}
|
||||
|
||||
sub object_menu {
|
||||
|
@ -42,9 +42,9 @@ sub new {
|
||||
{
|
||||
$self->{tree_icons} = Wx::ImageList->new(16, 16, 1);
|
||||
$tree->AssignImageList($self->{tree_icons});
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new($Slic3r::var->("brick.png"), wxBITMAP_TYPE_PNG)); # ICON_OBJECT
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new($Slic3r::var->("package.png"), wxBITMAP_TYPE_PNG)); # ICON_SOLIDMESH
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new($Slic3r::var->("plugin.png"), wxBITMAP_TYPE_PNG)); # ICON_MODIFIERMESH
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("brick.png"), wxBITMAP_TYPE_PNG)); # ICON_OBJECT
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("package.png"), wxBITMAP_TYPE_PNG)); # ICON_SOLIDMESH
|
||||
$self->{tree_icons}->Add(Wx::Bitmap->new(Slic3r::var("plugin.png"), wxBITMAP_TYPE_PNG)); # ICON_MODIFIERMESH
|
||||
|
||||
my $rootId = $tree->AddRoot("Object", ICON_OBJECT);
|
||||
$tree->SetPlData($rootId, { type => 'object' });
|
||||
@ -58,13 +58,13 @@ sub new {
|
||||
$self->{btn_split} = Wx::Button->new($self, -1, "Split part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
$self->{btn_move_up} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
|
||||
$self->{btn_move_down} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
|
||||
$self->{btn_load_part}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_modifier}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_lambda_modifier}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_delete}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_delete.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_split}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("shape_ungroup.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_move_up}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("bullet_arrow_up.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_move_down}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("bullet_arrow_down.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_part}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_modifier}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_lambda_modifier}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_delete}->SetBitmap(Wx::Bitmap->new(Slic3r::var("brick_delete.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_split}->SetBitmap(Wx::Bitmap->new(Slic3r::var("shape_ungroup.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_move_up}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_up.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_move_down}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_down.png"), wxBITMAP_TYPE_PNG));
|
||||
|
||||
# buttons sizer
|
||||
my $buttons_sizer = Wx::GridSizer->new(2, 3);
|
||||
|
@ -46,7 +46,7 @@ sub new {
|
||||
# option selector
|
||||
{
|
||||
# create the button
|
||||
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("add.png"), wxBITMAP_TYPE_PNG),
|
||||
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("add.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE);
|
||||
EVT_LEFT_DOWN($btn, sub {
|
||||
my $menu = Wx::Menu->new;
|
||||
@ -146,7 +146,7 @@ sub update_optgroup {
|
||||
# disallow deleting fixed options
|
||||
return undef if $self->{fixed_options}{$opt_key};
|
||||
|
||||
my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG),
|
||||
my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE);
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
$self->{config}->erase($opt_key);
|
||||
|
@ -24,12 +24,8 @@ use Wx qw(:bookctrl :dialog :keycode :icon :id :misc :panel :sizer :treectrl :wi
|
||||
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_KEY_DOWN EVT_CHECKBOX EVT_TREE_SEL_CHANGED);
|
||||
use base qw(Wx::Panel Class::Accessor);
|
||||
|
||||
# Index of the currently active preset.
|
||||
__PACKAGE__->mk_accessors(qw(current_preset));
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent, %params) = @_;
|
||||
my ($class, $parent, %params) = @_;
|
||||
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
|
||||
|
||||
# Vertical sizer to hold the choice menu and the rest of the page.
|
||||
@ -45,9 +41,9 @@ sub new {
|
||||
$self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
|
||||
|
||||
# buttons
|
||||
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("disk.png"), wxBITMAP_TYPE_PNG),
|
||||
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("disk.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG),
|
||||
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new(Slic3r::var("delete.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
$self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
|
||||
$self->{btn_delete_preset}->SetToolTipString("Delete this preset");
|
||||
@ -97,54 +93,18 @@ sub new {
|
||||
});
|
||||
|
||||
EVT_CHOICE($parent, $self->{presets_choice}, sub {
|
||||
$self->on_select_preset;
|
||||
$self->select_preset($self->{presets_choice}->GetStringSelection);
|
||||
$self->_on_presets_changed;
|
||||
});
|
||||
|
||||
EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset });
|
||||
EVT_BUTTON($self, $self->{btn_delete_preset}, sub { $self->delete_preset });
|
||||
|
||||
EVT_BUTTON($self, $self->{btn_delete_preset}, sub {
|
||||
my $i = $self->current_preset;
|
||||
# Don't let the user delete the '- default -' configuration.
|
||||
# This shall not happen as the 'delete' button is disabled for the '- default -' entry,
|
||||
# but better be safe than sorry.
|
||||
return if ($i == 0 && $self->get_current_preset->{default});
|
||||
my $res = Wx::MessageDialog->new($self, "Are you sure you want to delete the selected preset?", 'Delete Preset', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal;
|
||||
return unless $res == wxID_YES;
|
||||
# Delete the file.
|
||||
my $path = $self->{presets}[$i]->file;
|
||||
my $enc_path = Slic3r::encode_path($path);
|
||||
if (-e $enc_path && ! unlink $enc_path) {
|
||||
# Cannot delete the file, therefore the item will not be removed from the selection.
|
||||
Slic3r::GUI::show_error($self, "Cannot delete file $path : $!");
|
||||
return;
|
||||
}
|
||||
# Delete the preset.
|
||||
splice @{$self->{presets}}, $i, 1;
|
||||
# Delete the item from the UI component.
|
||||
$self->{presets_choice}->Delete($i - $self->{default_suppressed});
|
||||
$self->current_preset(undef);
|
||||
if ($self->{default_suppressed} && scalar(@{$self->{presets}}) == 1) {
|
||||
# Empty selection. Add the '- default -' item into the drop down selection.
|
||||
$self->{presets_choice}->Append($self->{presets}->[0]->name);
|
||||
# and remember that the '- default -' is shown.
|
||||
$self->{default_suppressed} = 0;
|
||||
}
|
||||
# Select the 0th item. If default is suppressed, select the first valid.
|
||||
$self->select_preset($self->{default_suppressed});
|
||||
$self->_on_presets_changed;
|
||||
});
|
||||
|
||||
# C++ instance DynamicPrintConfig
|
||||
$self->{config} = Slic3r::Config->new;
|
||||
# Initialize the DynamicPrintConfig by default keys/values.
|
||||
# Possible %params keys: no_controller
|
||||
$self->build(%params);
|
||||
$self->update_tree;
|
||||
$self->_update;
|
||||
if ($self->hidden_options) {
|
||||
$self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -154,18 +114,6 @@ sub no_defaults {
|
||||
return $Slic3r::GUI::Settings->{_}{no_defaults} ? 1 : 0;
|
||||
}
|
||||
|
||||
# Get a currently active preset (Perl class Slic3r::GUI::Tab::Preset).
|
||||
sub get_current_preset {
|
||||
my $self = shift;
|
||||
return $self->get_preset($self->current_preset);
|
||||
}
|
||||
|
||||
# Get a preset (Perl class Slic3r::GUI::Tab::Preset) with an index $i.
|
||||
sub get_preset {
|
||||
my ($self, $i) = @_;
|
||||
return $self->{presets}[$i];
|
||||
}
|
||||
|
||||
sub save_preset {
|
||||
my ($self, $name) = @_;
|
||||
|
||||
@ -175,7 +123,7 @@ sub save_preset {
|
||||
$self->{treectrl}->SetFocus;
|
||||
|
||||
if (!defined $name) {
|
||||
my $preset = $self->get_current_preset;
|
||||
my $preset = $self->{presets}->get_edited_preset;
|
||||
my $default_name = $preset->default ? 'Untitled' : $preset->name;
|
||||
$default_name =~ s/\.[iI][nN][iI]$//;
|
||||
|
||||
@ -185,12 +133,27 @@ sub save_preset {
|
||||
values => [ map $_->name, grep !$_->default && !$_->external, @{$self->{presets}} ],
|
||||
);
|
||||
return unless $dlg->ShowModal == wxID_OK;
|
||||
$name = $dlg->get_name;
|
||||
$name = Slic3r::normalize_utf8_nfc($dlg->get_name);
|
||||
}
|
||||
|
||||
$self->config->save(sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $name);
|
||||
$self->{config}->save(sprintf Slic3r::data_dir . "/%s/%s.ini", $self->name, $name);
|
||||
$self->load_presets;
|
||||
$self->select_preset_by_name($name);
|
||||
$self->select_preset($name);
|
||||
$self->_on_presets_changed;
|
||||
}
|
||||
|
||||
# Called for a currently selected preset.
|
||||
sub delete_preset {
|
||||
my ($self) = @_;
|
||||
my $current_preset = $self->{presets}->get_selected_preset;
|
||||
# Don't let the user delete the '- default -' configuration.
|
||||
return if $current_preset->{default} ||
|
||||
wxID_YES == Wx::MessageDialog->new($self, "Are you sure you want to delete the selected preset?", 'Delete Preset', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal;
|
||||
# Delete the file and select some other reasonable preset.
|
||||
eval { $self->{presets}->delete_file($current_preset->name); };
|
||||
Slic3r::GUI::catch_error($self) and return;
|
||||
# Delete the item from the UI component.
|
||||
$self->{presets}->update_platter_ui($self->{presets_choice});
|
||||
$self->_on_presets_changed;
|
||||
}
|
||||
|
||||
@ -210,115 +173,78 @@ sub on_presets_changed {
|
||||
sub _on_value_change {
|
||||
my ($self, $key, $value) = @_;
|
||||
$self->{on_value_change}->($key, $value) if $self->{on_value_change};
|
||||
$self->_update({ $key => 1 });
|
||||
$self->_update;
|
||||
}
|
||||
|
||||
# Override this to capture changes of configuration caused either by loading or switching a preset,
|
||||
# or by a user changing an option field.
|
||||
sub _update {}
|
||||
|
||||
# Call a callback to update the selection of presets on the platter.
|
||||
sub _on_presets_changed {
|
||||
my $self = shift;
|
||||
|
||||
my ($self) = @_;
|
||||
$self->{on_presets_changed}->(
|
||||
$self->{presets},
|
||||
$self->{default_suppressed},
|
||||
scalar($self->{presets_choice}->GetSelection) + $self->{default_suppressed},
|
||||
$self->is_dirty,
|
||||
$self->{presets}->current_is_dirty,
|
||||
) if $self->{on_presets_changed};
|
||||
}
|
||||
|
||||
sub on_preset_loaded {}
|
||||
sub hidden_options {}
|
||||
sub config { $_[0]->{config}->clone }
|
||||
|
||||
sub select_default_preset {
|
||||
my $self = shift;
|
||||
$self->select_preset(0);
|
||||
}
|
||||
|
||||
# Called by the UI combo box when the user switches profiles.
|
||||
# Select a preset by a name. If ! defined(name), then the first visible preset is selected.
|
||||
# If the current profile is modified, user is asked to save the changes.
|
||||
sub select_preset {
|
||||
my ($self, $i) = @_;
|
||||
if ($self->{default_suppressed} && $i == 0) {
|
||||
# Selecting the '- default -'. Add it to the combo box.
|
||||
$self->{default_suppressed} = 0;
|
||||
$self->{presets_choice}->Insert($self->{presets}->[0]->name, 0);
|
||||
} elsif ($self->no_defaults && ! $self->{default_suppressed} && $i > 0) {
|
||||
# The user wants to hide the '- default -' items and a non-default item has been added to the presets.
|
||||
# Hide the '- default -' item.
|
||||
$self->{presets_choice}->Delete(0);
|
||||
$self->{default_suppressed} = 1;
|
||||
}
|
||||
$self->{presets_choice}->SetSelection($i - $self->{default_suppressed});
|
||||
$self->on_select_preset;
|
||||
}
|
||||
|
||||
sub select_preset_by_name {
|
||||
my ($self, $name) = @_;
|
||||
|
||||
$name = Slic3r::normalize_utf8_nfc($name);
|
||||
$self->select_preset(first { $self->{presets}[$_]->name eq $name } 0 .. $#{$self->{presets}});
|
||||
}
|
||||
|
||||
sub on_select_preset {
|
||||
my $self = shift;
|
||||
|
||||
if ($self->is_dirty) {
|
||||
if ($self->{presets}->current_is_dirty) {
|
||||
# Display a dialog showing the dirty options in a human readable form.
|
||||
my $old_preset = $self->get_current_preset;
|
||||
my $old_preset = $self->{presets}->get_current_preset;
|
||||
my $name = $old_preset->default ? 'Default preset' : "Preset \"" . $old_preset->name . "\"";
|
||||
|
||||
# Collect descriptions of the dirty options.
|
||||
my @option_names = ();
|
||||
foreach my $opt_key (@{$self->dirty_options}) {
|
||||
foreach my $opt_key (@{$self->{presets}->current_dirty_options}) {
|
||||
my $opt = $Slic3r::Config::Options->{$opt_key};
|
||||
my $name = $opt->{full_label} // $opt->{label};
|
||||
if ($opt->{category}) {
|
||||
$name = $opt->{category} . " > $name";
|
||||
}
|
||||
$name = $opt->{category} . " > $name" if $opt->{category};
|
||||
push @option_names, $name;
|
||||
}
|
||||
|
||||
# Show a confirmation dialog with the list of dirty options.
|
||||
my $changes = join "\n", map "- $_", @option_names;
|
||||
my $confirm = Wx::MessageDialog->new($self, "$name has unsaved changes:\n$changes\n\nDiscard changes and continue anyway?",
|
||||
'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||
if ($confirm->ShowModal == wxID_NO) {
|
||||
$self->{presets_choice}->SetSelection($self->current_preset - $self->{default_suppressed});
|
||||
|
||||
# trigger the on_presets_changed event so that we also restore the previous value
|
||||
# in the plater selector
|
||||
$self->{presets}->update_platter_ui($self->{presets_choice});
|
||||
# Trigger the on_presets_changed event so that we also restore the previous value in the plater selector.
|
||||
$self->_on_presets_changed;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$self->current_preset($self->{presets_choice}->GetSelection + $self->{default_suppressed});
|
||||
my $preset = $self->get_current_preset;
|
||||
my $preset_config = $self->get_preset_config($preset);
|
||||
$self->{presets}->select_by_name_ui(defined $name ? $name : "", $self->{presets_choice});
|
||||
my $preset = $self->{presets}->get_current_preset;
|
||||
my $preset_config = $preset->config;
|
||||
eval {
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
my %keys_modified = ();
|
||||
foreach my $opt_key (@{$self->{config}->get_keys}) {
|
||||
if ($preset_config->has($opt_key)) {
|
||||
if ($self->{config}->serialize($opt_key) ne $preset_config->serialize($opt_key)) {
|
||||
if ($preset_config->has($opt_key) &&
|
||||
$self->{config}->serialize($opt_key) ne $preset_config->serialize($opt_key)) {
|
||||
$self->{config}->set($opt_key, $preset_config->get($opt_key));
|
||||
$keys_modified{$opt_key} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
($preset->default || $preset->external)
|
||||
? $self->{btn_delete_preset}->Disable
|
||||
: $self->{btn_delete_preset}->Enable;
|
||||
|
||||
$self->_update(\%keys_modified);
|
||||
$self->_update;
|
||||
# For the printer profile, generate the extruder pages.
|
||||
$self->on_preset_loaded;
|
||||
# Reload preset pages with the new configuration values.
|
||||
$self->reload_config;
|
||||
# Use this preset the next time Slic3r starts.
|
||||
$Slic3r::GUI::Settings->{presets}{$self->name} = $preset->file ? basename($preset->file) : '';
|
||||
};
|
||||
if ($@) {
|
||||
$@ = "I was unable to load the selected config file: $@";
|
||||
Slic3r::GUI::catch_error($self);
|
||||
$self->select_default_preset;
|
||||
}
|
||||
|
||||
# use CallAfter because some field triggers schedule on_change calls using CallAfter,
|
||||
# and we don't want them to be called after this update_dirty() as they would mark the
|
||||
@ -329,20 +255,16 @@ sub on_select_preset {
|
||||
$self->update_dirty;
|
||||
});
|
||||
|
||||
# Save the current application settings with the newly selected preset name.
|
||||
wxTheApp->save_settings;
|
||||
}
|
||||
|
||||
sub init_config_options {
|
||||
my ($self, @opt_keys) = @_;
|
||||
$self->{config}->apply(Slic3r::Config->new_from_defaults(@opt_keys));
|
||||
}
|
||||
|
||||
sub add_options_page {
|
||||
my $self = shift;
|
||||
my ($title, $icon, %params) = @_;
|
||||
|
||||
if ($icon) {
|
||||
my $bitmap = Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG);
|
||||
my $bitmap = Wx::Bitmap->new(Slic3r::var($icon), wxBITMAP_TYPE_PNG);
|
||||
$self->{icons}->Add($bitmap);
|
||||
$self->{iconcount}++;
|
||||
}
|
||||
@ -354,8 +276,9 @@ sub add_options_page {
|
||||
return $page;
|
||||
}
|
||||
|
||||
# Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields.
|
||||
sub reload_config {
|
||||
my $self = shift;
|
||||
my ($self) = @_;
|
||||
$_->reload_config for @{$self->{pages}};
|
||||
}
|
||||
|
||||
@ -388,87 +311,40 @@ sub update_tree {
|
||||
# comparing the selected preset config with $self->{config}.
|
||||
sub update_dirty {
|
||||
my ($self) = @_;
|
||||
my $list_updated;
|
||||
foreach my $i ($self->{default_suppressed}..$#{$self->{presets}}) {
|
||||
my $preset = $self->get_preset($i);
|
||||
my $label = ($i == $self->current_preset && $self->is_dirty) ? $preset->name . " (modified)" : $preset->name;
|
||||
my $idx = $i - $self->{default_suppressed};
|
||||
if ($self->{presets_choice}->GetString($idx) ne $label) {
|
||||
$self->{presets_choice}->SetString($idx, $label);
|
||||
$list_updated = 1;
|
||||
}
|
||||
}
|
||||
$self->{presets_choice}->SetSelection($self->current_preset - $self->{default_suppressed}) if ($list_updated); # http://trac.wxwidgets.org/ticket/13769
|
||||
$self->{presets}->update_dirty_ui($self->{presets_choice});
|
||||
$self->_on_presets_changed;
|
||||
}
|
||||
|
||||
# Has the selected preset been modified?
|
||||
sub is_dirty {
|
||||
my ($self) = @_;
|
||||
return @{$self->dirty_options} > 0;
|
||||
}
|
||||
|
||||
# Which options of the selected preset were modified?
|
||||
sub dirty_options {
|
||||
my ($self) = @_;
|
||||
return [] if !defined $self->current_preset; # happens during initialization
|
||||
return $self->get_preset_config($self->get_current_preset)->diff($self->{config});
|
||||
}
|
||||
|
||||
# Search all ini files in the presets directory, add them into the list of $self->{presets} in the form of Slic3r::GUI::Tab::Preset.
|
||||
# Initialize the drop down list box.
|
||||
sub load_presets {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{presets} = [
|
||||
Slic3r::GUI::Tab::Preset->new(
|
||||
default => 1,
|
||||
name => '- default -',
|
||||
),
|
||||
];
|
||||
print "Load presets, ui: " . $self->{presets_choice} . "\n";
|
||||
# $self->current_preset(undef);
|
||||
# $self->{presets}->set_default_suppressed(Slic3r::GUI::Tab->no_defaults);
|
||||
# $self->{presets_choice}->Clear;
|
||||
# foreach my $preset (@{$self->{presets}}) {
|
||||
# if ($preset->visible) {
|
||||
# # Set client data of the choice item to $preset.
|
||||
# $self->{presets_choice}->Append($preset->name, $preset);
|
||||
# }
|
||||
# }
|
||||
# {
|
||||
# # load last used preset
|
||||
# my $i = first { basename($self->{presets}[$_]->file) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
|
||||
# $self->select_preset($i || $self->{default_suppressed});
|
||||
# }
|
||||
|
||||
my %presets = wxTheApp->presets($self->name);
|
||||
foreach my $preset_name (sort keys %presets) {
|
||||
push @{$self->{presets}}, Slic3r::GUI::Tab::Preset->new(
|
||||
name => $preset_name,
|
||||
file => $presets{$preset_name},
|
||||
);
|
||||
}
|
||||
$self->current_preset(undef);
|
||||
$self->{default_suppressed} = Slic3r::GUI::Tab->no_defaults && scalar(@{$self->{presets}}) > 1;
|
||||
$self->{presets_choice}->Clear;
|
||||
foreach my $preset (@{$self->{presets}}) {
|
||||
next if ($preset->default && $self->{default_suppressed});
|
||||
$self->{presets_choice}->Append($preset->name);
|
||||
}
|
||||
{
|
||||
# load last used preset
|
||||
my $i = first { basename($self->{presets}[$_]->file) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
|
||||
$self->select_preset($i || $self->{default_suppressed});
|
||||
}
|
||||
$self->{presets}->update_platter_ui($self->{presets_choice});
|
||||
$self->_on_presets_changed;
|
||||
}
|
||||
|
||||
# Load a config file containing a Print, Filament & Printer preset.
|
||||
sub load_config_file {
|
||||
my ($self, $file) = @_;
|
||||
# look for the loaded config among the existing menu items
|
||||
my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
|
||||
if (!$i) {
|
||||
my $preset_name = basename($file); # keep the .ini suffix
|
||||
my $preset_new = Slic3r::GUI::Tab::Preset->new(
|
||||
file => $file,
|
||||
name => $preset_name,
|
||||
external => 1,
|
||||
);
|
||||
# Try to load the config file before it is entered into the list. If the loading fails, an undef is returned.
|
||||
return undef if ! defined $preset_new->config;
|
||||
push @{$self->{presets}}, $preset_new;
|
||||
$self->{presets_choice}->Append($preset_name);
|
||||
$i = $#{$self->{presets}};
|
||||
}
|
||||
$self->{presets_choice}->SetSelection($i - $self->{default_suppressed});
|
||||
$self->on_select_preset;
|
||||
$self->{presets}->update_platter_ui($self->{presets_choice});
|
||||
$self->select_preset;
|
||||
$self->_on_presets_changed;
|
||||
return 1;
|
||||
}
|
||||
@ -478,28 +354,22 @@ sub load_config_file {
|
||||
sub load_config {
|
||||
my ($self, $config) = @_;
|
||||
|
||||
my %keys_modified = ();
|
||||
my $modified = 0;
|
||||
foreach my $opt_key (@{$self->{config}->diff($config)}) {
|
||||
$self->{config}->set($opt_key, $config->get($opt_key));
|
||||
$keys_modified{$opt_key} = 1;
|
||||
$modified = 1;
|
||||
}
|
||||
if (keys(%keys_modified)) {
|
||||
if ($modified) {
|
||||
$self->update_dirty;
|
||||
# Initialize UI components with the config values.
|
||||
$self->reload_config;
|
||||
$self->_update(\%keys_modified);
|
||||
$self->_update;
|
||||
}
|
||||
}
|
||||
|
||||
# Load and return a config from the file associated with the $preset (Perl type Slic3r::GUI::Tab::Preset).
|
||||
sub get_preset_config {
|
||||
my ($self, $preset) = @_;
|
||||
return $preset->config($self->{config}->get_keys);
|
||||
}
|
||||
|
||||
# Find a field with an index over all pages of this tab.
|
||||
sub get_field {
|
||||
my ($self, $opt_key, $opt_index) = @_;
|
||||
|
||||
foreach my $page (@{ $self->{pages} }) {
|
||||
my $field = $page->get_field($opt_key, $opt_index);
|
||||
return $field if defined $field;
|
||||
@ -507,10 +377,9 @@ sub get_field {
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Set a key/value pair on this page. Return true if the value has been modified.
|
||||
sub set_value {
|
||||
my $self = shift;
|
||||
my ($opt_key, $value) = @_;
|
||||
|
||||
my ($self, $opt_key, $value) = @_;
|
||||
my $changed = 0;
|
||||
foreach my $page (@{ $self->{pages} }) {
|
||||
$changed = 1 if $page->set_value($opt_key, $value);
|
||||
@ -530,7 +399,8 @@ sub title { 'Print Settings' }
|
||||
sub build {
|
||||
my $self = shift;
|
||||
|
||||
$self->{config}->apply(wxTheApp->{preset_bundle}->prints->default_preset->config);
|
||||
$self->{presets} = wxTheApp->{preset_bundle}->print;
|
||||
$self->{config} = $self->{presets}->get_edited_preset->config_ref;
|
||||
|
||||
{
|
||||
my $page = $self->add_options_page('Layers and perimeters', 'layers.png');
|
||||
@ -789,6 +659,7 @@ sub build {
|
||||
}
|
||||
}
|
||||
|
||||
# Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields.
|
||||
sub reload_config {
|
||||
my ($self) = @_;
|
||||
# $self->_reload_compatible_printers_widget;
|
||||
@ -797,11 +668,9 @@ sub reload_config {
|
||||
|
||||
# Slic3r::GUI::Tab::Print::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
$keys_modified //= {};
|
||||
my ($self) = @_;
|
||||
|
||||
my $config = $self->{config};
|
||||
my $config = $self->{presets}->get_edited_preset->config_ref;
|
||||
|
||||
if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)) {
|
||||
my $dialog = Wx::MessageDialog->new($self,
|
||||
@ -879,10 +748,6 @@ sub _update {
|
||||
$self->load_config($new_conf);
|
||||
}
|
||||
|
||||
if ($keys_modified->{'layer_height'}) {
|
||||
# If the user had set the variable layer height, reset it and let the user know.
|
||||
}
|
||||
|
||||
if ($config->support_material) {
|
||||
# Ask only once.
|
||||
if (! $self->{support_material_overhangs_queried}) {
|
||||
@ -999,8 +864,6 @@ sub _update {
|
||||
for qw(wipe_tower_x wipe_tower_y wipe_tower_width wipe_tower_per_color_wipe);
|
||||
}
|
||||
|
||||
#sub hidden_options { !$Slic3r::have_threads ? qw(threads) : () }
|
||||
|
||||
package Slic3r::GUI::Tab::Filament;
|
||||
use base 'Slic3r::GUI::Tab';
|
||||
use Wx qw(wxTheApp);
|
||||
@ -1011,7 +874,8 @@ sub title { 'Filament Settings' }
|
||||
sub build {
|
||||
my $self = shift;
|
||||
|
||||
$self->{config}->apply(wxTheApp->{preset_bundle}->filaments->default_preset->config);
|
||||
$self->{presets} = wxTheApp->{preset_bundle}->filament;
|
||||
$self->{config} = $self->{presets}->get_edited_preset->config_ref;
|
||||
|
||||
{
|
||||
my $page = $self->add_options_page('Filament', 'spool.png');
|
||||
@ -1139,8 +1003,7 @@ sub build {
|
||||
|
||||
# Slic3r::GUI::Tab::Filament::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
$self->_update_description;
|
||||
|
||||
@ -1153,10 +1016,8 @@ sub _update {
|
||||
}
|
||||
|
||||
sub _update_description {
|
||||
my $self = shift;
|
||||
|
||||
my $config = $self->config;
|
||||
|
||||
my ($self) = @_;
|
||||
my $config = $self->{config};
|
||||
my $msg = "";
|
||||
my $fan_other_layers = $config->fan_always_on->[0]
|
||||
? sprintf "will always run at %d%%%s.", $config->min_fan_speed->[0],
|
||||
@ -1190,10 +1051,10 @@ sub name { 'printer' }
|
||||
sub title { 'Printer Settings' }
|
||||
|
||||
sub build {
|
||||
my $self = shift;
|
||||
my (%params) = @_;
|
||||
my ($self, %params) = @_;
|
||||
|
||||
$self->{config}->apply(wxTheApp->{preset_bundle}->printers->default_preset->config);
|
||||
$self->{presets} = wxTheApp->{preset_bundle}->printer;
|
||||
$self->{config} = $self->{presets}->get_edited_preset->config_ref;
|
||||
|
||||
my $bed_shape_widget = sub {
|
||||
my ($parent) = @_;
|
||||
@ -1201,7 +1062,7 @@ sub build {
|
||||
my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize,
|
||||
wxBU_LEFT | wxBU_EXACTFIT);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("cog.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("cog.png"), wxBITMAP_TYPE_PNG));
|
||||
|
||||
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
$sizer->Add($btn);
|
||||
@ -1268,7 +1129,7 @@ sub build {
|
||||
$serial_port->side_widget(sub {
|
||||
my ($parent) = @_;
|
||||
|
||||
my $btn = Wx::BitmapButton->new($parent, -1, Wx::Bitmap->new($Slic3r::var->("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
|
||||
my $btn = Wx::BitmapButton->new($parent, -1, Wx::Bitmap->new(Slic3r::var("arrow_rotate_clockwise.png"), wxBITMAP_TYPE_PNG),
|
||||
wxDefaultPosition, wxDefaultSize, &Wx::wxBORDER_NONE);
|
||||
$btn->SetToolTipString("Rescan serial ports")
|
||||
if $btn->can('SetToolTipString');
|
||||
@ -1282,7 +1143,7 @@ sub build {
|
||||
my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1,
|
||||
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG));
|
||||
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
my $sender = Slic3r::GCode::Sender->new;
|
||||
@ -1312,7 +1173,7 @@ sub build {
|
||||
|
||||
my $btn = Wx::Button->new($parent, -1, "Browse…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("zoom.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("zoom.png"), wxBITMAP_TYPE_PNG));
|
||||
|
||||
if (!eval "use Net::Bonjour; 1") {
|
||||
$btn->Disable;
|
||||
@ -1348,7 +1209,7 @@ sub build {
|
||||
my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1,
|
||||
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
$btn->SetFont($Slic3r::GUI::small_font);
|
||||
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->("wrench.png"), wxBITMAP_TYPE_PNG));
|
||||
$btn->SetBitmap(Wx::Bitmap->new(Slic3r::var("wrench.png"), wxBITMAP_TYPE_PNG));
|
||||
|
||||
EVT_BUTTON($self, $btn, sub {
|
||||
my $ua = LWP::UserAgent->new;
|
||||
@ -1565,8 +1426,7 @@ sub _build_extruder_pages {
|
||||
|
||||
# Slic3r::GUI::Tab::Printer::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my $config = $self->{config};
|
||||
|
||||
@ -1654,27 +1514,13 @@ sub on_preset_loaded {
|
||||
}
|
||||
}
|
||||
|
||||
# Load a config file containing a Print, Filament & Printer preset.
|
||||
sub load_config_file {
|
||||
my $self = shift;
|
||||
if ($self->SUPER::load_config_file(@_)) {
|
||||
Slic3r::GUI::warning_catcher($self)->(
|
||||
"Your configuration was imported. However, Slic3r is currently only able to import settings "
|
||||
. "for the first defined filament. We recommend you don't use exported configuration files "
|
||||
. "for multi-extruder setups and rely on the built-in preset management system instead.")
|
||||
if @{ $self->{config}->nozzle_diameter } > 1;
|
||||
return 1;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
# Single Tab page containing a {vsizer} of {optgroups}
|
||||
package Slic3r::GUI::Tab::Page;
|
||||
use Wx qw(wxTheApp :misc :panel :sizer);
|
||||
use base 'Wx::ScrolledWindow';
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent, $title, $iconID) = @_;
|
||||
my ($class, $parent, $title, $iconID) = @_;
|
||||
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
$self->{optgroups} = [];
|
||||
$self->{title} = $title;
|
||||
@ -1718,7 +1564,6 @@ sub reload_config {
|
||||
|
||||
sub get_field {
|
||||
my ($self, $opt_key, $opt_index) = @_;
|
||||
|
||||
foreach my $optgroup (@{ $self->{optgroups} }) {
|
||||
my $field = $optgroup->get_fieldc($opt_key, $opt_index);
|
||||
return $field if defined $field;
|
||||
@ -1727,9 +1572,7 @@ sub get_field {
|
||||
}
|
||||
|
||||
sub set_value {
|
||||
my $self = shift;
|
||||
my ($opt_key, $value) = @_;
|
||||
|
||||
my ($self, $opt_key, $value) = @_;
|
||||
my $changed = 0;
|
||||
foreach my $optgroup (@{$self->{optgroups}}) {
|
||||
$changed = 1 if $optgroup->set_value($opt_key, $value);
|
||||
@ -1743,8 +1586,7 @@ use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
|
||||
use base 'Wx::Dialog';
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent, %params) = @_;
|
||||
my ($class, $parent, %params) = @_;
|
||||
my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
|
||||
|
||||
my @values = @{$params{values}};
|
||||
@ -1770,7 +1612,6 @@ sub new {
|
||||
|
||||
sub accept {
|
||||
my ($self, $event) = @_;
|
||||
|
||||
if (($self->{chosen_name} = $self->{combo}->GetValue)) {
|
||||
if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/) {
|
||||
Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
|
||||
@ -1783,57 +1624,8 @@ sub accept {
|
||||
}
|
||||
|
||||
sub get_name {
|
||||
my $self = shift;
|
||||
my ($self) = @_;
|
||||
return $self->{chosen_name};
|
||||
}
|
||||
|
||||
package Slic3r::GUI::Tab::Preset;
|
||||
use Moo;
|
||||
use List::Util qw(any);
|
||||
|
||||
# The preset represents a "default" set of properties.
|
||||
has 'default' => (is => 'ro', default => sub { 0 });
|
||||
has 'external' => (is => 'ro', default => sub { 0 });
|
||||
has 'name' => (is => 'rw', required => 1);
|
||||
has 'file' => (is => 'rw');
|
||||
|
||||
# Load a config file, return a C++ class Slic3r::DynamicPrintConfig with $keys initialized from the config file.
|
||||
# In case of a "default" config item, return the default values.
|
||||
sub config {
|
||||
my ($self, $keys) = @_;
|
||||
|
||||
if ($self->default) {
|
||||
# Perl class Slic3r::Config extends the C++ class Slic3r::DynamicPrintConfig
|
||||
return Slic3r::Config->new_from_defaults(@$keys);
|
||||
} else {
|
||||
if (!-e Slic3r::encode_path($self->file)) {
|
||||
Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ").");
|
||||
return undef;
|
||||
}
|
||||
|
||||
# apply preset values on top of defaults
|
||||
my $config = Slic3r::Config->new_from_defaults(@$keys);
|
||||
my $external_config = eval { Slic3r::Config->load($self->file); };
|
||||
if ($@) {
|
||||
Slic3r::GUI::show_error(undef, $@);
|
||||
return undef;
|
||||
}
|
||||
$config->set($_, $external_config->get($_))
|
||||
for grep $external_config->has($_), @$keys;
|
||||
|
||||
if (any { $_ eq 'nozzle_diameter' } @$keys) {
|
||||
# Loaded the Printer settings. Verify, that all extruder dependent values have enough values.
|
||||
my $nozzle_diameter = $config->nozzle_diameter;
|
||||
my $num_extruders = scalar(@{$nozzle_diameter});
|
||||
foreach my $key (qw(deretract_speed extruder_colour retract_before_wipe)) {
|
||||
my $vec = $config->get($key);
|
||||
push @{$vec}, ($vec->[0]) x ($num_extruders - @{$vec});
|
||||
$config->set($key, $vec);
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -11,9 +11,6 @@ use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union
|
||||
use Slic3r::Print::State ':steps';
|
||||
use Slic3r::Surface ':types';
|
||||
|
||||
# If enabled, phases of prepare_infill will be written into SVG files to an "out" directory.
|
||||
our $SLIC3R_DEBUG_SLICE_PROCESSING = 0;
|
||||
|
||||
sub layers {
|
||||
my $self = shift;
|
||||
return [ map $self->get_layer($_), 0..($self->layer_count - 1) ];
|
||||
|
@ -100,12 +100,17 @@ if ($opt{save}) {
|
||||
my $config = Slic3r::Config->new_from_defaults;
|
||||
$config->apply($cli_config);
|
||||
|
||||
# locate or create data directory
|
||||
# Unix: ~/.Slic3r
|
||||
# Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
|
||||
# Mac: "~/Library/Application Support/Slic3r"
|
||||
Slic3r::set_data_dir($opt{datadir} || Wx::StandardPaths::Get->GetUserDataDir);
|
||||
|
||||
# launch GUI
|
||||
my $gui;
|
||||
if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") {
|
||||
{
|
||||
no warnings 'once';
|
||||
$Slic3r::GUI::datadir = $opt{datadir} // '';
|
||||
$Slic3r::GUI::no_controller = $opt{no_controller};
|
||||
$Slic3r::GUI::no_plater = $opt{no_plater};
|
||||
$Slic3r::GUI::autosave = $opt{autosave};
|
||||
|
@ -7,7 +7,8 @@ namespace Slic3r {
|
||||
template <class PointClass>
|
||||
BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> &points)
|
||||
{
|
||||
if (points.empty()) CONFESS("Empty point set supplied to BoundingBoxBase constructor");
|
||||
if (points.empty())
|
||||
CONFESS("Empty point set supplied to BoundingBoxBase constructor");
|
||||
typename std::vector<PointClass>::const_iterator it = points.begin();
|
||||
this->min.x = this->max.x = it->x;
|
||||
this->min.y = this->max.y = it->y;
|
||||
@ -26,7 +27,8 @@ template <class PointClass>
|
||||
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> &points)
|
||||
: BoundingBoxBase<PointClass>(points)
|
||||
{
|
||||
if (points.empty()) CONFESS("Empty point set supplied to BoundingBox3Base constructor");
|
||||
if (points.empty())
|
||||
CONFESS("Empty point set supplied to BoundingBox3Base constructor");
|
||||
typename std::vector<PointClass>::const_iterator it = points.begin();
|
||||
this->min.z = this->max.z = it->z;
|
||||
for (++it; it != points.end(); ++it) {
|
||||
@ -39,9 +41,10 @@ template BoundingBox3Base<Pointf3>::BoundingBox3Base(const std::vector<Pointf3>
|
||||
BoundingBox::BoundingBox(const Lines &lines)
|
||||
{
|
||||
Points points;
|
||||
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
|
||||
points.push_back(line->a);
|
||||
points.push_back(line->b);
|
||||
points.reserve(lines.size());
|
||||
for (const Line &line : lines) {
|
||||
points.emplace_back(line.a);
|
||||
points.emplace_back(line.b);
|
||||
}
|
||||
*this = BoundingBox(points);
|
||||
}
|
||||
@ -190,9 +193,9 @@ BoundingBox3Base<PointClass>::size() const
|
||||
}
|
||||
template Pointf3 BoundingBox3Base<Pointf3>::size() const;
|
||||
|
||||
template <class PointClass> double
|
||||
BoundingBoxBase<PointClass>::radius() const
|
||||
template <class PointClass> double BoundingBoxBase<PointClass>::radius() const
|
||||
{
|
||||
assert(this->defined);
|
||||
double x = this->max.x - this->min.x;
|
||||
double y = this->max.y - this->min.y;
|
||||
return 0.5 * sqrt(x*x+y*y);
|
||||
@ -200,8 +203,7 @@ BoundingBoxBase<PointClass>::radius() const
|
||||
template double BoundingBoxBase<Point>::radius() const;
|
||||
template double BoundingBoxBase<Pointf>::radius() const;
|
||||
|
||||
template <class PointClass> double
|
||||
BoundingBox3Base<PointClass>::radius() const
|
||||
template <class PointClass> double BoundingBox3Base<PointClass>::radius() const
|
||||
{
|
||||
double x = this->max.x - this->min.x;
|
||||
double y = this->max.y - this->min.y;
|
||||
|
@ -27,35 +27,36 @@ extern bool unescape_strings_cstyle(const std::string &str, std::vector<
|
||||
|
||||
// Type of a configuration value.
|
||||
enum ConfigOptionType {
|
||||
coNone,
|
||||
coVectorType = 0x4000,
|
||||
coNone = 0,
|
||||
// single float
|
||||
coFloat,
|
||||
coFloat = 1,
|
||||
// vector of floats
|
||||
coFloats,
|
||||
coFloats = coFloat + coVectorType,
|
||||
// single int
|
||||
coInt,
|
||||
coInt = 2,
|
||||
// vector of ints
|
||||
coInts,
|
||||
coInts = coInt + coVectorType,
|
||||
// single string
|
||||
coString,
|
||||
coString = 3,
|
||||
// vector of strings
|
||||
coStrings,
|
||||
coStrings = coString + coVectorType,
|
||||
// percent value. Currently only used for infill.
|
||||
coPercent,
|
||||
coPercent = 4,
|
||||
// percents value. Currently used for retract before wipe only.
|
||||
coPercents,
|
||||
coPercents = coPercent + coVectorType,
|
||||
// a fraction or an absolute value
|
||||
coFloatOrPercent,
|
||||
coFloatOrPercent = 5,
|
||||
// single 2d point. Currently not used.
|
||||
coPoint,
|
||||
coPoint = 6,
|
||||
// vector of 2d points. Currently used for the definition of the print bed and for the extruder offsets.
|
||||
coPoints,
|
||||
coPoints = coPoint + coVectorType,
|
||||
// single boolean value
|
||||
coBool,
|
||||
coBool = 7,
|
||||
// vector of boolean values
|
||||
coBools,
|
||||
coBools = coBool + coVectorType,
|
||||
// a generic enum
|
||||
coEnum,
|
||||
coEnum = 8,
|
||||
};
|
||||
|
||||
// A generic value of a configuration option.
|
||||
@ -75,6 +76,8 @@ public:
|
||||
virtual void setInt(int /* val */) { throw std::runtime_error("Calling ConfigOption::setInt on a non-int ConfigOption"); }
|
||||
virtual bool operator==(const ConfigOption &rhs) const = 0;
|
||||
bool operator!=(const ConfigOption &rhs) const { return ! (*this == rhs); }
|
||||
bool is_scalar() const { return (int(this->type()) & int(coVectorType)) == 0; }
|
||||
bool is_vector() const { return ! this->is_scalar(); }
|
||||
};
|
||||
|
||||
// Value of a single valued option (bool, int, float, string, point, enum)
|
||||
@ -110,6 +113,18 @@ class ConfigOptionVectorBase : public ConfigOption {
|
||||
public:
|
||||
// Currently used only to initialize the PlaceholderParser.
|
||||
virtual std::vector<std::string> vserialize() const = 0;
|
||||
// Set from a vector of ConfigOptions.
|
||||
// If the rhs ConfigOption is scalar, then its value is used,
|
||||
// otherwise for each of rhs, the first value of a vector is used.
|
||||
// This function is useful to collect values for multiple extrder / filament settings.
|
||||
virtual void set(const std::vector<const ConfigOption*> &rhs) = 0;
|
||||
// Set a single vector item from either a scalar option or the first value of a vector option.vector of ConfigOptions.
|
||||
// This function is useful to split values from multiple extrder / filament settings into separate configurations.
|
||||
virtual void set_at(const ConfigOption *rhs, size_t i, size_t j) = 0;
|
||||
|
||||
protected:
|
||||
// Used to verify type compatibility when assigning to / from a scalar ConfigOption.
|
||||
ConfigOptionType scalar_type() const { return static_cast<ConfigOptionType>(this->type() - coVectorType); }
|
||||
};
|
||||
|
||||
// Value of a vector valued option (bools, ints, floats, strings, points), template
|
||||
@ -125,13 +140,57 @@ public:
|
||||
throw std::runtime_error("ConfigOptionVector: Assigning an incompatible type");
|
||||
assert(dynamic_cast<const ConfigOptionVector<T>*>(rhs));
|
||||
this->values = static_cast<const ConfigOptionVector<T>*>(rhs)->values;
|
||||
};
|
||||
}
|
||||
|
||||
// Set from a vector of ConfigOptions.
|
||||
// If the rhs ConfigOption is scalar, then its value is used,
|
||||
// otherwise for each of rhs, the first value of a vector is used.
|
||||
// This function is useful to collect values for multiple extrder / filament settings.
|
||||
void set(const std::vector<const ConfigOption*> &rhs) override
|
||||
{
|
||||
this->values.clear();
|
||||
this->values.reserve(rhs.size());
|
||||
for (const ConfigOption *opt : rhs) {
|
||||
if (opt->type() == this->type()) {
|
||||
auto other = static_cast<const ConfigOptionVector<T>*>(opt);
|
||||
if (other->values.empty())
|
||||
throw std::runtime_error("ConfigOptionVector::set(): Assigning from an empty vector");
|
||||
this->values.emplace_back(other->values.front());
|
||||
} else if (opt->type() == this->scalar_type())
|
||||
this->values.emplace_back(static_cast<const ConfigOptionSingle<T>*>(opt)->value);
|
||||
else
|
||||
throw std::runtime_error("ConfigOptionVector::set():: Assigning an incompatible type");
|
||||
}
|
||||
}
|
||||
|
||||
// Set a single vector item from either a scalar option or the first value of a vector option.vector of ConfigOptions.
|
||||
// This function is useful to split values from multiple extrder / filament settings into separate configurations.
|
||||
void set_at(const ConfigOption *rhs, size_t i, size_t j) override
|
||||
{
|
||||
// It is expected that the vector value has at least one value, which is the default, if not overwritten.
|
||||
assert(! this->values.empty());
|
||||
if (this->values.size() <= i) {
|
||||
// Resize this vector, fill in the new vector fields with the copy of the first field.
|
||||
T v = this->values.front();
|
||||
this->values.resize(i + 1, v);
|
||||
}
|
||||
if (rhs->type() == this->type()) {
|
||||
// Assign the first value of the rhs vector.
|
||||
auto other = static_cast<const ConfigOptionVector<T>*>(rhs);
|
||||
if (other->values.empty())
|
||||
throw std::runtime_error("ConfigOptionVector::set_at(): Assigning from an empty vector");
|
||||
this->values[i] = other->get_at(j);
|
||||
} else if (rhs->type() == this->scalar_type())
|
||||
this->values[i] = static_cast<const ConfigOptionSingle<T>*>(rhs)->value;
|
||||
else
|
||||
throw std::runtime_error("ConfigOptionVector::set_at(): Assigning an incompatible type");
|
||||
}
|
||||
|
||||
T& get_at(size_t i)
|
||||
{
|
||||
assert(! this->values.empty());
|
||||
return (i < this->values.size()) ? this->values[i] : this->values.front();
|
||||
};
|
||||
}
|
||||
|
||||
const T& get_at(size_t i) const { return const_cast<ConfigOptionVector<T>*>(this)->get_at(i); }
|
||||
|
||||
|
@ -1208,6 +1208,8 @@ void TriangleMeshSlicer::make_expolygons(const Polygons &loops, ExPolygons* slic
|
||||
|
||||
// perform a safety offset to merge very close facets (TODO: find test case for this)
|
||||
double safety_offset = scale_(0.0499);
|
||||
//FIXME see https://github.com/prusa3d/Slic3r/issues/520
|
||||
// double safety_offset = scale_(0.0001);
|
||||
ExPolygons ex_slices = offset2_ex(p_slices, +safety_offset, -safety_offset);
|
||||
|
||||
#ifdef SLIC3R_TRIANGLEMESH_DEBUG
|
||||
|
@ -8,11 +8,21 @@ extern void trace(unsigned int level, const char *message);
|
||||
|
||||
// Set a path with GUI resource files.
|
||||
void set_var_dir(const std::string &path);
|
||||
// Return a path to the GUI resource files.
|
||||
// Return a full path to the GUI resource files.
|
||||
const std::string& var_dir();
|
||||
// Return a resource path for a file_name.
|
||||
// Return a full resource path for a file_name.
|
||||
std::string var(const std::string &file_name);
|
||||
|
||||
// Set a path with preset files.
|
||||
void set_data_dir(const std::string &path);
|
||||
// Return a full path to the GUI resource files.
|
||||
const std::string& data_dir();
|
||||
// Return a full path to a configuration file given its file name..
|
||||
std::string config_path(const std::string &file_name);
|
||||
// Return a full path to a configuration file given the section and name.
|
||||
// The suffix ".ini" will be added if it is missing in the name.
|
||||
std::string config_path(const std::string §ion, const std::string &name);
|
||||
|
||||
extern std::string encode_path(const char *src);
|
||||
extern std::string decode_path(const char *src);
|
||||
extern std::string normalize_utf8_nfc(const char *src);
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <boost/nowide/integration/filesystem.hpp>
|
||||
#include <boost/nowide/convert.hpp>
|
||||
|
||||
@ -87,6 +87,31 @@ std::string var(const std::string &file_name)
|
||||
return file.string();
|
||||
}
|
||||
|
||||
static std::string g_data_dir;
|
||||
|
||||
void set_data_dir(const std::string &dir)
|
||||
{
|
||||
g_data_dir = dir;
|
||||
}
|
||||
|
||||
const std::string& data_dir()
|
||||
{
|
||||
return g_data_dir;
|
||||
}
|
||||
|
||||
std::string config_path(const std::string &file_name)
|
||||
{
|
||||
auto file = boost::filesystem::canonical(boost::filesystem::path(g_data_dir) / file_name).make_preferred();
|
||||
return file.string();
|
||||
}
|
||||
|
||||
std::string config_path(const std::string §ion, const std::string &name)
|
||||
{
|
||||
auto file_name = boost::algorithm::iends_with(name, ".ini") ? name : name + ".ini";
|
||||
auto file = boost::filesystem::canonical(boost::filesystem::path(g_data_dir) / file_name).make_preferred();
|
||||
return file.string();
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
#ifdef SLIC3R_HAS_BROKEN_CROAK
|
||||
|
@ -13,8 +13,7 @@ namespace Slic3r { namespace GUI {
|
||||
IOPMAssertionID assertionID;
|
||||
#endif
|
||||
|
||||
void
|
||||
disable_screensaver()
|
||||
void disable_screensaver()
|
||||
{
|
||||
#if __APPLE__
|
||||
CFStringRef reasonForActivity = CFSTR("Slic3r");
|
||||
@ -26,8 +25,7 @@ disable_screensaver()
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
enable_screensaver()
|
||||
void enable_screensaver()
|
||||
{
|
||||
#if __APPLE__
|
||||
IOReturn success = IOPMAssertionRelease(assertionID);
|
||||
@ -36,8 +34,7 @@ enable_screensaver()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
debugged()
|
||||
bool debugged()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return IsDebuggerPresent();
|
||||
@ -46,8 +43,7 @@ debugged()
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
void
|
||||
break_to_debugger()
|
||||
void break_to_debugger()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
|
@ -4,9 +4,17 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#include <boost/nowide/cenv.hpp>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
#include <wx/image.h>
|
||||
#include <wx/choice.h>
|
||||
#include <wx/bmpcbox.h>
|
||||
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
|
||||
#if 0
|
||||
#define DEBUG
|
||||
#define _DEBUG
|
||||
@ -17,6 +25,42 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
static std::string g_suffix_modified = " (modified)";
|
||||
|
||||
// Load keys from a config file or a G-code.
|
||||
// Throw exceptions with reasonable messages if something goes wrong.
|
||||
static void load_config_file(DynamicPrintConfig &config, const std::string &path)
|
||||
{
|
||||
try {
|
||||
if (boost::algorithm::iends_with(path, ".gcode") || boost::algorithm::iends_with(path, ".g"))
|
||||
config.load_from_gcode(path);
|
||||
else
|
||||
config.load(path);
|
||||
} catch (const std::ifstream::failure&) {
|
||||
throw std::runtime_error(std::string("The selected preset does not exist anymore: ") + path);
|
||||
} catch (const std::runtime_error&) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + path);
|
||||
}
|
||||
|
||||
// Update new extruder fields at the printer profile.
|
||||
auto keys = config.keys();
|
||||
const auto &defaults = FullPrintConfig::defaults();
|
||||
if (std::find(keys.begin(), keys.end(), "nozzle_diameter") != keys.end()) {
|
||||
// Loaded the Printer settings. Verify, that all extruder dependent values have enough values.
|
||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter"));
|
||||
size_t num_extruders = nozzle_diameter->values.size();
|
||||
auto *deretract_speed = dynamic_cast<ConfigOptionFloats*>(config.option("deretract_speed"));
|
||||
deretract_speed->values.resize(num_extruders, deretract_speed->values.empty() ?
|
||||
defaults.deretract_speed.values.front() : deretract_speed->values.front());
|
||||
auto *extruder_colour = dynamic_cast<ConfigOptionStrings*>(config.option("extruder_colour"));
|
||||
extruder_colour->values.resize(num_extruders, extruder_colour->values.empty() ?
|
||||
defaults.extruder_colour.values.front() : extruder_colour->values.front());
|
||||
auto *retract_before_wipe = dynamic_cast<ConfigOptionPercents*>(config.option("retract_before_wipe"));
|
||||
retract_before_wipe->values.resize(num_extruders, retract_before_wipe->values.empty() ?
|
||||
defaults.retract_before_wipe.values.front() : retract_before_wipe->values.front());
|
||||
}
|
||||
}
|
||||
|
||||
// Load a config file, return a C++ class Slic3r::DynamicPrintConfig with $keys initialized from the config file.
|
||||
// In case of a "default" config item, return the default values.
|
||||
DynamicPrintConfig& Preset::load(const std::vector<std::string> &keys)
|
||||
@ -24,40 +68,24 @@ DynamicPrintConfig& Preset::load(const std::vector<std::string> &keys)
|
||||
// Set the configuration from the defaults.
|
||||
Slic3r::FullPrintConfig defaults;
|
||||
this->config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
|
||||
|
||||
if (! this->is_default) {
|
||||
if (! this->is_default)
|
||||
// Load the preset file, apply preset values on top of defaults.
|
||||
try {
|
||||
if (boost::algorithm::iends_with(this->file, ".gcode") || boost::algorithm::iends_with(this->file, ".g"))
|
||||
this->config.load_from_gcode(this->file);
|
||||
else
|
||||
this->config.load(this->file);
|
||||
} catch (const std::ifstream::failure&) {
|
||||
throw std::runtime_error(std::string("The selected preset does not exist anymore: ") + this->file);
|
||||
} catch (const std::runtime_error&) {
|
||||
throw std::runtime_error(std::string("Failed loading the preset file: ") + this->file);
|
||||
}
|
||||
|
||||
if (this->type == TYPE_PRINTER && std::find(keys.begin(), keys.end(), "nozzle_diameter") != keys.end()) {
|
||||
// Loaded the Printer settings. Verify, that all extruder dependent values have enough values.
|
||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(this->config.option("nozzle_diameter"));
|
||||
size_t num_extruders = nozzle_diameter->values.size();
|
||||
auto *deretract_speed = dynamic_cast<ConfigOptionFloats*>(this->config.option("deretract_speed"));
|
||||
deretract_speed->values.resize(num_extruders, deretract_speed->values.empty() ?
|
||||
defaults.deretract_speed.values.front() : deretract_speed->values.front());
|
||||
auto *extruder_colour = dynamic_cast<ConfigOptionStrings*>(this->config.option("extruder_colour"));
|
||||
extruder_colour->values.resize(num_extruders, extruder_colour->values.empty() ?
|
||||
defaults.extruder_colour.values.front() : extruder_colour->values.front());
|
||||
auto *retract_before_wipe = dynamic_cast<ConfigOptionPercents*>(this->config.option("retract_before_wipe"));
|
||||
retract_before_wipe->values.resize(num_extruders, retract_before_wipe->values.empty() ?
|
||||
defaults.retract_before_wipe.values.front() : retract_before_wipe->values.front());
|
||||
}
|
||||
}
|
||||
|
||||
load_config_file(this->config, this->file);
|
||||
this->loaded = true;
|
||||
return this->config;
|
||||
}
|
||||
|
||||
void Preset::save()
|
||||
{
|
||||
this->config.save(this->file);
|
||||
}
|
||||
|
||||
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
||||
std::string Preset::label() const
|
||||
{
|
||||
return this->name + (this->is_dirty ? g_suffix_modified : "");
|
||||
}
|
||||
|
||||
bool Preset::enable_compatible(const std::string &active_printer)
|
||||
{
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.optptr("compatible_printers"));
|
||||
@ -69,11 +97,20 @@ bool Preset::enable_compatible(const std::string &active_printer)
|
||||
|
||||
PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys) :
|
||||
m_type(type),
|
||||
m_edited_preset(type, "", false)
|
||||
m_edited_preset(type, "", false),
|
||||
m_idx_selected(0),
|
||||
m_bitmap_main_frame(new wxBitmap)
|
||||
{
|
||||
// Insert just the default preset.
|
||||
m_presets.emplace_back(Preset(type, "- default -", true));
|
||||
m_presets.front().load(keys);
|
||||
m_edited_preset.config.apply(m_presets.front().config);
|
||||
}
|
||||
|
||||
PresetCollection::~PresetCollection()
|
||||
{
|
||||
delete m_bitmap_main_frame;
|
||||
m_bitmap_main_frame = nullptr;
|
||||
}
|
||||
|
||||
// Load all presets found in dir_path.
|
||||
@ -96,6 +133,58 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
|
||||
|
||||
}
|
||||
}
|
||||
std::sort(m_presets.begin() + 1, m_presets.end(), [](const Preset &p1, const Preset &p2){ return p1.name < p2.name; });
|
||||
}
|
||||
|
||||
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
||||
// and select it, losing previous modifications.
|
||||
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select)
|
||||
{
|
||||
Preset key(m_type, name);
|
||||
auto it = std::lower_bound(m_presets.begin(), m_presets.end(), key);
|
||||
if (it != m_presets.end() && it->name == name) {
|
||||
// The preset with the same name was found.
|
||||
it->is_dirty = false;
|
||||
} else {
|
||||
it = m_presets.emplace(it, Preset(m_type, name, false));
|
||||
}
|
||||
Preset &preset = *it;
|
||||
preset.file = path;
|
||||
preset.config = this->default_preset().config;
|
||||
preset.loaded = true;
|
||||
this->get_selected_preset().is_dirty = false;
|
||||
if (select)
|
||||
this->select_preset_by_name(name, true);
|
||||
return preset;
|
||||
}
|
||||
|
||||
bool PresetCollection::load_bitmap_default(const std::string &file_name)
|
||||
{
|
||||
return m_bitmap_main_frame->LoadFile(wxString::FromUTF8(Slic3r::var(file_name).c_str()), wxBITMAP_TYPE_PNG);
|
||||
}
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found)
|
||||
{
|
||||
Preset key(m_type, name, false);
|
||||
auto it = std::lower_bound(m_presets.begin(), m_presets.end(), key,
|
||||
[](const Preset &p1, const Preset &p2) { return p1.name < p2.name; } );
|
||||
// Ensure that a temporary copy is returned if the preset found is currently selected.
|
||||
return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin()) :
|
||||
first_visible_if_not_found ? &this->first_visible() : nullptr;
|
||||
}
|
||||
|
||||
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
size_t PresetCollection::first_visible_idx() const
|
||||
{
|
||||
size_t idx = 0;
|
||||
for (; idx < this->m_presets.size(); ++ idx)
|
||||
if (m_presets[idx].is_visible)
|
||||
break;
|
||||
if (idx == this->m_presets.size())
|
||||
idx = 0;
|
||||
return idx;
|
||||
}
|
||||
|
||||
void PresetCollection::set_default_suppressed(bool default_suppressed)
|
||||
@ -117,7 +206,13 @@ void PresetCollection::enable_disable_compatible_to_printer(const std::string &a
|
||||
m_presets.front().is_visible = true;
|
||||
}
|
||||
|
||||
static std::string g_suffix_modified = " (modified)";
|
||||
// Save the preset under a new name. If the name is different from the old one,
|
||||
// a new preset is stored into the list of presets.
|
||||
// All presets are marked as not modified and the new preset is activated.
|
||||
//void PresetCollection::save_current_preset(const std::string &new_name);
|
||||
|
||||
// Delete the current preset, activate the first visible preset.
|
||||
//void PresetCollection::delete_current_preset();
|
||||
|
||||
// Update the wxChoice UI component from this list of presets.
|
||||
// Hide the
|
||||
@ -175,6 +270,113 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
|
||||
}
|
||||
}
|
||||
|
||||
void PresetCollection::update_platter_ui(wxChoice *ui)
|
||||
{
|
||||
if (ui == nullptr)
|
||||
return;
|
||||
|
||||
size_t n_visible = this->num_visible();
|
||||
size_t n_choice = size_t(ui->GetCount());
|
||||
if (std::abs(int(n_visible) - int(n_choice)) <= 1) {
|
||||
// The number of items differs by at most one, update the choice.
|
||||
} else {
|
||||
// Otherwise fill in the list from scratch.
|
||||
}
|
||||
|
||||
std::string name_selected = dynamic_cast<wxItemContainerImmutable*>(ui)->GetStringSelection().ToUTF8().data();
|
||||
if (boost::algorithm::iends_with(name_selected, g_suffix_modified))
|
||||
// Remove the g_suffix_modified.
|
||||
name_selected.erase(name_selected.end() - g_suffix_modified.size(), name_selected.end());
|
||||
|
||||
ui->Clear();
|
||||
for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++ i) {
|
||||
const Preset &preset = this->m_presets[i];
|
||||
const wxBitmap *bmp = (i == 0 || preset.is_visible) ? m_bitmap_compatible : m_bitmap_incompatible;
|
||||
ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), (void*)&preset);
|
||||
if (name_selected == preset.name)
|
||||
ui->SetSelection(ui->GetCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Update a dirty floag of the current preset, update the labels of the UI component accordingly.
|
||||
// Return true if the dirty flag changed.
|
||||
bool PresetCollection::update_dirty_ui(wxItemContainer *ui)
|
||||
{
|
||||
// 1) Update the dirty flag of the current preset.
|
||||
bool was_dirty = this->get_selected_preset().is_dirty;
|
||||
bool is_dirty = current_is_dirty();
|
||||
this->get_selected_preset().is_dirty = is_dirty;
|
||||
// 2) Update the labels.
|
||||
for (unsigned int ui_id = 0; ui_id < ui->GetCount(); ++ ui_id) {
|
||||
std::string old_label = ui->GetString(ui_id).utf8_str().data();
|
||||
std::string preset_name = boost::algorithm::ends_with(old_label, g_suffix_modified) ?
|
||||
old_label.substr(0, g_suffix_modified.size()) :
|
||||
old_label;
|
||||
const Preset *preset = this->find_preset(preset_name, false);
|
||||
assert(preset != nullptr);
|
||||
std::string new_label = preset->is_dirty ? preset->name + g_suffix_modified : preset->name;
|
||||
if (old_label != new_label)
|
||||
ui->SetString(ui_id, wxString::FromUTF8(new_label.c_str()));
|
||||
}
|
||||
return was_dirty != is_dirty;
|
||||
}
|
||||
|
||||
bool PresetCollection::update_dirty_ui(wxChoice *ui)
|
||||
{
|
||||
return update_dirty_ui(dynamic_cast<wxItemContainer*>(ui));
|
||||
}
|
||||
|
||||
Preset& PresetCollection::select_preset(size_t idx)
|
||||
{
|
||||
if (idx >= m_presets.size())
|
||||
idx = first_visible_idx();
|
||||
m_idx_selected = idx;
|
||||
m_edited_preset = m_presets[idx];
|
||||
return m_presets[idx];
|
||||
}
|
||||
|
||||
bool PresetCollection::select_preset_by_name(const std::string &name, bool force)
|
||||
{
|
||||
// 1) Try to find the preset by its name.
|
||||
Preset key(m_type, name, false);
|
||||
auto it = std::lower_bound(m_presets.begin(), m_presets.end(), key,
|
||||
[](const Preset &p1, const Preset &p2) { return p1.name < p2.name; } );
|
||||
size_t idx = 0;
|
||||
if (it != m_presets.end() && it->name == key.name)
|
||||
// Preset found by its name.
|
||||
idx = it - m_presets.begin();
|
||||
else {
|
||||
// Find the first visible preset.
|
||||
for (size_t i = 0; i < m_presets.size(); ++ i)
|
||||
if (m_presets[i].is_visible) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
// If the first visible preset was not found, return the 0th element, which is the default preset.
|
||||
}
|
||||
|
||||
// 2) Select the new preset.
|
||||
if (m_idx_selected != idx || force) {
|
||||
this->select_preset(idx);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PresetCollection::select_by_name_ui(char *name, wxItemContainer *ui)
|
||||
{
|
||||
this->select_preset_by_name(name, true);
|
||||
//FIXME this is not finished yet.
|
||||
//this->update_platter_ui(wxChoice *ui)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PresetCollection::select_by_name_ui(char *name, wxChoice *ui)
|
||||
{
|
||||
return this->select_by_name_ui(name, dynamic_cast<wxItemContainer*>(ui));
|
||||
}
|
||||
|
||||
PresetBundle::PresetBundle() :
|
||||
prints(Preset::TYPE_PRINT, print_options()),
|
||||
filaments(Preset::TYPE_FILAMENT, filament_options()),
|
||||
@ -182,6 +384,8 @@ PresetBundle::PresetBundle() :
|
||||
m_bitmapCompatible(new wxBitmap),
|
||||
m_bitmapIncompatible(new wxBitmap)
|
||||
{
|
||||
::wxInitAllImageHandlers();
|
||||
|
||||
// Create the ID config keys, as they are not part of the Static print config classes.
|
||||
this->prints.preset(0).config.opt_string("print_settings_id", true);
|
||||
this->filaments.preset(0).config.opt_string("filament_settings_id", true);
|
||||
@ -189,6 +393,13 @@ PresetBundle::PresetBundle() :
|
||||
// Create the "compatible printers" keys, as they are not part of the Static print config classes.
|
||||
this->filaments.preset(0).config.optptr("compatible_printers", true);
|
||||
this->prints.preset(0).config.optptr("compatible_printers", true);
|
||||
|
||||
this->prints .load_bitmap_default("cog.png");
|
||||
this->filaments.load_bitmap_default("spool.png");
|
||||
this->printers .load_bitmap_default("printer_empty.png");
|
||||
|
||||
// FIXME select some icons indicating compatibility.
|
||||
this->load_compatible_bitmaps("cog.png", "cog.png");
|
||||
}
|
||||
|
||||
PresetBundle::~PresetBundle()
|
||||
@ -206,14 +417,16 @@ PresetBundle::~PresetBundle()
|
||||
void PresetBundle::load_presets(const std::string &dir_path)
|
||||
{
|
||||
this->prints .load_presets(dir_path, "print");
|
||||
this->prints.load_presets(dir_path, "filament");
|
||||
this->prints.load_presets(dir_path, "printer");
|
||||
this->filaments.load_presets(dir_path, "filament");
|
||||
this->printers .load_presets(dir_path, "printer");
|
||||
}
|
||||
|
||||
bool PresetBundle::load_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible)
|
||||
bool PresetBundle::load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible)
|
||||
{
|
||||
bool loaded_compatible = m_bitmapCompatible ->LoadFile(wxString::FromUTF8(path_bitmap_compatible.c_str()));
|
||||
bool loaded_incompatible = m_bitmapIncompatible->LoadFile(wxString::FromUTF8(path_bitmap_incompatible.c_str()));
|
||||
bool loaded_compatible = m_bitmapCompatible ->LoadFile(
|
||||
wxString::FromUTF8(Slic3r::var(path_bitmap_compatible).c_str()), wxBITMAP_TYPE_PNG);
|
||||
bool loaded_incompatible = m_bitmapIncompatible->LoadFile(
|
||||
wxString::FromUTF8(Slic3r::var(path_bitmap_incompatible).c_str()), wxBITMAP_TYPE_PNG);
|
||||
if (loaded_compatible) {
|
||||
prints .set_bitmap_compatible(m_bitmapCompatible);
|
||||
filaments.set_bitmap_compatible(m_bitmapCompatible);
|
||||
@ -227,6 +440,269 @@ bool PresetBundle::load_bitmaps(const std::string &path_bitmap_compatible, const
|
||||
return loaded_compatible && loaded_incompatible;
|
||||
}
|
||||
|
||||
DynamicPrintConfig PresetBundle::full_config() const
|
||||
{
|
||||
DynamicPrintConfig out;
|
||||
out.apply(FullPrintConfig());
|
||||
out.apply(this->prints.get_edited_preset().config);
|
||||
out.apply(this->printers.get_edited_preset().config);
|
||||
|
||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(out.option("nozzle_diameter"));
|
||||
size_t num_extruders = nozzle_diameter->values.size();
|
||||
|
||||
if (num_extruders <= 1) {
|
||||
out.apply(this->filaments.get_edited_preset().config);
|
||||
} else {
|
||||
// Retrieve filament presets and build a single config object for them.
|
||||
// First collect the filament configurations based on the user selection of this->filament_presets.
|
||||
std::vector<const DynamicPrintConfig*> filament_configs;
|
||||
for (const std::string &filament_preset_name : this->filament_presets)
|
||||
filament_configs.emplace_back(&this->filaments.find_preset(filament_preset_name, true)->config);
|
||||
while (filament_configs.size() < num_extruders)
|
||||
filament_configs.emplace_back(&this->filaments.first_visible().config);
|
||||
// Option values to set a ConfigOptionVector from.
|
||||
std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr);
|
||||
// loop through options and apply them to the resulting config.
|
||||
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
|
||||
// Get a destination option.
|
||||
ConfigOption *opt_dst = out.option(key, false);
|
||||
if (opt_dst->is_scalar()) {
|
||||
// Get an option, do not create if it does not exist.
|
||||
const ConfigOption *opt_src = filament_configs.front()->option(key);
|
||||
if (opt_src != nullptr)
|
||||
opt_dst->set(opt_src);
|
||||
} else {
|
||||
// Setting a vector value from all filament_configs.
|
||||
for (size_t i = 0; i < filament_opts.size(); ++ i)
|
||||
filament_opts[i] = filament_configs[i]->option(key);
|
||||
static_cast<ConfigOptionVectorBase*>(opt_dst)->set(filament_opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char *keys[] = { "perimeter", "infill", "solid_infill", "support_material", "support_material_interface" };
|
||||
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++ i) {
|
||||
std::string key = std::string(keys[i]) + "_extruder";
|
||||
auto *opt = dynamic_cast<ConfigOptionInt*>(out.option(key, false));
|
||||
assert(opt != nullptr);
|
||||
opt->value = std::min<int>(opt->value, std::min<int>(0, int(num_extruders) - 1));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// Load an external config file containing the print, filament and printer presets.
|
||||
// Instead of a config file, a G-code may be loaded containing the full set of parameters.
|
||||
// In the future the configuration will likely be read from an AMF file as well.
|
||||
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
|
||||
void PresetBundle::load_config_file(const std::string &path)
|
||||
{
|
||||
// 1) Initialize a config from full defaults.
|
||||
DynamicPrintConfig config;
|
||||
config.apply(FullPrintConfig());
|
||||
|
||||
// 2) Try to load the config file.
|
||||
// Throw exceptions with reasonable messages if something goes wrong.
|
||||
Slic3r::load_config_file(config, path);
|
||||
|
||||
// 3) Create a name from the file name.
|
||||
// Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles.
|
||||
std::string name = boost::filesystem::path(path).filename().string();
|
||||
|
||||
// 3) If the loading succeeded, split and load the config into print / filament / printer settings.
|
||||
// First load the print and printer presets.
|
||||
for (size_t i_group = 0; i_group < 2; ++ i_group) {
|
||||
PresetCollection &presets = (i_group == 0) ? this->prints : this->printers;
|
||||
presets.load_preset(path, name, config).is_external = true;
|
||||
}
|
||||
|
||||
// Now load the filaments. If there are multiple filament presets, split them and load them.
|
||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("nozzle_diameter"));
|
||||
auto *filament_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("filament_diameter"));
|
||||
size_t num_extruders = std::min(nozzle_diameter->values.size(), filament_diameter->values.size());
|
||||
if (num_extruders <= 1) {
|
||||
this->filaments.load_preset(path, name, config).is_external = true;
|
||||
this->filament_presets.clear();
|
||||
this->filament_presets.emplace_back(name);
|
||||
} else {
|
||||
// Split the filament presets, load each of them separately.
|
||||
std::vector<DynamicPrintConfig> configs(num_extruders, this->filaments.default_preset().config);
|
||||
// loop through options and scatter them into configs.
|
||||
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
|
||||
const ConfigOption *other_opt = config.option(key, false);
|
||||
if (other_opt == nullptr)
|
||||
continue;
|
||||
if (other_opt->is_scalar()) {
|
||||
for (size_t i = 0; i < configs.size(); ++ i)
|
||||
configs[i].option(key, false)->set(other_opt);
|
||||
} else {
|
||||
for (size_t i = 0; i < configs.size(); ++ i)
|
||||
static_cast<ConfigOptionVectorBase*>(configs[i].option(key, false))->set_at(other_opt, 0, i);
|
||||
}
|
||||
}
|
||||
// Load the configs into this->filaments and make them active.
|
||||
filament_presets.clear();
|
||||
for (size_t i = 0; i < configs.size(); ++ i) {
|
||||
char suffix[64];
|
||||
if (i == 0)
|
||||
suffix[0] = 0;
|
||||
else
|
||||
sprintf(suffix, " (%d)", i);
|
||||
// Load all filament presets, but only select the first one in the preset dialog.
|
||||
this->filaments.load_preset(path, name + suffix, configs[i], i == 0).is_external = true;
|
||||
filament_presets.emplace_back(name + suffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string PresetCollection::name() const
|
||||
{
|
||||
switch (this->type()) {
|
||||
case Preset::TYPE_PRINT: return "print";
|
||||
case Preset::TYPE_FILAMENT: return "filament";
|
||||
case Preset::TYPE_PRINTER: return "printer";
|
||||
default: return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
// Load a config bundle file, into presets and store the loaded presets into separate files
|
||||
// of the local configuration directory.
|
||||
// Load settings into the provided settings instance.
|
||||
void PresetBundle::load_configbundle(const std::string &path, const DynamicPrintConfig &settings)
|
||||
{
|
||||
// 1) Read the complete config file into the boost::property_tree.
|
||||
namespace pt = boost::property_tree;
|
||||
pt::ptree tree;
|
||||
boost::nowide::ifstream ifs(path);
|
||||
pt::read_ini(ifs, tree);
|
||||
|
||||
// 2) Parse the property_tree, extract the active preset names and the profiles, save them into local config files.
|
||||
std::vector<std::string> loaded_prints;
|
||||
std::vector<std::string> loaded_filaments;
|
||||
std::vector<std::string> loaded_printers;
|
||||
std::string active_print;
|
||||
std::vector<std::string> active_filaments;
|
||||
std::string active_printer;
|
||||
for (const auto §ion : tree) {
|
||||
PresetCollection *presets = nullptr;
|
||||
std::vector<std::string> *loaded = nullptr;
|
||||
std::string preset_name;
|
||||
if (boost::starts_with(section.first, "print:")) {
|
||||
presets = &prints;
|
||||
loaded = &loaded_prints;
|
||||
preset_name = section.first.substr(6);
|
||||
} else if (boost::starts_with(section.first, "filament:")) {
|
||||
presets = &filaments;
|
||||
loaded = &loaded_filaments;
|
||||
preset_name = section.first.substr(9);
|
||||
} else if (boost::starts_with(section.first, "printer:")) {
|
||||
presets = &printers;
|
||||
loaded = &loaded_printers;
|
||||
preset_name = section.first.substr(8);
|
||||
} else if (section.first == "presets") {
|
||||
// Load the names of the active presets.
|
||||
for (auto &kvp : section.second) {
|
||||
if (kvp.first == "print") {
|
||||
active_print = kvp.second.data();
|
||||
} else if (boost::starts_with(kvp.first, "filament")) {
|
||||
int idx = 0;
|
||||
if (kvp.first == "filament" || sscanf(kvp.first.c_str(), "filament_%d", &idx) == 1) {
|
||||
if (int(active_filaments.size()) <= idx)
|
||||
active_filaments.resize(idx + 1, std::string());
|
||||
active_filaments[idx] = kvp.second.data();
|
||||
}
|
||||
} else if (kvp.first == "printer") {
|
||||
active_printer = kvp.second.data();
|
||||
}
|
||||
}
|
||||
} else if (section.first == "settings") {
|
||||
// Load the settings.
|
||||
for (auto &kvp : section.second) {
|
||||
if (kvp.first == "autocenter") {
|
||||
}
|
||||
}
|
||||
} else
|
||||
// Ignore an unknown section.
|
||||
continue;
|
||||
if (presets != nullptr) {
|
||||
// Load the print, filament or printer preset.
|
||||
DynamicPrintConfig config(presets->default_preset().config);
|
||||
for (auto &kvp : section.second)
|
||||
config.set_deserialize(kvp.first, kvp.second.data());
|
||||
// Load the preset into the list of presets, save it to disk.
|
||||
presets->load_preset(Slic3r::config_path(presets->name(), preset_name), preset_name, config, false).save();
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Activate the presets.
|
||||
if (! active_print.empty())
|
||||
prints.select_preset_by_name(active_print, true);
|
||||
if (! active_printer.empty())
|
||||
printers.select_preset_by_name(active_printer, true);
|
||||
// Activate the first filament preset.
|
||||
if (! active_filaments.empty() && ! active_filaments.front().empty())
|
||||
filaments.select_preset_by_name(active_filaments.front(), true);
|
||||
// Verify and select the filament presets.
|
||||
auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_selected_preset().config.option("nozzle_diameter"));
|
||||
size_t num_extruders = nozzle_diameter->values.size();
|
||||
if (this->filament_presets.size() < num_extruders)
|
||||
this->filament_presets.resize(num_extruders, filaments.get_selected_preset().name);
|
||||
for (size_t i = 0; i < num_extruders; ++ i)
|
||||
this->filament_presets[i] = (i < active_filaments.size()) ?
|
||||
filaments.find_preset(active_filaments[i], true)->name :
|
||||
filaments.first_visible().name;
|
||||
}
|
||||
|
||||
void PresetBundle::export_configbundle(const std::string &path, const DynamicPrintConfig &settings)
|
||||
{
|
||||
boost::nowide::ofstream c;
|
||||
c.open(path, std::ios::out | std::ios::trunc);
|
||||
|
||||
// Put a comment at the first line including the time stamp and Slic3r version.
|
||||
{
|
||||
std::time_t now;
|
||||
time(&now);
|
||||
char buf[sizeof "0000-00-00 00:00:00"];
|
||||
strftime(buf, sizeof(buf), "%F %T", gmtime(&now));
|
||||
c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << std::endl;
|
||||
}
|
||||
|
||||
// Export the print, filament and printer profiles.
|
||||
for (size_t i_group = 0; i_group < 3; ++ i_group) {
|
||||
const PresetCollection &presets = (i_group == 0) ? this->prints : (i_group == 1) ? this->filaments : this->printers;
|
||||
for (const Preset &preset : presets()) {
|
||||
if (preset.is_default || preset.is_external)
|
||||
// Only export the common presets, not external files or the default preset.
|
||||
continue;
|
||||
c << "[" << presets.name() << ":" << preset.name << "]" << std::endl;
|
||||
for (const std::string &opt_key : preset.config.keys())
|
||||
c << opt_key << " = " << preset.config.serialize(opt_key) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Export the names of the active presets.
|
||||
c << "[presets]" << std::endl;
|
||||
c << "print = " << this->prints.get_selected_preset().name << std::endl;
|
||||
c << "printer = " << this->printers.get_selected_preset().name << std::endl;
|
||||
for (size_t i = 0; i < this->filament_presets.size(); ++ i) {
|
||||
char suffix[64];
|
||||
if (i > 0)
|
||||
sprintf(suffix, "_%d", i);
|
||||
else
|
||||
suffix[0] = 0;
|
||||
c << "filament" << suffix << " = " << this->filament_presets[i] << std::endl;
|
||||
}
|
||||
|
||||
// Export the following setting values from the provided setting repository.
|
||||
static const char *settings_keys[] = { "autocenter" };
|
||||
c << "[presets]" << std::endl;
|
||||
c << "print = " << this->prints.get_selected_preset().name << std::endl;
|
||||
for (size_t i = 0; i < sizeof(settings_keys) / sizeof(settings_keys[0]); ++ i)
|
||||
c << settings_keys[i] << " = " << settings.serialize(settings_keys[i]) << std::endl;
|
||||
|
||||
c.close();
|
||||
}
|
||||
|
||||
static inline int hex_digit_to_int(const char c)
|
||||
{
|
||||
return
|
||||
@ -261,12 +737,12 @@ void PresetBundle::update_platter_filament_ui_colors(wxBitmapComboBox *ui, unsig
|
||||
extruder_color.clear();
|
||||
|
||||
for (unsigned int ui_id = 0; ui_id < ui->GetCount(); ++ ui_id) {
|
||||
if (! ui->HasClientUntypedData())
|
||||
continue;
|
||||
std::string preset_name = ui->GetString(ui_id).utf8_str().data();
|
||||
size_t filament_preset_id = size_t(ui->GetClientData(ui_id));
|
||||
const Preset &filament_preset = filaments.preset(filament_preset_id);
|
||||
const Preset *filament_preset = filaments.find_preset(preset_name, false);
|
||||
assert(filament_preset != nullptr);
|
||||
// Assign an extruder color to the selected item if the extruder color is defined.
|
||||
std::string filament_rgb = filament_preset.config.opt_string("filament_colour", 0);
|
||||
std::string filament_rgb = filament_preset->config.opt_string("filament_colour", 0);
|
||||
std::string extruder_rgb = (int(ui_id) == ui->GetSelection() && ! extruder_color.empty()) ? extruder_color : filament_rgb;
|
||||
wxBitmap *bitmap = nullptr;
|
||||
if (filament_rgb == extruder_rgb) {
|
||||
@ -362,4 +838,11 @@ const std::vector<std::string>& PresetBundle::printer_options()
|
||||
return s_opts;
|
||||
}
|
||||
|
||||
void PresetBundle::set_default_suppressed(bool default_suppressed)
|
||||
{
|
||||
prints.set_default_suppressed(default_suppressed);
|
||||
filaments.set_default_suppressed(default_suppressed);
|
||||
printers.set_default_suppressed(default_suppressed);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
@ -1,11 +1,15 @@
|
||||
#ifndef slic3r_Preset_hpp_
|
||||
#define slic3r_Preset_hpp_
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include "../../libslic3r/libslic3r.h"
|
||||
#include "../../libslic3r/PrintConfig.hpp"
|
||||
|
||||
class wxBitmap;
|
||||
class wxChoice;
|
||||
class wxBitmapComboBox;
|
||||
class wxItemContainer;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@ -53,10 +57,21 @@ public:
|
||||
// Throws std::runtime_error in case the file cannot be read.
|
||||
DynamicPrintConfig& load(const std::vector<std::string> &keys);
|
||||
|
||||
void save();
|
||||
|
||||
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
||||
std::string label() const;
|
||||
|
||||
// Set the is_dirty flag if the provided config is different from the active one.
|
||||
void set_dirty(const DynamicPrintConfig &config) { this->is_dirty = ! this->config.diff(config).empty(); }
|
||||
void set_dirty(bool dirty = true) { this->is_dirty = dirty; }
|
||||
void reset_dirty() { this->is_dirty = false; }
|
||||
|
||||
// Mark this preset as visible if it is compatible with active_printer.
|
||||
bool enable_compatible(const std::string &active_printer);
|
||||
|
||||
// Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection.
|
||||
bool operator<(const Preset &other) const { return this->name < other.name; }
|
||||
};
|
||||
|
||||
// Collections of presets of the same type (one of the Print, Filament or Printer type).
|
||||
@ -65,17 +80,29 @@ class PresetCollection
|
||||
public:
|
||||
// Initialize the PresetCollection with the "- default -" preset.
|
||||
PresetCollection(Preset::Type type, const std::vector<std::string> &keys);
|
||||
~PresetCollection();
|
||||
|
||||
Preset::Type type() const { return m_type; }
|
||||
std::string name() const;
|
||||
const std::deque<Preset>& operator()() const { return m_presets; }
|
||||
|
||||
// Load ini files of the particular type from the provided directory path.
|
||||
void load_presets(const std::string &dir_path, const std::string &subdir);
|
||||
|
||||
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
||||
// and select it, losing previous modifications.
|
||||
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true);
|
||||
|
||||
// Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame.
|
||||
bool load_bitmap_default(const std::string &file_name);
|
||||
|
||||
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items.
|
||||
void set_bitmap_compatible (const wxBitmap *bmp) { m_bitmap_compatible = bmp; }
|
||||
void set_bitmap_incompatible(const wxBitmap *bmp) { m_bitmap_incompatible = bmp; }
|
||||
|
||||
// Enable / disable the "- default -" preset.
|
||||
void set_default_suppressed(bool default_suppressed);
|
||||
bool is_default_suppressed() const { return m_default_suppressed; }
|
||||
bool is_default_suppressed() const { return m_default_suppressed || m_presets.size() <= 1; }
|
||||
|
||||
// Select a preset. If an invalid index is provided, the first visible preset is selected.
|
||||
Preset& select_preset(size_t idx);
|
||||
@ -87,33 +114,86 @@ public:
|
||||
const Preset& get_edited_preset() const { return m_edited_preset; }
|
||||
// Return a preset possibly with modifications.
|
||||
const Preset& default_preset() const { return m_presets.front(); }
|
||||
// Return a preset by an index. If the preset is active, a temporary copy is returned.
|
||||
Preset& preset(size_t idx) { return (int(idx) == m_idx_selected) ? m_edited_preset : m_presets[idx]; }
|
||||
const Preset& preset(size_t idx) const { return const_cast<PresetCollection*>(this)->preset(idx); }
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false);
|
||||
const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false) const
|
||||
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
|
||||
|
||||
size_t first_visible_idx() const;
|
||||
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
// Return the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
Preset& first_visible() { return this->preset(this->first_visible_idx()); }
|
||||
const Preset& first_visible() const { return this->preset(this->first_visible_idx()); }
|
||||
|
||||
// Return number of presets including the "- default -" preset.
|
||||
size_t size() const { return this->m_presets.size(); }
|
||||
|
||||
// For Print / Filament presets, disable those, which are not compatible with the printer.
|
||||
void enable_disable_compatible_to_printer(const std::string &active_printer);
|
||||
|
||||
size_t num_visible() const { return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); }
|
||||
void delete_preset(const size_t idx);
|
||||
|
||||
// Compare the content of get_selected_preset() with get_edited_preset() configs, return true if they differ.
|
||||
bool current_is_dirty() { return ! this->current_dirty_options().empty(); }
|
||||
// Compare the content of get_selected_preset() with get_edited_preset() configs, return the list of keys where they differ.
|
||||
std::vector<std::string> current_dirty_options() { return this->get_selected_preset().config.diff(this->get_edited_preset().config); }
|
||||
|
||||
// Save the preset under a new name. If the name is different from the old one,
|
||||
// a new preset is stored into the list of presets.
|
||||
// All presets are marked as not modified and the new preset is activated.
|
||||
void save_current_preset(const std::string &new_name);
|
||||
|
||||
// Delete the current preset, activate the first visible preset.
|
||||
void delete_current_preset();
|
||||
|
||||
// Update the choice UI from the list of presets.
|
||||
void update_editor_ui(wxBitmapComboBox *ui);
|
||||
void update_platter_ui(wxChoice *ui);
|
||||
void update_platter_ui(wxBitmapComboBox *ui);
|
||||
|
||||
// Update a dirty floag of the current preset, update the labels of the UI component accordingly.
|
||||
// Return true if the dirty flag changed.
|
||||
bool update_dirty_ui(wxItemContainer *ui);
|
||||
bool update_dirty_ui(wxChoice *ui);
|
||||
|
||||
// Select a profile by its name. Return true if the selection changed.
|
||||
// Without force, the selection is only updated if the index changes.
|
||||
// With force, the changes are reverted if the new index is the same as the old index.
|
||||
bool select_preset_by_name(const std::string &name, bool force);
|
||||
// Select a profile by its name, update selection at the UI component.
|
||||
// Return true if the selection changed.
|
||||
bool select_by_name_ui(char *name, wxItemContainer *ui);
|
||||
bool select_by_name_ui(char *name, wxChoice *ui);
|
||||
|
||||
private:
|
||||
PresetCollection();
|
||||
PresetCollection(const PresetCollection &other);
|
||||
PresetCollection& operator=(const PresetCollection &other);
|
||||
|
||||
// Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER.
|
||||
Preset::Type m_type;
|
||||
// List of presets, starting with the "- default -" preset.
|
||||
std::vector<Preset> m_presets;
|
||||
// Use deque to force the container to allocate an object per each entry,
|
||||
// so that the addresses of the presets don't change during resizing of the container.
|
||||
std::deque<Preset> m_presets;
|
||||
// Initially this preset contains a copy of the selected preset. Later on, this copy may be modified by the user.
|
||||
Preset m_edited_preset;
|
||||
// Selected preset.
|
||||
int m_idx_selected;
|
||||
// Is the "- default -" preset suppressed?
|
||||
bool m_default_suppressed = true;
|
||||
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items.
|
||||
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items of a Platter.
|
||||
// These bitmaps are not owned by PresetCollection, but by a PresetBundle.
|
||||
const wxBitmap *m_bitmap_compatible = nullptr;
|
||||
const wxBitmap *m_bitmap_incompatible = nullptr;
|
||||
// Marks placed at the wxBitmapComboBox of a MainFrame.
|
||||
// These bitmaps are owned by PresetCollection.
|
||||
wxBitmap *m_bitmap_main_frame;
|
||||
};
|
||||
|
||||
// Bundle of Print + Filament + Printer presets.
|
||||
@ -123,14 +203,32 @@ public:
|
||||
PresetBundle();
|
||||
~PresetBundle();
|
||||
|
||||
bool load_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible);
|
||||
|
||||
// Load ini files of all types (print, filament, printer) from the provided directory path.
|
||||
void load_presets(const std::string &dir_path);
|
||||
|
||||
PresetCollection prints;
|
||||
PresetCollection filaments;
|
||||
PresetCollection printers;
|
||||
// Filament preset names for a multi-extruder or multi-material print.
|
||||
// extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size()
|
||||
std::vector<std::string> filament_presets;
|
||||
|
||||
DynamicPrintConfig full_config() const;
|
||||
|
||||
// Load an external config file containing the print, filament and printer presets.
|
||||
// Instead of a config file, a G-code may be loaded containing the full set of parameters.
|
||||
// In the future the configuration will likely be read from an AMF file as well.
|
||||
// If the file is loaded successfully, its print / filament / printer profiles will be activated.
|
||||
void load_config_file(const std::string &path);
|
||||
|
||||
// Load a config bundle file, into presets and store the loaded presets into separate files
|
||||
// of the local configuration directory.
|
||||
// Load settings into the provided settings instance.
|
||||
// Activate the presets stored in the
|
||||
void load_configbundle(const std::string &path, const DynamicPrintConfig &settings);
|
||||
|
||||
// Export a config bundle file containing all the presets and the names of the active presets.
|
||||
void export_configbundle(const std::string &path, const DynamicPrintConfig &settings);
|
||||
|
||||
// Update the colors preview at the platter extruder combo box.
|
||||
void update_platter_filament_ui_colors(wxBitmapComboBox *ui, unsigned int idx_extruder, unsigned int idx_filament);
|
||||
@ -139,7 +237,12 @@ public:
|
||||
static const std::vector<std::string>& filament_options();
|
||||
static const std::vector<std::string>& printer_options();
|
||||
|
||||
// Enable / disable the "- default -" preset.
|
||||
void set_default_suppressed(bool default_suppressed);
|
||||
|
||||
private:
|
||||
bool load_compatible_bitmaps(const std::string &path_bitmap_compatible, const std::string &path_bitmap_incompatible);
|
||||
|
||||
// Indicator, that the preset is compatible with the selected printer.
|
||||
wxBitmap *m_bitmapCompatible;
|
||||
// Indicator, that the preset is NOT compatible with the selected printer.
|
||||
|
@ -8,17 +8,18 @@
|
||||
%name{Slic3r::GUI::Preset} class Preset {
|
||||
// owned by PresetCollection, no constructor/destructor
|
||||
|
||||
bool is_default() %code%{ RETVAL = THIS->is_default; %};
|
||||
bool is_external() %code%{ RETVAL = THIS->is_external; %};
|
||||
bool is_visible() %code%{ RETVAL = THIS->is_visible; %};
|
||||
bool is_dirty() %code%{ RETVAL = THIS->is_dirty; %};
|
||||
bool default() %code%{ RETVAL = THIS->is_default; %};
|
||||
bool external() %code%{ RETVAL = THIS->is_external; %};
|
||||
bool visible() %code%{ RETVAL = THIS->is_visible; %};
|
||||
bool dirty() %code%{ RETVAL = THIS->is_dirty; %};
|
||||
|
||||
const char* name() %code%{ RETVAL = THIS->name.c_str(); %};
|
||||
const char* file() %code%{ RETVAL = THIS->file.c_str(); %};
|
||||
|
||||
bool loaded() %code%{ RETVAL = THIS->loaded; %};
|
||||
|
||||
Ref<DynamicPrintConfig> config() %code%{ RETVAL = &THIS->config; %};
|
||||
Ref<DynamicPrintConfig> config_ref() %code%{ RETVAL = &THIS->config; %};
|
||||
Clone<DynamicPrintConfig> config() %code%{ RETVAL = &THIS->config; %};
|
||||
};
|
||||
|
||||
%name{Slic3r::GUI::PresetCollection} class PresetCollection {
|
||||
@ -27,6 +28,29 @@
|
||||
Ref<Preset> default_preset() %code%{ RETVAL = &THIS->default_preset(); %};
|
||||
size_t size() const;
|
||||
size_t num_visible() const;
|
||||
|
||||
Ref<Preset> get_selected_preset() %code%{ RETVAL = &THIS->get_selected_preset(); %};
|
||||
Ref<Preset> get_current_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
|
||||
std::string get_current_preset_name() %code%{ RETVAL = THIS->get_selected_preset().name; %};
|
||||
Ref<Preset> get_edited_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
|
||||
void set_default_suppressed(bool default_suppressed);
|
||||
|
||||
Ref<Preset> find_preset(char *name, bool first_visible_if_not_found = false) %code%{ RETVAL = THIS->find_preset(name, first_visible_if_not_found); %};
|
||||
|
||||
bool current_is_dirty();
|
||||
std::vector<std::string> current_dirty_options();
|
||||
|
||||
void update_platter_ui(SV *ui)
|
||||
%code%{ wxChoice* cb = (wxChoice*)wxPli_sv_2_object( aTHX_ ui, "Wx::Choice" );
|
||||
THIS->update_platter_ui(cb); %};
|
||||
|
||||
bool update_dirty_ui(SV *ui)
|
||||
%code%{ RETVAL = THIS->update_dirty_ui((wxChoice*)wxPli_sv_2_object(aTHX_ ui, "Wx::Choice")); %};
|
||||
|
||||
bool select_preset_by_name(char *name) %code%{ RETVAL = THIS->select_preset_by_name(name, true); %};
|
||||
bool select_by_name_ui(char *name, SV *ui)
|
||||
%code%{ RETVAL = THIS->select_by_name_ui(name, (wxChoice*)wxPli_sv_2_object(aTHX_ ui, "Wx::Choice")); %};
|
||||
|
||||
%{
|
||||
|
||||
SV*
|
||||
@ -43,6 +67,19 @@ PresetCollection::arrayref()
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
PresetCollection::presets_hash()
|
||||
CODE:
|
||||
HV* hv = newHV();
|
||||
for (size_t i = 1; i < THIS->size(); ++ i) {
|
||||
const Slic3r::Preset &preset = THIS->preset(i);
|
||||
if (! preset.is_default && ! preset.is_external)
|
||||
(void)hv_store(hv, preset.name.c_str(), - int(preset.name.size()), newSVpvn_utf8(preset.file.c_str(), preset.file.size(), true), 0);
|
||||
}
|
||||
RETVAL = (SV*)newRV_noinc((SV*)hv);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
};
|
||||
|
||||
@ -51,10 +88,12 @@ PresetCollection::arrayref()
|
||||
PresetBundle();
|
||||
~PresetBundle();
|
||||
|
||||
void load_bitmaps(std::string path_bitmap_compatible, std::string path_bitmap_incompatible);
|
||||
void load_presets(std::string dir_path);
|
||||
void set_default_suppressed(bool default_suppressed);
|
||||
|
||||
Ref<PresetCollection> prints() %code%{ RETVAL = &THIS->prints; %};
|
||||
Ref<PresetCollection> filaments() %code%{ RETVAL = &THIS->filaments; %};
|
||||
Ref<PresetCollection> printers() %code%{ RETVAL = &THIS->printers; %};
|
||||
Ref<PresetCollection> print() %code%{ RETVAL = &THIS->prints; %};
|
||||
Ref<PresetCollection> filament() %code%{ RETVAL = &THIS->filaments; %};
|
||||
Ref<PresetCollection> printer() %code%{ RETVAL = &THIS->printers; %};
|
||||
|
||||
Clone<DynamicPrintConfig> full_config() %code%{ RETVAL = THIS->full_config(); %};
|
||||
};
|
||||
|
@ -67,6 +67,25 @@ var(file_name)
|
||||
RETVAL = Slic3r::var(file_name);
|
||||
OUTPUT: RETVAL
|
||||
|
||||
void
|
||||
set_data_dir(dir)
|
||||
char *dir;
|
||||
CODE:
|
||||
Slic3r::set_data_dir(dir);
|
||||
|
||||
char*
|
||||
data_dir()
|
||||
CODE:
|
||||
RETVAL = const_cast<char*>(Slic3r::data_dir().c_str());
|
||||
OUTPUT: RETVAL
|
||||
|
||||
std::string
|
||||
config_path(file_name)
|
||||
const char *file_name;
|
||||
CODE:
|
||||
RETVAL = Slic3r::config_path(file_name);
|
||||
OUTPUT: RETVAL
|
||||
|
||||
std::string
|
||||
encode_path(src)
|
||||
const char *src;
|
||||
|
Loading…
Reference in New Issue
Block a user