CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Fireworks/Core/src/FWGeometryTableManagerBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGeometryTableManagerBase
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel, Matevz Tadel
00010 //         Created:  Thu Jan 27 14:50:57 CET 2011
00011 // $Id: FWGeometryTableManagerBase.cc,v 1.4 2012/02/23 00:50:25 amraktad Exp $
00012 //
00013 
00014 //#define PERFTOOL_GEO_TABLE
00015 
00016 // user include files
00017 #include <iostream>
00018 #include <boost/bind.hpp>
00019 #include <stack>
00020 #ifdef PERFTOOL_GEO_TABLE 
00021 #include <google/profiler.h>
00022 #endif
00023 #include "Fireworks/Core/interface/FWGeometryTableManagerBase.h"
00024 #include "Fireworks/Core/src/FWColorBoxIcon.h"
00025 #include "Fireworks/TableWidget/interface/GlobalContexts.h"
00026 #include "Fireworks/TableWidget/src/FWTabularWidget.h"
00027 #include "Fireworks/Core/interface/fwLog.h"
00028 
00029 #include "TMath.h"
00030 #include "TGeoVolume.h"
00031 #include "TGeoMatrix.h"
00032 #include "TGeoShape.h"
00033 #include "TGeoBBox.h"
00034 #include "TGeoMatrix.h"
00035 
00036 #include "TGFrame.h"
00037 #include "TEveUtil.h"
00038 
00039 
00040 const char* FWGeometryTableManagerBase::NodeInfo::name() const
00041 {
00042    return m_node->GetName();
00043 }
00044 
00045 
00046 FWGeometryTableManagerBase::ColorBoxRenderer::ColorBoxRenderer():
00047    FWTableCellRendererBase(),
00048    m_width(1),
00049    m_height(1),
00050    m_color(0xffffff),
00051    m_isSelected(false)
00052 {
00053    GCValues_t gval; 
00054    gval.fMask       = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle  | kGCGraphicsExposures;
00055    gval.fStipple    = gClient->GetResourcePool()->GetCheckeredBitmap();
00056    gval.fGraphicsExposures = kFALSE;
00057    gval.fBackground = gVirtualX->GetPixel(kGray);
00058    m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval,kTRUE);
00059 
00060 }
00061 
00062 FWGeometryTableManagerBase::ColorBoxRenderer::~ColorBoxRenderer()
00063 {
00064    gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
00065 }
00066 
00067 void FWGeometryTableManagerBase::ColorBoxRenderer::setData(Color_t c, bool s)
00068 {
00069    m_color = gVirtualX->GetPixel(c);
00070    m_isSelected = s;
00071 }
00072 
00073 
00074 void FWGeometryTableManagerBase::ColorBoxRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00075 {
00076    iX -= FWTabularWidget::kTextBuffer;
00077    iY -= FWTabularWidget::kTextBuffer;
00078    iWidth += 2*FWTabularWidget::kTextBuffer;
00079    iHeight += 2*FWTabularWidget::kTextBuffer;
00080 
00081    m_colorContext->SetFillStyle(kFillSolid);
00082    Pixel_t baq =  m_colorContext->GetForeground();
00083    m_colorContext->SetForeground(m_color);
00084    gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
00085 
00086    if (m_isSelected)
00087    {
00088       m_colorContext->SetFillStyle(kFillOpaqueStippled);
00089       gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
00090    }
00091    m_colorContext->SetForeground(baq);
00092 }
00093 
00094 //==============================================================================
00095 //==============================================================================
00096 //
00097 // class FWGeometryTableManagerBase
00098 //
00099 //==============================================================================
00100 //==============================================================================
00101 
00102 FWGeometryTableManagerBase::FWGeometryTableManagerBase()
00103    :   
00104    m_highlightIdx(-1),
00105    m_levelOffset(0)
00106 { 
00107    m_colorBoxRenderer.m_width  =  50;
00108    m_colorBoxRenderer.m_height =  m_renderer.height();
00109 
00110    GCValues_t gval;
00111    gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle  | kGCGraphicsExposures;
00112    gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
00113    gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
00114    gval.fFillStyle  = kFillOpaqueStippled; // kFillTiled;
00115    gval.fStipple    = gClient->GetResourcePool()->GetCheckeredBitmap();
00116    gval.fGraphicsExposures = kFALSE;
00117    m_highlightContext = gClient->GetGC(&gval, kTRUE);
00118 
00119    m_renderer.setHighlightContext( m_highlightContext);
00120 }
00121 
00122 FWGeometryTableManagerBase::~FWGeometryTableManagerBase()
00123 {
00124 }
00125 
00126 
00127 int FWGeometryTableManagerBase::unsortedRowNumber(int unsorted) const
00128 {
00129    return unsorted;
00130 }
00131 
00132 int FWGeometryTableManagerBase::numberOfRows() const 
00133 {
00134    return m_row_to_index.size();
00135 }
00136 
00137 
00138 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const 
00139 {
00140    std::vector<std::string> returnValue;
00141    returnValue.reserve(numberOfColumns());
00142 
00143    returnValue.push_back("Name");
00144    returnValue.push_back("Color");
00145    returnValue.push_back("RnrSelf");
00146    returnValue.push_back("RnrChildren");
00147    returnValue.push_back("Material");
00148    return returnValue;
00149 }
00150  
00151 const std::string FWGeometryTableManagerBase::title() const 
00152 {
00153    return "Geometry";
00154 }
00155 
00156 
00157 void  FWGeometryTableManagerBase::setBackgroundToWhite(bool iToWhite )
00158 {
00159    if(iToWhite) {
00160       m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
00161    } else {
00162       m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
00163    }
00164    m_renderer.setBlackIcon(iToWhite);
00165 }
00166 
00167 //______________________________________________________________________________
00168 bool FWGeometryTableManagerBase::firstColumnClicked(int row, int xPos)
00169 {
00170    if (row == -1)
00171       return false;
00172 
00173    int idx = rowToIndex()[row];
00174    // printf("click %s \n", m_entries[idx].name());
00175 
00176    int off = 0;
00177    if (idx >= 0)
00178       off = (m_entries[idx].m_level - m_levelOffset)* 20;
00179 
00180    //   printf("compare %d %d level %d\n" , xPos, off, idx);
00181    if (xPos >  off &&  xPos < (off + 20))
00182    {
00183       m_entries[idx].switchBit(kExpanded);
00184  
00185       recalculateVisibility();
00186       dataChanged();
00187       visualPropertiesChanged();
00188       return false;
00189    }
00190 
00191    return true;
00192 }
00193 
00194 
00195  
00196 
00197 //______________________________________________________________________________
00198 
00199 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const
00200 {
00201    // utility used by browser and FWGeoNode
00202    //   printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
00203    int pIdx  = data.m_parent;
00204 
00205    while (pIdx > 0)
00206    {
00207       // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
00208       mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
00209       pIdx = m_entries.at(pIdx).m_parent;
00210    }
00211 
00212    //   printf("right %s [%d]\n",data.name(), data.m_level );
00213    mtx.Multiply(data.m_node->GetMatrix());
00214 }
00215 
00216 //______________________________________________________________________________
00217 void FWGeometryTableManagerBase::redrawTable(bool setExpand) 
00218 {
00219    //   std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
00220    if (m_entries.empty()) return;
00221 
00222    //   if (setExpand) checkExpandLevel();
00223 
00224    recalculateVisibility();
00225 
00226 
00227    dataChanged();
00228    visualPropertiesChanged();
00229 }
00230 
00231 
00232 //______________________________________________________________________________
00233 
00234 void FWGeometryTableManagerBase::getNodePath(int idx, std::string& path) const
00235 {
00236    std::vector<std::string> relPath;
00237    while(idx >= 0)
00238    { 
00239       relPath.push_back( m_entries[idx].name());
00240       // printf("push %s \n",m_entries[idx].name() );
00241       idx  =  m_entries[idx].m_parent;
00242    }
00243 
00244    size_t ns = relPath.size();
00245    for (size_t i = 1; i < ns; ++i )
00246    {
00247       path +="/";
00248       path += relPath[ns-i -1];
00249       // printf("push_back add to path %s\n", path.c_str());
00250    }
00251 }
00252