CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Fireworks/Core/src/FWViewContextMenuHandlerGL.cc

Go to the documentation of this file.
00001 #include "Fireworks/Core/interface/FWViewContextMenuHandlerGL.h"
00002 
00003 #include "TClass.h"
00004 #include "TEveViewer.h"
00005 #include "TGLViewer.h"
00006 #include "TGLAnnotation.h"
00007 #include "TGLWidget.h"
00008 #include "TEveVector.h"
00009 
00010 #include "Fireworks/Core/interface/FWModelId.h"
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012 #include "Fireworks/Core/interface/FWEveView.h"
00013 
00014 
00015 #include "Fireworks/Core/interface/FWItemValueGetter.h"
00016 #include "Fireworks/Core/interface/FWSelectionManager.h"
00017 #include "Fireworks/Core/interface/FWEventItem.h"
00018 #include "Fireworks/Core/interface/Context.h"
00019 #include "Fireworks/Core/interface/FWRPZView.h"
00020 
00021 FWViewContextMenuHandlerGL::FWViewContextMenuHandlerGL( FWEveView* v) :
00022    m_view(v)
00023 {}
00024 
00025 void 
00026 FWViewContextMenuHandlerGL::init(FWViewContextMenuHandlerBase::MenuEntryAdder& adder, const FWModelId &id)
00027 {
00028    adder.addEntry("Add Annotation", kAnnotate);
00029    if (FWViewType::isProjected(m_view->typeId()))
00030    { 
00031       const char* p  = id.item()->purpose().c_str();
00032       bool enabled = (strstr(p, "Beam Spot") || strstr(p, "Vertices") );
00033       adder.addEntry("Use As Projection Origin", kCameraCenter, enabled);
00034       adder.addEntry("Reset Projection Origin", kResetCameraCenter, enabled);
00035    }
00036    else
00037    { 
00038       adder.addEntry("Set Camera Center", kCameraCenter);
00039       adder.addEntry("Reset Camera Center", kResetCameraCenter);
00040    }   
00041 }
00042 
00043 void 
00044 FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId &id, int iX, int iY)
00045 {
00046    TGLViewer *v = m_view->viewerGL();
00047 
00048    Window_t wdummy;
00049    Int_t    x, y;
00050    gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
00051 
00052    TGLVector3 pnt(x, y, 0.5*v->GetSelRec().GetMinZ());
00053    v->CurrentCamera().WindowToViewport(pnt);
00054    pnt = v->CurrentCamera().ViewportToWorld(pnt);
00055 
00056    switch (iEntryIndex)
00057    {
00058       case kAnnotate:
00059       {
00060          TGFrame* f = v->GetGLWidget();
00061          gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), f->GetId(), iX, iY, x, y, wdummy);
00062 
00063          std::string name = id.item()->modelName(id.index());
00064          if (id.item()->haveInterestingValue())
00065             name += ", " + id.item()->modelInterestingValueAsString(id.index());
00066 
00067          TGLAnnotation *an = new TGLAnnotation(v, name.c_str(),  x*1.f/f->GetWidth(), 1 - y*1.f/f->GetHeight(), pnt);
00068          an->SetUseColorSet(true);
00069          an->SetTextSize(0.03);
00070          break;
00071       }
00072       case kCameraCenter:
00073       {
00074          if (FWViewType::isProjected(m_view->typeId()))
00075          {
00076             FWModelId mId = *(m_view->context().selectionManager()->selected().begin());
00077             const FWItemValueGetter& valueGetter = mId.item()->valueGetter();
00078             TEveVector center;
00079             center.fX = valueGetter.valueFor(mId.item()->modelData(mId.index()), 0);
00080             center.fY = valueGetter.valueFor(mId.item()->modelData(mId.index()), 1);
00081             center.fZ = valueGetter.valueFor(mId.item()->modelData(mId.index()), 2);
00082 
00083             FWRPZView* pv = static_cast<FWRPZView*>(m_view);
00084             pv->shiftOrigin(center);
00085          }
00086          else
00087          {
00088             v->CurrentCamera().SetExternalCenter(true);
00089             v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
00090             v->SetDrawCameraCenter(true);
00091          }
00092          break;
00093       }
00094       case kResetCameraCenter:
00095       {
00096          if (FWViewType::isProjected(m_view->typeId()))
00097          {
00098             FWRPZView* pv = static_cast<FWRPZView*>(m_view);
00099             pv->resetOrigin();
00100          }
00101 
00102          v->CurrentCamera().SetExternalCenter(false);
00103          v->SetDrawCameraCenter(false);
00104          break;
00105       }
00106    }
00107 }