TEveSelection.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveSelection.cxx 32464 2010-03-04 15:45:13Z matevz $
00002 // Author: Matevz Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveSelection.h"
00013 #include "TEveProjectionBases.h"
00014 #include "TEveCompound.h"
00015 #include "TEveManager.h"
00016 
00017 #include "TClass.h"
00018 
00019 //______________________________________________________________________________
00020 //
00021 // Make sure there is a SINGLE running TEveSelection for each
00022 // selection type (select/highlight).
00023 
00024 ClassImp(TEveSelection);
00025 
00026 //______________________________________________________________________________
00027 TEveSelection::TEveSelection(const char* n, const char* t) :
00028    TEveElementList(n, t),
00029    fPickToSelect  (kPS_Projectable),
00030    fActive        (kTRUE),
00031    fIsMaster      (kTRUE)
00032 {
00033    // Constructor.
00034 
00035    fSelElement       = &TEveElement::SelectElement;
00036    fIncImpSelElement = &TEveElement::IncImpliedSelected;
00037    fDecImpSelElement = &TEveElement::DecImpliedSelected;
00038 }
00039 
00040 //______________________________________________________________________________
00041 void TEveSelection::SetHighlightMode()
00042 {
00043    // Set to 'highlight' mode.
00044 
00045    // Most importantly, this sets the pointers-to-function-members in
00046    // TEveElement that are used to mark elements as (un)selected and
00047    // implied-(un)selected.
00048 
00049    fPickToSelect = kPS_Projectable;
00050    fIsMaster     = kFALSE;
00051 
00052    fSelElement       = &TEveElement::HighlightElement;
00053    fIncImpSelElement = &TEveElement::IncImpliedHighlighted;
00054    fDecImpSelElement = &TEveElement::DecImpliedHighlighted;
00055 }
00056 
00057 
00058 /******************************************************************************/
00059 // Protected helpers
00060 /******************************************************************************/
00061 
00062 //______________________________________________________________________________
00063 void TEveSelection::DoElementSelect(TEveSelection::SelMap_i entry)
00064 {
00065    // Select element indicated by the entry and fill its
00066    // implied-selected set.
00067 
00068    TEveElement *el  = entry->first;
00069    Set_t       &set = entry->second;
00070 
00071    (el->*fSelElement)(kTRUE);
00072    el->FillImpliedSelectedSet(set);
00073    for (Set_i i = set.begin(); i != set.end(); ++i)
00074       ((*i)->*fIncImpSelElement)();
00075 }
00076 
00077 //______________________________________________________________________________
00078 void TEveSelection::DoElementUnselect(TEveSelection::SelMap_i entry)
00079 {
00080    // Deselect element indicated by the entry and clear its
00081    // implied-selected set.
00082 
00083    TEveElement *el  = entry->first;
00084    Set_t       &set = entry->second;
00085 
00086    for (Set_i i = set.begin(); i != set.end(); ++i)
00087       ((*i)->*fDecImpSelElement)();
00088    set.clear();
00089    (el->*fSelElement)(kFALSE);
00090 }
00091 
00092 
00093 /******************************************************************************/
00094 // Overrides of child-element-management virtuals from TEveElement
00095 /******************************************************************************/
00096 
00097 //______________________________________________________________________________
00098 Bool_t TEveSelection::AcceptElement(TEveElement* el)
00099 {
00100    // Pre-addition check. Deny addition if el is already selected.
00101    // Virtual from TEveElement.
00102 
00103    return el != this && fImpliedSelected.find(el) == fImpliedSelected.end() &&
00104           el->IsA()->InheritsFrom(TEveSelection::Class()) == kFALSE;
00105 }
00106 
00107 //______________________________________________________________________________
00108 void TEveSelection::AddElement(TEveElement* el)
00109 {
00110    // Add an element into selection, virtual from TEveElement.
00111 
00112    TEveElementList::AddElement(el);
00113 
00114    SelMap_i i = fImpliedSelected.insert(std::make_pair(el, Set_t())).first;
00115    if (fActive)
00116    {
00117       DoElementSelect(i);
00118    }
00119    SelectionAdded(el);
00120 }
00121 
00122 //______________________________________________________________________________
00123 void TEveSelection::RemoveElement(TEveElement* el)
00124 {
00125    // Add an element into selection, virtual from TEveElement.
00126    // Overriden here just so that a signal can be emitted.
00127 
00128    TEveElementList::RemoveElement(el);
00129    SelectionRemoved(el);
00130 }
00131 
00132 //______________________________________________________________________________
00133 void TEveSelection::RemoveElementLocal(TEveElement* el)
00134 {
00135    // Virtual from TEveElement.
00136 
00137    SelMap_i i = fImpliedSelected.find(el);
00138 
00139    if (i != fImpliedSelected.end())
00140    {
00141       if (fActive)
00142       {
00143          DoElementUnselect(i);
00144       }
00145       fImpliedSelected.erase(i);
00146    }
00147    else
00148    {
00149       Warning("TEveSelection::RemoveElementLocal", "element not found in map.");
00150    }
00151 }
00152 
00153 //______________________________________________________________________________
00154 void TEveSelection::RemoveElements()
00155 {
00156    // Add an element into selection, virtual from TEveElement.
00157    // Overriden here just so that a signal can be emitted.
00158 
00159    TEveElementList::RemoveElements();
00160    SelectionCleared();
00161 }
00162 
00163 //______________________________________________________________________________
00164 void TEveSelection::RemoveElementsLocal()
00165 {
00166    // Virtual from TEveElement.
00167 
00168    if (fActive)
00169    {
00170       for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
00171          DoElementUnselect(i);
00172    }
00173    fImpliedSelected.clear();
00174 }
00175 
00176 //______________________________________________________________________________
00177 void TEveSelection::RemoveImpliedSelected(TEveElement* el)
00178 {
00179    // Remove element from all implied-selected sets.
00180    //
00181    // This is called as part of the element destruction from
00182    // TEveManager::PreDeleteElement() and should not be called
00183    // directly.
00184 
00185    for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
00186    {
00187       Set_i j = i->second.find(el);
00188       if (j != i->second.end())
00189          i->second.erase(j);
00190    }
00191 }
00192 
00193 //______________________________________________________________________________
00194 void TEveSelection::RecheckImpliedSet(SelMap_i smi)
00195 {
00196    // Recalculate implied-selected state for given selection entry.
00197    // Add new elements to implied-selected set and increase their
00198    // implied-selected count.
00199 
00200    Set_t set;
00201    smi->first->FillImpliedSelectedSet(set);
00202    for (Set_i i = set.begin(); i != set.end(); ++i)
00203    {
00204       if (smi->second.find(*i) == smi->second.end())
00205       {
00206          smi->second.insert(*i);
00207          ((*i)->*fIncImpSelElement)();
00208       }
00209    }
00210 }
00211 
00212 //______________________________________________________________________________
00213 void TEveSelection::RecheckImpliedSetForElement(TEveElement* el)
00214 {
00215    // If given element is selected or implied-selected with this
00216    // selection and recheck implied-set for given selection entry.
00217 
00218    // Top-level selected.
00219    {
00220       SelMap_i i = fImpliedSelected.find(el);
00221       if (i != fImpliedSelected.end())
00222          RecheckImpliedSet(i);
00223    }
00224 
00225    // Implied selected, need to loop over all.
00226    {
00227       for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++ i)
00228       {
00229          if (i->second.find(el) != i->second.end())
00230             RecheckImpliedSet(i);
00231       }
00232    }
00233 }
00234 
00235 
00236 //******************************************************************************
00237 // Signals
00238 //******************************************************************************
00239 
00240 //______________________________________________________________________________
00241 void TEveSelection::SelectionAdded(TEveElement* el)
00242 {
00243    // Emit SelectionAdded signal.
00244 
00245    Emit("SelectionAdded(TEveElement*)", (Long_t)el);
00246 }
00247 
00248 //______________________________________________________________________________
00249 void TEveSelection::SelectionRemoved(TEveElement* el)
00250 {
00251    // Emit SelectionRemoved signal.
00252 
00253    Emit("SelectionRemoved(TEveElement*)", (Long_t)el);
00254 }
00255 
00256 //______________________________________________________________________________
00257 void TEveSelection::SelectionCleared()
00258 {
00259    // Emit SelectionCleared signal.
00260 
00261    Emit("SelectionCleared()");
00262 }
00263 
00264 //______________________________________________________________________________
00265 void TEveSelection::SelectionRepeated(TEveElement* el)
00266 {
00267    // Called when secondary selection changed internally.
00268 
00269    Emit("SelectionRepeated(TEveElement*)", (Long_t)el);
00270 }
00271 
00272 /******************************************************************************/
00273 // Activation / deactivation of selection
00274 /******************************************************************************/
00275 
00276 //______________________________________________________________________________
00277 void TEveSelection::ActivateSelection()
00278 {
00279    // Activate this selection.
00280 
00281    for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
00282       DoElementSelect(i);
00283    fActive = kTRUE;
00284 }
00285 
00286 //______________________________________________________________________________
00287 void TEveSelection::DeactivateSelection()
00288 {
00289    // Deactivate this selection.
00290 
00291    fActive = kFALSE;
00292    for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
00293       DoElementUnselect(i);
00294 }
00295 
00296 
00297 /******************************************************************************/
00298 // User input processing
00299 /******************************************************************************/
00300 
00301 //______________________________________________________________________________
00302 TEveElement* TEveSelection::MapPickedToSelected(TEveElement* el)
00303 {
00304    // Given element el that was picked or clicked by the user, find
00305    // the parent/ancestor element that should actually become the main
00306    // selected element according to current selection mode.
00307 
00308    if (el == 0)
00309       return 0;
00310 
00311    if (el->ForwardSelection())
00312    {
00313       return el->ForwardSelection();
00314    }
00315 
00316    switch (fPickToSelect)
00317    {
00318       case kPS_Ignore:
00319       {
00320          return 0;
00321       }
00322       case kPS_Element:
00323       {
00324          return el;
00325       }
00326       case kPS_Projectable:
00327       {
00328          TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
00329          if (pted)
00330             return dynamic_cast<TEveElement*>(pted->GetProjectable());
00331          return el;
00332       }
00333       case kPS_Compound:
00334       {
00335          TEveElement* cmpnd = el->GetCompound();
00336          if (cmpnd)
00337             return cmpnd;
00338          return el;
00339       }
00340       case kPS_PableCompound:
00341       {
00342          TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
00343          if (pted)
00344             el = dynamic_cast<TEveElement*>(pted->GetProjectable());
00345          TEveElement* cmpnd = el->GetCompound();
00346          if (cmpnd)
00347             return cmpnd;
00348          return el;
00349       }
00350       case kPS_Master:
00351       {
00352          TEveElement* mstr = el->GetMaster();
00353          if (mstr)
00354             return mstr;
00355          return el;
00356       }
00357    }
00358    return el;
00359 }
00360 
00361 //______________________________________________________________________________
00362 void TEveSelection::UserPickedElement(TEveElement* el, Bool_t multi)
00363 {
00364    // Called when user picks/clicks on an element. If multi is true,
00365    // the user is requiring a multiple selection (usually this is
00366    // associated with control-key being pressed at the time of pick
00367    // event).
00368 
00369    TEveElement *edit_el = el ? el->ForwardEdit() : 0;
00370 
00371    el = MapPickedToSelected(el);
00372 
00373    if (el || HasChildren())
00374    {
00375       if (!multi)
00376          RemoveElements();
00377       if (el)
00378       {
00379          if (HasChild(el))
00380              RemoveElement(el);
00381          else
00382             AddElement(el);
00383       }
00384       if (fIsMaster)
00385          gEve->ElementSelect(edit_el ? edit_el : el);
00386       gEve->Redraw3D();
00387    }
00388 }
00389 
00390 //______________________________________________________________________________
00391 void TEveSelection::UserRePickedElement(TEveElement* el)
00392 {
00393    // Called when secondary selection becomes empty.
00394 
00395    el = MapPickedToSelected(el);
00396    if (el && HasChild(el))
00397    {
00398       SelectionRepeated(el);
00399       gEve->Redraw3D();
00400    }
00401 }
00402 
00403 //______________________________________________________________________________
00404 void TEveSelection::UserUnPickedElement(TEveElement* el)
00405 {
00406    // Called when secondary selection becomes empty.
00407 
00408    el = MapPickedToSelected(el);
00409    if (el)
00410    {
00411       RemoveElement(el);
00412       gEve->Redraw3D();
00413    }
00414 }

Generated on Tue Jul 5 14:16:13 2011 for ROOT_528-00b_version by  doxygen 1.5.1