Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBrowserRCanvasWidget.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2021-01-25
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "RBrowserWidget.hxx"
14
16
17#include <ROOT/RCanvas.hxx>
18
19using namespace std::string_literals;
20using namespace ROOT::Browsable;
21
22
24
25 std::shared_ptr<ROOT::Experimental::RCanvas> fCanvas; ///<! drawn canvas
26
27public:
28
30 {
32 }
33
34 RBrowserRCanvasWidget(const std::string &name, std::shared_ptr<ROOT::Experimental::RCanvas> &canv) : ROOT::RBrowserWidget(name)
35 {
36 fCanvas = std::move(canv);
37 }
38
39 ~RBrowserRCanvasWidget() override = default;
40
41 std::string GetKind() const override { return "rcanvas"s; }
42
43 void Show(const std::string &arg) override
44 {
45 fCanvas->Show(arg);
46 }
47
48 std::string GetUrl() override
49 {
50 return fCanvas->GetWindowUrl(false);
51 }
52
53 std::string GetTitle() override
54 {
55 return fCanvas->GetTitle();
56 }
57
58 bool DrawElement(std::shared_ptr<RElement> &elem, const std::string &opt = "") override
59 {
60 if (!elem->IsCapable(RElement::kActDraw7))
61 return false;
62
63 auto obj = elem->GetObject();
64 if (!obj)
65 return false;
66
67 RProvider::ExtendProgressHandle(elem.get(), obj.get());
68
69 std::shared_ptr<ROOT::Experimental::RPadBase> subpad = fCanvas;
70
71 std::string drawopt = opt;
72
73 if (drawopt.compare(0,8,"<append>") == 0) {
74 drawopt.erase(0,8);
75 } else if (subpad->NumPrimitives() > 0) {
76 subpad->Wipe();
77 fCanvas->Modified();
78 fCanvas->Update(true);
79 }
80
81 if (drawopt == "<dflt>")
82 drawopt = RProvider::GetClassDrawOption(obj->GetClass());
83
84 if (RProvider::Draw7(subpad, obj, drawopt)) {
85 fCanvas->Modified();
86 fCanvas->Update(true);
87 return true;
88 }
89
90 return false;
91 }
92
93 void CheckModified() override
94 {
95 if (fCanvas->IsModified())
96 fCanvas->Update();
97 }
98
99};
100
101// ======================================================================
102
104protected:
105 std::shared_ptr<ROOT::RBrowserWidget> Create(const std::string &name) final
106 {
107 return std::make_shared<RBrowserRCanvasWidget>(name);
108 }
109
110 std::shared_ptr<ROOT::RBrowserWidget> CreateFor(const std::string &name, std::shared_ptr<RElement> &elem) final
111 {
112 auto holder = elem->GetObject();
113 if (!holder) return nullptr;
114
115 auto canv = holder->get_shared<ROOT::Experimental::RCanvas>();
116 if (!canv) return nullptr;
117
118 return std::make_shared<RBrowserRCanvasWidget>(name, canv);
119 }
120
121public:
123 ~RBrowserRCanvasProvider() override = default;
RBrowserRCanvasProvider sRBrowserRCanvasProvider
char name[80]
Definition TGX11.cxx:110
~RBrowserRCanvasProvider() override=default
std::shared_ptr< ROOT::RBrowserWidget > CreateFor(const std::string &name, std::shared_ptr< RElement > &elem) final
std::shared_ptr< ROOT::RBrowserWidget > Create(const std::string &name) final
RBrowserRCanvasWidget(const std::string &name, std::shared_ptr< ROOT::Experimental::RCanvas > &canv)
std::string GetUrl() override
std::shared_ptr< ROOT::Experimental::RCanvas > fCanvas
! drawn canvas
std::string GetTitle() override
~RBrowserRCanvasWidget() override=default
void Show(const std::string &arg) override
std::string GetKind() const override
RBrowserRCanvasWidget(const std::string &name)
bool DrawElement(std::shared_ptr< RElement > &elem, const std::string &opt="") override
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:56
static bool Draw7(std::shared_ptr< ROOT::Experimental::RPadBase > &subpad, std::unique_ptr< RHolder > &obj, const std::string &opt="")
Invoke drawing of object on RCanvas sub-pad All existing providers are checked, first checked are cla...
static std::string GetClassDrawOption(const ClassArg &)
Return configured draw option for the class.
static void ExtendProgressHandle(void *handle, void *handle2)
Extend progress handle - to be able react on sub item.
A window's topmost RPad.
Definition RCanvas.hxx:47
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition RCanvas.cxx:89
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...