27 using namespace std::string_literals;
32 ROOT::Experimental::REveGeomViewer::REveGeomViewer(TGeoManager *mgr,
const std::string &volname)
34 fWebWindow = RWebWindow::Create();
35 fWebWindow->SetDefaultPage(
"file:rootui5sys/eve7/geom.html");
38 fWebWindow->SetDataCallBack([
this](
unsigned connid,
const std::string &arg) { this->WebWindowCallback(connid, arg); });
39 fWebWindow->SetGeometry(900, 700);
40 fWebWindow->SetConnLimit(1);
41 fWebWindow->SetMaxQueueLength(30);
43 fDesc.SetPreferredOffline(gEnv->GetValue(
"WebGui.PreferredOffline",0) != 0);
44 fDesc.SetJsonComp(gEnv->GetValue(
"WebGui.JsonComp", TBufferJSON::kSkipTypeInfo + TBufferJSON::kNoSpaces));
45 fDesc.SetBuildShapes(gEnv->GetValue(
"WebGui.GeomBuildShapes", 1));
47 if (mgr) SetGeometry(mgr, volname);
53 ROOT::Experimental::REveGeomViewer::~REveGeomViewer()
61 void ROOT::Experimental::REveGeomViewer::SetGeometry(TGeoManager *mgr,
const std::string &volname)
64 fSelectedVolume = volname;
66 fDesc.Build(mgr, volname);
75 void ROOT::Experimental::REveGeomViewer::SelectVolume(
const std::string &volname)
77 if (volname != fSelectedVolume)
78 SetGeometry(fGeoManager, volname);
86 void ROOT::Experimental::REveGeomViewer::Show(
const RWebDisplayArgs &args,
bool always_start_new_browser)
88 std::string user_args =
"";
89 if (!GetShowHierarchy()) user_args =
"{ nobrowser: true }";
90 fWebWindow->SetUserArgs(user_args);
92 if ((fWebWindow->NumConnections(
true) == 0) || always_start_new_browser)
93 fWebWindow->Show(args);
99 void ROOT::Experimental::REveGeomViewer::Update()
101 fWebWindow->Send(0,
"RELOAD");
107 std::vector<int> ROOT::Experimental::REveGeomViewer::GetStackFromJson(
const std::string &json,
bool node_ids)
109 std::vector<int> *stack{
nullptr}, res;
111 if (TBufferJSON::FromJSON(stack, json.c_str())) {
112 if (node_ids) res = fDesc.MakeStackByIds(*stack);
116 R__ERROR_HERE(
"webeve") <<
"Fail convert " << json <<
" into vector<int>";
125 void ROOT::Experimental::REveGeomViewer::SendGeometry(
unsigned connid)
127 if (!fDesc.HasDrawData())
128 fDesc.CollectVisibles();
130 auto &json = fDesc.GetDrawJson();
132 printf(
"Produce geometry JSON %d\n", (
int) json.length());
134 fWebWindow->Send(connid, json);
142 void ROOT::Experimental::REveGeomViewer::SetDrawOptions(
const std::string &opt)
144 fDesc.SetDrawOptions(opt);
146 fWebWindow->Send(0,
"DROPT:"s + opt);
154 void ROOT::Experimental::REveGeomViewer::SaveImage(
const std::string &fname)
156 unsigned connid = fWebWindow->GetConnectionId();
158 fWebWindow->Send(connid,
"IMAGE:"s + fname);
164 void ROOT::Experimental::REveGeomViewer::WebWindowCallback(
unsigned connid,
const std::string &arg)
166 printf(
"Recv %s\n", arg.substr(0,100).c_str());
168 if (arg ==
"GETDRAW") {
170 SendGeometry(connid);
172 }
else if (arg ==
"QUIT_ROOT") {
174 fWebWindow->TerminateROOT();
176 }
else if (arg.compare(0, 7,
"SEARCH:") == 0) {
178 std::string query = arg.substr(7);
180 std::string hjson, json;
182 auto nmatches = fDesc.SearchVisibles(query, hjson, json);
184 printf(
"Searches %s found %d hjson %d json %d\n", query.c_str(), nmatches, (int) hjson.length(), (int) json.length());
187 fWebWindow->Send(connid, hjson);
190 fWebWindow->Send(connid, json);
192 }
else if (arg.compare(0,4,
"GET:") == 0) {
195 auto stack = GetStackFromJson(arg.substr(4));
197 auto nodeid = fDesc.FindNodeId(stack);
199 std::string json{
"SHAPE:"};
201 fDesc.ProduceDrawingFor(nodeid, json);
203 printf(
"Produce shape for stack json %d\n", (
int) json.length());
205 fWebWindow->Send(connid, json);
207 }
else if (arg.compare(0, 6,
"GVREQ:") == 0) {
209 auto req = TBufferJSON::FromJSON<REveGeomRequest>(arg.substr(6));
211 if (req && (req->oper ==
"HOVER")) {
212 if (req->path !=
"OFF")
213 req->stack = fDesc.MakeStackByPath(req->path);
215 }
else if (req && (req->oper ==
"HIGHL")) {
216 if (req->stack.size() > 0)
217 req->path = fDesc.MakePathByStack(req->stack);
219 }
else if (req && (req->oper ==
"INFO")) {
221 auto info = fDesc.MakeNodeInfo(req->path);
223 fWebWindow->Send(connid,
"NINFO:"s + TBufferJSON::ToJSON(info.get(), (fDesc.GetJsonComp() % 5) + TBufferJSON::kSameSuppression).Data());
233 fWebWindow->Send(connid,
"GVRPL:"s + TBufferJSON::ToJSON(req.get(), TBufferJSON::kSkipTypeInfo + TBufferJSON::kNoSpaces).Data());
235 }
else if ((arg.compare(0, 7,
"SETVI0:") == 0) || (arg.compare(0, 7,
"SETVI1:") == 0)) {
238 auto nodeid = std::stoi(arg.substr(7));
240 bool selected = (arg[5] ==
'1');
242 if (fDesc.ChangeNodeVisibility(nodeid, selected)) {
245 std::string json0 = fDesc.ProduceModifyReply(nodeid);
248 fWebWindow->Send(connid, json0);
250 if (selected && fDesc.IsPrincipalEndNode(nodeid)) {
254 std::string json{
"APPND:"};
256 if (fDesc.ProduceDrawingFor(nodeid, json,
true)) {
258 printf(
"Send appending JSON %d\n", (
int) json.length());
260 fWebWindow->Send(connid, json);
262 }
else if (selected) {
268 auto json = fDesc.ProcessBrowserRequest();
269 if (json.length() > 0) fWebWindow->Send(connid, json);
271 SendGeometry(connid);
274 }
else if (arg.compare(0,6,
"BRREQ:") == 0) {
278 if (!fDesc.IsBuild()) fDesc.Build(fGeoManager);
280 auto json = fDesc.ProcessBrowserRequest(arg.substr(6));
281 if (json.length() > 0) fWebWindow->Send(connid, json);
282 }
else if (arg.compare(0,6,
"IMAGE:") == 0) {
283 auto separ = arg.find(
"::",6);
284 if (separ == std::string::npos)
return;
286 std::string fname = arg.substr(6, separ-6);
291 if (cnt++>0) fname += std::to_string(cnt);
293 }
while (!gSystem->AccessPathName(fname.c_str()));
296 TString binary = TBase64::Decode(arg.c_str() + separ + 2);
298 std::ofstream ofs(fname);
299 ofs.write(binary.Data(), binary.Length());
302 printf(
"Image file %s size %d has been created\n", fname.c_str(), (int) binary.Length());
304 }
else if (arg.compare(0,4,
"CFG:") == 0) {
306 if (fDesc.ChangeConfiguration(arg.substr(4)))
307 SendGeometry(connid);
309 }
else if (arg ==
"RELOAD") {
311 SendGeometry(connid);