CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Fireworks/Core/src/FWOverlapTableView.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWOverlapTableView
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  
00010 //         Created:  Wed Jan  4 00:06:35 CET 2012
00011 // $Id: FWOverlapTableView.cc,v 1.12 2012/05/10 21:02:31 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <boost/bind.hpp>
00016 
00017 // user include files
00018 #include "Fireworks/Core/src/FWOverlapTableView.h"
00019 #include "Fireworks/Core/src/FWGeoTopNodeScene.h"
00020 #include "Fireworks/Core/src/FWOverlapTableManager.h"
00021 #include "Fireworks/Core/src/FWEveOverlap.h"
00022 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
00023 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00024 #include "Fireworks/Core/src/FWPopupMenu.cc"
00025 #include "Fireworks/Core/interface/fwLog.h"
00026 
00027 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00028 #include "Fireworks/Core/src/FWValidatorBase.h"
00029 
00030 #include "TEveScene.h"
00031 #include "TEveSceneInfo.h"
00032 #include "TEveWindow.h"
00033 
00034 #include "TEvePointSet.h"
00035 #include "TEveManager.h"
00036 
00037 
00038 #include "TGeoVolume.h"
00039 #include "TGeoMatrix.h"
00040 #include "TGeoShape.h"
00041 #include "TGeoBBox.h"
00042 #include "TGeoMatrix.h"
00043 #include "TGeoManager.h"
00044 
00045 #include "TGLViewer.h"
00046 #include "KeySymbols.h"
00047 #include "TGLabel.h"
00048 #include "TGNumberEntry.h"
00049 #include "TGListBox.h"
00050 #include "TGButton.h"
00051 #include "TEveViewer.h"
00052 #include "TGeoOverlap.h"
00053 #include "TGClient.h"
00054 
00055 static const std::string sUpdateMsg = "Please press Apply button to update overlaps.\n";
00056 
00057 
00058 FWOverlapTableView::FWOverlapTableView(TEveWindowSlot* iParent, FWColorManager* colMng) : 
00059    FWGeometryTableViewBase(iParent, FWViewType::kOverlapTable, colMng),
00060    m_applyButton(0),
00061    m_listOptionButton(0),
00062    m_tableManager(0),
00063    m_numEntry(0),
00064    m_runChecker(true),
00065    m_path(this,"Path:", std::string("/cms:World_1/cms:CMSE_1")),
00066    m_precision(this, "Precision", 0.05, 0.000001, 10),
00067    m_listAllNodes(this, "ListAllNodes", true),
00068    m_rnrOverlap(this, "Overlap", true),
00069    m_rnrExtrusion(this, "Extrusion", true),
00070    m_drawPoints(this, "DrawPoints", true),
00071    m_pointSize(this, "PointSize:", 1l, 0l, 10l)
00072 { 
00073    // top row
00074    TGHorizontalFrame* hp =  new TGHorizontalFrame(m_frame);
00075 
00076    {
00077       m_viewBox = new FWViewCombo(hp, this);
00078       hp->AddFrame( m_viewBox,new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
00079    }
00080 
00081    {
00082       TGTextButton* rb = new TGTextButton (hp, "CdTop");
00083       hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0) );
00084       rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdTop()");
00085    }
00086   
00087    {
00088       TGTextButton* rb = new TGTextButton (hp, "CdUp");
00089       hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00090       rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdUp()");
00091    }
00092    {
00093       hp->AddFrame(new TGLabel(hp, "Precision:"), new TGLayoutHints(kLHintsBottom, 10, 0, 0, 2));
00094       m_numEntry = new TGNumberEntry(hp,  m_precision.value(), 5, -1, TGNumberFormat::kNESReal, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, m_precision.min(), m_precision.max());
00095       hp->AddFrame(m_numEntry, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00096       m_numEntry->Connect("ValueSet(Long_t)","FWOverlapTableView",this,"precisionCallback(Long_t)");
00097    }
00098 
00099    { 
00100       m_listOptionButton  = new TGCheckButton(hp,m_listAllNodes.name().c_str());
00101       m_listOptionButton->SetState( m_listAllNodes.value() ? kButtonDown : kButtonUp );
00102       m_listOptionButton->Connect("Clicked()", "FWOverlapTableView", this, "setListAllNodes()");
00103       hp->AddFrame(m_listOptionButton, new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,0,1,1));
00104 
00105    }
00106    {
00107       m_applyButton = new TGTextButton (hp, "Apply");
00108       hp->AddFrame( m_applyButton, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00109       m_applyButton->Connect("Clicked()","FWOverlapTableView",this,"recalculate()");
00110    }
00111    
00112    m_frame->AddFrame(hp,new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 4, 2, 2, 0));
00113    m_tableManager = new FWOverlapTableManager(this);
00114 
00115    // std::cerr << " FWOverlapTableView::initGeometry \n";
00116   
00117    FWGeoTopNodeGLScene *gls = new FWGeoTopNodeGLScene(0);
00118 #if ROOT_VERSION_CODE < ROOT_VERSION(5,32,0)
00119    m_eveScene  = new  FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
00120 #else
00121    m_eveScene  = new  TEveScene(gls, "TopGeoNodeScene", "");
00122 #endif
00123 
00124    gEve->GetScenes()->AddElement(m_eveScene);
00125 
00126    m_eveTopNode = new  FWEveOverlap(this);
00127    m_eveTopNode->SetElementNameTitle("overlapNode", "opverlapNodetitle");
00128    m_eveTopNode->IncDenyDestroy();
00129    m_eveTopNode->SetPickable(true);
00130    m_eveScene->AddElement(m_eveTopNode);
00131 
00132    gls->m_eveTopNode = m_eveTopNode;
00133    m_eveTopNode->m_scene   = gls;
00134 
00135    m_marker = new TEvePointSet();
00136    m_marker->SetMarkerSize(5);
00137    m_marker->SetMainColor(kRed);
00138    m_marker->IncDenyDestroy();
00139 
00140   
00141    m_drawPoints.changed_.connect(boost::bind(&FWOverlapTableView::drawPoints,this));
00142    m_pointSize.changed_.connect(boost::bind(&FWOverlapTableView::pointSize,this));
00143    m_rnrOverlap.changed_.connect(boost::bind(&FWOverlapTableView::refreshTable3D,this));
00144    m_rnrExtrusion.changed_.connect(boost::bind(&FWGeometryTableViewBase::refreshTable3D,this));
00145   
00146    postConst();
00147 }
00148 //______________________________________________________________________________
00149 
00150 
00151 FWOverlapTableView::~FWOverlapTableView()
00152 {
00153    if (m_marker) m_marker->DecDenyDestroy();
00154 }
00155 
00156 //______________________________________________________________________________
00157 FWGeometryTableManagerBase* FWOverlapTableView::getTableManager()
00158 {
00159    return m_tableManager;
00160 }
00161 
00162 //______________________________________________________________________________
00163 bool FWOverlapTableView::listAllNodes() const
00164 {
00165    return m_listAllNodes.value();
00166 }
00167 
00168 //______________________________________________________________________________
00169 void FWOverlapTableView::setListAllNodes()
00170 {
00171    m_listAllNodes.set( m_listOptionButton->IsOn());
00172    refreshTable3D();
00173 }
00174 //______________________________________________________________________________
00175 
00176 TEveElement* FWOverlapTableView::getEveGeoElement() const
00177 {
00178    return m_eveTopNode;
00179 }
00180 
00181 //______________________________________________________________________________
00182 void FWOverlapTableView::precisionCallback(Long_t )
00183 {
00184    // std::cout << " ----------------------------- PRECISION \n" <<  m_numEntry->GetNumber();
00185    setCheckerState(true);
00186    m_precision.set( m_numEntry->GetNumber());
00187    std::cout << sUpdateMsg;
00188 }
00189 
00190 
00191 void FWOverlapTableView::recalculate()
00192 {
00193    //m_path.set(m_pathEntry->GetText());
00194    //  m_precision.set(m_numEntry->GetNumber());
00195    // std::cout << "                             $$$$ " << m_path.value() << std::endl;
00196    m_tableManager->importOverlaps(m_path.value(), m_precision.value());
00197    checkExpandLevel();
00198    getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
00199    refreshTable3D();
00200 
00201    setCheckerState(false);
00202 }
00203 
00204 
00205 //______________________________________________________________________________
00206 void FWOverlapTableView::setFrom(const FWConfiguration& iFrom)
00207 {
00208    m_enableRedraw = false;
00209 
00210    for (const_iterator it =begin(), itEnd = end(); it != itEnd; ++it)
00211    { 
00212       if ((*it)->name() == m_topNodeIdx.name()  )
00213          setTopNodePathFromConfig(iFrom);
00214       else 
00215          (*it)->setFrom(iFrom);
00216    }  
00217 
00218    m_viewersConfig = iFrom.valueForKey("Viewers");
00219    m_numEntry->SetNumber(m_precision.value());
00220   
00221    //  refreshTable3D();
00222    m_enableRedraw = true;
00223    recalculate();
00224 }
00225 
00226 //______________________________________________________________________________
00227 void FWOverlapTableView::populateController(ViewerParameterGUI& gui) const
00228 {
00229    gui.requestTab("Style").
00230       // addParam(&m_enableHighlight).
00231       // separator().
00232       addParam(&m_rnrOverlap).
00233       addParam(&m_rnrExtrusion).
00234       separator().
00235       addParam(&m_drawPoints).
00236       addParam(&m_pointSize);
00237    
00238    FWGeometryTableViewBase::populateController(gui);
00239 }
00240 
00241 //______________________________________________________________________________
00242 void FWOverlapTableView::drawPoints()
00243 {
00244    m_marker->SetRnrSelf(m_drawPoints.value());
00245    m_marker->ElementChanged();
00246    gEve->Redraw3D();
00247 }
00248 
00249 //______________________________________________________________________________
00250 void FWOverlapTableView::pointSize()
00251 {
00252    m_marker->SetMarkerSize(m_pointSize.value());
00253    m_marker->ElementChanged();
00254    gEve->Redraw3D();
00255 }
00256 
00257 //______________________________________________________________________________
00258 void FWOverlapTableView::cdUp()
00259 {
00260    setCheckerState(true);
00261    FWGeometryTableViewBase::cdUp();
00262 }
00263 //______________________________________________________________________________
00264 void FWOverlapTableView::cdTop()
00265 {
00266    if (m_topNodeIdx.value() == -1) return;
00267 
00268    setCheckerState(true);
00269    FWGeometryTableViewBase::cdTop();
00270 }
00271 //______________________________________________________________________________
00272 void FWOverlapTableView::setCheckerState(bool x)
00273 {
00274    m_runChecker = x;
00275    m_applyButton->SetForegroundColor(x ? 0xff0000 : 0x000000);
00276    gClient->NeedRedraw(m_applyButton);
00277 
00278 }
00279 //______________________________________________________________________________
00280 
00281 void FWOverlapTableView::chosenItem(int menuIdx)
00282 {
00283    // printf(" FWOverlapTableView::chosenItem chosen item %s \n", ni->name());
00284    
00285    switch (menuIdx) {
00286       case FWGeoTopNode::kPrintOverlap:
00287       {
00288          std::cout << "=============================================================================" <<  std::endl << std::endl;
00289          m_tableManager->printOverlaps(m_eveTopNode->getFirstSelectedTableIndex());
00290          break;
00291       }
00292       default:
00293          FWGeometryTableViewBase::chosenItem(menuIdx);
00294    }
00295 }
00296 
00297 //______________________________________________________________________________
00298 void FWOverlapTableView::refreshTable3D()
00299 {
00300    using namespace TMath;
00301    if (!m_enableRedraw) return;
00302    FWGeometryTableViewBase::refreshTable3D();
00303   
00304    std::vector<float> pnts;
00305    int cnt = 0;
00306   
00307    //   std::cout << "WOverlapTableView::refreshTable3D() "<< std::endl;
00308    int n0 =  getTopNodeIdx();
00309    int nd = 0; 
00310     m_tableManager->getNNodesTotal(m_tableManager->refEntries().at(n0).m_node, nd);
00311    int n1 = n0+nd; 
00312    //  printf("marker rnf %d %d \n", n0, n1);
00313    if (m_drawPoints.value()) {
00314       for (std::vector<int>::iterator i = m_markerIndices.begin(); i!=m_markerIndices.end(); i++, cnt+=3)
00315       {
00316          if (Abs(*i) >= n0 && Abs(*i) <= n1)
00317          {
00318             FWGeometryTableManagerBase::NodeInfo& data = m_tableManager->refEntries().at(Abs(*i));
00319             if ( data.testBit(FWOverlapTableManager::kVisMarker)  && 
00320                  ( (( *i > 0 ) && m_rnrOverlap.value()) ||  ((*i < 0) && m_rnrExtrusion.value()) )) 
00321             {
00322                pnts.push_back(m_markerVertices[cnt]);
00323                pnts.push_back(m_markerVertices[cnt+1]);
00324                pnts.push_back(m_markerVertices[cnt+2]);
00325             }
00326          }
00327       } 
00328    }
00329   
00330    m_marker->SetPolyMarker(int(pnts.size()/3), &pnts[0], 4);
00331    m_marker->ElementChanged();
00332    gEve->FullRedraw3D(false, true);
00333 }