28using namespace std::string_literals;
37 if (!
gROOT->IsWebDisplayBatch()) {
39 fWebWindow->SetDefaultPage(
"file:rootui5sys/geom/index.html");
50 fDesc.SetPreferredOffline(
gEnv->GetValue(
"WebGui.PreferredOffline", 0) != 0);
52 fDesc.SetBuildShapes(
gEnv->GetValue(
"WebGui.GeomBuildShapes", 1));
54 fDesc.AddSignalHandler(
this, [
this](
const std::string &kind) {
ProcessSignal(kind); });
65 fDesc.RemoveSignalHandler(
this);
76 fDesc.Build(mgr, volname);
114 std::string user_args =
"";
116 user_args =
"{ nobrowser: true }";
118 user_args =
"{ show_columns: true }";
124 if ((
fWebWindow->NumConnections(
true) == 0) || always_start_new_browser)
166 std::vector<int> *stack{
nullptr}, res;
170 res =
fDesc.MakeStackByIds(*stack);
187 if (!
fDesc.HasDrawData())
188 fDesc.ProduceDrawData();
191 fDesc.ProduceSearchData();
193 auto json0 =
fDesc.GetDrawJson();
194 auto json1 =
fDesc.GetSearchJson();
202 if (first_time || json1.empty())
215 fDesc.SetDrawOptions(opt);
243 if (!
fDesc.HasDrawData())
244 fDesc.ProduceDrawData();
246 std::string json =
fDesc.GetDrawJson();
247 if (json.find(
"GDRAW:") != 0) {
248 printf(
"GDRAW missing!!!!\n");
262 if (arg ==
"GETDRAW") {
266 }
else if (arg ==
"QUIT_ROOT") {
270 }
else if (arg.compare(0, 9,
"HCHANNEL:") == 0) {
272 int chid = std::stoi(arg.substr(9));
278 }
else if (arg.compare(0, 4,
"GET:") == 0) {
283 auto nodeid =
fDesc.FindNodeId(stack);
285 std::string json{
"SHAPE:"};
287 fDesc.ProduceDrawingFor(nodeid, json);
291 }
else if (arg.compare(0, 10,
"HIGHLIGHT:") == 0) {
293 if (stack &&
fDesc.SetHighlightedItem(*stack))
294 fDesc.IssueSignal(
this,
"HighlightItem");
295 }
else if (arg.compare(0, 6,
"IMAGE:") == 0) {
296 auto separ = arg.find(
"::", 6);
297 if (separ == std::string::npos)
300 std::string fname = arg.substr(6, separ - 6);
306 fname += std::to_string(cnt);
308 }
while (!
gSystem->AccessPathName(fname.c_str()));
313 std::ofstream ofs(fname);
317 printf(
"Image file %s size %d has been created\n", fname.c_str(), (
int)binary.
Length());
319 }
else if (arg.compare(0, 4,
"CFG:") == 0) {
321 if (
fDesc.ChangeConfiguration(arg.substr(4)))
324 }
else if (arg ==
"RELOAD") {
328 }
else if (arg.compare(0, 9,
"ACTIVATE:") == 0) {
329 fDesc.SetActiveItem(arg.substr(9));
330 fDesc.IssueSignal(
this,
"ActiveItem");
331 }
else if (arg.compare(0, 11,
"INFOACTIVE:") == 0) {
333 }
else if (arg.compare(0, 11,
"HIDE_ITEMS:") == 0) {
335 bool changed =
false;
337 for (
auto &itemname : *items)
338 if (
fDesc.SetPhysNodeVisibility(itemname,
false))
342 fDesc.IssueSignal(
this,
"NodeVisibility");
344 }
else if (arg ==
"SAVEMACRO") {
367 if ((kind ==
"SelectTop") || (kind ==
"NodeVisibility")) {
369 }
else if (kind ==
"ChangeSearch") {
370 auto json =
fDesc.GetSearchJson();
375 }
else if (kind ==
"ClearSearch") {
378 }
else if (kind ==
"HighlightItem") {
379 auto stack =
fDesc.GetHighlightedItem();
382 }
else if (kind ==
"ClickItem") {
384 auto stack =
fDesc.GetClickedItem();
385 auto info =
fDesc.MakeNodeInfo(stack);
399 std::ofstream
fs(fname);
402 std::string prefix =
" ";
404 auto p = fname.find(
'.');
406 fs <<
"void " << fname.substr(0, p) <<
"() { " << std::endl;
408 fs <<
"{" << std::endl;
413 fs << prefix <<
"gGeoManager->SetVisLevel(" <<
fGeoManager->GetVisLevel() <<
");" << std::endl;
415 fs << prefix <<
"// geometry is too large, please provide import like:" << std::endl << std::endl;
416 fs << prefix <<
"// TGeoManager::Import(\"filename.root\");" << std::endl;
421 fs << prefix <<
"auto viewer = std::make_shared<ROOT::RGeomViewer>(gGeoManager";
424 fs <<
");" << std::endl;
426 fDesc.SavePrimitive(
fs,
"viewer->Description().");
428 fs << prefix <<
"viewer->SetShowHierarchy(" << (
fShowHierarchy ?
"true" :
"false") <<
");" << std::endl;
429 fs << prefix <<
"viewer->SetShowColumns(" << (
fShowColumns ?
"true" :
"false") <<
");" << std::endl;
433 fs << prefix <<
"viewer->Show();" << std::endl << std::endl;
435 fs << prefix <<
"ROOT::Experimental::RDirectory::Heap().Add(\"geom_viewer\", viewer);" << std::endl;
437 fs <<
"}" << std::endl;
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
R__EXTERN TSystem * gSystem
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Experimental::RLogChannel & RGeomLog()
Log channel for Geomviewer diagnostics.