42using namespace std::string_literals;
58namespace Experimental {
113 std::list<std::shared_ptr<WebCommand>>
fCmds;
133 void ProcessData(
unsigned connid,
const std::string &arg);
185 return std::make_unique<RCanvasPainter>(
canv);
240 item.fCallback(
false);
252 for (
auto &&cmd :
fCmds) {
253 if (!connid || (cmd->fConnId == connid)) {
254 cmd->CallBack(
false);
287 if (std::find(conn.fSendQueue.begin(), conn.fSendQueue.end(),
""s) == conn.fSendQueue.end())
288 conn.fSendQueue.emplace_back(
""s);
291 if (!
fWindow->CanSend(conn.fConnId,
true))
297 ((
fCmds.front()->fConnId == 0) || (
fCmds.front()->fConnId == conn.fConnId))) {
299 auto &cmd =
fCmds.front();
301 cmd->fConnId = conn.fConnId;
307 }
else if (!conn.fSendQueue.empty()) {
309 buf = conn.fSendQueue.front().c_str();
310 conn.fSendQueue.pop_front();
314 buf = conn.fSendQueue.front().c_str();
315 conn.fSendQueue.pop_front();
325 ctxt.SetConnection(conn.fConnId, (conn.fConnId ==
fWebConn.begin()->fConnId));
349 if (item.fVersion > fSnapshotDelivered)
415 if (arg ==
"AddPanel") {
417 connid =
fWindow->GetConnectionId();
429 auto cmd = std::make_shared<WebCommand>(std::to_string(++
fCmdsCnt),
name, arg, callback, connid);
430 fCmds.emplace_back(cmd);
436 int res =
fWindow->WaitForTimed([
this, cmd](
double) {
438 R__LOG_DEBUG(0, CanvasPainerLog()) <<
"Command " << cmd->fName <<
" done";
439 return cmd->fResult ? 1 : -1;
443 if (!
fWindow->HasConnection(cmd->fConnId,
false))
470 ctxt.SetConnection(1,
true);
494 ctxt.SetConnection(1,
true);
513 if (arg.compare(0, header.length(), header) != 0)
515 cdata = arg.substr(header.length());
525 conn->fDelivered = (uint64_t)std::stoll(
cdata);
526 }
else if (arg ==
"QUIT") {
530 }
else if (arg ==
"START_BROWSER") {
531 gROOT->ProcessLine(
"auto br = std::make_shared<ROOT::RBrowser>();br->ClearOnClose(br);");
533 }
else if (arg ==
"RELOAD") {
535 }
else if (arg ==
"INTERRUPT") {
536 gROOT->SetInterrupt();
538 const char *sid =
cdata.c_str();
542 id.append(sid,
separ - sid);
547 }
else if (
fCmds.front()->fId !=
id) {
565 auto req = TBufferJSON::FromJSON<RDrawableRequest>(
cdata);
567 std::shared_ptr<RDrawable> drawable;
568 req->GetContext().SetCanvas(&
fCanvas);
569 if (req->GetId().empty() || (req->GetId() ==
"canvas")) {
570 req->GetContext().SetPad(
nullptr);
571 req->GetContext().SetDrawable(&
fCanvas, 0);
576 req->GetContext().SetDrawable(drawable.get(), 0);
579 req->GetContext().SetConnection(connid, conn ==
fWebConn.begin());
581 auto reply = req->Process();
583 if (req->ShouldBeReplyed()) {
585 reply = std::make_unique<RDrawableReply>();
587 reply->SetRequestId(req->GetRequestId());
590 conn->fSendQueue.emplace_back(
"REPL_REQ:"s +
json.Data());
594 if (req->NeedCanvasUpdate())
601 auto sz = TBufferJSON::FromJSON<std::vector<int>>(
cdata);
602 if (
sz &&
sz->size() == 2) {
625 fWindow->SetDefaultPage(
"file:rootui5sys/canv/canvas.html");
628 [
this](
unsigned connid) {
633 [
this](
unsigned connid,
const std::string &arg) {
ProcessData(connid, arg); },
635 [
this](
unsigned connid) {
678 return fWindow->NumConnections();
707 if (
gROOT->IsWebDisplayBatch())
722 if (
addr.length() == 0) {
730 std::string cmd(
"ADDPANEL:");
745 fWindow->SetClearOnClose(handle);
755 auto canvitem = std::make_unique<RCanvasDisplayItem>();
769 TClass::GetClass<RAttrMap::NoValue_t>(),
770 TClass::GetClass<RAttrMap::BoolValue_t>(),
771 TClass::GetClass<RAttrMap::IntValue_t>(),
772 TClass::GetClass<RAttrMap::DoubleValue_t>(),
773 TClass::GetClass<RAttrMap::StringValue_t>(),
774 TClass::GetClass<RAttrMap>(),
775 TClass::GetClass<RStyle::Block_t>(),
776 TClass::GetClass<RPadPos>(),
777 TClass::GetClass<RPadLength>(),
778 TClass::GetClass<RPadExtent>(),
779 TClass::GetClass<std::unordered_map<std::string,RAttrMap::Value_t*>>()
783 json.SetSkipClassInfo(cl);
785 auto res =
json.StoreObject(
canvitem.get(), TClass::GetClass<RCanvasDisplayItem>());
787 return std::string(res.Data());
794std::shared_ptr<RDrawable>
798 size_t pos =
search.find(
"#");
800 if (pos != std::string::npos)
805 return can.FindPrimitiveByDisplayId(
search);
814 size_t pos =
reply.find(
":");
815 if ((pos == std::string::npos) || (pos == 0)) {
821 reply.erase(0, pos + 1);
827 std::ofstream ofs(
fname, std::ios::binary);
846 auto cmd =
fCmds.front();
853 if ((cmd->fName ==
"SVG") || (cmd->fName ==
"PNG") || (cmd->fName ==
"JPEG")) {
854 if (
reply.length() == 0) {
858 std::ofstream ofs(cmd->fArg, std::ios::binary);
864 }
else if (cmd->fName.find(
"ADDPANEL:") == 0) {
884 std::this_thread::sleep_for(std::chrono::milliseconds(
int(
tm*1000)));
struct TNewCanvasPainterReg newCanvasPainterReg
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t win
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Abstract interface for painting a canvas.
static std::unique_ptr< Generator > & GetGenerator()
generator getter
static void ResetGlobalPainter()
Release the GeneratorImpl object.
std::unique_ptr< RVirtualCanvasPainter > Create(RCanvas &canv) const override
Create a new RCanvasPainter to paint the given RCanvas.
static void SetGlobalPainter()
Set RVirtualCanvasPainter::fgGenerator to a new GeneratorImpl object.
std::list< WebConn > fWebConn
!< configured display
std::list< std::shared_ptr< WebCommand > > fCmds
! list of submitted commands
uint64_t fCmdsCnt
! commands counter
uint64_t fSnapshotDelivered
! minimal version delivered to all connections
std::list< WebUpdate > fUpdatesLst
! list of callbacks for canvas update
void CancelCommands(unsigned connid=0)
Cancel command execution on provided connection All commands are cancelled, when connid === 0.
void SaveCreatedFile(std::string &reply)
Method called when GUI sends file to save on local disk File data coded with base64 coding beside SVG...
void CancelUpdates()
Cancel all pending Canvas::Update()
std::string GetWindowUrl(bool remote) final
Returns connection URL for web window.
bool ProduceBatchOutput(const std::string &fname, int width, int height) final
Produce batch output, using chrome headless mode with DOM dump.
std::shared_ptr< RDrawable > FindPrimitive(const RCanvas &can, const std::string &id, const RPadBase **subpad=nullptr)
Find drawable in the canvas with specified id Used to communicate with the clients,...
void DoWhenReady(const std::string &name, const std::string &arg, bool async, CanvasCallback_t callback) final
perform special action when drawing is ready
std::vector< Detail::RMenuItem > MenuItemsVector
std::shared_ptr< ROOT::RWebWindow > fWindow
std::string GetWindowAddr() const final
Returns web window name.
void Run(double tm=0.) final
Run canvas functionality for specified period of time Required when canvas used not from the main thr...
int NumDisplays() const final
Returns number of connected displays.
bool AddPanel(std::shared_ptr< ROOT::RWebWindow >) final
Add window as panel inside canvas window.
void FrontCommandReplied(const std::string &reply)
Process reply on the currently active command.
void ProcessData(unsigned connid, const std::string &arg)
Process data from the client.
int fJsonComp
! json compression for data send to client
void CanvasUpdated(uint64_t ver, bool async, CanvasCallback_t callback) final
Method invoked when canvas should be updated on the client side Depending from delivered status,...
void CheckDataToSend()
Check if canvas need to send data to the clients.
virtual ~RCanvasPainter()
Destructor.
void CreateWindow()
Create web window for canvas.
std::string ProduceJSON() final
Produce JSON for the canvas.
bool IsCanvasModified(uint64_t id) const final
return true if canvas modified since last painting
RCanvasPainter & operator=(const RCanvasPainter &)=delete
Disable assignment.
std::string CreateSnapshot(RDrawable::RDisplayContext &ctxt)
Create JSON representation of data, which should be send to the clients Here server-side painting is ...
RCanvasPainter(const RCanvasPainter &)=delete
Disable copy construction.
void SetClearOnClose(const std::shared_ptr< void > &) final
Set handle to window which will be cleared when connection is closed.
void NewDisplay(const std::string &where) final
Create new display for the canvas See ROOT::RWebWindowsManager::Show() docu for more info.
RCanvas & fCanvas
! Canvas we are painting, *this will be owned by canvas
const std::string & GetTitle() const
Get the canvas's title.
int GetHeight() const
Get canvas height.
uint64_t GetModified() const
Get modify counter.
void SetHeight(int height)
Set canvas height.
void SetWidth(int width)
Set canvas width.
int GetWidth() const
Get canvas width.
const std::string & GetId() const
A log configuration for a channel, e.g.
Base class for graphic containers for RDrawable-s.
void DisplayPrimitives(RPadBaseDisplayItem &paditem, RDisplayContext &ctxt)
Create display items for all primitives in the pad Each display item gets its special id,...
void Wipe()
Wipe the pad by clearing the list of primitives.
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
RWebDisplayArgs & SetWidgetKind(const std::string &kind)
set widget kind
RWebDisplayArgs & SetWidth(int w=0)
set preferable web window width
RWebDisplayArgs & SetHeight(int h=0)
set preferable web window height
static bool ProduceImage(const std::string &fname, const std::string &json, int width=800, int height=600, const char *batch_file=nullptr)
Produce image file using JSON data as source Invokes JSROOT drawing functionality in headless browser...
static bool CanProduceImages(const std::string &browser="")
Returns true if image production for specified browser kind is supported If browser not specified - u...
Represents web window, which can be shown in web browser or any other supported environment.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static bool EmbedFileDialog(const std::shared_ptr< RWebWindow > &window, unsigned connid, const std::string &args)
Create dialog instance to use as embedded dialog inside provided widget Loads libROOTBrowserv7 and tr...
static bool IsFileDialogMessage(const std::string &msg)
Check if this could be the message send by client to start new file dialog If returns true,...
static TString Decode(const char *data)
Decode a base64 string date into a generic TString.
Class for serializing object to and from JavaScript Object Notation (JSON) format.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
void SetCompact(int level)
Set level of space/newline/array compression Lower digit of compact parameter define formatting rules...
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
const char * Data() const
static TString ULLtoa(ULong64_t value, Int_t base)
Converts a ULong64_t (twice the range of an Long64_t) to a TString with respect to the base specified...
TString & Append(const char *cs)
std::function< void(bool)> CanvasCallback_t
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
unsigned fConnId
! connection id for the command, when 0 specified command will be submitted to any available connecti...
std::string fArg
! command arguments
bool fResult
! result of command execution
std::string fName
! command name
CanvasCallback_t fCallback
! callback function associated with command
WebCommand(const std::string &id, const std::string &name, const std::string &arg, CanvasCallback_t callback, unsigned connid)
enum ROOT::Experimental::RCanvasPainter::WebCommand::@64 sInit
! true when command submitted
std::string fId
! command identifier
unsigned fConnId
! connection id
std::list< std::string > fSendQueue
! send queue for the connection
RDrawable::Version_t fDelivered
! indicates version confirmed from canvas
RDrawable::Version_t fSend
! indicates version send to connection
uint64_t fVersion
! canvas version
CanvasCallback_t fCallback
! callback function associated with the update
WebUpdate(uint64_t ver, CanvasCallback_t callback)