CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Fireworks/Core/src/FWInteractionList.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWInteractionList
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Mon Apr 19 12:48:18 CEST 2010
00011 // $Id: FWInteractionList.cc,v 1.14 2011/08/20 03:48:40 amraktad Exp $
00012 //
00013 
00014 // user include files
00015 #include "TEveCompound.h"
00016 #include "TEveManager.h"
00017 #include "TEveSelection.h"
00018 
00019 #include "Fireworks/Core/interface/FWInteractionList.h"
00020 #include "Fireworks/Core/interface/FWEventItem.h"
00021 #include "Fireworks/Core/interface/FWModelIdFromEveSelector.h"
00022 #include "Fireworks/Core/interface/FWModelId.h"
00023 
00024 
00025 
00026 //
00027 // constants, enums and typedefs
00028 //
00029 
00030 //
00031 // static data member definitions
00032 //
00033 
00034 //
00035 // constructors and destructor
00036 //
00037 FWInteractionList::FWInteractionList(const FWEventItem* item)
00038    : m_item(item)
00039 {}
00040 
00041 // FWInteractionList::FWInteractionList(const FWInteractionList& rhs)
00042 // {
00043 //    // do actual copying here;
00044 // }
00045 
00046 FWInteractionList::~FWInteractionList()
00047 {
00048    for ( std::vector<TEveCompound*>::iterator i = m_compounds.begin(); i != m_compounds.end(); ++i)
00049    {
00050       // Interaction are created only in the standard use case, where user data is FWFromEveSelectorBase.
00051       // This is defined with return value of virtual function FWPRoxyBuilderBase::willHandleInteraction().
00052 
00053       if ((*i)->GetUserData())
00054          delete reinterpret_cast<FWFromEveSelectorBase*>((*i)->GetUserData());
00055 
00056       (*i)->RemoveElements();
00057       (*i)->DecDenyDestroy();
00058    }
00059 }
00060 
00061 
00062 //
00063 // member functions
00064 //
00065 
00070 void
00071 FWInteractionList::added(TEveElement* el, unsigned int idx)
00072 {
00073 
00074    // In the case a compound for the given index already exists, just add 
00075    // the TEveElement to it, otherwise create a new one.
00076    if (idx < m_compounds.size())
00077    {
00078       m_compounds[idx]->AddElement(el);
00079       return;
00080    }
00081 
00082    // Prepare name for the tooltip on mouseover in GL viewer.Value of
00083    // tooltip is TEveElement::fTitle
00084    std::string name = m_item->modelName(idx);
00085    if (m_item->haveInterestingValue())
00086       name += m_item->modelInterestingValueAsString(idx);
00087 
00088    TEveCompound* c = new TEveCompound(name.c_str(), name.c_str());
00089    c->EnableListElements(m_item->defaultDisplayProperties().isVisible());
00090    c->SetMainColor(m_item->defaultDisplayProperties().color());
00091    c->SetMainTransparency(m_item->defaultDisplayProperties().transparency());
00092    
00093    // Set flags to propagat attributes.
00094    c->CSCImplySelectAllChildren();
00095    c->CSCApplyMainColorToAllChildren();
00096    c->CSCApplyMainTransparencyToAllChildren();
00097 
00098    // TEveElement is auto-destroyed if is is not added to any parent. Alternative could 
00099    // be to use increase/decrease reference count.
00100    c->IncDenyDestroy();
00101    //  FWModelIdFromEveSelector is needed for interaction from Eve to Fireworks.
00102    //  FWEveViewManager gets ROOT signals with selected objects (TEveCompound)
00103    //  then cals doSelect() on the compound's user data.
00104    c->SetUserData(new FWModelIdFromEveSelector(FWModelId(m_item, idx)));
00105    // Order does not matter. What is added to TEveCompound is not concern of interaction list.
00106    // Interaction list operates ony with the compound.
00107    m_compounds.push_back(c);
00108    m_compounds.back()->AddElement(el); 
00109    // printf("%s[%d] FWInteractionList::added has childern %d\n",m_item->name().c_str(), idx,  m_compounds[idx]->NumChildren()); 
00110 }
00111 
00112  
00116 void
00117 FWInteractionList::modelChanges(const FWModelIds& iIds)
00118 { 
00119    assert (m_compounds.size() >= m_item->size());
00120 
00121    for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it)
00122    {
00123       const FWEventItem::ModelInfo& info = m_item->modelInfo(it->index());
00124       // std::cout <<" FWInteractionList::modelChanges  color "<< info.displayProperties().color()  << "(*it).index() " <<(*it).index() << "  " << m_item->name() <<std::endl;
00125       const FWDisplayProperties &p = info.displayProperties();
00126       TEveElement* comp = m_compounds[it->index()];
00127       comp->EnableListElements(p.isVisible(), p.isVisible());
00128       comp->SetMainColor(p.color());
00129       comp->SetMainTransparency(p.transparency());
00130 
00131       if (info.isSelected())
00132       {
00133          if (comp->GetSelectedLevel() != 1)
00134             gEve->GetSelection()->AddElement(comp);
00135       }
00136       else
00137       {
00138          if (comp->GetSelectedLevel() == 1)
00139             gEve->GetSelection()->RemoveElement(comp);
00140       }
00141    }
00142 }
00143 
00148 void
00149 FWInteractionList::itemChanged()
00150 {   for (size_t i = 0, e = m_item->size(); i < e; ++i)
00151    {
00152        // Assert for sizes is not necessary, becuse it is already in a 
00153       // proxy builder.
00154       TEveElement* comp = m_compounds[i];
00155       
00156       std::string name = m_item->modelName(i);
00157       if (m_item->haveInterestingValue())
00158          name += m_item->modelInterestingValueAsString(i);
00159 
00160       comp->SetElementTitle(name.c_str());
00161 
00162       const FWEventItem::ModelInfo& info = m_item->modelInfo(i);
00163       const FWDisplayProperties &p = info.displayProperties();
00164 
00165       if (p.isVisible() != comp->GetRnrSelf())
00166          comp->EnableListElements(p.isVisible(), p.isVisible());
00167 
00168       if (p.color() != comp->GetMainColor())
00169          comp->SetMainColor(p.color());
00170 
00171       if (p.transparency() != comp->GetMainTransparency())
00172          comp->SetMainTransparency(p.transparency());
00173 
00174    }
00175 }