Logo ROOT   6.10/09
Reference Guide
TCanvas.hxx
Go to the documentation of this file.
1 /// \file ROOT/TCanvas.h
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-08
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_TCanvas
16 #define ROOT7_TCanvas
17 
18 #include <experimental/string_view>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "ROOT/TDrawable.hxx"
24 
25 namespace ROOT {
26 namespace Experimental {
27 
28 namespace Internal {
29 class TCanvasSharedPtrMaker;
30 class TV5CanvasAdaptor;
31 }
32 
33 /** \class ROOT::Experimental::TCanvas
34  Graphic container for `TDrawable`-s.
35  Access is through TCanvasPtr.
36  */
37 
38 class TCanvas {
39 public:
40  using Primitives_t = std::vector<std::unique_ptr<Internal::TDrawable>>;
41 
42 private:
43  /// Content of the pad.
45 
46  /// Title of the canvas.
47  std::string fTitle;
48 
49  /// Adaptor for painting an old canvas.
50  std::unique_ptr<Internal::TV5CanvasAdaptor> fAdaptor;
51 
52  /// Disable copy construction for now.
53  TCanvas(const TCanvas&) = delete;
54 
55  /// Disable assignment for now.
56  TCanvas& operator=(const TCanvas&) = delete;
57 
58 public:
59  static std::shared_ptr<TCanvas> Create(const std::string& title);
60 
61  /// Create a temporary TCanvas; for long-lived ones please use Create().
62  TCanvas();
63 
64  /// Default destructor.
65  ///
66  /// Outline the implementation in sources.
67  ~TCanvas();
68 
69  // TODO: Draw() should return the Drawable&.
70  /// Add something to be painted.
71  /// The pad observes what's lifetime through a weak pointer.
72  template<class T>
73  void Draw(const std::shared_ptr<T>& what) {
74  // Requires GetDrawable(what, options) to be known!
75  fPrimitives.emplace_back(GetDrawable(what));
76  }
77 
78  /// Add something to be painted, with options.
79  /// The pad observes what's lifetime through a weak pointer.
80  template<class T, class OPTIONS>
81  void Draw(const std::shared_ptr<T>& what, const OPTIONS &options) {
82  // Requires GetDrawable(what, options) to be known!
83  fPrimitives.emplace_back(GetDrawable(what, options));
84  }
85 
86  /// Add something to be painted. The pad claims ownership.
87  template<class T>
88  void Draw(std::unique_ptr<T>&& what) {
89  // Requires GetDrawable(what, options) to be known!
90  fPrimitives.emplace_back(GetDrawable(std::move(what)));
91  }
92 
93  /// Add something to be painted, with options. The pad claims ownership.
94  template<class T, class OPTIONS>
95  void Draw(std::unique_ptr<T>&& what, const OPTIONS &options) {
96  // Requires GetDrawable(what, options) to be known!
97  fPrimitives.emplace_back(GetDrawable(std::move(what), options));
98  }
99 
100  /// Add a copy of something to be painted.
101  template<class T>
102  void Draw(const T& what) {
103  // Requires GetDrawable(what, options) to be known!
104  fPrimitives.emplace_back(GetDrawable(std::make_unique<T>(what)));
105  }
106 
107  /// Add a copy of something to be painted, with options.
108  template<class T, class OPTIONS>
109  void Draw(const T& what, const OPTIONS &options) {
110  // Requires GetDrawable(what, options) to be known!
111  fPrimitives.emplace_back(GetDrawable(std::make_unique<T>(what), options));
112  }
113 
114  /// Remove an object from the list of primitives.
115  //TODO: void Wipe();
116 
117  /// Paint the canvas elements ("primitives").
118  void Paint();
119 
120  /// Get the canvas's title.
121  const std::string& GetTitle() const { return fTitle; }
122 
123  /// Set the canvas's title.
124  void SetTitle(const std::string& title) { fTitle = title; }
125 
126  /// Get the elements contained in the canvas.
127  const Primitives_t& GetPrimitives() { return fPrimitives; }
128 
129 
130  static const std::vector<std::shared_ptr<TCanvas>> &GetCanvases();
131 };
132 
133 } // namespace Experimental
134 } // namespace ROOT
135 
136 #endif
void Draw(const std::shared_ptr< T > &what, const OPTIONS &options)
Add something to be painted, with options.
Definition: TCanvas.hxx:81
void Draw(const std::shared_ptr< T > &what)
Add something to be painted.
Definition: TCanvas.hxx:73
std::vector< std::unique_ptr< Internal::TDrawable > > Primitives_t
Definition: TCanvas.hxx:40
void Draw(std::unique_ptr< T > &&what, const OPTIONS &options)
Add something to be painted, with options. The pad claims ownership.
Definition: TCanvas.hxx:95
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::string fTitle
Title of the canvas.
Definition: TCanvas.hxx:47
double T(double x)
Definition: ChebyshevPol.h:34
Graphic container for TDrawable-s.
Definition: TCanvas.hxx:38
const std::string & GetTitle() const
Get the canvas&#39;s title.
Definition: TCanvas.hxx:121
std::unique_ptr< Internal::TV5CanvasAdaptor > fAdaptor
Adaptor for painting an old canvas.
Definition: TCanvas.hxx:50
Primitives_t fPrimitives
Content of the pad.
Definition: TCanvas.hxx:44
void Draw(const T &what)
Add a copy of something to be painted.
Definition: TCanvas.hxx:102
void Draw(std::unique_ptr< T > &&what)
Add something to be painted. The pad claims ownership.
Definition: TCanvas.hxx:88
void Draw(const T &what, const OPTIONS &options)
Add a copy of something to be painted, with options.
Definition: TCanvas.hxx:109
Binding & operator=(OUT(*fun)(void))
const Primitives_t & GetPrimitives()
Get the elements contained in the canvas.
Definition: TCanvas.hxx:127
std::unique_ptr< Internal::TDrawable > GetDrawable(const std::shared_ptr< THist< DIMENSIONS, PRECISION, STAT... >> &hist, THistDrawOptions< DIMENSIONS > opts={})
Interface to graphics taking a unique_ptr<THist>.
Definition: THist.hxx:357
void SetTitle(const std::string &title)
Set the canvas&#39;s title.
Definition: TCanvas.hxx:124