Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
45 REveViewer::~REveViewer()
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 
60 void REveViewer::AddScene(REveScene *scene)
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 
82 void REveViewer::RemoveElementLocal(REveElement* /*el*/)
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 
93 void REveViewer::RemoveElementsLocal()
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 
124 REveViewerList::~REveViewerList()
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 
134 void REveViewerList::AddElement(REveElement* el)
135 {
136  REveElement::AddElement(el);
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Decompoundofy el, call base-class version.
141 
142 void REveViewerList::RemoveElementLocal(REveElement* el)
143 {
144  // This was needed as viewer was in EveWindowManager hierarchy, too.
145  // el->DecParentIgnoreCnt();
146 
147  REveElement::RemoveElementLocal(el);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Decompoundofy children, call base-class version.
152 
153 void REveViewerList::RemoveElementsLocal()
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 
162  REveElement::RemoveElementsLocal();
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Connect to TGLViewer class-signals.
167 
168 void REveViewerList::Connect()
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 
192 void REveViewerList::Disconnect()
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 
252 void REveViewerList::DeleteAnnotations()
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 
264 void REveViewerList::SceneDestructing(REveScene* scene)
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 
279 void REveViewerList::HandleTooltip()
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 
310 void REveViewerList::OnMouseOver(TObject *, UInt_t /*state*/)
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 
332 void REveViewerList::OnReMouseOver(TObject *obj, UInt_t /*state*/)
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 
354 void REveViewerList::OnUnMouseOver(TObject *obj, UInt_t /*state*/)
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;
381  REX::gEve->GetSelection()->UserPickedElement(el, state & kKeyControlMask);
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;
398  REX::gEve->GetSelection()->UserRePickedElement(el);
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;
415  REX::gEve->GetSelection()->UserUnPickedElement(el);
416 }
417 
418 ////////////////////////////////////////////////////////////////////////////////
419 /// Set color brightness.
420 
421 void REveViewerList::SetColorBrightness(Float_t b)
422 {
423  REveUtil::SetColorBrightness(b, 1);
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// Switch background color.
428 
429 void REveViewerList::SwitchColorSet()
430 {
431  fUseLightColorSet = ! fUseLightColorSet;
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 }