CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
CmsAnnotation Class Reference

#include <CmsAnnotation.h>

Inheritance diagram for CmsAnnotation:

Public Member Functions

virtual void addTo (FWConfiguration &) const
 
 CmsAnnotation (TGLViewerBase *parent, Float_t posx, Float_t posy)
 
bool getAllowDestroy () const
 
Float_t getSize () const
 
bool getVisible () const
 
virtual Bool_t Handle (TGLRnrCtx &rnrCtx, TGLOvlSelectRecord &selRec, Event_t *event)
 
virtual Bool_t MouseEnter (TGLOvlSelectRecord &selRec)
 
virtual void MouseLeave ()
 
virtual void Render (TGLRnrCtx &rnrCtx)
 
void setAllowDestroy (bool x)
 
virtual void setFrom (const FWConfiguration &)
 
void setSize (Float_t x)
 
void setVisible (bool x)
 
virtual ~CmsAnnotation ()
 

Private Types

enum  EDrag { kMove, kResize, kNone }
 

Private Member Functions

 CmsAnnotation (const CmsAnnotation &)
 
const CmsAnnotationoperator= (const CmsAnnotation &)
 

Private Attributes

bool fActive
 
bool fAllowDestroy
 
EDrag fDrag
 last mouse position More...
 
Int_t fMouseX
 
Int_t fMouseY
 
TGLViewer * fParent
 
Float_t fPosX
 
Float_t fPosY
 
Float_t fSize
 
Float_t fSizeDrag
 relative size to viewport width More...
 

Detailed Description

Definition at line 9 of file CmsAnnotation.h.

Member Enumeration Documentation

enum CmsAnnotation::EDrag
private
Enumerator
kMove 
kResize 
kNone 

Definition at line 11 of file CmsAnnotation.h.

Constructor & Destructor Documentation

CmsAnnotation::CmsAnnotation ( TGLViewerBase *  parent,
Float_t  posx,
Float_t  posy 
)

Definition at line 16 of file CmsAnnotation.cc.

References fParent.

16  :
17  TGLOverlayElement(TGLOverlayElement::kUser),
18  fPosX(posx), fPosY(posy),
19  fMouseX(0), fMouseY(0),
20  fDrag(kNone),
21  fParent(0),
22  fSize(0.2),
23  fSizeDrag(0.0),
24  fActive(false),
25  fAllowDestroy(false)
26 {
27  // Constructor.
28  // Create annotation as plain text
29 
30  parent->AddOverlayElement(this);
31  fParent = (TGLViewer*)parent;
32 }
list parent
Definition: dbtoconf.py:74
TGLViewer * fParent
Definition: CmsAnnotation.h:49
EDrag fDrag
last mouse position
Definition: CmsAnnotation.h:47
Float_t fSizeDrag
relative size to viewport width
Definition: CmsAnnotation.h:52
CmsAnnotation::~CmsAnnotation ( )
virtual

Definition at line 35 of file CmsAnnotation.cc.

References fParent.

36 {
37  // Destructor.
38 
39  fParent->RemoveOverlayElement(this);
40 }
TGLViewer * fParent
Definition: CmsAnnotation.h:49
CmsAnnotation::CmsAnnotation ( const CmsAnnotation )
private

Member Function Documentation

void CmsAnnotation::addTo ( FWConfiguration iTo) const
virtual

Definition at line 328 of file CmsAnnotation.cc.

References FWConfiguration::addKeyValue(), fPosX, fPosY, fSize, alignCSCRings::s, x, and detailsBasic3DVector::y.

Referenced by FWEveView::addTo().

329 {
330  std::stringstream s;
331  s<<fSize;
332  iTo.addKeyValue("LogoSize",FWConfiguration(s.str()));
333 
334  std::stringstream x;
335  x<<fPosX;
336  iTo.addKeyValue("LogoPosX",FWConfiguration(x.str()));
337 
338  std::stringstream y;
339  y<<fPosY;
340  iTo.addKeyValue("LogoPosY",FWConfiguration(y.str()));
341 }
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: DDAxes.h:10
bool CmsAnnotation::getAllowDestroy ( ) const
inline

Definition at line 36 of file CmsAnnotation.h.

References fAllowDestroy.

36 { return fAllowDestroy; }
Float_t CmsAnnotation::getSize ( ) const
inline

Definition at line 30 of file CmsAnnotation.h.

References fSize.

30 { return fSize; }
bool CmsAnnotation::getVisible ( ) const

Definition at line 312 of file CmsAnnotation.cc.

313 {
314  return GetState() == TGLOverlayElement::kActive;
315 }
Bool_t CmsAnnotation::Handle ( TGLRnrCtx &  rnrCtx,
TGLOvlSelectRecord &  selRec,
Event_t *  event 
)
virtual

