Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFrame.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2017, 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_RFrame
10#define ROOT7_RFrame
11
12#include "ROOT/RDrawable.hxx"
13
15#include "ROOT/RAttrLine.hxx"
16#include "ROOT/RAttrFill.hxx"
17#include "ROOT/RAttrMargins.hxx"
18#include "ROOT/RAttrAxis.hxx"
19#include "ROOT/RAttrValue.hxx"
20#include "ROOT/RPadUserAxis.hxx"
21
22#include <memory>
23#include <map>
24
25class TRootIOCtor;
26
27namespace ROOT {
28namespace Experimental {
29
30
31/** \class RFrame
32\ingroup GpadROOT7
33\brief Holds an area where drawing on user coordinate-system can be performed.
34\authors Axel Naumann <axel@cern.ch> Sergey Linev <s.linev@gsi.de>
35\date 2017-09-26
36\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
37*/
38
39class RFrame : public RDrawable {
40
41 friend class RPadBase;
42
43public:
44
46 std::vector<double> values; ///< min/max values for all dimensions
47 std::vector<bool> flags; ///< flag if values available
48
49 void UpdateDim(unsigned ndim, const RUserRanges &src)
50 {
51 if (src.IsUnzoom(ndim)) {
52 ClearMinMax(ndim);
53 } else {
54 if (src.HasMin(ndim))
55 AssignMin(ndim, src.GetMin(ndim));
56 if (src.HasMax(ndim))
57 AssignMax(ndim, src.GetMax(ndim));
58 }
59 }
60
61 public:
62 // Default constructor - for I/O
63 RUserRanges() = default;
64
65 // Constructor for 1-d ranges
66 RUserRanges(double xmin, double xmax)
67 {
68 AssignMin(0, xmin);
69 AssignMax(0, xmax);
70 }
71
72 // Constructor for 2-d ranges
73 RUserRanges(double xmin, double xmax, double ymin, double ymax)
74 {
75 AssignMin(0, xmin);
76 AssignMax(0, xmax);
77 AssignMin(1, ymin);
78 AssignMax(1, ymax);
79 }
80
81 // Extend number of dimensions which can be stored in the object
82 void Extend(unsigned ndim = 3)
83 {
84 if (ndim*2 > values.size()) {
85 values.resize(ndim*2, 0.);
86 flags.resize(ndim*2, false);
87 }
88 }
89
90 bool HasMin(unsigned ndim) const { return (ndim*2 < flags.size()) && flags[ndim*2]; }
91 double GetMin(unsigned ndim) const { return (ndim*2 < values.size()) ? values[ndim*2] : 0.; }
92
93 // Assign minimum for specified dimension
94 void AssignMin(unsigned ndim, double value)
95 {
96 Extend(ndim+1);
97 values[ndim*2] = value;
98 flags[ndim*2] = true;
99 }
100
101 bool HasMax(unsigned ndim) const { return (ndim*2+1 < flags.size()) && flags[ndim*2+1]; }
102 double GetMax(unsigned ndim) const { return (ndim*2+1 < values.size()) ? values[ndim*2+1] : 0.; }
103
104 // Assign maximum for specified dimension
105 void AssignMax(unsigned ndim, double value)
106 {
107 Extend(ndim+1);
108 values[ndim*2+1] = value;
109 flags[ndim*2+1] = true;
110 }
111
112 void ClearMinMax(unsigned ndim)
113 {
114 if (ndim*2+1 < flags.size())
115 flags[ndim*2] = flags[ndim*2+1] = false;
116
117 if (ndim*2+1 < values.size())
118 values[ndim*2] = values[ndim*2+1] = 0.;
119 }
120
121 /** Returns true if axis configured as unzoomed, can be specified from client */
122 bool IsUnzoom(unsigned ndim) const
123 {
124 return (ndim*2+1 < flags.size()) && (ndim*2+1 < values.size()) &&
125 !flags[ndim*2] && !flags[ndim*2+1] &&
126 (values[ndim*2] < -0.5) && (values[ndim*2+1] < -0.5);
127 }
128
129 // Returns true if any value is specified
130 bool IsAny() const
131 {
132 for (auto fl : flags)
133 if (fl) return true;
134 return false;
135 }
136
137 void Update(const RUserRanges &src)
138 {
139 UpdateDim(0, src);
140 UpdateDim(1, src);
141 UpdateDim(2, src);
142 }
143
144 };
145
146private:
147 RAttrMargins fMargins{this, "margin"}; ///<! frame margins relative to pad
148 RAttrLine fAttrBorder{this, "border"}; ///<! line attributes for border
149 RAttrFill fAttrFill{this, "fill"}; ///<! fill attributes for the frame
150 RAttrAxis fAttrX{this, "x"}; ///<! drawing attributes for X axis
151 RAttrAxis fAttrY{this, "y"}; ///<! drawing attributes for Y axis
152 RAttrAxis fAttrZ{this, "z"}; ///<! drawing attributes for Z axis
153 RAttrValue<bool> fGridX{this, "gridx", false}; ///<! show grid for X axis
154 RAttrValue<bool> fGridY{this, "gridy", false}; ///<! show grid for Y axis
155 RAttrValue<bool> fSwapX{this, "swapx", false}; ///<! swap position of X axis
156 RAttrValue<bool> fSwapY{this, "swapy", false}; ///<! swap position of Y axis
157 RAttrValue<int> fTicksX{this, "ticksx", 1}; ///<! X ticks drawing:
158 RAttrValue<int> fTicksY{this, "ticksy", 1}; ///<! Y ticks drawing
159 std::map<unsigned, RUserRanges> fClientRanges; ///<! individual client ranges
160
161 /// Mapping of user coordinates to normal coordinates, one entry per dimension.
162 std::vector<std::unique_ptr<RPadUserAxisBase>> fUserCoord;
163
164 RFrame(const RFrame &) = delete;
165 RFrame &operator=(const RFrame &) = delete;
166
167 // Default constructor
168 RFrame() : RDrawable("frame")
169 {
171 }
172
173 /// Constructor taking user coordinate system, position and extent.
174 explicit RFrame(std::vector<std::unique_ptr<RPadUserAxisBase>> &&coords);
175
176 void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn);
177
178protected:
179
180 void PopulateMenu(RMenuItems &) override;
181
182 void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const;
183 void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges);
184
185public:
186
188 RUserRanges ranges; // specified ranges
189 public:
190 RZoomRequest() = default;
191 std::unique_ptr<RDrawableReply> Process() override
192 {
193 auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
194 if (frame) frame->SetClientRanges(GetContext().GetConnId(), ranges, GetContext().IsMainConn());
195 return nullptr;
196 }
197 };
198
199
201
202 const RAttrMargins &GetMargins() const { return fMargins; }
203 RFrame &SetMargins(const RAttrMargins &margins) { fMargins = margins; return *this; }
205
206 const RAttrLine &GetAttrBorder() const { return fAttrBorder; }
207 RFrame &SetAttrBorder(const RAttrLine &border) { fAttrBorder = border; return *this; }
209
210 const RAttrFill &GetAttrFill() const { return fAttrFill; }
211 RFrame &SetAttrFill(const RAttrFill &fill) { fAttrFill = fill; return *this; }
213
214 const RAttrAxis &GetAttrX() const { return fAttrX; }
215 RFrame &SetAttrX(const RAttrAxis &axis) { fAttrX = axis; return *this; }
216 RAttrAxis &AttrX() { return fAttrX; }
217
218 const RAttrAxis &GetAttrY() const { return fAttrY; }
219 RFrame &SetAttrY(const RAttrAxis &axis) { fAttrY = axis; return *this; }
220 RAttrAxis &AttrY() { return fAttrY; }
221
222 const RAttrAxis &GetAttrZ() const { return fAttrZ; }
223 RFrame &SetAttrZ(const RAttrAxis &axis) { fAttrZ = axis; return *this; }
224 RAttrAxis &AttrZ() { return fAttrZ; }
225
226 RFrame &SetGridX(bool on = true) { fGridX = on; return *this; }
227 bool GetGridX() const { return fGridX; }
228
229 RFrame &SetGridY(bool on = true) { fGridY = on; return *this; }
230 bool GetGridY() const { return fGridY; }
231
232 RFrame &SetSwapX(bool on = true) { fSwapX = on; return *this; }
233 bool GetSwapX() const { return fSwapX; }
234
235 RFrame &SetSwapY(bool on = true) { fSwapY = on; return *this; }
236 bool GetSwapY() const { return fSwapY; }
237
238 /** Configure X ticks drawing 0 - off, 1 - as configured for axis, 2 - both sides, 3 - labels on both side */
239 RFrame &SetTicksX(int v = 1) { fTicksX = v; return *this; }
240 int GetTicksX() const { return fTicksX; }
241
242 /** Configure Y ticks drawing 0 - off, 1 - as configured for axis, 2 - both sides, 3 - labels on both side */
243 RFrame &SetTicksY(int v = 1) { fTicksY = v; return *this; }
244 int GetTicksY() const { return fTicksY; }
245
246 void GetClientRanges(unsigned connid, RUserRanges &ranges);
247
248 /// Create `nDimensions` default axes for the user coordinate system.
249 void GrowToDimensions(size_t nDimensions);
250
251 /// Get the number of axes.
252 size_t GetNDimensions() const { return fUserCoord.size(); }
253
254 /// Get the current user coordinate system for a given dimension.
255 RPadUserAxisBase &GetUserAxis(size_t dimension) const { return *fUserCoord[dimension]; }
256
257 /// Set the user coordinate system.
258 void SetUserAxis(std::vector<std::unique_ptr<RPadUserAxisBase>> &&axes) { fUserCoord = std::move(axes); }
259
260 /// Convert user coordinates to normal coordinates.
261 std::array<RPadLength::Normal, 2> UserToNormal(const std::array<RPadLength::User, 2> &pos) const
262 {
263 return {{fUserCoord[0]->ToNormal(pos[0]), fUserCoord[1]->ToNormal(pos[1])}};
264 }
265};
266
267
268} // namespace Experimental
269} // namespace ROOT
270
271#endif
float xmin
float ymin
float xmax
float ymax
All supported axes attributes for: line, ticks, labels, title, min/max, log, reverse,...
Definition RAttrAxis.hxx:29
Drawing fill attributes for different objects.
Definition RAttrFill.hxx:27
Drawing line attributes for different objects.
Definition RAttrLine.hxx:27
A margins attributes. Only relative and pixel coordinates are allowed.
Template class to access single value from drawable or other attributes.
Base class for requests which can be submitted from the clients.
const RDrawable::RDisplayContext & GetContext() const
Base class for drawable entities: objects that can be painted on a RPad.
bool IsUnzoom(unsigned ndim) const
Returns true if axis configured as unzoomed, can be specified from client.
Definition RFrame.hxx:122
bool HasMin(unsigned ndim) const
Definition RFrame.hxx:90
void Update(const RUserRanges &src)
Definition RFrame.hxx:137
void AssignMin(unsigned ndim, double value)
Definition RFrame.hxx:94
RUserRanges(double xmin, double xmax, double ymin, double ymax)
Definition RFrame.hxx:73
bool HasMax(unsigned ndim) const
Definition RFrame.hxx:101
std::vector< double > values
min/max values for all dimensions
Definition RFrame.hxx:46
void UpdateDim(unsigned ndim, const RUserRanges &src)
Definition RFrame.hxx:49
double GetMax(unsigned ndim) const
Definition RFrame.hxx:102
RUserRanges(double xmin, double xmax)
Definition RFrame.hxx:66
std::vector< bool > flags
flag if values available
Definition RFrame.hxx:47
double GetMin(unsigned ndim) const
Definition RFrame.hxx:91
void AssignMax(unsigned ndim, double value)
Definition RFrame.hxx:105
std::unique_ptr< RDrawableReply > Process() override
Definition RFrame.hxx:191
Holds an area where drawing on user coordinate-system can be performed.
Definition RFrame.hxx:39
RAttrMargins & Margins()
Definition RFrame.hxx:204
std::array< RPadLength::Normal, 2 > UserToNormal(const std::array< RPadLength::User, 2 > &pos) const
Convert user coordinates to normal coordinates.
Definition RFrame.hxx:261
RFrame & SetAttrX(const RAttrAxis &axis)
Definition RFrame.hxx:215
RFrame & SetGridX(bool on=true)
Definition RFrame.hxx:226
std::map< unsigned, RUserRanges > fClientRanges
! individual client ranges
Definition RFrame.hxx:159
RAttrValue< int > fTicksY
! Y ticks drawing
Definition RFrame.hxx:158
const RAttrAxis & GetAttrY() const
Definition RFrame.hxx:218
RFrame & SetAttrFill(const RAttrFill &fill)
Definition RFrame.hxx:211
RAttrMargins fMargins
! frame margins relative to pad
Definition RFrame.hxx:147
RFrame(const RFrame &)=delete
RAttrValue< bool > fGridX
! show grid for X axis
Definition RFrame.hxx:153
RAttrAxis fAttrX
! drawing attributes for X axis
Definition RFrame.hxx:150
RFrame & SetSwapX(bool on=true)
Definition RFrame.hxx:232
const RAttrAxis & GetAttrZ() const
Definition RFrame.hxx:222
RAttrValue< bool > fGridY
! show grid for Y axis
Definition RFrame.hxx:154
void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges)
Internal - assign client zoomed range to specified axis.
Definition RFrame.cxx:45
RFrame & SetTicksY(int v=1)
Configure Y ticks drawing 0 - off, 1 - as configured for axis, 2 - both sides, 3 - labels on both sid...
Definition RFrame.hxx:243
void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const
Internal - extract range for specified axis.
Definition RFrame.cxx:33
RFrame & SetMargins(const RAttrMargins &margins)
Definition RFrame.hxx:203
const RAttrAxis & GetAttrX() const
Definition RFrame.hxx:214
void GetClientRanges(unsigned connid, RUserRanges &ranges)
Return ranges configured for the client.
Definition RFrame.cxx:114
RFrame & operator=(const RFrame &)=delete
RFrame(TRootIOCtor *)
Definition RFrame.hxx:200
size_t GetNDimensions() const
Get the number of axes.
Definition RFrame.hxx:252
RAttrValue< bool > fSwapX
! swap position of X axis
Definition RFrame.hxx:155
void SetUserAxis(std::vector< std::unique_ptr< RPadUserAxisBase > > &&axes)
Set the user coordinate system.
Definition RFrame.hxx:258
RFrame & SetAttrZ(const RAttrAxis &axis)
Definition RFrame.hxx:223
const RAttrMargins & GetMargins() const
Definition RFrame.hxx:202
RFrame & SetSwapY(bool on=true)
Definition RFrame.hxx:235
RAttrLine fAttrBorder
! line attributes for border
Definition RFrame.hxx:148
RAttrAxis fAttrY
! drawing attributes for Y axis
Definition RFrame.hxx:151
const RAttrFill & GetAttrFill() const
Definition RFrame.hxx:210
const RAttrLine & GetAttrBorder() const
Definition RFrame.hxx:206
std::vector< std::unique_ptr< RPadUserAxisBase > > fUserCoord
Mapping of user coordinates to normal coordinates, one entry per dimension.
Definition RFrame.hxx:162
RFrame & SetAttrBorder(const RAttrLine &border)
Definition RFrame.hxx:207
RAttrFill fAttrFill
! fill attributes for the frame
Definition RFrame.hxx:149
RAttrValue< int > fTicksX
! X ticks drawing:
Definition RFrame.hxx:157
RPadUserAxisBase & GetUserAxis(size_t dimension) const
Get the current user coordinate system for a given dimension.
Definition RFrame.hxx:255
RFrame & SetTicksX(int v=1)
Configure X ticks drawing 0 - off, 1 - as configured for axis, 2 - both sides, 3 - labels on both sid...
Definition RFrame.hxx:239
void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn)
Remember client range, can be used for drawing or stats box calculations.
Definition RFrame.cxx:94
RFrame & SetAttrY(const RAttrAxis &axis)
Definition RFrame.hxx:219
RAttrAxis fAttrZ
! drawing attributes for Z axis
Definition RFrame.hxx:152
RAttrValue< bool > fSwapY
! swap position of Y axis
Definition RFrame.hxx:156
void PopulateMenu(RMenuItems &) override
Provide context menu items.
Definition RFrame.cxx:74
RFrame & SetGridY(bool on=true)
Definition RFrame.hxx:229
void GrowToDimensions(size_t nDimensions)
Create nDimensions default axes for the user coordinate system.
Definition RFrame.cxx:60
RAttrLine & AttrBorder()
Definition RFrame.hxx:208
List of items for object context menu.
Base class for graphic containers for RDrawable-s.
Definition RPadBase.hxx:37
Base class for user coordinates (e.g.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...