3 #include "ITSModuleStepperGL.h"
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>
11 #include <Alieve/ITSModuleStepper.h>
12 #include <Alieve/ITSScaledModule.h>
14 #include <TGLRnrCtx.h>
15 #include <TGLSelectRecord.h>
18 using namespace Alieve;
20 //______________________________________________________________________
24 ClassImp(ITSModuleStepperGL)
26 ITSModuleStepperGL::ITSModuleStepperGL() : TGLObject(), fM(0)
28 fDLCache = false; // Disable display list.
31 ITSModuleStepperGL::~ITSModuleStepperGL()
34 /**************************************************************************/
36 Bool_t ITSModuleStepperGL::SetModel(TObject* obj, const Option_t* /*opt*/)
38 if(SetModelCheckClass(obj, ITSModuleStepper::Class())) {
39 fM = dynamic_cast<ITSModuleStepper*>(obj);
45 void ITSModuleStepperGL::SetBBox()
47 // !! This ok if master sub-classed from TAttBBox
48 SetAxisAlignedBBox(fM->AssertBBox());
51 /**************************************************************************/
53 void ITSModuleStepperGL::DirectDraw(TGLRnrCtx & rnrCtx) const
55 // printf("ITSModuleStepperGL::DirectDraw Style %d, LOD %d\n", rnrCtx.Style(), rnrCtx.LOD());
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;
64 glGetBooleanv(GL_LIGHTING, &lightp);
65 if (lightp) glDisable(GL_LIGHTING);
68 ColorFromIdx(MS.fWColor, color);
71 // render frame of grid stepper
74 glBegin(GL_LINE_LOOP);
83 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT);
84 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
85 glDisable(GL_CULL_FACE);
87 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
89 Float_t sx =0 ,sy = 0;
91 case ITSModuleStepper::PT_BottomLeft:
94 case ITSModuleStepper::PT_BottomRight:
97 case ITSModuleStepper::PT_TopLeft:
100 case ITSModuleStepper::PT_TopRight:
108 if (rnrCtx.SecSelection()) glPushName(0);
110 glTranslatef(sx, sy, 0.);
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);
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())
135 cnx = di->fSPDScaleX[scale], cnz = di->fSPDScaleZ[scale];
138 cnx = di->fSDDScaleX[scale], cnz = di->fSDDScaleZ[scale];
141 cnx = di->fSSDScale[scale], cnz = 1;
144 if (rnrCtx.SecSelection()) glLoadName(0);
145 RenderString(Form("Scale"), dy);
146 glTranslatef(0.07*dx, 0, 0);
148 if (rnrCtx.SecSelection()) glLoadName(6);
149 RenderSymbol(dx*1.2, dy*0.9, 5);
151 if (rnrCtx.SecSelection()) glLoadName(7);
152 RenderSymbol(dx*1.2, dy*0.9, 6);
154 glTranslatef(1*dx, 0, 0);
155 if (rnrCtx.SecSelection()) glLoadName(0);
156 RenderString(Form(" %dx%d ", cnx, cnz), dy, kFALSE);
159 if (rnrCtx.SecSelection()) glLoadName(5);
161 glTranslatef(W+2, 0, 0);
165 if (rnrCtx.SecSelection()) glPopName();
169 if (lightp) glEnable(GL_LIGHTING);
172 /**************************************************************************/
174 void ITSModuleStepperGL::RenderPalette(Float_t dx, Float_t dy) const
176 ITSModule* qs = dynamic_cast<ITSModule*>(*fM->BeginChildren());
177 RGBAPalette* p = qs->GetPalette();
178 Float_t xs = dx/(p->GetMaxVal()- p->GetMinVal());
182 glBegin(GL_QUAD_STRIP);
183 for(Int_t i=p->GetMinVal(); i<=p->GetMaxVal(); i++)
185 glColor4ubv(p->ColorFromValue(i + p->GetMinVal()));
193 /**************************************************************************/
195 void ITSModuleStepperGL::RenderSymbol(Float_t dx, Float_t dy, Int_t id) const
197 Float_t xs = dx/4, ys = dy/4;
201 glVertex2f(0,ys); glVertex2f(0, ys*3);
202 glVertex2f(dx, ys*3); glVertex2f(dx, ys);
208 glBegin(GL_TRIANGLES);
212 glVertex2f(xs*2.5, ys*3); glVertex2f(xs*1.5, ys*2); glVertex2f(xs*2.5, ys);
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);
223 glVertex2f(xs*1.5, ys); glVertex2f(xs*2.5, ys*2); glVertex2f(xs*1.5, ys*3);
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);
234 glVertex2f(xs, ys*2.5); glVertex2f(xs*2, ys*3.5); glVertex2f(xs*3, ys*2.5);
239 glVertex2f(xs, ys*1.5); glVertex2f(xs*2, ys*0.5); glVertex2f(xs*3, ys*1.5);
249 /**************************************************************************/
250 void ITSModuleStepperGL::RenderString(TString info, Float_t dy, Bool_t trans) const
254 GLUtilNS::GL_Capability_Switch texure_on(GL_TEXTURE_2D, true);
255 GLTextNS::txfBindFontTexture(GLTextNS::fgDefaultFont);
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;
262 txfRenderString(GLTextNS::fgDefaultFont, info.Data(), info.Length());
264 txfGetStringMetrics(GLTextNS::fgDefaultFont,info.Data(), info.Length() , w, ma, md);
269 glTranslatef(movex, 0, 0);
272 /**************************************************************************/
274 void ITSModuleStepperGL::ProcessSelection(TGLRnrCtx & /*rnrCtx*/,
275 TGLSelectRecord & rec)
277 // Processes secondary selection from TGLViewer.
278 // Calls TPointSet3D::PointSelected(Int_t) with index of selected
279 // point as an argument.
281 if (rec.GetN() < 2) return;
283 switch (rec.GetItem(1)) {
297 gReve->GetEditor()->DisplayRenderElement(*fM->BeginChildren());
301 DigitScaleInfo* si = fM->fScaleInfo;
304 si->ScaleChanged(si->fScale + 1);
305 gReve->GetEditor()->DisplayObject(gReve->GetEditor()->GetModel());
312 DigitScaleInfo* si = fM->fScaleInfo;
315 si->ScaleChanged(si->GetScale() - 1);
316 gReve->GetEditor()->DisplayObject(gReve->GetEditor()->GetModel());