File indexing completed on 2025-01-18 10:10:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ROOT7_RPadBase
0010 #define ROOT7_RPadBase
0011
0012 #include "ROOT/RDrawable.hxx"
0013 #include "ROOT/RFrame.hxx"
0014 #include "ROOT/RPadExtent.hxx"
0015 #include "ROOT/RPadPos.hxx"
0016 #include "ROOT/TypeTraits.hxx"
0017
0018 #include <memory>
0019 #include <vector>
0020 #include <algorithm>
0021
0022 namespace ROOT {
0023 namespace Experimental {
0024
0025 class RPad;
0026 class RCanvas;
0027 class RPadBaseDisplayItem;
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class RPadBase : public RDrawable {
0038
0039 private:
0040
0041 using Primitive_t = Internal::RIOShared<RDrawable>;
0042
0043
0044
0045 std::vector<Primitive_t> fPrimitives;
0046
0047
0048 RPadBase(const RPadBase &) = delete;
0049
0050
0051 RPadBase &operator=(const RPadBase &) = delete;
0052
0053 void TestIfFrameRequired(const RDrawable *drawable)
0054 {
0055 if (drawable->IsFrameRequired())
0056 AddFrame();
0057 }
0058
0059 protected:
0060
0061 explicit RPadBase(const char *csstype) : RDrawable(csstype) {}
0062
0063 void CollectShared(Internal::RIOSharedVector_t &) override;
0064
0065 void DisplayPrimitives(RPadBaseDisplayItem &paditem, RDisplayContext &ctxt);
0066
0067 void SetDrawableVersion(Version_t vers) override;
0068
0069 public:
0070
0071 using Primitives_t = std::vector<std::shared_ptr<RDrawable>>;
0072
0073 ~RPadBase() override;
0074
0075 void UseStyle(const std::shared_ptr<RStyle> &style) override;
0076
0077
0078
0079
0080 template <class T, class... ARGS>
0081 auto Draw(const std::shared_ptr<T> &what, ARGS... args)
0082 {
0083
0084 auto drawable = GetDrawable(what, args...);
0085
0086 TestIfFrameRequired(drawable.get());
0087
0088 fPrimitives.emplace_back(drawable);
0089
0090 return drawable;
0091 }
0092
0093
0094 template<class T, class... ARGS>
0095 std::shared_ptr<T> Draw(ARGS... args)
0096 {
0097 auto drawable = std::make_shared<T>(args...);
0098
0099 TestIfFrameRequired(drawable.get());
0100
0101 fPrimitives.emplace_back(drawable);
0102
0103 return drawable;
0104 }
0105
0106
0107 template<class T, class... ARGS>
0108 std::shared_ptr<T> Add(ARGS... args)
0109 {
0110 auto drawable = std::make_shared<T>(args...);
0111
0112 TestIfFrameRequired(drawable.get());
0113
0114 fPrimitives.emplace_back(drawable);
0115
0116 return drawable;
0117 }
0118
0119
0120 std::shared_ptr<RDrawable> Draw(std::shared_ptr<RDrawable> &&drawable)
0121 {
0122 TestIfFrameRequired(drawable.get());
0123
0124 auto dr = std::move(drawable);
0125
0126 fPrimitives.emplace_back(dr);
0127
0128 return dr;
0129 }
0130
0131
0132 unsigned NumPrimitives() const { return fPrimitives.size(); }
0133
0134
0135 std::shared_ptr<RDrawable> GetPrimitive(unsigned num) const
0136 {
0137 if (num >= fPrimitives.size()) return nullptr;
0138 return fPrimitives[num].get_shared();
0139 }
0140
0141 std::shared_ptr<RDrawable> FindPrimitive(const std::string &id) const;
0142
0143 std::shared_ptr<RDrawable> FindPrimitiveByDisplayId(const std::string &display_id) const;
0144
0145 const RPadBase *FindPadForPrimitiveWithDisplayId(const std::string &display_id) const;
0146
0147
0148 auto GetPrimitives() const
0149 {
0150 Primitives_t res;
0151 for (auto &entry : fPrimitives)
0152 res.emplace_back(entry.get_shared());
0153 return res;
0154 }
0155
0156
0157 bool Remove(const std::string &id)
0158 {
0159 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
0160 [&id](const Internal::RIOShared<RDrawable>& dr) { return dr->GetId() == id; });
0161 if (iter == fPrimitives.end())
0162 return false;
0163 iter->reset();
0164 fPrimitives.erase(iter);
0165 return true;
0166 }
0167
0168
0169 bool Remove(const std::shared_ptr<RDrawable> &drawable)
0170 {
0171 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
0172 [&drawable](const Internal::RIOShared<RDrawable>& dr) { return drawable.get() == dr.get(); });
0173 if (iter == fPrimitives.end())
0174 return false;
0175 iter->reset();
0176 fPrimitives.erase(iter);
0177 return true;
0178 }
0179
0180
0181 bool RemoveAt(unsigned indx)
0182 {
0183 if (indx >= fPrimitives.size()) return false;
0184 fPrimitives[indx].reset();
0185 fPrimitives.erase(fPrimitives.begin() + indx);
0186 return true;
0187 }
0188
0189
0190 void Wipe() { fPrimitives.clear(); }
0191
0192 std::shared_ptr<RFrame> AddFrame();
0193 std::shared_ptr<RFrame> GetFrame();
0194 const std::shared_ptr<RFrame> GetFrame() const;
0195
0196 std::shared_ptr<RPad> AddPad(const RPadPos &, const RPadExtent &);
0197
0198
0199
0200
0201
0202
0203 std::vector<std::vector<std::shared_ptr<RPad>>> Divide(int nHoriz, int nVert, const RPadExtent &padding = {});
0204
0205
0206 virtual const RCanvas *GetCanvas() const = 0;
0207
0208
0209 virtual RCanvas *GetCanvas() = 0;
0210 };
0211
0212 }
0213 }
0214
0215 #endif