26#include <nlohmann/json.hpp>
45REveScene::REveScene(
const std::string&
n,
const std::string& t) :
86 auto pred = [&](std::unique_ptr<REveClient> &client) {
87 return client->fId ==
id;
103 throw eh +
"Element id and dictionary has to be defined";
148 nlohmann::json jarr = nlohmann::json::array();
150 nlohmann::json jhdr = {};
151 jhdr[
"content"] =
"REveScene::StreamElements";
155 jhdr[
"commands"] = nlohmann::json::array();
157 nlohmann::json jcmd = {};
158 jcmd[
"name"] = cmd.fName;
159 jcmd[
"icon"] = cmd.fIcon;
160 jcmd[
"elementid"] = cmd.fElementId;
161 jcmd[
"elementclass"] = cmd.fElementClass;
162 jcmd[
"func"] = cmd.fAction;
163 jhdr[
"commands"].push_back(jcmd);
167 jarr.push_back(jhdr);
193 nlohmann::json jobj = {};
195 jarr.push_back(jobj);
200 if (el->
fScene == el && el !=
this)
228 if (
c->GetMother() == el)
253 nlohmann::json jobj = {};
255 jobj[
"fElementId"] = el->GetElementId();
258 el->WriteTransJson(jobj);
277 nlohmann::json jarr = nlohmann::json::array();
279 nlohmann::json jhdr = {};
280 jhdr[
"content"] =
"ElementsRepresentaionChanges";
283 jhdr[
"removedElements"] = nlohmann::json::array();
285 jhdr[
"removedElements"].push_back(re);
295 std::set<std::string> fTags;
297 std::vector<Block> blocks;
299 auto writeFull = [&](
REveElement *el, nlohmann::json &jobj) {
304 blocks.push_back({el,
true, {}});
311 auto writeEntries = [&](
REveElement *el, nlohmann::json &jobj) ->
bool {
326 std::vector<std::pair<UInt_t, UInt_t>> fRanges;
329 return fType == o.fType && fItemSize == o.fItemSize && fNElements == o.fNElements && fBytes == o.fBytes &&
330 fTex == o.fTex && fW == o.fW && fH == o.fH && fRanges == o.fRanges;
334 std::map<std::string, Shape>
m;
336 if (
auto e = rd->Find(t))
337 m[t] = {
e->GetType(),
e->GetItemSize(),
e->NElements(),
e->Bytes(),
338 e->GetTexFormat(),
e->GetTexW(),
e->GetTexH(),
e->RefRanges()};
341 const auto before = shapes(old_rd);
342 const std::string rnr_func = old_rd->
GetRnrFunc();
345 if (!rd || rd->
GetRnrFunc() != rnr_func || shapes(rd) != before)
348 nlohmann::json jrd = {};
352 jobj[
"render_data"] = jrd;
358 blocks.push_back({el,
false, tags});
367 nlohmann::json jobj = {};
369 jobj[
"changeBit"] = bits;
375 Info(
"REveScene::StreamRepresentationChanges",
"new element change %s %d\n",
407 jarr.push_back(jobj);
419 for (
auto &
b : blocks) {
421 auto rd_size =
b.fFull ?
b.fEl->fRenderData->Write(&
fOutputBinary[off], left)
430 nlohmann::json msg = { {
"header", jhdr}, {
"arr", jarr}};
435 Info(
"REveScene::StreamRepresentationChanges",
"class: %s changes %s ...",
GetCName(), msg.dump(1).c_str() );
444 printf(
" sending json, len = %d --> to conn_id = %d\n", (
int)
fOutputJson.size(), client->fId);
445 client->fWebWindow->Send(client->fId,
fOutputJson);
449 printf(
" sending binary, len = %d --> to conn_id = %d\n",
fTotalBinarySize, client->fId);
473 ::Info(
"REveScene::IsChanged",
"%s (changed_or_added=%d, removed=%d)",
GetCName(),
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
virtual void DestroyOrWarn()
Destroy this element. Prints a warning if deny-destroy is in force.
TClass * IsA() const
Return class for this element Return REveElement class in case dicitonary is not exisiting.
virtual void BuildRenderEntries(const std::set< std::string > &tags)
Bring the render data entries named in tags up to date for a kCBRenderEntries update,...
virtual void WriteTransJson(nlohmann::json &cj)
Write the main transformation and its motion for a kCBTrans update.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
const char * GetCName() const
virtual Bool_t GetRnrSelf() const
virtual void DestroyElements()
Destroy all children of this element.
UChar_t GetChangeBits() const
const std::set< std::string > & GetChangedEntryTags() const
virtual Bool_t GetRnrChildren() const
void SetChildClass(TClass *c)
ElementId_t GetElementId() const
virtual void ClearStamps()
std::list< REveElement * > List_t
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
REveRenderData * GetRenderData() const
REveException Exception-type thrown by Eve classes.
REveSceneList * GetScenes() const
void SceneSubscriberWaitingResponse(unsigned cinnId)
REveViewerList * GetViewers() const
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
static constexpr int kAlign
int GetBinarySize() const
Size of the block in the scene blob, a multiple of kAlign.
void WriteJson(Json &rd) const
render_data.size and render_data.entries; offsets are block-relative.
const std::string & GetRnrFunc() const
void EndAcceptingChanges()
REveSceneList(const REveSceneList &)=delete
void BeginAcceptingChanges()
Loop-wrapers over Scene children, element type checked on insertion.
void DestroyScenes()
Destroy all scenes and their contents.
std::vector< std::unique_ptr< REveClient > > fSubscribers
!
Bool_t HasSubscribers() const
void AddCommand(const std::string &name, const std::string &icon, const REveElement *element, const std::string &action)
void AddSubscriber(std::unique_ptr< REveClient > &&sub)
void ClearOutput()
Drop the output of the last StreamElements() or StreamRepresentationChanges() once it has been sent,...
std::vector< char > fOutputBinary
!
~REveScene() override
Destructor.
Bool_t fAcceptingChanges
!
void SceneElementRemoved(ElementId_t id)
void StreamRepresentationChanges()
Prepare data for sending element changes.
void StreamJsonRecurse(REveElement *el, nlohmann::json &jobj)
std::vector< SceneCommand > fCommands
!
void SendChangesToSubscribers()
void BeginAcceptingChanges()
List_t fElsWithBinaryData
void StreamMotionChanges(nlohmann::json &arr)
Move every element whose only pending change is kCBTrans from the change list into arr,...
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Write core json.
std::vector< ElementId_t > fRemovedElements
!
void SceneElementChanged(REveElement *element)
void EndAcceptingChanges()
void RemoveSubscriber(unsigned int)
static void AppendServerTime(std::string &msg)
Append "server_time" to the JSON message msg, a non-empty object or array: as its last key,...
static void StampServerTime(std::string &msg)
Set the "server_time" that AppendServerTime() put at the end of msg to now.
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers.
Namespace for ROOT features in testing.
R__EXTERN REveManager * gEve