5 #include "ReveManager.h"
10 #include <TBuffer3DTypes.h>
11 #include <TVirtualPad.h>
12 #include <TVirtualViewer3D.h>
16 //______________________________________________________________________________
19 // Base-class for displaying a digit collection.
20 // Provdies common services for:
21 // - specifying signal / color per digit
22 // - specifying object reference per digit
23 // - controlling palette and thresholds (external object RGBAPalette)
24 // - showing a frame around the digits (external object FrameBox)
25 // - specifying transformation matrix for the whole collection
26 // by data-member of class ZTrans.
29 // QuadSet: rectangle, hexagon or line per digit
30 // BoxSet a 3D box per digit
34 //______________________________________________________________________________
35 DigitSet::DigitSet(const Text_t* n, const Text_t* t) :
39 fDefaultValue (kMinInt),
40 fValueIsColor (kFALSE),
47 fRenderMode (RM_Fill),
48 fDisableLigting (kTRUE),
49 fEmitSignals (kFALSE),
50 fHistoButtons (kTRUE),
56 //______________________________________________________________________________
60 // Unreference frame and palette. Destroy referenced objects if they
61 // are owned by the DigitSet.
69 /******************************************************************************/
71 //______________________________________________________________________________
72 DigitSet::DigitBase* DigitSet::NewDigit()
74 // Protected method called whenever a new digit is added.
76 fLastDigit = new (fPlex.NewAtom()) DigitBase(fDefaultValue);
80 //______________________________________________________________________________
81 void DigitSet::ReleaseIds()
83 // Protected method. Release and delete the referenced objects, the
84 // ownership is *NOT* checked.
86 VoidCPlex::iterator qi(fPlex);
88 DigitBase& q = * (DigitBase*) qi();
89 if (q.fId.GetObject()) {
90 delete q.fId.GetObject();
96 /******************************************************************************/
97 /******************************************************************************/
99 //______________________________________________________________________________
100 void DigitSet::SetMainColor(Color_t color)
102 // Override from RenderElement, forward to Frame.
105 fFrame->SetFrameColor(color);
106 fFrame->UpdateBackPtrItems();
111 /******************************************************************************/
112 /******************************************************************************/
114 //______________________________________________________________________________
115 void DigitSet::RefitPlex()
117 // Instruct underlying memory allocator to regroup itself into a
118 // contiguous memory chunk.
123 /******************************************************************************/
125 //______________________________________________________________________________
126 void DigitSet::ScanMinMaxValues(Int_t& min, Int_t& max)
128 // Iterate over the digits and detmine min and max signal values.
130 if (fValueIsColor || fPlex.Size() == 0) return;
133 for (Int_t c=0; c<fPlex.VecSize(); ++c)
135 Char_t* a = fPlex.Chunk(c);
136 Int_t n = fPlex.NAtoms(c);
139 Int_t v = ((DigitBase*)a)->fValue;
140 if (v < min) min = v;
141 if (v > max) max = v;
149 /******************************************************************************/
151 //______________________________________________________________________________
152 void DigitSet::DigitValue(Int_t value)
154 // Set signal value for the last digit added.
156 fLastDigit->fValue = value;
159 //______________________________________________________________________________
160 void DigitSet::DigitColor(Color_t ci)
162 // Set color for the last digit added.
164 ColorFromIdx(ci, (UChar_t*) & fLastDigit->fValue, kTRUE);
167 //______________________________________________________________________________
168 void DigitSet::DigitColor(UChar_t r, UChar_t g, UChar_t b, UChar_t a)
170 // Set color for the last digit added.
172 UChar_t* x = (UChar_t*) & fLastDigit->fValue;
173 x[0] = r; x[1] = g; x[2] = b; x[3] = a;
176 //______________________________________________________________________________
177 void DigitSet::DigitColor(UChar_t* rgba)
179 // Set color for the last digit added.
181 UChar_t* x = (UChar_t*) & fLastDigit->fValue;
182 x[0] = rgba[0]; x[1] = rgba[1]; x[2] = rgba[2]; x[3] = rgba[3];
185 //______________________________________________________________________________
186 void DigitSet::DigitId(TObject* id)
188 // Set external object reference for the last digit added.
190 fLastDigit->fId = id;
193 /******************************************************************************/
194 /******************************************************************************/
196 //______________________________________________________________________________
197 void DigitSet::Paint(Option_t* /*option*/)
199 // Paint this object. Only direct rendering is supported.
201 static const Exc_t eH("DigitSet::Paint ");
203 TBuffer3D buff(TBuffer3DTypes::kGeneric);
207 buff.fColor = fFrame ? fFrame->GetFrameColor() : 1;
208 buff.fTransparency = 0;
209 fHMTrans.SetBuffer3D(buff);
210 buff.SetSectionsValid(TBuffer3D::kCore);
212 Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
213 if (reqSections != TBuffer3D::kNone)
214 Error(eH, "only direct GL rendering supported.");
217 //______________________________________________________________________________
218 void DigitSet::DigitSelected(Int_t idx)
220 // Called from renderer when a digit with index idx is selected.
223 CtrlClicked(this, idx);
225 DigitBase* qb = GetDigit(idx);
226 TObject* obj = qb->fId.GetObject();
227 printf("DigitSet::DigitSelected idx=%d, value=%d, obj=0x%lx\n",
228 idx, qb->fValue, (ULong_t)obj);
234 //______________________________________________________________________________
235 void DigitSet::CtrlClicked(DigitSet* qs, Int_t idx)
237 // Emit a CtrlClicked signal.
240 args[0] = (Long_t) qs;
241 args[1] = (Long_t) idx;
243 Emit("CtrlClicked(Reve::DigitSet*, Int_t)", args);
246 /******************************************************************************/
247 // Getters / Setters for Frame, RGBAPalette, ZTrans
248 /******************************************************************************/
250 //______________________________________________________________________________
251 void DigitSet::SetFrame(FrameBox* b)
253 // Set FrameBox pointer.
255 if (fFrame == b) return;
256 if (fFrame) fFrame->DecRefCount(this);
259 fFrame->IncRefCount(this);
260 SetMainColorPtr(fFrame->PtrFrameColor());
266 //______________________________________________________________________________
267 void DigitSet::SetPalette(RGBAPalette* p)
269 // Set RGBAPalette pointer.
271 if (fPalette == p) return;
272 if (fPalette) fPalette->DecRefCount();
274 if (fPalette) fPalette->IncRefCount();
277 //______________________________________________________________________________
278 RGBAPalette* DigitSet::AssertPalette()
280 // Make sure the RGBAPalette pointer is not null.
281 // If it is not set, a new one is instantiated and the range is set
282 // to current min/max signal values.
285 fPalette = new RGBAPalette;
286 if (!fValueIsColor) {
288 ScanMinMaxValues(min, max);
289 fPalette->SetLimits(min, max);
290 fPalette->SetMinMax(min, max);