Logo ROOT   master
Reference Guide
RDrawable.hxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 1995-2015, 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 
19 
20 namespace ROOT {
21 namespace Experimental {
22 
23 class RMenuItems;
24 class RPadBase;
25 class RAttrBase;
26 class RDisplayItem;
27 class RLegend;
28 
29 
30 namespace Internal {
31 
32 /** \class RIOSharedBase
33 \ingroup GpadROOT7
34 \author Sergey Linev <s.linev@gsi.de>
35 \date 2019-09-24
36 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
37 */
38 
40 public:
41  virtual const void *GetIOPtr() const = 0;
42  virtual bool HasShared() const = 0;
43  virtual void *MakeShared() = 0;
44  virtual void SetShared(void *shared) = 0;
45  virtual ~RIOSharedBase() = default;
46 };
47 
48 using RIOSharedVector_t = std::vector<RIOSharedBase *>;
49 
50 template<class T>
51 class RIOShared final : public RIOSharedBase {
52  std::shared_ptr<T> fShared; ///<! holder of object
53  T* fIO{nullptr}; ///< plain pointer for IO
54 public:
55  const void *GetIOPtr() const final { return fIO; }
56  virtual bool HasShared() const final { return fShared.get() != nullptr; }
57  virtual void *MakeShared() final { fShared.reset(fIO); return &fShared; }
58  virtual void SetShared(void *shared) final { fShared = *((std::shared_ptr<T> *) shared); }
59 
60  RIOShared() = default;
61 
62  RIOShared(const std::shared_ptr<T> &ptr) : RIOSharedBase()
63  {
64  fShared = ptr;
65  fIO = ptr.get();
66  }
67 
68  RIOShared &operator=(const std::shared_ptr<T> &ptr)
69  {
70  fShared = ptr;
71  fIO = ptr.get();
72  return *this;
73  }
74 
75  operator bool() const { return !!fShared || !!fIO; }
76 
77  const T *get() const { return fShared ? fShared.get() : fIO; }
78  T *get() { return fShared ? fShared.get() : fIO; }
79 
80  const T *operator->() const { return get(); }
81  T *operator->() { return get(); }
82 
83  std::shared_ptr<T> get_shared() const { return fShared; }
84 
85  void reset() { fShared.reset(); fIO = nullptr; }
86 };
87 
88 }
89 
90 /** \class RDrawable
91 \ingroup GpadROOT7
92 \brief Base class for drawable entities: objects that can be painted on a `RPad`.
93 \author Axel Naumann <axel@cern.ch>
94 \author Sergey Linev <s.linev@gsi.de>
95 \date 2015-08-07
96 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
97 */
98 
99 class RDrawable {
100 
101 friend class RPadBase; // to access Display method and IsFrameRequired
102 friend class RAttrBase;
103 friend class RStyle;
104 friend class RLegend; // to access CollectShared method
105 
106 private:
107  RAttrMap fAttr; ///< attributes values
108  std::weak_ptr<RStyle> fStyle; ///<! style applied for RDrawable, not stored when canvas is saved
109  std::string fCssType; ///<! drawable type, not stored in the root file, must be initialized in constructor
110  std::string fCssClass; ///< user defined drawable class, can later go inside map
111  std::string fId; ///< optional object identifier, may be used in CSS as well
112 
113 protected:
114 
116 
117  virtual bool IsFrameRequired() const { return false; }
118 
119  RAttrMap &GetAttrMap() { return fAttr; }
120  const RAttrMap &GetAttrMap() const { return fAttr; }
121 
122  bool MatchSelector(const std::string &selector) const;
123 
124  virtual std::unique_ptr<RDisplayItem> Display() const;
125 
126 public:
127 
128  explicit RDrawable(const std::string &type) : fCssType(type) {}
129 
130  virtual ~RDrawable();
131 
132  // copy constructor and assign operator !!!
133 
134  /** Method can be used to provide menu items for the drawn object */
135  virtual void PopulateMenu(RMenuItems &) {}
136 
137  virtual void Execute(const std::string &);
138 
139  virtual void UseStyle(const std::shared_ptr<RStyle> &style) { fStyle = style; }
140  void ClearStyle() { UseStyle(nullptr); }
141 
142  void SetCssClass(const std::string &cl) { fCssClass = cl; }
143  const std::string &GetCssClass() const { return fCssClass; }
144 
145  const std::string &GetCssType() const { return fCssType; }
146 
147  const std::string &GetId() const { return fId; }
148  void SetId(const std::string &id) { fId = id; }
149 
150 };
151 
152 /// Central method to insert drawable in list of pad primitives
153 /// By default drawable placed as is.
154 template <class DRAWABLE, std::enable_if_t<std::is_base_of<RDrawable, DRAWABLE>{}>* = nullptr>
155 inline auto GetDrawable(const std::shared_ptr<DRAWABLE> &drawable)
156 {
157  return drawable;
158 }
159 
160 } // namespace Experimental
161 } // namespace ROOT
162 
163 #endif
RAttrMap fAttr
attributes values
Definition: RDrawable.hxx:107
virtual void CollectShared(Internal::RIOSharedVector_t &)
Definition: RDrawable.hxx:115
void SetId(const std::string &id)
Definition: RDrawable.hxx:148
const void * GetIOPtr() const final
Definition: RDrawable.hxx:55
RIOShared & operator=(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:68
Base class for drawable entities: objects that can be painted on a RPad.
Definition: RDrawable.hxx:99
std::string fCssType
! drawable type, not stored in the root file, must be initialized in constructor
Definition: RDrawable.hxx:109
RIOShared(const std::shared_ptr< T > &ptr)
Definition: RDrawable.hxx:62
Returns the available number of logical cores.
Definition: StringConv.hxx:21
const std::string & GetId() const
Definition: RDrawable.hxx:147
double T(double x)
Definition: ChebyshevPol.h:34
std::weak_ptr< RStyle > fStyle
! style applied for RDrawable, not stored when canvas is saved
Definition: RDrawable.hxx:108
virtual const void * GetIOPtr() const =0
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:155
virtual void SetShared(void *shared)=0
const std::string & GetCssClass() const
Definition: RDrawable.hxx:143
RDrawable(const std::string &type)
Definition: RDrawable.hxx:128
std::shared_ptr< T > fShared
! holder of object
Definition: RDrawable.hxx:52
virtual std::unique_ptr< RDisplayItem > Display() const
Creates display item for drawable By default item contains drawable data itself.
Definition: RDrawable.cxx:42
virtual void Execute(const std::string &)
Definition: RDrawable.cxx:20
virtual void UseStyle(const std::shared_ptr< RStyle > &style)
Definition: RDrawable.hxx:139
virtual void * MakeShared() final
Definition: RDrawable.hxx:57
XFontStruct * id
Definition: TGX11.cxx:108
std::vector< RIOSharedBase * > RIOSharedVector_t
Definition: RDrawable.hxx:48
virtual bool IsFrameRequired() const
Definition: RDrawable.hxx:117
T * fIO
plain pointer for IO
Definition: RDrawable.hxx:53
Base class for all attributes, used with RDrawable.
Definition: RAttrBase.hxx:27
std::shared_ptr< T > get_shared() const
Definition: RDrawable.hxx:83
std::string fId
optional object identifier, may be used in CSS as well
Definition: RDrawable.hxx:111
virtual void SetShared(void *shared) final
Definition: RDrawable.hxx:58
void SetCssClass(const std::string &cl)
Definition: RDrawable.hxx:142
const std::string & GetCssType() const
Definition: RDrawable.hxx:145
const RAttrMap & GetAttrMap() const
Definition: RDrawable.hxx:120
virtual void PopulateMenu(RMenuItems &)
Method can be used to provide menu items for the drawn object.
Definition: RDrawable.hxx:135
int type
Definition: TGX11.cxx:120
TCanvas * style()
Definition: style.C:1
bool MatchSelector(const std::string &selector) const
Preliminary method which checks if drawable matches with given selector Following selector are allowe...
Definition: RDrawable.cxx:33
virtual bool HasShared() const final
Definition: RDrawable.hxx:56
std::string fCssClass
user defined drawable class, can later go inside map
Definition: RDrawable.hxx:110
List of items for object context menu.
Definition: RMenuItem.hxx:151
A set of defaults for graphics attributes, e.g.
Definition: RStyle.hxx:31
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37