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();
174 sel.fType = det; sel.fLayer=layer;
175 fDigitsInfo->GetModuleIDs(&sel, fIDs);
176 //in reder menu define a space between left and right pager
177 fPagerGap = 1.2*TextLength(Form("%d/%d",GetPages(), GetPages()));
181 /**************************************************************************/
183 void AliEveITSModuleStepper::DisplayTheta(Float_t min, Float_t max)
186 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
187 sel.fMaxTheta = max; sel.fMinTheta=min;
188 fDigitsInfo->GetModuleIDs(&sel, fIDs);
192 /**************************************************************************/
194 Int_t AliEveITSModuleStepper::GetCurrentPage()
196 Int_t idx = fPosition +1;
202 /**************************************************************************/
204 Int_t AliEveITSModuleStepper::GetPages()
206 Int_t n = fIDs.size()/Nxy();
207 if(fIDs.size() % Nxy()) n++;
211 /**************************************************************************/
213 void AliEveITSModuleStepper::Apply()
215 // printf("AliEveITSModuleStepper::Apply fPosition %d \n", fPosition);
216 gEve->DisableRedraw();
219 UInt_t idx = fPosition;
220 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
222 if(idx < fIDs.size())
224 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
225 mod->SetID(fIDs[idx], kFALSE);
226 TEveTrans& tr = mod->RefHMTrans();
228 tr.RotateLF(3,2,TMath::PiOver2());
229 tr.RotateLF(1,3,TMath::PiOver2());
233 Float_t* fp = mod->GetFrame()->GetFramePoints();
234 // switch x,z it will be rotated afterwards
239 Double_t sx = fStepper->GetDx();
240 Double_t sy = (mx*fStepper->GetDx())/mz;
241 if(sy > fStepper->GetDy())
243 // printf("fit width \n");
244 sy = fStepper->GetDy();
245 sx = (mz*fStepper->GetDx())/mx;
247 Float_t scale = (fExpandCell*sx)/mz;
248 tr.Scale(scale, scale, scale);
251 fStepper->GetPosition(p);
252 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
254 if(mod->GetSubDetID() == 2)
255 mod->SetName(Form("SSD %d", idx));
256 else if(mod->GetSubDetID() == 1)
257 mod->SetName(Form("SDD %d", idx));
259 mod->SetName(Form("SPD %d", idx));
260 mod->SetRnrSelf(kTRUE);
267 (*childit)->SetRnrSelf(kFALSE);
273 gEve->EnableRedraw();
276 /**************************************************************************/
278 void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
280 // render everyting in relative coordinates
281 glMatrixMode(GL_PROJECTION);
284 if (rnrCtx.Selection())
287 // glLoadMatrix(rnrCtx.GetCamera()->GetProjMBase());
288 TGLRect rect(*rnrCtx.GetPickRectangle());
289 rnrCtx.GetCamera()->WindowToViewport(rect);
290 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
291 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
294 glMatrixMode(GL_MODELVIEW);
299 glGetBooleanv(GL_LIGHTING, &lightp);
300 if (lightp) glDisable(GL_LIGHTING);
302 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
303 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
304 glDisable(GL_CULL_FACE);
306 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
308 RenderPalette(fPaletteLength, 1.6*fWWidth, fWHeight*0.6);
312 if (lightp) glEnable(GL_LIGHTING);
314 glMatrixMode(GL_PROJECTION);
317 glMatrixMode(GL_MODELVIEW);
322 /**************************************************************************/
323 // Protected sub-renderers
324 /**************************************************************************/
326 //______________________________________________________________________
327 Float_t AliEveITSModuleStepper::TextLength(const char* txt)
329 Float_t llx, lly, llz, urx, ury, urz;
330 fText->BBox(txt, llx, lly, llz, urx, ury, urz);
331 return (urx-llx)*fTextSize;
334 //______________________________________________________________________
335 void AliEveITSModuleStepper::RenderString(TString string, Int_t id)
337 Float_t txtY = fWHeight*0.5;
338 Float_t txtl = TextLength(string.Data());
340 if(id > 0) glLoadName(id);
341 if(id>0 && fWActive == id)
342 fText->SetTextColor(fWActiveCol);
344 fText->SetTextColor(fFontCol);
350 fText->SetTextColor(fWActiveCol);
352 fText->SetTextColor(fFontCol);
355 Float_t ss = fWWidth*0.4;
356 fText->PaintGLText(ss, txtY, -0.8, string.Data());
358 Float_t bw =2*ss+txtl;
359 RenderFrame(bw,fWHeight*2,id);
360 glTranslatef( bw, 0, 0);
364 fText->SetTextColor(fFontCol);
365 fText->PaintGLText(0, txtY, -0.8, string.Data());
366 glTranslatef(txtl, 0, 0);
370 //______________________________________________________________________
371 void AliEveITSModuleStepper::RenderFrame(Float_t dx, Float_t dy, Int_t id)
373 if(fRnrFrame == kFALSE)return;
375 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
376 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
379 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
381 TEveUtil:: TEveUtil::ColorFromIdx(fWCol, color);
385 glVertex2f(0, 0); glVertex2f(dx, 0);
386 glVertex2f(dx, dy); glVertex2f(0, dy);
391 //______________________________________________________________________
392 void AliEveITSModuleStepper::RenderSymbol(Float_t dx, Float_t dy, Int_t id)
398 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
400 TEveUtil::TEveUtil::ColorFromIdx(fWCol, color);
403 Float_t xs = dx/4, ys = dy/4;
406 glVertex2f(0,ys); glVertex2f(0, ys*3);
407 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
412 glBegin(GL_TRIANGLES);
417 // glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
418 glVertex2f(xs*3, ys*3); glVertex2f(xs*1, ys*2); glVertex2f(xs*3, ys);
424 glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
425 glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
431 //glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
432 glVertex2f(xs*1, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*1, ys*3);
438 glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
439 glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
445 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
451 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
462 //______________________________________________________________________
463 void AliEveITSModuleStepper::RenderPalette(Float_t dx, Float_t x, Float_t y)
467 glTranslatef(1 -x- dx, -1+y*4, 0);
468 AliEveITSModule* qs = dynamic_cast<AliEveITSModule*>(*BeginChildren());
469 TEveRGBAPalette* p = qs->GetPalette();
470 glBegin(GL_QUAD_STRIP);
471 glColor4ubv(p->ColorFromValue(p->GetMinVal()));
474 if (p->GetMaxVal() > p->GetMinVal() + 1)
476 Float_t xs = dx/(p->GetMaxVal() - p->GetMinVal());
478 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
480 glColor4ubv(p->ColorFromValue(i));
486 glColor4ubv(p->ColorFromValue(p->GetMaxVal()));
491 if (p->GetMaxVal() > p->GetMinVal())
493 glRotatef(-90,1, 0, 0 );
494 Double_t v1[3] = {0., 0., 0.};
495 Double_t v2[3] = {dx, 0, 0.};
496 fAxis->SetLabelsSize(fTextSize/dx);
497 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 206);
502 //______________________________________________________________________
503 void AliEveITSModuleStepper::RenderMenu()
505 Float_t ww = 2*fWWidth;
506 Float_t wh = 2*fWHeight;
510 glColor4f(a, a, a, a);
511 Float_t H = 1.9*wh*(1+ 2*fWOff);
514 glVertex3f(-1, -1, 0.1); glVertex3f(-1, -1+H, 0.1);
515 glVertex3f(1 , -1+H, 0.1); glVertex3f( 1, -1 , 0.1);
519 Float_t y_base = -1 + wh*0.35;
520 glTranslatef(-1, y_base, 0.);
524 glTranslatef(ww, 0, 0.);
525 fText->SetTextSize(fTextSize);
526 Float_t soff = ww*1.3;
527 glTranslatef(0, fWOff*wh, 0);
528 RenderSymbol(ww, wh, 2);
529 RenderFrame(ww,wh,2);
530 glTranslatef(soff, 0, 0);
531 RenderSymbol(ww, wh, 1);
532 RenderFrame(ww,wh,1);
533 glTranslatef(soff, 0, 0);
536 const char* txt = Form("%d/%d ", GetCurrentPage(), GetPages());
537 Float_t dx = (fPagerGap - TextLength(txt))*0.5;
538 fText->SetTextColor(fFontCol);
539 fText->PaintGLText(dx, wh*0.25, -0.8, txt);
541 glTranslatef(fPagerGap, 0, 0);
543 RenderSymbol(ww, wh, 3);
544 RenderFrame(ww,wh,3);
545 glTranslatef(soff, 0, 0);
546 RenderSymbol(ww, wh, 4);
547 RenderFrame(ww,wh,4);
548 glTranslatef(2*ww, 0, 0);
553 AliEveITSDigitsInfo* di = fDigitsInfo;
554 Int_t scale = fScaleInfo->GetScale() - 1;
555 AliEveITSScaledModule* sm = dynamic_cast<AliEveITSScaledModule*>(*BeginChildren());
556 Int_t cnx = 0, cnz = 0;
557 switch(sm->GetSubDetID())
560 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
563 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
566 cnx = di->fSSDScale[scale], cnz = 1;
569 glTranslatef(10*ww,0, 0);
570 RenderString(Form("Zoom: "));
572 glTranslatef(0, 0.2*wh, 0);
573 RenderSymbol(ww, wh*0.9, 5);
574 glTranslatef(0, 0.4*wh, 0);
575 RenderFrame(ww, wh*0.5, 5);
577 RenderSymbol(ww, wh*0.9, 6);
578 RenderFrame(ww, wh*0.5, 6);
579 glTranslatef(ww, 0, 0);
580 RenderString(Form("%dx%d ", cnx, cnz));
585 glTranslatef(18*ww, 0, 0);
587 RenderString("SPD", 8);
588 glTranslatef(bs, 0, 0);
589 RenderString("SDD", 9);
590 glTranslatef(bs, 0, 0);
591 RenderString("SSD", 10);
597 //______________________________________________________________________
598 void AliEveITSModuleStepper::RenderCellIDs()
600 fText->SetTextSize(fStepper->GetDy()*0.1);
601 fText->SetTextColor(fFontCol);
604 UInt_t idx = fPosition;
605 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
607 if(idx < fIDs.size())
609 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
610 TEveTrans& tr = mod->RefHMTrans();
611 TString name = Form("%d",mod->GetID());
613 x += fStepper->GetDx()*0.5;
614 y -= fStepper->GetDy()*0.5;
615 z += 0.4; // !!! MT hack - cross check with overlay rendering.
616 Float_t llx, lly, llz, urx, ury, urz;
617 fText->BBox(name, llx, lly, llz, urx, ury, urz);
618 tr.GetScale(sx, sy, sz);
619 fText->PaintGLText(x-(urx-llx)*sx, y, z, name);
626 /**************************************************************************/
627 // Virtual event handlers from TGLOverlayElement
628 /**************************************************************************/
630 //______________________________________________________________________
631 Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
632 TGLOvlSelectRecord & rec,
635 // Handle overlay event.
636 // Return TRUE if event was handled.
638 switch (event->fType)
642 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
643 if (fWActive != item) {
653 if (event->fCode != kButton1) {
656 switch (rec.GetItem(1))
672 AliEveDigitScaleInfo* si = fScaleInfo;
673 if(si->GetScale() < 5)
675 si->ScaleChanged(si->GetScale() + 1);
676 ElementChanged(kTRUE, kTRUE);
682 AliEveDigitScaleInfo* si = fScaleInfo;
683 if(si->GetScale() > 1)
685 si->ScaleChanged(si->GetScale() - 1);
686 ElementChanged(kTRUE, kTRUE);
691 gEve->GetEditor()->DisplayElement(*BeginChildren());
715 //______________________________________________________________________
716 Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
721 //______________________________________________________________________
722 void AliEveITSModuleStepper::MouseLeave()
724 // Mouse has left the element.