Logo ROOT  
Reference Guide
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 
22 using namespace ROOT::Experimental;
23 
24 // destructor, pin vtable
25 RDrawable::~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 
40 void 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__DEBUG_HERE("drawable") << "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 
59 bool 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 
68 std::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 }
RDisplayItem.hxx
ROOT::Experimental::RDrawable::RDisplayContext::GetLastVersion
Version_t GetLastVersion() const
Definition: RDrawable.hxx:177
ROOT::Experimental::RMenuItems::PopulateObjectMenu
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
Definition: RMenuItems.cxx:31
ROOT::Experimental::RDrawable::MatchSelector
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
TClass.h
ROOT::Experimental::RDrawable::~RDrawable
virtual ~RDrawable()
ROOT::Experimental::RDrawable::Execute
virtual void Execute(const std::string &)
Definition: RDrawable.cxx:40
ROOT::Experimental::RMenuItems
List of items for object context menu.
Definition: RMenuItems.hxx:153
RCanvas.hxx
TROOT.h
RLogger.hxx
R__DEBUG_HERE
#define R__DEBUG_HERE(GROUP)
Definition: RLogger.hxx:186
ROOT::Experimental::RDrawable::fCssType
std::string fCssType
! drawable type, not stored in the root file, must be initialized in constructor
Definition: RDrawable.hxx:186
ROOT::Experimental::RDrawable::RDisplayContext
Definition: RDrawable.hxx:137
TClass::GetClass
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:2925
ROOT::Experimental::RDrawable::fCssClass
std::string fCssClass
user defined drawable class, can later go inside map
Definition: RDrawable.hxx:187
RDrawable.hxx
ROOT::Experimental::RDrawable::PopulateMenu
virtual void PopulateMenu(RMenuItems &)
Definition: RDrawable.cxx:30
ROOT::Experimental::RDrawable::GetVersion
Version_t GetVersion() const
Definition: RDrawable.hxx:207
ROOT::Experimental::RDrawable::fId
std::string fId
optional object identifier, may be used in CSS as well
Definition: RDrawable.hxx:188
ROOT::Experimental::RDrawable::Display
virtual std::unique_ptr< RDisplayItem > Display(const RDisplayContext &)
Creates display item for drawable By default item contains drawable data itself.
Definition: RDrawable.cxx:68
ROOT::Experimental
Definition: RDirectory.hxx:36
RMenuItems.hxx
gROOT
#define gROOT
Definition: TROOT.h:406