Logo ROOT  
Reference Guide
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/RPadUserAxis.hxx"
17#include "ROOT/TypeTraits.hxx"
18
19#include <memory>
20#include <vector>
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())
57 }
58
59protected:
60 /// Allow derived classes to default construct a RPadBase.
61 RPadBase() : RDrawable("pad") {}
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 virtual ~RPadBase();
74
75 void UseStyle(const std::shared_ptr<RStyle> &style) override;
76
77 /// Divide this pad into a grid of subpads with padding in between.
78 /// \param nHoriz Number of horizontal pads.
79 /// \param nVert Number of vertical pads.
80 /// \param padding Padding between pads.
81 /// \returns vector of vector (ret[x][y]) of created pads.
82 std::vector<std::vector<std::shared_ptr<RPad>>> Divide(int nHoriz, int nVert, const RPadExtent &padding = {});
83
84 /// Create drawable of specified class T
85 template<class T, class... ARGS>
86 auto Draw(ARGS... args)
87 {
88 auto drawable = std::make_shared<T>(args...);
89
90 TestIfFrameRequired(drawable.get());
91
92 fPrimitives.emplace_back(drawable);
93
94 return drawable;
95 }
96
97 /// Add existing drawable instance to canvas
98 auto Draw(std::shared_ptr<RDrawable> &&drawable)
99 {
100 TestIfFrameRequired(drawable.get());
101
102 fPrimitives.emplace_back(std::move(drawable));
103
104 return fPrimitives.back().get_shared();
105 }
106
107 /// Add object to be painted.
108 /// Correspondent drawable will be created via GetDrawable() function which should be defined and be accessed at calling time.
109 /// If required, extra arguments for GetDrawable() function can be provided.
110 template <class T, class... ARGS>
111 auto Draw(const std::shared_ptr<T> &what, ARGS... args)
112 {
113 // Requires GetDrawable(what) to be known!
114 auto drawable = GetDrawable(what, args...);
115
116 TestIfFrameRequired(drawable.get());
117
118 fPrimitives.emplace_back(drawable);
119
120 return drawable;
121 }
122
123 /// returns number of primitives in the pad
124 unsigned NumPrimitives() const { return fPrimitives.size(); }
125
126 /// returns primitive of given number
127 std::shared_ptr<RDrawable> GetPrimitive(unsigned num) const
128 {
129 if (num >= fPrimitives.size()) return nullptr;
130 return fPrimitives[num].get_shared();
131 }
132
133 std::shared_ptr<RDrawable> FindPrimitive(const std::string &id) const;
134
135 std::shared_ptr<RDrawable> FindPrimitiveByDisplayId(const std::string &display_id) const;
136
137 const RPadBase *FindPadForPrimitiveWithDisplayId(const std::string &display_id) const;
138
139 /// Get all primitives contained in the pad.
140 auto GetPrimitives() const
141 {
142 Primitives_t res;
143 for (auto &entry : fPrimitives)
144 res.emplace_back(entry.get_shared());
145 return res;
146 }
147
148 /// Remove an object from the list of primitives.
149 bool Remove(const std::string &id)
150 {
151 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
152 [&id](const Internal::RIOShared<RDrawable>& dr) { return dr->GetId() == id; });
153 if (iter == fPrimitives.end())
154 return false;
155 iter->reset();
156 fPrimitives.erase(iter);
157 return true;
158 }
159
160 /// Remove drawable from list of primitives
161 bool Remove(const std::shared_ptr<RDrawable> &drawable)
162 {
163 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
164 [&drawable](const Internal::RIOShared<RDrawable>& dr) { return drawable.get() == dr.get(); });
165 if (iter == fPrimitives.end())
166 return false;
167 iter->reset();
168 fPrimitives.erase(iter);
169 return true;
170 }
171
172 /// Remove drawable at specified position
173 bool RemoveAt(unsigned indx)
174 {
175 if (indx >= fPrimitives.size()) return false;
176 fPrimitives[indx].reset();
177 fPrimitives.erase(fPrimitives.begin() + indx);
178 return true;
179 }
180
181 /// Wipe the pad by clearing the list of primitives.
182 void Wipe() { fPrimitives.clear(); }
183
184 std::shared_ptr<RFrame> GetOrCreateFrame();
185 std::shared_ptr<RFrame> GetFrame();
186 const std::shared_ptr<RFrame> GetFrame() const;
187
188 RPadUserAxisBase* GetOrCreateAxis(size_t dimension);
189 RPadUserAxisBase* GetAxis(size_t dimension) const;
190
191 void SetAxisBounds(int dimension, double begin, double end);
192 void SetAxisBound(int dimension, RPadUserAxisBase::EAxisBoundsKind boundsKind, double bound);
193 void SetAxisAutoBounds(int dimension);
194
195 void SetAllAxisBounds(const std::vector<std::array<double, 2>> &vecBeginAndEnd);
196
197 /// Simple struct representing an axis bound.
200 double fBound = 0.;
201 };
202 void SetAllAxisBound(const std::vector<BoundKindAndValue> &vecBoundAndKind);
204
205 /// Convert a `Pixel` position to Canvas-normalized positions.
206 virtual std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const = 0;
207
208 /// Access to the top-most canvas, if any (const version).
209 virtual const RCanvas *GetCanvas() const = 0;
210
211 /// Access to the top-most canvas, if any (non-const version).
212 virtual RCanvas *GetCanvas() = 0;
213
214 /// Convert user coordinates to normal coordinates.
215 std::array<RPadLength::Normal, 2> UserToNormal(const std::array<RPadLength::User, 2> &pos) const;
216
217 void AssignAutoColors();
218};
219
220} // namespace Experimental
221} // namespace ROOT
222
223#endif
short Version_t
Definition: RtypesCore.h:63
A window's topmost RPad.
Definition: RCanvas.hxx:46
Base class for drawable entities: objects that can be painted on a RPad.
Definition: RDrawable.hxx:102
virtual bool IsFrameRequired() const
Definition: RDrawable.hxx:175
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
RPadBase & operator=(const RPadBase &)=delete
Disable assignment.
RPadBase(const RPadBase &)=delete
Disable copy construction.
std::shared_ptr< RFrame > GetFrame()
Get a frame object if exists.
Definition: RPadBase.cxx:229
auto Draw(std::shared_ptr< RDrawable > &&drawable)
Add existing drawable instance to canvas.
Definition: RPadBase.hxx:98
bool Remove(const std::shared_ptr< RDrawable > &drawable)
Remove drawable from list of primitives.
Definition: RPadBase.hxx:161
std::array< RPadLength::Normal, 2 > UserToNormal(const std::array< RPadLength::User, 2 > &pos) const
Convert user coordinates to normal coordinates.
Definition: RPadBase.cxx:355
std::shared_ptr< RFrame > GetOrCreateFrame()
Get a frame object for the pad.
Definition: RPadBase.cxx:201
virtual std::array< RPadLength::Normal, 2 > PixelsToNormal(const std::array< RPadLength::Pixel, 2 > &pos) const =0
Convert a Pixel position to Canvas-normalized positions.
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:136
void UseStyle(const std::shared_ptr< RStyle > &style) override
Use provided style for pad and all primitives inside.
Definition: RPadBase.cxx:28
RPadBase()
Allow derived classes to default construct a RPadBase.
Definition: RPadBase.hxx:61
void CollectShared(Internal::RIOSharedVector_t &) override
Collect all shared items to resolve shared_ptr after IO.
Definition: RPadBase.cxx:332
auto Draw(ARGS... args)
Create drawable of specified class T.
Definition: RPadBase.hxx:86
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:164
void TestIfFrameRequired(const RDrawable *drawable)
Definition: RPadBase.hxx:53
std::vector< std::shared_ptr< RDrawable > > Primitives_t
Definition: RPadBase.hxx:71
void SetAllAxisBound(const std::vector< BoundKindAndValue > &vecBoundAndKind)
Set the range of an axis as bound kind and bound (up or down).
Definition: RPadBase.cxx:313
void SetAxisBounds(int dimension, double begin, double end)
Set the range of an axis as begin, end.
Definition: RPadBase.cxx:267
std::shared_ptr< RDrawable > GetPrimitive(unsigned num) const
returns primitive of given number
Definition: RPadBase.hxx:127
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:149
void SetAllAxisAutoBounds()
Set the range of an axis as bound kind and bound (up or down).
Definition: RPadBase.cxx:344
void SetDrawableVersion(Version_t vers) override
Assign drawable version - for pad itself and all primitives.
Definition: RPadBase.cxx:366
void SetAxisBound(int dimension, RPadUserAxisBase::EAxisBoundsKind boundsKind, double bound)
Set the range of an axis as bound kind and bound (up or down).
Definition: RPadBase.cxx:276
auto GetPrimitives() const
Get all primitives contained in the pad.
Definition: RPadBase.hxx:140
unsigned NumPrimitives() const
returns number of primitives in the pad
Definition: RPadBase.hxx:124
std::vector< Primitive_t > fPrimitives
Content of the pad.
Definition: RPadBase.hxx:45
void SetAllAxisBounds(const std::vector< std::array< double, 2 > > &vecBeginAndEnd)
Set the range of an axis as bound kind and bound (up or down).
Definition: RPadBase.cxx:294
virtual RCanvas * GetCanvas()=0
Access to the top-most canvas, if any (non-const version).
RPadUserAxisBase * GetAxis(size_t dimension) const
Get a pad axis from the RFrame.
Definition: RPadBase.cxx:244
bool RemoveAt(unsigned indx)
Remove drawable at specified position.
Definition: RPadBase.hxx:173
void AssignAutoColors()
Method collect existing colors and assign new values if required.
Definition: RPadBase.cxx:108
RPadUserAxisBase * GetOrCreateAxis(size_t dimension)
Get a pad axis from the RFrame.
Definition: RPadBase.cxx:257
auto Draw(const std::shared_ptr< T > &what, ARGS... args)
Add object to be painted.
Definition: RPadBase.hxx:111
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:62
void Wipe()
Wipe the pad by clearing the list of primitives.
Definition: RPadBase.hxx:182
void SetAxisAutoBounds(int dimension)
Set the range of an axis as bound kind and bound (up or down).
Definition: RPadBase.cxx:285
std::shared_ptr< RDrawable > FindPrimitive(const std::string &id) const
Find primitive with specified id.
Definition: RPadBase.cxx:38
const RPadBase * FindPadForPrimitiveWithDisplayId(const std::string &display_id) const
Find subpad which contains primitive with given display id.
Definition: RPadBase.cxx:85
An extent / size (horizontal and vertical) in a RPad.
Definition: RPadExtent.hxx:27
Base class for user coordinates (e.g.
EAxisBoundsKind
Types of axis bounds to respect by the painter.
@ kAxisBoundsAuto
no defined axis range; the painter will decide
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition: RDrawable.hxx:51
auto GetDrawable(const std::shared_ptr< DRAWABLE > &drawable)
Central method to insert drawable in list of pad primitives By default drawable placed as is.
Definition: RDrawable.hxx:216
double T(double x)
Definition: ChebyshevPol.h:34
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
static const char * what
Definition: stlLoader.cc:6
Simple struct representing an axis bound.
Definition: RPadBase.hxx:198
RPadUserAxisBase::EAxisBoundsKind fKind
Definition: RPadBase.hxx:199
TCanvas * style()
Definition: style.C:1
#define ARGS(alist)
Definition: gifencode.c:10