Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLManipSet.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Feb 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TGLManipSet.h"
13 
14 #include "TGLTransManip.h"
15 #include "TGLScaleManip.h"
16 #include "TGLRotateManip.h"
17 
18 #include "TGLPhysicalShape.h"
19 #include "TGLRnrCtx.h"
20 #include "TGLSelectRecord.h"
21 
22 #include "TGLIncludes.h"
23 
24 #include <KeySymbols.h>
25 #include <TVirtualX.h>
26 
27 /** \class TGLManipSet
28 \ingroup opengl
29 
30 Combine all available manipulators in a collection.
31 
32 At first I wanted to merge them back into TGLManip (to have a
33 single class) but then it seemed somehow messy.
34 Maybe next time.
35 */
36 
37 ClassImp(TGLManipSet);
38 
39 TGLManipSet::TGLManipSet() :
40  TGLOverlayElement(kViewer),
41  fType (kTrans),
42  fDrawBBox (kFALSE)
43 {
44  // Constructor.
45 
46  fManip[kTrans] = new TGLTransManip;
47  fManip[kScale] = new TGLScaleManip;
48  fManip[kRotate] = new TGLRotateManip;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Destructor.
53 
54 TGLManipSet::~TGLManipSet()
55 {
56  for (Int_t i=kTrans; i<kEndType; ++i)
57  delete fManip[i];
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Set phys-shape, override of virtual from TGLPShapeRef.
62 /// Forward to all managed manipulators.
63 
64 void TGLManipSet::SetPShape(TGLPhysicalShape* shape)
65 {
66  TGLPShapeRef::SetPShape(shape);
67  for (Int_t i=kTrans; i<kEndType; ++i)
68  fManip[i]->Attach(shape);
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Mouse has entered this element.
73 /// Always accept.
74 
75 Bool_t TGLManipSet::MouseEnter(TGLOvlSelectRecord& /*selRec*/)
76 {
77  TGLManip* manip = GetCurrentManip();
78  manip->SetActive(kFALSE);
79  manip->SetSelectedWidget(0);
80  return kTRUE;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Handle overlay event.
85 /// Return TRUE if event was handled.
86 
87 Bool_t TGLManipSet::Handle(TGLRnrCtx& rnrCtx,
88  TGLOvlSelectRecord& selRec,
89  Event_t* event)
90 {
91  TGLManip* manip = GetCurrentManip();
92 
93  switch (event->fType)
94  {
95  case kButtonPress:
96  {
97  return manip->HandleButton(*event, rnrCtx.RefCamera());
98  }
99  case kButtonRelease:
100  {
101  manip->SetActive(kFALSE);
102  return kTRUE;
103  }
104  case kMotionNotify:
105  {
106  if (manip->GetActive())
107  return manip->HandleMotion(*event, rnrCtx.RefCamera());
108  if (selRec.GetCurrItem() != manip->GetSelectedWidget())
109  {
110  manip->SetSelectedWidget(selRec.GetCurrItem());
111  return kTRUE;
112  }
113  return kFALSE;
114  }
115  case kGKeyPress:
116  {
117  switch (rnrCtx.GetEventKeySym())
118  {
119  case kKey_V: case kKey_v:
120  SetManipType(kTrans);
121  return kTRUE;
122  case kKey_C: case kKey_c:
123  SetManipType(kRotate);
124  return kTRUE;
125  case kKey_X: case kKey_x:
126  SetManipType(kScale);
127  return kTRUE;
128  default:
129  return kFALSE;
130  }
131  }
132  default:
133  {
134  return kFALSE;
135  }
136  }
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Mouse has left the element.
141 
142 void TGLManipSet::MouseLeave()
143 {
144  TGLManip* manip = GetCurrentManip();
145  manip->SetActive(kFALSE);
146  manip->SetSelectedWidget(0);
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Render the manipulator and bounding-box.
151 
152 void TGLManipSet::Render(TGLRnrCtx& rnrCtx)
153 {
154  if (fPShape == 0)
155  return;
156 
157  if (rnrCtx.Selection())
158  {
159  TGLUtil::SetDrawQuality(12);
160  fManip[fType]->Draw(rnrCtx.RefCamera());
161  TGLUtil::ResetDrawQuality();
162  } else {
163  fManip[fType]->Draw(rnrCtx.RefCamera());
164  }
165 
166  if (fDrawBBox && ! rnrCtx.Selection())
167  {
168  // TODO: This must be replaced by some color in rnrCtx,
169  // like def-overlay-color, background-color, foreground-color
170  // Or at least bkgcol ... i can then find high contrast.
171  TGLUtil::Color(rnrCtx.ColorSet().Markup());
172  glDisable(GL_LIGHTING);
173  fPShape->BoundingBox().Draw();
174  glEnable(GL_LIGHTING);
175  }
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Set manipulator type, range checked.
180 
181 void TGLManipSet::SetManipType(Int_t type)
182 {
183  if (type < 0 || type >= kEndType)
184  return;
185  fType = (EManip) type;
186 }