CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWViewContextMenuHandlerGL.cc
Go to the documentation of this file.
2 
3 #include "TClass.h"
4 #include "TEveViewer.h"
5 #include "TGLViewer.h"
6 #include "TGLAnnotation.h"
7 #include "TGLWidget.h"
8 #include "TEveVector.h"
9 
13 
14 
20 
22  m_view(v)
23 {}
24 
25 void
27 {
28  adder.addEntry("Add Annotation", kAnnotate);
30  {
31  const char* p = id.item()->purpose().c_str();
32  bool enabled = (strstr(p, "Beam Spot") || strstr(p, "Vertices") );
33  adder.addEntry("Use As Projection Origin", kCameraCenter, enabled);
34  adder.addEntry("Reset Projection Origin", kResetCameraCenter, enabled);
35  }
36  else
37  {
38  adder.addEntry("Set Camera Center", kCameraCenter);
39  adder.addEntry("Reset Camera Center", kResetCameraCenter);
40  }
41 }
42 
43 void
44 FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId &id, int iX, int iY)
45 {
46  TGLViewer *v = m_view->viewerGL();
47 
48  Window_t wdummy;
49  Int_t x, y;
50  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
51 
52  TGLVector3 pnt(x, y, 0.5*v->GetSelRec().GetMinZ());
53  v->CurrentCamera().WindowToViewport(pnt);
54  pnt = v->CurrentCamera().ViewportToWorld(pnt);
55 
56  switch (iEntryIndex)
57  {
58  case kAnnotate:
59  {
60  TGFrame* f = v->GetGLWidget();
61  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), f->GetId(), iX, iY, x, y, wdummy);
62 
63  std::string name = id.item()->modelName(id.index());
64  if (id.item()->haveInterestingValue())
65  name += ", " + id.item()->modelInterestingValueAsString(id.index());
66 
67  TGLAnnotation *an = new TGLAnnotation(v, name.c_str(), x*1.f/f->GetWidth(), 1 - y*1.f/f->GetHeight(), pnt);
68  an->SetUseColorSet(true);
69  an->SetTextSize(0.03);
70  break;
71  }
72  case kCameraCenter:
73  {
75  {
76  FWModelId mId = *(m_view->context().selectionManager()->selected().begin());
77  const FWItemValueGetter& valueGetter = mId.item()->valueGetter();
78  TEveVector center;
79  center.fX = valueGetter.valueFor(mId.item()->modelData(mId.index()), 0);
80  center.fY = valueGetter.valueFor(mId.item()->modelData(mId.index()), 1);
81  center.fZ = valueGetter.valueFor(mId.item()->modelData(mId.index()), 2);
82 
83  FWRPZView* pv = static_cast<FWRPZView*>(m_view);
84  pv->shiftOrigin(center);
85  }
86  else
87  {
88  v->CurrentCamera().SetExternalCenter(true);
89  v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
90  v->SetDrawCameraCenter(true);
91  }
92  break;
93  }
94  case kResetCameraCenter:
95  {
97  {
98  FWRPZView* pv = static_cast<FWRPZView*>(m_view);
99  pv->resetOrigin();
100  }
101 
102  v->CurrentCamera().SetExternalCenter(false);
103  v->SetDrawCameraCenter(false);
104  break;
105  }
106  }
107 }
const std::set< FWModelId > & selected() const
const FWItemValueGetter & valueGetter() const
one value from the model which is normally used for the popup
Definition: FWEventItem.h:118
virtual void select(int iEntryIndex, const FWModelId &id, int iX, int iY)
TGLViewer * viewerGL() const
Definition: FWEveView.cc:197
void resetOrigin()
Definition: FWRPZView.cc:245
static bool isProjected(int)
Definition: FWViewType.cc:128
int index() const
Definition: FWModelId.h:49
double f[11][100]
FWSelectionManager * selectionManager() const
Definition: Context.h:57
void shiftOrigin(TEveVector &center)
Definition: FWRPZView.cc:227
virtual void init(FWViewContextMenuHandlerBase::MenuEntryAdder &, const FWModelId &id)
Called when have to add entries to the context menu.
const fireworks::Context & context()
Definition: FWEveView.h:64
double valueFor(const void *, int idx) const
int addEntry(const char *iEntryName, int idx, bool enable=true)
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:567
Definition: DDAxes.h:10
const FWEventItem * item() const
Definition: FWModelId.h:44
FWViewType::EType typeId() const
Definition: FWViewBase.h:41