Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RCanvas.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_RCanvas
10#define ROOT7_RCanvas
11
12#include "ROOT/RPadBase.hxx"
15
16#include <memory>
17#include <string>
18#include <vector>
19#include <list>
20
21namespace ROOT {
22namespace Experimental {
23
25 std::vector<std::string> ids; ///< array of ids
26 std::vector<std::string> names; ///< array of attribute names
27 std::vector<std::unique_ptr<RAttrMap::Value_t>> values; ///< array of values
28 bool update{true}; ///< update canvas at the end
29 bool fNeedUpdate{false}; ///<! is canvas update required
32public:
33 RChangeAttrRequest() = default; // for I/O
34 ~RChangeAttrRequest() override = default;
35 std::unique_ptr<RDrawableReply> Process() override;
36 bool NeedCanvasUpdate() const override { return fNeedUpdate; }
37};
38
39/** \class RCanvas
40\ingroup GpadROOT7
41\brief A window's topmost `RPad`.
42\author Axel Naumann <axel@cern.ch>
43\date 2015-07-08
44\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
45*/
46
47class RCanvas: public RPadBase {
48friend class RPadBase; /// use for ID generation
49friend class RCanvasPainter; /// used for primitives drawing
50friend class RChangeAttrRequest; /// to apply attributes changes
51private:
52 /// Title of the canvas.
53 std::string fTitle;
54
55 /// Width of the canvas in pixels
56 int fWidth{0};
57
58 /// Height of the canvas in pixels
59 int fHeight{0};
60
61 /// Modify counter, incremented every time canvas is changed
63
64 /// The painter of this canvas, bootstrapping the graphics connection.
65 /// Unmapped canvases (those that never had `Draw()` invoked) might not have
66 /// a painter.
67 std::unique_ptr<Internal::RVirtualCanvasPainter> fPainter; ///<!
68
69 /// indicate if Show() method was called before
70 bool fShown{false}; ///<!
71
72 /// indicate if Update() method was called before
73 bool fUpdated{false}; ///<!
74
75 /// Disable copy construction for now.
76 RCanvas(const RCanvas &) = delete;
77
78 /// Disable assignment for now.
79 RCanvas &operator=(const RCanvas &) = delete;
80
81 // Increment modify counter
82 uint64_t IncModified() { return ++fModified; }
83
84public:
85 static std::shared_ptr<RCanvas> Create(const std::string &title);
86
87 /// Create a temporary RCanvas; for long-lived ones please use Create().
88 RCanvas() : RPadBase("canvas") {}
89
90 ~RCanvas() override = default;
91
92 const RCanvas *GetCanvas() const override { return this; }
93
94 /// Access to the top-most canvas, if any (non-const version).
95 RCanvas *GetCanvas() override { return this; }
96
97 /// Set canvas pixel size - width and height
98 void SetSize(int width, int height)
99 {
100 fWidth = width;
101 fHeight = height;
102 }
103
104 /// Set canvas width
105 void SetWidth(int width) { fWidth = width; }
106
107 /// Set canvas height
109
110 /// Get canvas width
111 int GetWidth() const { return fWidth; }
112
113 /// Get canvas height
114 int GetHeight() const { return fHeight; }
115
116 /// Display the canvas.
117 void Show(const std::string &where = "");
118
119 /// returns true if Show() method was called
120 bool IsShown() const { return fShown; }
121
122 /// clear IsShown() flag
123 void ClearShown() { fShown = false; }
124
125 /// Returns window name used to display canvas
126 std::string GetWindowAddr() const;
127
128 /// Returns window URL which can be used for connection
129 std::string GetWindowUrl(bool remote);
130
131 /// Hide all canvas displays
132 void Hide();
133
134 /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
135 void Remove();
136
137 /// Insert panel into the canvas, canvas should be shown at this moment
138 template <class PANEL>
139 bool AddPanel(std::shared_ptr<PANEL> &panel)
140 {
141 if (!fPainter) return false;
142 return fPainter->AddPanel(panel->GetWindow());
143 }
144
145 /// Get modify counter
146 uint64_t GetModified() const { return fModified; }
147
148 // Set newest version to all primitives
150
151 /// Set newest version to specified drawable
152 void Modified(std::shared_ptr<RDrawable> drawable)
153 {
154 // TODO: may be check that drawable belong to the canvas
155 if (drawable)
156 drawable->SetDrawableVersion(IncModified());
157 }
158
159 // Return if canvas was modified and not yet updated
160 bool IsModified() const;
161
162 /// update drawing
163 void Update(bool async = false, CanvasCallback_t callback = nullptr);
164
165 /// returns true if Update() method was called
166 bool IsUpdated() const { return fUpdated; }
167
168 /// clear IsUpdated() flag
169 void ClearUpdated() { fUpdated = false; }
170
171 /// Run canvas functionality for given time (in seconds)
172 void Run(double tm = 0.);
173
174 /// Save canvas in image file
175 bool SaveAs(const std::string &filename);
176
177 /// Provide JSON which can be used for offline display
178 std::string CreateJSON();
179
180 std::string GetUID() const;
181
182 /// Get the canvas's title.
183 const std::string &GetTitle() const { return fTitle; }
184
185 /// Set the canvas's title.
186 RCanvas &SetTitle(const std::string &title)
187 {
188 fTitle = title;
189 return *this;
190 }
191
192 void ResolveSharedPtrs();
193
194 void ClearOnClose(const std::shared_ptr<void> &handle);
195
196 static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
197
198 static void ReleaseHeldCanvases();
199};
200
201} // namespace Experimental
202} // namespace ROOT
203
204#endif
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 filename
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Implementation of painter for ROOT::Experimental::RCanvas, using RWebWindow.
A window's topmost RPad.
Definition RCanvas.hxx:47
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases()
Returns list of created canvases.
Definition RCanvas.cxx:45
RCanvas(const RCanvas &)=delete
Disable copy construction for now.
static void ReleaseHeldCanvases()
Release list of held canvases pointers If no other shared pointers exists on the canvas,...
Definition RCanvas.cxx:56
RCanvas * GetCanvas() override
Access to the top-most canvas, if any (non-const version).
Definition RCanvas.hxx:95
const std::string & GetTitle() const
Get the canvas's title.
Definition RCanvas.hxx:183
bool SaveAs(const std::string &filename)
Save canvas in image file.
Definition RCanvas.cxx:181
void SetSize(int width, int height)
Set canvas pixel size - width and height.
Definition RCanvas.hxx:98
RCanvas & SetTitle(const std::string &title)
Set the canvas's title.
Definition RCanvas.hxx:186
Version_t fModified
Modify counter, incremented every time canvas is changed.
Definition RCanvas.hxx:62
std::string GetWindowUrl(bool remote)
Returns window URL which can be used for connection.
Definition RCanvas.cxx:159
int GetHeight() const
Get canvas height.
Definition RCanvas.hxx:114
bool IsModified() const
Returns true is canvas was modified since last painting.
Definition RCanvas.cxx:70
RCanvas & operator=(const RCanvas &)=delete
Disable assignment for now.
void Show(const std::string &where="")
Display the canvas.
Definition RCanvas.cxx:115
bool fShown
indicate if Show() method was called before
Definition RCanvas.hxx:70
std::string GetWindowAddr() const
Returns window name used to display canvas.
Definition RCanvas.cxx:147
void Remove()
Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.
Definition RCanvas.cxx:225
void ResolveSharedPtrs()
To resolve problem with storing of shared pointers Call this method when reading canvas from the file...
Definition RCanvas.cxx:299
void Run(double tm=0.)
Run canvas functionality for given time (in seconds)
Definition RCanvas.cxx:285
uint64_t GetModified() const
Get modify counter.
Definition RCanvas.hxx:146
int fHeight
Height of the canvas in pixels.
Definition RCanvas.hxx:59
std::string fTitle
to apply attributes changes
Definition RCanvas.hxx:53
bool IsUpdated() const
returns true if Update() method was called
Definition RCanvas.hxx:166
std::string GetUID() const
Return unique identifier for the canvas Used in iPython display.
Definition RCanvas.cxx:199
std::string CreateJSON()
Provide JSON which can be used for offline display.
Definition RCanvas.cxx:211
void SetHeight(int height)
Set canvas height.
Definition RCanvas.hxx:108
bool IsShown() const
returns true if Show() method was called
Definition RCanvas.hxx:120
std::unique_ptr< Internal::RVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition RCanvas.hxx:67
int fWidth
Width of the canvas in pixels.
Definition RCanvas.hxx:56
bool fUpdated
indicate if Update() method was called before
Definition RCanvas.hxx:73
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition RCanvas.cxx:89
void ClearShown()
clear IsShown() flag
Definition RCanvas.hxx:123
void ClearOnClose(const std::shared_ptr< void > &handle)
Set handle which will be cleared when connection is closed.
Definition RCanvas.cxx:239
void SetWidth(int width)
Set canvas width.
Definition RCanvas.hxx:105
const RCanvas * GetCanvas() const override
Access to the top-most canvas, if any (const version).
Definition RCanvas.hxx:92
RCanvas()
Create a temporary RCanvas; for long-lived ones please use Create().
Definition RCanvas.hxx:88
void Modified(std::shared_ptr< RDrawable > drawable)
Set newest version to specified drawable.
Definition RCanvas.hxx:152
int GetWidth() const
Get canvas width.
Definition RCanvas.hxx:111
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition RCanvas.hxx:139
void ClearUpdated()
clear IsUpdated() flag
Definition RCanvas.hxx:169
~RCanvas() override=default
void Hide()
Hide all canvas displays.
Definition RCanvas.cxx:171
std::vector< std::unique_ptr< RAttrMap::Value_t > > values
array of values
Definition RCanvas.hxx:27
std::vector< std::string > names
array of attribute names
Definition RCanvas.hxx:26
std::vector< std::string > ids
array of ids
Definition RCanvas.hxx:25
bool NeedCanvasUpdate() const override
Definition RCanvas.hxx:36
bool fNeedUpdate
! is canvas update required
Definition RCanvas.hxx:29
RChangeAttrRequest & operator=(const RChangeAttrRequest &)=delete
bool update
update canvas at the end
Definition RCanvas.hxx:28
std::unique_ptr< RDrawableReply > Process() override
Apply attributes changes to the drawable Return mask with actions which were really applied.
Definition RCanvas.cxx:327
RChangeAttrRequest(const RChangeAttrRequest &)=delete
Base class for requests which can be submitted from the clients.
Base class for graphic containers for RDrawable-s.
Definition RPadBase.hxx:37
void SetDrawableVersion(Version_t vers) override
Assign drawable version - for pad itself and all primitives.
Definition RPadBase.cxx:238
std::function< void(bool)> CanvasCallback_t
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...