CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Core/src/FWDigitSetProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWDigitSetProxyBuilder
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Tue Oct 19 12:00:50 CEST 2010
00011 // $Id: FWDigitSetProxyBuilder.cc,v 1.3 2010/12/03 20:38:57 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "TEveDigitSet.h"
00018 #include "TEveBoxSet.h"
00019 #include "TEveManager.h"
00020 #include "TEveSelection.h"
00021 
00022 #include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h"
00023 #include "Fireworks/Core/interface/FWFromEveSelectorBase.h"
00024 #include "Fireworks/Core/interface/FWDisplayProperties.h"
00025 #include "Fireworks/Core/interface/FWModelId.h"
00026 #include "Fireworks/Core/interface/FWEventItem.h"
00027 
00028 
00029 class FWSecondarySelectableSelector : public FWFromEveSelectorBase
00030 {
00031 public:
00032    FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t& s, const FWEventItem* i): m_selected(s), m_item(i) {}
00033    ~FWSecondarySelectableSelector() {}
00034 
00035    virtual void doSelect()
00036    {
00037       syncSelection();
00038    }
00039 
00040    virtual void doUnselect()
00041    { 
00042       syncSelection(); 
00043    }
00044 
00045    const FWEventItem* item() const { return m_item; }
00046 
00047 private:
00048    const TEveSecondarySelectable::SelectionSet_t& m_selected;
00049    const FWEventItem* m_item;
00050 
00051    void syncSelection()
00052    {
00053       size_t size = m_item->size();
00054       for (size_t i = 0; i < size; ++i)
00055       {
00056          FWEventItem::ModelInfo modelInfo = m_item->modelInfo(i);
00057          TEveSecondarySelectable::SelectionSet_ci si = m_selected.find(i);
00058          if ((si != m_selected.end()) != modelInfo.isSelected() )
00059          {
00060             if (si != m_selected.end())
00061                m_item->select(i);
00062             else
00063                m_item->unselect(i);
00064          }
00065       }
00066    }
00067 };
00068 
00069 //==============================================================================
00070 //==============================================================================
00071 //==============================================================================
00072 
00073 FWDigitSetProxyBuilder::FWDigitSetProxyBuilder():
00074    m_boxSet(0)
00075 {
00076 }
00077 
00078 FWDigitSetProxyBuilder::~FWDigitSetProxyBuilder()
00079 {
00080 }
00081 
00082 TString FWDigitSetProxyBuilder::getTooltip(TEveDigitSet* set, int idx)
00083 {
00084    TEveElement* el = static_cast<TEveElement*>(set); // tmp-workaround
00085    FWSecondarySelectableSelector* ss = static_cast<FWSecondarySelectableSelector*>(el->GetUserData());
00086    return ss->item()->modelInterestingValueAsString(idx);
00087 }
00088 
00089 TEveBoxSet* FWDigitSetProxyBuilder::addBoxSetToProduct(TEveElementList* product)
00090 {
00091    assert(!product->HasChildren());
00092    
00093    m_boxSet = new TEveBoxSet();
00094    m_boxSet->SetTooltipCBFoo(getTooltip);
00095    m_boxSet->Reset(TEveBoxSet::kBT_FreeBox, true, 256);
00096    FWSecondarySelectableSelector* sel = new FWSecondarySelectableSelector(m_boxSet->RefSelectedSet(), item());
00097    m_boxSet->SetUserData(sel);
00098    m_boxSet->SetPickable(1);
00099    m_boxSet->SetAlwaysSecSelect(1);
00100 
00101    product->AddElement(m_boxSet);
00102 
00103    return m_boxSet;
00104 }
00105 
00106 TEveDigitSet* FWDigitSetProxyBuilder::digitSet(TEveElement* product)
00107 {
00108    assert(product->NumChildren() == 1);
00109    return static_cast<TEveDigitSet*>(*product->BeginChildren());
00110 }
00111 
00112 void FWDigitSetProxyBuilder::addBox(TEveBoxSet* boxSet, const float* pnts, const FWDisplayProperties& dp)
00113 {
00114    boxSet->AddBox(pnts);
00115    boxSet->DigitValue(dp.isVisible());
00116 
00117    if (dp.isVisible()) 
00118       boxSet->DigitColor(dp.color(), dp.transparency());
00119 
00120    if (dp.transparency())
00121       boxSet->SetMainTransparency(dp.transparency());
00122 }
00123 
00124 void FWDigitSetProxyBuilder::modelChanges(const FWModelIds& iIds, Product* product)
00125 {
00126    TEveDigitSet* digits = digitSet(product->m_elements);
00127    if (!digits) return;
00128    
00129    TEveSecondarySelectable::SelectionSet_t& selected = (TEveSecondarySelectable::SelectionSet_t&)(digits->RefSelectedSet());
00130 
00131    for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it)
00132    {
00133       const FWEventItem::ModelInfo& info = item()->modelInfo(it->index());
00134 
00135       // id display properties
00136       const FWDisplayProperties &p = info.displayProperties();
00137       digits->SetCurrentDigit(it->index());
00138       digits->DigitValue(p.isVisible());
00139       if (p.isVisible())
00140          digits->DigitColor(p.color(), p.transparency());
00141 
00142       // id selection
00143       TEveSecondarySelectable::SelectionSet_ci si = selected.find(it->index());
00144       if (info.isSelected())
00145       {
00146          if (si == selected.end())
00147             selected.insert(it->index());
00148       }
00149       else
00150       {
00151          if ( si != selected.end())
00152             selected.erase(si);
00153       }
00154    }
00155 
00156    if(!selected.empty()) {
00157       if(0==digits->GetSelectedLevel()) {
00158          gEve->GetSelection()->AddElement(digits);
00159       }
00160    } else {
00161       if(1==digits->GetSelectedLevel()||2==digits->GetSelectedLevel()) {
00162          gEve->GetSelection()->RemoveElement(digits);
00163       }
00164    }
00165 
00166    digits->StampObjProps();
00167 }