Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:43

0001 /*************************************************************************
0002  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers.               *
0003  * All rights reserved.                                                  *
0004  *                                                                       *
0005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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 /** \class RFrame
0031 \ingroup GpadROOT7
0032 \brief Holds an area where drawing on user coordinate-system can be performed.
0033 \authors Axel Naumann <axel@cern.ch> Sergey Linev <s.linev@gsi.de>
0034 \date 2017-09-26
0035 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0036 */
0037 
0038 class RFrame : public RDrawable  {
0039 
0040    friend class RPadBase;
0041 
0042 public:
0043 
0044    class RUserRanges {
0045       std::vector<double> values;  ///< min/max values for all dimensions
0046       std::vector<bool> flags;     ///< flag if values available
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       // Default constructor - for I/O
0062       RUserRanges() = default;
0063 
0064       // Constructor for 1-d ranges
0065       RUserRanges(double xmin, double xmax)
0066       {
0067          AssignMin(0, xmin);
0068          AssignMax(0, xmax);
0069       }
0070 
0071       // Constructor for 2-d ranges
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       // Extend number of dimensions which can be stored in the object
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       // Assign minimum for specified dimension
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       // Assign maximum for specified dimension
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       /** Returns true if axis configured as unzoomed, can be specified from client */
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       // Returns true if any value is specified
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; ///<! individual client ranges
0148 
0149    RFrame(const RFrame &) = delete;
0150    RFrame &operator=(const RFrame &) = delete;
0151 
0152    // Default constructor
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; // specified 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"};              ///<! frame margins relative to pad
0181    RAttrBorder border{this, "border"};                 ///<! frame border attributes
0182    RAttrFill fill{this, "fill"};                       ///<! frame fill attributes
0183    RAttrAxis x{this, "x"};                             ///<! drawing attributes for X axis
0184    RAttrAxis y{this, "y"};                             ///<! drawing attributes for Y axis
0185    RAttrAxis z{this, "z"};                             ///<! drawing attributes for Z axis
0186    RAttrAxis x2{this, "x2"};                           ///<! drawing attributes for X2 axis
0187    RAttrAxis y2{this, "y2"};                           ///<! drawing attributes for Y2 axis
0188    RAttrValue<bool> drawAxes{this, "drawAxes", false}; ///<! draw axes by frame
0189    RAttrValue<bool> gridX{this, "gridX", false};       ///<! show grid for X axis
0190    RAttrValue<bool> gridY{this, "gridY", false};       ///<! show grid for Y axis
0191    RAttrValue<bool> swapX{this, "swapX", false};       ///<! swap position of X axis
0192    RAttrValue<bool> swapY{this, "swapY", false};       ///<! swap position of Y axis
0193    RAttrValue<int> ticksX{this, "ticksX", 1};          ///<! X ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
0194    RAttrValue<int> ticksY{this, "ticksY", 1};          ///<! Y ticks drawing: 0 - off, 1 - normal, 2 - both sides, 3 - both sides with labels
0195 
0196    RFrame(TRootIOCtor*) : RFrame() {}
0197 
0198    void GetClientRanges(unsigned connid, RUserRanges &ranges);
0199 };
0200 
0201 
0202 } // namespace Experimental
0203 } // namespace ROOT
0204 
0205 #endif