28using namespace std::string_literals;
45 if (!
gROOT->IsWebDisplayBatch()) {
47 fWebWindow->SetDefaultPage(
"file:rootui5sys/geom/index.html");
58 fDesc.SetPreferredOffline(
gEnv->GetValue(
"WebGui.PreferredOffline", 0) != 0);
60 fDesc.SetBuildShapes(
gEnv->GetValue(
"WebGui.GeomBuildShapes", 1));
62 fDesc.AddSignalHandler(
this, [
this](
const std::string &kind) {
ProcessSignal(kind); });
73 fDesc.RemoveSignalHandler(
this);
87 fDesc.Build(mgr, volname);
125 std::string user_args =
"";
127 user_args =
"{ nobrowser: true }";
129 user_args =
"{ show_columns: true }";
135 if ((
fWebWindow->NumConnections(
true) == 0) || always_start_new_browser)
178 std::vector<int> *stack{
nullptr}, res;
182 res =
fDesc.MakeStackByIds(*stack);
199 if (!
fDesc.HasDrawData())
200 fDesc.ProduceDrawData();
203 fDesc.ProduceSearchData();
205 auto json0 =
fDesc.GetDrawJson();
206 auto json1 =
fDesc.GetSearchJson();
214 if (first_time || json1.empty())
227 fDesc.SetDrawOptions(opt);
246 if (connid && (width <= 0) && (height <= 0)) {
254 if (!
fDesc.HasDrawData())
255 fDesc.ProduceDrawData();
257 std::string json =
fDesc.GetDrawJson();
258 if (json.find(
"GDRAW:") != 0) {
259 printf(
"GDRAW missing!!!!\n");
273 if (arg ==
"GETDRAW") {
277 }
else if (arg ==
"QUIT_ROOT") {
281 }
else if (arg.compare(0, 9,
"HCHANNEL:") == 0) {
283 int chid = std::stoi(arg.substr(9));
289 }
else if (arg.compare(0, 4,
"GET:") == 0) {
294 auto nodeid =
fDesc.FindNodeId(stack);
296 std::string json{
"SHAPE:"};
298 fDesc.ProduceDrawingFor(nodeid, json);
302 }
else if (arg.compare(0, 10,
"HIGHLIGHT:") == 0) {
304 if (stack &&
fDesc.SetHighlightedItem(*stack))
305 fDesc.IssueSignal(
this,
"HighlightItem");
306 }
else if (arg.compare(0, 6,
"IMAGE:") == 0) {
307 auto separ = arg.find(
"::", 6);
308 if (separ == std::string::npos)
311 std::string fname = arg.substr(6, separ - 6);
317 fname += std::to_string(cnt);
319 }
while (!
gSystem->AccessPathName(fname.c_str()));
324 std::ofstream ofs(fname);
328 printf(
"Image file %s size %d has been created\n", fname.c_str(), (
int)binary.
Length());
330 }
else if (arg.compare(0, 4,
"CFG:") == 0) {
332 if (
fDesc.ChangeConfiguration(arg.substr(4)))
335 }
else if (arg ==
"RELOAD") {
339 }
else if (arg.compare(0, 9,
"ACTIVATE:") == 0) {
340 fDesc.SetActiveItem(arg.substr(9));
341 fDesc.IssueSignal(
this,
"ActiveItem");
342 }
else if (arg.compare(0, 11,
"INFOACTIVE:") == 0) {
344 }
else if (arg.compare(0, 11,
"HIDE_ITEMS:") == 0) {
346 bool changed =
false;
348 for (
auto &itemname : *items)
349 if (
fDesc.SetPhysNodeVisibility(itemname,
false))
353 fDesc.IssueSignal(
this,
"NodeVisibility");
355 }
else if (arg ==
"SAVEMACRO") {
378 if ((kind ==
"SelectTop") || (kind ==
"NodeVisibility")) {
380 }
else if (kind ==
"ChangeSearch") {
381 auto json =
fDesc.GetSearchJson();
386 }
else if (kind ==
"ClearSearch") {
389 }
else if (kind ==
"HighlightItem") {
390 auto stack =
fDesc.GetHighlightedItem();
393 }
else if (kind ==
"ClickItem") {
395 auto stack =
fDesc.GetClickedItem();
396 auto info =
fDesc.MakeNodeInfo(stack);
410 std::ofstream fs(fname);
413 std::string prefix =
" ";
415 fs <<
"std::shared_ptr<ROOT::RGeomViewer> rgeom_viewer;\n\n";
417 auto p = fname.find(
'.');
419 fs <<
"void " << fname.substr(0, p) <<
"()\n";
424 fs << prefix <<
"gGeoManager->SetVisLevel(" <<
fGeoManager->GetVisLevel() <<
");\n";
426 fs << prefix <<
"// geometry is too large, please provide import like:\n";
427 fs << prefix <<
"// TGeoManager::Import(\"filename.root\");\n";
430 fs << prefix <<
"\n";
432 fs << prefix <<
"rgeom_viewer = std::make_shared<ROOT::RGeomViewer>(gGeoManager";
437 fDesc.SavePrimitive(fs,
"rgeom_viewer->Description().");
439 fs << prefix <<
"rgeom_viewer->SetShowHierarchy(" << (
fShowHierarchy ?
"true" :
"false") <<
");\n";
440 fs << prefix <<
"rgeom_viewer->SetShowColumns(" << (
fShowColumns ?
"true" :
"false") <<
");\n";
442 fs << prefix <<
"\n";
444 fs << prefix <<
"rgeom_viewer->Show();\n";
448 printf(
"Macro %s has been created\n", fname.c_str());
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
RGeomViewer(TGeoManager *mgr=nullptr, const std::string &volname="")
constructor
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...
void SetGeometry(TGeoManager *mgr, const std::string &volname="")
assign new geometry to the viewer
std::vector< int > GetStackFromJson(const std::string &json, bool node_ids=false)
convert JSON into stack array
virtual ~RGeomViewer()
destructor
void SendGeometry(unsigned connid=0, bool first_time=false)
Send data for principal geometry draw Should be used when essential settings were changed in geometry...
std::string GetWindowAddr() const
Return web window address (name) used for geometry viewer.
std::shared_ptr< RGeomHierarchy > fWebHierarchy
! web handle for hierarchy part
void WebWindowDisconnect(unsigned connid)
Process disconnect event Clear cache data and dependent connections.
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.
bool fShowHierarchy
! if hierarchy visible by default
bool GetShowColumns() const
void SaveAsMacro(const std::string &fname)
Save viewer configuration as macro.
std::shared_ptr< RWebWindow > fWebWindow
! web window to show geometry
void Update()
Update geometry drawings in all web displays.
void ProcessSignal(const std::string &)
Process signal from geom description when it changed by any means.
bool GetShowHierarchy() const
Returns default hierarchy browser visibility.
void SetDrawOptions(const std::string &opt)
Configures draw option for geometry Normally has effect before first drawing of the geometry When geo...
TGeoManager * fGeoManager
! geometry to show
std::string GetWindowUrl(bool remote)
Return web window URL which can be used for connection See ROOT::RWebWindow::GetUrl docu for more det...
bool fShowColumns
! show columns in hierarchy
std::string fSelectedVolume
! name of selected volume
void WebWindowCallback(unsigned connid, const std::string &arg)
Process data from client.
bool fInfoActive
! true when info page active and node info need to be provided
void SetOnlyVolume(TGeoVolume *vol)
Draw only specified volume, special case when volume stored without valid geomanager.
void SelectVolume(const std::string &volname)
Select visible top volume, all other volumes will be disabled.
void SaveImage(const std::string &fname="geometry.png", int width=0, int height=0)
Produce PNG image of the geometry If web-browser is shown and drawing completed, image is requested f...
RGeomDescription fDesc
! geometry description, send to the client as first message
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
const std::string & GetWidgetKind() const
returns widget kind
static bool ProduceImage(const std::string &fname, const std::string &json, int width=800, int height=600, const char *batch_file=nullptr)
Produce image file using JSON data as source Invokes JSROOT drawing functionality in headless browser...
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)
@ kSkipTypeInfo
do not store typenames in JSON
@ 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)
The manager class for any TGeo geometry.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
const char * Data() const
RLogChannel & RGeomLog()
Log channel for Geomviewer diagnostics.