Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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>
17#include <ROOT/REveManager.hxx>
19
20#include <nlohmann/json.hpp>
21
22using namespace ROOT::Experimental;
23namespace REX = ROOT::Experimental;
24
25/** \class REveViewer
26\ingroup REve
27Eve representation of a GL view. In a gist, it's a camera + a list of scenes.
28
29*/
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor.
33
34REveViewer::REveViewer(const std::string& n, const std::string& t) :
35 REveElement(n, t)
36{
37 // SetChildClass(TClass::GetClass<REveSceneInfo>());
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Destructor.
42
44{}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Redraw viewer immediately.
48
49void REveViewer::Redraw(Bool_t /*resetCameras*/)
50{
51 // if (resetCameras) fGLViewer->PostSceneBuildSetup(kTRUE);
52 // fGLViewer->RequestDraw(TGLRnrCtx::kLODHigh);
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Add 'scene' to the list of scenes.
57
59{
60 static const REveException eh("REveViewer::AddScene ");
61
62 for (auto &c: RefChildren()) {
63 auto sinfo = dynamic_cast<REveSceneInfo*>(c);
64
65 if (sinfo && sinfo->GetScene() == scene)
66 {
67 throw eh + "scene already in the viewer.";
68 }
69 }
70
71 auto si = new REveSceneInfo(this, scene);
72 AddElement(si);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Remove element 'el' from the list of children and also remove
77/// appropriate GLScene from GLViewer's list of scenes.
78/// Virtual from REveElement.
79
81{
82 // fGLViewer->RemoveScene(((REveSceneInfo*)el)->GetGLScene());
83
84 // XXXXX Notify clients !!! Or will this be automatic?
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Remove all children, forwarded to GLViewer.
89/// Virtual from REveElement.
90
92{
93 // fGLViewer->RemoveAllScenes();
94
95 // XXXXX Notify clients !!! Or will this be automatic?
96}
97
98
99/** \class REveViewerList
100\ingroup REve
101List of Viewers providing common operations on REveViewer collections.
102*/
103
104////////////////////////////////////////////////////////////////////////////////
105//
107{
108 fAxesType = (EAxesType)at;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113//
115{
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Stream Camera Info.
122/// Virtual from REveElement.
123int REveViewer::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
124{
125 std::string ct;
126 switch (fCameraType)
127 {
128 case kCameraPerspXOZ: ct = "PerspXOZ"; break;
129 case kCameraOrthoXOY: ct = "OrthoXOY"; break;
130 }
131 j["CameraType"] = ct;
132 j["Mandatory"] = fMandatory;
133 j["AxesType"] = fAxesType;
134 j["BlackBg"] = fBlackBackground;
135
136 j["UT_PostStream"] = "UT_EveViewerUpdate";
137
138 return REveElement::WriteCoreJson(j, rnr_offset);
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Function called from MIR when user closes one of the viewer window.
143// Client id stored in thread local data
145{
147}
148////////////////////////////////////////////////////////////////////////////////
149/// Function called from MIR when user wants to stream unsubscribed view.
150// Client id stored in thread local data
152{
153 gEve->ConnectEveViewer(this);
154}
155
156////////////////////////////////////////////////////////////////////////////////
157///
158// Set Flag if this viewer is presented on connect
160{
161 fMandatory = x;
162 for (auto &c : RefChildren()) {
163 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
165 }
166}
167
168////////////////////////////////////////////////////////////////////////////////
169
170REveViewerList::REveViewerList(const std::string &n, const std::string &t) :
171 REveElement (n, t),
172 fShowTooltip (kTRUE),
173
174 fBrightness(0),
175 fUseLightColorSet(kFALSE)
176{
177 // Constructor.
178
179 SetChildClass(TClass::GetClass<REveViewer>());
180 Connect();
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Destructor.
185
187{
188 Disconnect();
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Call base-class implementation.
193/// If compound is open and compound of the new element is not set,
194/// the el's compound is set to this.
195
197{
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Decompoundofy el, call base-class version.
203
205{
206 // This was needed as viewer was in EveWindowManager hierarchy, too.
207 // el->DecParentIgnoreCnt();
208
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Decompoundofy children, call base-class version.
214
216{
217 // This was needed as viewer was in EveWindowManager hierarchy, too.
218 // el->DecParentIgnoreCnt();
219 // for (auto &c: fChildren)
220 // {
221 // c->DecParentIgnoreCnt();
222 // }
223
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Connect to TGLViewer class-signals.
229
231{
232 // TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
233 // "REveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
234
235 // TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
236 // "REveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
237
238 // TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
239 // "REveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
240
241 // TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
242 // "REveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
243
244 // TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
245 // "REveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
246
247 // TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
248 // "REveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Disconnect from TGLViewer class-signals.
253
255{
256 // TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
257 // this, "OnMouseOver(TObject*,UInt_t)");
258
259 // TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
260 // this, "OnReMouseOver(TObject*,UInt_t)");
261
262 // TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
263 // this, "OnUnMouseOver(TObject*,UInt_t)");
264
265 // TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
266 // this, "OnClicked(TObject*,UInt_t,UInt_t)");
267
268 // TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
269 // this, "OnReClicked(TObject*,UInt_t,UInt_t)");
270
271 // TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
272 // this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Repaint viewers that are tagged as changed.
277
278void REveViewerList::RepaintChangedViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
279{
280 //for (auto &c: fChildren) {
281 // TGLViewer* glv = ((REveViewer*)c)->GetGLViewer();
282 // if (glv->IsChanged())
283 // {
284 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
285 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
286
287 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
288
289 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
290 // }
291 //}
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Repaint all viewers.
296
297void REveViewerList::RepaintAllViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
298{
299 // for (auto &c: fChildren) {
300 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
301
302 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
303 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
304
305 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
306
307 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
308 // }
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// Delete annotations from all viewers.
313
315{
316 // for (auto &c: fChildren) {
317 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
318 // glv->DeleteOverlayAnnotations();
319 // }
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Callback done from a REveScene destructor allowing proper
324/// removal of the scene from affected viewers.
325
327{
328 for (auto &viewer: fChildren) {
329 for (auto &j: viewer->RefChildren()) {
330 REveSceneInfo* sinfo = (REveSceneInfo *) j;
331 if (sinfo->GetScene() == scene)
332 viewer->RemoveElement(sinfo);
333 }
334 }
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Show / hide tooltip for various MouseOver events.
339/// Must be called from slots where sender is TGLEventHandler.
340
342{
343 if (fShowTooltip)
344 {
345 // TGLViewer *glw = dynamic_cast<TGLViewer*>((TQObject*) gTQSender);
346 // TGLEventHandler *glh = (TGLEventHandler*) glw->GetEventHandler();
347 // if (REX::gEve->GetHighlight()->NumChildren() == 1)
348 // {
349 // TString title(REX::gEve->GetHighlight()->FirstChild()->GetHighlightTooltip());
350 // if ( ! title.IsNull())
351 // glh->TriggerTooltip(title);
352 // }
353 // else
354 // {
355 // glh->RemoveTooltip();
356 // }
357 }
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Slot for global TGLViewer::MouseOver() signal.
362///
363/// The attempt is made to determine the REveElement being
364/// represented by the physical shape and global highlight is updated
365/// accordingly.
366///
367/// If REveElement::IsPickable() returns false, the element is not
368/// highlighted.
369///
370/// Highlight is always in single-selection mode.
371
373{
374 // REveElement *el = dynamic_cast<REveElement*>(obj);
375 // if (el && !el->IsPickable())
376 // el = nullptr;
377
378 // void *qsender = gTQSender;
379 // REX::gEve->GetHighlight()->UserPickedElement(el, kFALSE);
380 // gTQSender = qsender;
381
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// Slot for global TGLViewer::ReMouseOver().
387///
388/// The obj is dyn-casted to the REveElement and global selection is
389/// updated accordingly.
390///
391/// If REveElement::IsPickable() returns false, the element is not
392/// selected.
393
395{
396 REveElement* el = dynamic_cast<REveElement*>(obj);
397 if (el && !el->IsPickable())
398 el = nullptr;
399
400 // void *qsender = gTQSender;
401 // REX::gEve->GetHighlight()->UserRePickedElement(el);
402 // gTQSender = qsender;
403
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Slot for global TGLViewer::UnMouseOver().
409///
410/// The obj is dyn-casted to the REveElement and global selection is
411/// updated accordingly.
412///
413/// If REveElement::IsPickable() returns false, the element is not
414/// selected.
415
417{
418 REveElement* el = dynamic_cast<REveElement*>(obj);
419 if (el && !el->IsPickable())
420 el = nullptr;
421
422 // void *qsender = gTQSender;
423 // REX::gEve->GetHighlight()->UserUnPickedElement(el);
424 // gTQSender = qsender;
425
427}
428
429////////////////////////////////////////////////////////////////////////////////
430/// Slot for global TGLViewer::Clicked().
431///
432/// The obj is dyn-casted to the REveElement and global selection is
433/// updated accordingly.
434///
435/// If REveElement::IsPickable() returns false, the element is not
436/// selected.
437
438void REveViewerList::OnClicked(TObject *obj, UInt_t /*button*/, UInt_t state)
439{
440 REveElement* el = dynamic_cast<REveElement*>(obj);
441 if (el && !el->IsPickable())
442 el = nullptr;
444}
445
446////////////////////////////////////////////////////////////////////////////////
447/// Slot for global TGLViewer::ReClicked().
448///
449/// The obj is dyn-casted to the REveElement and global selection is
450/// updated accordingly.
451///
452/// If REveElement::IsPickable() returns false, the element is not
453/// selected.
454
455void REveViewerList::OnReClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
456{
457 REveElement* el = dynamic_cast<REveElement*>(obj);
458 if (el && !el->IsPickable())
459 el = nullptr;
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Slot for global TGLViewer::UnClicked().
465///
466/// The obj is dyn-casted to the REveElement and global selection is
467/// updated accordingly.
468///
469/// If REveElement::IsPickable() returns false, the element is not
470/// selected.
471
472void REveViewerList::OnUnClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
473{
474 REveElement* el = dynamic_cast<REveElement*>(obj);
475 if (el && !el->IsPickable())
476 el = nullptr;
478}
479
480////////////////////////////////////////////////////////////////////////////////
481/// Set color brightness.
482
484{
486}
487
488////////////////////////////////////////////////////////////////////////////////
489/// Switch background color.
490
492{
494 // for (auto &c: fChildren) {
495 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
496 // if ( fUseLightColorSet)
497 // glv->UseLightColorSet();
498 // else
499 // glv->UseDarkColorSet();
500
501 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
502 // }
503}
const Mask_t kKeyControlMask
Definition GuiTypes.h:197
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
virtual void RemoveElementsLocal()
Perform additional local removal of all elements.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual void RemoveElementLocal(REveElement *el)
Perform additional local removal of el.
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:41
void DisconnectEveViewer(REveViewer *)
REveSelection * GetSelection() const
void ConnectEveViewer(REveViewer *)
REveSceneInfo Scene in a viewer.
virtual void UserRePickedElement(REveElement *el)
Called when element selection is repeated.
virtual void UserPickedElement(REveElement *el, Bool_t multi=kFALSE)
Called when user picks/clicks on an element.
virtual void UserUnPickedElement(REveElement *el)
Called when an element is unselected.
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:206
void RemoveElementsLocal() override
Decompoundofy children, call base-class version.
void OnUnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::UnClicked().
void AddElement(REveElement *el) override
Call base-class implementation.
~REveViewerList() override
Destructor.
void OnReClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::ReClicked().
void OnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::Clicked().
void HandleTooltip()
Show / hide tooltip for various MouseOver events.
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers.
void OnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::MouseOver() signal.
void SetColorBrightness(Float_t b)
Set color brightness.
void RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint all viewers.
void OnUnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::UnMouseOver().
virtual void Disconnect()
Disconnect from TGLViewer class-signals.
void RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint viewers that are tagged as changed.
void OnReMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::ReMouseOver().
void SwitchColorSet()
Switch background color.
REveViewerList(const REveViewerList &)=delete
virtual void Connect()
Connect to TGLViewer class-signals.
void DeleteAnnotations()
Delete annotations from all viewers.
void RemoveElementLocal(REveElement *el) override
Decompoundofy el, call base-class version.
void RemoveElementLocal(REveElement *el) override
Remove element 'el' from the list of children and also remove appropriate GLScene from GLViewer's lis...
void DisconnectClient()
Function called from MIR when user closes one of the viewer window.
void ConnectClient()
Function called from MIR when user wants to stream unsubscribed view.
~REveViewer() override
Destructor.
void RemoveElementsLocal() override
Remove all children, forwarded to GLViewer.
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Stream Camera Info.
void Redraw(Bool_t resetCameras=kFALSE)
Redraw viewer immediately.
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
Mother of all ROOT objects.
Definition TObject.h:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve