Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Fireworks/Core/interface/FWViewContextMenuHandlerGL.h"
0002 
0003 #include "TClass.h"
0004 #include "TEveViewer.h"
0005 #include "TGLViewer.h"
0006 #include "TGLAnnotation.h"
0007 #include "TGLWidget.h"
0008 #include "TEveVector.h"
0009 #include "TVirtualX.h"
0010 
0011 #include "Fireworks/Core/interface/FWModelId.h"
0012 #include "Fireworks/Core/interface/FWEventItem.h"
0013 #include "Fireworks/Core/interface/FWEveView.h"
0014 
0015 #include "Fireworks/Core/interface/FWItemValueGetter.h"
0016 #include "Fireworks/Core/interface/FWSelectionManager.h"
0017 #include "Fireworks/Core/interface/FWEventItem.h"
0018 #include "Fireworks/Core/interface/Context.h"
0019 #include "Fireworks/Core/interface/FWRPZView.h"
0020 
0021 FWViewContextMenuHandlerGL::FWViewContextMenuHandlerGL(FWEveView* v) : m_view(v) {}
0022 
0023 void FWViewContextMenuHandlerGL::init(FWViewContextMenuHandlerBase::MenuEntryAdder& adder, const FWModelId& id) {
0024   adder.addEntry("Add Annotation", kAnnotate);
0025   if (FWViewType::isProjected(m_view->typeId())) {
0026     const char* p = id.item()->purpose().c_str();
0027     bool enabled = (strstr(p, "Beam Spot") || strstr(p, "Vertices"));
0028     adder.addEntry("Use As Projection Origin", kCameraCenter, enabled);
0029     adder.addEntry("Reset Projection Origin", kResetCameraCenter, enabled);
0030   } else {
0031     adder.addEntry("Set Camera Center", kCameraCenter);
0032     adder.addEntry("Reset Camera Center", kResetCameraCenter);
0033   }
0034 }
0035 
0036 void FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId& id, int iX, int iY) {
0037   TGLViewer* v = m_view->viewerGL();
0038 
0039   Window_t wdummy;
0040   Int_t x, y;
0041   gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
0042 
0043   TGLVector3 pnt(x, y, 0.5 * v->GetSelRec().GetMinZ());
0044   v->CurrentCamera().WindowToViewport(pnt);
0045   pnt = v->CurrentCamera().ViewportToWorld(pnt);
0046 
0047   switch (iEntryIndex) {
0048     case kAnnotate: {
0049       TGFrame* f = v->GetGLWidget();
0050       gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), f->GetId(), iX, iY, x, y, wdummy);
0051 
0052       std::string name = id.item()->modelName(id.index());
0053       if (id.item()->haveInterestingValue())
0054         name += ", " + id.item()->modelInterestingValueAsString(id.index());
0055 
0056       TGLAnnotation* an =
0057           new TGLAnnotation(v, name.c_str(), x * 1.f / f->GetWidth(), 1 - y * 1.f / f->GetHeight(), pnt);
0058       an->SetUseColorSet(true);
0059       an->SetTextSize(0.03);
0060       break;
0061     }
0062     case kCameraCenter: {
0063       if (FWViewType::isProjected(m_view->typeId())) {
0064         FWModelId mId = *(m_view->context().selectionManager()->selected().begin());
0065         const FWItemValueGetter& valueGetter = mId.item()->valueGetter();
0066         TEveVector center;
0067         center.fX = valueGetter.valueFor(mId.item()->modelData(mId.index()), 0);
0068         center.fY = valueGetter.valueFor(mId.item()->modelData(mId.index()), 1);
0069         center.fZ = valueGetter.valueFor(mId.item()->modelData(mId.index()), 2);
0070 
0071         FWRPZView* pv = static_cast<FWRPZView*>(m_view);
0072         pv->shiftOrigin(center);
0073       } else {
0074         v->CurrentCamera().SetExternalCenter(true);
0075         v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
0076         v->SetDrawCameraCenter(true);
0077       }
0078       break;
0079     }
0080     case kResetCameraCenter: {
0081       if (FWViewType::isProjected(m_view->typeId())) {
0082         FWRPZView* pv = static_cast<FWRPZView*>(m_view);
0083         pv->resetOrigin();
0084       }
0085 
0086       v->CurrentCamera().SetExternalCenter(false);
0087       v->SetDrawCameraCenter(false);
0088       break;
0089     }
0090   }
0091 }