00001 // @(#)root/eve:$Id: TEveSecondarySelectable.cxx 37392 2010-12-08 11:32:08Z 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 "TEveSecondarySelectable.h" 00013 #include "TEveElement.h" 00014 00015 #include "TGLSelectRecord.h" 00016 00017 //______________________________________________________________________________ 00018 // 00019 // Semi-abstract interface for classes supporting secondary-selection. 00020 // 00021 // Element class that inherits from this, should also implement the 00022 // following virtuals from TEveElement: 00023 // virtual void UnSelected(); 00024 // virtual void UnHighlighted(); 00025 // and clear corresponding selection-set from there. 00026 // 00027 // To support tooltips for sub-elements, implement: 00028 // virtual TString TEveElement::GetHighlightTooltip(); 00029 // and return tooltip for the entry in the fHighlightedSet. 00030 // There should always be a single entry there. 00031 // See TEveDigitSet for an example. 00032 00033 00034 ClassImp(TEveSecondarySelectable); 00035 00036 //______________________________________________________________________________ 00037 TEveSecondarySelectable::TEveSecondarySelectable() : 00038 fAlwaysSecSelect(kFALSE) 00039 { 00040 // Constructor. 00041 } 00042 00043 //______________________________________________________________________________ 00044 void TEveSecondarySelectable::ProcessGLSelection(TGLSelectRecord& rec) 00045 { 00046 // Process secondary GL selection and populate selected set accordingly. 00047 00048 if (rec.GetHighlight()) 00049 ProcessGLSelectionInternal(rec, fHighlightedSet); 00050 else 00051 ProcessGLSelectionInternal(rec, fSelectedSet); 00052 } 00053 00054 //______________________________________________________________________________ 00055 void TEveSecondarySelectable::ProcessGLSelectionInternal(TGLSelectRecord& rec, 00056 SelectionSet_t& sset) 00057 { 00058 // Process secondary GL selection and populate given set accordingly. 00059 00060 Int_t id = (rec.GetN() > 1) ? (Int_t) rec.GetItem(1) : -1; 00061 00062 if (sset.empty()) 00063 { 00064 if (id >= 0) 00065 { 00066 sset.insert(id); 00067 rec.SetSecSelResult(TGLSelectRecord::kEnteringSelection); 00068 } 00069 } 00070 else 00071 { 00072 if (id >= 0) 00073 { 00074 if (rec.GetMultiple()) 00075 { 00076 if (sset.find(id) == sset.end()) 00077 { 00078 sset.insert(id); 00079 rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection); 00080 } 00081 else 00082 { 00083 sset.erase(id); 00084 if (sset.empty()) 00085 rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection); 00086 else 00087 rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection); 00088 } 00089 } 00090 else 00091 { 00092 if (sset.size() != 1 || sset.find(id) == sset.end()) 00093 { 00094 sset.clear(); 00095 sset.insert(id); 00096 rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection); 00097 } 00098 } 00099 } 00100 else 00101 { 00102 if (!rec.GetMultiple()) 00103 { 00104 sset.clear(); 00105 rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection); 00106 } 00107 } 00108 } 00109 00110 if (rec.GetSecSelResult() != TGLSelectRecord::kNone) 00111 { 00112 dynamic_cast<TEveElement*>(this)->StampColorSelection(); 00113 } 00114 }