Go to the documentation of this file.00001 #include "Fireworks/Core/interface/FWViewContextMenuHandlerGL.h"
00002
00003 #include "TEveViewer.h"
00004 #include "TGLViewer.h"
00005 #include "TGLAnnotation.h"
00006 #include "TGLWidget.h"
00007
00008 #include "Fireworks/Core/interface/FWModelId.h"
00009 #include "Fireworks/Core/interface/FWEventItem.h"
00010
00011 FWViewContextMenuHandlerGL::FWViewContextMenuHandlerGL(TEveViewer* v):
00012 m_viewer(v),
00013 m_pickCameraCenter(false)
00014 {
00015 }
00016
00017 void
00018 FWViewContextMenuHandlerGL::init(FWViewContextMenuHandlerBase::MenuEntryAdder& adder)
00019 {
00020 adder.addEntry("Add Annotation");
00021 if (m_pickCameraCenter)
00022 {
00023 adder.addEntry("Set Camera Center");
00024 adder.addEntry("Reset Camera Center");
00025 }
00026 }
00027
00028 void
00029 FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId &id, int iX, int iY)
00030 {
00031 TGLViewer* v = m_viewer->GetGLViewer();
00032
00033 Window_t wdummy;
00034 Int_t x,y;
00035 gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
00036 TGLVector3 pnt(x, y, 0.5*v->GetSelRec().GetMinZ());
00037 v->CurrentCamera().WindowToViewport(pnt);
00038 pnt = v->CurrentCamera().ViewportToWorld(pnt);
00039
00040 switch (iEntryIndex)
00041 {
00042 case kAnnotate:
00043 {
00044 TGFrame* f = v->GetGLWidget();
00045 gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), f->GetId(), iX, iY, x, y, wdummy);
00046
00047 std::string name = id.item()->modelName(id.index());
00048 if (id.item()->haveInterestingValue())
00049 name += ", " + id.item()->modelInterestingValueAsString(id.index());
00050
00051 TGLAnnotation* an = new TGLAnnotation(v, name.c_str(), x*1.f/f->GetWidth(), 1 - y*1.f/f->GetHeight(), pnt);
00052 an->SetUseColorSet(true);
00053 an->SetTextSize(0.03);
00054 break;
00055 }
00056 case kCameraCenter:
00057 {
00058 v->CurrentCamera().SetExternalCenter(true);
00059 v->SetDrawCameraCenter(true);
00060 v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
00061 break;
00062 }
00063 case kResetCameraCenter:
00064 {
00065 v->CurrentCamera().SetExternalCenter(false);
00066 v->SetDrawCameraCenter(false);
00067 break;
00068 }
00069 }
00070 }