Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RGeomHierarchy.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, 3.03.2023
2
3/*************************************************************************
4 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
12
13#include <ROOT/RWebWindow.hxx>
14
15#include "TBufferJSON.h"
16
17using namespace std::string_literals;
18
19using namespace ROOT;
20
21//////////////////////////////////////////////////////////////////////////////////////////////
22/// constructor
23
24RGeomHierarchy::RGeomHierarchy(RGeomDescription &desc, bool use_server_threads) : fDesc(desc)
25{
27 fWebWindow->SetDataCallBack([this](unsigned connid, const std::string &arg) { WebWindowCallback(connid, arg); });
28
29 fWebWindow->SetDefaultPage("file:rootui5sys/geom/index.html");
30 fWebWindow->SetGeometry(600, 900); // configure predefined window geometry
31
32 if (use_server_threads)
33 fWebWindow->UseServerThreads();
34
35 fDesc.AddSignalHandler(this, [this](const std::string &kind) { ProcessSignal(kind); });
36}
37
38//////////////////////////////////////////////////////////////////////////////////////////////
39/// destructor
40
42{
44}
45
46//////////////////////////////////////////////////////////////////////////////////////////////
47/// Process data from client
48
49void RGeomHierarchy::WebWindowCallback(unsigned connid, const std::string &arg)
50{
51 if (arg.compare(0, 6, "BRREQ:") == 0) {
52 // central place for processing browser requests
53 auto json = fDesc.ProcessBrowserRequest(arg.substr(6));
54 if (json.length() > 0)
55 fWebWindow->Send(connid, json);
56 } else if (arg.compare(0, 7, "SEARCH:") == 0) {
57
58 std::string query = arg.substr(7);
59
60 if (!query.empty()) {
61 std::string hjson, json;
62 fDesc.SearchVisibles(query, hjson, json);
63 // send reply with appropriate header - NOFOUND, FOUND0:, FOUND1:
64 fWebWindow->Send(0, hjson);
65 // inform viewer that search is changed
66 if (fDesc.SetSearch(query, json))
67 fDesc.IssueSignal(this, json.empty() ? "ClearSearch" : "ChangeSearch");
68 } else {
69 fDesc.SetSearch(""s, ""s);
70 fDesc.IssueSignal(this, "ClearSearch");
71 }
72
73 auto connids = fWebWindow->GetConnections(connid);
74
75 for (auto id : connids)
76 fWebWindow->Send(id, "SETSR:"s + query);
77
78 } else if (arg.compare(0, 7, "SETTOP:") == 0) {
79 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
80 if (path && fDesc.SelectTop(*path)) {
81 fDesc.IssueSignal(this, "SelectTop");
82 auto connids = fWebWindow->GetConnections(connid);
83
84 for (auto id : connids)
85 fWebWindow->Send(id, "UPDATE"s);
86 }
87 } else if (arg.compare(0, 6, "HOVER:") == 0) {
88 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(6));
89 if (path) {
90 auto stack = fDesc.MakeStackByPath(*path);
91 if (fDesc.SetHighlightedItem(stack))
92 fDesc.IssueSignal(this, "HighlightItem");
93 }
94 } else if (arg.compare(0, 6, "CLICK:") == 0) {
95 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(6));
96 if (path) {
97 auto stack = fDesc.MakeStackByPath(*path);
98 if (fDesc.SetClickedItem(stack))
99 fDesc.IssueSignal(this, "ClickItem");
100 }
101 } else if ((arg.compare(0, 7, "SETVI0:") == 0) || (arg.compare(0, 7, "SETVI1:") == 0)) {
102 // change visibility for specified nodeid
103
104 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
105
106 bool on = (arg[5] == '1');
107
108 if (path && fDesc.ChangeNodeVisibility(*path, on))
109 fDesc.IssueSignal(this, "NodeVisibility");
110
111 } else if ((arg.compare(0, 5, "SHOW:") == 0) || (arg.compare(0, 5, "HIDE:") == 0)) {
112 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(5));
113 if (path && fDesc.SetPhysNodeVisibility(*path, arg.compare(0, 5, "SHOW:") == 0))
114 fDesc.IssueSignal(this, "NodeVisibility");
115 } else if (arg.compare(0, 6, "CLEAR:") == 0) {
116 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(6));
117 if (path && fDesc.ClearPhysNodeVisibility(*path))
118 fDesc.IssueSignal(this, "NodeVisibility");
119 } else if (arg == "CLEARALL"s) {
121 fDesc.IssueSignal(this, "NodeVisibility");
122 }
123}
124
125/////////////////////////////////////////////////////////////////////////////////
126/// Show hierarchy in web window
127
129{
130 if (args.GetWidgetKind().empty())
131 const_cast<RWebDisplayArgs *>(&args)->SetWidgetKind("RGeomHierarchy");
132
133 fWebWindow->SetUserArgs("{ show_columns: true, only_hierarchy: true }");
135}
136
137/////////////////////////////////////////////////////////////////////////////////
138/// Update client - reload hierarchy
139
141{
142 if (fWebWindow)
143 fWebWindow->Send(0, "RELOAD"s);
144}
145
146/////////////////////////////////////////////////////////////////////////////////
147/// Let browse to specified location
148
149void RGeomHierarchy::BrowseTo(const std::string &itemname)
150{
151 if (fWebWindow)
152 fWebWindow->Send(0, "ACTIV:"s + itemname);
153}
154
155/////////////////////////////////////////////////////////////////////////////////
156/// Process signals from geometry description object
157
158void RGeomHierarchy::ProcessSignal(const std::string &kind)
159{
160 if (kind == "HighlightItem") {
161 auto stack = fDesc.GetHighlightedItem();
162 auto path = fDesc.MakePathByStack(stack);
163 if (stack.empty())
164 path = {"__OFF__"}; // just clear highlight
165 if (fWebWindow)
166 fWebWindow->Send(0, "HIGHL:"s + TBufferJSON::ToJSON(&path).Data());
167 } else if (kind == "NodeVisibility") {
168 // visibility changed from RGeomViewer, update hierarchy
169 if (fWebWindow)
170 fWebWindow->Send(0, "UPDATE"s);
171 } else if (kind == "ActiveItem") {
173 }
174}
175
176//////////////////////////////////////////////////////////////////////////////////////////////
177/// Set handle which will be cleared when connection is closed
178/// Must be called after window is shown
179
180void RGeomHierarchy::ClearOnClose(const std::shared_ptr<void> &handle)
181{
182 if (fWebWindow)
183 fWebWindow->SetClearOnClose(handle);
184}
nlohmann::json json
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
std::string ProcessBrowserRequest(const std::string &req="")
Find description object for requested shape If not exists - will be created.
void IssueSignal(const void *handler, const std::string &kind)
Issue signal, which distributed on all handlers - excluding source handler.
bool SetSearch(const std::string &query, const std::string &json)
Change search query and belongs to it json string Returns true if any parameter was really changed.
bool SetHighlightedItem(const std::vector< int > &stack)
bool SelectTop(const std::vector< std::string > &path)
Select top node by path Used by the client to change active node Returns true if selected node was ch...
bool ChangeNodeVisibility(const std::vector< std::string > &path, bool on)
Change visibility for specified element Returns true if changes was performed.
bool ClearAllPhysVisibility()
Reset all custom visibility settings.
bool SetPhysNodeVisibility(const std::vector< std::string > &path, bool on=true)
Set visibility of physical node by path It overrules TGeo visibility flags - but only for specific ph...
bool ClearPhysNodeVisibility(const std::vector< std::string > &path)
Reset custom visibility of physical node by path.
int SearchVisibles(const std::string &find, std::string &hjson, std::string &json)
Search visible nodes for provided name If number of found elements less than 100, create description ...
std::vector< std::string > MakePathByStack(const std::vector< int > &stack)
Returns path string for provided stack.
void AddSignalHandler(const void *handler, RGeomSignalFunc_t func)
Add signal handler.
std::vector< int > MakeStackByPath(const std::vector< std::string > &path)
Produce stack based on string path Used to highlight geo volumes by browser hover event.
std::vector< int > GetHighlightedItem() const
void RemoveSignalHandler(const void *handler)
Remove signal handler.
std::string GetActiveItem() const
bool SetClickedItem(const std::vector< int > &stack)
void Show(const RWebDisplayArgs &args="")
Show hierarchy in web window.
void Update()
Update client - reload hierarchy.
RGeomHierarchy(RGeomDescription &desc, bool use_server_threads=false)
constructor
std::shared_ptr< RWebWindow > fWebWindow
! web window to show geometry
virtual ~RGeomHierarchy()
destructor
void ClearOnClose(const std::shared_ptr< void > &handle)
Set handle which will be cleared when connection is closed Must be called after window is shown.
void BrowseTo(const std::string &itemname)
Let browse to specified location.
void ProcessSignal(const std::string &kind)
Process signals from geometry description object.
void WebWindowCallback(unsigned connid, const std::string &arg)
Process data from client.
RGeomDescription & fDesc
! geometry description, shared with external
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
const std::string & GetWidgetKind() const
returns widget kind
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static unsigned ShowWindow(std::shared_ptr< RWebWindow > window, const RWebDisplayArgs &args="")
Static method to show web window Has to be used instead of RWebWindow::Show() when window potentially...
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:75
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...