#include "TEveSelection.h"
#include "TEveProjectionBases.h"
#include "TEveCompound.h"
#include "TEveManager.h"
#include "TClass.h"
ClassImp(TEveSelection);
TEveSelection::TEveSelection(const Text_t* n, const Text_t* t) :
TEveElementList(n, t),
fPickToSelect (kPS_Projectable),
fActive (kTRUE),
fIsMaster (kTRUE)
{
fSelElement = &TEveElement::SelectElement;
fIncImpSelElement = &TEveElement::IncImpliedSelected;
fDecImpSelElement = &TEveElement::DecImpliedSelected;
}
void TEveSelection::SetHighlightMode()
{
fPickToSelect = kPS_Projectable;
fIsMaster = kFALSE;
fSelElement = &TEveElement::HighlightElement;
fIncImpSelElement = &TEveElement::IncImpliedHighlighted;
fDecImpSelElement = &TEveElement::DecImpliedHighlighted;
}
void TEveSelection::DoElementSelect(TEveSelection::SelMap_i entry)
{
TEveElement *el = entry->first;
Set_t &set = entry->second;
(el->*fSelElement)(kTRUE);
el->FillImpliedSelectedSet(set);
for (Set_i i = set.begin(); i != set.end(); ++i)
((*i)->*fIncImpSelElement)();
}
void TEveSelection::DoElementUnselect(TEveSelection::SelMap_i entry)
{
TEveElement *el = entry->first;
Set_t &set = entry->second;
for (Set_i i = set.begin(); i != set.end(); ++i)
((*i)->*fDecImpSelElement)();
set.clear();
(el->*fSelElement)(kFALSE);
}
Bool_t TEveSelection::AcceptElement(TEveElement* el)
{
return el != this && fImpliedSelected.find(el) == fImpliedSelected.end() &&
el->IsA()->InheritsFrom(TEveSelection::Class()) == kFALSE;
}
void TEveSelection::AddElement(TEveElement* el)
{
TEveElementList::AddElement(el);
SelMap_i i = fImpliedSelected.insert(std::make_pair(el, Set_t())).first;
if (fActive)
{
DoElementSelect(i);
}
SelectionAdded(el);
}
void TEveSelection::RemoveElement(TEveElement* el)
{
TEveElementList::RemoveElement(el);
SelectionRemoved(el);
}
void TEveSelection::RemoveElementLocal(TEveElement* el)
{
SelMap_i i = fImpliedSelected.find(el);
if (i != fImpliedSelected.end())
{
if (fActive)
{
DoElementUnselect(i);
}
fImpliedSelected.erase(i);
}
else
{
Warning("TEveSelection::RemoveElementLocal", "element not found in map.");
}
}
void TEveSelection::RemoveElements()
{
TEveElementList::RemoveElements();
SelectionCleared();
}
void TEveSelection::RemoveElementsLocal()
{
if (fActive)
{
for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
DoElementUnselect(i);
}
fImpliedSelected.clear();
}
void TEveSelection::RemoveImpliedSelected(TEveElement* el)
{
for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
{
Set_i j = i->second.find(el);
if (j != i->second.end())
i->second.erase(j);
}
}
void TEveSelection::SelectionAdded(TEveElement* el)
{
Emit("SelectionAdded(TEveElement*)", (Long_t)el);
}
void TEveSelection::SelectionRemoved(TEveElement* el)
{
Emit("SelectionRemoved(TEveElement*)", (Long_t)el);
}
void TEveSelection::SelectionCleared()
{
Emit("SelectionCleared()");
}
void TEveSelection::ActivateSelection()
{
for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
DoElementSelect(i);
fActive = kTRUE;
}
void TEveSelection::DeactivateSelection()
{
fActive = kFALSE;
for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
DoElementUnselect(i);
}
TEveElement* TEveSelection::MapPickedToSelected(TEveElement* el)
{
if (el == 0)
return 0;
switch (fPickToSelect)
{
case kPS_Ignore:
{
return 0;
}
case kPS_Element:
{
return el;
}
case kPS_Projectable:
{
TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
if (pted)
return dynamic_cast<TEveElement*>(pted->GetProjectable());
return el;
}
case kPS_Compound:
{
TEveElement* cmpnd = el->GetCompound();
if (cmpnd)
return cmpnd;
return el;
}
case kPS_PableCompound:
{
TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
if (pted)
el = dynamic_cast<TEveElement*>(pted->GetProjectable());
TEveElement* cmpnd = el->GetCompound();
if (cmpnd)
return cmpnd;
return el;
}
case kPS_Master:
{
TEveElement* mstr = el->GetMaster();
if (mstr)
return mstr;
return el;
}
}
return el;
}
void TEveSelection::UserPickedElement(TEveElement* el, Bool_t multi)
{
el = MapPickedToSelected(el);
if (el || HasChildren())
{
if (!multi)
RemoveElements();
if (el)
{
if (HasChild(el))
RemoveElement(el);
else
AddElement(el);
}
if (fIsMaster)
gEve->ElementSelect(el);
gEve->Redraw3D();
}
}
Last change: Tue Aug 26 17:15:32 2008
Last generated: 2008-08-26 17:15
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.