CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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.7 2012/05/10 23:57:52 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 #include "boost/lexical_cast.hpp"
00039 
00040 
00041 const char* FWGeometryTableManagerBase::NodeInfo::name() const
00042 {
00043    return m_node->GetName();
00044 }
00045 
00046 
00047 FWGeometryTableManagerBase::ColorBoxRenderer::ColorBoxRenderer():
00048    FWTableCellRendererBase(),
00049    m_width(1),
00050    m_height(1),
00051    m_color(0xffffff),
00052    m_isSelected(false)
00053 {
00054    GCValues_t gval; 
00055    gval.fMask       = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle  | kGCGraphicsExposures;
00056    gval.fStipple    = gClient->GetResourcePool()->GetCheckeredBitmap();
00057    gval.fGraphicsExposures = kFALSE;
00058    gval.fBackground = gVirtualX->GetPixel(kGray);
00059    m_colorContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gval,kTRUE);
00060 
00061 }
00062 
00063 FWGeometryTableManagerBase::ColorBoxRenderer::~ColorBoxRenderer()
00064 {
00065    gClient->GetResourcePool()->GetGCPool()->FreeGC(m_colorContext->GetGC());
00066 }
00067 
00068 void FWGeometryTableManagerBase::ColorBoxRenderer::setData(Color_t c, bool s)
00069 {
00070    m_color = gVirtualX->GetPixel(c);
00071    m_isSelected = s;
00072 }
00073 
00074 
00075 void FWGeometryTableManagerBase::ColorBoxRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00076 {
00077    iX -= FWTabularWidget::kTextBuffer;
00078    iY -= FWTabularWidget::kTextBuffer;
00079    iWidth += 2*FWTabularWidget::kTextBuffer;
00080    iHeight += 2*FWTabularWidget::kTextBuffer;
00081 
00082    m_colorContext->SetFillStyle(kFillSolid);
00083    Pixel_t baq =  m_colorContext->GetForeground();
00084    m_colorContext->SetForeground(m_color);
00085    gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
00086 
00087    if (m_isSelected)
00088    {
00089       m_colorContext->SetFillStyle(kFillOpaqueStippled);
00090       gVirtualX->FillRectangle(iID, m_colorContext->GetGC(), iX, iY, iWidth, iHeight);
00091    }
00092    m_colorContext->SetForeground(baq);
00093 }
00094 
00095 //==============================================================================
00096 //==============================================================================
00097 //
00098 // class FWGeometryTableManagerBase
00099 //
00100 //==============================================================================
00101 //==============================================================================
00102 
00103 FWGeometryTableManagerBase::FWGeometryTableManagerBase()
00104    :   
00105    m_highlightIdx(-1),
00106    m_levelOffset(0),
00107    m_editor(0),
00108    m_editTransparencyIdx(-1)
00109 { 
00110    m_colorBoxRenderer.m_width  =  50;
00111    m_colorBoxRenderer.m_height =  m_renderer.height();
00112 
00113    GCValues_t gval;
00114    gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle  | kGCGraphicsExposures;
00115    gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
00116    gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
00117    gval.fFillStyle  = kFillOpaqueStippled; // kFillTiled;
00118    gval.fStipple    = gClient->GetResourcePool()->GetCheckeredBitmap();
00119    gval.fGraphicsExposures = kFALSE;
00120    m_highlightContext = gClient->GetGC(&gval, kTRUE);
00121 
00122    m_renderer.setHighlightContext( m_highlightContext);
00123 }
00124 
00125 FWGeometryTableManagerBase::~FWGeometryTableManagerBase()
00126 {
00127 }
00128 
00129 
00130 int FWGeometryTableManagerBase::unsortedRowNumber(int unsorted) const
00131 {
00132    return unsorted;
00133 }
00134 
00135 int FWGeometryTableManagerBase::numberOfRows() const 
00136 {
00137    return m_row_to_index.size();
00138 }
00139 
00140 
00141 std::vector<std::string> FWGeometryTableManagerBase::getTitles() const 
00142 {
00143    std::vector<std::string> returnValue;
00144    returnValue.reserve(numberOfColumns());
00145 
00146    returnValue.push_back("Name");
00147    returnValue.push_back("Color");
00148    returnValue.push_back("Opcty");
00149    returnValue.push_back("RnrSelf");
00150    returnValue.push_back("RnrChildren");
00151    returnValue.push_back("Material");
00152    return returnValue;
00153 }
00154  
00155 const std::string FWGeometryTableManagerBase::title() const 
00156 {
00157    return "Geometry";
00158 }
00159 
00160 
00161 void  FWGeometryTableManagerBase::setBackgroundToWhite(bool iToWhite )
00162 {
00163    if(iToWhite) {
00164       m_renderer.setGraphicsContext(&TGFrame::GetBlackGC());
00165    } else {
00166       m_renderer.setGraphicsContext(&TGFrame::GetWhiteGC());
00167    }
00168    m_renderer.setBlackIcon(iToWhite);
00169 }
00170 
00171 //______________________________________________________________________________
00172 bool FWGeometryTableManagerBase::firstColumnClicked(int row, int xPos)
00173 {
00174    if (row == -1)
00175       return false;
00176 
00177    int idx = rowToIndex()[row];
00178    // printf("click %s \n", m_entries[idx].name());
00179 
00180    int off = 0;
00181    if (idx >= 0)
00182       off = (m_entries[idx].m_level - m_levelOffset)* 20;
00183 
00184    //   printf("compare %d %d level %d\n" , xPos, off, idx);
00185    if (xPos >  off &&  xPos < (off + 20))
00186    {
00187       m_entries[idx].switchBit(kExpanded);
00188  
00189       recalculateVisibility();
00190       dataChanged();
00191       visualPropertiesChanged();
00192       return false;
00193    }
00194 
00195    return true;
00196 }
00197 
00198 
00199  
00200 
00201 //______________________________________________________________________________
00202 
00203 void FWGeometryTableManagerBase::getNodeMatrix(const NodeInfo& data, TGeoHMatrix& mtx) const
00204 {
00205    // utility used by browser and FWGeoNode
00206    //   printf("================ FWGeometryTableManagerBase::getNodeMatri \n");
00207    int pIdx  = data.m_parent;
00208 
00209    while (pIdx > 0)
00210    {
00211       // printf("%s [%d]\n",m_entries.at(pIdx).name(), m_entries.at(pIdx).m_level );
00212       mtx.MultiplyLeft(m_entries.at(pIdx).m_node->GetMatrix());
00213       pIdx = m_entries.at(pIdx).m_parent;
00214    }
00215 
00216    //   printf("right %s [%d]\n",data.name(), data.m_level );
00217    mtx.Multiply(data.m_node->GetMatrix());
00218 }
00219 
00220 //______________________________________________________________________________
00221 void FWGeometryTableManagerBase::redrawTable(bool setExpand) 
00222 {
00223    //   std::cerr << "GeometryTableManagerBase::redrawTable ------------------------------------- \n";
00224    if (m_entries.empty()) return;
00225 
00226    //   if (setExpand) checkExpandLevel();
00227 
00228    recalculateVisibility();
00229 
00230 
00231    dataChanged();
00232    visualPropertiesChanged();
00233 }
00234 
00235 
00236 //______________________________________________________________________________
00237 
00238 void FWGeometryTableManagerBase::getNodePath(int idx, std::string& path) const
00239 {
00240    std::vector<std::string> relPath;
00241    while(idx >= 0)
00242    { 
00243       relPath.push_back( m_entries[idx].name());
00244       // printf("push %s \n",m_entries[idx].name() );
00245       idx  =  m_entries[idx].m_parent;
00246    }
00247 
00248    size_t ns = relPath.size();
00249    for (size_t i = 1; i < ns; ++i )
00250    {
00251       path +="/";
00252       path += relPath[ns-i -1];
00253       // printf("push_back add to path %s\n", path.c_str());
00254    }
00255 }
00256 
00257 //______________________________________________________________________________
00258 
00259 
00260 void FWGeometryTableManagerBase::setCellValueEditor(TGTextEntry *editor)
00261 {
00262    m_editor = editor;
00263    m_renderer.setCellEditor(m_editor);
00264 }
00265 
00266 void FWGeometryTableManagerBase::showEditor(int row)
00267 {
00268    m_editTransparencyIdx = row;
00269    m_editor->UnmapWindow();
00270    m_editor->SetText(Form("%d", 100 - m_entries[row].m_transparency));
00271    m_editor->Resize(40, 17);
00272    m_editor->SetCursorPosition(2);
00273    redrawTable();
00274 }
00275 
00276 
00277 
00278 void FWGeometryTableManagerBase::applyTransparencyFromEditor()
00279 {
00280    if ( m_editTransparencyIdx >= 0)
00281    {
00282       using boost::lexical_cast;
00283       using boost::bad_lexical_cast;
00284       try {
00285          int t = lexical_cast<int>(m_editor->GetText());
00286          if (t > 100 || t < 0 )
00287          {
00288             fwLog(fwlog::kError) << "Transparency must be set in procentage [0-100].";
00289             return;
00290          }
00291          m_entries[m_editTransparencyIdx].m_transparency = 100 - t;
00292          cancelEditor(true);
00293       }
00294       catch (bad_lexical_cast &) {
00295          fwLog(fwlog::kError) << "Bad Lexical cast. Transparency must be set in procentage [0-100].";
00296       }
00297    }
00298 }
00299 
00300 void FWGeometryTableManagerBase::cancelEditor(bool redraw)
00301 {
00302    m_editTransparencyIdx = -1;
00303 
00304    if ( m_editor->IsMapped())
00305    {
00306       m_editor->UnmapWindow(); 
00307       if (redraw) redrawTable();
00308    }
00309 }
00310 
00311 
00312 //------------------------------------------------------------------------------
00313 
00314 void FWGeometryTableManagerBase::setVisibility(NodeInfo& data, bool x)
00315 {
00316    data.setBitVal(kVisNodeSelf, x);
00317 }
00318 
00319 //------------------------------------------------------------------------------
00320 
00321 void FWGeometryTableManagerBase::setVisibilityChld(NodeInfo& data, bool x)
00322 {
00323    data.setBitVal(kVisNodeChld, x);
00324 }
00325 //______________________________________________________________________________
00326 
00327 void FWGeometryTableManagerBase::setDaughtersSelfVisibility(int selectedIdx, bool v)
00328 {
00329    TGeoNode  *parentNode = m_entries[selectedIdx].m_node;
00330    int nD   = parentNode->GetNdaughters();
00331    int dOff = 0;
00332    for (int n = 0; n != nD; ++n)
00333    {
00334       int idx = selectedIdx + 1 + n + dOff;
00335       NodeInfo& data = m_entries[idx];
00336       
00337       setVisibility(data, v);
00338       setVisibilityChld(data, v);
00339       
00340       getNNodesTotal(parentNode->GetDaughter(n), dOff);
00341    }
00342 }
00343 
00344 //------------------------------------------------------------------------------
00345 
00346 bool FWGeometryTableManagerBase::getVisibility(const NodeInfo& data) const
00347 {
00348    return data.testBit(kVisNodeSelf);
00349 }
00350 
00351 bool FWGeometryTableManagerBase::getVisibilityChld(const NodeInfo& data) const
00352 {
00353    return data.testBit(kVisNodeChld);
00354 }
00355 
00356