Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPadBase.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2019, 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_RPadBase
10#define ROOT7_RPadBase
11
12#include "ROOT/RDrawable.hxx"
13#include "ROOT/RFrame.hxx"
14#include "ROOT/RPadExtent.hxx"
15#include "ROOT/RPadPos.hxx"
16#include "ROOT/TypeTraits.hxx"
17
18#include <memory>
19#include <vector>
20#include <algorithm>
21
22namespace ROOT {
23namespace Experimental {
24
25class RPad;
26class RCanvas;
27class RPadBaseDisplayItem;
28
29/** \class ROOT::Experimental::RPadBase
30\ingroup GpadROOT7
31\brief Base class for graphic containers for `RDrawable`-s.
32\authors Axel Naumann <axel@cern.ch> Sergey Linev <s.linev@gsi.de>
33\date 2019-10-02
34\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
35*/
36
37class RPadBase : public RDrawable {
38
39private:
40
42
43 /// Content of the pad.
44
45 std::vector<Primitive_t> fPrimitives;
46
47 /// Disable copy construction.
48 RPadBase(const RPadBase &) = delete;
49
50 /// Disable assignment.
51 RPadBase &operator=(const RPadBase &) = delete;
52
53 void TestIfFrameRequired(const RDrawable *drawable)
54 {
55 if (drawable->IsFrameRequired())
56 AddFrame();
57 }
58
59protected:
60 /// Allow derived classes to default construct a RPadBase.
61 explicit RPadBase(const char *csstype) : RDrawable(csstype) {}
62
64
65 void DisplayPrimitives(RPadBaseDisplayItem &paditem, RDisplayContext &ctxt);
66
67 void SetDrawableVersion(Version_t vers) override;
68
69public:
70
71 using Primitives_t = std::vector<std::shared_ptr<RDrawable>>;
72
73 ~RPadBase() override;
74
75 void UseStyle(const std::shared_ptr<RStyle> &style) override;
76
77 /// Add object to be painted.
78 /// Correspondent drawable will be created via GetDrawable() function which should be defined and be accessed at calling time.
79 /// If required, extra arguments for GetDrawable() function can be provided.
80 template <class T, class... ARGS>
81 auto Draw(const std::shared_ptr<T> &what, ARGS... args)
82 {
83 // Requires GetDrawable(what) to be known!
84 auto drawable = GetDrawable(what, args...);
85
86 TestIfFrameRequired(drawable.get());
87
88 fPrimitives.emplace_back(drawable);
89
90 return drawable;
91 }
92
93 /// Create drawable of specified class T
94 template<class T, class... ARGS>
95 std::shared_ptr<T> Draw(ARGS... args)
96 {
97 auto drawable = std::make_shared<T>(args...);
98
99 TestIfFrameRequired(drawable.get());
100
101 fPrimitives.emplace_back(drawable);
102
103 return drawable;
104 }
105
106 /// Add drawable of specified class T
107 template<class T, class... ARGS>
108 std::shared_ptr<T> Add(ARGS... args)
109 {
110 auto drawable = std::make_shared<T>(args...);
111
112 TestIfFrameRequired(drawable.get());
113
114 fPrimitives.emplace_back(drawable);
115
116 return drawable;
117 }
118
119 /// Add existing drawable instance to canvas
120 std::shared_ptr<RDrawable> Draw(std::shared_ptr<RDrawable> &&drawable)
121 {
122 TestIfFrameRequired(drawable.get());
123
124 auto dr = std::move(drawable);
125
126 fPrimitives.emplace_back(dr);
127
128 return dr;
129 }
130
131 /// returns number of primitives in the pad
132 unsigned NumPrimitives() const { return fPrimitives.size(); }
133
134 /// returns primitive of given number
135 std::shared_ptr<RDrawable> GetPrimitive(unsigned num) const
136 {
137 if (num >= fPrimitives.size()) return nullptr;
138 return fPrimitives[num].get_shared();
139 }
140
141 std::shared_ptr<RDrawable> FindPrimitive(const std::string &id) const;
142
143 std::shared_ptr<RDrawable> FindPrimitiveByDisplayId(const std::string &display_id) const;
144
145 const RPadBase *FindPadForPrimitiveWithDisplayId(const std::string &display_id) const;
146
147 /// Get all primitives contained in the pad.
148 auto GetPrimitives() const
149 {
150 Primitives_t res;
151 for (auto &entry : fPrimitives)
152 res.emplace_back(entry.get_shared());
153 return res;
154 }
155
156 /// Remove an object from the list of primitives.
157 bool Remove(const std::string &id)
158 {
159 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
160 [&id](const Internal::RIOShared<RDrawable>& dr) { return dr->GetId() == id; });
161 if (iter == fPrimitives.end())
162 return false;
163 iter->reset();
164 fPrimitives.erase(iter);
165 return true;
166 }
167
168 /// Remove drawable from list of primitives
169 bool Remove(const std::shared_ptr<RDrawable> &drawable)
170 {
171 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
172 [&drawable](const Internal::RIOShared<RDrawable>& dr) { return drawable.get() == dr.get(); });
173 if (iter == fPrimitives.end())
174 return false;
175 iter->reset();
176 fPrimitives.erase(iter);
177 return true;
178 }
179
180 /// Remove drawable at specified position
181 bool RemoveAt(unsigned indx)
182 {
183 if (indx >= fPrimitives.size()) return false;
184 fPrimitives[indx].reset();
185 fPrimitives.erase(fPrimitives.begin() + indx);
186 return true;
187 }
188
189 /// Wipe the pad by clearing the list of primitives.
190 void Wipe() { fPrimitives.clear(); }
191
192 std::shared_ptr<RFrame> AddFrame();
193 std::shared_ptr<RFrame> GetFrame();
194 const std::shared_ptr<RFrame> GetFrame() const;
195
196 std::shared_ptr<RPad> AddPad(const RPadPos &, const RPadExtent &);
197
198 /// Divide this pad into a grid of subpads with padding in between.
199 /// \param nHoriz Number of horizontal pads.
200 /// \param nVert Number of vertical pads.
201 /// \param padding Padding between pads.
202 /// \returns vector of vector (ret[x][y]) of created pads.
203 std::vector<std::vector<std::shared_ptr<RPad>>> Divide(int nHoriz, int nVert, const RPadExtent &padding = {});
204
205 /// Access to the top-most canvas, if any (const version).
206 virtual const RCanvas *GetCanvas() const = 0;
207
208 /// Access to the top-most canvas, if any (non-const version).
209 virtual RCanvas *GetCanvas() = 0;
210};
211
212} // namespace Experimental
213} // namespace ROOT
214
215#endif
short Version_t
Definition RtypesCore.h:65
Option_t Option_t style
A window's topmost RPad.
Definition RCanvas.hxx:47
Base class for drawable entities: objects that can be painted on a RPad.
virtual bool IsFrameRequired() const
Base class for graphic containers for RDrawable-s.
Definition RPadBase.hxx:37
RPadBase & operator=(const RPadBase &)=delete
Disable assignment.
void DisplayPrimitives(RPadBaseDisplayItem &paditem, RDisplayContext &ctxt)
Create display items for all primitives in the pad Each display item gets its special id,...
Definition RPadBase.cxx:112
RPadBase(const RPadBase &)=delete
Disable copy construction.
bool Remove(const std::shared_ptr< RDrawable > &drawable)
Remove drawable from list of primitives.
Definition RPadBase.hxx:169
void SetDrawableVersion(Version_t vers) override
Assign drawable version - for pad itself and all primitives.
Definition RPadBase.cxx:238
std::shared_ptr< T > Draw(ARGS... args)
Create drawable of specified class T.
Definition RPadBase.hxx:95
std::shared_ptr< T > Add(ARGS... args)
Add drawable of specified class T.
Definition RPadBase.hxx:108
std::shared_ptr< RDrawable > FindPrimitiveByDisplayId(const std::string &display_id) const
Find primitive with unique id, produce for RDisplayItem Such id used for client-server identification...
Definition RPadBase.cxx:64
RPadBase(const char *csstype)
Allow derived classes to default construct a RPadBase.
Definition RPadBase.hxx:61
const RPadBase * FindPadForPrimitiveWithDisplayId(const std::string &display_id) const
Find subpad which contains primitive with given display id.
Definition RPadBase.cxx:87
void TestIfFrameRequired(const RDrawable *drawable)
Definition RPadBase.hxx:53
std::vector< std::shared_ptr< RDrawable > > Primitives_t
Definition RPadBase.hxx:71
std::shared_ptr< RDrawable > GetPrimitive(unsigned num) const
returns primitive of given number
Definition RPadBase.hxx:135
std::shared_ptr< RFrame > GetFrame()
Get a frame object if exists.
Definition RPadBase.cxx:214
std::shared_ptr< RPad > AddPad(const RPadPos &, const RPadExtent &)
Add subpad.
Definition RPadBase.cxx:138
virtual const RCanvas * GetCanvas() const =0
Access to the top-most canvas, if any (const version).
bool Remove(const std::string &id)
Remove an object from the list of primitives.
Definition RPadBase.hxx:157
std::shared_ptr< RDrawable > FindPrimitive(const std::string &id) const
Find primitive with specified id.
Definition RPadBase.cxx:40
void CollectShared(Internal::RIOSharedVector_t &) override
Collect all shared items to resolve shared_ptr after IO.
Definition RPadBase.cxx:226
auto GetPrimitives() const
Get all primitives contained in the pad.
Definition RPadBase.hxx:148
unsigned NumPrimitives() const
returns number of primitives in the pad
Definition RPadBase.hxx:132
std::vector< Primitive_t > fPrimitives
Content of the pad.
Definition RPadBase.hxx:45
std::vector< std::vector< std::shared_ptr< RPad > > > Divide(int nHoriz, int nVert, const RPadExtent &padding={})
Divide this pad into a grid of subpads with padding in between.
Definition RPadBase.cxx:154
virtual RCanvas * GetCanvas()=0
Access to the top-most canvas, if any (non-const version).
std::shared_ptr< RFrame > AddFrame()
Add a frame object for the pad.
Definition RPadBase.cxx:189
bool RemoveAt(unsigned indx)
Remove drawable at specified position.
Definition RPadBase.hxx:181
auto Draw(const std::shared_ptr< T > &what, ARGS... args)
Add object to be painted.
Definition RPadBase.hxx:81
std::shared_ptr< RDrawable > Draw(std::shared_ptr< RDrawable > &&drawable)
Add existing drawable instance to canvas.
Definition RPadBase.hxx:120
void Wipe()
Wipe the pad by clearing the list of primitives.
Definition RPadBase.hxx:190
void UseStyle(const std::shared_ptr< RStyle > &style) override
Use provided style for pad and all primitives inside.
Definition RPadBase.cxx:30
An extent / size (horizontal and vertical) in a RPad.
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition RDrawable.hxx:52
auto GetDrawable(const std::shared_ptr< DRAWABLE > &drawable)
Central method to insert drawable in list of pad primitives By default drawable placed as is.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
static const char * what
Definition stlLoader.cc:6
#define ARGS(alist)
Definition gifencode.c:10