8#include <display/SplitGLView.h>
9#include <display/EveGeometry.h>
10#include <display/InfoWidget.h>
11#include <framework/logging/Logger.h>
14#include "TEveManager.h"
15#include "TEveBrowser.h"
16#include "TEveProjectionAxes.h"
17#include "TEveViewer.h"
18#include "TEveWindowManager.h"
20#include "TGStatusBar.h"
22#include "TGLPhysicalShape.h"
23#include "TGLLogicalShape.h"
33 bool toggleMenuEntry(TGPopupMenu* menu,
int entryid)
35 if (menu->IsEntryChecked(entryid))
36 menu->UnCheckEntry(entryid);
38 menu->CheckEntry(entryid);
39 return menu->IsEntryChecked(entryid);
47 const char* projectionName[3] = {
"3D",
"Rho/Z",
"R/Phi" };
48 TGLViewer::ECameraType cameraType[3] = { TGLViewer::kCameraPerspXOZ, TGLViewer::kCameraOrthoXOY, TGLViewer::kCameraOrthoXOY };
50 TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
51 TEveWindowPack* pack = slot->MakePack();
53 pack->SetShowTitleBar(kFALSE);
55 TEveWindowSlot* viewerslots[3];
56 auto pack1 = pack->NewSlot()->MakePack();
57 pack1->SetHorizontal();
58 pack1->SetShowTitleBar(kFALSE);
59 viewerslots[0] = pack1->NewSlotWithWeight(0.7);
60 TEveWindowSlot* infoslot = pack1->NewSlotWithWeight(0.3);
62 auto pack2 = pack->NewSlot()->MakePack();
63 pack2->SetHorizontal();
64 pack2->SetShowTitleBar(kFALSE);
65 viewerslots[1] = pack2->NewSlot();
66 viewerslots[2] = pack2->NewSlot();
70 for (
int iFrame = 0; iFrame < 3; iFrame++) {
71 TEveViewer* viewer =
new TEveViewer(TString::Format(
"%s viewer", projectionName[iFrame]));
72 m_glViewer[iFrame] = viewer->SpawnGLEmbeddedViewer();
73 viewerslots[iFrame]->ReplaceWindow(viewer);
74 viewerslots[iFrame] =
nullptr;
76 viewer->SetShowTitleBar(kFALSE);
79 m_glViewer[iFrame]->SetCurrentCamera(cameraType[iFrame]);
81 TEveProjectionManager* projectionMgr = 0;
83 m_rhozManager =
new TEveProjectionManager(TEveProjection::kPT_RhoZ);
85 m_glViewer[iFrame]->CurrentCamera().Zoom(+300,
false,
false);
86 }
else if (iFrame == 2) {
87 m_rphiManager =
new TEveProjectionManager(TEveProjection::kPT_RPhi);
89 m_glViewer[iFrame]->CurrentCamera().Zoom(-50,
false,
false);
93 m_glViewer[iFrame]->Connect(
"MouseOver(TGLPhysicalShape*)",
"Belle2::SplitGLView",
this,
"onMouseOver(TGLPhysicalShape*)");
94 m_glViewer[iFrame]->Connect(
"Clicked(TObject*)",
"Belle2::SplitGLView",
this,
"onClicked(TObject*)");
96 viewer->AddScene(gEve->GetGlobalScene());
97 viewer->AddScene(gEve->GetEventScene());
101 s = gEve->SpawnNewScene(TString::Format(
"%s projection", projectionName[iFrame]));
105 gEve->GetViewers()->AddElement(viewer);
107 s->AddElement(projectionMgr);
108 gEve->AddToListTree(projectionMgr, kTRUE);
109 TEveProjectionAxes* axes =
new TEveProjectionAxes(projectionMgr);
110 projectionMgr->AddElement(axes);
116 TEveWindowFrame* eveFrame =
new TEveWindowFrame(
m_infoWidget,
"DataStore Info");
117 infoslot->ReplaceWindow(eveFrame);
118 eveFrame->SetShowTitleBar(kFALSE);
123 m_cameraMenu =
new TGPopupMenu(gClient->GetDefaultRoot());
124 m_cameraMenu->AddEntry(
"Perspective (Floor X/Z)", kGLPerspXOZ);
125 m_cameraMenu->AddEntry(
"Perspective (Floor Y/Z)", kGLPerspYOZ);
126 m_cameraMenu->AddEntry(
"Perspective (Floor X/Y)", kGLPerspXOY);
131 m_cameraMenu->AddEntry(
"Orthographic: Allow Rotating", kGLOrthoRotate);
132 m_cameraMenu->AddEntry(
"Orthographic: Right Click to Dolly", kGLOrthoDolly);
134 m_cameraMenu->AddEntry(
"Perspective: Enable Stereographic 3D (Requires Hardware or stereowrap)", kGLStereo);
136 m_sceneMenu =
new TGPopupMenu(gClient->GetDefaultRoot());
137 m_sceneMenu->AddEntry(
"&Update Current", kSceneUpdate);
138 m_sceneMenu->AddEntry(
"Update &All", kSceneUpdateAll);
140 m_sceneMenu->AddEntry(
"&Show Scale for Projections", kShowScale);
143 m_sceneMenu->AddEntry(
"Save &Geometry Extract", kSaveGeometryExtract);
145 TGMenuBar* menuBar = gEve->GetBrowser()->GetMenuBar();
146 menuBar->AddPopup(
"&Camera",
m_cameraMenu,
new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
147 menuBar->AddPopup(
"&Scene",
m_sceneMenu,
new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
150 m_cameraMenu->Connect(
"Activated(Int_t)",
"Belle2::SplitGLView",
this,
"handleMenu(Int_t)");
151 m_sceneMenu->Connect(
"Activated(Int_t)",
"Belle2::SplitGLView",
this,
"handleMenu(Int_t)");
159 gEve->GetListTree()->Connect(
"Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)",
160 "Belle2::SplitGLView",
this,
"itemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
166 for (
int i = 0; i < 3; i++) {
180 TGLViewer::ECameraType cameraType;
181 switch (cameraAction) {
183 cameraType = TGLViewer::kCameraPerspYOZ;
186 cameraType = TGLViewer::kCameraPerspXOZ;
189 cameraType = TGLViewer::kCameraPerspXOY;
192 cameraType = TGLViewer::kCameraOrthoXOY;
195 cameraType = TGLViewer::kCameraOrthoXOZ;
198 cameraType = TGLViewer::kCameraOrthoZOY;
201 B2ERROR(
"unknown camera action " << cameraAction);
204 viewer->SetCurrentCamera(cameraType);
211 switch (menuCommand) {
236 case kSceneUpdateAll:
237 for (
int i = 0; i < 3; i++)
245 case kSaveGeometryExtract:
259 m_statusBar->SetText(Form(
"User clicked on: \"%s\"", obj->GetName()), 1);
261 TEveElement* elem =
dynamic_cast<TEveElement*
>(obj);
262 if (TEveProjected* projected =
dynamic_cast<TEveProjected*
>(obj)) {
263 elem =
dynamic_cast<TEveElement*
>(projected->GetProjectable());
268 TGListTreeItem* eventItem = gEve->GetListTree()->FindItemByPathname(
"Event");
269 TGListTreeItem* item = gEve->GetListTree()->FindItemByObj(eventItem, elem);
272 gEve->GetBrowser()->GetTabLeft()->SetTab(
"Eve");
275 TGListTreeItem* parent = item;
276 while ((parent = parent->GetParent()) !=
nullptr)
277 gEve->GetListTree()->OpenItem(parent);
280 gEve->GetListTree()->AdjustPosition(item);
288 TGLEmbeddedViewer* sender =
dynamic_cast<TGLEmbeddedViewer*
>(
static_cast<TQObject*
>(gTQSender));
291 B2WARNING(
"onClicked() signal not from a TGLEmbeddedViewer?");
299 const TEveWindow* currentWindow = gEve->GetWindowManager()->GetCurrentWindow();
302 for (
int i = 0; i < 3; i++) {
317 for (
int i = 0; i < 3; i++) {
324 B2WARNING(
"setActiveViewer(): viewer not found!");
360 if (shape && shape->GetLogical() && shape->GetLogical()->GetExternal())
362 shape->GetLogical()->GetExternal()->GetName()), 0);
370 Bool_t state = toggleMenuEntry(
m_cameraMenu, kGLOrthoRotate);
380 Bool_t state = !toggleMenuEntry(
m_cameraMenu, kGLOrthoDolly);
398 bool state = toggleMenuEntry(
m_sceneMenu, kShowScale);
401 for (
auto mgr : projections) {
402 TEveElement::List_ci end_it = mgr->EndChildren();
403 for (TEveElement::List_i it = mgr->BeginChildren(); it != end_it; ++it) {
404 TEveProjectionAxes* a =
dynamic_cast<TEveProjectionAxes*
>(*it);
406 a->SetRnrSelf(state);
410 gEve->Redraw3D(
false);
417 static const TEveException eh(
"SplitGLView::itemClicked ");
418 TEveElement* re =
static_cast<TEveElement*
>(item->GetUserData());
420 TObject* obj = re->GetObject(eh);
421 if (obj->InheritsFrom(
"TEveViewer")) {
422 TGLViewer* v =
static_cast<TEveViewer*
>(obj)->GetGLViewer();
424 if (v->InheritsFrom(
"TGLEmbeddedViewer")) {
425 TGLEmbeddedViewer* ev = (TGLEmbeddedViewer*)v;
426 gVirtualX->SetInputFocus(ev->GetGLWidget()->GetId());
void onMouseOver(TGLPhysicalShape *shape)
show name of shape in status bar.
InfoWidget * m_infoWidget
text-based info viewer.
void itemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y=43)
handler for clicks inside GL viewer.
void toggleOrthoRotate()
toggle wether the active viewer may be rotated (not that useful for projections).
virtual ~SplitGLView()
destructor.
TEveWindow * m_window[3]
corresponding windows
void toggleShowScale()
Toggle visibility of axes for projections.
TGPopupMenu * m_sceneMenu
'Scene' popup menu
TEveProjectionManager * m_rhozManager
Rho-Z projection.
TGPopupMenu * m_cameraMenu
'Camera' popup menu
void updateCamera(int cameraAction)
change camera type, given one of EMenuCommands.
TGLEmbeddedViewer * getActiveGLViewer()
return TGLEmbeddedViewer that is active right now.
void onClicked(TObject *obj)
make current viewer active & show name of obj in status bar.
void toggleOrthoDolly()
Toggle state of the 'Ortho allow dolly' menu entry.
void toggleStereo()
Toggle stereo viewing for perspective viewer.
int m_activeViewer
selected viewer/window, or -1.
SplitGLView()
constructor.
void setActiveViewer(TGLEmbeddedViewer *v)
set m_activeViewer and update UI accordingly.
TEveProjectionManager * m_rphiManager
R-Phi projection.
void handleMenu(Int_t menuCommand)
menu item handler
TGStatusBar * m_statusBar
status bar
TGLEmbeddedViewer * m_glViewer[3]
GL viewers.
void saveExtract()
Save a geometry extract from the current state of the TGeo geometry.
Abstract base class for different kinds of events.