TGeoEltuEditor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoEltuEditor.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 //  TGeoEltuEditor                                                      //
00015 //                                                                      //
00016 //////////////////////////////////////////////////////////////////////////
00017 //Begin_Html
00018 /*
00019 <img src="gif/eltu_pic.gif">
00020 */
00021 //End_Html
00022 //Begin_Html
00023 /*
00024 <img src="gif/eltu_ed.jpg">
00025 */
00026 //End_Html
00027 
00028 #include "TGeoEltuEditor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoEltu.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 
00042 ClassImp(TGeoEltuEditor)
00043 
00044 enum ETGeoEltuWid {
00045    kELTU_NAME, kELTU_A, kELTU_B,  kELTU_DZ,
00046    kELTU_APPLY, kELTU_UNDO
00047 };
00048 
00049 //______________________________________________________________________________
00050 TGeoEltuEditor::TGeoEltuEditor(const TGWindow *p, Int_t width,
00051                                    Int_t height, UInt_t options, Pixel_t back)
00052    : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00053 {
00054    // Constructor for para editor
00055    fShape   = 0;
00056    fAi = fBi = fDzi = 0.0;
00057    fNamei = "";
00058    fIsModified = kFALSE;
00059    fIsShapeEditable = kTRUE;
00060 
00061    // TextEntry for shape name
00062    MakeTitle("Name");
00063    fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kELTU_NAME);
00064    fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00065    fShapeName->SetToolTipText("Enter the elliptical tube name");
00066    fShapeName->Associate(this);
00067    AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00068 
00069    TGTextEntry *nef;
00070    MakeTitle("Dimensions");
00071    // Number entry for A
00072    TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00073    f1->AddFrame(new TGLabel(f1, "A"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00074    fEA = new TGNumberEntry(f1, 0., 5, kELTU_A);
00075    fEA->SetNumAttr(TGNumberFormat::kNEAPositive);
00076    fEA->Resize(100, fEA->GetDefaultHeight());
00077    nef = (TGTextEntry*)fEA->GetNumberEntry();
00078    nef->SetToolTipText("Enter the semi-axis of the ellipse along x");
00079    fEA->Associate(this);
00080    f1->AddFrame(fEA, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00081    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00082    
00083    // Number entry for B
00084    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00085    f1->AddFrame(new TGLabel(f1, "B"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00086    fEB = new TGNumberEntry(f1, 0., 5, kELTU_B);
00087    fEB->SetNumAttr(TGNumberFormat::kNEAPositive);
00088    fEB->Resize(100, fEB->GetDefaultHeight());
00089    nef = (TGTextEntry*)fEB->GetNumberEntry();
00090    nef->SetToolTipText("Enter the semi-axis of the ellipse along y");
00091    fEB->Associate(this);
00092    f1->AddFrame(fEB, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00093    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00094    
00095    // Number entry for dz
00096    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00097    f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00098    fEDz = new TGNumberEntry(f1, 0., 5, kELTU_DZ);
00099    fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00100    fEDz->Resize(100, fEDz->GetDefaultHeight());
00101    nef = (TGTextEntry*)fEDz->GetNumberEntry();
00102    nef->SetToolTipText("Enter the half-lenth in Z");
00103    fEDz->Associate(this);
00104    f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
00105    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00106  
00107    // Delayed draw
00108    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00109    fDelayed = new TGCheckButton(f1, "Delayed draw");
00110    f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00111    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00112 
00113    // Buttons
00114    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00115    fApply = new TGTextButton(f1, "Apply");
00116    f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00117    fApply->Associate(this);
00118    fUndo = new TGTextButton(f1, "Undo");
00119    f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00120    fUndo->Associate(this);
00121    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00122    fUndo->SetSize(fApply->GetSize());
00123 }
00124 
00125 //______________________________________________________________________________
00126 TGeoEltuEditor::~TGeoEltuEditor()
00127 {
00128 // Destructor
00129    TGFrameElement *el;
00130    TIter next(GetList());
00131    while ((el = (TGFrameElement *)next())) {
00132       if (el->fFrame->IsComposite()) 
00133          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00134    }
00135    Cleanup();   
00136 }
00137 
00138 //______________________________________________________________________________
00139 void TGeoEltuEditor::ConnectSignals2Slots()
00140 {
00141    // Connect signals to slots.
00142    fApply->Connect("Clicked()", "TGeoEltuEditor", this, "DoApply()");
00143    fUndo->Connect("Clicked()", "TGeoEltuEditor", this, "DoUndo()");
00144    fShapeName->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
00145    fEA->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoA()");
00146    fEB->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoB()");
00147    fEDz->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoDz()");
00148    fEA->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
00149    fEB->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
00150    fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
00151    fInit = kFALSE;
00152 }
00153 
00154 //______________________________________________________________________________
00155 void TGeoEltuEditor::SetModel(TObject* obj)
00156 {
00157    // Connect to the selected object.
00158    if (obj == 0 || (obj->IsA()!=TGeoEltu::Class())) {
00159       SetActive(kFALSE);
00160       return;                 
00161    } 
00162    fShape = (TGeoEltu*)obj;
00163    fAi = fShape->GetA();
00164    fBi = fShape->GetB();
00165    fDzi = fShape->GetDz();
00166    const char *sname = fShape->GetName();
00167    if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00168    else {
00169       fShapeName->SetText(sname);
00170       fNamei = sname;
00171    }   
00172    fEA->SetNumber(fAi);
00173    fEB->SetNumber(fBi);
00174    fEDz->SetNumber(fDzi);
00175    fApply->SetEnabled(kFALSE);
00176    fUndo->SetEnabled(kFALSE);
00177    
00178    if (fInit) ConnectSignals2Slots();
00179    SetActive();
00180 }
00181 
00182 //______________________________________________________________________________
00183 void TGeoEltuEditor::DoName()
00184 {
00185 // Slot for name.
00186    DoModified();
00187 }
00188 
00189 //______________________________________________________________________________
00190 Bool_t TGeoEltuEditor::IsDelayed() const
00191 {
00192 // Check if shape drawing is delayed.
00193    return (fDelayed->GetState() == kButtonDown);
00194 }
00195 
00196 //______________________________________________________________________________
00197 void TGeoEltuEditor::DoApply()
00198 {
00199 // Slot for applying current settings.
00200    const char *name = fShapeName->GetText();
00201    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00202    Double_t a = fEA->GetNumber();
00203    Double_t b = fEB->GetNumber(); 
00204    Double_t z = fEDz->GetNumber();  
00205    Double_t param[3];
00206    param[0] = a;
00207    param[1] = b;
00208    param[2] = z;
00209    fShape->SetDimensions(param);
00210    fShape->ComputeBBox();
00211    fUndo->SetEnabled();
00212    fApply->SetEnabled(kFALSE);
00213    if (fPad) {
00214       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00215          TView *view = fPad->GetView();
00216          if (!view) {
00217             fShape->Draw();
00218             fPad->GetView()->ShowAxis();
00219          } else {
00220             view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
00221                            fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
00222             Update();
00223          }                  
00224       } else Update();
00225    }   
00226 }
00227 
00228 //______________________________________________________________________________
00229 void TGeoEltuEditor::DoModified()
00230 {
00231 // Slot for notifying modifications.
00232    fApply->SetEnabled();
00233 }
00234 
00235 //______________________________________________________________________________
00236 void TGeoEltuEditor::DoUndo()
00237 {
00238 // Slot for undoing last operation.
00239    fEA->SetNumber(fAi);
00240    fEB->SetNumber(fBi);
00241    fEDz->SetNumber(fDzi);
00242    DoApply();
00243    fUndo->SetEnabled(kFALSE);
00244    fApply->SetEnabled(kFALSE);
00245 }
00246    
00247 //______________________________________________________________________________
00248 void TGeoEltuEditor::DoA()
00249 {
00250 // Slot for A.
00251    Double_t a = fEA->GetNumber();
00252    if (a <= 0) {
00253       a = 0.1;
00254       fEA->SetNumber(a);
00255    }   
00256    DoModified();
00257    if (!IsDelayed()) DoApply();
00258 }
00259 
00260 //______________________________________________________________________________
00261 void TGeoEltuEditor::DoB()
00262 {
00263 // Slot for B.
00264    Double_t b = fEB->GetNumber();
00265    if (b <= 0) {
00266       b = 0.1;
00267       fEB->SetNumber(b);
00268    }   
00269    DoModified();
00270    if (!IsDelayed()) DoApply();
00271 }
00272 
00273 //______________________________________________________________________________
00274 void TGeoEltuEditor::DoDz()
00275 {
00276 // Slot for Z.
00277    Double_t z = fEDz->GetNumber();
00278    if (z <= 0) {
00279       z = 0.1;
00280       fEDz->SetNumber(z);
00281    }   
00282    DoModified();
00283    if (!IsDelayed()) DoApply();
00284 }
00285 

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