27using namespace std::string_literals;
35 fWebWindow->SetDefaultPage(
"file:rootui5sys/eve7/geom.html");
64 fSelectedVolume = volname;
66 fDesc.Build(mgr, volname);
77 if (volname != fSelectedVolume)
78 SetGeometry(fGeoManager, volname);
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);
103 fWebWindow->Send(0,
"RELOAD");
111 std::vector<int> *stack{
nullptr}, res;
114 if (node_ids) res = fDesc.MakeStackByIds(*stack);
129 if (!fDesc.HasDrawData())
130 fDesc.CollectVisibles();
132 auto &
json = fDesc.GetDrawJson();
136 fWebWindow->Send(connid,
json);
146 fDesc.SetDrawOptions(opt);
147 unsigned connid = fWebWindow->GetConnectionId();
149 fWebWindow->Send(connid,
"DROPT:"s + opt);
159 unsigned connid = fWebWindow->GetConnectionId();
161 fWebWindow->Send(connid,
"IMAGE:"s + fname);
169 printf(
"Recv %s\n", arg.substr(0,100).c_str());
171 if (arg ==
"GETDRAW") {
173 SendGeometry(connid);
175 }
else if (arg ==
"QUIT_ROOT") {
177 fWebWindow->TerminateROOT();
179 }
else if (arg.compare(0, 7,
"SEARCH:") == 0) {
181 std::string query = arg.substr(7);
183 std::string hjson,
json;
185 auto nmatches = fDesc.SearchVisibles(query, hjson,
json);
187 printf(
"Searches %s found %d hjson %d json %d\n", query.c_str(), nmatches, (
int) hjson.length(), (
int)
json.length());
190 fWebWindow->Send(connid, hjson);
193 fWebWindow->Send(connid,
json);
195 }
else if (arg.compare(0,4,
"GET:") == 0) {
198 auto stack = GetStackFromJson(arg.substr(4));
200 auto nodeid = fDesc.FindNodeId(stack);
202 std::string
json{
"SHAPE:"};
204 fDesc.ProduceDrawingFor(nodeid,
json);
206 printf(
"Produce shape for stack json %d\n", (
int)
json.length());
208 fWebWindow->Send(connid,
json);
210 }
else if (arg.compare(0, 6,
"GVREQ:") == 0) {
212 auto req = TBufferJSON::FromJSON<REveGeomRequest>(arg.substr(6));
214 if (req && (req->oper ==
"HOVER")) {
215 if (req->path !=
"OFF")
216 req->stack = fDesc.MakeStackByPath(req->path);
218 }
else if (req && (req->oper ==
"HIGHL")) {
219 if (req->stack.size() > 0)
220 req->path = fDesc.MakePathByStack(req->stack);
222 }
else if (req && (req->oper ==
"INFO")) {
224 auto info = fDesc.MakeNodeInfo(req->path);
238 }
else if ((arg.compare(0, 7,
"SETVI0:") == 0) || (arg.compare(0, 7,
"SETVI1:") == 0)) {
241 auto nodeid = std::stoi(arg.substr(7));
243 bool selected = (arg[5] ==
'1');
245 if (fDesc.ChangeNodeVisibility(nodeid, selected)) {
248 std::string json0 = fDesc.ProduceModifyReply(nodeid);
251 fWebWindow->Send(connid, json0);
253 if (selected && fDesc.IsPrincipalEndNode(nodeid)) {
257 std::string
json{
"APPND:"};
259 if (fDesc.ProduceDrawingFor(nodeid,
json,
true)) {
261 printf(
"Send appending JSON %d\n", (
int)
json.length());
263 fWebWindow->Send(connid,
json);
265 }
else if (selected) {
271 auto json = fDesc.ProcessBrowserRequest();
272 if (
json.length() > 0) fWebWindow->Send(connid,
json);
274 SendGeometry(connid);
277 }
else if (arg.compare(0,6,
"BRREQ:") == 0) {
281 if (!fDesc.IsBuild()) fDesc.Build(fGeoManager);
283 auto json = fDesc.ProcessBrowserRequest(arg.substr(6));
284 if (
json.length() > 0) fWebWindow->Send(connid,
json);
285 }
else if (arg.compare(0,6,
"IMAGE:") == 0) {
286 auto separ = arg.find(
"::",6);
287 if (separ == std::string::npos)
return;
289 std::string fname = arg.substr(6, separ-6);
294 if (
cnt++>0) fname += std::to_string(
cnt);
301 std::ofstream ofs(fname);
305 printf(
"Image file %s size %d has been created\n", fname.c_str(), (
int) binary.
Length());
307 }
else if (arg.compare(0,4,
"CFG:") == 0) {
309 if (fDesc.ChangeConfiguration(arg.substr(4)))
310 SendGeometry(connid);
312 }
else if (arg ==
"RELOAD") {
314 SendGeometry(connid);
#define R__ERROR_HERE(GROUP)
#define R__DEBUG_HERE(GROUP)
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::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)
static Bool_t FromJSON(T *&obj, const char *json)
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
@ kSameSuppression
zero suppression plus compress many similar values together
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.
static constexpr double s
basic_json<> json
default JSON class