Warning, file /include/root/TWebCanvas.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_TWebCanvas
0012 #define ROOT_TWebCanvas
0013
0014 #include "TCanvasImp.h"
0015
0016 #include "TString.h"
0017 #include "TList.h"
0018 #include "TWebPadOptions.h"
0019
0020 #include <ROOT/RWebWindow.hxx>
0021
0022 #include <vector>
0023 #include <string>
0024 #include <queue>
0025 #include <functional>
0026 #include <map>
0027
0028 class TPad;
0029 class TPadWebSnapshot;
0030 class TWebPS;
0031 class TObjLink;
0032 class TExec;
0033 class TWebCanvasTimer;
0034
0035 class TWebCanvas : public TCanvasImp {
0036
0037 friend class TWebCanvasTimer;
0038
0039 public:
0040
0041 using UpdatedSignal_t = std::function<void()>;
0042
0043
0044 using PadSignal_t = std::function<void(TPad *)>;
0045
0046
0047 using PadClickedSignal_t = std::function<void(TPad *, int, int)>;
0048
0049
0050 using ObjectSelectSignal_t = std::function<void(TPad *, TObject *)>;
0051
0052 protected:
0053
0054
0055 using PadPaintingReady_t = std::function<void(TPadWebSnapshot *)>;
0056
0057 struct WebConn {
0058 unsigned fConnId{0};
0059 Long64_t fCheckedVersion{0};
0060 Long64_t fSendVersion{0};
0061 Long64_t fDrawVersion{0};
0062 UInt_t fLastSendHash{0};
0063 std::map<std::string, std::string> fCtrl;
0064 std::queue<std::string> fSend;
0065
0066 WebConn(unsigned id) : fConnId(id) {}
0067 bool is_batch() const { return fConnId == 0; }
0068 bool match(unsigned id) const { return !is_batch() && ((fConnId == id) || (id == 0)); }
0069 void reset()
0070 {
0071 fCheckedVersion = fSendVersion = fDrawVersion = 0;
0072 fLastSendHash = 0;
0073 }
0074 };
0075
0076 struct PadStatus {
0077 Long64_t fVersion{0};
0078 bool _detected{false};
0079 bool _modified{false};
0080 bool _has_specials{false};
0081 };
0082
0083 std::vector<WebConn> fWebConn;
0084 TWebCanvasTimer *fTimer{nullptr};
0085
0086 std::map<TPad*, PadStatus> fPadsStatus;
0087
0088 std::shared_ptr<ROOT::RWebWindow> fWindow;
0089
0090 Bool_t fReadOnly{kFALSE};
0091 Long64_t fCanvVersion{1};
0092 UInt_t fClientBits{0};
0093 std::vector<TPad *> fAllPads;
0094 Int_t fStyleDelivery{0};
0095 Int_t fPaletteDelivery{1};
0096 Int_t fPrimitivesMerge{100};
0097 Int_t fJsonComp{0};
0098 std::string fCustomScripts;
0099 std::vector<std::string> fCustomClasses;
0100 Bool_t fCanCreateObjects{kTRUE};
0101 Bool_t fLongerPolling{kFALSE};
0102 Bool_t fProcessingData{kFALSE};
0103 Bool_t fAsyncMode{kFALSE};
0104 Long64_t fStyleVersion{0};
0105 UInt_t fStyleHash{0};
0106 Long64_t fColorsVersion{0};
0107 UInt_t fColorsHash{0};
0108 Int_t fTF1UseSave{1};
0109 std::vector<int> fWindowGeometry;
0110 Bool_t fFixedSize{kFALSE};
0111
0112 UpdatedSignal_t fUpdatedSignal;
0113 PadSignal_t fActivePadChangedSignal;
0114 PadClickedSignal_t fPadClickedSignal;
0115 PadClickedSignal_t fPadDblClickedSignal;
0116 ObjectSelectSignal_t fObjSelectSignal;
0117
0118 void Lock() override {}
0119 void Unlock() override {}
0120 Bool_t IsLocked() override { return kFALSE; }
0121
0122 Bool_t IsWeb() const override { return kTRUE; }
0123 Bool_t PerformUpdate(Bool_t async) override;
0124 TVirtualPadPainter *CreatePadPainter() override;
0125
0126 UInt_t CalculateColorsHash();
0127 void AddColorsPalette(TPadWebSnapshot &master);
0128 void AddCustomFonts(TPadWebSnapshot &master);
0129
0130 void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps = nullptr);
0131 void CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t version, PadPaintingReady_t func);
0132
0133 void CheckPadModified(TPad *pad);
0134
0135 Bool_t CheckCanvasModified(bool force_modified = false);
0136
0137 void AddCtrlMsg(unsigned connid, const std::string &key, const std::string &value);
0138
0139 void AddSendQueue(unsigned connid, const std::string &msg);
0140
0141 Bool_t CheckDataToSend(unsigned connid = 0);
0142
0143 Bool_t WaitWhenCanvasPainted(Long64_t ver);
0144
0145 virtual Bool_t IsJSSupportedClass(TObject *obj, Bool_t many_primitives = kFALSE);
0146
0147 Bool_t IsFirstConn(unsigned connid) const { return (connid != 0) && (fWebConn.size() > 1) && (fWebConn[1].fConnId == connid); }
0148
0149 Bool_t IsFirstDrawn() const { return (fWebConn.size() > 1) && (fWebConn[1].fDrawVersion > 0); }
0150
0151 void ShowCmd(const std::string &arg, Bool_t show);
0152
0153 void AssignStatusBits(UInt_t bits);
0154
0155 virtual Bool_t ProcessData(unsigned connid, const std::string &arg);
0156
0157 virtual Bool_t DecodePadOptions(const std::string &, bool process_execs = false);
0158
0159 virtual Bool_t CanCreateObject(const std::string &) { return !IsReadOnly() && fCanCreateObjects; }
0160
0161 TPad *ProcessObjectOptions(TWebObjectOptions &item, TPad *pad, int idcnt = 1);
0162
0163 TObject *FindPrimitive(const std::string &id, int idcnt = 1, TPad *pad = nullptr, TObjLink **objlnk = nullptr, TPad **objpad = nullptr);
0164
0165 void ProcessExecs(TPad *pad, TExec *extra = nullptr);
0166
0167 void ProcessLinesForObject(TObject *obj, const std::string &lines);
0168
0169 public:
0170 TWebCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height, Bool_t readonly = kTRUE);
0171 ~TWebCanvas() override;
0172
0173 void ShowWebWindow(const ROOT::RWebDisplayArgs &user_args = "");
0174
0175 const std::shared_ptr<ROOT::RWebWindow> &GetWebWindow() const { return fWindow; }
0176
0177 virtual Bool_t IsReadOnly() const { return fReadOnly; }
0178
0179 Int_t InitWindow() override;
0180 void Close() override;
0181 void Show() override;
0182
0183 UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override;
0184
0185 void ShowMenuBar(Bool_t show = kTRUE) override { ShowCmd("Menu", show); }
0186 void ShowStatusBar(Bool_t show = kTRUE) override { ShowCmd("StatusBar", show); }
0187 void ShowEditor(Bool_t show = kTRUE) override { ShowCmd("Editor", show); }
0188 void ShowToolBar(Bool_t show = kTRUE) override { ShowCmd("ToolBar", show); }
0189 void ShowToolTips(Bool_t show = kTRUE) override { ShowCmd("ToolTips", show); }
0190
0191
0192
0193 void ActivateInEditor(TPad *pad, TObject *obj);
0194
0195 void ForceUpdate() override;
0196
0197 void SetWindowPosition(Int_t x, Int_t y) override;
0198 void SetWindowSize(UInt_t w, UInt_t h) override;
0199 void SetWindowTitle(const char *newTitle) override;
0200 void SetCanvasSize(UInt_t w, UInt_t h) override;
0201 void Iconify() override;
0202 void RaiseWindow() override;
0203
0204
0205
0206
0207
0208
0209 Bool_t HasEditor() const override;
0210 Bool_t HasMenuBar() const override;
0211 Bool_t HasStatusBar() const override;
0212 Bool_t HasToolBar() const override { return kFALSE; }
0213 Bool_t HasToolTips() const override;
0214
0215 void SetUpdatedHandler(UpdatedSignal_t func) { fUpdatedSignal = func; }
0216 void SetActivePadChangedHandler(PadSignal_t func) { fActivePadChangedSignal = func; }
0217 void SetPadClickedHandler(PadClickedSignal_t func) { fPadClickedSignal = func; }
0218 void SetPadDblClickedHandler(PadClickedSignal_t func) { fPadDblClickedSignal = func; }
0219 void SetObjSelectHandler(ObjectSelectSignal_t func) { fObjSelectSignal = func; }
0220
0221 void SetCanCreateObjects(Bool_t on = kTRUE) { fCanCreateObjects = on; }
0222 Bool_t GetCanCreateObjects() const { return fCanCreateObjects; }
0223
0224 void SetStyleDelivery(Int_t val) { fStyleDelivery = val; }
0225 Int_t GetStyleDelivery() const { return fStyleDelivery; }
0226
0227 void SetPaletteDelivery(Int_t val) { fPaletteDelivery = val; }
0228 Int_t GetPaletteDelivery() const { return fPaletteDelivery; }
0229
0230 void SetPrimitivesMerge(Int_t cnt) { fPrimitivesMerge = cnt; }
0231 Int_t GetPrimitivesMerge() const { return fPrimitivesMerge; }
0232
0233 void SetLongerPolling(Bool_t on) { fLongerPolling = on; }
0234 Bool_t GetLongerPolling() const { return fLongerPolling; }
0235
0236 void SetCustomScripts(const std::string &src);
0237
0238 void AddCustomClass(const std::string &clname, bool with_derived = false);
0239 bool IsCustomClass(const TClass *cl) const;
0240
0241 void SetAsyncMode(Bool_t on = kTRUE) { fAsyncMode = on; }
0242 Bool_t IsAsyncMode() const { return fAsyncMode; }
0243
0244 Bool_t IsFixedSize() const { return fFixedSize; }
0245
0246 static Font_t AddFont(const char *name, const char *ttffile, Int_t precision = 2);
0247
0248 static TString CreatePadJSON(TPad *pad, Int_t json_compression = 0, Bool_t batchmode = kFALSE);
0249 static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression = 0, Bool_t batchmode = kFALSE);
0250 static Int_t StoreCanvasJSON(TCanvas *c, const char *filename, const char *option = "");
0251
0252 static bool ProduceImage(TPad *pad, const char *filename, Int_t width = 0, Int_t height = 0);
0253
0254 static bool ProduceImages(std::vector<TPad *> pads, const char *filename, Int_t width = 0, Int_t height = 0);
0255
0256 static TCanvasImp *NewCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height);
0257
0258 ClassDefOverride(TWebCanvas, 0)
0259 };
0260
0261 #endif