3 #include "ITSModuleStepper.h"
4 #include "ITSDigitsInfo.h"
5 #include "ITSScaledModule.h"
7 #include "Reve/ReveManager.h"
8 #include "Reve/RGEditor.h"
9 #include "Reve/GridStepper.h"
10 #include "Reve/GLTextNS.h"
11 #include "Reve/ZTrans.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>
28 using namespace Alieve;
30 //______________________________________________________________________
34 ClassImp(ITSModuleStepper)
36 ITSModuleStepper::ITSModuleStepper(ITSDigitsInfo* di) :
37 RenderElementList("ITS 2DStore", "ITSModuleStepper", kTRUE),
67 // override member from base RenderElementList
68 fChildClass = ITSScaledModule::Class();
70 SetMainColorPtr(&fWCol);
72 fDigitsInfo->IncRefCount();
74 fStepper = new GridStepper();
75 fStepper->SetNs(5, 4);
77 fScaleInfo = new DigitScaleInfo();
78 fScaleInfo->IncRefCount();
80 fAxis = new TGLAxis();
81 fAxis->SetLineColor(4);
82 fAxis->SetTextColor(fFontCol);
84 fText = new TGLText();
85 fText->SetTextColor(fFontCol);
86 fText->SetGLTextFont(40);
87 fText->SetGLTextAngles(0, 0, 0);
88 fText->SetTextSize(fTextSize);
90 gReve->GetGLViewer()->AddOverlayElement(this);
93 ITSModuleStepper::~ITSModuleStepper()
95 gReve->GetGLViewer()->RemoveOverlayElement(this);
97 fScaleInfo->DecRefCount();
98 fDigitsInfo->DecRefCount();
106 /**************************************************************************/
108 void ITSModuleStepper::Capacity()
110 Int_t N = fStepper->Nx*fStepper->Ny;
111 if(N != GetNChildren())
114 for(Int_t m=0; m<N; m++)
116 AddElement(new ITSScaledModule(m, fDigitsInfo, fScaleInfo));
121 /**************************************************************************/
123 void ITSModuleStepper::SetFirst(Int_t first)
125 Int_t lastpage = fIDs.size()/Nxy();
126 if(fIDs.size() % Nxy() ) lastpage++;
128 Int_t first_lastpage = (lastpage -1)*Nxy();
129 if(first > first_lastpage) first = first_lastpage;
130 if(first < 0) first = 0;
135 void ITSModuleStepper::Start()
141 void ITSModuleStepper::Next()
143 SetFirst(fPosition + Nxy());
146 void ITSModuleStepper::Previous()
148 // move to the top left corner first
149 SetFirst(fPosition - Nxy());
152 void ITSModuleStepper::End()
154 Int_t lastpage = fIDs.size()/Nxy();
155 if(fIDs.size() % Nxy() ) lastpage++;
156 fPosition = (lastpage -1)*Nxy();
162 /**************************************************************************/
164 void ITSModuleStepper::DisplayDet(Int_t det, Int_t layer)
168 ITSModuleSelection sel = ITSModuleSelection();
169 sel.fType = det; sel.fLayer=layer;
170 fDigitsInfo->GetModuleIDs(&sel, fIDs);
171 //in reder menu define a space between left and right pager
172 fPagerGap = 1.2*TextLength(Form("%d/%d",GetPages(), GetPages()));
176 /**************************************************************************/
178 void ITSModuleStepper::DisplayTheta(Float_t min, Float_t max)
181 ITSModuleSelection sel = ITSModuleSelection();
182 sel.fMaxTheta = max; sel.fMinTheta=min;
183 fDigitsInfo->GetModuleIDs(&sel, fIDs);
187 /**************************************************************************/
189 Int_t ITSModuleStepper::GetCurrentPage()
191 Int_t idx = fPosition +1;
197 /**************************************************************************/
199 Int_t ITSModuleStepper::GetPages()
201 Int_t n = fIDs.size()/Nxy();
202 if(fIDs.size() % Nxy()) n++;
206 /**************************************************************************/
208 void ITSModuleStepper::Apply()
210 // printf("ITSModuleStepper::Apply fPosition %d \n", fPosition);
211 gReve->DisableRedraw();
214 UInt_t idx = fPosition;
215 for(List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
217 if(idx < fIDs.size())
219 ITSScaledModule* mod = dynamic_cast<ITSScaledModule*>(*childit);
220 mod->SetID(fIDs[idx], kFALSE);
221 ZTrans& tr = mod->RefHMTrans();
223 tr.RotateLF(3,2,TMath::PiOver2());
224 tr.RotateLF(1,3,TMath::PiOver2());
228 Float_t* fp = mod->GetFrame()->GetFramePoints();
229 // switch x,z it will be rotated afterwards
234 Double_t sx = fStepper->Dx;
235 Double_t sy = (mx*fStepper->Dx)/mz;
236 if(sy > fStepper->Dy)
238 // printf("fit width \n");
240 sx = (mz*fStepper->Dx)/mx;
242 Float_t scale = (fExpandCell*sx)/mz;
243 tr.Scale(scale, scale, scale);
246 fStepper->GetPosition(p);
247 tr.SetPos(p[0]+0.5*fStepper->Dx, p[1]+0.5*fStepper->Dy, p[2]+0.5*fStepper->Dz);
249 if(mod->GetSubDetID() == 2)
250 mod->SetName(Form("SSD %d", idx));
251 else if(mod->GetSubDetID() == 1)
252 mod->SetName(Form("SDD %d", idx));
254 mod->SetName(Form("SPD %d", idx));
255 mod->SetRnrSelf(kTRUE);
262 (*childit)->SetRnrSelf(kFALSE);
268 gReve->EnableRedraw();
271 /**************************************************************************/
273 void ITSModuleStepper::Render(TGLRnrCtx& rnrCtx)
275 // render everyting in relative coordinates
276 glMatrixMode(GL_PROJECTION);
279 if (rnrCtx.Selection())
282 // glLoadMatrix(rnrCtx.GetCamera()->GetProjMBase());
283 TGLRect rect(*rnrCtx.GetPickRectangle());
284 rnrCtx.GetCamera()->WindowToViewport(rect);
285 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
286 (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
289 glMatrixMode(GL_MODELVIEW);
294 glGetBooleanv(GL_LIGHTING, &lightp);
295 if (lightp) glDisable(GL_LIGHTING);
297 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
298 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
299 glDisable(GL_CULL_FACE);
301 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
303 RenderPalette(fPaletteLength, 1.6*fWWidth, fWHeight*0.6);
307 if (lightp) glEnable(GL_LIGHTING);
309 glMatrixMode(GL_PROJECTION);
312 glMatrixMode(GL_MODELVIEW);
317 /**************************************************************************/
318 // Protected sub-renderers
319 /**************************************************************************/
321 //______________________________________________________________________
322 Float_t ITSModuleStepper::TextLength(const char* txt)
324 Float_t llx, lly, llz, urx, ury, urz;
325 fText->BBox(txt, llx, lly, llz, urx, ury, urz);
326 return (urx-llx)*fTextSize;
329 //______________________________________________________________________
330 void ITSModuleStepper::RenderString(TString string, Int_t id)
332 Float_t txtY = fWHeight*0.5;
333 Float_t txtl = TextLength(string.Data());
335 if(id > 0) glLoadName(id);
336 if(id>0 && fWActive == id)
337 fText->SetTextColor(fWActiveCol);
339 fText->SetTextColor(fFontCol);
345 fText->SetTextColor(fWActiveCol);
347 fText->SetTextColor(fFontCol);
350 Float_t ss = fWWidth*0.4;
351 fText->PaintGLText(ss, txtY, -0.8, string.Data());
353 Float_t bw =2*ss+txtl;
354 RenderFrame(bw,fWHeight*2,id);
355 glTranslatef( bw, 0, 0);
359 fText->SetTextColor(fFontCol);
360 fText->PaintGLText(0, txtY, -0.8, string.Data());
361 glTranslatef(txtl, 0, 0);
365 //______________________________________________________________________
366 void ITSModuleStepper::RenderFrame(Float_t dx, Float_t dy, Int_t id)
368 if(fRnrFrame == kFALSE)return;
370 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
371 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
374 ColorFromIdx(fWActiveCol, color);
376 ColorFromIdx(fWCol, color);
380 glVertex2f(0, 0); glVertex2f(dx, 0);
381 glVertex2f(dx, dy); glVertex2f(0, dy);
386 //______________________________________________________________________
387 void ITSModuleStepper::RenderSymbol(Float_t dx, Float_t dy, Int_t id)
393 ColorFromIdx(fWActiveCol, color);
395 ColorFromIdx(fWCol, color);
398 Float_t xs = dx/4, ys = dy/4;
401 glVertex2f(0,ys); glVertex2f(0, ys*3);
402 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
407 glBegin(GL_TRIANGLES);
412 // glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
413 glVertex2f(xs*3, ys*3); glVertex2f(xs*1, ys*2); glVertex2f(xs*3, ys);
419 glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
420 glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
426 //glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
427 glVertex2f(xs*1, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*1, ys*3);
433 glVertex2f(xs, ys); glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
434 glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
440 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
446 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
457 //______________________________________________________________________
458 void ITSModuleStepper::RenderPalette(Float_t dx, Float_t x, Float_t y)
462 glTranslatef(1 -x- dx, -1+y*4, 0);
463 ITSModule* qs = dynamic_cast<ITSModule*>(*BeginChildren());
464 RGBAPalette* p = qs->GetPalette();
465 glBegin(GL_QUAD_STRIP);
466 glColor4ubv(p->ColorFromValue(p->GetMinVal()));
469 if (p->GetMaxVal() > p->GetMinVal() + 1)
471 Float_t xs = dx/(p->GetMaxVal() - p->GetMinVal());
473 for(Int_t i=p->GetMinVal() + 1; i<p->GetMaxVal(); i++)
475 glColor4ubv(p->ColorFromValue(i));
481 glColor4ubv(p->ColorFromValue(p->GetMaxVal()));
486 if (p->GetMaxVal() > p->GetMinVal())
488 glRotatef(-90,1, 0, 0 );
489 Double_t v1[3] = {0., 0., 0.};
490 Double_t v2[3] = {dx, 0, 0.};
491 fAxis->SetLabelsSize(fTextSize/dx);
492 fAxis->PaintGLAxis(v1, v2, p->GetMinVal(), p->GetMaxVal(), 206);
497 //______________________________________________________________________
498 void ITSModuleStepper::RenderMenu()
500 Float_t ww = 2*fWWidth;
501 Float_t wh = 2*fWHeight;
505 glColor4f(a, a, a, a);
506 Float_t H = 1.9*wh*(1+ 2*fWOff);
509 glVertex3f(-1, -1, 0.1); glVertex3f(-1, -1+H, 0.1);
510 glVertex3f(1 , -1+H, 0.1); glVertex3f( 1, -1 , 0.1);
514 Float_t y_base = -1 + wh*0.35;
515 glTranslatef(-1, y_base, 0.);
519 glTranslatef(ww, 0, 0.);
520 fText->SetTextSize(fTextSize);
521 Float_t soff = ww*1.3;
522 glTranslatef(0, fWOff*wh, 0);
523 RenderSymbol(ww, wh, 2);
524 RenderFrame(ww,wh,2);
525 glTranslatef(soff, 0, 0);
526 RenderSymbol(ww, wh, 1);
527 RenderFrame(ww,wh,1);
528 glTranslatef(soff, 0, 0);
531 const char* txt = Form("%d/%d ", GetCurrentPage(), GetPages());
532 Float_t dx = (fPagerGap - TextLength(txt))*0.5;
533 fText->SetTextColor(fFontCol);
534 fText->PaintGLText(dx, wh*0.25, -0.8, txt);
536 glTranslatef(fPagerGap, 0, 0);
538 RenderSymbol(ww, wh, 3);
539 RenderFrame(ww,wh,3);
540 glTranslatef(soff, 0, 0);
541 RenderSymbol(ww, wh, 4);
542 RenderFrame(ww,wh,4);
543 glTranslatef(2*ww, 0, 0);
548 ITSDigitsInfo* di = fDigitsInfo;
549 Int_t scale = fScaleInfo->GetScale() - 1;
550 ITSScaledModule* sm = dynamic_cast<ITSScaledModule*>(*BeginChildren());
551 Int_t cnx = 0, cnz = 0;
552 switch(sm->GetSubDetID())
555 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
558 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
561 cnx = di->fSSDScale[scale], cnz = 1;
564 glTranslatef(10*ww,0, 0);
565 RenderString(Form("Zoom: "));
567 glTranslatef(0, 0.2*wh, 0);
568 RenderSymbol(ww, wh*0.9, 5);
569 glTranslatef(0, 0.4*wh, 0);
570 RenderFrame(ww, wh*0.5, 5);
572 RenderSymbol(ww, wh*0.9, 6);
573 RenderFrame(ww, wh*0.5, 6);
574 glTranslatef(ww, 0, 0);
575 RenderString(Form("%dx%d ", cnx, cnz));
580 glTranslatef(18*ww, 0, 0);
582 RenderString("SPD", 8);
583 glTranslatef(bs, 0, 0);
584 RenderString("SDD", 9);
585 glTranslatef(bs, 0, 0);
586 RenderString("SSD", 10);
592 //______________________________________________________________________
593 void ITSModuleStepper::RenderCellIDs()
595 fText->SetTextSize(fStepper->Dy*0.1);
596 fText->SetTextColor(fFontCol);
599 UInt_t idx = fPosition;
600 for (List_i childit=fChildren.begin(); childit!=fChildren.end(); ++childit)
602 if(idx < fIDs.size())
604 ITSScaledModule* mod = dynamic_cast<ITSScaledModule*>(*childit);
605 ZTrans& tr = mod->RefHMTrans();
606 TString name = Form("%d",mod->GetID());
608 x += fStepper->Dx*0.5;
609 y -= fStepper->Dy*0.5;
610 z += 0.4; // !!! MT hack - cross check with overlay rendering.
611 Float_t llx, lly, llz, urx, ury, urz;
612 fText->BBox(name, llx, lly, llz, urx, ury, urz);
613 tr.GetScale(sx, sy, sz);
614 fText->PaintGLText(x-(urx-llx)*sx, y, z, name);
621 /**************************************************************************/
622 // Virtual event handlers from TGLOverlayElement
623 /**************************************************************************/
625 //______________________________________________________________________
626 Bool_t ITSModuleStepper::Handle(TGLRnrCtx & /*rnrCtx*/,
627 TGLOvlSelectRecord & rec,
630 // Handle overlay event.
631 // Return TRUE if event was handled.
633 switch (event->fType)
637 Int_t item = rec.GetN() < 2 ? -1 : (Int_t)rec.GetItem(1);
638 if (fWActive != item) {
648 if (event->fCode != kButton1) {
651 switch (rec.GetItem(1))
667 DigitScaleInfo* si = fScaleInfo;
668 if(si->GetScale() < 5)
670 si->ScaleChanged(si->GetScale() + 1);
671 ElementChanged(kTRUE, kTRUE);
677 DigitScaleInfo* si = fScaleInfo;
678 if(si->GetScale() > 1)
680 si->ScaleChanged(si->GetScale() - 1);
681 ElementChanged(kTRUE, kTRUE);
686 gReve->GetEditor()->DisplayRenderElement(*BeginChildren());
710 //______________________________________________________________________
711 Bool_t ITSModuleStepper::MouseEnter(TGLOvlSelectRecord& /*rec*/)
716 //______________________________________________________________________
717 void ITSModuleStepper::MouseLeave()
719 // Mouse has left the element.