Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebCanvas.h
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 7/12/2016
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_TWebCanvas
12#define ROOT_TWebCanvas
13
14#include "TCanvasImp.h"
15
16#include "TString.h"
17#include "TList.h"
18#include "TWebPadOptions.h"
19
20#include <ROOT/RWebWindow.hxx>
21
22#include <vector>
23#include <string>
24#include <queue>
25#include <functional>
26
27class TPad;
28class TPadWebSnapshot;
29class TWebPS;
30class TObjLink;
31
32class TWebCanvas : public TCanvasImp {
33
34public:
35 /// Function type for signals, invoked when canvas drawing or update is completed
36 using UpdatedSignal_t = std::function<void()>;
37
38 /// Function type for pad-related signals - like activate pad signal
39 using PadSignal_t = std::function<void(TPad *)>;
40
41 /// Function type for pad-click signals
42 using PadClickedSignal_t = std::function<void(TPad *, int, int)>;
43
44 /// Function type for signals, invoked when object is selected
45 using ObjectSelectSignal_t = std::function<void(TPad *, TObject *)>;
46
47protected:
48
49 /// Function called when pad painting produced
50 using PadPaintingReady_t = std::function<void(TPadWebSnapshot *)>;
51
52 struct WebConn {
53 unsigned fConnId{0}; ///<! connection id
54 Long64_t fSendVersion{0}; ///<! canvas version send to the client
55 Long64_t fDrawVersion{0}; ///<! canvas version drawn (confirmed) by client
56 std::queue<std::string> fSend; ///<! send queue, processed after sending draw data
57 WebConn(unsigned id) : fConnId(id) {}
58 };
59
60 std::vector<WebConn> fWebConn; ///<! connections
61
62 std::shared_ptr<ROOT::Experimental::RWebWindow> fWindow; ///!< configured display
63
64 Bool_t fReadOnly{true}; ///<! in read-only mode canvas cannot be changed from client side
65 Bool_t fHasSpecials{false}; ///<! has special objects which may require pad ranges
66 Long64_t fCanvVersion{1}; ///<! actual canvas version, changed with every new Modified() call
67 UInt_t fClientBits{0}; ///<! latest status bits from client like editor visible or not
68 TList fPrimitivesLists; ///<! list of lists of primitives, temporary collected during painting
69 Int_t fStyleDelivery{0}; ///<! gStyle delivery to clients: 0:never, 1:once, 2:always
70 Int_t fPaletteDelivery{1}; ///<! colors palette delivery 0:never, 1:once, 2:always, 3:per subpad
71 Int_t fPrimitivesMerge{100}; ///<! number of PS primitives, which will be merged together
72 Int_t fJsonComp{0}; ///<! compression factor for messages send to the client
73 std::string fCustomScripts; ///<! custom JavaScript code or URL on JavaScript files to load before start drawing
74 std::vector<std::string> fCustomClasses; ///<! list of custom classes, which can be delivered as is to client
75 Bool_t fCanCreateObjects{kTRUE}; ///<! indicates if canvas allowed to create extra objects for interactive painting
76 Bool_t fLongerPolling{kFALSE}; ///<! when true, make longer polling in blocking operations
77 Bool_t fProcessingData{kFALSE}; ///<! flag used to prevent blocking methods when process data is invoked
78 Bool_t fAsyncMode{kFALSE}; ///<! when true, methods like TCanvas::Update will never block
79
80 UpdatedSignal_t fUpdatedSignal; ///<! signal emitted when canvas updated or state is changed
81 PadSignal_t fActivePadChangedSignal; ///<! signal emitted when active pad changed in the canvas
82 PadClickedSignal_t fPadClickedSignal; ///<! signal emitted when simple mouse click performed on the pad
83 PadClickedSignal_t fPadDblClickedSignal; ///<! signal emitted when simple mouse click performed on the pad
84 ObjectSelectSignal_t fObjSelectSignal; ///<! signal emitted when new object selected in the pad
85
86 void Lock() override {}
87 void Unlock() override {}
88 Bool_t IsLocked() override { return kFALSE; }
89
90 Bool_t IsWeb() const override { return kTRUE; }
91 Bool_t PerformUpdate() override;
93
95 void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps = nullptr);
96 void CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t version, PadPaintingReady_t func);
97
98 Bool_t CheckPadModified(TPad *pad, Bool_t inc_version = kTRUE);
99
100 Bool_t AddToSendQueue(unsigned connid, const std::string &msg);
101
102 void CheckDataToSend(unsigned connid = 0);
103
105
106 virtual Bool_t IsJSSupportedClass(TObject *obj);
107
108 Bool_t IsFirstConn(unsigned connid) const { return (connid!=0) && (fWebConn.size()>0) && (fWebConn[0].fConnId == connid) ;}
109
110 void ShowCmd(const std::string &arg, Bool_t show);
111
112 void AssignStatusBits(UInt_t bits);
113
114 virtual Bool_t ProcessData(unsigned connid, const std::string &arg);
115
116 virtual Bool_t DecodePadOptions(const std::string &);
117
118 virtual Bool_t CanCreateObject(const std::string &) { return !IsReadOnly() && fCanCreateObjects; }
119
121
122 TObject *FindPrimitive(const std::string &id, TPad *pad = nullptr, TObjLink **padlnk = nullptr, TPad **objpad = nullptr);
123
124public:
125 TWebCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height, Bool_t readonly = kTRUE);
126 virtual ~TWebCanvas() = default;
127
128 void ShowWebWindow(const ROOT::Experimental::RWebDisplayArgs &user_args = "");
129
130 const std::shared_ptr<ROOT::Experimental::RWebWindow> &GetWebWindow() const { return fWindow; }
131
132 virtual Bool_t IsReadOnly() const { return fReadOnly; }
133
134 Int_t InitWindow() override;
135 void Close() override;
136 void Show() override;
137
138 UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override;
139
140 void ShowMenuBar(Bool_t show = kTRUE) override { ShowCmd("Menu", show); }
141 void ShowStatusBar(Bool_t show = kTRUE) override { ShowCmd("StatusBar", show); }
142 void ShowEditor(Bool_t show = kTRUE) override { ShowCmd("Editor", show); }
143 void ShowToolBar(Bool_t show = kTRUE) override { ShowCmd("ToolBar", show); }
144 void ShowToolTips(Bool_t show = kTRUE) override { ShowCmd("ToolTips", show); }
145
146
147 // web-canvas specific methods
148
149 void ActivateInEditor(TPad *pad, TObject *obj);
150
151 void ForceUpdate() override;
152
153
154 /*
155 virtual void Iconify() { }
156 virtual void SetStatusText(const char *text = 0, Int_t partidx = 0);
157 virtual void SetWindowPosition(Int_t x, Int_t y);
158 virtual void SetWindowSize(UInt_t w, UInt_t h);
159 virtual void SetWindowTitle(const char *newTitle);
160 virtual void SetCanvasSize(UInt_t w, UInt_t h);
161 virtual void RaiseWindow();
162 virtual void ReallyDelete();
163 */
164
165 Bool_t HasEditor() const override;
166 Bool_t HasMenuBar() const override;
167 Bool_t HasStatusBar() const override;
168 Bool_t HasToolBar() const override { return kFALSE; }
169 Bool_t HasToolTips() const override;
170
176
179
182
185
188
191
192 void SetCustomScripts(const std::string &src);
193
194 void AddCustomClass(const std::string &clname, bool with_derived = false);
195 bool IsCustomClass(const TClass *cl) const;
196
197 void SetAsyncMode(Bool_t on = kTRUE) { fAsyncMode = on; }
198 Bool_t IsAsyncMode() const { return fAsyncMode; }
199
200 static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression = 0);
201 static Int_t StoreCanvasJSON(TCanvas *c, const char *filename, const char *option = "");
202
203 static bool ProduceImage(TCanvas *c, const char *filename, Int_t width = 0, Int_t height = 0);
204
205 ClassDefOverride(TWebCanvas, 0) // Web-based implementation for TCanvasImp, read-only mode
206};
207
208#endif
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
include TDocParser_001 C image html pict1_TDocParser_001 png width
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
ABC describing GUI independent main window (with menubar, scrollbars and a drawing area).
Definition TCanvasImp.h:30
The Canvas class.
Definition TCanvas.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
The most important graphics class in the ROOT system.
Definition TPad.h:26
Basic string class.
Definition TString.h:136
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
Basic TCanvasImp ABI implementation for Web-based GUI Provides painting of main ROOT6 classes in web ...
Definition TWebCanvas.h:32
TVirtualPadPainter * CreatePadPainter() override
Creates web-based pad painter.
void ForceUpdate() override
Increment canvas version and force sending data to client - do not wit for reply.
Int_t GetPrimitivesMerge() const
Definition TWebCanvas.h:187
void AddCustomClass(const std::string &clname, bool with_derived=false)
Assign custom class.
Bool_t CheckPadModified(TPad *pad, Bool_t inc_version=kTRUE)
Returns true if any pad in the canvas were modified Reset modified flags, increment canvas version (i...
void ShowCmd(const std::string &arg, Bool_t show)
Function used to send command to browser to toggle menu, toolbar, editors, ...
Bool_t fCanCreateObjects
! indicates if canvas allowed to create extra objects for interactive painting
Definition TWebCanvas.h:75
std::string fCustomScripts
! custom JavaScript code or URL on JavaScript files to load before start drawing
Definition TWebCanvas.h:73
virtual Bool_t IsReadOnly() const
Definition TWebCanvas.h:132
virtual Bool_t IsJSSupportedClass(TObject *obj)
Returns kTRUE when object is fully supported on JSROOT side In ROOT7 Paint function will just return ...
void SetCustomScripts(const std::string &src)
Configures custom script for canvas.
ObjectSelectSignal_t fObjSelectSignal
! signal emitted when new object selected in the pad
Definition TWebCanvas.h:84
PadClickedSignal_t fPadClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:82
static bool ProduceImage(TCanvas *c, const char *filename, Int_t width=0, Int_t height=0)
Create image using batch (headless) capability of Chrome browser Supported png, jpeg,...
void SetActivePadChangedHandler(PadSignal_t func)
Definition TWebCanvas.h:172
void SetLongerPolling(Bool_t on)
Definition TWebCanvas.h:189
virtual Bool_t CanCreateObject(const std::string &)
Definition TWebCanvas.h:118
void SetStyleDelivery(Int_t val)
Definition TWebCanvas.h:180
const std::shared_ptr< ROOT::Experimental::RWebWindow > & GetWebWindow() const
Definition TWebCanvas.h:130
Int_t fPrimitivesMerge
! number of PS primitives, which will be merged together
Definition TWebCanvas.h:71
void ShowToolTips(Bool_t show=kTRUE) override
Definition TWebCanvas.h:144
void SetAsyncMode(Bool_t on=kTRUE)
Definition TWebCanvas.h:197
std::function< void()> UpdatedSignal_t
Function type for signals, invoked when canvas drawing or update is completed.
Definition TWebCanvas.h:36
void Show() override
Show canvas in browser window.
Bool_t HasToolBar() const override
Definition TWebCanvas.h:168
Bool_t WaitWhenCanvasPainted(Long64_t ver)
Wait when specified version of canvas was painted and confirmed by browser.
Bool_t IsWeb() const override
Definition TWebCanvas.h:90
void ShowMenuBar(Bool_t show=kTRUE) override
Definition TWebCanvas.h:140
std::vector< std::string > fCustomClasses
! list of custom classes, which can be delivered as is to client
Definition TWebCanvas.h:74
Bool_t IsAsyncMode() const
Definition TWebCanvas.h:198
static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression=0)
Create JSON painting output for given canvas Produce JSON can be used for offline drawing with JSROOT...
Bool_t HasStatusBar() const override
Returns kTRUE if web canvas has status bar.
void Close() override
Close web canvas - not implemented.
Bool_t HasMenuBar() const override
Returns kTRUE if web canvas has menu bar.
Int_t InitWindow() override
Initialize window for the web canvas At this place canvas is not yet register to the list of canvases...
void SetPadDblClickedHandler(PadClickedSignal_t func)
Definition TWebCanvas.h:174
void ActivateInEditor(TPad *pad, TObject *obj)
Activate object in editor in web browser.
std::vector< WebConn > fWebConn
! connections
Definition TWebCanvas.h:60
PadSignal_t fActivePadChangedSignal
! signal emitted when active pad changed in the canvas
Definition TWebCanvas.h:81
Bool_t GetLongerPolling() const
Definition TWebCanvas.h:190
void ShowWebWindow(const ROOT::Experimental::RWebDisplayArgs &user_args="")
Show canvas in specified place.
UInt_t fClientBits
! latest status bits from client like editor visible or not
Definition TWebCanvas.h:67
std::function< void(TPadWebSnapshot *)> PadPaintingReady_t
Function called when pad painting produced.
Definition TWebCanvas.h:50
Int_t fPaletteDelivery
! colors palette delivery 0:never, 1:once, 2:always, 3:per subpad
Definition TWebCanvas.h:70
void ShowToolBar(Bool_t show=kTRUE) override
Definition TWebCanvas.h:143
Bool_t fProcessingData
! flag used to prevent blocking methods when process data is invoked
Definition TWebCanvas.h:77
Bool_t HasToolTips() const override
Returns kTRUE if tooltips are activated in web canvas.
Bool_t AddToSendQueue(unsigned connid, const std::string &msg)
Add message to send queue for specified connection If connid == 0, message will be add to all connect...
Long64_t fCanvVersion
! actual canvas version, changed with every new Modified() call
Definition TWebCanvas.h:66
bool IsCustomClass(const TClass *cl) const
Checks if class belongs to custom.
void SetPadClickedHandler(PadClickedSignal_t func)
Definition TWebCanvas.h:173
void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps=nullptr)
Creates representation of the object for painting in web browser.
void AddColorsPalette(TPadWebSnapshot &master)
Add special canvas objects like colors list at selected palette.
void SetUpdatedHandler(UpdatedSignal_t func)
Definition TWebCanvas.h:171
std::function< void(TPad *, int, int)> PadClickedSignal_t
Function type for pad-click signals.
Definition TWebCanvas.h:42
virtual Bool_t DecodePadOptions(const std::string &)
Decode all pad options, which includes ranges plus objects options.
Bool_t PerformUpdate() override
if canvas or any subpad was modified, scan all primitives in the TCanvas and subpads and convert them...
Bool_t fLongerPolling
! when true, make longer polling in blocking operations
Definition TWebCanvas.h:76
void ShowStatusBar(Bool_t show=kTRUE) override
Definition TWebCanvas.h:141
void CheckDataToSend(unsigned connid=0)
Check if any data should be send to client If connid != 0, only selected connection will be checked.
void Unlock() override
Definition TWebCanvas.h:87
UpdatedSignal_t fUpdatedSignal
! signal emitted when canvas updated or state is changed
Definition TWebCanvas.h:80
Bool_t IsLocked() override
Definition TWebCanvas.h:88
Int_t fJsonComp
! compression factor for messages send to the client
Definition TWebCanvas.h:72
Bool_t IsFirstConn(unsigned connid) const
Definition TWebCanvas.h:108
Bool_t fReadOnly
!< configured display
Definition TWebCanvas.h:64
Bool_t fAsyncMode
! when true, methods like TCanvas::Update will never block
Definition TWebCanvas.h:78
void ShowEditor(Bool_t show=kTRUE) override
Definition TWebCanvas.h:142
Bool_t fHasSpecials
! has special objects which may require pad ranges
Definition TWebCanvas.h:65
void AssignStatusBits(UInt_t bits)
Assign clients bits.
virtual Bool_t ProcessData(unsigned connid, const std::string &arg)
Handle data from web browser Returns kFALSE if message was not processed.
std::function< void(TPad *)> PadSignal_t
Function type for pad-related signals - like activate pad signal.
Definition TWebCanvas.h:39
TPad * ProcessObjectOptions(TWebObjectOptions &item, TPad *pad)
Process data for single primitive Returns object pad if object was modified.
void SetCanCreateObjects(Bool_t on=kTRUE)
Definition TWebCanvas.h:177
static Int_t StoreCanvasJSON(TCanvas *c, const char *filename, const char *option="")
Create JSON painting output for given canvas and store into the file See TBufferJSON::ExportToFile() ...
void SetPrimitivesMerge(Int_t cnt)
Definition TWebCanvas.h:186
UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override
Returns window geometry including borders and menus.
std::shared_ptr< ROOT::Experimental::RWebWindow > fWindow
Definition TWebCanvas.h:62
void SetPaletteDelivery(Int_t val)
Definition TWebCanvas.h:183
void SetObjSelectHandler(ObjectSelectSignal_t func)
Definition TWebCanvas.h:175
std::function< void(TPad *, TObject *)> ObjectSelectSignal_t
Function type for signals, invoked when object is selected.
Definition TWebCanvas.h:45
Bool_t HasEditor() const override
Returns kTRUE if web canvas has graphical editor.
Int_t fStyleDelivery
! gStyle delivery to clients: 0:never, 1:once, 2:always
Definition TWebCanvas.h:69
PadClickedSignal_t fPadDblClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:83
void Lock() override
Definition TWebCanvas.h:86
TList fPrimitivesLists
! list of lists of primitives, temporary collected during painting
Definition TWebCanvas.h:68
void CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t version, PadPaintingReady_t func)
Create snapshot for pad and all primitives Callback function is used to create JSON in the middle of ...
Bool_t GetCanCreateObjects() const
Definition TWebCanvas.h:178
Int_t GetPaletteDelivery() const
Definition TWebCanvas.h:184
TObject * FindPrimitive(const std::string &id, TPad *pad=nullptr, TObjLink **padlnk=nullptr, TPad **objpad=nullptr)
Search of object with given id in list of primitives One could specify pad where search could be star...
virtual ~TWebCanvas()=default
Int_t GetStyleDelivery() const
Definition TWebCanvas.h:181
Class used to transport drawing options from the client.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
std::queue< std::string > fSend
! send queue, processed after sending draw data
Definition TWebCanvas.h:56
WebConn(unsigned id)
Definition TWebCanvas.h:57
unsigned fConnId
! connection id
Definition TWebCanvas.h:53
Long64_t fSendVersion
! canvas version send to the client
Definition TWebCanvas.h:54
Long64_t fDrawVersion
! canvas version drawn (confirmed) by client
Definition TWebCanvas.h:55