TGLManip.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLManip.cxx 34006 2010-06-21 10:36:05Z matevz $
00002 // Author:  Richard Maunder  16/09/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLManip.h"
00013 #include "TGLUtil.h"
00014 #include "TGLCamera.h"
00015 #include "TGLPhysicalShape.h"
00016 #include "TGLIncludes.h"
00017 #include "TROOT.h"
00018 
00019 #include "TVirtualX.h"
00020 
00021 //______________________________________________________________________________
00022 //                                                                      
00023 // Abstract base class for viewer manipulators, which allow direct in   
00024 // viewer manipulation of a (TGlPhysicalShape) object - currently       
00025 // translation, scaling and rotation along/round objects local axes.    
00026 // See derived classes for these implementations.                       
00027 //                                                                      
00028 // This class provides binding to the zero or one manipulated physical, 
00029 // hit testing (selection) for manipulator sub component (widget), and  
00030 // some common mouse action handling/tracking.                          
00031 
00032 ClassImp(TGLManip);
00033 
00034 //______________________________________________________________________________
00035 TGLManip::TGLManip() :
00036    fShape(0),
00037    fSelectedWidget(0), fActive(kFALSE),
00038    fFirstMouse(0, 0),
00039    fLastMouse(0, 0)
00040 {
00041    // Construct a manipulator object, bound to supplied viewer, and no
00042    // physical shape.
00043 }
00044 
00045 //______________________________________________________________________________
00046 TGLManip::TGLManip(TGLPhysicalShape* shape) :
00047    fShape(shape),
00048    fSelectedWidget(0), fActive(kFALSE),
00049    fFirstMouse(0, 0),
00050    fLastMouse(0, 0)
00051 {
00052    // Construct a manipulator object, bound to supplied physical shape.
00053 }
00054 
00055 //______________________________________________________________________________
00056 TGLManip::TGLManip(const TGLManip& gm) :
00057   TVirtualGLManip(gm),
00058   fShape(gm.fShape),
00059   fSelectedWidget(gm.fSelectedWidget),
00060   fActive(gm.fActive),
00061   fFirstMouse(gm.fFirstMouse),
00062   fLastMouse(gm.fLastMouse)
00063 {
00064    // Copy constructor.
00065 }
00066 
00067 //______________________________________________________________________________
00068 TGLManip& TGLManip::operator=(const TGLManip& gm)
00069 {
00070    // Assignement operator.
00071 
00072    if(this!=&gm) {
00073       TVirtualGLManip::operator=(gm);
00074       fShape=gm.fShape;
00075       fSelectedWidget=gm.fSelectedWidget;
00076       fActive=gm.fActive;
00077       fFirstMouse=gm.fFirstMouse;
00078       fLastMouse=gm.fLastMouse;
00079    }
00080    return *this;
00081 }
00082 
00083 //______________________________________________________________________________
00084 TGLManip::~TGLManip()
00085 {
00086    // Destroy manipulator object.
00087 }
00088 
00089 //______________________________________________________________________________
00090 const UChar_t* TGLManip::ColorFor(UInt_t widget) const
00091 {
00092    // Returns color to be used for given widget.
00093 
00094    if (widget == fSelectedWidget)
00095    {
00096       return TGLUtil::fgYellow;
00097    }
00098    else
00099    {
00100       switch (widget)
00101       {
00102          case 1:  return TGLUtil::fgRed;
00103          case 2:  return TGLUtil::fgGreen;
00104          case 3:  return TGLUtil::fgBlue;
00105          default: return TGLUtil::fgGrey;
00106       }
00107    }
00108 }
00109 
00110 //______________________________________________________________________________
00111 Bool_t TGLManip::HandleButton(const Event_t& event, const TGLCamera& /*camera*/)
00112 {
00113    // Handle a mouse button event - return kTRUE if processed, kFALSE otherwise
00114 
00115    // Only interested in Left mouse button actions
00116    if (event.fCode != kButton1) {
00117       return kFALSE;
00118    }
00119 
00120    // Mouse down on selected widget?
00121    if (event.fType == kButtonPress && fSelectedWidget != 0) {
00122       fFirstMouse.SetX(event.fX);
00123       fFirstMouse.SetY(event.fY);
00124       fLastMouse.SetX(event.fX);
00125       fLastMouse.SetY(event.fY);
00126       fActive = kTRUE;
00127       return kTRUE;
00128    } else if (event.fType == kButtonRelease && fActive) {
00129       fActive = kFALSE;
00130       return kTRUE;
00131    } else {
00132       return kFALSE;
00133    }
00134 }
00135 
00136 //______________________________________________________________________________
00137 Bool_t TGLManip::HandleMotion(const Event_t&   /*event*/,
00138                               const TGLCamera& /*camera*/)
00139 {
00140    // Handle a mouse button event - return kTRUE if widget selection change
00141    // kFALSE otherwise
00142 
00143    return kFALSE;
00144 }
00145 
00146 //______________________________________________________________________________
00147 void TGLManip::CalcDrawScale(const TGLBoundingBox& box,
00148                              const TGLCamera&      camera,
00149                              Double_t&             base,
00150                              TGLVector3            axis[3]) const
00151 {
00152    // Calculates base and axis scale factor (in world units) for
00153    // drawing manipulators with reasonable size range in current
00154    // camera.
00155 
00156    // Calculate a base scale
00157    base = box.Extents().Mag() / 100.0;
00158 
00159    // Clamp this base scale to a viewport pixel range
00160    // Allow some variation so zooming is noticable
00161    TGLVector3 pixelInWorld = camera.ViewportDeltaToWorld(box.Center(), 1, 1);
00162    Double_t pixelScale = pixelInWorld.Mag();
00163    if (base < pixelScale * 3.0) {
00164       base = pixelScale * 3.0;
00165    } else if (base > pixelScale * 6.0) {
00166       base = pixelScale * 6.0;
00167    }
00168 
00169    // Calculate some axis scales
00170    for (UInt_t i = 0; i<3; i++) {
00171       if (box.IsEmpty()) {
00172          axis[i] = box.Axis(i, kTRUE)*base*-10.0;
00173       } else {
00174          axis[i] = box.Axis(i, kFALSE)*-0.51;
00175          if (axis[i].Mag() < base*10.0) {
00176             axis[i] = box.Axis(i, kTRUE)*base*-10.0;
00177          }
00178       }
00179    }
00180 }

Generated on Tue Jul 5 14:18:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1