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