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