Logo ROOT  
Reference Guide
ROOT::Experimental::RCanvas Class Reference

A window's topmost RPad.

Author
Axel Naumann axel@.nosp@m.cern.nosp@m..ch
Date
2015-07-08
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!

Definition at line 47 of file RCanvas.hxx.

Public Member Functions

 RCanvas ()
 Create a temporary RCanvas; for long-lived ones please use Create(). More...
 
 ~RCanvas ()=default
 
template<class PANEL >
bool AddPanel (std::shared_ptr< PANEL > &panel)
 Insert panel into the canvas, canvas should be shown at this moment. More...
 
void ClearShown ()
 
std::string CreateJSON ()
 Provide JSON which can be used for offline display. More...
 
const RCanvasGetCanvas () const override
 Access to the top-most canvas, if any (const version). More...
 
RCanvasGetCanvas () override
 Access to the top-most canvas, if any (non-const version). More...
 
int GetHeight () const
 Get canvas height. More...
 
uint64_t GetModified () const
 Get modify counter. More...
 
const std::string & GetTitle () const
 Get the canvas's title. More...
 
int GetWidth () const
 Get canvas width. More...
 
std::string GetWindowAddr () const
 Returns window name used to display canvas. More...
 
void Hide ()
 Hide all canvas displays. More...
 
bool IsModified () const
 Returns true is canvas was modified since last painting. More...
 
bool IsShown () const
 
void Modified ()
 
void Modified (std::shared_ptr< RDrawable > drawable)
 Set newest version to specified drawable. More...
 
void Remove ()
 Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed. More...
 
void ResolveSharedPtrs ()
 To resolve problem with storing of shared pointers Call this method when reading canvas from the file Can be called many times - after reinitialization of shared pointers no changes will be performed. More...
 
void Run (double tm=0.)
 Run canvas functionality for given time (in seconds) More...
 
bool SaveAs (const std::string &filename)
 Save canvas in image file. More...
 
void SetHeight (int height)
 Set canvas height. More...
 
void SetSize (int width, int height)
 Set canvas pixel size - width and height. More...
 
RCanvasSetTitle (const std::string &title)
 Set the canvas's title. More...
 
void SetWidth (int width)
 Set canvas width. More...
 
void Show (const std::string &where="")
 Display the canvas. More...
 
void Update (bool async=false, CanvasCallback_t callback=nullptr)
 update drawing More...
 
- Public Member Functions inherited from ROOT::Experimental::RPadBase
virtual ~RPadBase ()
 
template<class T , class... ARGS>
std::shared_ptr< T > Add (ARGS... args)
 Add drawable of specified class T. More...
 
std::shared_ptr< RFrameAddFrame ()
 Add a frame object for the pad. More...
 
std::shared_ptr< RPadAddPad (const RPadPos &, const RPadExtent &)
 Add subpad. More...
 
std::vector< std::vector< std::shared_ptr< RPad > > > Divide (int nHoriz, int nVert, const RPadExtent &padding={})
 Divide this pad into a grid of subpads with padding in between. More...
 
template<class T , class... ARGS>
std::shared_ptr< T > Draw (ARGS... args)
 Create drawable of specified class T. More...
 
template<class T , class... ARGS>
auto Draw (const std::shared_ptr< T > &what, ARGS... args)
 Add object to be painted. More...
 
std::shared_ptr< RDrawableDraw (std::shared_ptr< RDrawable > &&drawable)
 Add existing drawable instance to canvas. More...
 
const RPadBaseFindPadForPrimitiveWithDisplayId (const std::string &display_id) const
 Find subpad which contains primitive with given display id. More...
 
std::shared_ptr< RDrawableFindPrimitive (const std::string &id) const
 Find primitive with specified id. More...
 
std::shared_ptr< RDrawableFindPrimitiveByDisplayId (const std::string &display_id) const
 Find primitive with unique id, produce for RDisplayItem Such id used for client-server identification of objects. More...
 