Definition at line 211 of file CmsAnnotation.cc.

References f, fDrag, fMouseX, fMouseY, fParent, fPosX, fPosY, fSize, fSizeDrag, h, kMove, kNone, kResize, siStripFEDMonitor_P5_cff::Max, siStripFEDMonitor_P5_cff::Min, corrVsCorr::rx, corrVsCorr::ry, and w().

214 {
215  // Handle overlay event.
216  // Return TRUE if event was handled.
217 
218  if (selRec.GetN() < 2) return kFALSE;
219  int recID = selRec.GetItem(1);
220 
221  switch (event->fType)
222  {
223  case kButtonPress:
224  {
225  fMouseX = event->fX;
226  fMouseY = event->fY;
227  fDrag = (recID == kResize) ? kResize : kMove;
228  fSizeDrag = fSize;
229  return kTRUE;
230  }
231  case kButtonRelease:
232  {
233  fDrag = kNone;
234  if (recID == 7)
235  {
236  fParent->RequestDraw(rnrCtx.ViewerLOD());
237  delete this;
238  return kTRUE;
239  }
240  break;
241  }
242  case kMotionNotify:
243  {
244  const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
245  if (vp.Width() == 0 || vp.Height() == 0) return false;
246  if (fDrag != kNone)
247  {
248  if (fDrag == kMove)
249  {
250  fPosX += (Float_t)(event->fX - fMouseX) / vp.Width();
251  fPosY -= (Float_t)(event->fY - fMouseY) / vp.Height();
252  fMouseX = event->fX;
253  fMouseY = event->fY;
254 
255  Float_t h = fSize;
256  Float_t w = fSize/vp.Aspect();
257 
258  // Make sure we don't go offscreen (use fDraw variables set in draw)
259  if (fPosX < 0)
260  fPosX = 0;
261  else if (fPosX +w > 1.0f)
262  fPosX = 1.0f - w;
263  if (fPosY < h)
264  fPosY = h;
265  else if (fPosY > 1.0f)
266  fPosY = 1.0f;
267  }
268  else
269  {
270  using namespace TMath;
271  Float_t oovpw = 1.0f / vp.Width(), oovph = 1.0f / vp.Height();
272 
273  Float_t xw = oovpw * Min(Max(0, event->fX), vp.Width());
274  Float_t yw = oovph * Min(Max(0, vp.Height() - event->fY), vp.Height());
275 
276  Float_t rx = Max((xw - fPosX) / (oovpw * fMouseX - fPosX), 0.0f);
277  Float_t ry = Max((yw - fPosY) / (oovph*(vp.Height() - fMouseY) - fPosY), 0.0f);
278 
279  fSize = Max(fSizeDrag * Min(rx, ry), 0.01f);
280  }
281  }
282  return kTRUE;
283  }
284  default:
285  {
286  return kFALSE;
287  }
288  }
289 
290  return false;
291 }
double f[11][100]
TGLViewer * fParent
Definition: CmsAnnotation.h:49
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
EDrag fDrag
last mouse position
Definition: CmsAnnotation.h:47
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T w() const
Float_t fSizeDrag
relative size to viewport width
Definition: CmsAnnotation.h:52
Bool_t CmsAnnotation::MouseEnter ( TGLOvlSelectRecord &  selRec)
virtual

Definition at line 294 of file CmsAnnotation.cc.

References fActive.

295 {
296  // Mouse has entered overlay area.
297 
298  fActive = kTRUE;
299  return kTRUE;
300 }
void CmsAnnotation::MouseLeave ( )
virtual

Definition at line 303 of file CmsAnnotation.cc.

References fActive.

304 {
305  // Mouse has left overlay area.
306 
307  fActive = kFALSE;
308 }
const CmsAnnotation& CmsAnnotation::operator= ( const CmsAnnotation )
private
void CmsAnnotation::Render ( TGLRnrCtx &  rnrCtx)
virtual

Definition at line 44 of file CmsAnnotation.cc.

References a, newFWLiteAna::base, FWCheckBoxIcon::coreIcondir(), fActive, fAllowDestroy, fPosX, fPosY, fSize, i, kMove, kResize, alignCSCRings::s, and detailsBasic3DVector::z.

