00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEveDigitSet.h"
00013 #include "TEveManager.h"
00014 #include "TEveTrans.h"
00015
00016 #include "TColor.h"
00017 #include "TRefArray.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 ClassImp(TEveDigitSet);
00058
00059
00060 TEveDigitSet::TEveDigitSet(const char* n, const char* t) :
00061 TEveElement (fColor),
00062 TNamed (n, t),
00063
00064 fDigitIds (0),
00065 fDefaultValue (kMinInt),
00066 fValueIsColor (kFALSE),
00067 fSingleColor (kFALSE),
00068 fAntiFlick (kTRUE),
00069 fOwnIds (kFALSE),
00070 fPlex (),
00071 fLastDigit (0),
00072 fLastIdx (-1),
00073
00074 fColor (kWhite),
00075 fFrame (0),
00076 fPalette (0),
00077 fRenderMode (kRM_AsIs),
00078 fDisableLighting(kTRUE),
00079 fHistoButtons (kTRUE),
00080 fEmitSignals (kFALSE),
00081 fCallbackFoo (0),
00082 fTooltipCBFoo (0)
00083 {
00084
00085
00086 fCanEditMainColor = kTRUE;
00087 fCanEditMainTransparency = kTRUE;
00088 InitMainTrans();
00089 }
00090
00091
00092 TEveDigitSet::~TEveDigitSet()
00093 {
00094
00095
00096
00097
00098 SetFrame(0);
00099 SetPalette(0);
00100 if (fOwnIds)
00101 ReleaseIds();
00102 delete fDigitIds;
00103 }
00104
00105
00106
00107
00108 TEveDigitSet::DigitBase_t* TEveDigitSet::NewDigit()
00109 {
00110
00111
00112 fLastIdx = fPlex.Size();
00113 fLastDigit = new (fPlex.NewAtom()) DigitBase_t(fDefaultValue);
00114 return fLastDigit;
00115 }
00116
00117
00118 void TEveDigitSet::ReleaseIds()
00119 {
00120
00121
00122
00123 if (fDigitIds)
00124 {
00125 const Int_t N = fDigitIds->GetSize();
00126
00127 for (Int_t i = 0; i < N; ++i)
00128 delete fDigitIds->At(i);
00129
00130 fDigitIds->Expand(0);
00131 }
00132 }
00133
00134
00135
00136
00137 void TEveDigitSet::UseSingleColor()
00138 {
00139
00140
00141
00142 fSingleColor = kTRUE;
00143 }
00144
00145
00146 void TEveDigitSet::SetMainColor(Color_t color)
00147 {
00148
00149
00150 if (fSingleColor)
00151 {
00152 TEveElement::SetMainColor(color);
00153 }
00154 else if (fFrame)
00155 {
00156 fFrame->SetFrameColor(color);
00157 fFrame->StampBackPtrElements(kCBColorSelection);
00158 }
00159 }
00160
00161
00162 void TEveDigitSet::UnSelected()
00163 {
00164
00165
00166
00167 fSelectedSet.clear();
00168 TEveElement::UnSelected();
00169 }
00170
00171
00172 void TEveDigitSet::UnHighlighted()
00173 {
00174
00175
00176
00177 fHighlightedSet.clear();
00178 TEveElement::UnHighlighted();
00179 }
00180
00181
00182 TString TEveDigitSet::GetHighlightTooltip()
00183 {
00184
00185
00186
00187 if (fHighlightedSet.empty()) return "";
00188
00189 if (GetAlwaysSecSelect())
00190 {
00191 if (fTooltipCBFoo)
00192 {
00193 return (fTooltipCBFoo)(this, *fHighlightedSet.begin());
00194 }
00195 else if (fDigitIds)
00196 {
00197 TObject *o = GetId(*fHighlightedSet.begin());
00198 if (o)
00199 return TString(o->GetName());
00200 }
00201 return TString::Format("%s; idx=%d", GetElementName(), *fHighlightedSet.begin());
00202 }
00203 else
00204 {
00205 return TEveElement::GetHighlightTooltip();
00206 }
00207 }
00208
00209
00210
00211
00212
00213
00214 void TEveDigitSet::RefitPlex()
00215 {
00216
00217
00218
00219 fPlex.Refit();
00220 }
00221
00222
00223
00224
00225 void TEveDigitSet::ScanMinMaxValues(Int_t& min, Int_t& max)
00226 {
00227
00228
00229 if (fValueIsColor || fPlex.Size() == 0) return;
00230 min = kMaxInt;
00231 max = kMinInt;
00232 for (Int_t c=0; c<fPlex.VecSize(); ++c)
00233 {
00234 Char_t* a = fPlex.Chunk(c);
00235 Int_t n = fPlex.NAtoms(c);
00236 while (n--)
00237 {
00238 Int_t v = ((DigitBase_t*)a)->fValue;
00239 if (v < min) min = v;
00240 if (v > max) max = v;
00241 a += fPlex.S();
00242 }
00243 }
00244 if (min == max)
00245 --min;
00246 }
00247
00248
00249
00250
00251 void TEveDigitSet::SetCurrentDigit(Int_t idx)
00252 {
00253
00254
00255
00256
00257
00258 fLastIdx = idx;
00259 fLastDigit = GetDigit(idx);
00260 }
00261
00262
00263 void TEveDigitSet::DigitValue(Int_t value)
00264 {
00265
00266
00267 fLastDigit->fValue = value;
00268 }
00269
00270
00271 void TEveDigitSet::DigitColor(Color_t ci)
00272 {
00273
00274
00275 TEveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, kTRUE);
00276 }
00277
00278
00279 void TEveDigitSet::DigitColor(Color_t ci, Char_t transparency)
00280 {
00281
00282
00283 TEveUtil::ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, transparency);
00284 }
00285
00286
00287 void TEveDigitSet::DigitColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
00288 {
00289
00290
00291 UChar_t* x = (UChar_t*) & fLastDigit->fValue;
00292 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
00293 }
00294
00295
00296 void TEveDigitSet::DigitColor(UChar_t* rgba)
00297 {
00298
00299
00300 UChar_t* x = (UChar_t*) & fLastDigit->fValue;
00301 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
00302 }
00303
00304
00305 void TEveDigitSet::DigitId(TObject* id)
00306 {
00307
00308
00309 DigitId(fLastIdx, id);
00310 }
00311
00312
00313 void TEveDigitSet::DigitUserData(void* ud)
00314 {
00315
00316
00317 fLastDigit->fUserData = ud;
00318 }
00319
00320
00321 void TEveDigitSet::DigitId(Int_t n, TObject* id)
00322 {
00323
00324
00325 if (!fDigitIds)
00326 fDigitIds = new TRefArray;
00327
00328 if (fOwnIds && n < fDigitIds->GetSize() && fDigitIds->At(n))
00329 delete fDigitIds->At(n);
00330
00331 fDigitIds->AddAtAndExpand(id, n);
00332 }
00333
00334
00335 void TEveDigitSet::DigitUserData(Int_t n, void* ud)
00336 {
00337
00338
00339 GetDigit(n)->fUserData = ud;
00340 }
00341
00342
00343 TObject* TEveDigitSet::GetId(Int_t n) const
00344 {
00345
00346
00347 return fDigitIds ? fDigitIds->At(n) : 0;
00348 }
00349
00350
00351 void* TEveDigitSet::GetUserData(Int_t n) const
00352 {
00353
00354
00355 return GetDigit(n)->fUserData;
00356 }
00357
00358
00359
00360
00361
00362 void TEveDigitSet::Paint(Option_t*)
00363 {
00364
00365
00366 PaintStandard(this);
00367 }
00368
00369
00370 void TEveDigitSet::DigitSelected(Int_t idx)
00371 {
00372
00373
00374
00375 DigitBase_t *qb = GetDigit(idx);
00376 TObject *obj = GetId(idx);
00377
00378 if (fCallbackFoo) {
00379 (fCallbackFoo)(this, idx, obj);
00380 }
00381 if (fEmitSignals) {
00382 SecSelected(this, idx);
00383 } else {
00384 printf("TEveDigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
00385 idx, qb->fValue, (ULong_t)obj);
00386 if (obj)
00387 obj->Print();
00388 }
00389 }
00390
00391
00392 void TEveDigitSet::SecSelected(TEveDigitSet* qs, Int_t idx)
00393 {
00394
00395
00396
00397 Long_t args[2];
00398 args[0] = (Long_t) qs;
00399 args[1] = (Long_t) idx;
00400
00401 Emit("SecSelected(TEveDigitSet*, Int_t)", args);
00402 }
00403
00404
00405
00406
00407
00408
00409 void TEveDigitSet::SetFrame(TEveFrameBox* b)
00410 {
00411
00412
00413 if (fFrame == b) return;
00414 if (fFrame) fFrame->DecRefCount(this);
00415 fFrame = b;
00416 if (fFrame) {
00417 fFrame->IncRefCount(this);
00418 if (!fSingleColor) {
00419 SetMainColorPtr(fFrame->PtrFrameColor());
00420 }
00421 } else {
00422 SetMainColorPtr(&fColor);
00423 }
00424 }
00425
00426
00427 void TEveDigitSet::SetPalette(TEveRGBAPalette* p)
00428 {
00429
00430
00431 if (fPalette == p) return;
00432 if (fPalette) fPalette->DecRefCount();
00433 fPalette = p;
00434 if (fPalette) fPalette->IncRefCount();
00435 }
00436
00437
00438 TEveRGBAPalette* TEveDigitSet::AssertPalette()
00439 {
00440
00441
00442
00443
00444 if (fPalette == 0) {
00445 fPalette = new TEveRGBAPalette;
00446 if (!fValueIsColor) {
00447 Int_t min, max;
00448 ScanMinMaxValues(min, max);
00449 fPalette->SetLimits(min, max);
00450 fPalette->SetMinMax(min, max);
00451 }
00452 }
00453 return fPalette;
00454 }