00001 #include "VisReco/VisCustomTracker/interface/VisCuTkSlWindow.h"
00002 #include "VisReco/VisCustomTracker/interface/VisCuTkSelectionBar.h"
00003 #include "VisReco/VisCustomTracker/interface/VisCuCmsTracker.h"
00004 #include "VisReco/VisCustomTracker/interface/VisCuTracker.h"
00005
00006 #include "VisReco/VisCustomTracker/interface/VisCuTkSubDetector.h"
00007 #include "VisReco/VisCustomTracker/interface/VisCuTkPartDetector.h"
00008 #include "VisReco/VisCustomTracker/interface/VisCuTkLayer.h"
00009
00010
00011 #include <qpainter.h>
00012 #include <iostream>
00013
00014 VisCuTkSelectionBar::VisCuTkSelectionBar(VisCuTkSlWindow* sw, QWidget *parent, const char *name )
00015 : QWidget( parent, name )
00016 {
00017 setPalette( QPalette( QColor( 250, 250, 250) ) );
00018 xmin = -3.0; xmax = 3.0; ymin = -0.1; ymax =1.0;
00019
00020 gpp = sw;
00021 }
00022
00023 void VisCuTkSelectionBar::setTracker(VisCuCmsTracker * tr)
00024 {
00025 tracker=tr;
00026 drawSelectionBars();
00027 }
00028
00029 void VisCuTkSelectionBar::drawSelectionBars(){
00030
00031 float xsq[]={2.75,2.57,2.39,2.21,2.03,1.85,1.67,1.50,1.33,1.16,1.03,0.90,0.77,0.64,0.51,- 0.51,-0.64,-0.77,-0.90,-1.03,-1.16,-1.33,-1.50,-1.67,-1.85,-2.03,-2.21,-2.39,-2.57,-2.75,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85,-2.85};
00032 float ysq[]={0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.090,0.140,0.190,0.31,0.36,0.43,0.48,0.55,0.61,0.67,0.74,0.81,0.88};
00033
00034 float rmedioS[]={0.387, 0.447, 0.507, 0.567, 0.657, 0.777, 0.887};
00035 float rmedioP[]={0.0155, 0.065, 0.105, 0.145, 0.185, 0.225, 0.265};
00036
00037 float sizeF[]={0.08,0.08,0.08,0.08,0.11,0.14,0.14};
00038 float xp[]={-0.40,-0.29, -0.18,-0.06,0.06,0.18,0.29,0.40};
00039 float xsi[]={-0.60,-0.50,-0.40,-0.30,-0.20,-0.10,0.10,0.20,0.30,0.40,0.50,0.60};
00040 float xso[]={-1.13,-0.93,-0.74,-0.55,-0.36,-0.16,0.05,0.24,0.44,0.63,0.82,1.01};
00041 int nlay;
00042 ntotlay =0;
00043 nelem=0;
00044
00045 for(unsigned int i=0; i<tracker->components(); i++){
00046 VisCuTkSubDetector* subDetector = tracker->getComponent(i+1);
00047 for(unsigned int j=0; j<subDetector->components(); j++ ){
00048 VisCuTkPartDetector* partDetector = subDetector->getComponent(j+1);
00049 for(unsigned int k=0; k<partDetector->components(); k++ ){
00050 ntotlay++;
00051 nlay=VisCuTracker::nlayer(i+1,j+1,k+1);
00052
00053 VisCuTkLayer* layer = partDetector->getComponent(k+1);
00054 if(nlay<31){
00055 rsqr[nelem]=QRect(xpixel(xsq[(31-nlay)-1]),ypixel(ysq[nlay-1]),5,5);
00056 state[nelem]=layer;
00057 nelem=nelem+1;
00058 }else {
00059 rsqr[nelem]=QRect(xpixel(xsq[nlay-1]-0.05),ypixel(ysq[nlay-1]),5,5);
00060 state[nelem]=layer;
00061 nelem=nelem+1;
00062 }
00063 if(nlay<31){
00064 rsqr[nelem]=QRect(xpixel(xsq[(31-nlay)-1]),ypixel(-0.03),5,5);
00065 state[nelem]=layer;
00066 nelem=nelem+1;
00067 }
00068 else{
00069 rsqr[nelem]=QRect(xpixel(2.90),ypixel(ysq[nlay-1]),5,5);
00070 state[nelem]=layer;
00071 nelem=nelem+1;
00072 }
00073 }
00074 }
00075 }
00076
00077
00078 for(unsigned int i=0; i<tracker->components(); i++){
00079 VisCuTkSubDetector* subDetector = tracker->getComponent(i+1);
00080 for(unsigned int j=0; j<subDetector->components(); j++ ){
00081 VisCuTkPartDetector* partDetector = subDetector->getComponent(j+1);
00082 for(unsigned int k=0; k<partDetector->components(); k++ ){
00083 nlay=VisCuTracker::nlayer(i+1,j+1,k+1);
00084 VisCuTkLayer* layer = partDetector->getComponent(k+1);
00085 for(unsigned int l=0; l<layer->components(); l++ ){
00086 VisCuTkSubLayer* sublayer = layer->getComponent(l+1);
00087 int id = sublayer->getId();
00088 float a = 0;
00089 if(nlay<13 || (nlay>18 && nlay<31)){
00090 if(nlay<13 && id%2==0)a=0.05;
00091 if(nlay<13 && id%2!=0)a=0.0;
00092 if((nlay>18 && nlay<31) && id%2==0)a=0.0;
00093 if((nlay>18 && nlay<31) && id%2!=0)a=0.05;
00094 int xendcap = xpixel(xsq[(31-nlay)-1]+ a);
00095 rsqr[nelem]=QRect(xendcap,ypixel(rmedioS[id-1]),3,ypixel(0)-ypixel(sizeF[id-1]));
00096 state[nelem]= sublayer;
00097 nelem=nelem+1;
00098 }
00099 if(nlay>12 && nlay<19 ){
00100 if(nlay==16 || nlay==17 || nlay==18)a=0.03;
00101 int xpixel1 = xpixel(xsq[(31-nlay)-1]+a);
00102 rsqr[nelem]=QRect(xpixel1,ypixel(rmedioP[id-1]),3,6);
00103 state[nelem]= sublayer;
00104 nelem=nelem+1;
00105 }
00106 if(nlay>30 && nlay<34){
00107 rsqr[nelem]=QRect(xpixel(xp[id-1]),ypixel(ysq[nlay-1]),8,3);
00108 state[nelem]= sublayer;
00109 nelem=nelem+1;
00110 }
00111 if(nlay>33 && nlay<38){
00112 rsqr[nelem]=QRect(xpixel(xsi[id-1]),ypixel(ysq[nlay-1]),8,3);
00113 state[nelem]= sublayer;
00114 nelem=nelem+1;
00115 }
00116 if(nlay>37){
00117 if((id%2==0 && id<7) || (id>6 && id%2!=0))a = 0.01;
00118 rsqr[nelem]=QRect(xpixel(xso[id-1]),ypixel(ysq[nlay-1]+a),17,3);
00119 state[nelem]= sublayer;
00120 nelem=nelem+1;
00121 }
00122 }
00123 }
00124 }
00125 }
00126 }
00127
00128 void VisCuTkSelectionBar::update(){
00129 repaint();
00130 }
00131
00132 void VisCuTkSelectionBar::mousePressEvent(QMouseEvent *e)
00133 {
00134 for(int i=0; i<nelem; i++){
00135 if(rsqr[i].contains(e->pos())){
00136 if((i%2==1 && i<(2*ntotlay)) || i>(2*ntotlay-1)){
00137 if(i%2==1 && i<(2*ntotlay)){
00138 VisCuTkLayer* lay = dynamic_cast<VisCuTkLayer*>(state[i]);
00139 label.setNum(lay->getId());
00140 gpp->labelinfop->setText(" Layer "+label+" of "+lay->getOwner()->getName()+" selected");
00141 } else{
00142 VisCuTkSubLayer* subly = dynamic_cast<VisCuTkSubLayer*>(state[i]);
00143 label.setNum(subly->getId());
00144 label1.setNum(subly->getOwner()->getId());
00145 gpp->labelinfop->setText( "Ring "+label+ " layer "+label1+ " of "+subly->getOwner()->getOwner()->getName()+" selected" );
00146 }
00147 gpp->drawpart(state[i]);
00148 repaint();
00149 }
00150 if(i%2==0 && i<(2*ntotlay)){
00151 VisCuTkLayer* lay = dynamic_cast<VisCuTkLayer*>(state[i]);
00152 if(lay->getSlWindow()==0 ||lay->getSlWindow()->close() ){
00153 layerWindow = new VisCuTkLayerSlWindow(0, "layerWindow",0,state[i], this);
00154 layerWindow->show();
00155 lay->setSlWindow(layerWindow);
00156 repaint();
00157 } else {
00158 if(lay->getSlWindow()->isMinimized()){
00159 lay->getSlWindow()->showNormal();
00160 lay->getSlWindow()->setActiveWindow();
00161 lay->getSlWindow()->raise();
00162 }
00163 }
00164 repaint();
00165 }
00166 break;
00167 }
00168 }
00169 }
00170
00171 void VisCuTkSelectionBar::paintEvent(QPaintEvent*)
00172 {
00173 QPainter p( this );
00174 p.setPen(black);
00175
00176 for(int i=0; i<(2*ntotlay); i++){
00177 if((i%2)==1){
00178 p.setBrush(yellow);
00179 if(state[i]->isVisible()) p.setBrush(red);
00180 }
00181 else {
00182 VisCuTkLayer* lay = dynamic_cast<VisCuTkLayer*>(state[i]);
00183 if(lay->getSlWindow()!=0)p.setBrush(red);else p.setBrush(green);
00184 }
00185 p.drawRect(rsqr[i]);
00186 }
00187 for(int i=(2*ntotlay); i<nelem; i++){
00188 p.setBrush(black);
00189 VisCuTkSubLayer* sublay = dynamic_cast<VisCuTkSubLayer*>(state[i]);
00190 if(sublay->isStereo()){
00191 p.setPen(blue);
00192 p.setBrush(blue);
00193 }
00194 if(state[i]->isVisible()) {
00195 p.setPen(red);
00196 p.setBrush(red);
00197 }
00198 p.drawRect(rsqr[i]);
00199 p.setPen(black);
00200 }
00201 }
00202 QSizePolicy VisCuTkSelectionBar::sizePolicy() const
00203 {
00204 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
00205 }
00206
00207