45 {
46  if (rnrCtx.GetCamera()->RefViewport().Width() == 0 ||
47  rnrCtx.GetCamera()->RefViewport().Height() == 0 ) return;
48 
49  static UInt_t ttid_black = 0;
50  static UInt_t ttid_white = 0;
51 
52  bool whiteBg = rnrCtx.ColorSet().Background().GetColorIndex() == kWhite;
53  UInt_t& ttid = whiteBg ? ttid_white : ttid_black;
54 
55  if ( (whiteBg == false && ttid == 0) || (whiteBg && ttid == 0))
56  {
57  TImage* imgs[3];
58  TString base = whiteBg ? "White" : "Black";
59  imgs[0] = TImage::Open(FWCheckBoxIcon::coreIcondir()+"CMSLogo" + base + "Bg.png");
60  imgs[1] = TImage::Open(FWCheckBoxIcon::coreIcondir()+"CMSLogo" + base + "BgM.png");
61  imgs[2] = TImage::Open(FWCheckBoxIcon::coreIcondir()+"CMSLogo" + base + "BgS.png");
62 
63  glGenTextures(1, &ttid);
64  glBindTexture(GL_TEXTURE_2D, ttid);
65 
66  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
67  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
68  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
69  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
70  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL,0);
71  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
72 
73 
74  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
75  glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
76 
77  for (int i=0; i < 3; i++)
78  glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, imgs[i]->GetWidth(), imgs[i]->GetHeight(), 0,
79  GL_BGRA, GL_UNSIGNED_BYTE, imgs[i]->GetArgbArray());
80 
81  glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
82 
83  for (int i=0; i < 3; i++)
84  delete imgs[i];
85  }
86 
87  glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT );
88  TGLCapabilitySwitch lights_off(GL_LIGHTING, kFALSE);
89 
90 
91  // reset matrix
92  glMatrixMode(GL_PROJECTION);
93  glPushMatrix();
94  glLoadIdentity();
95 
96  if (rnrCtx.Selection())
97  {
98  TGLRect rect(*rnrCtx.GetPickRectangle());
99  rnrCtx.GetCamera()->WindowToViewport(rect);
100  gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
101  (Int_t*) rnrCtx.GetCamera()->RefViewport().CArr());
102  }
103  const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
104  glOrtho(vp.X(), vp.Width(), vp.Y(), vp.Height(), 0, 1);
105  glMatrixMode(GL_MODELVIEW);
106  glPushMatrix();
107  glLoadIdentity();
108 
109  // move to pos
110  Float_t posX = vp.Width() * fPosX;
111  Float_t posY = vp.Height() * fPosY;
112  glTranslatef(posX, posY, -0.99);
113 
114  glDisable(GL_DEPTH_TEST);
115  glEnable(GL_BLEND);
116  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
117 
118  glEnable(GL_TEXTURE_2D);
119  glBindTexture(GL_TEXTURE_2D, ttid);
120 
121  glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
122 
123  // logo
124  glPushName(kMove);
125  TGLUtil::Color(rnrCtx.ColorSet().Background().GetColorIndex());
126  glBegin(GL_QUADS);
127  Float_t z = 0.9;
128  Float_t a = fSize * vp.Height();
129  glTexCoord2f(0, 1); glVertex3f( 0, -a, z);
130  glTexCoord2f(1, 1); glVertex3f( a, -a, z);
131  glTexCoord2f(1, 0); glVertex3f( a, 0, z);
132  glTexCoord2f(0, 0); glVertex3f( 0, 0, z);
133  glEnd();
134  glPopName();
135 
136 
137  glDisable(GL_TEXTURE_2D);
138 
139  if (fActive)
140  {
141  // resize button
142  glPushMatrix();
143  glBegin(GL_QUADS);
144  Float_t a = fSize * vp.Height();
145  TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 95);
146  glTexCoord2f(0, 1); glVertex3f( 0, -a, z);
147  glTexCoord2f(1, 1); glVertex3f( a, -a, z);
148  glTexCoord2f(1, 0); glVertex3f( a, 0, z);
149  glTexCoord2f(0, 0); glVertex3f( 0, 0, z);
150  glEnd();
151 
152  glTranslatef(a, -a, 0);
153  a *= 0.2;
154  z = 0.95;
155  glPushName(kResize);
156  TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 100);
157  glBegin(GL_QUADS);
158  glVertex3f( 0, 0, z);
159  glVertex3f( 0, a, z);
160  glVertex3f(-a, a, z);
161  glVertex3f(-a, 0, z);
162  glEnd();
163  {
164  glTranslatef(-a/3, a/3, 0);
165  glBegin(GL_LINES);
166  TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 40);
167  Float_t s = a / 3;
168  glVertex3f( 0, 0, z); glVertex3f( 0, s, z);
169  glVertex3f( 0, 0, z); glVertex3f( -s, 0, z);
170  glEnd();
171  }
172  glPopName();
173  glPopMatrix();
174 
175  // delete
176  if (fAllowDestroy)
177  {
178  glPushName(7);
179  TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 100);
180  glTranslatef(0, -a, 0);
181  glBegin(GL_QUADS);
182  glVertex3f( 0, 0, z);
183  glVertex3f( a, 0, z);
184  glVertex3f( a, a, z);
185  glVertex3f( 0, a, z);
186  glEnd();
187  {
188  glBegin(GL_LINES);
189  TGLUtil::ColorTransparency(rnrCtx.ColorSet().Markup().GetColorIndex(), 40);
190  Float_t s = a/3;
191  glVertex3f( s, s, z);
192  glVertex3f( a-s, a-s, z);
193  glVertex3f( s, a-s, z);
194  glVertex3f( a-s, s, z);
195  glEnd();
196  }
197  glPopName();
198  }
199  }
200 
201  glEnable(GL_DEPTH_TEST);
202  glMatrixMode(GL_PROJECTION);
203  glPopMatrix();
204  glMatrixMode(GL_MODELVIEW);
205  glPopMatrix();
206 
207  glPopAttrib();
208 }
static const TString & coreIcondir()
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
float float float z
double a
Definition: hdecay.h:121
void CmsAnnotation::setAllowDestroy ( bool  x)
inline

