Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDrawable.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include "ROOT/RDrawable.hxx"
10#include "ROOT/RDisplayItem.hxx"
11#include "ROOT/RMenuItems.hxx"
12#include "ROOT/RLogger.hxx"
13#include "ROOT/RCanvas.hxx"
14
15#include "TClass.h"
16#include "TROOT.h"
17
18#include <cassert>
19#include <string>
20#include <sstream>
21
22using namespace ROOT::Experimental;
23
24// destructor, pin vtable
25RDrawable::~RDrawable() = default;
26
27/////////////////////////////////////////////////////////////////////
28// Fill context menu items for the ROOT class
29
31{
32 auto isA = TClass::GetClass(typeid(*this));
33 if (isA)
34 items.PopulateObjectMenu(this, isA);
35}
36
37/////////////////////////////////////////////////////////////////////
38// Execute command for the drawable
39
40void RDrawable::Execute(const std::string &exec)
41{
42 auto isA = TClass::GetClass(typeid(*this));
43 if (!isA) return;
44
45 std::stringstream cmd;
46 cmd << "((" << isA->GetName() << " *) " << std::hex << std::showbase << (size_t)this << ")->" << exec << ";";
47 R__LOG_DEBUG(0, GPadLog()) << "RDrawable::Execute Obj " << this << " cmd " << exec;
48 gROOT->ProcessLine(cmd.str().c_str());
49}
50
51/////////////////////////////////////////////////////////////////////////////
52/// Preliminary method which checks if drawable matches with given selector
53/// Following selector are allowed:
54/// "type" or "#id" or ".class_name"
55/// Here type is drawable kind like 'rect' or 'pad'
56/// id is drawable identifier, specified with RDrawable::SetId() method
57/// class_name is drawable class name, specified with RDrawable::SetCssClass() method
58
59bool RDrawable::MatchSelector(const std::string &selector) const
60{
61 return (selector == fCssType) || (!fCssClass.empty() && (selector == std::string(".") + fCssClass)) || (!fId.empty() && (selector == std::string("#") + fId));
62}
63
64/////////////////////////////////////////////////////////////////////////////
65/// Creates display item for drawable
66/// By default item contains drawable data itself
67
68std::unique_ptr<RDisplayItem> RDrawable::Display(const RDisplayContext &ctxt)
69{
70 if (GetVersion() > ctxt.GetLastVersion())
71 return std::make_unique<RDrawableDisplayItem>(*this);
72
73 return nullptr;
74}
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Definition RLogger.hxx:365
#define gROOT
Definition TROOT.h:404
virtual void Execute(const std::string &)
Definition RDrawable.cxx:40
Version_t GetVersion() const
std::string fCssClass
user-defined CSS class, used for RStyle
virtual void PopulateMenu(RMenuItems &)
Definition RDrawable.cxx:30
std::string fId
user-defined CSS id, used for RStyle
bool MatchSelector(const std::string &selector) const
Preliminary method which checks if drawable matches with given selector Following selector are allowe...
Definition RDrawable.cxx:59
const char * fCssType
! drawable type, not stored in the root file, must be initialized in constructor
virtual std::unique_ptr< RDisplayItem > Display(const RDisplayContext &)
Creates display item for drawable By default item contains drawable data itself.
Definition RDrawable.cxx:68
List of items for object context menu.
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2966
RLogChannel & GPadLog()
Log channel for GPad diagnostics.
Definition RAttrBase.cxx:17