Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveManager.hxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
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 #ifndef ROOT7_REveManager
13 #define ROOT7_REveManager
14 
15 #include <ROOT/REveElement.hxx>
16 
17 #include <ROOT/RWebDisplayArgs.hxx>
18 
19 #include "TSysEvtHandler.h"
20 #include "TTimer.h"
21 
22 #include <memory>
23 #include <unordered_map>
24 
25 class TMap;
26 class TExMap;
27 class TMacro;
28 class TFolder;
29 class TGeoManager;
30 
31 namespace ROOT {
32 namespace Experimental {
33 
34 class REveSelection;
35 class REveViewer;
36 class REveViewerList;
37 class REveScene;
38 class REveSceneList;
39 
40 class RWebWindow;
41 class REveGeomViewer;
42 
43 class REveManager
44 {
45  REveManager(const REveManager&); // Not implemented
46  REveManager& operator=(const REveManager&); // Not implemented
47 
48 public:
49  class RRedrawDisabler {
50  private:
51  RRedrawDisabler(const RRedrawDisabler &); // Not implemented
52  RRedrawDisabler &operator=(const RRedrawDisabler &); // Not implemented
53 
54  REveManager *fMgr{nullptr};
55 
56  public:
57  RRedrawDisabler(REveManager *m) : fMgr(m)
58  {
59  if (fMgr)
60  fMgr->DisableRedraw();
61  }
62  virtual ~RRedrawDisabler()
63  {
64  if (fMgr)
65  fMgr->EnableRedraw();
66  }
67  };
68 
69  class RExceptionHandler : public TStdExceptionHandler {
70  public:
71  RExceptionHandler() : TStdExceptionHandler() { Add(); }
72  virtual ~RExceptionHandler() { Remove(); }
73 
74  virtual EStatus Handle(std::exception& exc);
75 
76  ClassDef(RExceptionHandler, 0);
77  };
78 
79  struct Conn
80  {
81  unsigned fId{0};
82 
83  Conn() = default;
84  Conn(unsigned int cId) : fId(cId) {}
85  };
86 
87 protected:
88  RExceptionHandler *fExcHandler{nullptr}; //!< exception handler
89 
90  TMap *fVizDB{nullptr};
91  Bool_t fVizDBReplace{kFALSE};
92  Bool_t fVizDBUpdate{kFALSE};
93 
94  TMap *fGeometries{nullptr}; // TODO: use std::map<std::string, std::unique_ptr<TGeoManager>>
95  TMap *fGeometryAliases{nullptr}; // TODO: use std::map<std::string, std::string>
96 
97  TFolder *fMacroFolder{nullptr};
98 
99  REveScene *fWorld{nullptr};
100 
101  REveViewerList *fViewers{nullptr};
102  REveSceneList *fScenes{nullptr};
103 
104  REveScene *fGlobalScene{nullptr};
105  REveScene *fEventScene{nullptr};
106 
107  Int_t fRedrawDisabled{0};
108  Bool_t fFullRedraw{kFALSE};
109  Bool_t fResetCameras{kFALSE};
110  Bool_t fDropLogicals{kFALSE};
111  Bool_t fKeepEmptyCont{kFALSE};
112  Bool_t fTimerActive{kFALSE};
113  TTimer fRedrawTimer;
114 
115  // ElementId management
116  std::unordered_map<ElementId_t, REveElement*> fElementIdMap;
117  ElementId_t fLastElementId{0};
118  ElementId_t fNumElementIds{0};
119  ElementId_t fMaxElementIds{std::numeric_limits<ElementId_t>::max()};
120 
121  // Selection / highlight elements
122  REveElement *fSelectionList{nullptr};
123  REveSelection *fSelection{nullptr};
124  REveSelection *fHighlight{nullptr};
125 
126  std::shared_ptr<ROOT::Experimental::RWebWindow> fWebWindow;
127  std::vector<Conn> fConnList;
128 
129  void WindowConnect(unsigned connid);
130  void WindowData(unsigned connid, const std::string &arg);
131  void WindowDisconnect(unsigned connid);
132 
133 public:
134  REveManager(); // (Bool_t map_window=kTRUE, Option_t* opt="FI");
135  virtual ~REveManager();
136 
137  RExceptionHandler *GetExcHandler() const { return fExcHandler; }
138 
139  REveSelection *GetSelection() const { return fSelection; }
140  REveSelection *GetHighlight() const { return fHighlight; }
141 
142  REveSceneList *GetScenes() const { return fScenes; }
143  REveViewerList *GetViewers() const { return fViewers; }
144 
145  REveScene *GetGlobalScene() const { return fGlobalScene; }
146  REveScene *GetEventScene() const { return fEventScene; }
147 
148  REveScene *GetWorld() const { return fWorld; }
149 
150  REveViewer *SpawnNewViewer(const char *name, const char *title = "");
151  REveScene *SpawnNewScene(const char *name, const char *title = "");
152 
153  TFolder *GetMacroFolder() const { return fMacroFolder; }
154  TMacro *GetMacro(const char *name) const;
155 
156  void DisableRedraw() { ++fRedrawDisabled; }
157  void EnableRedraw() { --fRedrawDisabled; if (fRedrawDisabled <= 0) Redraw3D(); }
158 
159  void Redraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE)
160  {
161  if (fRedrawDisabled <= 0 && !fTimerActive) RegisterRedraw3D();
162  if (resetCameras) fResetCameras = kTRUE;
163  if (dropLogicals) fDropLogicals = kTRUE;
164  }
165  void RegisterRedraw3D();
166  void DoRedraw3D();
167  void FullRedraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE);
168 
169  void ClearAllSelections();
170 
171  Bool_t GetKeepEmptyCont() const { return fKeepEmptyCont; }
172  void SetKeepEmptyCont(Bool_t k) { fKeepEmptyCont = k; }
173 
174  void AddElement(REveElement *element, REveElement* parent = nullptr);
175  void AddGlobalElement(REveElement *element, REveElement* parent = nullptr);
176 
177  void RemoveElement(REveElement* element, REveElement* parent);
178 
179  REveElement* FindElementById (ElementId_t id) const;
180  void AssignElementId (REveElement* element);
181  void PreDeleteElement(REveElement* element);
182 
183  // VizDB - Visualization-parameter data-base.
184  Bool_t InsertVizDBEntry(const TString& tag, REveElement* model,
185  Bool_t replace, Bool_t update);
186  Bool_t InsertVizDBEntry(const TString& tag, REveElement* model);
187  REveElement* FindVizDBEntry (const TString& tag);
188 
189  void LoadVizDB(const TString& filename, Bool_t replace, Bool_t update);
190  void LoadVizDB(const TString& filename);
191  void SaveVizDB(const TString& filename);
192 
193  Bool_t GetVizDBReplace() const { return fVizDBReplace; }
194  Bool_t GetVizDBUpdate () const { return fVizDBUpdate; }
195  void SetVizDBReplace(Bool_t r) { fVizDBReplace = r; }
196  void SetVizDBUpdate (Bool_t u) { fVizDBUpdate = u; }
197 
198 
199  // Geometry management.
200  TGeoManager* GetGeometry(const TString& filename);
201  TGeoManager* GetGeometryByAlias(const TString& alias);
202  TGeoManager* GetDefaultGeometry();
203  void RegisterGeometryAlias(const TString& alias, const TString& filename);
204 
205  void ClearROOTClassSaved();
206 
207  void AddLocation(const std::string& name, const std::string& path);
208  void SetDefaultHtmlPage(const std::string& path);
209  void SetClientVersion(const std::string& version);
210 
211  static REveManager* Create();
212  static void Terminate();
213 
214  // Access to internals, needed for low-level control in advanced
215  // applications.
216 
217  void EnforceTimerActive (Bool_t ta) { fTimerActive = ta; }
218 
219  // void Send(void* buff, unsigned connid);
220  void Send(unsigned connid, const std::string &data);
221  void SendBinary(unsigned connid, const void *data, std::size_t len);
222 
223  void DestroyElementsOf(REveElement::List_t &els);
224 
225  void BroadcastElementsOf(REveElement::List_t &els);
226 
227  void Show(const RWebDisplayArgs &args = "");
228 
229  std::shared_ptr<REveGeomViewer> ShowGeometry(const RWebDisplayArgs &args = "");
230 };
231 
232 R__EXTERN REveManager* gEve;
233 
234 }}
235 
236 #endif