Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:36

0001 /*************************************************************************
0002  * Copyright (C) 1995-2020, 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_RMenuItems
0010 #define ROOT7_RMenuItems
0011 
0012 #include <string>
0013 #include <vector>
0014 #include <memory>
0015 
0016 #include <ROOT/RDrawableRequest.hxx>
0017 
0018 #include "TClass.h"
0019 
0020 namespace ROOT {
0021 namespace Experimental {
0022 namespace Detail {
0023 
0024 /** \class RMenuItem
0025 \ingroup GpadROOT7
0026 \brief Base class for menu items, shown on JS side.
0027 \author Sergey Linev
0028 \date 2017-06-29
0029 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0030 */
0031 
0032 class RMenuItem {
0033 protected:
0034    std::string fName;       ///< name of the menu item
0035    std::string fTitle;      ///< title of menu item
0036    std::string fExec;       ///< execute when item is activated
0037    std::string fClassName;  ///< class to which belongs menu item
0038 public:
0039    /** Default constructor */
0040    RMenuItem() = default;
0041 
0042    /** Create menu item with the name and title
0043     *  name used to display item in the object context menu,
0044     *  title shown as hint info for that item  */
0045    RMenuItem(const std::string &name, const std::string &title) : fName(name), fTitle(title) {}
0046 
0047    /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
0048    virtual ~RMenuItem() = default;
0049 
0050    /** Set execution string with all required arguments,
0051     * which will be executed when menu item is selected  */
0052    void SetExec(const std::string &exec) { fExec = exec; }
0053 
0054    /** Set class name for menu item, will be used to group items together */
0055    void SetClassName(const std::string &clname) { fClassName = clname; }
0056 
0057    /** Returns menu item name */
0058    const std::string &GetName() const { return fName; }
0059 
0060    /** Returns execution string for the menu item */
0061    const std::string &GetExec() const { return fExec; }
0062 };
0063 
0064 /** \class RCheckedMenuItem
0065 \ingroup GpadROOT7
0066 \brief Menu item with check box
0067 \author Sergey Linev
0068 \date 2017-06-29
0069 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0070 */
0071 
0072 class RCheckedMenuItem : public RMenuItem {
0073 protected:
0074    bool fChecked = false; ///< state of checkbox
0075 public:
0076    /** Default constructor */
0077    RCheckedMenuItem() = default;
0078 
0079    /** Create checked menu item  */
0080    RCheckedMenuItem(const std::string &name, const std::string &title, bool checked = false)
0081       : RMenuItem(name, title), fChecked(checked)
0082    {
0083    }
0084 
0085    /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
0086    ~RCheckedMenuItem() override {}
0087 
0088    /** Set checked state for the item, default is none */
0089    void SetChecked(bool on = true) { fChecked = on; }
0090 
0091    bool IsChecked() const { return fChecked; }
0092 };
0093 
0094 /** \class RMenuArgument
0095 \ingroup GpadROOT7
0096 \brief Argument description for menu item which should invoke class method
0097 \author Sergey Linev
0098 \date 2017-06-29
0099 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0100 */
0101 
0102 class RMenuArgument {
0103 protected:
0104    std::string fName;     ///<  name of call argument
0105    std::string fTitle;    ///<  title of call argument
0106    std::string fTypeName; ///<  typename
0107    std::string fDefault;  ///<  default value
0108 public:
0109    /** Default constructor */
0110    RMenuArgument() = default;
0111 
0112    RMenuArgument(const std::string &name, const std::string &title, const std::string &typname,
0113                  const std::string &dflt = "")
0114       : fName(name), fTitle(title), fTypeName(typname), fDefault(dflt)
0115    {
0116    }
0117 
0118    void SetDefault(const std::string &dflt) { fDefault = dflt; }
0119 };
0120 
0121 /** \class RArgsMenuItem
0122 \ingroup GpadROOT7
0123 \brief Menu item which requires extra arguments for invoked class method
0124 \author Sergey Linev
0125 \date 2017-06-29
0126 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0127 */
0128 
0129 class RArgsMenuItem : public RMenuItem {
0130 protected:
0131    std::vector<RMenuArgument> fArgs;
0132 
0133 public:
0134    /** Default constructor */
0135    RArgsMenuItem() = default;
0136 
0137    RArgsMenuItem(const std::string &name, const std::string &title) : RMenuItem(name, title) {}
0138 
0139    /** virtual destructor need for vtable, used when vector of RMenuItem* is stored */
0140    ~RArgsMenuItem() override {}
0141 
0142    void AddArg(const RMenuArgument &arg) { fArgs.emplace_back(arg); }
0143 };
0144 
0145 } // namespace Detail
0146 
0147 ///////////////////////////////////////////////////////////////////////
0148 
0149 /** \class RMenuItems
0150 \ingroup GpadROOT7
0151 \brief List of items for object context menu
0152 \author Sergey Linev
0153 \date 2017-06-29
0154 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0155 */
0156 
0157 class RMenuItems : public RDrawableReply {
0158 protected:
0159    std::string fId;                                        ///< object identifier
0160    std::string fSpecifier;                                 ///<! extra specifier, used only on server
0161    std::vector<std::unique_ptr<Detail::RMenuItem>> fItems; ///< list of items in the menu
0162 public:
0163    RMenuItems() = default;
0164 
0165    RMenuItems(const std::string &_id, const std::string &_specifier)
0166    {
0167       fId = _id;
0168       fSpecifier = _specifier;
0169    }
0170 
0171    ~RMenuItems() override;
0172 
0173    const std::string &GetFullId() const { return fId; }
0174    const std::string &GetSpecifier() const { return fSpecifier; }
0175 
0176    auto Size() const { return fItems.size(); }
0177 
0178    void Add(std::unique_ptr<Detail::RMenuItem> &&item) { fItems.emplace_back(std::move(item)); }
0179 
0180    void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, const TClass *cl = nullptr)
0181    {
0182       auto item = std::make_unique<Detail::RMenuItem>(name, title);
0183       item->SetExec(exec);
0184       if (cl) item->SetClassName(cl->GetName());
0185       Add(std::move(item));
0186    }
0187 
0188    void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, const TClass *cl = nullptr)
0189    {
0190       auto item = std::make_unique<Detail::RCheckedMenuItem>(name, title, checked);
0191       item->SetExec(toggle);
0192       if (cl) item->SetClassName(cl->GetName());
0193       Add(std::move(item));
0194    }
0195 
0196    void PopulateObjectMenu(void *obj, TClass *cl);
0197 };
0198 
0199 
0200 /** \class RDrawableMenuRequest
0201 \ingroup GpadROOT7
0202 \brief Request menu items for the drawable object
0203 \author Sergey Linev
0204 \date 2020-04-14
0205 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0206 */
0207 
0208 class RDrawableMenuRequest : public RDrawableRequest {
0209    std::string menukind;
0210    std::string menureqid;
0211 public:
0212    std::unique_ptr<RDrawableReply> Process() override;
0213 };
0214 
0215 
0216 } // namespace Experimental
0217 } // namespace ROOT
0218 
0219 #endif