Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDrawable.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, 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\authors Axel Naumann <axel@cern.ch>, Sergey Linev <s.linev@gsi.de>
104\date 2015-08-07
105\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
106*/
107
109
110friend class RPadBase; // to access Display method and IsFrameRequired
111friend class RCanvas; // to access SetDrawableVersion
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 const char *fCssType{nullptr}; ///<! drawable type, not stored in the root file, must be initialized in constructor
175 std::string fCssClass; ///< user-defined CSS class, used for RStyle
176 std::string fId; ///< user-defined CSS id, used for RStyle
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 void SetCssType(const char *csstype) { fCssType = csstype; }
193
194 virtual void OnDisplayItemDestroyed(RDisplayItem *) const {}
195
196 virtual void SetDrawableVersion(Version_t vers) { fVersion = vers; }
197 Version_t GetVersion() const { return fVersion; }
198
199 virtual void PopulateMenu(RMenuItems &);
200
201 virtual void Execute(const std::string &);
202
203 RDrawable(const RDrawable &) = delete;
204 RDrawable &operator=(const RDrawable &) = delete;
205
206public:
207
208 explicit RDrawable(const char *csstype) : fCssType(csstype) {}
209
210 virtual ~RDrawable();
211
212 virtual void UseStyle(const std::shared_ptr<RStyle> &style) { fStyle = style; }
213 void ClearStyle() { UseStyle(nullptr); }
214
215 const char *GetCssType() const { return fCssType; }
216
217 void SetCssClass(const std::string &cl) { fCssClass = cl; }
218 const std::string &GetCssClass() const { return fCssClass; }
219
220 void SetId(const std::string &id) { fId = id; }
221 const std::string &GetId() const { return fId; }
222};
223
224/// Central method to insert drawable in list of pad primitives
225/// By default drawable placed as is.
226
227template <class DRAWABLE, std::enable_if_t<std::is_base_of<RDrawable, DRAWABLE>{}>* = nullptr>
228inline auto GetDrawable(const std::shared_ptr<DRAWABLE> &drawable)
229{
230 return drawable;
231}
232
233} // namespace Experimental
234} // namespace ROOT
235
236#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t style
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 CSS class, used for RStyle
RDrawable(const char *csstype)
virtual void PopulateMenu(RMenuItems &)
Definition RDrawable.cxx:30
std::string fId
user-defined CSS id, used for RStyle
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
const char * fCssType
! drawable type, not stored in the root file, must be initialized in constructor
virtual void UseStyle(const std::shared_ptr< RStyle > &style)
void SetCssType(const char *csstype)
const std::string & GetCssClass() const
void SetId(const std::string &id)
virtual void CollectShared(Internal::RIOSharedVector_t &)
const char * GetCssType() const
Version_t fVersion
! drawable version, changed from the canvas
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...