Logo ROOT  
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>
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/// Stream Camera Info.
106/// Virtual from REveElement.
108{
109 std::string ct;
110 switch (fCameraType)
111 {
112 case kCameraPerspXOZ: ct = "PerspXOZ"; break;
113 case kCameraOrthoXOY: ct = "OrthoXOY"; break;
114 }
115 j["CameraType"] = ct;
116 j["Mandatory"] = fMandatory;
117
118 j["UT_PostStream"] = "UT_EveViewSubscribed";
119
120 return REveElement::WriteCoreJson(j, rnr_offset);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Function called from MIR when user closes one of the viewer window.
125// Client id stored in thread local data
127{
129}
130////////////////////////////////////////////////////////////////////////////////
131/// Function called from MIR when user wants to stream unsubscribed view.
132// Client id stored in thread local data
134{
135 gEve->ConnectEveViewer(this);
136}
137
138////////////////////////////////////////////////////////////////////////////////
139///
140// Set Flag if this viewer is presented on connect
142{
143 fMandatory = x;
144 for (auto &c : RefChildren()) {
145 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
147 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151
152REveViewerList::REveViewerList(const std::string &n, const std::string &t) :
153 REveElement (n, t),
154 fShowTooltip (kTRUE),
155
156 fBrightness(0),
157 fUseLightColorSet(kFALSE)
158{
159 // Constructor.
160
161 SetChildClass(TClass::GetClass<REveViewer>());
162 Connect();
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Destructor.
167
169{
170 Disconnect();
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Call base-class implementation.
175/// If compound is open and compound of the new element is not set,
176/// the el's compound is set to this.
177
179{
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Decompoundofy el, call base-class version.
185
187{
188 // This was needed as viewer was in EveWindowManager hierarchy, too.
189 // el->DecParentIgnoreCnt();
190
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Decompoundofy children, call base-class version.
196
198{
199 // This was needed as viewer was in EveWindowManager hierarchy, too.
200 // el->DecParentIgnoreCnt();
201 // for (auto &c: fChildren)
202 // {
203 // c->DecParentIgnoreCnt();
204 // }
205
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Connect to TGLViewer class-signals.
211
213{
214 // TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
215 // "REveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
216
217 // TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
218 // "REveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
219
220 // TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
221 // "REveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
222
223 // TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
224 // "REveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
225
226 // TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
227 // "REveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
228
229 // TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
230 // "REveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Disconnect from TGLViewer class-signals.
235
237{
238 // TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
239 // this, "OnMouseOver(TObject*,UInt_t)");
240
241 // TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
242 // this, "OnReMouseOver(TObject*,UInt_t)");
243
244 // TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
245 // this, "OnUnMouseOver(TObject*,UInt_t)");
246
247 // TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
248 // this, "OnClicked(TObject*,UInt_t,UInt_t)");
249
250 // TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
251 // this, "OnReClicked(TObject*,UInt_t,UInt_t)");
252
253 // TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
254 // this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Repaint viewers that are tagged as changed.
259
260void REveViewerList::RepaintChangedViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
261{
262 //for (auto &c: fChildren) {
263 // TGLViewer* glv = ((REveViewer*)c)->GetGLViewer();
264 // if (glv->IsChanged())
265 // {
266 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
267 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
268
269 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
270
271 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
272 // }
273 //}
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Repaint all viewers.
278
279void REveViewerList::RepaintAllViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
280{
281 // for (auto &c: fChildren) {
282 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
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/// Delete annotations from all viewers.
295
297{
298 // for (auto &c: fChildren) {
299 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
300 // glv->DeleteOverlayAnnotations();
301 // }
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// Callback done from a REveScene destructor allowing proper
306/// removal of the scene from affected viewers.
307
309{
310 for (auto &viewer: fChildren) {
311 for (auto &j: viewer->RefChildren()) {
312 REveSceneInfo* sinfo = (REveSceneInfo *) j;
313 if (sinfo->GetScene() == scene)
314 viewer->RemoveElement(sinfo);
315 }
316 }
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Show / hide tooltip for various MouseOver events.
321/// Must be called from slots where sender is TGLEventHandler.
322
324{
325 if (fShowTooltip)
326 {
327 // TGLViewer *glw = dynamic_cast<TGLViewer*>((TQObject*) gTQSender);
328 // TGLEventHandler *glh = (TGLEventHandler*) glw->GetEventHandler();
329 // if (REX::gEve->GetHighlight()->NumChildren() == 1)
330 // {
331 // TString title(REX::gEve->GetHighlight()->FirstChild()->GetHighlightTooltip());
332 // if ( ! title.IsNull())
333 // glh->TriggerTooltip(title);
334 // }
335 // else
336 // {
337 // glh->RemoveTooltip();
338 // }
339 }
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Slot for global TGLViewer::MouseOver() signal.
344///
345/// The attempt is made to determine the REveElement being
346/// represented by the physical shape and global highlight is updated
347/// accordingly.
348///
349/// If REveElement::IsPickable() returns false, the element is not
350/// highlighted.
351///
352/// Highlight is always in single-selection mode.
353
355{
356 // REveElement *el = dynamic_cast<REveElement*>(obj);
357 // if (el && !el->IsPickable())
358 // el = nullptr;
359
360 // void *qsender = gTQSender;
361 // REX::gEve->GetHighlight()->UserPickedElement(el, kFALSE);
362 // gTQSender = qsender;
363
365}
366
367////////////////////////////////////////////////////////////////////////////////
368/// Slot for global TGLViewer::ReMouseOver().
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
377{
378 REveElement* el = dynamic_cast<REveElement*>(obj);
379 if (el && !el->IsPickable())
380 el = 0;
381
382 // void *qsender = gTQSender;
383 // REX::gEve->GetHighlight()->UserRePickedElement(el);
384 // gTQSender = qsender;
385
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Slot for global TGLViewer::UnMouseOver().
391///
392/// The obj is dyn-casted to the REveElement and global selection is
393/// updated accordingly.
394///
395/// If REveElement::IsPickable() returns false, the element is not
396/// selected.
397
399{
400 REveElement* el = dynamic_cast<REveElement*>(obj);
401 if (el && !el->IsPickable())
402 el = 0;
403
404 // void *qsender = gTQSender;
405 // REX::gEve->GetHighlight()->UserUnPickedElement(el);
406 // gTQSender = qsender;
407
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Slot for global TGLViewer::Clicked().
413///
414/// The obj is dyn-casted to the REveElement and global selection is
415/// updated accordingly.
416///
417/// If REveElement::IsPickable() returns false, the element is not
418/// selected.
419
420void REveViewerList::OnClicked(TObject *obj, UInt_t /*button*/, UInt_t state)
421{
422 REveElement* el = dynamic_cast<REveElement*>(obj);
423 if (el && !el->IsPickable())
424 el = 0;
426}
427
428////////////////////////////////////////////////////////////////////////////////
429/// Slot for global TGLViewer::ReClicked().
430///
431/// The obj is dyn-casted to the REveElement and global selection is
432/// updated accordingly.
433///
434/// If REveElement::IsPickable() returns false, the element is not
435/// selected.
436
437void REveViewerList::OnReClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
438{
439 REveElement* el = dynamic_cast<REveElement*>(obj);
440 if (el && !el->IsPickable())
441 el = 0;
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Slot for global TGLViewer::UnClicked().
447///
448/// The obj is dyn-casted to the REveElement and global selection is
449/// updated accordingly.
450///
451/// If REveElement::IsPickable() returns false, the element is not
452/// selected.
453
454void REveViewerList::OnUnClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
455{
456 REveElement* el = dynamic_cast<REveElement*>(obj);
457 if (el && !el->IsPickable())
458 el = 0;
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Set color brightness.
464
466{
468}
469
470////////////////////////////////////////////////////////////////////////////////
471/// Switch background color.
472
474{
476 // for (auto &c: fChildren) {
477 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
478 // if ( fUseLightColorSet)
479 // glv->UseLightColorSet();
480 // else
481 // glv->UseDarkColorSet();
482
483 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
484 // }
485}
const Mask_t kKeyControlMask
Definition: GuiTypes.h:197
#define c(i)
Definition: RSha256.hxx:101
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
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 *)
void ConnectEveViewer(REveViewer *)
REveSceneInfo Scene in a viewer.
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.
Definition: REveViewer.cxx:197
void OnUnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::UnClicked().
Definition: REveViewer.cxx:454
void AddElement(REveElement *el) override
Call base-class implementation.
Definition: REveViewer.cxx:178
void OnReClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::ReClicked().
Definition: REveViewer.cxx:437
void OnClicked(TObject *obj, UInt_t button, UInt_t state)
Slot for global TGLViewer::Clicked().
Definition: REveViewer.cxx:420
void HandleTooltip()
Show / hide tooltip for various MouseOver events.
Definition: REveViewer.cxx:323
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers.
Definition: REveViewer.cxx:308
void OnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::MouseOver() signal.
Definition: REveViewer.cxx:354
void SetColorBrightness(Float_t b)
Set color brightness.
Definition: REveViewer.cxx:465
void RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint all viewers.
Definition: REveViewer.cxx:279
void OnUnMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::UnMouseOver().
Definition: REveViewer.cxx:398
virtual void Disconnect()
Disconnect from TGLViewer class-signals.
Definition: REveViewer.cxx:236
void RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint viewers that are tagged as changed.
Definition: REveViewer.cxx:260
void OnReMouseOver(TObject *obj, UInt_t state)
Slot for global TGLViewer::ReMouseOver().
Definition: REveViewer.cxx:376
virtual ~REveViewerList()
Destructor.
Definition: REveViewer.cxx:168
void SwitchColorSet()
Switch background color.
Definition: REveViewer.cxx:473
REveViewerList(const REveViewerList &)=delete
virtual void Connect()
Connect to TGLViewer class-signals.
Definition: REveViewer.cxx:212
void DeleteAnnotations()
Delete annotations from all viewers.
Definition: REveViewer.cxx:296
void RemoveElementLocal(REveElement *el) override
Decompoundofy el, call base-class version.
Definition: REveViewer.cxx:186
void RemoveElementLocal(REveElement *el) override
Remove element 'el' from the list of children and also remove appropriate GLScene from GLViewer's lis...
Definition: REveViewer.cxx:80
void DisconnectClient()
Function called from MIR when user closes one of the viewer window.
Definition: REveViewer.cxx:126
void ConnectClient()
Function called from MIR when user wants to stream unsubscribed view.
Definition: REveViewer.cxx:133
void RemoveElementsLocal() override
Remove all children, forwarded to GLViewer.
Definition: REveViewer.cxx:91
virtual ~REveViewer()
Destructor.
Definition: REveViewer.cxx:43
REveViewer(const REveViewer &)=delete
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Stream Camera Info.
Definition: REveViewer.cxx:107
void Redraw(Bool_t resetCameras=kFALSE)
Redraw viewer immediately.
Definition: REveViewer.cxx:49
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
Definition: REveViewer.cxx:58
TEveSelection * GetSelection() const
Definition: TEveManager.h:129
virtual void UserRePickedElement(TEveElement *el)
Called when secondary selection becomes empty.
virtual void UserPickedElement(TEveElement *el, Bool_t multi=kFALSE)
Called when user picks/clicks on an element.
virtual void UserUnPickedElement(TEveElement *el)
Called when secondary selection becomes empty.
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
basic_json<> json
Definition: REveElement.hxx:62