<commit_before>/// \file ROOT/TPad.hxx
/// \ingroup Gpad ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2017-07-06
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2017, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT7_TPad
#define ROOT7_TPad

#include <memory>
#include <vector>

#include "ROOT/TDrawable.hxx"
#include "ROOT/TFrame.hxx"
#include "ROOT/TPadExtent.hxx"
#include "ROOT/TPadPos.hxx"
#include "ROOT/TypeTraits.hxx"

namespace ROOT {
namespace Experimental {

class TPad;

namespace Internal {
class TVirtualCanvasPainter;
}

/** \class ROOT::Experimental::TPadBase
  Base class for graphic containers for `TDrawable`-s.
  */

class TPadBase {
public:
   using Primitives_t = std::vector<std::unique_ptr<TDrawable>>;

private:
   /// Content of the pad.
   Primitives_t fPrimitives;

   /// TFrame with user coordinate system, if used by this pad.
   std::unique_ptr<TFrame> fFrame;

   /// Disable copy construction.
   TPadBase(const TPadBase &) = delete;

   /// Disable assignment.
   TPadBase &operator=(const TPadBase &) = delete;

   /// Adds a `DRAWABLE` to `fPrimitives`, returning the drawing options as given by `DRAWABLE::Options()`.
   template <class DRAWABLE>
   auto &AddDrawable(std::unique_ptr<DRAWABLE> &&uPtr)
   {
      DRAWABLE &drw = *uPtr;
      fPrimitives.emplace_back(std::move(uPtr));
      return drw.GetOptions();
   }

protected:
   /// Allow derived classes to default construct a TPadBase.
   TPadBase() = default;

public:
   virtual ~TPadBase();

   /// Divide this pad into a grid of subpad with padding in between.
   /// \param nHoriz Number of horizontal pads.
   /// \param nVert Number of vertical pads.
   /// \param padding Padding between pads.
   /// \returns vector of vector (ret[x][y]) of created pads.
   std::vector<std::vector<TPad *>> Divide(int nHoriz, int nVert, const TPadExtent &padding = {});

   /// Add something to be painted.
   /// The pad observes what's lifetime through a weak pointer.
   template <class T>
   auto &Draw(const std::shared_ptr<T> &what)
   {
      // Requires GetDrawable(what) to be known!
      return AddDrawable(GetDrawable(what, *this));
   }

   /// Add something to be painted. The pad claims ownership.
   template <class T>
   auto &Draw(std::unique_ptr<T> &&what)
   {
      // Requires GetDrawable(what) to be known!
      return AddDrawable(GetDrawable(std::move(what), *this));
   }

   /// Add a copy of something to be painted.
   template <class T, class = typename std::enable_if<!ROOT::TypeTraits::IsSmartOrDumbPtr<T>::value>::type>
   auto &Draw(const T &what)
   {
      // Requires GetDrawable(what) to be known!
      return Draw(std::make_unique<T>(what));
   }

   /// Remove an object from the list of primitives.
   // TODO: void Wipe();

   /// Get the elements contained in the canvas.
   const Primitives_t &GetPrimitives() const { return fPrimitives; }

   /// Convert a `Pixel` position to Canvas-normalized positions.
   virtual std::array<TPadCoord::Normal, 2> PixelsToNormal(const std::array<TPadCoord::Pixel, 2> &pos) const = 0;

   /// Access to the top-most canvas, if any (const version).
   virtual const TCanvas &GetCanvas() const = 0;

   /// Access to the top-most canvas, if any (non-const version).
   virtual TCanvas &GetCanvas() = 0;

   /// Convert user coordinates to normal coordinates.
   std::array<TPadCoord::Normal, 2> UserToNormal(const std::array<TPadCoord::User, 2> &pos) const
   {
      return fFrame->UserToNormal(pos);
   }
};

class TPadDrawable;

/** \class ROOT::Experimental::TPad
  Graphic container for `TDrawable`-s.
  */

class TPad: public TPadBase {
private:
   /// Pad containing this pad as a sub-pad.
   const TPadBase *fParent = nullptr;

   /// Size of the pad in the parent's (!) coordinate system.
   TPadExtent fSize;


public:

   friend std::unique_ptr<TPadDrawable> GetDrawable(std::unique_ptr<TPad> &&pad, const TPadBase &parent);

   /// Create a child pad.
   TPad(const TPadBase &parent, const TPadExtent &size): fParent(&parent), fSize(size) {}

