2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliEveITSModuleStepper.h"
11 #include "AliEveITSDigitsInfo.h"
12 #include "AliEveITSScaledModule.h"
14 #include <TEveManager.h>
15 #include <TEveGedEditor.h>
16 #include <TEveGridStepper.h>
17 #include <TEveGLText.h>
18 #include <TEveTrans.h>
22 #include <TBuffer3D.h>
23 #include <TBuffer3DTypes.h>
24 #include <TVirtualPad.h>
25 #include <TVirtualViewer3D.h>
27 #include <TGLRnrCtx.h>
28 #include <TGLSelectRecord.h>
30 // #include <FTFont.h>
32 #include <TGLViewer.h>
35 //______________________________________________________________________________
36 // AliEveITSModuleStepper
39 ClassImp(AliEveITSModuleStepper)
41 AliEveITSModuleStepper::AliEveITSModuleStepper(AliEveITSDigitsInfo* di) :
42 TEveElementList("ITS 2DStore", "AliEveITSModuleStepper", kTRUE),
72 // override member from base TEveElementList
73 fChildClass = AliEveITSScaledModule::Class();
75 SetMainColorPtr(&fWCol);
77 fDigitsInfo->IncRefCount();
79 fStepper = new TEveGridStepper();
80 fStepper->SetNs(5, 4);
82 fScaleInfo = new AliEveDigitScaleInfo();
83 fScaleInfo->IncRefCount();
85 fAxis = new TGLAxis();
86 fAxis->SetLineColor(4);
87 fAxis->SetTextColor(fFontCol);
89 fText = new TGLText();
90 fText->SetTextColor(fFontCol);
91 fText->SetGLTextFont(40);
92 fText->SetGLTextAngles(0, 0, 0);
93 fText->SetTextSize(fTextSize);
95 gEve->GetGLViewer()->AddOverlayElement(this);
98 AliEveITSModuleStepper::~AliEveITSModuleStepper()
100 gEve->GetGLViewer()->RemoveOverlayElement(this);
102 fScaleInfo->DecRefCount();
103 fDigitsInfo->DecRefCount();
111 /******************************************************************************/
113 void AliEveITSModuleStepper::Capacity()
115 Int_t N = fStepper->GetNx()*fStepper->GetNy();
116 if (N != GetNChildren())
119 for (Int_t m=0; m<N; m++)
121 AddElement(new AliEveITSScaledModule(m, fDigitsInfo, fScaleInfo));
126 /******************************************************************************/
128 void AliEveITSModuleStepper::SetFirst(Int_t first)
130 Int_t lastpage = fIDs.size()/Nxy();
131 if(fIDs.size() % Nxy() ) lastpage++;
133 Int_t first_lastpage = (lastpage -1)*Nxy();
134 if(first > first_lastpage) first = first_lastpage;
135 if(first < 0) first = 0;
140 void AliEveITSModuleStepper::Start()
146 void AliEveITSModuleStepper::Next()
148 SetFirst(fPosition + Nxy());
151 void AliEveITSModuleStepper::Previous()
153 // move to the top left corner first
154 SetFirst(fPosition - Nxy());
157 void AliEveITSModuleStepper::End()
159 Int_t lastpage = fIDs.size()/Nxy();
160 if(fIDs.size() % Nxy() ) lastpage++;
161 fPosition = (lastpage -1)*Nxy();
167 /******************************************************************************/
169 void AliEveITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
173 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
176 fDigitsInfo->GetModuleIDs(&sel, fIDs);
177 //in reder menu define a space between left and right pager
178 fPagerGap = 1.2*TextLength(Form("%d/%d",GetPages(), GetPages()));
182 /******************************************************************************/
184 void AliEveITSModuleStepper::DisplayTheta(Float_t min, Float_t max)
187 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
188 sel.SetThetaRange(min, max);
189 fDigitsInfo->GetModuleIDs(&sel, fIDs);
193 /******************************************************************************/
195 Int_t AliEveITSModuleStepper::GetCurrentPage()
197 Int_t idx = fPosition +1;
203 /******************************************************************************/
205 Int_t AliEveITSModuleStepper::GetPages()
207 Int_t n = fIDs.size()/Nxy();
208 if(fIDs.size() % Nxy()) n++;
212 /******************************************************************************/
214 void AliEveITSModuleStepper::Apply()
216 // printf("AliEveITSModuleStepper::Apply fPosition %d \n", fPosition);
217 gEve->DisableRedraw();
220 UInt_t idx = fPosition;
221 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
223 if(idx < fIDs.size())
225 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
226 mod->SetID(fIDs[idx], kFALSE);
227 TEveTrans& tr = mod->RefHMTrans();
229 tr.RotateLF(3,2,TMath::PiOver2());
230 tr.RotateLF(1,3,TMath::PiOver2());
234 Float_t* fp = mod->GetFrame()->GetFramePoints();
235 // switch x,z it will be rotated afterwards
240 Double_t sx = fStepper->GetDx();
241 Double_t sy = (mx*fStepper->GetDx())/mz;
242 if(sy > fStepper->GetDy())
244 // printf("fit width \n");
245 sy = fStepper->GetDy();
246 sx = (mz*fStepper->GetDx())/mx;
248 Float_t scale = (fExpandCell*sx)/mz;
249 tr.Scale(scale, scale, scale);
252 fStepper->GetPosition(p);
253 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
255 if(mod->GetSubDetID() == 2)
256 mod->SetName(Form("SSD %d", idx));
257 else if(mod->GetSubDetID() == 1)
258 mod->SetName(Form("SDD %d", idx));
260 mod->SetName(Form("SPD %d", idx));
261 mod->SetRnrSelf(kTRUE);
268 (*childit)->SetRnrSelf(kFALSE);
274 gEve->EnableRedraw();
277 /******************************************************************************/
279 void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
281 // render everyting in relative coordinates
282 glMatrixMode(GL_PROJECTION);
285 if (rnrCtx.Selection())
288 // glLoadMatrix(rnrCtx.GetCamera()->GetProjMBase());
289 TGLRect rect(*rnrCtx.GetPickRectangle());
290 rnrCtx.GetCamera()->WindowToViewport(rect);
291 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
292 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
295 glMatrixMode(GL_MODELVIEW);
300 glGetBooleanv(GL_LIGHTING, &lightp);
301 if (lightp) glDisable(GL_LIGHTING);
303 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
304 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
305 glDisable(GL_CULL_FACE);
307 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
309 RenderPalette(fPaletteLength, 1.6*fWWidth, fWHeight*0.6);
313 if (lightp) glEnable(GL_LIGHTING);
315 glMatrixMode(GL_PROJECTION);
318 glMatrixMode(GL_MODELVIEW);
323 /******************************************************************************/
324 // Protected sub-renderers
325 /******************************************************************************/
327 //______________________________________________________________________________
328 Float_t AliEveITSModuleStepper::TextLength(const char* txt)
330 Float_t llx, lly, llz, urx, ury, urz;
331 fText->BBox(txt, llx, lly, llz, urx, ury, urz);
332 return (urx-llx)*fTextSize;
335 //______________________________________________________________________________
336 void AliEveITSModuleStepper::RenderString(TString string, Int_t id)
338 Float_t txtY = fWHeight*0.5;
339 Float_t txtl = TextLength(string.Data());
341 if(id > 0) glLoadName(id);
342 if(id>0 && fWActive == id)
343 fText->SetTextColor(fWActiveCol);
345 fText->SetTextColor(fFontCol);
351 fText->SetTextColor(fWActiveCol);
353 fText->SetTextColor(fFontCol);
356 Float_t ss = fWWidth*0.4;
357 fText->PaintGLText(ss, txtY, -0.8, string.Data());
359 Float_t bw =2*ss+txtl;
360 RenderFrame(bw,fWHeight*2,id);
361 glTranslatef( bw, 0, 0);
365 fText->SetTextColor(fFontCol);
366 fText->PaintGLText(0, txtY, -0.8, string.Data());
367 glTranslatef(txtl, 0, 0);
371 //______________________________________________________________________________
372 void AliEveITSModuleStepper::RenderFrame(Float_t dx, Float_t dy, Int_t id)
374 if(fRnrFrame == kFALSE)return;
376 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
377 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
380 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
382 TEveUtil:: TEveUtil::ColorFromIdx(fWCol, color);
386 glVertex2f(0, 0); glVertex2f(dx, 0);
387 glVertex2f(dx, dy); glVertex2f(0, dy);
392 //______________________________________________________________________________
393 void AliEveITSModuleStepper::RenderSymbol(Float_t dx, Float_t dy, Int_t id)
399 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
401 TEveUtil::TEveUtil::ColorFromIdx(fWCol, color);
404 Float_t xs = dx/4, ys = dy/4;
407 glVertex2f(0,ys); glVertex2f(0, ys*3);
408 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
413 glBegin(GL_TRIANGLES);
418 // glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
419 glVertex2f(xs*3, ys*3); glVertex2f(xs*1, ys*2); glVertex2f(xs*3, ys);
425 glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
426 glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
432 //glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
433 glVertex2f(xs*1, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*1, ys*3);
439 glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
440 glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
446 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
452 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
463 //______________________________________________________________________________
464 void AliEveITSModuleStepper::RenderPalette(Float_t dx, Float_t x, Float_t y)
468 glTranslatef(1 -x- dx, -1+y*4, 0);
469 AliEveITSModule* qs = dynamic_cast<AliEveITSModule*>(*BeginChildren());
470 TEveRGBAPalette* p = qs->GetPalette();
471 glBegin(GL_QUAD_STRIP);
472 glColor4ubv(p->ColorFromValue(p->GetMinVal()));
475 if (p->GetMaxVal() > p->GetMinVal() + 1)
477 Float_t xs = dx/(p->GetMaxVal() - p->GetMinVal());
479 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
481 glColor4ubv(p->ColorFromValue(i));
487 glColor4ubv(p->ColorFromValue(p->GetMaxVal()));
492 if (p->GetMaxVal() > p->GetMinVal())
494 glRotatef(-90,1, 0, 0 );
495 Double_t v1[3] = {0., 0., 0.};
496 Double_t v2[3] = {dx, 0, 0.};
497 fAxis->SetLabelsSize(fTextSize/dx);
498 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 206);
503 //______________________________________________________________________________
504 void AliEveITSModuleStepper::RenderMenu()
506 Float_t ww = 2*fWWidth;
507 Float_t wh = 2*fWHeight;
511 glColor4f(a, a, a, a);
512 Float_t H = 1.9*wh*(1+ 2*fWOff);
515 glVertex3f(-1, -1, 0.1); glVertex3f(-1, -1+H, 0.1);
516 glVertex3f(1 , -1+H, 0.1); glVertex3f( 1, -1 , 0.1);
520 Float_t y_base = -1 + wh*0.35;
521 glTranslatef(-1, y_base, 0.);
525 glTranslatef(ww, 0, 0.);
526 fText->SetTextSize(fTextSize);
527 Float_t soff = ww*1.3;
528 glTranslatef(0, fWOff*wh, 0);
529 RenderSymbol(ww, wh, 2);
530 RenderFrame(ww,wh,2);
531 glTranslatef(soff, 0, 0);
532 RenderSymbol(ww, wh, 1);
533 RenderFrame(ww,wh,1);
534 glTranslatef(soff, 0, 0);
537 const char* txt = Form("%d/%d ", GetCurrentPage(), GetPages());
538 Float_t dx = (fPagerGap - TextLength(txt))*0.5;
539 fText->SetTextColor(fFontCol);
540 fText->PaintGLText(dx, wh*0.25, -0.8, txt);
542 glTranslatef(fPagerGap, 0, 0);
544 RenderSymbol(ww, wh, 3);
545 RenderFrame(ww,wh,3);
546 glTranslatef(soff, 0, 0);
547 RenderSymbol(ww, wh, 4);
548 RenderFrame(ww,wh,4);
549 glTranslatef(2*ww, 0, 0);
554 AliEveITSDigitsInfo* di = fDigitsInfo;
555 Int_t scale = fScaleInfo->GetScale() - 1;
556 AliEveITSScaledModule* sm = dynamic_cast<AliEveITSScaledModule*>(*BeginChildren());
557 Int_t cnx = 0, cnz = 0;
558 switch(sm->GetSubDetID())
561 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
564 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
567 cnx = di->fSSDScale[scale], cnz = 1;
570 glTranslatef(10*ww,0, 0);
571 RenderString(Form("Zoom: "));
573 glTranslatef(0, 0.2*wh, 0);
574 RenderSymbol(ww, wh*0.9, 5);
575 glTranslatef(0, 0.4*wh, 0);
576 RenderFrame(ww, wh*0.5, 5);
578 RenderSymbol(ww, wh*0.9, 6);
579 RenderFrame(ww, wh*0.5, 6);
580 glTranslatef(ww, 0, 0);
581 RenderString(Form("%dx%d ", cnx, cnz));
586 glTranslatef(18*ww, 0, 0);
588 RenderString("SPD", 8);
589 glTranslatef(bs, 0, 0);
590 RenderString("SDD", 9);
591 glTranslatef(bs, 0, 0);
592 RenderString("SSD", 10);
598 //______________________________________________________________________________
599 void AliEveITSModuleStepper::RenderCellIDs()
601 fText->SetTextSize(fStepper->GetDy()*0.1);
602 fText->SetTextColor(fFontCol);
605 UInt_t idx = fPosition;
606 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
608 if(idx < fIDs.size())
610 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
611 TEveTrans& tr = mod->RefHMTrans();
612 TString name = Form("%d",mod->GetID());
614 x += fStepper->GetDx()*0.5;
615 y -= fStepper->GetDy()*0.5;
616 z += 0.4; // !!! MT hack - cross check with overlay rendering.
617 Float_t llx, lly, llz, urx, ury, urz;
618 fText->BBox(name, llx, lly, llz, urx, ury, urz);
619 tr.GetScale(sx, sy, sz);
620 fText->PaintGLText(x-(urx-llx)*sx, y, z, name);
627 /******************************************************************************/
628 // Virtual event handlers from TGLOverlayElement
629 /******************************************************************************/
631 //______________________________________________________________________________
632 Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
633 TGLOvlSelectRecord & rec,
636 // Handle overlay event.
637 // Return TRUE if event was handled.
639 switch (event->fType)
643 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
644 if (fWActive != item) {
654 if (event->fCode != kButton1) {
657 switch (rec.GetItem(1))
673 AliEveDigitScaleInfo* si = fScaleInfo;
674 if(si->GetScale() < 5)
676 si->ScaleChanged(si->GetScale() + 1);
677 ElementChanged(kTRUE, kTRUE);
683 AliEveDigitScaleInfo* si = fScaleInfo;
684 if(si->GetScale() > 1)
686 si->ScaleChanged(si->GetScale() - 1);
687 ElementChanged(kTRUE, kTRUE);
692 gEve->GetEditor()->DisplayElement(*BeginChildren());
716 //______________________________________________________________________________
717 Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
722 //______________________________________________________________________________
723 void AliEveITSModuleStepper::MouseLeave()
725 // Mouse has left the element.