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/RAttrBorder.hxx"
16#include "ROOT/RAttrFill.hxx"
17#include "ROOT/RAttrMargins.hxx"
18#include "ROOT/RAttrAxis.hxx"
19#include "ROOT/RAttrValue.hxx"
20
21#include <memory>
22#include <map>
23
24class TRootIOCtor;
25
26namespace ROOT {
27namespace Experimental {
28
29
30/** \class RFrame
31\ingroup GpadROOT7
32\brief Holds an area where drawing on user coordinate-system can be performed.
33\authors Axel Naumann <axel@cern.ch> Sergey Linev <s.linev@gsi.de>
34\date 2017-09-26
35\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
36*/
37
38class RFrame : public RDrawable {
39
40 friend class RPadBase;
41
42public:
43
45 std::vector<double> values; ///< min/max values for all dimensions
46 std::vector<bool> flags; ///< flag if values available
47
48 void UpdateDim(unsigned ndim, const RUserRanges &src)
49 {
50 if (src.IsUnzoom(ndim)) {
51 ClearMinMax(ndim);
52 } else {
53 if (src.HasMin(ndim))
54 AssignMin(ndim, src.GetMin(ndim));
55 if (src.HasMax(ndim))
56 AssignMax(ndim, src.GetMax(ndim));
57 }
58 }
59
60 public:
61 // Default constructor - for I/O
62 RUserRanges() = default;
63
64 // Constructor for 1-d ranges
65 RUserRanges(double xmin, double xmax)
66 {
67 AssignMin(0, xmin);
68 AssignMax(0, xmax);
69 }
70
71 // Constructor for 2-d ranges
72 RUserRanges(double xmin, double xmax, double ymin, double ymax)
73 {
74 AssignMin(0, xmin);
75 AssignMax(0, xmax);
76 AssignMin(1, ymin);
77 AssignMax(1, ymax);
78 }
79
80 // Extend number of dimensions which can be stored in the object
81 void Extend(unsigned ndim = 3)
82 {
83 if (ndim*2 > values.size()) {
84 values.resize(ndim*2, 0.);
85 flags.resize(ndim*2, false);
86 }
87 }
88
89 bool HasMin(unsigned ndim) const { return (ndim*2 < flags.size()) && flags[ndim*2]; }
90 double GetMin(unsigned ndim) const { return (ndim*2 < values.size()) ? values[ndim*2] : 0.; }
91
92 // Assign minimum for specified dimension
93 void AssignMin(unsigned ndim, double value)
94 {
95 Extend(ndim+1);
96 values[ndim*2] = value;
97 flags[ndim*2] = true;
98 }
99
100 bool HasMax(unsigned ndim) const { return (ndim*2+1 < flags.size()) && flags[ndim*2+1]; }
101 double GetMax(unsigned ndim) const { return (ndim*2+1 < values.size()) ? values[ndim*2+1] : 0.; }
102
103 // Assign maximum for specified dimension
104 void AssignMax(unsigned ndim, double value)
105 {
106 Extend(ndim+1);
107 values[ndim*2+1] = value;
108 flags[ndim*2+1] = true;
109 }
110
111 void ClearMinMax(unsigned ndim)
112 {
113 if (ndim*2+1 < flags.size())
114 flags[ndim*2] = flags[ndim*2+1] = false;
115
116 if (ndim*2+1 < values.size())
117 values[ndim*2] = values[ndim*2+1] = 0.;
118 }
119
120 /** Returns true if axis configured as unzoomed, can be specified from client */
121 bool IsUnzoom(unsigned ndim) const
122 {
123 return (ndim*2+1 < flags.size()) && (ndim*2+1 < values.size()) &&
124 !flags[ndim*2] && !flags[ndim*2+1] &&
125 (values[ndim*2] < -0.5) && (values[ndim*2+1] < -0.5);
126 }
127
128 // Returns true if any value is specified
129 bool IsAny() const
130 {
131 for (auto fl : flags)
132 if (fl) return true;
133 return false;
134 }
135
136 void Update(const RUserRanges &src)
137 {
138 UpdateDim(0, src);
139 UpdateDim(1, src);
140 UpdateDim(2, src);
141 UpdateDim(3, src);
142 UpdateDim(4, src);
143 }
144 };
145
146private:
147 std::map<unsigned, RUserRanges> fClientRanges; ///<! individual client ranges
148
149 RFrame(const RFrame &) = delete;
150 RFrame &operator=(const RFrame &) = delete;
151
152 // Default constructor
153 RFrame() : RDrawable("frame")
154 {
155 }
156
157 void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn);
158
159protected:
160
161 void PopulateMenu(RMenuItems &) override;
162
163 void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const;
164 void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges);
165
166public:
167
169 RUserRanges ranges; // specified ranges
170 public:
171 RZoomRequest() = default;
172 std::unique_ptr<RDrawableReply> Process() override
173 {
174 auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
175 if (frame) frame->SetClientRanges(GetContext().GetConnId(), ranges, GetContext().IsMainConn());
176 return nullptr;
177 }
178 };
179
180 RAttrMargins margins{this, "margins"}; ///<! frame margins relative to pad
181 RAttrBorder border{this, "border"}; ///<! frame border attributes
182 RAttrFill fill{this, "fill"}; ///<! frame fill attributes
183 RAttrAxis x{this, "x"}; ///<! drawing attributes for X axis
184 RAttrAxis y{this, "y"}; ///<! drawing attributes for Y axis
185 RAttrAxis z{this, "z"}; ///<! drawing attributes for Z axis
186 RAttrAxis x2{this, "x2"}; ///<! drawing attributes for X2 axis
187 RAttrAxis y2{this, "y2"}; ///<! drawing attributes for Y2 axis
188 RAttrValue<bool> drawAxes{this, "drawAxes", false}; ///<! draw axes by frame
189 RAttrValue<bool> gridX{this, "gridX", false}; ///<! show grid for X axis
190 RAttrValue<bool> gridY{this, "gridY", false}; ///<! show grid for Y axis
191 RAttrValue<bool> swapX{this, "swapX", false}; ///<! swap position of X axis
192 RAttrValue<bool> swapY{this, "swapY", false}; ///<! swap position of Y axis
193 RAttrValue<int> ticksX{this, "ticksX", 1}; ///<! X ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
194 RAttrValue<int> ticksY{this, "ticksY", 1}; ///<! Y ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
195
197
198 void GetClientRanges(unsigned connid, RUserRanges &ranges);
199};
200
201
202} // namespace Experimental
203} // namespace ROOT
204
205#endif
float xmin
Definition: THbookFile.cxx:95
float ymin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
float ymax
Definition: THbookFile.cxx:95
All supported axes attributes for: line, ticks, labels, title, min/max, log, reverse,...
Definition: RAttrAxis.hxx:99
Drawing line attributes for different objects.
Definition: RAttrBorder.hxx:26
Drawing fill attributes for different objects.
Definition: RAttrFill.hxx:26
A margins attributes. Only relative and pixel coordinates are allowed.
Template class to access single value from drawable or other attributes.
Definition: RAttrValue.hxx:26
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:108
bool IsUnzoom(unsigned ndim) const
Returns true if axis configured as unzoomed, can be specified from client.
Definition: RFrame.hxx:121
bool HasMin(unsigned ndim) const
Definition: RFrame.hxx:89
void Update(const RUserRanges &src)
Definition: RFrame.hxx:136
void AssignMin(unsigned ndim, double value)
Definition: RFrame.hxx:93
RUserRanges(double xmin, double xmax, double ymin, double ymax)
Definition: RFrame.hxx:72
bool HasMax(unsigned ndim) const
Definition: RFrame.hxx:100
std::vector< double > values
min/max values for all dimensions
Definition: RFrame.hxx:45
void UpdateDim(unsigned ndim, const RUserRanges &src)
Definition: RFrame.hxx:48
double GetMax(unsigned ndim) const
Definition: RFrame.hxx:101
RUserRanges(double xmin, double xmax)
Definition: RFrame.hxx:65
std::vector< bool > flags
flag if values available
Definition: RFrame.hxx:46
double GetMin(unsigned ndim) const
Definition: RFrame.hxx:90
void AssignMax(unsigned ndim, double value)
Definition: RFrame.hxx:104
void Extend(unsigned ndim=3)
Definition: RFrame.hxx:81
std::unique_ptr< RDrawableReply > Process() override
Definition: RFrame.hxx:172
Holds an area where drawing on user coordinate-system can be performed.
Definition: RFrame.hxx:38
RAttrValue< bool > drawAxes
! draw axes by frame
Definition: RFrame.hxx:188
std::map< unsigned, RUserRanges > fClientRanges
! individual client ranges
Definition: RFrame.hxx:147
RAttrAxis z
! drawing attributes for Z axis
Definition: RFrame.hxx:185
RAttrValue< bool > swapY
! swap position of Y axis
Definition: RFrame.hxx:192
RAttrValue< bool > gridY
! show grid for Y axis
Definition: RFrame.hxx:190
RAttrAxis y
! drawing attributes for Y axis
Definition: RFrame.hxx:184
RFrame(const RFrame &)=delete
RAttrFill fill
! frame fill attributes
Definition: RFrame.hxx:182
void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges)
Internal - assign client zoomed range to specified axis.
Definition: RFrame.cxx:36
RAttrValue< bool > swapX
! swap position of X axis
Definition: RFrame.hxx:191
void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const
Internal - extract range for specified axis.
Definition: RFrame.cxx:24
void GetClientRanges(unsigned connid, RUserRanges &ranges)
Return ranges configured for the client.
Definition: RFrame.cxx:94
RAttrValue< bool > gridX
! show grid for X axis
Definition: RFrame.hxx:189
RFrame & operator=(const RFrame &)=delete
RFrame(TRootIOCtor *)
Definition: RFrame.hxx:196
RAttrBorder border
! frame border attributes
Definition: RFrame.hxx:181
RAttrMargins margins
! frame margins relative to pad
Definition: RFrame.hxx:180
RAttrAxis x2
! drawing attributes for X2 axis
Definition: RFrame.hxx:186
RAttrValue< int > ticksY
! Y ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
Definition: RFrame.hxx:194
RAttrAxis y2
! drawing attributes for Y2 axis
Definition: RFrame.hxx:187
void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn)
Remember client range, can be used for drawing or stats box calculations.
Definition: RFrame.cxx:72
RAttrAxis x
! drawing attributes for X axis
Definition: RFrame.hxx:183
RAttrValue< int > ticksX
! X ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
Definition: RFrame.hxx:193
void PopulateMenu(RMenuItems &) override
Provide context menu items.
Definition: RFrame.cxx:52
List of items for object context menu.
Definition: RMenuItems.hxx:157
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...