TGLManipSet.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLManipSet.cxx 28885 2009-06-10 15:51:12Z matevz $
00002 // Author:  Matevz Tadel, Feb 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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 "TGLManipSet.h"
00013 
00014 #include "TGLTransManip.h"
00015 #include "TGLScaleManip.h"
00016 #include "TGLRotateManip.h"
00017 
00018 #include "TGLPhysicalShape.h"
00019 #include "TGLRnrCtx.h"
00020 #include "TGLSelectRecord.h"
00021 
00022 #include "TGLIncludes.h"
00023 
00024 #include <KeySymbols.h>
00025 #include <TVirtualX.h>
00026 
00027 //______________________________________________________________________
00028 //
00029 // Combine all available manipulators in a collection.
00030 //
00031 // At first I wanted to merge them back into TGLManip (to have a
00032 // single class) but then it seemed somehow messy.
00033 // Maybe next time.
00034 
00035 ClassImp(TGLManipSet);
00036 
00037 TGLManipSet::TGLManipSet() :
00038    TGLOverlayElement(kViewer),
00039    fType     (kTrans),
00040    fDrawBBox (kFALSE)
00041 {
00042    // Constructor.
00043 
00044    fManip[kTrans]  = new TGLTransManip;
00045    fManip[kScale]  = new TGLScaleManip;
00046    fManip[kRotate] = new TGLRotateManip;
00047 }
00048 
00049 //______________________________________________________________________
00050 TGLManipSet::~TGLManipSet()
00051 {
00052    // Destructor.
00053 
00054    for (Int_t i=kTrans; i<kEndType; ++i)
00055       delete fManip[i];
00056 }
00057 
00058 //______________________________________________________________________
00059 void TGLManipSet::SetPShape(TGLPhysicalShape* shape)
00060 {
00061    // Set phys-shape, override of virtual from TGLPShapeRef.
00062    // Forward to all managed manipulators.
00063 
00064    TGLPShapeRef::SetPShape(shape);
00065    for (Int_t i=kTrans; i<kEndType; ++i)
00066       fManip[i]->Attach(shape);
00067 }
00068 
00069 /**************************************************************************/
00070 /**************************************************************************/
00071 
00072 //______________________________________________________________________
00073 Bool_t TGLManipSet::MouseEnter(TGLOvlSelectRecord& /*selRec*/)
00074 {
00075    // Mouse has enetered this element.
00076    // Always accept.
00077 
00078    TGLManip* manip = GetCurrentManip();
00079    manip->SetActive(kFALSE);
00080    manip->SetSelectedWidget(0);
00081    return kTRUE;
00082 }
00083 
00084 //______________________________________________________________________
00085 Bool_t TGLManipSet::Handle(TGLRnrCtx&          rnrCtx,
00086                            TGLOvlSelectRecord& selRec,
00087                            Event_t*            event)
00088 {
00089    // Handle overlay event.
00090    // Return TRUE if event was handled.
00091 
00092    TGLManip* manip = GetCurrentManip();
00093 
00094    switch (event->fType)
00095    {
00096       case kButtonPress:
00097       {
00098          return manip->HandleButton(*event, rnrCtx.RefCamera());
00099       }
00100       case kButtonRelease:
00101       {
00102          manip->SetActive(kFALSE);
00103          return kTRUE;
00104       }
00105       case kMotionNotify:
00106       {
00107          if (manip->GetActive())
00108             return manip->HandleMotion(*event, rnrCtx.RefCamera());
00109          if (selRec.GetCurrItem() != manip->GetSelectedWidget())
00110          {
00111             manip->SetSelectedWidget(selRec.GetCurrItem());
00112             return kTRUE;
00113          }
00114          return kFALSE;
00115       }
00116       case kGKeyPress:
00117       {
00118          switch (rnrCtx.GetEventKeySym())
00119          {
00120             case kKey_V: case kKey_v:
00121                SetManipType(kTrans);
00122                return kTRUE;
00123             case kKey_C: case kKey_c:
00124                SetManipType(kRotate);
00125                return kTRUE;
00126             case kKey_X: case kKey_x:
00127                SetManipType(kScale);
00128                return kTRUE;
00129             default:
00130                return kFALSE;
00131          }
00132       }
00133       default:
00134       {
00135          return kFALSE;
00136       }
00137    }
00138 }
00139 
00140 //______________________________________________________________________
00141 void TGLManipSet::MouseLeave()
00142 {
00143    // Mouse has left the element.
00144 
00145    TGLManip* manip = GetCurrentManip();
00146    manip->SetActive(kFALSE);
00147    manip->SetSelectedWidget(0);
00148 }
00149 
00150 //______________________________________________________________________
00151 void TGLManipSet::Render(TGLRnrCtx& rnrCtx)
00152 {
00153    // Render the manipulator and bounding-box.
00154 
00155    if (fPShape == 0)
00156       return;
00157 
00158    if (rnrCtx.Selection())
00159    {
00160       TGLUtil::SetDrawQuality(12);
00161       fManip[fType]->Draw(rnrCtx.RefCamera());
00162       TGLUtil::ResetDrawQuality();
00163    } else {
00164       fManip[fType]->Draw(rnrCtx.RefCamera());
00165    }
00166 
00167    if (fDrawBBox && ! rnrCtx.Selection())
00168    {
00169       // TODO: This must be replaced by some color in rnrCtx,
00170       // like def-overlay-color, background-color, foreground-color
00171       // Or at least bkgcol ... i can then find high contrast.
00172       TGLUtil::Color(rnrCtx.ColorSet().Markup());
00173       glDisable(GL_LIGHTING);
00174       fPShape->BoundingBox().Draw();
00175       glEnable(GL_LIGHTING);
00176    }
00177 }
00178 
00179 //______________________________________________________________________
00180 void TGLManipSet::SetManipType(Int_t type)
00181 {
00182    // Set manipulator type, range checked.
00183 
00184    if (type < 0 || type >= kEndType)
00185       return;
00186    fType = (EManip) type;
00187 }

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