virtual const RCanvasGetCanvas () const =0
 Access to the top-most canvas, if any (const version). More...
 
virtual RCanvasGetCanvas ()=0
 Access to the top-most canvas, if any (non-const version). More...
 
std::shared_ptr< RFrameGetFrame ()
 Get a frame object if exists. More...
 
const std::shared_ptr< RFrameGetFrame () const
 Get a frame object if exists. More...
 
std::shared_ptr< RDrawableGetPrimitive (unsigned num) const
 returns primitive of given number More...
 
auto GetPrimitives () const
 Get all primitives contained in the pad. More...
 
unsigned NumPrimitives () const
 returns number of primitives in the pad More...
 
bool Remove (const std::shared_ptr< RDrawable > &drawable)
 Remove drawable from list of primitives. More...
 
bool Remove (const std::string &id)
 Remove an object from the list of primitives. More...
 
bool RemoveAt (unsigned indx)
 Remove drawable at specified position. More...
 
void UseStyle (const std::shared_ptr< RStyle > &style) override
 Use provided style for pad and all primitives inside. More...
 
void Wipe ()
 Wipe the pad by clearing the list of primitives. More...
 
- Public Member Functions inherited from ROOT::Experimental::RDrawable
 RDrawable (const char *csstype)
 
virtual ~RDrawable ()
 
void ClearStyle ()
 
const std::string & GetCssClass () const
 
const char * GetCssType () const
 
const std::string & GetId () const
 
void SetCssClass (const std::string &cl)
 
void SetId (const std::string &id)
 
virtual void UseStyle (const std::shared_ptr< RStyle > &style)
 

Static Public Member Functions

static std::shared_ptr< RCanvasCreate (const std::string &title)
 Create new canvas instance. More...
 
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases ()
 Returns list of created canvases. More...
 
static void ReleaseHeldCanvases ()
 Release list of held canvases pointers If no other shared pointers exists on the canvas, object will be destroyed. More...
 

Private Member Functions

 RCanvas (const RCanvas &)=delete
 Disable copy construction for now. More...
 
uint64_t IncModified ()
 
RCanvasoperator= (const RCanvas &)=delete
 Disable assignment for now. More...
 

Private Attributes

int fHeight {0}
 Height of the canvas in pixels. More...
 
Version_t fModified {1}
 Modify counter, incremented every time canvas is changed. More...
 
std::unique_ptr< Internal::RVirtualCanvasPainterfPainter
 The painter of this canvas, bootstrapping the graphics connection. More...
 
bool fShown {false}
 indicate if Show() method was called before More...
 
std::string fTitle
 to apply attributes changes More...
 
int fWidth {0}
 Width of the canvas in pixels. More...
 

Friends

class RCanvasPainter
 use for ID generation More...
 
class RChangeAttrRequest
 used for primitives drawing More...
 
class RPadBase
 

Additional Inherited Members

- Public Types inherited from ROOT::Experimental::RPadBase
using Primitives_t = std::vector< std::shared_ptr< RDrawable > >
 
- Public Types inherited from ROOT::Experimental::RDrawable
using Version_t = uint64_t
 
- Protected Member Functions inherited from ROOT::Experimental::RPadBase
 RPadBase (const char *csstype)
 Allow derived classes to default construct a RPadBase. More...
 
void CollectShared (Internal::RIOSharedVector_t &) override
 Collect all shared items to resolve shared_ptr after IO. More...
 
void DisplayPrimitives (RPadBaseDisplayItem &paditem, RDisplayContext &ctxt)
 Create display items for all primitives in the pad Each display item gets its special id, which used later for client-server communication Second parameter is version id which already delivered to the client. More...
 
void SetDrawableVersion (Version_t vers) override
 Assign drawable version - for pad itself and all primitives. More...
 
- Protected Member Functions inherited from ROOT::Experimental::RDrawable
 RDrawable (const RDrawable &)=delete
 
