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 ROOT::Experimental;
20
21using namespace std::string_literals;
22
23
25
26 std::shared_ptr<RCanvas> fCanvas; ///<! drawn canvas
27
28public:
29
31 {
33 }
34
35 RBrowserRCanvasWidget(const std::string &name, std::shared_ptr<RCanvas> &canv) : RBrowserWidget(name)
36 {
37 fCanvas = std::move(canv);
38 }
39
40 virtual ~RBrowserRCanvasWidget() = default;
41
42 std::string GetKind() const override { return "rcanvas"s; }
43
44 void Show(const std::string &arg) override
45 {
46 fCanvas->Show(arg);
47 }
48
49 std::string GetUrl() override
50 {
51 return "../"s + fCanvas->GetWindowAddr() + "/"s;
52 }
53
54 std::string GetTitle() override
55 {
56 return fCanvas->GetTitle();
57 }
58
59 bool DrawElement(std::shared_ptr<Browsable::RElement> &elem, const std::string &opt = "") override
60 {
61 if (!elem->IsCapable(Browsable::RElement::kActDraw7))
62 return false;
63
64 auto obj = elem->GetObject();
65 if (!obj)
66 return false;
67
68 std::shared_ptr<RPadBase> subpad = fCanvas;
69
70 std::string drawopt = opt;
71
72 if (drawopt.compare(0,8,"<append>") == 0) {
73 drawopt.erase(0,8);
74 } else if (subpad->NumPrimitives() > 0) {
75 subpad->Wipe();
76 fCanvas->Modified();
77 fCanvas->Update(true);
78 }
79
80 if (drawopt == "<dflt>")
81 drawopt = Browsable::RProvider::GetClassDrawOption(obj->GetClass());
82
83 if (Browsable::RProvider::Draw7(subpad, obj, drawopt)) {
84 fCanvas->Modified();
85 fCanvas->Update(true);
86 return true;
87 }
88
89 return false;
90 }
91
92 void CheckModified() override
93 {
94 if (fCanvas->IsModified())
95 fCanvas->Update();
96 }
97
98};
99
100// ======================================================================
101
103protected:
104 std::shared_ptr<RBrowserWidget> Create(const std::string &name) final
105 {
106 return std::make_shared<RBrowserRCanvasWidget>(name);
107 }
108
109 std::shared_ptr<RBrowserWidget> CreateFor(const std::string &name, std::shared_ptr<Browsable::RElement> &elem) final
110 {
111 auto holder = elem->GetObject();
112 if (!holder) return nullptr;
113
114 auto canv = holder->get_shared<RCanvas>();
115 if (!canv) return nullptr;
116
117 return std::make_shared<RBrowserRCanvasWidget>(name, canv);
118 }
119
120public:
RBrowserRCanvasProvider sRBrowserRCanvasProvider
char name[80]
Definition TGX11.cxx:110
std::shared_ptr< RBrowserWidget > Create(const std::string &name) final
~RBrowserRCanvasProvider()=default
std::shared_ptr< RBrowserWidget > CreateFor(const std::string &name, std::shared_ptr< Browsable::RElement > &elem) final
std::shared_ptr< RCanvas > fCanvas
! drawn canvas
std::string GetUrl() override
RBrowserRCanvasWidget(const std::string &name, std::shared_ptr< RCanvas > &canv)
std::string GetTitle() override
void Show(const std::string &arg) override
std::string GetKind() const override
RBrowserRCanvasWidget(const std::string &name)
bool DrawElement(std::shared_ptr< Browsable::RElement > &elem, const std::string &opt="") override
virtual ~RBrowserRCanvasWidget()=default
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:57
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.
Abstract Web-based widget, which can be used in the RBrowser Used to embed canvas,...
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:86