CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 
00026 void 
00027 FWViewContextMenuHandlerGL::init(FWViewContextMenuHandlerBase::MenuEntryAdder& adder, const FWModelId &id)
00028 {
00029    adder.addEntry("Add Annotation", kAnnotate);
00030    if (FWViewType::isProjected(m_view->typeId()))
00031    { 
00032       const char* p  = id.item()->purpose().c_str();
00033       bool enabled = (strstr(p, "Beam Spot") || strstr(p, "Vertices") );
00034       adder.addEntry("Use As Projection Origin", kCameraCenter, enabled);
00035       adder.addEntry("Reset Projection Origin", kResetCameraCenter, enabled);
00036    }
00037    else
00038    { 
00039       adder.addEntry("Set Camera Center", kCameraCenter);
00040       adder.addEntry("Reset Camera Center", kResetCameraCenter);
00041    }   
00042 }
00043 
00044 void 
00045 FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId &id, int iX, int iY)
00046 {
00047    TGLViewer* v = m_view->viewerGL();
00048 
00049    Window_t wdummy;
00050    Int_t x,y;
00051    gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);   
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          TEveVector center;
00075          if (FWViewType::isProjected(m_view->typeId()))
00076          {
00077 
00078             // AMT:: find way to get values without using FWItemValueGetter
00079 
00080             FWModelId mId = *(m_view->context().selectionManager()->selected().begin());
00081             const FWEventItem* item = mId.item();
00082 
00083             bool bs = strstr(item->purpose().c_str(), "Beam Spot");
00084             std::vector<std::pair<std::string,std::string> > func;
00085             func.push_back(std::pair<std::string,std::string>("", "cm"));
00086             {  
00087                func.back().first = bs ? "x0" : "x";
00088                FWItemValueGetter valueGetter(ROOT::Reflex::Type::ByTypeInfo(*(item->modelType()->GetTypeInfo())), func);
00089                center.fX = valueGetter.valueFor(item->modelData(mId.index())); 
00090             }
00091             {
00092                func.back().first = bs ? "y0" : "y";
00093                FWItemValueGetter valueGetter(ROOT::Reflex::Type::ByTypeInfo(*(item->modelType()->GetTypeInfo())), func);
00094                center.fY = valueGetter.valueFor(item->modelData(mId.index()));
00095             }
00096             {  
00097                func.back().first = bs ? "z0" : "z";
00098                FWItemValueGetter valueGetter(ROOT::Reflex::Type::ByTypeInfo(*(item->modelType()->GetTypeInfo())), func);
00099                center.fZ = valueGetter.valueFor(item->modelData(mId.index()));
00100             }
00101 
00102             FWRPZView* pv = static_cast<FWRPZView*>(m_view);
00103             pv->shiftOrigin(center);
00104          }
00105 
00106          else
00107          {
00108             v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
00109             v->CurrentCamera().SetExternalCenter(true);
00110             v->SetDrawCameraCenter(true);
00111          }
00112 
00113          break;
00114       }
00115       case kResetCameraCenter:
00116       { 
00117          if (FWViewType::isProjected(m_view->typeId()))
00118          {
00119             FWRPZView* pv = static_cast<FWRPZView*>(m_view);
00120             pv->resetOrigin();
00121          }
00122 
00123          v->CurrentCamera().SetExternalCenter(false);
00124          v->SetDrawCameraCenter(false);
00125          break;
00126       }
00127    }
00128 }