virtual void CollectShared (Internal::RIOSharedVector_t &)
 
virtual std::unique_ptr< RDisplayItemDisplay (const RDisplayContext &)
 Creates display item for drawable By default item contains drawable data itself. More...
 
virtual void Execute (const std::string &)
 
RAttrMapGetAttrMap ()
 
const RAttrMapGetAttrMap () const
 
Version_t GetVersion () const
 
virtual bool IsFrameRequired () const
 
bool MatchSelector (const std::string &selector) const
 Preliminary method which checks if drawable matches with given selector Following selector are allowed: "type" or "#id" or ".class_name" Here type is drawable kind like 'rect' or 'pad' id is drawable identifier, specified with RDrawable::SetId() method class_name is drawable class name, specified with RDrawable::SetCssClass() method. More...
 
virtual void OnDisplayItemDestroyed (RDisplayItem *) const
 
RDrawableoperator= (const RDrawable &)=delete
 
virtual void PopulateMenu (RMenuItems &)
 
void SetCssType (const char *csstype)
 
virtual void SetDrawableVersion (Version_t vers)
 

#include <ROOT/RCanvas.hxx>

Inheritance diagram for ROOT::Experimental::RCanvas:
[legend]

Constructor & Destructor Documentation

◆ RCanvas() [1/2]

ROOT::Experimental::RCanvas::RCanvas ( const RCanvas )
privatedelete

Disable copy construction for now.

◆ RCanvas() [2/2]

ROOT::Experimental::RCanvas::RCanvas ( )
inline

Create a temporary RCanvas; for long-lived ones please use Create().

Definition at line 85 of file RCanvas.hxx.

◆ ~RCanvas()

ROOT::Experimental::RCanvas::~RCanvas ( )
default

Member Function Documentation

◆ AddPanel()

template<class PANEL >
bool ROOT::Experimental::RCanvas::AddPanel ( std::shared_ptr< PANEL > &  panel)
inline

Insert panel into the canvas, canvas should be shown at this moment.

Definition at line 130 of file RCanvas.hxx.

◆ ClearShown()

void ROOT::Experimental::RCanvas::ClearShown ( )
inline

Definition at line 117 of file RCanvas.hxx.

◆ Create()

std::shared_ptr< ROOT::Experimental::RCanvas > ROOT::Experimental::RCanvas::Create ( const std::string &  title)
static

Create new canvas instance.

Definition at line 103 of file RCanvas.cxx.

◆ CreateJSON()

std::string ROOT::Experimental::RCanvas::CreateJSON ( )

Provide JSON which can be used for offline display.

Create JSON data for the canvas Can be used of offline display with JSROOT.

Definition at line 207 of file RCanvas.cxx.

◆ GetCanvas() [1/2]

const RCanvas * ROOT::Experimental::RCanvas::GetCanvas ( ) const
inlineoverridevirtual

Access to the top-most canvas, if any (const version).

Implements ROOT::Experimental::RPadBase.

Definition at line 89 of file RCanvas.hxx.

◆ GetCanvas() [2/2]

RCanvas * ROOT::Experimental::RCanvas::GetCanvas ( )
inlineoverridevirtual

Access to the top-most canvas, if any (non-const version).

Implements ROOT::Experimental::RPadBase.

Definition at line 92 of file RCanvas.hxx.

◆ GetCanvases()

const std::vector< std::shared_ptr< ROOT::Experimental::RCanvas > > ROOT::Experimental::RCanvas::GetCanvases ( )
static

Returns list of created canvases.

Definition at line 44 of file RCanvas.cxx.

◆ GetHeight()

int ROOT::Experimental::RCanvas::GetHeight ( ) const
inline

Get canvas height.

Definition at line 111 of file RCanvas.hxx.

◆ GetModified()

uint64_t ROOT::Experimental::RCanvas::GetModified ( ) const
inline

Get modify counter.

Definition at line 137 of file RCanvas.hxx.

