]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/DigitSet.cxx
Record changes.
[u/mrichter/AliRoot.git] / EVE / Reve / DigitSet.cxx
1 // $Header$
2
3 #include "DigitSet.h"
4
5 #include "ReveManager.h"
6
7 #include <TColor.h>
8
9 #include <TBuffer3D.h>
10 #include <TBuffer3DTypes.h>
11 #include <TVirtualPad.h>
12 #include <TVirtualViewer3D.h>
13
14 using namespace Reve;
15
16 //______________________________________________________________________
17 // DigitSet
18 //
19
20 ClassImp(DigitSet)
21
22 DigitSet::DigitSet(const Text_t* n, const Text_t* t) :
23   RenderElement   (),
24   TNamed          (n, t),
25
26   fDefaultValue   (kMinInt),
27   fValueIsColor   (kFALSE),
28   fOwnIds         (kFALSE),
29   fPlex           (),
30   fLastDigit      (0),
31
32   fFrame          (0),
33   fPalette        (0),
34   fRenderMode     (RM_Fill),
35   fDisableLigting (kTRUE),
36   fEmitSignals    (kFALSE),
37   fHistoButtons   (kTRUE),
38   fHMTrans        ()
39 {
40
41 }
42
43 DigitSet::~DigitSet()
44 {
45   SetFrame(0);
46   SetPalette(0);
47   if (fOwnIds)
48     ReleaseIds();
49 }
50
51 /**************************************************************************/
52
53 DigitSet::DigitBase* DigitSet::NewDigit()
54 {
55   fLastDigit = new (fPlex.NewAtom()) DigitBase(fDefaultValue);
56   return fLastDigit;
57 }
58
59 void DigitSet::ReleaseIds()
60 {
61   VoidCPlex::iterator qi(fPlex);
62   while (qi.next()) {
63     DigitBase& q = * (DigitBase*) qi();
64     if (q.fId.GetObject()) {
65       delete q.fId.GetObject();
66       q.fId = 0;
67     }
68   }
69 }
70
71 /**************************************************************************/
72 /**************************************************************************/
73
74 void DigitSet::SetMainColor(Color_t color)
75 {
76   // Override from RenderElement, forward to Frame.
77
78   if (fFrame) {
79     fFrame->SetFrameColor(color);
80     fFrame->UpdateBackPtrItems();
81   }
82   gReve->Redraw3D();
83 }
84
85 /**************************************************************************/
86 /**************************************************************************/
87
88 void DigitSet::RefitPlex()
89 {
90   // Instruct underlying memory allocator to regroup itself into a
91   // contiguous memory chunk.
92
93   fPlex.Refit();
94 }
95
96 /**************************************************************************/
97
98 void DigitSet::ScanMinMaxValues(Int_t& min, Int_t& max)
99 {
100   if (fValueIsColor || fPlex.Size() == 0) return;
101   min = kMaxInt;
102   max = kMinInt;
103   for (Int_t c=0; c<fPlex.VecSize(); ++c)
104   {
105     Char_t* a = fPlex.Chunk(c);
106     Int_t   n = fPlex.NAtoms(c);
107     while (n--)
108     {
109       Int_t v = ((DigitBase*)a)->fValue;
110       if (v < min) min = v;
111       if (v > max) max = v;
112       a += fPlex.S();
113     }
114   }
115   if (min == max)
116     --min;
117 }
118
119 /**************************************************************************/
120
121
122 void DigitSet::DigitValue(Int_t value)
123 {
124   fLastDigit->fValue = value;
125 }
126
127 void DigitSet::DigitColor(Color_t ci)
128 {
129   ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, kTRUE);
130 }
131
132 void DigitSet::DigitColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
133 {
134   UChar_t* x = (UChar_t*) & fLastDigit->fValue;
135   x[0] = r; x[1] = g; x[2] = b; x[3] = a;
136 }
137
138 void DigitSet::DigitColor(UChar_t* rgba)
139 {
140   UChar_t* x = (UChar_t*) & fLastDigit->fValue;
141   x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
142 }
143
144 /**************************************************************************/
145
146 void DigitSet::DigitId(TObject* id)
147 {
148   fLastDigit->fId = id;
149 }
150
151 /**************************************************************************/
152 /**************************************************************************/
153
154 void DigitSet::Paint(Option_t* /*option*/)
155 {
156   static const Exc_t eH("DigitSet::Paint ");
157
158   TBuffer3D buff(TBuffer3DTypes::kGeneric);
159
160   // Section kCore
161   buff.fID           = this;
162   buff.fColor        = fFrame ? fFrame->GetFrameColor() : 1;
163   buff.fTransparency = 0;
164   fHMTrans.SetBuffer3D(buff);
165   buff.SetSectionsValid(TBuffer3D::kCore);
166
167   Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
168   if (reqSections != TBuffer3D::kNone)
169     Error(eH, "only direct GL rendering supported.");
170 }
171
172 void DigitSet::DigitSelected(Int_t idx)
173 {
174   if (fEmitSignals) {
175     CtrlClicked(this, idx);
176   } else {
177     DigitBase* qb = GetDigit(idx);
178     TObject* obj = qb->fId.GetObject();
179     printf("DigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
180            idx, qb->fValue, (ULong_t)obj);
181     if (obj)
182       obj->Print();
183   }
184 }
185
186 void DigitSet::CtrlClicked(DigitSet* qs, Int_t idx)
187 {
188   Long_t args[2];
189   args[0] = (Long_t) qs;
190   args[1] = (Long_t) idx;
191
192   Emit("CtrlClicked(Reve::DigitSet*, Int_t)", args);
193 }
194
195 /**************************************************************************/
196 // Getters / Setters for Frame, RGBAPalette, ZTrans
197 /**************************************************************************/
198
199 void DigitSet::SetFrame(FrameBox* b)
200 {
201   if (fFrame == b) return;
202   if (fFrame) fFrame->DecRefCount(this);
203   fFrame = b;
204   if (fFrame) {
205     fFrame->IncRefCount(this);
206     SetMainColorPtr(fFrame->PtrFrameColor());
207   } else {
208     SetMainColorPtr(0);
209   }
210 }
211
212 void DigitSet::SetPalette(RGBAPalette* p)
213 {
214   if (fPalette == p) return;
215   if (fPalette) fPalette->DecRefCount();
216   fPalette = p;
217   if (fPalette) fPalette->IncRefCount();
218 }
219
220 RGBAPalette* DigitSet::AssertPalette()
221 {
222   if (fPalette == 0) {
223     fPalette = new RGBAPalette;
224     if (!fValueIsColor) {
225       Int_t min, max;
226       ScanMinMaxValues(min, max);
227       fPalette->SetLimits(min, max);
228       fPalette->SetMinMax(min, max);
229     }
230   }
231   return fPalette;
232 }