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>
33 //______________________________________________________________________________
35 // Display scaled ITS modules in a paged layout, also providing
36 // GL-overaly control GUI.
39 ClassImp(AliEveITSModuleStepper)
41 AliEveITSModuleStepper::AliEveITSModuleStepper(AliEveITSDigitsInfo* di) :
42 TEveElementList("ITS 2DStore", "AliEveITSModuleStepper", kTRUE),
52 fModuleFont(), fTextFont(), fSymbolFont(),
64 SetMainColorPtr(&fTextCol);
65 fAxis = new TGLAxis();
67 // override member from base TEveElementList
68 fChildClass = AliEveITSScaledModule::Class();
70 fDigitsInfo->IncRefCount();
72 fStepper = new TEveGridStepper();
73 fStepper->SetNs(5, 4);
75 fScaleInfo = new AliEveDigitScaleInfo();
76 fScaleInfo->IncRefCount();
78 gEve->GetDefaultGLViewer()->AddOverlayElement(this);
81 AliEveITSModuleStepper::~AliEveITSModuleStepper()
85 gEve->GetDefaultGLViewer()->RemoveOverlayElement(this);
87 fScaleInfo->DecRefCount();
88 fDigitsInfo->DecRefCount();
94 /******************************************************************************/
96 void AliEveITSModuleStepper::Capacity()
98 // Make sure we have just enough children (module representations)
99 // to store as many modules as required by the grid-stepper
102 Int_t n = fStepper->GetNx()*fStepper->GetNy();
103 if (n != NumChildren())
106 for (Int_t m=0; m<n; ++m)
108 AddElement(new AliEveITSScaledModule(m, fDigitsInfo, fScaleInfo));
113 /******************************************************************************/
115 void AliEveITSModuleStepper::SetFirst(Int_t first)
117 // Se module ID which apply to first item in stepper.
119 Int_t lastpage = fModuleIDs.size()/Nxy();
120 if (fModuleIDs.size() % Nxy() ) lastpage++;
122 Int_t firstLastpage = (lastpage - 1)*Nxy();
123 if (first > firstLastpage) first = firstLastpage;
124 if (first < 0) first = 0;
129 void AliEveITSModuleStepper::Start()
137 void AliEveITSModuleStepper::Next()
141 SetFirst(fPosition + Nxy());
144 void AliEveITSModuleStepper::Previous()
146 // Go to previous page.
148 SetFirst(fPosition - Nxy());
151 void AliEveITSModuleStepper::End()
155 Int_t lastpage = fModuleIDs.size()/Nxy();
156 if (fModuleIDs.size() % Nxy()) lastpage++;
157 fPosition = (lastpage - 1)*Nxy();
163 /******************************************************************************/
165 void AliEveITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
167 // Select modules to display by sub-det type / layer.
171 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
174 fDigitsInfo->GetModuleIDs(&sel, fModuleIDs);
175 //in reder menu define a space between left and right pager
179 /******************************************************************************/
181 Int_t AliEveITSModuleStepper::GetCurrentPage() const
183 // Get number of current page.
185 Int_t idx = fPosition + 1;
187 if (idx % Nxy()) n++;
191 /******************************************************************************/
193 Int_t AliEveITSModuleStepper::GetPages()
195 // Get number of all pages.
197 Int_t n = fModuleIDs.size()/Nxy();
198 if (fModuleIDs.size() % Nxy()) n++;
202 /******************************************************************************/
204 void AliEveITSModuleStepper::Apply()
206 // Apply current settings to children modules.
208 gEve->DisableRedraw();
211 UInt_t idx = fPosition;
212 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
214 if (idx < fModuleIDs.size())
216 AliEveITSScaledModule* mod = static_cast<AliEveITSScaledModule*>(*childit);
217 mod->SetID(fModuleIDs[idx], kFALSE);
218 TEveTrans& tr = mod->RefMainTrans();
220 tr.RotateLF(3,2,TMath::PiOver2());
221 tr.RotateLF(1,3,TMath::PiOver2());
225 Float_t* fp = mod->GetFrame()->GetFramePoints();
226 // switch x,z it will be rotated afterwards
231 Double_t sx = fStepper->GetDx();
232 Double_t sy = (mx*fStepper->GetDx())/mz;
233 if (sy > fStepper->GetDy())
235 sy = fStepper->GetDy();
236 sx = (mz*fStepper->GetDx())/mx;
238 Float_t scale = (0.85*sx)/mz;
239 tr.Scale(scale, scale, scale);
242 fStepper->GetPosition(p);
243 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
245 if (mod->GetSubDetID() == 2)
246 mod->SetName(Form("SSD %d", idx));
247 else if (mod->GetSubDetID() == 1)
248 mod->SetName(Form("SDD %d", idx));
250 mod->SetName(Form("SPD %d", idx));
251 mod->SetRnrSelf(kTRUE);
257 (*childit)->SetRnrSelf(kFALSE);
263 gEve->EnableRedraw();
267 /******************************************************************************/
268 // Virtual event handlers from TGLOverlayElement
269 /******************************************************************************/
271 //______________________________________________________________________________
272 Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
273 TGLOvlSelectRecord & rec,
276 // Handle overlay event.
277 // Return TRUE if event was handled.
279 switch (event->fType)
283 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
284 if (fActiveID != item) {
294 if (event->fCode != kButton1) {
297 switch (rec.GetItem(1))
313 AliEveDigitScaleInfo* si = fScaleInfo;
314 if (si->GetScale() < 5)
316 si->ScaleChanged(si->GetScale() + 1);
317 ElementChanged(kTRUE, kTRUE);
323 AliEveDigitScaleInfo* si = fScaleInfo;
324 if (si->GetScale() > 1)
326 si->ScaleChanged(si->GetScale() - 1);
327 ElementChanged(kTRUE, kTRUE);
332 gEve->GetEditor()->DisplayElement(*BeginChildren());
356 //______________________________________________________________________________
357 Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
359 // Mouse has entered overlay area.
364 //______________________________________________________________________________
365 void AliEveITSModuleStepper::MouseLeave()
367 // Mouse has left overlay area.
373 /******************************************************************************/
374 // Protected sub-renderers
375 /******************************************************************************/
377 //______________________________________________________________________________
378 void AliEveITSModuleStepper::RenderText(const char* txt, Int_t id, const TGLFont &font, Float_t step)
380 // Render text for button id.
382 Float_t llx, lly, llz, urx, ury, urz;
383 font.BBox(txt, llx, lly, llz, urx, ury, urz);
384 (fActiveID == id && id > 0) ? TGLUtil::Color(fActiveCol) :TGLUtil::Color(fTextCol);
388 // center text in the step interval
391 glTranslatef((step-urx+llx)*0.5f-llx, 0, 0);
395 glTranslatef(step, 0, 0);
403 glTranslatef(urx, 0, 0);
407 //______________________________________________________________________________
408 void AliEveITSModuleStepper::RenderPalette(TEveRGBAPalette* p)
410 // Render color palette with number axis.
412 Float_t length = 7*fTextSize;
413 Float_t x = 1.5*fTextSize;
414 Float_t y = 0.2*fTextSize;
416 glTranslatef(x, 0.8*fTextSize, 0);
418 TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
420 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
421 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
422 glDisable(GL_CULL_FACE);
424 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
426 glBegin(GL_QUAD_STRIP);
427 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMinVal()));
430 if (p->GetMaxVal() > p->GetMinVal() + 1)
432 Float_t xs = length/(p->GetMaxVal() - p->GetMinVal());
434 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
436 TGLUtil::Color4ubv(p->ColorFromValue(i));
442 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMaxVal()));
443 glVertex2f(length, 0);
444 glVertex2f(length, y);
447 glRotatef(-90, 1, 0, 0 );
448 Double_t v1[3] = {0., 0., 0.};
449 Double_t v2[3] = {length, 0, 0.};
450 fAxis->SetTextColor(kGray+1);
451 fAxis->SetLineColor(kGray+1);
452 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 5);
456 //______________________________________________________________________________
457 void AliEveITSModuleStepper::RenderMenu(Int_t curP, Int_t maxP, Int_t scaleX, Int_t scaleZ)
459 // Make UI to set page in stepper and UI to scale in the AliEveITSScaledModule.
461 TGLUtil::Color(fTextCol);
462 fTextFont.PreRender();
463 glTranslatef(0, fTextSize*0.3, 0);
466 glTranslatef(fTextSize*0.2, 0 , 0);
467 RenderText("9", 2, fSymbolFont); // last page
468 RenderText("3", 1, fSymbolFont);//last page
469 RenderText(Form("%d/%d", curP, maxP),-1, fTextFont, 2.7*fTextSize); //status
471 // bugg in webdings font , bbox does not give realistic value
472 Float_t llx, lly, llz, urx, ury, urz;
473 fSymbolFont.BBox("4", llx, lly, llz, urx, ury, urz);
474 glTranslatef(-llx, 0, 0);
476 RenderText("4", 3, fSymbolFont); // next page
477 RenderText(":",4, fSymbolFont); // last page
481 glTranslatef(fTextSize,0, 0);
482 RenderText(Form("Zoom:"), -1, fTextFont);
483 RenderText("6", 6, fSymbolFont);
484 RenderText("5", 5, fSymbolFont);
485 RenderText(Form("%dx%d", scaleX, scaleZ), -1, fTextFont, 2*fTextSize);
489 glTranslatef(fTextSize, 0, 0);
490 RenderText("SPD ", 8, fTextFont);
491 RenderText("SDD ", 9, fTextFont);
492 RenderText("SSD ", 10, fTextFont);
493 fTextFont.PostRender();
497 //______________________________________________________________________________
498 void AliEveITSModuleStepper::RenderModuleIDs()
500 // Render module-ids.
503 UInt_t idx = fPosition;
504 Float_t llx, lly, llz, urx, ury, urz;
505 fModuleFont.PreRender();
506 TGLUtil::Color(kWhite);
507 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
509 if (idx < fModuleIDs.size())
511 AliEveITSScaledModule* mod = static_cast<AliEveITSScaledModule*>(*childit);
512 TEveTrans& tr = mod->RefMainTrans();
514 x += fStepper->GetDx()*0.5;
515 y -= fStepper->GetDy()*0.5;
516 z += 0.4; // !!! MT hack - cross check with overlay rendering.
517 const char* txt = Form("%d",mod->GetID());
518 fModuleFont.BBox(txt, llx, lly, llz, urx, ury, urz);
519 glRasterPos3f(x, y, z);
520 glBitmap(0, 0, 0, 0,-urx, 0, 0);
521 fModuleFont.Render(txt);
525 fModuleFont.PostRender();
528 /******************************************************************************/
530 void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
532 // Render the overlay elements.
534 AliEveITSScaledModule* sm = static_cast<AliEveITSScaledModule*>(*BeginChildren());
535 Int_t scaleIdx = fScaleInfo->GetScale() - 1;
536 Int_t cnx = 0, cnz = 0;
537 switch(sm->GetSubDetID())
540 cnx = fDigitsInfo->fSPDScaleX[scaleIdx];
541 cnz = fDigitsInfo->fSPDScaleZ[scaleIdx];
544 cnx = fDigitsInfo->fSDDScaleX[scaleIdx];
545 cnz = fDigitsInfo->fSDDScaleZ[scaleIdx];
548 cnx = fDigitsInfo->fSSDScale[scaleIdx];
554 if (fTextFont.GetMode() == TGLFont::kUndef)
556 #if ROOT_VERSION_CODE >= 332547
557 rnrCtx.RegisterFont(fTextSize, 4, TGLFont::kTexture, fTextFont);
558 rnrCtx.RegisterFont(72, 31, TGLFont::kTexture, fSymbolFont);
559 rnrCtx.RegisterFont(14, 4, TGLFont::kPixmap, fModuleFont);
561 fTextFont = rnrCtx.GetFont(fTextSize, 4, TGLFont::kTexture);
562 fSymbolFont = rnrCtx.GetFont(72, 31, TGLFont::kTexture);
563 fModuleFont = rnrCtx.GetFont(14, 4, TGLFont::kPixmap);
569 glMatrixMode(GL_PROJECTION);
572 if (rnrCtx.Selection())
574 TGLRect rect(*rnrCtx.GetPickRectangle());
575 rnrCtx.GetCamera()->WindowToViewport(rect);
576 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
577 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
579 glMatrixMode(GL_MODELVIEW);
582 glTranslatef(-1, -1, 0); // translate to lower left corner
583 Float_t txtScale = fMenuHeight/fTextSize*0.5; // scale text
584 glScalef(txtScale, txtScale, 1.);
588 RenderMenu(GetCurrentPage(), GetPages(), cnx, cnz);
591 Double_t labelSize = 1.6*txtScale*fTextSize;
592 fAxis->SetLabelsSize(labelSize);
593 fAxis->SetLabelsOffset(1.2*labelSize);
594 RenderPalette(sm->GetPalette());
597 glMatrixMode(GL_PROJECTION);
599 glMatrixMode(GL_MODELVIEW);