CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 #include "TVirtualX.h"
10 
14 
20 
22 
24  adder.addEntry("Add Annotation", kAnnotate);
26  const char* p = id.item()->purpose().c_str();
27  bool enabled = (strstr(p, "Beam Spot") || strstr(p, "Vertices"));
28  adder.addEntry("Use As Projection Origin", kCameraCenter, enabled);
29  adder.addEntry("Reset Projection Origin", kResetCameraCenter, enabled);
30  } else {
31  adder.addEntry("Set Camera Center", kCameraCenter);
32  adder.addEntry("Reset Camera Center", kResetCameraCenter);
33  }
34 }
35 
36 void FWViewContextMenuHandlerGL::select(int iEntryIndex, const FWModelId& id, int iX, int iY) {
37  TGLViewer* v = m_view->viewerGL();
38 
39  Window_t wdummy;
40  Int_t x, y;
41  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), v->GetGLWidget()->GetId(), iX, iY, x, y, wdummy);
42 
43  TGLVector3 pnt(x, y, 0.5 * v->GetSelRec().GetMinZ());
44  v->CurrentCamera().WindowToViewport(pnt);
45  pnt = v->CurrentCamera().ViewportToWorld(pnt);
46 
47  switch (iEntryIndex) {
48  case kAnnotate: {
49  TGFrame* f = v->GetGLWidget();
50  gVirtualX->TranslateCoordinates(gClient->GetDefaultRoot()->GetId(), f->GetId(), iX, iY, x, y, wdummy);
51 
52  std::string name = id.item()->modelName(id.index());
53  if (id.item()->haveInterestingValue())
54  name += ", " + id.item()->modelInterestingValueAsString(id.index());
55 
56  TGLAnnotation* an =
57  new TGLAnnotation(v, name.c_str(), x * 1.f / f->GetWidth(), 1 - y * 1.f / f->GetHeight(), pnt);
58  an->SetUseColorSet(true);
59  an->SetTextSize(0.03);
60  break;
61  }
62  case kCameraCenter: {
64  FWModelId mId = *(m_view->context().selectionManager()->selected().begin());
65  const FWItemValueGetter& valueGetter = mId.item()->valueGetter();
66  TEveVector center;
67  center.fX = valueGetter.valueFor(mId.item()->modelData(mId.index()), 0);
68  center.fY = valueGetter.valueFor(mId.item()->modelData(mId.index()), 1);
69  center.fZ = valueGetter.valueFor(mId.item()->modelData(mId.index()), 2);
70 
71  FWRPZView* pv = static_cast<FWRPZView*>(m_view);
72  pv->shiftOrigin(center);
73  } else {
74  v->CurrentCamera().SetExternalCenter(true);
75  v->CurrentCamera().SetCenterVec(pnt.X(), pnt.Y(), pnt.Z());
76  v->SetDrawCameraCenter(true);
77  }
78  break;
79  }
80  case kResetCameraCenter: {
82  FWRPZView* pv = static_cast<FWRPZView*>(m_view);
83  pv->resetOrigin();
84  }
85 
86  v->CurrentCamera().SetExternalCenter(false);
87  v->SetDrawCameraCenter(false);
88  break;
89  }
90  }
91 }
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:112
void select(int iEntryIndex, const FWModelId &id, int iX, int iY) override
TGLViewer * viewerGL() const
Definition: FWEveView.cc:177
void resetOrigin()
Definition: FWRPZView.cc:239
static bool isProjected(int)
Definition: FWViewType.cc:100
int index() const
Definition: FWModelId.h:41
void init(FWViewContextMenuHandlerBase::MenuEntryAdder &, const FWModelId &id) override
Called when have to add entries to the context menu.
FWSelectionManager * selectionManager() const
Definition: Context.h:54
void shiftOrigin(TEveVector &center)
Definition: FWRPZView.cc:223
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:466
const FWEventItem * item() const
Definition: FWModelId.h:39
FWViewType::EType typeId() const
Definition: FWViewBase.h:42