Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveDataSimpleProxyBuilder.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2020
3
4/*************************************************************************
5 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
13
15#include <ROOT/REveCompound.hxx>
16#include <ROOT/REveScene.hxx>
17#include <ROOT/RLogger.hxx>
18#include <cassert>
19#include <TClass.h>
20
21using namespace ROOT::Experimental;
22
24{}
25
27{
28 for (auto &p : m_products) {
29 for (auto &compound : p->m_elements->RefChildren())
30 compound->DecDenyDestroy();
31 }
32}
33
35{
36 for (auto &p : m_products) {
37 auto spbIt = fProductMap.find(p->m_elements);
38 if (spbIt != fProductMap.end()) {
39 REveElement *product = p->m_elements;
40 for (auto &compound : product->RefChildren()) {
41 REveCollectionCompound *collComp = dynamic_cast<REveCollectionCompound *>(compound);
42 collComp->DestroyElements();
43 collComp->fUsed = false;
44 }
45 (spbIt)->second->map.clear();
46 }
47 }
48
49 CleanLocal();
50}
51
52//______________________________________________________________________________
53REveElement *REveDataSimpleProxyBuilder::CreateProduct(const std::string &viewType, const REveViewContext *viewContext)
54{
55 REveElement *productEl = REveDataProxyBuilderBase::CreateProduct(viewType, viewContext);
56 auto it = fProductMap.find(productEl);
57 if (it == fProductMap.end())
58 fProductMap.emplace(productEl, new SPBProduct);
59 return productEl;
60}
61//______________________________________________________________________________
63REveDataSimpleProxyBuilder::CreateCompound(bool set_color, bool propagate_color_to_all_children)
64{
66 c->IncDenyDestroy();
67 c->CSCImplySelectAllChildren();
68 c->SetPickable(true);
69 if (set_color)
70 {
71 c->SetMainColor(Collection()->GetMainColor());
72 c->SetMainTransparency(Collection()->GetMainTransparency());
73 }
74 if (propagate_color_to_all_children)
75 {
76 c->CSCApplyMainColorToAllChildren();
77 c->CSCApplyMainTransparencyToAllChildren();
78 }
79 else
80 {
81 c->CSCApplyMainColorToMatchingChildren();
82 c->CSCApplyMainTransparencyToMatchingChildren();
83 }
84 return c;
85}
86
87//______________________________________________________________________________
89{
90 SPBProduct *spb = nullptr;
91
92 // printf("REveDataSimpleProxyBuilder::GetHolder begin %s %d \n", Collection()->GetCName(), idx);
93
94 auto it = fProductMap.find(product);
95 if (it != fProductMap.end()) {
96 spb = it->second;
97 } else {
98 spb = new SPBProduct;
99 fProductMap.emplace(product, spb);
100 }
101
102 REveCollectionCompound *itemHolder = nullptr;
103
104 auto pmIt = spb->map.find(idx);
105 if (pmIt != spb->map.end()) {
106 itemHolder = pmIt->second;
107 // printf("GetHolder already in map %d \n", idx);
108 } else {
109 int testIdx = 0;
110 if (product->NumChildren() > (int)spb->map.size()) {
111 for (auto &cr : product->RefChildren()) {
113 if (!cc->fUsed) {
114 itemHolder = cc;
115 break;
116 }
117 testIdx++;
118 }
119 if (!itemHolder){
120 std::cerr << "REveDataSimpleProxyBuilder::GetHolder can't reuse product\n";
121 }
122 if (testIdx != (int)spb->map.size()) {
123 std::cout << "REveDataSimpleProxyBuilder::GetHolder number of used products do not match product size\n";
124 }
125 }
126 if (!itemHolder) {
127
128 if ((int)spb->map.size() != product->NumChildren()) {
129 std::cout << "REveDataSimpleProxyBuilder::GetHolder total number of products do not match product size\n";
130 };
131 itemHolder = CreateCompound(true, true);
132 product->AddElement(itemHolder);
133 }
134 spb->map.emplace(idx, itemHolder);
135 itemHolder->fUsed = true;
136 itemHolder->SetMainColor(Collection()->GetDataItem(idx)->GetMainColor());
137 std::string name(TString::Format("%s %d", Collection()->GetCName(), idx));
138 itemHolder->SetName(name);
139 }
140
141 return itemHolder;
142}
143
144void
146 REveElement* product, const REveViewContext* vc)
147{
148 // printf("REveDataSimpleProxyBuilder::Build %s %d\n", collection->GetCName(), collection->GetNItems());
149 auto size = collection->GetNItems();
150 for (int index = 0; index < size; ++index)
151 {
152 const REveDataItem* di = Collection()->GetDataItem(index);
153 if (di->GetRnrSelf() && !di->GetFiltered())
154 {
155 REveCompound *itemHolder = GetHolder(product, index);
156 BuildItem(collection->GetDataPtr(index), index, itemHolder, vc);
157 }
158 }
159}
160
161void
163 REveElement* product, const std::string& viewType, const REveViewContext* vc)
164{
165 auto size = collection->GetNItems();
166 for (int index = 0; index < size; ++index)
167 {
168 auto di = Collection()->GetDataItem(index);
169 if (di->GetRnrSelf() && !di->GetFiltered())
170 {
171 REveCompound *itemHolder = GetHolder(product, index);
172 BuildItemViewType(collection->GetDataPtr(index), index, itemHolder, viewType, vc);
173 }
174 }
175 // printf("END Build view type [%s] product size %d\n",viewType.c_str(), product->NumChildren());
176}
177
178//______________________________________________________________________________
179
180namespace
181{
182 void applyColorAttrToChildren(REveElement* p) {
183 for (auto &it: p->RefChildren())
184 {
185 REveElement* c = it;
186 if (c->GetMainColor() != p->GetMainColor())
187 {
189 }
190 applyColorAttrToChildren(c);
191 }
192 }
193}
194
196{
197 for (auto itemIdx : iIds) {
198 const REveDataItem *item = Collection()->GetDataItem(itemIdx);
199 bool visible = ((!item->GetFiltered()) && item->GetRnrSelf()) && Collection()->GetRnrSelf();
200
201 auto sit = fProductMap.find(p->m_elements);
202 if (sit == fProductMap.end()) {
203 std::cerr << "REveDataSimpleProxyBuilder::ModelChanges product not found!\n";
204 return;
205 }
206 auto spb = sit->second;
207 REveCompound *holder = nullptr;
208 auto hmit = spb->map.find(itemIdx);
209 if (hmit != spb->map.end())
210 holder = hmit->second;
211
212 bool createHolder = visible && !holder;
213
214 if (createHolder) {
215 holder = GetHolder(p->m_elements, itemIdx);
216
217 if (HaveSingleProduct())
218 BuildItem(Collection()->GetDataPtr(itemIdx), itemIdx, holder, p->m_viewContext);
219 else
220 BuildItemViewType(Collection()->GetDataPtr(itemIdx), itemIdx, holder, p->m_viewType, p->m_viewContext);
221
222 applyColorAttrToChildren(holder);
223 p->m_elements->ProjectChild(holder);
224 } else if (holder) {
225 holder->SetRnrSelf(visible);
226 holder->SetRnrChildren(visible);
227 holder->SetMainColor(item->GetMainColor());
228 applyColorAttrToChildren(holder);
229 LocalModelChanges(itemIdx, holder, p->m_viewContext);
230 }
231 }
232}
233//______________________________________________________________________________
234
235bool
236REveDataSimpleProxyBuilder::VisibilityModelChanges(int idx, REveElement* iCompound, const std::string& viewType, const REveViewContext* vc)
237{
238 const REveDataItem *item = Collection()->GetDataItem(idx);
239 bool returnValue = false;
240
241 if (item->GetVisible() ) {
242 if (HaveSingleProduct())
243 BuildItem(Collection()->GetDataPtr(idx), idx, iCompound, vc);
244 else
245 BuildItemViewType(Collection()->GetDataPtr(idx), idx, iCompound, viewType, vc);
246 returnValue = true;
247 }
248 return returnValue;
249}
250
251//______________________________________________________________________________
252
254{
255 for (auto &s : Collection()->GetItemList()->RefSelectedSet()) {
256 // printf("Fill implied selected %d \n", s);
257 auto spb = fProductMap[p->m_elements];
258 auto it = spb->map.find(s);
259 if (it != spb->map.end()) {
260 // printf("Fill implied selected %s \n", it->second->GetCName());
261 it->second->FillImpliedSelectedSet(impSet);
262 }
263 }
264}
265
266//==============================================================================
267
268//==============================================================================
269
270//==============================================================================
271
273{
274 fCollection = c;
276}
277
278//______________________________________________________________________________
279
281{
282 // deny destroy ??
283}
284
285//______________________________________________________________________________
286
288{
289 static const REveException eh("REveCollectionCompound::GetSelectionMaster()");
290
292 return fCollection->GetItemList();
293
295 try {
296
297 std::size_t found = fName.find_last_of(" ");
298 if (found == std::string::npos)
299 {
300 throw(eh + TString::Format("Can't retrive item index from %s", fName.c_str()));
301 }
302 std::string idss = fName.substr(found + 1);
303 int idx = stoi(idss);
304 // printf("REveCollectionCompound::GetSelectionMaster %d\n", idx);
305 fCollection->GetItemList()->RefSelectedSet().insert(idx);
306 } catch (std::exception& e) {
307 R__LOG_ERROR(REveLog()) << "REveCollectionCompound::GetSelectionMaster " << e.what() << std::endl;
308 fCollection->GetItemList()->RefSelectedSet().insert(0);
309 }
310 return fCollection->GetItemList();
311}
#define R__LOG_ERROR(...)
Definition RLogger.hxx:362
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char name[80]
Definition TGX11.cxx:110
virtual REveElement * GetSelectionMaster() override
Returns the master element - that is:
void SetMainColor(Color_t color) override
SetMainColor for the compound.
const REveDataItem * GetDataItem(Int_t i) const
virtual void LocalModelChanges(int idx, REveElement *el, const REveViewContext *ctx)
virtual REveElement * CreateProduct(const std::string &viewType, const REveViewContext *)
virtual REveElement * CreateProduct(const std::string &viewType, const REveViewContext *) override
void FillImpliedSelected(REveElement::Set_t &impSet, Product *p) override
virtual void BuildItem(const void *data, int index, REveElement *iCollectionHolder, const REveViewContext *)=0
REveCompound * GetHolder(REveElement *product, int idx)
void BuildProduct(const REveDataCollection *iCollection, REveElement *product, const REveViewContext *) override
bool VisibilityModelChanges(int idx, REveElement *, const std::string &viewType, const REveViewContext *) override
std::map< REveElement *, SPBProduct * > fProductMap
virtual void BuildItemViewType(const void *data, int index, REveElement *iCollectionHolder, const std::string &viewType, const REveViewContext *)=0
void ModelChanges(const REveDataCollection::Ids_t &iIds, Product *p) override
REveCollectionCompound * CreateCompound(bool set_color=true, bool propagate_color_to_all_children=false)
void BuildProductViewType(const REveDataCollection *iCollection, REveElement *product, const std::string &viewType, const REveViewContext *) override
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual Bool_t GetRnrSelf() const
virtual Bool_t SetRnrChildren(Bool_t rnr)
Set render state of this element's children, i.e.
virtual void DestroyElements()
Destroy all children of this element.
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
void SetSelectionMaster(REveElement *el)
std::set< REveElement * > Set_t
virtual void SetMainColor(Color_t color)
Set main color of the element.
virtual Color_t GetMainColor() const
void SetName(const std::string &name)
Set name of an element.
virtual void ProjectChild(REveElement *el, Bool_t same_depth=kTRUE)
If this is a projectable, loop over all projected replicas and add the projected image of child 'el' ...
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:41
Bool_t IsAcceptingChanges() const
Definition REveScene.hxx:97
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2336
void compound()
Definition compound.C:25
RLogChannel & REveLog()
Log channel for Eve diagnostics.
Definition REveTypes.cxx:47