22#include <nlohmann/json.hpp>
41REveScene::REveScene(
const std::string&
n,
const std::string& t) :
75 auto pred = [&](std::unique_ptr<REveClient> &client) {
76 return client->fId ==
id;
92 throw eh +
"Element id and dictionary has to be defined";
147 jhdr[
"content"] =
"REveScene::StreamElements";
151 jhdr[
"commands"] = nlohmann::json::array();
154 jcmd[
"name"] = cmd.fName;
155 jcmd[
"icon"] = cmd.fIcon;
156 jcmd[
"elementid"] = cmd.fElementId;
157 jcmd[
"elementclass"] = cmd.fElementClass;
158 jcmd[
"func"] = cmd.fAction;
159 jhdr[
"commands"].push_back(jcmd);
163 jarr.push_back(jhdr);
190 jarr.push_back(jobj);
195 if (el->
fScene == el && el !=
this)
202 assert (rd_size % 4 == 0);
223 if (
c->GetMother() == el)
247 jhdr[
"content"] =
"ElementsRepresentaionChanges";
250 jhdr[
"removedElements"] = nlohmann::json::array();
252 jhdr[
"removedElements"].push_back(re);
260 UChar_t bits = el->GetChangeBits();
263 jobj[
"fElementId"] = el->GetElementId();
264 jobj[
"changeBit"] = bits;
270 Info(
"REveScene::StreamRepresentationChanges",
"new element change %s %d\n",
271 el->GetCName(), bits);
276 assert (rd_size % 4 == 0);
285 jobj[
"fRnrSelf"] = el->GetRnrSelf();
286 jobj[
"fRnrChildren"] = el->GetRnrChildren();
291 el->WriteCoreJson(jobj, -1);
299 jarr.push_back(jobj);
324 Info(
"REveScene::StreamRepresentationChanges",
"class: %s changes %s ...",
GetCName(), msg.dump(1).c_str() );
331 printf(
" sending json, len = %d --> to conn_id = %d\n", (
int)
fOutputJson.size(), client->fId);
332 client->fWebWindow->Send(client->fId,
fOutputJson);
335 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);
578 ::Info(
"REveSceneList::ProcessSceneChanges",
"processing");
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
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)
void SceneSubscriberProcessingChanges(unsigned cinnId)
REveViewerList * GetViewers() const
REveSceneList(const REveSceneList &)=delete
void ProcessSceneChanges()
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)
virtual ~REveScene()
Destructor.
std::vector< char > fOutputBinary
!
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
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
basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, adl_serializer, std::vector< std::uint8_t > > json