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/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
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
00116
00117 FWGeoTopNodeGLScene *gls = new FWGeoTopNodeGLScene(0);
00118 m_eveScene = new TEveScene(gls, "OverlapScene", "");
00119 gEve->GetScenes()->AddElement(m_eveScene);
00120
00121 m_eveTopNode = new FWEveOverlap(this);
00122 m_eveTopNode->SetElementNameTitle("overlapNode", "opverlapNodetitle");
00123 m_eveTopNode->IncDenyDestroy();
00124 m_eveTopNode->SetPickable(true);
00125 m_eveScene->AddElement(m_eveTopNode);
00126
00127 gls->fTopNodeJebo = m_eveTopNode;
00128 m_eveTopNode->fSceneJebo = gls;
00129
00130 m_marker = new TEvePointSet();
00131 m_marker->SetMarkerSize(5);
00132 m_marker->SetMainColor(kRed);
00133 m_marker->IncDenyDestroy();
00134
00135
00136 m_drawPoints.changed_.connect(boost::bind(&FWOverlapTableView::drawPoints,this));
00137 m_pointSize.changed_.connect(boost::bind(&FWOverlapTableView::pointSize,this));
00138 m_rnrOverlap.changed_.connect(boost::bind(&FWOverlapTableView::refreshTable3D,this));
00139 m_rnrExtrusion.changed_.connect(boost::bind(&FWGeometryTableViewBase::refreshTable3D,this));
00140
00141 postConst();
00142 }
00143
00144
00145
00146 FWOverlapTableView::~FWOverlapTableView()
00147 {
00148 if (m_marker) m_marker->DecDenyDestroy();
00149 }
00150
00151
00152 FWGeometryTableManagerBase* FWOverlapTableView::getTableManager()
00153 {
00154 return m_tableManager;
00155 }
00156
00157
00158 bool FWOverlapTableView::listAllNodes() const
00159 {
00160 return m_listAllNodes.value();
00161 }
00162
00163
00164 void FWOverlapTableView::setListAllNodes()
00165 {
00166 m_listAllNodes.set( m_listOptionButton->IsOn());
00167 refreshTable3D();
00168 }
00169
00170
00171 TEveElement* FWOverlapTableView::getEveGeoElement() const
00172 {
00173 return m_eveTopNode;
00174 }
00175
00176
00177 void FWOverlapTableView::precisionCallback(Long_t )
00178 {
00179
00180 setCheckerState(true);
00181 m_precision.set( m_numEntry->GetNumber());
00182 std::cout << sUpdateMsg;
00183 }
00184
00185
00186 void FWOverlapTableView::recalculate()
00187 {
00188
00189
00190
00191 m_tableManager->importOverlaps(m_path.value(), m_precision.value());
00192 checkExpandLevel();
00193 getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
00194 refreshTable3D();
00195
00196 setCheckerState(false);
00197 }
00198
00199
00200
00201 void FWOverlapTableView::setFrom(const FWConfiguration& iFrom)
00202 {
00203 m_enableRedraw = false;
00204 for(const_iterator it =begin(), itEnd = end();
00205 it != itEnd;
00206 ++it) {
00207 (*it)->setFrom(iFrom);
00208
00209 }
00210 m_viewersConfig = iFrom.valueForKey("Viewers");
00211 m_numEntry->SetNumber(m_precision.value());
00212
00213
00214
00215 m_enableRedraw = true;
00216 recalculate();
00217 }
00218
00219
00220 void FWOverlapTableView::populateController(ViewerParameterGUI& gui) const
00221 {
00222 gui.requestTab("Style").
00223
00224
00225 addParam(&m_rnrOverlap).
00226 addParam(&m_rnrExtrusion).
00227 separator().
00228 addParam(&m_drawPoints).
00229 addParam(&m_pointSize);
00230 }
00231
00232
00233 void FWOverlapTableView::drawPoints()
00234 {
00235 m_marker->SetRnrSelf(m_drawPoints.value());
00236 m_marker->ElementChanged();
00237 gEve->Redraw3D();
00238 }
00239
00240
00241 void FWOverlapTableView::pointSize()
00242 {
00243 m_marker->SetMarkerSize(m_pointSize.value());
00244 m_marker->ElementChanged();
00245 gEve->Redraw3D();
00246 }
00247
00248
00249 void FWOverlapTableView::cdUp()
00250 {
00251 setCheckerState(true);
00252 FWGeometryTableViewBase::cdUp();
00253 }
00254
00255 void FWOverlapTableView::cdTop()
00256 {
00257 if (m_topNodeIdx.value() == -1) return;
00258
00259 setCheckerState(true);
00260 FWGeometryTableViewBase::cdTop();
00261 }
00262
00263 void FWOverlapTableView::setCheckerState(bool x)
00264 {
00265 m_runChecker = x;
00266 m_applyButton->SetForegroundColor(x ? 0xff0000 : 0x000000);
00267 gClient->NeedRedraw(m_applyButton);
00268
00269 }
00270
00271
00272 void FWOverlapTableView::chosenItem(int menuIdx)
00273 {
00274 int selectedIdx = m_eveTopNode->getFirstSelectedTableIndex();
00275 FWGeometryTableManagerBase::NodeInfo& ni = getTableManager()->refEntry(m_eveTopNode->getFirstSelectedTableIndex());
00276
00277
00278
00279 TGeoVolume* gv = ni.m_node->GetVolume();
00280 bool resetHome = false;
00281 if (gv)
00282 {
00283 switch (menuIdx) {
00284 case FWEveOverlap::kOvlDaugtersVisOff:
00285 m_tableManager->setDaughtersSelfVisibility(selectedIdx, false);
00286 refreshTable3D();
00287 break;
00288 case FWEveOverlap::kOvlDaugtersVisOn:
00289 m_tableManager->setDaughtersSelfVisibility(selectedIdx, true);
00290 refreshTable3D();
00291 break;
00292
00293 case FWEveOverlap::kOvlSetTopNode:
00294 if (m_topNodeIdx.value() > selectedIdx )
00295 {
00296 cdNode(m_eveTopNode->getFirstSelectedTableIndex());
00297 }
00298 else
00299 {
00300 cdNode(m_eveTopNode->getFirstSelectedTableIndex());
00301 std::cout << sUpdateMsg;
00302 }
00303 break;
00304
00305
00306
00307
00308
00309
00310
00311 ;
00312 case FWEveOverlap::kOvlCamera:
00313 {
00314 TGeoHMatrix mtx;
00315 getTableManager()->getNodeMatrix( ni, mtx);
00316
00317 static double pnt[3];
00318 TGeoBBox* bb = static_cast<TGeoBBox*>( ni.m_node->GetVolume()->GetShape());
00319 const double* origin = bb->GetOrigin();
00320 mtx.LocalToMaster(origin, pnt);
00321
00322 TEveElementList* vl = gEve->GetViewers();
00323 for (TEveElement::List_i it = vl->BeginChildren(); it != vl->EndChildren(); ++it)
00324 {
00325 TEveViewer* v = ((TEveViewer*)(*it));
00326 TString name = v->GetElementName();
00327 if (name.Contains("3D"))
00328 {
00329 v->GetGLViewer()->SetDrawCameraCenter(true);
00330 TGLCamera& cam = v->GetGLViewer()->CurrentCamera();
00331 cam.SetExternalCenter(true);
00332 cam.SetCenterVec(pnt[0], pnt[1], pnt[2]);
00333 }
00334 }
00335 if (resetHome) gEve->FullRedraw3D(true, true);
00336 break;
00337 }
00338 case FWEveOverlap::kOvlPrintOvl:
00339 {
00340 std::cout << "=============================================================================" << std::endl << std::endl;
00341 m_tableManager->printOverlaps(m_eveTopNode->getFirstSelectedTableIndex());
00342 break;
00343 }
00344 case FWEveOverlap::kOvlPrintPath:
00345 {
00346
00347 std::cout << "\npath: "<< ni.m_node->GetTitle() << std::endl;
00348
00349 }
00350 }
00351 }
00352 refreshTable3D();
00353 }
00354
00355
00356 void FWOverlapTableView::refreshTable3D()
00357 {
00358 using namespace TMath;
00359 if (!m_enableRedraw) return;
00360 FWGeometryTableViewBase::refreshTable3D();
00361
00362 std::vector<float> pnts;
00363 int cnt = 0;
00364
00365
00366 int n0 = getTopNodeIdx();
00367 int nd = 0;
00368 m_tableManager->getNNodesTotal(m_tableManager->refEntries().at(n0).m_node, nd);
00369 int n1 = n0+nd;
00370
00371 if (m_drawPoints.value()) {
00372 for (std::vector<int>::iterator i = m_markerIndices.begin(); i!=m_markerIndices.end(); i++, cnt+=3)
00373 {
00374 if (Abs(*i) >= n0 && Abs(*i) <= n1)
00375 {
00376 FWGeometryTableManagerBase::NodeInfo& data = m_tableManager->refEntries().at(Abs(*i));
00377 if ( data.testBit(FWOverlapTableManager::kVisMarker) &&
00378 ( (( *i > 0 ) && m_rnrOverlap.value()) || ((*i < 0) && m_rnrExtrusion.value()) ))
00379 {
00380 pnts.push_back(m_markerVertices[cnt]);
00381 pnts.push_back(m_markerVertices[cnt+1]);
00382 pnts.push_back(m_markerVertices[cnt+2]);
00383 }
00384 }
00385 }
00386 }
00387
00388 m_marker->SetPolyMarker(int(pnts.size()/3), &pnts[0], 4);
00389 m_marker->ElementChanged();
00390 gEve->FullRedraw3D(false, true);
00391 }