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#include <ROOT/REveText.hxx>
20
21#include <nlohmann/json.hpp>
22#include "TROOT.h"
23
24using namespace ROOT::Experimental;
25namespace REX = ROOT::Experimental;
26
27/** \class REveViewer
28\ingroup REve
29Eve representation of a GL view. In a gist, it's a camera + a list of scenes.
30
31*/
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor.
35
36REveViewer::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
47
48////////////////////////////////////////////////////////////////////////////////
49/// Redraw viewer immediately.
50
51void 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);
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
103List of Viewers providing common operations on REveViewer collections.
104*/
105
106////////////////////////////////////////////////////////////////////////////////
107//
109{
110 fAxesType = (EAxesType)at;
111 if (fAxesType != kAxesNone) {
112 std::string fn = "LiberationSerif-Regular";
113 std::string rf_dir = std::string(TROOT::GetDataDir().Data()) + "/fonts/";
114 REX::REveText::AssertSdfFont(fn, rf_dir + fn + ".ttf");
115 }
117}
118
119////////////////////////////////////////////////////////////////////////////////
120//
126
127////////////////////////////////////////////////////////////////////////////////
128/// Stream Camera Info.
129/// Virtual from REveElement.
131{
133
134 j["Mandatory"] = fMandatory;
135 j["AxesType"] = fAxesType;
136 j["BlackBg"] = fBlackBackground;
137
138 j["UT_PostStream"] = "UT_EveViewerUpdate";
139
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Function called from MIR when user closes one of the viewer window.
145// Client id stored in thread local data
150////////////////////////////////////////////////////////////////////////////////
151/// Function called from MIR when user wants to stream unsubscribed view.
152// Client id stored in thread local data
157
158////////////////////////////////////////////////////////////////////////////////
159///
160// Set Flag if this viewer is presented on connect
162{
163 fMandatory = x;
164 for (auto &c : RefChildren()) {
165 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
166 sinfo->GetScene()->GetScene()->SetMandatory(fMandatory);
167 }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171///
172// Set base vectors of camera base matrix
173//
175{
176 switch(cameraType) {
177 case kCameraPerspXOZ:
178 fCamera.Setup(kCameraPerspXOZ, "PerspXOZ", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0)); // XOZ floor
179 break;
180 case kCameraPerspYOZ:
181 fCamera.Setup(kCameraPerspYOZ, "PerspYOZ", REveVector(0.0, -1.0, 0.0), REveVector(1.0, 0.0, 0.0));// YOZ floor
182 break;
183 case kCameraPerspXOY:
184 fCamera.Setup(kCameraPerspXOY, "PerspXOY", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 0.0, 1.0));// XOY floor
185 break;
186 case kCameraOrthoXOY:
187 fCamera.Setup(kCameraOrthoXOY, "OrthoXOY", REveVector(0.0, 0.0, 1.0), REveVector(0.0, 1.0, 0.0));// Looking down Z axis, X horz, Y vert
188 break;
189 case kCameraOrthoXOZ:
190 fCamera.Setup(kCameraOrthoXOZ, "OrthoXOZ", REveVector(0.0, -1.0, 0.0), REveVector(0.0, 0.0, 1.0));// Looking along Y axis, X horz, Z vert
191 break;
192 case kCameraOrthoZOY:
193 fCamera.Setup(kCameraOrthoZOY, "OrthoZOY", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0));// Looking along X axis, Z horz, Y vert
194 break;
195 case kCameraOrthoZOX:
196 fCamera.Setup(kCameraOrthoZOX, "OrthoZOX", REveVector(0.0,-1.0, 0.0), REveVector(1.0, 0.0, 0.0)); // Looking along Y axis, Z horz, X vert
197 break;
198 case kCameraOrthoXnOY:
199 fCamera.Setup(kCameraOrthoXnOY, "OrthoXnOY", REveVector(0.0, 0.0, -1.0), REveVector(0.0, 1.0, 0.0));// Looking along Z axis, -X horz, Y vert
200 break;
201 case kCameraOrthoXnOZ:
202 fCamera.Setup(kCameraOrthoXnOZ, "OrthoXnOZ", REveVector(0.0, 1.0, 0.0), REveVector(0.0, 0.0, 1.0));// Looking down Y axis, -X horz, Z vert
203 break;
204 case kCameraOrthoZnOY:
205 fCamera.Setup(kCameraOrthoZnOY, "OrthoZnOY", REveVector(1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0)); // Looking down X axis, -Z horz, Y vert
206 break;
207 case kCameraOrthoZnOX:
208 fCamera.Setup(kCameraOrthoZnOX, "OrthoZnOX", REveVector(0.0, 1.0, 0.0), REveVector(1.0, 0.0, 0.0)); // Looking down Y axis, -Z horz, X vert
209 break;
210 default:
211 Error("REveViewer::SetCurrentCamera", "invalid camera type");
212 return;
213 }
214}
215
216////////////////////////////////////////////////////////////////////////////////
217//
218// Set camera base matrix
219//
221{
222 fType = type;
223 fName = name;
224 fV1 = v1;
225 fV2 = v2;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229///
230// Stream camera info
231//
232int REveViewer::REveCamera::WriteCoreJson(nlohmann::json &j, Int_t /*rnr_offset*/)
233{
234 nlohmann::json out;
235 out["type"] = fName;
236 out["V1"] = {fV1.fX, fV1.fY, fV1.fZ};
237 out["V2"] = {fV2.fX, fV2.fY, fV2.fZ};
238
239 j["camera"] = out;
240
241 return 0;
242}
243
244////////////////////////////////////////////////////////////////////////////////
245
246REveViewerList::REveViewerList(const std::string &n, const std::string &t) :
247 REveElement (n, t),
248 fShowTooltip (kTRUE),
249
250 fBrightness(0),
251 fUseLightColorSet(kFALSE)
252{
253 // Constructor.
254
255 SetChildClass(TClass::GetClass<REveViewer>());
256 Connect();
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Destructor.
261
266
267////////////////////////////////////////////////////////////////////////////////
268/// Call base-class implementation.
269/// If compound is open and compound of the new element is not set,
270/// the el's compound is set to this.
271
276
277////////////////////////////////////////////////////////////////////////////////
278/// Decompoundofy el, call base-class version.
279
281{
282 // This was needed as viewer was in EveWindowManager hierarchy, too.
283 // el->DecParentIgnoreCnt();
284
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Decompoundofy children, call base-class version.
290
292{
293 // This was needed as viewer was in EveWindowManager hierarchy, too.
294 // el->DecParentIgnoreCnt();
295 // for (auto &c: fChildren)
296 // {
297 // c->DecParentIgnoreCnt();
298 // }
299
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Connect to TGLViewer class-signals.
305
307{
308 // TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
309 // "REveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
310
311 // TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
312 // "REveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
313
314 // TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
315 // "REveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
316
317 // TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
318 // "REveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
319
320 // TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
321 // "REveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
322
323 // TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
324 // "REveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Disconnect from TGLViewer class-signals.
329
331{
332 // TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
333 // this, "OnMouseOver(TObject*,UInt_t)");
334
335 // TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
336 // this, "OnReMouseOver(TObject*,UInt_t)");
337
338 // TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
339 // this, "OnUnMouseOver(TObject*,UInt_t)");
340
341 // TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
342 // this, "OnClicked(TObject*,UInt_t,UInt_t)");
343
344 // TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
345 // this, "OnReClicked(TObject*,UInt_t,UInt_t)");
346
347 // TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
348 // this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// Repaint viewers that are tagged as changed.
353
354void REveViewerList::RepaintChangedViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
355{
356 //for (auto &c: fChildren) {
357 // TGLViewer* glv = ((REveViewer*)c)->GetGLViewer();
358 // if (glv->IsChanged())
359 // {
360 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
361 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
362
363 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
364
365 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
366 // }
367 //}
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Repaint all viewers.
372
373void REveViewerList::RepaintAllViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
374{
375 // for (auto &c: fChildren) {
376 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
377
378 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
379 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
380
381 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
382
383 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
384 // }
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// Delete annotations from all viewers.
389
391{
392 // for (auto &c: fChildren) {
393 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
394 // glv->DeleteOverlayAnnotations();
395 // }
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Callback done from a REveScene destructor allowing proper
400/// removal of the scene from affected viewers.
401
403{
404 for (auto &viewer: fChildren) {
405 for (auto &j: viewer->RefChildren()) {
407 if (sinfo->GetScene() == scene)
408 viewer->RemoveElement(sinfo);
409 }
410 }
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Show / hide tooltip for various MouseOver events.
415/// Must be called from slots where sender is TGLEventHandler.
416
418{
419 if (fShowTooltip)
420 {
421 // TGLViewer *glw = dynamic_cast<TGLViewer*>((TQObject*) gTQSender);
422 // TGLEventHandler *glh = (TGLEventHandler*) glw->GetEventHandler();
423 // if (REX::gEve->GetHighlight()->NumChildren() == 1)
424 // {
425 // TString title(REX::gEve->GetHighlight()->FirstChild()->GetHighlightTooltip());
426 // if ( ! title.IsNull())
427 // glh->TriggerTooltip(title);
428 // }
429 // else
430 // {
431 // glh->RemoveTooltip();
432 // }
433 }
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Set color brightness.
438
443
444////////////////////////////////////////////////////////////////////////////////
445/// Switch background color.
446
448{
450 // To implement something along the lines of:
451 // BeginChanges on EveWorld; // Here or in the calling function
452 // for (auto &c: fChildren) {
453 // REveViewer* v = (REveViewer *)c;
454 // if ( fUseLightColorSet)
455 // c->UseLightColorSet();
456 // else
457 // c->UseDarkColorSet();
458 // }
459 // EndChanges on EveWorld;
460}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
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 Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
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.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
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:226
void RemoveElementsLocal() override
Decompoundofy children, call base-class version.
void AddElement(REveElement *el) override
Call base-class implementation.
~REveViewerList() override
Destructor.
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 SetColorBrightness(Float_t b)
Set color brightness.
void RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint all viewers.
virtual void Disconnect()
Disconnect from TGLViewer class-signals.
void RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint viewers that are tagged as changed.
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 Setup(ECameraType type, const std::string &name, REveVector v1, REveVector v2)
int WriteCoreJson(nlohmann::json &j, Int_t)
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.
void SetCameraType(ECameraType t)
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.
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Definition TROOT.cxx:3118
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
REveVectorT< Float_t > REveVector