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>
23 #include <TBuffer3D.h>
24 #include <TBuffer3DTypes.h>
25 #include <TVirtualPad.h>
26 #include <TVirtualViewer3D.h>
28 #include <TGLRnrCtx.h>
29 #include <TGLSelectRecord.h>
31 // #include <FTFont.h>
33 #include <TGLViewer.h>
36 //______________________________________________________________________________
37 // AliEveITSModuleStepper
40 ClassImp(AliEveITSModuleStepper)
42 AliEveITSModuleStepper::AliEveITSModuleStepper(AliEveITSDigitsInfo* di) :
43 TEveElementList("ITS 2DStore", "AliEveITSModuleStepper", kTRUE),
74 // override member from base TEveElementList
75 fChildClass = AliEveITSScaledModule::Class();
77 SetMainColorPtr(&fWCol);
79 fDigitsInfo->IncRefCount();
81 fStepper = new TEveGridStepper();
82 fStepper->SetNs(5, 4);
84 fScaleInfo = new AliEveDigitScaleInfo();
85 fScaleInfo->IncRefCount();
87 fAxis = new TGLAxis();
88 fAxis->SetLineColor(4);
89 fAxis->SetTextColor(fFontCol);
91 fText = new TGLText();
92 fText->SetTextColor(fFontCol);
93 fText->SetGLTextFont(40);
94 fText->SetGLTextAngles(0, 0, 0);
95 fText->SetTextSize(fTextSize);
97 gEve->GetGLViewer()->AddOverlayElement(this);
100 AliEveITSModuleStepper::~AliEveITSModuleStepper()
102 gEve->GetGLViewer()->RemoveOverlayElement(this);
104 fScaleInfo->DecRefCount();
105 fDigitsInfo->DecRefCount();
113 /******************************************************************************/
115 void AliEveITSModuleStepper::Capacity()
117 Int_t N = fStepper->GetNx()*fStepper->GetNy();
118 if (N != GetNChildren())
121 for (Int_t m=0; m<N; m++)
123 AddElement(new AliEveITSScaledModule(m, fDigitsInfo, fScaleInfo));
128 /******************************************************************************/
130 void AliEveITSModuleStepper::SetFirst(Int_t first)
132 Int_t lastpage = fIDs.size()/Nxy();
133 if(fIDs.size() % Nxy() ) lastpage++;
135 Int_t first_lastpage = (lastpage -1)*Nxy();
136 if(first > first_lastpage) first = first_lastpage;
137 if(first < 0) first = 0;
142 void AliEveITSModuleStepper::Start()
148 void AliEveITSModuleStepper::Next()
150 SetFirst(fPosition + Nxy());
153 void AliEveITSModuleStepper::Previous()
155 // move to the top left corner first
156 SetFirst(fPosition - Nxy());
159 void AliEveITSModuleStepper::End()
161 Int_t lastpage = fIDs.size()/Nxy();
162 if(fIDs.size() % Nxy() ) lastpage++;
163 fPosition = (lastpage -1)*Nxy();
169 /******************************************************************************/
171 void AliEveITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
175 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
178 fDigitsInfo->GetModuleIDs(&sel, fIDs);
179 //in reder menu define a space between left and right pager
180 fPagerGap = 1.2*TextLength(Form("%d/%d",GetPages(), GetPages()));
184 /******************************************************************************/
186 void AliEveITSModuleStepper::DisplayTheta(Float_t min, Float_t max)
189 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
190 sel.SetThetaRange(min, max);
191 fDigitsInfo->GetModuleIDs(&sel, fIDs);
195 /******************************************************************************/
197 Int_t AliEveITSModuleStepper::GetCurrentPage()
199 Int_t idx = fPosition +1;
205 /******************************************************************************/
207 Int_t AliEveITSModuleStepper::GetPages()
209 Int_t n = fIDs.size()/Nxy();
210 if(fIDs.size() % Nxy()) n++;
214 /******************************************************************************/
216 void AliEveITSModuleStepper::Apply()
218 // printf("AliEveITSModuleStepper::Apply fPosition %d \n", fPosition);
219 gEve->DisableRedraw();
222 UInt_t idx = fPosition;
223 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
225 if(idx < fIDs.size())
227 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
228 mod->SetID(fIDs[idx], kFALSE);
229 TEveTrans& tr = mod->RefHMTrans();
231 tr.RotateLF(3,2,TMath::PiOver2());
232 tr.RotateLF(1,3,TMath::PiOver2());
236 Float_t* fp = mod->GetFrame()->GetFramePoints();
237 // switch x,z it will be rotated afterwards
242 Double_t sx = fStepper->GetDx();
243 Double_t sy = (mx*fStepper->GetDx())/mz;
244 if(sy > fStepper->GetDy())
246 // printf("fit width \n");
247 sy = fStepper->GetDy();
248 sx = (mz*fStepper->GetDx())/mx;
250 Float_t scale = (fExpandCell*sx)/mz;
251 tr.Scale(scale, scale, scale);
254 fStepper->GetPosition(p);
255 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
257 if(mod->GetSubDetID() == 2)
258 mod->SetName(Form("SSD %d", idx));
259 else if(mod->GetSubDetID() == 1)
260 mod->SetName(Form("SDD %d", idx));
262 mod->SetName(Form("SPD %d", idx));
263 mod->SetRnrSelf(kTRUE);
270 (*childit)->SetRnrSelf(kFALSE);
276 gEve->EnableRedraw();
279 /******************************************************************************/
281 void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
283 // render everyting in relative coordinates
284 glMatrixMode(GL_PROJECTION);
287 if (rnrCtx.Selection())
290 // glLoadMatrix(rnrCtx.GetCamera()->GetProjMBase());
291 TGLRect rect(*rnrCtx.GetPickRectangle());
292 rnrCtx.GetCamera()->WindowToViewport(rect);
293 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
294 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
297 glMatrixMode(GL_MODELVIEW);
302 glGetBooleanv(GL_LIGHTING, &lightp);
303 if (lightp) glDisable(GL_LIGHTING);
305 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
306 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
307 glDisable(GL_CULL_FACE);
309 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
311 RenderPalette(fPaletteLength, 1.6*fWWidth, fWHeight*0.6);
315 if (lightp) glEnable(GL_LIGHTING);
317 glMatrixMode(GL_PROJECTION);
320 glMatrixMode(GL_MODELVIEW);
325 /******************************************************************************/
326 // Protected sub-renderers
327 /******************************************************************************/
329 //______________________________________________________________________________
330 Float_t AliEveITSModuleStepper::TextLength(const char* txt)
332 Float_t llx, lly, llz, urx, ury, urz;
333 fText->BBox(txt, llx, lly, llz, urx, ury, urz);
334 return (urx-llx)*fTextSize;
337 //______________________________________________________________________________
338 void AliEveITSModuleStepper::RenderString(TString string, Int_t id)
340 Float_t txtY = fWHeight*0.5;
341 Float_t txtl = TextLength(string.Data());
343 if(id > 0) glLoadName(id);
344 if(id>0 && fWActive == id)
345 fText->SetTextColor(fWActiveCol);
347 fText->SetTextColor(fFontCol);
353 fText->SetTextColor(fWActiveCol);
355 fText->SetTextColor(fFontCol);
358 Float_t ss = fWWidth*0.4;
359 fText->PaintGLText(ss, txtY, -0.8, string.Data());
361 Float_t bw =2*ss+txtl;
362 RenderFrame(bw,fWHeight*2,id);
363 glTranslatef( bw, 0, 0);
367 fText->SetTextColor(fFontCol);
368 fText->PaintGLText(0, txtY, -0.8, string.Data());
369 glTranslatef(txtl, 0, 0);
373 //______________________________________________________________________________
374 void AliEveITSModuleStepper::RenderFrame(Float_t dx, Float_t dy, Int_t id)
376 if(fRnrFrame == kFALSE)return;
378 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
379 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
382 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
384 TEveUtil:: TEveUtil::ColorFromIdx(fWCol, color);
388 glVertex2f(0, 0); glVertex2f(dx, 0);
389 glVertex2f(dx, dy); glVertex2f(0, dy);
394 //______________________________________________________________________________
395 void AliEveITSModuleStepper::RenderSymbol(Float_t dx, Float_t dy, Int_t id)
401 TEveUtil::TEveUtil::ColorFromIdx(fWActiveCol, color);
403 TEveUtil::TEveUtil::ColorFromIdx(fWCol, color);
406 Float_t xs = dx/4, ys = dy/4;
409 glVertex2f(0,ys); glVertex2f(0, ys*3);
410 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
415 glBegin(GL_TRIANGLES);
420 // glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
421 glVertex2f(xs*3, ys*3); glVertex2f(xs*1, ys*2); glVertex2f(xs*3, ys);
427 glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
428 glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
434 //glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
435 glVertex2f(xs*1, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*1, ys*3);
441 glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
442 glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
448 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
454 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
465 //______________________________________________________________________________
466 void AliEveITSModuleStepper::RenderPalette(Float_t dx, Float_t x, Float_t y)
470 glTranslatef(1 -x- dx, -1+y*4, 0);
471 AliEveITSModule* qs = dynamic_cast<AliEveITSModule*>(*BeginChildren());
472 TEveRGBAPalette* p = qs->GetPalette();
473 glBegin(GL_QUAD_STRIP);
474 glColor4ubv(p->ColorFromValue(p->GetMinVal()));
477 if (p->GetMaxVal() > p->GetMinVal() + 1)
479 Float_t xs = dx/(p->GetMaxVal() - p->GetMinVal());
481 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
483 glColor4ubv(p->ColorFromValue(i));
489 glColor4ubv(p->ColorFromValue(p->GetMaxVal()));
494 if (p->GetMaxVal() > p->GetMinVal())
496 glRotatef(-90,1, 0, 0 );
497 Double_t v1[3] = {0., 0., 0.};
498 Double_t v2[3] = {dx, 0, 0.};
499 fAxis->SetLabelsSize(fTextSize/dx);
500 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 206);
505 //______________________________________________________________________________
506 void AliEveITSModuleStepper::RenderMenu()
508 Float_t ww = 2*fWWidth;
509 Float_t wh = 2*fWHeight;
513 glColor4f(a, a, a, a);
514 Float_t H = 1.9*wh*(1+ 2*fWOff);
517 glVertex3f(-1, -1, 0.1); glVertex3f(-1, -1+H, 0.1);
518 glVertex3f(1 , -1+H, 0.1); glVertex3f( 1, -1 , 0.1);
522 Float_t y_base = -1 + wh*0.35;
523 glTranslatef(-1, y_base, 0.);
527 glTranslatef(ww, 0, 0.);
528 fText->SetTextSize(fTextSize);
529 Float_t soff = ww*1.3;
530 glTranslatef(0, fWOff*wh, 0);
531 RenderSymbol(ww, wh, 2);
532 RenderFrame(ww,wh,2);
533 glTranslatef(soff, 0, 0);
534 RenderSymbol(ww, wh, 1);
535 RenderFrame(ww,wh,1);
536 glTranslatef(soff, 0, 0);
539 const char* txt = Form("%d/%d ", GetCurrentPage(), GetPages());
540 Float_t dx = (fPagerGap - TextLength(txt))*0.5;
541 fText->SetTextColor(fFontCol);
542 fText->PaintGLText(dx, wh*0.25, -0.8, txt);
544 glTranslatef(fPagerGap, 0, 0);
546 RenderSymbol(ww, wh, 3);
547 RenderFrame(ww,wh,3);
548 glTranslatef(soff, 0, 0);
549 RenderSymbol(ww, wh, 4);
550 RenderFrame(ww,wh,4);
551 glTranslatef(2*ww, 0, 0);
556 AliEveITSDigitsInfo* di = fDigitsInfo;
557 Int_t scale = fScaleInfo->GetScale() - 1;
558 AliEveITSScaledModule* sm = dynamic_cast<AliEveITSScaledModule*>(*BeginChildren());
559 Int_t cnx = 0, cnz = 0;
560 switch(sm->GetSubDetID())
563 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
566 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
569 cnx = di->fSSDScale[scale], cnz = 1;
572 glTranslatef(10*ww,0, 0);
573 RenderString(Form("Zoom: "));
575 glTranslatef(0, 0.2*wh, 0);
576 RenderSymbol(ww, wh*0.9, 5);
577 glTranslatef(0, 0.4*wh, 0);
578 RenderFrame(ww, wh*0.5, 5);
580 RenderSymbol(ww, wh*0.9, 6);
581 RenderFrame(ww, wh*0.5, 6);
582 glTranslatef(ww, 0, 0);
583 RenderString(Form("%dx%d ", cnx, cnz));
588 glTranslatef(18*ww, 0, 0);
590 RenderString("SPD", 8);
591 glTranslatef(bs, 0, 0);
592 RenderString("SDD", 9);
593 glTranslatef(bs, 0, 0);
594 RenderString("SSD", 10);
600 //______________________________________________________________________________
601 void AliEveITSModuleStepper::RenderCellIDs()
603 fText->SetTextSize(fStepper->GetDy()*0.1);
604 fText->SetTextColor(fFontCol);
607 UInt_t idx = fPosition;
608 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
610 if(idx < fIDs.size())
612 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
613 TEveTrans& tr = mod->RefHMTrans();
614 TString name = Form("%d",mod->GetID());
616 x += fStepper->GetDx()*0.5;
617 y -= fStepper->GetDy()*0.5;
618 z += 0.4; // !!! MT hack - cross check with overlay rendering.
619 Float_t llx, lly, llz, urx, ury, urz;
620 fText->BBox(name, llx, lly, llz, urx, ury, urz);
621 tr.GetScale(sx, sy, sz);
622 fText->PaintGLText(x-(urx-llx)*sx, y, z, name);
629 /******************************************************************************/
630 // Virtual event handlers from TGLOverlayElement
631 /******************************************************************************/
633 //______________________________________________________________________________
634 Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
635 TGLOvlSelectRecord & rec,
638 // Handle overlay event.
639 // Return TRUE if event was handled.
641 switch (event->fType)
645 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
646 if (fWActive != item) {
656 if (event->fCode != kButton1) {
659 switch (rec.GetItem(1))
675 AliEveDigitScaleInfo* si = fScaleInfo;
676 if(si->GetScale() < 5)
678 si->ScaleChanged(si->GetScale() + 1);
679 ElementChanged(kTRUE, kTRUE);
685 AliEveDigitScaleInfo* si = fScaleInfo;
686 if(si->GetScale() > 1)
688 si->ScaleChanged(si->GetScale() - 1);
689 ElementChanged(kTRUE, kTRUE);
694 gEve->GetEditor()->DisplayElement(*BeginChildren());
718 //______________________________________________________________________________
719 Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
724 //______________________________________________________________________________
725 void AliEveITSModuleStepper::MouseLeave()
727 // Mouse has left the element.