Logo ROOT  
Reference Guide
 
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
20using namespace std::string_literals;
21using namespace ROOT;
22
23///////////////////////////////////////////////////////////////
24/// Returns string which can be send to browser client to set/change
25/// title of the widget tab
26
28{
29 std::vector<std::string> args = { GetName(), GetTitle(), Browsable::RElement::GetPathAsString(GetPath()) };
30
31 return "SET_TITLE:"s + TBufferJSON::ToJSON(&args).Data();
32}
33
34///////////////////////////////////////////////////////////////
35/// Constructor
36
38{
39 GetMap().emplace(kind, this);
40}
41
42///////////////////////////////////////////////////////////////
43/// Destructor
44
46{
47 auto &map = GetMap();
48 auto iter = std::find_if(map.begin(), map.end(),
49 [this](const ProvidersMap_t::value_type &pair) { return this == pair.second; });
50
51 if (iter != map.end())
52 map.erase(iter);
53}
54
55///////////////////////////////////////////////////////////////
56/// Returns static map of existing providers
57
59{
61 return mMap;
62}
63
64///////////////////////////////////////////////////////////////
65/// Create specified widget
66
67std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidget(const std::string &kind, const std::string &name)
68{
69 auto &map = GetMap();
70 auto iter = map.find(kind);
71 if (iter == map.end()) {
72 // try to load necessary libraries
73 if (kind == "geom"s)
74 gSystem->Load("libROOTBrowserGeomWidget");
75 else if (kind == "tree"s)
76 gSystem->Load("libROOTBrowserTreeWidget");
77 else if (kind == "tcanvas"s)
78 gSystem->Load("libROOTBrowserTCanvasWidget");
79 else if (kind == "rcanvas"s)
80 gSystem->Load("libROOTBrowserRCanvasWidget");
81 iter = map.find(kind);
82 if (iter == map.end())
83 return nullptr;
84 }
85 return iter->second->Create(name);
86}
87
88///////////////////////////////////////////////////////////////
89/// Create specified widget for existing object
90
91std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr<Browsable::RElement> &element)
92{
93 auto &map = GetMap();
94 auto iter = map.find(kind);
95 if (iter == map.end()) {
96 // try to load necessary libraries
97 if (kind == "geom"s)
98 gSystem->Load("libROOTBrowserGeomWidget");
99 else if (kind == "tree"s)
100 gSystem->Load("libROOTBrowserTreeWidget");
101 else if (kind == "tcanvas"s)
102 gSystem->Load("libROOTBrowserTCanvasWidget");
103 else if (kind == "rcanvas"s)
104 gSystem->Load("libROOTBrowserRCanvasWidget");
105 iter = map.find(kind);
106 if (iter == map.end())
107 return nullptr;
108 }
109 return iter->second->CreateFor(name, element);
110}
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:160
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.
virtual ~RBrowserWidgetProvider()
Destructor.
RBrowserWidgetProvider(const std::string &kind)
Constructor.
const Browsable::RElementPath_t & GetPath() const
virtual std::string GetTitle()
const std::string & GetName() 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:376
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1857
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.