Logo ROOT  
Reference Guide
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 fNeedUpdate{false}; ///<! is canvas update required
31public:
32 RChangeAttrRequest() = default; // for I/O
33 virtual ~RChangeAttrRequest() = default;
34 std::unique_ptr<RDrawableReply> Process() override;
35 bool NeedCanvasUpdate() const override { return fNeedUpdate; }
36};
37
38/** \class RCanvas
39\ingroup GpadROOT7
40\brief A window's topmost `RPad`.
41\author Axel Naumann <axel@cern.ch>
42\date 2015-07-08
43\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
44*/
45
46class RCanvas: public RPadBase {
47friend class RPadBase; /// use for ID generation
48friend class RCanvasPainter; /// used for primitives drawing
49friend class RChangeAttrRequest; /// to apply attributes changes
50private:
51 /// Title of the canvas.
52 std::string fTitle;
53
54 /// Size of the canvas in pixels,
55 std::array<RPadLength::Pixel, 2> fSize;
56
57 /// Modify counter, incremented every time canvas is changed
59
60 /// The painter of this canvas, bootstrapping the graphics connection.
61 /// Unmapped canvases (those that never had `Draw()` invoked) might not have
62 /// a painter.
63 std::unique_ptr<Internal::RVirtualCanvasPainter> fPainter; ///<!
64
65 /// Disable copy construction for now.
66 RCanvas(const RCanvas &) = delete;
67
68 /// Disable assignment for now.
69 RCanvas &operator=(const RCanvas &) = delete;
70
71 // Increment modify counter
72 uint64_t IncModified() { return ++fModified; }
73
74public:
75 static std::shared_ptr<RCanvas> Create(const std::string &title);
76
77 /// Create a temporary RCanvas; for long-lived ones please use Create().
78 RCanvas() = default;
79
80 ~RCanvas() = default;
81
82 const RCanvas *GetCanvas() const override { return this; }
83
84 /// Access to the top-most canvas, if any (non-const version).
85 RCanvas *GetCanvas() override { return this; }
86
87 /// Return canvas pixel size as array with two elements - width and height
88 const std::array<RPadLength::Pixel, 2> &GetSize() const { return fSize; }
89
90 /// Set canvas pixel size as array with two elements - width and height
91 RCanvas &SetSize(const std::array<RPadLength::Pixel, 2> &sz)
92 {
93 fSize = sz;
94 return *this;
95 }
96
97 /// Set canvas pixel size - width and height
99 {
100 fSize[0] = width;
101 fSize[1] = height;
102 return *this;
103 }
104
105 /// Display the canvas.
106 void Show(const std::string &where = "");
107
108 /// Returns window name used to display canvas
109 std::string GetWindowAddr() const;
110
111 /// Hide all canvas displays
112 void Hide();
113
114 /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
115 void Remove();
116
117 /// Insert panel into the canvas, canvas should be shown at this moment
118 template <class PANEL>
119 bool AddPanel(std::shared_ptr<PANEL> &panel)
120 {
121 if (!fPainter) return false;
122 return fPainter->AddPanel(panel->GetWindow());
123 }
124
125 // Get modify counter
126 uint64_t GetModified() const { return fModified; }
127
128 // Set newest version to all primitives
130
131 // Return if canvas was modified and not yet updated
132 bool IsModified() const;
133
134 /// update drawing
135 void Update(bool async = false, CanvasCallback_t callback = nullptr);
136
137 /// Run canvas functionality for given time (in seconds)
138 void Run(double tm = 0.);
139
140 /// Save canvas in image file
141 bool SaveAs(const std::string &filename);
142
143 /// Get the canvas's title.
144 const std::string &GetTitle() const { return fTitle; }
145
146 /// Set the canvas's title.
147 RCanvas &SetTitle(const std::string &title)
148 {
149 fTitle = title;
150 return *this;
151 }
152
153 void ResolveSharedPtrs();
154
155 /// Convert a `Pixel` position to Canvas-normalized positions.
156 std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const final
157 {
158 return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
159 }
160
161 static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
162};
163
164} // namespace Experimental
165} // namespace ROOT
166
167#endif
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
A window's topmost RPad.
Definition: RCanvas.hxx:46
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases()
Returns list of created canvases.
Definition: RCanvas.cxx:43
RCanvas(const RCanvas &)=delete
Disable copy construction for now.
RCanvas * GetCanvas() override
Access to the top-most canvas, if any (non-const version).
Definition: RCanvas.hxx:85
const std::string & GetTitle() const
Get the canvas's title.
Definition: RCanvas.hxx:144
bool SaveAs(const std::string &filename)
Save canvas in image file.
Definition: RCanvas.cxx:143
RCanvas & SetSize(const RPadLength::Pixel &width, const RPadLength::Pixel &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:147
RCanvas & SetSize(const std::array< RPadLength::Pixel, 2 > &sz)
Set canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:91
Version_t fModified
Modify counter, incremented every time canvas is changed.
Definition: RCanvas.hxx:58
std::array< RPadLength::Normal, 2 > PixelsToNormal(const std::array< RPadLength::Pixel, 2 > &pos) const final
Convert a Pixel position to Canvas-normalized positions.
Definition: RCanvas.hxx:156
std::array< RPadLength::Pixel, 2 > fSize
Size of the canvas in pixels,.
Definition: RCanvas.hxx:55
bool IsModified() const
Returns true is canvas was modified since last painting.
Definition: RCanvas.cxx:53
const std::array< RPadLength::Pixel, 2 > & GetSize() const
Return canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:88
RCanvas & operator=(const RCanvas &)=delete
Disable assignment for now.
void Show(const std::string &where="")
Display the canvas.
Definition: RCanvas.cxx:95
std::string GetWindowAddr() const
Returns window name used to display canvas.
Definition: RCanvas.cxx:121
void Remove()
Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.
Definition: RCanvas.cxx:160
void ResolveSharedPtrs()
To resolve problem with storing of shared pointers Call this method when reading canvas from the file...
Definition: RCanvas.cxx:225
void Run(double tm=0.)
Run canvas functionality for given time (in seconds)
Definition: RCanvas.cxx:211
uint64_t GetModified() const
Definition: RCanvas.hxx:126
std::string fTitle
to apply attributes changes
Definition: RCanvas.hxx:52
std::unique_ptr< Internal::RVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition: RCanvas.hxx:63
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:70
RCanvas()=default
Create a temporary RCanvas; for long-lived ones please use Create().
const RCanvas * GetCanvas() const override
Access to the top-most canvas, if any (const version).
Definition: RCanvas.hxx:82
void Update(bool async=false, CanvasCallback_t callback=nullptr)
update drawing
Definition: RCanvas.cxx:61
friend class RCanvasPainter
use for ID generation
Definition: RCanvas.hxx:48
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition: RCanvas.hxx:119
void Hide()
Hide all canvas displays.
Definition: RCanvas.cxx:133
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:35
bool fNeedUpdate
! is canvas update required
Definition: RCanvas.hxx:28
RChangeAttrRequest & operator=(const RChangeAttrRequest &)=delete
std::unique_ptr< RDrawableReply > Process() override
Apply attributes changes to the drawable Return mask with actions which were really applied.
Definition: RCanvas.cxx:253
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:366
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...
Definition: StringConv.hxx:21