From 8948566ea275b7e6d3de861494885bf58c896afc Mon Sep 17 00:00:00 2001 From: Zaher Salman Date: Thu, 27 Aug 2015 13:59:05 +0200 Subject: [PATCH] Fixed ability to load configuration files with backward compatibility. Development will not be propagated to qt3 branch. --- trimsp/src/TrimSPGUI4/TrimSPGUI4.pm | 121 +++++++++++++++++++++++-- trimsp/src/TrimSPGUI4/Ui_TrimSPGUI4.pm | 4 +- 2 files changed, 113 insertions(+), 12 deletions(-) diff --git a/trimsp/src/TrimSPGUI4/TrimSPGUI4.pm b/trimsp/src/TrimSPGUI4/TrimSPGUI4.pm index 83b7131..1f5cb35 100644 --- a/trimsp/src/TrimSPGUI4/TrimSPGUI4.pm +++ b/trimsp/src/TrimSPGUI4/TrimSPGUI4.pm @@ -41,8 +41,15 @@ sub NEW { sub child { # Take type and name from input my ( $object, $name ) = @_; - my $Attrib = this->findChildren($object, $name); - $Attrib = @{$Attrib}[0]; + + my $Attrib = this->findChildren($object,$name); + if (@$Attrib) { + $Attrib = @$Attrib[0]; + } else { + $Attrib = 0; + } +# print "name = $name and attrib = $Attrib\n"; + # Return handle on widget return($Attrib); } @@ -605,8 +612,8 @@ sub StartSequenceOne this->{ui}->progress->update(); undef %All; undef $cmd; - print "at end\n"; - sleep(10); +# print "at end\n"; +# sleep(10); return(0); } @@ -677,16 +684,23 @@ sub OpenFile open (INF,q{<},"$file" ); my @lines = ; close(INF); +# Remove comment lines, empty lines and lines starting with "[" + @lines = grep {!/^\#/} @lines; + @lines = grep {/\S/} @lines; + @lines = grep {!/^\[/} @lines; + @lines = grep {/\s+/} @lines; + + @lines = &ConvertCFG(@lines); + my $Attrib=""; foreach my $line (@lines) { # Remove white spaces - $line =~ s/\s+//g; +# $line =~ s/\s+//g; my @InitPar = split (/=/,$line); -# Possible backward compatibility: NL to numLayer # Check it is not empty or title line if ($InitPar[0] || $InitPar[1]) { if (!$Types{$InitPar[0]}) { - # No type is found, probably table cell? + # No type is found, probably table cell? $Types{$InitPar[0]}="Qt::LineEdit"; } # Get widget by name @@ -702,17 +716,44 @@ sub OpenFile $Attrib->setChecked(0); } } elsif ($Types{$InitPar[0]} eq "Qt::ComboBox") { - $Attrib-> setCurrentIndex($InitPar[1]); + $Attrib->setCurrentIndex($InitPar[1]); } else { $Attrib->setText($InitPar[1]); } + } else { +# child not found probably table cell +# Identify layers parameters and convert to row column + my $col = $InitPar[0]; + my $row = $InitPar[0]; +# Flag takes 1 for table item and zero if not + my $flag = 0; + $col =~ s/\d//g; + $row =~ s/[^0-9]//g; + if ($col eq "LComp") { + $col = 0; + $flag = 1; + } elsif ($col eq "Lrho") { + $col = 1; + $flag = 1; + } elsif ($col eq "Ld") { + $col = 2; + $flag = 1; + } + if ($flag) { + my $cell = this->{ui}->layerTable->item($row-1,$col); + if (!$cell) { + $cell = Qt::TableWidgetItem(); + this->{ui}->layerTable->setItem($row-1,$col,$cell); + } + this->{ui}->layerTable->item($row-1,$col)->setText($InitPar[1]); + } } } } } } -# Subroutine: Save configuration file to TrimSP.cfg +# Subroutine: Create configuration file sub GenInitFile { my %All = %{CollectValues()}; @@ -794,6 +835,66 @@ sub SaveFileAs } } +# Subroutine: Convert old configuration file to new format +sub ConvertCFG +{ +# Get cleaned lines + my @lines = @_; + +# Backward compatibility: NL to numLayer + my %BackSubs = ("NL","numLayer", + "NProj","numberProj", + "E","valEnergy", + "SigE","sigEnergy", + "Angle","valAngle", + "SigAngle","sigAngle", + "Seed","ranSeed", + "FNPre","fileNamePrefix", + "Path","workPath", + "ScanSeq","scanSeq", + "ScanList","scanList", + "ListRadio","radioList", + "ScanListdz","scanListdz", + "LoopRadio","radioLoop", + "SFrom","scanFrom", + "STo","scanTo", + "SStep","scanStep" + ); + + # Go over all elements of %BackSubs and substitute + foreach my $key (keys %BackSubs) { + @lines = map {s/^$key=/$BackSubs{$key}=/; $_;} @lines; + } + + # deal with ProjType + %BackSubs = ("ProjType=Muon","projComboBox=0", + "ProjType=Li8","projComboBox=1", + "ProjType=B12","projComboBox=2", + "ProjType=H","projComboBox=3" + ); + + # Go over all elements of %BackSubs and substitute + foreach my $key (keys %BackSubs) { + @lines = map {s/^$key/$BackSubs{$key}/; $_;} @lines; + } + + + # deal with scan radios + %BackSubs = ("ERadio=1","comboScan=0", + "SigERadio=1","comboScan=1", + "AngleRadio=1","comboScan=2", + "SigAngleRadio=1","comboScan=3", + "NProjRadio=1","comboScan=4", + ); + + # Go over all elements of %BackSubs and substitute + foreach my $key (keys %BackSubs) { + @lines = map {s/^$key/$BackSubs{$key}/; $_;} @lines; + } + + return(@lines); +} + # Subroutine: Plot implantation profiles using root macro sub PlotProfiles { @@ -930,7 +1031,7 @@ sub findDensity # See if you have the density my $Density=Chem::Densities($Compound); # If the density is in the database submit it - if ($Density != 0 ) { + if ($Density ne "" ) { $layerTable->item($row,$col+1)->setText($Density); } } diff --git a/trimsp/src/TrimSPGUI4/Ui_TrimSPGUI4.pm b/trimsp/src/TrimSPGUI4/Ui_TrimSPGUI4.pm index 7bc1235..cfc926a 100644 --- a/trimsp/src/TrimSPGUI4/Ui_TrimSPGUI4.pm +++ b/trimsp/src/TrimSPGUI4/Ui_TrimSPGUI4.pm @@ -5,7 +5,7 @@ ################################################################################# ## Form generated from reading UI file 'TrimSPGUI4.ui' ## -## Created: Wed Jun 24 14:33:41 2015 +## Created: Thu Aug 27 10:51:18 2015 ## by: Qt User Interface Compiler version 4.8.6 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! @@ -1531,4 +1531,4 @@ sub retranslate_ui { retranslateUi( $trimSPGUI4 ); } -1; +1; \ No newline at end of file