CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Fireworks/Core/src/FWGLEventHandler.cc

Go to the documentation of this file.
00001 #include "Fireworks/Core/interface/FWGLEventHandler.h"
00002 #include "Fireworks/Core/interface/FWGUIManager.h"
00003 #include "Fireworks/Core/interface/FWEveView.h"
00004 #include "Fireworks/Core/interface/FW3DViewBase.h"
00005 #include "Fireworks/Core/src/FW3DViewDistanceMeasureTool.h"
00006 
00007 #include "KeySymbols.h"
00008 #include "TGLViewer.h"
00009 #include "TGLWidget.h"
00010 #include "TGLPhysicalShape.h"
00011 #include "TGLLogicalShape.h"
00012 #include "TEveGedEditor.h"
00013 #include "TEveViewer.h"
00014 #include "FWGeoTopNodeScene.h"
00015 
00016 FWGLEventHandler::FWGLEventHandler(TGWindow *w, TObject *obj, TEveCaloLego* l):
00017    TEveLegoEventHandler(w, obj, l),
00018    m_viewer(0)
00019 {}
00020 
00021 void
00022 FWGLEventHandler::PopupContextMenu(TGLPhysicalShape* pshp,  Event_t *event, Int_t gx, Int_t gy)
00023 {
00024    // Popup context menu.
00025   
00026    if (event->fState & kKeyShiftMask && event->fState & kKeyControlMask)
00027    {
00028       TGLEventHandler::PopupContextMenu(pshp, event, gx, gy);
00029       return;
00030    }
00031   
00032    if (pshp)
00033    {
00034       SelectForClicked(event);
00035     
00036       if (pshp->GetLogical()) 
00037       {
00038          FWGeoTopNodeGLScene* js = dynamic_cast<FWGeoTopNodeGLScene*>(pshp->GetLogical()->GetScene());
00039          if (js) {
00040             js->GeoPopupMenu(gx, gy, m_viewer->viewerGL());
00041             return;
00042          }
00043       }
00044     
00045       openSelectedModelContextMenu_(gx,gy);
00046    }
00047 }
00048 
00049 Bool_t FWGLEventHandler::HandleButton(Event_t *event)
00050 {
00051    Bool_t res = TEveLegoEventHandler::HandleButton(event);
00052    if (m_viewer->requestGLHandlerPick() && event->fType == kButtonPress )
00053    {
00054        Int_t    x, y;
00055        Window_t childdum;
00056        gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), fGLViewer->GetGLWidget()->GetId(),event->fX, event->fY, x, y, childdum);                fGLViewer->RequestSelect(event->fX, event->fY);
00057        if (fGLViewer->GetSelRec().GetN() > 0 ) 
00058          {
00059            TGLVector3 v(event->fX, event->fY, 0.5*fGLViewer->GetSelRec().GetMinZ());
00060            fGLViewer->CurrentCamera().WindowToViewport(v);
00061            v = fGLViewer->CurrentCamera().ViewportToWorld(v);
00062            FW3DViewBase* v3d = dynamic_cast<FW3DViewBase*>(m_viewer);
00063            v3d->setCurrentDMTVertex(v.X(), v.Y(), v.Z());
00064          }
00065    }
00066 
00067    return res;
00068 }
00069 
00070 Bool_t FWGLEventHandler::HandleKey(Event_t *event)
00071 {
00072    UInt_t keysym;
00073    char tmp[2];
00074    gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
00075 
00076    if (keysym == kKey_Enter || keysym == kKey_Return || keysym == kKey_Space)
00077    {
00078       if (event->fType == kGKeyPress)
00079       {
00080          Int_t    x, y;
00081          Window_t childdum;
00082          gVirtualX->TranslateCoordinates(fGLViewer->GetGLWidget()->GetId(), gClient->GetDefaultRoot()->GetId(),
00083                                          event->fX, event->fY, x, y, childdum);
00084 
00085          fGLViewer->RequestSelect(event->fX, event->fY);
00086          PopupContextMenu(fGLViewer->GetSelRec().GetPhysShape(), event, x, y);
00087       }
00088       return kTRUE;
00089    }
00090    else {
00091       return TEveLegoEventHandler::HandleKey(event);
00092 
00093    }
00094 }
00095 
00096 Bool_t FWGLEventHandler::HandleFocusChange(Event_t *event)
00097 {
00098    // Handle generic Event_t type 'event' - provided to catch focus changes
00099    // and terminate any interaction in viewer.
00100 
00101    if (m_viewer->viewer() && event->fType == kFocusOut)
00102       TEveGedEditor::ElementChanged(m_viewer->viewer());
00103 
00104    return TGLEventHandler::HandleFocusChange(event);
00105 }
00106 
00107 //______________________________________________________________________________
00108 Bool_t FWGLEventHandler::HandleCrossing(Event_t *event)
00109 {
00110    // Handle generic Event_t type 'event' - provided to catch focus changes
00111    // and terminate any interaction in viewer.
00112 
00113    if (m_viewer->viewer() && event->fType == kLeaveNotify)
00114       TEveGedEditor::ElementChanged(m_viewer->viewer());
00115 
00116    return TGLEventHandler::HandleCrossing(event);
00117 }