TEveTransEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveTransEditor.cxx 22539 2008-03-08 14:36:37Z rdm $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, 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 "TEveTransEditor.h"
00013 #include "TEveTrans.h"
00014 #include "TEveGValuators.h"
00015 
00016 #include "TVirtualPad.h"
00017 #include "TMath.h"
00018 
00019 #include "TGButton.h"
00020 #include "TGLabel.h"
00021 
00022 //______________________________________________________________________________
00023 // TEveTransSubEditor
00024 //
00025 // Sub-editor for TEveTrans class.
00026 
00027 ClassImp(TEveTransSubEditor);
00028 
00029 //______________________________________________________________________________
00030 TEveTransSubEditor::TEveTransSubEditor(TGWindow* p) :
00031    TGVerticalFrame (p),
00032    fTrans          (0),
00033    fTopHorFrame    (0),
00034    fUseTrans       (0),
00035    fEditTrans      (0),
00036    fEditTransFrame (0),
00037    fPos            (0),
00038    fRot            (0),
00039    fScale          (0),
00040    fAutoUpdate     (0),
00041    fUpdate         (0)
00042 {
00043    // Constructor.
00044 
00045    // --- Top controls
00046 
00047    fTopHorFrame = new TGHorizontalFrame(this);
00048 
00049    fUseTrans  = new TGCheckButton(fTopHorFrame, "UseTrans");
00050    fTopHorFrame->AddFrame(fUseTrans, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
00051    fUseTrans->Connect("Toggled(Bool_t)", "TEveTransSubEditor", this, "DoUseTrans()");
00052    fEditTrans = new TGCheckButton(fTopHorFrame, "EditTrans");
00053    fTopHorFrame->AddFrame(fEditTrans, new TGLayoutHints(kLHintsLeft, 2,1,0,0));
00054    fEditTrans->Connect("Toggled(Bool_t)"," TEveTransSubEditor", this, "DoEditTrans()");
00055 
00056    AddFrame(fTopHorFrame, new TGLayoutHints(kLHintsTop, 0,0,2,1));
00057 
00058    // --- Trans edit part
00059 
00060    fEditTransFrame = new TGVerticalFrame(this);
00061 
00062    TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
00063 
00064    TGHorizontalFrame* hfp = new TGHorizontalFrame(fEditTransFrame);
00065    TGLabel* labp = new TGLabel(hfp, "Location");
00066    labp->SetTextFont(font);
00067    hfp->AddFrame(labp);
00068    fEditTransFrame->AddFrame(hfp,  new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
00069    fPos = new TEveGTriVecValuator(fEditTransFrame, "Pos", 160, 20);
00070    fPos->SetNELength(6);
00071    fPos->Build(kFALSE, "", "", "");
00072    fPos->SetLimits(-1e5, 1e5, TGNumberFormat::kNESRealThree);
00073    fPos->GetValuator(0)->SetToolTip("X coordinate");
00074    fPos->GetValuator(1)->SetToolTip("Y coordinate");
00075    fPos->GetValuator(2)->SetToolTip("Z coordinate");
00076    fEditTransFrame->AddFrame(fPos, new TGLayoutHints(kLHintsTop , 0,0,0,0));
00077 
00078    TGHorizontalFrame* hfr = new TGHorizontalFrame(fEditTransFrame);
00079    TGLabel* labr = new TGLabel(hfr, "Rotation");
00080    labr->SetTextFont(font);
00081    hfr->AddFrame(labr);
00082    fEditTransFrame->AddFrame(hfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
00083    fRot = new TEveGTriVecValuator(fEditTransFrame, "Rot", 160, 20);
00084    fRot->SetNELength(6);
00085    fRot->Build(kFALSE, "", "", "");
00086    fRot->SetLimits(-360, 360, TGNumberFormat::kNESRealOne);
00087    fRot->GetValuator(0)->SetToolTip("X coordinate");
00088    fRot->GetValuator(1)->SetToolTip("Y coordinate");
00089    fRot->GetValuator(2)->SetToolTip("Z coordinate");
00090    fEditTransFrame->AddFrame(fRot, new TGLayoutHints(kLHintsTop , 0,0, 0, 0));
00091 
00092    TGHorizontalFrame* hfs = new TGHorizontalFrame(fEditTransFrame);
00093    TGLabel* labs = new TGLabel(hfs, "Scale");
00094    labs->SetTextFont(font);
00095    hfs->AddFrame(labs);
00096    fEditTransFrame->AddFrame(hfs, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
00097    fScale = new TEveGTriVecValuator(fEditTransFrame, "Scale", 160, 20);
00098    fScale->SetNELength(6);
00099    fScale->Build(kFALSE, "", "", "");
00100    fScale->SetLimits(1e-2, 1e2, TGNumberFormat::kNESRealTwo);
00101    fScale->GetValuator(0)->SetToolTip("X coordinate");
00102    fScale->GetValuator(1)->SetToolTip("Y coordinate");
00103    fScale->GetValuator(2)->SetToolTip("Z coordinate");
00104    fEditTransFrame->AddFrame(fScale, new TGLayoutHints(kLHintsTop , 0,0,0, 2));
00105 
00106    fPos  ->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
00107    fRot  ->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
00108    fScale->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
00109 
00110    {
00111       TGHorizontalFrame* hframe = new TGHorizontalFrame(fEditTransFrame);
00112       fAutoUpdate = new TGCheckButton(hframe, "AutoUpdate");
00113       hframe->AddFrame(fAutoUpdate, new TGLayoutHints(kLHintsLeft, 1,1,1,1));
00114       fUpdate = new TGTextButton(hframe, "Update");
00115       hframe->AddFrame(fUpdate, new TGLayoutHints(kLHintsLeft, 0,0,1,1));
00116       fUpdate->Connect("Clicked()", "TEveTransSubEditor", this, "TransChanged()");
00117 
00118       fEditTransFrame->AddFrame(hframe, new TGLayoutHints(kLHintsTop , 0,0,4,0));
00119    }
00120 
00121    AddFrame(fEditTransFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,1,2));
00122 }
00123 
00124 /******************************************************************************/
00125 
00126 //______________________________________________________________________________
00127 void TEveTransSubEditor::SetModel(TEveTrans* t)
00128 {
00129    // Set model object.
00130 
00131    fTrans = t;
00132 
00133    fUseTrans ->SetState(fTrans->fUseTrans  ? kButtonDown : kButtonUp);
00134    fEditTrans->SetState(fTrans->fEditTrans ? kButtonDown : kButtonUp);
00135    if (fTrans->fEditTrans)
00136    {
00137       for (Int_t i=0; i<3; ++i)
00138       {
00139          fRot  ->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditRotation());
00140          fScale->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditScale());
00141       }
00142       fEditTransFrame->MapWindow();
00143    }
00144    else
00145    {
00146       fEditTransFrame->UnmapWindow();
00147    }
00148 
00149    ((TGMainFrame*)fEditTransFrame->GetMainFrame())->Layout();
00150 
00151    fPos->SetValues(fTrans->ArrT());
00152    Float_t a[3];
00153    fTrans->GetRotAngles(a);
00154    a[0] *= TMath::RadToDeg();
00155    a[1] *= TMath::RadToDeg();
00156    a[2] *= TMath::RadToDeg();
00157    fRot->SetValues(a);
00158    Double_t x, y, z;
00159    fTrans->GetScale(x, y, z);
00160    fScale->SetValues(x, y, z);
00161 }
00162 
00163 //______________________________________________________________________________
00164 void TEveTransSubEditor::SetTransFromData()
00165 {
00166    // Set model object from widget data.
00167 
00168    Double_t v[3];
00169    fTrans->UnitTrans();
00170    fRot->GetValues(v);
00171    fTrans->SetRotByAngles(v[0]*TMath::DegToRad(), v[1]*TMath::DegToRad(), v[2]*TMath::DegToRad());
00172    fPos->GetValues(v);
00173    fTrans->SetPos(v);
00174    fScale->GetValues(v);
00175    fTrans->Scale(v[0], v[1], v[2]);
00176 }
00177 
00178 /******************************************************************************/
00179 
00180 //______________________________________________________________________________
00181 void TEveTransSubEditor::UseTrans()
00182 {
00183    // Emit "UseTrans()" signal.
00184 
00185    Emit("UseTrans()");
00186 }
00187 
00188 //______________________________________________________________________________
00189 void TEveTransSubEditor::TransChanged()
00190 {
00191    // Set transformation values from widget and emit "TransChanged()" signal.
00192 
00193    SetTransFromData();
00194    Emit("TransChanged()");
00195 }
00196 
00197 /******************************************************************************/
00198 
00199 //______________________________________________________________________________
00200 void TEveTransSubEditor::DoUseTrans()
00201 {
00202    // Slot for UseTrans.
00203 
00204    fTrans->SetUseTrans(fUseTrans->IsOn());
00205    UseTrans();
00206 }
00207 
00208 //______________________________________________________________________________
00209 void TEveTransSubEditor::DoEditTrans()
00210 {
00211    // Slot for EditTrans.
00212 
00213    fTrans->SetEditTrans(fEditTrans->IsOn());
00214    TransChanged();
00215 }
00216 
00217 //______________________________________________________________________________
00218 void TEveTransSubEditor::DoTransChanged()
00219 {
00220    // Slot for TransChanged.
00221 
00222    if (fAutoUpdate->IsOn())
00223       TransChanged();
00224 }
00225 
00226 
00227 //______________________________________________________________________________
00228 // TEveTransEditor
00229 //
00230 // Editor for TEveTrans class.
00231 
00232 ClassImp(TEveTransEditor);
00233 
00234 //______________________________________________________________________________
00235 TEveTransEditor::TEveTransEditor(const TGWindow *p, Int_t width, Int_t height,
00236                                  UInt_t options, Pixel_t back) :
00237    TGedFrame(p, width, height, options | kVerticalFrame, back),
00238    fM (0),
00239    fSE(0)
00240 {
00241    // Constructor.
00242 
00243    MakeTitle("TEveTrans");
00244 
00245    fSE = new TEveTransSubEditor(this);
00246    AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
00247    fSE->Connect("UseTrans()",     "TEveTransEditor", this, "Update()");
00248    fSE->Connect("TransChanged()", "TEveTransEditor", this, "Update()");
00249 }
00250 
00251 /******************************************************************************/
00252 
00253 //______________________________________________________________________________
00254 void TEveTransEditor::SetModel(TObject* obj)
00255 {
00256    // Set model object.
00257 
00258    fM = dynamic_cast<TEveTrans*>(obj);
00259    fSE->SetModel(fM);
00260 }

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