TGeoSphereEditor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoSphereEditor.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: M.Gheata 
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, 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 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 //  TGeoSphereEditor                                                      //
00015 //                                                                      //
00016 //////////////////////////////////////////////////////////////////////////
00017 //Begin_Html
00018 /*
00019 <img src="gif/sphe_pic.gif">
00020 */
00021 //End_Html
00022 //Begin_Html
00023 /*
00024 <img src="gif/sphe_ed.jpg">
00025 */
00026 //End_Html
00027 
00028 #include "TGeoSphereEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoSphere.h"
00031 #include "TGeoManager.h"
00032 #include "TVirtualGeoPainter.h"
00033 #include "TPad.h"
00034 #include "TView.h"
00035 #include "TGTab.h"
00036 #include "TGComboBox.h"
00037 #include "TGButton.h"
00038 #include "TGTextEntry.h"
00039 #include "TGNumberEntry.h"
00040 #include "TGLabel.h"
00041 #include "TGDoubleSlider.h"
00042 
00043 ClassImp(TGeoSphereEditor)
00044 
00045 enum ETGeoSphereWid {
00046    kSPHERE_NAME, kSPHERE_RMIN, kSPHERE_RMAX, kSPHERE_THETA1,
00047    kSPHERE_THETA2, kSPHERE_PHI1, kSPHERE_PHI2, kSPHERE_PHI, kSPHERE_THETA, 
00048    kSPHERE_APPLY, kSPHERE_UNDO
00049 };
00050 
00051 //______________________________________________________________________________
00052 TGeoSphereEditor::TGeoSphereEditor(const TGWindow *p, Int_t width,
00053                                    Int_t height, UInt_t options, Pixel_t back)
00054    : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00055 {
00056    // Constructor for sphere editor
00057    fShape   = 0;
00058    fRmini = fRmaxi = fTheta1i = fTheta2i = fPhi1i = fPhi2i = 0.0;
00059    fNamei = "";
00060    fIsModified = kFALSE;
00061    fIsShapeEditable = kTRUE;
00062    fLock = kFALSE;
00063 
00064    // TextEntry for shape name
00065    MakeTitle("Name");
00066    fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
00067    fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00068    fShapeName->SetToolTipText("Enter the sphere name");
00069    fShapeName->Associate(this);
00070    AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00071 
00072    TGTextEntry *nef;
00073    MakeTitle("Sphere dimensions");
00074    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
00075    // Number entry for rmin
00076    TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00077                                  kLHintsExpandX | kOwnBackground);
00078    f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00079    fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
00080    fERmin->SetNumAttr(TGNumberFormat::kNEANonNegative);
00081    nef = (TGTextEntry*)fERmin->GetNumberEntry();
00082    nef->SetToolTipText("Enter the inner radius");
00083    fERmin->Associate(this);
00084    fERmin->Resize(100, fERmin->GetDefaultHeight());
00085    f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00086    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00087    
00088    // Number entry for Rmax
00089    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00090                                  kLHintsExpandX | kOwnBackground);
00091    f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00092    fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
00093    fERmax->SetNumAttr(TGNumberFormat::kNEANonNegative);
00094    nef = (TGTextEntry*)fERmax->GetNumberEntry();
00095    nef->SetToolTipText("Enter the outer radius");
00096    fERmax->Associate(this);
00097    fERmax->Resize(100, fERmax->GetDefaultHeight());
00098    f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00099    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00100    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00101    
00102    MakeTitle("Phi/theta range");
00103    TGCompositeFrame *f11 = new TGCompositeFrame(this, 150,200, kHorizontalFrame);
00104    compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
00105    // Vertical slider
00106    fSPhi = new TGDoubleVSlider(compxyz,140);
00107    fSPhi->SetRange(0.,720.);
00108    compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4)); 
00109    f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
00110    f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
00111    fEPhi1 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI1);
00112    fEPhi1->Resize(30, fEPhi1->GetDefaultHeight());
00113    fEPhi1->SetNumAttr(TGNumberFormat::kNEANonNegative);
00114    nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
00115    nef->SetToolTipText("Enter the phi1 value");
00116    fEPhi1->Associate(this);
00117    f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00118 
00119    fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
00120    fEPhi2->Resize(30, fEPhi2->GetDefaultHeight());
00121    fEPhi2->SetNumAttr(TGNumberFormat::kNEANonNegative);
00122    nef = (TGTextEntry*)fEPhi2->GetNumberEntry();
00123    nef->SetToolTipText("Enter the phi2 value");
00124    fEPhi2->Associate(this);
00125    fEPhi2->Resize(30, fEPhi2->GetDefaultHeight());
00126    f1->AddFrame(fEPhi2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00127    f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
00128    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
00129    
00130    compxyz->Resize(75,150);
00131    f11->AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
00132       
00133    compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
00134    // Vertical slider
00135    fSTheta = new TGDoubleVSlider(compxyz,140);
00136    fSTheta->SetRange(0.,180.);
00137    compxyz->AddFrame(fSTheta, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4)); 
00138    f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
00139    f1->AddFrame(new TGLabel(f1, "Theta min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
00140    fETheta1 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA1);
00141    fETheta1->Resize(30, fETheta1->GetDefaultHeight());
00142    fETheta1->SetNumAttr(TGNumberFormat::kNEANonNegative);
00143    nef = (TGTextEntry*)fETheta1->GetNumberEntry();
00144    nef->SetToolTipText("Enter the theta1 value");
00145    fETheta1->Associate(this);
00146    f1->AddFrame(fETheta1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00147 
00148    fETheta2 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA2);
00149    fETheta2->Resize(30, fETheta2->GetDefaultHeight());
00150    fETheta2->SetNumAttr(TGNumberFormat::kNEANonNegative);
00151    nef = (TGTextEntry*)fETheta2->GetNumberEntry();
00152    nef->SetToolTipText("Enter the theta2 value");
00153    fETheta2->Associate(this);
00154    f1->AddFrame(fETheta2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00155    f1->AddFrame(new TGLabel(f1, "Theta max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
00156    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
00157    
00158    compxyz->Resize(75,150);
00159    f11->AddFrame(compxyz, new TGLayoutHints(kLHintsRight, 0, 0, 0, 0));  
00160 
00161    AddFrame(f11, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
00162    
00163    // Delayed draw
00164    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00165    fDelayed = new TGCheckButton(f1, "Delayed draw");
00166    f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00167    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00168 
00169    // Buttons
00170    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00171    fApply = new TGTextButton(f1, "Apply");
00172    f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00173    fApply->Associate(this);
00174    fUndo = new TGTextButton(f1, "Undo");
00175    f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00176    fUndo->Associate(this);
00177    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00178    fUndo->SetSize(fApply->GetSize());
00179 }
00180 
00181 //______________________________________________________________________________
00182 TGeoSphereEditor::~TGeoSphereEditor()
00183 {
00184 // Destructor.
00185    TGFrameElement *el;
00186    TIter next(GetList());
00187    while ((el = (TGFrameElement *)next())) {
00188       if (el->fFrame->IsComposite()) 
00189          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00190    }
00191    Cleanup();   
00192 }
00193 
00194 //______________________________________________________________________________
00195 void TGeoSphereEditor::ConnectSignals2Slots()
00196 {
00197    // Connect signals to slots.
00198    fApply->Connect("Clicked()", "TGeoSphereEditor", this, "DoApply()");
00199    fUndo->Connect("Clicked()", "TGeoSphereEditor", this, "DoUndo()");
00200    fShapeName->Connect("TextChanged(const char *)", "TGeoSphereEditor", this, "DoModified()");
00201    fERmin->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmin()");
00202    fERmax->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmax()");
00203    fEPhi1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi1()");
00204    fEPhi2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi2()");
00205    fETheta1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta1()");
00206    fETheta2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta2()");
00207    fSPhi->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoPhi()");
00208    fSTheta->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoTheta()");
00209    fInit = kFALSE;
00210 }
00211 
00212 
00213 //______________________________________________________________________________
00214 void TGeoSphereEditor::SetModel(TObject* obj)
00215 {
00216    // Connect to a given sphere.
00217    if (obj == 0 || (obj->IsA()!=TGeoSphere::Class())) {
00218       SetActive(kFALSE);
00219       return;                 
00220    } 
00221    fShape = (TGeoSphere*)obj;
00222    fRmini = fShape->GetRmin();
00223    fRmaxi = fShape->GetRmax();
00224    fPhi1i = fShape->GetPhi1();
00225    fPhi2i = fShape->GetPhi2();
00226    fTheta1i = fShape->GetTheta1();
00227    fTheta2i = fShape->GetTheta2();
00228    fNamei = fShape->GetName();
00229    fShapeName->SetText(fShape->GetName());
00230    fERmin->SetNumber(fRmini);
00231    fERmax->SetNumber(fRmaxi);
00232    fEPhi1->SetNumber(fPhi1i);
00233    fEPhi2->SetNumber(fPhi2i);
00234    fETheta1->SetNumber(fTheta1i);
00235    fETheta2->SetNumber(fTheta2i);
00236    fSPhi->SetPosition(fPhi1i, fPhi2i);
00237    fSTheta->SetPosition(fTheta1i, fTheta2i);
00238    
00239    fApply->SetEnabled(kFALSE);
00240    fUndo->SetEnabled(kFALSE);
00241    
00242    if (fInit) ConnectSignals2Slots();
00243    SetActive();
00244 }
00245 
00246 //______________________________________________________________________________
00247 Bool_t TGeoSphereEditor::IsDelayed() const
00248 {
00249 // Check if shape drawing is delayed.
00250    return (fDelayed->GetState() == kButtonDown);
00251 }
00252 
00253 //______________________________________________________________________________
00254 void TGeoSphereEditor::DoName()
00255 {
00256 // Slot for name.
00257    DoModified();
00258 }
00259 
00260 //______________________________________________________________________________
00261 void TGeoSphereEditor::DoApply()
00262 {
00263 // Slot for applying modifications.
00264    const char *name = fShapeName->GetText();
00265    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00266    Double_t rmin = fERmin->GetNumber();
00267    Double_t rmax = fERmax->GetNumber();
00268    Double_t phi1 = fEPhi1->GetNumber();
00269    Double_t phi2 = fEPhi2->GetNumber();
00270    if ((phi2-phi1) > 360.001) {
00271       phi1 = 0.;
00272       phi2 = 360.;
00273       fEPhi1->SetNumber(phi1);
00274       fEPhi2->SetNumber(phi2);
00275       fLock = kTRUE;
00276       fSPhi->SetPosition(phi1,phi2);
00277       fLock = kFALSE;
00278    }   
00279    Double_t theta1 = fETheta1->GetNumber();
00280    Double_t theta2 = fETheta2->GetNumber();
00281    fShape->SetSphDimensions(rmin, rmax, theta1,theta2,phi1,phi2);
00282    fShape->ComputeBBox();
00283    fUndo->SetEnabled();
00284    fApply->SetEnabled(kFALSE);
00285    if (fPad) {
00286       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00287          fShape->Draw();
00288          fPad->GetView()->ShowAxis();
00289       } else Update();
00290    }   
00291 }
00292 
00293 //______________________________________________________________________________
00294 void TGeoSphereEditor::DoModified()
00295 {
00296 // Slot for signaling modifications.
00297    fApply->SetEnabled();
00298 }
00299 
00300 //______________________________________________________________________________
00301 void TGeoSphereEditor::DoUndo()
00302 {
00303 // Slot for undoing last operation.
00304    fERmin->SetNumber(fRmini);
00305    fERmax->SetNumber(fRmaxi);
00306    fEPhi1->SetNumber(fPhi1i);
00307    fEPhi2->SetNumber(fPhi2i);
00308    fSPhi->SetPosition(fPhi1i,fPhi2i);
00309    fETheta1->SetNumber(fTheta1i);
00310    fETheta2->SetNumber(fTheta2i);
00311    fSTheta->SetPosition(fTheta1i,fTheta2i);
00312    DoApply();
00313    fUndo->SetEnabled(kFALSE);
00314    fApply->SetEnabled(kFALSE);
00315 }
00316    
00317 //______________________________________________________________________________
00318 void TGeoSphereEditor::DoRmin()
00319 {
00320 // Slot for Rmin.
00321    Double_t rmin = fERmin->GetNumber();
00322    Double_t rmax = fERmax->GetNumber();
00323    if (rmin <= 0.) {
00324       rmin = 0.;
00325       fERmin->SetNumber(rmin);
00326    }   
00327    if (rmin >= rmax) {
00328       rmin = rmax - 0.1;
00329       fERmin->SetNumber(rmin);
00330    }   
00331    DoModified();
00332    if (!IsDelayed()) DoApply();
00333 }
00334 
00335 //______________________________________________________________________________
00336 void TGeoSphereEditor::DoRmax()
00337 {
00338 // Slot for Rmax.
00339    Double_t rmin = fERmin->GetNumber();
00340    Double_t rmax = fERmax->GetNumber();
00341    if (rmax <= 0.) {
00342       rmax = 0.1;
00343       fERmax->SetNumber(rmax);
00344    }   
00345    if (rmax < rmin+1.e-10) {
00346       rmax = rmin + 0.1;
00347       if (rmin < 0.) rmin = 0.;
00348       fERmax->SetNumber(rmax);
00349    }   
00350    DoModified();
00351    if (!IsDelayed()) DoApply();
00352 }
00353 
00354 //______________________________________________________________________________
00355 void TGeoSphereEditor::DoPhi1()
00356 {
00357 // Slot for phi1.
00358    Double_t phi1 = fEPhi1->GetNumber();
00359    Double_t phi2 = fEPhi2->GetNumber();
00360    if (phi1 > 360-1.e-10) {
00361       phi1 = 0.;
00362       fEPhi1->SetNumber(phi1);
00363    }   
00364    if (phi2<phi1+1.e-10) {
00365       phi1 = phi2 - 0.1;
00366       fEPhi1->SetNumber(phi1);
00367    }   
00368    if (!fLock) {
00369       DoModified();
00370       fLock = kTRUE;
00371       fSPhi->SetPosition(phi1,phi2);
00372    } else fLock = kFALSE;
00373    if (!IsDelayed()) DoApply();
00374 }
00375 
00376 //______________________________________________________________________________
00377 void TGeoSphereEditor::DoPhi2()
00378 {
00379 // Slot for phi2.
00380    Double_t phi1 = fEPhi1->GetNumber();
00381    Double_t phi2 = fEPhi2->GetNumber();
00382    if (phi2-phi1 > 360.) {
00383       phi2 -= 360.;
00384       fEPhi2->SetNumber(phi2);
00385    }   
00386    if (phi2<phi1+1.e-10) {
00387       phi2 = phi1 + 0.1;
00388       fEPhi2->SetNumber(phi2);
00389    }   
00390    if (!fLock) {
00391       DoModified();
00392       fLock = kTRUE;
00393       fSPhi->SetPosition(phi1,phi2);
00394    } else fLock = kFALSE;
00395    if (!IsDelayed()) DoApply();
00396 }
00397 
00398 //______________________________________________________________________________
00399 void TGeoSphereEditor::DoPhi()
00400 {
00401 // Slot for phi slider.
00402    if (!fLock) {
00403       DoModified();
00404       fLock = kTRUE;
00405       fEPhi1->SetNumber(fSPhi->GetMinPosition());
00406       fLock = kTRUE;
00407       fEPhi2->SetNumber(fSPhi->GetMaxPosition());
00408    } else fLock = kFALSE;   
00409    if (!IsDelayed()) DoApply();
00410 }
00411 
00412 //______________________________________________________________________________
00413 void TGeoSphereEditor::DoTheta1()
00414 {
00415 // Slot for theta1.
00416    Double_t theta1 = fETheta1->GetNumber();
00417    Double_t theta2 = fETheta2->GetNumber();
00418    if (theta2<theta1+1.e-10) {
00419       theta2 = theta1 + 0.1;
00420       fETheta2->SetNumber(theta2);
00421    }   
00422    if (!fLock) {
00423       DoModified();
00424       fLock = kTRUE;
00425       fSTheta->SetPosition(theta1,theta2);
00426    } else fLock = kFALSE;
00427    if (!IsDelayed()) DoApply();
00428 }
00429 
00430 //______________________________________________________________________________
00431 void TGeoSphereEditor::DoTheta2()
00432 {
00433 // Slot for theta2.
00434    Double_t theta1 = fETheta1->GetNumber();
00435    Double_t theta2 = fETheta2->GetNumber();
00436    if (theta2<theta1+1.e-10) {
00437       theta1 = theta2 - 0.1;
00438       fETheta1->SetNumber(theta1);
00439    }   
00440    if (!fLock) {
00441       DoModified();
00442       fLock = kTRUE;
00443       fSTheta->SetPosition(theta1,theta2);
00444    } else fLock = kFALSE;
00445    if (!IsDelayed()) DoApply();
00446 }
00447 
00448 //______________________________________________________________________________
00449 void TGeoSphereEditor::DoTheta()
00450 {
00451    // Slot for theta slider.
00452    if (!fLock) {
00453       DoModified();
00454       fLock = kTRUE;
00455       fETheta1->SetNumber(fSTheta->GetMinPosition());
00456       fLock = kTRUE;
00457       fETheta2->SetNumber(fSTheta->GetMaxPosition());
00458    } else fLock = kFALSE;   
00459    if (!IsDelayed()) DoApply();
00460 }

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