Logo ROOT   6.21/01
Reference Guide
REveViewer.cxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include <ROOT/REveViewer.hxx>
13 
14 #include <ROOT/REveUtil.hxx>
15 #include <ROOT/REveScene.hxx>
16 #include <ROOT/REveSceneInfo.hxx>
17 #include <ROOT/REveManager.hxx>
18 #include <ROOT/REveSelection.hxx>
19 
20 #include "TApplication.h"
21 #include "TEnv.h"
22 #include "TSystem.h"
23 
24 using namespace ROOT::Experimental;
25 namespace REX = ROOT::Experimental;
26 
27 /** \class REveViewer
28 \ingroup REve
29 Eve representation of a GL view. In a gist, it's a camera + a list of scenes.
30 
31 */
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor.
35 
36 REveViewer::REveViewer(const std::string& n, const std::string& t) :
37  REveElement(n, t)
38 {
39  // SetChildClass(TClass::GetClass<REveSceneInfo>());
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Destructor.
44 
46 {}
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Redraw viewer immediately.
50 
51 void REveViewer::Redraw(Bool_t /*resetCameras*/)
52 {
53  // if (resetCameras) fGLViewer->PostSceneBuildSetup(kTRUE);
54  // fGLViewer->RequestDraw(TGLRnrCtx::kLODHigh);
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Add 'scene' to the list of scenes.
59 
61 {
62  static const REveException eh("REveViewer::AddScene ");
63 
64  for (auto &c: RefChildren()) {
65  auto sinfo = dynamic_cast<REveSceneInfo*>(c);
66 
67  if (sinfo && sinfo->GetScene() == scene)
68  {
69  throw eh + "scene already in the viewer.";
70  }
71  }
72 
73  auto si = new REveSceneInfo(this, scene);
74  AddElement(si);
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Remove element 'el' from the list of children and also remove
79 /// appropriate GLScene from GLViewer's list of scenes.
80 /// Virtual from REveElement.
81 
83 {
84  // fGLViewer->RemoveScene(((REveSceneInfo*)el)->GetGLScene());
85 
86  // XXXXX Notify clients !!! Or will this be automatic?
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Remove all children, forwarded to GLViewer.
91 /// Virtual from REveElement.
92 
94 {
95  // fGLViewer->RemoveAllScenes();
96 
97  // XXXXX Notify clients !!! Or will this be automatic?
98 }
99 
100 
101 /** \class REveViewerList
102 \ingroup REve
103 List of Viewers providing common operations on REveViewer collections.
104 */
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 
108 REveViewerList::REveViewerList(const std::string &n, const std::string &t) :
109  REveElement (n, t),
110  fShowTooltip (kTRUE),
111 
112  fBrightness(0),
113  fUseLightColorSet(kFALSE)
114 {
115  // Constructor.
116 
117  SetChildClass(TClass::GetClass<REveViewer>());
118  Connect();
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Destructor.
123 
125 {
126  Disconnect();
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Call base-class implementation.
131 /// If compound is open and compound of the new element is not set,
132 /// the el's compound is set to this.
133 
135 {
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Decompoundofy el, call base-class version.
141 
143 {
144  // This was needed as viewer was in EveWindowManager hierarchy, too.
145  // el->DecParentIgnoreCnt();
146 
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Decompoundofy children, call base-class version.
152 
154 {
155  // This was needed as viewer was in EveWindowManager hierarchy, too.
156  // el->DecParentIgnoreCnt();
157  // for (auto &c: fChildren)
158  // {
159  // c->DecParentIgnoreCnt();
160  // }
161 
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Connect to TGLViewer class-signals.
167 
169 {
170  // TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
171  // "REveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
172 
173  // TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
174  // "REveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
175 
176  // TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
177  // "REveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
178 
179  // TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
180  // "REveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
181 
182  // TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
183  // "REveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
184 
185  // TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
186  // "REveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Disconnect from TGLViewer class-signals.
191 
193 {
194  // TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
195  // this, "OnMouseOver(TObject*,UInt_t)");
196 
197  // TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
198  // this, "OnReMouseOver(TObject*,UInt_t)");
199 
200  // TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
201  // this, "OnUnMouseOver(TObject*,UInt_t)");
202 
203  // TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
204  // this, "OnClicked(TObject*,UInt_t,UInt_t)");
205 
206  // TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
207  // this, "OnReClicked(TObject*,UInt_t,UInt_t)");
208 
209  // TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
210  // this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Repaint viewers that are tagged as changed.
215 
216 void REveViewerList::RepaintChangedViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
217 {
218  //for (auto &c: fChildren) {
219  // TGLViewer* glv = ((REveViewer*)c)->GetGLViewer();
220  // if (glv->IsChanged())
221  // {
222  // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
223  // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
224 
225  // glv->RequestDraw(TGLRnrCtx::kLODHigh);
226 
227  // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
228  // }
229  //}
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Repaint all viewers.
234 
235 void REveViewerList::RepaintAllViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
236 {
237  // for (auto &c: fChildren) {
238  // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
239 
240  // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
241  // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
242 
243  // glv->RequestDraw(TGLRnrCtx::kLODHigh);
244 
245  // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
246  // }
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 /// Delete annotations from all viewers.
251 
253 {
254  // for (auto &c: fChildren) {
255  // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
256  // glv->DeleteOverlayAnnotations();
257  // }
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Callback done from a REveScene destructor allowing proper
262 /// removal of the scene from affected viewers.
263 
265 {
266  for (auto &viewer: fChildren) {
267  for (auto &j: viewer->RefChildren()) {
268  REveSceneInfo* sinfo = (REveSceneInfo *) j;
269  if (sinfo->GetScene() == scene)
270  viewer->RemoveElement(sinfo);
271  }
272  }
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Show / hide tooltip for various MouseOver events.
277 /// Must be called from slots where sender is TGLEventHandler.
278 
280 {
281  if (fShowTooltip)
282  {
283  // TGLViewer *glw = dynamic_cast<TGLViewer*>((TQObject*) gTQSender);
284  // TGLEventHandler *glh = (TGLEventHandler*) glw->GetEventHandler();
285  // if (REX::gEve->GetHighlight()->NumChildren() == 1)
286  // {
287  // TString title(REX::gEve->GetHighlight()->FirstChild()->GetHighlightTooltip());
288  // if ( ! title.IsNull())
289  // glh->TriggerTooltip(title);
290  // }
291  // else
292  // {
293  // glh->RemoveTooltip();
294  // }
295  }
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Slot for global TGLViewer::MouseOver() signal.
300 ///
301 /// The attempt is made to determine the REveElement being
302 /// represented by the physical shape and global highlight is updated
303 /// accordingly.
304 ///
305 /// If REveElement::IsPickable() returns false, the element is not
306 /// highlighted.
307 ///
308 /// Highlight is always in single-selection mode.
309 
311 {
312  // REveElement *el = dynamic_cast<REveElement*>(obj);
313  // if (el && !el->IsPickable())
314  // el = nullptr;
315 
316  // void *qsender = gTQSender;
317  // REX::gEve->GetHighlight()->UserPickedElement(el, kFALSE);
318  // gTQSender = qsender;
319 
320  HandleTooltip();
321 }
322 
323 ////////////////////////////////////////////////////////////////////////////////
324 /// Slot for global TGLViewer::ReMouseOver().
325 ///
326 /// The obj is dyn-casted to the REveElement and global selection is
327 /// updated accordingly.
328 ///
329 /// If REveElement::IsPickable() returns false, the element is not
330 /// selected.
331 
333 {
334  REveElement* el = dynamic_cast<REveElement*>(obj);
335  if (el && !el->IsPickable())
336  el = 0;
337 
338  // void *qsender = gTQSender;
339  // REX::gEve->GetHighlight()->UserRePickedElement(el);
340  // gTQSender = qsender;
341 
342  HandleTooltip();
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Slot for global TGLViewer::UnMouseOver().
347 ///
348 /// The obj is dyn-casted to the REveElement and global selection is
349 /// updated accordingly.
350 ///
351 /// If REveElement::IsPickable() returns false, the element is not
352 /// selected.
353 
355 {
356  REveElement* el = dynamic_cast<REveElement*>(obj);
357  if (el && !el->IsPickable())
358  el = 0;
359 
360  // void *qsender = gTQSender;
361  // REX::gEve->GetHighlight()->UserUnPickedElement(el);
362  // gTQSender = qsender;
363 
364  HandleTooltip();
365 }
366 
367 ////////////////////////////////////////////////////////////////////////////////
368 /// Slot for global TGLViewer::Clicked().
369 ///
370 /// The obj is dyn-casted to the REveElement and global selection is
371 /// updated accordingly.
372 ///
373 /// If REveElement::IsPickable() returns false, the element is not
374 /// selected.
375 
376 void REveViewerList::OnClicked(TObject *obj, UInt_t /*button*/, UInt_t state)
377 {
378  REveElement* el = dynamic_cast<REveElement*>(obj);
379  if (el && !el->IsPickable())
380  el = 0;
382 }
383 
384 ////////////////////////////////////////////////////////////////////////////////
385 /// Slot for global TGLViewer::ReClicked().
386 ///
387 /// The obj is dyn-casted to the REveElement and global selection is
388 /// updated accordingly.
389 ///
390 /// If REveElement::IsPickable() returns false, the element is not
391 /// selected.
392 
393 void REveViewerList::OnReClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
394 {
395  REveElement* el = dynamic_cast<REveElement*>(obj);
396  if (el && !el->IsPickable())
397  el = 0;
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 /// Slot for global TGLViewer::UnClicked().
403 ///
404 /// The obj is dyn-casted to the REveElement and global selection is
405 /// updated accordingly.
406 ///
407 /// If REveElement::IsPickable() returns false, the element is not
408 /// selected.
409 
410 void REveViewerList::OnUnClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
411 {
412  REveElement* el = dynamic_cast<REveElement*>(obj);
413  if (el && !el->IsPickable())
414  el = 0;
416 }
417 
418 ////////////////////////////////////////////////////////////////////////////////
419 /// Set color brightness.
420 
422 {
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// Switch background color.
428 
430 {
432  // for (auto &c: fChildren) {
433  // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
434  // if ( fUseLightColorSet)
435  // glv->UseLightColorSet();
436  // else
437  // glv->UseDarkColorSet();
438 
439  // glv->RequestDraw(TGLRnrCtx::kLODHigh);
440  // }
441 }
void RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint all viewers.
Definition: REveViewer.cxx:235
void OnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::Clicked().
Definition: REveViewer.cxx:376
void RemoveElementLocal(REveElement *el) override
Decompoundofy el, call base-class version.
Definition: REveViewer.cxx:142
virtual void UserUnPickedElement(TEveElement *el)
Called when secondary selection becomes empty.
virtual void Disconnect()
Disconnect from TGLViewer class-signals.
Definition: REveViewer.cxx:192
float Float_t
Definition: RtypesCore.h:53
virtual void RemoveElementsLocal()
Perform additional local removal of all elements.
virtual void UserPickedElement(TEveElement *el, Bool_t multi=kFALSE)
Called when user picks/clicks on an element.
REveViewer(const REveViewer &)=delete
static void SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE)
Tweak all ROOT colors to become brighter (if value > 0) or darker (value < 0).
Definition: REveUtil.cxx:210
void OnUnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::UnClicked().
Definition: REveViewer.cxx:410
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers...
Definition: REveViewer.cxx:264
bool Bool_t
Definition: RtypesCore.h:59
void Redraw(Bool_t resetCameras=kFALSE)
Redraw viewer immediately.
Definition: REveViewer.cxx:51
virtual ~REveViewerList()
Destructor.
Definition: REveViewer.cxx:124
virtual void RemoveElementLocal(REveElement *el)
Perform additional local removal of el.
void OnReClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::ReClicked().
Definition: REveViewer.cxx:393
void RemoveElementsLocal() override
Decompoundofy children, call base-class version.
Definition: REveViewer.cxx:153
virtual void AddElement(REveElement *el)
Add el to the list of children.
void RemoveElementsLocal() override
Remove all children, forwarded to GLViewer.
Definition: REveViewer.cxx:93
void OnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::MouseOver() signal.
Definition: REveViewer.cxx:310
virtual void UserRePickedElement(TEveElement *el)
Called when secondary selection becomes empty.
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
REveViewerList(const REveViewerList &)=delete
void SetColorBrightness(Float_t b)
Set color brightness.
Definition: REveViewer.cxx:421
virtual ~REveViewer()
Destructor.
Definition: REveViewer.cxx:45
void OnUnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::UnMouseOver().
Definition: REveViewer.cxx:354
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void AddScene(REveScene *scene)
Add &#39;scene&#39; to the list of scenes.
Definition: REveViewer.cxx:60
void AddElement(REveElement *el) override
Call base-class implementation.
Definition: REveViewer.cxx:134
const Bool_t kFALSE
Definition: RtypesCore.h:88
TEveSelection * GetSelection() const
Definition: TEveManager.h:129
void RemoveElementLocal(REveElement *el) override
Remove element &#39;el&#39; from the list of children and also remove appropriate GLScene from GLViewer&#39;s lis...
Definition: REveViewer.cxx:82
Mother of all ROOT objects.
Definition: TObject.h:37
void SwitchColorSet()
Switch background color.
Definition: REveViewer.cxx:429
void HandleTooltip()
Show / hide tooltip for various MouseOver events.
Definition: REveViewer.cxx:279
void DeleteAnnotations()
Delete annotations from all viewers.
Definition: REveViewer.cxx:252
REveSceneInfo Scene in a viewer.
void OnReMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::ReMouseOver().
Definition: REveViewer.cxx:332
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
void RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint viewers that are tagged as changed.
Definition: REveViewer.cxx:216
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define c(i)
Definition: RSha256.hxx:101
const Mask_t kKeyControlMask
Definition: GuiTypes.h:196
virtual void Connect()
Connect to TGLViewer class-signals.
Definition: REveViewer.cxx:168
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
REveException Exception-type thrown by Eve classes.
Definition: REveTypes.hxx:40