Skip to content

Commit

Permalink
[rframe] provide connection id for drawable display context
Browse files Browse the repository at this point in the history
Connection id can be used to provide client-dependent output
Also there is always master connection flag.
Use connection info in RFrame and RStatBox when processing ranges
requests
  • Loading branch information
linev committed May 7, 2020
1 parent 5a0acf1 commit e95d23c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 24 deletions.
17 changes: 16 additions & 1 deletion graf2d/gpadv7/inc/ROOT/RDrawable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ public:
RCanvas *fCanvas{nullptr}; ///<! canvas where drawable is displayed
RPadBase *fPad{nullptr}; ///<! subpad where drawable is displayed
RDrawable *fDrawable{nullptr}; ///<! reference on the drawable
Version_t fLastVersion{0}; ///<! last version used to di
Version_t fLastVersion{0}; ///<! last displayed version
unsigned fIndex{0}; ///<! index in list of primitives
unsigned fConnId{0}; ///<! connection id
bool fMainConn{false}; ///<! is main connection

public:

Expand All @@ -130,19 +132,32 @@ public:
{
}

/** Set canvas */
void SetCanvas(RCanvas *canv) { fCanvas = canv; }
/** Set pad */
void SetPad(RPadBase *pad) { fPad = pad; }
/** Set drawable and its index in list of primitives */
void SetDrawable(RDrawable *dr, unsigned indx)
{
fDrawable = dr;
fIndex = indx;
}
/** Set connection id and ismain flag for connection */
void SetConnection(unsigned connid, bool ismain)
{
fConnId = connid;
fMainConn = ismain;
}

RCanvas *GetCanvas() const { return fCanvas; }
RPadBase *GetPad() const { return fPad; }
RDrawable *GetDrawable() const { return fDrawable; }
unsigned GetIndex() const { return fIndex; }

Version_t GetLastVersion() const { return fLastVersion; }

unsigned GetConnId() const { return fConnId; }
bool IsMainConn() const { return fMainConn; }
};

private:
Expand Down
36 changes: 23 additions & 13 deletions graf2d/gpadv7/inc/ROOT/RFrame.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public:
}
}

/** Returns true if axis configured as unzoomed, can be specified from client */
bool IsUnzoom(unsigned ndim) const
{
return (ndim*2+1 < flags.size()) && (ndim*2+1 < values.size()) &&
!flags[ndim*2] && !flags[ndim*2+1] &&
(values[ndim*2] < -0.5) && (values[ndim*2+1] < -0.5);
}

// Returns true if any value is specified
bool IsAny() const
{
Expand All @@ -110,18 +118,6 @@ public:
}
};

class RZoomRequest : public RDrawableRequest {
RUserRanges ranges; // specified ranges
public:
RZoomRequest() = default;
std::unique_ptr<RDrawableReply> Process() override
{
auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
if (frame) frame->SetClientRanges(0, ranges);
return nullptr;
}
};

private:

class RFrameAttrs : public RAttrBase {
Expand Down Expand Up @@ -153,16 +149,30 @@ private:
/// Constructor taking user coordinate system, position and extent.
explicit RFrame(std::vector<std::unique_ptr<RPadUserAxisBase>> &&coords);

void SetClientRanges(unsigned connid, const RUserRanges &ranges);
void SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn);

protected:

void PopulateMenu(RMenuItems &) override;

void GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ranges) const;
void AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges);

public:

class RZoomRequest : public RDrawableRequest {
RUserRanges ranges; // specified ranges
public:
RZoomRequest() = default;
std::unique_ptr<RDrawableReply> Process() override
{
auto frame = dynamic_cast<RFrame *>(GetContext().GetDrawable());
if (frame) frame->SetClientRanges(GetContext().GetConnId(), ranges, GetContext().IsMainConn());
return nullptr;
}
};


RFrame(TRootIOCtor*) : RFrame() {}

const RAttrMargins &GetMargins() const { return fMargins; }
Expand Down
24 changes: 22 additions & 2 deletions graf2d/gpadv7/src/RFrame.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ void RFrame::GetAxisRanges(unsigned ndim, const RAttrAxis &axis, RUserRanges &ra
ranges.AssignMax(ndim, axis.GetZoomMax(), true);
}

////////////////////////////////////////////////////////////////////////////
/// Internal - assign client zoomed range to specified axis

void RFrame::AssignZoomRange(unsigned ndim, RAttrAxis &axis, const RUserRanges &ranges)
{
if (ranges.IsUnzoom(ndim)) {
axis.ClearZoomMinMax();
} else {
if (ranges.HasMin(ndim))
axis.SetZoomMin(ranges.GetMin(ndim));
if (ranges.HasMax(ndim))
axis.SetZoomMax(ranges.GetMax(ndim));
}
}

