00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <boost/bind.hpp>
00016
00017
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/FWEveDigitSetScalableMarker.cc"
00025 #include "Fireworks/Core/src/FWPopupMenu.cc"
00026 #include "Fireworks/Core/interface/fwLog.h"
00027
00028 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00029 #include "Fireworks/Core/src/FWValidatorBase.h"
00030 #include "Fireworks/Core/src/FWEveDigitSetScalableMarker.cc"
00031
00032 #include "TEveScene.h"
00033 #include "TEveSceneInfo.h"
00034 #include "TEveWindow.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", 4l, 0l, 10l),
00072 m_extrusionMarkerColor(this, "ExtrusionMarkerColor", 0l, 0l, 20l),
00073 m_overlapMarkerColor(this, "OverlapMarkerColor", 9l, 0l, 20l)
00074 {
00075
00076 TGHorizontalFrame* hp = new TGHorizontalFrame(m_frame);
00077
00078 {
00079 m_viewBox = new FWViewCombo(hp, this);
00080 hp->AddFrame( m_viewBox,new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
00081 }
00082
00083 {
00084 TGTextButton* rb = new TGTextButton (hp, "CdTop");
00085 hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0) );
00086 rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdTop()");
00087 }
00088
00089 {
00090 TGTextButton* rb = new TGTextButton (hp, "CdUp");
00091 hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00092 rb->Connect("Clicked()","FWGeometryTableViewBase",this,"cdUp()");
00093 }
00094 {
00095 hp->AddFrame(new TGLabel(hp, "Precision:"), new TGLayoutHints(kLHintsBottom, 10, 0, 0, 2));
00096 m_numEntry = new TGNumberEntry(hp, m_precision.value(), 5, -1, TGNumberFormat::kNESReal, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, m_precision.min(), m_precision.max());
00097 hp->AddFrame(m_numEntry, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00098 m_numEntry->Connect("ValueSet(Long_t)","FWOverlapTableView",this,"precisionCallback(Long_t)");
00099 }
00100
00101 {
00102 m_listOptionButton = new TGCheckButton(hp,m_listAllNodes.name().c_str());
00103 m_listOptionButton->SetState( m_listAllNodes.value() ? kButtonDown : kButtonUp );
00104 m_listOptionButton->Connect("Clicked()", "FWOverlapTableView", this, "setListAllNodes()");
00105 hp->AddFrame(m_listOptionButton, new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,0,1,1));
00106
00107 }
00108 {
00109 m_applyButton = new TGTextButton (hp, "Apply");
00110 hp->AddFrame( m_applyButton, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
00111 m_applyButton->Connect("Clicked()","FWOverlapTableView",this,"recalculate()");
00112 }
00113
00114 m_frame->AddFrame(hp,new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 4, 2, 2, 0));
00115 m_tableManager = new FWOverlapTableManager(this);
00116
00117
00118
00119 FWGeoTopNodeGLScene *gls = new FWGeoTopNodeGLScene(0);
00120 #if ROOT_VERSION_CODE < ROOT_VERSION(5,32,0)
00121 m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
00122 #else
00123 m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
00124 #endif
00125
00126 gEve->GetScenes()->AddElement(m_eveScene);
00127
00128 m_eveTopNode = new FWEveOverlap(this);
00129 m_eveTopNode->SetElementNameTitle("overlapNode", "opverlapNodetitle");
00130 m_eveTopNode->IncDenyDestroy();
00131 m_eveTopNode->SetPickable(true);
00132 m_eveScene->AddElement(m_eveTopNode);
00133
00134 gls->m_eveTopNode = m_eveTopNode;
00135 m_eveTopNode->m_scene = gls;
00136
00137 m_marker = new FWEveDigitSetScalableMarker();
00138 m_marker->SetMainColor(kRed);
00139 m_marker->IncDenyDestroy();
00140 m_marker->Reset(TEveQuadSet::kQT_FreeQuad, kFALSE, 32);
00141 m_marker->SetOwnIds(kTRUE);
00142 m_marker->SetAlwaysSecSelect(kTRUE);
00143 m_marker->SetPickable(kTRUE);
00144 m_marker->SetOwnIds(kTRUE);
00145
00146
00147 m_drawPoints.changed_.connect(boost::bind(&FWOverlapTableView::drawPoints,this));
00148 m_pointSize.changed_.connect(boost::bind(&FWOverlapTableView::pointSize,this));
00149 m_rnrOverlap.changed_.connect(boost::bind(&FWOverlapTableView::refreshTable3D,this));
00150 m_overlapMarkerColor.changed_.connect(boost::bind(&FWOverlapTableView::refreshTable3D,this));
00151 m_extrusionMarkerColor.changed_.connect(boost::bind(&FWOverlapTableView::refreshTable3D,this));
00152 m_rnrExtrusion.changed_.connect(boost::bind(&FWGeometryTableViewBase::refreshTable3D,this));
00153
00154 postConst();
00155 }
00156
00157
00158
00159 FWOverlapTableView::~FWOverlapTableView()
00160 {
00161 if (m_marker) m_marker->DecDenyDestroy();
00162 }
00163
00164
00165 FWGeometryTableManagerBase* FWOverlapTableView::getTableManager()
00166 {
00167 return m_tableManager;
00168 }
00169
00170
00171 bool FWOverlapTableView::listAllNodes() const
00172 {
00173 return m_listAllNodes.value();
00174 }
00175
00176
00177 void FWOverlapTableView::setListAllNodes()
00178 {
00179 m_listAllNodes.set( m_listOptionButton->IsOn());
00180 refreshTable3D();
00181 }
00182
00183
00184 TEveElement* FWOverlapTableView::getEveGeoElement() const
00185 {
00186 return m_eveTopNode;
00187 }
00188
00189
00190 void FWOverlapTableView::precisionCallback(Long_t )
00191 {
00192
00193 setCheckerState(true);
00194 m_precision.set( m_numEntry->GetNumber());
00195 std::cout << sUpdateMsg;
00196 }
00197
00198
00199 void FWOverlapTableView::recalculate()
00200 {
00201
00202
00203
00204 m_tableManager->importOverlaps(m_path.value(), m_precision.value());
00205 checkExpandLevel();
00206 getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
00207 refreshTable3D();
00208
00209 setCheckerState(false);
00210 }
00211
00212
00213
00214 void FWOverlapTableView::setFrom(const FWConfiguration& iFrom)
00215 {
00216 m_enableRedraw = false;
00217
00218 for (const_iterator it =begin(), itEnd = end(); it != itEnd; ++it)
00219 {
00220 (*it)->setFrom(iFrom);
00221 }
00222
00223 m_viewersConfig = iFrom.valueForKey("Viewers");
00224 m_numEntry->SetNumber(m_precision.value());
00225
00226
00227 m_enableRedraw = true;
00228 recalculate();
00229 }
00230
00231
00232 void FWOverlapTableView::populateController(ViewerParameterGUI& gui) const
00233 {
00234 gui.requestTab("Style").
00235
00236
00237 addParam(&m_rnrOverlap).
00238 addParam(&m_rnrExtrusion).
00239 separator().
00240 addParam(&m_extrusionMarkerColor).
00241 addParam(&m_overlapMarkerColor).
00242 addParam(&m_pointSize);
00243
00244 FWGeometryTableViewBase::populateController(gui);
00245 }
00246
00247
00248 void FWOverlapTableView::drawPoints()
00249 {
00250 m_marker->SetRnrSelf(m_drawPoints.value());
00251 m_marker->ElementChanged();
00252 gEve->Redraw3D();
00253 }
00254
00255
00256 void FWOverlapTableView::pointSize()
00257 {
00258 m_marker->SetMarkerSize(m_pointSize.value());
00259 m_marker->ElementChanged();
00260 gEve->Redraw3D();
00261 }
00262
00263
00264 void FWOverlapTableView::cdUp()
00265 {
00266 setCheckerState(true);
00267 FWGeometryTableViewBase::cdUp();
00268 }
00269
00270 void FWOverlapTableView::cdTop()
00271 {
00272 if (m_topNodeIdx.value() == -1) return;
00273
00274 setCheckerState(true);
00275 FWGeometryTableViewBase::cdTop();
00276 }
00277
00278 void FWOverlapTableView::setCheckerState(bool x)
00279 {
00280 m_runChecker = x;
00281 m_applyButton->SetForegroundColor(x ? 0xff0000 : 0x000000);
00282 gClient->NeedRedraw(m_applyButton);
00283
00284 }
00285
00286
00287 void FWOverlapTableView::chosenItem(int menuIdx)
00288 {
00289
00290
00291 switch (menuIdx) {
00292 case FWGeoTopNode::kPrintOverlap:
00293 {
00294 std::cout << "=============================================================================" << std::endl << std::endl;
00295 m_tableManager->printOverlaps(m_eveTopNode->getFirstSelectedTableIndex());
00296 break;
00297 }
00298 default:
00299 FWGeometryTableViewBase::chosenItem(menuIdx);
00300 }
00301 }
00302
00303
00304 void FWOverlapTableView::refreshTable3D()
00305 {
00306 using namespace TMath;
00307 if (!m_enableRedraw) return;
00308 FWGeometryTableViewBase::refreshTable3D();
00309
00310 for (int i = 0; i < m_marker->GetPlex()->Size(); ++i)
00311 {
00312 FWOverlapTableManager::QuadId* id = (FWOverlapTableManager::QuadId*) m_marker->GetId(i);
00313 TEveQuadSet::QFreeQuad_t* q = (TEveQuadSet::QFreeQuad_t*)m_marker->GetDigit(i);
00314 q->fValue = -1;
00315
00316
00317 bool rnr = false;
00318
00319 for (std::vector<int>::iterator j = id->m_nodes.begin(); j < id->m_nodes.end(); ++j)
00320 {
00321 if ( (id->m_ovl->IsExtrusion() && m_rnrExtrusion.value()) || (id->m_ovl->IsOverlap() && m_rnrOverlap.value()))
00322 {
00323 if (*j == getTopNodeIdx() || m_tableManager->isNodeRendered(*j, getTopNodeIdx() )) {
00324 rnr = true;
00325 break;
00326 }
00327 }
00328 }
00329
00330 if (rnr) {
00331 q->fValue = (id->m_ovl->IsOverlap()) ? m_overlapMarkerColor.value() : m_extrusionMarkerColor.value();
00332 q->fValue += 1000;
00333 }
00334 }
00335
00336 m_marker->ElementChanged();
00337 gEve->FullRedraw3D(false, true);
00338 }