   /// Destructor to have a vtable.
   virtual ~TPad();<commit_msg>TPad must be able to modify the parent pad.<commit_after>/// \file ROOT/TPad.hxx
/// \ingroup Gpad ROOT7
/// \author <NAME> <<EMAIL>>
/// \date 2017-07-06
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
 * Copyright (C) 1995-2017, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT7_TPad
#define ROOT7_TPad

#include <memory>
#include <vector>

#include "ROOT/TDrawable.hxx"
#include "ROOT/TFrame.hxx"
#include "ROOT/TPadExtent.hxx"
#include "ROOT/TPadPos.hxx"
#include "ROOT/TypeTraits.hxx"

namespace ROOT {
namespace Experimental {

class TPad;

namespace Internal {
class TVirtualCanvasPainter;
}

/** \class ROOT::Experimental::TPadBase
  Base class for graphic containers for `TDrawable`-s.
  */

class TPadBase {
public:
   using Primitives_t = std::vector<std::unique_ptr<TDrawable>>;

private:
   /// Content of the pad.
   Primitives_t fPrimitives;

   /// TFrame with user coordinate system, if used by this pad.
   std::unique_ptr<TFrame> fFrame;

   /// Disable copy construction.
   TPadBase(const TPadBase &) = delete;

   /// Disable assignment.
   TPadBase &operator=(const TPadBase &) = delete;

   /// Adds a `DRAWABLE` to `fPrimitives`, returning the drawing options as given by `DRAWABLE::Options()`.
   template <class DRAWABLE>
   auto &AddDrawable(std::unique_ptr<DRAWABLE> &&uPtr)
   {
      DRAWABLE &drw = *uPtr;
      fPrimitives.emplace_back(std::move(uPtr));
      return drw.GetOptions();
   }

protected:
   /// Allow derived classes to default construct a TPadBase.
   TPadBase() = default;

public:
   virtual ~TPadBase();

   /// Divide this pad into a grid of subpad with padding in between.
   /// \param nHoriz Number of horizontal pads.
   /// \param nVert Number of vertical pads.
   /// \param padding Padding between pads.
   /// \returns vector of vector (ret[x][y]) of created pads.
   std::vector<std::vector<TPad *>> Divide(int nHoriz, int nVert, const TPadExtent &padding = {});

   /// Add something to be painted.
   /// The pad observes what's lifetime through a weak pointer.
   template <class T>
   auto &Draw(const std::shared_ptr<T> &what)
   {
      // Requires GetDrawable(what) to be known!
      return AddDrawable(GetDrawable(what, *this));
   }

   /// Add something to be painted. The pad claims ownership.
   template <class T>
   auto &Draw(std::unique_ptr<T> &&what)
   {
      // Requires GetDrawable(what) to be known!
      return AddDrawable(GetDrawable(std::move(what), *this));
   }

   /// Add a copy of something to be painted.
   template <class T, class = typename std::enable_if<!ROOT::TypeTraits::IsSmartOrDumbPtr<T>::value>::type>
   auto &Draw(const T &what)
   {
      // Requires GetDrawable(what) to be known!
      return Draw(std::make_unique<T>(what));
   }

   /// Remove an object from the list of primitives.
   // TODO: void Wipe();

   /// Get the elements contained in the canvas.
   const Primitives_t &GetPrimitives() const { return fPrimitives; }

   /// Convert a `Pixel` position to Canvas-normalized positions.
   virtual std::array<TPadCoord::Normal, 2> PixelsToNormal(const std::array<TPadCoord::Pixel, 2> &pos) const = 0;

   /// Access to the top-most canvas, if any (const version).
   virtual const TCanvas &GetCanvas() const = 0;

   /// Access to the top-most canvas, if any (non-const version).
   virtual TCanvas &GetCanvas() = 0;

   /// Convert user coordinates to normal coordinates.
   std::array<TPadCoord::Normal, 2> UserToNormal(const std::array<TPadCoord::User, 2> &pos) const
   {
      return fFrame->UserToNormal(pos);
   }
};

class TPadDrawable;

/** \class ROOT::Experimental::TPad
  Graphic container for `TDrawable`-s.
  */

class TPad: public TPadBase {
private:
   /// Pad containing this pad as a sub-pad.
   TPadBase *fParent = nullptr; //-> This must never be nullptr!

   /// Size of the pad in the parent's (!) coordinate system.
   TPadExtent fSize;

public:

   friend std::unique_ptr<TPadDrawable> GetDrawable(std::unique_ptr<TPad> &&pad, const TPadBase &parent);

   /// Create a child pad.
   TPad(TPadBase &parent, const TPadExtent &size): fParent(&parent), fSize(size) {}

   /// Destructor to have a vtable.
   virtual ~TPad();
{'fraction_non_alphanumeric': 0.15281042957896987, 'fraction_numerical': 0.00577046377431075, 'mean_word_length': 2.996157130657558, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878070', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2815, 'n_words': 878}