From ab89469494f6434c6c74f707e6e5065ad8e97159 Mon Sep 17 00:00:00 2001 From: Gilbert Date: Fri, 23 Feb 2018 01:26:58 +0100 Subject: [PATCH] Import Config from GCode File (#4316) * Added comments to avoid merge conflicts. * Import Config from GCode-File * undo comments in prefs * Update MainFrame.pm * Update MainFrame.pm consistent code --- lib/Slic3r/GUI/MainFrame.pm | 61 ++++++++++++++++++++++++++++++++++++ var/lorry_import.png | Bin 0 -> 798 bytes 2 files changed, 61 insertions(+) create mode 100644 var/lorry_import.png diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 345e9b631..bcfc81f39 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -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 = ; + 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 ; # 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 -> + 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 file after load_config? + +} + sub export_configbundle { my $self = shift; diff --git a/var/lorry_import.png b/var/lorry_import.png new file mode 100644 index 0000000000000000000000000000000000000000..5aaf8a33ea11da9c7bbefa35734ed9c559d8a225 GIT binary patch literal 798 zcmV+(1L6FMP)pF8FWQhbW?9;ba!ELWdLwtX>N2bZe?^J zG%heMGBNQWX_Wu~0-H%hK~y+TrIJ}l)Ik`)|J6$u^wdKHLC~SmO=YB|rEX$$SXt2R zwOSrqXqhOwYMEKt7F$|oy4i+qY3ZtMwX2(^ZLL>cTcVO3bkP<)^c4LXSBQ+Ihz5Sl z%s1cnV?Jgi;JUh<3jhBx!3^eBRy#4}ZhulQI6G2;U1aG@4L}IQ; zRMTI3nqFfTJ%*z^txTc&RswxBXIY(oA75n+tCH^FdD!sHJ+@Nr5HzWS#r*f-lWd~S z_KDgqJ4NOfEQ!APQG_LFu-~N0J~m%$BS784+H5QSnHFTJ4R|Nk<9X0b_-QL%33o7d z*m?5>K7WOU;krSuB-Nh?boBbHIt^Pz5?y8SwCfJgb}f>YD`7NU-h-(mhAD}on5i6t zrN_=EA(#`S9TL=JtYhFoo}<@}8?ihoj-mBx1kHsZSTF6QOzqD?<#={$yjhSjmOSGC zwVfYu*^A6BF>x zo`|1nG66YLze`(u<`d{WmrW~Yv(al70V`bCuzUtStEVt6ek5|OA31et9If8R<%Uc& zjag_drzm->VtbzJ&|A8?y7q^Lh7uJOg;=9dD43o+f*pk(eEST8cuu+{e{k^lez literal 0 HcmV?d00001