/* * Title: PupeSimulateWin.cpp * Author: M.Thomas BEAM Ltd * Date: 2007-02-13 * * Contents: Status Display * * Mod Rec: * */ #include <PupeSimulateWin.h> #include <qlayout.h> #include <qpushbutton.h> #include <qvgroupbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qfiledialog.h> #include <BFile.h> PupeSimulateWin::PupeSimulateWin(QWidget* w,Control& c) : ocontrol(c) { QGridLayout* grid; QLabel* channelLabel; QLabel* dataFileLabel; QLabel* contentsLabel; QButton* fileSelectButton; BString s; int row = 0; this->setMaximumSize(QSize(600,500)); grid = new QGridLayout(this,5,3); grid->setMargin(20); grid->setSpacing(20); s = "<p><b>Pupe Test Data<b></p>"; s += "<p>Enter specifications for the test data of a Pupe channel</p>"; contentsLabel = new QLabel(s.retStr(),this); ochannel = new QSpinBox(1,60,1,this,""); ochannel->setWrapping(true); channelLabel = new QLabel("Channel Number",this); dataFileLabel = new QLabel("Test Data file",this); osimulationRamFilename = new QLineEdit(this,"ramfilename"); fileSelectButton = new QPushButton("Select",this,""); oloadSimulationRam = new QPushButton("Load Test Data",this,""); oclearSimulationRam = new QPushButton("Clear Test Data",this,""); row = 0; grid->addWidget(contentsLabel,row,1); row++; grid->addWidget(channelLabel,row,0); grid->addWidget(ochannel,row,1); row++; grid->addWidget(dataFileLabel,row,0); grid->addWidget(osimulationRamFilename,row,1); grid->addWidget(fileSelectButton,row,2); row++; grid->addWidget(oloadSimulationRam,row,1); row++; grid->addWidget(oclearSimulationRam,row,1); row++; connect(fileSelectButton,SIGNAL(clicked()),this,SLOT(selectFile())); connect(oloadSimulationRam,SIGNAL(clicked()),this,SLOT(loadRam())); connect(oclearSimulationRam,SIGNAL(clicked()),this,SLOT(clearRam())); } PupeSimulateWin::~PupeSimulateWin() {} void PupeSimulateWin::selectFile() { QString s = QFileDialog::getOpenFileName( "/usr/tms/data", "Tms Channel Test Data File (*.psd)", this, "open file dialog", "Choose a file" ); osimulationRamFilename->setText(s); } void PupeSimulateWin::show() { BError err; Tms::ConfigInfo info; QWidget::show(); if (err = ocontrol.getConfiguration(info)) { return; } ochannel->setMaxValue(info.puReferences.size()); } void PupeSimulateWin::loadRam() { BError err; BFile f; BString fname; Tms::PuChannel puChannel; BArray< UInt32 > data; int nb; fname = osimulationRamFilename->text().ascii(); if(err = ocontrol.getPuChannel(ochannel->value(), puChannel)){ warningDialog("Pupe Test Data - Loading",err); return; } if (err = f.open(fname,"r")) { warningDialog("Pupe Test Data - Loading",err); return; } data.resize(1024); if((nb = f.read(&data[0], 1024 * sizeof(UInt32))) <= 0){ err.set(1, BString("Error: Reading 1024 32bit data items from file: ") + fname); warningDialog("Pupe Test Data",err); return; } data.resize(nb / sizeof(UInt32)); if (err = ocontrol.setTestData(puChannel,true,data)) { warningDialog("Pupe Test Data - Loading",err); return; } } void PupeSimulateWin::clearRam() { BError err; Tms::PuChannel puChannel; BArray< UInt32 > data; if(err = ocontrol.getPuChannel(ochannel->value(), puChannel)){ warningDialog("Pupe Test Data - Clear",err); return; } if(err = ocontrol.setTestData(puChannel, 0, data)){ warningDialog("Pupe Test Data- Clear",err); return; } } void PupeSimulateWin::warningDialog(BString title, BError err){ BString m; m = BString("<h5>") + title + "</h5><p>" + err.getString() + "</p>"; QMessageBox::warning(this, "Warning", m.retStr()); }