#include "GroupEditor.h" #include "STRodCrate.h" #include "STControlEngine.h" #include "OptionsPanel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include GroupEditor::GroupEditor( STControlEngine &in_engine, int iCrate, int iGrp, QWidget* parent, const char* , bool , Qt::WFlags fl) : QDialog(parent,fl), m_engine(in_engine), m_grpId(iGrp) { setupUi(this); m_crate = m_engine.getSTRodCrates()[iCrate]; PP0Box->clear(); moduleTable->setColumnWidth(0,90); moduleTable->setColumnWidth(1,75); moduleTable->setColumnWidth(2,75); moduleTable->setColumnWidth(3,70); moduleTable->setColumnWidth(4,75); moduleTable->setColumnWidth(5,55); moduleTable->setColumnWidth(6,60); for(int i=7;inumCols();i++) moduleTable->setColumnWidth(i,75); setupTable(); groupLabel->setText(("Configuration of module group "+m_crate->getGrpName(m_grpId)).c_str()); m_pasteAction = new QAction("paste",QKeySequence("Ctrl+V"),this,"pasteAct"); m_copyAction = new QAction("copy",QKeySequence("Ctrl+C"),this,"copyAct"); QObject::connect(saveButton, SIGNAL(clicked()), this, SLOT(saveConfig())); QObject::connect(moduleTable, SIGNAL(valueChanged(int,int)), this, SLOT(setEdited(int,int))); QObject::connect(m_copyAction,SIGNAL(activated()),this,SLOT(copyToCB())); QObject::connect(m_pasteAction,SIGNAL(activated()),this,SLOT(pasteFromCB())); // deal with the group config via the default panel m_op = new optionsPanel(m_crate->getGrpConf(m_grpId),this,"grppan",true); // display optionPanel's tabs in our own display for (int i=0; im_tabwidget->count();i++) tabWidget->insertTab( m_op->m_tabwidget->page(i), m_op->m_tabwidget->label(i)); // connect change of PP0 type to re-calculation of links connect( PP0Box, SIGNAL( activated(int) ), this, SLOT( setAllLinks() ) ); } GroupEditor::~GroupEditor() { } void GroupEditor::saveConfig() { m_op->save(); for(std::vector::iterator it=m_edited.begin(); it!=m_edited.end(); it++){ Config &conf = m_crate->getPixModuleConf(m_grpId, (*it)); //m_modules[(*it)+1]->config(); // write group ID bool isOK; int value = moduleTable->text((*it),3).toInt(&isOK); if(conf["general"]["GroupId"].name()!="__TrashConfObj__" && isOK) *((int *)((ConfInt&)conf["general"]["GroupId"]).m_value) = value; value = moduleTable->text((*it),4).toInt(&isOK); if(conf["general"]["ModuleId"].name()!="__TrashConfObj__" && isOK) *((int *)((ConfInt&)conf["general"]["ModuleId"]).m_value) = value; value = moduleTable->text((*it),5).toInt(&isOK); if(conf["pp0"]["position"].name()!="__TrashConfObj__" && isOK) *((int *)((ConfInt&)conf["pp0"]["position"]).m_value) = value; value = PP0Box->currentItem(); if(value<=2) *((int *)((ConfInt&)conf["pp0"]["Type"]).m_value) = value; value = moduleTable->text((*it),6).toInt(&isOK); if(conf["general"]["InputLink"].name()!="__TrashConfObj__" && isOK) *((int *)((ConfInt&)conf["general"]["InputLink"]).m_value) = value; for(int j=1;j<5;j++){ char llabel[30]; sprintf(llabel,"OutputLink%d",j); value = 16*(moduleTable->text((*it),6+j).left(1).toInt(&isOK))+ moduleTable->text((*it),6+j).right(1).toInt(&isOK); //16*(moduleTable->text((*it),6+j).left(1).toInt(&isOK))+tmpStrg.toInt(&isOK) if(conf["general"][llabel].name()!="__TrashConfObj__" && isOK) *((int *)((ConfInt&)conf["general"][llabel]).m_value) = value; } if(moduleTable->text((*it),1).isEmpty() && conf["geometry"]["Type"].name()!="__TrashConfObj__"){ value = 0; *((int *)((ConfInt&)conf["geometry"]["Type"]).m_value) = value; if(conf["geometry"]["staveID"].name()!="__TrashConfObj__") *((int *)((ConfInt&)conf["geometry"]["staveID"]).m_value) = value; if(conf["geometry"]["position"].name()!="__TrashConfObj__") *((int *)((ConfInt&)conf["geometry"]["position"]).m_value) = value; } else { int aSN = moduleTable->text((*it),1).toInt(&isOK); if(isOK){ if(aSN<9000) value = 1; // stave else value = 2; // sector *((int *)((ConfInt&)conf["geometry"]["Type"]).m_value) = value; if(conf["geometry"]["position"].name()!="__TrashConfObj__") *((int *)((ConfInt&)conf["geometry"]["staveID"]).m_value) = aSN; value = moduleTable->text((*it),2).toInt(&isOK); if((conf["geometry"]["position"].name()!="__TrashConfObj__") && isOK) *((int *)((ConfInt&)conf["geometry"]["position"]).m_value) = value; } } } accept(); } void GroupEditor::setupTable() { std::vector< std::pair > list; m_crate->getModules(m_grpId, list); int allPP0 = -1; for(int iMod=0; iMod<(int)list.size(); iMod++){ moduleTable->setNumRows(iMod+1); //m_modules.insert(std::make_pair(nmod,*it)); moduleTable->setText(iMod,0,TLogFile::GetNameFromPath(m_crate->getModName(m_grpId, iMod).c_str()).c_str()); Config &conf = m_crate->getPixModuleConf(m_grpId, iMod); // assembly info if(conf["geometry"]["Type"].name()!="__TrashConfObj__"){ int assy_type = ((ConfInt&)conf["geometry"]["Type"]).getValue(); if(assy_type>0){ if(conf["geometry"]["staveID"].name()!="__TrashConfObj__") moduleTable->setText(iMod,1,QString::number(((ConfInt&)conf["geometry"]["staveID"]).getValue())); if(conf["geometry"]["position"].name()!="__TrashConfObj__") moduleTable->setText(iMod,2,QString::number(((ConfInt&)conf["geometry"]["position"]).getValue())); } } // read group ID if(conf["general"]["GroupId"].name()!="__TrashConfObj__") moduleTable->setText(iMod,3,QString::number(((ConfInt&)conf["general"]["GroupId"]).getValue())); // read module ID if(conf["general"]["ModuleId"].name()!="__TrashConfObj__") moduleTable->setText(iMod,4,QString::number(((ConfInt&)conf["general"]["ModuleId"]).getValue())); // read PP0-slot if(conf["pp0"]["position"].name()!="__TrashConfObj__") moduleTable->setText(iMod,5,QString::number(((ConfInt&)conf["pp0"]["position"]).getValue())); if(PP0Box->count()==0){ // fill PP0 type box std::map syms = ((ConfList&)conf["pp0"]["Type"]).symbols(); for(std::map::iterator it = syms.begin(); it!=syms.end(); it++) PP0Box->insertItem("dummy"+QString::number(it->second)); for(std::map::iterator it = syms.begin(); it!=syms.end(); it++){ PP0Box->setCurrentItem(it->second); PP0Box->setCurrentText((it->first).c_str()); } PP0Box->insertItem("keep module settings"); } int pp0 = ((ConfInt&)conf["pp0"]["Type"]).getValue(); if(allPP0<0) allPP0 = pp0; else if(allPP0!=pp0) allPP0=3; // read links if(conf["general"]["InputLink"].name()!="__TrashConfObj__") moduleTable->setText(iMod,6,QString::number(((ConfInt&)conf["general"]["InputLink"]).getValue())); for(int j=1;j<5;j++){ char llabel[30]; sprintf(llabel,"OutputLink%d",j); if(conf["general"][llabel].name()!="__TrashConfObj__"){ int olink = ((ConfInt&)conf["general"][llabel]).getValue(); moduleTable->setText(iMod,6+j,QString::number(olink/16)+":"+QString::number(olink%16)); } } } PP0Box->setCurrentItem(allPP0); moduleTable->setColumnReadOnly(0,true); } void GroupEditor::setEdited(int row, int col) { if(col==5){ Config &modConf = m_crate->getPixModuleConf(m_grpId, row+1); //m_modules[row+1]->config(); int pp0 = PP0Box->currentItem(); if(pp0>2) pp0 = ((ConfList&)modConf["pp0"]["Type"]).getValue(); Config &cfgROD = m_crate->getPixCtrlConf(m_grpId); int type = ((ConfInt&)cfgROD["fmt"]["linkMap_0"]).getValue() & 0x3; std::vector in, out1, out2, out3, out4; PixLib::listLinks(in,out1,out2,out3,out4,type, pp0); int slot = moduleTable->text(row,5).toInt(); if(slot>0 && slot<29){ moduleTable->setText(row, 6,QString::number(in.at(slot-1))); moduleTable->setText(row, 7,QString::number(out1.at(slot-1)/16)+":"+QString::number(out1.at(slot-1)%16)); moduleTable->setText(row, 8,QString::number(out2.at(slot-1)/16)+":"+QString::number(out2.at(slot-1)%16)); moduleTable->setText(row, 9,QString::number(out3.at(slot-1)/16)+":"+QString::number(out3.at(slot-1)%16)); moduleTable->setText(row,10,QString::number(out4.at(slot-1)/16)+":"+QString::number(out4.at(slot-1)%16)); // } } else{ moduleTable->setText(row, 6,""); moduleTable->setText(row, 7,""); moduleTable->setText(row, 8,""); moduleTable->setText(row, 9,""); moduleTable->setText(row,10,""); } } // rest (forgotten what) for(std::vector::iterator it=m_edited.begin(); it!=m_edited.end(); it++) if((*it)==row) return; m_edited.push_back(row); // m_editedMod.push_back(m_modules[row+1]); } void GroupEditor::copyToCB() { int i,j, ncsel; QString cbText=""; for(i=0;inumRows();i++){ ncsel=0; for(j=0;jnumCols();j++){ if(moduleTable->isSelected(i,j)){ cbText+=moduleTable->text(i,j)+"\t"; ncsel++; } } if(ncsel>0){ cbText.remove(cbText.length()-1,1); cbText+="\n"; } } QClipboard *cb = QApplication::clipboard(); cb->setText(cbText); } void GroupEditor::pasteFromCB() { int row=-1, col=-1; for(int i=0;inumRows();i++){ for(int j=0;jnumCols();j++){ if(moduleTable->isSelected(i,j)){ row = i; col = j; break; } } } if(row<0 || col<0){ QMessageBox::warning(this,"STControl GroupEditor::pasteFromCB()", "No table cell was selected, can't paste."); return; } QClipboard *cb = QApplication::clipboard(); QString rowText,cellText,cbText=cb->text(); int pos1=0, pos2=0; int currRow = row, currCol = col; // pick CB text into lines - 1 line per table row while(pos1>=0){ pos1 = cbText.find("\n"); if(pos1>=0){ rowText = cbText.left(pos1); pos2 = 0; currCol = col; // pick row text into tab-separated cell entries while(pos2>=0){ pos2 = rowText.find("\t"); if(pos2>=0){ cellText = rowText.left(pos2); rowText.remove(0,pos2+1); if(currColnumCols() && currRownumRows()) moduleTable->setText(currRow, currCol, cellText); currCol++; } } // last part of line has not tab at the end, must paste explicitly if(currColnumCols() && currRownumRows()) moduleTable->setText(currRow, currCol, rowText); // remove processed line from CB text cbText.remove(0,pos1+1); currRow++; } } } void GroupEditor::setAllLinks() { if(PP0Box->currentText()!="keep module settings"){ for(int i=0;inumRows();i++){ setEdited(i, 5); } } }