00001 #include <iostream>
00002
00003 #include <boost/bind.hpp>
00004 #include <boost/regex.hpp>
00005
00006 #include "Fireworks/Core/interface/FWGeometryTableViewBase.h"
00007 #include "Fireworks/Core/interface/FWGeoTopNode.h"
00008 #include "Fireworks/Core/interface/fwLog.h"
00009 #include "Fireworks/Core/interface/FWGeometryTableManagerBase.h"
00010 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00011 #include "Fireworks/Core/interface/FWGUIManager.h"
00012 #include "Fireworks/Core/interface/FWColorManager.h"
00013 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00014 #include "Fireworks/Core/src/FWColorSelect.h"
00015 #include "Fireworks/Core/src/FWPopupMenu.cc"
00016 #include "Fireworks/Core/src/FWGeoTopNodeScene.h"
00017
00018 #include "TGFileDialog.h"
00019 #include "TGeoNode.h"
00020 #include "TGeoMatrix.h"
00021 #include "TGStatusBar.h"
00022 #include "TGButton.h"
00023 #include "TGLabel.h"
00024 #include "TGLPhysicalShape.h"
00025 #include "TGMenu.h"
00026 #include "TGComboBox.h"
00027
00028 #include "TEvePointSet.h"
00029 #include "TGeoShape.h"
00030 #include "TGeoBBox.h"
00031 #include "TEveManager.h"
00032 #include "TEveGeoNode.h"
00033 #include "TEveScene.h"
00034 #include "TEveSceneInfo.h"
00035 #include "TEveViewer.h"
00036 #include "TGLViewer.h"
00037 #include "TGLCamera.h"
00038 #include "TEveSelection.h"
00039 #ifdef PERFTOOL_BROWSER
00040 #include <google/profiler.h>
00041 #endif
00042
00043
00044
00045
00046
00047
00048
00049
00050 Bool_t FWGeometryTableViewBase::FWViewCombo::HandleButton(Event_t* event)
00051 {
00052 if (event->fType == kButtonPress)
00053 {
00054 bool map = false;
00055
00056 FWPopupMenu* m_viewPopup = new FWPopupMenu(0);
00057
00058 TEveElementList* views = gEve->GetViewers();
00059 int idx = 0;
00060
00061 for (TEveElement::List_i it = views->BeginChildren(); it != views->EndChildren(); ++it)
00062 {
00063 TEveViewer* v = ((TEveViewer*)(*it));
00064 if (strstr( v->GetElementName(), "3D") )
00065 {
00066 bool added = false;
00067 m_viewPopup->AddEntry(v->GetElementName(), idx);
00068
00069 for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
00070 {
00071 TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
00072 if (m_el && s->HasChildren() && s->FirstChild() == m_el) {
00073 added = true;
00074 break;
00075 }
00076 }
00077 map = true;
00078 if (added)
00079 m_viewPopup->CheckEntry(idx);
00080 }
00081 ++idx;
00082 }
00083
00084 if (map) {
00085
00086 Window_t wdummy;
00087 Int_t ax,ay;
00088 gVirtualX->TranslateCoordinates(GetId(),
00089 gClient->GetDefaultRoot()->GetId(),
00090 event->fX, event->fY,
00091 ax,ay,
00092 wdummy);
00093
00094
00095 m_viewPopup->PlaceMenu(ax, ay, true,true);
00096 m_viewPopup->Connect("Activated(Int_t)",
00097 "FWGeometryTableViewBase",
00098 const_cast<FWGeometryTableViewBase*>(m_tableView),
00099 "selectView(Int_t)");
00100 }
00101 else
00102 {
00103 fwLog(fwlog::kInfo) << "No 3D View added. \n";
00104 }
00105 }
00106 return true;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 FWGeometryTableViewBase::FWGeometryTableViewBase(TEveWindowSlot* iParent,FWViewType::EType type, FWColorManager* colMng )
00116 : FWViewBase(type),
00117 m_topNodeIdx(this, "TopNodeIndex", -1l, 0, 1e7),
00118 m_autoExpand(this,"ExpandList:", 1l, 0l, 100l),
00119 m_enableHighlight(this,"EnableHighlight", true),
00120 m_colorManager(colMng),
00121 m_colorPopup(0),
00122 m_eveWindow(0),
00123 m_frame(0),
00124 m_viewBox(0),
00125 m_viewersConfig(0),
00126 m_enableRedraw(true),
00127 m_marker(0),
00128 m_eveTopNode(0),
00129 m_eveScene(0),
00130 m_tableRowIndexForColorPopup(-1)
00131 {
00132 m_eveWindow = iParent->MakeFrame(0);
00133 TGCompositeFrame* xf = m_eveWindow->GetGUICompositeFrame();
00134
00135 m_frame = new TGVerticalFrame(xf);
00136
00137
00138 xf->AddFrame(m_frame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00139 }
00140
00141 void FWGeometryTableViewBase::postConst()
00142 {
00143 m_tableWidget = new FWTableWidget(getTableManager(), m_frame);
00144 m_frame->AddFrame(m_tableWidget,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,2,2,0,0));
00145 m_tableWidget->SetBackgroundColor(0xffffff);
00146 m_tableWidget->SetLineSeparatorColor(0x000000);
00147 m_tableWidget->SetHeaderBackgroundColor(0xececec);
00148 m_tableWidget->Connect("cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)",
00149 "FWGeometryTableViewBase",this,
00150 "cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)");
00151 m_tableWidget->disableGrowInWidth();
00152
00153
00154
00155 m_frame->MapSubwindows();
00156 m_frame->Layout();
00157 m_eveWindow->GetGUICompositeFrame()->Layout();
00158 m_frame->MapWindow();
00159 }
00160
00161
00162 FWGeometryTableViewBase::~FWGeometryTableViewBase()
00163 {
00164
00165 TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
00166 frame->RemoveFrame( m_frame );
00167 delete m_frame;
00168
00169
00170
00171 m_eveWindow->DestroyWindowAndSlot();
00172 delete getTableManager();
00173 }
00174
00175
00176 namespace {
00177 TEveScene* getMarkerScene(TEveViewer* v)
00178 {
00179 TEveElement* si = v->FindChild(Form("SI - GeoScene %s", v->GetElementName()));
00180 if(si)
00181 return ((TEveSceneInfo*)(si))->GetScene();
00182 else
00183 return 0;
00184 }
00185 }
00186
00187
00188
00189 void FWGeometryTableViewBase::cdNode(int idx)
00190 {
00191 std::string p;
00192 getTableManager()->getNodePath(idx, p);
00193 setPath(idx, p);
00194 }
00195
00196 void FWGeometryTableViewBase::cdTop()
00197 {
00198 std::string path = "/" ;
00199 path += getTableManager()->refEntries().at(0).name();
00200 setPath(-1, path );
00201 }
00202
00203 void FWGeometryTableViewBase::cdUp()
00204 {
00205 if (getTopNodeIdx() != -1)
00206 {
00207 int pIdx = getTableManager()->refEntries()[getTopNodeIdx()].m_parent;
00208 std::string p;
00209 getTableManager()->getNodePath(pIdx, p);
00210 setPath(pIdx, p);
00211 }
00212 }
00213
00214 void FWGeometryTableViewBase::setPath(int parentIdx, std::string&)
00215 {
00216 m_eveTopNode->clearSelection();
00217
00218
00219 m_topNodeIdx.set(parentIdx);
00220
00221 getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
00222
00223
00224 checkExpandLevel();
00225 refreshTable3D();
00226 }
00227
00228
00229
00230 void FWGeometryTableViewBase::checkExpandLevel()
00231 {
00232
00233 int ae = m_autoExpand.value();
00234 if ( m_topNodeIdx.value() > 0)
00235 ae += getTableManager()->refEntries().at(m_topNodeIdx.value()).m_level;
00236
00237 for (FWGeometryTableManagerBase::Entries_i i = getTableManager()->refEntries().begin(); i != getTableManager()->refEntries().end(); ++i)
00238 {
00239 if (i->m_level < ae)
00240 i->setBit(FWGeometryTableManagerBase::kExpanded);
00241 else
00242 i->resetBit(FWGeometryTableManagerBase::kExpanded);
00243 }
00244 }
00245
00246
00247
00248 void
00249 FWGeometryTableViewBase::populate3DViewsFromConfig()
00250 {
00251
00252 if (m_viewersConfig) {
00253 TEveElementList* viewers = gEve->GetViewers();
00254 const FWConfiguration::KeyValues* keyVals = m_viewersConfig->keyValues();
00255
00256 if(0!=keyVals)
00257 {
00258 for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it) {
00259
00260 TString sname = it->first;
00261 TEveViewer* v = dynamic_cast<TEveViewer*>(viewers->FindChild(sname.Data()));
00262 if (!v)
00263 {
00264 fwLog(fwlog::kError) << "FWGeometryTableViewBase::populate3DViewsFromConfig no viewer found " << it->first << std::endl;
00265 return;
00266 }
00267 v->AddScene(m_eveScene);
00268 m_viewBox->setElement(m_eveTopNode);
00269 if (m_marker) getMarkerScene(v)->AddElement(m_marker);
00270
00271 gEve->FullRedraw3D(false, true);
00272 }
00273 }
00274 }
00275 }
00276
00277
00278
00279 void
00280 FWGeometryTableViewBase::selectView(int idx)
00281 {
00282
00283
00284 m_viewBox->setElement(m_eveTopNode);
00285
00286 TEveElement::List_i it = gEve->GetViewers()->BeginChildren();
00287 std::advance(it, idx);
00288 TEveViewer* v = (TEveViewer*)(*it);
00289
00290 for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit )
00291 {
00292 if ((((TEveSceneInfo*)(*eit))->GetScene()) == m_eveScene)
00293 {
00294 v->RemoveElement(*eit);
00295 if (m_marker) getMarkerScene(v)->RemoveElement(m_marker);
00296 gEve->Redraw3D();
00297 return;
00298 }
00299 }
00300
00301 if (m_marker) getMarkerScene(v)->AddElement(m_marker);
00302 v->AddScene(m_eveScene);
00303 gEve->Redraw3D();
00304 }
00305
00306
00307
00308 void
00309 FWGeometryTableViewBase::setColumnSelected(int idx)
00310 {
00311
00312 if (gEve->GetSelection()->HasChild( m_eveTopNode))
00313 gEve->GetSelection()->RemoveElement( m_eveTopNode);
00314
00315 if (gEve->GetHighlight()->HasChild( m_eveTopNode))
00316 gEve->GetHighlight()->RemoveElement( m_eveTopNode);
00317
00318
00319 m_eveTopNode->UnSelected();
00320 m_eveTopNode->UnHighlighted();
00321
00322
00323 if (m_eveTopNode->selectPhysicalFromTable(idx))
00324 gEve->GetSelection()->AddElement(m_eveTopNode);
00325
00326 getTableManager()->refEntry(idx).setBit(FWGeometryTableManagerBase::kSelected);
00327 getTableManager()->redrawTable();
00328 gEve->Redraw3D();
00329 }
00330
00331
00332 void
00333 FWGeometryTableViewBase::cellClicked(Int_t iRow, Int_t iColumn, Int_t iButton, Int_t iKeyMod, Int_t x, Int_t y)
00334 {
00335 int idx = getTableManager()->rowToIndex()[iRow];
00336 FWGeometryTableManagerBase::NodeInfo& ni = getTableManager()->refEntries()[idx];
00337
00338 bool elementChanged = false;
00339 if (iButton == kButton1)
00340 {
00341 if (iColumn == 0)
00342 {
00343 Window_t wdummy;
00344 Int_t xLoc,yLoc;
00345 gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), m_tableWidget->GetId(), x, y, xLoc, yLoc, wdummy);
00346
00347 if (getTableManager()->firstColumnClicked(iRow, xLoc))
00348 setColumnSelected(idx);
00349 }
00350 else if (iColumn == 1)
00351 {
00352 std::vector<Color_t> colors;
00353 m_colorManager->fillLimitedColors(colors);
00354
00355 if (!m_colorPopup) {
00356 m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
00357 m_colorPopup->InitContent("", colors);
00358 m_colorPopup->Connect("ColorSelected(Color_t)","FWGeometryTableViewBase", const_cast<FWGeometryTableViewBase*>(this), "nodeColorChangeRequested(Color_t");
00359 }
00360 m_tableRowIndexForColorPopup = idx;
00361 m_colorPopup->SetName("Selected");
00362 m_colorPopup->ResetColors(colors, m_colorManager->backgroundColorIndex()==FWColorManager::kBlackIndex);
00363 m_colorPopup->PlacePopup(x, y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
00364 return;
00365 }
00366 else if (iColumn == 2)
00367 {
00368 ni.switchBit(FWGeometryTableManagerBase::kVisNodeSelf);
00369 elementChanged = true;
00370 }
00371 else if (iColumn == 3)
00372 {
00373 ni.switchBit(FWGeometryTableManagerBase::kVisNodeChld);
00374 elementChanged = true;
00375 }
00376 else if (iColumn == 5)
00377 {
00378
00379 ni.switchBit(BIT(5));
00380 elementChanged = true;
00381 }
00382 else
00383 {setColumnSelected(idx);
00384 }
00385
00386 if (elementChanged) {
00387 refreshTable3D();
00388
00389 }
00390 }
00391 else if (iColumn == 0)
00392 {
00393 setColumnSelected(idx);
00394 m_eveTopNode->popupMenu(x, y);
00395 }
00396 }
00397
00398
00399 void FWGeometryTableViewBase::setBackgroundColor()
00400 {
00401 bool backgroundIsWhite = m_colorManager->backgroundColorIndex()==FWColorManager::kWhiteIndex;
00402 if(backgroundIsWhite) {
00403 m_tableWidget->SetBackgroundColor(0xffffff);
00404 m_tableWidget->SetLineSeparatorColor(0x000000);
00405 } else {
00406 m_tableWidget->SetBackgroundColor(0x000000);
00407 m_tableWidget->SetLineSeparatorColor(0xffffff);
00408 }
00409 getTableManager()->setBackgroundToWhite(backgroundIsWhite);
00410 gClient->NeedRedraw(m_tableWidget);
00411 }
00412
00413
00414
00415 void FWGeometryTableViewBase::nodeColorChangeRequested(Color_t col)
00416 {
00417
00418 if (m_tableRowIndexForColorPopup >= 0) {
00419 FWGeometryTableManagerBase::NodeInfo& ni = getTableManager()->refEntries()[m_tableRowIndexForColorPopup];
00420 ni.m_color = col;
00421 ni.m_node->GetVolume()->SetLineColor(col);
00422 refreshTable3D();
00423 m_tableRowIndexForColorPopup = -1;
00424 }
00425 }
00426
00427
00428
00429 void FWGeometryTableViewBase::refreshTable3D()
00430 {
00431 if (gEve->GetSelection()->HasChild(m_eveTopNode))
00432 gEve->GetSelection()->RemoveElement(m_eveTopNode);
00433
00434 if (gEve->GetHighlight()->HasChild(m_eveTopNode))
00435 gEve->GetHighlight()->RemoveElement(m_eveTopNode);
00436
00437 m_eveTopNode->fSceneJebo->PadPaint(m_eveTopNode->fSceneJebo->GetPad());
00438 gEve->Redraw3D();
00439
00440 getTableManager()->redrawTable();
00441 }
00442
00443
00444
00445 void FWGeometryTableViewBase::addTo(FWConfiguration& iTo) const
00446 {
00447 FWConfigurableParameterizable::addTo(iTo);
00448
00449 FWConfiguration viewers(1);
00450 FWConfiguration tempArea;
00451
00452 for(TEveElement::List_i k = gEve->GetViewers()->BeginChildren(); k!= gEve->GetViewers()->EndChildren(); ++k)
00453 {
00454 for (TEveElement::List_i eit = (*k)->BeginChildren(); eit != (*k)->EndChildren(); ++eit )
00455 {
00456 TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
00457 if (s->GetGLScene() == m_eveTopNode->fSceneJebo)
00458 {
00459 viewers.addKeyValue( (*k)->GetElementName(), tempArea);
00460 break;
00461 }
00462 }
00463 }
00464
00465 iTo.addKeyValue("Viewers", viewers, true);
00466 }
00467
00468
00469
00470 void FWGeometryTableViewBase::setFrom(const FWConfiguration& iFrom)
00471 {
00472 m_enableRedraw = false;
00473 for(const_iterator it =begin(), itEnd = end();
00474 it != itEnd;
00475 ++it) {
00476
00477
00478 (*it)->setFrom(iFrom);
00479
00480 }
00481 m_viewersConfig = iFrom.valueForKey("Viewers");
00482
00483 m_enableRedraw = true;
00484 refreshTable3D();
00485 }