◆ GetTitle()

const std::string & ROOT::Experimental::RCanvas::GetTitle ( ) const
inline

Get the canvas's title.

Definition at line 166 of file RCanvas.hxx.

◆ GetWidth()

int ROOT::Experimental::RCanvas::GetWidth ( ) const
inline

Get canvas width.

Definition at line 108 of file RCanvas.hxx.

◆ GetWindowAddr()

std::string ROOT::Experimental::RCanvas::GetWindowAddr ( ) const

Returns window name used to display canvas.

Returns window name for canvas.

Definition at line 167 of file RCanvas.cxx.

◆ Hide()

void ROOT::Experimental::RCanvas::Hide ( )

Hide all canvas displays.

Definition at line 179 of file RCanvas.cxx.

◆ IncModified()

uint64_t ROOT::Experimental::RCanvas::IncModified ( )
inlineprivate

Definition at line 79 of file RCanvas.hxx.

◆ IsModified()

bool ROOT::Experimental::RCanvas::IsModified ( ) const

Returns true is canvas was modified since last painting.

Definition at line 69 of file RCanvas.cxx.

◆ IsShown()

bool ROOT::Experimental::RCanvas::IsShown ( ) const
inline

Definition at line 116 of file RCanvas.hxx.

◆ Modified() [1/2]

void ROOT::Experimental::RCanvas::Modified ( )
inline

Definition at line 140 of file RCanvas.hxx.

◆ Modified() [2/2]

void ROOT::Experimental::RCanvas::Modified ( std::shared_ptr< RDrawable drawable)
inline

Set newest version to specified drawable.

Definition at line 143 of file RCanvas.hxx.

◆ operator=()

RCanvas & ROOT::Experimental::RCanvas::operator= ( const RCanvas )
privatedelete

Disable assignment for now.

◆ ReleaseHeldCanvases()

void ROOT::Experimental::RCanvas::ReleaseHeldCanvases ( )
static

Release list of held canvases pointers If no other shared pointers exists on the canvas, object will be destroyed.

Definition at line 55 of file RCanvas.cxx.

◆ Remove()

void ROOT::Experimental::RCanvas::Remove ( )

Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.

Remove canvas from global canvas lists, will be destroyed once last shared_ptr is disappear.

Definition at line 221 of file RCanvas.cxx.

◆ ResolveSharedPtrs()

void ROOT::Experimental::RCanvas::ResolveSharedPtrs ( )

To resolve problem with storing of shared pointers Call this method when reading canvas from the file Can be called many times - after reinitialization of shared pointers no changes will be performed.

Definition at line 286 of file RCanvas.cxx.

◆ Run()

void ROOT::Experimental::RCanvas::Run ( double  tm = 0.)

Run canvas functionality for given time (in seconds)

Run canvas functionality for the given time (in seconds) Used to process canvas-related actions in the appropriate thread context.

Must be regularly called when canvas created and used in extra thread. Time parameter specifies minimal execution time in seconds - if default value 0 is used, just all pending actions will be performed. When canvas is not yet displayed - just performs sleep for given time interval.

Example of usage:

void draw_canvas(bool &run_loop, std::make_shared<RH1D> hist)
{
auto canvas = RCanvas::Create("Canvas title");
canvas->Draw(hist)->SetLineColor(RColor::kBlue);
canvas->Show();
while (run_loop) {
pHist->Fill(1);
canvas->Modified();
canvas->Update();
canvas->Run(0.1); // process canvas events
}
canvas->Remove();
}
int main()
{
RAxisConfig xaxis(100, -10., 10.);
auto pHist = std::make_shared<RH1D>(xaxis);
bool run_loop = true;
std::thread thrd(draw_canvas, run_loop, pHist);
std::this_thread::sleep_for(std::chrono::seconds(100));
run_loop = false;
thrd.join();
return 0;
}
int main(int argc, char *argv[])
Definition: cef_main.cxx:54
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:103
static constexpr R__DLLEXPORT RGB_t kBlue
Definition: RColor.hxx:186