Definition at line 37 of file CmsAnnotation.h.

References fAllowDestroy, and x.

37 { fAllowDestroy = x; }
Definition: DDAxes.h:10
void CmsAnnotation::setFrom ( const FWConfiguration iFrom)
virtual

Definition at line 344 of file CmsAnnotation.cc.

References fPosX, fPosY, fSize, FWConfiguration::value(), relativeConstraints::value, and FWConfiguration::valueForKey().

Referenced by FWEveView::setFrom().

345 {
346  const FWConfiguration* value;
347  value = iFrom.valueForKey("LogoSize");
348  if (value) fSize = atof(value->value().c_str());
349 
350  value = iFrom.valueForKey("LogoPosX");
351  if (value) fPosX = atof(value->value().c_str());
352 
353  value = iFrom.valueForKey("LogoPosY");
354  if (value) fPosY = atof(value->value().c_str());
355 
356 }
const std::string & value(unsigned int iIndex=0) const
const FWConfiguration * valueForKey(const std::string &iKey) const
void CmsAnnotation::setSize ( Float_t  x)
inline

Definition at line 31 of file CmsAnnotation.h.

References fSize, and x.

31 { fSize = x; }
Definition: DDAxes.h:10
void CmsAnnotation::setVisible ( bool  x)

Definition at line 318 of file CmsAnnotation.cc.

References fParent.

Referenced by FWEveView::FWEveView().

319 {
320  SetState(x ? (TGLOverlayElement::kActive) : (TGLOverlayElement::kInvisible));
321  fParent->Changed();
322  gEve->Redraw3D();
323 }
TGLViewer * fParent
Definition: CmsAnnotation.h:49
Definition: DDAxes.h:10

Member Data Documentation

bool CmsAnnotation::fActive
private

Definition at line 54 of file CmsAnnotation.h.

Referenced by MouseEnter(), MouseLeave(), and Render().

bool CmsAnnotation::fAllowDestroy
private

Definition at line 55 of file CmsAnnotation.h.

Referenced by getAllowDestroy(), Render(), and setAllowDestroy().

EDrag CmsAnnotation::fDrag
private

last mouse position

Definition at line 47 of file CmsAnnotation.h.

Referenced by Handle().

Int_t CmsAnnotation::fMouseX
private

Definition at line 46 of file CmsAnnotation.h.

Referenced by Handle().

Int_t CmsAnnotation::fMouseY
private

Definition at line 46 of file CmsAnnotation.h.

Referenced by Handle().

TGLViewer* CmsAnnotation::fParent
private

Definition at line 49 of file CmsAnnotation.h.

Referenced by CmsAnnotation(), Handle(), setVisible(), and ~CmsAnnotation().

Float_t CmsAnnotation::fPosX
private

Definition at line 43 of file CmsAnnotation.h.

Referenced by addTo(), Handle(), Render(), and setFrom().

Float_t CmsAnnotation::fPosY
private

Definition at line 44 of file CmsAnnotation.h.

Referenced by addTo(), Handle(), Render(), and setFrom().

Float_t CmsAnnotation::fSize
private

Definition at line 51 of file CmsAnnotation.h.

Referenced by addTo(), getSize(), Handle(), Render(), setFrom(), and setSize().

Float_t CmsAnnotation::fSizeDrag
private

relative size to viewport width

Definition at line 52 of file CmsAnnotation.h.

Referenced by Handle().