forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveElement.cxx
2261 lines (1881 loc) · 66.8 KB
/
TEveElement.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveElement.h"
#include "TEveCompound.h"
#include "TEveTrans.h"
#include "TEveManager.h"
#include "TEveSelection.h"
#include "TEveProjectionBases.h"
#include "TEveProjectionManager.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualPad.h"
#include "TVirtualViewer3D.h"
#include "TGeoMatrix.h"
#include "TClass.h"
#include "TPRegexp.h"
#include "TROOT.h"
#include "TColor.h"
#include "TEveBrowser.h"
#include "TGListTree.h"
#include "TGPicture.h"
#include <algorithm>
/** \class TEveElement::TEveListTreeInfo
\ingroup TEve
Structure holding information about TGListTree and TGListTreeItem
that represents given TEveElement. This needed because each element
can appear in several list-trees as well as several times in the
same list-tree.
*/
ClassImp(TEveElement::TEveListTreeInfo);
/** \class TEveElement
\ingroup TEve
Base class for TEveUtil visualization elements, providing hierarchy
management, rendering control and list-tree item management.
*/
ClassImp(TEveElement);
const TGPicture* TEveElement::fgRnrIcons[4] = { 0 };
const TGPicture* TEveElement::fgListTreeIcons[9] = { 0 };
////////////////////////////////////////////////////////////////////////////////
/// Default constructor.
TEveElement::TEveElement() :
fParents (),
fChildren (),
fCompound (0),
fVizModel (0),
fVizTag (),
fNumChildren (0),
fParentIgnoreCnt (0),
fTopItemCnt (0),
fDenyDestroy (0),
fDestroyOnZeroRefCnt (kTRUE),
fRnrSelf (kTRUE),
fRnrChildren (kTRUE),
fCanEditMainColor (kFALSE),
fCanEditMainTransparency(kFALSE),
fCanEditMainTrans (kFALSE),
fMainTransparency (0),
fMainColorPtr (0),
fMainTrans (0),
fItems (),
fSource (),
fUserData (0),
fPickable (kFALSE),
fSelected (kFALSE),
fHighlighted (kFALSE),
fImpliedSelected (0),
fImpliedHighlighted (0),
fCSCBits (0),
fChangeBits (0),
fDestructing (kNone)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveElement::TEveElement(Color_t& main_color) :
fParents (),
fChildren (),
fCompound (0),
fVizModel (0),
fVizTag (),
fNumChildren (0),
fParentIgnoreCnt (0),
fTopItemCnt (0),
fDenyDestroy (0),
fDestroyOnZeroRefCnt (kTRUE),
fRnrSelf (kTRUE),
fRnrChildren (kTRUE),
fCanEditMainColor (kFALSE),
fCanEditMainTransparency(kFALSE),
fCanEditMainTrans (kFALSE),
fMainTransparency (0),
fMainColorPtr (&main_color),
fMainTrans (0),
fItems (),
fSource (),
fUserData (0),
fPickable (kFALSE),
fSelected (kFALSE),
fHighlighted (kFALSE),
fImpliedSelected (0),
fImpliedHighlighted (0),
fCSCBits (0),
fChangeBits (0),
fDestructing (kNone)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Copy constructor. Does shallow copy.
/// For deep-cloning and children-cloning, see:
/// ~~~ {.cpp}
/// TEveElement* CloneElementRecurse(Int_t level)
/// void CloneChildrenRecurse(TEveElement* dest, Int_t level)
/// ~~~
/// 'TRef fSource' is copied but 'void* UserData' is NOT.
/// If the element is projectable, its projections are NOT copied.
///
/// Not implemented for most sub-classes, let us know.
/// Note that sub-classes of TEveProjected are NOT and will NOT be copyable.
TEveElement::TEveElement(const TEveElement& e) :
fParents (),
fChildren (),
fCompound (0),
fVizModel (0),
fVizTag (e.fVizTag),
fNumChildren (0),
fParentIgnoreCnt (0),
fTopItemCnt (0),
fDenyDestroy (0),
fDestroyOnZeroRefCnt (e.fDestroyOnZeroRefCnt),
fRnrSelf (e.fRnrSelf),
fRnrChildren (e.fRnrChildren),
fCanEditMainColor (e.fCanEditMainColor),
fCanEditMainTransparency(e.fCanEditMainTransparency),
fCanEditMainTrans (e.fCanEditMainTrans),
fMainTransparency (e.fMainTransparency),
fMainColorPtr (0),
fMainTrans (0),
fItems (),
fSource (e.fSource),
fUserData (0),
fPickable (e.fPickable),
fSelected (kFALSE),
fHighlighted (kFALSE),
fImpliedSelected (0),
fImpliedHighlighted (0),
fCSCBits (e.fCSCBits),
fChangeBits (0),
fDestructing (kNone)
{
SetVizModel(e.fVizModel);
if (e.fMainColorPtr)
fMainColorPtr = (Color_t*)((const char*) this + ((const char*) e.fMainColorPtr - (const char*) &e));
if (e.fMainTrans)
fMainTrans = new TEveTrans(*e.fMainTrans);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor. Do not call this method directly, either call Destroy() or
/// Annihilate(). See also DestroyElements() and AnnihilateElements() if you
/// need to delete all children of an element.
TEveElement::~TEveElement()
{
if (fDestructing != kAnnihilate)
{
fDestructing = kStandard;
RemoveElementsInternal();
for (List_i p=fParents.begin(); p!=fParents.end(); ++p)
{
(*p)->RemoveElementLocal(this);
(*p)->fChildren.remove(this);
--((*p)->fNumChildren);
}
}
fParents.clear();
for (sLTI_i i=fItems.begin(); i!=fItems.end(); ++i)
i->fTree->DeleteItem(i->fItem);
delete fMainTrans;
}
////////////////////////////////////////////////////////////////////////////////
/// Called before the element is deleted, thus offering the last chance
/// to detach from acquired resources and from the framework itself.
/// Here the request is just passed to TEveManager.
/// If you override it, make sure to call base-class version.
void TEveElement::PreDeleteElement()
{
gEve->PreDeleteElement(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Clone the element via copy constructor.
/// Should be implemented for all classes that require cloning support.
TEveElement* TEveElement::CloneElement() const
{
return new TEveElement(*this);
}
////////////////////////////////////////////////////////////////////////////////
/// Clone elements and recurse 'level' deep over children.
/// - If level == 0, only the element itself is cloned (default).
/// - If level == -1, all the hierarchy is cloned.
TEveElement* TEveElement::CloneElementRecurse(Int_t level) const
{
TEveElement* el = CloneElement();
if (level--)
{
CloneChildrenRecurse(el, level);
}
return el;
}
////////////////////////////////////////////////////////////////////////////////
/// Clone children and attach them to the dest element.
/// If level == 0, only the direct descendants are cloned (default).
/// If level == -1, all the hierarchy is cloned.
void TEveElement::CloneChildrenRecurse(TEveElement* dest, Int_t level) const
{
for (List_ci i=fChildren.begin(); i!=fChildren.end(); ++i)
{
dest->AddElement((*i)->CloneElementRecurse(level));
}
}
//==============================================================================
////////////////////////////////////////////////////////////////////////////////
/// Virtual function for retrieving name of the element.
/// Here we attempt to cast the assigned object into TNamed and call
/// GetName() there.
const char* TEveElement::GetElementName() const
{
static const TEveException eh("TEveElement::GetElementName ");
TNamed* named = dynamic_cast<TNamed*>(GetObject(eh));
return named ? named->GetName() : "<no-name>";
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function for retrieving title of the render-element.
/// Here we attempt to cast the assigned object into TNamed and call
/// GetTitle() there.
const char* TEveElement::GetElementTitle() const
{
static const TEveException eh("TEveElement::GetElementTitle ");
TNamed* named = dynamic_cast<TNamed*>(GetObject(eh));
return named ? named->GetTitle() : "<no-title>";
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function for setting of name of an element.
/// Here we attempt to cast the assigned object into TNamed and call
/// SetName() there.
/// If you override this call NameTitleChanged() from there.
void TEveElement::SetElementName(const char* name)
{
static const TEveException eh("TEveElement::SetElementName ");
TNamed* named = dynamic_cast<TNamed*>(GetObject(eh));
if (named) {
named->SetName(name);
NameTitleChanged();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function for setting of title of an element.
/// Here we attempt to cast the assigned object into TNamed and call
/// SetTitle() there.
/// If you override this call NameTitleChanged() from there.
void TEveElement::SetElementTitle(const char* title)
{
static const TEveException eh("TEveElement::SetElementTitle ");
TNamed* named = dynamic_cast<TNamed*>(GetObject(eh));
if (named) {
named->SetTitle(title);
NameTitleChanged();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function for setting of name and title of render element.
/// Here we attempt to cast the assigned object into TNamed and call
/// SetNameTitle() there.
/// If you override this call NameTitleChanged() from there.
void TEveElement::SetElementNameTitle(const char* name, const char* title)
{
static const TEveException eh("TEveElement::SetElementNameTitle ");
TNamed* named = dynamic_cast<TNamed*>(GetObject(eh));
if (named) {
named->SetNameTitle(name, title);
NameTitleChanged();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called when a name or title of the element has
/// been changed.
/// If you override this, call also the version of your direct base-class.
void TEveElement::NameTitleChanged()
{
// Nothing to do - list-tree-items take this info directly.
}
//******************************************************************************
////////////////////////////////////////////////////////////////////////////////
/// Set visualization-parameter model element.
/// Calling of this function from outside of EVE should in principle
/// be avoided as it can lead to dis-synchronization of viz-tag and
/// viz-model.
void TEveElement::SetVizModel(TEveElement* model)
{
if (fVizModel) {
--fParentIgnoreCnt;
fVizModel->RemoveElement(this);
}
fVizModel = model;
if (fVizModel) {
fVizModel->AddElement(this);
++fParentIgnoreCnt;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Find model element in VizDB that corresponds to previously
/// assigned fVizTag and set fVizModel accordingly.
/// If the tag is not found in VizDB, the old model-element is kept
/// and false is returned.
Bool_t TEveElement::FindVizModel()
{
TEveElement* model = gEve->FindVizDBEntry(fVizTag);
if (model)
{
SetVizModel(model);
return kTRUE;
}
else
{
return kFALSE;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set the VizTag, find model-element from the VizDB and copy
/// visualization-parameters from it. If the model is not found and
/// fallback_tag is non-null, its search is attempted as well.
/// For example: ApplyVizTag("TPC Clusters", "Clusters");
///
/// If the model-element can not be found a warning is printed and
/// false is returned.
Bool_t TEveElement::ApplyVizTag(const TString& tag, const TString& fallback_tag)
{
SetVizTag(tag);
if (FindVizModel())
{
CopyVizParamsFromDB();
return kTRUE;
}
if ( ! fallback_tag.IsNull())
{
SetVizTag(fallback_tag);
if (FindVizModel())
{
CopyVizParamsFromDB();
return kTRUE;
}
}
Warning("TEveElement::ApplyVizTag", "entry for tag '%s' not found in VizDB.", tag.Data());
return kFALSE;
}
////////////////////////////////////////////////////////////////////////////////
/// Propagate visualization parameters to dependent elements.
///
/// MainColor is propagated independently in SetMainColor().
/// In this case, as fMainColor is a pointer to Color_t, it should
/// be set in TProperClass::CopyVizParams().
///
/// Render state is not propagated. Maybe it should be, at least optionally.
void TEveElement::PropagateVizParamsToProjecteds()
{
TEveProjectable* pable = dynamic_cast<TEveProjectable*>(this);
if (pable && pable->HasProjecteds())
{
pable->PropagateVizParams();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Propagate visualization parameters from element el (defaulting
/// to this) to all elements (children).
///
/// The primary use of this is for model-elements from
/// visualization-parameter database.
void TEveElement::PropagateVizParamsToElements(TEveElement* el)
{
if (el == 0)
el = this;
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
(*i)->CopyVizParams(el);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Copy visualization parameters from element el.
/// This method needs to be overriden by any class that introduces
/// new parameters.
/// Color is copied in sub-classes which define it.
/// See, for example, TEvePointSet::CopyVizParams(),
/// TEveLine::CopyVizParams() and TEveTrack::CopyVizParams().
void TEveElement::CopyVizParams(const TEveElement* el)
{
fCanEditMainColor = el->fCanEditMainColor;
fCanEditMainTransparency = el->fCanEditMainTransparency;
fMainTransparency = el->fMainTransparency;
AddStamp(kCBColorSelection | kCBObjProps);
}
////////////////////////////////////////////////////////////////////////////////
/// Copy visualization parameters from the model-element fVizModel.
/// A warning is printed if the model-element fVizModel is not set.
void TEveElement::CopyVizParamsFromDB()
{
if (fVizModel)
{
CopyVizParams(fVizModel);
}
else
{
Warning("TEveElement::CopyVizParamsFromDB", "VizModel has not been set.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Save visualization parameters for this element with given tag.
///
/// This function creates the instantiation code, calls virtual
/// WriteVizParams() and, at the end, writes out the code for
/// registration of the model into the VizDB.
void TEveElement::SaveVizParams(std::ostream& out, const TString& tag, const TString& var)
{
static const TEveException eh("TEveElement::GetObject ");
TString t = " ";
TString cls(GetObject(eh)->ClassName());
out << "\n";
TString intro = " TAG='" + tag + "', CLASS='" + cls + "'";
out << " //" << intro << "\n";
out << " //" << TString('-', intro.Length()) << "\n";
out << t << cls << "* " << var <<" = new " << cls << ";\n";
WriteVizParams(out, var);
out << t << "gEve->InsertVizDBEntry(\"" << tag << "\", "<< var <<");\n";
}
////////////////////////////////////////////////////////////////////////////////
/// Write-out visual parameters for this object.
/// This is a virtual function and all sub-classes are required to
/// first call the base-element version.
/// The name of the element pointer is 'x%03d', due to cint limitations.
/// Three spaces should be used for indentation, same as in
/// SavePrimitive() methods.
void TEveElement::WriteVizParams(std::ostream& out, const TString& var)
{
TString t = " " + var + "->";
out << t << "SetElementName(\"" << GetElementName() << "\");\n";
out << t << "SetElementTitle(\"" << GetElementTitle() << "\");\n";
out << t << "SetEditMainColor(" << fCanEditMainColor << ");\n";
out << t << "SetEditMainTransparency(" << fCanEditMainTransparency << ");\n";
out << t << "SetMainTransparency(" << fMainTransparency << ");\n";
}
////////////////////////////////////////////////////////////////////////////////
/// Set visual parameters for this object for given tag.
void TEveElement::VizDB_Apply(const char* tag)
{
if (ApplyVizTag(tag))
{
PropagateVizParamsToProjecteds();
gEve->Redraw3D();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Reset visual parameters for this object from VizDB.
/// The model object must be already set.
void TEveElement::VizDB_Reapply()
{
if (fVizModel)
{
CopyVizParamsFromDB();
PropagateVizParamsToProjecteds();
gEve->Redraw3D();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Copy visual parameters from this element to viz-db model.
/// If update is set, all clients of the model will be updated to
/// the new value.
/// A warning is printed if the model-element fVizModel is not set.
void TEveElement::VizDB_UpdateModel(Bool_t update)
{
if (fVizModel)
{
fVizModel->CopyVizParams(this);
if (update)
{
fVizModel->PropagateVizParamsToElements(fVizModel);
gEve->Redraw3D();
}
}
else
{
Warning("VizDB_UpdateModel", "VizModel has not been set.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Create a replica of element and insert it into VizDB with given tag.
/// If replace is true an existing element with the same tag will be replaced.
/// If update is true, existing client of tag will be updated.
void TEveElement::VizDB_Insert(const char* tag, Bool_t replace, Bool_t update)
{
static const TEveException eh("TEveElement::GetObject ");
TClass* cls = GetObject(eh)->IsA();
TEveElement* el = reinterpret_cast<TEveElement*>(cls->New());
if (el == 0) {
Error("VizDB_Insert", "Creation of replica failed.");
return;
}
el->CopyVizParams(this);
Bool_t succ = gEve->InsertVizDBEntry(tag, el, replace, update);
if (succ && update)
gEve->Redraw3D();
}
////////////////////////////////////////////////////////////////////////////////
/// Returns the master element - that is:
/// - master of projectable, if this is a projected;
/// - master of compound, if fCompound is set;
/// - master of first compound parent, if kSCBTakeAnyParentAsMaster bit is set;
/// If non of the above is true, *this* is returned.
TEveElement* TEveElement::GetMaster()
{
TEveProjected* proj = dynamic_cast<TEveProjected*>(this);
if (proj)
{
return dynamic_cast<TEveElement*>(proj->GetProjectable())->GetMaster();
}
if (fCompound)
{
return fCompound->GetMaster();
}
if (TestCSCBits(kCSCBTakeAnyParentAsMaster))
{
for (List_i i = fParents.begin(); i != fParents.end(); ++i)
if (dynamic_cast<TEveCompound*>(*i))
return (*i)->GetMaster();
}
return this;
}
////////////////////////////////////////////////////////////////////////////////
/// Add re into the list parents.
///
/// Adding parent is subordinate to adding an element.
/// This is an internal function.
void TEveElement::AddParent(TEveElement* re)
{
fParents.push_back(re);
}
////////////////////////////////////////////////////////////////////////////////
/// Remove re from the list of parents.
/// Removing parent is subordinate to removing an element.
/// This is an internal function.
void TEveElement::RemoveParent(TEveElement* re)
{
static const TEveException eh("TEveElement::RemoveParent ");
fParents.remove(re);
CheckReferenceCount(eh);
}
/******************************************************************************/
////////////////////////////////////////////////////////////////////////////////
/// Check external references to this and eventually auto-destruct
/// the render-element.
void TEveElement::CheckReferenceCount(const TEveException& eh)
{
if (fDestructing != kNone)
return;
if (NumParents() <= fParentIgnoreCnt && fTopItemCnt <= 0 &&
fDestroyOnZeroRefCnt && fDenyDestroy <= 0)
{
if (gEve->GetUseOrphanage())
{
if (gDebug > 0)
Info(eh, "moving to orphanage '%s' on zero reference count.", GetElementName());
PreDeleteElement();
gEve->GetOrphanage()->AddElement(this);
}
else
{
if (gDebug > 0)
Info(eh, "auto-destructing '%s' on zero reference count.", GetElementName());
PreDeleteElement();
delete this;
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Collect all parents of class TEveScene. This is needed to
/// automatically detect which scenes need to be updated.
///
/// Overriden in TEveScene to include itself and return.
void TEveElement::CollectSceneParents(List_t& scenes)
{
for (List_i p=fParents.begin(); p!=fParents.end(); ++p)
(*p)->CollectSceneParents(scenes);
}
////////////////////////////////////////////////////////////////////////////////
/// Collect scene-parents from all children. This is needed to
/// automatically detect which scenes need to be updated during/after
/// a full sub-tree update.
/// Argument parent specifies parent in traversed hierarchy for which we can
/// skip the upwards search.
void TEveElement::CollectSceneParentsFromChildren(List_t& scenes,
TEveElement* parent)
{
for (List_i p=fParents.begin(); p!=fParents.end(); ++p)
{
if (*p != parent) (*p)->CollectSceneParents(scenes);
}
for (List_i c=fChildren.begin(); c!=fChildren.end(); ++c)
{
(*c)->CollectSceneParentsFromChildren(scenes, this);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Populates parent with elements.
/// parent must be an already existing representation of *this*.
/// Returns number of inserted elements.
/// If parent already has children, it does nothing.
///
/// Element can be inserted in a list-tree several times, thus we can not
/// search through fItems to get parent here.
/// Anyhow, it is probably known as it must have been selected by the user.
void TEveElement::ExpandIntoListTree(TGListTree* ltree,
TGListTreeItem* parent)
{
if (parent->GetFirstChild() != 0)
return;
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
(*i)->AddIntoListTree(ltree, parent);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Destroy sub-tree under item 'parent' in list-tree 'ltree'.
void TEveElement::DestroyListSubTree(TGListTree* ltree,
TGListTreeItem* parent)
{
TGListTreeItem* i = parent->GetFirstChild();
while (i != 0)
{
TEveElement* re = (TEveElement*) i->GetUserData();
i = i->GetNextSibling();
re->RemoveFromListTree(ltree, parent);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add this element into ltree to an already existing item
/// parent_lti. Children, if any, are added as below the newly created item.
/// Returns the newly created list-tree-item.
TGListTreeItem* TEveElement::AddIntoListTree(TGListTree* ltree,
TGListTreeItem* parent_lti)
{
static const TEveException eh("TEveElement::AddIntoListTree ");
TGListTreeItem* item = new TEveListTreeItem(this);
ltree->AddItem(parent_lti, item);
fItems.insert(TEveListTreeInfo(ltree, item));
if (parent_lti == 0)
++fTopItemCnt;
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
(*i)->AddIntoListTree(ltree, item);
}
ltree->ClearViewPort();
return item;
}
////////////////////////////////////////////////////////////////////////////////
/// Add this render element into ltree to all items belonging to
/// parent. Returns list-tree-item from the first register entry (but
/// we use a set for that so it can be anything).
TGListTreeItem* TEveElement::AddIntoListTree(TGListTree* ltree,
TEveElement* parent)
{
TGListTreeItem* lti = 0;
if (parent == 0) {
lti = AddIntoListTree(ltree, (TGListTreeItem*) 0);
} else {
for (sLTI_ri i = parent->fItems.rbegin(); i != parent->fItems.rend(); ++i)
{
if (i->fTree == ltree)
lti = AddIntoListTree(ltree, i->fItem);
}
}
return lti;
}
////////////////////////////////////////////////////////////////////////////////
/// Add this render element into all list-trees and all items
/// belonging to parent. Returns list-tree-item from the first
/// register entry (but we use a set for that so it can be anything).
TGListTreeItem* TEveElement::AddIntoListTrees(TEveElement* parent)
{
TGListTreeItem* lti = 0;
for (sLTI_ri i = parent->fItems.rbegin(); i != parent->fItems.rend(); ++i)
{
lti = AddIntoListTree(i->fTree, i->fItem);
}
return lti;
}
////////////////////////////////////////////////////////////////////////////////
/// Remove element from list-tree 'ltree' where its parent item is
/// 'parent_lti'.
/// Returns kTRUE if the item was found and removed, kFALSE
/// otherwise.
Bool_t TEveElement::RemoveFromListTree(TGListTree* ltree,
TGListTreeItem* parent_lti)
{
static const TEveException eh("TEveElement::RemoveFromListTree ");
sLTI_i i = FindItem(ltree, parent_lti);
if (i != fItems.end()) {
DestroyListSubTree(ltree, i->fItem);
ltree->DeleteItem(i->fItem);
ltree->ClearViewPort();
fItems.erase(i);
if (parent_lti == 0) {
--fTopItemCnt;
CheckReferenceCount(eh);
}
return kTRUE;
} else {
return kFALSE;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Remove element from all list-trees where 'parent' is the
/// user-data of the parent list-tree-item.
Int_t TEveElement::RemoveFromListTrees(TEveElement* parent)
{
static const TEveException eh("TEveElement::RemoveFromListTrees ");
Int_t count = 0;
sLTI_i i = fItems.begin();
while (i != fItems.end())
{
sLTI_i j = i++;
TGListTreeItem *plti = j->fItem->GetParent();
if ((plti != 0 && (TEveElement*) plti->GetUserData() == parent) ||
(plti == 0 && parent == 0))
{
DestroyListSubTree(j->fTree, j->fItem);
j->fTree->DeleteItem(j->fItem);
j->fTree->ClearViewPort();
fItems.erase(j);
if (parent == 0)
--fTopItemCnt;
++count;
}
}
if (parent == 0 && count > 0)
CheckReferenceCount(eh);
return count;
}
////////////////////////////////////////////////////////////////////////////////
/// Find any list-tree-item of this element in list-tree 'ltree'.
/// Note that each element can be placed into the same list-tree on
/// several postions.
TEveElement::sLTI_i TEveElement::FindItem(TGListTree* ltree)
{
for (sLTI_i i = fItems.begin(); i != fItems.end(); ++i)
if (i->fTree == ltree)
return i;
return fItems.end();
}
////////////////////////////////////////////////////////////////////////////////
/// Find list-tree-item of this element with given parent
/// list-tree-item.
TEveElement::sLTI_i TEveElement::FindItem(TGListTree* ltree,
TGListTreeItem* parent_lti)
{
for (sLTI_i i = fItems.begin(); i != fItems.end(); ++i)
if (i->fTree == ltree && i->fItem->GetParent() == parent_lti)
return i;
return fItems.end();
}
////////////////////////////////////////////////////////////////////////////////
/// Find any list-tree-item of this element in list-tree 'ltree'.
/// Note that each element can be placed into the same list-tree on
/// several postions.
TGListTreeItem* TEveElement::FindListTreeItem(TGListTree* ltree)
{
for (sLTI_i i = fItems.begin(); i != fItems.end(); ++i)
if (i->fTree == ltree)
return i->fItem;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Find list-tree-item of this element with given parent
/// list-tree-item.
TGListTreeItem* TEveElement::FindListTreeItem(TGListTree* ltree,
TGListTreeItem* parent_lti)
{
for (sLTI_i i = fItems.begin(); i != fItems.end(); ++i)
if (i->fTree == ltree && i->fItem->GetParent() == parent_lti)
return i->fItem;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Get a TObject associated with this render-element.
/// Most cases uses double-inheritance from TEveElement and TObject
/// so we just do a dynamic cast here.
/// If some TEveElement descendant implements a different scheme,
/// this virtual method should be overriden accordingly.
TObject* TEveElement::GetObject(const TEveException& eh) const
{
const TObject* obj = dynamic_cast<const TObject*>(this);
if (obj == 0)
throw(eh + "not a TObject.");
return const_cast<TObject*>(obj);
}
////////////////////////////////////////////////////////////////////////////////
/// Show GUI editor for this object.
/// This is forwarded to TEveManager::EditElement().
void TEveElement::SpawnEditor()
{
gEve->EditElement(this);
}
////////////////////////////////////////////////////////////////////////////////
/// Export render-element to CINT with variable name var_name.
void TEveElement::ExportToCINT(char* var_name)
{
const char* cname = IsA()->GetName();
gROOT->ProcessLine(TString::Format("%s* %s = (%s*)0x%lx;", cname, var_name, cname, (ULong_t)this));
}
////////////////////////////////////////////////////////////////////////////////
/// Call Dump() on source object.
/// Throws an exception if it is not set.
void TEveElement::DumpSourceObject() const
{
static const TEveException eh("TEveElement::DumpSourceObject ");
TObject *so = GetSourceObject();
if (!so)
throw eh + "source-object not set.";
so->Dump();
}
////////////////////////////////////////////////////////////////////////////////
/// Call Print() on source object.
/// Throws an exception if it is not set.
void TEveElement::PrintSourceObject() const
{
static const TEveException eh("TEveElement::PrintSourceObject ");
TObject *so = GetSourceObject();
if (!so)
throw eh + "source-object not set.";
so->Print();
}
////////////////////////////////////////////////////////////////////////////////
/// Export source object to CINT with given name for the variable.
/// Throws an exception if it is not set.
void TEveElement::ExportSourceObjectToCINT(char* var_name) const
{
static const TEveException eh("TEveElement::ExportSourceObjectToCINT ");