]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveITSModuleStepper.cxx
Converting PWGLFQATasks to native cmake
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSModuleStepper.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
82b3616d 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveITSModuleStepper.h"
11#include "AliEveITSDigitsInfo.h"
12#include "AliEveITSScaledModule.h"
82b3616d 13
84aff7a4 14#include <TEveManager.h>
15#include <TEveGedEditor.h>
16#include <TEveGridStepper.h>
84aff7a4 17#include <TEveTrans.h>
09edeb17 18
32e219c2 19#include <TGLRnrCtx.h>
c87a8d78 20#include <TGLIncludes.h>
32e219c2 21#include <TGLSelectRecord.h>
a15e6d7d 22#include <TGLUtil.h>
32e219c2 23#include <TGLViewer.h>
c87a8d78 24#include <TGLAxis.h>
d810d0de 25
c87a8d78 26#include <TMath.h>
27#include <THLimitsFinder.h>
28#include <TVirtualPad.h>
82b3616d 29
a3d4f532 30#include <RVersion.h>
31
01ff6975 32
57ffa5fb 33//______________________________________________________________________________
82b3616d 34//
698e2c9b 35// Display scaled ITS modules in a paged layout, also providing
36// GL-overaly control GUI.
37
82b3616d 38
d810d0de 39ClassImp(AliEveITSModuleStepper)
82b3616d 40
d810d0de 41AliEveITSModuleStepper::AliEveITSModuleStepper(AliEveITSDigitsInfo* di) :
42 TEveElementList("ITS 2DStore", "AliEveITSModuleStepper", kTRUE),
32e219c2 43
32e219c2 44 fDigitsInfo(di),
45 fScaleInfo(0),
c87a8d78 46 fStepper(0),
32e219c2 47
c87a8d78 48 fModuleIDs(),
49 fPosition(0),
32e219c2 50 fSubDet(-1),
09edeb17 51
9af86b69 52 fModuleFont(), fTextFont(), fSymbolFont(),
32e219c2 53 fAxis(0),
c87a8d78 54
55 fMenuHeight(0.13),
56 fTextSize(64),
57 fTextCol(kGray+1),
58 fActiveCol(kRed-4),
59
60 fActiveID(-1)
82b3616d 61{
698e2c9b 62 // Constructor.
63
c87a8d78 64 SetMainColorPtr(&fTextCol);
65 fAxis = new TGLAxis();
66
84aff7a4 67 // override member from base TEveElementList
d810d0de 68 fChildClass = AliEveITSScaledModule::Class();
32e219c2 69
32e219c2 70 fDigitsInfo->IncRefCount();
71
84aff7a4 72 fStepper = new TEveGridStepper();
32e219c2 73 fStepper->SetNs(5, 4);
74
d810d0de 75 fScaleInfo = new AliEveDigitScaleInfo();
32e219c2 76 fScaleInfo->IncRefCount();
64c42545 77
68ca2fe7 78 gEve->GetDefaultGLViewer()->AddOverlayElement(this);
82b3616d 79}
80
d810d0de 81AliEveITSModuleStepper::~AliEveITSModuleStepper()
82b3616d 82{
698e2c9b 83 // Destructor.
84
68ca2fe7 85 gEve->GetDefaultGLViewer()->RemoveOverlayElement(this);
32e219c2 86
c87a8d78 87 fScaleInfo->DecRefCount();
32e219c2 88 fDigitsInfo->DecRefCount();
89
82b3616d 90 delete fStepper;
32e219c2 91 delete fAxis;
82b3616d 92}
93
57ffa5fb 94/******************************************************************************/
d7e36bcf 95
d810d0de 96void AliEveITSModuleStepper::Capacity()
82b3616d 97{
698e2c9b 98 // Make sure we have just enough children (module representations)
99 // to store as many modules as required by the grid-stepper
100 // configuration.
101
a15e6d7d 102 Int_t n = fStepper->GetNx()*fStepper->GetNy();
fbc350a3 103 if (n != NumChildren())
82b3616d 104 {
32e219c2 105 DestroyElements();
a15e6d7d 106 for (Int_t m=0; m<n; ++m)
32e219c2 107 {
d810d0de 108 AddElement(new AliEveITSScaledModule(m, fDigitsInfo, fScaleInfo));
32e219c2 109 }
82b3616d 110 }
82b3616d 111}
112
57ffa5fb 113/******************************************************************************/
d7e36bcf 114
d810d0de 115void AliEveITSModuleStepper::SetFirst(Int_t first)
09edeb17 116{
c87a8d78 117 // Se module ID which apply to first item in stepper.
118
119 Int_t lastpage = fModuleIDs.size()/Nxy();
ba5a649d 120 if (fModuleIDs.size() % Nxy() ) lastpage++;
51346b82 121
698e2c9b 122 Int_t firstLastpage = (lastpage - 1)*Nxy();
ba5a649d 123 if (first > firstLastpage) first = firstLastpage;
124 if (first < 0) first = 0;
09edeb17 125 fPosition = first;
09edeb17 126 Apply();
127}
128
d810d0de 129void AliEveITSModuleStepper::Start()
82b3616d 130{
698e2c9b 131 // Go to first page.
132
09edeb17 133 fPosition = 0;
82b3616d 134 Apply();
135}
136
d810d0de 137void AliEveITSModuleStepper::Next()
82b3616d 138{
698e2c9b 139 // Go to next page.
140
32e219c2 141 SetFirst(fPosition + Nxy());
09edeb17 142}
143
d810d0de 144void AliEveITSModuleStepper::Previous()
09edeb17 145{
698e2c9b 146 // Go to previous page.
147
32e219c2 148 SetFirst(fPosition - Nxy());
09edeb17 149}
150
d810d0de 151void AliEveITSModuleStepper::End()
51346b82 152{
698e2c9b 153 // Go to last page.
154
c87a8d78 155 Int_t lastpage = fModuleIDs.size()/Nxy();
156 if (fModuleIDs.size() % Nxy()) lastpage++;
698e2c9b 157 fPosition = (lastpage - 1)*Nxy();
09edeb17 158
51346b82 159 fStepper->Reset();
82b3616d 160 Apply();
161}
162
57ffa5fb 163/******************************************************************************/
d7e36bcf 164
d810d0de 165void AliEveITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
32e219c2 166{
c87a8d78 167 // Select modules to display by sub-det type / layer.
698e2c9b 168
32e219c2 169 fSubDet = det;
c87a8d78 170 fModuleIDs.clear();
d810d0de 171 AliEveITSModuleSelection sel = AliEveITSModuleSelection();
51346b82 172 sel.SetType (det);
173 sel.SetLayer(layer);
c87a8d78 174 fDigitsInfo->GetModuleIDs(&sel, fModuleIDs);
32e219c2 175 //in reder menu define a space between left and right pager
32e219c2 176 Start();
177}
178
57ffa5fb 179/******************************************************************************/
32e219c2 180
a15e6d7d 181Int_t AliEveITSModuleStepper::GetCurrentPage() const
32e219c2 182{
698e2c9b 183 // Get number of current page.
184
185 Int_t idx = fPosition + 1;
186 Int_t n = idx/Nxy();
187 if (idx % Nxy()) n++;
32e219c2 188 return n;
189}
190
57ffa5fb 191/******************************************************************************/
32e219c2 192
d810d0de 193Int_t AliEveITSModuleStepper::GetPages()
32e219c2 194{
698e2c9b 195 // Get number of all pages.
196
c87a8d78 197 Int_t n = fModuleIDs.size()/Nxy();
ba5a649d 198 if (fModuleIDs.size() % Nxy()) n++;
32e219c2 199 return n;
200}
51346b82 201
57ffa5fb 202/******************************************************************************/
32e219c2 203
d810d0de 204void AliEveITSModuleStepper::Apply()
82b3616d 205{
698e2c9b 206 // Apply current settings to children modules.
207
84aff7a4 208 gEve->DisableRedraw();
32e219c2 209 Capacity();
09edeb17 210
211 UInt_t idx = fPosition;
32e219c2 212 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
82b3616d 213 {
ba5a649d 214 if (idx < fModuleIDs.size())
82b3616d 215 {
01ff6975 216 AliEveITSScaledModule* mod = static_cast<AliEveITSScaledModule*>(*childit);
c87a8d78 217 mod->SetID(fModuleIDs[idx], kFALSE);
a15e6d7d 218 TEveTrans& tr = mod->RefMainTrans();
32e219c2 219 tr.UnitTrans();
220 tr.RotateLF(3,2,TMath::PiOver2());
51346b82 221 tr.RotateLF(1,3,TMath::PiOver2());
82b3616d 222
51346b82 223 // scaling
32e219c2 224 Float_t mz, mx;
d7e36bcf 225 Float_t* fp = mod->GetFrame()->GetFramePoints();
226 // switch x,z it will be rotated afterwards
32e219c2 227 mx = -2*fp[0];
228 mz = -2*fp[2];
d7e36bcf 229
32e219c2 230 // fit width first
84aff7a4 231 Double_t sx = fStepper->GetDx();
232 Double_t sy = (mx*fStepper->GetDx())/mz;
ba5a649d 233 if (sy > fStepper->GetDy())
82b3616d 234 {
84aff7a4 235 sy = fStepper->GetDy();
236 sx = (mz*fStepper->GetDx())/mx;
82b3616d 237 }
c87a8d78 238 Float_t scale = (0.85*sx)/mz;
32e219c2 239 tr.Scale(scale, scale, scale);
64c42545 240
32e219c2 241 Float_t p[3];
242 fStepper->GetPosition(p);
84aff7a4 243 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
51346b82 244
ba5a649d 245 if (mod->GetSubDetID() == 2)
b3ffcccb 246 mod->SetName(Form("SSD %d", idx));
ba5a649d 247 else if (mod->GetSubDetID() == 1)
b3ffcccb 248 mod->SetName(Form("SDD %d", idx));
d7e36bcf 249 else
b3ffcccb 250 mod->SetName(Form("SPD %d", idx));
32e219c2 251 mod->SetRnrSelf(kTRUE);
d7e36bcf 252
09edeb17 253 fStepper->Step();
254 idx++;
82b3616d 255 }
256 else {
257 (*childit)->SetRnrSelf(kFALSE);
258 }
259 }
09edeb17 260
32e219c2 261 fStepper->Reset();
262 ElementChanged();
84aff7a4 263 gEve->EnableRedraw();
82b3616d 264}
09edeb17 265
32e219c2 266
57ffa5fb 267/******************************************************************************/
32e219c2 268// Virtual event handlers from TGLOverlayElement
57ffa5fb 269/******************************************************************************/
09edeb17 270
57ffa5fb 271//______________________________________________________________________________
d810d0de 272Bool_t AliEveITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
698e2c9b 273 TGLOvlSelectRecord & rec,
274 Event_t * event)
09edeb17 275{
32e219c2 276 // Handle overlay event.
277 // Return TRUE if event was handled.
278
279 switch (event->fType)
51346b82 280 {
32e219c2 281 case kMotionNotify:
282 {
283 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
c87a8d78 284 if (fActiveID != item) {
285 fActiveID = item;
32e219c2 286 return kTRUE;
287 } else {
288 return kFALSE;
289 }
290 break;
291 }
292 case kButtonPress:
293 {
294 if (event->fCode != kButton1) {
295 return kFALSE;
296 }
297 switch (rec.GetItem(1))
298 {
299 case 1:
300 Previous();
301 break;
302 case 2:
303 Start();
304 break;
305 case 3:
306 Next();
307 break;
308 case 4:
309 End();
310 break;
311 case 5:
312 {
d810d0de 313 AliEveDigitScaleInfo* si = fScaleInfo;
ba5a649d 314 if (si->GetScale() < 5)
32e219c2 315 {
51346b82 316 si->ScaleChanged(si->GetScale() + 1);
32e219c2 317 ElementChanged(kTRUE, kTRUE);
318 }
319 break;
320 }
321 case 6:
322 {
d810d0de 323 AliEveDigitScaleInfo* si = fScaleInfo;
ba5a649d 324 if (si->GetScale() > 1)
32e219c2 325 {
51346b82 326 si->ScaleChanged(si->GetScale() - 1);
32e219c2 327 ElementChanged(kTRUE, kTRUE);
328 }
329 break;
330 }
331 case 7:
84aff7a4 332 gEve->GetEditor()->DisplayElement(*BeginChildren());
32e219c2 333 break;
334
335 case 8:
c87a8d78 336 DisplayDet(0, -1);
32e219c2 337 break;
51346b82 338 case 9:
c87a8d78 339 DisplayDet(1, -1);
32e219c2 340 break;
51346b82 341 case 10:
c87a8d78 342 DisplayDet(2, -1);
32e219c2 343 break;
344 default:
345 break;
346 }
347 return kTRUE;
348 break;
349 }
350 default:
351 break;
352 } // end switch
353 return kFALSE;
09edeb17 354}
32e219c2 355
57ffa5fb 356//______________________________________________________________________________
d810d0de 357Bool_t AliEveITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
32e219c2 358{
698e2c9b 359 // Mouse has entered overlay area.
360
32e219c2 361 return kTRUE;
362}
363
57ffa5fb 364//______________________________________________________________________________
d810d0de 365void AliEveITSModuleStepper::MouseLeave()
32e219c2 366{
698e2c9b 367 // Mouse has left overlay area.
32e219c2 368
c87a8d78 369 fActiveID = -1;
370}
371
372
373/******************************************************************************/
374// Protected sub-renderers
375/******************************************************************************/
376
377//______________________________________________________________________________
ba5a649d 378void AliEveITSModuleStepper::RenderText(const char* txt, Int_t id, const TGLFont &font, Float_t step)
c87a8d78 379{
380 // Render text for button id.
381
382 Float_t llx, lly, llz, urx, ury, urz;
c87a8d78 383 font.BBox(txt, llx, lly, llz, urx, ury, urz);
ba5a649d 384 (fActiveID == id && id > 0) ? TGLUtil::Color(fActiveCol) :TGLUtil::Color(fTextCol);
385
386 if (step > 0)
387 {
388 // center text in the step interval
389 glPushMatrix();
390 if (step>urx)
391 glTranslatef((step-urx+llx)*0.5f-llx, 0, 0);
392 glLoadName(id);
393 font.Render(txt);
394 glPopMatrix();
395 glTranslatef(step, 0, 0);
396 }
397 else
398 {
399 glLoadName(id);
400 glPushMatrix();
401 font.Render(txt);
402 glPopMatrix();
403 glTranslatef(urx, 0, 0);
404 }
c87a8d78 405}
406
407//______________________________________________________________________________
408void AliEveITSModuleStepper::RenderPalette(TEveRGBAPalette* p)
409{
410 // Render color palette with number axis.
411
412 Float_t length = 7*fTextSize;
413 Float_t x = 1.5*fTextSize;
414 Float_t y = 0.2*fTextSize;
415
416 glTranslatef(x, 0.8*fTextSize, 0);
417
418 TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
419
420 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
421 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
422 glDisable(GL_CULL_FACE);
423 glEnable(GL_BLEND);
424 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
425
426 glBegin(GL_QUAD_STRIP);
427 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMinVal()));
428 glVertex2f(0, 0);
429 glVertex2f(0, y);
430 if (p->GetMaxVal() > p->GetMinVal() + 1)
431 {
432 Float_t xs = length/(p->GetMaxVal() - p->GetMinVal());
433 Float_t x0 = xs;
434 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
435 {
436 TGLUtil::Color4ubv(p->ColorFromValue(i));
437 glVertex2f(x0, 0);
438 glVertex2f(x0, y);
439 x0+=xs;
440 }
441 }
442 TGLUtil::Color4ubv(p->ColorFromValue(p->GetMaxVal()));
443 glVertex2f(length, 0);
444 glVertex2f(length, y);
445 glEnd();
446
ba5a649d 447 glRotatef(-90, 1, 0, 0 );
c87a8d78 448 Double_t v1[3] = {0., 0., 0.};
449 Double_t v2[3] = {length, 0, 0.};
ba5a649d 450 fAxis->SetTextColor(kGray+1);
451 fAxis->SetLineColor(kGray+1);
c87a8d78 452 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 5);
453 glPopAttrib();
454}
455
456//______________________________________________________________________________
457void AliEveITSModuleStepper::RenderMenu(Int_t curP, Int_t maxP, Int_t scaleX, Int_t scaleZ)
458{
459 // Make UI to set page in stepper and UI to scale in the AliEveITSScaledModule.
460
461 TGLUtil::Color(fTextCol);
462 fTextFont.PreRender();
463 glTranslatef(0, fTextSize*0.3, 0);
ba5a649d 464 {
465 // pager
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
470 {
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);
475 }
476 RenderText("4", 3, fSymbolFont); // next page
477 RenderText(":",4, fSymbolFont); // last page
478 }
479 {
480 // scale
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);
486 }
487 {
488 // detectors
489 glTranslatef(fTextSize, 0, 0);
490 RenderText("SPD ", 8, fTextFont);
491 RenderText("SDD ", 9, fTextFont);
492 RenderText("SSD ", 10, fTextFont);
493 fTextFont.PostRender();
494 }
c87a8d78 495}
496
497//______________________________________________________________________________
498void AliEveITSModuleStepper::RenderModuleIDs()
499{
500 // Render module-ids.
501
502 Double_t x, y, z;
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)
508 {
ba5a649d 509 if (idx < fModuleIDs.size())
c87a8d78 510 {
01ff6975 511 AliEveITSScaledModule* mod = static_cast<AliEveITSScaledModule*>(*childit);
c87a8d78 512 TEveTrans& tr = mod->RefMainTrans();
513 tr.GetPos(x,y,z);
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);
522 idx++;
523 }
524 }
525 fModuleFont.PostRender();
526}
527
528/******************************************************************************/
529
530void AliEveITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
531{
532 // Render the overlay elements.
533
01ff6975 534 AliEveITSScaledModule* sm = static_cast<AliEveITSScaledModule*>(*BeginChildren());
9af86b69 535 Int_t scaleIdx = fScaleInfo->GetScale() - 1;
c87a8d78 536 Int_t cnx = 0, cnz = 0;
537 switch(sm->GetSubDetID())
538 {
539 case 0:
9af86b69 540 cnx = fDigitsInfo->fSPDScaleX[scaleIdx];
541 cnz = fDigitsInfo->fSPDScaleZ[scaleIdx];
c87a8d78 542 break;
543 case 1:
9af86b69 544 cnx = fDigitsInfo->fSDDScaleX[scaleIdx];
545 cnz = fDigitsInfo->fSDDScaleZ[scaleIdx];
c87a8d78 546 break;
547 case 2:
9af86b69 548 cnx = fDigitsInfo->fSSDScale[scaleIdx];
549 cnz = 1;
c87a8d78 550 break;
551 }
552
553 // init fonts
ba5a649d 554 if (fTextFont.GetMode() == TGLFont::kUndef)
c87a8d78 555 {
a3d4f532 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);
560#else
75522c26 561 fTextFont = rnrCtx.GetFont(fTextSize, 4, TGLFont::kTexture);
562 fSymbolFont = rnrCtx.GetFont(72, 31, TGLFont::kTexture);
563 fModuleFont = rnrCtx.GetFont(14, 4, TGLFont::kPixmap);
a3d4f532 564#endif
c87a8d78 565 }
566
567 {
568 // toolbar
569 glMatrixMode(GL_PROJECTION);
570 glPushMatrix();
571 glLoadIdentity();
572 if (rnrCtx.Selection())
573 {
574 TGLRect rect(*rnrCtx.GetPickRectangle());
575 rnrCtx.GetCamera()->WindowToViewport(rect);
576 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
01ff6975 577 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
c87a8d78 578 }
579 glMatrixMode(GL_MODELVIEW);
580 glPushMatrix();
581 glLoadIdentity();
582 glTranslatef(-1, -1, 0); // translate to lower left corner
9af86b69 583 Float_t txtScale = fMenuHeight/fTextSize*0.5; // scale text
584 glScalef(txtScale, txtScale, 1.);
c87a8d78 585
586 //menu
587 glPushName(0);
588 RenderMenu(GetCurrentPage(), GetPages(), cnx, cnz);
589 glPopName();
590 //palette
9af86b69 591 Double_t labelSize = 1.6*txtScale*fTextSize;
592 fAxis->SetLabelsSize(labelSize);
593 fAxis->SetLabelsOffset(1.2*labelSize);
c87a8d78 594 RenderPalette(sm->GetPalette());
595
596 glPopMatrix();
597 glMatrixMode(GL_PROJECTION);
598 glPopMatrix();
599 glMatrixMode(GL_MODELVIEW);
600 }
601 RenderModuleIDs();
51346b82 602}