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