Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBrowserTCanvasWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2021-01-25
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
16
17#include "TCanvas.h"
18#include "TROOT.h"
19#include "TClass.h"
20#include "TEnv.h"
21#include "TWebCanvas.h"
22
23#include <map>
24
25using namespace ROOT;
26
27using namespace std::string_literals;
28
29
31
32 std::unique_ptr<TCanvas> fCanvas; ///<! drawn canvas
33 TWebCanvas *fWebCanvas{nullptr}; ///<! web implementation, owned by TCanvas
34
35 std::multimap<TVirtualPad *, std::unique_ptr<Browsable::RHolder>> fObjects; ///<! objects holder, associated with pads
36
37 void SetPrivateCanvasFields(bool on_init)
38 {
40 if (offset > 0) {
41 Int_t *id = (Int_t *)((char*) fCanvas.get() + offset);
42 if (*id == fCanvas->GetCanvasID()) *id = on_init ? 111222333 : -1;
43 } else {
44 printf("ERROR: Cannot modify TCanvas::fCanvasID data member\n");
45 }
46
48 if (offset > 0) {
49 Int_t *id = (Int_t *)((char*) fCanvas.get() + offset);
50 if (*id == fCanvas->GetPixmapID()) *id = on_init ? 332211 : -1;
51 } else {
52 printf("ERROR: Cannot modify TCanvas::fPixmapID data member\n");
53 }
54
56 if (offset > 0) {
57 TPad **moth = (TPad **)((char*) fCanvas.get() + offset);
58 if (*moth == fCanvas->GetMother()) *moth = on_init ? fCanvas.get() : nullptr;
59 } else {
60 printf("ERROR: Cannot set TCanvas::fMother data member\n");
61 }
62
64 if (offset > 0) {
65 UInt_t *cw = (UInt_t *)((char*) fCanvas.get() + offset);
66 if (*cw == fCanvas->GetWw()) *cw = on_init ? 800 : 0;
67 } else {
68 printf("ERROR: Cannot set TCanvas::fCw data member\n");
69 }
70
72 if (offset > 0) {
73 UInt_t *ch = (UInt_t *)((char*) fCanvas.get() + offset);
74 if (*ch == fCanvas->GetWh()) *ch = on_init ? 600 : 0;
75 } else {
76 printf("ERROR: Cannot set TCanvas::fCw data member\n");
77 }
78
79 }
80
81public:
82
84 {
85 fCanvas = std::make_unique<TCanvas>(kFALSE);
86 fCanvas->SetName(name.c_str());
87 fCanvas->SetTitle(name.c_str());
91 fCanvas->SetCanvas(fCanvas.get());
92 fCanvas->SetBatch(kTRUE); // mark canvas as batch
93 fCanvas->SetEditable(kTRUE); // ensure fPrimitives are created
94
95 Bool_t readonly = gEnv->GetValue("WebGui.FullCanvas", (Int_t) 1) == 0;
96
97 // create implementation
98 fWebCanvas = new TWebCanvas(fCanvas.get(), "title", 0, 0, 800, 600, readonly);
99
100 // use async mode to prevent blocking inside qt5/qt6/cef
102
103 // assign implementation
104 fCanvas->SetCanvasImp(fWebCanvas);
106 fCanvas->cd();
107
109 gROOT->GetListOfCleanups()->Add(fCanvas.get());
110 }
111
112 RBrowserTCanvasWidget(const std::string &name, std::unique_ptr<TCanvas> &canv) : RBrowserWidget(name)
113 {
114 fCanvas = std::move(canv);
115 fCanvas->SetBatch(kTRUE); // mark canvas as batch
116
117 Bool_t readonly = gEnv->GetValue("WebGui.FullCanvas", (Int_t) 1) == 0;
118
119 // create implementation
120 fWebCanvas = new TWebCanvas(fCanvas.get(), "title", 0, 0, 800, 600, readonly);
121
122 // use async mode to prevent blocking inside qt5/qt6/cef
124
125 // assign implementation
126 fCanvas->SetCanvasImp(fWebCanvas);
128 fCanvas->cd();
129
131 gROOT->GetListOfCleanups()->Add(fCanvas.get());
132 }
133
135 {
136 {
138 gROOT->GetListOfCleanups()->Remove(fCanvas.get());
139 }
140
142
143 gROOT->GetListOfCanvases()->Remove(fCanvas.get());
144
145 if ((fCanvas->GetCanvasID() == -1) && (fCanvas->GetCanvasImp() == fWebCanvas)) {
146 fCanvas->SetCanvasImp(nullptr);
147 delete fWebCanvas;
148 }
149
150 fCanvas->Close();
151 }
152
153 std::string GetKind() const override { return "tcanvas"s; }
154
155 void SetActive() override
156 {
157 fCanvas->cd();
158 }
159
160 void Show(const std::string &arg) override
161 {
163 }
164
165 std::string GetUrl() override
166 {
167 return "../"s + fWebCanvas->GetWebWindow()->GetAddr() + "/"s;
168 }
169
170 std::string GetTitle() override
171 {
172 return fCanvas->GetName();
173 }
174
175 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string &opt = "") override
176 {
177 if (!elem->IsCapable(Browsable::RElement::kActDraw6))
178 return false;
179
180 std::unique_ptr<Browsable::RHolder> obj = elem->GetObject();
181 if (!obj)
182 return false;
183
184 Browsable::RProvider::ExtendProgressHandle(elem.get(), obj.get());
185
186 std::string drawopt = opt;
187
188 // first remove all objects which may belong to removed pads
189 bool find_removed_pad;
190 do {
191 find_removed_pad = false;
192 for (auto &entry : fObjects)
193 if ((entry.first != fCanvas.get()) && !fCanvas->FindObject(entry.first)) {
194 fObjects.erase(entry.first);
195 find_removed_pad = true;
196 break;
197 }
198 } while (find_removed_pad);
199
200 TVirtualPad *pad = fCanvas.get();
201 if (gPad && fCanvas.get()->FindObject(gPad))
202 pad = gPad;
203
204 if (drawopt.compare(0,8,"<append>") == 0) {
205 drawopt.erase(0,8);
206 } else {
207 pad->GetListOfPrimitives()->Clear();
208 if (pad == fCanvas.get())
209 fObjects.clear();
210 else
211 fObjects.erase(pad);
212 pad->Range(0,0,1,1); // set default range
213 }
214
215 if (drawopt == "<dflt>")
216 drawopt = Browsable::RProvider::GetClassDrawOption(obj->GetClass());
217
218 if (Browsable::RProvider::Draw6(pad, obj, drawopt)) {
219 fObjects.emplace(pad, std::move(obj));
220 pad->Modified();
221 fCanvas->UpdateAsync();
222 return true;
223 }
224
225 return false;
226 }
227
228 void CheckModified() override
229 {
230 if (fCanvas->IsModified())
231 fCanvas->UpdateAsync();
232 }
233
234};
235
236// ======================================================================
237
239protected:
240 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
241 {
242 return std::make_shared<RBrowserTCanvasWidget>(name);
243 }
244
245 std::shared_ptr<RBrowserWidget> CreateFor(const std::string &name, std::shared_ptr<Browsable::RElement> &elem) final
246 {
247 auto holder = elem->GetObject();
248 if (!holder) return nullptr;
249
250 auto canv = holder->get_unique<TCanvas>();
251 if (!canv) return nullptr;
252
253 return std::make_shared<RBrowserTCanvasWidget>(name, canv);
254 }
255
256public:
260
RBrowserTCanvasProvider sRBrowserTCanvasProvider
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:407
#define R__LOCKGUARD(mutex)
#define gPad
~RBrowserTCanvasProvider()=default
std::shared_ptr< RBrowserWidget > Create(const std::string &name) final
std::shared_ptr< RBrowserWidget > CreateFor(const std::string &name, std::shared_ptr< Browsable::RElement > &elem) final
TWebCanvas * fWebCanvas
! web implementation, owned by TCanvas
std::unique_ptr< TCanvas > fCanvas
! drawn canvas
RBrowserTCanvasWidget(const std::string &name, std::unique_ptr< TCanvas > &canv)
void Show(const std::string &arg) override
std::string GetTitle() override
std::string GetKind() const override
std::multimap< TVirtualPad *, std::unique_ptr< Browsable::RHolder > > fObjects
! objects holder, associated with pads
RBrowserTCanvasWidget(const std::string &name)
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &opt="") override
std::string GetUrl() override
void SetPrivateCanvasFields(bool on_init)
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:55
static bool Draw6(TVirtualPad *subpad, std::unique_ptr< RHolder > &obj, const std::string &opt="")
Invoke drawing of object on TCanvas sub-pad All existing providers are checked, first checked are cla...
static std::string GetClassDrawOption(const ClassArg &)
Return configured draw option for the class.
static void ExtendProgressHandle(void *handle, void *handle2)
Extend progress handle - to be able react on sub item.
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
The Canvas class.
Definition TCanvas.h:23
@ kShowToolBar
Definition TCanvas.h:92
@ kMenuBar
Definition TCanvas.h:91
@ kShowEditor
Definition TCanvas.h:93
static TClass * Class()
Longptr_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition TClass.cxx:3477
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:402
The most important graphics class in the ROOT system.
Definition TPad.h:28
TVirtualPad * GetMother() const override
Definition TPad.h:257
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const =0
virtual void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)=0
Basic TCanvasImp ABI implementation for Web-based Graphics Provides painting of main ROOT classes in ...
Definition TWebCanvas.h:35
const std::shared_ptr< ROOT::RWebWindow > & GetWebWindow() const
Definition TWebCanvas.h:174
void ShowWebWindow(const ROOT::RWebDisplayArgs &user_args="")
Show canvas in specified place.
void SetAsyncMode(Bool_t on=kTRUE)
Definition TWebCanvas.h:240
void Close() override
Close web canvas - not implemented.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.