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 <TEveTrans.h>
19 #include <TGLRnrCtx.h>
20 #include <TGLIncludes.h>
21 #include <TGLSelectRecord.h>
23 #include <TGLViewer.h>
27 #include <THLimitsFinder.h>
28 #include <TVirtualPad.h>
32 //______________________________________________________________________________
34 // Display scaled ITS modules in a paged layout, also providing
35 // GL-overaly control GUI.
38 ClassImp(AliEveITSModuleStepper)
40 AliEveITSModuleStepper::AliEveITSModuleStepper(AliEveITSDigitsInfo* di) :
41 TEveElementList("ITS 2DStore", "AliEveITSModuleStepper", kTRUE),
51 fModuleFont(), fTextFont(), fSymbolFont(),
63 SetMainColorPtr(&fTextCol);
64 fAxis = new TGLAxis();
66 // override member from base TEveElementList
67 fChildClass = AliEveITSScaledModule::Class();
69 fDigitsInfo->IncRefCount();
71 fStepper = new TEveGridStepper();
72 fStepper->SetNs(5, 4);
74 fScaleInfo = new AliEveDigitScaleInfo();
75 fScaleInfo->IncRefCount();
77 gEve->GetGLViewer()->AddOverlayElement(this);
80 AliEveITSModuleStepper::~AliEveITSModuleStepper()
84 gEve->GetGLViewer()->RemoveOverlayElement(this);
86 fScaleInfo->DecRefCount();
87 fDigitsInfo->DecRefCount();
93 /******************************************************************************/
95 void AliEveITSModuleStepper::Capacity()
97 // Make sure we have just enough children (module representations)
98 // to store as many modules as required by the grid-stepper
101 Int_t n = fStepper->GetNx()*fStepper->GetNy();
102 if (n != NumChildren())
105 for (Int_t m=0; m<n; ++m)
107 AddElement(new AliEveITSScaledModule(m, fDigitsInfo, fScaleInfo));
112 /******************************************************************************/
114 void AliEveITSModuleStepper::SetFirst(Int_t first)
116 // Se module ID which apply to first item in stepper.
118 Int_t lastpage = fModuleIDs.size()/Nxy();
119 if (fModuleIDs.size() % Nxy() ) lastpage++;
121 Int_t firstLastpage = (lastpage - 1)*Nxy();
122 if (first > firstLastpage) first = firstLastpage;
123 if (first < 0) first = 0;
128 void AliEveITSModuleStepper::Start()
136 void AliEveITSModuleStepper::Next()
140 SetFirst(fPosition + Nxy());
143 void AliEveITSModuleStepper::Previous()
145 // Go to previous page.
147 SetFirst(fPosition - Nxy());
150 void AliEveITSModuleStepper::End()
154 Int_t lastpage = fModuleIDs.size()/Nxy();
155 if (fModuleIDs.size() % Nxy()) lastpage++;
156 fPosition = (lastpage - 1)*Nxy();
162 /******************************************************************************/
164 void AliEveITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
166 // Select modules to display by sub-det type / layer.
170 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
173 fDigitsInfo->GetModuleIDs(&sel, fModuleIDs);
174 //in reder menu define a space between left and right pager
178 /******************************************************************************/
180 Int_t AliEveITSModuleStepper::GetCurrentPage() const
182 // Get number of current page.
184 Int_t idx = fPosition + 1;
186 if (idx % Nxy()) n++;
190 /******************************************************************************/
192 Int_t AliEveITSModuleStepper::GetPages()
194 // Get number of all pages.
196 Int_t n = fModuleIDs.size()/Nxy();
197 if (fModuleIDs.size() % Nxy()) n++;
201 /******************************************************************************/
203 void AliEveITSModuleStepper::Apply()
205 // Apply current settings to children modules.
207 gEve->DisableRedraw();
210 UInt_t idx = fPosition;
211 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
213 if (idx < fModuleIDs.size())
215 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
216 mod->SetID(fModuleIDs[idx], kFALSE);
217 TEveTrans& tr = mod->RefMainTrans();
219 tr.RotateLF(3,2,TMath::PiOver2());
220 tr.RotateLF(1,3,TMath::PiOver2());
224 Float_t* fp = mod->GetFrame()->GetFramePoints();
225 // switch x,z it will be rotated afterwards
230 Double_t sx = fStepper->GetDx();
231 Double_t sy = (mx*fStepper->GetDx())/mz;
232 if (sy > fStepper->GetDy())
234 sy = fStepper->GetDy();
235 sx = (mz*fStepper->GetDx())/mx;
237 Float_t scale = (0.85*sx)/mz;
238 tr.Scale(scale, scale, scale);
241 fStepper->GetPosition(p);
242 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
244 if (mod->GetSubDetID() == 2)
245 mod->SetName(Form("SSD %d", idx));
246 else if (mod->GetSubDetID() == 1)
247 mod->SetName(Form("SDD %d", idx));
249 mod->SetName(Form("SPD %d", idx));
250 mod->SetRnrSelf(kTRUE);
256 (*childit)->SetRnrSelf(kFALSE);
262 gEve->EnableRedraw();
266 /******************************************************************************/
267 // Virtual event handlers from TGLOverlayElement
268 /******************************************************************************/
270 //______________________________________________________________________________
271 Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
272 TGLOvlSelectRecord & rec,
275 // Handle overlay event.
276 // Return TRUE if event was handled.
278 switch (event->fType)
282 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
283 if (fActiveID != item) {
293 if (event->fCode != kButton1) {
296 switch (rec.GetItem(1))
312 AliEveDigitScaleInfo* si = fScaleInfo;
313 if (si->GetScale() < 5)
315 si->ScaleChanged(si->GetScale() + 1);
316 ElementChanged(kTRUE, kTRUE);
322 AliEveDigitScaleInfo* si = fScaleInfo;
323 if (si->GetScale() > 1)
325 si->ScaleChanged(si->GetScale() - 1);
326 ElementChanged(kTRUE, kTRUE);
331 gEve->GetEditor()->DisplayElement(*BeginChildren());
355 //______________________________________________________________________________
356 Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
358 // Mouse has entered overlay area.
363 //______________________________________________________________________________
364 void AliEveITSModuleStepper::MouseLeave()
366 // Mouse has left overlay area.
372 /******************************************************************************/
373 // Protected sub-renderers
374 /******************************************************************************/
376 //______________________________________________________________________________
377 void AliEveITSModuleStepper::RenderText(const char* txt, Int_t id, const TGLFont &font, Float_t step)
379 // Render text for button id.
381 Float_t llx, lly, llz, urx, ury, urz;
382 font.BBox(txt, llx, lly, llz, urx, ury, urz);
383 (fActiveID == id && id > 0) ? TGLUtil::Color(fActiveCol) :TGLUtil::Color(fTextCol);
387 // center text in the step interval
390 glTranslatef((step-urx+llx)*0.5f-llx, 0, 0);
394 glTranslatef(step, 0, 0);
402 glTranslatef(urx, 0, 0);
406 //______________________________________________________________________________
407 void AliEveITSModuleStepper::RenderPalette(TEveRGBAPalette* p)
409 // Render color palette with number axis.
411 Float_t length = 7*fTextSize;
412 Float_t x = 1.5*fTextSize;
413 Float_t y = 0.2*fTextSize;
415 glTranslatef(x, 0.8*fTextSize, 0);
417 TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
419 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
420 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
421 glDisable(GL_CULL_FACE);
423 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
425 glBegin(GL_QUAD_STRIP);
426 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMinVal()));
429 if (p->GetMaxVal() > p->GetMinVal() + 1)
431 Float_t xs = length/(p->GetMaxVal() - p->GetMinVal());
433 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
435 TGLUtil::Color4ubv(p->ColorFromValue(i));
441 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMaxVal()));
442 glVertex2f(length, 0);
443 glVertex2f(length, y);
446 glRotatef(-90, 1, 0, 0 );
447 Double_t v1[3] = {0., 0., 0.};
448 Double_t v2[3] = {length, 0, 0.};
449 fAxis->SetTextColor(kGray+1);
450 fAxis->SetLineColor(kGray+1);
451 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 5);
455 //______________________________________________________________________________
456 void AliEveITSModuleStepper::RenderMenu(Int_t curP, Int_t maxP, Int_t scaleX, Int_t scaleZ)
458 // Make UI to set page in stepper and UI to scale in the AliEveITSScaledModule.
460 TGLUtil::Color(fTextCol);
461 fTextFont.PreRender();
462 glTranslatef(0, fTextSize*0.3, 0);
465 glTranslatef(fTextSize*0.2, 0 , 0);
466 RenderText("9", 2, fSymbolFont); // last page
467 RenderText("3", 1, fSymbolFont);//last page
468 RenderText(Form("%d/%d", curP, maxP),-1, fTextFont, 2.7*fTextSize); //status
470 // bugg in webdings font , bbox does not give realistic value
471 Float_t llx, lly, llz, urx, ury, urz;
472 fSymbolFont.BBox("4", llx, lly, llz, urx, ury, urz);
473 glTranslatef(-llx, 0, 0);
475 RenderText("4", 3, fSymbolFont); // next page
476 RenderText(":",4, fSymbolFont); // last page
480 glTranslatef(fTextSize,0, 0);
481 RenderText(Form("Zoom:"), -1, fTextFont);
482 RenderText("6", 6, fSymbolFont);
483 RenderText("5", 5, fSymbolFont);
484 RenderText(Form("%dx%d", scaleX, scaleZ), -1, fTextFont, 2*fTextSize);
488 glTranslatef(fTextSize, 0, 0);
489 RenderText("SPD ", 8, fTextFont);
490 RenderText("SDD ", 9, fTextFont);
491 RenderText("SSD ", 10, fTextFont);
492 fTextFont.PostRender();
496 //______________________________________________________________________________
497 void AliEveITSModuleStepper::RenderModuleIDs()
499 // Render module-ids.
502 UInt_t idx = fPosition;
503 Float_t llx, lly, llz, urx, ury, urz;
504 fModuleFont.PreRender();
505 TGLUtil::Color(kWhite);
506 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
508 if (idx < fModuleIDs.size())
510 AliEveITSScaledModule* mod = dynamic_cast<AliEveITSScaledModule*>(*childit);
511 TEveTrans& tr = mod->RefMainTrans();
513 x += fStepper->GetDx()*0.5;
514 y -= fStepper->GetDy()*0.5;
515 z += 0.4; // !!! MT hack - cross check with overlay rendering.
516 const char* txt = Form("%d",mod->GetID());
517 fModuleFont.BBox(txt, llx, lly, llz, urx, ury, urz);
518 glRasterPos3f(x, y, z);
519 glBitmap(0, 0, 0, 0,-urx, 0, 0);
520 fModuleFont.Render(txt);
524 fModuleFont.PostRender();
527 /******************************************************************************/
529 void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
531 // Render the overlay elements.
533 AliEveITSScaledModule* sm = dynamic_cast<AliEveITSScaledModule*>(*BeginChildren());
534 Int_t scaleIdx = fScaleInfo->GetScale() - 1;
535 Int_t cnx = 0, cnz = 0;
536 switch(sm->GetSubDetID())
539 cnx = fDigitsInfo->fSPDScaleX[scaleIdx];
540 cnz = fDigitsInfo->fSPDScaleZ[scaleIdx];
543 cnx = fDigitsInfo->fSDDScaleX[scaleIdx];
544 cnz = fDigitsInfo->fSDDScaleZ[scaleIdx];
547 cnx = fDigitsInfo->fSSDScale[scaleIdx];
553 if (fTextFont.GetMode() == TGLFont::kUndef)
555 #if ROOT_VERSION_CODE >= 332547
556 rnrCtx.RegisterFont(fTextSize, 4, TGLFont::kTexture, fTextFont);
557 rnrCtx.RegisterFont(72, 31, TGLFont::kTexture, fSymbolFont);
558 rnrCtx.RegisterFont(14, 4, TGLFont::kPixmap, fModuleFont);
560 fTextFont = rnrCtx.GetFont(fTextSize, 4, TGLFont::kTexture);
561 fSymbolFont = rnrCtx.GetFont(72, 31, TGLFont::kTexture);
562 fModuleFont = rnrCtx.GetFont(14, 4, TGLFont::kPixmap);
568 glMatrixMode(GL_PROJECTION);
571 if (rnrCtx.Selection())
573 TGLRect rect(*rnrCtx.GetPickRectangle());
574 rnrCtx.GetCamera()->WindowToViewport(rect);
575 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
576 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
578 glMatrixMode(GL_MODELVIEW);
581 glTranslatef(-1, -1, 0); // translate to lower left corner
582 Float_t txtScale = fMenuHeight/fTextSize*0.5; // scale text
583 glScalef(txtScale, txtScale, 1.);
587 RenderMenu(GetCurrentPage(), GetPages(), cnx, cnz);
590 Double_t labelSize = 1.6*txtScale*fTextSize;
591 fAxis->SetLabelsSize(labelSize);
592 fAxis->SetLabelsOffset(1.2*labelSize);
593 RenderPalette(sm->GetPalette());
596 glMatrixMode(GL_PROJECTION);
598 glMatrixMode(GL_MODELVIEW);