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
4/*************************************************************************
5 * Copyright (C) 1995-2021, 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 "RBrowserWidget.hxx"
13
14#include <algorithm>
15
16#include "TSystem.h"
17#include "TBufferJSON.h"
18
19using namespace std::string_literals;
20using namespace ROOT;
21
22///////////////////////////////////////////////////////////////
23/// Returns string which can be send to browser client to set/change
24/// title of the widget tab
25
27{
28 std::vector<std::string> args = { GetName(), GetTitle(), Browsable::RElement::GetPathAsString(GetPath()) };
29
30 return "SET_TITLE:"s + TBufferJSON::ToJSON(&args).Data();
31}
32
33///////////////////////////////////////////////////////////////
34/// Constructor
35
37{
38 GetMap().emplace(kind, this);
39}
40
41///////////////////////////////////////////////////////////////
42/// Destructor
43
45{
46 auto &map = GetMap();
47 auto iter = std::find_if(map.begin(), map.end(),
48 [this](const ProvidersMap_t::value_type &pair) { return this == pair.second; });
49
50 if (iter != map.end())
51 map.erase(iter);
52}
53
54///////////////////////////////////////////////////////////////
55/// Returns static map of existing providers
56
62
63///////////////////////////////////////////////////////////////
64/// Returns provider for specified kind
65
67{
68 auto &map = GetMap();
69 auto iter = map.find(kind);
70 if (iter == map.end()) {
71 // try to load necessary libraries
72 if (kind == "geom"s)
73 gSystem->Load("libROOTBrowserGeomWidget");
74 else if (kind == "tree"s)
75 gSystem->Load("libROOTBrowserTreeWidget");
76 else if (kind == "tcanvas"s)
77 gSystem->Load("libROOTBrowserTCanvasWidget");
78 else if (kind == "rcanvas"s)
79 gSystem->Load("libROOTBrowserRCanvasWidget");
80 iter = map.find(kind);
81 if (iter == map.end())
82 return nullptr;
83 }
84 return iter->second;
85}
86
87
88///////////////////////////////////////////////////////////////
89/// Create specified widget
90
91std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidget(const std::string &kind, const std::string &name)
92{
93 auto provider = GetProvider(kind);
94
95 return provider ? provider->Create(name) : nullptr;
96}
97
98///////////////////////////////////////////////////////////////
99/// Create specified widget for existing object
100
101std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::CreateWidgetFor(const std::string &kind, const std::string &name, std::shared_ptr<Browsable::RElement> &element)
102{
103 auto provider = GetProvider(kind);
104
105 return provider ? provider->CreateFor(name, element) : nullptr;
106}
107
108///////////////////////////////////////////////////////////////
109/// Check if catch window can be identified and normal widget can be created
110/// Used for TCanvas created in macro and catch by RBrowser
111
112std::shared_ptr<RBrowserWidget> RBrowserWidgetProvider::DetectCatchedWindow(const std::string &kind, RWebWindow &win)
113{
114 auto provider = GetProvider(kind);
115
116 return provider ? provider->DetectWindow(win) : nullptr;
117}
118
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 win
char name[80]
Definition TGX11.cxx:148
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
static std::string GetPathAsString(const RElementPath_t &path)
Converts element path back to string.
Definition RElement.cxx:162
std::map< std::string, RBrowserWidgetProvider * > ProvidersMap_t
static RBrowserWidgetProvider * GetProvider(const std::string &kind)
Returns provider for specified kind.
static std::shared_ptr< RBrowserWidget > DetectCatchedWindow(const std::string &kind, RWebWindow &win)
Check if catch window can be identified and normal widget can be created Used for TCanvas created in ...
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.
Represents web window, which can be shown in web browser or any other supported environment.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:77
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1872