////////////////////////////////////////////////////////////////////////////
/// Deprecated, to be removed soon

Expand Down Expand Up @@ -77,11 +92,16 @@ void RFrame::PopulateMenu(RMenuItems &items)
////////////////////////////////////////////////////////////////////////////
/// Remember client range, can be used for drawing or stats box calculations

void RFrame::SetClientRanges(unsigned connid, const RUserRanges &ranges)
void RFrame::SetClientRanges(unsigned connid, const RUserRanges &ranges, bool ismainconn)
{
fClientRanges[connid] = ranges;
}

if (ismainconn) {
AssignZoomRange(0, AttrX(), ranges);
AssignZoomRange(1, AttrY(), ranges);
AssignZoomRange(2, AttrZ(), ranges);
}
}

////////////////////////////////////////////////////////////////////////////
/// Return ranges configured for the client
Expand Down
19 changes: 13 additions & 6 deletions gui/canvaspainter/src/RCanvasPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class RCanvasPainter : public Internal::RVirtualCanvasPainter {

void ProcessData(unsigned connid, const std::string &arg);

std::string CreateSnapshot(RDrawable::Version_t vers);
std::string CreateSnapshot(RDrawable::RDisplayContext &ctxt);

std::shared_ptr<RDrawable> FindPrimitive(const RCanvas &can, const std::string &id, const RPadBase **subpad = nullptr);

Expand Down Expand Up @@ -309,7 +309,11 @@ void RCanvasPainter::CheckDataToSend()
buf = "SNAP:";
buf += TString::ULLtoa(fCanvas.GetModified(), 10);
buf += ":";
buf += CreateSnapshot(conn.fSend);

RDrawable::RDisplayContext ctxt(&fCanvas, &fCanvas, conn.fSend);
ctxt.SetConnection(conn.fConnId, (conn.fConnId == fWebConn.begin()->fConnId));

buf += CreateSnapshot(ctxt);

conn.fSend = fCanvas.GetModified();
}
Expand Down Expand Up @@ -444,7 +448,10 @@ void RCanvasPainter::DoWhenReady(const std::string &name, const std::string &arg

bool RCanvasPainter::ProduceBatchOutput(const std::string &fname, int width, int height)
{
auto snapshot = CreateSnapshot(0);
RDrawable::RDisplayContext ctxt(&fCanvas, &fCanvas, 0);
ctxt.SetConnection(1, true);

auto snapshot = CreateSnapshot(ctxt);

return RWebDisplayHandle::ProduceImage(fname, snapshot, width, height);
}
Expand Down Expand Up @@ -516,6 +523,8 @@ void RCanvasPainter::ProcessData(unsigned connid, const std::string &arg)
req->GetContext().SetDrawable(drawable.get(), 0);
}

req->GetContext().SetConnection(connid, conn == fWebConn.begin());

auto reply = req->Process();

if (req->ShouldBeReplyed()) {
Expand Down Expand Up @@ -657,12 +666,10 @@ bool RCanvasPainter::AddPanel(std::shared_ptr<RWebWindow> win)
/// Here server-side painting is performed - each drawable adds own elements in
/// so-called display list, which transferred to the clients

std::string RCanvasPainter::CreateSnapshot(RDrawable::Version_t vers)
std::string RCanvasPainter::CreateSnapshot(RDrawable::RDisplayContext &ctxt)
{
auto canvitem = std::make_unique<RCanvasDisplayItem>();

RDrawable::RDisplayContext ctxt(&fCanvas, &fCanvas, vers);

fCanvas.DisplayPrimitives(*canvitem, ctxt);

canvitem->SetTitle(fCanvas.GetTitle());
Expand Down
2 changes: 1 addition & 1 deletion hist/histdrawv7/inc/ROOT/RHistStatBox.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public:

auto frame = GetContext().GetPad()->GetFrame();
RFrame::RUserRanges ranges;
if (frame) frame->GetClientRanges(0, ranges);
if (frame) frame->GetClientRanges(GetContext().GetConnId(), ranges);

auto reply = std::make_unique<RReply>();

Expand Down
2 changes: 1 addition & 1 deletion hist/histdrawv7/src/RHistStatBox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::unique_ptr<RDisplayItem> RHistStatBoxBase::Display(const RDisplayContext &c
RFrame::RUserRanges ranges;

auto frame = ctxt.GetPad()->GetFrame();
if (frame) frame->GetClientRanges(0, ranges);
if (frame) frame->GetClientRanges(ctxt.GetConnId(), ranges);

std::vector<std::string> lines;

Expand Down

0 comments on commit e95d23c

Please sign in to comment.