Logo ROOT  
Reference Guide
RDrawable.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, 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_RDrawable
10#define ROOT7_RDrawable
11
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <ROOT/RAttrMap.hxx>
17#include <ROOT/RStyle.hxx>
18
19namespace ROOT {
20namespace Experimental {
21
22class RMenuItems;
23class RPadBase;
24class RAttrBase;
25class RDisplayItem;
26class RIndirectDisplayItem;
27class RLegend;
28class RCanvas;
29class RChangeAttrRequest;
30class RDrawableMenuRequest;
31class RDrawableExecRequest;
32
33namespace Internal {
34
35/** \class RIOSharedBase
36\ingroup GpadROOT7
37\author Sergey Linev <s.linev@gsi.de>
38\date 2019-09-24
39\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
40*/
41
43public:
44 virtual const void *GetIOPtr() const = 0;
45 virtual bool HasShared() const = 0;
46 virtual void *MakeShared() = 0;
47 virtual void SetShared(void *shared) = 0;
48 virtual ~RIOSharedBase() = default;
49};
50
51using RIOSharedVector_t = std::vector<RIOSharedBase *>;
52
53template<class T>
54class RIOShared final : public RIOSharedBase {
55 std::shared_ptr<T> fShared; ///<! holder of object
56 T* fIO{nullptr}; ///< plain pointer for IO
57public:
58 const void *GetIOPtr() const final { return fIO; }
59 virtual bool HasShared() const final { return fShared.get() != nullptr; }
60 virtual void *MakeShared() final { fShared.reset(fIO); return &fShared; }
61 virtual void SetShared(void *shared) final { fShared = *((std::shared_ptr<T> *) shared); }
62
63 RIOShared() = default;
64
65 RIOShared(const std::shared_ptr<T> &ptr) : RIOSharedBase()
66 {
67 fShared = ptr;
68 fIO = ptr.get();
69 }
70
71 RIOShared &operator=(const std::shared_ptr<T> &ptr)
72 {
73 fShared = ptr;
74 fIO = ptr.get();
75 return *this;
76 }
77
78 operator bool() const { return !!fShared || !!fIO; }
79
80 const T *get() const { return fShared ? fShared.get() : fIO; }
81 T *get() { return fShared ? fShared.get() : fIO; }
82
83 const T *operator->() const { return get(); }
84 T *operator->() { return get(); }
85
86 std::shared_ptr<T> get_shared() const { return fShared; }
87
88 void reset() { fShared.reset(); fIO = nullptr; }
89};
90
91} // namespace Internal
92
93/** \class RDrawable
94\ingroup GpadROOT7
95\brief Base class for drawable entities: objects that can be painted on a `RPad`.
96\author Axel Naumann <axel@cern.ch>
97\author Sergey Linev <s.linev@gsi.de>
98\date 2015-08-07
99\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
100*/
101
103
104friend class RPadBase; // to access Display method and IsFrameRequired
105friend class RAttrBase;
106friend class RStyle;
107friend class RLegend; // to access CollectShared method
108friend class RIndirectDisplayItem; // to access attributes and other members
109friend class RChangeAttrRequest; // access SetDrawableVersion and AttrMap
110friend class RDrawableMenuRequest; // access PopulateMenu method
111friend class RDrawableExecRequest; // access Execute() method
112
113public:
114
115 using Version_t = uint64_t;
116
118 RCanvas *fCanvas{nullptr}; ///<! canvas where drawable is displayed
119 RPadBase *fPad{nullptr}; ///<! subpad where drawable is displayed
120 RDrawable *fDrawable{nullptr}; ///<! reference on the drawable
121 Version_t fLastVersion{0}; ///<! last displayed version
122 unsigned fIndex{0}; ///<! index in list of primitives
123 unsigned fConnId{0}; ///<! connection id
124 bool fMainConn{false}; ///<! is main connection
125
126 public:
127
128 RDisplayContext() = default;
129
130 RDisplayContext(RCanvas *canv, RPadBase *pad, Version_t vers = 0) :
131 fCanvas(canv), fPad(pad), fLastVersion(vers)
132 {
133 }
134
135 /** Set canvas */
136 void SetCanvas(RCanvas *canv) { fCanvas = canv; }
137 /** Set pad */
138 void SetPad(RPadBase *pad) { fPad = pad; }
139 /** Set drawable and its index in list of primitives */
140 void SetDrawable(RDrawable *dr, unsigned indx)
141 {
142 fDrawable = dr;
143 fIndex = indx;
144 }
145 /** Set connection id and ismain flag for connection */
146 void SetConnection(unsigned connid, bool ismain)
147 {
148 fConnId = connid;
149 fMainConn = ismain;
150 }
151
152 RCanvas *GetCanvas() const { return fCanvas; }
153 RPadBase *GetPad() const { return fPad; }
154 RDrawable *GetDrawable() const { return fDrawable; }
155 unsigned GetIndex() const { return fIndex; }
156
158
159 unsigned GetConnId() const { return fConnId; }
160 bool IsMainConn() const { return fMainConn; }
161 };
162
163private:
164 RAttrMap fAttr; ///< attributes values
165 std::weak_ptr<RStyle> fStyle; ///<! style applied for RDrawable, not stored when canvas is saved
166 std::string fCssType; ///<! drawable type, not stored in the root file, must be initialized in constructor
167 std::string fCssClass; ///< user defined drawable class, can later go inside map
168 std::string fId; ///< optional object identifier, may be used in CSS as well
169 Version_t fVersion{1}; ///<! drawable version, changed from the canvas
170
171protected:
172
174
175 virtual bool IsFrameRequired() const { return false; }
176
177 RAttrMap &GetAttrMap() { return fAttr; }
178 const RAttrMap &GetAttrMap() const { return fAttr; }
179
180 bool MatchSelector(const std::string &selector) const;
181
182 virtual std::unique_ptr<RDisplayItem> Display(const RDisplayContext &);
183
184 virtual void SetDrawableVersion(Version_t vers) { fVersion = vers; }
185 Version_t GetVersion() const { return fVersion; }
186
187 virtual void PopulateMenu(RMenuItems &);
188
189 virtual void Execute(const std::string &);
190
191 RDrawable(const RDrawable &) = delete;
192 RDrawable &operator=(const RDrawable &) = delete;
193
194public:
195
196 explicit RDrawable(const std::string &type) : fCssType(type) {}
197
198 virtual ~RDrawable();
199
200 virtual void UseStyle(const std::shared_ptr<RStyle> &style) { fStyle = style; }
201 void ClearStyle() { UseStyle(nullptr); }
202
203 void SetCssClass(const std::string &cl) { fCssClass = cl; }
204 const std::string &GetCssClass() const { return fCssClass; }
205
206 const std::string &GetCssType() const { return fCssType; }
207
208 const std::string &GetId() const { return fId; }
209 void SetId(const std::string &id) { fId = id; }
210};
211
212/// Central method to insert drawable in list of pad primitives
213/// By default drawable placed as is.
214
215template <class DRAWABLE, std::enable_if_t<std::is_base_of<RDrawable, DRAWABLE>{}>* = nullptr>
216inline auto GetDrawable(const std::shared_ptr<DRAWABLE> &drawable)
217{
218 return drawable;
219}
220
221} // namespace Experimental
222} // namespace ROOT
223
224#endif
XFontStruct * id
Definition: TGX11.cxx:108
int type
Definition: TGX11.cxx:120
virtual void SetShared(void *shared)=0
virtual const void * GetIOPtr() const =0
std::shared_ptr< T > fShared
! holder of object
Definition: RDrawable.hxx:55
virtual void SetShared(void *shared) final
Definition: RDrawable.hxx:61
RIOShared(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:65
const void * GetIOPtr() const final
Definition: RDrawable.hxx:58
virtual void * MakeShared() final
Definition: RDrawable.hxx:60
virtual bool HasShared() const final
Definition: RDrawable.hxx:59
RIOShared & operator=(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:71
std::shared_ptr< T > get_shared() const
Definition: RDrawable.hxx:86
Base class for all attributes, used with RDrawable.
Definition: RAttrBase.hxx:27
A window's topmost RPad.
Definition: RCanvas.hxx:46
Base class for requests which can be submitted from the clients.
Request menu items for the drawable object.
Definition: RMenuItems.hxx:202
void SetDrawable(RDrawable *dr, unsigned indx)
Set drawable and its index in list of primitives.
Definition: RDrawable.hxx:140
void SetCanvas(RCanvas *canv)
Set canvas.
Definition: RDrawable.hxx:136
RDisplayContext(RCanvas *canv, RPadBase *pad, Version_t vers=0)
Definition: RDrawable.hxx:130
RPadBase * fPad
! subpad where drawable is displayed
Definition: RDrawable.hxx:119
RDrawable * fDrawable
! reference on the drawable
Definition: RDrawable.hxx:120
void SetConnection(unsigned connid, bool ismain)
Set connection id and ismain flag for connection.
Definition: RDrawable.hxx:146
unsigned fIndex
! index in list of primitives
Definition: RDrawable.hxx:122
Version_t fLastVersion
! last displayed version
Definition: RDrawable.hxx:121
RCanvas * fCanvas
! canvas where drawable is displayed
Definition: RDrawable.hxx:118
Base class for drawable entities: objects that can be painted on a RPad.
Definition: RDrawable.hxx:102
const RAttrMap & GetAttrMap() const
Definition: RDrawable.hxx:178
RDrawable(const RDrawable &)=delete
RDrawable & operator=(const RDrawable &)=delete
virtual void Execute(const std::string &)
Definition: RDrawable.cxx:40
virtual bool IsFrameRequired() const
Definition: RDrawable.hxx:175
Version_t GetVersion() const
Definition: RDrawable.hxx:185
std::weak_ptr< RStyle > fStyle
! style applied for RDrawable, not stored when canvas is saved
Definition: RDrawable.hxx:165
const std::string & GetId() const
Definition: RDrawable.hxx:208
void SetCssClass(const std::string &cl)
Definition: RDrawable.hxx:203
RAttrMap fAttr
attributes values
Definition: RDrawable.hxx:164
virtual void SetDrawableVersion(Version_t vers)
Definition: RDrawable.hxx:184
std::string fCssClass
user defined drawable class, can later go inside map
Definition: RDrawable.hxx:167
virtual void PopulateMenu(RMenuItems &)
Definition: RDrawable.cxx:30
std::string fId
optional object identifier, may be used in CSS as well
Definition: RDrawable.hxx:168
const std::string & GetCssType() const
Definition: RDrawable.hxx:206
bool MatchSelector(const std::string &selector) const
Preliminary method which checks if drawable matches with given selector Following selector are allowe...
Definition: RDrawable.cxx:59
virtual void UseStyle(const std::shared_ptr< RStyle > &style)
Definition: RDrawable.hxx:200
const std::string & GetCssClass() const
Definition: RDrawable.hxx:204
void SetId(const std::string &id)
Definition: RDrawable.hxx:209
virtual void CollectShared(Internal::RIOSharedVector_t &)
Definition: RDrawable.hxx:173
RDrawable(const std::string &type)
Definition: RDrawable.hxx:196
Version_t fVersion
! drawable version, changed from the canvas
Definition: RDrawable.hxx:169
std::string fCssType
! drawable type, not stored in the root file, must be initialized in constructor
Definition: RDrawable.hxx:166
virtual std::unique_ptr< RDisplayItem > Display(const RDisplayContext &)
Creates display item for drawable By default item contains drawable data itself.
Definition: RDrawable.cxx:68
List of items for object context menu.
Definition: RMenuItems.hxx:153
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
A set of defaults for graphics attributes, e.g.
Definition: RStyle.hxx:31
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
TCanvas * style()
Definition: style.C:1