Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:14

0001 #include "Fireworks/Core/interface/FWGLEventHandler.h"
0002 #include "Fireworks/Core/interface/FWGUIManager.h"
0003 #include "Fireworks/Core/interface/FWEveView.h"
0004 #include "Fireworks/Core/interface/FW3DViewBase.h"
0005 #include "Fireworks/Core/src/FW3DViewDistanceMeasureTool.h"
0006 
0007 #include "KeySymbols.h"
0008 #include "TGLViewer.h"
0009 #include "TGLWidget.h"
0010 #include "TGLPhysicalShape.h"
0011 #include "TGLLogicalShape.h"
0012 #include "TEveGedEditor.h"
0013 #include "TEveViewer.h"
0014 #include "FWGeoTopNodeScene.h"
0015 #include "TVirtualX.h"
0016 
0017 FWGLEventHandler::FWGLEventHandler(TGWindow *w, TObject *obj, TEveCaloLego *l)
0018     : TEveLegoEventHandler(w, obj, l), m_viewer(nullptr) {}
0019 
0020 //______________________________________________________________________________
0021 void FWGLEventHandler::PopupContextMenu(TGLPhysicalShape *pshp, Event_t *event, Int_t gx, Int_t gy) {
0022   // Popup context menu.
0023 
0024   if (event->fState & kKeyShiftMask && event->fState & kKeyControlMask) {
0025     TGLEventHandler::PopupContextMenu(pshp, event, gx, gy);
0026     return;
0027   }
0028 
0029   if (m_viewer && pshp) {
0030     SelectForClicked(event);
0031 
0032     if (pshp->GetLogical()) {
0033       FWGeoTopNodeGLScene *js = dynamic_cast<FWGeoTopNodeGLScene *>(pshp->GetLogical()->GetScene());
0034       if (js) {
0035         js->GeoPopupMenu(gx, gy, fGLViewer);
0036         return;
0037       }
0038     }
0039 
0040     openSelectedModelContextMenu_(gx, gy);
0041   }
0042 }
0043 
0044 //______________________________________________________________________________
0045 
0046 Bool_t FWGLEventHandler::HandleButton(Event_t *event) {
0047   Bool_t res = TEveLegoEventHandler::HandleButton(event);
0048   if (m_viewer && m_viewer->requestGLHandlerPick() && event->fType == kButtonPress) {
0049     Int_t x, y;
0050     Window_t childdum;
0051     gVirtualX->TranslateCoordinates(
0052         gClient->GetDefaultRoot()->GetId(), fGLViewer->GetGLWidget()->GetId(), event->fX, event->fY, x, y, childdum);
0053     fGLViewer->RequestSelect(event->fX, event->fY);
0054     if (fGLViewer->GetSelRec().GetN() > 0) {
0055       TGLVector3 v(event->fX, event->fY, 0.5 * fGLViewer->GetSelRec().GetMinZ());
0056       fGLViewer->CurrentCamera().WindowToViewport(v);
0057       v = fGLViewer->CurrentCamera().ViewportToWorld(v);
0058       FW3DViewBase *v3d = dynamic_cast<FW3DViewBase *>(m_viewer);
0059       v3d->setCurrentDMTVertex(v.X(), v.Y(), v.Z());
0060     }
0061   }
0062 
0063   return res;
0064 }
0065 
0066 Bool_t FWGLEventHandler::HandleKey(Event_t *event) {
0067   UInt_t keysym;
0068   char tmp[2];
0069   gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
0070 
0071   if (m_viewer && (keysym == kKey_Enter || keysym == kKey_Return || keysym == kKey_Space)) {
0072     if (event->fType == kGKeyPress) {
0073       Int_t x, y;
0074       Window_t childdum;
0075       gVirtualX->TranslateCoordinates(
0076           fGLViewer->GetGLWidget()->GetId(), gClient->GetDefaultRoot()->GetId(), event->fX, event->fY, x, y, childdum);
0077 
0078       fGLViewer->RequestSelect(event->fX, event->fY);
0079       PopupContextMenu(fGLViewer->GetSelRec().GetPhysShape(), event, x, y);
0080     }
0081     return kTRUE;
0082   } else {
0083     return TEveLegoEventHandler::HandleKey(event);
0084   }
0085 }
0086 
0087 Bool_t FWGLEventHandler::HandleFocusChange(Event_t *event) {
0088   // Handle generic Event_t type 'event' - provided to catch focus changes
0089   // and terminate any interaction in viewer.
0090 
0091   if (m_viewer && m_viewer->viewer() && event->fType == kFocusOut)
0092     TEveGedEditor::ElementChanged(m_viewer->viewer());
0093 
0094   return TGLEventHandler::HandleFocusChange(event);
0095 }
0096 
0097 //______________________________________________________________________________
0098 Bool_t FWGLEventHandler::HandleCrossing(Event_t *event) {
0099   // Handle generic Event_t type 'event' - provided to catch focus changes
0100   // and terminate any interaction in viewer.
0101 
0102   if (m_viewer && m_viewer->viewer() && event->fType == kLeaveNotify)
0103     TEveGedEditor::ElementChanged(m_viewer->viewer());
0104 
0105   return TGLEventHandler::HandleCrossing(event);
0106 }