259 lines
5.5 KiB
C
259 lines
5.5 KiB
C
/****************************************************************************
|
|
** ui.h extension file, included from the uic-generated form implementation.
|
|
**
|
|
** If you want to add, delete, or rename functions or slots, use
|
|
** Qt Designer to update this file, preserving your code.
|
|
**
|
|
** You should not define a constructor or destructor in this file.
|
|
** Instead, write your code in functions called init() and destroy().
|
|
** These will automatically be called by the form's constructor and
|
|
** destructor.
|
|
*****************************************************************************/
|
|
|
|
|
|
void QmuSRSim::fileNew()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::fileOpen()
|
|
{
|
|
my $file=Qt::FileDialog::getOpenFileName(
|
|
".",
|
|
"Initialization file (.* *.*)",
|
|
this,
|
|
"open file dialog",
|
|
"Choose an initialization file");
|
|
|
|
# If the user gave a valid filename try to read it
|
|
if ($file ne "") {
|
|
open (INF,q{<},"$file" );
|
|
my @lines = <INF>;
|
|
close(INF);
|
|
my $Attrib="";
|
|
foreach my $line (@lines) {
|
|
# Remove white spaces
|
|
$line =~ s/\s+//g;
|
|
my @InitPar = split (/=/,$line);
|
|
# Check it is not empty or title line
|
|
if ($InitPar[0] ne "" && $InitPar[1] ne "") {
|
|
$Attrib = child($InitPar[0]);
|
|
$Attrib->setText($InitPar[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void QmuSRSim::fileSave()
|
|
{
|
|
my %All=CreateAllInput();
|
|
my $InitFile="";
|
|
for my $key (keys %All) {
|
|
$InitFile=$InitFile.$key."=".$All{$key}."\n";
|
|
}
|
|
|
|
# Save to default file name "TriumSP.cfg"
|
|
my $file = "musrSim.cfg";
|
|
open (OUTF,q{>},"$file" );
|
|
print OUTF (" $InitFile");
|
|
close(OUTF);
|
|
}
|
|
|
|
|
|
void QmuSRSim::fileSaveAs()
|
|
{
|
|
my %All=CreateAllInput();
|
|
my $InitFile="";
|
|
for my $key (keys %All) {
|
|
$InitFile=$InitFile.$key."=".$All{$key}."\n";
|
|
}
|
|
|
|
my $file=Qt::FileDialog::getSaveFileName(
|
|
"musrSim cfg",
|
|
"musrSim GUI Initialization file (*.cfg)",
|
|
this,
|
|
"save file dialog",
|
|
"Choose a filename to save under");
|
|
# if the user gave a filename then sanesave copy to it
|
|
if ($file ne "") {
|
|
open (OUTF,q{>},"$file" );
|
|
print OUTF (" $InitFile");
|
|
close(OUTF);
|
|
}
|
|
}
|
|
|
|
|
|
void QmuSRSim::filePrint()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::fileExit()
|
|
{
|
|
my $Ans = Qt::MessageBox::question( this, "Quit?","Are you sure you want to quit?","&Yes","&No","",0,1);
|
|
if ($Ans==0) {
|
|
# Then quit
|
|
Qt::Application::exit( 0 );
|
|
}
|
|
# Otherwize go back
|
|
}
|
|
|
|
|
|
void QmuSRSim::editUndo()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::editRedo()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::editCut()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::editCopy()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::editPaste()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::editFind()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::helpIndex()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::helpContents()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void QmuSRSim::helpAbout()
|
|
{
|
|
my $AboutText="
|
|
This is a GUI that uses the muSRSim binary, to simulate the LEM muon
|
|
beam properties.
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This software is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with MuSRFitGUI. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
Copyright 2011 by Zaher Salman and the LEM Group.
|
|
<zaher.salman\@psi.ch>
|
|
";
|
|
my $AboutWindow = Qt::MessageBox::information( this, "About QmuSRSim GUI",$AboutText);
|
|
|
|
}
|
|
|
|
void QmuSRSim::CreateAllInput()
|
|
{
|
|
my %All=();
|
|
my @AllParams= ("L1","L3","TL","BFIELD","RA_T","RA_B","RA_R","RA_L","SR_B","SR_E","ENERGY",
|
|
"L1_2","L2_2","L3_2","BFIELD_2","RA_T_2","RA_B_2","RA_R_2","RA_L_2","ENERGY_2");
|
|
foreach my $Param (@AllParams) {
|
|
my $Child = child($Param);
|
|
my $Value = $Child->text;
|
|
$All{$Param}=$Value;
|
|
# print "$Param=".$All{$Param}."\n";
|
|
}
|
|
# Return Hash with all important values
|
|
return %All;
|
|
}
|
|
|
|
|
|
|
|
void QmuSRSim::StartCalc()
|
|
{
|
|
my %All=CreateAllInput();
|
|
my $Page = Tabs->currentPageIndex;
|
|
my %ToReplace=();
|
|
my @SpaceHolder=();
|
|
my $FName="SRBeamLine.mac";
|
|
# 0 for spin rotator and 1 for current.
|
|
if ($Page == 0) {
|
|
%ToReplace= (
|
|
"L1"=>"L1VOLTAGE",
|
|
"L3"=>"L3VOLTAGE",
|
|
"TL"=>"TLVOLTAGE",
|
|
"BFIELD"=>"SAM_BFIELD",
|
|
"RA_T"=>"RA_TVOL",
|
|
"RA_B"=>"RA_BVOL",
|
|
"RA_R"=>"RA_RVOL",
|
|
"RA_L"=>"RA_LVOL",
|
|
"SR_B"=>"SR_BFIELD",
|
|
"SR_E"=>"SR_EFIELD",
|
|
"ENERGY"=>"ENERGY"
|
|
);
|
|
# Use the following template
|
|
$FName="SRBeamLine.mac";
|
|
} elsif ($Page == 1) {
|
|
%ToReplace= (
|
|
"L1_2"=>"L1VOLTAGE",
|
|
"L2_2"=>"L2VOLTAGE",
|
|
"L3_2"=>"L3VOLTAGE",
|
|
"BFIELD_2"=>"SAM_BFIELD",
|
|
"RA_T_2"=>"RA_TVOL",
|
|
"RA_B_2"=>"RA_BVOL",
|
|
"RA_R_2"=>"RA_RVOL",
|
|
"RA_L_2"=>"RA_LVOL",
|
|
"ENERGY_2"=>"ENERGY"
|
|
);
|
|
# Use the following template
|
|
$FName="CBeamLine.mac";
|
|
}
|
|
|
|
open(MACF,"$FName");
|
|
my @lines=<MACF>;
|
|
close(MACF);
|
|
|
|
for my $key (keys %ToReplace) {
|
|
# Need to check values of replace parameters...
|
|
map(s/$ToReplace{$key}/$All{$key}/, @lines);
|
|
print "Replacing \t".$ToReplace{$key}."\t by \t".$All{$key}."\n";
|
|
}
|
|
|
|
open(NEWMACF,">1000.mac");
|
|
print NEWMACF @lines;
|
|
close(NEWMACF);
|
|
|
|
my $DIR=`pwd`;
|
|
chomp $DIR;
|
|
my $SimDIR="~/LEM/simulation/geant4/musrSim";
|
|
my $SYSROOT="/usr/local";
|
|
my $cmd="cd $SimDIR; . /usr/local/geant4/4.9.3/env.sh; export SYSROOT=$SYSROOT; cd run; $SimDIR/bin/Linux-g++/musrSim $DIR/1000.mac";
|
|
system("$cmd");
|
|
|
|
}
|
|
|