Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*************************************************************************
0002  * Copyright (C) 1995-2015, 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_RCanvas
0010 #define ROOT7_RCanvas
0011 
0012 #include "ROOT/RPadBase.hxx"
0013 #include "ROOT/RVirtualCanvasPainter.hxx"
0014 #include "ROOT/RDrawableRequest.hxx"
0015 
0016 #include <memory>
0017 #include <string>
0018 #include <vector>
0019 #include <list>
0020 
0021 namespace ROOT {
0022 namespace Experimental {
0023 
0024 class RChangeAttrRequest : public RDrawableRequest {
0025    std::vector<std::string> ids;                           ///< array of ids
0026    std::vector<std::string> names;                         ///< array of attribute names
0027    std::vector<std::unique_ptr<RAttrMap::Value_t>> values; ///< array of values
0028    bool update{true};                                      ///< update canvas at the end
0029    bool fNeedUpdate{false};       ///<! is canvas update required
0030    RChangeAttrRequest(const RChangeAttrRequest &) = delete;
0031    RChangeAttrRequest& operator=(const RChangeAttrRequest &) = delete;
0032 public:
0033    RChangeAttrRequest() = default; // for I/O
0034    ~RChangeAttrRequest() override = default;
0035    std::unique_ptr<RDrawableReply> Process() override;
0036    bool NeedCanvasUpdate() const override { return fNeedUpdate; }
0037 };
0038 
0039 /** \class RCanvas
0040 \ingroup GpadROOT7
0041 \brief A window's topmost `RPad`.
0042 \author Axel Naumann <axel@cern.ch>
0043 \date 2015-07-08
0044 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0045 */
0046 
0047 class RCanvas: public RPadBase {
0048 friend class RPadBase;  /// use for ID generation
0049 friend class RCanvasPainter; /// used for primitives drawing
0050 friend class RChangeAttrRequest; /// to apply attributes changes
0051 private:
0052    /// Title of the canvas.
0053    std::string fTitle;
0054 
0055    /// Width of the canvas in pixels
0056    int fWidth{0};
0057 
0058    /// Height of the canvas in pixels
0059    int fHeight{0};
0060 
0061    /// Modify counter, incremented every time canvas is changed
0062    Version_t fModified{1}; ///<!
0063 
0064    /// The painter of this canvas, bootstrapping the graphics connection.
0065    /// Unmapped canvases (those that never had `Draw()` invoked) might not have
0066    /// a painter.
0067    std::unique_ptr<Internal::RVirtualCanvasPainter> fPainter; ///<!
0068 
0069    /// indicate if Show() method was called before
0070    bool fShown{false}; ///<!
0071 
0072    /// indicate if Update() method was called before
0073    bool fUpdated{false}; ///<!
0074 
0075    /// Disable copy construction for now.
0076    RCanvas(const RCanvas &) = delete;
0077 
0078    /// Disable assignment for now.
0079    RCanvas &operator=(const RCanvas &) = delete;
0080 
0081    // Increment modify counter
0082    uint64_t IncModified() { return ++fModified; }
0083 
0084 public:
0085    static std::shared_ptr<RCanvas> Create(const std::string &title);
0086 
0087    /// Create a temporary RCanvas; for long-lived ones please use Create().
0088    RCanvas() : RPadBase("canvas") {}
0089 
0090    ~RCanvas() override = default;
0091 
0092    const RCanvas *GetCanvas() const override { return this; }
0093 
0094    /// Access to the top-most canvas, if any (non-const version).
0095    RCanvas *GetCanvas() override { return this; }
0096 
0097    /// Set canvas pixel size - width and height
0098    void SetSize(int width, int height)
0099    {
0100       fWidth = width;
0101       fHeight = height;
0102    }
0103 
0104    /// Set canvas width
0105    void SetWidth(int width) { fWidth = width; }
0106 
0107    /// Set canvas height
0108    void SetHeight(int height) { fHeight = height; }
0109 
0110    /// Get canvas width
0111    int GetWidth() const { return fWidth; }
0112 
0113    /// Get canvas height
0114    int GetHeight() const { return fHeight; }
0115 
0116    /// Display the canvas.
0117    void Show(const std::string &where = "");
0118 
0119    /// returns true if Show() method was called
0120    bool IsShown() const { return fShown; }
0121 
0122    /// clear IsShown() flag
0123    void ClearShown() { fShown = false; }
0124 
0125    /// Returns window name used to display canvas
0126    std::string GetWindowAddr() const;
0127 
0128    /// Returns window URL which can be used for connection
0129    std::string GetWindowUrl(bool remote);
0130 
0131    /// Hide all canvas displays
0132    void Hide();
0133 
0134    /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
0135    void Remove();
0136 
0137    /// Insert panel into the canvas, canvas should be shown at this moment
0138    template <class PANEL>
0139    bool AddPanel(std::shared_ptr<PANEL> &panel)
0140    {
0141       if (!fPainter) return false;
0142       return fPainter->AddPanel(panel->GetWindow());
0143    }
0144 
0145    /// Get modify counter
0146    uint64_t GetModified() const { return fModified; }
0147 
0148    // Set newest version to all primitives
0149    void Modified() { SetDrawableVersion(IncModified()); }
0150 
0151    /// Set newest version to specified drawable
0152    void Modified(std::shared_ptr<RDrawable> drawable)
0153    {
0154       // TODO: may be check that drawable belong to the canvas
0155       if (drawable)
0156          drawable->SetDrawableVersion(IncModified());
0157    }
0158 
0159    // Return if canvas was modified and not yet updated
0160    bool IsModified() const;
0161 
0162    /// update drawing
0163    void Update(bool async = false, CanvasCallback_t callback = nullptr);
0164 
0165    /// returns true if Update() method was called
0166    bool IsUpdated() const { return fUpdated; }
0167 
0168    /// clear IsUpdated() flag
0169    void ClearUpdated() { fUpdated = false; }
0170 
0171    /// Run canvas functionality for given time (in seconds)
0172    void Run(double tm = 0.);
0173 
0174    /// Save canvas in image file
0175    bool SaveAs(const std::string &filename);
0176 
0177    /// Provide JSON which can be used for offline display
0178    std::string CreateJSON();
0179 
0180    std::string GetUID() const;
0181 
0182    /// Get the canvas's title.
0183    const std::string &GetTitle() const { return fTitle; }
0184 
0185    /// Set the canvas's title.
0186    RCanvas &SetTitle(const std::string &title)
0187    {
0188       fTitle = title;
0189       return *this;
0190    }
0191 
0192    void ResolveSharedPtrs();
0193 
0194    void ClearOnClose(const std::shared_ptr<void> &handle);
0195 
0196    static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
0197 
0198    static void ReleaseHeldCanvases();
0199 };
0200 
0201 } // namespace Experimental
0202 } // namespace ROOT
0203 
0204 #endif