Definition at line 272 of file RCanvas.cxx.

◆ SaveAs()

bool ROOT::Experimental::RCanvas::SaveAs ( const std::string &  filename)

Save canvas in image file.

Create image file for the canvas Supported SVG (extension .svg), JPEG (extension .jpg or .jpeg), PNG (extension .png) or JSON (extension .json)

Definition at line 189 of file RCanvas.cxx.

◆ SetHeight()

void ROOT::Experimental::RCanvas::SetHeight ( int  height)
inline

Set canvas height.

Definition at line 105 of file RCanvas.hxx.

◆ SetSize()

void ROOT::Experimental::RCanvas::SetSize ( int  width,
int  height 
)
inline

Set canvas pixel size - width and height.

Definition at line 95 of file RCanvas.hxx.

◆ SetTitle()

RCanvas & ROOT::Experimental::RCanvas::SetTitle ( const std::string &  title)
inline

Set the canvas's title.

Definition at line 169 of file RCanvas.hxx.

◆ SetWidth()

void ROOT::Experimental::RCanvas::SetWidth ( int  width)
inline

Set canvas width.

Definition at line 102 of file RCanvas.hxx.

◆ Show()

void ROOT::Experimental::RCanvas::Show ( const std::string &  where = "")

Display the canvas.

Create new display for the canvas The parameter where specifies which program could be used for display creation Possible values:

  • cef Chromium Embeded Framework, local display, local communication
  • qt5 Qt5 WebEngine (when running via rootqt5), local display, local communication
  • browser default system web-browser, communication via random http port from range 8800 - 9800
  • <prog> any program name which will be started instead of default browser, like firefox or /usr/bin/opera one could also specify $url in program name, which will be replaced with canvas URL
  • native either any available local display or default browser

Canvas can be displayed in several different places

Definition at line 136 of file RCanvas.cxx.

◆ Update()

void ROOT::Experimental::RCanvas::Update ( bool  async = false,
CanvasCallback_t  callback = nullptr 
)

update drawing

Update canvas.

Definition at line 77 of file RCanvas.cxx.

Friends And Related Function Documentation

◆ RCanvasPainter

friend class RCanvasPainter
friend

use for ID generation

Definition at line 49 of file RCanvas.hxx.

◆ RChangeAttrRequest

friend class RChangeAttrRequest
friend

used for primitives drawing

Definition at line 50 of file RCanvas.hxx.

◆ RPadBase

friend class RPadBase
friend

Definition at line 48 of file RCanvas.hxx.

Member Data Documentation

◆ fHeight

int ROOT::Experimental::RCanvas::fHeight {0}
private

Height of the canvas in pixels.

Definition at line 59 of file RCanvas.hxx.

◆ fModified

Version_t ROOT::Experimental::RCanvas::fModified {1}
private

Modify counter, incremented every time canvas is changed.

!

Definition at line 62 of file RCanvas.hxx.

◆ fPainter

std::unique_ptr<Internal::RVirtualCanvasPainter> ROOT::Experimental::RCanvas::fPainter
private

The painter of this canvas, bootstrapping the graphics connection.

Unmapped canvases (those that never had Draw() invoked) might not have a painter. !

Definition at line 67 of file RCanvas.hxx.

◆ fShown

bool ROOT::Experimental::RCanvas::fShown {false}
private

indicate if Show() method was called before

!

Definition at line 70 of file RCanvas.hxx.

◆ fTitle

std::string ROOT::Experimental::RCanvas::fTitle
private

to apply attributes changes

Title of the canvas.

Definition at line 53 of file RCanvas.hxx.

◆ fWidth

int ROOT::Experimental::RCanvas::fWidth {0}
private

Width of the canvas in pixels.

Definition at line 56 of file RCanvas.hxx.


The documentation for this class was generated from the following files: