// @(#)root/eve:$Id$
// Author: Matevz Tadel 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 "TEveCompound.h"

//==============================================================================
//==============================================================================
// TEveCompound
//==============================================================================

//______________________________________________________________________________
//
// Description of TEveCompound
//

ClassImp(TEveCompound);

//______________________________________________________________________________
TEveCompound::TEveCompound(const char* n, const char* t, Bool_t doColor, Bool_t doTransparency) :
   TEveElementList (n, t, doColor, doTransparency),
   fCompoundOpen   (0)
{
   // Constructor.
}

//______________________________________________________________________________
void TEveCompound::SetMainColor(Color_t color)
{
   // SetMainColor for the compound.
   // The color is also propagated to children with compound set to this
   // whose current color is the same as the old color.
   //
   // The following CompoundSelectionColorBits have further influence:
   //   kCSCBApplyMainColorToAllChildren      - apply color to all children;
   //   kCSCBApplyMainColorToMatchingChildren - apply color to children who have
   //                                           matching old color.

   Color_t old_color = GetMainColor();

   TEveElement::SetMainColor(color);

   Bool_t color_all      = TestCSCBits(kCSCBApplyMainColorToAllChildren);
   Bool_t color_matching = TestCSCBits(kCSCBApplyMainColorToMatchingChildren);

   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
   {
      if (color_all || (color_matching && (*i)->GetMainColor() == old_color) ||
          ((*i)->GetCompound() == this && (*i)->GetMainColor() == old_color))
      {
         (*i)->SetMainColor(color);
      }
   }
}

//______________________________________________________________________________
void TEveCompound::SetMainTransparency(Char_t t)
{
   // SetMainTransparency for the compound.
   // The transparenct is also propagated to children with compound set to this
   // whose current transparency is the same as the old transparency.
   //
   // The following CompoundSelectionColorBits have further influence:
   //   kCSCBApplyMainTransparencyToAllChildren      - apply transparency to all children;
   //   kCSCBApplyMainTransparencyToMatchingChildren - apply transparency to children who have
   //                                                  matching transparency.

   Char_t old_t = GetMainTransparency();

   TEveElement::SetMainTransparency(t);

   Bool_t chg_all      = TestCSCBits(kCSCBApplyMainTransparencyToAllChildren);
   Bool_t chg_matching = TestCSCBits(kCSCBApplyMainTransparencyToMatchingChildren);

   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
   {
      if (chg_all || (chg_matching && (*i)->GetMainTransparency() == old_t) ||
          ((*i)->GetCompound() == this && (*i)->GetMainTransparency() == old_t))
      {
         (*i)->SetMainTransparency(t);
      }
   }
}

//******************************************************************************

//______________________________________________________________________________
void TEveCompound::AddElement(TEveElement* el)
{
   // Call base-class implementation.
   // If compund is open and compound of the new element is not set,
   // the el's compound is set to this.
   // You might also want to call RecheckImpliedSelections().

   TEveElementList::AddElement(el);
   if (IsCompoundOpen() && el->GetCompound() == 0)
      el->SetCompound(this);
}

//______________________________________________________________________________
void TEveCompound::RemoveElementLocal(TEveElement* el)
{
   // Decompoundofy el, call base-class version.

   if (el->GetCompound() == this)
      el->SetCompound(0);

   TEveElementList::RemoveElementLocal(el);
}

//______________________________________________________________________________
void TEveCompound::RemoveElementsLocal()
{
   // Decompoundofy children, call base-class version.

   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
   {
      if ((*i)->GetCompound() == this)
         (*i)->SetCompound(0);
   }

   TEveElementList::RemoveElementsLocal();
}

//******************************************************************************

//______________________________________________________________________________
void TEveCompound::FillImpliedSelectedSet(Set_t& impSelSet)
{
   // Recurse on all children that are in this compund and
   // call the base-class version.
   // If SelectionColorBit kSCBImplySelectAllChildren is set, then all
   // children are added to the set.
   //
   // Note that projected replicas of the compound will be added to
   // the set in base-class function that handles projectables.

   Bool_t select_all = TestCSCBits(kCSCBImplySelectAllChildren);

   for (List_i i = fChildren.begin(); i != fChildren.end(); ++i)
   {
      if (select_all || (*i)->GetCompound() == this)
      {
         if (impSelSet.insert(*i).second)
            (*i)->FillImpliedSelectedSet(impSelSet);
      }
   }

   TEveElementList::FillImpliedSelectedSet(impSelSet);
}

//******************************************************************************

//______________________________________________________________________________
TClass* TEveCompound::ProjectedClass(const TEveProjection*) const
{
   // Virtual from TEveProjectable, returns TEveCompoundProjected class.

   return TEveCompoundProjected::Class();
}


//==============================================================================
//==============================================================================
// TEveCompoundProjected
//==============================================================================

//______________________________________________________________________________
//
// Description of TEveCompoundProjected
//

ClassImp(TEveCompoundProjected);

//______________________________________________________________________________
TEveCompoundProjected::TEveCompoundProjected() :
   TEveCompound  (),
   TEveProjected ()
{
   // Constructor.
}

//______________________________________________________________________________
void TEveCompoundProjected::SetMainColor(Color_t color)
{
   // Revert back to the behaviour of TEveElement as color
   // is propagated:
   // a) from projectable -> projected
   // b) from compound -> compound elements
   // and we do not need to do this twice for projected-compound-elements.

   TEveElement::SetMainColor(color);
}
 TEveCompound.cxx:1
 TEveCompound.cxx:2
 TEveCompound.cxx:3
 TEveCompound.cxx:4
 TEveCompound.cxx:5
 TEveCompound.cxx:6
 TEveCompound.cxx:7
 TEveCompound.cxx:8
 TEveCompound.cxx:9
 TEveCompound.cxx:10
 TEveCompound.cxx:11
 TEveCompound.cxx:12
 TEveCompound.cxx:13
 TEveCompound.cxx:14
 TEveCompound.cxx:15
 TEveCompound.cxx:16
 TEveCompound.cxx:17
 TEveCompound.cxx:18
 TEveCompound.cxx:19
 TEveCompound.cxx:20
 TEveCompound.cxx:21
 TEveCompound.cxx:22
 TEveCompound.cxx:23
 TEveCompound.cxx:24
 TEveCompound.cxx:25
 TEveCompound.cxx:26
 TEveCompound.cxx:27
 TEveCompound.cxx:28
 TEveCompound.cxx:29
 TEveCompound.cxx:30
 TEveCompound.cxx:31
 TEveCompound.cxx:32
 TEveCompound.cxx:33
 TEveCompound.cxx:34
 TEveCompound.cxx:35
 TEveCompound.cxx:36
 TEveCompound.cxx:37
 TEveCompound.cxx:38
 TEveCompound.cxx:39
 TEveCompound.cxx:40
 TEveCompound.cxx:41
 TEveCompound.cxx:42
 TEveCompound.cxx:43
 TEveCompound.cxx:44
 TEveCompound.cxx:45
 TEveCompound.cxx:46
 TEveCompound.cxx:47
 TEveCompound.cxx:48
 TEveCompound.cxx:49
 TEveCompound.cxx:50
 TEveCompound.cxx:51
 TEveCompound.cxx:52
 TEveCompound.cxx:53
 TEveCompound.cxx:54
 TEveCompound.cxx:55
 TEveCompound.cxx:56
 TEveCompound.cxx:57
 TEveCompound.cxx:58
 TEveCompound.cxx:59
 TEveCompound.cxx:60
 TEveCompound.cxx:61
 TEveCompound.cxx:62
 TEveCompound.cxx:63
 TEveCompound.cxx:64
 TEveCompound.cxx:65
 TEveCompound.cxx:66
 TEveCompound.cxx:67
 TEveCompound.cxx:68
 TEveCompound.cxx:69
 TEveCompound.cxx:70
 TEveCompound.cxx:71
 TEveCompound.cxx:72
 TEveCompound.cxx:73
 TEveCompound.cxx:74
 TEveCompound.cxx:75
 TEveCompound.cxx:76
 TEveCompound.cxx:77
 TEveCompound.cxx:78
 TEveCompound.cxx:79
 TEveCompound.cxx:80
 TEveCompound.cxx:81
 TEveCompound.cxx:82
 TEveCompound.cxx:83
 TEveCompound.cxx:84
 TEveCompound.cxx:85
 TEveCompound.cxx:86
 TEveCompound.cxx:87
 TEveCompound.cxx:88
 TEveCompound.cxx:89
 TEveCompound.cxx:90
 TEveCompound.cxx:91
 TEveCompound.cxx:92
 TEveCompound.cxx:93
 TEveCompound.cxx:94
 TEveCompound.cxx:95
 TEveCompound.cxx:96
 TEveCompound.cxx:97
 TEveCompound.cxx:98
 TEveCompound.cxx:99
 TEveCompound.cxx:100
 TEveCompound.cxx:101
 TEveCompound.cxx:102
 TEveCompound.cxx:103
 TEveCompound.cxx:104
 TEveCompound.cxx:105
 TEveCompound.cxx:106
 TEveCompound.cxx:107
 TEveCompound.cxx:108
 TEveCompound.cxx:109
 TEveCompound.cxx:110
 TEveCompound.cxx:111
 TEveCompound.cxx:112
 TEveCompound.cxx:113
 TEveCompound.cxx:114
 TEveCompound.cxx:115
 TEveCompound.cxx:116
 TEveCompound.cxx:117
 TEveCompound.cxx:118
 TEveCompound.cxx:119
 TEveCompound.cxx:120
 TEveCompound.cxx:121
 TEveCompound.cxx:122
 TEveCompound.cxx:123
 TEveCompound.cxx:124
 TEveCompound.cxx:125
 TEveCompound.cxx:126
 TEveCompound.cxx:127
 TEveCompound.cxx:128
 TEveCompound.cxx:129
 TEveCompound.cxx:130
 TEveCompound.cxx:131
 TEveCompound.cxx:132
 TEveCompound.cxx:133
 TEveCompound.cxx:134
 TEveCompound.cxx:135
 TEveCompound.cxx:136
 TEveCompound.cxx:137
 TEveCompound.cxx:138
 TEveCompound.cxx:139
 TEveCompound.cxx:140
 TEveCompound.cxx:141
 TEveCompound.cxx:142
 TEveCompound.cxx:143
 TEveCompound.cxx:144
 TEveCompound.cxx:145
 TEveCompound.cxx:146
 TEveCompound.cxx:147
 TEveCompound.cxx:148
 TEveCompound.cxx:149
 TEveCompound.cxx:150
 TEveCompound.cxx:151
 TEveCompound.cxx:152
 TEveCompound.cxx:153
 TEveCompound.cxx:154
 TEveCompound.cxx:155
 TEveCompound.cxx:156
 TEveCompound.cxx:157
 TEveCompound.cxx:158
 TEveCompound.cxx:159
 TEveCompound.cxx:160
 TEveCompound.cxx:161
 TEveCompound.cxx:162
 TEveCompound.cxx:163
 TEveCompound.cxx:164
 TEveCompound.cxx:165
 TEveCompound.cxx:166
 TEveCompound.cxx:167
 TEveCompound.cxx:168
 TEveCompound.cxx:169
 TEveCompound.cxx:170
 TEveCompound.cxx:171
 TEveCompound.cxx:172
 TEveCompound.cxx:173
 TEveCompound.cxx:174
 TEveCompound.cxx:175
 TEveCompound.cxx:176
 TEveCompound.cxx:177
 TEveCompound.cxx:178
 TEveCompound.cxx:179
 TEveCompound.cxx:180
 TEveCompound.cxx:181
 TEveCompound.cxx:182
 TEveCompound.cxx:183
 TEveCompound.cxx:184
 TEveCompound.cxx:185
 TEveCompound.cxx:186
 TEveCompound.cxx:187
 TEveCompound.cxx:188
 TEveCompound.cxx:189
 TEveCompound.cxx:190
 TEveCompound.cxx:191
 TEveCompound.cxx:192
 TEveCompound.cxx:193
 TEveCompound.cxx:194
 TEveCompound.cxx:195
 TEveCompound.cxx:196
 TEveCompound.cxx:197
 TEveCompound.cxx:198
 TEveCompound.cxx:199
 TEveCompound.cxx:200