22#include <nlohmann/json.hpp>
41REveScene::REveScene(
const std::string&
n,
const std::string& t) :
80 auto pred = [&](std::unique_ptr<REveClient> &client) {
81 return client->fId ==
id;
97 throw eh +
"Element id and dictionary has to be defined";
142 nlohmann::json jarr = nlohmann::json::array();
144 nlohmann::json jhdr = {};
145 jhdr[
"content"] =
"REveScene::StreamElements";
149 jhdr[
"commands"] = nlohmann::json::array();
151 nlohmann::json jcmd = {};
152 jcmd[
"name"] = cmd.fName;
153 jcmd[
"icon"] = cmd.fIcon;
154 jcmd[
"elementid"] = cmd.fElementId;
155 jcmd[
"elementclass"] = cmd.fElementClass;
156 jcmd[
"func"] = cmd.fAction;
157 jhdr[
"commands"].push_back(jcmd);
161 jarr.push_back(jhdr);
186 nlohmann::json jobj = {};
188 jarr.push_back(jobj);
193 if (el->
fScene == el && el !=
this)
200 assert (rd_size % 4 == 0);
221 if (
c->GetMother() == el)
239 nlohmann::json jarr = nlohmann::json::array();
241 nlohmann::json jhdr = {};
242 jhdr[
"content"] =
"ElementsRepresentaionChanges";
245 jhdr[
"removedElements"] = nlohmann::json::array();
247 jhdr[
"removedElements"].push_back(re);
255 UChar_t bits = el->GetChangeBits();
257 nlohmann::json jobj = {};
258 jobj[
"fElementId"] = el->GetElementId();
259 jobj[
"changeBit"] = bits;
265 Info(
"REveScene::StreamRepresentationChanges",
"new element change %s %d\n",
266 el->GetCName(), bits);
271 assert (rd_size % 4 == 0);
280 jobj[
"fRnrSelf"] = el->GetRnrSelf();
281 jobj[
"fRnrChildren"] = el->GetRnrChildren();
286 el->WriteCoreJson(jobj, -1);
294 jarr.push_back(jobj);
315 nlohmann::json msg = { {
"header", jhdr}, {
"arr", jarr}};
319 Info(
"REveScene::StreamRepresentationChanges",
"class: %s changes %s ...",
GetCName(), msg.dump(1).c_str() );
327 printf(
" sending json, len = %d --> to conn_id = %d\n", (
int)
fOutputJson.size(), client->fId);
328 client->fWebWindow->Send(client->fId,
fOutputJson);
332 printf(
" sending binary, len = %d --> to conn_id = %d\n",
fTotalBinarySize, client->fId);
345 ::Info(
"REveScene::IsChanged",
"%s (changed_or_added=%d, removed=%d)",
GetCName(),
356void REveScene::Repaint(Bool_t dropLogicals)
358 if (dropLogicals) fGLScene->SetSmartRefresh(kFALSE);
359 fGLScene->PadPaint(fPad);
360 if (dropLogicals) fGLScene->SetSmartRefresh(kTRUE);
363 // Hack to propagate selection state to physical shapes.
365 // Should actually be published in PadPaint() following a direct
366 // AddObject() call, but would need some other stuff for that.
367 // Optionally, this could be exported via the TAtt3D and everything
370 TGLScene::LogicalShapeMap_t& logs = fGLScene->RefLogicalShapes();
372 for (TGLScene::LogicalShapeMapIt_t li = logs.begin(); li != logs.end(); ++li)
374 elm = dynamic_cast<REveElement*>(li->first);
375 if (elm && li->second->Ref() == 1)
377 TGLPhysicalShape* pshp = const_cast<TGLPhysicalShape*>(li->second->GetFirstPhysical());
378 pshp->Select(elm->GetSelectedLevel());
382 // Fix positions for hierarchical scenes.
385 RetransHierarchically();
393void REveScene::RetransHierarchically()
395 fGLScene->BeginUpdate();
397 RetransHierarchicallyRecurse(this, RefMainTrans());
399 fGLScene->EndUpdate();
406void REveScene::RetransHierarchicallyRecurse(REveElement* el, const REveTrans& tp)
408 static const REveException eh("REveScene::RetransHierarchicallyRecurse ");
411 if (el->HasMainTrans())
412 t *= el->RefMainTrans();
414 if (el->GetRnrSelf() && el != this)
416 fGLScene->UpdatePhysioLogical(el->GetRenderObject(eh), t.Array(), 0);
419 if (el->GetRnrChildren())
421 for (auto &c: el->RefChildren())
423 if (c->GetRnrAnything())
424 RetransHierarchicallyRecurse(c, t);
435void REveScene::Paint(Option_t* option)
439 for (auto &c: fChildren)
441 // c->PadPaint(option);
450void REveScene::DestroyElementRenderers(REveElement* element)
452 static const REveException eh("REveScene::DestroyElementRenderers ");
454 fGLScene->BeginUpdate();
455 Bool_t changed = fGLScene->DestroyLogical(element->GetRenderObject(eh), kFALSE);
456 fGLScene->EndUpdate(changed, changed);
463void REveScene::DestroyElementRenderers(TObject* rnrObj)
465 fGLScene->BeginUpdate();
466 Bool_t changed = fGLScene->DestroyLogical(rnrObj, kFALSE);
467 fGLScene->EndUpdate(changed, changed);
519void REveSceneList::RepaintChangedScenes(Bool_t dropLogicals)
521 for (auto &c: fChildren)
523 REveScene* s = (REveScene*) c;
526 s->Repaint(dropLogicals);
534void REveSceneList::RepaintAllScenes(Bool_t dropLogicals)
536 for (auto &c: fChildren)
538 ((REveScene *)c)->Repaint(dropLogicals);
545void REveSceneList::DestroyElementRenderers(REveElement* element)
547 static const REveException eh("REveSceneList::DestroyElementRenderers ");
549 TObject* obj = element->GetRenderObject(eh);
550 for (auto &c: fChildren)
552 ((REveScene *)c)->DestroyElementRenderers(obj);
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
virtual void DestroyOrWarn()
Destroy this element. Prints a warning if deny-destroy is in force.
TClass * IsA() const
Return class for this element.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
const char * GetCName() const
virtual void DestroyElements()
Destroy all children of this element.
void SetChildClass(TClass *c)
ElementId_t GetElementId() const
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
REveException Exception-type thrown by Eve classes.
REveSceneList * GetScenes() const
void SceneSubscriberWaitingResponse(unsigned cinnId)
REveViewerList * GetViewers() const
REveSceneList(const REveSceneList &)=delete
void DestroyScenes()
Destroy all scenes and their contents.
void AcceptChanges(bool)
Set accept changes flag on all scenes.
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)
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
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)
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers.
R__EXTERN REveManager * gEve