TGeoNodeEditor.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoNodeEditor.cxx 21494 2007-12-19 15:50:40Z brun $
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 //  TGeoNodeEditor - Editor class for TGeoNode objects
00015 //                                                                      
00016 //______________________________________________________________________________
00017 
00018 #include "TGeoNodeEditor.h"
00019 #include "TGedEditor.h"
00020 #include "TGeoManager.h"
00021 #include "TGeoMatrix.h"
00022 #include "TGeoNode.h"
00023 #include "TPad.h"
00024 #include "TGTab.h"
00025 #include "TGComboBox.h"
00026 #include "TGButton.h"
00027 #include "TGTextEntry.h"
00028 #include "TGNumberEntry.h"
00029 #include "TGLabel.h"
00030 #include "TGeoTabManager.h"
00031 
00032 ClassImp(TGeoNodeEditor)
00033 
00034 enum ETGeoNodeWid {
00035    kNODE_NAME, kNODE_ID, kNODE_VOLSEL, kNODE_MVOLSEL,
00036    kNODE_MATRIX, kNODE_EDIT_VOL, kNODE_EDIT_MATRIX
00037 };
00038 
00039 //______________________________________________________________________________
00040 TGeoNodeEditor::TGeoNodeEditor(const TGWindow *p, Int_t width,
00041                                Int_t height, UInt_t options, Pixel_t back)
00042    : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
00043 {
00044    // Constructor for node editor
00045    
00046    fNode   = 0;
00047    fIsEditable = kTRUE;
00048    Pixel_t color;
00049       
00050    // TextEntry for medium name
00051    TGTextEntry *nef;
00052    MakeTitle("Name");
00053    TGCompositeFrame *f1 = new TGCompositeFrame(this, 140, 30, kHorizontalFrame | kRaisedFrame);
00054    fNodeName = new TGTextEntry(f1, new TGTextBuffer(50), kNODE_NAME);
00055    fNodeName->Resize(100, fNodeName->GetDefaultHeight());
00056    fNodeName->SetToolTipText("Enter the node name");
00057    fNodeName->Associate(this);
00058    f1->AddFrame(fNodeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00059    f1->AddFrame(new TGLabel(f1, "ID"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));   
00060    fNodeNumber = new TGNumberEntry(f1, 0., 1, kNODE_ID);
00061    nef = (TGTextEntry*)fNodeNumber->GetNumberEntry();
00062    nef->SetToolTipText("Enter the node copy number");
00063    fNodeNumber->Associate(this);
00064    f1->AddFrame(fNodeNumber, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
00065    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 3, 3, 2, 5));
00066 
00067 
00068 // Mother volume selection
00069    MakeTitle("Mother volume");
00070    f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
00071    fSelectedMother = 0;
00072    fLSelMother = new TGLabel(f1, "Select mother");
00073    gClient->GetColorByName("#0000ff", color);
00074    fLSelMother->SetTextColor(color);
00075    fLSelMother->ChangeOptions(kSunkenFrame | kDoubleBorder);
00076    f1->AddFrame(fLSelMother, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
00077    fBSelMother = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_MVOLSEL);
00078    fBSelMother->SetToolTipText("Select one of the existing volumes");
00079    fBSelMother->Associate(this);
00080    f1->AddFrame(fBSelMother, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
00081    fEditMother = new TGTextButton(f1, "Edit");
00082    f1->AddFrame(fEditMother, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
00083    fEditMother->Associate(this);
00084    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
00085    
00086 // Volume selection
00087    MakeTitle("Volume");
00088    f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
00089    fSelectedVolume = 0;
00090    fLSelVolume = new TGLabel(f1, "Select volume");
00091    gClient->GetColorByName("#0000ff", color);
00092    fLSelVolume->SetTextColor(color);
00093    fLSelVolume->ChangeOptions(kSunkenFrame | kDoubleBorder);
00094    f1->AddFrame(fLSelVolume, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
00095    fBSelVolume = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_VOLSEL);
00096    fBSelVolume->SetToolTipText("Select one of the existing volumes");
00097    fBSelVolume->Associate(this);
00098    f1->AddFrame(fBSelVolume, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
00099    fEditVolume = new TGTextButton(f1, "Edit");
00100    f1->AddFrame(fEditVolume, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
00101    fEditVolume->Associate(this);
00102    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
00103 
00104 // Matrix selection
00105    MakeTitle("Matrix");
00106    f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
00107    fSelectedMatrix = 0;
00108    fLSelMatrix = new TGLabel(f1, "Select matrix");
00109    gClient->GetColorByName("#0000ff", color);
00110    fLSelMatrix->SetTextColor(color);
00111    fLSelMatrix->ChangeOptions(kSunkenFrame | kDoubleBorder);
00112    f1->AddFrame(fLSelMatrix, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
00113    fBSelMatrix = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_MATRIX);
00114    fBSelMatrix->SetToolTipText("Select one of the existing matrices");
00115    fBSelMatrix->Associate(this);
00116    f1->AddFrame(fBSelMatrix, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
00117    fEditMatrix = new TGTextButton(f1, "Edit");
00118    f1->AddFrame(fEditMatrix, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
00119    fEditMatrix->Associate(this);
00120    AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
00121   
00122    // Buttons
00123    f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
00124    fApply = new TGTextButton(f1, "Apply");
00125    f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
00126    fApply->Associate(this);
00127    fUndo = new TGTextButton(f1, "Undo");
00128    f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
00129    fUndo->Associate(this);
00130    AddFrame(f1,  new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));  
00131    fUndo->SetSize(fApply->GetSize());
00132 }
00133 
00134 //______________________________________________________________________________
00135 TGeoNodeEditor::~TGeoNodeEditor()
00136 {
00137 // Destructor
00138    TGFrameElement *el;
00139    TIter next(GetList());
00140    while ((el = (TGFrameElement *)next())) {
00141       if (el->fFrame->IsComposite()) 
00142          TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
00143    }
00144    Cleanup();   
00145 }
00146 
00147 //______________________________________________________________________________
00148 void TGeoNodeEditor::ConnectSignals2Slots()
00149 {
00150    // Connect signals to slots.
00151    fBSelMother->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectMother()");
00152    fBSelVolume->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectVolume()");
00153    fBSelMatrix->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectMatrix()");
00154    fApply->Connect("Clicked()", "TGeoNodeEditor", this, "DoApply()");
00155    fUndo->Connect("Clicked()", "TGeoNodeEditor", this, "DoUndo()");
00156    fEditMother->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditMother()");
00157    fEditVolume->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditVolume()");
00158    fEditMatrix->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditMatrix()");
00159    fNodeName->Connect("TextChanged(const char *)", "TGeoNodeEditor", this, "DoNodeName()");
00160    fInit = kFALSE;
00161 }
00162 
00163 
00164 //______________________________________________________________________________
00165 void TGeoNodeEditor::SetModel(TObject* obj)
00166 {
00167    // Connect to a editable object.
00168    if (obj == 0 || !obj->InheritsFrom(TGeoNode::Class())) {
00169       SetActive(kFALSE);
00170       return;                 
00171    } 
00172    fNode = (TGeoNode*)obj;
00173    const char *sname = fNode->GetName();
00174    fNodeName->SetText(sname);
00175 
00176    fNodeNumber->SetNumber(fNode->GetNumber());
00177 
00178    fSelectedMother = fNode->GetMotherVolume();
00179    if (fSelectedMother) fLSelMother->SetText(fSelectedMother->GetName());
00180    fSelectedVolume = fNode->GetVolume();
00181    if (fSelectedVolume) fLSelVolume->SetText(fSelectedVolume->GetName());
00182    fSelectedMatrix = fNode->GetMatrix();
00183    if (fSelectedMatrix) fLSelMatrix->SetText(fSelectedMatrix->GetName());
00184 
00185    fApply->SetEnabled(kFALSE);
00186    fUndo->SetEnabled(kFALSE);
00187    
00188    if (fInit) ConnectSignals2Slots();
00189    SetActive();
00190 }
00191 
00192 //______________________________________________________________________________
00193 void TGeoNodeEditor::DoSelectMother()
00194 {
00195 // Select the mother volume.
00196    TGeoVolume *vol = fSelectedMother;
00197    new TGeoVolumeDialog(fBSelMother, gClient->GetRoot(), 200,300);  
00198    fSelectedMother = (TGeoVolume*)TGeoVolumeDialog::GetSelected();
00199    if (fSelectedMother) fLSelMother->SetText(fSelectedMother->GetName());
00200    else fSelectedMother = vol;
00201 }
00202 
00203 //______________________________________________________________________________
00204 void TGeoNodeEditor::DoSelectVolume()
00205 {
00206 // Select the volume.
00207    TGeoVolume *vol = fSelectedVolume;
00208    new TGeoVolumeDialog(fBSelVolume, gClient->GetRoot(), 200,300);  
00209    fSelectedVolume = (TGeoVolume*)TGeoVolumeDialog::GetSelected();
00210    if (fSelectedVolume) fLSelVolume->SetText(fSelectedVolume->GetName());
00211    else fSelectedVolume = vol;
00212 }
00213 
00214 //______________________________________________________________________________
00215 void TGeoNodeEditor::DoSelectMatrix()
00216 {
00217 // Select the matrix.
00218    TGeoMatrix *matrix = fSelectedMatrix;
00219    new TGeoMatrixDialog(fBSelMatrix, gClient->GetRoot(), 200,300);  
00220    fSelectedMatrix = (TGeoMatrix*)TGeoMatrixDialog::GetSelected();
00221    if (fSelectedMatrix) fLSelMatrix->SetText(fSelectedMatrix->GetName());
00222    else fSelectedMatrix = matrix;
00223 }
00224 
00225 //______________________________________________________________________________
00226 void TGeoNodeEditor::DoEditMother()
00227 {
00228 // Edit the mother volume.
00229    if (!fSelectedMother) {
00230       fTabMgr->SetVolTabEnabled(kFALSE);
00231       return;
00232    }   
00233    fTabMgr->SetVolTabEnabled();
00234    fTabMgr->GetVolumeEditor(fSelectedMother);
00235    fTabMgr->SetTab();
00236    fSelectedMother->Draw();
00237 }
00238 
00239 //______________________________________________________________________________
00240 void TGeoNodeEditor::DoEditVolume()
00241 {
00242 // Edit selected volume.
00243    if (!fSelectedVolume) {
00244       fTabMgr->SetVolTabEnabled(kFALSE);
00245       return;
00246    }   
00247    fTabMgr->SetVolTabEnabled();
00248    fTabMgr->GetVolumeEditor(fSelectedVolume);
00249    fTabMgr->SetTab();
00250    fSelectedVolume->Draw();
00251 }
00252 
00253 //______________________________________________________________________________
00254 void TGeoNodeEditor::DoEditMatrix()
00255 {
00256 // Edit selected material.
00257    if (!fSelectedMatrix) return;
00258    fTabMgr->GetMatrixEditor(fSelectedMatrix);
00259 }
00260 
00261 //______________________________________________________________________________
00262 void TGeoNodeEditor::DoNodeName()
00263 {
00264 // Change node name.
00265    const char *name = fNodeName->GetText();
00266    if (!strlen(name) || !strcmp(name, fNode->GetName())) return;
00267    fNode->SetName(name);
00268 }
00269 
00270 //______________________________________________________________________________
00271 void TGeoNodeEditor::DoNodeNumber()
00272 {
00273 // Change node copy number
00274    
00275 }
00276 
00277 //______________________________________________________________________________
00278 void TGeoNodeEditor::DoApply()
00279 {
00280 // Slot for applying modifications.
00281 }
00282 
00283 //______________________________________________________________________________
00284 void TGeoNodeEditor::DoUndo()
00285 {
00286 // Slot for undoing last operation.
00287 }
00288    

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