#include "ConfigTable.h" #include "GeneralDBfunctions.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ConfigTable::ConfigTable(QApplication &app, QWidget* parent, const char* , bool , Qt::WFlags fl) : QDialog(parent,fl), m_app(app){ // : ConfigTableBase(parent,name,modal,fl), m_app(app){ setupUi(this); QObject::connect(addModButton, SIGNAL(clicked()), this, SLOT(addModule())); QObject::connect(addStaveButton, SIGNAL(clicked()), this, SLOT(addStave())); QObject::connect(browseButton, SIGNAL(clicked()), this, SLOT(browseModPath())); QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); QObject::connect(configPath, SIGNAL(textChanged(QString)), this, SLOT(checkOutDir())); QObject::connect(configRootDB, SIGNAL(toggled(bool)), this, SLOT(rootdbSet(bool))); QObject::connect(configTDAQ, SIGNAL(toggled(bool)), this, SLOT(tdaqSet(bool))); QObject::connect(moduleTable, SIGNAL(currentChanged(int,int)), this, SLOT(currentCell(int,int))); QObject::connect(moduleTable, SIGNAL(valueChanged(int,int)), this, SLOT(calculateLinks(int,int))); QObject::connect(newRodButton, SIGNAL(clicked()), this, SLOT(acceptNewRod())); QObject::connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); QObject::connect(PP0Box, SIGNAL(activated(int)), this, SLOT(pp0TypeChanged())); QObject::connect(removeButton, SIGNAL(clicked()), this, SLOT(removeEntry())); QObject::connect(rodSpeed, SIGNAL(activated(int)), this, SLOT(pp0TypeChanged())); m_currRow = -1; m_userPDB=""; m_passwdPDB=""; // configure module table int i; moduleTable->setColumnWidth(0,80); moduleTable->setColumnWidth(1,65); moduleTable->setColumnWidth(2,60); moduleTable->setColumnWidth(3,55); moduleTable->setColumnWidth(4,35); moduleTable->setColumnWidth(5,45); for(i=6;i<10;i++) moduleTable->setColumnWidth(i,60); moduleTable->setColumnWidth(10,200); moduleTable->setColumnWidth(11,200); } ConfigTable::~ConfigTable(){ } void ConfigTable::browseModPath(){ QString path = Q3FileDialog::getExistingDirectory(configPath->text(),this,"outpath", "select module base dir",FALSE); configPath->setText(path); } void ConfigTable::addEntry(const char *mname, const char *staveSN, int pos, const char *connName){ int nRows=moduleTable->numRows()+1; QString myConnName = ""; if(connName!=0) myConnName = connName; if(nRows>26){ // more than the ROD can cope with - issue a warning } moduleTable->setNumRows(nRows); moduleTable->setText(nRows-1,0,mname); if(staveSN!=0){ moduleTable->setText(nRows-1,1,staveSN); if(pos>=0) moduleTable->setText(nRows-1,2,QString::number(pos)); } moduleTable->setText(nRows-1,3,QString::number((nRows-1)%4)); int slot = slotOffset->value()+nRows; // crreate rest of connectivity name if(myConnName.left(1)=="D"){ myConnName += QString::number(pos); slot += (nRows-1)/6; } else if(myConnName.left(1)=="L"){ int cPos = pos-7; slot += (nRows-1)/13; if(myConnName.right(1)=="2" && cPos>=0) slot +=1; if(cPos<0){ cPos = 7-pos; myConnName += (myConnName.right(1)=="1"?"-C/7":"-C/6"); myConnName += "-M"+QString::number(cPos)+"C"; } else if (cPos==0){ myConnName += (myConnName.right(1)=="1"?"-C/7":"-A/7"); myConnName += "-M0"; }else{ myConnName += (myConnName.right(1)=="1"?"-A/6":"-A/7"); myConnName += "-M"+QString::number(cPos)+"A"; } } moduleTable->setText(nRows-1,11,myConnName); if(myConnName.left(1)=="D") moduleTable->setText(nRows-1,4,QString::number(slot)); calculateLinks(nRows-1,4); return; } void ConfigTable::addModule(){ ModWin getmod(this,"NewModule", TRUE, Qt::WType_TopLevel); getmod.TextboxLabel->setText("Enter module SN"); getmod.ModuleName->setFocus(); if(getmod.exec()==1 && !getmod.ModuleName->text().isEmpty()){ addEntry(getmod.ModuleName->text().latin1()); loadCfgFilenames(moduleTable->numRows()-1); okButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); newRodButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); } return; } void ConfigTable::addStave(){ ModWin getstv(this,"NewStave", TRUE, Qt::WType_TopLevel); getstv.ModuleName->setText("2021200001"); getstv.TextboxLabel->setText("Enter stave/sector SN"); getstv.ModuleName->setFocus(); if(getstv.exec()==1 && !getstv.ModuleName->text().isEmpty()){ if(m_userPDB.isEmpty() || m_passwdPDB.isEmpty()){ LoginPanel lp(this,"loginpanel"); lp.HostLabel->setText("Login details for PDB:"); lp.HostName->hide(); lp.UserID->setText(""); lp.Password->setText(""); lp.exec(); m_userPDB = lp.UserID->text(); m_passwdPDB = lp.Password->text(); } // get modules for this stave/sector CDatabaseCom cdb(m_userPDB.latin1(),m_passwdPDB.latin1(), (getstv.ModuleName->text()).latin1()); QApplication::setOverrideCursor(Qt::waitCursor); std::vector modSNs = cdb.getStaveSNs(m_app); // check if stave/sector is already assembled QString connName=""; // if(connNameBox->isChecked()){ CDatabaseCom cdb2(m_userPDB.latin1(),m_passwdPDB.latin1(), (getstv.ModuleName->text()).latin1()); std::string par1Name, par2Name; int par1Pos, par2Pos; cdb2.getParent(m_app, par1Name, par1Pos); if(getstv.ModuleName->text().right(4).left(1)!="9" && par1Pos>=0){ // it's not a sector, must be stave -> get half-shell from bi-stave CDatabaseCom cdb3(m_userPDB.latin1(),m_passwdPDB.latin1(), par1Name.c_str()); cdb3.getParent(m_app, par2Name, par2Pos); // if(par2Pos>=0) par2Pos++; if(par2Pos>=0){ QString tmpSN = par2Name.c_str(); // define off-set in bi-stave count for bottom HS int incr = 2-tmpSN.left(1).toInt(); int nbist[3]={6,10,13}; incr = incr*nbist[tmpSN.right(2).left(1).toInt()]; if(par2Pos==0) incr = 2*nbist[tmpSN.right(2).left(1).toInt()]; else incr += par2Pos; connName = "L"+tmpSN.right(2).left(1)+"-B"+QString::number(incr)+"-S"+QString::number(par1Pos); } } else if(par1Pos>=0){ QString tmpSN = par1Name.c_str(); connName = "D"+tmpSN.right(2).left(1)+(tmpSN.right(1)=="1"?"A":"C"); connName += "-S"+QString::number(par1Pos+1)+"-M"; } //} int posCount=0; for(std::vector::iterator it=modSNs.begin(); it!=modSNs.end();it++){ posCount++; QString tmpstr = (*it).c_str(); addEntry(tmpstr.latin1(), getstv.ModuleName->text().right(4).latin1(), posCount, connName.latin1()); loadCfgFilenames(moduleTable->numRows()-1); } okButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); newRodButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); } QApplication::restoreOverrideCursor(); } void ConfigTable::removeEntry(){ if(m_currRow<0) { QMessageBox::warning(this,"ConfigTable::removeEntry","You must select a cell before trying to remove it!"); return; } if(moduleTable->isRowReadOnly(m_currRow)){ QMessageBox::warning(this,"ConfigTable::removeEntry","Module entry is read-only, can't delete."); return; } // special treat for last column - could be a combo box int lastCol = moduleTable->numCols()-1; Q3ComboTableItem *tabIt = dynamic_cast(moduleTable->item(m_currRow,lastCol)); if(tabIt!=0){ delete tabIt; moduleTable->setItem( m_currRow, lastCol, 0); } int nRows=moduleTable->numRows(); for(int i=m_currRow; inumCols()-1;col++) moduleTable->setText(i,col,moduleTable->text(i+1,col)); // special treat for last column - could be a combo box tabIt = dynamic_cast(moduleTable->item(i+1,lastCol)); if(tabIt==0){ moduleTable->setText(i, lastCol, moduleTable->text(i+1,lastCol)); } else{ moduleTable->takeItem(tabIt); moduleTable->setItem(i, lastCol, tabIt); } } moduleTable->setNumRows(nRows-1); m_currRow = moduleTable->currentRow(); okButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); newRodButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); } void ConfigTable::currentCell(int row,int){ m_currRow = row; } void ConfigTable::checkOutDir(){ okButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); newRodButton->setEnabled((!configPath->text().isEmpty() && moduleTable->numRows()>0)); if(!configPath->text().isEmpty()) loadCfgFilenames(-1); } void ConfigTable::loadCfgFilenames(int row){ int i, rowStart=row, rowStop=row+1; if(row<0){ rowStart= 0; rowStop = moduleTable->numRows(); } QString fullPath; for(i=rowStart;iisRowReadOnly(i)){ delete (moduleTable->item(i,10)); fullPath = configPath->text(); if(configTDAQ->isChecked()){ fullPath += "/M"; fullPath += moduleTable->text(i,0); fullPath += "/configs/"; QDir cfgdir(fullPath,"*.cfg",QDir::Name, QDir::Files); int nFiles = cfgdir.count(); if(nFiles==1) moduleTable->setText(i,10,cfgdir[0]); else if(nFiles>1){ Q3ComboTableItem *comboItem = new Q3ComboTableItem ( moduleTable, cfgdir.entryList() ); comboItem->setCurrentItem(0); moduleTable->setItem( i, 10, comboItem); } } else if(configRootDB->isChecked()){ fullPath += "/M"; fullPath += moduleTable->text(i,0); QDir cfgdir(fullPath,"*.cfg.root",QDir::Name, QDir::Files); int nFiles = cfgdir.count(); if(nFiles==1) moduleTable->setText(i,10,cfgdir[0]); else if(nFiles>1){ Q3ComboTableItem *comboItem = new Q3ComboTableItem ( moduleTable, cfgdir.entryList() ); comboItem->setCurrentItem(0); moduleTable->setItem( i, 10, comboItem); } } } } } void ConfigTable::tdaqSet(bool isON){ configRootDB->setChecked(!isON); loadCfgFilenames(-1); // connNameBox->setEnabled(!isON); // if(isON) connNameBox->setChecked(false); // if(!isON) // QMessageBox::warning(this,"Module cfg page","RootDB mode not yet implemented."); // configTDAQ->setChecked(true); // configRootDB->setChecked(false); } void ConfigTable::rootdbSet(bool isON){ configTDAQ->setChecked(!isON); loadCfgFilenames(-1); // connNameBox->setEnabled(isON); // if(!isON) connNameBox->setChecked(false); // if(isON) // QMessageBox::warning(this,"Module cfg page","RootDB mode not yet implemented."); // configTDAQ->setChecked(true); // configRootDB->setChecked(false); } void ConfigTable::loadModules(std::vector names){ configTabWidget->setCurrentPage(1); configTabWidget->setTabEnabled(configTabWidget->page(0),false); for(std::vector::iterator IT=names.begin(); IT!=names.end(); IT++){ addEntry((*IT).latin1()); int currRow=moduleTable->numRows()-1; moduleTable->setText(currRow,3,""); moduleTable->setText(currRow,4,""); moduleTable->setText(currRow,5,""); moduleTable->setText(currRow,6,""); moduleTable->setText(currRow,7,""); moduleTable->setText(currRow,8,""); moduleTable->setText(currRow,9,""); moduleTable->setText(currRow,10,"already loaded module"); moduleTable->setRowReadOnly(currRow,true); } newRodButton->hide(); } void ConfigTable::calculateLinks(int row, int col) { if(col==4) { int pp0 = PP0Box->currentItem(); int type = rodSpeed->currentItem(); std::vector in, out1, out2, out3, out4; PixLib::listLinks(in,out1,out2,out3,out4,type, pp0); int slot = moduleTable->text(row,col).toInt(); for(int i = 0; i<28; i++) { if(slot==i+1) { moduleTable->setText(row,5,QString::number(in.at(i))); moduleTable->setText(row,6,QString::number(out1.at(i)/16)+":"+QString::number(out1.at(i)%16)); moduleTable->setText(row,7,QString::number(out2.at(i)/16)+":"+QString::number(out2.at(i)%16)); moduleTable->setText(row,8,QString::number(out3.at(i)/16)+":"+QString::number(out3.at(i)%16)); moduleTable->setText(row,9,QString::number(out4.at(i)/16)+":"+QString::number(out4.at(i)%16)); return; } } moduleTable->setText(row,5,""); moduleTable->setText(row,6,""); moduleTable->setText(row,7,""); moduleTable->setText(row,8,""); moduleTable->setText(row,9,""); } return; } void ConfigTable::pp0TypeChanged() { for(int i = 0; inumRows(); i++) { if(!(moduleTable->isRowReadOnly(i))) calculateLinks(i,4); } }