File indexing completed on 2025-01-18 10:10:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_RFrame
0010 #define ROOT7_RFrame
0011
0012 #include "ROOT/RDrawable.hxx"
0013
0014 #include "ROOT/RDrawableRequest.hxx"
0015 #include "ROOT/RAttrBorder.hxx"
0016 #include "ROOT/RAttrFill.hxx"
0017 #include "ROOT/RAttrMargins.hxx"
0018 #include "ROOT/RAttrAxis.hxx"
0019 #include "ROOT/RAttrValue.hxx"
0020
0021 #include <memory>
0022 #include <map>
0023
0024 class TRootIOCtor;
0025
0026 namespace ROOT {
0027 namespace Experimental {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class RFrame : public RDrawable {
0039
0040 friend class RPadBase;
0041
0042 public:
0043
0044 class RUserRanges {
0045 std::vector<double> values;
0046 std::vector<bool> flags;
0047
0048 void UpdateDim(unsigned ndim, const RUserRanges &src)
0049 {
0050 if (src.IsUnzoom(ndim)) {
0051 ClearMinMax(ndim);
0052 } else {
0053 if (src.HasMin(ndim))
0054 AssignMin(ndim, src.GetMin(ndim));
0055 if (src.HasMax(ndim))
0056 AssignMax(ndim, src.GetMax(ndim));
0057 }
0058 }
0059
0060 public:
0061
0062 RUserRanges() = default;
0063
0064
0065 RUserRanges(double xmin, double xmax)
0066 {
0067 AssignMin(0, xmin);
0068 AssignMax(0, xmax);
0069 }
0070
0071
0072 RUserRanges(double xmin, double xmax, double ymin, double ymax)
0073 {
0074 AssignMin(0, xmin);
0075 AssignMax(0, xmax);
0076 AssignMin(1, ymin);
0077 AssignMax(1, ymax);
0078 }
0079
0080
0081 void Extend(unsigned ndim = 3)
0082 {
0083 if (ndim*2 > values.size()) {
0084 values.resize(ndim*2, 0.);
0085 flags.resize(ndim*2, false);
0086 }
0087 }
0088
0089 bool HasMin(unsigned ndim) const { return (ndim*2 < flags.size()) && flags[ndim*2]; }
0090 double GetMin(unsigned ndim) const { return (ndim*2 < values.size()) ? values[ndim*2] : 0.; }
0091
0092
0093 void AssignMin(unsigned ndim, double value)
0094 {
0095 Extend(ndim+1);
0096 values[ndim*2] = value;
0097 flags[ndim*2] = true;
0098 }
0099
0100 bool HasMax(unsigned ndim) const { return (ndim*2+1 < flags.size()) && flags[ndim*2+1]; }
0101 double GetMax(unsigned ndim) const { return (ndim*2+1 < values.size()) ? values[ndim*2+1] : 0.; }
0102
0103
0104 void AssignMax(unsigned ndim, double value)
0105 {
0106 Extend(ndim+1);
0107 values[ndim*2+1] = value;
0108 flags[ndim*2+1] = true;
0109 }
0110
0111 void ClearMinMax(unsigned ndim)
0112 {
0113 if (ndim*2+1 < flags.size())
0114 flags[ndim*2] = flags[ndim*2+1] = false;
0115
0116 if (ndim*2+1 < values.size())
0117 values[ndim*2] = values[ndim*2+1] = 0.;
0118 }
0119
0120
0121 bool IsUnzoom(unsigned ndim) const
0122 {
0123 return (ndim*2+1 < flags.size()) && (ndim*2+1 < values.size()) &&
0124 !flags[ndim*2] && !flags[ndim*2+1] &&
0125 (values[ndim*2] < -0.5) && (values[ndim*2+1] < -0.5);
0126 }
0127
0128
0129 bool IsAny() const
0130 {
0131 for (auto fl : flags)
0132 if (fl) return true;
0133 return false;
0134 }
0135
0136 void Update(const RUserRanges &src)
0137 {
0138 UpdateDim(0, src);
0139 UpdateDim(1, src);
0140 UpdateDim(2, src);
0141 UpdateDim(3, src);
0142 UpdateDim(4, src);
0143 }
0144 };
0145
0146 private:
0147 std::map<unsigned, RUserRanges> fClientRanges;
0148
0149 RFrame(const RFrame &) = delete;
0150 RFrame &operator=(const RFrame &) = delete;
0151
0152
0153 RFrame() : RDrawable("frame")
0154 {
0155 }
0156
0157 void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn);
0158
0159 protected:
0160
0161 void PopulateMenu(RMenuItems &) override;
0162
0163 void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const;
0164 void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges);
0165
0166 public:
0167
0168 class RZoomRequest : public RDrawableRequest {
0169 RUserRanges ranges;
0170 public:
0171 RZoomRequest() = default;
0172 std::unique_ptr<RDrawableReply> Process() override
0173 {
0174 auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
0175 if (frame) frame->SetClientRanges(GetContext().GetConnId(), ranges, GetContext().IsMainConn());
0176 return nullptr;
0177 }
0178 };
0179
0180 RAttrMargins margins{this, "margins"};
0181 RAttrBorder border{this, "border"};
0182 RAttrFill fill{this, "fill"};
0183 RAttrAxis x{this, "x"};
0184 RAttrAxis y{this, "y"};
0185 RAttrAxis z{this, "z"};
0186 RAttrAxis x2{this, "x2"};
0187 RAttrAxis y2{this, "y2"};
0188 RAttrValue<bool> drawAxes{this, "drawAxes", false};
0189 RAttrValue<bool> gridX{this, "gridX", false};
0190 RAttrValue<bool> gridY{this, "gridY", false};
0191 RAttrValue<bool> swapX{this, "swapX", false};
0192 RAttrValue<bool> swapY{this, "swapY", false};
0193 RAttrValue<int> ticksX{this, "ticksX", 1};
0194 RAttrValue<int> ticksY{this, "ticksY", 1};
0195
0196 RFrame(TRootIOCtor*) : RFrame() {}
0197
0198 void GetClientRanges(unsigned connid, RUserRanges &ranges);
0199 };
0200
0201
0202 }
0203 }
0204
0205 #endif