Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-17 23:10:45

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWOverlapTableView
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:
0010 //         Created:  Wed Jan  4 00:06:35 CET 2012
0011 //
0012 
0013 // system include files
0014 #include <functional>
0015 
0016 // user include files
0017 #include "Fireworks/Core/src/FWOverlapTableView.h"
0018 #include "Fireworks/Core/src/FWGeoTopNodeScene.h"
0019 #include "Fireworks/Core/src/FWOverlapTableManager.h"
0020 #include "Fireworks/Core/src/FWEveOverlap.h"
0021 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
0022 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0023 #include "Fireworks/Core/src/FWPopupMenu.cc"
0024 #include "Fireworks/Core/interface/fwLog.h"
0025 
0026 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
0027 #include "Fireworks/Core/interface/FWValidatorBase.h"
0028 #include "Fireworks/Core/src/FWEveDigitSetScalableMarker.h"
0029 
0030 #include "TEveScene.h"
0031 #include "TEveSceneInfo.h"
0032 #include "TEveWindow.h"
0033 #include "TEveManager.h"
0034 
0035 #include "TGeoVolume.h"
0036 #include "TGeoMatrix.h"
0037 #include "TGeoShape.h"
0038 #include "TGeoBBox.h"
0039 #include "TGeoMatrix.h"
0040 #include "TGeoManager.h"
0041 
0042 #include "TGLViewer.h"
0043 #include "KeySymbols.h"
0044 #include "TGLabel.h"
0045 #include "TGNumberEntry.h"
0046 #include "TGListBox.h"
0047 #include "TGButton.h"
0048 #include "TEveViewer.h"
0049 #include "TGeoOverlap.h"
0050 #include "TGClient.h"
0051 
0052 static const std::string sUpdateMsg = "Please press Apply button to update overlaps.\n";
0053 
0054 FWOverlapTableView::FWOverlapTableView(TEveWindowSlot* iParent, FWColorManager* colMng)
0055     : FWGeometryTableViewBase(iParent, FWViewType::kOverlapTable, colMng),
0056       m_applyButton(nullptr),
0057       m_listOptionButton(nullptr),
0058       m_tableManager(nullptr),
0059       m_numEntry(nullptr),
0060       m_runChecker(true),
0061       m_path(this, "Path:", std::string("/cms:World_1/cms:CMSE_1")),
0062       m_precision(this, "Precision", 0.05, 0.000001, 10),
0063       m_listAllNodes(this, "ListAllNodes", true),
0064       m_rnrOverlap(this, "Overlap", true),
0065       m_rnrExtrusion(this, "Extrusion", true),
0066       m_drawPoints(this, "DrawPoints", true),
0067       m_pointSize(this, "PointSize", 4l, 0l, 10l),
0068       m_extrusionMarkerColor(this, "ExtrusionMarkerColor", 0l, 0l, 20l),
0069       m_overlapMarkerColor(this, "OverlapMarkerColor", 9l, 0l, 20l) {
0070   // top row
0071   TGHorizontalFrame* hp = new TGHorizontalFrame(m_frame);
0072 
0073   {
0074     m_viewBox = new FWViewCombo(hp, this);
0075     hp->AddFrame(m_viewBox, new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
0076   }
0077 
0078   {
0079     TGTextButton* rb = new TGTextButton(hp, "CdTop");
0080     hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0081     rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdTop()");
0082   }
0083 
0084   {
0085     TGTextButton* rb = new TGTextButton(hp, "CdUp");
0086     hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0087     rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdUp()");
0088   }
0089   {
0090     hp->AddFrame(new TGLabel(hp, "Precision:"), new TGLayoutHints(kLHintsBottom, 10, 0, 0, 2));
0091     m_numEntry = new TGNumberEntry(hp,
0092                                    m_precision.value(),
0093                                    5,
0094                                    -1,
0095                                    TGNumberFormat::kNESReal,
0096                                    TGNumberFormat::kNEAAnyNumber,
0097                                    TGNumberFormat::kNELLimitMinMax,
0098                                    m_precision.min(),
0099                                    m_precision.max());
0100     hp->AddFrame(m_numEntry, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0101     m_numEntry->Connect("ValueSet(Long_t)", "FWOverlapTableView", this, "precisionCallback(Long_t)");
0102   }
0103 
0104   {
0105     m_listOptionButton = new TGCheckButton(hp, m_listAllNodes.name().c_str());
0106     m_listOptionButton->SetState(m_listAllNodes.value() ? kButtonDown : kButtonUp);
0107     m_listOptionButton->Connect("Clicked()", "FWOverlapTableView", this, "setListAllNodes()");
0108     hp->AddFrame(m_listOptionButton, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 0, 1, 1));
0109   }
0110   {
0111     m_applyButton = new TGTextButton(hp, "Apply");
0112     hp->AddFrame(m_applyButton, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0113     m_applyButton->Connect("Clicked()", "FWOverlapTableView", this, "recalculate()");
0114   }
0115 
0116   m_frame->AddFrame(hp, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 4, 2, 2, 0));
0117   m_tableManager = new FWOverlapTableManager(this);
0118 
0119   // std::cerr << " FWOverlapTableView::initGeometry \n";
0120 
0121   FWGeoTopNodeGLScene* gls = new FWGeoTopNodeGLScene(nullptr);
0122 #if ROOT_VERSION_CODE < ROOT_VERSION(5, 32, 0)
0123   m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
0124 #else
0125   m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
0126 #endif
0127 
0128   gEve->GetScenes()->AddElement(m_eveScene);
0129 
0130   m_eveTopNode = new FWEveOverlap(this);
0131   m_eveTopNode->SetElementNameTitle("overlapNode", "opverlapNodetitle");
0132   m_eveTopNode->IncDenyDestroy();
0133   m_eveTopNode->SetPickable(true);
0134   m_eveScene->AddElement(m_eveTopNode);
0135 
0136   gls->m_eveTopNode = m_eveTopNode;
0137   m_eveTopNode->m_scene = gls;
0138 
0139   m_marker = new FWEveDigitSetScalableMarker();
0140   m_marker->SetMainColor(kRed);
0141   m_marker->IncDenyDestroy();
0142   m_marker->Reset(TEveQuadSet::kQT_FreeQuad, kFALSE, 32);
0143   m_marker->SetOwnIds(kTRUE);
0144   m_marker->SetAlwaysSecSelect(kTRUE);
0145   m_marker->SetPickable(kTRUE);
0146   m_marker->SetOwnIds(kTRUE);
0147 
0148   m_drawPoints.changed_.connect(std::bind(&FWOverlapTableView::drawPoints, this));
0149   m_pointSize.changed_.connect(std::bind(&FWOverlapTableView::pointSize, this));
0150   m_rnrOverlap.changed_.connect(std::bind(&FWOverlapTableView::refreshTable3D, this));
0151   m_overlapMarkerColor.changed_.connect(std::bind(&FWOverlapTableView::refreshTable3D, this));
0152   m_extrusionMarkerColor.changed_.connect(std::bind(&FWOverlapTableView::refreshTable3D, this));
0153   m_rnrExtrusion.changed_.connect(std::bind(&FWGeometryTableViewBase::refreshTable3D, this));
0154 
0155   postConst();
0156 }
0157 //______________________________________________________________________________
0158 
0159 FWOverlapTableView::~FWOverlapTableView() {
0160   if (m_marker)
0161     m_marker->DecDenyDestroy();
0162 }
0163 
0164 //______________________________________________________________________________
0165 FWGeometryTableManagerBase* FWOverlapTableView::getTableManager() { return m_tableManager; }
0166 
0167 //______________________________________________________________________________
0168 bool FWOverlapTableView::listAllNodes() const { return m_listAllNodes.value(); }
0169 
0170 //______________________________________________________________________________
0171 void FWOverlapTableView::setListAllNodes() {
0172   m_listAllNodes.set(m_listOptionButton->IsOn());
0173   refreshTable3D();
0174 }
0175 //______________________________________________________________________________
0176 
0177 TEveElement* FWOverlapTableView::getEveGeoElement() const { return m_eveTopNode; }
0178 
0179 //______________________________________________________________________________
0180 void FWOverlapTableView::precisionCallback(Long_t) {
0181   // std::cout << " ----------------------------- PRECISION \n" <<  m_numEntry->GetNumber();
0182   setCheckerState(true);
0183   m_precision.set(m_numEntry->GetNumber());
0184   std::cout << sUpdateMsg;
0185 }
0186 
0187 void FWOverlapTableView::recalculate() {
0188   //m_path.set(m_pathEntry->GetText());
0189   //  m_precision.set(m_numEntry->GetNumber());
0190   // std::cout << "                             $$$$ " << m_path.value() << std::endl;
0191   m_tableManager->importOverlaps(m_path.value(), m_precision.value());
0192   checkExpandLevel();
0193   getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
0194   refreshTable3D();
0195 
0196   setCheckerState(false);
0197 }
0198 
0199 //______________________________________________________________________________
0200 void FWOverlapTableView::setFrom(const FWConfiguration& iFrom) {
0201   m_enableRedraw = false;
0202 
0203   for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
0204     (*it)->setFrom(iFrom);
0205   }
0206 
0207   m_viewersConfig = iFrom.valueForKey("Viewers");
0208   m_numEntry->SetNumber(m_precision.value());
0209 
0210   //  refreshTable3D();
0211   m_enableRedraw = true;
0212   recalculate();
0213 }
0214 
0215 //______________________________________________________________________________
0216 void FWOverlapTableView::populateController(ViewerParameterGUI& gui) const {
0217   gui.requestTab("Style")
0218       .
0219       // addParam(&m_enableHighlight).
0220       // separator().
0221       addParam(&m_rnrOverlap)
0222       .addParam(&m_rnrExtrusion)
0223       .separator()
0224       .addParam(&m_extrusionMarkerColor)
0225       .addParam(&m_overlapMarkerColor)
0226       .addParam(&m_pointSize);
0227 
0228   FWGeometryTableViewBase::populateController(gui);
0229 }
0230 
0231 //______________________________________________________________________________
0232 void FWOverlapTableView::drawPoints() {
0233   m_marker->SetRnrSelf(m_drawPoints.value());
0234   m_marker->ElementChanged();
0235   gEve->Redraw3D();
0236 }
0237 
0238 //______________________________________________________________________________
0239 void FWOverlapTableView::pointSize() {
0240   m_marker->SetMarkerSize(m_pointSize.value());
0241   m_marker->ElementChanged();
0242   gEve->Redraw3D();
0243 }
0244 
0245 //______________________________________________________________________________
0246 void FWOverlapTableView::cdUp() {
0247   setCheckerState(true);
0248   FWGeometryTableViewBase::cdUp();
0249 }
0250 //______________________________________________________________________________
0251 void FWOverlapTableView::cdTop() {
0252   if (m_topNodeIdx.value() == -1)
0253     return;
0254 
0255   setCheckerState(true);
0256   FWGeometryTableViewBase::cdTop();
0257 }
0258 //______________________________________________________________________________
0259 void FWOverlapTableView::setCheckerState(bool x) {
0260   m_runChecker = x;
0261   m_applyButton->SetForegroundColor(x ? 0xff0000 : 0x000000);
0262   gClient->NeedRedraw(m_applyButton);
0263 }
0264 //______________________________________________________________________________
0265 
0266 void FWOverlapTableView::chosenItem(int menuIdx) {
0267   // printf(" FWOverlapTableView::chosenItem chosen item %s \n", ni->name());
0268 
0269   switch (menuIdx) {
0270     case FWGeoTopNode::kPrintOverlap: {
0271       std::cout << "=============================================================================" << std::endl
0272                 << std::endl;
0273       m_tableManager->printOverlaps(m_eveTopNode->getFirstSelectedTableIndex());
0274       break;
0275     }
0276     default:
0277       FWGeometryTableViewBase::chosenItem(menuIdx);
0278   }
0279 }
0280 
0281 //______________________________________________________________________________
0282 void FWOverlapTableView::refreshTable3D() {
0283   using namespace TMath;
0284   if (!m_enableRedraw)
0285     return;
0286   FWGeometryTableViewBase::refreshTable3D();
0287 
0288   for (int i = 0; i < m_marker->GetPlex()->Size(); ++i) {
0289     FWOverlapTableManager::QuadId* id = (FWOverlapTableManager::QuadId*)m_marker->GetId(i);
0290     TEveQuadSet::QFreeQuad_t* q = (TEveQuadSet::QFreeQuad_t*)m_marker->GetDigit(i);
0291     q->fValue = -1;
0292 
0293     // check if any of the overlaping nodes is visible -> is in the subtree
0294     bool rnr = false;
0295 
0296     for (std::vector<int>::iterator j = id->m_nodes.begin(); j < id->m_nodes.end(); ++j) {
0297       if ((id->m_ovl->IsExtrusion() && m_rnrExtrusion.value()) || (id->m_ovl->IsOverlap() && m_rnrOverlap.value())) {
0298         if (*j == getTopNodeIdx() || m_tableManager->isNodeRendered(*j, getTopNodeIdx())) {
0299           rnr = true;
0300           break;
0301         }
0302       }
0303     }
0304 
0305     if (rnr) {
0306       q->fValue = (id->m_ovl->IsOverlap()) ? m_overlapMarkerColor.value() : m_extrusionMarkerColor.value();
0307       q->fValue += 1000;
0308     }
0309   }
0310 
0311   m_marker->ElementChanged();
0312   gEve->FullRedraw3D(false, true);
0313 }