TGeoTrd2Editor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoTrd2Editor.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 //  TGeoTrd2Editor                                                      //
00015 //                                                                      //
00016 //////////////////////////////////////////////////////////////////////////
00017 //Begin_Html
00018 /*
00019 <img src="gif/trd2_pic.gif">
00020 */
00021 //End_Html
00022 //Begin_Html
00023 /*
00024 <img src="gif/trd2_ed.jpg">
00025 */
00026 //End_Html
00027 
00028 #include "TGeoTrd2Editor.h"
00029 #include "TGeoTabManager.h"
00030 #include "TGeoTrd2.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(TGeoTrd2Editor)
00043 
00044 enum ETGeoTrd2Wid {
00045    kTRD2_NAME, kTRD2_X1, kTRD2_X2,  kTRD2_Y1, kTRD2_Y2, kTRD2_Z,
00046    kTRD2_APPLY, kTRD2_UNDO
00047 };
00048 
00049 //______________________________________________________________________________
00050 TGeoTrd2Editor::TGeoTrd2Editor(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 trd2 editor
00055    fShape   = 0;
00056    fDxi1 = fDxi2 = fDyi1 = fDyi2 = fDzi = 0.0;
00057    fNamei = "";
00058    fIsModified = kFALSE;
00059    fIsShapeEditable = kFALSE;
00060 
00061    // TextEntry for shape name
00062    MakeTitle("Name");
00063    fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD2_NAME);
00064    fShapeName->Resize(135, fShapeName->GetDefaultHeight());
00065    fShapeName->SetToolTipText("Enter the box name");
00066    fShapeName->Associate(this);
00067    AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00068 
00069    TGTextEntry *nef;
00070    MakeTitle("Trd2 dimensions");
00071    TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
00072   
00073    // Number entry for dx1
00074    TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00075                                  kLHintsExpandX | kFixedWidth | kOwnBackground);
00076    f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00077    fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD2_X1);
00078    fEDx1->SetNumAttr(TGNumberFormat::kNEAPositive);
00079    nef = (TGTextEntry*)fEDx1->GetNumberEntry();
00080    nef->SetToolTipText("Enter the half-lenth in X1");
00081    fEDx1->Associate(this);
00082    f1->AddFrame(fEDx1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00083    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00084    
00085    // Number entry for dx2
00086    f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00087                                  kLHintsExpandX | kFixedWidth | kOwnBackground);
00088    f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00089    fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD2_X2);
00090    fEDx2->SetNumAttr(TGNumberFormat::kNEAPositive);
00091    nef = (TGTextEntry*)fEDx2->GetNumberEntry();
00092    nef->SetToolTipText("Enter the  half-lenth in X2");
00093    fEDx2->Associate(this);
00094    f1->AddFrame(fEDx2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00095    compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00096 
00097    // Number entry for dy1
00098    TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00099                                  kLHintsExpandX | kFixedWidth | kOwnBackground);
00100    f2->AddFrame(new TGLabel(f2, "DY1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00101    fEDy1 = new TGNumberEntry(f2, 0., 5, kTRD2_Y1);
00102    fEDy1->SetNumAttr(TGNumberFormat::kNEAPositive);
00103    nef = (TGTextEntry*)fEDy1->GetNumberEntry();
00104    nef->SetToolTipText("Enter the half-lenth in Y1");
00105    fEDy1->Associate(this);
00106    f2->AddFrame(fEDy1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00107    compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00108    
00109    // Number entry for dy2
00110    f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00111                                  kLHintsExpandX | kFixedWidth | kOwnBackground);
00112    f2->AddFrame(new TGLabel(f2, "DY2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00113    fEDy2 = new TGNumberEntry(f2, 0., 5, kTRD2_Y2);
00114    fEDy2->SetNumAttr(TGNumberFormat::kNEAPositive);
00115    nef = (TGTextEntry*)fEDy2->GetNumberEntry();
00116    nef->SetToolTipText("Enter the half-lenth in Y2");
00117    fEDy2->Associate(this);
00118    f2->AddFrame(fEDy2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00119    compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00120    
00121    // Number entry for dz
00122    TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
00123                                  kLHintsExpandX | kFixedWidth | kOwnBackground);
00124    f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
00125    fEDz = new TGNumberEntry(f3, 0., 5, kTRD2_Z);
00126    fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
00127    nef = (TGTextEntry*)fEDz->GetNumberEntry();
00128    nef->SetToolTipText("Enter the  half-lenth in Z");
00129    fEDz->Associate(this);
00130    f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00131    compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00132    
00133    compxyz->Resize(150,30);
00134    AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
00135       
00136    // Delayed draw
00137    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
00138    fDelayed = new TGCheckButton(f1, "Delayed draw");
00139    f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
00140    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00141 
00142    // Buttons
00143    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00144    fApply = new TGTextButton(f1, "Apply");
00145    f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00146    fApply->Associate(this);
00147    fUndo = new TGTextButton(f1, "Undo");
00148    f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00149    fUndo->Associate(this);
00150    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00151    fUndo->SetSize(fApply->GetSize());
00152 }
00153 
00154 //______________________________________________________________________________
00155 TGeoTrd2Editor::~TGeoTrd2Editor()
00156 {
00157 // Destructor.
00158    TGFrameElement *el;
00159    TIter next(GetList());
00160    while ((el = (TGFrameElement *)next())) {
00161       if (el->fFrame->IsComposite()) 
00162          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00163    }
00164    Cleanup();   
00165 }
00166 
00167 //______________________________________________________________________________
00168 void TGeoTrd2Editor::ConnectSignals2Slots()
00169 {
00170    // Connect signals to slots.
00171    fApply->Connect("Clicked()", "TGeoTrd2Editor", this, "DoApply()");
00172    fUndo->Connect("Clicked()", "TGeoTrd2Editor", this, "DoUndo()");
00173    fShapeName->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00174    fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx1()");
00175    fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx2()");
00176    fEDy1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy1()");
00177    fEDy2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy2()");
00178    fEDz->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDz()");
00179    fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00180    fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00181    fEDy1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00182    fEDy2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00183    fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
00184    fInit = kFALSE;
00185 }
00186 
00187 
00188 //______________________________________________________________________________
00189 void TGeoTrd2Editor::SetModel(TObject* obj)
00190 {
00191    // Connect to the selected object.
00192    if (obj == 0 || (obj->IsA()!=TGeoTrd2::Class())) {
00193       SetActive(kFALSE);
00194       return;                 
00195    } 
00196    fShape = (TGeoTrd2*)obj;
00197    fDxi1 = fShape->GetDx1();
00198    fDxi2 = fShape->GetDx2();
00199    fDyi1 = fShape->GetDy1();
00200    fDyi2 = fShape->GetDy2();
00201    fDzi = fShape->GetDz();
00202    const char *sname = fShape->GetName();
00203    if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
00204    else {
00205       fShapeName->SetText(sname);
00206       fNamei = sname;
00207    }   
00208    fEDx1->SetNumber(fDxi1);
00209    fEDx2->SetNumber(fDxi2);
00210    fEDy1->SetNumber(fDyi1);
00211    fEDy2->SetNumber(fDyi2);
00212    fEDz->SetNumber(fDzi);
00213    fApply->SetEnabled(kFALSE);
00214    fUndo->SetEnabled(kFALSE);
00215    
00216    if (fInit) ConnectSignals2Slots();
00217    SetActive();
00218 }
00219 
00220 //______________________________________________________________________________
00221 Bool_t TGeoTrd2Editor::IsDelayed() const
00222 {
00223 // Check if shape drawing is delayed.
00224    return (fDelayed->GetState() == kButtonDown);
00225 }
00226 
00227 //______________________________________________________________________________
00228 void TGeoTrd2Editor::DoName()
00229 {
00230 // Perform name change.
00231    DoModified();
00232 }
00233 
00234 //______________________________________________________________________________
00235 void TGeoTrd2Editor::DoApply()
00236 {
00237 // Slot for applying modifications.
00238    const char *name = fShapeName->GetText();
00239    if (strcmp(name,fShape->GetName())) fShape->SetName(name);
00240    Double_t dx1 = fEDx1->GetNumber();
00241    Double_t dx2 = fEDx2->GetNumber();
00242    Double_t dy1 = fEDy1->GetNumber(); 
00243    Double_t dy2 = fEDy2->GetNumber(); 
00244    Double_t dz = fEDz->GetNumber();
00245    Double_t param[5];
00246    param[0] = dx1;
00247    param[1] = dx2;
00248    param[2] = dy1;
00249    param[3] = dy2;
00250    param[4] = dz;
00251    fShape->SetDimensions(param);
00252    fShape->ComputeBBox();
00253    fUndo->SetEnabled();
00254    fApply->SetEnabled(kFALSE);
00255    if (fPad) {
00256       if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
00257          fShape->Draw();
00258          fPad->GetView()->ShowAxis();
00259       } else Update();
00260    }   
00261 }
00262 
00263 //______________________________________________________________________________
00264 void TGeoTrd2Editor::DoModified()
00265 {
00266 // Slot for signaling modifications.
00267    fApply->SetEnabled();
00268 }
00269 
00270 //______________________________________________________________________________
00271 void TGeoTrd2Editor::DoUndo()
00272 {
00273 // Slot for undoing last operation.
00274    fEDx1->SetNumber(fDxi1);
00275    fEDx2->SetNumber(fDxi2);
00276    fEDy1->SetNumber(fDyi1);
00277    fEDy2->SetNumber(fDyi2);
00278    fEDz->SetNumber(fDzi);
00279    DoApply();
00280    fUndo->SetEnabled(kFALSE);
00281    fApply->SetEnabled(kFALSE);
00282 }
00283    
00284 //______________________________________________________________________________
00285 void TGeoTrd2Editor::DoDx1()
00286 {
00287 // Slot for dx1.
00288    Double_t dx1 = fEDx1->GetNumber();
00289    Double_t dx2 = fEDx2->GetNumber();
00290    if (dx1<0) {
00291       dx1 = 0;
00292       fEDx1->SetNumber(dx1);
00293    }
00294    if (dx1<1.e-6 && dx2<1.e-6) {
00295       dx1 = 0.1;
00296       fEDx1->SetNumber(dx1);
00297    }      
00298    DoModified();
00299    if (!IsDelayed()) DoApply();
00300 }
00301 
00302 //______________________________________________________________________________
00303 void TGeoTrd2Editor::DoDx2()
00304 {
00305 // Slot for dx2.
00306    Double_t dx1 = fEDx1->GetNumber();
00307    Double_t dx2 = fEDx2->GetNumber();
00308    if (dx2<0) {
00309       dx2 = 0;
00310       fEDx2->SetNumber(dx2);
00311    }
00312    if (dx1<1.e-6 && dx2<1.e-6) {
00313       dx2 = 0.1;
00314       fEDx2->SetNumber(dx2);
00315    }      
00316    DoModified();
00317    if (!IsDelayed()) DoApply();
00318 }
00319 
00320 //______________________________________________________________________________
00321 void TGeoTrd2Editor::DoDy1()
00322 {
00323 // Slot for dy1.
00324    Double_t dy1 = fEDy1->GetNumber();
00325    Double_t dy2 = fEDy2->GetNumber();
00326    if (dy1<0) {
00327       dy1 = 0;
00328       fEDy1->SetNumber(dy1);
00329    }
00330    if (dy1<1.e-6 && dy2<1.e-6) {
00331       dy1 = 0.1;
00332       fEDy1->SetNumber(dy1);
00333    }      
00334    DoModified();
00335    if (!IsDelayed()) DoApply();
00336 }
00337 
00338 //______________________________________________________________________________
00339 void TGeoTrd2Editor::DoDy2()
00340 {
00341 // Slot for dy2.
00342    Double_t dy1 = fEDy1->GetNumber();
00343    Double_t dy2 = fEDy2->GetNumber();
00344    if (dy2<0) {
00345       dy2 = 0;
00346       fEDy2->SetNumber(dy2);
00347    }
00348    if (dy1<1.e-6 && dy2<1.e-6) {
00349       dy2 = 0.1;
00350       fEDy2->SetNumber(dy2);
00351    }      
00352    DoModified();
00353    if (!IsDelayed()) DoApply();
00354 }
00355 
00356 //______________________________________________________________________________
00357 void TGeoTrd2Editor::DoDz()
00358 {
00359 // Slot for dz.
00360    Double_t dz = fEDz->GetNumber();
00361    if (dz<=0) {
00362       dz = 0.1;
00363       fEDz->SetNumber(dz);
00364    }
00365    DoModified();
00366    if (!IsDelayed()) DoApply();
00367 }
00368 
00369 

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