/* * Title: PhaseTableWin.cpp * Author: M.Thomas BEAM Ltd * Date: 2007-02-13 * * Contents: Status Display * * Mod Rec: * */ #include <PhaseTableWin.h> #include <qlayout.h> #include <qpushbutton.h> #include <qvgroupbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qfiledialog.h> #include <qcheckbox.h> #include <BFile.h> #include <qgroupbox.h> #include <qvbox.h> #include <Globals.h> #include <TmsD.h> #include <TmsC.h> #include <TmsS.h> #include <TmsLib.h> using namespace Tms; PhaseTableWin::PhaseTableWin(QWidget* w,Control& c) : ocontrol(c) { QGridLayout* grid; QLabel* dataFileLabel; QLabel* contentsLabel; BString s; int row = 0; this->setMaximumSize(QSize(600,650)); grid = new QGridLayout(this,5,3); grid->setMargin(20); grid->setSpacing(20); s = "<p><b>Cycle Parameters<b></p>"; s += "<p>Select Cycle parameters file to be loaded</p>"; contentsLabel = new QLabel(s.retStr(),this); dataFileLabel = new QLabel("Cycle Parameters File",this); oreadCycleParamsFile = new QPushButton("Select",this,""); ocycleParamsFilename = new QLineEdit(this,"ramfilename"); oloadCycleParams = new QPushButton("Load Cycle Parameters",this,""); osaveCycleParamsFile = new QPushButton("Save Cycle Parameters",this,""); ocycleType = new QLineEdit(this,""); oinfo = new QLineEdit(this,""); opllFrefGain = new QLineEdit(this,""); opllGain = new QLineEdit(this,""); opllInitialFrequency = new QLineEdit(this,""); opllInitialFrequencyDelay = new QLineEdit(this,""); row = 0; grid->addWidget(contentsLabel,row,1); row++; grid->addWidget(dataFileLabel,row,0); grid->addWidget(ocycleParamsFilename,row,1); grid->addWidget(oreadCycleParamsFile,row,2); row++; grid->addWidget(new QLabel("Cycle Type",this,""),row,0);grid->addWidget(ocycleType,row,1);row++; grid->addWidget(new QLabel("Info",this,""),row,0);grid->addWidget(oinfo,row,1); row++; grid->addWidget(new QLabel("Pll Initial Frequency",this,""),row,0);grid->addWidget(opllInitialFrequency,row,1);row++; grid->addWidget(new QLabel("Pll Initial Frequency Delay",this,""),row,0);grid->addWidget(opllInitialFrequencyDelay,row,1);row++; grid->addWidget(new QLabel("Pll Fref Gain",this,""),row,0);grid->addWidget(opllFrefGain,row,1);row++; grid->addWidget(new QLabel("Pll Gain",this,""),row,0);grid->addWidget(opllGain,row,1);row++; grid->addWidget(oloadCycleParams,row,1); row++; grid->addWidget(osaveCycleParamsFile,row,1); row++; connect(oreadCycleParamsFile,SIGNAL(clicked()),this,SLOT(readCycleParamsFile())); connect(oloadCycleParams,SIGNAL(clicked()),this,SLOT(loadCycleParams())); connect(osaveCycleParamsFile,SIGNAL(clicked()),this,SLOT(saveCycleParamsFile())); } PhaseTableWin::~PhaseTableWin() {} void PhaseTableWin::readCycleParamsFile() { BError err; BFile f; BString fname; TmsCycleParams cycleParamFile(""); QString s = QFileDialog::getOpenFileName( "/usr/tms/stateTables", "Tms Cycle Parameters File (*.spt)", this, "open file dialog", "Choose a file" ); ocycleParamsFilename->setText(s); fname = ocycleParamsFilename->text().ascii(); if (err = f.open(fname,"r")) { warningDialog("Cycle Parameters - Reading",err); return; } if(err = cycleParamFile.getCycleParams(fname,oparams)) { warningDialog("Cycle Parameters - Read Parsing",err); return; } update(); gstatusbar->message("Cycle Parameters Read",2000); } void PhaseTableWin::loadCycleParams() { BError err; if(err = ocontrol.setControlInfo(oparams)){ warningDialog("Cycle Parameters - Loading Cycle Params",err); return; } gstatusbar->message("Cycle Parameters Loaded",2000); } void PhaseTableWin::update() { ocycleType->setText(oparams.cycleType.retStr()); oinfo->setText(oparams.info.retStr()); opllInitialFrequency->setText(uIntToStr(oparams.pllInitialFrequency).retStr()); opllInitialFrequencyDelay->setText(uIntToStr(oparams.pllInitialFrequencyDelay).retStr()); opllFrefGain->setText(uIntToStr(oparams.pllFrefGain).retStr()); opllGain->setText(uIntToStr(oparams.pllGain).retStr()); } void PhaseTableWin::saveCycleParamsFile() { BError err; BFile f; BString fname; TmsCycleParams cycleParamFile(""); bool ok; fname = ocycleParamsFilename->text().ascii(); oparams.cycleType = ocycleType->text().ascii(); oparams.info = oinfo->text().ascii(); oparams.pllInitialFrequency = opllInitialFrequency->text().toUInt(&ok); oparams.pllInitialFrequencyDelay = opllInitialFrequencyDelay->text().toUInt(&ok); oparams.pllFrefGain = opllFrefGain->text().toUInt(&ok); oparams.pllGain = opllGain->text().toUInt(&ok); QString s = QFileDialog::getSaveFileName("/usr/tms/stateTables","Tms Cycle Parameters File (*.spt)",this,"save file dialog","Specify filename"); fname = s.ascii(); if (fname.len() == 0) return; if (QFile::exists(fname.retStr())){ BString msg = "The specified file already exists are you "; msg += BString("positive you wish to over write the file"); if (! confirmDialog("Confirm Action",msg)) { return; } } if(err = cycleParamFile.writeCycleParams(fname,oparams)) { warningDialog("Cycle Parameters - Save",err); return; } ocycleParamsFilename->setText(fname.retStr()); gstatusbar->message("Cycle Parameters Saved",2000); } BString PhaseTableWin::uIntToStr(UInt32 val) { BString s; s.printf("%lu",val); return s; } void PhaseTableWin::warningDialog(BString title, BError err){ BString m; QMessageBox b; m = BString("<h5>") + title + "</h5><p>" + err.getString() + "</p>"; b.setMinimumWidth(300); b.setCaption("tmsControlGui - Warning"); b.setIcon(QMessageBox::Warning); b.setText(m.retStr()); b.exec(); } int PhaseTableWin::confirmDialog(BString title,BString msg){ BString m; m = BString("<h5>") + title + "</h5><p>" + msg + "</p>"; if (QMessageBox::question(this,"tmsControlGui - Question",m.retStr(),QMessageBox::Ok,QMessageBox::Cancel) == QMessageBox::Ok) { return 1; } else { return 0; } }