File indexing completed on 2024-04-06 12:11:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <functional>
0015
0016
0017 #include "Fireworks/Core/src/FWGeometryTableView.h"
0018 #include "Fireworks/Core/src/FWGeoTopNodeScene.h"
0019 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
0020 #include "Fireworks/Core/interface/FWViewType.h"
0021 #include "Fireworks/Core/interface/FWGeometryTableManagerBase.h"
0022 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0023 #include "Fireworks/Core/src/FWGeometryTableManager.h"
0024 #include "Fireworks/Core/interface/fwLog.h"
0025 #include "Fireworks/Core/interface/FWEnumParameter.h"
0026 #include "Fireworks/Core/interface/FWEnumParameterSetter.h"
0027
0028 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
0029 #include "Fireworks/Core/interface/FWGUIManager.h"
0030 #include "Fireworks/Core/interface/FWValidatorBase.h"
0031 #include "Fireworks/Core/src/FWEveDetectorGeo.h"
0032
0033 #include "KeySymbols.h"
0034 #include "TGButton.h"
0035 #include "TGComboBox.h"
0036 #include "TGLabel.h"
0037 #include "TGListBox.h"
0038 #include "TGLViewer.h"
0039 #include "TGeoMatrix.h"
0040 #include "TGeoBBox.h"
0041 #include "TVirtualX.h"
0042 #include "TEveViewer.h"
0043 #include "TEveScene.h"
0044 #include "TEveSceneInfo.h"
0045 #include "TEveManager.h"
0046 #include "TGeoManager.h"
0047 #include "TGLCamera.h"
0048
0049
0050
0051
0052
0053
0054 class FWGeoMaterialValidator : public FWValidatorBase {
0055 public:
0056 FWGeometryTableView* m_browser;
0057 mutable std::vector<const char*> m_list;
0058 FWGeoMaterialValidator(FWGeometryTableView* v) { m_browser = v; }
0059 ~FWGeoMaterialValidator() override {}
0060
0061 virtual void addDaughtersRec(TGeoVolume* v) const {
0062 switch (m_browser->getFilterType()) {
0063 case FWGeometryTableView::kFilterMaterialName:
0064 m_list.push_back(v->GetMaterial()->GetName());
0065 break;
0066 case FWGeometryTableView::kFilterMaterialTitle:
0067 m_list.push_back(v->GetMaterial()->GetTitle());
0068 break;
0069 case FWGeometryTableView::kFilterShapeName:
0070 m_list.push_back(v->GetShape()->GetName());
0071 break;
0072 case FWGeometryTableView::kFilterShapeClassName:
0073 m_list.push_back(v->GetShape()->ClassName());
0074 break;
0075 default:
0076 std::cerr << "FWGeoMaterialValidator unhandeled case. \n";
0077 }
0078
0079 for (int i = 0; i < v->GetNdaughters(); ++i)
0080 addDaughtersRec(v->GetNode(i)->GetVolume());
0081 }
0082
0083 void fillOptions(const char* iBegin,
0084 const char* iEnd,
0085 std::vector<std::pair<std::shared_ptr<std::string>, std::string> >& oOptions) const override {
0086 oOptions.clear();
0087 m_list.clear();
0088
0089 FWGeometryTableManagerBase::Entries_i tnit = m_browser->getTableManager()->refEntries().begin();
0090 std::advance(tnit, m_browser->getTopNodeIdx());
0091 FWGeometryTableViewManager::getGeoMangeur();
0092 addDaughtersRec(tnit->m_node->GetVolume());
0093
0094 std::sort(m_list.begin(), m_list.end());
0095 std::vector<const char*>::iterator ui = std::unique(m_list.begin(), m_list.end());
0096 m_list.resize(ui - m_list.begin());
0097
0098 std::string part(iBegin, iEnd);
0099 unsigned int part_size = part.size();
0100 std::string h = "";
0101
0102 oOptions.push_back(std::make_pair(std::make_shared<std::string>(*m_list.begin()), h));
0103 std::vector<const char*>::iterator startIt = m_list.begin();
0104 startIt++;
0105 for (std::vector<const char*>::iterator i = startIt; i != m_list.end(); ++i) {
0106
0107 if ((strlen(*i) >= part_size) && strncmp(*i, part.c_str(), part_size) == 0) {
0108 oOptions.push_back(std::make_pair(std::make_shared<std::string>((*i)), &((*i)[part_size])));
0109 }
0110 }
0111 }
0112
0113 bool isStringValid(std::string& exp) {
0114 std::cerr << "validation not used \n";
0115 return false;
0116 }
0117 };
0118
0119
0120
0121
0122
0123 FWGeometryTableView::FWGeometryTableView(TEveWindowSlot* iParent, FWColorManager* colMng)
0124 : FWGeometryTableViewBase(iParent, FWViewType::kGeometryTable, colMng),
0125 m_tableManager(nullptr),
0126 m_filterEntry(nullptr),
0127 m_filterValidator(nullptr),
0128 m_mode(this, "Mode", 0l, 0l, 1l),
0129 m_disableTopNode(this, "HideTopNode", true),
0130 m_visLevel(this, "VisLevel", 3l, 1l, 100l),
0131 m_filter(this, "Materials", std::string()),
0132 m_filterType(this, "FilterType:", 0l, 0l, 3l),
0133 m_visLevelFilter(this, "IgnoreVisLevelOnFilter", true),
0134 m_selectRegion(this, "SelectNearCameraCenter", false),
0135 m_regionRadius(this, "SphereRadius", 10.0, 1.0, 300.0),
0136 m_proximityAlgo(this, "Proximity algorithm", 1l, 0l, 1l) {
0137 FWGeoTopNodeGLScene* gls = new FWGeoTopNodeGLScene(nullptr);
0138 #if ROOT_VERSION_CODE < ROOT_VERSION(5, 32, 0)
0139 m_eveScene = new FWGeoTopNodeEveScene(gls, "TopGeoNodeScene", "");
0140 #else
0141 m_eveScene = new TEveScene(gls, "TopGeoNodeScene", "");
0142 #endif
0143 gEve->GetScenes()->AddElement(m_eveScene);
0144
0145 m_eveTopNode = new FWEveDetectorGeo(this);
0146 m_eveTopNode->IncDenyDestroy();
0147 m_eveTopNode->SetPickable(true);
0148 m_eveScene->AddElement(m_eveTopNode);
0149
0150 gls->m_eveTopNode = m_eveTopNode;
0151 m_eveTopNode->m_scene = gls;
0152
0153
0154 TGHorizontalFrame* hp = new TGHorizontalFrame(m_frame);
0155 {
0156 TGTextButton* rb = new TGTextButton(hp, "CdTop");
0157 hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0158 rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdTop()");
0159 }
0160 {
0161 TGTextButton* rb = new TGTextButton(hp, "CdUp");
0162 hp->AddFrame(rb, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
0163 rb->Connect("Clicked()", "FWGeometryTableViewBase", this, "cdUp()");
0164 }
0165 {
0166 m_viewBox = new FWViewCombo(hp, this);
0167 hp->AddFrame(m_viewBox, new TGLayoutHints(kLHintsExpandY, 2, 2, 0, 0));
0168 }
0169 {
0170 m_filterType.addEntry(kFilterMaterialName, "MaterialName");
0171 m_filterType.addEntry(kFilterMaterialTitle, "MaterialTitle");
0172 m_filterType.addEntry(kFilterShapeName, "ShapeName");
0173 m_filterType.addEntry(kFilterShapeClassName, "ShapeClassName");
0174
0175 std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor((FWParameterBase*)&m_filterType));
0176 ptr->attach((FWParameterBase*)&m_filterType, this);
0177
0178 TGFrame* pframe = ptr->build(hp, false);
0179 hp->AddFrame(pframe, new TGLayoutHints(kLHintsLeft));
0180 m_filterTypeSetter.swap(ptr);
0181 }
0182 {
0183 hp->AddFrame(new TGLabel(hp, "FilterExp:"), new TGLayoutHints(kLHintsBottom, 0, 0, 0, 2));
0184 m_filterEntry = new FWGUIValidatingTextEntry(hp);
0185 m_filterEntry->SetHeight(20);
0186 m_filterValidator = new FWGeoMaterialValidator(this);
0187 m_filterEntry->setValidator(m_filterValidator);
0188 hp->AddFrame(m_filterEntry, new TGLayoutHints(kLHintsExpandX, 0, 2, 1, 0));
0189 m_filterEntry->setMaxListBoxHeight(150);
0190 m_filterEntry->getListBox()->Connect("Selected(int)", "FWGeometryTableView", this, "filterListCallback()");
0191 m_filterEntry->Connect("ReturnPressed()", "FWGeometryTableView", this, "filterTextEntryCallback()");
0192
0193 gVirtualX->GrabKey(m_filterEntry->GetId(), gVirtualX->KeysymToKeycode((int)kKey_A), kKeyControlMask, true);
0194 }
0195 m_frame->AddFrame(hp, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 2, 0));
0196
0197 m_tableManager = new FWGeometryTableManager(this);
0198 {
0199 TEveGeoManagerHolder gmgr(FWGeometryTableViewManager::getGeoMangeur());
0200 m_tableManager->loadGeometry(gGeoManager->GetTopNode(), gGeoManager->GetListOfVolumes());
0201 }
0202 cdTop();
0203
0204 m_mode.addEntry(kNode, "Node");
0205 m_mode.addEntry(kVolume, "Volume");
0206
0207 m_mode.changed_.connect(std::bind(&FWGeometryTableView::refreshTable3D, this));
0208 m_autoExpand.changed_.connect(std::bind(&FWGeometryTableView::autoExpandCallback, this));
0209 m_visLevel.changed_.connect(std::bind(&FWGeometryTableView::refreshTable3D, this));
0210
0211 m_visLevelFilter.changed_.connect(std::bind(&FWGeometryTableView::refreshTable3D, this));
0212
0213 m_disableTopNode.changed_.connect(std::bind(&FWGeometryTableView::updateVisibilityTopNode, this));
0214 postConst();
0215
0216 m_proximityAlgo.addEntry(kBBoxCenter, "BBox center");
0217 m_proximityAlgo.addEntry(kBBoxSurface, "BBox surface");
0218
0219 m_selectRegion.changed_.connect(std::bind(&FWGeometryTableView::checkRegionOfInterest, this));
0220 m_regionRadius.changed_.connect(std::bind(&FWGeometryTableView::checkRegionOfInterest, this));
0221 m_proximityAlgo.changed_.connect(std::bind(&FWGeometryTableView::checkRegionOfInterest, this));
0222 }
0223
0224 FWGeometryTableView::~FWGeometryTableView() {}
0225
0226
0227 void FWGeometryTableView::setPath(int parentIdx, std::string&) {
0228 m_eveTopNode->clearSelection();
0229
0230 m_topNodeIdx.set(parentIdx);
0231 getTableManager()
0232 ->refEntries()
0233 .at(getTopNodeIdx())
0234 .setBitVal(FWGeometryTableManagerBase::kVisNodeSelf, !m_disableTopNode.value());
0235 getTableManager()->setLevelOffset(getTableManager()->refEntries().at(getTopNodeIdx()).m_level);
0236
0237 checkExpandLevel();
0238 refreshTable3D();
0239 }
0240
0241
0242 FWGeometryTableManagerBase* FWGeometryTableView::getTableManager() { return m_tableManager; }
0243
0244
0245 void FWGeometryTableView::autoExpandCallback() {
0246 if (!m_enableRedraw)
0247 return;
0248 checkExpandLevel();
0249 getTableManager()->redrawTable(true);
0250 }
0251
0252
0253 void FWGeometryTableView::filterTextEntryCallback() {
0254
0255 std::string exp = m_filterEntry->GetText();
0256 updateFilter(exp);
0257 }
0258
0259
0260 void FWGeometryTableView::filterListCallback() {
0261
0262
0263 std::string exp = m_filterEntry->GetText();
0264 updateFilter(exp);
0265 }
0266
0267
0268 void FWGeometryTableView::updateFilter(std::string& exp) {
0269
0270
0271 if (exp.empty()) {
0272
0273 for (FWGeometryTableManagerBase::Entries_i i = m_tableManager->refEntries().begin();
0274 i != m_tableManager->refEntries().end();
0275 ++i) {
0276 m_tableManager->setVisibility(*i, true);
0277 m_tableManager->setVisibilityChld(*i, true);
0278 }
0279
0280
0281 m_filterEntry->Clear();
0282 }
0283
0284 m_filter.set(exp);
0285 m_tableManager->updateFilter(m_filterType.value());
0286 refreshTable3D();
0287 }
0288
0289
0290
0291 void FWGeometryTableView::populateController(ViewerParameterGUI& gui) const {
0292 gui.requestTab("Style")
0293 .addParam(&m_mode)
0294 .addParam(&m_autoExpand)
0295 .separator()
0296 .addParam(&m_disableTopNode)
0297 .addParam(&m_minParentTransparency)
0298 .addParam(&m_minLeafTransparency)
0299 .addParam(&m_visLevel)
0300 .addParam(&m_visLevelFilter)
0301 .separator()
0302 .addParam(&m_selectRegion)
0303 .addParam(&m_regionRadius)
0304 .addParam(&m_proximityAlgo)
0305 .separator();
0306
0307 TGTextButton* butt = new TGTextButton(gui.getTabContainer(), "ReloadColors");
0308 gui.getTabContainer()->AddFrame(butt);
0309 butt->Connect("Clicked()", "FWGeometryTableViewBase", (FWGeometryTableViewBase*)this, "reloadColors()");
0310 }
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 bool viewIsChecked(TEveViewer* v, TEveElement* el) {
0331 if (strstr(v->GetElementName(), "3D")) {
0332 for (TEveElement::List_i eit = v->BeginChildren(); eit != v->EndChildren(); ++eit) {
0333 TEveScene* s = ((TEveSceneInfo*)*eit)->GetScene();
0334 if (el && s->HasChildren() && s->FirstChild() == el)
0335 return true;
0336 }
0337 }
0338 return false;
0339 }
0340
0341 void FWGeometryTableView::checkRegionOfInterest() {
0342 if (m_selectRegion.value()) {
0343 double* center = nullptr;
0344 for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it) {
0345 TEveViewer* v = ((TEveViewer*)(*it));
0346 if (viewIsChecked(v, m_eveTopNode)) {
0347 if (center) {
0348 fwLog(fwlog::kWarning) << "Center picked from first view \n";
0349 } else {
0350 center = v->GetGLViewer()->CurrentCamera().GetCenterVec();
0351 fwLog(fwlog::kInfo) << Form(
0352 "Center picked (%.1f, %.1f, %.1f) from first selected 3D view \n", center[0], center[1], center[2]);
0353 }
0354 }
0355 }
0356
0357 if (!center) {
0358 fwLog(fwlog::kError) << "No 3D view selected \n";
0359 return;
0360 }
0361
0362 m_tableManager->checkRegionOfInterest(center, m_regionRadius.value(), m_proximityAlgo.value());
0363 } else {
0364 m_tableManager->resetRegionOfInterest();
0365 }
0366
0367 refreshTable3D();
0368 }
0369
0370
0371
0372 void FWGeometryTableView::setFrom(const FWConfiguration& iFrom) {
0373 m_enableRedraw = false;
0374 for (const_iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
0375
0376 if ((*it)->name() == m_topNodeIdx.name())
0377 setTopNodePathFromConfig(iFrom);
0378 else
0379 (*it)->setFrom(iFrom);
0380 }
0381
0382 cdNode(m_topNodeIdx.value());
0383
0384 TGComboBox* cbox = ((FWEnumParameterSetter*)m_filterTypeSetter.get())->getWidget();
0385 cbox->Select(m_filterType.value(), false);
0386 m_viewersConfig = iFrom.valueForKey("Viewers");
0387
0388 m_enableRedraw = true;
0389 m_filterEntry->SetText(m_filter.value().c_str(), false);
0390 m_tableManager->updateFilter(m_filterType.value());
0391 checkExpandLevel();
0392 refreshTable3D();
0393
0394
0395
0396
0397
0398 }
0399
0400
0401
0402 void FWGeometryTableView::updateVisibilityTopNode() {
0403 getTableManager()
0404 ->refEntries()
0405 .at(getTopNodeIdx())
0406 .setBitVal(FWGeometryTableManagerBase::kVisNodeSelf, !m_disableTopNode.value());
0407 refreshTable3D();
0408 }