Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
webwindow.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webgui
3/// \ingroup webwidgets
4/// Use of `bootstrap` framework together with RWebWindow class.
5///
6/// In webwindow.cxx RWebWindow created
7/// In `dist` directory HTML files generated with bootstrap are placed
8/// One also can see usage of embed TWebCanvas in such application
9///
10/// \macro_code
11///
12/// \author Sergey Linev
13
14#include <ROOT/RWebWindow.hxx>
15
16#include "TCanvas.h"
17#include "TWebCanvas.h"
18#include "TTimer.h"
19
20std::shared_ptr<ROOT::RWebWindow> window;
21
22TCanvas *canvas = nullptr;
23TH1I *hist = nullptr;
24
25int counter = 0;
26
27void ProcessData(unsigned connid, const std::string &arg)
28{
29 printf("Get msg %s \n", arg.c_str());
30
31 counter++;
32
33 if (arg == "get_text") {
34 // send arbitrary text message
35 window->Send(connid, TString::Format("Message%d", counter).Data());
36 } else if (arg == "get_binary") {
37 // send float array as binary
38 float arr[10];
39 for (int n = 0; n < 10; ++n)
40 arr[n] = counter;
41 window->SendBinary(connid, arr, sizeof(arr));
42 } else if (arg == "halt") {
43 // terminate ROOT
44 window->TerminateROOT();
45 } else if (arg.compare(0, 8, "channel:") == 0) {
46 int chid = std::stoi(arg.substr(8));
47 printf("Get channel request %d\n", chid);
48 auto web_imp = dynamic_cast<TWebCanvas *>(canvas->GetCanvasImp());
49 web_imp->ShowWebWindow({ window, connid, chid });
50 }
51}
52
53void update_canvas()
54{
55 hist->FillRandom("gaus", 5000);
56 canvas->Modified();
57 canvas->Update();
58}
59
60void webwindow()
61{
62 // create window
63 window = ROOT::RWebWindow::Create();
64
65 // create TCanvas with pre-configure web display
66 canvas = TWebCanvas::CreateWebCanvas("Canvas1", "Example of web canvas");
67
68
69 hist = new TH1I("hpx", "Test histogram", 40, -5, 5);
70 hist->FillRandom("gaus", 10000);
71 canvas->Add(hist);
72
73 // start regular fill of histogram and update of canvas
74 auto timer = new TTimer("update_canvas()", 2000, kFALSE);
75 timer->TurnOn();
76
77
78 // configure default html page
79 // either HTML code can be specified or just name of file after 'file:' prefix
80 std::string fdir = __FILE__;
81 auto pos = fdir.find("webwindow.cxx");
82 if (pos > 0)
83 fdir.resize(pos);
84 else
85 fdir = "./";
86 window->SetDefaultPage("file:" + fdir + "dist/index.html");
87
88 // this is call-back, invoked when message received from client
89 window->SetDataCallBack(ProcessData);
90
91 window->SetGeometry(1200, 800); // configure predefined geometry
92
93 window->Show();
94}
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
The Canvas class.
Definition TCanvas.h:23
TCanvasImp * GetCanvasImp() const override
Definition TCanvas.h:158
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2488
1-D histogram with an int per channel (see TH1 documentation)
Definition TH1.h:568
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition TH1.cxx:3500
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7342
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with speicified draw option When.
Definition TPad.cxx:418
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
Basic TCanvasImp ABI implementation for Web-based Graphics Provides painting of main ROOT classes in ...
Definition TWebCanvas.h:35
static TCanvas * CreateWebCanvas(const char *name, const char *title, UInt_t width=1200, UInt_t height=800)
Create TCanvas and assign TWebCanvas implementation to it Canvas is not displayed automatically,...
const Int_t n
Definition legend1.C:16