Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RBrowserWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2021-01-22
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
15#include <algorithm>
16
17#include "TSystem.h"
18#include "TBufferJSON.h"
19
20
21using namespace std::string_literals;
22using namespace ROOT::Experimental;
23
24
25///////////////////////////////////////////////////////////////
26/// Returns string which can be send to browser client to set/change
27/// title of the widget tab
28
30{
31 std::vector<std::string> args = { GetName(), GetTitle(), Browsable::RElement::GetPathAsString(GetPath()) };
32
33 return "SET_TITLE:"s + TBufferJSON::ToJSON(&args).Data();
34}
35
36///////////////////////////////////////////////////////////////
37/// Constructor
38
40{
41 GetMap().emplace(kind, this);
42}
43
44///////////////////////////////////////////////////////////////
45/// Destructor
46
48{
49 auto &map = GetMap();
50 auto iter = std::find_if(map.begin(), map.end(),
51 [this](const ProvidersMap_t::value_type &pair) { return this == pair.second; });
52
53 if (iter != map.end())
54 map.erase(iter);
55}
56
57///////////////////////////////////////////////////////////////
58/// Returns static map of existing providers
59
61{
63 return mMap;
64}
65
66///////////////////////////////////////////////////////////////
67/// Create specified widget
68
69std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidget(const std::string &kind, const std::string &name)
70{
71 auto &map = GetMap();
72 auto iter = map.find(kind);
73 if (iter == map.end()) {
74 // try to load necessary libraries
75 if (kind == "geom"s)
76 gSystem->Load("libROOTBrowserGeomWidget");
77 else if (kind == "tree"s)
78 gSystem->Load("libROOTBrowserTreeWidget");
79 else if (kind == "tcanvas"s)
80 gSystem->Load("libROOTBrowserTCanvasWidget");
81 else if (kind == "rcanvas"s)
82 gSystem->Load("libROOTBrowserRCanvasWidget");
83 iter = map.find(kind);
84 if (iter == map.end())
85 return nullptr;
86 }
87 return iter->second->Create(name);
88}
89
90///////////////////////////////////////////////////////////////
91/// Create specified widget for existing object
92
93std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr<Browsable::RElement> &element)
94{
95 auto &map = GetMap();
96 auto iter = map.find(kind);
97 if (iter == map.end()) {
98 // try to load necessary libraries
99 if (kind == "geom"s)
100 gSystem->Load("libROOTBrowserGeomWidget");
101 else if (kind == "tree"s)
102 gSystem->Load("libROOTBrowserTreeWidget");
103 else if (kind == "tcanvas"s)
104 gSystem->Load("libROOTBrowserTCanvasWidget");
105 else if (kind == "rcanvas"s)
106 gSystem->Load("libROOTBrowserRCanvasWidget");
107 iter = map.find(kind);
108 if (iter == map.end())
109 return nullptr;
110 }
111 return iter->second->CreateFor(name, element);
112}
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:159
std::map< std::string, RBrowserWidgetProvider * > ProvidersMap_t
static std::shared_ptr< RBrowserWidget > CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr< Browsable::RElement > &element)
Create specified widget for existing object.
static std::shared_ptr< RBrowserWidget > CreateWidget(const std::string &kind, const std::string &name)
Create specified widget.
static ProvidersMap_t & GetMap()
Returns static map of existing providers.
RBrowserWidgetProvider(const std::string &kind)
Constructor.
const std::string & GetName() const
const Browsable::RElementPath_t & GetPath() const
std::string SendWidgetTitle()
Returns string which can be send to browser client to set/change title of the widget tab.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:75
const char * Data() const
Definition TString.h:380
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1858