TGeoTubeEditor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoTubeEditor.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 //  TGeoTubeEditor                                                      //
00015 //                                                                      //
00016 //////////////////////////////////////////////////////////////////////////
00017 //Begin_Html
00018 /*
00019 <img src="gif/tube_pic.gif">
00020 */
00021 //End_Html
00022 //Begin_Html
00023 /*
00024 <img src="gif/tube_ed.jpg">
00025 */
00026 //End_Html
00027 
00028 #include "TGeoTubeEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoTube.h"
00031 #include "TGeoManager.h"
00032 #include "TVirtualGeoPainter.h"
00033 #include "TPad.h"
00034 #include "TView.h"
00035 #include "TGTab.h"
00036 #include "TMath.h"
00037 #include "TGComboBox.h"
00038 #include "TGButton.h"
00039 #include "TGTextEntry.h"
00040 #include "TGNumberEntry.h"
00041 #include "TGLabel.h"
00042 #include "TGDoubleSlider.h"
00043 
00044 ClassImp(TGeoTubeEditor)
00045 
00046 enum ETGeoTubeWid {
00047    kTUBE_NAME, kTUBE_RMIN, kTUBE_RMAX, kTUBE_Z,
00048    kTUBE_APPLY, kTUBE_UNDO
00049 };
00050 
00051 //______________________________________________________________________________
00052 TGeoTubeEditor::TGeoTubeEditor(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 tube editor
00057    fShape   = 0;
00058    fRmini = fRmaxi = fDzi = 0.0;
00059    fNamei = "";
00060    fIsModified = kFALSE;
00061    fIsShapeEditable = kTRUE;
00062 
00063    // TextEntry for shape name
00064    MakeTitle("Name");
00065    fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTUBE_NAME);
00066    fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00067    fShapeName->SetToolTipText("Enter the box name");
00068    fShapeName->Associate(this);
00069    AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00070 
00071    TGTextEntry *nef;
00072    MakeTitle("Tube dimensions");
00073    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
00074    // Number entry for rmin
00075    TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00076    f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00077    fERmin = new TGNumberEntry(f1, 0., 5, kTUBE_RMIN);
00078    fERmin->SetNumAttr(TGNumberFormat::kNEANonNegative);
00079    nef = (TGTextEntry*)fERmin->GetNumberEntry();
00080    nef->SetToolTipText("Enter the inner radius");
00081    fERmin->Associate(this);
00082    fERmin->Resize(100,fERmin->GetDefaultHeight());
00083    f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00084    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00085    
00086    // Number entry for Rmax
00087    f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00088    f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00089    fERmax = new TGNumberEntry(f1, 0., 5, kTUBE_RMAX);
00090    fERmax->SetNumAttr(TGNumberFormat::kNEANonNegative);
00091    nef = (TGTextEntry*)fERmax->GetNumberEntry();
00092    nef->SetToolTipText("Enter the outer radius");
00093    fERmax->Associate(this);
00094    fERmax->Resize(100,fERmax->GetDefaultHeight());
00095    f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00096    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00097    
00098    // Number entry for dz
00099    f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00100    f1->AddFrame(new TGLabel(f1, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00101    fEDz = new TGNumberEntry(f1, 0., 5, kTUBE_Z);
00102    fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00103    nef = (TGTextEntry*)fEDz->GetNumberEntry();
00104    nef->SetToolTipText("Enter the tube half-lenth in Z");
00105    fEDz->Associate(this);
00106    fEDz->Resize(100,fEDz->GetDefaultHeight());
00107    f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00108    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00109    
00110 //   compxyz->Resize(150,30);
00111    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00112       
00113    // Delayed draw
00114    fDFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00115    fDelayed = new TGCheckButton(fDFrame, "Delayed draw");
00116    fDFrame->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00117    AddFrame(fDFrame,  new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));  
00118 
00119    // Buttons
00120    fBFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00121    fApply = new TGTextButton(fBFrame, "Apply");
00122    fBFrame->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00123    fApply->Associate(this);
00124    fUndo = new TGTextButton(fBFrame, "Undo");
00125    fBFrame->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00126    fUndo->Associate(this);
00127    AddFrame(fBFrame,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00128    fUndo->SetSize(fApply->GetSize());
00129 }
00130 
00131 //______________________________________________________________________________
00132 TGeoTubeEditor::~TGeoTubeEditor()
00133 {
00134 // Destructor
00135    TGFrameElement *el;
00136    TIter next(GetList());
00137    while ((el = (TGFrameElement *)next())) {
00138       if (el->fFrame->IsComposite()) 
00139          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00140    }
00141    Cleanup();   
00142 }
00143 
00144 //______________________________________________________________________________
00145 void TGeoTubeEditor::ConnectSignals2Slots()
00146 {
00147    // Connect signals to slots.
00148    fApply->Connect("Clicked()", "TGeoTubeEditor", this, "DoApply()");
00149    fUndo->Connect("Clicked()", "TGeoTubeEditor", this, "DoUndo()");
00150    fShapeName->Connect("TextChanged(const char *)", "TGeoTubeEditor", this, "DoModified()");
00151    fERmin->Connect("ValueSet(Long_t)", "TGeoTubeEditor", this, "DoRmin()");
00152    fERmax->Connect("ValueSet(Long_t)", "TGeoTubeEditor", this, "DoRmax()");
00153    fEDz->Connect("ValueSet(Long_t)", "TGeoTubeEditor", this, "DoDz()");
00154    fERmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTubeEditor", this, "DoRmin()");
00155    fERmax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTubeEditor", this, "DoRmax()");
00156    fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTubeEditor", this, "DoDz()");
00157    fInit = kFALSE;
00158 }
00159 
00160 
00161 //______________________________________________________________________________
00162 void TGeoTubeEditor::SetModel(TObject* obj)
00163 {
00164    // Connect to the selected object.
00165    if (obj == 0 || (obj->IsA()!=TGeoTube::Class())) {
00166       SetActive(kFALSE);
00167       return;                 
00168    } 
00169    fShape = (TGeoTube*)obj;
00170    fRmini = fShape->GetRmin();
00171    fRmaxi = fShape->GetRmax();
00172    fDzi = fShape->GetDz();
00173    fNamei = fShape->GetName();
00174    fShapeName->SetText(fShape->GetName());
00175    fERmin->SetNumber(fRmini);
00176    fERmax->SetNumber(fRmaxi);
00177    fEDz->SetNumber(fDzi);
00178    fApply->SetEnabled(kFALSE);
00179    fUndo->SetEnabled(kFALSE);
00180    
00181    if (fInit) ConnectSignals2Slots();
00182    SetActive();
00183 }
00184 
00185 //______________________________________________________________________________
00186 Bool_t TGeoTubeEditor::IsDelayed() const
00187 {
00188 // Check if shape drawing is delayed.
00189    return (fDelayed->GetState() == kButtonDown);
00190 }
00191 
00192 //______________________________________________________________________________
00193 void TGeoTubeEditor::DoName()
00194 {
00195 // Perform name change.
00196    DoModified();
00197 }
00198 
00199 //______________________________________________________________________________
00200 void TGeoTubeEditor::DoApply()
00201 {
00202 // Slot for applying modifications.
00203    const char *name = fShapeName->GetText();
00204    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00205    Double_t rmin = fERmin->GetNumber();
00206    Double_t rmax = fERmax->GetNumber();
00207    Double_t dz = fEDz->GetNumber();
00208    fShape->SetTubeDimensions(rmin, rmax, dz);
00209    fShape->ComputeBBox();
00210    fUndo->SetEnabled();
00211    fApply->SetEnabled(kFALSE);
00212    if (fPad) {
00213       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00214          fShape->Draw();
00215          fPad->GetView()->ShowAxis();
00216       } else Update();
00217    }   
00218 }
00219 
00220 //______________________________________________________________________________
00221 void TGeoTubeEditor::DoModified()
00222 {
00223 // Slot for signaling modifications.
00224    fApply->SetEnabled();
00225 }
00226 
00227 //______________________________________________________________________________
00228 void TGeoTubeEditor::DoUndo()
00229 {
00230 // Slot for undoing last operation.
00231    fERmin->SetNumber(fRmini);
00232    fERmax->SetNumber(fRmaxi);
00233    fEDz->SetNumber(fDzi);
00234    DoApply();
00235    fUndo->SetEnabled(kFALSE);
00236    fApply->SetEnabled(kFALSE);
00237 }
00238    
00239 //______________________________________________________________________________
00240 void TGeoTubeEditor::DoRmin()
00241 {
00242 // Slot for rmin.
00243    Double_t rmin = fERmin->GetNumber();
00244    Double_t rmax = fERmax->GetNumber();
00245    if (rmax<rmin+1.e-10) {
00246       rmin = rmax - 0.1;
00247       fERmin->SetNumber(rmin);
00248    }   
00249    DoModified();
00250    if (!IsDelayed()) DoApply();
00251 }
00252 
00253 //______________________________________________________________________________
00254 void TGeoTubeEditor::DoRmax()
00255 {
00256 // Slot for rmax.
00257    Double_t rmin = fERmin->GetNumber();
00258    Double_t rmax = fERmax->GetNumber();
00259    if (rmax <= 0.) {
00260       rmax = 0.1;
00261       fERmax->SetNumber(rmax);
00262    }     
00263    if (rmax<rmin+1.e-10) {
00264       rmax = rmin + 0.1;
00265       fERmax->SetNumber(rmax);
00266    }   
00267    DoModified();
00268    if (!IsDelayed()) DoApply();
00269 }
00270 
00271 //______________________________________________________________________________
00272 void TGeoTubeEditor::DoDz()
00273 {
00274 // Slot for dz.
00275    Double_t dz = fEDz->GetNumber();
00276    if (dz<=0) {
00277       dz = 0.1;
00278       fEDz->SetNumber(dz);
00279    }   
00280    DoModified();
00281    if (!IsDelayed()) DoApply();
00282 }
00283 
00284 //////////////////////////////////////////////////////////////////////////
00285 //                                                                      //
00286 //  TGeoTubeSegEditor                                                   //
00287 //                                                                      //
00288 //////////////////////////////////////////////////////////////////////////
00289 //Begin_Html
00290 /*
00291 <img src="gif/tubs_pic.gif">
00292 */
00293 //End_Html
00294 //Begin_Html
00295 /*
00296 <img src="gif/tubs_ed.jpg">
00297 */
00298 //End_Html
00299 
00300 ClassImp(TGeoTubeSegEditor)
00301 
00302 enum ETGeoTubeSegWid {
00303    kTUBESEG_PHI1, kTUBESEG_PHI2, kTUBESEG_PHI
00304 };
00305 
00306 //______________________________________________________________________________
00307 TGeoTubeSegEditor::TGeoTubeSegEditor(const TGWindow *p, Int_t width,
00308                                      Int_t height, UInt_t options, Pixel_t back)
00309   : TGeoTubeEditor(p, width, height, options | kVerticalFrame, back)
00310 {
00311    // Constructor for tube segment editor
00312    fLock = kFALSE;
00313    MakeTitle("Phi range");
00314    TGTextEntry *nef;
00315    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 155, 110, kHorizontalFrame | kFixedWidth | kFixedHeight | kRaisedFrame);
00316    // Vertical slider
00317    fSPhi = new TGDoubleVSlider(compxyz,100);
00318    fSPhi->SetRange(0.,720.);
00319    fSPhi->Resize(fSPhi->GetDefaultWidth(), 100);
00320    compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4)); 
00321    TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 135, 100, kVerticalFrame | kFixedHeight);
00322    f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 6, 0));
00323    fEPhi1 = new TGNumberEntry(f1, 0., 5, kTUBESEG_PHI1);
00324    fEPhi1->Resize(100, fEPhi1->GetDefaultHeight());
00325    fEPhi1->SetNumAttr(TGNumberFormat::kNEANonNegative);
00326    nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
00327    nef->SetToolTipText("Enter the phi1 value");
00328    fEPhi1->Associate(this);
00329    f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 2, 2, 2));
00330 
00331    fEPhi2 = new TGNumberEntry(f1, 0., 5, kTUBESEG_PHI2);
00332    fEPhi2->Resize(100, fEPhi2->GetDefaultHeight());
00333    fEPhi2->SetNumAttr(TGNumberFormat::kNEANonNegative);
00334    nef = (TGTextEntry*)fEPhi2->GetNumberEntry();
00335    nef->SetToolTipText("Enter the phi2 value");
00336    fEPhi2->Associate(this);
00337    f1->AddFrame(fEPhi2, new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 2, 2));
00338    f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom, 0, 0, 6, 2));
00339    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00340    
00341 //   compxyz->Resize(150,150);
00342    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00343    TGeoTabManager::MoveFrame(fDFrame, this);
00344    TGeoTabManager::MoveFrame(fBFrame, this);
00345 }
00346 
00347 //______________________________________________________________________________
00348 TGeoTubeSegEditor::~TGeoTubeSegEditor()
00349 {
00350 // Destructor
00351    TGFrameElement *el;
00352    TIter next(GetList());
00353    while ((el = (TGFrameElement *)next())) {
00354       if (el->fFrame->IsComposite()) 
00355          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00356    }
00357    Cleanup();   
00358 }
00359 
00360 //______________________________________________________________________________
00361 void TGeoTubeSegEditor::ConnectSignals2Slots()
00362 {
00363    // Connect signals to slots.
00364    TGeoTubeEditor::ConnectSignals2Slots();
00365    Disconnect(fApply, "Clicked()",(TGeoTubeEditor*)this, "DoApply()");
00366    Disconnect(fUndo, "Clicked()",(TGeoTubeEditor*)this, "DoUndo()");
00367    fApply->Connect("Clicked()", "TGeoTubeSegEditor", this, "DoApply()");
00368    fUndo->Connect("Clicked()", "TGeoTubeSegEditor", this, "DoUndo()");
00369    fEPhi1->Connect("ValueSet(Long_t)", "TGeoTubeSegEditor", this, "DoPhi1()");
00370    fEPhi2->Connect("ValueSet(Long_t)", "TGeoTubeSegEditor", this, "DoPhi2()");
00371 //   fEPhi1->GetNumberEntry()->Connect("TextChanged(const char *)","TGeoTubeSegEditor", this, "DoPhi1()");
00372 //   fEPhi2->GetNumberEntry()->Connect("TextChanged(const char *)","TGeoTubeSegEditor", this, "DoPhi2()");
00373    fSPhi->Connect("PositionChanged()","TGeoTubeSegEditor", this, "DoPhi()");
00374 }
00375 
00376 //______________________________________________________________________________
00377 void TGeoTubeSegEditor::SetModel(TObject* obj)
00378 {
00379    // Connect to the selected object.
00380    if (obj == 0 || (obj->IsA()!=TGeoTubeSeg::Class())) {
00381       SetActive(kFALSE);
00382       return;                 
00383    } 
00384    fShape = (TGeoTube*)obj;
00385    fRmini = fShape->GetRmin();
00386    fRmaxi = fShape->GetRmax();
00387    fDzi = fShape->GetDz();
00388    fNamei = fShape->GetName();
00389    fPmini = ((TGeoTubeSeg*)fShape)->GetPhi1();
00390    fPmaxi = ((TGeoTubeSeg*)fShape)->GetPhi2();
00391    fShapeName->SetText(fShape->GetName());
00392    fEPhi1->SetNumber(fPmini);
00393    fEPhi2->SetNumber(fPmaxi);
00394    fSPhi->SetPosition(fPmini,fPmaxi);
00395    fERmin->SetNumber(fRmini);
00396    fERmax->SetNumber(fRmaxi);
00397    fEDz->SetNumber(fDzi);
00398    fApply->SetEnabled(kFALSE);
00399    fUndo->SetEnabled(kFALSE);
00400    
00401    if (fInit) ConnectSignals2Slots();
00402    SetActive();
00403 }
00404 
00405 //______________________________________________________________________________
00406 void TGeoTubeSegEditor::DoPhi1()
00407 {
00408 // Slot for phi1.
00409    Double_t phi1 = fEPhi1->GetNumber();
00410    Double_t phi2 = fEPhi2->GetNumber();
00411    if (phi1 > 360-1.e-10) {
00412       phi1 = 0.;
00413       fEPhi1->SetNumber(phi1);
00414    }   
00415    if (phi2<phi1+1.e-10) {
00416       phi1 = phi2 - 0.1;
00417       fEPhi1->SetNumber(phi1);
00418    }   
00419    if (!fLock) {
00420       DoModified();
00421       fLock = kTRUE;
00422       fSPhi->SetPosition(phi1,phi2);
00423    } else fLock = kFALSE;
00424    if (!IsDelayed()) DoApply();
00425 }
00426 
00427 //______________________________________________________________________________
00428 void TGeoTubeSegEditor::DoPhi2()
00429 {
00430 // Slot for phi2.
00431    Double_t phi1 = fEPhi1->GetNumber();
00432    Double_t phi2 = fEPhi2->GetNumber();
00433    if (phi2-phi1 > 360.) {
00434       phi2 -= 360.;
00435       fEPhi2->SetNumber(phi2);
00436    }   
00437    if (phi2<phi1+1.e-10) {
00438       phi2 = phi1 + 0.1;
00439       fEPhi2->SetNumber(phi2);
00440    }   
00441    if (!fLock) {
00442       DoModified();
00443       fLock = kTRUE;
00444       fSPhi->SetPosition(phi1,phi2);
00445    } else fLock = kFALSE;
00446    if (!IsDelayed()) DoApply();
00447 }
00448 
00449 //______________________________________________________________________________
00450 void TGeoTubeSegEditor::DoPhi()
00451 {
00452 // Slot for phi slider.
00453    if (!fLock) {
00454       DoModified();
00455       fLock = kTRUE;
00456       fEPhi1->SetNumber(fSPhi->GetMinPosition());
00457       fLock = kTRUE;
00458       fEPhi2->SetNumber(fSPhi->GetMaxPosition());
00459    } else fLock = kFALSE;   
00460    if (!IsDelayed()) DoApply();
00461 }
00462 
00463 //______________________________________________________________________________
00464 void TGeoTubeSegEditor::DoApply()
00465 {
00466 // Slot for applying modifications.
00467    fApply->SetEnabled(kFALSE);
00468    const char *name = fShapeName->GetText();
00469    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00470    Double_t rmin = fERmin->GetNumber();
00471    Double_t rmax = fERmax->GetNumber();
00472    if (rmin<0 || rmax<rmin) return;
00473    Double_t dz = fEDz->GetNumber();
00474    Double_t phi1 = fEPhi1->GetNumber();
00475    Double_t phi2 = fEPhi2->GetNumber();
00476    if ((phi2-phi1) > 360.001) {
00477       phi1 = 0.;
00478       phi2 = 360.;
00479       fEPhi1->SetNumber(phi1);
00480       fEPhi2->SetNumber(phi2);
00481       fLock = kTRUE;
00482       fSPhi->SetPosition(phi1,phi2);
00483       fLock = kFALSE;
00484    }   
00485    ((TGeoTubeSeg*)fShape)->SetTubsDimensions(rmin, rmax, dz, phi1, phi2);
00486    fShape->ComputeBBox();
00487    fUndo->SetEnabled();
00488    if (fPad) {
00489       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00490          fShape->Draw();
00491          fPad->GetView()->ShowAxis();
00492       } else Update();
00493    }   
00494 }
00495 
00496 //______________________________________________________________________________
00497 void TGeoTubeSegEditor::DoUndo()
00498 {
00499 // Slot for undoing last operation.
00500    fERmin->SetNumber(fRmini);
00501    fERmax->SetNumber(fRmaxi);
00502    fEDz->SetNumber(fDzi);
00503    fEPhi1->SetNumber(fPmini);
00504    fEPhi2->SetNumber(fPmaxi);
00505    fSPhi->SetPosition(fPmini,fPmaxi);
00506    DoApply();
00507    fUndo->SetEnabled(kFALSE);
00508    fApply->SetEnabled(kFALSE);
00509 }
00510 
00511 //////////////////////////////////////////////////////////////////////////
00512 //                                                                      //
00513 //  TGeoCtubEditor                                                   //
00514 //                                                                      //
00515 //////////////////////////////////////////////////////////////////////////
00516 //Begin_Html
00517 /*
00518 <img src="gif/ctub_pic.gif">
00519 */
00520 //End_Html
00521 //Begin_Html
00522 /*
00523 <img src="gif/ctub_ed.jpg">
00524 */
00525 //End_Html
00526 
00527 ClassImp(TGeoCtubEditor)
00528 
00529 enum ETGeoCtubSegWid {
00530    kCTUB_THLO, kCTUB_PHLO, kCTUB_THHI, kCTUB_PHHI
00531 };
00532 
00533 //______________________________________________________________________________
00534 TGeoCtubEditor::TGeoCtubEditor(const TGWindow *p, Int_t width,
00535                                Int_t height, UInt_t options, Pixel_t back)
00536   : TGeoTubeSegEditor(p, width, height, options, back)
00537 {
00538    // Constructor for cut tube editor
00539    MakeTitle("Theta/phi low");
00540    TGTextEntry *nef;
00541    // Number entry for theta/phi of the lower normal
00542    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
00543    TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00544    f1->AddFrame(new TGLabel(f1, "TH_LO"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00545    fEThlo = new TGNumberEntry(f1, 0., 5, kCTUB_THLO);
00546    fEThlo->SetNumAttr(TGNumberFormat::kNEANonNegative);
00547    nef = (TGTextEntry*)fEThlo->GetNumberEntry();
00548    nef->SetToolTipText("Enter the theta angle of the lower plane normal");
00549    fEThlo->Associate(this);
00550    fEThlo->Connect("ValueSet(Long_t)", "TGeoCtubEditor", this, "DoThlo()");
00551    nef->Connect("TextChanged(const char *)","TGeoCtubEditor", this, "DoModified()");
00552    fEThlo->Resize(100,fEThlo->GetDefaultHeight());
00553    f1->AddFrame(fEThlo, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00554    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00555 
00556    f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00557    f1->AddFrame(new TGLabel(f1, "PH_LO"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00558    fEPhlo = new TGNumberEntry(f1, 0., 5, kCTUB_PHLO);
00559    fEPhlo->SetNumAttr(TGNumberFormat::kNEANonNegative);
00560    nef = (TGTextEntry*)fEPhlo->GetNumberEntry();
00561    nef->SetToolTipText("Enter the phi angle of the lower plane normal");
00562    fEPhlo->Associate(this);
00563    fEPhlo->Connect("ValueSet(Long_t)", "TGeoCtubEditor", this, "DoPhlo()");
00564    nef->Connect("TextChanged(const char *)","TGeoCtubEditor", this, "DoModified()");
00565    fEPhlo->Resize(100,fEPhlo->GetDefaultHeight());
00566    f1->AddFrame(fEPhlo, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00567    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00568    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00569 
00570    // Number entry for theta/phi of the lower normal
00571    MakeTitle("Theta/phi high");
00572    compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
00573    f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00574    f1->AddFrame(new TGLabel(f1, "TH_HI"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00575    fEThhi = new TGNumberEntry(f1, 0., 5, kCTUB_THHI);
00576    fEThhi->SetNumAttr(TGNumberFormat::kNEANonNegative);
00577    nef = (TGTextEntry*)fEThhi->GetNumberEntry();
00578    nef->SetToolTipText("Enter the theta angle of the upper plane normal");
00579    fEThhi->Associate(this);
00580    fEThhi->Connect("ValueSet(Long_t)", "TGeoCtubEditor", this, "DoThhi()");
00581    nef->Connect("TextChanged(const char *)","TGeoCtubEditor", this, "DoModified()");
00582    fEThhi->Resize(100,fEThhi->GetDefaultHeight());
00583    f1->AddFrame(fEThhi, new TGLayoutHints(kLHintsRight , 2, 2, 2, 2));
00584    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
00585 
00586    f1 = new TGCompositeFrame(compxyz, 155, 30, kHorizontalFrame | kFixedWidth);
00587    f1->AddFrame(new TGLabel(f1, "PH_HI"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00588    fEPhhi = new TGNumberEntry(f1, 0., 5, kCTUB_PHHI);
00589    fEPhhi->SetNumAttr(TGNumberFormat::kNEANonNegative);
00590    nef = (TGTextEntry*)fEPhhi->GetNumberEntry();
00591    nef->SetToolTipText("Enter the phi angle of the upper plane normal");
00592    fEPhhi->Associate(this);
00593    fEPhhi->Connect("ValueSet(Long_t)", "TGeoCtubEditor", this, "DoPhhi()");
00594    nef->Connect("TextChanged(const char *)","TGeoCtubEditor", this, "DoModified()");
00595    fEPhhi->Resize(100,fEPhhi->GetDefaultHeight());
00596    f1->AddFrame(fEPhhi, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00597    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00598    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
00599    TGeoTabManager::MoveFrame(fDFrame, this);
00600    TGeoTabManager::MoveFrame(fBFrame, this);
00601 }
00602 
00603 //______________________________________________________________________________
00604 TGeoCtubEditor::~TGeoCtubEditor()
00605 {
00606 // Destructor
00607    TGFrameElement *el;
00608    TIter next(GetList());
00609    while ((el = (TGFrameElement *)next())) {
00610       if (el->fFrame->IsComposite()) 
00611          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00612    }
00613    Cleanup();   
00614 }
00615 
00616 //______________________________________________________________________________
00617 void TGeoCtubEditor::SetModel(TObject* obj)
00618 {
00619    // Connect to the selected object.
00620    if (obj == 0 || (obj->IsA()!=TGeoCtub::Class())) {
00621       SetActive(kFALSE);
00622       return;                 
00623    } 
00624    fShape = (TGeoTube*)obj;
00625    fRmini = fShape->GetRmin();
00626    fRmaxi = fShape->GetRmax();
00627    fDzi = fShape->GetDz();
00628    fNamei = fShape->GetName();
00629    fPmini = ((TGeoTubeSeg*)fShape)->GetPhi1();
00630    fPmaxi = ((TGeoTubeSeg*)fShape)->GetPhi2();
00631    const Double_t *nlo = ((TGeoCtub*)fShape)->GetNlow();
00632    const Double_t *nhi = ((TGeoCtub*)fShape)->GetNhigh();
00633    fThlo = TMath::RadToDeg() * TMath::ACos(nlo[2]);
00634    fPhlo = TMath::RadToDeg() * TMath::ATan2(nlo[1], nlo[0]);
00635    fThhi = TMath::RadToDeg() * TMath::ACos(nhi[2]);
00636    fPhhi = TMath::RadToDeg() * TMath::ATan2(nhi[1], nhi[0]);
00637    
00638    fShapeName->SetText(fShape->GetName());
00639    fEPhi1->SetNumber(fPmini);
00640    fEPhi2->SetNumber(fPmaxi);
00641    fSPhi->SetPosition(fPmini,fPmaxi);
00642    fERmin->SetNumber(fRmini);
00643    fERmax->SetNumber(fRmaxi);
00644    fEDz->SetNumber(fDzi);
00645    fEThlo->SetNumber(fThlo);
00646    fEPhlo->SetNumber(fPhlo);
00647    fEThhi->SetNumber(fThhi);
00648    fEPhhi->SetNumber(fPhhi);
00649    fApply->SetEnabled(kFALSE);
00650    fUndo->SetEnabled(kFALSE);
00651    
00652    if (fInit) ConnectSignals2Slots();
00653    SetActive();
00654 }
00655 
00656 //______________________________________________________________________________
00657 void TGeoCtubEditor::DoThlo()
00658 {
00659 // Slot for phi1.
00660    Double_t thlo = fEThlo->GetNumber();
00661    if (thlo <= 90.) {thlo = 91.; fEThlo->SetNumber(thlo);}
00662    if (thlo > 180.) {thlo = 180.; fEThlo->SetNumber(thlo);}
00663    DoModified();
00664    if (!IsDelayed()) DoApply();
00665 }
00666 
00667 //______________________________________________________________________________
00668 void TGeoCtubEditor::DoPhlo()
00669 {
00670 // Slot for phi1.
00671    Double_t phlo = fEPhlo->GetNumber();
00672    if (phlo >= 360.) {
00673       phlo = 0.; 
00674       fEPhlo->SetNumber(phlo);
00675    }
00676    DoModified();
00677    if (!IsDelayed()) DoApply();
00678 }
00679    
00680 //______________________________________________________________________________
00681 void TGeoCtubEditor::DoThhi()
00682 {
00683 // Slot for phi1.
00684    Double_t thhi = fEThhi->GetNumber();
00685    if (thhi >= 90.) {thhi = 89.; fEThhi->SetNumber(thhi);}
00686    DoModified();
00687    if (!IsDelayed()) DoApply();
00688 }
00689 
00690 //______________________________________________________________________________
00691 void TGeoCtubEditor::DoPhhi()
00692 {
00693 // Slot for phi1.
00694    Double_t phhi = fEPhhi->GetNumber();
00695    if (phhi >= 360.) {
00696       phhi = 0.; 
00697       fEPhhi->SetNumber(phhi);
00698    }
00699    DoModified();
00700    if (!IsDelayed()) DoApply();
00701 }
00702 
00703 //______________________________________________________________________________
00704 void TGeoCtubEditor::DoApply()
00705 {
00706 // Slot for applying modifications.
00707    fApply->SetEnabled(kFALSE);
00708    const char *name = fShapeName->GetText();
00709    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00710    Double_t rmin = fERmin->GetNumber();
00711    Double_t rmax = fERmax->GetNumber();
00712    if (rmin<0 || rmax<rmin) return;
00713    Double_t dz = fEDz->GetNumber();
00714    Double_t phi1 = fEPhi1->GetNumber();
00715    Double_t phi2 = fEPhi2->GetNumber();
00716    if ((phi2-phi1) > 360.001) {
00717       phi1 = 0.;
00718       phi2 = 360.;
00719       fEPhi1->SetNumber(phi1);
00720       fEPhi2->SetNumber(phi2);
00721       fLock = kTRUE;
00722       fSPhi->SetPosition(phi1,phi2);
00723       fLock = kFALSE;
00724    } 
00725    Double_t thlo = TMath::DegToRad()*fEThlo->GetNumber();
00726    Double_t phlo = TMath::DegToRad()*fEPhlo->GetNumber();
00727    Double_t thhi = TMath::DegToRad()*fEThhi->GetNumber();  
00728    Double_t phhi = TMath::DegToRad()*fEPhhi->GetNumber();
00729    Double_t lx = TMath::Sin(thlo)*TMath::Cos(phlo);  
00730    Double_t ly = TMath::Sin(thlo)*TMath::Sin(phlo);  
00731    Double_t lz = TMath::Cos(thlo);
00732    Double_t tx = TMath::Sin(thhi)*TMath::Cos(phhi);  
00733    Double_t ty = TMath::Sin(thhi)*TMath::Sin(phhi);  
00734    Double_t tz = TMath::Cos(thhi);
00735    ((TGeoCtub*)fShape)->SetCtubDimensions(rmin, rmax, dz, phi1, phi2, lx,ly,lz,tx,ty,tz);
00736    fShape->ComputeBBox();
00737    fUndo->SetEnabled();
00738    if (fPad) {
00739       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00740          fShape->Draw();
00741          fPad->GetView()->ShowAxis();
00742       } else Update();
00743    }   
00744 }
00745 
00746 //______________________________________________________________________________
00747 void TGeoCtubEditor::DoUndo()
00748 {
00749 // Slot for undoing last operation.
00750    fERmin->SetNumber(fRmini);
00751    fERmax->SetNumber(fRmaxi);
00752    fEDz->SetNumber(fDzi);
00753    fEPhi1->SetNumber(fPmini);
00754    fEPhi2->SetNumber(fPmaxi);
00755    fSPhi->SetPosition(fPmini,fPmaxi);
00756    fEThlo->SetNumber(fThlo);
00757    fEPhlo->SetNumber(fPhlo);
00758    fEThhi->SetNumber(fThhi);
00759    fEPhhi->SetNumber(fPhhi);
00760    
00761    DoApply();
00762    fUndo->SetEnabled(kFALSE);
00763    fApply->SetEnabled(kFALSE);
00764 }

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