]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/ITSModuleStepperGL.cxx
fixed typo in ESDListNames
[u/mrichter/AliRoot.git] / EVE / Alieve / ITSModuleStepperGL.cxx
1 // $Header$
2
3 #include "ITSModuleStepperGL.h"
4
5 #include <Reve/GLTextNS.h>
6 #include <Reve/GLUtilNS.h>
7 #include <Reve/RGTopFrame.h>
8 #include <Reve/RGEditor.h>
9 #include <Reve/RGBAPalette.h>
10
11 #include <Alieve/ITSModuleStepper.h>
12 #include <Alieve/ITSScaledModule.h>
13
14 #include <TGLRnrCtx.h>
15 #include <TGLSelectRecord.h>
16
17 using namespace Reve;
18 using namespace Alieve;
19
20 //______________________________________________________________________
21 // ITSModuleStepperGL
22 //
23
24 ClassImp(ITSModuleStepperGL)
25
26 ITSModuleStepperGL::ITSModuleStepperGL() : TGLObject(), fM(0)
27 {
28   fDLCache = false; // Disable display list.
29 }
30
31 ITSModuleStepperGL::~ITSModuleStepperGL()
32 {}
33
34 /**************************************************************************/
35
36 Bool_t ITSModuleStepperGL::SetModel(TObject* obj, const Option_t* /*opt*/)
37 {
38   if(SetModelCheckClass(obj, ITSModuleStepper::Class())) {
39     fM = dynamic_cast<ITSModuleStepper*>(obj);
40     return kTRUE;
41   }
42   return kFALSE;
43 }
44
45 void ITSModuleStepperGL::SetBBox()
46 {
47   // !! This ok if master sub-classed from TAttBBox
48   SetAxisAlignedBBox(fM->AssertBBox());
49 }
50
51 /**************************************************************************/
52
53 void ITSModuleStepperGL::DirectDraw(TGLRnrCtx & rnrCtx) const
54 {
55   // printf("ITSModuleStepperGL::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD()); 
56
57   ITSModuleStepper& MS = *fM;
58   Int_t W = Int_t(MS.fStepper->Dx*MS.fStepper->Nx);
59   Int_t H = Int_t(MS.fStepper->Dy*MS.fStepper->Ny);
60   Float_t dx = W*MS.fWWidth;
61   Float_t dy = 6; // H*MS.fWHeight;
62
63   GLboolean lightp;
64   glGetBooleanv(GL_LIGHTING, &lightp);
65   if (lightp) glDisable(GL_LIGHTING);
66    
67   UChar_t color[4];
68   ColorFromIdx(MS.fWColor, color);
69   glColor4ubv(color);
70
71   // render frame of grid stepper
72   if (MS.fRnrFrame)
73   {
74     glBegin(GL_LINE_LOOP);
75     glVertex2f(-1,  -1);       
76     glVertex2f(W+1, -1);
77     glVertex2f(W+1,  H+1);
78     glVertex2f(-1 ,  H+1);
79     glEnd();
80   }
81
82   // triangles
83   glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
84   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
85   glDisable(GL_CULL_FACE);
86   glEnable(GL_BLEND);
87   glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
88     
89   Float_t sx =0 ,sy = 0;
90   switch(MS.fWCorner) {
91     case ITSModuleStepper::PT_BottomLeft:
92       sy = -dy;
93       break;
94     case ITSModuleStepper::PT_BottomRight:
95       sy = -dy;
96       break;
97     case ITSModuleStepper::PT_TopLeft:
98       sy = H;
99       break;
100     case ITSModuleStepper::PT_TopRight:
101       sy = H;
102       break;
103     default:
104       sy = dy;
105       break;
106   }
107   
108   if (rnrCtx.SecSelection()) glPushName(0);
109   glPushMatrix();
110   glTranslatef(sx, sy, 0.);
111
112   // pager
113   if (rnrCtx.SecSelection()) glLoadName(2);
114   RenderSymbol(dx, dy, 2);
115   glTranslatef(dx, 0, 0);
116   if (rnrCtx.SecSelection()) glLoadName(1);
117   RenderSymbol(dx*1.2, dy, 1);
118   glTranslatef(dx, 0, 0);
119   RenderString(Form(" %d/%d ", MS.GetCurrentPage(), MS.GetPages()), dy);
120   if (rnrCtx.SecSelection()) glLoadName(3);
121   RenderSymbol(dx*1.2, dy, 3);
122   glTranslatef(dx, 0, 0);
123   if (rnrCtx.SecSelection()) glLoadName(4);
124   RenderSymbol(dx, dy, 4);
125   glTranslatef(2*dx, 0, 0);
126   
127   // scale info
128   Int_t cnx = 0, cnz = 0;
129   ITSDigitsInfo* di = MS.fDigitsInfo;
130   Int_t scale = fM->fScaleInfo->GetScale() - 1;
131   ITSScaledModule* sm = dynamic_cast<ITSScaledModule*>(*fM->BeginChildren());
132   switch(sm->GetSubDetID())
133   {
134     case 0: 
135       cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
136       break;
137     case 1: 
138       cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
139       break;
140     case 2:
141       cnx = di->fSSDScale[scale], cnz = 1;
142       break;
143   }
144   if (rnrCtx.SecSelection()) glLoadName(0);
145   RenderString(Form("Scale"), dy);
146   glTranslatef(0.07*dx, 0, 0);
147   // up down arrows 
148   if (rnrCtx.SecSelection()) glLoadName(6);
149   RenderSymbol(dx*1.2, dy*0.9, 5);
150
151   if (rnrCtx.SecSelection()) glLoadName(7);
152   RenderSymbol(dx*1.2, dy*0.9, 6);
153
154   glTranslatef(1*dx, 0, 0);
155   if (rnrCtx.SecSelection()) glLoadName(0);
156   RenderString(Form(" %dx%d ", cnx, cnz), dy, kFALSE);
157
158   glPopMatrix();
159   if (rnrCtx.SecSelection()) glLoadName(5);
160   glPushMatrix();
161   glTranslatef(W+2, 0, 0);
162   RenderPalette(H, 4);
163   glPopMatrix();
164
165   if (rnrCtx.SecSelection()) glPopName();
166
167   glPopAttrib();
168
169   if (lightp) glEnable(GL_LIGHTING);
170 }
171
172 /**************************************************************************/
173
174 void ITSModuleStepperGL::RenderPalette(Float_t dx, Float_t dy) const
175 {
176   ITSModule* qs = dynamic_cast<ITSModule*>(*fM->BeginChildren());
177   RGBAPalette* p = qs->GetPalette();
178   Float_t xs = dx/(p->GetMaxVal()- p->GetMinVal());
179   Float_t ys = dy;
180
181   Float_t x  = 0;
182   glBegin(GL_QUAD_STRIP);
183   for(Int_t i=p->GetMinVal(); i<=p->GetMaxVal(); i++) 
184   {
185     glColor4ubv(p->ColorFromValue(i + p->GetMinVal()));
186     glVertex2f(0,  x);
187     glVertex2f(ys, x);
188     x+=xs;
189   }
190   glEnd();
191 }
192
193 /**************************************************************************/
194
195 void ITSModuleStepperGL::RenderSymbol(Float_t dx, Float_t dy, Int_t id) const
196 {
197   Float_t xs = dx/4, ys = dy/4;
198
199   if(id == 0) {
200     glBegin(GL_QUADS);
201     glVertex2f(0,ys); glVertex2f(0, ys*3); 
202     glVertex2f(dx, ys*3); glVertex2f(dx, ys);
203     glEnd();
204     return;
205   }
206   
207
208   glBegin(GL_TRIANGLES);
209   switch (id) {
210     case 1:
211     {
212       glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
213       break;
214     }
215     case 2:
216     {
217       glVertex2f(xs*2, ys*3); glVertex2f(xs, ys*2); glVertex2f(xs*2, ys);
218       glVertex2f(xs*3, ys*3); glVertex2f(xs*2, ys*2); glVertex2f(xs*3, ys);
219       break;
220     }
221     case 3:
222     {
223       glVertex2f(xs*1.5, ys);  glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
224       break;
225     }
226     case 4:
227     {
228       glVertex2f(xs, ys);  glVertex2f(xs*2, ys*2); glVertex2f(xs, ys*3);
229       glVertex2f(xs*2, ys); glVertex2f(xs*3, ys*2); glVertex2f(xs*2, ys*3);
230       break;
231     }
232     case 5:
233     {
234       glVertex2f(xs, ys*2.5);  glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
235       break;
236     }
237     case 6:
238     {
239       glVertex2f(xs, ys*1.5);  glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
240       break;
241     }
242    
243     default:
244       break;
245   }
246   glEnd();
247 }
248
249 /**************************************************************************/
250 void ITSModuleStepperGL::RenderString(TString info, Float_t dy, Bool_t trans) const
251 {
252   Float_t movex = 0; 
253   
254   GLUtilNS::GL_Capability_Switch texure_on(GL_TEXTURE_2D, true);
255   GLTextNS::txfBindFontTexture(GLTextNS::fgDefaultFont);
256
257   glPushMatrix();
258   glTranslatef(0, dy*0.25, 0);
259   Float_t s = (dy)/ (GLTextNS::fgDefaultFont->max_height());
260   Float_t sx = s*0.75; Float_t sy = s*0.8;
261   glScalef(sx, sy, 1);
262   txfRenderString(GLTextNS::fgDefaultFont, info.Data(), info.Length());
263   Int_t w, ma, md;
264   txfGetStringMetrics(GLTextNS::fgDefaultFont,info.Data(), info.Length() , w, ma, md);
265   movex = w*sx;
266   glPopMatrix();
267
268   if(trans)
269     glTranslatef(movex, 0, 0);
270 }
271
272 /**************************************************************************/
273
274 void ITSModuleStepperGL::ProcessSelection(TGLRnrCtx       & /*rnrCtx*/,
275                                           TGLSelectRecord & rec)
276 {
277   // Processes secondary selection from TGLViewer.
278   // Calls TPointSet3D::PointSelected(Int_t) with index of selected
279   // point as an argument.
280
281   if (rec.GetN() < 2) return;
282
283   switch (rec.GetItem(1)) {
284     case 1:
285       fM->Previous();
286       break;
287     case 2:
288       fM->Start();
289       break;
290     case 3:
291       fM->Next();
292       break;
293     case 4:
294       fM->End();
295       break;
296     case 5:
297       gReve->GetEditor()->DisplayRenderElement(*fM->BeginChildren());
298       break;
299     case 6:
300     {
301       DigitScaleInfo* si = fM->fScaleInfo;
302       if(si->fScale < 5) 
303       {
304         si->ScaleChanged(si->fScale + 1);
305         gReve->GetEditor()->DisplayObject(gReve->GetEditor()->GetModel());
306         gReve->Redraw3D();
307       }
308       break;
309     }
310     case 7:
311     {
312       DigitScaleInfo* si = fM->fScaleInfo;
313       if(si->fScale > 1) 
314       {
315         si->ScaleChanged(si->GetScale() - 1);
316         gReve->GetEditor()->DisplayObject(gReve->GetEditor()->GetModel());
317         gReve->Redraw3D();
318       }
319       break;
320     }
321     default:
322       break;
323   }
324 }