Logo ROOT  
Reference Guide
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
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\author Axel Naumann <axel@cern.ch>
35\author Sergey Linev <s.linev@gsi.de>
36\date 2017-09-26
37\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
38*/
39
40class RFrame : public RDrawable {
41
42 friend class RPadBase;
43
44public:
45
47 std::vector<double> values; ///< min/max values for all dimensions
48 std::vector<bool> flags; ///< flag if values available
49 public:
50 // Default constructor - for I/O
51 RUserRanges() = default;
52
53 // Constructor for 1-d ranges
54 RUserRanges(double xmin, double xmax)
55 {
56 AssignMin(0, xmin);
57 AssignMax(0, xmax);
58 }
59
60 // Constructor for 2-d ranges
61 RUserRanges(double xmin, double xmax, double ymin, double ymax)
62 {
63 AssignMin(0, xmin);
64 AssignMax(0, xmax);
65 AssignMin(1, ymin);
66 AssignMax(1, ymax);
67 }
68
69 // Extend number of dimensions which can be stored in the object
70 void Extend(unsigned ndim = 3)
71 {
72 if (ndim*2 > values.size()) {
73 values.resize(ndim*2, 0.);
74 flags.resize(ndim*2, false);
75 }
76 }
77
78 bool HasMin(unsigned ndim) const { return (ndim*2 < flags.size()) && flags[ndim*2]; }
79 double GetMin(unsigned ndim) const { return (ndim*2 < values.size()) ? values[ndim*2] : 0.; }
80
81 // Assign minimum for specified dimension
82 void AssignMin(unsigned ndim, double value, bool force = false)
83 {
84 if (!HasMin(ndim) || force) {
85 Extend(ndim+1);
86 values[ndim*2] = value;
87 flags[ndim*2] = true;
88 }
89 }
90
91 bool HasMax(unsigned ndim) const { return (ndim*2+1 < flags.size()) && flags[ndim*2+1]; }
92 double GetMax(unsigned ndim) const { return (ndim*2+1 < values.size()) ? values[ndim*2+1] : 0.; }
93
94 // Assign maximum for specified dimension
95 void AssignMax(unsigned ndim, double value, bool force = false)
96 {
97 if (!HasMax(ndim) || force) {
98 Extend(ndim+1);
99 values[ndim*2+1] = value;
100 flags[ndim*2+1] = true;
101 }
102 }
103
104 /** Returns true if axis configured as unzoomed, can be specified from client */
105 bool IsUnzoom(unsigned ndim) const
106 {
107 return (ndim*2+1 < flags.size()) && (ndim*2+1 < values.size()) &&
108 !flags[ndim*2] && !flags[ndim*2+1] &&
109 (values[ndim*2] < -0.5) && (values[ndim*2+1] < -0.5);
110 }
111
112 // Returns true if any value is specified
113 bool IsAny() const
114 {
115 for (auto fl : flags)
116 if (fl) return true;
117 return false;
118 }
119 };
120
121private:
122
123 class RFrameAttrs : public RAttrBase {
124 friend class RFrame;
125 R__ATTR_CLASS(RFrameAttrs, "", AddBool("gridx", false).AddBool("gridy",false));
126 };
127
128 RAttrMargins fMargins{this, "margin_"}; ///<!
129 RAttrLine fAttrBorder{this, "border_"}; ///<!
130 RAttrFill fAttrFill{this, "fill_"}; ///<!
131 RAttrAxis fAttrX{this, "x_"}; ///<!
132 RAttrAxis fAttrY{this, "y_"}; ///<!
133 RAttrAxis fAttrZ{this, "z_"}; ///<!
134 RFrameAttrs fAttr{this,""}; ///<! own frame attributes
135 std::map<unsigned, RUserRanges> fClientRanges; ///<! individual client ranges
136
137 /// Mapping of user coordinates to normal coordinates, one entry per dimension.
138 std::vector<std::unique_ptr<RPadUserAxisBase>> fUserCoord;
139
140 RFrame(const RFrame &) = delete;
141 RFrame &operator=(const RFrame &) = delete;
142
143 // Default constructor
144 RFrame() : RDrawable("frame")
145 {
147 }
148
149 /// Constructor taking user coordinate system, position and extent.
150 explicit RFrame(std::vector<std::unique_ptr<RPadUserAxisBase>> &&coords);
151
152 void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn);
153
154protected:
155
156 void PopulateMenu(RMenuItems &) override;
157
158 void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const;
159 void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges);
160
161public:
162
164 RUserRanges ranges; // specified ranges
165 public:
166 RZoomRequest() = default;
167 std::unique_ptr<RDrawableReply> Process() override
168 {
169 auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
170 if (frame) frame->SetClientRanges(GetContext().GetConnId(), ranges, GetContext().IsMainConn());
171 return nullptr;
172 }
173 };
174
175
177
178 const RAttrMargins &GetMargins() const { return fMargins; }
179 RFrame &SetMargins(const RAttrMargins &margins) { fMargins = margins; return *this; }
181
182 const RAttrLine &GetAttrBorder() const { return fAttrBorder; }
183 RFrame &SetAttrBorder(const RAttrLine &border) { fAttrBorder = border; return *this; }
185
186 const RAttrFill &GetAttrFill() const { return fAttrFill; }
187 RFrame &SetAttrFill(const RAttrFill &fill) { fAttrFill = fill; return *this; }
189
190 const RAttrAxis &GetAttrX() const { return fAttrX; }
191 RFrame &SetAttrX(const RAttrAxis &axis) { fAttrX = axis; return *this; }
192 RAttrAxis &AttrX() { return fAttrX; }
193
194 const RAttrAxis &GetAttrY() const { return fAttrY; }
195 RFrame &SetAttrY(const RAttrAxis &axis) { fAttrY = axis; return *this; }
196 RAttrAxis &AttrY() { return fAttrY; }
197
198 const RAttrAxis &GetAttrZ() const { return fAttrZ; }
199 RFrame &SetAttrZ(const RAttrAxis &axis) { fAttrZ = axis; return *this; }
200 RAttrAxis &AttrZ() { return fAttrZ; }
201
202 RFrame &SetGridX(bool on = true) { fAttr.SetValue("gridx", on); return *this; }
203 bool GetGridX() const { return fAttr.GetValue<bool>("gridx"); }
204
205 RFrame &SetGridY(bool on = true) { fAttr.SetValue("gridy", on); return *this; }
206 bool GetGridY() const { return fAttr.GetValue<bool>("gridy"); }
207
208 void GetClientRanges(unsigned connid, RUserRanges &ranges);
209
210 /// Create `nDimensions` default axes for the user coordinate system.
211 void GrowToDimensions(size_t nDimensions);
212
213 /// Get the number of axes.
214 size_t GetNDimensions() const { return fUserCoord.size(); }
215
216 /// Get the current user coordinate system for a given dimension.
217 RPadUserAxisBase &GetUserAxis(size_t dimension) const { return *fUserCoord[dimension]; }
218
219 /// Set the user coordinate system.
220 void SetUserAxis(std::vector<std::unique_ptr<RPadUserAxisBase>> &&axes) { fUserCoord = std::move(axes); }
221
222 /// Convert user coordinates to normal coordinates.
223 std::array<RPadLength::Normal, 2> UserToNormal(const std::array<RPadLength::User, 2> &pos) const
224 {
225 return {{fUserCoord[0]->ToNormal(pos[0]), fUserCoord[1]->ToNormal(pos[1])}};
226 }
227};
228
229
230} // namespace Experimental
231} // namespace ROOT
232
233#endif
float xmin
Definition: THbookFile.cxx:93
float ymin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
float ymax
Definition: THbookFile.cxx:93
All kind of drawing a axis: line, text, ticks, min/max, log, invert, ...
Definition: RAttrAxis.hxx:27
Base class for all attributes, used with RDrawable.
Definition: RAttrBase.hxx:27
void SetValue(const std::string &name, bool value)
Set boolean value.
Definition: RAttrBase.cxx:133
T GetValue(const std::string &name) const
Definition: RAttrBase.hxx:170
Drawing fill attributes for different objects.
Definition: RAttrFill.hxx:26
Drawing line attributes for different objects.
Definition: RAttrLine.hxx:26
A margins attributes. Only relative and pixel coordinates are allowed.
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.
Definition: RDrawable.hxx:102
R__ATTR_CLASS(RFrameAttrs, "", AddBool("gridx", false).AddBool("gridy", false))
bool IsUnzoom(unsigned ndim) const
Returns true if axis configured as unzoomed, can be specified from client.
Definition: RFrame.hxx:105
bool HasMin(unsigned ndim) const
Definition: RFrame.hxx:78
RUserRanges(double xmin, double xmax, double ymin, double ymax)
Definition: RFrame.hxx:61
void AssignMin(unsigned ndim, double value, bool force=false)
Definition: RFrame.hxx:82
bool HasMax(unsigned ndim) const
Definition: RFrame.hxx:91
std::vector< double > values
min/max values for all dimensions
Definition: RFrame.hxx:47
double GetMax(unsigned ndim) const
Definition: RFrame.hxx:92
void AssignMax(unsigned ndim, double value, bool force=false)
Definition: RFrame.hxx:95
RUserRanges(double xmin, double xmax)
Definition: RFrame.hxx:54
std::vector< bool > flags
flag if values available
Definition: RFrame.hxx:48
double GetMin(unsigned ndim) const
Definition: RFrame.hxx:79
void Extend(unsigned ndim=3)
Definition: RFrame.hxx:70
std::unique_ptr< RDrawableReply > Process() override
Definition: RFrame.hxx:167
Holds an area where drawing on user coordinate-system can be performed.
Definition: RFrame.hxx:40
RAttrMargins & Margins()
Definition: RFrame.hxx:180
std::array< RPadLength::Normal, 2 > UserToNormal(const std::array< RPadLength::User, 2 > &pos) const
Convert user coordinates to normal coordinates.
Definition: RFrame.hxx:223
RAttrFill & AttrFill()
Definition: RFrame.hxx:188
RFrame & SetAttrX(const RAttrAxis &axis)
Definition: RFrame.hxx:191
RFrame & SetGridX(bool on=true)
Definition: RFrame.hxx:202
std::map< unsigned, RUserRanges > fClientRanges
! individual client ranges
Definition: RFrame.hxx:135
const RAttrAxis & GetAttrY() const
Definition: RFrame.hxx:194
RFrame & SetAttrFill(const RAttrFill &fill)
Definition: RFrame.hxx:187
RAttrMargins fMargins
!
Definition: RFrame.hxx:128
RFrame(const RFrame &)=delete
const RAttrAxis & GetAttrZ() const
Definition: RFrame.hxx:198
void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges)
Internal - assign client zoomed range to specified axis.
Definition: RFrame.cxx:51
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:179
const RAttrAxis & GetAttrX() const
Definition: RFrame.hxx:190
void GetClientRanges(unsigned connid, RUserRanges &ranges)
Return ranges configured for the client.
Definition: RFrame.cxx:109
RFrame & operator=(const RFrame &)=delete
RFrame(TRootIOCtor *)
Definition: RFrame.hxx:176
size_t GetNDimensions() const
Get the number of axes.
Definition: RFrame.hxx:214
void SetUserAxis(std::vector< std::unique_ptr< RPadUserAxisBase > > &&axes)
Set the user coordinate system.
Definition: RFrame.hxx:220
RFrame & SetAttrZ(const RAttrAxis &axis)
Definition: RFrame.hxx:199
const RAttrMargins & GetMargins() const
Definition: RFrame.hxx:178
const RAttrFill & GetAttrFill() const
Definition: RFrame.hxx:186
const RAttrLine & GetAttrBorder() const
Definition: RFrame.hxx:182
std::vector< std::unique_ptr< RPadUserAxisBase > > fUserCoord
Mapping of user coordinates to normal coordinates, one entry per dimension.
Definition: RFrame.hxx:138
RFrame & SetAttrBorder(const RAttrLine &border)
Definition: RFrame.hxx:183
RPadUserAxisBase & GetUserAxis(size_t dimension) const
Get the current user coordinate system for a given dimension.
Definition: RFrame.hxx:217
void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn)
Remember client range, can be used for drawing or stats box calculations.
Definition: RFrame.cxx:95
RFrame & SetAttrY(const RAttrAxis &axis)
Definition: RFrame.hxx:195
void PopulateMenu(RMenuItems &) override
Provide context menu items.
Definition: RFrame.cxx:80
RFrameAttrs fAttr
! own frame attributes
Definition: RFrame.hxx:134
RFrame & SetGridY(bool on=true)
Definition: RFrame.hxx:205
void GrowToDimensions(size_t nDimensions)
Create nDimensions default axes for the user coordinate system.
Definition: RFrame.cxx:66
RAttrLine & AttrBorder()
Definition: RFrame.hxx:184
List of items for object context menu.
Definition: RMenuItems.hxx:153
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...
Definition: StringConv.hxx:21
fill
Definition: fit1_py.py:6