Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:16

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWInteractionList
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Mon Apr 19 12:48:18 CEST 2010
0011 //
0012 
0013 // user include files
0014 #include <cassert>
0015 #include "TEveCompound.h"
0016 #include "TEveManager.h"
0017 #include "TEveSelection.h"
0018 
0019 #include "Fireworks/Core/interface/FWInteractionList.h"
0020 #include "Fireworks/Core/interface/FWEventItem.h"
0021 #include "Fireworks/Core/interface/FWModelIdFromEveSelector.h"
0022 #include "Fireworks/Core/interface/FWModelId.h"
0023 
0024 //
0025 // constants, enums and typedefs
0026 //
0027 
0028 //
0029 // static data member definitions
0030 //
0031 
0032 //
0033 // constructors and destructor
0034 //
0035 FWInteractionList::FWInteractionList(const FWEventItem* item) : m_item(item) {}
0036 
0037 // FWInteractionList::FWInteractionList(const FWInteractionList& rhs)
0038 // {
0039 //    // do actual copying here;
0040 // }
0041 
0042 FWInteractionList::~FWInteractionList() {
0043   for (std::vector<TEveCompound*>::iterator i = m_compounds.begin(); i != m_compounds.end(); ++i) {
0044     // Interaction are created only in the standard use case, where user data is FWFromEveSelectorBase.
0045     // This is defined with return value of virtual function FWPRoxyBuilderBase::willHandleInteraction().
0046 
0047     if ((*i)->GetUserData())
0048       delete reinterpret_cast<FWFromEveSelectorBase*>((*i)->GetUserData());
0049 
0050     (*i)->RemoveElements();
0051     (*i)->DecDenyDestroy();
0052   }
0053 }
0054 
0055 //
0056 // member functions
0057 //
0058 
0059 /** This function is called from FWProxyBuilderBase::build() function (e.g. on next event).
0060     The PB build function creates TEveElement for each element of collection and calls
0061     this function to add the element to "master" element, which is a TEveCompound.
0062 */
0063 void FWInteractionList::added(TEveElement* el, unsigned int idx) {
0064   // In the case a compound for the given index already exists, just add
0065   // the TEveElement to it, otherwise create a new one.
0066   if (idx < m_compounds.size()) {
0067     m_compounds[idx]->AddElement(el);
0068     return;
0069   }
0070 
0071   // Prepare name for the tooltip on mouseover in GL viewer.Value of
0072   // tooltip is TEveElement::fTitle
0073   std::string name = m_item->modelName(idx);
0074   if (m_item->haveInterestingValue())
0075     name += m_item->modelInterestingValueAsString(idx);
0076 
0077   TEveCompound* c = new TEveCompound(name.c_str(), name.c_str());
0078   c->EnableListElements(m_item->defaultDisplayProperties().isVisible());
0079   c->SetMainColor(m_item->defaultDisplayProperties().color());
0080   c->SetMainTransparency(m_item->defaultDisplayProperties().transparency());
0081 
0082   // Set flags to propagat attributes.
0083   c->CSCImplySelectAllChildren();
0084   c->CSCApplyMainColorToAllChildren();
0085   c->CSCApplyMainTransparencyToAllChildren();
0086 
0087   // TEveElement is auto-destroyed if is is not added to any parent. Alternative could
0088   // be to use increase/decrease reference count.
0089   c->IncDenyDestroy();
0090   //  FWModelIdFromEveSelector is needed for interaction from Eve to Fireworks.
0091   //  FWEveViewManager gets ROOT signals with selected objects (TEveCompound)
0092   //  then cals doSelect() on the compound's user data.
0093   c->SetUserData(new FWModelIdFromEveSelector(FWModelId(m_item, idx)));
0094   // Order does not matter. What is added to TEveCompound is not concern of interaction list.
0095   // Interaction list operates ony with the compound.
0096   m_compounds.push_back(c);
0097   m_compounds.back()->AddElement(el);
0098   // printf("%s[%d] FWInteractionList::added has childern %d\n",m_item->name().c_str(), idx,  m_compounds[idx]->NumChildren());
0099 }
0100 
0101 /** This method is called from FWEveViewManager::modelChanges(), which
0102      has modelChanges callback same as all other view maangers.
0103 */
0104 void FWInteractionList::modelChanges(const FWModelIds& iIds) {
0105   assert(m_compounds.size() >= m_item->size());
0106 
0107   for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it) {
0108     const FWEventItem::ModelInfo& info = m_item->modelInfo(it->index());
0109     // std::cout <<" FWInteractionList::modelChanges  color "<< info.displayProperties().color()  << "(*it).index() " <<(*it).index() << "  " << m_item->name() <<std::endl;
0110     const FWDisplayProperties& p = info.displayProperties();
0111     TEveElement* comp = m_compounds[it->index()];
0112     comp->EnableListElements(p.isVisible(), p.isVisible());
0113     comp->SetMainColor(p.color());
0114     comp->SetMainTransparency(p.transparency());
0115 
0116     if (info.isSelected()) {
0117       if (comp->GetSelectedLevel() != 1)
0118         gEve->GetSelection()->AddElement(comp);
0119     } else {
0120       if (comp->GetSelectedLevel() == 1)
0121         gEve->GetSelection()->RemoveElement(comp);
0122     }
0123   }
0124 }
0125 
0126 /**
0127   This method is called from FWEveViewManager::itemChanged(), which is a callback of
0128   signal FWEventItem::itemChanged_.
0129 */
0130 void FWInteractionList::itemChanged() {
0131   for (size_t i = 0, e = m_item->size(); i < e; ++i) {
0132     // Assert for sizes is not necessary, becuse it is already in a
0133     // proxy builder.
0134     TEveElement* comp = m_compounds[i];
0135 
0136     std::string name = m_item->modelName(i);
0137     if (m_item->haveInterestingValue())
0138       name += m_item->modelInterestingValueAsString(i);
0139 
0140     comp->SetElementTitle(name.c_str());
0141 
0142     const FWEventItem::ModelInfo& info = m_item->modelInfo(i);
0143     const FWDisplayProperties& p = info.displayProperties();
0144 
0145     if (p.isVisible() != comp->GetRnrSelf())
0146       comp->EnableListElements(p.isVisible(), p.isVisible());
0147 
0148     if (p.color() != comp->GetMainColor())
0149       comp->SetMainColor(p.color());
0150 
0151     if (p.transparency() != comp->GetMainTransparency())
0152       comp->SetMainTransparency(p.transparency());
0153   }
0154 }