CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Fireworks/Core/src/FWViewGeometryList.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWViewGeometryList
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel 
00010 //         Created:  Tue Sep 14 13:28:13 CEST 2010
00011 // $Id: FWViewGeometryList.cc,v 1.6 2011/09/27 04:27:08 amraktad Exp $
00012 //
00013 
00014 #include <boost/bind.hpp>
00015 #include "TEveScene.h"
00016 #include "TEveManager.h"
00017 #include "TEveCompound.h"
00018 
00019 #include "Fireworks/Core/interface/FWViewGeometryList.h"
00020 #include "Fireworks/Core/interface/FWGeometry.h"
00021 #include "Fireworks/Core/interface/Context.h"
00022 
00023 FWViewGeometryList::FWViewGeometryList(const fireworks::Context& context, bool projected):
00024    m_context(context),
00025    m_geom(0),
00026    m_projected(projected)
00027 { 
00028    m_geom = context.getGeom();
00029 
00030    for (int i = 0; i < kFWGeomColorSize; ++i)
00031    {
00032       m_colorComp[i] = new TEveCompound(Form("3D view color compund [%d]", i));
00033       m_colorComp[i]->SetMainColor(m_context.colorManager()->geomColor(FWGeomColorIndex(i)));
00034       m_colorComp[i]->SetMainTransparency(m_context.colorManager()->geomTransparency(m_projected));
00035       m_colorComp[i]->CSCApplyMainColorToAllChildren();
00036       m_colorComp[i]->CSCApplyMainTransparencyToMatchingChildren();
00037    }
00038    m_colorConnection = context.colorManager()->geomColorsHaveChanged_.connect(boost::bind(&FWViewGeometryList::updateColors, this));
00039    m_transpConnection =  context.colorManager()->geomTransparencyHaveChanged_.connect(boost::bind(&FWViewGeometryList::updateTransparency,this,  _1));
00040 }
00041 
00042 FWViewGeometryList::~FWViewGeometryList()
00043 {
00044    m_transpConnection.disconnect();
00045    m_colorConnection.disconnect();
00046    for (int i = 0; i < kFWGeomColorSize; ++i)
00047    {
00048       if (m_colorComp[i]) m_colorComp[i]->Destroy();
00049    }
00050 }
00051 
00052 void
00053 FWViewGeometryList::addToCompound(TEveElement* el, FWGeomColorIndex colIdx ,  bool applyTransp) const
00054 {
00055    el->SetMainColor( m_colorComp[colIdx]->GetMainColor()); 
00056    if (applyTransp) 
00057       el->SetMainTransparency( m_colorComp[colIdx]->GetMainTransparency());  
00058 
00059    el->SetPickable(true); 
00060    m_colorComp[colIdx]->AddElement(el);
00061 }
00062 
00063 void
00064 FWViewGeometryList::updateColors()
00065 { 
00066    //  printf("%p FWViewGeometryList::updateColors projected %d %s \n", this, m_projected, GetElementName());
00067    for (int i = 0; i < kFWGeomColorSize; ++i)
00068    {
00069       m_colorComp[i]->SetMainColor(m_context.colorManager()->geomColor(FWGeomColorIndex(i)));
00070       m_colorComp[i]->SetMainTransparency(m_context.colorManager()->geomTransparency(m_projected));
00071       m_colorComp[i]->ElementChanged();
00072    }
00073 }
00074 
00075 void
00076 FWViewGeometryList::updateTransparency(bool projectedType)
00077 {
00078    //  printf("%p transp [%d]\n", this, iTransp);
00079 
00080    if (projectedType == m_projected)
00081    { 
00082       for (int i = 0; i < kFWGeomColorSize; ++i)
00083       {
00084          m_colorComp[i]->SetMainTransparency(m_context.colorManager()->geomTransparency(projectedType));
00085          m_colorComp[i]->ElementChanged();
00086       }
00087    }
00088 }