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 "TWebCanvas.h"
21
22using namespace ROOT::Experimental;
23
24using namespace std::string_literals;
25
26
28
29 std::unique_ptr<TCanvas> fCanvas; ///<! drawn canvas
30 TWebCanvas *fWebCanvas{nullptr}; ///<! web implementation, owned by TCanvas
31
32 std::unique_ptr<Browsable::RHolder> fObject; // TObject drawing in the TCanvas
33
34 void SetPrivateCanvasFields(bool on_init)
35 {
36 Long_t offset = TCanvas::Class()->GetDataMemberOffset("fCanvasID");
37 if (offset > 0) {
38 Int_t *id = (Int_t *)((char*) fCanvas.get() + offset);
39 if (*id == fCanvas->GetCanvasID()) *id = on_init ? 111222333 : -1;
40 } else {
41 printf("ERROR: Cannot modify TCanvas::fCanvasID data member\n");
42 }
43
44 offset = TCanvas::Class()->GetDataMemberOffset("fPixmapID");
45 if (offset > 0) {
46 Int_t *id = (Int_t *)((char*) fCanvas.get() + offset);
47 if (*id == fCanvas->GetPixmapID()) *id = on_init ? 332211 : -1;
48 } else {
49 printf("ERROR: Cannot modify TCanvas::fPixmapID data member\n");
50 }
51
52 offset = TCanvas::Class()->GetDataMemberOffset("fMother");
53 if (offset > 0) {
54 TPad **moth = (TPad **)((char*) fCanvas.get() + offset);
55 if (*moth == fCanvas->GetMother()) *moth = on_init ? fCanvas.get() : nullptr;
56 } else {
57 printf("ERROR: Cannot set TCanvas::fMother data member\n");
58 }
59 }
60
61public:
62
64 {
65 fCanvas = std::make_unique<TCanvas>(kFALSE);
66 fCanvas->SetName(name.c_str());
67 fCanvas->SetTitle(name.c_str());
71 fCanvas->SetCanvas(fCanvas.get());
72 fCanvas->SetBatch(kTRUE); // mark canvas as batch
73 fCanvas->SetEditable(kTRUE); // ensure fPrimitives are created
74
75 // create implementation
76 fWebCanvas = new TWebCanvas(fCanvas.get(), "title", 0, 0, 800, 600);
77
78 // assign implementation
79 fCanvas->SetCanvasImp(fWebCanvas);
80
82 fCanvas->cd();
83 }
84
85 RBrowserTCanvasWidget(const std::string &name, std::unique_ptr<TCanvas> &canv) : RBrowserWidget(name)
86 {
87 fCanvas = std::move(canv);
88 fCanvas->SetBatch(kTRUE); // mark canvas as batch
89
90 // create implementation
91 fWebCanvas = new TWebCanvas(fCanvas.get(), "title", 0, 0, 800, 600);
92
93 // assign implementation
94 fCanvas->SetCanvasImp(fWebCanvas);
96 fCanvas->cd();
97 }
98
100 {
102
103 gROOT->GetListOfCanvases()->Remove(fCanvas.get());
104
105 fCanvas->Close();
106 }
107
108 std::string GetKind() const override { return "tcanvas"s; }
109
110 void SetActive() override
111 {
112 fCanvas->cd();
113 }
114
115 void Show(const std::string &arg) override
116 {
118 }
119
120 std::string GetUrl() override
121 {
122 return "../"s + fWebCanvas->GetWebWindow()->GetAddr() + "/"s;
123 }
124
125 std::string GetTitle() override
126 {
127 return fCanvas->GetName();
128 }
129
130 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string &opt) override
131 {
132 if (!elem->IsCapable(Browsable::RElement::kActDraw6))
133 return false;
134
135 fObject = elem->GetObject();
136
138 fCanvas->ForceUpdate();
139 return true;
140 }
141
142 return false;
143 }
144
145 void CheckModified() override
146 {
147 if (fCanvas->IsModified())
148 fCanvas->Update();
149 }
150
151};
152
153// ======================================================================
154
156protected:
157 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
158 {
159 return std::make_shared<RBrowserTCanvasWidget>(name);
160 }
161
162 std::shared_ptr<RBrowserWidget> CreateFor(const std::string &name, std::shared_ptr<Browsable::RElement> &elem) final
163 {
164 auto holder = elem->GetObject();
165 if (!holder) return nullptr;
166
167 auto canv = holder->get_unique<TCanvas>();
168 if (!canv) return nullptr;
169
170 return std::make_shared<RBrowserTCanvasWidget>(name, canv);
171 }
172
173public:
177
RBrowserTCanvasProvider sRBrowserTCanvasProvider
const Bool_t kFALSE
Definition RtypesCore.h:101
long Long_t
Definition RtypesCore.h:54
const Bool_t kTRUE
Definition RtypesCore.h:100
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:404
~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)
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &opt) override
void Show(const std::string &arg) override
std::string GetTitle() override
std::string GetKind() const override
RBrowserTCanvasWidget(const std::string &name)
std::string GetUrl() override
std::unique_ptr< Browsable::RHolder > fObject
void SetPrivateCanvasFields(bool on_init)
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:54
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...
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:90
@ kMenuBar
Definition TCanvas.h:89
@ kShowEditor
Definition TCanvas.h:91
The most important graphics class in the ROOT system.
Definition TPad.h:26
TVirtualPad * GetMother() const override
Definition TPad.h:253
Basic TCanvasImp ABI implementation for Web-based GUI Provides painting of main ROOT6 classes in web ...
Definition TWebCanvas.h:32
const std::shared_ptr< ROOT::Experimental::RWebWindow > & GetWebWindow() const
Definition TWebCanvas.h:130
void ShowWebWindow(const ROOT::Experimental::RWebDisplayArgs &user_args="")
Show canvas in specified place.