28using namespace std::string_literals;
36 fWebWindow->SetDefaultPage(
"file:rootui5sys/eve7/geom.html");
65 fSelectedVolume = volname;
67 fDesc.Build(mgr, volname);
78 if (volname != fSelectedVolume)
79 SetGeometry(fGeoManager, volname);
89 std::string user_args =
"";
90 if (!GetShowHierarchy()) user_args =
"{ nobrowser: true }";
91 fWebWindow->SetUserArgs(user_args);
93 if ((fWebWindow->NumConnections(
true) == 0) || always_start_new_browser)
94 fWebWindow->Show(args);
104 if (!fWebWindow)
return "";
105 return fWebWindow->GetAddr();
113 fWebWindow->Send(0,
"RELOAD");
121 std::vector<int> *stack{
nullptr}, res;
124 if (node_ids) res = fDesc.MakeStackByIds(*stack);
139 if (!fDesc.HasDrawData())
140 fDesc.CollectVisibles();
142 auto &json = fDesc.GetDrawJson();
146 fWebWindow->Send(connid, json);
156 fDesc.SetDrawOptions(opt);
157 unsigned connid = fWebWindow->GetConnectionId();
159 fWebWindow->Send(connid,
"DROPT:"s + opt);
169 unsigned connid = fWebWindow->GetConnectionId();
171 fWebWindow->Send(connid,
"IMAGE:"s + fname);
179 printf(
"Recv %s\n", arg.substr(0,100).c_str());
181 if (arg ==
"GETDRAW") {
183 SendGeometry(connid);
185 }
else if (arg ==
"QUIT_ROOT") {
187 fWebWindow->TerminateROOT();
189 }
else if (arg.compare(0, 7,
"SEARCH:") == 0) {
191 std::string query = arg.substr(7);
193 std::string hjson, json;
195 auto nmatches = fDesc.SearchVisibles(query, hjson, json);
197 printf(
"Searches %s found %d hjson %d json %d\n", query.c_str(), nmatches, (
int) hjson.length(), (
int) json.length());
200 fWebWindow->Send(connid, hjson);
203 fWebWindow->Send(connid, json);
205 }
else if (arg.compare(0,4,
"GET:") == 0) {
208 auto stack = GetStackFromJson(arg.substr(4));
210 auto nodeid = fDesc.FindNodeId(stack);
212 std::string json{
"SHAPE:"};
214 fDesc.ProduceDrawingFor(nodeid, json);
216 printf(
"Produce shape for stack json %d\n", (
int) json.length());
218 fWebWindow->Send(connid, json);
220 }
else if (arg.compare(0, 6,
"GVREQ:") == 0) {
222 auto req = TBufferJSON::FromJSON<REveGeomRequest>(arg.substr(6));
224 if (req && (req->oper ==
"HOVER")) {
225 if ((req->path.size() > 0 ) && (req->path[0] !=
"OFF"))
226 req->stack = fDesc.MakeStackByPath(req->path);
228 }
else if (req && (req->oper ==
"HIGHL")) {
229 if (req->stack.size() > 0)
230 req->path = fDesc.MakePathByStack(req->stack);
232 }
else if (req && (req->oper ==
"INFO")) {
234 auto info = fDesc.MakeNodeInfo(req->path);
248 }
else if ((arg.compare(0, 7,
"SETVI0:") == 0) || (arg.compare(0, 7,
"SETVI1:") == 0)) {
251 auto nodeid = std::stoi(arg.substr(7));
253 bool selected = (arg[5] ==
'1');
255 if (fDesc.ChangeNodeVisibility(nodeid, selected)) {
258 std::string json0 = fDesc.ProduceModifyReply(nodeid);
261 fWebWindow->Send(connid, json0);
263 if (selected && fDesc.IsPrincipalEndNode(nodeid)) {
267 std::string json{
"APPND:"};
269 if (fDesc.ProduceDrawingFor(nodeid, json,
true)) {
271 printf(
"Send appending JSON %d\n", (
int) json.length());
273 fWebWindow->Send(connid, json);
275 }
else if (selected) {
281 auto json = fDesc.ProcessBrowserRequest();
282 if (json.length() > 0) fWebWindow->Send(connid, json);
284 SendGeometry(connid);
287 }
else if (arg.compare(0,6,
"BRREQ:") == 0) {
291 if (!fDesc.IsBuild()) fDesc.Build(fGeoManager);
293 auto json = fDesc.ProcessBrowserRequest(arg.substr(6));
294 if (json.length() > 0) fWebWindow->Send(connid, json);
295 }
else if (arg.compare(0,6,
"IMAGE:") == 0) {
296 auto separ = arg.find(
"::",6);
297 if (separ == std::string::npos)
return;
299 std::string fname = arg.substr(6, separ-6);
304 if (cnt++>0) fname += std::to_string(cnt);
311 std::ofstream ofs(fname);
315 printf(
"Image file %s size %d has been created\n", fname.c_str(), (
int) binary.
Length());
317 }
else if (arg.compare(0,4,
"CFG:") == 0) {
319 if (fDesc.ChangeConfiguration(arg.substr(4)))
320 SendGeometry(connid);
322 }
else if (arg ==
"RELOAD") {
324 SendGeometry(connid);
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
R__EXTERN TSystem * gSystem
void SetJsonComp(int comp=0)
Set JSON compression level for data transfer.
void SetBuildShapes(int lvl=1)
Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client,...
void SetPreferredOffline(bool on)
Set preference of offline operations.
void SaveImage(const std::string &fname="geometry.png")
Produce PNG image of drawn geometry Drawing should be completed at the moment Executed asynchronous -...
void SelectVolume(const std::string &volname)
Select visible top volume, all other volumes will be disabled.
void Update()
Update geometry drawings in all web displays.
void SendGeometry(unsigned connid)
Send data for principal geometry draw.
std::string GetWindowAddr() const
Return URL address of web window used for geometry viewer.
std::shared_ptr< RWebWindow > fWebWindow
! web window to show geometry
REveGeomDescription fDesc
! geometry description, send to the client as first message
REveGeomViewer(TGeoManager *mgr=nullptr, const std::string &volname="")
constructor
void WebWindowCallback(unsigned connid, const std::string &arg)
receive data from client
std::vector< int > GetStackFromJson(const std::string &json, bool node_ids=false)
convert JSON into stack array
virtual ~REveGeomViewer()
destructor
void SetDrawOptions(const std::string &opt)
Configures draw option for geometry Normally has effect before first drawing of the geometry When geo...
void SetGeometry(TGeoManager *mgr, const std::string &volname="")
assign new geometry to the viewer
void Show(const RWebDisplayArgs &args="", bool always_start_new_browser=false)
Show or update geometry in web window If web browser already started - just refresh drawing like "rel...
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString Decode(const char *data)
Decode a base64 string date into a generic TString.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
@ kSameSuppression
zero suppression plus compress many similar values together
static Bool_t FromJSON(T *&obj, const char *json)
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
The manager class for any TGeo geometry.
const char * Data() const
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
RLogChannel & EveLog()
Log channel for Eve diagnostics.