|
@@ -146,6 +146,9 @@ sub _init_menubar {
|
|
|
wxTheApp->append_menu_item($fileMenu, "&Export Config Bundle…", 'Export all presets to file', sub {
|
|
|
$self->export_configbundle;
|
|
|
}, undef, 'lorry_go.png');
|
|
|
+ wxTheApp->append_menu_item($fileMenu, "&Import Config from GCode-File…", 'Load presets from a created GCode-File', sub {
|
|
|
+ $self->import_fromGCode;
|
|
|
+ }, undef, 'lorry_import.png');
|
|
|
$fileMenu->AppendSeparator();
|
|
|
my $repeat;
|
|
|
wxTheApp->append_menu_item($fileMenu, "Q&uick Slice…\tCtrl+U", 'Slice file', sub {
|
|
@@ -557,6 +560,64 @@ sub load_config_file {
|
|
|
$self->{plater}->select_preset_by_name($name, $_) for qw(print filament printer);
|
|
|
}
|
|
|
|
|
|
+sub import_fromGCode{ # import configuration from gcode file sliced with Slic3r
|
|
|
+ my ($self, $file) = @_;
|
|
|
+
|
|
|
+ if (!$file) {
|
|
|
+ my $dir = $last_config ? dirname($last_config) : $Slic3r::GUI::Settings->{recent}{config_directory} || $Slic3r::GUI::Settings->{recent}{skein_directory} || '';
|
|
|
+ my $dlg = Wx::FileDialog->new($self, 'Select GCode File to load config from:', $dir, &Slic3r::GUI::FILE_WILDCARDS->{gcode}, &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
|
|
+ return unless $dlg->ShowModal == wxID_OK;
|
|
|
+ $file = Slic3r::decode_path($dlg->GetPaths);
|
|
|
+ $dlg->Destroy;
|
|
|
+ }
|
|
|
+
|
|
|
+ $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file);
|
|
|
+ wxTheApp->save_settings;
|
|
|
+
|
|
|
+ # open $file and read the first line to make sure it was sliced using Slic3r
|
|
|
+ open(FILEFIRSTLINE, '<', "$file")
|
|
|
+ or die( "Can't open file to import gcode: $!" );
|
|
|
+ my $firstLine = <FILEFIRSTLINE>;
|
|
|
+ close (FILEFIRSTLINE);
|
|
|
+
|
|
|
+ # Exit, if file was not sliced using Slic3r
|
|
|
+ if( index($firstLine, "generated by Slic3r") < 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ # if file sliced by Slic3r, read it
|
|
|
+ open(GFILE, "$file")
|
|
|
+ or die( "Can't open file to import gcode: $!" );
|
|
|
+ my @lines = reverse <GFILE>; # read the file from the back
|
|
|
+
|
|
|
+ my $line;
|
|
|
+ my @settinglines="";
|
|
|
+ foreach $line (@lines) {
|
|
|
+ # if line is empty, we're done -> EOF
|
|
|
+ if (substr($line, 0, 1) eq ";"){
|
|
|
+ $line = substr($line,2, length($line)-2);
|
|
|
+ push @settinglines, $line;
|
|
|
+ } else {
|
|
|
+ last;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ close (GFILE);
|
|
|
+
|
|
|
+ # (over-) write config to temp-file -> <gcode-filename.ini>
|
|
|
+ my $tempfile = substr $file, 0, rindex( $file, q{.} );
|
|
|
+ $tempfile="$tempfile.ini";
|
|
|
+
|
|
|
+ open (TEMPFILESETTINGS, "> $tempfile");
|
|
|
+ print TEMPFILESETTINGS @settinglines;
|
|
|
+ close (TEMPFILESETTINGS);
|
|
|
+
|
|
|
+ $self->load_config_file($tempfile);
|
|
|
+
|
|
|
+ # todo: do we want to delete the <gcode-filename.ini> file after load_config?
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
sub export_configbundle {
|
|
|
my $self = shift;
|
|
|
|