#include "ModuleMap.h" #include "ModuleLabel.h" #include "Sector.h" #include #include #include #include #include #include #include #include #include #include //Added by qt3to4: #include #include #include #include ModuleMap::ModuleMap(int items, int modules, const char *in_label, QWidget* parent, const char* name, bool modal, Qt::WFlags fl) : QDialog(parent, name, modal, fl), m_nItems(items), m_nMods(modules), m_assyType(userdef) { if ( !name ) setName( "ModuleMapBase" ); setCaption("Module map"); setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, 0, 0, sizePolicy().hasHeightForWidth() ) ); resize( QSize(465, 77).expandedTo(minimumSizeHint()) ); m_topLabel = new QLabel(in_label, this, "topLabel"); QString iLabel = "Item "; setup(iLabel); } ModuleMap::ModuleMap(assyType in_assyType, const char *in_label, QWidget* parent, const char* name, bool modal, Qt::WFlags fl) : QDialog(parent, name, modal, fl), m_assyType(in_assyType) { if ( !name ) setName( "ModuleMapBase" ); setCaption("Module map"); setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, 0, 0, sizePolicy().hasHeightForWidth() ) ); resize( QSize(465, 77).expandedTo(minimumSizeHint()) ); m_topLabel = new QLabel(in_label, this, "topLabel"); // QString assyType = in_assyType; QString iLabel = "Stave "; if(in_assyType==disk){ m_nMods=6; m_nItems=8; iLabel = "Sector "; } else if(in_assyType==sector){ m_nMods=6; m_nItems=1; iLabel = "Sector "; } else if(in_assyType==stave){ m_nMods=13; m_nItems=1; } else{ m_nMods=13; if(in_assyType==layer0) m_nItems=22; else if(in_assyType==layer1) m_nItems=38; else if(in_assyType==halfshell2) m_nItems=26; } if(in_assyType==disk){ setMinimumSize(550,550); resize(600,600); for(int i=0;i<8;i++) new Sector(this,"stv"+QString::number(i+1), i); } else setup(iLabel); } void ModuleMap::setup(QString iLabel) { Q3VBoxLayout *ModuleMapBaseLayout = new Q3VBoxLayout( this, 11, 6, "ModuleMapBaseLayout"); Q3VBoxLayout *ModuleMapSubLayout = new Q3VBoxLayout( 0,0, 6, "ModuleMapSubLayout"); ModuleMapSubLayout->addWidget( m_topLabel); Q3Grid *moduleMap = new Q3Grid( m_nItems+1, Qt::Vertical, this, "moduleMap" ); moduleMap->setSpacing(3); moduleMap->setMargin(2); QLabel *labels; QString stvLabels[13]={"M6C", "M5C", "M4C", "M3C", "M2C", "M1C" , "M0", "M1A", "M2A", "M3A", "M4A", "M5A", "M6A"}; for(int i=0;i<=m_nMods;i++){ for(int j=0;j<=m_nItems;j++){ if(j==0){ if(i==0){ labels = new QLabel("", moduleMap, "dummy"); } else{ QString ltxt = "Position "+QString::number(i); if(m_nMods==13){ // use stave labels ltxt = stvLabels[i-1]; } QString name = "head"+QString::number(i); labels = new QLabel(ltxt, moduleMap, name); labels->setBackgroundColor(Qt::white); } } else{ if(i==0){ QString ltxt = iLabel+QString::number(j); QString name = "stv"+QString::number(j); labels = new QLabel(ltxt, moduleMap, name); labels->setBackgroundColor(Qt::white); } else{ QString ltxt = "Module "+QString::number(i); QString name = "mod"+QString::number(i)+"s"+QString::number(j); labels = new ModuleLabelBarrel(ltxt, moduleMap, name); } } } } ModuleMapSubLayout->addWidget( moduleMap ); ModuleMapBaseLayout->addLayout(ModuleMapSubLayout); } ModuleLabel* ModuleMap::loadModule(void* mod, const char *name) { if(m_modLabels[name]==0) return 0; m_modLabels[name]->loadModule(mod); m_modLabels[name]->updateStatus("unknown"); // if(m_assyType==disk) // paintEvent(0); return m_modLabels[name]; } ModuleLabel* ModuleMap::loadModule(const char *name, int staveID, int modID, const char *staveName) { if(staveID>=m_nItems || modID>=m_nMods) return 0; QString cname = "mod"+QString::number(modID+1)+"s"+QString::number(staveID+1); ModuleLabel *ml = dynamic_cast(child(cname)); if(ml==0) return 0; ml->setText(name); ml->updateStatus("unknown"); m_modLabels.insert(std::make_pair(name,ml)); // also label stave/sector correctly if requested if(staveName!=0){ if(m_assyType==disk){ cname = "stv"+QString::number(staveID+1); Sector *l = dynamic_cast(child(cname)); if(l!=0) l->setLabel(QString(staveName)); } else{ cname = "stv"+QString::number(staveID+1); QLabel *l = dynamic_cast(child(cname)); if(l!=0) l->setText(staveName); } } // if(m_assyType==disk) // paintEvent(0); return ml; } void ModuleMap::updateStatus() { for(std::map::iterator it = m_modLabels.begin(); it!= m_modLabels.end(); it++) it->second->updateStatus(); if(m_assyType==disk && isVisible()) paintEvent(0); } void ModuleMap::updateStatus(std::map modList) { for(std::map::iterator it = modList.begin(); it!= modList.end(); it++) if(m_modLabels[it->first]!=0) m_modLabels[it->first]->updateStatus(it->second.c_str()); if(m_assyType==disk && isVisible()) paintEvent(0); } const char* ModuleMap::getLabel() { return m_topLabel->text().latin1(); } void ModuleMap::reset(bool res_all) { m_modLabels.clear(); QString iLabel = "Stave "; if(m_assyType==sector || m_assyType==disk) iLabel = "Sector "; else if(m_assyType==userdef) iLabel = "Item "; for(int i=0;i<=m_nMods;i++){ for(int j=1;j<=m_nItems;j++){ if(i==0){ QString ltxt = iLabel+QString::number(j); QString name = "stv"+QString::number(j); if(res_all){ if(m_assyType==disk){ Sector *sec = dynamic_cast(child(name)); if(sec!=0) sec->setLabel(ltxt); } else{ QLabel *label = dynamic_cast(child(name)); if(label!=0) label->setText(ltxt); } } } else{ QString ltxt = "Module "+QString::number(i); QString name = "mod"+QString::number(i)+"s"+QString::number(j); ModuleLabel *label = dynamic_cast(child(name)); if(label!=0){ label->loadModule(0); label->setText(ltxt); label->setBackgroundColor(Qt::darkGray); } } } } if(m_assyType==disk && isVisible()) paintEvent(0); } void ModuleMap::paintEvent ( QPaintEvent * ) { if(m_assyType==disk){ for(int i=0;i<8;i++){ Sector *sec = dynamic_cast(child("stv"+QString::number(i+1))); if(sec!=0) sec->paint(); } QPainter pb(this); pb.setPen(QPen(Qt::black,1)); pb.setBrush(QBrush(Qt::lightGray)); pb.translate(width()/2,height()/2); pb.drawEllipse(-70,-70,140,140); } } void ModuleMap::mouseDoubleClickEvent ( QMouseEvent * e ) { if(m_assyType==disk){ for(int i=0;i<8;i++) ((Sector*)child("stv"+QString::number(i+1)))->extEvent(e); } }