3 #include "ITSModuleStepper.h"
4 #include "ITSDigitsInfo.h"
5 #include "ITSScaledModule.h"
7 #include <TEveManager.h>
8 #include <TEveGedEditor.h>
9 #include <TEveGridStepper.h>
10 #include <TEveGLText.h>
11 #include <TEveTrans.h>
15 #include <TBuffer3D.h>
16 #include <TBuffer3DTypes.h>
17 #include <TVirtualPad.h>
18 #include <TVirtualViewer3D.h>
20 #include <TGLRnrCtx.h>
21 #include <TGLSelectRecord.h>
23 // #include <FTFont.h>
25 #include <TGLViewer.h>
26 using namespace Alieve;
28 //______________________________________________________________________
32 ClassImp(ITSModuleStepper)
34 ITSModuleStepper::ITSModuleStepper(ITSDigitsInfo* di) :
35 TEveElementList("ITS 2DStore", "ITSModuleStepper", kTRUE),
65 // override member from base TEveElementList
66 fChildClass = ITSScaledModule::Class();
68 SetMainColorPtr(&fWCol);
70 fDigitsInfo->IncRefCount();
72 fStepper = new TEveGridStepper();
73 fStepper->SetNs(5, 4);
75 fScaleInfo = new DigitScaleInfo();
76 fScaleInfo->IncRefCount();
78 fAxis = new TGLAxis();
79 fAxis->SetLineColor(4);
80 fAxis->SetTextColor(fFontCol);
82 fText = new TGLText();
83 fText->SetTextColor(fFontCol);
84 fText->SetGLTextFont(40);
85 fText->SetGLTextAngles(0, 0, 0);
86 fText->SetTextSize(fTextSize);
88 gEve->GetGLViewer()->AddOverlayElement(this);
91 ITSModuleStepper::~ITSModuleStepper()
93 gEve->GetGLViewer()->RemoveOverlayElement(this);
95 fScaleInfo->DecRefCount();
96 fDigitsInfo->DecRefCount();
104 /**************************************************************************/
106 void ITSModuleStepper::Capacity()
108 Int_t N = fStepper->GetNx()*fStepper->GetNy();
109 if (N != GetNChildren())
112 for (Int_t m=0; m<N; m++)
114 AddElement(new ITSScaledModule(m, fDigitsInfo, fScaleInfo));
119 /**************************************************************************/
121 void ITSModuleStepper::SetFirst(Int_t first)
123 Int_t lastpage = fIDs.size()/Nxy();
124 if(fIDs.size() % Nxy() ) lastpage++;
126 Int_t first_lastpage = (lastpage -1)*Nxy();
127 if(first > first_lastpage) first = first_lastpage;
128 if(first < 0) first = 0;
133 void ITSModuleStepper::Start()
139 void ITSModuleStepper::Next()
141 SetFirst(fPosition + Nxy());
144 void ITSModuleStepper::Previous()
146 // move to the top left corner first
147 SetFirst(fPosition - Nxy());
150 void ITSModuleStepper::End()
152 Int_t lastpage = fIDs.size()/Nxy();
153 if(fIDs.size() % Nxy() ) lastpage++;
154 fPosition = (lastpage -1)*Nxy();
160 /**************************************************************************/
162 void ITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
166 ITSModuleSelection sel = ITSModuleSelection();
167 sel.fType = det; sel.fLayer=layer;
168 fDigitsInfo->GetModuleIDs(&sel, fIDs);
169 //in reder menu define a space between left and right pager
170 fPagerGap = 1.2*TextLength(Form("%d/%d",GetPages(), GetPages()));
174 /**************************************************************************/
176 void ITSModuleStepper::DisplayTheta(Float_t min, Float_t max)
179 ITSModuleSelection sel = ITSModuleSelection();
180 sel.fMaxTheta = max; sel.fMinTheta=min;
181 fDigitsInfo->GetModuleIDs(&sel, fIDs);
185 /**************************************************************************/
187 Int_t ITSModuleStepper::GetCurrentPage()
189 Int_t idx = fPosition +1;
195 /**************************************************************************/
197 Int_t ITSModuleStepper::GetPages()
199 Int_t n = fIDs.size()/Nxy();
200 if(fIDs.size() % Nxy()) n++;
204 /**************************************************************************/
206 void ITSModuleStepper::Apply()
208 // printf("ITSModuleStepper::Apply fPosition %d \n", fPosition);
209 gEve->DisableRedraw();
212 UInt_t idx = fPosition;
213 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
215 if(idx < fIDs.size())
217 ITSScaledModule* mod = dynamic_cast<ITSScaledModule*>(*childit);
218 mod->SetID(fIDs[idx], kFALSE);
219 TEveTrans& tr = mod->RefHMTrans();
221 tr.RotateLF(3,2,TMath::PiOver2());
222 tr.RotateLF(1,3,TMath::PiOver2());
226 Float_t* fp = mod->GetFrame()->GetFramePoints();
227 // switch x,z it will be rotated afterwards
232 Double_t sx = fStepper->GetDx();
233 Double_t sy = (mx*fStepper->GetDx())/mz;
234 if(sy > fStepper->GetDy())
236 // printf("fit width \n");
237 sy = fStepper->GetDy();
238 sx = (mz*fStepper->GetDx())/mx;
240 Float_t scale = (fExpandCell*sx)/mz;
241 tr.Scale(scale, scale, scale);
244 fStepper->GetPosition(p);
245 tr.SetPos(p[0]+0.5*fStepper->GetDx(), p[1]+0.5*fStepper->GetDy(), p[2]+0.5*fStepper->GetDz());
247 if(mod->GetSubDetID() == 2)
248 mod->SetName(Form("SSD %d", idx));
249 else if(mod->GetSubDetID() == 1)
250 mod->SetName(Form("SDD %d", idx));
252 mod->SetName(Form("SPD %d", idx));
253 mod->SetRnrSelf(kTRUE);
260 (*childit)->SetRnrSelf(kFALSE);
266 gEve->EnableRedraw();
269 /**************************************************************************/
271 void ITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
273 // render everyting in relative coordinates
274 glMatrixMode(GL_PROJECTION);
277 if (rnrCtx.Selection())
280 // glLoadMatrix(rnrCtx.GetCamera()->GetProjMBase());
281 TGLRect rect(*rnrCtx.GetPickRectangle());
282 rnrCtx.GetCamera()->WindowToViewport(rect);
283 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
284 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
287 glMatrixMode(GL_MODELVIEW);
292 glGetBooleanv(GL_LIGHTING, &lightp);
293 if (lightp) glDisable(GL_LIGHTING);
295 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
296 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
297 glDisable(GL_CULL_FACE);
299 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
301 RenderPalette(fPaletteLength, 1.6*fWWidth, fWHeight*0.6);
305 if (lightp) glEnable(GL_LIGHTING);
307 glMatrixMode(GL_PROJECTION);
310 glMatrixMode(GL_MODELVIEW);
315 /**************************************************************************/
316 // Protected sub-renderers
317 /**************************************************************************/
319 //______________________________________________________________________
320 Float_t ITSModuleStepper::TextLength(const char* txt)
322 Float_t llx, lly, llz, urx, ury, urz;
323 fText->BBox(txt, llx, lly, llz, urx, ury, urz);
324 return (urx-llx)*fTextSize;
327 //______________________________________________________________________
328 void ITSModuleStepper::RenderString(TString string, Int_t id)
330 Float_t txtY = fWHeight*0.5;
331 Float_t txtl = TextLength(string.Data());
333 if(id > 0) glLoadName(id);
334 if(id>0 && fWActive == id)
335 fText->SetTextColor(fWActiveCol);
337 fText->SetTextColor(fFontCol);
343 fText->SetTextColor(fWActiveCol);
345 fText->SetTextColor(fFontCol);
348 Float_t ss = fWWidth*0.4;
349 fText->PaintGLText(ss, txtY, -0.8, string.Data());
351 Float_t bw =2*ss+txtl;
352 RenderFrame(bw,fWHeight*2,id);
353 glTranslatef( bw, 0, 0);
357 fText->SetTextColor(fFontCol);
358 fText->PaintGLText(0, txtY, -0.8, string.Data());
359 glTranslatef(txtl, 0, 0);
363 //______________________________________________________________________
364 void ITSModuleStepper::RenderFrame(Float_t dx, Float_t dy, Int_t id)
366 if(fRnrFrame == kFALSE)return;
368 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
369 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
372 TEveUtil::ColorFromIdx(fWActiveCol, color);
374 TEveUtil:: ColorFromIdx(fWCol, color);
378 glVertex2f(0, 0); glVertex2f(dx, 0);
379 glVertex2f(dx, dy); glVertex2f(0, dy);
384 //______________________________________________________________________
385 void ITSModuleStepper::RenderSymbol(Float_t dx, Float_t dy, Int_t id)
391 TEveUtil::ColorFromIdx(fWActiveCol, color);
393 TEveUtil::ColorFromIdx(fWCol, color);
396 Float_t xs = dx/4, ys = dy/4;
399 glVertex2f(0,ys); glVertex2f(0, ys*3);
400 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
405 glBegin(GL_TRIANGLES);
410 // glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
411 glVertex2f(xs*3, ys*3); glVertex2f(xs*1, ys*2); glVertex2f(xs*3, ys);
417 glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
418 glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
424 //glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
425 glVertex2f(xs*1, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*1, ys*3);
431 glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
432 glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
438 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
444 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
455 //______________________________________________________________________
456 void ITSModuleStepper::RenderPalette(Float_t dx, Float_t x, Float_t y)
460 glTranslatef(1 -x- dx, -1+y*4, 0);
461 ITSModule* qs = dynamic_cast<ITSModule*>(*BeginChildren());
462 TEveRGBAPalette* p = qs->GetPalette();
463 glBegin(GL_QUAD_STRIP);
464 glColor4ubv(p->ColorFromValue(p->GetMinVal()));
467 if (p->GetMaxVal() > p->GetMinVal() + 1)
469 Float_t xs = dx/(p->GetMaxVal() - p->GetMinVal());
471 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
473 glColor4ubv(p->ColorFromValue(i));
479 glColor4ubv(p->ColorFromValue(p->GetMaxVal()));
484 if (p->GetMaxVal() > p->GetMinVal())
486 glRotatef(-90,1, 0, 0 );
487 Double_t v1[3] = {0., 0., 0.};
488 Double_t v2[3] = {dx, 0, 0.};
489 fAxis->SetLabelsSize(fTextSize/dx);
490 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 206);
495 //______________________________________________________________________
496 void ITSModuleStepper::RenderMenu()
498 Float_t ww = 2*fWWidth;
499 Float_t wh = 2*fWHeight;
503 glColor4f(a, a, a, a);
504 Float_t H = 1.9*wh*(1+ 2*fWOff);
507 glVertex3f(-1, -1, 0.1); glVertex3f(-1, -1+H, 0.1);
508 glVertex3f(1 , -1+H, 0.1); glVertex3f( 1, -1 , 0.1);
512 Float_t y_base = -1 + wh*0.35;
513 glTranslatef(-1, y_base, 0.);
517 glTranslatef(ww, 0, 0.);
518 fText->SetTextSize(fTextSize);
519 Float_t soff = ww*1.3;
520 glTranslatef(0, fWOff*wh, 0);
521 RenderSymbol(ww, wh, 2);
522 RenderFrame(ww,wh,2);
523 glTranslatef(soff, 0, 0);
524 RenderSymbol(ww, wh, 1);
525 RenderFrame(ww,wh,1);
526 glTranslatef(soff, 0, 0);
529 const char* txt = Form("%d/%d ", GetCurrentPage(), GetPages());
530 Float_t dx = (fPagerGap - TextLength(txt))*0.5;
531 fText->SetTextColor(fFontCol);
532 fText->PaintGLText(dx, wh*0.25, -0.8, txt);
534 glTranslatef(fPagerGap, 0, 0);
536 RenderSymbol(ww, wh, 3);
537 RenderFrame(ww,wh,3);
538 glTranslatef(soff, 0, 0);
539 RenderSymbol(ww, wh, 4);
540 RenderFrame(ww,wh,4);
541 glTranslatef(2*ww, 0, 0);
546 ITSDigitsInfo* di = fDigitsInfo;
547 Int_t scale = fScaleInfo->GetScale() - 1;
548 ITSScaledModule* sm = dynamic_cast<ITSScaledModule*>(*BeginChildren());
549 Int_t cnx = 0, cnz = 0;
550 switch(sm->GetSubDetID())
553 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
556 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
559 cnx = di->fSSDScale[scale], cnz = 1;
562 glTranslatef(10*ww,0, 0);
563 RenderString(Form("Zoom: "));
565 glTranslatef(0, 0.2*wh, 0);
566 RenderSymbol(ww, wh*0.9, 5);
567 glTranslatef(0, 0.4*wh, 0);
568 RenderFrame(ww, wh*0.5, 5);
570 RenderSymbol(ww, wh*0.9, 6);
571 RenderFrame(ww, wh*0.5, 6);
572 glTranslatef(ww, 0, 0);
573 RenderString(Form("%dx%d ", cnx, cnz));
578 glTranslatef(18*ww, 0, 0);
580 RenderString("SPD", 8);
581 glTranslatef(bs, 0, 0);
582 RenderString("SDD", 9);
583 glTranslatef(bs, 0, 0);
584 RenderString("SSD", 10);
590 //______________________________________________________________________
591 void ITSModuleStepper::RenderCellIDs()
593 fText->SetTextSize(fStepper->GetDy()*0.1);
594 fText->SetTextColor(fFontCol);
597 UInt_t idx = fPosition;
598 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
600 if(idx < fIDs.size())
602 ITSScaledModule* mod = dynamic_cast<ITSScaledModule*>(*childit);
603 TEveTrans& tr = mod->RefHMTrans();
604 TString name = Form("%d",mod->GetID());
606 x += fStepper->GetDx()*0.5;
607 y -= fStepper->GetDy()*0.5;
608 z += 0.4; // !!! MT hack - cross check with overlay rendering.
609 Float_t llx, lly, llz, urx, ury, urz;
610 fText->BBox(name, llx, lly, llz, urx, ury, urz);
611 tr.GetScale(sx, sy, sz);
612 fText->PaintGLText(x-(urx-llx)*sx, y, z, name);
619 /**************************************************************************/
620 // Virtual event handlers from TGLOverlayElement
621 /**************************************************************************/
623 //______________________________________________________________________
624 Bool_t ITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
625 TGLOvlSelectRecord & rec,
628 // Handle overlay event.
629 // Return TRUE if event was handled.
631 switch (event->fType)
635 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
636 if (fWActive != item) {
646 if (event->fCode != kButton1) {
649 switch (rec.GetItem(1))
665 DigitScaleInfo* si = fScaleInfo;
666 if(si->GetScale() < 5)
668 si->ScaleChanged(si->GetScale() + 1);
669 ElementChanged(kTRUE, kTRUE);
675 DigitScaleInfo* si = fScaleInfo;
676 if(si->GetScale() > 1)
678 si->ScaleChanged(si->GetScale() - 1);
679 ElementChanged(kTRUE, kTRUE);
684 gEve->GetEditor()->DisplayElement(*BeginChildren());
708 //______________________________________________________________________
709 Bool_t ITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
714 //______________________________________________________________________
715 void ITSModuleStepper::MouseLeave()
717 // Mouse has left the element.